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

BUS FAULT happened, when try the ADC on nrf52832 board with adc_read_async in zephyr

Hello,

I'm not sure it is a good place to ask the this question here. I have also asked this at zephyr maillist, but till now no one can help me.

I've found that the NRF9160 SDK use the zephyr code, so maybe some guys could give me some advice.

I am trying to use ADC on nrf52832 with zephyr, when I call adc_read_async to start adc sampling on nrf52832 board, the hardware exception happened.
I have use the debuger to trace the fault, it happened after call adc_read_async function. But I can't get any more information about the fault by the debuger.

Here is the log:

***** Booting Zephyr OS zephyr-v1.14.0-1483-g0da2b2f804d6 *****
[10:47:33:951] ***** BUS FAULT *****
[10:47:33:951]   Precise data bus error
[10:47:33:955]   BFAR Address: 0x9af7eac2
[10:47:33:955] ***** Hardware exception *****
[10:47:33:959] Current thread ID = 0x200024b4
[10:47:33:965] Faulting instruction address = 0x20d9c
[10:47:33:965] Fatal fault in ISR! Spinning...

the following was my demo code:

zephyr config: 
CONFIG_ADC=y
CONFIG_ADC_ASYNC=y
CONFIG_ADC_0=y
CONFIG_ADC_NRFX_SAADC=y
CONFIG_ADC_CONFIGURABLE_INPUTS=y


------------------------------------------------------------------------------------

 
#define ADC_DEVICE_NAME        DT_ADC_0_NAME
#define ADC_RESOLUTION       10
#define ADC_GAIN               ADC_GAIN_1_6
#define ADC_REFERENCE       ADC_REF_INTERNAL
#define ADC_ACQUISITION_TIME      ADC_ACQ_TIME(ADC_ACQ_TIME_MICROSECONDS, 10)
#define ADC_1ST_CHANNEL_ID        0
#define ADC_1ST_CHANNEL_INPUT  NRF_SAADC_INPUT_AIN1
 
#define BUFFER_SIZE  6
static s16_t m_sample_buffer[BUFFER_SIZE];
 
static const struct adc_channel_cfg m_1st_channel_cfg = {
    .gain             = ADC_GAIN,
    .reference        = ADC_REFERENCE,
    .acquisition_time = ADC_ACQUISITION_TIME,
    .channel_id       = ADC_1ST_CHANNEL_ID,
#if defined(CONFIG_ADC_CONFIGURABLE_INPUTS)
    .input_positive   = ADC_1ST_CHANNEL_INPUT,
#endif
};
 
static struct k_poll_signal async_sig;
 
struct device *get_adc_device(void)
{
    return device_get_binding(ADC_DEVICE_NAME);
}
 
static struct device *init_adc(void)
{
    int ret;
 
    struct device *adc_dev = device_get_binding(ADC_DEVICE_NAME);
    if (adc_dev == NULL) {
        printk("Cannot get ADC device\r\n");
        return NULL;
    }
 
    ret = adc_channel_setup(adc_dev, &m_1st_channel_cfg);
    if (ret != 0) {
        printk("Setting up of the channel failed with code %d\r\n", ret);
        return NULL;
    }
 
    (void)memset(m_sample_buffer, 0, sizeof(m_sample_buffer));
    return adc_dev;
}
 
 
void main(void)
{
    int ret;
    struct device *adc_dev;
 
    struct k_poll_event async_evt = K_POLL_EVENT_INITIALIZER(K_POLL_TYPE_SIGNAL, K_POLL_MODE_NOTIFY_ONLY, &async_sig);
 
    const struct adc_sequence_options options = {
        .extra_samplings = 0,
        .interval_us  = 125,
    };
   
    const struct adc_sequence sequence = {
        .options     = &options,
        .channels    = BIT(ADC_1ST_CHANNEL_ID),
        .buffer      = m_sample_buffer,
        .buffer_size = sizeof(m_sample_buffer),
        .resolution  = ADC_RESOLUTION,
    };
 
    adc_dev = init_adc();
    if (adc_dev != NULL) {
        ret = adc_read_async(adc_dev, &sequence, &async_sig);    //the exception happened here.
        if (ret != 0) {
            printk("adc_read_async() failed with code %d", ret);
        }
        k_poll(&async_evt, 1, K_FOREVER);
     }
 
     printk("enter infinite loop ...\r\n");
 
     while(1) {
         k_sleep(MSEC_PER_SEC);
      }
}

Regards,
Jeremy
Parents Reply Children
No Data
Related