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

flashwrite operation causing "hard fault"

Hi,

I've been trying to read/write data from/to the internal flash storage after a ble disconnect event occurs on my nRF52 development board.

I am using SDK11 and softdevice s132

I am using the following test snippet for this operation-

case BLE_GAP_EVT_DISCONNECTED:
            err_code = bsp_indication_set(BSP_INDICATE_IDLE);
            APP_ERROR_CHECK(err_code);
            m_conn_handle = BLE_CONN_HANDLE_INVALID;
			sd_ble_gap_adv_stop();
			sd_ble_gap_scan_stop();
			NRF_UART0->TASKS_STOPTX = 1;
			NRF_UART0->TASKS_STOPRX = 1;
			NRF_UART0->ENABLE = 0;
					
			uint32_t * addr;
            uint8_t    patwr;
            uint8_t    patrd;

      
            uint32_t   pg_size;
            uint32_t   pg_num;

            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);
		    memcpy(&patrd,addr,1);
	        //patrd = (uint8_t)*(addr);
	    	uint8_t flag=4;
		    if(patrd==0x45){
		    	flag=1;
		    	LEDS_ON(BSP_LED_0_MASK);
	        }
		    else{
			    flag=0;
			    LEDS_ON(BSP_LED_1_MASK); 
			}
	    	
	    	err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
			APP_ERROR_CHECK(err_code);
		
			//Start scanning for peripherals which advertise. 
			scan_start();
            break;

This results in a kind of runtime error causing all LEDs to light up and freezing the device. I observed using debug mode that this occurs at sd_ble_gap_adv_stop(); when the flash code is present but does not occur when the flash code is absent. This is confusing because the flash part of the code appears after the sd_ble_gap_adv_stop(); and I'm assuming if the code is executed sequentially there shouldn't be any difference at that step.

Either way, I would appreciate any solutions for my problem.

Edit : The "hard fault" appeared when i was experimenting with sd_ble_gap_adv_stop(); by commenting it out, when it is present the debug call stack is just 0x000000 and it exhibits the freeze+LED conditions I mentioned above

Thank you

Parents Reply Children
No Data
Related