added uart for h743

This commit is contained in:
hathach 2020-07-01 18:27:48 +07:00
parent a512a31c9d
commit 77315ba7ce
1 changed files with 10 additions and 12 deletions

View File

@ -61,6 +61,7 @@ void OTG_HS_IRQHandler(void)
#define BUTTON_PIN GPIO_PIN_13 #define BUTTON_PIN GPIO_PIN_13
#define BUTTON_STATE_ACTIVE 0 #define BUTTON_STATE_ACTIVE 0
// Need to change jumper setting J7 and J8 from RS-232 to STLink
#define UARTx USART1 #define UARTx USART1
#define UART_GPIO_PORT GPIOB #define UART_GPIO_PORT GPIOB
#define UART_GPIO_AF GPIO_AF4_USART1 #define UART_GPIO_AF GPIO_AF4_USART1
@ -74,8 +75,8 @@ static void all_rcc_clk_enable(void)
{ {
__HAL_RCC_GPIOA_CLK_ENABLE(); // LED __HAL_RCC_GPIOA_CLK_ENABLE(); // LED
__HAL_RCC_GPIOC_CLK_ENABLE(); // Button __HAL_RCC_GPIOC_CLK_ENABLE(); // Button
// __HAL_RCC_GPIOB_CLK_ENABLE(); // Uart tx, rx __HAL_RCC_GPIOB_CLK_ENABLE(); // Uart tx, rx
// __HAL_RCC_USART1_CLK_ENABLE(); // Uart module __HAL_RCC_USART1_CLK_ENABLE(); // Uart module
} }
/* PWR, RCC, GPIO (All): AHB4 (D3 domain) /* PWR, RCC, GPIO (All): AHB4 (D3 domain)
@ -197,20 +198,19 @@ void board_init(void)
GPIO_InitTypeDef GPIO_InitStruct; GPIO_InitTypeDef GPIO_InitStruct;
// LED // LED
GPIO_InitStruct.Pin = LED_PIN; GPIO_InitStruct.Pin = LED_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(LED_PORT, &GPIO_InitStruct); HAL_GPIO_Init(LED_PORT, &GPIO_InitStruct);
// Button // Button
GPIO_InitStruct.Pin = BUTTON_PIN; GPIO_InitStruct.Pin = BUTTON_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(BUTTON_PORT, &GPIO_InitStruct); HAL_GPIO_Init(BUTTON_PORT, &GPIO_InitStruct);
#if 0
// Uart // Uart
GPIO_InitStruct.Pin = UART_TX_PIN | UART_RX_PIN; GPIO_InitStruct.Pin = UART_TX_PIN | UART_RX_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
@ -228,7 +228,6 @@ void board_init(void)
UartHandle.Init.Mode = UART_MODE_TX_RX; UartHandle.Init.Mode = UART_MODE_TX_RX;
UartHandle.Init.OverSampling = UART_OVERSAMPLING_16; UartHandle.Init.OverSampling = UART_OVERSAMPLING_16;
HAL_UART_Init(&UartHandle); HAL_UART_Init(&UartHandle);
#endif
#if BOARD_DEVICE_RHPORT_NUM == 0 #if BOARD_DEVICE_RHPORT_NUM == 0
// Despite being call USB2_OTG // Despite being call USB2_OTG
@ -365,8 +364,7 @@ int board_uart_read(uint8_t* buf, int len)
int board_uart_write(void const * buf, int len) int board_uart_write(void const * buf, int len)
{ {
(void) buf; (void) len; HAL_UART_Transmit(&UartHandle, (uint8_t*) buf, len, 0xffff);
// HAL_UART_Transmit(&UartHandle, (uint8_t*) buf, len, 0xffff);
return len; return len;
} }