mirror of
https://github.com/hathach/tinyusb.git
synced 2025-03-14 04:18:56 +00:00
enable stm32f4 host
This commit is contained in:
parent
772edf879b
commit
4baeeeb564
@ -12,4 +12,5 @@ mcu:MSP432E4
|
||||
mcu:RX65X
|
||||
mcu:RAXXX
|
||||
mcu:MAX3421
|
||||
mcu:STM32F4
|
||||
mcu:STM32F7
|
||||
|
@ -12,4 +12,5 @@ mcu:MSP432E4
|
||||
mcu:RX65X
|
||||
mcu:RAXXX
|
||||
mcu:MAX3421
|
||||
mcu:STM32F4
|
||||
mcu:STM32F7
|
||||
|
@ -6,6 +6,5 @@ set(LD_FILE_GNU ${CMAKE_CURRENT_LIST_DIR}/STM32F405RGTx_FLASH.ld)
|
||||
function(update_board TARGET)
|
||||
target_compile_definitions(${TARGET} PUBLIC
|
||||
STM32F405xx
|
||||
BOARD_TUD_RHPORT=0
|
||||
)
|
||||
endfunction()
|
||||
|
@ -31,22 +31,35 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// LED
|
||||
#define LED_PORT GPIOC
|
||||
#define LED_PIN GPIO_PIN_1
|
||||
#define LED_STATE_ON 1
|
||||
|
||||
// Button: Pin D5
|
||||
#define BUTTON_PORT GPIOC
|
||||
#define BUTTON_PIN GPIO_PIN_7
|
||||
#define BUTTON_STATE_ACTIVE 0
|
||||
|
||||
// UART
|
||||
#define UART_DEV 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
|
||||
|
||||
#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 = GPIOC,
|
||||
.pin_init = { .Pin = GPIO_PIN_4, .Mode = GPIO_MODE_OUTPUT_PP, .Pull = GPIO_PULLDOWN, .Speed = GPIO_SPEED_HIGH, .Alternate = 0 },
|
||||
.active_state = 1
|
||||
},
|
||||
{ // BUTTON
|
||||
.port = GPIOC,
|
||||
.pin_init = { .Pin = GPIO_PIN_7, .Mode = GPIO_MODE_INPUT, .Pull = GPIO_PULLUP, .Speed = GPIO_SPEED_HIGH, .Alternate = 0 },
|
||||
.active_state = 0
|
||||
},
|
||||
{ // UART TX
|
||||
.port = GPIOB,
|
||||
.pin_init = { .Pin = GPIO_PIN_10, .Mode = GPIO_MODE_AF_PP, .Pull = GPIO_PULLUP, .Speed = GPIO_SPEED_HIGH, .Alternate = GPIO_AF7_USART3 },
|
||||
.active_state = 0
|
||||
},
|
||||
{ // UART RX
|
||||
.port = GPIOB,
|
||||
.pin_init = { .Pin = GPIO_PIN_11, .Mode = GPIO_MODE_AF_PP, .Pull = GPIO_PULLUP, .Speed = GPIO_SPEED_HIGH, .Alternate = GPIO_AF7_USART3 },
|
||||
.active_state = 0
|
||||
},
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// RCC Clock
|
||||
@ -84,17 +97,20 @@ static inline void board_clock_init(void)
|
||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
|
||||
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);
|
||||
|
||||
// Enable clocks for LED, Button, Uart
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||
// Enable clocks for Uart
|
||||
__HAL_RCC_USART3_CLK_ENABLE();
|
||||
}
|
||||
|
||||
static inline void board_vbus_sense_init(void)
|
||||
{
|
||||
// Enable VBUS sense (B device) via pin PA9
|
||||
USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_NOVBUSSENS;
|
||||
USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBUSBSEN;
|
||||
static inline void board_vbus_sense_init(uint8_t rhport) {
|
||||
if (rhport == 0) {
|
||||
// Enable VBUS sense (B device) via pin PA9
|
||||
USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_NOVBUSSENS;
|
||||
USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBUSBSEN;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void board_vbus_set(uint8_t rhport, bool state) {
|
||||
(void) rhport; (void) state;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -6,6 +6,5 @@ set(LD_FILE_GNU ${CMAKE_CURRENT_LIST_DIR}/STM32F405RGTx_FLASH.ld)
|
||||
function(update_board TARGET)
|
||||
target_compile_definitions(${TARGET} PUBLIC
|
||||
STM32F405xx
|
||||
BOARD_TUD_RHPORT=0
|
||||
)
|
||||
endfunction()
|
||||
|
@ -31,22 +31,35 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Blue LED is chosen because the other LEDs are connected to ST-LINK lines.
|
||||
#define LED_PORT GPIOB
|
||||
#define LED_PIN GPIO_PIN_4
|
||||
#define LED_STATE_ON 1
|
||||
#define UART_DEV USART2
|
||||
|
||||
#define BUTTON_PORT GPIOB
|
||||
#define BUTTON_PIN GPIO_PIN_3
|
||||
#define BUTTON_STATE_ACTIVE 1
|
||||
#define PINID_LED 0
|
||||
#define PINID_BUTTON 1
|
||||
#define PINID_UART_TX 2
|
||||
#define PINID_UART_RX 3
|
||||
|
||||
// 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
|
||||
static board_pindef_t board_pindef[] = {
|
||||
{ // LED
|
||||
.port = GPIOB,
|
||||
.pin_init = { .Pin = GPIO_PIN_4, .Mode = GPIO_MODE_OUTPUT_PP, .Pull = GPIO_PULLDOWN, .Speed = GPIO_SPEED_HIGH, .Alternate = 0 },
|
||||
.active_state = 1
|
||||
},
|
||||
{ // BUTTON
|
||||
.port = GPIOB,
|
||||
.pin_init = { .Pin = GPIO_PIN_3, .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
|
||||
@ -84,15 +97,20 @@ static inline void board_clock_init(void)
|
||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
|
||||
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);
|
||||
|
||||
// Enable clocks for LED, Button, Uart
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
// Enable clocks for Uart
|
||||
__HAL_RCC_USART2_CLK_ENABLE();
|
||||
}
|
||||
|
||||
static inline void board_vbus_sense_init(void)
|
||||
{
|
||||
// Enable VBUS sense (B device) via pin PA9
|
||||
USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_NOVBUSSENS;
|
||||
USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBUSBSEN;
|
||||
static inline void board_vbus_sense_init(uint8_t rhport) {
|
||||
if (rhport == 0) {
|
||||
// Enable VBUS sense (B device) via pin PA9
|
||||
USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_NOVBUSSENS;
|
||||
USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBUSBSEN;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void board_vbus_set(uint8_t rhport, bool state) {
|
||||
(void) rhport; (void) state;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -6,6 +6,5 @@ set(LD_FILE_GNU ${CMAKE_CURRENT_LIST_DIR}/STM32F401VCTx_FLASH.ld)
|
||||
function(update_board TARGET)
|
||||
target_compile_definitions(${TARGET} PUBLIC
|
||||
STM32F405xx
|
||||
BOARD_TUD_RHPORT=0
|
||||
)
|
||||
endfunction()
|
||||
|
@ -31,23 +31,36 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// LED
|
||||
#define LED_PORT GPIOC
|
||||
#define LED_PIN GPIO_PIN_13
|
||||
#define LED_STATE_ON 0
|
||||
|
||||
// Button
|
||||
#define BUTTON_PORT GPIOA
|
||||
#define BUTTON_PIN GPIO_PIN_0
|
||||
#define BUTTON_STATE_ACTIVE 0
|
||||
|
||||
// Enable PA2 as the debug log UART
|
||||
//#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 UART_DEV USART2
|
||||
|
||||
#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 = GPIOC,
|
||||
.pin_init = { .Pin = GPIO_PIN_13, .Mode = GPIO_MODE_OUTPUT_PP, .Pull = GPIO_PULLUP, .Speed = GPIO_SPEED_HIGH, .Alternate = 0 },
|
||||
.active_state = 0
|
||||
},
|
||||
{ // BUTTON
|
||||
.port = GPIOA,
|
||||
.pin_init = { .Pin = GPIO_PIN_0, .Mode = GPIO_MODE_INPUT, .Pull = GPIO_PULLUP, .Speed = GPIO_SPEED_HIGH, .Alternate = 0 },
|
||||
.active_state = 0
|
||||
},
|
||||
{ // 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
|
||||
@ -85,18 +98,21 @@ static inline void board_clock_init(void)
|
||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
|
||||
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2);
|
||||
|
||||
// Enable clocks for LED, Button, Uart
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||
//__HAL_RCC_USART2_CLK_ENABLE();
|
||||
// Enable clocks for Uart
|
||||
__HAL_RCC_USART2_CLK_ENABLE();
|
||||
}
|
||||
|
||||
static inline void board_vbus_sense_init(void)
|
||||
{
|
||||
static inline void board_vbus_sense_init(uint8_t rhport) {
|
||||
// Blackpill 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;
|
||||
if (rhport == 0) {
|
||||
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
|
||||
|
@ -7,7 +7,5 @@ function(update_board TARGET)
|
||||
target_compile_definitions(${TARGET} PUBLIC
|
||||
STM32F407xx
|
||||
HSE_VALUE=8000000
|
||||
BOARD_TUD_RHPORT=0
|
||||
BOARD_TUD_MAX_SPEED=OPT_MODE_FULL_SPEED
|
||||
)
|
||||
endfunction()
|
||||
|
@ -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
|
||||
|
@ -6,6 +6,5 @@ set(LD_FILE_GNU ${CMAKE_CURRENT_LIST_DIR}/STM32F407VGTx_FLASH.ld)
|
||||
function(update_board TARGET)
|
||||
target_compile_definitions(${TARGET} PUBLIC
|
||||
STM32F407xx
|
||||
BOARD_TUD_RHPORT=0
|
||||
)
|
||||
endfunction()
|
||||
|
@ -31,23 +31,43 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// LED
|
||||
#define LED_PORT GPIOD
|
||||
#define LED_PIN GPIO_PIN_14
|
||||
#define LED_STATE_ON 1
|
||||
|
||||
// Button
|
||||
#define BUTTON_PORT GPIOA
|
||||
#define BUTTON_PIN GPIO_PIN_0
|
||||
#define BUTTON_STATE_ACTIVE 1
|
||||
|
||||
// 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
|
||||
#define PINID_VBUS0_EN 4
|
||||
|
||||
static board_pindef_t board_pindef[] = {
|
||||
{ // LED
|
||||
.port = GPIOD,
|
||||
.pin_init = { .Pin = GPIO_PIN_14, .Mode = GPIO_MODE_OUTPUT_PP, .Pull = GPIO_PULLDOWN, .Speed = GPIO_SPEED_HIGH, .Alternate = 0 },
|
||||
.active_state = 1
|
||||
},
|
||||
{ // BUTTON
|
||||
.port = GPIOA,
|
||||
.pin_init = { .Pin = GPIO_PIN_0, .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
|
||||
},
|
||||
{ // VBUS0 EN
|
||||
.port = GPIOC,
|
||||
.pin_init = { .Pin = GPIO_PIN_0, .Mode = GPIO_MODE_OUTPUT_PP, .Pull = GPIO_NOPULL, .Speed = GPIO_SPEED_HIGH, .Alternate = 0 },
|
||||
.active_state = 0
|
||||
}
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// RCC Clock
|
||||
@ -85,17 +105,23 @@ static inline void board_clock_init(void)
|
||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
|
||||
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);
|
||||
|
||||
// Enable clocks for LED, Button, Uart
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||
// Enable clocks Uart
|
||||
__HAL_RCC_USART2_CLK_ENABLE();
|
||||
}
|
||||
|
||||
static inline void board_vbus_sense_init(void)
|
||||
{
|
||||
// Enable VBUS sense (B device) via pin PA9
|
||||
USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_NOVBUSSENS;
|
||||
USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBUSBSEN;
|
||||
static inline void board_vbus_sense_init(uint8_t rhport) {
|
||||
if (rhport == 0) {
|
||||
// Enable VBUS sense (B device) via pin PA9
|
||||
USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_NOVBUSSENS;
|
||||
USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBUSBSEN;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void board_vbus_set(uint8_t rhport, bool state) {
|
||||
if (rhport == 0) {
|
||||
board_pindef_t* pindef = &board_pindef[PINID_VBUS0_EN];
|
||||
HAL_GPIO_WritePin(pindef->port, pindef->pin_init.Pin, state == pindef->active_state ? GPIO_PIN_SET : GPIO_PIN_RESET);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -6,6 +6,5 @@ set(LD_FILE_GNU ${CMAKE_CURRENT_LIST_DIR}/STM32F411CEUx_FLASH.ld)
|
||||
function(update_board TARGET)
|
||||
target_compile_definitions(${TARGET} PUBLIC
|
||||
STM32F411xE
|
||||
BOARD_TUD_RHPORT=0
|
||||
)
|
||||
endfunction()
|
||||
|
@ -31,23 +31,35 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// LED
|
||||
#define LED_PORT GPIOC
|
||||
#define LED_PIN GPIO_PIN_13
|
||||
#define LED_STATE_ON 0
|
||||
#define UART_DEV USART2
|
||||
|
||||
// Button
|
||||
#define BUTTON_PORT GPIOA
|
||||
#define BUTTON_PIN GPIO_PIN_0
|
||||
#define BUTTON_STATE_ACTIVE 0
|
||||
|
||||
// Enable PA2 as the debug log UART
|
||||
//#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 = GPIOC,
|
||||
.pin_init = { .Pin = GPIO_PIN_13, .Mode = GPIO_MODE_OUTPUT_PP, .Pull = GPIO_PULLUP, .Speed = GPIO_SPEED_HIGH, .Alternate = 0 },
|
||||
.active_state = 0
|
||||
},
|
||||
{ // BUTTON
|
||||
.port = GPIOA,
|
||||
.pin_init = { .Pin = GPIO_PIN_0, .Mode = GPIO_MODE_INPUT, .Pull = GPIO_PULLUP, .Speed = GPIO_SPEED_HIGH, .Alternate = 0 },
|
||||
.active_state = 0
|
||||
},
|
||||
{ // 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
|
||||
@ -85,18 +97,21 @@ static inline void board_clock_init(void)
|
||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
|
||||
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2);
|
||||
|
||||
// Enable clocks for LED, Button, Uart
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||
//__HAL_RCC_USART2_CLK_ENABLE();
|
||||
// Enable clocks for Uart
|
||||
__HAL_RCC_USART2_CLK_ENABLE();
|
||||
}
|
||||
|
||||
static inline void board_vbus_sense_init(void)
|
||||
{
|
||||
static inline void board_vbus_sense_init(uint8_t rhport) {
|
||||
// Blackpill 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;
|
||||
if (rhport == 0) {
|
||||
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
|
||||
|
@ -6,6 +6,5 @@ set(LD_FILE_GNU ${CMAKE_CURRENT_LIST_DIR}/STM32F411VETx_FLASH.ld)
|
||||
function(update_board TARGET)
|
||||
target_compile_definitions(${TARGET} PUBLIC
|
||||
STM32F411xE
|
||||
BOARD_TUD_RHPORT=0
|
||||
)
|
||||
endfunction()
|
||||
|
@ -31,28 +31,46 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Orange LED
|
||||
#define LED_PORT GPIOD
|
||||
#define LED_PIN GPIO_PIN_13
|
||||
#define LED_STATE_ON 1
|
||||
|
||||
#define BUTTON_PORT GPIOA
|
||||
#define BUTTON_PIN GPIO_PIN_0
|
||||
#define BUTTON_STATE_ACTIVE 1
|
||||
|
||||
// Enable PA2 as the debug log UART
|
||||
#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
|
||||
#define PINID_VBUS0_EN 4
|
||||
|
||||
static board_pindef_t board_pindef[] = {
|
||||
{ // LED
|
||||
.port = GPIOD,
|
||||
.pin_init = { .Pin = GPIO_PIN_13, .Mode = GPIO_MODE_OUTPUT_PP, .Pull = GPIO_PULLDOWN, .Speed = GPIO_SPEED_HIGH, .Alternate = 0 },
|
||||
.active_state = 1
|
||||
},
|
||||
{ // BUTTON
|
||||
.port = GPIOA,
|
||||
.pin_init = { .Pin = GPIO_PIN_0, .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
|
||||
},
|
||||
{ // VBUS0 EN
|
||||
.port = GPIOC,
|
||||
.pin_init = { .Pin = GPIO_PIN_0, .Mode = GPIO_MODE_OUTPUT_PP, .Pull = GPIO_NOPULL, .Speed = GPIO_SPEED_HIGH, .Alternate = 0 },
|
||||
.active_state = 0
|
||||
}
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// RCC Clock
|
||||
//--------------------------------------------------------------------+
|
||||
static inline void board_clock_init(void)
|
||||
{
|
||||
static inline void board_clock_init(void) {
|
||||
RCC_ClkInitTypeDef RCC_ClkInitStruct;
|
||||
RCC_OscInitTypeDef RCC_OscInitStruct;
|
||||
|
||||
@ -84,17 +102,23 @@ static inline void board_clock_init(void)
|
||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
|
||||
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2);
|
||||
|
||||
// Enable clocks for LED, Button, Uart
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||
// Enable clocks for UART
|
||||
__HAL_RCC_USART2_CLK_ENABLE();
|
||||
}
|
||||
|
||||
static inline void board_vbus_sense_init(void)
|
||||
{
|
||||
static inline void board_vbus_sense_init(uint8_t rhport) {
|
||||
// Enable VBUS sense (B device) via pin PA9
|
||||
USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_NOVBUSSENS;
|
||||
USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBUSBSEN;
|
||||
if (rhport == 0) {
|
||||
USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_NOVBUSSENS;
|
||||
USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBUSBSEN;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void board_vbus_set(uint8_t rhport, bool state) {
|
||||
if (rhport == 0) {
|
||||
board_pindef_t* pindef = &board_pindef[PINID_VBUS0_EN];
|
||||
HAL_GPIO_WritePin(pindef->port, pindef->pin_init.Pin, state == pindef->active_state ? GPIO_PIN_SET : GPIO_PIN_RESET);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -7,6 +7,5 @@ set(LD_FILE_GNU ${CMAKE_CURRENT_LIST_DIR}/STM32F412ZGTx_FLASH.ld)
|
||||
function(update_board TARGET)
|
||||
target_compile_definitions(${TARGET} PUBLIC
|
||||
STM32F412Zx
|
||||
BOARD_TUD_RHPORT=0
|
||||
)
|
||||
endfunction()
|
||||
|
@ -43,16 +43,45 @@
|
||||
|
||||
// UART Enable PA2 as the debug log UART
|
||||
#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
|
||||
#define PINID_VBUS0_EN 4
|
||||
|
||||
static board_pindef_t board_pindef[] = {
|
||||
{ // LED
|
||||
.port = GPIOE,
|
||||
.pin_init = { .Pin = GPIO_PIN_2, .Mode = GPIO_MODE_OUTPUT_PP, .Pull = GPIO_PULLUP, .Speed = GPIO_SPEED_HIGH, .Alternate = 0 },
|
||||
.active_state = 0
|
||||
},
|
||||
{ // BUTTON
|
||||
.port = GPIOA,
|
||||
.pin_init = { .Pin = GPIO_PIN_0, .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
|
||||
},
|
||||
{ // VBUS0 EN
|
||||
.port = GPIOG,
|
||||
.pin_init = { .Pin = GPIO_PIN_8, .Mode = GPIO_MODE_OUTPUT_PP, .Pull = GPIO_NOPULL, .Speed = GPIO_SPEED_HIGH, .Alternate = 0 },
|
||||
.active_state = 0
|
||||
}
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// RCC Clock
|
||||
//--------------------------------------------------------------------+
|
||||
static inline void board_clock_init(void)
|
||||
{
|
||||
static inline void board_clock_init(void) {
|
||||
RCC_ClkInitTypeDef RCC_ClkInitStruct;
|
||||
RCC_OscInitTypeDef RCC_OscInitStruct;
|
||||
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
|
||||
@ -99,18 +128,25 @@ static inline void board_clock_init(void)
|
||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
|
||||
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3);
|
||||
|
||||
// Enable clocks for LED, Button, Uart
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOE_CLK_ENABLE();
|
||||
// Enable clocks for Uart
|
||||
__HAL_RCC_USART2_CLK_ENABLE();
|
||||
}
|
||||
|
||||
static inline void board_vbus_sense_init(void)
|
||||
{
|
||||
// Enable VBUS sense (B device) via pin PA9
|
||||
USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBDEN;
|
||||
static inline void board_vbus_sense_init(uint8_t rhport) {
|
||||
if (rhport == 0) {
|
||||
// Enable VBUS sense (B device) via pin PA9
|
||||
USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBDEN;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void board_vbus_set(uint8_t rhport, bool state) {
|
||||
if (rhport == 0) {
|
||||
board_pindef_t* pindef = &board_pindef[PINID_VBUS0_EN];
|
||||
HAL_GPIO_WritePin(pindef->port, pindef->pin_init.Pin, state == pindef->active_state ? GPIO_PIN_SET : GPIO_PIN_RESET);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -31,22 +31,42 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// LED
|
||||
#define LED_PORT GPIOB
|
||||
#define LED_PIN GPIO_PIN_14
|
||||
#define LED_STATE_ON 0
|
||||
|
||||
// Button
|
||||
#define BUTTON_PORT GPIOC
|
||||
#define BUTTON_PIN GPIO_PIN_13
|
||||
#define BUTTON_STATE_ACTIVE 1
|
||||
|
||||
// UART Enable for STLink VCOM
|
||||
#define UART_DEV USART3
|
||||
#define UART_GPIO_PORT GPIOD
|
||||
#define UART_GPIO_AF GPIO_AF7_USART3
|
||||
#define UART_TX_PIN GPIO_PIN_8
|
||||
#define UART_RX_PIN GPIO_PIN_9
|
||||
|
||||
#define PINID_LED 0
|
||||
#define PINID_BUTTON 1
|
||||
#define PINID_UART_TX 2
|
||||
#define PINID_UART_RX 3
|
||||
#define PINID_VBUS0_EN 4
|
||||
|
||||
static board_pindef_t board_pindef[] = {
|
||||
{ // LED
|
||||
.port = GPIOB,
|
||||
.pin_init = { .Pin = GPIO_PIN_14, .Mode = GPIO_MODE_OUTPUT_PP, .Pull = GPIO_PULLUP, .Speed = GPIO_SPEED_HIGH, .Alternate = 0 },
|
||||
.active_state = 0
|
||||
},
|
||||
{ // BUTTON
|
||||
.port = GPIOC,
|
||||
.pin_init = { .Pin = GPIO_PIN_13, .Mode = GPIO_MODE_INPUT, .Pull = GPIO_PULLDOWN, .Speed = GPIO_SPEED_HIGH, .Alternate = 0 },
|
||||
.active_state = 1
|
||||
},
|
||||
{ // UART TX
|
||||
.port = GPIOD,
|
||||
.pin_init = { .Pin = GPIO_PIN_8, .Mode = GPIO_MODE_AF_PP, .Pull = GPIO_PULLUP, .Speed = GPIO_SPEED_HIGH, .Alternate = GPIO_AF7_USART3 },
|
||||
.active_state = 0
|
||||
},
|
||||
{ // UART RX
|
||||
.port = GPIOD,
|
||||
.pin_init = { .Pin = GPIO_PIN_9, .Mode = GPIO_MODE_AF_PP, .Pull = GPIO_PULLUP, .Speed = GPIO_SPEED_HIGH, .Alternate = GPIO_AF7_USART3 },
|
||||
.active_state = 0
|
||||
},
|
||||
{ // VBUS0 EN
|
||||
.port = GPIOG,
|
||||
.pin_init = { .Pin = GPIO_PIN_6, .Mode = GPIO_MODE_OUTPUT_PP, .Pull = GPIO_PULLDOWN, .Speed = GPIO_SPEED_HIGH, .Alternate = 0 },
|
||||
.active_state = 1
|
||||
}
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// RCC Clock
|
||||
@ -99,17 +119,22 @@ static inline void board_clock_init(void)
|
||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
|
||||
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3);
|
||||
|
||||
// Enable clocks for LED, Button, Uart
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||
// Enable clocks for Uart
|
||||
__HAL_RCC_USART3_CLK_ENABLE();
|
||||
}
|
||||
|
||||
static inline void board_vbus_sense_init(void)
|
||||
{
|
||||
// Enable VBUS sense (B device) via pin PA9
|
||||
USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBDEN;
|
||||
static inline void board_vbus_sense_init(uint8_t rhport) {
|
||||
if (rhport == 0) {
|
||||
// Enable VBUS sense (B device) via pin PA9
|
||||
USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBDEN;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void board_vbus_set(uint8_t rhport, bool state) {
|
||||
if (rhport == 0) {
|
||||
board_pindef_t* pindef = &board_pindef[PINID_VBUS0_EN];
|
||||
HAL_GPIO_WritePin(pindef->port, pindef->pin_init.Pin, state == pindef->active_state ? GPIO_PIN_SET : GPIO_PIN_RESET);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -31,22 +31,43 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// LED
|
||||
#define LED_PORT GPIOB
|
||||
#define LED_PIN GPIO_PIN_14
|
||||
#define LED_STATE_ON 0
|
||||
|
||||
// Button
|
||||
#define BUTTON_PORT GPIOC
|
||||
#define BUTTON_PIN GPIO_PIN_13
|
||||
#define BUTTON_STATE_ACTIVE 1
|
||||
|
||||
// UART Enable for STLink VCOM
|
||||
#define UART_DEV USART3
|
||||
#define UART_GPIO_PORT GPIOD
|
||||
#define UART_GPIO_AF GPIO_AF7_USART3
|
||||
#define UART_TX_PIN GPIO_PIN_8
|
||||
#define UART_RX_PIN GPIO_PIN_9
|
||||
|
||||
#define PINID_LED 0
|
||||
#define PINID_BUTTON 1
|
||||
#define PINID_UART_TX 2
|
||||
#define PINID_UART_RX 3
|
||||
#define PINID_VBUS0_EN 4
|
||||
|
||||
static board_pindef_t board_pindef[] = {
|
||||
{ // LED
|
||||
.port = GPIOB,
|
||||
.pin_init = { .Pin = GPIO_PIN_14, .Mode = GPIO_MODE_OUTPUT_PP, .Pull = GPIO_PULLUP, .Speed = GPIO_SPEED_HIGH, .Alternate = 0 },
|
||||
.active_state = 0
|
||||
},
|
||||
{ // BUTTON
|
||||
.port = GPIOC,
|
||||
.pin_init = { .Pin = GPIO_PIN_13, .Mode = GPIO_MODE_INPUT, .Pull = GPIO_PULLDOWN, .Speed = GPIO_SPEED_HIGH, .Alternate = 0 },
|
||||
.active_state = 1
|
||||
},
|
||||
{ // UART TX
|
||||
.port = GPIOD,
|
||||
.pin_init = { .Pin = GPIO_PIN_8, .Mode = GPIO_MODE_AF_PP, .Pull = GPIO_PULLUP, .Speed = GPIO_SPEED_HIGH, .Alternate = GPIO_AF7_USART3 },
|
||||
.active_state = 0
|
||||
},
|
||||
{ // UART RX
|
||||
.port = GPIOD,
|
||||
.pin_init = { .Pin = GPIO_PIN_9, .Mode = GPIO_MODE_AF_PP, .Pull = GPIO_PULLUP, .Speed = GPIO_SPEED_HIGH, .Alternate = GPIO_AF7_USART3 },
|
||||
.active_state = 0
|
||||
},
|
||||
{ // VBUS0 EN
|
||||
.port = GPIOG,
|
||||
.pin_init = { .Pin = GPIO_PIN_6, .Mode = GPIO_MODE_OUTPUT_PP, .Pull = GPIO_PULLDOWN, .Speed = GPIO_SPEED_HIGH, .Alternate = 0 },
|
||||
.active_state = 1
|
||||
}
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// RCC Clock
|
||||
@ -87,18 +108,23 @@ static inline void board_clock_init(void)
|
||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
|
||||
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);
|
||||
|
||||
// Enable clocks for LED, Button, Uart
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||
// Enable clocks Uart
|
||||
__HAL_RCC_USART3_CLK_ENABLE();
|
||||
}
|
||||
|
||||
static inline void board_vbus_sense_init(void)
|
||||
{
|
||||
// Enable VBUS sense (B device) via pin PA9
|
||||
USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_NOVBUSSENS;
|
||||
USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBUSBSEN;
|
||||
static inline void board_vbus_sense_init(uint8_t rhport) {
|
||||
if (rhport == 0) {
|
||||
// Enable VBUS sense (B device) via pin PA9
|
||||
USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_NOVBUSSENS;
|
||||
USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBUSBSEN;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void board_vbus_set(uint8_t rhport, bool state) {
|
||||
if (rhport == 0) {
|
||||
board_pindef_t* pindef = &board_pindef[PINID_VBUS0_EN];
|
||||
HAL_GPIO_WritePin(pindef->port, pindef->pin_init.Pin, state == pindef->active_state ? GPIO_PIN_SET : GPIO_PIN_RESET);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -26,6 +26,13 @@
|
||||
|
||||
#include "stm32f4xx_hal.h"
|
||||
#include "bsp/board_api.h"
|
||||
|
||||
typedef struct {
|
||||
GPIO_TypeDef* port;
|
||||
GPIO_InitTypeDef pin_init;
|
||||
uint8_t active_state;
|
||||
} board_pindef_t;
|
||||
|
||||
#include "board.h"
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
@ -42,12 +49,49 @@ void OTG_HS_IRQHandler(void) {
|
||||
//--------------------------------------------------------------------+
|
||||
// MACRO TYPEDEF CONSTANT ENUM
|
||||
//--------------------------------------------------------------------+
|
||||
UART_HandleTypeDef UartHandle;
|
||||
UART_HandleTypeDef UartHandle = {
|
||||
.Instance = UART_DEV,
|
||||
.Init = {
|
||||
.BaudRate = CFG_BOARD_UART_BAUDRATE,
|
||||
.WordLength = UART_WORDLENGTH_8B,
|
||||
.StopBits = UART_STOPBITS_1,
|
||||
.Parity = UART_PARITY_NONE,
|
||||
.HwFlowCtl = UART_HWCONTROL_NONE,
|
||||
.Mode = UART_MODE_TX_RX,
|
||||
.OverSampling = UART_OVERSAMPLING_16
|
||||
}
|
||||
};
|
||||
|
||||
void board_init(void) {
|
||||
board_clock_init();
|
||||
//SystemCoreClockUpdate();
|
||||
|
||||
// Enable All GPIOs clocks
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||
#ifdef __HAL_RCC_GPIOE_CLK_ENABLE
|
||||
__HAL_RCC_GPIOE_CLK_ENABLE();
|
||||
#endif
|
||||
#ifdef __HAL_RCC_GPIOF_CLK_ENABLE
|
||||
__HAL_RCC_GPIOF_CLK_ENABLE();
|
||||
#endif
|
||||
#ifdef __HAL_RCC_GPIOG_CLK_ENABLE
|
||||
__HAL_RCC_GPIOG_CLK_ENABLE();
|
||||
#endif
|
||||
__HAL_RCC_GPIOH_CLK_ENABLE();
|
||||
#ifdef __HAL_RCC_GPIOI_CLK_ENABLE
|
||||
__HAL_RCC_GPIOI_CLK_ENABLE();
|
||||
#endif
|
||||
#ifdef __HAL_RCC_GPIOJ_CLK_ENABLE
|
||||
__HAL_RCC_GPIOJ_CLK_ENABLE();
|
||||
#endif
|
||||
|
||||
for (uint8_t i = 0; i < TU_ARRAY_SIZE(board_pindef); i++) {
|
||||
HAL_GPIO_Init(board_pindef[i].port, &board_pindef[i].pin_init);
|
||||
}
|
||||
|
||||
#if CFG_TUSB_OS == OPT_OS_NONE
|
||||
// 1ms tick timer
|
||||
SysTick_Config(SystemCoreClock / 1000);
|
||||
@ -59,49 +103,14 @@ void board_init(void) {
|
||||
NVIC_SetPriority(OTG_FS_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY );
|
||||
#endif
|
||||
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
|
||||
// LED
|
||||
GPIO_InitStruct.Pin = LED_PIN;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
HAL_GPIO_Init(LED_PORT, &GPIO_InitStruct);
|
||||
|
||||
board_led_write(false);
|
||||
|
||||
// Button
|
||||
GPIO_InitStruct.Pin = BUTTON_PIN;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = BUTTON_STATE_ACTIVE ? GPIO_PULLDOWN : GPIO_PULLUP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
HAL_GPIO_Init(BUTTON_PORT, &GPIO_InitStruct);
|
||||
|
||||
#ifdef UART_DEV
|
||||
// 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);
|
||||
|
||||
UartHandle = (UART_HandleTypeDef) {
|
||||
.Instance = UART_DEV,
|
||||
.Init.BaudRate = CFG_BOARD_UART_BAUDRATE,
|
||||
.Init.WordLength = UART_WORDLENGTH_8B,
|
||||
.Init.StopBits = UART_STOPBITS_1,
|
||||
.Init.Parity = UART_PARITY_NONE,
|
||||
.Init.HwFlowCtl = UART_HWCONTROL_NONE,
|
||||
.Init.Mode = UART_MODE_TX_RX,
|
||||
.Init.OverSampling = UART_OVERSAMPLING_16
|
||||
};
|
||||
HAL_UART_Init(&UartHandle);
|
||||
#endif
|
||||
|
||||
#if BOARD_TUD_RHPORT == 0
|
||||
/* Configure USB FS GPIOs */
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
//------------- USB FS -------------//
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
|
||||
/* Configure USB D+ D- Pins */
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_11 | GPIO_PIN_12;
|
||||
@ -127,11 +136,9 @@ void board_init(void) {
|
||||
|
||||
// Enable USB OTG clock
|
||||
__HAL_RCC_USB_OTG_FS_CLK_ENABLE();
|
||||
#else
|
||||
/* Configure USB HS GPIOs */
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
|
||||
/* Configure USB D+ D- Pins */
|
||||
//------------- USB HS -------------//
|
||||
#ifdef __HAL_RCC_USB_OTG_HS_CLK_ENABLE
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_14 | GPIO_PIN_15;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
@ -166,7 +173,13 @@ void board_init(void) {
|
||||
HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
|
||||
#endif
|
||||
|
||||
board_vbus_sense_init();
|
||||
#if CFG_TUD_ENABLED
|
||||
board_vbus_sense_init(BOARD_TUD_RHPORT);
|
||||
#endif
|
||||
|
||||
#if CFG_TUH_ENABLED
|
||||
board_vbus_set(BOARD_TUD_RHPORT, true);
|
||||
#endif
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
@ -174,12 +187,22 @@ void board_init(void) {
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
void board_led_write(bool state) {
|
||||
GPIO_PinState pin_state = (GPIO_PinState) (state ? LED_STATE_ON : (1 - LED_STATE_ON));
|
||||
HAL_GPIO_WritePin(LED_PORT, LED_PIN, pin_state);
|
||||
#ifdef PINID_LED
|
||||
board_pindef_t* pindef = &board_pindef[PINID_LED];
|
||||
GPIO_PinState pin_state = state == pindef->active_state ? GPIO_PIN_SET : GPIO_PIN_RESET;
|
||||
HAL_GPIO_WritePin(pindef->port, pindef->pin_init.Pin, pin_state);
|
||||
#else
|
||||
(void) state;
|
||||
#endif
|
||||
}
|
||||
|
||||
uint32_t board_button_read(void) {
|
||||
return BUTTON_STATE_ACTIVE == HAL_GPIO_ReadPin(BUTTON_PORT, BUTTON_PIN);
|
||||
#ifdef PINID_BUTTON
|
||||
board_pindef_t* pindef = &board_pindef[PINID_BUTTON];
|
||||
return pindef->active_state == HAL_GPIO_ReadPin(pindef->port, pindef->pin_init.Pin);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
size_t board_get_unique_id(uint8_t id[], size_t max_len) {
|
||||
|
@ -16,6 +16,28 @@ set(CMAKE_TOOLCHAIN_FILE ${TOP}/examples/build_system/cmake/toolchain/arm_${TOOL
|
||||
|
||||
set(FAMILY_MCUS STM32F4 CACHE INTERNAL "")
|
||||
|
||||
# ----------------------
|
||||
# Port & Speed Selection
|
||||
# ----------------------
|
||||
if (NOT DEFINED RHPORT_DEVICE)
|
||||
set(RHPORT_DEVICE 0)
|
||||
endif ()
|
||||
if (NOT DEFINED RHPORT_HOST)
|
||||
set(RHPORT_HOST 0)
|
||||
endif ()
|
||||
|
||||
if (NOT DEFINED RHPORT_SPEED)
|
||||
# Most F7 does not has built-in HS PHY
|
||||
set(RHPORT_SPEED OPT_MODE_FULL_SPEED OPT_MODE_FULL_SPEED)
|
||||
endif ()
|
||||
if (NOT DEFINED RHPORT_DEVICE_SPEED)
|
||||
list(GET RHPORT_SPEED ${RHPORT_DEVICE} RHPORT_DEVICE_SPEED)
|
||||
endif ()
|
||||
if (NOT DEFINED RHPORT_HOST_SPEED)
|
||||
list(GET RHPORT_SPEED ${RHPORT_HOST} RHPORT_HOST_SPEED)
|
||||
endif ()
|
||||
|
||||
cmake_print_variables(RHPORT_DEVICE RHPORT_DEVICE_SPEED RHPORT_HOST RHPORT_HOST_SPEED)
|
||||
|
||||
#------------------------------------
|
||||
# BOARD_TARGET
|
||||
@ -52,8 +74,12 @@ function(add_board_target BOARD_TARGET)
|
||||
${ST_CMSIS}/Include
|
||||
${ST_HAL_DRIVER}/Inc
|
||||
)
|
||||
# target_compile_options(${BOARD_TARGET} PUBLIC)
|
||||
# target_compile_definitions(${BOARD_TARGET} PUBLIC)
|
||||
target_compile_definitions(${BOARD_TARGET} PUBLIC
|
||||
BOARD_TUD_RHPORT=${RHPORT_DEVICE}
|
||||
BOARD_TUD_MAX_SPEED=${RHPORT_DEVICE_SPEED}
|
||||
BOARD_TUH_RHPORT=${RHPORT_HOST}
|
||||
BOARD_TUH_MAX_SPEED=${RHPORT_HOST_SPEED}
|
||||
)
|
||||
|
||||
update_board(${BOARD_TARGET})
|
||||
|
||||
|
@ -8,14 +8,40 @@ ST_HAL_DRIVER = hw/mcu/st/stm32$(ST_FAMILY)xx_hal_driver
|
||||
include $(TOP)/$(BOARD_PATH)/board.mk
|
||||
CPU_CORE ?= cortex-m4
|
||||
|
||||
PORT ?= 0
|
||||
# ----------------------
|
||||
# Port & Speed Selection
|
||||
# ----------------------
|
||||
RHPORT_SPEED ?= OPT_MODE_FULL_SPEED OPT_MODE_FULL_SPEED
|
||||
RHPORT_DEVICE ?= 0
|
||||
RHPORT_HOST ?= 0
|
||||
|
||||
# Determine RHPORT_DEVICE_SPEED if not defined
|
||||
ifndef RHPORT_DEVICE_SPEED
|
||||
ifeq ($(RHPORT_DEVICE), 0)
|
||||
RHPORT_DEVICE_SPEED = $(firstword $(RHPORT_SPEED))
|
||||
else
|
||||
RHPORT_DEVICE_SPEED = $(lastword $(RHPORT_SPEED))
|
||||
endif
|
||||
endif
|
||||
|
||||
# Determine RHPORT_HOST_SPEED if not defined
|
||||
ifndef RHPORT_HOST_SPEED
|
||||
ifeq ($(RHPORT_HOST), 0)
|
||||
RHPORT_HOST_SPEED = $(firstword $(RHPORT_SPEED))
|
||||
else
|
||||
RHPORT_HOST_SPEED = $(lastword $(RHPORT_SPEED))
|
||||
endif
|
||||
endif
|
||||
|
||||
# --------------
|
||||
# Compiler Flags
|
||||
# --------------
|
||||
CFLAGS += \
|
||||
-DCFG_TUSB_MCU=OPT_MCU_STM32F4 \
|
||||
-DBOARD_TUD_RHPORT=$(PORT)
|
||||
-DBOARD_TUD_RHPORT=${RHPORT_DEVICE} \
|
||||
-DBOARD_TUD_MAX_SPEED=${RHPORT_DEVICE_SPEED} \
|
||||
-DBOARD_TUH_RHPORT=${RHPORT_HOST} \
|
||||
-DBOARD_TUH_MAX_SPEED=${RHPORT_HOST_SPEED} \
|
||||
|
||||
# GCC Flags
|
||||
CFLAGS_GCC += \
|
||||
|
@ -16,6 +16,16 @@ set(CMAKE_TOOLCHAIN_FILE ${TOP}/examples/build_system/cmake/toolchain/arm_${TOOL
|
||||
|
||||
set(FAMILY_MCUS STM32F7 CACHE INTERNAL "")
|
||||
|
||||
# ----------------------
|
||||
# Port & Speed Selection
|
||||
# ----------------------
|
||||
if (NOT DEFINED RHPORT_DEVICE)
|
||||
set(RHPORT_DEVICE 0)
|
||||
endif ()
|
||||
if (NOT DEFINED RHPORT_HOST)
|
||||
set(RHPORT_HOST 0)
|
||||
endif ()
|
||||
|
||||
if (NOT DEFINED RHPORT_SPEED)
|
||||
# Most F7 does not has built-in HS PHY
|
||||
set(RHPORT_SPEED OPT_MODE_FULL_SPEED OPT_MODE_FULL_SPEED)
|
||||
|
@ -8,8 +8,12 @@ ST_HAL_DRIVER = hw/mcu/st/stm32$(ST_FAMILY)xx_hal_driver
|
||||
include $(TOP)/$(BOARD_PATH)/board.mk
|
||||
CPU_CORE ?= cortex-m7-fpsp
|
||||
|
||||
# Default RHPORT_SPEED if not defined
|
||||
# ----------------------
|
||||
# Port & Speed Selection
|
||||
# ----------------------
|
||||
RHPORT_SPEED ?= OPT_MODE_FULL_SPEED OPT_MODE_FULL_SPEED
|
||||
RHPORT_DEVICE ?= 0
|
||||
RHPORT_HOST ?= 0
|
||||
|
||||
# Determine RHPORT_DEVICE_SPEED if not defined
|
||||
ifndef RHPORT_DEVICE_SPEED
|
||||
@ -34,20 +38,23 @@ endif
|
||||
# --------------
|
||||
CFLAGS += \
|
||||
-DCFG_TUSB_MCU=OPT_MCU_STM32F7 \
|
||||
-DBOARD_TUD_RHPORT=$(PORT)
|
||||
-DBOARD_TUD_RHPORT=${RHPORT_DEVICE} \
|
||||
-DBOARD_TUD_MAX_SPEED=${RHPORT_DEVICE_SPEED} \
|
||||
-DBOARD_TUH_RHPORT=${RHPORT_HOST} \
|
||||
-DBOARD_TUH_MAX_SPEED=${RHPORT_HOST_SPEED} \
|
||||
|
||||
ifeq ($(PORT), 1)
|
||||
ifeq ($(SPEED), high)
|
||||
CFLAGS += -DBOARD_TUD_MAX_SPEED=OPT_MODE_HIGH_SPEED
|
||||
$(info "Using OTG_HS in HighSpeed mode")
|
||||
else
|
||||
CFLAGS += -DBOARD_TUD_MAX_SPEED=OPT_MODE_FULL_SPEED
|
||||
$(info "Using OTG_HS in FullSpeed mode")
|
||||
endif
|
||||
else
|
||||
CFLAGS += -DBOARD_TUD_MAX_SPEED=OPT_MODE_FULL_SPEED
|
||||
$(info "Using OTG_FS")
|
||||
endif
|
||||
#ifeq ($(PORT), 1)
|
||||
# ifeq ($(SPEED), high)
|
||||
# CFLAGS += -DBOARD_TUD_MAX_SPEED=OPT_MODE_HIGH_SPEED
|
||||
# $(info "Using OTG_HS in HighSpeed mode")
|
||||
# else
|
||||
# CFLAGS += -DBOARD_TUD_MAX_SPEED=OPT_MODE_FULL_SPEED
|
||||
# $(info "Using OTG_HS in FullSpeed mode")
|
||||
# endif
|
||||
#else
|
||||
# CFLAGS += -DBOARD_TUD_MAX_SPEED=OPT_MODE_FULL_SPEED
|
||||
# $(info "Using OTG_FS")
|
||||
#endif
|
||||
|
||||
# GCC Flags
|
||||
CFLAGS_GCC += \
|
||||
|
Loading…
x
Reference in New Issue
Block a user