We are using nrf51822 for products of our company. We use mbed + nRF51822 driver + BLE_API for the BLE peripheral devices. The softdevice is s130 ver 1.0.0.
I create an application with the linkscript as below, the secured BLE works fine.
MEMORY
{
FLASH (rx) : ORIGIN = 0x0001C000, LENGTH = 0x24000
RAM (rwx) : ORIGIN = 0x20002800, LENGTH = 0x5800
}
Currently I have a use case that boot this application with a short boot code. I create the boot code as below:
#define APPLICATION_ADDRESS 0x00023800
typedef void (*pFunction)(void);
pFunction JumpToApplication;
uint32_t JumpAddress;
void main()
{
/* Jump to user application */
JumpAddress = *(__IO uint32_t*) (APPLICATION_ADDRESS + 4);
JumpToApplication = (pFunction) JumpAddress;
/* Initialize user application's Stack Pointer */
__set_MSP(*(__IO uint32_t*) APPLICATION_ADDRESS);
JumpToApplication();
}
The linkscript for the boot code is:
MEMORY
{
FLASH (rx) : ORIGIN = 0x0001C000, LENGTH = 0x7800
RAM (rwx) : ORIGIN = 0x20002800, LENGTH = 0x5800
}
And change the linkscript for the application as below:
MEMORY
{
FLASH (rx) : ORIGIN = 0x00023800, LENGTH = 0x1C800
RAM (rwx) : ORIGIN = 0x20002800, LENGTH = 0x5800
}
This means that I put the boot code at 0x0001C000, the application at 0x00023800. Then the after startup the nrf51822 will jump from softdevice code to the bootcode, and then jump to the application code.
I found the application can be executed correctly, but after calling initializeSecurity() the cpu gets stuck. After debugging I found the problem happened after calling sd_flash_page_erase() in pstorage_init(). But the return value for sd_flash_page_erase() is NRF_SUCCESS.
I tried to replace sd_flash_page_erase() with ble_flash_page_erase(), the problem is gone. And this problem doesn't exist when start the same application without this boot code (start the application by softdevice directly at 0x0001C000).
Could you please help on resolving this problem?