correct LED, button and uart for feather_stm32f405

This commit is contained in:
hathach
2019-11-09 00:08:32 +07:00
parent 3c49ff153e
commit 943b7467d8
4 changed files with 39 additions and 13 deletions

View File

@@ -31,7 +31,7 @@
// Blue LED is chosen because the other LEDs are connected to ST-LINK lines.
#define LED_PORT GPIOC
#define LED_PIN GPIO_PIN_4
#define LED_PIN GPIO_PIN_1
#define LED_STATE_ON 1
// Pin D5
@@ -39,6 +39,24 @@
#define BUTTON_PIN GPIO_PIN_7
#define BUTTON_STATE_ACTIVE 0
#define UARTx USART3
#define UART_GPIO_PORT GPIOB
#define UART_GPIO_AF GPIO_AF7_USART3
#define UART_TX_PIN GPIO_PIN_10
#define UART_RX_PIN GPIO_PIN_11
UART_HandleTypeDef UartHandle;
// enable all LED, Button, Uart, USB clock
static void all_rcc_clk_enable(void)
{
__HAL_RCC_GPIOA_CLK_ENABLE(); // USB D+, D-
__HAL_RCC_GPIOC_CLK_ENABLE(); // LED, Button
__HAL_RCC_GPIOB_CLK_ENABLE(); // Uart tx, rx
__HAL_RCC_USART3_CLK_ENABLE(); // Uart module
}
/**
* @brief System Clock Configuration
* The system Clock is configured as follow :
@@ -104,14 +122,13 @@ void board_init(void)
#endif
SystemClock_Config();
// Notify runtime of frequency change.
SystemCoreClockUpdate();
all_rcc_clk_enable();
GPIO_InitTypeDef GPIO_InitStruct;
// LED
__HAL_RCC_GPIOC_CLK_ENABLE();
GPIO_InitStruct.Pin = LED_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
@@ -121,19 +138,25 @@ void board_init(void)
board_led_write(false);
// Button
//__HAL_RCC_GPIOC_CLK_ENABLE();
GPIO_InitStruct.Pin = BUTTON_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
HAL_GPIO_Init(BUTTON_PORT, &GPIO_InitStruct);
// Uart
GPIO_InitStruct.Pin = UART_TX_PIN | UART_RX_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Alternate = UART_GPIO_AF;
HAL_GPIO_Init(UART_GPIO_PORT, &GPIO_InitStruct);
// Enable USB OTG clock
__HAL_RCC_USB_OTG_FS_CLK_ENABLE();
// USB Pin Init
// PA9- VUSB, PA10- ID, PA11- DM, PA12- DP
__HAL_RCC_GPIOA_CLK_ENABLE();
/* Configure DM DP Pins */
GPIO_InitStruct.Pin = GPIO_PIN_11 | GPIO_PIN_12;
@@ -180,8 +203,8 @@ int board_uart_read(uint8_t* buf, int len)
int board_uart_write(void const * buf, int len)
{
(void) buf; (void) len;
return 0;
HAL_UART_Transmit(&UartHandle, (uint8_t*) buf, len, 0xffff);
return len;
}
#if CFG_TUSB_OS == OPT_OS_NONE