This post will describe the process for building and using the NXP Kinetis Bootloader version 2.0.0 with the MCUXpresso IDE and SDK. This guide assumes you are familiar with creating and running projects using MCUXpresso and have installed the SDK for your target processor. This procedure is tested and working with the MKV56F24.
Symbol | Value |
---|---|
__DATA_RAM | _data |
__DATA_ROM | _etext |
__START_BSS | _bss |
__END_BSS | _ebss |
__STACK_TOP | _vStackTop |
__VECTOR_RAM | __vectors_start__ |
__VECTOR_TABLE | __vectors_start__ |
If the processor is a Cortex M7 you should additionally define
Symbol | Value |
---|---|
CPU_IS_ARM_CORTEX_M7 | 1 |
Now that the source has been pruned we need to apply a few modifications to account for the new memory layout and linker files in MCUXpresso.
source/startup/crt0_gcc.S
@@ -43,10 +43,10 @@ .extern SystemInit .extern init_data_bss .extern main - .extern __StackTop + .extern _vStackTop .extern init_interrupts - .extern __isr_vector + .extern g_pfnVectors #define SCS_BASE (0xE000E000) /*!< System Control Space Base Address */ @@ -59,7 +59,7 @@ Reset_Handler: cpsid i // Set VTOR register in SCB first thing we do. - ldr r0,=__isr_vector + ldr r0,=g_pfnVectors ldr r1,=SCB_BASE str r0,[r1, #SCB_VTOR_OFFSET] @@ -77,7 +77,7 @@ Reset_Handler: mov r12,r7 // Initialize the stack pointer - ldr r0,=__StackTop + ldr r0,=_vStackTop mov r13,r0
source/startup/startup.c
@@ -97,10 +97,10 @@ void init_data_bss(void) #if defined(__GNUC__) extern uint32_t __DATA_ROM[]; extern uint32_t __DATA_RAM[]; - extern char __DATA_END[]; + extern uint32_t _edata[]; data_ram = (uint8_t *)__DATA_RAM; data_rom = (uint8_t *)__DATA_ROM; - data_rom_end = (uint8_t *)__DATA_END; // This is actually a RAM address in CodeWarrior + data_rom_end = (uint8_t *)(__DATA_ROM + (_edata - __DATA_RAM)); n = data_rom_end - data_rom; #elif(defined(__ICCARM__)) data_ram = __section_begin(".data");
source/property/src/property.c
@@ -75,14 +75,16 @@ extern uint32_t Image$$ARM_LIB_STACK$$ZI$$Limit[]; #define __ROM_START ((uint32_t)Image$$VECTOR_ROM$$Base) #define __ROM_END ((uint32_t)Image$$ER_m_text$$Limit) #elif(defined(__GNUC__)) // GCC -extern uint32_t __VECTOR_RAM[]; extern uint32_t __VECTOR_TABLE[]; -extern char __DATA_END[]; +extern uint32_t __DATA_ROM[]; +extern uint32_t __DATA_RAM[]; +extern uint32_t _edata[]; extern uint32_t __STACK_TOP[]; -#define __RAM_START ((uint32_t)__VECTOR_RAM) -#define __RAM_END ((uint32_t)__STACK_TOP - 1) +extern uint32_t __top_RAM[]; +#define __RAM_START ((uint32_t)__STACK_TOP - 1) +#define __RAM_END ((uint32_t)__top_RAM) #define __ROM_START ((uint32_t)__VECTOR_TABLE) -#define __ROM_END ((uint32_t)__DATA_END) +#define __ROM_END ((uint32_t)(__DATA_ROM + (_edata - __DATA_RAM))) #else #error Unknown toolchain! #endif // __ICCARM__
Now we need to add the processor specific configuration. Create/import the following files for your device according to section 10 of the MCU Bootloader Reference Manual:
Additionally, if you are using FlexCAN, you may need to define a "const flexcan_timing_config_t bit_rate_table[]" in source/bootloader/src/flexcan_peripheral_interface.c
I am using MCUXpresso 11.1.1 In step 2, I cannot see an option to include crc under drivers tab(where the others are).
Am I misunderstanding something?
Best regards,
Baldur
Hi,
Thanks for the procedure.
On my side, I use USB to communicate with bootloader.There are extra steps to get compiling sources.
I am working on it.
I currently get an elf but it is too big in size.
If someone has managed to get bootloader compiling with USB support, I'm interrested in the procedure.
Nicolas
As I said in my previous message, the executable is too big.
I tried to compile the bootloader (V2.0) for MK22F51212 with KDS 3.0. I also get a too big executable.
By too big, I mean it is more than 0xA000 bytes in size.
Bootloader seeks for application information at address 0xA000 so bootloader size has to be lower than 0xA000 bytes.
This is the case with bootloader version 1.2 I has using till now with KDS.
Any pointers on how to get a correct bootloader size ?
I finaly succeeded in reducing the executable size. I had to set "Optimise for size (-Os)" option in Properties/C/C++ Build/Settings/MCU C Compiler/Optimization/Optimization Level.