How to check if whole program is flashed on ARM?

0

I'm using arm-none-eabi-gcc 5.3 to produce binaries for STM32L4. I'm using bootloader to flash program. Problem is I can't be sure if I'm flashing whole file. I don't have any CRC available. Flash starts on 0x80000000 and 0x80040000 (2 banks for bootloader and main program). Currently I assuming If 0x80040004 is between 0x80040000 and 0x80080000, program is flashed. But how can I check if program is valid? I can't find where is size of binary that should be written on flash, so I can check last few integers.

Here is first few bytes from BIN (sorry, can't post whole file): enter image description here Last byte that is not programmed is 0x80051C00 (program has 72704 bytes).

c
flash
arm
embedded
asked on Stack Overflow Nov 23, 2017 by Razi91 • edited Nov 23, 2017 by Clifford

1 Answer

1

The most likely error is loss of data connection during the transfer so that the image is only partially written. The chances of programming error once the data is received is probably negligible, although your transfer protocol should include some sort of data integrity check. For that you could simply validate the checksum of hex-file records or use a protocol with CRC error checking such as XMODEM-CRC or XMODEM-1K.

Ensuring that you do not attempt to start a partially loaded application image is simple. It is not necessary to program the flash in address order or even the order the data arrives in. Given that, when the data for the reset-vector at 0x80040004 is received, you retain it in RAM and program it last. That way the reset vector value will always be 0xFFFFFFFF if the programming did not complete:

Pseudo-code:

WHILE receiving data

    IF program_address in range
        // Write all data except address at reset vector
        IF program_address == 0x80040004
            start_address = program_data
        ELSE
            write( program_address, program_data )
        ENDIF
    ENDIF
ENDWHILE

// Write reset vector *LAST*
write( 0x80040004, start_address )

Then in the start-up code:

IF @0x80040004 == 0xFFFFFFFFFF
    NO APPLICATION - DO SOMETHING!
ELSE
    START APPLICATION
ENDIF
answered on Stack Overflow Nov 23, 2017 by Clifford • edited Nov 23, 2017 by Clifford

User contributions licensed under CC BY-SA 3.0