Skip to main content
Jal Panchal
Associate III
November 30, 2018
Question

Unable to establish Nucleo - STM32L476RG - USB CDC communication.

  • November 30, 2018
  • 4 replies
  • 3810 views

I am trying to send and receive data through the USB port on the Nucleo-L476RG, but am unable to see any data on Putty.

I generated an initialization code with STM32CubeMX enabling the following:

  • RCC
  • USB_OTG
  • USB_DEVICE
  • SYS Serial wire
  • RTC clock source
  • Let CubeMX solve the clock conflicts - the USB got a 48MHz signal

In the generated code,

I am able to see the COM port and am trying to read the data on Putty but I see nothing.

I am attaching the CubeMX file

Am I missing something ?

  •  
This topic has been closed for replies.

4 replies

Tesla DeLorean
Guru
December 1, 2018

Which USB port? The one connected to the F103 providing the ST-LINK functionality? Or one you've wired up?

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Jal Panchal
Associate III
December 3, 2018

I have only made one connection, through the ST Link port.

Tesla DeLorean
Guru
December 3, 2018

Ok, so that's not electrically connected in a way that permits USB to work on the L476.

The ST-LINK VCP connects as a USART ​

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Jal Panchal
Associate III
December 3, 2018

Oh okay. I wasn't aware of that. Can you guide me on how to connect the Nucleo L746RG to a computer to get data over serial ?

Thank you for the prompt replies! This is very helpful :)

Tesla DeLorean
Guru
December 3, 2018
//****************************************************************************
 
#define USART_VCP USART2
 
#ifdef USART_CR1_TXEIE_TXFNFIE // FIFO Support
#define USART_CR1_RXNEIE USART_CR1_RXNEIE_RXFNEIE
#define USART_CR1_TXEIE USART_CR1_TXEIE_TXFNFIE
#define USART_ISR_RXNE USART_ISR_RXNE_RXFNE
#define USART_ISR_TXE USART_ISR_TXE_TXFNF
#endif // Copyright (C) 2018 sourcer32@gmail.com
 
//****************************************************************************
 
void OutChar(char c)
{
 while((USART_VCP->ISR & USART_ISR_TXE) == 0); // Wait for Empty
 
 USART_VCP->TDR = c; // Send Char
}
 
//****************************************************************************
 
void OutString(char *s)
{
 while(*s)
 {
 while((USART_VCP->ISR & USART_ISR_TXE) == 0); // Wait for Empty
 
 USART_VCP->TDR = *s++; // Send Char
 }
} 
 
//****************************************************************************
 
void USART2_Init(void)
{
 GPIO_InitTypeDef GPIO_InitStruct = { 0 };
 
 __USART2_CLK_ENABLE();
 __GPIOA_CLK_ENABLE();
 
 /* UART RX/TX GPIO pin configuration */
 GPIO_InitStruct.Pin = GPIO_PIN_2 | GPIO_PIN_3;
 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
 GPIO_InitStruct.Pull = GPIO_PULLUP;
 GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
 GPIO_InitStruct.Alternate = GPIO_AF7_USART2;
 
 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
 
 /*## Configure the UART peripheral ######################################*/
 /* Put the USART peripheral in the Asynchronous mode (UART Mode) */
 /* UART1 configured as follow:
 - Word Length = 8 Bits
 - Stop Bit = One Stop bit
 - Parity = NO parity
 - BaudRate = 115200 baud
 - Hardware flow control disabled (RTS and CTS signals) */
 UartHandle.Instance = USART2;
 
 UartHandle.Init.BaudRate = 115200;
 UartHandle.Init.WordLength = UART_WORDLENGTH_8B;
 UartHandle.Init.StopBits = UART_STOPBITS_1;
 UartHandle.Init.Parity = UART_PARITY_NONE;
 UartHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
 UartHandle.Init.Mode = UART_MODE_TX_RX;
 
 UartHandle.Init.OverSampling = UART_OVERSAMPLING_16;
#ifdef UART_ONE_BIT_SAMPLE_DISABLE
 UartHandle.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
#endif
 
 if (HAL_UART_Init(&UartHandle) != HAL_OK)
 {
 /* Initialization Error */
 Error_Handler();
 }
 
// HAL_NVIC_SetPriority(USART2_IRQn, 1, 0);
// HAL_NVIC_EnableIRQ(USART2_IRQn);
}
 
//******************************************************************************
 
int main(void)
{
 /* STM32L4xx HAL library initialization:
 - Configure the Flash prefetch, Flash preread and Buffer caches
 - Systick timer is configured by default as source of time base, but user
 can eventually implement his proper time base source (a general purpose
 timer for example or other time source), keeping in mind that Time base
 duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and
 handled in milliseconds basis.
 - Low Level Initialization
 */
 
 HAL_Init();
 
 /* Configure the System clock to have a frequency of 80 MHz */
 SystemClock_Config();
 
	USART2_Init();
 
	OutString("Nucleo L476RG\r\n");
 
 /* Infinite loop */
 while (1)
 {
 }
}
 
//****************************************************************************

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Jal Panchal
Associate III
December 3, 2018

Oh wow! Thank you.

This will send data through the ST-LINK connected USB port ? Or I have to make another connection ?

crequensy
Visitor II
March 10, 2020

i have same problem , i couldn't connect it can you check it out also

https://github.com/sezaacar/USB-multiple-cdc-STM32L476RG/issues/1