This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Custom SPI Bootloader (from Flash)

Hello.

I want to develop a custom bootloader with the same purpose as described in Very simple SPI bootloader

I'm using a 52832 with Eclipse/GCC and nRF SDK V13.0

As basis i was using the secure BLE dfu example. The example itself is working fine. I just obtained that the nRF Connect App does not recognise the reboot into the application properly after the DFU is executed. As a next step i was duplicating the source of nrf_serial_dfu (replacing the uart interface with flash memory access is easy here i think) and registering it instead of the nrf_ble_dfu.

But it seems that my SPI is not working (nrf_drv_spim). Next to the Flash there is also a CAN Controller connected to the SPI for reporting the update process to some external micro. Both libraries (Flash and CAN, written on my own) work flawless in the application and can store the firmware from CAN into flash. Not so in the bootloader. Even sending a CAN message in the main does not work. What could i miss? Is LFCLK mandatory? I don't think so, because the CAN even does not write messages if they are called from ble_dfu_transport_init, where the LFCLK is initialized in the ble_stack_init before. Another problem is that i'm actually not able to debug the bootloader. I'm using the debug linker file, the bootloader start address is adjusted but as i set optimization level to 0 in the makefile the linker returns an error in the nrf_bootloader_app_start_asm.

Can anybody help?

  • I get the feeling (no, i still can't compile a debug compatible firmware), that the problem is related to the spi. I can initialize an spi interface but working with it is not possible. May it be related to the Easy DMA?

    A typical read from flash looks like this (m_spi_xfer_done is set by the dma callback when transfer was executed):

    if (pin_cs > 0){Flash_AT25_select();}
    flash_spi->m_spi_xfer_done = false;
    err_code = nrf_drv_spi_transfer(&flash_spi->m_spi_instance,&m_tx_buf,4,&m_rx_buf,length_bytes+4);
    while (!flash_spi->m_spi_xfer_done)
    {
    	//Prevent Low Power State
    	__WFE();
    }
    if (pin_cs > 0){Flash_AT25_unselect();}
    

    So, first question: I read now about the interrupt forwarding of the mbr. how does it work? Do i need the forwarding here? I have a softdevice flashed (S132 V4.0.2), but want to leave it disabled if possible in the bootloader.

  • Hi,

    The next step would be to be able to debug the bootloader. When compiling with optimization level to 0, you will need to allocate more flash space for the bootloader in the .ld file.

    You will also need to add -fomit-frame-pointer to the compiler flags for it to compile correctly.

Related