2019-09-28 05:21 PM
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.
2019-09-28 05:30 PM
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
2019-09-28 05:53 PM
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?
2019-09-28 06:00 PM
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.
2019-09-28 06:05 PM
Yes, that is correct. This example is for RAM but the Write Memory Command should work with any memory region with user privileges.
2019-09-28 06:21 PM
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.
2019-09-28 06:26 PM
What part?
Write deeper into RAM, the system loader might expect to be using some of it.
2019-09-28 06:51 PM
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.