Hello, I'm getting started with FreeRTOS in Nordic SDK 15.3
I have created a small test code, using binary Semaphore from FreeRTOS, that waits signal from SAADC callback. I also use SDK timer module to setup continuous ADC sampling via PPI
However, I found that the code stucks in PendSV handler, sometimes from Semaphore wait function sometimes earlier.(see pictures). Used same config as in blinky freertos example.
My question is should I use it inside tasks only, or it actually should work.
int main(void) { (void)NRF_LOG_INIT(NULL); NRF_LOG_DEFAULT_BACKENDS_INIT(); // spim_init(); // // ext_flash_init(); drv_saadc_init(); comp_battery_init(); drv_saadc_sampling_start(); start_up_reason(); NRF_LOG_INFO("\r\nBAt example started.\r\n"); while (true) { nrf_delay_ms(1000); (void)comp_battery_get_soc(); } }
void comp_battery_init(void) { // Configure BATTERY_ENABLE_PIN and CHARGE_CONTROL_PIN nrf_gpio_cfg_output(BATTERY_ENABLE_PIN); nrf_gpio_cfg_output(BAT_ADC_EN); /* Create a binary semaphore without using any dynamic memory allocation. The semaphore's data structures will be saved into the xSemaphoreBuffer variable. */ bat_semaphore = xSemaphoreCreateBinaryStatic(&bat_SemaphoreBuffer); /* The pxSemaphoreBuffer was not NULL, so it is expected that the handle will not be NULL. */ configASSERT(bat_semaphore); drv_saadc_register_user_cb(ADC_4V2, battery_adc_cb); battery_connection(CONNECTED); } uint8_t comp_battery_get_soc(void) { uint16_t soc_mapped = 0; static uint32_t soc_sum = 0; static int32_t bat_vol_prev = 0; if (xSemaphoreTake(bat_semaphore, (TickType_t) 100) == pdTRUE) { /* SOC code here } else { NRF_LOG_DEBUG("FAILED TO GET SEMAPHORE"); } return bat_soc; } /************************************************************************************* * @brief Briefly explain what function does * @param Describe input params and their limitations * @retval Describe return param **************************************************************************************/ static void battery_adc_cb(int32_t adc_converted_results) { static BaseType_t xHigherPriorityTaskWoken = pdFALSE; xHigherPriorityTaskWoken = pdFALSE; /* Unblock the task by releasing the semaphore. */ xSemaphoreGiveFromISR(bat_semaphore, &xHigherPriorityTaskWoken ); current_battery_voltage = (uint16_t )adc_converted_results; }