本文整理汇总了C++中HAL_UART_Init函数的典型用法代码示例。如果您正苦于以下问题:C++ HAL_UART_Init函数的具体用法?C++ HAL_UART_Init怎么用?C++ HAL_UART_Init使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了HAL_UART_Init函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MX_USART2_UART_Init
/* USART2 init function */
void MX_USART2_UART_Init(void)
{
huart2.Instance = USART2;
huart2.Init.BaudRate = 38400;
huart2.Init.WordLength = UART_WORDLENGTH_8B;
huart2.Init.StopBits = UART_STOPBITS_1;
huart2.Init.Parity = UART_PARITY_NONE;
huart2.Init.Mode = UART_MODE_TX_RX;
huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart2.Init.OverSampling = UART_OVERSAMPLING_16;
huart2.Init.OneBitSampling = UART_ONEBIT_SAMPLING_DISABLED ;
huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
HAL_UART_Init(&huart2);
}
示例2: CDC_Itf_Init
/**
* @brief Initializes the CDC media low layer
* @param None
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
*/
static int8_t CDC_Itf_Init(void)
{
/*##-1- Configure the UART peripheral ######################################*/
/* Put the USART peripheral in the Asynchronous mode (UART Mode) */
/* USART 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 = USARTx;
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;
if(HAL_UART_Init(&UartHandle) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
/*##-2- Put UART peripheral in IT reception process ########################*/
/* Any data received will be stored in "UserTxBuffer" buffer */
if(HAL_UART_Receive_IT(&UartHandle, (uint8_t *)UserTxBuffer, 1) != HAL_OK)
{
/* Transfer error in reception process */
Error_Handler();
}
/*##-3- Configure the TIM Base generation #################################*/
TIM_Config();
/*##-4- Start the TIM Base generation in interrupt mode ####################*/
/* Start Channel1 */
if(HAL_TIM_Base_Start_IT(&TimHandle) != HAL_OK)
{
/* Starting Error */
Error_Handler();
}
/*##-5- Set Application Buffers ############################################*/
USBD_CDC_SetTxBuffer(&USBD_Device_HS, UserTxBuffer, 0);
USBD_CDC_SetRxBuffer(&USBD_Device_HS, UserRxBuffer);
return (USBD_OK);
}
示例3: uart_init
static void uart_init(void)
{
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;
if(HAL_UART_Init(&UartHandle) != HAL_OK) {
Error_Handler();
}
}
示例4: MX_USART2_UART_Init
void MX_USART2_UART_Init(void)
{
huart2.Instance = USART2;
huart2.Init.BaudRate = 921600;
huart2.Init.WordLength = UART_WORDLENGTH_8B;
huart2.Init.StopBits = UART_STOPBITS_1;
huart2.Init.Parity = UART_PARITY_NONE;
huart2.Init.Mode = UART_MODE_TX_RX;
huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart2.Init.OverSampling = UART_OVERSAMPLING_16;
HAL_UART_Init(&huart2);
}
示例5: UART1_Init
/**
* @brief Initializes the UART
* @param None
* @retval None
*/
ErrorStatus UART1_Init()
{
/* Make sure we only initialize it once */
if (!prvInitialized)
{
/* Init GPIO */
UART_GPIO_CLK_ENABLE();
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.Pin = UART_TX_PIN;
GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
GPIO_InitStructure.Pull = GPIO_NOPULL;
GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;
HAL_GPIO_Init(UART_PORT, &GPIO_InitStructure);
GPIO_InitStructure.Pin = UART_RX_PIN;
GPIO_InitStructure.Mode = GPIO_MODE_AF_INPUT;
HAL_GPIO_Init(UART_PORT, &GPIO_InitStructure);
/* Init the RX Buffer */
prvRxBufferIn = &prvRxBuffer[0];
prvRxBufferOut = &prvRxBuffer[0];
prvRxBufferCount = 0;
/* Enable UART clock */
__HAL_RCC_USART1_CLK_ENABLE();
/* Init the UART */
UART_Handle.Instance = USART1;
UART_Handle.Init.BaudRate = 115200;
UART_Handle.Init.WordLength = UART_WORDLENGTH_8B;
UART_Handle.Init.StopBits = UART_STOPBITS_1;
UART_Handle.Init.Parity = UART_PARITY_NONE;
UART_Handle.Init.Mode = UART_MODE_TX_RX;
UART_Handle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
if (HAL_UART_Init(&UART_Handle) != HAL_OK)
return ERROR;
/* Enable the UART Data Register not empty Interrupt */
__HAL_UART_ENABLE_IT(&UART_Handle, UART_IT_RXNE);
/* NVIC for USART */
HAL_NVIC_SetPriority(USART1_IRQn, 0, 1);
HAL_NVIC_EnableIRQ(USART1_IRQn);
prvInitialized = true;
return SUCCESS;
}
return ERROR;
}
示例6: UplinkDMA2_Setup
/* Uplink DMA 2 (port-to-port) setup */
void UplinkDMA2_Setup(UART_HandleTypeDef* huartSrc, UART_HandleTypeDef* huartDst)
{
/* UART RX DMA (DMA1 Ch3) */
if (huartSrc->Instance == USART1) {
__HAL_DMA1_REMAP(HAL_DMA1_CH3_USART1_RX);
} else if (huartSrc->Instance == USART2) {
__HAL_DMA1_REMAP(HAL_DMA1_CH3_USART2_RX);
} else if (huartSrc->Instance == USART3) {
__HAL_DMA1_REMAP(HAL_DMA1_CH3_USART3_RX);
} else if (huartSrc->Instance == USART4) {
__HAL_DMA1_REMAP(HAL_DMA1_CH3_USART4_RX);
} else if (huartSrc->Instance == USART5) {
__HAL_DMA1_REMAP(HAL_DMA1_CH3_USART5_RX);
} else if (huartSrc->Instance == USART6) {
__HAL_DMA1_REMAP(HAL_DMA1_CH3_USART6_RX);
} else if (huartSrc->Instance == USART7) {
__HAL_DMA1_REMAP(HAL_DMA1_CH3_USART7_RX);
} else if (huartSrc->Instance == USART8) {
__HAL_DMA1_REMAP(HAL_DMA1_CH3_USART8_RX);
}
__HAL_LINKDMA(huartSrc,hdmarx,uplinkDMA2);
/* Setup streaming baudrate */
huartSrc->Init.BaudRate = 3000000;
HAL_UART_Init(huartSrc);
huartDst->Init.BaudRate = 3000000;
HAL_UART_Init(huartDst);
/* DMA interrupt init */
HAL_NVIC_SetPriority(DMA1_Ch2_3_DMA2_Ch1_2_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(DMA1_Ch2_3_DMA2_Ch1_2_IRQn);
/* Start DMA stream */
huartSrc->State = HAL_UART_STATE_READY;
HAL_UART_Receive_DMA(huartSrc, (uint8_t *)(&(huartDst->Instance->TDR)), 1);
}
示例7: HAL_UART_DeInit
void HardwareSerial::begin(uint32_t baud) {
HAL_StatusTypeDef status;
if ( huart6.Init.BaudRate != baud ) {
HAL_UART_DeInit(&huart6);
huart6.Init.BaudRate = baud;
HAL_UART_Init(&huart6);
}
this->tx_in_progress = false;
this->rx_buffer_bytes_available = 0;
this->rx_buffer_index = 0;
receive_request_pending = false;
status = HAL_UART_Receive_IT(&huart6, &this->rx_buffer[this->rx_buffer_index], 1);
}
示例8: MX_USART6_UART_Init
/* USART6 init function */
static void MX_USART6_UART_Init(void)
{
huart6.Instance = USART6;
huart6.Init.BaudRate = 115200;
huart6.Init.WordLength = UART_WORDLENGTH_8B;
huart6.Init.StopBits = UART_STOPBITS_1;
huart6.Init.Parity = UART_PARITY_NONE;
huart6.Init.Mode = UART_MODE_TX_RX;
huart6.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart6.Init.OverSampling = UART_OVERSAMPLING_16;
if (HAL_UART_Init(&huart6) != HAL_OK)
{
Error_Handler();
}
}
示例9: LBF_UART1_Init
void LBF_UART1_Init (void)
{
// Based on Cube MX
huart1.Instance = USART1;
huart1.Init.BaudRate = 115200;
huart1.Init.WordLength = UART_WORDLENGTH_8B;
huart1.Init.StopBits = UART_STOPBITS_1;
huart1.Init.Parity = UART_PARITY_NONE;
huart1.Init.Mode = UART_MODE_TX_RX;
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
HAL_UART_Init(&huart1);
}
示例10: MX_USART2_UART_Init
/* USART2 init function */
void MX_USART2_UART_Init(void){
huart2.Instance = USART2;
huart2.Init.BaudRate = 115200;
huart2.Init.WordLength = UART_WORDLENGTH_8B;
huart2.Init.StopBits = UART_STOPBITS_1;
huart2.Init.Parity = UART_PARITY_NONE;
huart2.Init.Mode = UART_MODE_TX_RX;
huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart2.Init.OverSampling = UART_OVERSAMPLING_16;
HAL_UART_Init(&huart2);
// initilisation de l'affichage à chaque Reset
SendStr("\n\r UART ");
SendStr("\r\n control :# ");
}
示例11: board_uart_init
void board_uart_init (long baud_rate)
{
// see Clive Example that works fine (uses old Std Lib, not HAL)
//#if defined(USES_CONSOLE_WRITE) || defined(USES_CONSOLE_READ) || defined(USES_DEBUG_LOG)
GPIO_InitTypeDef GPIO_InitStruct;
//--------------------------------------------------
// Configure the GPIOs that used for the UART pins
// Most Nucleos use:
// PA.2 = USART2_TX PA.3 = USART2_RX
// But L4 Discovery uses:
// PD.5 = USART2_TX PD.6 = USART2_RX
//--------------------------------------------------
// change to internal pin_MuxConfig() instead ??? !!! WVD ??? !!!
#if defined(USE_STM32L476G_DISCO_REVB)
GPIO_InitStruct.Pin = GPIO_PIN_5 | GPIO_PIN_6; // PD5 / PD6
#else
GPIO_InitStruct.Pin = GPIO_PIN_2 | GPIO_PIN_3; // PA2 / PA3
#endif
GPIO_InitStruct.Alternate = GPIO_AF7_USART2; // set Alt Function = UART
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
#if defined(USE_STM32L476G_DISCO_REVB)
HAL_GPIO_Init (GPIOD, &GPIO_InitStruct); // Setup UART GPIO D port pins
#else
HAL_GPIO_Init (GPIOA, &GPIO_InitStruct); // Setup UART GPIO A port pins
#endif
//--------------------------------------------------
// Configure the UART module.
//--------------------------------------------------
__HAL_RCC_USART2_CLK_ENABLE(); // Turn on UART clocks
_g_UartHandle.Instance = USART2; // Set UART module to use
_g_UartHandle.Init.BaudRate = baud_rate;
_g_UartHandle.Init.WordLength = UART_WORDLENGTH_8B; // setup as 8N1
_g_UartHandle.Init.StopBits = UART_STOPBITS_1;
_g_UartHandle.Init.Parity = UART_PARITY_NONE; // no parity KEY !
_g_UartHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE; // No flow ctl
_g_UartHandle.Init.OverSampling = UART_OVERSAMPLING_16;
_g_UartHandle.Init.Mode = UART_MODE_TX_RX; // Enable RX and TX
HAL_UART_Init (&_g_UartHandle);
//#endif
}
示例12: USARTx_TX_GPIO_CLK_ENABLE
uart::uart ( void)
{
huart.Instance = USARTx;
huart.Init.BaudRate = 115200;
huart.Init.WordLength = UART_WORDLENGTH_8B;
huart.Init.StopBits = UART_STOPBITS_1;
huart.Init.Parity = UART_PARITY_NONE;
huart.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart.Init.Mode = UART_MODE_TX_RX;
huart.Init.OverSampling = UART_OVERSAMPLING_16;
GPIO_InitTypeDef GPIO_InitStruct;
/*##-1- Enable peripherals and GPIO Clocks #################################*/
/* Enable GPIO TX/RX clock */
USARTx_TX_GPIO_CLK_ENABLE();
USARTx_RX_GPIO_CLK_ENABLE();
/* Enable USART1 clock */
USARTx_CLK_ENABLE();
/*##-2- Configure peripheral GPIO ##########################################*/
/* UART TX GPIO pin configuration */
GPIO_InitStruct.Pin = USARTx_TX_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
GPIO_InitStruct.Alternate = USARTx_TX_AF;
HAL_GPIO_Init(USARTx_TX_GPIO_PORT, &GPIO_InitStruct);
/* UART RX GPIO pin configuration */
GPIO_InitStruct.Pin = USARTx_RX_PIN;
GPIO_InitStruct.Alternate = USARTx_RX_AF;
HAL_GPIO_Init(USARTx_RX_GPIO_PORT, &GPIO_InitStruct);
/*##-3- Configure the NVIC for UART ########################################*/
/* NVIC for USARTx */
HAL_NVIC_SetPriority(USARTx_IRQn, 0, 1);
HAL_NVIC_EnableIRQ(USARTx_IRQn);
if( HAL_UART_Init( &huart) != HAL_OK)
asm("bkpt 0");
HAL_StatusTypeDef status;
status=HAL_UART_Receive_IT( &huart, (uint8_t *)0x01, 1); // dummy call to switch RX on
if( status != HAL_OK)
asm("bkpt 0");
}
示例13: main
/**
* @brief Main program
* @param None
* @retval None
*/
int main(void)
{
/* STM32F3xx HAL library initialization:
- Configure the Flash prefetch
- Configure the Systick to generate an interrupt each 1 msec
- Set NVIC Group Priority to 4
- Low Level Initialization
*/
HAL_Init();
/* Configure the system clock to 64 MHz */
SystemClock_Config();
/* Initialize BSP Led for LED2 */
BSP_LED_Init(LED2);
/*##-1- Configure the UART peripheral ######################################*/
/* Put the USART peripheral in the Asynchronous mode (UART Mode) */
/* UART configured as follows:
- Word Length = 8 Bits (7 data bit + 1 parity bit) :
BE CAREFUL : Program 7 data bits + 1 parity bit in PC HyperTerminal
- Stop Bit = One Stop bit
- Parity = ODD parity
- BaudRate = 9600 baud
- Hardware flow control disabled (RTS and CTS signals) */
UartHandle.Instance = USARTx;
UartHandle.Init.BaudRate = 9600;
UartHandle.Init.WordLength = UART_WORDLENGTH_8B;
UartHandle.Init.StopBits = UART_STOPBITS_1;
UartHandle.Init.Parity = UART_PARITY_ODD;
UartHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
UartHandle.Init.Mode = UART_MODE_TX_RX;
if (HAL_UART_Init(&UartHandle) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
/* Output a message on Hyperterminal using printf function */
printf("\n\r UART Printf Example: retarget the C library printf function to the UART\n\r");
printf("** Test finished successfully. ** \n\r");
/* Infinite loop */
while (1)
{
}
}
示例14: UART_BAUD
/*****************************************************************
Name : void UART_BAUD(uint32_t value)
Fuction : config the uart baud
Input : baud value
Output : void
Author : @hiyangdong
Version : V0.1
Time : 30 Nov. 2015
*****************************************************************/
void UART_BAUD(uint32_t value)
{
#if BLE_UART == huart1
BLE_UART.Instance = USART1;
#elif BLE_UART == huart2
BLE_UART.Instance = USART2;
#endif
BLE_UART.Init.BaudRate = value;
BLE_UART.Init.WordLength = UART_WORDLENGTH_8B;
BLE_UART.Init.StopBits = UART_STOPBITS_1;
BLE_UART.Init.Parity = UART_PARITY_NONE;
BLE_UART.Init.Mode = UART_MODE_TX_RX;
BLE_UART.Init.HwFlowCtl = UART_HWCONTROL_NONE;
BLE_UART.Init.OverSampling = UART_OVERSAMPLING_16;
HAL_UART_Init(&BLE_UART);
}
示例15: USART_Configuration
void USART_Configuration(UART_HandleTypeDef* usartHandle)
{
usartHandle->Instance = USART1;
usartHandle->Init.BaudRate = 9600;
usartHandle->Init.WordLength = UART_WORDLENGTH_8B;
usartHandle->Init.StopBits = UART_STOPBITS_1;
usartHandle->Init.Parity = UART_PARITY_NONE;
usartHandle->Init.HwFlowCtl = UART_HWCONTROL_NONE;
usartHandle->Init.Mode = UART_MODE_TX_RX;
usartHandle->Init.OverSampling = UART_OVERSAMPLING_16;
if (HAL_UART_Init(usartHandle) != HAL_OK)
{
errorHandler("USART_INIT");
}
__HAL_UART_ENABLE(usartHandle);
}