summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <[email protected]>2023-06-01 15:58:02 +0700
committerhathach <[email protected]>2023-06-01 15:58:02 +0700
commit6b44d8fb55345e19fd82a6169258fbf357a15f81 (patch)
treecb0ba130893425b672488dfe5a55093cb228a08d
parentaf59864ab51d43b0308df617097949b399c5d112 (diff)
add cmake support for g0, exlicitly call HAL_Init() and also HAL_IncTick() in systick irq, fix button active state.
-rw-r--r--hw/bsp/lpc18/family.cmake5
-rw-r--r--hw/bsp/stm32g0/boards/stm32g0b1nucleo/board.cmake15
-rw-r--r--hw/bsp/stm32g0/boards/stm32g0b1nucleo/board.h15
-rw-r--r--hw/bsp/stm32g0/family.c2
-rw-r--r--hw/bsp/stm32g0/family.cmake137
-rw-r--r--tools/cmake/cpu/cortex-m0plus.cmake11
6 files changed, 169 insertions, 16 deletions
diff --git a/hw/bsp/lpc18/family.cmake b/hw/bsp/lpc18/family.cmake
index 1bfc63d21..515348e10 100644
--- a/hw/bsp/lpc18/family.cmake
+++ b/hw/bsp/lpc18/family.cmake
@@ -46,14 +46,9 @@ if (NOT TARGET ${BOARD_TARGET})
)
update_board(${BOARD_TARGET})
- if (NOT DEFINED LD_FILE_${TOOLCHAIN})
- MESSAGE(FATAL_ERROR "LD_FILE_${TOOLCHAIN} not defined")
- endif ()
-
if (TOOLCHAIN STREQUAL "gcc")
target_link_options(${BOARD_TARGET} PUBLIC
"LINKER:--script=${LD_FILE_gcc}"
- "LINKER:-Map=$<IF:$<BOOL:$<TARGET_PROPERTY:OUTPUT_NAME>>,$<TARGET_PROPERTY:OUTPUT_NAME>,$<TARGET_PROPERTY:NAME>>${CMAKE_EXECUTABLE_SUFFIX}.map"
# nanolib
--specs=nosys.specs
--specs=nano.specs
diff --git a/hw/bsp/stm32g0/boards/stm32g0b1nucleo/board.cmake b/hw/bsp/stm32g0/boards/stm32g0b1nucleo/board.cmake
new file mode 100644
index 000000000..c9f2a9c8e
--- /dev/null
+++ b/hw/bsp/stm32g0/boards/stm32g0b1nucleo/board.cmake
@@ -0,0 +1,15 @@
+#set(MCU_VARIANT MIMXRT1011)
+set(JLINK_DEVICE STM32G0B1RE)
+
+set(LD_FILE_gcc ${CMAKE_CURRENT_LIST_DIR}/STM32G0B1RETx_FLASH.ld)
+set(LD_FILE_iar ${ST_CMSIS}/Source/Templates/iar/linker/stm32g0b1xx_flash.icf)
+
+set(STARTUP_FILE_gcc ${ST_CMSIS}/Source/Templates/gcc/startup_stm32g0b1xx.s)
+set(STARTUP_FILE_iar ${ST_CMSIS}/Source/Templates/iar/startup_stm32g0b1xx.s)
+
+function(update_board TARGET)
+ target_compile_definitions(${TARGET} PUBLIC
+ STM32G0B1xx
+ #HSE_VALUE=8000000U
+ )
+endfunction()
diff --git a/hw/bsp/stm32g0/boards/stm32g0b1nucleo/board.h b/hw/bsp/stm32g0/boards/stm32g0b1nucleo/board.h
index 0d651ea4e..e622c71c2 100644
--- a/hw/bsp/stm32g0/boards/stm32g0b1nucleo/board.h
+++ b/hw/bsp/stm32g0/boards/stm32g0b1nucleo/board.h
@@ -44,7 +44,7 @@
// Button
#define BUTTON_PORT GPIOC
#define BUTTON_PIN GPIO_PIN_13
-#define BUTTON_STATE_ACTIVE 1
+#define BUTTON_STATE_ACTIVE 0
// UART Enable for STLink VCOM
#define UART_DEV USART2
@@ -64,17 +64,11 @@ static inline void board_clock_init(void)
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = { 0 };
- /** Tick priority is used in HAL_RCC_OscConfig, so we need to enable it now
- */
- HAL_InitTick(0);
-
- /** Configure the main internal regulator output voltage
- */
+ /** Configure the main internal regulator output voltage */
HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1);
/** Initializes the RCC Oscillators according to the specified parameters
- * in the RCC_OscInitTypeDef structure.
- */
+ * in the RCC_OscInitTypeDef structure. */
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
@@ -91,8 +85,7 @@ static inline void board_clock_init(void)
PeriphClkInitStruct.UsbClockSelection = RCC_USBCLKSOURCE_PLL;
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
- /** Initializes the CPU, AHB and APB buses clocks
- */
+ /** Initializes the CPU, AHB and APB buses clocks */
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
diff --git a/hw/bsp/stm32g0/family.c b/hw/bsp/stm32g0/family.c
index 10023b7e2..1a975915f 100644
--- a/hw/bsp/stm32g0/family.c
+++ b/hw/bsp/stm32g0/family.c
@@ -44,6 +44,7 @@ UART_HandleTypeDef UartHandle;
void board_init(void)
{
+ HAL_Init(); // required for HAL_RCC_Osc TODO check with freeRTOS
board_clock_init();
// Enable All GPIOs clocks
@@ -162,6 +163,7 @@ volatile uint32_t system_ticks = 0;
void SysTick_Handler (void)
{
system_ticks++;
+ HAL_IncTick();
}
uint32_t board_millis(void)
diff --git a/hw/bsp/stm32g0/family.cmake b/hw/bsp/stm32g0/family.cmake
new file mode 100644
index 000000000..5fc9387e5
--- /dev/null
+++ b/hw/bsp/stm32g0/family.cmake
@@ -0,0 +1,137 @@
+include_guard()
+
+if (NOT BOARD)
+ message(FATAL_ERROR "BOARD not specified")
+endif ()
+
+set(ST_FAMILY g0)
+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(CMSIS_5 ${TOP}/lib/CMSIS_5)
+
+# enable LTO
+#set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
+
+# toolchain set up
+set(CMAKE_SYSTEM_PROCESSOR cortex-m0plus CACHE INTERNAL "System Processor")
+set(CMAKE_TOOLCHAIN_FILE ${TOP}/tools/cmake/toolchain/arm_${TOOLCHAIN}.cmake)
+
+set(FAMILY_MCUS STM32G0 CACHE INTERNAL "")
+
+# include board specific
+include(${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}/board.cmake)
+
+
+#------------------------------------
+# BOARD_TARGET
+#------------------------------------
+# only need to be built ONCE for all examples
+set(BOARD_TARGET board_${BOARD})
+if (NOT TARGET ${BOARD_TARGET})
+ add_library(${BOARD_TARGET} STATIC
+ ${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_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_gpio.c
+ ${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal_uart.c
+ ${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal_uart_ex.c
+ )
+ target_include_directories(${BOARD_TARGET} PUBLIC
+ ${CMAKE_CURRENT_LIST_DIR}
+ ${CMSIS_5}/CMSIS/Core/Include
+ ${ST_CMSIS}/Include
+ ${ST_HAL_DRIVER}/Inc
+ )
+ target_compile_options(${BOARD_TARGET} PUBLIC
+ )
+ target_compile_definitions(${BOARD_TARGET} PUBLIC
+ )
+ update_board(${BOARD_TARGET})
+
+ target_sources(${BOARD_TARGET} PUBLIC
+ ${STARTUP_FILE_${TOOLCHAIN}}
+ )
+
+ if (TOOLCHAIN STREQUAL "gcc")
+ target_link_options(${BOARD_TARGET} PUBLIC
+ "LINKER:--script=${LD_FILE_gcc}"
+ -nostartfiles
+ # nanolib
+ --specs=nosys.specs
+ --specs=nano.specs
+ )
+ else ()
+ # TODO support IAR
+ target_link_options(${BOARD_TARGET} PUBLIC
+ "LINKER:--config=${LD_FILE_iar}"
+ )
+ endif ()
+endif () # BOARD_TARGET
+
+
+#------------------------------------
+# Functions
+#------------------------------------
+function(family_configure_example TARGET)
+ family_configure_common(${TARGET})
+
+ #---------- Port Specific ----------
+ # These files are built for each example since it depends on example's tusb_config.h
+ target_sources(${TARGET} PUBLIC
+ # TinyUSB Port
+ ${TOP}/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c
+ # BSP
+ ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/family.c
+ ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../board.c
+ )
+ target_include_directories(${TARGET} PUBLIC
+ # family, hw, board
+ ${CMAKE_CURRENT_FUNCTION_LIST_DIR}
+ ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../../
+ ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/boards/${BOARD}
+ )
+
+ #---------- TinyUSB ----------
+ # tinyusb target is built for each example since it depends on example's tusb_config.h
+ set(TINYUSB_TARGET_PREFIX ${TARGET}-)
+ add_library(${TARGET}-tinyusb_config INTERFACE)
+
+ target_include_directories(${TARGET}-tinyusb_config INTERFACE
+ ${CMAKE_CURRENT_SOURCE_DIR}/src
+ )
+ target_compile_definitions(${TARGET}-tinyusb_config INTERFACE
+ CFG_TUSB_MCU=OPT_MCU_STM32G0
+ )
+
+ # tinyusb's CMakeList.txt
+ add_subdirectory(${TOP}/src ${CMAKE_CURRENT_BINARY_DIR}/tinyusb)
+
+ # Link dependencies
+ target_link_libraries(${TARGET} PUBLIC ${BOARD_TARGET} ${TARGET}-tinyusb)
+
+ # group target (not yet supported by clion)
+ set_target_properties(${TARGET}-tinyusb ${TARGET}-tinyusb_config
+ PROPERTIES FOLDER ${TARGET}_sub
+ )
+
+ #---------- Flash ----------
+ family_flash_jlink(${TARGET})
+endfunction()
+
+
+function(family_configure_device_example TARGET)
+ family_configure_example(${TARGET})
+endfunction()
+
+function(family_configure_host_example TARGET)
+ family_configure_example(${TARGET})
+endfunction()
+
+function(family_configure_dual_usb_example TARGET)
+ family_configure_example(${TARGET})
+endfunction()
diff --git a/tools/cmake/cpu/cortex-m0plus.cmake b/tools/cmake/cpu/cortex-m0plus.cmake
new file mode 100644
index 000000000..1e316ccfc
--- /dev/null
+++ b/tools/cmake/cpu/cortex-m0plus.cmake
@@ -0,0 +1,11 @@
+if (TOOLCHAIN STREQUAL "gcc")
+ list(APPEND TOOLCHAIN_COMMON_FLAGS
+ -mthumb
+ -mcpu=cortex-m0plus
+ -mfloat-abi=soft
+ )
+
+ set(FREERTOS_PORT GCC_ARM_CM0 CACHE INTERNAL "")
+else ()
+ # TODO support IAR
+endif ()