cancel
Showing results for 
Search instead for 
Did you mean: 

STM32CubeMx with FreeRTOS, LED, UART stuck in infinite loop

jephua
Associate II
Posted on July 31, 2014 at 03:55

Hi there, I am using the STM32CubeMx code generator with the STM32L053 discovery board. In CubeMx, I enabled USART2 and changed the baud rate to 9600. Also, I configured the pins PA0 for user push button, PA5 for red LED, PB4 for green LED.

Here is a snippet of code that i inserted in TrueStudio:

/* USER CODE BEGIN 2 */
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, GPIO_PIN_SET);
/* USER CODE END 2 */

This is before the code generated for FreeRTOS but the debug never reaches this line of code. It gets stuck here line 124: 0690X00000605XWQAY.png However, if i were to disable the USART2 in CubeMx, the LED works! Is there some configuration procedure to note??? I have not called the function HAL_UART_MspInit yet...
9 REPLIES 9
jephua
Associate II
Posted on July 31, 2014 at 04:01

I did a step over debug starting from the main() and found out that the function MX_GPIO_Init(); generated by STMCubeMx went into the infinite loop.

This is the generated code:

GPIO_InitTypeDef GPIO_InitStruct;
/* GPIO Ports Clock Enable */
__GPIOA_CLK_ENABLE();
__GPIOB_CLK_ENABLE();
/*Configure GPIO pin : PA0 */
GPIO_InitStruct.Pin = GPIO_PIN_0;
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/*Configure GPIO pin : PA5 */
GPIO_InitStruct.Pin = GPIO_PIN_5;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/*Configure GPIO pin : PB4 */
GPIO_InitStruct.Pin = GPIO_PIN_4;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/* EXTI interrupt init*/
HAL_NVIC_SetPriority(EXTI0_1_IRQn, 3, 0);
HAL_NVIC_EnableIRQ(EXTI0_1_IRQn);

Any ideas why this piece of code causing infinite loop?
Posted on July 31, 2014 at 04:49

Any ideas why this piece of code causing infinite loop?

There's no interrupt handler code for the EXTI you enabled?
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
jephua
Associate II
Posted on July 31, 2014 at 05:08 There is (it is generated by STMCubeMx in another file):

/**
* @brief This function handles EXTI Line 0 and Line 1 interrupt.
*/
void EXTI0_1_IRQHandler(void)
{
HAL_NVIC_ClearPendingIRQ(EXTI0_1_IRQn);
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_0);
}

But this interrupt is used for the pushbutton though...
jephua
Associate II
Posted on July 31, 2014 at 09:32

During debugging, i stepped through and found that the line MX_GPIO_Init(); caused the debugger to go to the Infinite Loop in the file startup_stm21l053xx.s.

Anyone know what is going on??? I am just trying to enable LEDs and USART only...

Posted on July 31, 2014 at 16:51

Are you sure it's not Hard Faulting? What other vectors in the table are pointing at this Default Handler location?

Review the vector table, review the .MAP, and understand the registers and stack state immediately prior to it trapping into the loop.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
jephua
Associate II
Posted on July 31, 2014 at 17:05

I'm just beginning to use this STMCubeMx software and the MCU so I am afraid I do not know much to debug this problem. But the thing is, there was not much user input code (except for the GPIO for LED control), most of the code and initialization is done by CubeMx... So I am thinking if there is any step I missed or it it some bug in the generated code..

Amel NASRI
ST Employee
Posted on August 04, 2014 at 15:56

Would it be possible to attach the .IOC file for the generated project leading to described issue?

-Mayla-

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

jephua
Associate II
Posted on August 05, 2014 at 05:31

Hi Mayla,

I have attached the ioc file

________________

Attachments :

stm32_l0_gpad.ioc : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HzQA&d=%2Fa%2F0X0000000bLf%2FsxDrO2m9CclQ2wPeGKhm_k0oBOTb5WjUg5pqHndx7Rg&asPdf=false
stm32cube-t
Senior III
Posted on September 18, 2014 at 17:26

Hello Eugene,

There is a known issue that will be fixed in STM32CubeMX 4.4.

Please update the generated code as highlighted below to ensure the systick handler code is called only only once freeRTOS is initialized:

void SysTick_Handler(void)

{

 

if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) {

    xPortSysTickHandler();

}

HAL_IncTick();

}

Best regards