STM32CubeExpansion_LRWAN : vcom.c -->> vcom_Init( )
Is this function related to UART communication ?
What void " vcom_Init( void (*TxCb)(void) ) " do ?
And what is the argument of this function ?
thanks in advence
Is this function related to UART communication ?
What void " vcom_Init( void (*TxCb)(void) ) " do ?
And what is the argument of this function ?
thanks in advence
Here is a suggestion: forget vcom.c altogether.
Write this function in your code.
/**
* Write to the UART.
*
* Used by printf, puts and other similar functions in stdio. Writes
* at the most ‘length’ bytes and returns the number of bytes written.
*
* @param handle the file handle (unused)
* @param buff a buffer with the string to write
* @param length the number of characters to write
* @return the number of characters written
*/
int
_write(int handle, char *buff, int length) {
(void)handle;
#ifdef DEBUG_WITH_UART
HAL_UART_Transmit(&huart1, (uint8_t *)buff, length, TRANSMISSION_DELAY);
#endif // DEBUG_WITH_UART
return 0;
}Now you can use printf to format and send your code. If you do not define DEBUG_WITH_UART, the function will do nothing and will probably be optimised away.
To initialise the serial port, this is what I use:
/**
* Configure and initialise UART1.
*
* UART1 is configured at 460800 bps, 8N1. DMA is not used, since it
* was tested and interfered with the radio reception.
*/
void
serialPortConfig(void) {
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOA_CLK_ENABLE();
#if defined DEBUG_WITH_UART || !defined USE_STLINK_V2_1
/* Peripheral clock enable */
__HAL_RCC_USART1_CLK_ENABLE();
huart1.Instance = USART1;
huart1.Init.BaudRate = 460800;
huart1.Init.WordLength = UART_WORDLENGTH_8B;
huart1.Init.StopBits = UART_STOPBITS_1;
huart1.Init.Parity = UART_PARITY_NONE;
huart1.Init.Mode = UART_MODE_TX;
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
huart1.Init.OneBitSampling = UART_ONEBIT_SAMPLING_DISABLED;
huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
HAL_UART_Init(&huart1);
/* USART1 GPIO Configuration
PA9 ------> USART1_TX
PA10 ------> USART1_RX
*/
GPIO_InitTypeDef GPIO_InitStruct = {0};
GPIO_InitStruct.Pin = GPIO_PIN_9;// | GPIO_PIN_10;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF4_USART1;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
#endif // DEBUG_WITH_UART
}Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.