I use the UART Bootloader from the AN12218 example.
I'm using in my application a FreeRTOS. When I do implement only a blinking LED Task, it is working, also with the right frequency.
But it seems like, that no peripheral (UART, SPI, I2C, CAN) is acutally working. For example, when I try to send CAN messages out, when the application is loaded from the bootloader, my CAN device detects only errors.
So for me it seems like, I'm missing something here. Is there something else, that needs to be reset, when switching from the bootloader to the application? Or maybe is my linker file wrong?
The main problem is also, that I do not know how to debug this problem, becuase it only appears, when the application is loaded from the bootloader, when I only download the application (with start address 0x0 in linker file), than the program works perfectly fine.
I hope somebody has an idea.
Bootloader Linker file:
Application linker file:
I figured my problem out and also from the AN12218 Bootloader UART example.
First of all: The demoCode of the AN12218 does not return any error code if erasing sectors or programming sectors have generated errors. The error codes are generated by the flash drivers, but are not being passed to mem_man.c file or the comm.c file. With that you don't know if a write operation was successfull
Second problem: In order to write data to the flash memory of the S32Kx family, the flash adress must be 64-bit aligned. That means that the least three bits (2:0) must be zero. Unfortunately the S32 Design studio produces srec files which are not 64-bit aligned. To make a srec file 64-bit aligned some external tool needs to be used. It is described here: Aligning S19 Records to 64-bit Boundaries | MCU on Eclipse
My feature request for NXP is: Make an option in S32 design studio to produce 64-bit aligned srec files. Now everytime I have to use that external tool to make it 64-bit aligned, which is kind of annoying and it was really hard to find out that this caused the problem in the first place.
Thanks for your help.
Thank you for your comments. It will be useful for other customers.
Also, the Memory window in the S32DS can be useful to check the data in the memory.
Actually, the information about the 64-bit aligned address is placed under the "Table 36-40. Program Phrase Command FCCOB requirements" in the RM rev 9.
"The Flash address Must be 64-bit aligned (Flash address [2:0] = 000)"
The "My feature request for NXP" is rather for the IDE support. Probably stanish has more information.
This might be an issue with LSB bit...please check this thread:
I'd also suggest to disable interrupts before jumping to the application.
Thanks for the Feedback Stan.
Unfortunately I don't understand what I need to change regarding to the LSB bit problem. For me it seems also, that this thread has been unresolved or I don't see the answer.
Regarding the interrupts: How do I disable them all with one command?
Please ignore my suggestion regarding LSB bit ... I haven't test instruction that moves address to PC. I typically saw branching into application e.g. https://community.nxp.com/thread/451750#comment-908810
Anyway, I'd strongly recommend you to get the MCU into state as close as possible to the after reset values.
I'd focus on peripherals used by bootloader that generate interrupts -> de-initilaize these modules so they cannot invoke an interrupt when the global interrupts are enabled.
Such pending interrupts could execute interrupt handlers that are not used by the application so the execution can ends up in the default interrupt handler or in a fault exception.
If you 'd like to debug both application and bootloader together please check this document:
This will help you to debug the issue.
Hope it helps.
I was able to debug it deeper. Now I think I found the problem:
The bootloader did not write the complete application to the flash.
The bootloader is unable to write data bytes to the flash memory if the adress is greater than 0x13F80.
The FlashProgram function in fsl_flash_driver_c90tfs.c returns always FTFx_ERR_ACCERR for flash adresses greater than 0x13F80... The only thing I found out so far, that the flash Config was made for the S32K148 since the AN12218 project was originally a s32k148 project.
Is this the problem? How can I solve it?
This is the current flash configuration:
I also tried to change, so it will more suit the s32k144, but with no success (I reduced the pflashSize to
Does these values matter or is it something else?
Is the memory above 0x13F80 somehow locked?
Thanks for helping
The Linker files seem to be correct.
Could you please try to create a simple interrupt application as your user application and loaded it by the bootloader?
(for a check that issue is not because of interrupts).
Also, you can try to check the registers in S32DS using Attach feature.
This allows you to search the registry even after a reset.
I hope it helps you.
I tried the hello_interrupts example and it is working correctly.
I also tried the FlexCAN example and it does also work.
Next thing to figure out: Why does it not work within my freertos, when loaded from the bootloader...
Did you try to look at your register settings by Attach feature in S32DS after the jump?
The interrupts can be disabled by this code: __asm("cpsid i");