Hello,
We have a head-scratching issue
For the sake of brevity, please assume in the following that the definition of "it works" is "the bootloader manages to jump into the app, which then runs and enumerates on USB".
Development setup:
We have a custom device based on the nRF52820, SDK 17.1.0, no softdevice, gcc toolchain.
Our build system is based on CMake, since it integrates well with the CLion IDE we use. The cmake files are a fork of Polidea's. Here is the fork we use (master branch).
We flash the MBR, Bootloader and application with bootloader settings page.
The linker files we use are part of our cmake fork above, here is the folder.
The bootloader uses this ldfile for the debug build and this ldfile for the release build.
The application uses this ldfile when flashed together with the debug BL, or this ldfile when flashed together with the release BL.
Both the application and bootloader use USB CDC ACM as interface for a custom protocol (the app) and the DFU protocol (the bootloader).
The application is based on FreeRTOS (we had to make a minor modification to the port files, since the context switching code assumes the presence of an FPU, which the 820 does NOT have)
The bootloader is essentially the Secure Bootloader with minor modifications for our custom board and integration into our CMake build.
The issue we observe is that the debug BL works whether the app is built for release OR debug.
The release BL only enumerates if no application is flashed, or an application is flashed but without bl_settings.
If an app with valid settings page is present, the app won't start and the USB won't enumerate.
The lack of USB enumeration seems to point to the fact that the BL is not simply refusing to boot the app (otherwise the bootloader would enumerate as USB device and it would loop, waiting for a DFU to start), but rather that either it tries to jump into the app, which then dies, or simply writing an app to the flash corrupts something.
In fact, attaching the debugger (to the release BL, with an app+bootloader settings flashed) is interesting: the bootloader reaches correctly app_start()
, sets MSP and jumps to the app. Stepping after that finds the CPU looping forever at address 0x14ee
, the application HardFault
handler.
The same debugging steps, done on the debug build of the BL, show that the bootloader reaches correctly app_start()
, and then jumps in the app, which goes on executing normally.
My guess is that there is something wrong with either the linker files, or some gcc argument that differs between the Release and the Debug build, however I can't find anything that is obviously wrong with that.