cancel
Showing results for 
Search instead for 
Did you mean: 

NUCLEO-H743ZI2 and STLink VCP

Manu Abraham
Senior

Hi,

Can someone throw some light in here, please ?

I have a Nucleo-H743ZI2 (MB1364C) board. From schematics it appears to me that UART3 is connected to STLink and can be used as a regular COM port ?

Is it possible to use UART3/VCP on the STLink as a regular serial port ?

Running Putty on COM8 STLink Virtual COM port, I get some chinese chars

0693W000001s9wfQAA.png

Any idea, what's going on ?

Are those coming from the STLink firmware ?

The code that I am running on it:

#include "main.h"
 
/**
 * System Clock Configuration
 * The system Clock is configured as follow :
 * 	System Clock source	= PLL1 (HSE BYPASS)
 *	SYSCLK(Hz)		= 400000000 (CPU Clock)
 *	HCLK(Hz)		= 200000000 (AXI and AHBs Clock)
 *	AHB Prescaler		= 2
 *	D1 APB3 Prescaler	= 2 (APB3 Clock  100MHz)
 *	D2 APB1 Prescaler	= 2 (APB1 Clock  100MHz)
 *	D2 APB2 Prescaler	= 2 (APB2 Clock  100MHz)
 *	D3 APB4 Prescaler	= 2 (APB4 Clock  100MHz)
 *	HSE Frequency(Hz)	= 8000000
 *	PLL_M			= 4
 *	PLL_N			= 400
 *	PLL_P			= 2
 *	PLL_Q			= 4
 *	PLL_R			= 2
 *	VDD(V)			= 3.3
 *	Flash Latency(WS)	= 4
 */
static void SystemClock_Config(void)
{
	/* Power Configuration */
	LL_PWR_ConfigSupply(LL_PWR_LDO_SUPPLY);
	LL_PWR_SetRegulVoltageScaling(LL_PWR_REGU_VOLTAGE_SCALE1);
	while (LL_PWR_IsActiveFlag_VOS() == 0) { }
 
	LL_RCC_HSE_EnableBypass();
	LL_RCC_HSE_Enable();
	while (LL_RCC_HSE_IsReady() != 1) { }
 
	LL_FLASH_SetLatency(LL_FLASH_LATENCY_4);
 
	/* Main PLL configuration and activation */
	LL_RCC_PLL_SetSource(LL_RCC_PLLSOURCE_HSE);
	LL_RCC_PLL1P_Enable();
	LL_RCC_PLL1Q_Enable();
	LL_RCC_PLL1R_Enable();
	LL_RCC_PLL1FRACN_Disable();
	LL_RCC_PLL1_SetVCOInputRange(LL_RCC_PLLINPUTRANGE_2_4);
	LL_RCC_PLL1_SetVCOOutputRange(LL_RCC_PLLVCORANGE_WIDE);
	LL_RCC_PLL1_SetM(4);
	LL_RCC_PLL1_SetN(400);
	LL_RCC_PLL1_SetP(2);
	LL_RCC_PLL1_SetQ(4);
	LL_RCC_PLL1_SetR(2);
	LL_RCC_PLL1_Enable();
	while (LL_RCC_PLL1_IsReady() != 1) { }
 
	LL_RCC_SetSysPrescaler(LL_RCC_SYSCLK_DIV_1);
	LL_RCC_SetAHBPrescaler(LL_RCC_AHB_DIV_2);
	LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_2);
	LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_2);
	LL_RCC_SetAPB4Prescaler(LL_RCC_APB4_DIV_2);
	LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL1);	/* Set PLL1 as System Clock Source */
	while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL1) { }
 
	SysTick_Config(400000000 / 4000);			/* Set systick to 1ms */
	SystemCoreClock = 400000000;				/* Update CMSIS variable */
}
 
#define STLINK_RX_Pin		LL_GPIO_PIN_8
#define STLINK_TX_Pin		LL_GPIO_PIN_9
#define APB_Div			2
 
void config_usart(void)
{
	LL_AHB4_GRP1_EnableClock(LL_AHB4_GRP1_PERIPH_GPIOD);
 
	LL_GPIO_SetPinMode(GPIOD, STLINK_TX_Pin, LL_GPIO_MODE_ALTERNATE);
	LL_GPIO_SetAFPin_8_15(GPIOD, STLINK_TX_Pin, LL_GPIO_AF_7);
	LL_GPIO_SetPinSpeed(GPIOD, STLINK_TX_Pin, LL_GPIO_SPEED_FREQ_HIGH);
	LL_GPIO_SetPinOutputType(GPIOD, STLINK_TX_Pin, LL_GPIO_OUTPUT_PUSHPULL);
	LL_GPIO_SetPinPull(GPIOD, STLINK_TX_Pin, LL_GPIO_PULL_NO);
 
	LL_GPIO_SetPinMode(GPIOD, STLINK_RX_Pin, LL_GPIO_MODE_ALTERNATE);
	LL_GPIO_SetAFPin_8_15(GPIOD, STLINK_RX_Pin, LL_GPIO_AF_7);
	LL_GPIO_SetPinSpeed(GPIOD, STLINK_RX_Pin, LL_GPIO_SPEED_FREQ_HIGH);
	LL_GPIO_SetPinOutputType(GPIOD, STLINK_RX_Pin, LL_GPIO_OUTPUT_PUSHPULL);
	LL_GPIO_SetPinPull(GPIOD, STLINK_RX_Pin, LL_GPIO_PULL_NO);
 
	LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_USART3);
	LL_USART_Disable(USART3);
 
	LL_USART_SetTransferDirection(USART3, LL_USART_DIRECTION_TX_RX);
	LL_USART_ConfigCharacter(USART3,
				 LL_USART_DATAWIDTH_8B,
				 LL_USART_PARITY_NONE,
				 LL_USART_STOPBITS_1);
 
	LL_USART_SetHWFlowCtrl(USART3, LL_USART_HWCONTROL_NONE);
	LL_USART_SetOverSampling(USART3, LL_USART_OVERSAMPLING_16);
	LL_USART_SetBaudRate(USART3,
			     SystemCoreClock/APB_Div,
			     LL_USART_PRESCALER_DIV1,
			     LL_USART_OVERSAMPLING_16,
			     115200);
 
	LL_USART_SetTXFIFOThreshold(USART3, LL_USART_FIFOTHRESHOLD_1_8);
	LL_USART_SetRXFIFOThreshold(USART3, LL_USART_FIFOTHRESHOLD_1_8);
	LL_USART_DisableFIFO(USART3);
	LL_USART_Enable(USART3);
 
	while ((!(LL_USART_IsActiveFlag_TEACK(USART3))) ||
	       (!(LL_USART_IsActiveFlag_REACK(USART3)))) { }
}
 
 
uint8_t bytes = 0;
const uint8_t tx_str[] = "STM32H743 USART Tx Test: @115200bps, 8N1\r\n";
 
void BufferTransfer(void)
{
	/* Send characters one per one, until last char to be sent */
	while (bytes < sizeof (tx_str)) {
		while (!LL_USART_IsActiveFlag_TXE(USART3)) {}	/* Wait for TXE flag to be raised */
 
		if (bytes == (sizeof (tx_str) - 1))
			LL_USART_ClearFlag_TC(USART3);		/* If last char to be sent, clear TC flag */
 
		LL_USART_TransmitData8(USART3, tx_str[bytes++]);
	}
	while (!LL_USART_IsActiveFlag_TC(USART3)) {}		/* Wait for TC flag to be raised for last char */
}
 
 
int main(void)
{
//	SCB_EnableICache();
//	SCB_EnableDCache();
	SystemClock_Config();
	config_usart();
	BufferTransfer();
 
	while (1) { }
}

6 REPLIES 6

>>Any idea, what's going on ?

Clocks/baud rate not what you want. Suspect you're going to need to unpack the register settings, and determine what you have. Scope the TX pins to measure bit timing achieved.

Attached code outputting at 115200 8N1, should prove the plumbing and terminal working.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Hi Clive,

Thanks for the quick reply and the help.

As you rightly said, the clocks issue and not setting the clock source.

These 2 changes helped.

#define APB_Div         4

LL_RCC_SetUSARTClockSource(LL_RCC_USART234578_CLKSOURCE_PCLK1);      /* Clk source */

Though that did the trick, still the question about the Chinese chars.

If I do comment out the clock source, I still do see the chinese chars.

0693W000001s9zoQAA.png

Any thoughts ?

Thanks,

Manu

I did try a Google translate of the characters,

昀▒▒昆▒▒▒▒▒▒▒▒▒▒

Yún ▒▒kūn ▒▒▒▒▒▒▒▒▒▒

It seems to read as Yun and Kun ?? meaning Cloud and Earth/Universe ??

But still wonder where they come from ..

Thanks,

Manu

TDK
Guru

Is there an external pullup on that line? Line could be toggling due to noise or interference when the chip is in reset.

If you got those chars when your baud settings were incorrect then it's probably not from something your chip is doing.

I suppose the ST-Link chip could be creating those. Seems odd though.

If you feel a post has answered your question, please click "Accept as Solution".

No pullups on the line.

I also wondered why ST Link was doing it, but had no clue.

My bad, it was not commenting out the clk source, that brought out those chars, but change to the baud rate with:

#define APB_Div         4

to

#define APB_Div         2

That clears up the issue, I guess ..

Thanks and sorry about the noise.

I would look at the binary values behind these, and perhaps the signal from the STM32 on a logic analyzer.

My guess is that the clocks are wrong, or the pll isn't locked/running properly, due to startup issues or inconsistencies.

Basically you're trying to translate line noise, at a different baud rate.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..