cancel
Showing results for 
Search instead for 
Did you mean: 

[RTOS] osDelay stuck after passing argument in UART printf function

APapa.14
Associate

Hello !

My project works with FreeRTOS and HAL library (generate by CubeMX) on STM32L496 and I use TIM1 as timebase source instead of SystTick.

I have a problem with osDelay().

I have these functions to print what I want with an UART :

/* --------------------------------------------------------------------------*/
uint8_t	TUTxPutByte(uint8_t p_data)
{
 
	//Push character on UART
	return HAL_UART_Transmit(&huart3, &p_data, 1, 1);
 
 
}//end TUTxPutByte
/* --------------------------------------------------------------------------*/
 
 
/* --------------------------------------------------------------------------*/
uint8_t	sendMsg(char * p_msg_to_send, uint8_t p_CRLF)
{
	uint8_t	i = 0;					//Loop variable
	uint8_t	lengthMsg = 0;			//Length of ASCII data
	uint8_t	statusReturn = HAL_OK;	//Error function return
 
	//Calculate length of message
	lengthMsg = strlen(p_msg_to_send);
 
	//Transmit loop
	for(i = 0; i < lengthMsg; i++){
		//Send char by char with error control of HAL function
		if((statusReturn = TUTxPutByte(p_msg_to_send[i])) != HAL_OK)
		{
			return statusReturn;
		}
	}//end for
 
	//String termination
	if((p_CRLF == SEND_CR) || (p_CRLF == SEND_CR_LF))
	{
		//Send CR with error control of HAL function
		if((statusReturn = TUTxPutByte(0x0D)) != HAL_OK)	// [ASCII] CR
		{
			return statusReturn;
		}
	}
 
	//String termination
	if((p_CRLF == SEND_LF) || (p_CRLF == SEND_CR_LF))
	{
		//Send LF with error control of HAL function
		if((statusReturn = TUTxPutByte(0x0A)) != HAL_OK)	//< [ASCII] LF
		{
			return statusReturn;
		}
	}
 
	//Normal case
	return HAL_OK;
}//end sendMsg
/* --------------------------------------------------------------------------*/
 
/* --------------------------------------------------------------------------*/
uint8_t cprintf (const char *format, ...)
{
	uint8_t		i = 0;
	char		msg_to_write[SIZE_BUFFER_DEBUG] = {'\0'};	//Maximum 128 characters
 
	//Stack declaration
	va_list pile;
	//Last argument
	va_start(pile, format);
	//Array construction
	i = vsnprintf (msg_to_write, SIZE_BUFFER_DEBUG, format, pile);
 
	//Close stack
	va_end(pile);
 
	//Send Msg
	sendMsg(msg_to_write, NO_CR_LF);
 
	//Return number of characters sent
	return i;
}//end cprintf
/* --------------------------------------------------------------------------*/

When I use cprintf() function with a simple array (without arguments), all it works in my task, nothing stuck.

The problem is when I have an argument with cprintf as below:

void TestLOGTask(void const * argument)
{
    uint8_t value = 'a';
    for(;;)
    {
        cprintf("Value : %c\r\n", value);
        osDelay(250);
    }
}
 
void OtherTask(void const * argument)
{
    for(;;)
    {
        HAL_GPIO_WritePin(GPIOB, GPIO_PIN14, GPIO_PIN_SET);
        osDelay(250);
        HAL_GPIO_WritePin(GPIOB, GPIO_PIN14, GPIO_PIN_RESET);
        osDelay(250);
    }
}

osDelay stuck the runing execution in this configuration : it just execute one time my cprintf and stop execution of all task (including the blink led).

When I put HAL_Delay instead of osDelay() in TestLOGTask() OR/XOR OtherTask(), It works.

To resume :

  • Code works if no argument in cprintf
  • Code works if there is runing HAL_Delay at least in one task

Do you have any idea to solve this problem ?

Maybe due to mis-overwritting of the OS of tick function ?

This is strange because HAL_Delay just get tick, no set or init things.

Thank you in advance to any one who may be able to give me some ideas.

Adrian

2 REPLIES 2
APapa.14
Associate

I solve this problem by increase the stack size of my task (use printf functions...).

However, I don't understand how it can works by using HAL_Delay() function.

I''m really appreciate your answer. I spent on it a whole day until I found your answer.