Hi everybody,
I think have a problem which involve writing on the external memory of the nrf52840, what I want is when I receive data from the NUS service I want to store it on the external memory.
But I encountered an issus with the reading I always read 0 as if I didn't write on the memory and I had a problem before too which involve WAIT_FOR_PERIPH() from the QSPI example that cause infinite loop on the write I fixed it by replacing it with a nrf_delay_ms().
// This is my function which I have a problem
void nus_data_handler(ble_nus_evt_t * p_evt)
{
if (p_evt->type == BLE_NUS_EVT_RX_DATA)
{
uint32_t err_code;
uint8_t strRev;
uint32_t i;
NRF_LOG_INFO("Received data from BLE NUS. Writing data on UART.");
NRF_LOG_HEXDUMP_INFO(p_evt->params.rx_data.p_data, p_evt->params.rx_data.length);
for(int i=0; i<p_evt->params.rx_data.length; i++)
{
NRF_LOG_INFO("%d",p_evt->params.rx_data.p_data[i]);
}
NRF_LOG_INFO("Data lenght is : %d",p_evt->params.rx_data.length);
NRF_LOG_FLUSH();
for(i=0;i<p_evt->params.rx_data.length;i++)
{
m_buffer_tx[i] = p_evt->params.rx_data.p_data[i];
}
m_finished = false;
err_code = nrf_drv_qspi_write(m_buffer_tx, p_evt->params.rx_data.length, 0);
APP_ERROR_CHECK(err_code);
NRF_LOG_HEXDUMP_INFO(m_buffer_tx,p_evt->params.rx_data.length);
// WAIT_FOR_PERIPH();
nrf_delay_ms(1000);
NRF_LOG_INFO("Process of writing data start");
NRF_LOG_FLUSH();
err_code = nrf_drv_qspi_read(m_buffer_rx, p_evt->params.rx_data.length, 0);
// WAIT_FOR_PERIPH();
nrf_delay_ms(1000);
NRF_LOG_INFO("Data read");
NRF_LOG_INFO("Compare...");
NRF_LOG_FLUSH();
if (memcmp(m_buffer_tx, m_buffer_rx, p_evt->params.rx_data.length) == 0)
{
NRF_LOG_INFO("Data consistent");
NRF_LOG_FLUSH();
}
else
{
NRF_LOG_INFO("Data inconsistent");
NRF_LOG_HEXDUMP_INFO(m_buffer_rx,p_evt->params.rx_data.length);
NRF_LOG_FLUSH();
}
nrf_delay_ms(1000);
err_code = nrf_drv_qspi_erase(NRF_QSPI_ERASE_LEN_64KB, 0);
APP_ERROR_CHECK(err_code);
// WAIT_FOR_PERIPH();
nrf_delay_ms(1000);
NRF_LOG_INFO("Process of erasing first block start");
// nrf_drv_qspi_uninit();
for (uint32_t i = 0; i < p_evt->params.rx_data.length; i++)
{
do
{
err_code = app_uart_put(p_evt->params.rx_data.p_data[i]);
if ((err_code != NRF_SUCCESS) && (err_code != NRF_ERROR_BUSY))
{
NRF_LOG_ERROR("Failed receiving NUS message. Error 0x%x. ", err_code);
APP_ERROR_CHECK(err_code);
}
} while (err_code == NRF_ERROR_BUSY);
}
if (p_evt->params.rx_data.p_data[p_evt->params.rx_data.length - 1] == '\r')
{
while (app_uart_put('\n') == NRF_ERROR_BUSY);
}
}
} // This is how i initialize my qspi in my main function
nrf_drv_qspi_config_t config = NRF_DRV_QSPI_DEFAULT_CONFIG;
err_code = nrf_drv_qspi_init(&config, qspi_handler, NULL);
APP_ERROR_CHECK(err_code);
NRF_LOG_INFO("QSPI example started.");
configure_memory();
m_finished = false;
err_code = nrf_drv_qspi_erase(NRF_QSPI_ERASE_LEN_64KB, 0);
APP_ERROR_CHECK(err_code);
WAIT_FOR_PERIPH();
NRF_LOG_INFO("Process of erasing first block start");
Thanks for the help !