cancel
Showing results for 
Search instead for 
Did you mean: 

STM32MP157A, enable USART2 through ST-LINK

Fnx_QT
Associate III

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 :

 

0693W00000VOTVUQA5.png0693W00000VOTVjQAP.png 

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.

1 ACCEPTED SOLUTION

Accepted Solutions

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 :

  • use another UART (e.g. USART3 with external 3.3V UART<->USB cable)
  • use virtual UART thru OPENAMP/RPMsg TTY

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'

In order 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.

View solution in original post

4 REPLIES 4
PatrickF
ST Employee

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:

  • SystemClock_Config() is executed (which is under IS_ENGINEERING_BOOT_MODE condition) ?
  • USART clock is enabled ?
  • GPIOs AFMUX are correctly sets to right pins ?

Maybe first try to send characters using HAL_USART_Transmit() fonction instead of printf().

Regards.

In order 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.
Fnx_QT
Associate III

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 ?

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 :

  • use another UART (e.g. USART3 with external 3.3V UART<->USB cable)
  • use virtual UART thru OPENAMP/RPMsg TTY

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'

In order 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.
Fnx_QT
Associate III

Thank you ! :)