2018-03-19 12:15 PM
Looks like I found a small bug in STM32 CubeMX code generation. It can be reproduced this way:
1. Create new project for STM32F091RB.
2. Enable USART5 with Asynchronous mode and Hardware Flow Control (RS485) on.
3. In Project Settings select Toolchain/IDE = SW4STM32 (probably irrelevant).
4. Generate the code.
As result in the stm32f0xx_hal_msp.c file we have:
void HAL_UART_MspInit(UART_HandleTypeDef* huart)
{GPIO_InitTypeDef GPIO_InitStruct;
if(huart->Instance==USART5) {GPIO_InitStruct.Pin = GPIO_PIN_12;
...
GPIO_InitStruct.Alternate = GPIO_AF2_USART5; HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); ... GPIO_InitStruct.Pin = GPIO_PIN_2;...
GPIO_InitStruct.Alternate = GPIO_AF2_USART5;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_5;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; /* [1] */
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
}
}
The initialization of
GPIO_InitStruct.
Alternate field for PB5 is missing after the line marked by /* [1] */. The missing line should be:GPIO_InitStruct.Alternate = GPIO_AF4_USART5;
Otherwise the previous value for PD2 pin is used (
GPIO_AF2_USART5
) and the UART5_DE pin doesn't work.2018-04-11 08:07 AM
Hello Evgeniy,
Thanks for your feedback.
I confirm the bug. The issue will be fixed next CubeMX release.
Best regards,
Houda
2018-06-08 03:39 AM
Hello
evgen
You can switch to STM32CubeMX4.0 available now on ST website.
This issue is resolved.
regards,
Houda
2018-06-25 06:49 AM
I found similar - maybe related - bug. I used 4.26.0 to generate code for the STM32F042K6Ux. It worked fine with 4.25, but now it completely skipped the generation of MX_GPIO_Init.
Can anybody help me how to get back to 4.25, because I am sort of stuck. I could try to generate the block by hand but I am not sure I can trust the 4.6.0
Thanks,
Ron
2019-01-28 08:58 AM
I have seen this problem today as well with Truestudio 9.0.1 and cube but it seems intermittent. I take an old project and move it and sometimes it does not generate the MX_GPIO_Init code even though I set some GPIO pins explicitly in Cube.