cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to establish Nucleo - STM32L476RG - USB CDC communication.

Jal Panchal
Associate III

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 ?

  •  
9 REPLIES 9

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
Up vote any posts that you find helpful, it shows what's working..
Jal Panchal
Associate III

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

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
Up vote any posts that you find helpful, it shows what's working..
Jal Panchal
Associate III

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 🙂

//****************************************************************************
 
#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
Up vote any posts that you find helpful, it shows what's working..

Oh wow! Thank you.

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

You need to draw inferences from what people tell you and be able to apply logic and reasoning. Teachers in the US look for students to ask probing questions, not be guided, I think you'll find it a significant cultural difference in approach.

Your options here are to review the code and see what's inferred, or pull a User Manual for the NUCLEO and walk through the circuit diagram. Both would be instructive.

https://www.st.com/content/ccc/resource/technical/document/user_manual/98/2e/fa/4b/e0/82/43/b7/DM00105823.pdf/files/DM00105823.pdf/jcr:content/translations/en.DM00105823.pdf

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

All right, I'll check that.

Thank you.

crequensy
Associate

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