cancel
Showing results for 
Search instead for 
Did you mean: 

Could someone please carefully explain or show a Write Memory Command example (using USART)? (Ref. AN3155, pages 18 - 21) The main confusion is what to send after 'Byte 8' , below I try to show an example of writing 0x42424242 to 0x200001a0 (in RAM).

SKitt
Associate II

Sent: 0x7F // Test Pattern

Received: 0x79 // ACK

Sent byte 1: 0x31    // WRITE command

Sent byte 2: 0xCE // WRITE command complement

Received:   0x79 // ACK   

Sent byte 3: 0x20   // Destination address MSB

Sent byte 4: 0x00

Sent byte 5: 0x01

Sent byte 6: 0xA0    // Destination address LSB

Sent byte 7: 0x24 // Checksum = 0x20 ^ 0x00 ^ 0x01 ^ 0xa0 = 0x81

Received: 0x79 // ACK

Sent byte 8: 0x04 // N = 4 (number of bytes to send)

Sent 0x42 // This is where I start to get confused

Sent 0x42

Sent 0x42

Sent 0x42

Sent 0x04 // Checksum = 0x04 ^ 0x42 ^ 0x42 ^ 0x42 ^ 0x42 = 0x04

Received: 0x1F // NACK

Also tried with N=5 (with Checksum= 0x05), because AN3155 confusingly shows 'N+1' , with same results.

Please, please, please do not oversimplify your answer and thank you for reading my question.

7 REPLIES 7
TDK
Guru

Byte 8 is the number of bytes to send minus one. So sending a 3 means you need to send 4 data bytes. So

(Byte 8) send 3

send 4 data bytes

send checksum

wait for ack

Yes, the AN is misleading and could be written better on this point.

Note that you must write a multiple of 4 bytes

If you feel a post has answered your question, please click "Accept as Solution".
SKitt
Associate II

Thank you for your reply, TDK.

I have modified the code, but the result is the same:

Sent byte 8: 0x03   // N = 3 (number of bytes to send)

Sent 0x42       // This is where I start to get confused

Sent 0x42

Sent 0x42

Sent 0x42

Sent 0x03       // Checksum = 0x03 ^ 0x42 ^ 0x42 ^ 0x42 ^ 0x42 = 0x03

Received:   0x1F   // NACK

The data 0x42424242 is divided into sending 0x42 four times; so, that complies with the "multiple of 4 bytes" note in AN3155 - right?

Any other thoughts on how to do this?

It looks like you’re writing to RAM, not FLASH. Isnt 0x200001A0 in ram? Doesn't flash start at 0x08000000?

edit: apparently this should work for both flash and ram. Im not sure. I can look at my code in a day and let you know if I see anything off.

If you feel a post has answered your question, please click "Accept as Solution".
SKitt
Associate II

Yes, that is correct. This example is for RAM but the Write Memory Command should work with any memory region with user privileges.

SKitt
Associate II

For verification purposes, I modified the destination address to 0x08001020 (a null spot in Flash) and had the exact same result as with the RAM region. Thank you for your correspondence.

EDIT: Sorry. I failed to note a compilation error before uploading the code. After fixing that and retrying, the writing to this Flash address and region works. =)

In other words, now 0x08001020 = 42424242.

What part?

Write deeper into RAM, the system loader might expect to be using some of it.

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

Yes, that is correct. In accordance with the 'Note' on pg 18/38 of AN3155: "When writing to the RAM, user must not overlap the first RAM used by the bootloader

firmware."

I re-modified the destination address for a higher address in RAM and now it works: 0x20001020 = 42424242

Thank you both for helping me through this stone wall.

Points to TDK for helping me modify the 4 to a 3 ( N-1). [Note for ST: please correct this in the AN3155]

Points to Clive Two.Zero for reminding me of the Note on pg 18/35.