summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <[email protected]>2019-09-05 22:41:58 +0700
committerhathach <[email protected]>2019-09-05 22:41:58 +0700
commit1d2223a11681eb61cda365a1e9acd30addc83913 (patch)
treeb2c18c71b24c03819ef27818e16a11051154c921
parentc4b384d22f6e3c6b7b443bf4ce41c42d6da0bb90 (diff)
switch stm32f3 to use st_driver
-rw-r--r--hw/bsp/stm32f303disco/board.mk25
-rw-r--r--hw/bsp/stm32f303disco/stm32f303disco.c27
-rw-r--r--hw/bsp/stm32f407disco/board.mk2
m---------hw/mcu/st/st_driver0
4 files changed, 32 insertions, 22 deletions
diff --git a/hw/bsp/stm32f303disco/board.mk b/hw/bsp/stm32f303disco/board.mk
index 7a493c244..de7457a35 100644
--- a/hw/bsp/stm32f303disco/board.mk
+++ b/hw/bsp/stm32f303disco/board.mk
@@ -1,32 +1,35 @@
CFLAGS += \
-DHSE_VALUE=8000000 \
- -DCFG_TUSB_MCU=OPT_MCU_STM32F3 \
-DSTM32F303xC \
-mthumb \
-mabi=aapcs-linux \
-mcpu=cortex-m4 \
-mfloat-abi=hard \
-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.
LD_FILE = hw/bsp/stm32f303disco/STM32F303VCTx_FLASH.ld
SRC_C += \
- hw/mcu/st/system-init/system_stm32f3xx.c \
- hw/mcu/st/stm32lib/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal.c \
- hw/mcu/st/stm32lib/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_cortex.c \
- hw/mcu/st/stm32lib/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_rcc.c \
- hw/mcu/st/stm32lib/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_gpio.c
+ $(ST_CMSIS)/Source/Templates/system_stm32f3xx.c \
+ $(ST_HAL_DRIVER)/Src/stm32f3xx_hal.c \
+ $(ST_HAL_DRIVER)/Src/stm32f3xx_hal_cortex.c \
+ $(ST_HAL_DRIVER)/Src/stm32f3xx_hal_rcc.c \
+ $(ST_HAL_DRIVER)/Src/stm32f3xx_hal_gpio.c
SRC_S += \
hw/mcu/st/startup/stm32f3/startup_stm32f303xc.s
INC += \
- $(TOP)/hw/bsp/stm32f303disco \
- $(TOP)/hw/mcu/st/cmsis \
- $(TOP)/hw/mcu/st/stm32lib/CMSIS/STM32F3xx/Include \
- $(TOP)/hw/mcu/st/stm32lib/STM32F3xx_HAL_Driver/Inc
+ $(TOP)/hw/mcu/st/st_driver/CMSIS/Include \
+ $(TOP)/$(ST_CMSIS)/Include \
+ $(TOP)/$(ST_HAL_DRIVER)/Inc \
+ $(TOP)/hw/bsp/$(BOARD)
# For TinyUSB port source
VENDOR = st
diff --git a/hw/bsp/stm32f303disco/stm32f303disco.c b/hw/bsp/stm32f303disco/stm32f303disco.c
index c5e1108eb..45ba7a4f9 100644
--- a/hw/bsp/stm32f303disco/stm32f303disco.c
+++ b/hw/bsp/stm32f303disco/stm32f303disco.c
@@ -29,8 +29,13 @@
#include "stm32f3xx.h"
#include "stm32f3xx_hal_conf.h"
-#define LED_PORT GPIOE
-#define LED_PIN GPIO_PIN_9
+#define LED_PORT GPIOE
+#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)
{
@@ -64,10 +69,8 @@ void board_init(void)
// Notify runtime of frequency change.
SystemCoreClockUpdate();
- /* -1- Enable GPIO Clock (to be able to program the configuration registers) */
+ // LED
__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_InitStruct.Pin = LED_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
@@ -75,7 +78,13 @@ void board_init(void)
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
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
RCC->AHB2ENR |= RCC_AHB2ENR_OTGFSEN;
@@ -102,18 +111,16 @@ void board_init(void)
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)
{
- // TODO implement
- return 0;
+ return BUTTON_STATE_ACTIVE == HAL_GPIO_ReadPin(BUTTON_PORT, BUTTON_PIN);
}
#if CFG_TUSB_OS == OPT_OS_NONE
volatile uint32_t system_ticks = 0;
-
void SysTick_Handler (void)
{
system_ticks++;
diff --git a/hw/bsp/stm32f407disco/board.mk b/hw/bsp/stm32f407disco/board.mk
index cf4890174..93df2fda3 100644
--- a/hw/bsp/stm32f407disco/board.mk
+++ b/hw/bsp/stm32f407disco/board.mk
@@ -20,7 +20,7 @@ SRC_C += \
$(ST_HAL_DRIVER)/Src/stm32f4xx_hal.c \
$(ST_HAL_DRIVER)/Src/stm32f4xx_hal_cortex.c \
$(ST_HAL_DRIVER)/Src/stm32f4xx_hal_rcc.c \
- $(ST_HAL_DRIVER)/Src/stm32f4xx_hal_gpio.c
+ $(ST_HAL_DRIVER)/Src/stm32f4xx_hal_gpio.c
SRC_S += \
$(ST_CMSIS)/Source/Templates/gcc/startup_stm32f407xx.s
diff --git a/hw/mcu/st/st_driver b/hw/mcu/st/st_driver
-Subproject acc346e98e646ba16b7c495ef3e9363d289b8ea
+Subproject fd4cb843d79efa2ad41bc8ff0b2bd0f8c2c5529