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

Write data to flash through fstorage in the bootloader example

Hi

Use SDK15.3 path .. \ .. \ examples \ dfu \ secure_bootloader \ pca10040_ble \ arm5_no_packs. Using fstorage to write flash data, the function nrf_fstorage_write returns NRF_SUCESS, but when I read the value in flash again, it is not written normally. Is this the reason? I have tried to achieve normal in the APP application, but the bootloader is not normal. Can you help me analyze the reason? Attached below is my code snippet and compressed package.

uint8_t write_boot_flag(void)
{
	ret_code_t err_code;
	uint32_t m_data = 0, x_data = 0;
	
	nrf_fstorage_api_t * p_fs_api;	

	p_fs_api = &nrf_fstorage_sd;

	err_code = nrf_fstorage_init(&fstorage, p_fs_api, NULL);
	APP_ERROR_CHECK(err_code);	

	err_code = nrf_fstorage_erase(&fstorage, 0x3e000, 4, NULL);
	APP_ERROR_CHECK(err_code);
	wait_for_flash_ready(&fstorage);
	
	m_data = 0x52465246;
    err_code = nrf_fstorage_write(&fstorage, 0x3e000, &m_data, sizeof(m_data), NULL);
    APP_ERROR_CHECK(err_code);
    wait_for_flash_ready(&fstorage);
	
    err_code = nrf_fstorage_read(&fstorage, 0x3e000, &x_data, sizeof(x_data));
    APP_ERROR_CHECK(err_code);
    wait_for_flash_ready(&fstorage);	
	
	if(x_data == 0x52465246)
	{
		bsp_board_led_on(BSP_BOARD_LED_2);
	}
	else if(x_data == 0xFFFFFFFF)
	{
		bsp_board_led_on(BSP_BOARD_LED_1);
	}	

	return NRF_SUCCESS;
}

dfu.zip

Parents Reply Children
No Data
Related