Hi,
I've been trying to read/write data from/to the internal flash storage of my nRF52 development board.
I am using SDK11 and softdevice s132
I have modified the flashwrite main function as follows-
int main(void) { uint32_t * addr; uint8_t patwr; uint8_t patrd; uint8_t patold; uint32_t i; uint32_t pg_size; uint32_t pg_num; LEDS_CONFIGURE(BSP_LED_0_MASK); LEDS_CONFIGURE(BSP_LED_1_MASK); LEDS_OFF(BSP_LED_0_MASK); LEDS_OFF(BSP_LED_1_MASK); pg_size = NRF_FICR->CODEPAGESIZE; pg_num = NRF_FICR->CODESIZE - 1; // Use last page in flash // Start address: addr = (uint32_t *)(pg_size * pg_num); // Erase page: flash_page_erase(addr); patwr=0x45; flash_word_write(addr, (uint32_t)patwr); //patrd = (uint8_t)*(addr); //gave same result as memcpy memcpy(&patrd,addr,1); uint8_t flag=4; if(patrd==0x45){ flag=1; LEDS_ON(BSP_LED_0_MASK); } else{ flag=0; LEDS_ON(BSP_LED_1_MASK); } }
It initially showed the LED1 (else case) to evaluated.
When i followed execution using debug, it resulted in the correct LED (LED0) being turned on but when it reaches the end of the main loop it goes into "Systeminit()" and returns to main. On this 2nd execution, write action did not occur and hence LED1 got triggered. I don't know the reason for this or if I should be bothered about it.
I actually intend for this operation to be performed on a central+peripheral BLE device but when i tried using the page erase+write parts of the above snippet, it caused a runtime error which i could not identify with keil.
For clarification, I have this flash write operation set to occur when the "Disconnect event" occurs and after advertising and scanning have been stopped.It occurs before scan/advertising are restarted. I observed with debug that when flash code is included after sd_ble_gap_adv_stop(); it undergoes the runtime error in this function and when the flash code is absent there is no error thrown at this point.
Any solution for this would be appreciated.
Thank you