switch stm32f3 to use st_driver

This commit is contained in:
hathach 2019-09-05 22:41:58 +07:00
parent c4b384d22f
commit 1d2223a116
4 changed files with 33 additions and 23 deletions

View File

@ -1,32 +1,35 @@
CFLAGS += \ CFLAGS += \
-DHSE_VALUE=8000000 \ -DHSE_VALUE=8000000 \
-DCFG_TUSB_MCU=OPT_MCU_STM32F3 \
-DSTM32F303xC \ -DSTM32F303xC \
-mthumb \ -mthumb \
-mabi=aapcs-linux \ -mabi=aapcs-linux \
-mcpu=cortex-m4 \ -mcpu=cortex-m4 \
-mfloat-abi=hard \ -mfloat-abi=hard \
-mfpu=fpv4-sp-d16 \ -mfpu=fpv4-sp-d16 \
-nostdlib -nostartfiles -nostdlib -nostartfiles \
-DCFG_TUSB_MCU=OPT_MCU_STM32F3
ST_HAL_DRIVER = hw/mcu/st/st_driver/STM32F3xx_HAL_Driver
ST_CMSIS = hw/mcu/st/st_driver/CMSIS/Device/ST/STM32F3xx
# All source paths should be relative to the top level. # All source paths should be relative to the top level.
LD_FILE = hw/bsp/stm32f303disco/STM32F303VCTx_FLASH.ld LD_FILE = hw/bsp/stm32f303disco/STM32F303VCTx_FLASH.ld
SRC_C += \ SRC_C += \
hw/mcu/st/system-init/system_stm32f3xx.c \ $(ST_CMSIS)/Source/Templates/system_stm32f3xx.c \
hw/mcu/st/stm32lib/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal.c \ $(ST_HAL_DRIVER)/Src/stm32f3xx_hal.c \
hw/mcu/st/stm32lib/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_cortex.c \ $(ST_HAL_DRIVER)/Src/stm32f3xx_hal_cortex.c \
hw/mcu/st/stm32lib/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_rcc.c \ $(ST_HAL_DRIVER)/Src/stm32f3xx_hal_rcc.c \
hw/mcu/st/stm32lib/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_gpio.c $(ST_HAL_DRIVER)/Src/stm32f3xx_hal_gpio.c
SRC_S += \ SRC_S += \
hw/mcu/st/startup/stm32f3/startup_stm32f303xc.s hw/mcu/st/startup/stm32f3/startup_stm32f303xc.s
INC += \ INC += \
$(TOP)/hw/bsp/stm32f303disco \ $(TOP)/hw/mcu/st/st_driver/CMSIS/Include \
$(TOP)/hw/mcu/st/cmsis \ $(TOP)/$(ST_CMSIS)/Include \
$(TOP)/hw/mcu/st/stm32lib/CMSIS/STM32F3xx/Include \ $(TOP)/$(ST_HAL_DRIVER)/Inc \
$(TOP)/hw/mcu/st/stm32lib/STM32F3xx_HAL_Driver/Inc $(TOP)/hw/bsp/$(BOARD)
# For TinyUSB port source # For TinyUSB port source
VENDOR = st VENDOR = st

View File

@ -31,6 +31,11 @@
#define LED_PORT GPIOE #define LED_PORT GPIOE
#define LED_PIN GPIO_PIN_9 #define LED_PIN GPIO_PIN_9
#define LED_STATE_ON 1
#define BUTTON_PORT GPIOA
#define BUTTON_PIN GPIO_PIN_0
#define BUTTON_STATE_ACTIVE 1
void board_init(void) void board_init(void)
{ {
@ -64,10 +69,8 @@ void board_init(void)
// Notify runtime of frequency change. // Notify runtime of frequency change.
SystemCoreClockUpdate(); SystemCoreClockUpdate();
/* -1- Enable GPIO Clock (to be able to program the configuration registers) */ // LED
__HAL_RCC_GPIOE_CLK_ENABLE(); __HAL_RCC_GPIOE_CLK_ENABLE();
/* -2- Configure PE.8 to PE.15 IOs in output push-pull mode to drive external LEDs */
GPIO_InitTypeDef GPIO_InitStruct; GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitStruct.Pin = LED_PIN; GPIO_InitStruct.Pin = LED_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
@ -75,7 +78,13 @@ void board_init(void)
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(LED_PORT, &GPIO_InitStruct); HAL_GPIO_Init(LED_PORT, &GPIO_InitStruct);
board_led_write(false); // Button
__HAL_RCC_GPIOA_CLK_ENABLE();
GPIO_InitStruct.Pin = BUTTON_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(BUTTON_PORT, &GPIO_InitStruct);
#if 0 #if 0
RCC->AHB2ENR |= RCC_AHB2ENR_OTGFSEN; RCC->AHB2ENR |= RCC_AHB2ENR_OTGFSEN;
@ -102,18 +111,16 @@ void board_init(void)
void board_led_write(bool state) void board_led_write(bool state)
{ {
HAL_GPIO_WritePin(LED_PORT, LED_PIN, state); HAL_GPIO_WritePin(LED_PORT, LED_PIN, state ? LED_STATE_ON : (1-LED_STATE_ON));
} }
uint32_t board_button_read(void) uint32_t board_button_read(void)
{ {
// TODO implement return BUTTON_STATE_ACTIVE == HAL_GPIO_ReadPin(BUTTON_PORT, BUTTON_PIN);
return 0;
} }
#if CFG_TUSB_OS == OPT_OS_NONE #if CFG_TUSB_OS == OPT_OS_NONE
volatile uint32_t system_ticks = 0; volatile uint32_t system_ticks = 0;
void SysTick_Handler (void) void SysTick_Handler (void)
{ {
system_ticks++; system_ticks++;

@ -1 +1 @@
Subproject commit acc346e98e646ba16b7c495ef3e9363d289b8ea1 Subproject commit fd4cb843d79efa2ad41bc8ff0b2bd0f8c2c55297