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

nrf51822 hangs after calling sd_flash_page_erase()

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?

Parents
  • When the SoftDevice is enabled you should use sd_flash_page_erase() and sd_flash_write() functions. Please see this Section in the S130 SoftDevice Specification for more information.

    A return of NRF_SUCCESS from sd_flash_page_erase() doesn't mean that the page is erased, it just means that the SoftDevice successfully received your call.

    If the flash operation is succesful you will get a NRF_EVT_FLASH_OPERATION_SUCCESS event in sys_evt_dispatch(). I recommend you to have a flag that is set you do a flash operation, and is unset when you get NRF_EVT_FLASH_OPERATION_SUCCESS. Check the flag before you do a flash operation.

  • I'm using the nRF51822 driver from nordic. The function sd_flash_page_erase() and sd_flash_write() are called in pstorage.c. The state mechine is controlled in pstorage.c. So I don't need to add additional flag to control flash operation in it. I also tried to just comment out sd_flash_page_erase(PSTORAGE_SWAP_ADDR / PSTORAGE_FLASH_PAGE_SIZE) in pstorage_init() and the problem was gone. So this problem should not caused by page is not erased successfully. Please notice that the application is fine before I change the flash address for it from 0x0001C000 to 0x00023800.

Reply
  • I'm using the nRF51822 driver from nordic. The function sd_flash_page_erase() and sd_flash_write() are called in pstorage.c. The state mechine is controlled in pstorage.c. So I don't need to add additional flag to control flash operation in it. I also tried to just comment out sd_flash_page_erase(PSTORAGE_SWAP_ADDR / PSTORAGE_FLASH_PAGE_SIZE) in pstorage_init() and the problem was gone. So this problem should not caused by page is not erased successfully. Please notice that the application is fine before I change the flash address for it from 0x0001C000 to 0x00023800.

Children
No Data
Related