• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ HAL_UART_Init函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中HAL_UART_Init函数的典型用法代码示例。如果您正苦于以下问题:C++ HAL_UART_Init函数的具体用法?C++ HAL_UART_Init怎么用?C++ HAL_UART_Init使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了HAL_UART_Init函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:nosnav,项目名称:mastering-stm32,代码行数:15,代码来源:nucleo_hal_bsp.c


示例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);
}
开发者ID:PaxInstruments,项目名称:STM32CubeF4,代码行数:55,代码来源:usbd_cdc_interface.c


示例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(); 
    }
}
开发者ID:asmcos,项目名称:uart411,代码行数:14,代码来源:main.c


示例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);

}
开发者ID:prime5711,项目名称:STM32F4_Example,代码行数:14,代码来源:usart.c


示例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;
}
开发者ID:hampussandberg,项目名称:HexConnect,代码行数:55,代码来源:uart1.c


示例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);

}
开发者ID:OUWECAD,项目名称:MOWE,代码行数:38,代码来源:aos_pd_dma.c


示例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);

}
开发者ID:FRC1640,项目名称:2015-Code,代码行数:15,代码来源:HardwareSerial.cpp


示例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();
	}
}
开发者ID:CynaCons,项目名称:stm32_BluTechDevice,代码行数:16,代码来源:main.c


示例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);

}
开发者ID:La-BlueFrog,项目名称:KickStart-V1,代码行数:15,代码来源:LBF_UART1_Init.c


示例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 :# ");

}
开发者ID:cgroupsupport,项目名称:grrv,代码行数:16,代码来源:uart_test.c


示例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

}
开发者ID:GrandviewIoT,项目名称:Industrial_IoT_Projects,代码行数:48,代码来源:board_L4.c


示例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");
}
开发者ID:Alexander-Wilms,项目名称:STM3240G-EVAL,代码行数:48,代码来源:uart.cpp


示例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)
  {
  }
}
开发者ID:PaxInstruments,项目名称:STM32CubeF3,代码行数:53,代码来源:main.c


示例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);
}
开发者ID:DavidYangShare,项目名称:STM32F030Bootloader,代码行数:25,代码来源:BLE.c


示例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);
}
开发者ID:SethDrake,项目名称:co2monitor,代码行数:16,代码来源:main.cpp


示例16: prvEnableRs232Interface

/**
 * @brief	Enables the RS232 interface with the current settings
 * @param	None
 * @retval	None
 */
static void prvEnableRs232Interface()
{
	/* Enable UART clock */
	__UART4_CLK_ENABLE();

	/* Configure priority and enable interrupt */
	HAL_NVIC_SetPriority(UART4_IRQn, configLIBRARY_LOWEST_INTERRUPT_PRIORITY, 0);
	HAL_NVIC_EnableIRQ(UART4_IRQn);

	/* Enable the UART */
	HAL_UART_Init(&UART_Handle);

	/* If we are in RX mode we should start receiving data */
	if (UART_Handle.Init.Mode == UARTMode_RX || UART_Handle.Init.Mode == UARTMode_TX_RX)
		HAL_UART_Receive_IT(&UART_Handle, &prvReceivedByte, 1);
}
开发者ID:efimefimefim,项目名称:HexConnect,代码行数:21,代码来源:rs232_task.c


示例17: Serial_Config

/*====================================================================================================*/
void Serial_Config( void )
{
  GPIO_InitTypeDef GPIO_InitStruct;

  /* UART Clk ******************************************************************/
  UARTx_TX_GPIO_CLK_ENABLE();
  UARTx_RX_GPIO_CLK_ENABLE();
  UARTx_CLK_ENABLE();

  /* UART Pin ******************************************************************/
  GPIO_InitStruct.Mode      = GPIO_MODE_ANALOG;
  GPIO_InitStruct.Pull      = GPIO_NOPULL;
  GPIO_InitStruct.Speed     = GPIO_SPEED_HIGH;

  GPIO_InitStruct.Pin       = GPIO_PIN_15;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  GPIO_InitStruct.Pin       = GPIO_PIN_7;
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

  GPIO_InitStruct.Mode      = GPIO_MODE_AF_PP;
  GPIO_InitStruct.Pull      = GPIO_PULLUP;
  GPIO_InitStruct.Speed     = GPIO_SPEED_HIGH;

  GPIO_InitStruct.Pin       = UARTx_TX_PIN;
  GPIO_InitStruct.Alternate = UARTx_TX_AF;
  HAL_GPIO_Init(UARTx_TX_GPIO_PORT, &GPIO_InitStruct);

  GPIO_InitStruct.Pin       = UARTx_RX_PIN;
  GPIO_InitStruct.Alternate = UARTx_RX_AF;
  HAL_GPIO_Init(UARTx_RX_GPIO_PORT, &GPIO_InitStruct);

  /* UART Init *****************************************************************/
  Serial_HandleStruct.Instance          = UARTx;
  Serial_HandleStruct.Init.BaudRate     = UARTx_BAUDRATE;
  Serial_HandleStruct.Init.WordLength   = UARTx_BYTESIZE;
  Serial_HandleStruct.Init.StopBits     = UARTx_STOPBITS;
  Serial_HandleStruct.Init.Parity       = UARTx_PARITY;
  Serial_HandleStruct.Init.HwFlowCtl    = UARTx_HARDWARECTRL;
  Serial_HandleStruct.Init.Mode         = UARTx_MODE;
  Serial_HandleStruct.Init.OverSampling = UARTx_OVERSAMPLE;
  HAL_UART_Init(&Serial_HandleStruct);

  /* UART Enable ***************************************************************/
  __HAL_UART_ENABLE(&Serial_HandleStruct);
  __HAL_UART_CLEAR_FLAG(&Serial_HandleStruct, UART_FLAG_TC);
}
开发者ID:KitSprout,项目名称:WheelLED,代码行数:48,代码来源:module_serial.c


示例18: CDC_Init_FS

/**
  * @brief  CDC_Init_FS
  *         Initializes the CDC media low layer over the FS USB IP
  * @param  None
  * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
  */
static int8_t CDC_Init_FS(void)
{
  husb = &hUsbDeviceFS;

  /* Configure the USART with some sensible defaults

     TODO: If possible, don't drive TX high while CDC is "closed"?
   */
  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;
  huart2.Init.OneBitSampling = UART_ONEBIT_SAMPLING_DISABLED ;
  huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
  HAL_UART_Init(&huart2);

  /* Enable USART2 in NVIC, set priority to high */
  NVIC_SetPriority(USART2_IRQn, USART_IRQ_PRIORITY);
  NVIC_EnableIRQ(USART2_IRQn);

  /* UART2 receives data to the CDC transmit buffer, byte at a time :( */
  if(HAL_UART_Receive_IT(&huart2, usart2cdc_rx, 1) != HAL_OK)
    return USBD_FAIL;

  /* Configure USB transmit timer */
  husbtimer.Instance = TIM3;
  husbtimer.Init.Period = 10000 - 1; /* approx 10ms, I think... */
  husbtimer.Init.Prescaler = 48-1;
  husbtimer.Init.ClockDivision = 0;
  husbtimer.Init.CounterMode = TIM_COUNTERMODE_UP;
  if(HAL_TIM_Base_Init(&husbtimer) != HAL_OK)
    return USBD_FAIL;

  __TIM3_CLK_ENABLE();
  NVIC_SetPriority(TIM3_IRQn, USB_TIMER_IRQ_PRIORITY);
  NVIC_EnableIRQ(TIM3_IRQn);

  /* Set Application USB Buffers */
  USBD_CDC_SetTxBuffer(husb, usart2cdc_tx, 0); /* don't send anything now */
  USBD_CDC_SetRxBuffer(husb, cdc2usart_buf_a);     /* read into here if CDC data comes */

  return USBD_OK;
}
开发者ID:pjbirch,项目名称:ESPlant,代码行数:53,代码来源:usbd_cdc_if.c


示例19: serial_set_cts_flow

/*!
 * @brief enable or disable CTS hardware flow control on open device
 * @retval 0 on success
 * @retval -1 on failure
 * @param[in] obj pointer to object instance
 * @param[in] enabled non-zero value enable flow control
 * @note serial port must be opened
 */
int
serial_set_cts_flow(serial *obj, int enable)
{
    struct_uart *uart;
    serial_private *prv;

    prv = (serial_private *)obj->prv;
    uart = (struct_uart *)(prv->fd);

    if (prv->fd < 0) {
        return(-1);
    }
    if(HAL_UART_Init(uart->handle) != HAL_OK){
        return 1;
    }
    return 0;
}
开发者ID:abit-corp,项目名称:phs-shield,代码行数:25,代码来源:serial_posix_api.c


示例20: BLE_BAUD

/*****************************************************************
Name			:	void BLE_BAUD(uint32_t value)
Fuction		:	config the Baud
Input			:	baud value
Output		:	void						
Author		:	@hiyangdong
Version		:	V0.1
Time			:	30 Nov. 2015
*****************************************************************/
void BLE_BAUD(uint32_t value)
{

	BLE_CFG(CFG);
	HAL_Delay(100);
	if(value == 4800) 	HAL_UART_Transmit(&huart2 , "<BAUD4800>",   12, 100);	
	if(value == 9600) 	HAL_UART_Transmit(&huart2 , "<BAUD9600>",   12, 100);
	if(value == 19200)	HAL_UART_Transmit(&huart2 , "<BAUD19200>",  12, 100);
	if(value == 38400)	HAL_UART_Transmit(&huart2 , "<BAUD38400>",  12, 100);
	if(value == 57600)	HAL_UART_Transmit(&huart2 , "<BAUD57600>",  12, 100);
	if(value == 115200) HAL_UART_Transmit(&huart2 , "<BAUD115200>", 12, 100);
	if(value == 256000)	HAL_UART_Transmit(&huart2 , "<BAUD256000>", 12, 100);
	HAL_Delay(100);
	BLE_CFG(TRA);
  huart2.Init.BaudRate = value;
  HAL_UART_Init(&huart2);
}
开发者ID:DavidYangShare,项目名称:STM32F030Bootloader,代码行数:26,代码来源:BLE.c



注:本文中的HAL_UART_Init函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ HAL_UART_Receive_IT函数代码示例发布时间:2022-05-30
下一篇:
C++ HAL_UART_IRQHandler函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap