2022-02-11 11:34 AM
I have a motor control board built around the STM32F446RET6.
I was updating code using motor control workbench to alter the control parameters.
After an update, I was no longer able to use the motor control workbench console to communicate with the board through USART3.
Here is the sequence of events that 'broke' the link.
Here are the versions of the SW tools I am using:
Motor Control Workbench - 5.4.7
STMCubeMX - 6.3.0
STMCubeIDE - 1.3.0
I have reviewed the USART settings in CubeMX, I everything looks okay to me.
I have a point on the board where I can scope USART3-RX and USART3-TX.
There is definitely activity on RX, but I rarely see any signals on TX.
I also attempted to put a breakpoint in the code for the USART, but this breakpoint never got triggered. So it appears the interrupt routine is not being called.
Any advice on where to look to correct this issue?
2022-02-12 02:10 AM
Hi,
What method are your using for USART TX / RX?
A long shot, but rebuilding can sometimes result in Cube placing the DMA_Init after the associated USARTx_UART_Init()...
Cheers.
2022-02-12 05:56 AM
Check clocks and pin settings. Perhaps hidden in MSP code file.
Make sure HSE_VALUE define matches your external clock source, as this often leads to baud rates appearing wrong. Look in stm32F4xx_hal_conf.h
Perhaps test sending a 0x55 (U) test pattern in a loop so you can scope the data.
2022-02-14 03:58 PM
I checked into some of these things as best as I can.
First, the UART is set up to be interrupt driven.
I checked to see if DMA_Init was run afterwards, and I did not see DMA_Init
For clocks, I started my code generation using motor control workbench. For the MCU I am using, it has 3 external clock speeds: 8 MHz, 16 MHz and 25 MHz.
I have a 12 MHz crystal for the external clock, so I used 8 MHz.
So, I used the clock setting feature in STMCUbeMX to change the external clock frequency to 12 MHz, and adjusted the prescalers as needed.
Recompiling with the new code did not change anything, still no communication.
As for pin configuration, I noticed that no GPIO initialization has been made for PC10 and PC11, which are the USART3 RX and TX pins I am using.
My next step might be to insert some code to initialize these pins, and see if that solves the problem.
2022-02-14 04:12 PM
If you have the USART configured in your .ioc then it is quite uncommon for Cube to fail to generate the appropriate GPIO config.
To check, cube puts the associated initialisation of the GPIO (and the DMA if enabled) in the function:
HAL_UART_MspInit()
2022-02-14 05:35 PM
grep or find-in-file the HAL_UART_MspInit() function typically stm32f3xx_hal_msp.c or similar MSP file..
2022-02-15 08:55 AM
Thanks to both of you for these suggestions.
I have found both HAL_UART_MspInit() and HAL_UART_Init() in the file stm32f4xx_hal_uart.c
Neither of these files contain code to initialize the GPIOs.
Below is the code form HAL_UART_MspInit()
I didn't include HAL_UART_Init; it is long and seems to be mostly low level setting of bits, etc.
It does seem bizarre that the I haven't seen the routines to initialize the GPIOs.
Note: I don't see the file stm32f4xx_hal_msp.c in the driver section of my code.
Is it possible that this is the missing piece to the code?
Thank you
Dale
/**
* @brief UART MSP Init.
* @param huart Pointer to a UART_HandleTypeDef structure that contains
* the configuration information for the specified UART module.
* @retval None
*/
__weak void HAL_UART_MspInit(UART_HandleTypeDef *huart)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(huart);
/* NOTE: This function should not be modified, when the callback is needed,
the HAL_UART_MspInit could be implemented in the user file
*/
}
2022-02-15 09:06 AM
Those are some weak functions to allow the linker to complete.
In a more normal setup these would be in an MSP file, or in your own HAL code for initializing the USART.
Assuming you didn't archive your working code/build..
2022-02-15 02:39 PM
Unfortunately, no.
I have some older code, that was used to program a Nucleo board in early development.
I had communication working on that prototype.
I don't know my way around ST code that well.
So I am not sure where to look for the MSP files.
I do not have my own code at this time to initialize the USART.
2022-02-15 03:04 PM
I don't use CubeMX or code generators, they just obfuscate the details.
Here from CubeF4 an example
Might I suggest find a File Manager or Viewer that lets you search files, or some kind of static analysis tool that lets you browse the source, and cross-reference the functions and files. Lot of things integrated into current IDEs. but they do exist external too them and good for understanding structure and relationships in code you didn't write yourself.