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) [AN3155] 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.