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

nRF52832 flash write problem.

Hi, I have a problem when write data to flash on nRF52832. my code is like below:



err_code = nrf_drv_clock_init();
APP_ERROR_CHECK(err_code);

// Activate deep sleep mode.
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
fds_init();
ble_stack_init();
timers_init();
gap_params_init();
gatt_init();
services_init();
advertising_init();
conn_params_init();
peer_manager_init();

while(1)
{
DPRINTF(LOG_INFO, "test_task\r\n");
DPRINTF(LOG_INFO, "erase\r\n");
nrf_fstorage_erase(&m_fs,0x0007F000,4*1024,NULL);
delay_ms(1000);
DPRINTF(LOG_INFO, "read\r\n");
memcpy(&s_dfu_settings,m_dfu_settings_buffer,4*1024);
delay_ms(1000);
DPRINTF(LOG_INFO, "s_dfu_settings.bank_1.bank_code = %d \r\n",s_dfu_settings.bank_1.bank_code);
DPRINTF(LOG_INFO, "write\r\n");
s_dfu_settings.bank_1.bank_code = 3;
memcpy(s,&s_dfu_settings,4*1024);
delay_ms(1000);
nrf_fstorage_write(&m_fs,0x0007F000,s,4*1024,NULL);
delay_ms(1000);
DPRINTF(LOG_INFO, "read again\r\n");
memcpy(&s_dfu_settings,m_dfu_settings_buffer,4*1024);
delay_ms(1000);
DPRINTF(LOG_INFO, "s_dfu_settings.bank_1.bank_code = %d \r\n",s_dfu_settings.bank_1.bank_code);
}

The document says if SD present,use the fstorage_sd. But when run above, it will freeze at nrf_fstorage_erase, without any other fault. So whether my api use correct or not?

Parents
  • If you look at nrf_fstorage_erase(...) in the infocenter and the explantion for the argument len, it says the following: "Number of pages to erase.". Thus you have to input the number of pages, not the size in bytes.

    A single page in the nRF52832 is of size 4096 bytes (=0x1000 bytes), and setting the len input to 1 instead, will erase 4*1024 bytes.

    Best regards, Simon.

  • Thank for attention. Accturally, I am developing nrf52832 with freertos, and I found the api of flash must be used the fstorge_sd type when softdevice is present. But I want to use nvmc type. So I must stop ble stack with the sd_adv_stop first. When I ereaser or write flash in a task, it will lead to a hardfault. Finally, I change the priority of configMAX_SYSCALL_INTERRUPT_PRIORITY to APP_LOWEST, and it worked. So I wonder if there is some handle in sd_adv_stop could lead to hardfault when I make the interrupt was controlled by RTOS?

    Best regards, Nero

  • configMAX_SYSCALL_INTERRUPT_PRIORITY needs to be lower in priority than the SVC priority which is set to 4 in nRF52 devices. If you set the priority  of configMAX_SYSCALL_INTERRUPT_PRIORITY  higher than SVC call then any sd_xxx call that converts to SVC call will hardfault.

Reply Children
Related