cancel
Showing results for 
Search instead for 
Did you mean: 

Bootloader read memory command fails

Clament John
Associate II
Posted on June 13, 2017 at 09:14

I'm using an STM32F103 and flashing a code into it using the bootloader. I'm successful in writing the code into the MCU, but when I try reading it using the Read Memory command (pg13) [

http://www.st.com/content/ccc/resource/technical/document/application_note/51/5f/03/1e/bd/9b/45/be/CD00264342.pdf/files/CD00264342.pdf/jcr:content/translations/en.CD00264342.pdf

] it fails at step 6 (Send the number of bytes to be read (1 byte) & a checksum (1 byte).)  I receive a NACK. It's confusing here, so I tried sending both XOR of 8th byte with 0 and in the next try tried sending complement of 8th byte, both failed.

Here's what I'm doing:

1. Read 128 byte of the file to be written from SD card 

2. Write this 128 bytes into the STM32 flash (code space) through the boot loader //works perfectly fine

3. Read back the recently written 128 bytes to verify if the write was successful.

4. If data written == read, move on. Write the next set of data. 

5. Loop till the whole file has been written.

6. Send GO command and reset the STM.

P.S. I know the write command is working because previously I only had the write command, and it was working in the field. But some devices were flashed with the wrong/ corrupted code. So I'm reading back and checking if the data were written is the right one.

#stm32 #boot-loader
4 REPLIES 4
noobsen
Associate

@Clament John wrote:
Posted on June 13, 2017 at 09:14

... but when I try reading it using the Read Memory command it fails at step 6 (Send the number of bytes to be read (1 byte) & a checksum (1 byte).)  I receive a NACK. It's confusing here, so I tried sending both XOR of 8th byte with 0 and in the next try tried sending complement of 8th byte, both failed ...

 

#stm32 #boot-loader

Hi, 

it is an old issue but I had the same problem. I think there is specification failure. Try to add +1 to calculate the check sum for the amount of data you want to receive. This solves the problem for me.

example you want to get 128 bytes:  0x7F (data), 0x7F (checksum) => NACK 
correct: 0x7F (data), 0x80 (checksum) => OK 

I'm not convinced.

Show an actual transactional example. I don't recall having issues with the AN3155 protocol docs and F1 parts, but the docs have likely been reworked a few times in the last 15+ years 

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
noobsen
Associate

What should I say. The current specification AN3155 doesn't work with a STMF103C8 for the Read Memory Command. It takes me one day to find a solution for this error.

AN3155AN3155

If you take Byte 8 (127) and make a XOR of Byte 8 (127) for Byte 9, you will get a NACK.
If you take Byte 8 (127) and make a XOR of Byte 8 +1 (128) for Byte 9, you will get an OK.

I found this solution by sniffing the communication of the old program "Flash Loader Demo".
But this is only for the Read Memory Command and there only for Byte 9!

brymat
Associate II

I think I have figured this out as I was having the same issue.  The key is the wording in AN3155:

"Checksum: XOR byte 8 (complement of byte 8)"

 

It actually means that the second byte is the complement of the first byte.  In C, this would be the ~ operator.  This is the same as the command byte.

 

Example 1:

Byte 0 = 0x01 (Read 2 bytes)

Byte 1 = 0xFE

 

Example 2:

Byte 0 = 0x7F (Read 128 byte)

Byte 1 = 0x80