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

nrf52 spi not working when bootloader flashed

I'm tying to read and write external memory using Spi bus

when I flash only the softdevice and the app, the program works fine

but when I flash the bootloader, the program hang (does't get out of the loop below).

it's really a matter of bootloader flashing, I always replicate the behavior :

  • without bootloader it's working (not blocking at while (read_status_register(&spi) & 0x01) {}; )

  • with bootloader it's blocking

I have no issue with SPI configurations, it works well without bootloader

with the bootloader I flashed, the DFU works fine anyway

How does the running sequence work when bootloader present?

Can the bootloader configure some IO even when the app is running

the program freeze exaclty when calling nrf_drv_spi_transfer . the PINS used for SPI are P19, P20 P21 P22. once nrf_drv_spi_transfer is called the device is no longer detected. I had to call nrfjprog --recover to reflash it again

  • @HungBui without the bootloader it doest stuck, but with the bootloader it stuck there forever,

  • I know, but what we need to do is to debug and know where exactly it stuck, and why, simply say "stuck" won't help.

  • Hi Makouda,

    I'm having a look at the code now. I can see that you never check for error code return from any call with the SPI driver, why ? You should always check it .

    It's not easy to debug here as I don't have the same external flash as yours to test. I used a dummy SPI slave instead.

    What I can see is that the SPI worked the same with or without the bootloader. I can see you write 255 byte with most of them are 0xFF, and then try to read the status with 0x05 0xCC . Same behaviour with or without bootloader.

    So as you described, you can never get through the while (read_status_register(&spi) & 0x01) {}; you would need to check why the slave doesn't return the status code you expected. Which status code it returns ? I would suggest to hook a logic analyzer to see what happened on the SPI lines.

    You would need to narrow down what could be the different when your application run after the bootloader, and without the bootloader. I assume the error persist even if you reset the board. At least I can see SPI works fine.

  • @makouda: Could you also step into nrf_drv_spi_transfer ? And check which exactly line of code return value 3 ? You may need to add debug trace (UART/RTT) if the error only comes occasionally

  • Hi @HungBui I think I have another issue, when I omitted waiting for

    while (read_status_register(&spi) & 0x01) {}; 
    

    and trying to write to flash and Bootloader present I can no longer detect the nrf52 with segger I tried with other cards and I always have the same problem : I can no longer detect it to flash it using nrfgostudio. how can this be possible? is the Bootloader affecting the segger pins??. it's stange because I dont have access to SWDIO and SWDCLK. does the Bootloader somewhere affect SWDIO and SWDCLK

Related