mirror of
https://github.com/hathach/tinyusb.git
synced 2025-01-17 05:32:55 +08:00
update bsp for h7 to support host mode
This commit is contained in:
parent
4baeeeb564
commit
9920ebff4a
@ -4,4 +4,6 @@ board:mcb1800
|
||||
mcu:RP2040
|
||||
mcu:ra6m5
|
||||
mcu:MAX3421
|
||||
mcu:STM32F4
|
||||
mcu:STM32F7
|
||||
mcu:STM32H7
|
||||
|
@ -4,5 +4,6 @@ board:mcb1800
|
||||
mcu:RP2040
|
||||
mcu:ra6m5
|
||||
mcu:MAX3421
|
||||
mcu:STM32H7
|
||||
mcu:STM32F4
|
||||
mcu:STM32F7
|
||||
mcu:STM32H7
|
||||
|
@ -12,3 +12,6 @@ mcu:MSP432E4
|
||||
mcu:RX65X
|
||||
mcu:RAXXX
|
||||
mcu:MAX3421
|
||||
mcu:STM32F4
|
||||
mcu:STM32F7
|
||||
mcu:STM32H7
|
||||
|
@ -14,3 +14,4 @@ mcu:RAXXX
|
||||
mcu:MAX3421
|
||||
mcu:STM32F4
|
||||
mcu:STM32F7
|
||||
mcu:STM32H7
|
||||
|
@ -130,13 +130,12 @@ void tuh_hid_report_received_cb(uint8_t dev_addr, uint8_t instance, uint8_t cons
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// look up new key in previous keys
|
||||
static inline bool find_key_in_report(hid_keyboard_report_t const *report, uint8_t keycode)
|
||||
{
|
||||
for(uint8_t i=0; i<6; i++)
|
||||
{
|
||||
if (report->keycode[i] == keycode) return true;
|
||||
static inline bool find_key_in_report(hid_keyboard_report_t const* report, uint8_t keycode) {
|
||||
for (uint8_t i = 0; i < 6; i++) {
|
||||
if (report->keycode[i] == keycode) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -9,3 +9,6 @@ mcu:MIMXRT11XX
|
||||
mcu:MSP432E4
|
||||
mcu:RX65X
|
||||
mcu:MAX3421
|
||||
mcu:STM32F4
|
||||
mcu:STM32F7
|
||||
mcu:STM32H7
|
||||
|
@ -14,3 +14,6 @@ mcu:RX65X
|
||||
mcu:RAXXX
|
||||
mcu:STM32H7
|
||||
mcu:STM32F7
|
||||
mcu:STM32F4
|
||||
mcu:STM32F7
|
||||
mcu:STM32H7
|
||||
|
@ -12,3 +12,6 @@ mcu:MSP432E4
|
||||
mcu:RX65X
|
||||
mcu:RAXXX
|
||||
mcu:MAX3421
|
||||
mcu:STM32F4
|
||||
mcu:STM32F7
|
||||
mcu:STM32H7
|
||||
|
@ -14,3 +14,4 @@ mcu:RAXXX
|
||||
mcu:MAX3421
|
||||
mcu:STM32F4
|
||||
mcu:STM32F7
|
||||
mcu:STM32H7
|
||||
|
@ -4,9 +4,6 @@ RHPORT_SPEED = OPT_MODE_FULL_SPEED OPT_MODE_HIGH_SPEED
|
||||
RHPORT_DEVICE ?= 1
|
||||
RHPORT_HOST ?= 0
|
||||
|
||||
PORT ?= 1
|
||||
SPEED ?= high
|
||||
|
||||
CFLAGS += \
|
||||
-DSTM32F723xx \
|
||||
-DHSE_VALUE=25000000 \
|
||||
|
@ -8,8 +8,5 @@ function(update_board TARGET)
|
||||
STM32H750xx
|
||||
HSE_VALUE=16000000
|
||||
CORE_CM7
|
||||
# default to PORT 0
|
||||
BOARD_TUD_RHPORT=0
|
||||
BOARD_TUD_MAX_SPEED=OPT_MODE_FULL_SPEED
|
||||
)
|
||||
endfunction()
|
||||
|
@ -31,32 +31,46 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define LED_PORT GPIOC
|
||||
#define LED_PIN GPIO_PIN_7
|
||||
#define LED_STATE_ON 1
|
||||
|
||||
// Blue push-button
|
||||
#define BUTTON_PORT GPIOC
|
||||
#define BUTTON_PIN GPIO_PIN_13
|
||||
#define BUTTON_STATE_ACTIVE 1
|
||||
|
||||
// UART
|
||||
#define UART_DEV USART3
|
||||
#define UART_CLK_EN __HAL_RCC_USART3_CLK_ENABLE
|
||||
#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
|
||||
|
||||
// VBUS Sense detection
|
||||
#define OTG_FS_VBUS_SENSE 1
|
||||
#define OTG_HS_VBUS_SENSE 0
|
||||
|
||||
#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_7, .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_13, .Mode = GPIO_MODE_INPUT, .Pull = GPIO_PULLDOWN, .Speed = GPIO_SPEED_HIGH, .Alternate = 0 },
|
||||
.active_state = 1
|
||||
},
|
||||
{ // 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
|
||||
//--------------------------------------------------------------------+
|
||||
static inline void SystemClock_Config(void)
|
||||
{
|
||||
static inline void SystemClock_Config(void) {
|
||||
RCC_ClkInitTypeDef RCC_ClkInitStruct = { 0 };
|
||||
RCC_OscInitTypeDef RCC_OscInitStruct = { 0 };
|
||||
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = { 0 };
|
||||
@ -128,11 +142,14 @@ static inline void SystemClock_Config(void)
|
||||
HAL_EnableCompensationCell();
|
||||
}
|
||||
|
||||
static inline void board_init2(void)
|
||||
{
|
||||
static inline void board_init2(void) {
|
||||
// For this board does nothing
|
||||
}
|
||||
|
||||
void board_vbus_set(uint8_t rhport, bool state) {
|
||||
(void) rhport; (void) state;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -1,16 +1,8 @@
|
||||
MCU_VARIANT = stm32h750xx
|
||||
CFLAGS += -DSTM32H750xx -DCORE_CM7 -DHSE_VALUE=16000000
|
||||
|
||||
# Default is FulSpeed port
|
||||
PORT ?= 0
|
||||
|
||||
# GCC
|
||||
SRC_S_GCC += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32h750xx.s
|
||||
LD_FILE_GCC = $(BOARD_PATH)/stm32h750ibkx_flash.ld
|
||||
|
||||
# IAR
|
||||
SRC_S_IAR += $(ST_CMSIS)/Source/Templates/iar/startup_stm32h750xx.s
|
||||
LD_FILE_IAR = $(ST_CMSIS)/Source/Templates/iar/linker/stm32h750xx_flash.icf
|
||||
|
||||
# For flash-jlink target
|
||||
JLINK_DEVICE = stm32h750ibk6_m7
|
||||
|
||||
|
@ -7,8 +7,5 @@ function(update_board TARGET)
|
||||
target_compile_definitions(${TARGET} PUBLIC
|
||||
STM32H723xx
|
||||
HSE_VALUE=8000000
|
||||
# default to PORT 0
|
||||
BOARD_TUD_RHPORT=0
|
||||
BOARD_TUD_MAX_SPEED=OPT_MODE_FULL_SPEED
|
||||
)
|
||||
endfunction()
|
||||
|
@ -31,20 +31,8 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define LED_PORT GPIOB
|
||||
#define LED_PIN GPIO_PIN_0
|
||||
#define LED_STATE_ON 1
|
||||
|
||||
#define BUTTON_PORT GPIOC
|
||||
#define BUTTON_PIN GPIO_PIN_13
|
||||
#define BUTTON_STATE_ACTIVE 1
|
||||
|
||||
#define UART_DEV USART3
|
||||
#define UART_CLK_EN __HAL_RCC_USART3_CLK_ENABLE
|
||||
#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
|
||||
|
||||
// VBUS Sense detection
|
||||
#define OTG_FS_VBUS_SENSE 1
|
||||
@ -59,6 +47,40 @@
|
||||
#define GPIO_AF10_OTG2_HS GPIO_AF10_OTG1_HS
|
||||
#define USB_OTG_FS USB_OTG_HS
|
||||
|
||||
#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_0, .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_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 = GPIOD,
|
||||
.pin_init = { .Pin = GPIO_PIN_10, .Mode = GPIO_MODE_OUTPUT_OD, .Pull = GPIO_NOPULL, .Speed = GPIO_SPEED_HIGH, .Alternate = 0 },
|
||||
.active_state = 0
|
||||
}
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// RCC Clock
|
||||
//--------------------------------------------------------------------+
|
||||
@ -118,11 +140,16 @@ static inline void SystemClock_Config(void)
|
||||
HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphCLKInitStruct);
|
||||
}
|
||||
|
||||
static inline void board_init2(void)
|
||||
{
|
||||
static inline void board_init2(void) {
|
||||
// For this board does nothing
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
@ -1,15 +1,7 @@
|
||||
MCU_VARIANT = stm32h723xx
|
||||
CFLAGS += -DSTM32H723xx -DHSE_VALUE=8000000
|
||||
|
||||
# Default is FulSpeed port
|
||||
PORT ?= 0
|
||||
|
||||
# GCC
|
||||
SRC_S_GCC += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32h723xx.s
|
||||
LD_FILE_GCC = $(FAMILY_PATH)/linker/stm32h723xx_flash.ld
|
||||
|
||||
# IAR
|
||||
SRC_S_IAR += $(ST_CMSIS)/Source/Templates/iar/startup_stm32h723xx.s
|
||||
LD_FILE_IAR = $(ST_CMSIS)/Source/Templates/iar/linker/stm32h723xx_flash.icf
|
||||
LD_FILE_GCC = $(FAMILY_PATH)/linker/${MCU_VARIANT}_flash.ld
|
||||
|
||||
# For flash-jlink target
|
||||
JLINK_DEVICE = stm32h723zg
|
||||
|
@ -4,12 +4,26 @@ set(JLINK_OPTION "-USB jtrace")
|
||||
|
||||
set(LD_FILE_GNU ${CMAKE_CURRENT_LIST_DIR}/../../linker/${MCU_VARIANT}_flash.ld)
|
||||
|
||||
set(RHPORT_SPEED OPT_MODE_FULL_SPEED OPT_MODE_HIGH_SPEED)
|
||||
|
||||
# device default to PORT 1 High Speed
|
||||
if (NOT DEFINED RHPORT_DEVICE)
|
||||
set(RHPORT_DEVICE 1)
|
||||
endif()
|
||||
if (NOT DEFINED RHPORT_HOST)
|
||||
set(RHPORT_HOST 0)
|
||||
endif()
|
||||
|
||||
function(update_board TARGET)
|
||||
target_sources(${TARGET} PUBLIC
|
||||
${ST_MFXSTM32L152}/mfxstm32l152.c
|
||||
${ST_MFXSTM32L152}/mfxstm32l152_reg.c
|
||||
)
|
||||
target_include_directories(${TARGET} PUBLIC
|
||||
${ST_MFXSTM32L152}
|
||||
)
|
||||
target_compile_definitions(${TARGET} PUBLIC
|
||||
STM32H743xx
|
||||
HSE_VALUE=25000000
|
||||
# default to PORT 1 High Speed
|
||||
BOARD_TUD_RHPORT=1
|
||||
BOARD_TUD_MAX_SPEED=OPT_MODE_HIGH_SPEED
|
||||
)
|
||||
endfunction()
|
||||
|
@ -33,22 +33,9 @@
|
||||
|
||||
#include "mfxstm32l152.h"
|
||||
|
||||
#define LED_PORT GPIOA
|
||||
#define LED_PIN GPIO_PIN_4
|
||||
#define LED_STATE_ON 1
|
||||
|
||||
// Tamper push-button
|
||||
#define BUTTON_PORT GPIOC
|
||||
#define BUTTON_PIN GPIO_PIN_13
|
||||
#define BUTTON_STATE_ACTIVE 0
|
||||
|
||||
// Need to change jumper setting J7 and J8 from RS-232 to STLink
|
||||
#define UART_DEV USART1
|
||||
#define UART_CLK_EN __HAL_RCC_USART1_CLK_ENABLE
|
||||
#define UART_GPIO_PORT GPIOB
|
||||
#define UART_GPIO_AF GPIO_AF4_USART1
|
||||
#define UART_TX_PIN GPIO_PIN_14
|
||||
#define UART_RX_PIN GPIO_PIN_15
|
||||
|
||||
// VBUS Sense detection
|
||||
#define OTG_FS_VBUS_SENSE 1
|
||||
@ -60,13 +47,43 @@
|
||||
{GPIOB, GPIO_PIN_5 }, {GPIOB, GPIO_PIN_10}, {GPIOB, GPIO_PIN_11}, {GPIOB, GPIO_PIN_12}, \
|
||||
{GPIOB, GPIO_PIN_13}, {GPIOC, GPIO_PIN_0 }, {GPIOH, GPIO_PIN_4 }, {GPIOI, GPIO_PIN_11}
|
||||
|
||||
/* Definition for I2C1 Pins */
|
||||
#define BUS_I2C1_SCL_PIN GPIO_PIN_6
|
||||
#define BUS_I2C1_SDA_PIN GPIO_PIN_7
|
||||
#define BUS_I2C1_SCL_GPIO_PORT GPIOB
|
||||
#define BUS_I2C1_SDA_GPIO_PORT GPIOB
|
||||
#define BUS_I2C1_SCL_AF GPIO_AF4_I2C1
|
||||
#define BUS_I2C1_SDA_AF GPIO_AF4_I2C1
|
||||
#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_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_13, .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_14, .Mode = GPIO_MODE_AF_PP, .Pull = GPIO_PULLUP, .Speed = GPIO_SPEED_HIGH, .Alternate = GPIO_AF4_USART1 },
|
||||
.active_state = 0
|
||||
},
|
||||
{ // UART RX
|
||||
.port = GPIOB,
|
||||
.pin_init = { .Pin = GPIO_PIN_15, .Mode = GPIO_MODE_AF_PP, .Pull = GPIO_PULLUP, .Speed = GPIO_SPEED_HIGH, .Alternate = GPIO_AF4_USART1 },
|
||||
.active_state = 0
|
||||
},
|
||||
{ // I2C SCL for MFX VBUS
|
||||
.port = GPIOB,
|
||||
.pin_init = { .Pin = GPIO_PIN_6, .Mode = GPIO_MODE_AF_OD, .Pull = GPIO_NOPULL, .Speed = GPIO_SPEED_HIGH, .Alternate = GPIO_AF4_I2C1 },
|
||||
.active_state = 0
|
||||
},
|
||||
{ // I2C SDA for MFX VBUS
|
||||
.port = GPIOB,
|
||||
.pin_init = { .Pin = GPIO_PIN_7, .Mode = GPIO_MODE_AF_OD, .Pull = GPIO_NOPULL, .Speed = GPIO_SPEED_HIGH, .Alternate = GPIO_AF4_I2C1 },
|
||||
.active_state = 1
|
||||
},
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// RCC Clock
|
||||
@ -145,141 +162,91 @@ static inline void SystemClock_Config(void) {
|
||||
//--------------------------------------------------------------------+
|
||||
// MFX
|
||||
//--------------------------------------------------------------------+
|
||||
I2C_HandleTypeDef hbus_i2c1 = { .Instance = I2C1};
|
||||
static I2C_HandleTypeDef i2c_handle = {
|
||||
.Instance = I2C1,
|
||||
.Init = {
|
||||
.Timing = 0x10C0ECFF,
|
||||
.OwnAddress1 = 0,
|
||||
.AddressingMode = I2C_ADDRESSINGMODE_7BIT,
|
||||
.DualAddressMode = I2C_DUALADDRESS_DISABLE,
|
||||
.OwnAddress2 = 0,
|
||||
.OwnAddress2Masks = I2C_OA2_NOMASK,
|
||||
.GeneralCallMode = I2C_GENERALCALL_DISABLE,
|
||||
.NoStretchMode = I2C_NOSTRETCH_DISABLE,
|
||||
}
|
||||
};
|
||||
static MFXSTM32L152_Object_t mfx_obj = { 0 };
|
||||
static MFXSTM32L152_IO_Mode_t* mfx_io_drv = NULL;
|
||||
|
||||
HAL_StatusTypeDef MX_I2C1_Init(I2C_HandleTypeDef* hI2c, uint32_t timing) {
|
||||
hI2c->Init.Timing = timing;
|
||||
hI2c->Init.OwnAddress1 = 0;
|
||||
hI2c->Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
|
||||
hI2c->Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
|
||||
hI2c->Init.OwnAddress2 = 0;
|
||||
hI2c->Init.OwnAddress2Masks = I2C_OA2_NOMASK;
|
||||
hI2c->Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
|
||||
hI2c->Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
|
||||
|
||||
if (HAL_I2C_Init(hI2c) != HAL_OK) {
|
||||
return HAL_ERROR;
|
||||
}
|
||||
if (HAL_I2CEx_ConfigAnalogFilter(hI2c, I2C_ANALOGFILTER_ENABLE) != HAL_OK) {
|
||||
return HAL_ERROR;
|
||||
}
|
||||
if (HAL_I2CEx_ConfigDigitalFilter(hI2c, 0) != HAL_OK) {
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
int32_t BSP_I2C1_Init(void) {
|
||||
// Init I2C
|
||||
GPIO_InitTypeDef gpio_init_structure;
|
||||
gpio_init_structure.Pin = BUS_I2C1_SCL_PIN;
|
||||
gpio_init_structure.Mode = GPIO_MODE_AF_OD;
|
||||
gpio_init_structure.Pull = GPIO_NOPULL;
|
||||
gpio_init_structure.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
gpio_init_structure.Alternate = BUS_I2C1_SCL_AF;
|
||||
HAL_GPIO_Init(BUS_I2C1_SCL_GPIO_PORT, &gpio_init_structure);
|
||||
|
||||
gpio_init_structure.Pin = BUS_I2C1_SDA_PIN;
|
||||
gpio_init_structure.Mode = GPIO_MODE_AF_OD;
|
||||
gpio_init_structure.Pull = GPIO_NOPULL;
|
||||
gpio_init_structure.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
gpio_init_structure.Alternate = BUS_I2C1_SDA_AF;
|
||||
HAL_GPIO_Init(BUS_I2C1_SDA_GPIO_PORT, &gpio_init_structure);
|
||||
static MFXSTM32L152_IO_Mode_t* mfx_io = NULL;
|
||||
static uint32_t mfx_vbus_pin[2] = { MFXSTM32L152_GPIO_PIN_7, MFXSTM32L152_GPIO_PIN_9 };
|
||||
|
||||
int32_t board_i2c_init(void) {
|
||||
__HAL_RCC_I2C1_CLK_ENABLE();
|
||||
__HAL_RCC_I2C1_FORCE_RESET();
|
||||
__HAL_RCC_I2C1_RELEASE_RESET();
|
||||
|
||||
if (MX_I2C1_Init(&hbus_i2c1, /*0x10C0ECFF*/ 1890596921) != HAL_OK) {
|
||||
return -1;
|
||||
if (HAL_I2C_Init(&i2c_handle) != HAL_OK) {
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t BSP_I2C1_DeInit(void) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t BSP_I2C1_ReadReg(uint16_t DevAddr, uint16_t Reg, uint8_t *pData, uint16_t Length) {
|
||||
if (HAL_OK != HAL_I2C_Mem_Read(&hbus_i2c1, DevAddr, Reg, I2C_MEMADD_SIZE_8BIT, pData, Length, 10000)) {
|
||||
return -1;
|
||||
if (HAL_I2CEx_ConfigAnalogFilter(&i2c_handle, I2C_ANALOGFILTER_ENABLE) != HAL_OK) {
|
||||
return HAL_ERROR;
|
||||
}
|
||||
if (HAL_I2CEx_ConfigDigitalFilter(&i2c_handle, 0) != HAL_OK) {
|
||||
return HAL_ERROR;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t BSP_I2C1_WriteReg(uint16_t DevAddr, uint16_t Reg, uint8_t *pData, uint16_t Length) {
|
||||
if(HAL_OK != HAL_I2C_Mem_Write(&hbus_i2c1, DevAddr, Reg, I2C_MEMADD_SIZE_8BIT, pData, Length, 10000)) {
|
||||
return -1;
|
||||
}
|
||||
int32_t board_i2c_deinit(void) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t i2c_readreg(uint16_t DevAddr, uint16_t Reg, uint8_t *pData, uint16_t Length) {
|
||||
TU_ASSERT (HAL_OK == HAL_I2C_Mem_Read(&i2c_handle, DevAddr, Reg, I2C_MEMADD_SIZE_8BIT, pData, Length, 10000));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t i2c_writereg(uint16_t DevAddr, uint16_t Reg, uint8_t *pData, uint16_t Length) {
|
||||
TU_ASSERT(HAL_OK == HAL_I2C_Mem_Write(&i2c_handle, DevAddr, Reg, I2C_MEMADD_SIZE_8BIT, pData, Length, 10000));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline void board_init2(void) {
|
||||
// Init MFX IO expanding for vbus drive
|
||||
BSP_I2C1_Init();
|
||||
// IO control via MFX
|
||||
MFXSTM32L152_IO_t io_ctx;
|
||||
io_ctx.Init = board_i2c_init;
|
||||
io_ctx.DeInit = board_i2c_deinit;
|
||||
io_ctx.ReadReg = i2c_readreg;
|
||||
io_ctx.WriteReg = i2c_writereg;
|
||||
io_ctx.GetTick = (MFXSTM32L152_GetTick_Func) HAL_GetTick;
|
||||
|
||||
/* Configure the audio driver */
|
||||
MFXSTM32L152_IO_t IOCtx;
|
||||
IOCtx.Init = BSP_I2C1_DeInit;
|
||||
IOCtx.DeInit = BSP_I2C1_DeInit;
|
||||
IOCtx.ReadReg = BSP_I2C1_ReadReg;
|
||||
IOCtx.WriteReg = BSP_I2C1_WriteReg;
|
||||
IOCtx.GetTick = (MFXSTM32L152_GetTick_Func) HAL_GetTick;
|
||||
|
||||
uint8_t i2c_address[] = {0x84, 0x86};
|
||||
uint16_t i2c_addr[] = { 0x84, 0x86 };
|
||||
for(uint8_t i = 0U; i < 2U; i++) {
|
||||
uint32_t mfx_id;
|
||||
IOCtx.Address = (uint16_t)i2c_address[i];
|
||||
if (MFXSTM32L152_RegisterBusIO(&mfx_obj, &IOCtx) != MFXSTM32L152_OK) {
|
||||
return;
|
||||
}
|
||||
if (MFXSTM32L152_ReadID(&mfx_obj, &mfx_id) != MFXSTM32L152_OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
io_ctx.Address = i2c_addr[i];
|
||||
TU_ASSERT(MFXSTM32L152_RegisterBusIO(&mfx_obj, &io_ctx) == MFXSTM32L152_OK, );
|
||||
TU_ASSERT(MFXSTM32L152_ReadID(&mfx_obj, &mfx_id) == MFXSTM32L152_OK, );
|
||||
if ((mfx_id == MFXSTM32L152_ID) || (mfx_id == MFXSTM32L152_ID_2)) {
|
||||
if (MFXSTM32L152_Init(&mfx_obj) != MFXSTM32L152_OK) {
|
||||
return;
|
||||
}
|
||||
TU_ASSERT(MFXSTM32L152_Init(&mfx_obj) == MFXSTM32L152_OK, );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
mfx_io_drv = &MFXSTM32L152_IO_Driver;
|
||||
mfx_io = &MFXSTM32L152_IO_Driver;
|
||||
mfx_io->IO_Start(&mfx_obj, MFXSTM32L152_GPIO_PINS_ALL);
|
||||
|
||||
static MFXSTM32L152_IO_Init_t io_init = { 0 };
|
||||
mfx_io_drv->Init(&mfx_obj, &io_init);
|
||||
|
||||
io_init.Pin = MFXSTM32L152_GPIO_PIN_7;
|
||||
io_init.Mode = MFXSTM32L152_GPIO_MODE_OUTPUT_PP;
|
||||
io_init.Pull = MFXSTM32L152_GPIO_PULLUP;
|
||||
mfx_io_drv->Init(&mfx_obj, &io_init); // VBUS[0]
|
||||
|
||||
io_init.Pin = MFXSTM32L152_GPIO_PIN_9;
|
||||
mfx_io_drv->Init(&mfx_obj, &io_init); // VBUS[1]
|
||||
|
||||
#if 1 // write then read IO7 but it does not seems to change value
|
||||
int32_t pin_value;
|
||||
pin_value = mfx_io_drv->IO_ReadPin(&mfx_obj, MFXSTM32L152_GPIO_PIN_7);
|
||||
TU_LOG1_INT(pin_value);
|
||||
|
||||
mfx_io_drv->IO_WritePin(&mfx_obj, MFXSTM32L152_GPIO_PIN_7, 1);
|
||||
|
||||
pin_value = mfx_io_drv->IO_ReadPin(&mfx_obj, MFXSTM32L152_GPIO_PIN_7);
|
||||
TU_LOG1_INT(pin_value);
|
||||
#endif
|
||||
for(uint32_t i=0; i<2; i++) {
|
||||
MFXSTM32L152_IO_Init_t io_init = {
|
||||
.Pin = mfx_vbus_pin[i],
|
||||
.Mode = MFXSTM32L152_GPIO_MODE_OUTPUT_PP,
|
||||
.Pull = MFXSTM32L152_GPIO_PULLUP,
|
||||
};
|
||||
mfx_io->Init(&mfx_obj, &io_init);
|
||||
}
|
||||
}
|
||||
|
||||
// vbus drive
|
||||
// VBUS1 is actually controlled by USB3320C PHY (using dwc2 drivebus signal)
|
||||
void board_vbus_set(uint8_t rhport, bool state) {
|
||||
if ( mfx_io_drv ) {
|
||||
uint32_t io_pin = (_rhport) ? MFXSTM32L152_GPIO_PIN_9 : MFXSTM32L152_GPIO_PIN_7;
|
||||
mfx_io_drv->IO_WritePin(&Io_CompObj, io_pin, _on);
|
||||
if (mfx_io) {
|
||||
mfx_io->IO_WritePin(&mfx_obj, mfx_vbus_pin[rhport], state);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,16 +1,17 @@
|
||||
MCU_VARIANT = stm32h743xx
|
||||
CFLAGS += -DSTM32H743xx -DHSE_VALUE=25000000
|
||||
|
||||
# Default is Highspeed port
|
||||
PORT ?= 1
|
||||
SPEED ?= high
|
||||
RHPORT_SPEED = OPT_MODE_FULL_SPEED OPT_MODE_HIGH_SPEED
|
||||
RHPORT_DEVICE ?= 1
|
||||
RHPORT_HOST ?= 0
|
||||
|
||||
# GCC
|
||||
SRC_S_GCC += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32h743xx.s
|
||||
LD_FILE_GCC = $(FAMILY_PATH)/linker/stm32h743xx_flash.ld
|
||||
LD_FILE_GCC = $(FAMILY_PATH)/linker/${MCU_VARIANT}_flash.ld
|
||||
|
||||
# IAR
|
||||
SRC_S_IAR += $(ST_CMSIS)/Source/Templates/iar/startup_stm32h743xx.s
|
||||
LD_FILE_IAR = $(ST_CMSIS)/Source/Templates/iar/linker/stm32h743xx_flash.icf
|
||||
SRC_C += \
|
||||
${ST_MFXSTM32L152}/mfxstm32l152.c \
|
||||
${ST_MFXSTM32L152}/mfxstm32l152_reg.c \
|
||||
|
||||
INC += $(TOP)/${ST_MFXSTM32L152}
|
||||
|
||||
# For flash-jlink target
|
||||
JLINK_DEVICE = stm32h743xi
|
||||
|
@ -7,8 +7,5 @@ function(update_board TARGET)
|
||||
target_compile_definitions(${TARGET} PUBLIC
|
||||
STM32H743xx
|
||||
HSE_VALUE=8000000
|
||||
# default to PORT 0
|
||||
BOARD_TUD_RHPORT=0
|
||||
BOARD_TUD_MAX_SPEED=OPT_MODE_FULL_SPEED
|
||||
)
|
||||
endfunction()
|
||||
|
@ -31,25 +31,47 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define LED_PORT GPIOB
|
||||
#define LED_PIN GPIO_PIN_0
|
||||
#define LED_STATE_ON 1
|
||||
|
||||
#define BUTTON_PORT GPIOC
|
||||
#define BUTTON_PIN GPIO_PIN_13
|
||||
#define BUTTON_STATE_ACTIVE 1
|
||||
|
||||
#define UART_DEV USART3
|
||||
#define UART_CLK_EN __HAL_RCC_USART3_CLK_ENABLE
|
||||
#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
|
||||
|
||||
// VBUS Sense detection
|
||||
#define OTG_FS_VBUS_SENSE 1
|
||||
#define OTG_HS_VBUS_SENSE 0
|
||||
|
||||
#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_0, .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_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 = GPIOD,
|
||||
.pin_init = { .Pin = GPIO_PIN_10, .Mode = GPIO_MODE_OUTPUT_OD, .Pull = GPIO_NOPULL, .Speed = GPIO_SPEED_HIGH, .Alternate = 0 },
|
||||
.active_state = 0
|
||||
}
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// RCC Clock
|
||||
//--------------------------------------------------------------------+
|
||||
@ -100,8 +122,7 @@ static inline void SystemClock_Config(void) {
|
||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV2;
|
||||
RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV2;
|
||||
|
||||
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
|
||||
{
|
||||
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
@ -116,17 +137,21 @@ static inline void SystemClock_Config(void) {
|
||||
PeriphClkInitStruct.PLL3.PLL3RGE = RCC_PLL3VCIRANGE_3;
|
||||
PeriphClkInitStruct.PLL3.PLL3FRACN = 0;
|
||||
PeriphClkInitStruct.UsbClockSelection = RCC_USBCLKSOURCE_PLL3;
|
||||
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
|
||||
{
|
||||
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
}
|
||||
|
||||
static inline void board_init2(void)
|
||||
{
|
||||
static inline void board_init2(void) {
|
||||
// For this board does nothing
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
@ -1,15 +1,7 @@
|
||||
MCU_VARIANT = stm32h743xx
|
||||
CFLAGS += -DSTM32H743xx -DHSE_VALUE=8000000
|
||||
|
||||
# Default is FulSpeed port
|
||||
PORT ?= 0
|
||||
|
||||
# GCC
|
||||
SRC_S_GCC += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32h743xx.s
|
||||
LD_FILE_GCC = $(FAMILY_PATH)/linker/stm32h743xx_flash.ld
|
||||
|
||||
# IAR
|
||||
SRC_S_IAR += $(ST_CMSIS)/Source/Templates/iar/startup_stm32h743xx.s
|
||||
LD_FILE_IAR = $(ST_CMSIS)/Source/Templates/iar/linker/stm32h743xx_flash.icf
|
||||
LD_FILE_GCC = $(FAMILY_PATH)/linker/${MCU_VARIANT}_flash.ld
|
||||
|
||||
# For flash-jlink target
|
||||
JLINK_DEVICE = stm32h743zi
|
||||
|
@ -9,8 +9,5 @@ function(update_board TARGET)
|
||||
STM32H745xx
|
||||
HSE_VALUE=25000000
|
||||
CORE_CM7
|
||||
# default to PORT 0
|
||||
BOARD_TUD_RHPORT=0
|
||||
BOARD_TUD_MAX_SPEED=OPT_MODE_FULL_SPEED
|
||||
)
|
||||
endfunction()
|
||||
|
@ -31,27 +31,48 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define LED_PORT GPIOJ
|
||||
#define LED_PIN GPIO_PIN_2
|
||||
#define LED_STATE_ON 1
|
||||
|
||||
// Blue push-button
|
||||
#define BUTTON_PORT GPIOC
|
||||
#define BUTTON_PIN GPIO_PIN_13
|
||||
#define BUTTON_STATE_ACTIVE 1
|
||||
|
||||
// UART
|
||||
#define UART_DEV USART3
|
||||
#define UART_CLK_EN __HAL_RCC_USART3_CLK_ENABLE
|
||||
#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
|
||||
|
||||
// VBUS Sense detection
|
||||
#define OTG_FS_VBUS_SENSE 1
|
||||
#define OTG_HS_VBUS_SENSE 0
|
||||
|
||||
#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 = GPIOJ,
|
||||
.pin_init = { .Pin = GPIO_PIN_2, .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_13, .Mode = GPIO_MODE_INPUT, .Pull = GPIO_PULLDOWN, .Speed = GPIO_SPEED_HIGH, .Alternate = 0 },
|
||||
.active_state = 1
|
||||
},
|
||||
{ // 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
|
||||
},
|
||||
{ // VBUS0 EN
|
||||
.port = GPIOA,
|
||||
.pin_init = { .Pin = GPIO_PIN_5, .Mode = GPIO_MODE_OUTPUT_OD, .Pull = GPIO_NOPULL, .Speed = GPIO_SPEED_HIGH, .Alternate = 0 },
|
||||
.active_state = 1
|
||||
}
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// RCC Clock
|
||||
//--------------------------------------------------------------------+
|
||||
@ -127,11 +148,17 @@ static inline void SystemClock_Config(void)
|
||||
HAL_EnableCompensationCell();
|
||||
}
|
||||
|
||||
static inline void board_init2(void)
|
||||
{
|
||||
static inline void board_init2(void) {
|
||||
// For this board does nothing
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -1,17 +1,12 @@
|
||||
# STM32H745I-DISCO uses OTG_FS
|
||||
# FIXME: Reset enumerates, un/replug USB plug does not enumerate
|
||||
|
||||
MCU_VARIANT = stm32h745xx
|
||||
CFLAGS += -DSTM32H745xx -DCORE_CM7 -DHSE_VALUE=25000000
|
||||
|
||||
# Default is FulSpeed port
|
||||
PORT ?= 0
|
||||
|
||||
# GCC
|
||||
SRC_S_GCC += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32h745xx.s
|
||||
LD_FILE_GCC = $(ST_CMSIS)/Source/Templates/gcc/linker/stm32h745xx_flash_CM7.ld
|
||||
|
||||
# IAR
|
||||
SRC_S_IAR += $(ST_CMSIS)/Source/Templates/iar/startup_stm32h745xx.s
|
||||
LD_FILE_IAR = $(ST_CMSIS)/Source/Templates/iar/linker/stm32h745xx_flash_CM7.icf
|
||||
|
||||
# For flash-jlink target
|
||||
|
@ -9,8 +9,5 @@ function(update_board TARGET)
|
||||
STM32H750xx
|
||||
HSE_VALUE=25000000
|
||||
CORE_CM7
|
||||
# default to PORT 0
|
||||
BOARD_TUD_RHPORT=0
|
||||
BOARD_TUD_MAX_SPEED=OPT_MODE_FULL_SPEED
|
||||
)
|
||||
endfunction()
|
||||
|
@ -31,27 +31,42 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define LED_PORT GPIOE
|
||||
#define LED_PIN GPIO_PIN_3
|
||||
#define LED_STATE_ON 1
|
||||
|
||||
// Blue push-button
|
||||
#define BUTTON_PORT GPIOC
|
||||
#define BUTTON_PIN GPIO_PIN_13
|
||||
#define BUTTON_STATE_ACTIVE 1
|
||||
|
||||
// UART
|
||||
//#define UART_DEV USART3
|
||||
//#define UART_CLK_EN __HAL_RCC_USART3_CLK_ENABLE
|
||||
//#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 UART_DEV USART3
|
||||
#define UART_CLK_EN __HAL_RCC_USART3_CLK_ENABLE
|
||||
|
||||
// VBUS Sense detection
|
||||
#define OTG_FS_VBUS_SENSE 1
|
||||
#define OTG_HS_VBUS_SENSE 0
|
||||
|
||||
#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 = GPIOE,
|
||||
.pin_init = { .Pin = GPIO_PIN_3, .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_13, .Mode = GPIO_MODE_INPUT, .Pull = GPIO_PULLDOWN, .Speed = GPIO_SPEED_HIGH, .Alternate = 0 },
|
||||
.active_state = 1
|
||||
},
|
||||
{ // 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
|
||||
//--------------------------------------------------------------------+
|
||||
@ -125,6 +140,10 @@ static inline void board_init2(void) {
|
||||
// For this board does nothing
|
||||
}
|
||||
|
||||
void board_vbus_set(uint8_t rhport, bool state) {
|
||||
(void) rhport; (void) state;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -1,19 +1,10 @@
|
||||
# STM32H745I-DISCO uses OTG_FS
|
||||
# FIXME: Reset enumerates, un/replug USB plug does not enumerate
|
||||
|
||||
MCU_VARIANT = stm32h750xx
|
||||
CFLAGS += -DSTM32H750xx -DCORE_CM7 -DHSE_VALUE=25000000
|
||||
|
||||
# Default is FulSpeed port
|
||||
PORT ?= 0
|
||||
|
||||
# GCC
|
||||
SRC_S_GCC += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32h750xx.s
|
||||
LD_FILE_GCC = $(BOARD_PATH)/stm32h750xx_flash_CM7.ld
|
||||
|
||||
# IAR
|
||||
SRC_S_IAR += $(ST_CMSIS)/Source/Templates/iar/startup_stm32h750xx.s
|
||||
LD_FILE_IAR = $(ST_CMSIS)/Source/Templates/iar/linker/stm32h750xx_flash.icf
|
||||
|
||||
# For flash-jlink target
|
||||
JLINK_DEVICE = stm32h750vb
|
||||
|
||||
|
@ -9,8 +9,5 @@ function(update_board TARGET)
|
||||
STM32H750xx
|
||||
HSE_VALUE=25000000
|
||||
CORE_CM7
|
||||
# default to PORT 0
|
||||
BOARD_TUD_RHPORT=0
|
||||
BOARD_TUD_MAX_SPEED=OPT_MODE_FULL_SPEED
|
||||
)
|
||||
endfunction()
|
||||
|
@ -31,33 +31,47 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define LED_PORT GPIOJ
|
||||
#define LED_PIN GPIO_PIN_2
|
||||
#define LED_STATE_ON 1
|
||||
|
||||
// Blue push-button
|
||||
#define BUTTON_PORT GPIOC
|
||||
#define BUTTON_PIN GPIO_PIN_13
|
||||
#define BUTTON_STATE_ACTIVE 1
|
||||
|
||||
// UART
|
||||
#define UART_DEV USART3
|
||||
#define UART_CLK_EN __HAL_RCC_USART3_CLK_ENABLE
|
||||
#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
|
||||
|
||||
// VBUS Sense detection
|
||||
#define OTG_FS_VBUS_SENSE 1
|
||||
#define OTG_HS_VBUS_SENSE 0
|
||||
|
||||
// USB HS External PHY Pin: CLK, STP, DIR, NXT, D0-D7
|
||||
#define ULPI_PINS \
|
||||
{GPIOA, GPIO_PIN_3 }, {GPIOA, GPIO_PIN_5 }, {GPIOB, GPIO_PIN_0 }, {GPIOB, GPIO_PIN_1 }, \
|
||||
{GPIOB, GPIO_PIN_5 }, {GPIOB, GPIO_PIN_10}, {GPIOB, GPIO_PIN_11}, {GPIOB, GPIO_PIN_12}, \
|
||||
{GPIOB, GPIO_PIN_13}, {GPIOC, GPIO_PIN_0 }, {GPIOH, GPIO_PIN_4 }, {GPIOI, GPIO_PIN_11}
|
||||
#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 = GPIOJ,
|
||||
.pin_init = { .Pin = GPIO_PIN_2, .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_13, .Mode = GPIO_MODE_INPUT, .Pull = GPIO_PULLDOWN, .Speed = GPIO_SPEED_HIGH, .Alternate = 0 },
|
||||
.active_state = 1
|
||||
},
|
||||
{ // 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
|
||||
},
|
||||
{ // VBUS0 EN
|
||||
.port = GPIOA,
|
||||
.pin_init = { .Pin = GPIO_PIN_5, .Mode = GPIO_MODE_OUTPUT_OD, .Pull = GPIO_NOPULL, .Speed = GPIO_SPEED_HIGH, .Alternate = 0 },
|
||||
.active_state = 1
|
||||
}
|
||||
};
|
||||
//--------------------------------------------------------------------+
|
||||
// RCC Clock
|
||||
//--------------------------------------------------------------------+
|
||||
@ -132,11 +146,17 @@ static inline void SystemClock_Config(void)
|
||||
HAL_EnableCompensationCell();
|
||||
}
|
||||
|
||||
static inline void board_init2(void)
|
||||
{
|
||||
static inline void board_init2(void) {
|
||||
// For this board does nothing
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -1,19 +1,10 @@
|
||||
# STM32H745I-DISCO uses OTG_FS
|
||||
# FIXME: Reset enumerates, un/replug USB plug does not enumerate
|
||||
|
||||
MCU_VARIANT = stm32h750xx
|
||||
CFLAGS += -DSTM32H750xx -DCORE_CM7 -DHSE_VALUE=25000000
|
||||
|
||||
# Default is FulSpeed port
|
||||
PORT ?= 0
|
||||
|
||||
# GCC
|
||||
SRC_S_GCC += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32h750xx.s
|
||||
LD_FILE_GCC = $(BOARD_PATH)/stm32h750xx_flash_CM7.ld
|
||||
|
||||
# IAR
|
||||
SRC_S_IAR += $(ST_CMSIS)/Source/Templates/iar/startup_stm32h750xx.s
|
||||
LD_FILE_IAR = $(ST_CMSIS)/Source/Templates/iar/linker/stm32h750xx_flash.icf
|
||||
|
||||
# For flash-jlink target
|
||||
JLINK_DEVICE = stm32h750xb
|
||||
|
||||
|
@ -3,14 +3,21 @@ set(JLINK_DEVICE stm32h743xi)
|
||||
|
||||
set(LD_FILE_GNU ${CMAKE_CURRENT_LIST_DIR}/../../linker/${MCU_VARIANT}_flash.ld)
|
||||
|
||||
set(RHPORT_SPEED OPT_MODE_FULL_SPEED OPT_MODE_HIGH_SPEED)
|
||||
|
||||
# device default to PORT 1 High Speed
|
||||
if (NOT DEFINED RHPORT_DEVICE)
|
||||
set(RHPORT_DEVICE 1)
|
||||
endif()
|
||||
if (NOT DEFINED RHPORT_HOST)
|
||||
set(RHPORT_HOST 0)
|
||||
endif()
|
||||
|
||||
function(update_board TARGET)
|
||||
target_compile_definitions(${TARGET} PUBLIC
|
||||
STM32H743xx
|
||||
HSE_VALUE=8000000
|
||||
HAL_TIM_MODULE_ENABLED
|
||||
# default to PORT 1 High Speed
|
||||
BOARD_TUD_RHPORT=1
|
||||
BOARD_TUD_MAX_SPEED=OPT_MODE_HIGH_SPEED
|
||||
)
|
||||
target_sources(${TARGET} PUBLIC
|
||||
${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal_tim.c
|
||||
|
@ -70,22 +70,9 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define LED_PORT GPIOB
|
||||
#define LED_PIN GPIO_PIN_6
|
||||
#define LED_STATE_ON 1
|
||||
|
||||
// Tamper push-button
|
||||
#define BUTTON_PORT GPIOA
|
||||
#define BUTTON_PIN GPIO_PIN_0
|
||||
#define BUTTON_STATE_ACTIVE 1
|
||||
|
||||
// Need to change jumper setting J7 and J8 from RS-232 to STLink
|
||||
#define UART_DEV USART3
|
||||
#define UART_CLK_EN __HAL_RCC_USART3_CLK_ENABLE
|
||||
#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
|
||||
|
||||
// VBUS Sense detection
|
||||
#define OTG_FS_VBUS_SENSE 1
|
||||
@ -101,6 +88,45 @@
|
||||
#define ULPI_RST_PORT GPIOD
|
||||
#define ULPI_RST_PIN GPIO_PIN_14
|
||||
|
||||
#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 = GPIOB,
|
||||
.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 = 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 = 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
|
||||
},
|
||||
|
||||
{ // I2C SCL for MFX VBUS
|
||||
.port = GPIOB,
|
||||
.pin_init = { .Pin = GPIO_PIN_6, .Mode = GPIO_MODE_AF_OD, .Pull = GPIO_NOPULL, .Speed = GPIO_SPEED_HIGH, .Alternate = GPIO_AF4_I2C1 },
|
||||
.active_state = 0
|
||||
},
|
||||
{ // I2C SDA for MFX VBUS
|
||||
.port = GPIOB,
|
||||
.pin_init = { .Pin = GPIO_PIN_7, .Mode = GPIO_MODE_AF_OD, .Pull = GPIO_NOPULL, .Speed = GPIO_SPEED_HIGH, .Alternate = GPIO_AF4_I2C1 },
|
||||
.active_state = 1
|
||||
},
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// RCC Clock
|
||||
//--------------------------------------------------------------------+
|
||||
@ -178,8 +204,7 @@ static inline void SystemClock_Config(void)
|
||||
static inline void timer_board_delay(TIM_HandleTypeDef* tim_hdl, uint32_t ms)
|
||||
{
|
||||
uint32_t startMs = __HAL_TIM_GET_COUNTER(tim_hdl);
|
||||
while ((__HAL_TIM_GET_COUNTER(tim_hdl) - startMs) < ms)
|
||||
{
|
||||
while ((__HAL_TIM_GET_COUNTER(tim_hdl) - startMs) < ms) {
|
||||
asm("nop"); //do nothing
|
||||
}
|
||||
}
|
||||
@ -230,6 +255,11 @@ static inline void board_init2(void)
|
||||
__HAL_RCC_TIM2_CLK_DISABLE();
|
||||
}
|
||||
|
||||
// need to short a jumper
|
||||
void board_vbus_set(uint8_t rhport, bool state) {
|
||||
(void) rhport; (void) state;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -1,7 +1,11 @@
|
||||
MCU_VARIANT = stm32h743xx
|
||||
CFLAGS += -DSTM32H743xx -DHSE_VALUE=8000000
|
||||
|
||||
# Default is HS port
|
||||
PORT ?= 1
|
||||
RHPORT_SPEED = OPT_MODE_FULL_SPEED OPT_MODE_HIGH_SPEED
|
||||
RHPORT_DEVICE ?= 1
|
||||
RHPORT_HOST ?= 0
|
||||
|
||||
LD_FILE_GCC = $(FAMILY_PATH)/linker/stm32h743xx_flash.ld
|
||||
|
||||
# Use Timer module for ULPI PHY reset
|
||||
CFLAGS += -DHAL_TIM_MODULE_ENABLED
|
||||
@ -9,14 +13,6 @@ SRC_C += \
|
||||
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_tim.c \
|
||||
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_tim_ex.c
|
||||
|
||||
# GCC
|
||||
SRC_S_GCC += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32h743xx.s
|
||||
LD_FILE_GCC = $(FAMILY_PATH)/linker/stm32h743xx_flash.ld
|
||||
|
||||
# IAR
|
||||
SRC_S_IAR += $(ST_CMSIS)/Source/Templates/iar/startup_stm32h743xx.s
|
||||
LD_FILE_IAR = $(ST_CMSIS)/Source/Templates/iar/linker/stm32h743xx_flash.icf
|
||||
|
||||
# For flash-jlink target
|
||||
JLINK_DEVICE = stm32h743ii
|
||||
|
||||
|
@ -31,7 +31,12 @@
|
||||
#include "bsp/board_api.h"
|
||||
|
||||
TU_ATTR_UNUSED static void Error_Handler(void) { }
|
||||
void board_vbus_set(uint8_t rhport, bool state) TU_ATTR_WEAK;
|
||||
|
||||
typedef struct {
|
||||
GPIO_TypeDef* port;
|
||||
GPIO_InitTypeDef pin_init;
|
||||
uint8_t active_state;
|
||||
} board_pindef_t;
|
||||
|
||||
#include "board.h"
|
||||
|
||||
@ -39,7 +44,20 @@ void board_vbus_set(uint8_t rhport, bool state) TU_ATTR_WEAK;
|
||||
// MACRO TYPEDEF CONSTANT ENUM
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
UART_HandleTypeDef UartHandle;
|
||||
#ifdef UART_DEV
|
||||
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,
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Forward USB interrupt events to TinyUSB IRQ Handler
|
||||
@ -60,8 +78,6 @@ void OTG_HS_IRQHandler(void) {
|
||||
#ifdef TRACE_ETM
|
||||
void trace_etm_init(void) {
|
||||
// H7 trace pin is PE2 to PE6
|
||||
// __HAL_RCC_GPIOE_CLK_ENABLE();
|
||||
|
||||
GPIO_InitTypeDef gpio_init;
|
||||
gpio_init.Pin = GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6;
|
||||
gpio_init.Mode = GPIO_MODE_AF_PP;
|
||||
@ -83,20 +99,24 @@ void board_init(void) {
|
||||
|
||||
// Enable All GPIOs clocks
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE(); // USB ULPI NXT
|
||||
__HAL_RCC_GPIOC_CLK_ENABLE(); // USB ULPI NXT
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOE_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOF_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOG_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOH_CLK_ENABLE(); // USB ULPI NXT
|
||||
__HAL_RCC_GPIOH_CLK_ENABLE();
|
||||
#ifdef __HAL_RCC_GPIOI_CLK_ENABLE
|
||||
__HAL_RCC_GPIOI_CLK_ENABLE(); // USB ULPI NXT
|
||||
__HAL_RCC_GPIOI_CLK_ENABLE();
|
||||
#endif
|
||||
__HAL_RCC_GPIOJ_CLK_ENABLE();
|
||||
|
||||
trace_etm_init();
|
||||
|
||||
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);
|
||||
@ -115,39 +135,8 @@ void board_init(void) {
|
||||
|
||||
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);
|
||||
|
||||
// Button
|
||||
GPIO_InitStruct.Pin = BUTTON_PIN;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
HAL_GPIO_Init(BUTTON_PORT, &GPIO_InitStruct);
|
||||
|
||||
#ifdef UART_DEV
|
||||
// Uart
|
||||
UART_CLK_EN();
|
||||
|
||||
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_VERY_HIGH;
|
||||
GPIO_InitStruct.Alternate = UART_GPIO_AF;
|
||||
HAL_GPIO_Init(UART_GPIO_PORT, &GPIO_InitStruct);
|
||||
|
||||
UartHandle.Instance = UART_DEV;
|
||||
UartHandle.Init.BaudRate = CFG_BOARD_UART_BAUDRATE;
|
||||
UartHandle.Init.WordLength = UART_WORDLENGTH_8B;
|
||||
UartHandle.Init.StopBits = UART_STOPBITS_1;
|
||||
UartHandle.Init.Parity = UART_PARITY_NONE;
|
||||
UartHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
||||
UartHandle.Init.Mode = UART_MODE_TX_RX;
|
||||
UartHandle.Init.OverSampling = UART_OVERSAMPLING_16;
|
||||
HAL_UART_Init(&UartHandle);
|
||||
#endif
|
||||
|
||||
@ -237,8 +226,7 @@ void board_init(void) {
|
||||
|
||||
HAL_PWREx_EnableUSBVoltageDetector();
|
||||
|
||||
// For waveshare openh743 ULPI PHY reset walkaround
|
||||
board_init2();
|
||||
board_init2(); // optional init
|
||||
|
||||
#if CFG_TUH_ENABLED
|
||||
board_vbus_set(BOARD_TUH_RHPORT, 1);
|
||||
@ -251,12 +239,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)) ? 1 : 0;
|
||||
#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) {
|
||||
@ -282,14 +280,13 @@ int board_uart_write(void const *buf, int len) {
|
||||
#ifdef UART_DEV
|
||||
HAL_UART_Transmit(&UartHandle, (uint8_t * )(uintptr_t)
|
||||
buf, len, 0xffff);
|
||||
#else
|
||||
(void) buf;
|
||||
#endif
|
||||
|
||||
return len;
|
||||
#else
|
||||
(void) buf; (void) len;
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#if CFG_TUSB_OS == OPT_OS_NONE
|
||||
volatile uint32_t system_ticks = 0;
|
||||
|
||||
|
@ -5,7 +5,7 @@ set(ST_PREFIX stm32${ST_FAMILY}xx)
|
||||
|
||||
set(ST_HAL_DRIVER ${TOP}/hw/mcu/st/stm32${ST_FAMILY}xx_hal_driver)
|
||||
set(ST_CMSIS ${TOP}/hw/mcu/st/cmsis_device_${ST_FAMILY})
|
||||
set(MFXSTM32L152 ${TOP}/hw/mcu/st/stm32-mfxstm32l152)
|
||||
set(ST_MFXSTM32L152 ${TOP}/hw/mcu/st/stm32-mfxstm32l152)
|
||||
set(CMSIS_5 ${TOP}/lib/CMSIS_5)
|
||||
|
||||
# include board specific
|
||||
@ -17,6 +17,26 @@ set(CMAKE_TOOLCHAIN_FILE ${TOP}/examples/build_system/cmake/toolchain/arm_${TOOL
|
||||
|
||||
set(FAMILY_MCUS STM32H7 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 ()
|
||||
|
||||
#------------------------------------
|
||||
# BOARD_TARGET
|
||||
@ -52,19 +72,19 @@ function(add_board_target BOARD_TARGET)
|
||||
${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal_uart.c
|
||||
${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal_uart_ex.c
|
||||
${STARTUP_FILE_${CMAKE_C_COMPILER_ID}}
|
||||
# MFXSTM32L152
|
||||
${MFXSTM32L152}/mfxstm32l152.c
|
||||
${MFXSTM32L152}/mfxstm32l152_reg.c
|
||||
)
|
||||
target_include_directories(${BOARD_TARGET} PUBLIC
|
||||
${CMAKE_CURRENT_FUNCTION_LIST_DIR}
|
||||
${CMSIS_5}/CMSIS/Core/Include
|
||||
${ST_CMSIS}/Include
|
||||
${ST_HAL_DRIVER}/Inc
|
||||
${MFXSTM32L152}
|
||||
)
|
||||
#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})
|
||||
|
||||
|
@ -1,31 +1,48 @@
|
||||
UF2_FAMILY_ID = 0x6db66082
|
||||
ST_FAMILY = h7
|
||||
DEPS_SUBMODULES += lib/CMSIS_5 hw/mcu/st/cmsis_device_$(ST_FAMILY) hw/mcu/st/stm32$(ST_FAMILY)xx_hal_driver
|
||||
|
||||
ST_PREFIX = stm32${ST_FAMILY}xx
|
||||
ST_CMSIS = hw/mcu/st/cmsis_device_$(ST_FAMILY)
|
||||
ST_HAL_DRIVER = hw/mcu/st/stm32$(ST_FAMILY)xx_hal_driver
|
||||
ST_HAL_DRIVER = hw/mcu/st/${ST_PREFIX}_hal_driver
|
||||
ST_MFXSTM32L152 = hw/mcu/st/stm32-mfxstm32l152
|
||||
|
||||
UF2_FAMILY_ID = 0x6db66082
|
||||
|
||||
include $(TOP)/$(BOARD_PATH)/board.mk
|
||||
CPU_CORE ?= cortex-m7
|
||||
|
||||
# ----------------------
|
||||
# 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_STM32H7 \
|
||||
-DBOARD_TUD_RHPORT=$(PORT)
|
||||
|
||||
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
|
||||
$(info "Using OTG_FS")
|
||||
endif
|
||||
-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 += \
|
||||
@ -48,20 +65,29 @@ SRC_C += \
|
||||
src/portable/synopsys/dwc2/dcd_dwc2.c \
|
||||
src/portable/synopsys/dwc2/hcd_dwc2.c \
|
||||
src/portable/synopsys/dwc2/dwc2_common.c \
|
||||
$(ST_CMSIS)/Source/Templates/system_stm32$(ST_FAMILY)xx.c \
|
||||
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal.c \
|
||||
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_cortex.c \
|
||||
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_dma.c \
|
||||
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_gpio.c \
|
||||
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_pwr.c \
|
||||
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_pwr_ex.c \
|
||||
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_rcc.c \
|
||||
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_rcc_ex.c \
|
||||
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_uart.c \
|
||||
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_uart_ex.c \
|
||||
$(ST_CMSIS)/Source/Templates/system_${ST_PREFIX}.c \
|
||||
$(ST_HAL_DRIVER)/Src/${ST_PREFIX}_hal.c \
|
||||
$(ST_HAL_DRIVER)/Src/${ST_PREFIX}_hal_cortex.c \
|
||||
$(ST_HAL_DRIVER)/Src/${ST_PREFIX}_hal_dma.c \
|
||||
$(ST_HAL_DRIVER)/Src/${ST_PREFIX}_hal_gpio.c \
|
||||
${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal_i2c.c \
|
||||
${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal_i2c_ex.c \
|
||||
$(ST_HAL_DRIVER)/Src/${ST_PREFIX}_hal_pwr.c \
|
||||
$(ST_HAL_DRIVER)/Src/${ST_PREFIX}_hal_pwr_ex.c \
|
||||
$(ST_HAL_DRIVER)/Src/${ST_PREFIX}_hal_rcc.c \
|
||||
$(ST_HAL_DRIVER)/Src/${ST_PREFIX}_hal_rcc_ex.c \
|
||||
$(ST_HAL_DRIVER)/Src/${ST_PREFIX}_hal_uart.c \
|
||||
$(ST_HAL_DRIVER)/Src/${ST_PREFIX}_hal_uart_ex.c \
|
||||
|
||||
INC += \
|
||||
$(TOP)/$(BOARD_PATH) \
|
||||
$(TOP)/lib/CMSIS_5/CMSIS/Core/Include \
|
||||
$(TOP)/$(ST_CMSIS)/Include \
|
||||
$(TOP)/$(ST_HAL_DRIVER)/Inc
|
||||
|
||||
# Startup
|
||||
SRC_S_GCC += $(ST_CMSIS)/Source/Templates/gcc/startup_$(MCU_VARIANT).s
|
||||
SRC_S_IAR += $(ST_CMSIS)/Source/Templates/iar/startup_$(MCU_VARIANT).s
|
||||
|
||||
# Linker
|
||||
LD_FILE_IAR ?= $(ST_CMSIS)/Source/Templates/iar/linker/$(MCU_VARIANT)_flash.icf
|
||||
|
Loading…
x
Reference in New Issue
Block a user