2018-11-30 03:14 PM
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:
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 ?
2018-11-30 04:59 PM
Which USB port? The one connected to the F103 providing the ST-LINK functionality? Or one you've wired up?
2018-12-03 05:18 AM
I have only made one connection, through the ST Link port.
2018-12-03 05:31 AM
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
2018-12-03 08:05 AM
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 :)
2018-12-03 09:00 AM
//****************************************************************************
#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)
{
}
}
//****************************************************************************
2018-12-03 09:19 AM
Oh wow! Thank you.
This will send data through the ST-LINK connected USB port ? Or I have to make another connection ?
2018-12-03 09:44 AM
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.
2018-12-03 09:50 AM
All right, I'll check that.
Thank you.
2020-03-10 01:34 AM
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