I am using nrf51822. Separately BLE and flash are working perfectly alright. But when I comment err_code = ble_advertising_start(BLE_ADV_MODE_FAST); this line flash is working alright. Vice versa when I comment flash_packet_transfer(arr,sizeof(arr)); this line BLE working fine. But simultaneously creating hardfault.
uint8_t arr[18] = {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17};
int main(void)
{
ble_stack_init();
gap_params_init();
services_init();
advertising_init();
conn_params_init();
err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
for(;;){
flash_packet_transfer(arr,sizeof(arr));
packet_num++;
nrf_delay_ms(5000);
NRF_LOG_FLUSH();
}
}
void flash_packet_transfer(uint8_t *data,uint8_t len)
{
uint32_t addr;
uint32_t pg_size;
uint32_t flash_write_word;
uint32_t pg_num;
uint32_t flash_addr;
uint32_t *ptr;
uint8_t buf_count;
uint8_t previous_date = 0;
uint8_t date_count =0;
data_buffer_t data_buf;
uint32_t flash_add_storage_location = 0x33800;
pg_size = NRF_FICR->CODEPAGESIZE;
addr = (FLASH_START_ADDR+ (packet_num * (len+2)));
flash_page_erase((uint32_t *)flash_add_storage_location);
flash_word_write((uint32_t *)flash_add_storage_location, addr);
if(addr % pg_size ==0){
flash_page_erase((uint32_t *)addr);
}
ptr = (uint32_t *)addr;
for(uint8_t i=0;i<len;i=i+4){
flash_write_word = ((data[i+3] << 24) | (data[i+2] << 16) | (data[i+1] << 8) | data[i]);
flash_word_write(ptr,flash_write_word);
ptr = ptr+1;
}
}