User Tools

Site Tools


manual:ports:armcm4_s32k14

ARM Cortex-M4 for S32K14x

Bootloader size

Due to the presence of the bootloader in the on-chip flash memory, the start address of the user program needs to be adjusted to make sure both programs do not overlap. Additionally, the bootloader's flash driver needs to be properly configured to prevent accidental erasure of the bootloader during firmware updates.

To reserve flash memory for the bootloader and protect it from being erased and/or reprogrammed during firmware updates, comment out lines in table flashLayout[] in source-file flash.c. Refer to the demo bootloader program for an example.

Adjusting the start address of the user program in flash to make sure it doesn't overlap with the bootloader, is achieved by changing the program's ROM start address in the linker descriptor file. Set it to the start address as present in the first line in table flashLayout[] that is not commented out. In the previous example, the first 8kb (0x00002000) are reserved for the bootloader. Therefore everything in the user program, including the vector table, needs to be moved forward 8kb:

Checksum location

A 32-bit checksum value is programmed by the bootloader at the end of a programming session. Upon startup, the bootloader verifies the correctness of this checksum to determine if a valid user program is present and can be started.

The bootloader programs this value at the end of the user program's vector table. Its exact location is configured by macro FLASH_VECTOR_TABLE_CS_OFFSET in flash.c. The vector table size can vary based on the microcontroller derivative you are using. Please verify that the default value of FLASH_VECTOR_TABLE_CS_OFFSET is correct. If not, you can simply override the value by adding the macro with the correct value to the blt_conf.h configuration header file.

The user program must reserve space for this 32-bit checksum value. With the default configuration of FLASH_VECTOR_TABLE_CS_OFFSET, the 32-bit checksum is located at vector number 254 in the vector table, since this one is unused anyways. All that needs to be done is writing a dummy placeholder value at this location. This reserves space for the checksum at memory address: flash base address + flash reserved for bootloader + FLASH_VECTOR_TABLE_CS_OFFSET. Refer to the demo program for an example.

Stackpointer initialization

On the ARM Cortex-M4 the first entry into the vector table holds the initialization value for the stackpointer, which is automatically loaded into the CPU's stackpointer register upon reset.

After reset, the bootloader gets started first and, if a valid user program is present, it is the bootloaders responsibility to start the user program. This unfortunately means that the automatic initialization of the CPU's stackpointer register does not work for the user program. The user program therefore needs to explicitly set the initial value of the CPU's stackpointer register in the reset interrupt service routine. Refer to the demo program for an example.

manual/ports/armcm4_s32k14.txt · Last modified: 2020/03/20 11:43 by voorburg