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

@ -20,7 +20,8 @@ SRC_C += \
$(ST_HAL_DRIVER)/Src/stm32f4xx_hal.c \ $(ST_HAL_DRIVER)/Src/stm32f4xx_hal.c \
$(ST_HAL_DRIVER)/Src/stm32f4xx_hal_cortex.c \ $(ST_HAL_DRIVER)/Src/stm32f4xx_hal_cortex.c \
$(ST_HAL_DRIVER)/Src/stm32f4xx_hal_rcc.c \ $(ST_HAL_DRIVER)/Src/stm32f4xx_hal_rcc.c \
$(ST_HAL_DRIVER)/Src/stm32f4xx_hal_gpio.c $(ST_HAL_DRIVER)/Src/stm32f4xx_hal_gpio.c \
$(ST_HAL_DRIVER)/Src/stm32f4xx_hal_uart.c
SRC_S += \ SRC_S += \
$(ST_CMSIS)/Source/Templates/gcc/startup_stm32f405xx.s $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f405xx.s
@ -46,5 +47,5 @@ JLINK_IF = swd
STM32Prog = STM32_Programmer_CLI STM32Prog = STM32_Programmer_CLI
# flash target using on-board stlink # flash target using on-board stlink
flash: $(BUILD)/$(BOARD)-firmware.elf flash: $(BUILD)/$(BOARD)-firmware.bin
$(STM32Prog) --connect port=swd --write $< --go dfu-util -R -a 0 --dfuse-address 0x08000000 -D $<

View File

@ -31,7 +31,7 @@
// Blue LED is chosen because the other LEDs are connected to ST-LINK lines. // Blue LED is chosen because the other LEDs are connected to ST-LINK lines.
#define LED_PORT GPIOC #define LED_PORT GPIOC
#define LED_PIN GPIO_PIN_4 #define LED_PIN GPIO_PIN_1
#define LED_STATE_ON 1 #define LED_STATE_ON 1
// Pin D5 // Pin D5
@ -39,6 +39,24 @@
#define BUTTON_PIN GPIO_PIN_7 #define BUTTON_PIN GPIO_PIN_7
#define BUTTON_STATE_ACTIVE 0 #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 * @brief System Clock Configuration
* The system Clock is configured as follow : * The system Clock is configured as follow :
@ -104,14 +122,13 @@ void board_init(void)
#endif #endif
SystemClock_Config(); SystemClock_Config();
// Notify runtime of frequency change.
SystemCoreClockUpdate(); SystemCoreClockUpdate();
all_rcc_clk_enable();
GPIO_InitTypeDef GPIO_InitStruct; GPIO_InitTypeDef GPIO_InitStruct;
// LED // LED
__HAL_RCC_GPIOC_CLK_ENABLE();
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;
@ -121,19 +138,25 @@ void board_init(void)
board_led_write(false); board_led_write(false);
// Button // Button
//__HAL_RCC_GPIOC_CLK_ENABLE();
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_PULLUP; GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FAST; GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
HAL_GPIO_Init(BUTTON_PORT, &GPIO_InitStruct); 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 // Enable USB OTG clock
__HAL_RCC_USB_OTG_FS_CLK_ENABLE(); __HAL_RCC_USB_OTG_FS_CLK_ENABLE();
// USB Pin Init // USB Pin Init
// PA9- VUSB, PA10- ID, PA11- DM, PA12- DP // PA9- VUSB, PA10- ID, PA11- DM, PA12- DP
__HAL_RCC_GPIOA_CLK_ENABLE();
/* Configure DM DP Pins */ /* Configure DM DP Pins */
GPIO_InitStruct.Pin = GPIO_PIN_11 | GPIO_PIN_12; 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) int board_uart_write(void const * buf, int len)
{ {
(void) buf; (void) len; HAL_UART_Transmit(&UartHandle, (uint8_t*) buf, len, 0xffff);
return 0; return len;
} }
#if CFG_TUSB_OS == OPT_OS_NONE #if CFG_TUSB_OS == OPT_OS_NONE

View File

@ -75,7 +75,7 @@
/* #define HAL_MMC_MODULE_ENABLED */ /* #define HAL_MMC_MODULE_ENABLED */
/* #define HAL_SPI_MODULE_ENABLED */ /* #define HAL_SPI_MODULE_ENABLED */
/* #define HAL_TIM_MODULE_ENABLED */ /* #define HAL_TIM_MODULE_ENABLED */
/* #define HAL_UART_MODULE_ENABLED */ #define HAL_UART_MODULE_ENABLED
/* #define HAL_USART_MODULE_ENABLED */ /* #define HAL_USART_MODULE_ENABLED */
/* #define HAL_IRDA_MODULE_ENABLED */ /* #define HAL_IRDA_MODULE_ENABLED */
/* #define HAL_SMARTCARD_MODULE_ENABLED */ /* #define HAL_SMARTCARD_MODULE_ENABLED */
@ -199,6 +199,8 @@
#define USE_HAL_SPI_REGISTER_CALLBACKS 0U /* SPI register callback disabled */ #define USE_HAL_SPI_REGISTER_CALLBACKS 0U /* SPI register callback disabled */
#define USE_HAL_SWPMI_REGISTER_CALLBACKS 0U /* SWPMI register callback disabled */ #define USE_HAL_SWPMI_REGISTER_CALLBACKS 0U /* SWPMI register callback disabled */
#define USE_HAL_TIM_REGISTER_CALLBACKS 0U /* TIM register callback disabled */ #define USE_HAL_TIM_REGISTER_CALLBACKS 0U /* TIM register callback disabled */
#define USE_HAL_UART_REGISTER_CALLBACKS 0U /* UART register callback disabled */
#define USE_HAL_USART_REGISTER_CALLBACKS 0U /* USART register callback disabled */
#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U /* WWDG register callback disabled */ #define USE_HAL_WWDG_REGISTER_CALLBACKS 0U /* WWDG register callback disabled */
/* ########################## Assert Selection ############################## */ /* ########################## Assert Selection ############################## */

View File

@ -43,9 +43,9 @@
#define UART_TX_PIN GPIO_PIN_9 #define UART_TX_PIN GPIO_PIN_9
#define UART_RX_PIN GPIO_PIN_10 #define UART_RX_PIN GPIO_PIN_10
UART_HandleTypeDef UartHandle; UART_HandleTypeDef UartHandle;
// enable all LED, Button, Uart, USB clock // enable all LED, Button, Uart, USB clock
static void all_rcc_clk_enable(void) static void all_rcc_clk_enable(void)
{ {