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

code lines ignored when moving from debug to release and vise versa

hello Nordic

i am using nrf52840, sdk 16.0 working on ther peripheral ble_blinky example, working with Segger IDE (ses)

i have lines of code missing when i am debugging after changing from release to debug and other lines missing when i move from debug to release, can you explain the logic or rules behind ?

also for some reson a code that works well in release mode while debugging, crashed when switching to debug mode 

it crashes in the channel init line :

ret_code_t err_code;
    //nrf_drv_saadc_config_t audio_saadc_config;
    nrf_saadc_channel_config_t audio_channel_config;

    nrf_gpio_cfg_output(ARDUINO_13_PIN); // FOR DEBUG

    //Configure SAADC
    audio_saadc_config.resolution = NRF_SAADC_RESOLUTION_14BIT;       //Set SAADC resolution to 12-bit. This will make the SAADC output values from 0 (when input voltage is 0V) to 2^12=2048 (when input voltage is 3.6V for channel gain setting of 1/6).
    audio_saadc_config.oversample = NRF_SAADC_OVERSAMPLE_DISABLED;    //DIABLED - //Set oversample to 4x. This will make the SAADC output a single averaged value when the SAMPLE task is triggered 4 times.
    audio_saadc_config.interrupt_priority = APP_IRQ_PRIORITY_LOW;     //Set SAADC interrupt to low priority.
    audio_saadc_config.low_power_mode = NRFX_SAADC_CONFIG_LP_MODE;
	
    //Configure SAADC channels:
    audio_channel_config.reference = NRF_SAADC_REFERENCE_VDD4;          //Set internal reference of fixed 0.6 volts
    audio_channel_config.gain = NRF_SAADC_GAIN1_4;                      //Set input gain to 1/6. The maximum SAADC input voltage is then 0.6V/(1/6)=3.6V. The single ended input range is then 0V-3.6V
    audio_channel_config.acq_time = NRF_SAADC_ACQTIME_10US;             //Set acquisition time. Set low acquisition time to enable maximum sampling frequency of 200kHz. Set high acquisition time to allow maximum source resistance up to 800 kohm, see the SAADC electrical specification in the PS. 
    audio_channel_config.mode = NRF_SAADC_MODE_SINGLE_ENDED;            //Set SAADC as single ended. This means it will only have the positive pin as input, and the negative pin is shorted to ground (0V) internally.
    audio_channel_config.resistor_p = NRF_SAADC_RESISTOR_DISABLED;      //Disable pullup resistor on the input pin
    audio_channel_config.resistor_n = NRF_SAADC_RESISTOR_DISABLED;        
    audio_channel_config.burst = NRF_SAADC_BURST_ENABLED;   

//    err_code = nrf_drv_saadc_init(&audio_saadc_config, audio_saadc_callback);
//    APP_ERROR_CHECK(err_code);

    audio_channel_config.pin_p = AUDIO_PIEZO_ADC_INPUT_PIN; 
    err_code = nrf_drv_saadc_channel_init(0, &audio_channel_config);
    APP_ERROR_CHECK(err_code);

hope to read from you soon

best regards

Ziv

Parents Reply Children
  • hi

    when in release it ignores some lines that i put for debug purposes, i guess it does some efficiency improvement by its own.

    more importantly right now is the second question, regarding the failing of the channel init cause of the assertions in debug mode which prevent me from returning to develop in debug mode (see my previous message for the code)

    hope to read from you soon 

    best regards

    Ziv

  • Maybe you could add some additional information here?

    Upload the entire code and maybe debug your application, adding some information about where the assert happens.

    Br,
    Joakim

  • hi Joakim

    well the main issue when going from release back to debug mode while debugging, i guess its the assertions that are ignored when working in release mode of debugging.

    my issue is that i am trying to implement 2 saadc (one on 3 channels with no over sampling and sampling that continues until saadc is stopped (by saadc_uninit)  another with one channel and oversampling and sample should start only when i call for it)

    currently i fail in this assertion when trying to init the channel

    my code goes like this (which is changed from release because of other assertions in the channels initiation)

    this is my init config for saadc 1

    //Configure SAADC
        audio_saadc_config.resolution = NRF_SAADC_RESOLUTION_14BIT;       //Set SAADC resolution to 12-bit. This will make the SAADC output values from 0 (when input voltage is 0V) to 2^12=2048 (when input voltage is 3.6V for channel gain setting of 1/6).
        audio_saadc_config.oversample = NRF_SAADC_OVERSAMPLE_DISABLED;    //DIABLED - //Set oversample to 4x. This will make the SAADC output a single averaged value when the SAMPLE task is triggered 4 times.
        audio_saadc_config.interrupt_priority = APP_IRQ_PRIORITY_LOW;     //Set SAADC interrupt to low priority.
        audio_saadc_config.low_power_mode = NRFX_SAADC_CONFIG_LP_MODE;
    	
        //Configure SAADC channels:
        audio_channel_config.reference = NRF_SAADC_REFERENCE_VDD4;          //Set internal reference of fixed 0.6 volts
        audio_channel_config.gain = NRF_SAADC_GAIN1_4;                      //Set input gain to 1/6. The maximum SAADC input voltage is then 0.6V/(1/6)=3.6V. The single ended input range is then 0V-3.6V
        audio_channel_config.acq_time = NRF_SAADC_ACQTIME_10US;             //Set acquisition time. Set low acquisition time to enable maximum sampling frequency of 200kHz. Set high acquisition time to allow maximum source resistance up to 800 kohm, see the SAADC electrical specification in the PS. 
        audio_channel_config.mode = NRF_SAADC_MODE_SINGLE_ENDED;            //Set SAADC as single ended. This means it will only have the positive pin as input, and the negative pin is shorted to ground (0V) internally.
        audio_channel_config.pin_n = NRF_SAADC_INPUT_DISABLED;              //Since the SAADC is single ended, the negative pin is disabled. The negative pin is shorted to ground internally.
        audio_channel_config.resistor_p = NRF_SAADC_RESISTOR_DISABLED;      //Disable pullup resistor on the input pin
        audio_channel_config.resistor_n = NRF_SAADC_RESISTOR_DISABLED;        
        audio_channel_config.burst = NRF_SAADC_BURST_DISABLED;   
        
        
        nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
        timer_cfg.frequency = NRF_TIMER_FREQ_4MHz; // added TBD test
        timer_cfg.bit_width = NRF_TIMER_BIT_WIDTH_32;               // ?? WHAT IS THIS WIDTH ??
        err_code = nrf_drv_timer_init(&m_timer, &timer_cfg, audio_saadc_sample_timer_event_handler);  //timer_handler);
        APP_ERROR_CHECK(err_code);
    
        nrf_drv_timer_extended_compare(&m_timer, NRF_TIMER_CC_CHANNEL0, TICS_FOR_32KHZ, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, false);
        nrf_drv_timer_enable(&m_timer);
    
    // samling event configurations - get handlers address: 
        uint32_t timer_compare_event_addr = nrf_drv_timer_compare_event_address_get(&m_timer, NRF_TIMER_CC_CHANNEL0);
        uint32_t saadc_sample_task_addr   = nrf_drv_saadc_sample_task_get();
    
    // samling event configurations - ppi timer event to start saadc sampling:
        err_code = nrf_drv_ppi_channel_alloc(&m_ppi_channel);
        APP_ERROR_CHECK(err_code);
    
        err_code = nrf_drv_ppi_channel_assign(m_ppi_channel, timer_compare_event_addr, saadc_sample_task_addr);
        APP_ERROR_CHECK(err_code);

    this is how i init the saadc 1 in my module handler that is called from the main loop:

    err_code = nrf_drv_ppi_channel_enable(m_ppi_channel);
                APP_ERROR_CHECK(err_code);
                // TBD - START 2 MIN TIMER - smaple counting instead of timer 
                //Initialize SAADC 
                err_code = nrf_drv_saadc_init(&audio_saadc_config, audio_saadc_callback);
                APP_ERROR_CHECK(err_code);
    
                audio_channel_config.pin_p = AUDIO_PIEZO_ADC_INPUT_PIN; 
                err_code = nrf_drv_saadc_channel_init(ADC_PIEZO_CHANNEL, &audio_channel_config);
                APP_ERROR_CHECK(err_code);
    
                audio_channel_config.pin_p = AUDIO_MIC_ADC_INPUT_PIN;
                err_code = nrf_drv_saadc_channel_init(ADC_MIC_CHANNEL, &audio_channel_config);
                APP_ERROR_CHECK(err_code);
    
                audio_channel_config.pin_p = AUDIO_PIEZO_ADC_INPUT_PREAMPLYFIER_INPUT_PIN;
                err_code = nrf_drv_saadc_channel_init(ADC_AMPLIFIER_CHANNEL, &audio_channel_config);
                APP_ERROR_CHECK(err_code);
    
                err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool[0], CONVERTED_ADC_SAMPELS_BUFF_SIZE);
                APP_ERROR_CHECK(err_code);
    
                err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool[1], CONVERTED_ADC_SAMPELS_BUFF_SIZE);
                APP_ERROR_CHECK(err_code);

    when trying to init the second channel i get assert here:

     // Oversampling can be used only with one channel.
        NRFX_ASSERT((nrf_saadc_oversample_get() != NRF_SAADC_OVERSAMPLE_DISABLED) ||
                    (m_cb.active_channels == 0));

    before i call on this init of saadc1 i have saadc 2 which its configs:

    //Configure SAADC
        hydr_saadc_config.resolution         = NRF_SAADC_RESOLUTION_14BIT;   //Set SAADC resolution to 12-bit. This will make the SAADC output values from 0 (when input voltage is 0V) to 2^12=2048 (when input voltage is 3.6V for channel gain setting of 1/6).
        hydr_saadc_config.oversample         = NRF_SAADC_OVERSAMPLE_4X;      //Set oversample to 4x. This will make the SAADC output a single averaged value when the SAMPLE task is triggered 4 times.
        hydr_saadc_config.interrupt_priority = APP_IRQ_PRIORITY_LOW;         //Set SAADC interrupt to low priority.
        hydr_saadc_config.low_power_mode     = NRFX_SAADC_CONFIG_LP_MODE;
    	  
      //Configure SAADC channel
        hydr_channel_config.reference = NRF_SAADC_REFERENCE_VDD4;          //Set internal reference of fixed 0.6 volts
        hydr_channel_config.gain = NRF_SAADC_GAIN1_4;                      //Set input gain to 1/6. The maximum SAADC input voltage is then 0.6V/(1/6)=3.6V. The single ended input range is then 0V-3.6V
        hydr_channel_config.acq_time = NRF_SAADC_ACQTIME_10US;             //Set acquisition time. Set low acquisition time to enable maximum sampling frequency of 200kHz. Set high acquisition time to allow maximum source resistance up to 800 kohm, see the SAADC electrical specification in the PS. 
        hydr_channel_config.mode = NRF_SAADC_MODE_SINGLE_ENDED;            //Set SAADC as single ended. This means it will only have the positive pin as input, and the negative pin is shorted to ground (0V) internally.
        hydr_channel_config.pin_p = HYDRATION_ADC_INPUT_PIN;               // adc input pin
        hydr_channel_config.pin_n = NRF_SAADC_INPUT_DISABLED;              //Since the SAADC is single ended, the negative pin is disabled. The negative pin is shorted to ground internally.
        hydr_channel_config.resistor_p = NRF_SAADC_RESISTOR_DISABLED;      //Disable pullup resistor on the input pin
        hydr_channel_config.resistor_n = NRF_SAADC_RESISTOR_DISABLED;        
        hydr_channel_config.burst = NRF_SAADC_BURST_ENABLED;

    my init call for it in the module handler called from main loop looks like this:

    //Initialize SAADC
                    err_code = nrf_drv_saadc_init(&hydr_saadc_config, hydr_saadc_callback);
                    APP_ERROR_CHECK(err_code);
      
                  //Initialize SAADC channel
                    err_code = nrf_drv_saadc_channel_init(ADC_HYDRATION_CHANNEL, &hydr_channel_config);
                    APP_ERROR_CHECK(err_code);
    
                    err_code = nrf_drv_saadc_buffer_convert(hydr_buffer_pool[0], HYDR_NUMBER_OF_ADC_SAMPLES);
                    APP_ERROR_CHECK(err_code);
    
                    err_code = nrf_drv_saadc_buffer_convert(hydr_buffer_pool[1], HYDR_NUMBER_OF_ADC_SAMPLES);
                    APP_ERROR_CHECK(err_code);

    and i call for a sample like this:

    err_code = nrf_drv_saadc_sample(); 

    in my saadc2 callback i uninit the saadc:

    static void hydr_saadc_callback(nrf_drv_saadc_evt_t const * p_event)
    {
        if (p_event->type == NRF_DRV_SAADC_EVT_DONE)
        {
            ret_code_t err_code;
            err_code = nrf_drv_saadc_buffer_convert(p_event->data.done.p_buffer, HYDR_NUMBER_OF_ADC_SAMPLES);
            APP_ERROR_CHECK(err_code);
    
            hydration_sample_buff[count_of_10_min_sample_events] /*hydr_val*/ = p_event->data.done.p_buffer[0];// + p_event->data.done.p_buffer[1] + p_event->data.done.p_buffer[2] + p_event->data.done.p_buffer[3])/4;        
            measurments_state = MEASURE_STATE_DONE;
            nrf_drv_saadc_uninit();
        }
    }

    hope my problem is better understood now 

    its strange that i get an assert for oversampling while my oversampling is disabled in that configuration 

    and if there is a way to make all configs of an instance and channels of saadc saved instead of reconfigure them every time i want to start working with one of the saadcs then it will be great

    hope to read from you soon

    best regards

    Ziv

  • Thanks.

    I will ask one of my colleagues with more experience using SAADC to review the code.

    Br,
    Joakim

  • Hi again.

    Had one of my colleagues look at this.

    From what he could see, you get an assert when moving from config1 to config2, which will most likely happen if you don't uninitialize SAADC driver first. He couldn't see any code for un-initializing config1, so that might be the issue.

    BR,
    Joakim

Related