This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Nrf51422 how to use sd_flash_page_erase, sd_flash_write in SD210

Hi, Now I use these fun in ANT SD210 like below:

void MyFlashWrite(ble_ant_csc_t* cscdata) { uint32_t addr; uint32_t patwr[3]; uint32_t pg_size; uint32_t pg_num; patwr[0]=111;//cscdata->cadence_revolution_cnt_tmp; patwr[1]=222; patwr[2]=333;

  pg_size = NRF_FICR->CODEPAGESIZE;
pg_num  = NRF_FICR->CODESIZE - 1;  // Use last page in flash

addr = (pg_size * pg_num);// Start address
  printf("Write Addr: 0x%X \r\n",addr);
sd_flash_page_erase(addr);// Erase page
  sd_flash_write	(	&addr, patwr, 3 );	

}

void MyFlashRead(ble_ant_csc_t* cscdata) { uint32_t *addr; uint32_t pg_data; uint32_t pg_size; uint32_t pg_num;

  pg_size = NRF_FICR->CODEPAGESIZE;
pg_num  = NRF_FICR->CODESIZE - 1;  // Use last page in flash
  printf("pg_size: 0x%X, pg_num: 0x%X\r\n",pg_size,pg_num);

addr = (uint32_t *)(pg_size * pg_num);// Start address
  printf("Read Addr: 0x%X \r\n",addr);
  flash_word_read(addr, &pg_data);
  printf("pg_data: %d \r\n",pg_data);

}

But the data read back always be 0, so I dont know where is the problem. and I dont find any answer in other question, so Does anyone can tell me how to use flash read/write in Ant SD210.

Thanks

  • Since ANT use the same mechanism as BLE for flash writes while protocol activity, it should work the same way.

    After you do a flash write or read, you should get a system event which are defined in nrf_soc.h

      NRF_EVT_FLASH_OPERATION_SUCCESS,              /**< Event indicating that the ongoing flash operation has completed successfully. */
      NRF_EVT_FLASH_OPERATION_ERROR,                /**< Event indicating that the ongoing flash operation has timed out with an error. */
    

    So you should first check if the flash operation is successful or not

    I am not an expert in ANT, but i know that it is the same mechanism there, so do not use the code directly, i just used it to explain the concept.

  • Hi, I dont see the on_sys_evt in ANT->bsc_tx->cadence example. and the flash does not have read fun, I just saw the fun in nRF51 Series > SoftDevices > S210 SoftDevice > S210 SoftDevice API > S210 SoftDevice v5.0.0 > API Reference > SoC Library API There are

    1.uint32_t sd_flash_page_erase	(uint32_t 	page_number)
    2.uint32_t sd_flash_protect	(uint32_t 	protenset0, uint32_t 	protenset1 )
    3.uint32_t sd_flash_write	(uint32_t *const 	p_dst, uint32_t const *const 	p_src, uint32_t 	size)
    

    that's all.

    So does any one of your company can tell me where has a document or example. Because I just 3 words need save before MCU into sleep.

    Thanks.

  • like i said, i am not expert in ANT, the function names might be different in ANT. If you want to look at an example try nRF5_SDK_11.0.0-2.alpha_bc3f6a0\examples\dfu\experimental_ant_bootloader. It shows you for example how to use sd_flash_page_erase.

Related