STM32CubeMx with FreeRTOS, LED, UART stuck in infinite loop
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-07-30 6:55 PM
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:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-07-30 7:01 PM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-07-30 7:49 PM
Any ideas why this piece of code causing infinite loop?
There's no interrupt handler code for the EXTI you enabled?Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-07-30 8:08 PM
/**
* @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...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-07-31 12:32 AM
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...- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-07-31 7:51 AM
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.Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-07-31 8:05 AM
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..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-08-04 6:56 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-08-04 8:31 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-09-18 8:26 AM
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