2022-10-31 01:37 AM - last edited on 2023-07-11 09:39 AM by Kevin HUBER
Hi,
I have a STM32MP157A-EV1 board. I'm running it in the engineering boot mode and programming the Cortex-M4 directly through the STM32CubeIDE. At the moment, I do not use the Cortex-A7.
I would like to enable USART2 and use it through the ST-LINK to view the printf command that I do on the Cortex-M4.
What I did was enabling USART2 in STM32CubeMX :
I did not change any other configuration and simply regenerated the code. Then I used these functions:
In retarget.c
UART_HandleTypeDef *gHuart;
void RetargetInit(UART_HandleTypeDef *huart) {
gHuart = huart;
/* Disable I/O buffering for STDOUT stream, so that
* chars are sent out as soon as they are printed. */
setvbuf(stdout, NULL, _IONBF, 0);
}
In main.c
#include "main.h"
#include "cmsis_os.h"
...
UART_HandleTypeDef huart2;
static void MX_USART2_UART_Init(void);
...
int main(){
...
MX_USART2_UART_Init();
RetargetInit(&huart2);
...
while (1)
{
/* USER CODE END WHILE */
printf("\r\nYour name: \r\n");
scanf("%s", buf);
printf("\r\nHello, %s!\r\n", buf);
/* USER CODE BEGIN 3 */
}
}
However, when I use the Open console on MPU serial device I get absolutely no ouput.
It seems that UART is blocked on the UART_WaitOnFlagUntilTimeout in the stm32mp1xx_hal_uart.c.
Did I do something wrong or is there a simpler method ?
Thank you for your help.
Solved! Go to Solution.
2022-10-31 03:08 AM
Hi @Fnx_QT
You could connect USART3 to STLINK using external wires for RX/TX from MB1262 board CN21 to MB1263 JP4/JP5 middle point (jumper removed). See EV1 User Manual or schematics for details.
As you don't use Linux yet, simpler option is to use UART4 (already on JP4/JP5) .
Then, when you will add Linux in the picture, as UART4 is the default Linux console, you will have to comments all UART4 in your SW (you could use IS_ENGINEERING_BOOT_MODE macro) and either :
Regards,
In order to give better visibility on the answered topics, please click on 'Select as Best' on the reply which solved your issue or answered your question. See also 'Best Answers'
2022-10-31 02:43 AM
Hi @Fnx_QT
USART2 is not connected externally on STM32MP157A-EV1 board (PD5 is NAND_NWE and PF4 is SDMMC3_D1). I assume you have a specific motherboard and you use an external STLINKV3, right ?
On regular EV1 board, embedded STLINK VCP is connected to UART4 (using some jumpers), or you could have access to USART3 on GPIO expansion (CN21).
For USART2, did you check (within code and/or debugger) that:
Maybe first try to send characters using HAL_USART_Transmit() fonction instead of printf().
Regards.
2022-10-31 02:52 AM
Hi @PatrickF
Yes just found out that USART2 was not connected externally sorry. I now use USART3 connected to the PIN PB10 and PB12 on the GPIO connector (CN21).
No I don't have a specific motheboard, I use the one that comes with evaluation kit (STM32MP15X-EVAL) and I use the integrated ST-Link v2.1.
I made progress, I used the UART_Receive_Transmit_Console example furnished by ST from the eval kit and it worked by connecting a USB TTL converter to GPIO pins PB10 and PB12.
Now I try to replicate the configuration through STM32CubeMX. I enabled USART3 and configured the ouput pins as PB10 and PB12 as in the example.
I then retested with the same code and it worked. I can now successfuly send UART through printf and then read the serial output through the GPIO pins. Thanks.
However, is there a way to make the UART serial output goes through the ST-Link V2.1 integrated adapter ?
2022-10-31 03:08 AM
Hi @Fnx_QT
You could connect USART3 to STLINK using external wires for RX/TX from MB1262 board CN21 to MB1263 JP4/JP5 middle point (jumper removed). See EV1 User Manual or schematics for details.
As you don't use Linux yet, simpler option is to use UART4 (already on JP4/JP5) .
Then, when you will add Linux in the picture, as UART4 is the default Linux console, you will have to comments all UART4 in your SW (you could use IS_ENGINEERING_BOOT_MODE macro) and either :
Regards,
In order to give better visibility on the answered topics, please click on 'Select as Best' on the reply which solved your issue or answered your question. See also 'Best Answers'
2022-11-03 06:27 AM
Thank you ! :)