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

Test PPI + ADC . But System error : SOFTDEVICE: INVALID MEMORY ACCESS

Hi All,

     I use SDK 15.2 to periodically trigger ADC acquisition tasks via PPI. But SOFTDEVICE: INVALID MEMORY ACCESS error occurred while the system is running.

I found an error that occurred when initializing the ADC and PPI configuration.

/************* saadc_init****************/

void saadc_init(void)
{
ret_code_t err_code;

err_code = nrf_drv_saadc_init(NULL, saadc_callback);
APP_ERROR_CHECK(err_code);

nrf_saadc_channel_config_t channel0_config = {
.resistor_p = NRF_SAADC_RESISTOR_DISABLED, \
.resistor_n = NRF_SAADC_RESISTOR_DISABLED, \
.gain = NRF_SAADC_GAIN1_4, \
.reference = NRF_SAADC_REFERENCE_INTERNAL, \
.acq_time = SAADC_CH_CONFIG_TACQ_40us, \
.mode = NRF_SAADC_MODE_SINGLE_ENDED, \
.burst = NRF_SAADC_BURST_DISABLED, \
.pin_p = (nrf_saadc_input_t)(NRF_SAADC_INPUT_AIN0), \
.pin_n = NRF_SAADC_INPUT_DISABLED \
} ;
err_code = nrf_drv_saadc_channel_init(0, &channel0_config);
APP_ERROR_CHECK(err_code);

nrf_saadc_channel_config_t channel4_config = {
.resistor_p = NRF_SAADC_RESISTOR_DISABLED, \
.resistor_n = NRF_SAADC_RESISTOR_DISABLED, \
.gain = NRF_SAADC_GAIN1_3, \
.reference = NRF_SAADC_REFERENCE_INTERNAL, \
.acq_time = NRF_SAADC_ACQTIME_40US, \
.mode = NRF_SAADC_MODE_SINGLE_ENDED, \
.burst = NRF_SAADC_BURST_DISABLED, \
.pin_p = (nrf_saadc_input_t)(NRF_SAADC_INPUT_AIN4), \
.pin_n = NRF_SAADC_INPUT_DISABLED \
} ;

/************The system can be operated after shielding***********/


err_code = nrf_drv_saadc_channel_init(4, &channel4_config);
APP_ERROR_CHECK(err_code);


err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool, SAMPLES_IN_BUFFER);
APP_ERROR_CHECK(err_code);

saadc_sampling_event_init();
saadc_sampling_event_enable();

// err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool[1], SAMPLES_IN_BUFFER);
// APP_ERROR_CHECK(err_code);

/***************************end**************************/

}

Attachment is my ADC configuration code.

So what is the cause of this? How can I solve this problem? Please help me, thank you!

ADC+PPI.zip

Parents
  • Hi,

    I expect the problem is that your p_event->data.done.p_buffer in your saadc_callback() function points to some address in the SoftDevice region, and therefore you get a NRF_FAULT_ID_APP_MEMACC error. The buffer is never set (as you have commented out the code where you initially call nrf_drv_saadc_buffer_convert with m_buffer_pool), so it points to somewhere random which happens to be within the RAM region used by the SoftDevice.

    (You always have to provide a pointer to the buffer when you call nrf_drv_saadc_buffer_convert(). This pointer is then copied to nrf_drv_saadc_evt_t::data.done.p_buffer which is why p_event->data.done.p_buffer can be used used in the SAADC example to reuse the same buffer for subsequent calls.)

  • Hi  Einar,

     Thanks for you replay!

      I have verified your thoughts, but this error still occurs.

      I initialized  nrf_drv_saadc_buffer_convert(m_buffer_pool, SAMPLES_IN_BUFFER); 

      And i defined : nrf_saadc_value_t     m_buffer_pool[SAMPLES_IN_BUFFER]; 

      So, can I expect you to give me a relevant test code? Thank you very much!

  • Hi,

    I do not spot any other issues in your code. I have combined the BLE Beacon example and SAADC peripheral example in this project to demonstrate how you can do it (ble_app_beacon_saadc_sdk_15.2.zip). Essentially there is no overlap whatsoever, but you need to make sure you don't use TIMER0 as that is used by the SoftDevice. ...Wait a minute.... While writing the last sentence i thought of checking that in your code and indeed, you use timer 0, and this will result in a NRF_FAULT_ID_APP_MEMACC in older SDKs. If you were using SDK 15.2 and build a debug version, you would instead get an assert in nrfx_timer.c (line 72 in SDK 15.2).

    As a side note you could have found earlier that this was a issue with TIMER0 by checking the info parameter in the error handler, as described in the NRF_FAULT_ID_APP_MEMACC API documentation and this post.

Reply
  • Hi,

    I do not spot any other issues in your code. I have combined the BLE Beacon example and SAADC peripheral example in this project to demonstrate how you can do it (ble_app_beacon_saadc_sdk_15.2.zip). Essentially there is no overlap whatsoever, but you need to make sure you don't use TIMER0 as that is used by the SoftDevice. ...Wait a minute.... While writing the last sentence i thought of checking that in your code and indeed, you use timer 0, and this will result in a NRF_FAULT_ID_APP_MEMACC in older SDKs. If you were using SDK 15.2 and build a debug version, you would instead get an assert in nrfx_timer.c (line 72 in SDK 15.2).

    As a side note you could have found earlier that this was a issue with TIMER0 by checking the info parameter in the error handler, as described in the NRF_FAULT_ID_APP_MEMACC API documentation and this post.

Children
Related