AnsweredAssumed Answered

Peripheral in Master Mode (SPI)

Question asked by Marc Ohlmann on Dec 13, 2016
Latest reply on Dec 15, 2016 by Fan Yang

I have managed to get the freedom_bootloader (from Kinetis Bootloader v2.0)  code sample working on an MK22FN512xxx12 microcontroller on a custom board. I used the provided KinetisFlashTool to upload the led_demo_a000 and successfully booted into it, I have also managed to do the same with my own project code. 


For my project, I have an external chip with its own memory space (AT25 Flash). On the AT25 Flash, I will have a flag that notifies the bootloader that an update is ready to be made. The bootloader will then read from a specific address in the AT25 flash which contains the updated firmware that needs to be written to the MK22F512 flash. However, as specified in the documentation, SPI is only supported in slave mode, so I need to modify the bootloader to use SPI in master mode.


At the moment I have the SPI disabled according to the bootloader. I have injected some routines of my own inside bootloader_init() that configure the SPI to run in master mode. I am able to communicate with the AT25 and read from it, but I cannot seem to find out how to approach writing to the MK22F512 flash.


I don't have a full understanding about how the bootloader works, but I was hoping to find a way to modify the SPI peripheral to initialize as a master. The modified peripheral would then notify the bootloader that the SPI peripheral is active, and start the data transfer + flash program routines. If I cannot do that then I need to just manually write to the flash from bootloader_init() and let the rest of the bootloader run with a dummy peripheral so that it just leads to a timeout. 


The problem is I don't understand is how to get the data transfer + flash program routines to start. I also don't know how to manually write to the MK22F512 flash. I tried using the commands provided by fsl_flash, but I keep running into error status codes and hard faults.


I will appreciate any insights, alternate approaches, or anything that can help me get this working. I have looked through all the documentation I could find on the bootloader and searched for related questions here, but I am still at a loss.