summaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
authorHa Thach <[email protected]>2021-08-29 21:49:10 +0700
committerGitHub <[email protected]>2021-08-29 21:49:10 +0700
commit4492a7021cb33cb3079f2e949d6e22ddd3d33f49 (patch)
treeb14be02e6d0a7d632e320431cc3543e123de78fa /hw
parent61592526928be9626317ef82bbe42d0edaf7fa14 (diff)
parent31959295965f6b19c35bb770b1e430bdfa7b4606 (diff)
Merge branch 'master' into merge-waveshare-h7
Diffstat (limited to 'hw')
-rw-r--r--hw/bsp/board_mcu.h3
-rw-r--r--hw/bsp/frdm_k32l2b/board.h56
-rw-r--r--hw/bsp/frdm_k32l2b/board.mk51
-rw-r--r--hw/bsp/frdm_k32l2b/frdm_k32l2b.c140
-rw-r--r--hw/bsp/stm32f0/family.c2
-rw-r--r--hw/bsp/stm32f1/boards/stm32f103_bluepill/STM32F103X8_FLASH.ld (renamed from hw/bsp/stm32f103bluepill/STM32F103XB_FLASH.ld)2
-rw-r--r--hw/bsp/stm32f1/boards/stm32f103_bluepill/board.h92
-rw-r--r--hw/bsp/stm32f1/boards/stm32f103_bluepill/board.mk11
-rw-r--r--hw/bsp/stm32f1/boards/stm32f103_mini_2/STM32F103XC_FLASH.ld167
-rw-r--r--hw/bsp/stm32f1/boards/stm32f103_mini_2/board.h92
-rw-r--r--hw/bsp/stm32f1/boards/stm32f103_mini_2/board.mk11
-rw-r--r--hw/bsp/stm32f1/family.c (renamed from hw/bsp/stm32f103bluepill/stm32f103bluepill.c)82
-rw-r--r--hw/bsp/stm32f1/family.mk (renamed from hw/bsp/stm32f103bluepill/board.mk)14
-rw-r--r--hw/bsp/stm32f1/stm32f1xx_hal_conf.h (renamed from hw/bsp/stm32f103bluepill/stm32f1xx_hal_conf.h)0
14 files changed, 648 insertions, 75 deletions
diff --git a/hw/bsp/board_mcu.h b/hw/bsp/board_mcu.h
index acfd7348d..8cc50c808 100644
--- a/hw/bsp/board_mcu.h
+++ b/hw/bsp/board_mcu.h
@@ -46,7 +46,8 @@
#include "chip.h"
#elif CFG_TUSB_MCU == OPT_MCU_LPC51UXX || CFG_TUSB_MCU == OPT_MCU_LPC54XXX || \
- CFG_TUSB_MCU == OPT_MCU_LPC55XX || CFG_TUSB_MCU == OPT_MCU_MKL25ZXX
+ CFG_TUSB_MCU == OPT_MCU_LPC55XX || CFG_TUSB_MCU == OPT_MCU_MKL25ZXX || \
+ CFG_TUSB_MCU == OPT_MCU_K32L2BXX
#include "fsl_device_registers.h"
#elif CFG_TUSB_MCU == OPT_MCU_NRF5X
diff --git a/hw/bsp/frdm_k32l2b/board.h b/hw/bsp/frdm_k32l2b/board.h
new file mode 100644
index 000000000..825367915
--- /dev/null
+++ b/hw/bsp/frdm_k32l2b/board.h
@@ -0,0 +1,56 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2019, Ha Thach (tinyusb.org)
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * This file is part of the TinyUSB stack.
+ */
+
+
+#ifndef BOARD_H_
+#define BOARD_H_
+
+#include "fsl_device_registers.h"
+
+// LED
+#define LED_PIN_CLOCK kCLOCK_PortD
+#define LED_GPIO GPIOD
+#define LED_PORT PORTD
+#define LED_PIN 5
+#define LED_STATE_ON 0
+
+// SW3 button1
+#define BUTTON_PIN_CLOCK kCLOCK_PortC
+#define BUTTON_GPIO GPIOC
+#define BUTTON_PORT PORTC
+#define BUTTON_PIN 3
+#define BUTTON_STATE_ACTIVE 0
+
+// UART
+#define UART_PORT LPUART0
+#define UART_PIN_CLOCK kCLOCK_PortA
+#define UART_PIN_PORT PORTA
+#define UART_PIN_RX 1u
+#define UART_PIN_TX 2u
+#define SOPT5_LPUART0RXSRC_LPUART_RX 0x00u /*!<@brief LPUART0 Receive Data Source Select: LPUART_RX pin */
+#define SOPT5_LPUART0TXSRC_LPUART_TX 0x00u /*!<@brief LPUART0 Transmit Data Source Select: LPUART0_TX pin */
+
+#endif /* BOARD_H_ */
diff --git a/hw/bsp/frdm_k32l2b/board.mk b/hw/bsp/frdm_k32l2b/board.mk
new file mode 100644
index 000000000..56df553da
--- /dev/null
+++ b/hw/bsp/frdm_k32l2b/board.mk
@@ -0,0 +1,51 @@
+SDK_DIR = hw/mcu/nxp/mcux-sdk
+DEPS_SUBMODULES += $(SDK_DIR)
+
+CFLAGS += \
+ -mthumb \
+ -mabi=aapcs \
+ -mcpu=cortex-m0plus \
+ -DCPU_K32L2B31VLH0A \
+ -DCFG_TUSB_MCU=OPT_MCU_K32L2BXX
+
+# mcu driver cause following warnings
+CFLAGS += -Wno-error=unused-parameter
+
+MCU_DIR = $(SDK_DIR)/devices/K32L2B31A
+
+# All source paths should be relative to the top level.
+LD_FILE = $(MCU_DIR)/gcc/K32L2B31xxxxA_flash.ld
+
+SRC_C += \
+ src/portable/nxp/khci/dcd_khci.c \
+ $(MCU_DIR)/system_K32L2B31A.c \
+ $(MCU_DIR)/project_template/clock_config.c \
+ $(MCU_DIR)/drivers/fsl_clock.c \
+ $(SDK_DIR)/drivers/gpio/fsl_gpio.c \
+ $(SDK_DIR)/drivers/lpuart/fsl_lpuart.c
+
+INC += \
+ $(TOP)/hw/bsp/$(BOARD) \
+ $(TOP)/$(SDK_DIR)/CMSIS/Include \
+ $(TOP)/$(SDK_DIR)/drivers/smc \
+ $(TOP)/$(SDK_DIR)/drivers/common \
+ $(TOP)/$(SDK_DIR)/drivers/gpio \
+ $(TOP)/$(SDK_DIR)/drivers/port \
+ $(TOP)/$(SDK_DIR)/drivers/lpuart \
+ $(TOP)/$(MCU_DIR) \
+ $(TOP)/$(MCU_DIR)/drivers \
+ $(TOP)/$(MCU_DIR)/project_template \
+
+SRC_S += $(MCU_DIR)/gcc/startup_K32L2B31A.S
+
+# For freeRTOS port source
+FREERTOS_PORT = ARM_CM0
+
+# For flash-jlink target
+JLINK_DEVICE = MKL25Z128xxx4
+
+# For flash-pyocd target
+PYOCD_TARGET = K32L2B
+
+# flash using pyocd
+flash: flash-pyocd
diff --git a/hw/bsp/frdm_k32l2b/frdm_k32l2b.c b/hw/bsp/frdm_k32l2b/frdm_k32l2b.c
new file mode 100644
index 000000000..c45095caa
--- /dev/null
+++ b/hw/bsp/frdm_k32l2b/frdm_k32l2b.c
@@ -0,0 +1,140 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2018, hathach (tinyusb.org)
+ * Copyright (c) 2020, Koji Kitayama
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * This file is part of the TinyUSB stack.
+ */
+
+#include "../board.h"
+#include "board.h"
+#include "fsl_gpio.h"
+#include "fsl_port.h"
+#include "fsl_clock.h"
+#include "fsl_lpuart.h"
+
+#include "clock_config.h"
+
+//--------------------------------------------------------------------+
+// Forward USB interrupt events to TinyUSB IRQ Handler
+//--------------------------------------------------------------------+
+void USB0_IRQHandler(void)
+{
+ tud_int_handler(0);
+}
+
+void board_init(void)
+{
+ /* Enable port clocks for UART/LED/Button pins */
+ CLOCK_EnableClock(UART_PIN_CLOCK);
+ CLOCK_EnableClock(LED_PIN_CLOCK);
+ CLOCK_EnableClock(BUTTON_PIN_CLOCK);
+
+ gpio_pin_config_t led_config = { kGPIO_DigitalOutput, 0 };
+ GPIO_PinInit(LED_GPIO, LED_PIN, &led_config);
+ PORT_SetPinMux(LED_PORT, LED_PIN, kPORT_MuxAsGpio);
+
+ gpio_pin_config_t button_config = { kGPIO_DigitalInput, 0 };
+ GPIO_PinInit(BUTTON_GPIO, BUTTON_PIN, &button_config);
+ const port_pin_config_t BUTTON_CFG = {
+ kPORT_PullUp,
+ kPORT_FastSlewRate,
+ kPORT_PassiveFilterDisable,
+ kPORT_LowDriveStrength,
+ kPORT_MuxAsGpio
+ };
+ PORT_SetPinConfig(BUTTON_PORT, BUTTON_PIN, &BUTTON_CFG);
+
+ /* PORTA1 (pin 23) is configured as LPUART0_RX */
+ PORT_SetPinMux(PORTA, 1U, kPORT_MuxAlt2);
+ /* PORTA2 (pin 24) is configured as LPUART0_TX */
+ PORT_SetPinMux(PORTA, 2U, kPORT_MuxAlt2);
+
+ SIM->SOPT5 = ((SIM->SOPT5 &
+ /* Mask bits to zero which are setting */
+ (~(SIM_SOPT5_LPUART0TXSRC_MASK | SIM_SOPT5_LPUART0RXSRC_MASK)))
+ /* LPUART0 Transmit Data Source Select: LPUART0_TX pin. */
+ | SIM_SOPT5_LPUART0TXSRC(SOPT5_LPUART0TXSRC_LPUART_TX)
+ /* LPUART0 Receive Data Source Select: LPUART_RX pin. */
+ | SIM_SOPT5_LPUART0RXSRC(SOPT5_LPUART0RXSRC_LPUART_RX));
+
+ BOARD_BootClockRUN();
+ SystemCoreClockUpdate();
+ CLOCK_SetLpuart0Clock(1);
+
+#if CFG_TUSB_OS == OPT_OS_NONE
+ // 1ms tick timer
+ SysTick_Config(SystemCoreClock / 1000);
+#elif CFG_TUSB_OS == OPT_OS_FREERTOS
+ // If freeRTOS is used, IRQ priority is limit by max syscall ( smaller is higher )
+ NVIC_SetPriority(USB0_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY );
+#endif
+
+ lpuart_config_t uart_config;
+ LPUART_GetDefaultConfig(&uart_config);
+ uart_config.baudRate_Bps = CFG_BOARD_UART_BAUDRATE;
+ uart_config.enableTx = true;
+ uart_config.enableRx = true;
+ LPUART_Init(UART_PORT, &uart_config, CLOCK_GetFreq(kCLOCK_McgIrc48MClk));
+
+ // USB
+ CLOCK_EnableUsbfs0Clock(kCLOCK_UsbSrcIrc48M, 48000000U);
+}
+
+//--------------------------------------------------------------------+
+// Board porting API
+//--------------------------------------------------------------------+
+
+void board_led_write(bool state)
+{
+ GPIO_PinWrite(LED_GPIO, LED_PIN, state ? LED_STATE_ON : (1-LED_STATE_ON));
+}
+
+uint32_t board_button_read(void)
+{
+ return BUTTON_STATE_ACTIVE == GPIO_PinRead(BUTTON_GPIO, BUTTON_PIN);
+}
+
+int board_uart_read(uint8_t* buf, int len)
+{
+ LPUART_ReadBlocking(UART_PORT, buf, len);
+ return len;
+}
+
+int board_uart_write(void const * buf, int len)
+{
+ LPUART_WriteBlocking(UART_PORT, (uint8_t*)buf, len);
+ return len;
+}
+
+#if CFG_TUSB_OS == OPT_OS_NONE
+volatile uint32_t system_ticks = 0;
+void SysTick_Handler(void)
+{
+ system_ticks++;
+}
+
+uint32_t board_millis(void)
+{
+ return system_ticks;
+}
+#endif
diff --git a/hw/bsp/stm32f0/family.c b/hw/bsp/stm32f0/family.c
index 351a7c8c6..68b924432 100644
--- a/hw/bsp/stm32f0/family.c
+++ b/hw/bsp/stm32f0/family.c
@@ -64,7 +64,7 @@ void board_init(void)
SysTick->CTRL &= ~1U;
// If freeRTOS is used, IRQ priority is limit by max syscall ( smaller is higher )
- NVIC_SetPriority(USB_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY );
+ NVIC_SetPriority(USB_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY);
#endif
// LED
diff --git a/hw/bsp/stm32f103bluepill/STM32F103XB_FLASH.ld b/hw/bsp/stm32f1/boards/stm32f103_bluepill/STM32F103X8_FLASH.ld
index 4be9df61b..ca1804905 100644
--- a/hw/bsp/stm32f103bluepill/STM32F103XB_FLASH.ld
+++ b/hw/bsp/stm32f1/boards/stm32f103_bluepill/STM32F103X8_FLASH.ld
@@ -41,7 +41,7 @@ _Min_Stack_Size = 0x400; /* required amount of stack */
/* Specify the memory areas */
MEMORY
{
-FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 128K
+FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 64K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 20K
}
diff --git a/hw/bsp/stm32f1/boards/stm32f103_bluepill/board.h b/hw/bsp/stm32f1/boards/stm32f103_bluepill/board.h
new file mode 100644
index 000000000..57a607ed5
--- /dev/null
+++ b/hw/bsp/stm32f1/boards/stm32f103_bluepill/board.h
@@ -0,0 +1,92 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2020, Ha Thach (tinyusb.org)
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * This file is part of the TinyUSB stack.
+ */
+
+#ifndef BOARD_H_
+#define BOARD_H_
+
+#ifdef __cplusplus
+ 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 1
+
+// UART
+//#define UART_DEV USART1
+//#define UART_CLK_EN __HAL_RCC_USART1_CLK_ENABLE
+//#define UART_GPIO_PORT GPIOA
+//#define UART_GPIO_AF GPIO_AF1_USART1
+//#define UART_TX_PIN GPIO_PIN_9
+//#define UART_RX_PIN GPIO_PIN_10
+
+//--------------------------------------------------------------------+
+// RCC Clock
+//--------------------------------------------------------------------+
+static inline void board_stm32f1_clock_init(void)
+{
+ RCC_ClkInitTypeDef clkinitstruct = {0};
+ RCC_OscInitTypeDef oscinitstruct = {0};
+ RCC_PeriphCLKInitTypeDef rccperiphclkinit = {0};
+
+ /* Enable HSE Oscillator and activate PLL with HSE as source */
+ oscinitstruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
+ oscinitstruct.HSEState = RCC_HSE_ON;
+ oscinitstruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
+ oscinitstruct.PLL.PLLMUL = RCC_PLL_MUL9;
+ oscinitstruct.PLL.PLLState = RCC_PLL_ON;
+ oscinitstruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
+ HAL_RCC_OscConfig(&oscinitstruct);
+
+ /* USB clock selection */
+ rccperiphclkinit.PeriphClockSelection = RCC_PERIPHCLK_USB;
+ rccperiphclkinit.UsbClockSelection = RCC_USBCLKSOURCE_PLL_DIV1_5;
+ HAL_RCCEx_PeriphCLKConfig(&rccperiphclkinit);
+
+ /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers */
+ clkinitstruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
+ clkinitstruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
+ clkinitstruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
+ clkinitstruct.APB1CLKDivider = RCC_HCLK_DIV2;
+ clkinitstruct.APB2CLKDivider = RCC_HCLK_DIV1;
+ HAL_RCC_ClockConfig(&clkinitstruct, FLASH_LATENCY_2);
+}
+
+static inline void board_vbus_sense_init(void)
+{
+}
+
+#ifdef __cplusplus
+ }
+#endif
+
+#endif /* BOARD_H_ */
diff --git a/hw/bsp/stm32f1/boards/stm32f103_bluepill/board.mk b/hw/bsp/stm32f1/boards/stm32f103_bluepill/board.mk
new file mode 100644
index 000000000..9c690ca7e
--- /dev/null
+++ b/hw/bsp/stm32f1/boards/stm32f103_bluepill/board.mk
@@ -0,0 +1,11 @@
+CFLAGS += -DSTM32F103xB -DHSE_VALUE=8000000U
+
+# All source paths should be relative to the top level.
+LD_FILE = $(BOARD_PATH)/STM32F103X8_FLASH.ld
+SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f103xb.s
+
+# For flash-jlink target
+JLINK_DEVICE = stm32f103c8
+
+# flash target ROM bootloader
+flash: flash-dfu-util
diff --git a/hw/bsp/stm32f1/boards/stm32f103_mini_2/STM32F103XC_FLASH.ld b/hw/bsp/stm32f1/boards/stm32f103_mini_2/STM32F103XC_FLASH.ld
new file mode 100644
index 000000000..da40d1eb2
--- /dev/null
+++ b/hw/bsp/stm32f1/boards/stm32f103_mini_2/STM32F103XC_FLASH.ld
@@ -0,0 +1,167 @@
+/*
+*****************************************************************************
+**
+** File : STM32F103XB_FLASH.ld
+**
+** Abstract : Linker script for STM32F103xB Device with
+** 128KByte FLASH, 20KByte RAM
+**
+** Set heap size, stack size and stack location according
+** to application requirements.
+**
+** Set memory bank area and size if external memory is used.
+**
+** Target : STMicroelectronics STM32
+**
+**
+** Distribution: The file is distributed as is, without any warranty
+** of any kind.
+**
+** (c)Copyright Ac6.
+** You may use this file as-is or modify it according to the needs of your
+** project. Distribution of this file (unmodified or modified) is not
+** permitted. Ac6 permit registered System Workbench for MCU users the
+** rights to distribute the assembled, compiled & linked contents of this
+** file as part of an application binary file, provided that it is built
+** using the System Workbench for MCU toolchain.
+**
+*****************************************************************************
+*/
+
+/* Entry Point */
+ENTRY(Reset_Handler)
+
+/* Highest address of the user mode stack */
+_estack = 0x20004FFF; /* end of RAM */
+
+/* Generate a link error if heap and stack don't fit into RAM */
+_Min_Heap_Size = 0x200; /* required amount of heap */
+_Min_Stack_Size = 0x400; /* required amount of stack */
+
+/* Specify the memory areas */
+MEMORY
+{
+FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 256K
+RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 48K
+}
+
+/* Define output sections */
+SECTIONS
+{
+ /* The startup code goes first into FLASH */
+ .isr_vector :
+ {
+ . = ALIGN(4);
+ KEEP(*(.isr_vector)) /* Startup code */
+ . = ALIGN(4);
+ } >FLASH
+
+ /* The program code and other data goes into FLASH */
+ .text :
+ {
+ . = ALIGN(4);
+ *(.text) /* .text sections (code) */
+ *(.text*) /* .text* sections (code) */
+ *(.glue_7) /* glue arm to thumb code */
+ *(.glue_7t) /* glue thumb to arm code */
+ *(.eh_frame)
+
+ KEEP (*(.init))
+ KEEP (*(.fini))
+
+ . = ALIGN(4);
+ _etext = .; /* define a global symbols at end of code */
+ } >FLASH
+
+ /* Constant data goes into FLASH */
+ .rodata :
+ {
+ . = ALIGN(4);
+ *(.rodata) /* .rodata sections (constants, strings, etc.) */
+ *(.rodata*) /* .rodata* sections (constants, strings, etc.) */
+ . = ALIGN(4);
+ } >FLASH
+
+ .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH
+ .ARM : {
+ __exidx_start = .;
+ *(.ARM.exidx*)
+ __exidx_end = .;
+ } >FLASH
+
+ .preinit_array :
+ {
+ PROVIDE_HIDDEN (__preinit_array_start = .);
+ KEEP (*(.preinit_array*))
+ PROVIDE_HIDDEN (__preinit_array_end = .);
+ } >FLASH
+ .init_array :
+ {
+ PROVIDE_HIDDEN (__init_array_start = .);
+ KEEP (*(SORT(.init_array.*)))
+ KEEP (*(.init_array*))
+ PROVIDE_HIDDEN (__init_array_end = .);
+ } >FLASH
+ .fini_array :
+ {
+ PROVIDE_HIDDEN (__fini_array_start = .);
+ KEEP (*(SORT(.fini_array.*)))
+ KEEP (*(.fini_array*))
+ PROVIDE_HIDDEN (__fini_array_end = .);
+ } >FLASH
+
+ /* used by the startup to initialize data */
+ _sidata = LOADADDR(.data);
+
+ /* Initialized data sections goes into RAM, load LMA copy after code */
+ .data :
+ {
+ . = ALIGN(4);
+ _sdata = .; /* create a global symbol at data start */
+ *(.data) /* .data sections */
+ *(.data*) /* .data* sections */
+
+ . = ALIGN(4);
+ _edata = .; /* define a global symbol at data end */
+ } >RAM AT> FLASH
+
+
+ /* Uninitialized data section */
+ . = ALIGN(4);
+ .bss :
+ {
+ /* This is used by the startup in order to initialize the .bss secion */
+ _sbss = .; /* define a global symbol at bss start */
+ __bss_start__ = _sbss;
+ *(.bss)
+ *(.bss*)
+ *(COMMON)
+
+ . = ALIGN(4);
+ _ebss = .; /* define a global symbol at bss end */
+ __bss_end__ = _ebss;
+ } >RAM
+
+ /* User_heap_stack section, used to check that there is enough RAM left */
+ ._user_heap_stack :
+ {
+ . = ALIGN(8);
+ PROVIDE ( end = . );
+ PROVIDE ( _end = . );
+ . = . + _Min_Heap_Size;
+ . = . + _Min_Stack_Size;
+ . = ALIGN(8);
+ } >RAM
+
+
+
+ /* Remove information from the standard libraries */
+ /DISCARD/ :
+ {
+ libc.a ( * )
+ libm.a ( * )
+ libgcc.a ( * )
+ }
+
+ .ARM.attributes 0 : { *(.ARM.attributes) }
+}
diff --git a/hw/bsp/stm32f1/boards/stm32f103_mini_2/board.h b/hw/bsp/stm32f1/boards/stm32f103_mini_2/board.h
new file mode 100644
index 000000000..bedce7f14
--- /dev/null
+++ b/hw/bsp/stm32f1/boards/stm32f103_mini_2/board.h
@@ -0,0 +1,92 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2020, Ha Thach (tinyusb.org)
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * This file is part of the TinyUSB stack.
+ */
+
+#ifndef BOARD_H_
+#define BOARD_H_
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+// LED
+#define LED_PORT GPIOA
+#define LED_PIN GPIO_PIN_8
+#define LED_STATE_ON 0
+
+// Button
+#define BUTTON_PORT GPIOA
+#define BUTTON_PIN GPIO_PIN_0
+#define BUTTON_STATE_ACTIVE 1
+
+// UART
+//#define UART_DEV USART1
+//#define UART_CLK_EN __HAL_RCC_USART1_CLK_ENABLE
+//#define UART_GPIO_PORT GPIOA
+//#define UART_GPIO_AF GPIO_AF1_USART1
+//#define UART_TX_PIN GPIO_PIN_9
+//#define UART_RX_PIN GPIO_PIN_10
+
+//--------------------------------------------------------------------+
+// RCC Clock
+//--------------------------------------------------------------------+
+static inline void board_stm32f1_clock_init(void)
+{
+ RCC_ClkInitTypeDef clkinitstruct = {0};
+ RCC_OscInitTypeDef oscinitstruct = {0};
+ RCC_PeriphCLKInitTypeDef rccperiphclkinit = {0};
+
+ /* Enable HSE Oscillator and activate PLL with HSE as source */
+ oscinitstruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
+ oscinitstruct.HSEState = RCC_HSE_ON;
+ oscinitstruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
+ oscinitstruct.PLL.PLLMUL = RCC_PLL_MUL9;
+ oscinitstruct.PLL.PLLState = RCC_PLL_ON;
+ oscinitstruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
+ HAL_RCC_OscConfig(&oscinitstruct);
+
+ /* USB clock selection */
+ rccperiphclkinit.PeriphClockSelection = RCC_PERIPHCLK_USB;
+ rccperiphclkinit.UsbClockSelection = RCC_USBCLKSOURCE_PLL_DIV1_5;
+ HAL_RCCEx_PeriphCLKConfig(&rccperiphclkinit);
+
+ /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers */
+ clkinitstruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
+ clkinitstruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
+ clkinitstruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
+ clkinitstruct.APB1CLKDivider = RCC_HCLK_DIV2;
+ clkinitstruct.APB2CLKDivider = RCC_HCLK_DIV1;
+ HAL_RCC_ClockConfig(&clkinitstruct, FLASH_LATENCY_2);
+}
+
+static inline void board_vbus_sense_init(void)
+{
+}
+
+#ifdef __cplusplus
+ }
+#endif
+
+#endif /* BOARD_H_ */
diff --git a/hw/bsp/stm32f1/boards/stm32f103_mini_2/board.mk b/hw/bsp/stm32f1/boards/stm32f103_mini_2/board.mk
new file mode 100644
index 000000000..eeda87080
--- /dev/null
+++ b/hw/bsp/stm32f1/boards/stm32f103_mini_2/board.mk
@@ -0,0 +1,11 @@
+CFLAGS += -DSTM32F103xB -DHSE_VALUE=8000000U
+
+# All source paths should be relative to the top level.
+LD_FILE = $(BOARD_PATH)/STM32F103XC_FLASH.ld
+SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f103xb.s
+
+# For flash-jlink target
+JLINK_DEVICE = stm32f103rc
+
+# flash target ROM bootloader
+flash: flash-jlink
diff --git a/hw/bsp/stm32f103bluepill/stm32f103bluepill.c b/hw/bsp/stm32f1/family.c
index 600f3aaef..8fcf9ebd6 100644
--- a/hw/bsp/stm32f103bluepill/stm32f103bluepill.c
+++ b/hw/bsp/stm32f1/family.c
@@ -24,8 +24,9 @@
* This file is part of the TinyUSB stack.
*/
-#include "../board.h"
#include "stm32f1xx_hal.h"
+#include "bsp/board.h"
+#include "board.h"
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
@@ -48,90 +49,45 @@ void USBWakeUp_IRQHandler(void)
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM
//--------------------------------------------------------------------+
-#define LED_PORT GPIOC
-#define LED_PIN GPIO_PIN_13
-#define LED_STATE_ON 0
-
-#define BUTTON_PORT GPIOA
-#define BUTTON_PIN GPIO_PIN_0
-#define BUTTON_STATE_ACTIVE 1
-
-
-/**
- * @brief System Clock Configuration
- * The system Clock is configured as follow :
- * System Clock source = PLL (HSE)
- * SYSCLK(Hz) = 72000000
- * HCLK(Hz) = 72000000
- * AHB Prescaler = 1
- * APB1 Prescaler = 2
- * APB2 Prescaler = 1
- * HSE Frequency(Hz) = 8000000
- * HSE PREDIV1 = 1
- * PLLMUL = 9
- * Flash Latency(WS) = 2
- * @param None
- * @retval None
- */
-void SystemClock_Config(void)
-{
- RCC_ClkInitTypeDef clkinitstruct = {0};
- RCC_OscInitTypeDef oscinitstruct = {0};
- RCC_PeriphCLKInitTypeDef rccperiphclkinit = {0};
-
- /* Enable HSE Oscillator and activate PLL with HSE as source */
- oscinitstruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
- oscinitstruct.HSEState = RCC_HSE_ON;
- oscinitstruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
- oscinitstruct.PLL.PLLMUL = RCC_PLL_MUL9;
- oscinitstruct.PLL.PLLState = RCC_PLL_ON;
- oscinitstruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
- HAL_RCC_OscConfig(&oscinitstruct);
-
- /* USB clock selection */
- rccperiphclkinit.PeriphClockSelection = RCC_PERIPHCLK_USB;
- rccperiphclkinit.UsbClockSelection = RCC_USBCLKSOURCE_PLL_DIV1_5;
- HAL_RCCEx_PeriphCLKConfig(&rccperiphclkinit);
-
- /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers */
- clkinitstruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
- clkinitstruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
- clkinitstruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
- clkinitstruct.APB1CLKDivider = RCC_HCLK_DIV2;
- clkinitstruct.APB2CLKDivider = RCC_HCLK_DIV1;
- HAL_RCC_ClockConfig(&clkinitstruct, FLASH_LATENCY_2);
-}
void board_init(void)
{
-
- SystemClock_Config();
+ board_stm32f1_clock_init();
- #if CFG_TUSB_OS == OPT_OS_NONE
+ // Enable All GPIOs clocks
+ __HAL_RCC_GPIOA_CLK_ENABLE();
+ __HAL_RCC_GPIOB_CLK_ENABLE();
+ __HAL_RCC_GPIOC_CLK_ENABLE();
+ __HAL_RCC_GPIOD_CLK_ENABLE();
+
+#if CFG_TUSB_OS == OPT_OS_NONE
// 1ms tick timer
SysTick_Config(SystemCoreClock / 1000);
- #endif
+
+#elif CFG_TUSB_OS == OPT_OS_FREERTOS
+ // If freeRTOS is used, IRQ priority is limit by max syscall ( smaller is higher )
+ NVIC_SetPriority(USB_HP_CAN1_TX_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY);
+ NVIC_SetPriority(USB_LP_CAN1_RX0_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY);
+ NVIC_SetPriority(USBWakeUp_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY);
+#endif
// LED
- __HAL_RCC_GPIOC_CLK_ENABLE();
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitStruct.Pin = LED_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
- GPIO_InitStruct.Pull = GPIO_PULLUP;
+ GPIO_InitStruct.Pull = LED_STATE_ON ? GPIO_PULLDOWN : GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(LED_PORT, &GPIO_InitStruct);
// Button
- __HAL_RCC_GPIOA_CLK_ENABLE();
GPIO_InitStruct.Pin = BUTTON_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
- GPIO_InitStruct.Pull = GPIO_PULLDOWN;
+ GPIO_InitStruct.Pull = BUTTON_STATE_ACTIVE ? GPIO_PULLDOWN : GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(BUTTON_PORT, &GPIO_InitStruct);
// USB Pins
// Configure USB DM and DP pins.
- __HAL_RCC_GPIOA_CLK_ENABLE();
GPIO_InitStruct.Pin = (GPIO_PIN_11 | GPIO_PIN_12);
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
diff --git a/hw/bsp/stm32f103bluepill/board.mk b/hw/bsp/stm32f1/family.mk
index 656a37323..3fb2e6e70 100644
--- a/hw/bsp/stm32f103bluepill/board.mk
+++ b/hw/bsp/stm32f1/family.mk
@@ -4,6 +4,8 @@ DEPS_SUBMODULES += lib/CMSIS_5 hw/mcu/st/cmsis_device_$(ST_FAMILY) hw/mcu/st/stm
ST_CMSIS = hw/mcu/st/cmsis_device_$(ST_FAMILY)
ST_HAL_DRIVER = hw/mcu/st/stm32$(ST_FAMILY)xx_hal_driver
+include $(TOP)/$(BOARD_PATH)/board.mk
+
CFLAGS += \
-flto \
-mthumb \
@@ -11,15 +13,12 @@ CFLAGS += \
-mcpu=cortex-m3 \
-mfloat-abi=soft \
-nostdlib -nostartfiles \
- -DSTM32F103xB \
-DCFG_TUSB_MCU=OPT_MCU_STM32F1
# mcu driver cause following warnings
#CFLAGS += -Wno-error=unused-parameter
# All source paths should be relative to the top level.
-LD_FILE = hw/bsp/$(BOARD)/STM32F103XB_FLASH.ld
-
SRC_C += \
src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c \
$(ST_CMSIS)/Source/Templates/system_stm32$(ST_FAMILY)xx.c \
@@ -29,14 +28,11 @@ SRC_C += \
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_rcc_ex.c \
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_gpio.c
-SRC_S += \
- $(ST_CMSIS)/Source/Templates/gcc/startup_stm32f103xb.s
-
INC += \
+ $(TOP)/$(BOARD_PATH) \
$(TOP)/lib/CMSIS_5/CMSIS/Core/Include \
$(TOP)/$(ST_CMSIS)/Include \
- $(TOP)/$(ST_HAL_DRIVER)/Inc \
- $(TOP)/hw/bsp/$(BOARD)
+ $(TOP)/$(ST_HAL_DRIVER)/Inc
# For freeRTOS port source
FREERTOS_PORT = ARM_CM3
@@ -45,5 +41,5 @@ FREERTOS_PORT = ARM_CM3
JLINK_DEVICE = stm32f103c8
# flash target ROM bootloader
-flash: $(BUILD)/$(PROJECT).bin
+flash-dfu-util: $(BUILD)/$(PROJECT).bin
dfu-util -R -a 0 --dfuse-address 0x08000000 -D $<
diff --git a/hw/bsp/stm32f103bluepill/stm32f1xx_hal_conf.h b/hw/bsp/stm32f1/stm32f1xx_hal_conf.h
index a4a3f3086..a4a3f3086 100644
--- a/hw/bsp/stm32f103bluepill/stm32f1xx_hal_conf.h
+++ b/hw/bsp/stm32f1/stm32f1xx_hal_conf.h