Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


Loading

xSemaphoreTake() . Program gets stuck . need help debugging

Posted by asantos on February 6, 2019

Hi,

I am using the nordic NRF52832 on a custom board. My program implements a binary semaphore, which is given in the RTC interrupt handler. My send_data task (this is the only task) waits for this semaphore in the beginning of the loop.

I have been trying to debug it but I have not found the problem. The portYIELDWITHINAPI(); line inside xQueueSemaphoreTake() is reached and then my program seems to hang. The code inside void vApplicationIdleHook( void ) is not run though, which should be the code run after the context switch.

I attach the part of the code relative to this issue. Please let me know how to debug this.

Thanks

Code in main.c ~~~ void vApplicationIdleHook( void ) { while(1) {
NRFLOGDEBUG("Idle task"); delayms(1000); } ~~~ ~~~ /* Create task for senddata blinking with priority set to 2 */ UNUSEDVARIABLE(xTaskCreate(senddata, "senddata", configMINIMALSTACKSIZE + 200, NULL, 2, &senddata_handle)); ~~~

Code in task.c ~~~ // RTC timer APPTIMERDEF(mledatimerid); /** * @brief RTC instance number * */

define PERIODIC_RTC 2

/** * @brief RTC compare channel used * */

define PERIODICRTCCC 0

/** * @brief Number of RTC ticks between interrupts */

define PERIODICTIMERUS 5000000ULL
define PERIODICRTCTICKS (RTCUSTOTICKS(PERIODICTIMERUS, RTCDEFAULTCONFIGFREQUENCY))

/** * @brief Semaphore set in RTC event */ static SemaphoreHandlet senddatasemaphore = NULL; /** * @brief RTC configuration */ static nrfdrvrtcconfigt const mrtcconfig = NRFDRVRTCDEFAULTCONFIG; /** * @brief RTC instance * * Instance of the RTC used for led blinking */ static nrfdrvrtct const mrtc = NRFDRVRTCINSTANCE(PERIODIC_RTC);

static void periodicrtchandler(nrfdrvrtcinttypet inttype) { NRFLOGDEBUG("Send data RTC handler"); BaseTypet yieldreq = pdFALSE; BaseTypet retval; retcodet errcode; errcode = nrfdrvrtcccset( &mrtc, PERIODICRTCCC, (nrfrtcccget(mrtc.preg, PERIODICRTCCC) + PERIODICRTCTICKS) & RTCCOUNTERCOUNTERMsk, true); APPERRORCHECK(errcode);

/* The returned value may be safely ignored, if error is returned it only means that * the semaphore is already given (raised). */ UNUSEDVARIABLE(xSemaphoreGiveFromISR(senddatasemaphore, &yieldreq)); // Request a context switch (switch to other task). Interrupt safe verison of taskYIELD() portYIELDFROMISR(yieldreq); } ~~~ ~~~ /** * @brief senddata task entry function. * * @param[in] pvParameter Pointer that will be used as the parameter for the task. */ void senddata(void * pvParameter) { NRFLOG_INFO("---------- SEND DATA TASK ----------");

// Create rtc instance and compare channel
NRF_LOG_DEBUG("Init RTC");
ret_code_t err_code;
err_code = nrf_drv_rtc_init(&m_rtc, &m_rtc_config, periodic_rtc_handler);
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_rtc_cc_set(&m_rtc, PERIODIC_RTC_CC, PERIODIC_RTC_TICKS, true);
APP_ERROR_CHECK(err_code);
// Enable RTC instance
nrf_drv_rtc_enable(&m_rtc);

// Create semaphore

send_data_semaphore = xSemaphoreCreateBinary();
UNUSED_PARAMETER(pvParameter);
// Begin task loop
while(1)
{	
		NRF_LOG_DEBUG("Waiting for semaphore to begin task");
	UNUSED_VARIABLE(xSemaphoreTake(send_data_semaphore, portMAX_DELAY));
		NRF_LOG_INFO("++++++++++++++++task begin++++++++++++++++\r\n");

~~~


xSemaphoreTake() . Program gets stuck . need help debugging

Posted by richarddamon on February 6, 2019

Idle task, and thus Idle hook MUST NOT BLOCK, as there must always be a task ready to run.

Your vApplicationIdleHook() is broken.


xSemaphoreTake() . Program gets stuck . need help debugging

Posted by asantos on February 7, 2019

Hi, Thanks for your support I have changed my idle task hook to this, but I still have an issue

~~~ void vApplicationIdleHook( void ) { while(1) {
NRFLOGDEBUG("Idle task"); } } ~~~


xSemaphoreTake() . Program gets stuck . need help debugging

Posted by asantos on February 7, 2019

Hi, Thanks for your support I have changed my idle task hook to this, but I still have an issue

~~~ void vApplicationIdleHook( void ) { while(1) {
NRFLOGDEBUG("Idle task"); } } ~~~


xSemaphoreTake() . Program gets stuck . need help debugging

Posted by asantos on February 7, 2019

Hi Richard,

I have already fixed it. It turns out that my task usStackDepth was too small.

Thanks for everything


xSemaphoreTake() . Program gets stuck . need help debugging

Posted by richarddamon on February 7, 2019

Just as a comment, I would not put an infinte loop like you have in the idle hook, as that says that the rest of the Idle task won't run, so if any task deletes itself, its resources won't be cleared up.

Also, I would be careful that NRFLOGDEBUG doesn't block (it likely doesn't, but just spin-waits for the debug port to be ready, but should be checked).


[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]


Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS v10.2.0 is available for immediate download. MIT licensed, and including RISC-V and ARMv8-M (Cortex-M33) demos.

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Cadence Tensilica Cortes

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Mediatek

Renesas

RISC-V

SiFIve RISC-V

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner