Fix flash memory address being a word-address
This commit is contained in:
parent
3a04b1f488
commit
a72bf67b07
@ -321,13 +321,15 @@ static inline void formatLoadAddressAnswer(Message &msg)
|
||||
|
||||
static inline void formatReadFlashIspAnswer(Message &msg, uint32_t &addr)
|
||||
{
|
||||
const uint16_t byteAddress = 2 * addr;
|
||||
const uint16_t numBytes = static_cast<uint16_t>(msg.body[1]) << 8 | msg.body[2];
|
||||
msg.size = 3 + numBytes;
|
||||
msg.body[1] = STATUS_CMD_OK;
|
||||
for (uint16_t i = 0; i < numBytes; ++i) {
|
||||
msg.body[i + 2] = pgm_read_byte(static_cast<uint16_t>(addr + i));
|
||||
msg.body[i + 2] = pgm_read_byte(static_cast<uint16_t>(byteAddress + i));
|
||||
}
|
||||
addr += numBytes;
|
||||
const auto numWords = numBytes / 2;
|
||||
addr += numWords;
|
||||
msg.body[numBytes + 2] = STATUS_CMD_OK;
|
||||
|
||||
msg.checksum = calcChecksum(msg);
|
||||
@ -459,10 +461,12 @@ static inline void formatReadEepromIspAnswer(Message &msg, uint32_t &addr)
|
||||
|
||||
static inline void formatProgramFlashIspAnswer(Message &msg, uint32_t &addr)
|
||||
{
|
||||
if (addr < getFlashSize())
|
||||
writeFlashPage(addr, msg.body + 10);
|
||||
const auto byteAddress = 2 * addr;
|
||||
if (byteAddress < getFlashSize())
|
||||
writeFlashPage(byteAddress, msg.body + 10);
|
||||
const uint16_t numBytes = static_cast<uint16_t>(msg.body[1]) << 8 | msg.body[2];
|
||||
addr += numBytes;
|
||||
const auto numWords = numBytes / 2;
|
||||
addr += numWords;
|
||||
|
||||
msg.size = 2;
|
||||
msg.body[1] = STATUS_CMD_OK;
|
||||
|
Loading…
Reference in New Issue
Block a user