enable stm32f4 host

This commit is contained in:
hathach
2024-11-07 09:49:04 +07:00
parent 772edf879b
commit 4baeeeb564
25 changed files with 588 additions and 287 deletions

View File

@@ -31,24 +31,36 @@
extern "C" {
#endif
// LED
#define LED_PORT GPIOA
#define LED_PIN GPIO_PIN_6
#define LED_STATE_ON 1
// Button
#define BUTTON_PORT GPIOE
#define BUTTON_PIN GPIO_PIN_4
#define BUTTON_STATE_ACTIVE 0
// Enable PA2 as the debug log UART
// It is not routed to the ST/Link on the Discovery board.
#define UART_DEV USART2
#define UART_GPIO_PORT GPIOA
#define UART_GPIO_AF GPIO_AF7_USART2
#define UART_TX_PIN GPIO_PIN_2
#define UART_RX_PIN GPIO_PIN_3
#define PINID_LED 0
#define PINID_BUTTON 1
#define PINID_UART_TX 2
#define PINID_UART_RX 3
static board_pindef_t board_pindef[] = {
{ // LED
.port = GPIOA,
.pin_init = { .Pin = GPIO_PIN_6, .Mode = GPIO_MODE_OUTPUT_PP, .Pull = GPIO_PULLDOWN, .Speed = GPIO_SPEED_HIGH, .Alternate = 0 },
.active_state = 1
},
{ // BUTTON
.port = GPIOE,
.pin_init = { .Pin = GPIO_PIN_4, .Mode = GPIO_MODE_INPUT, .Pull = GPIO_PULLDOWN, .Speed = GPIO_SPEED_HIGH, .Alternate = 0 },
.active_state = 1
},
{ // UART TX
.port = GPIOA,
.pin_init = { .Pin = GPIO_PIN_2, .Mode = GPIO_MODE_AF_PP, .Pull = GPIO_PULLUP, .Speed = GPIO_SPEED_HIGH, .Alternate = GPIO_AF7_USART2 },
.active_state = 0
},
{ // UART RX
.port = GPIOA,
.pin_init = { .Pin = GPIO_PIN_3, .Mode = GPIO_MODE_AF_PP, .Pull = GPIO_PULLUP, .Speed = GPIO_SPEED_HIGH, .Alternate = GPIO_AF7_USART2 },
.active_state = 0
},
};
//--------------------------------------------------------------------+
// RCC Clock
//--------------------------------------------------------------------+
@@ -86,18 +98,20 @@ static inline void board_clock_init(void)
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);
// Enable clocks for LED, Button, Uart
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOE_CLK_ENABLE();
__HAL_RCC_GPIOH_CLK_ENABLE();
__HAL_RCC_USART2_CLK_ENABLE();
}
static inline void board_vbus_sense_init(void)
{
static inline void board_vbus_sense_init(uint8_t rhport) {
if (rhport == 0) {
// Black F407VET6 doesn't use VBUS sense (B device) explicitly disable it
USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_NOVBUSSENS;
USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBUSBSEN;
USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBUSASEN;
}
}
static inline void board_vbus_set(uint8_t rhport, bool state) {
(void) rhport; (void) state;
}
#ifdef __cplusplus