Skip to content

Commit 6b44d8f

Browse files
committed
add cmake support for g0, exlicitly call HAL_Init() and also HAL_IncTick() in systick irq, fix button active state.
1 parent af59864 commit 6b44d8f

File tree

6 files changed

+169
-16
lines changed

6 files changed

+169
-16
lines changed

hw/bsp/lpc18/family.cmake

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,9 @@ if (NOT TARGET ${BOARD_TARGET})
4646
)
4747
update_board(${BOARD_TARGET})
4848

49-
if (NOT DEFINED LD_FILE_${TOOLCHAIN})
50-
MESSAGE(FATAL_ERROR "LD_FILE_${TOOLCHAIN} not defined")
51-
endif ()
52-
5349
if (TOOLCHAIN STREQUAL "gcc")
5450
target_link_options(${BOARD_TARGET} PUBLIC
5551
"LINKER:--script=${LD_FILE_gcc}"
56-
"LINKER:-Map=$<IF:$<BOOL:$<TARGET_PROPERTY:OUTPUT_NAME>>,$<TARGET_PROPERTY:OUTPUT_NAME>,$<TARGET_PROPERTY:NAME>>${CMAKE_EXECUTABLE_SUFFIX}.map"
5752
# nanolib
5853
--specs=nosys.specs
5954
--specs=nano.specs
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#set(MCU_VARIANT MIMXRT1011)
2+
set(JLINK_DEVICE STM32G0B1RE)
3+
4+
set(LD_FILE_gcc ${CMAKE_CURRENT_LIST_DIR}/STM32G0B1RETx_FLASH.ld)
5+
set(LD_FILE_iar ${ST_CMSIS}/Source/Templates/iar/linker/stm32g0b1xx_flash.icf)
6+
7+
set(STARTUP_FILE_gcc ${ST_CMSIS}/Source/Templates/gcc/startup_stm32g0b1xx.s)
8+
set(STARTUP_FILE_iar ${ST_CMSIS}/Source/Templates/iar/startup_stm32g0b1xx.s)
9+
10+
function(update_board TARGET)
11+
target_compile_definitions(${TARGET} PUBLIC
12+
STM32G0B1xx
13+
#HSE_VALUE=8000000U
14+
)
15+
endfunction()

hw/bsp/stm32g0/boards/stm32g0b1nucleo/board.h

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
// Button
4545
#define BUTTON_PORT GPIOC
4646
#define BUTTON_PIN GPIO_PIN_13
47-
#define BUTTON_STATE_ACTIVE 1
47+
#define BUTTON_STATE_ACTIVE 0
4848

4949
// UART Enable for STLink VCOM
5050
#define UART_DEV USART2
@@ -64,17 +64,11 @@ static inline void board_clock_init(void)
6464
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
6565
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = { 0 };
6666

67-
/** Tick priority is used in HAL_RCC_OscConfig, so we need to enable it now
68-
*/
69-
HAL_InitTick(0);
70-
71-
/** Configure the main internal regulator output voltage
72-
*/
67+
/** Configure the main internal regulator output voltage */
7368
HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1);
7469

7570
/** Initializes the RCC Oscillators according to the specified parameters
76-
* in the RCC_OscInitTypeDef structure.
77-
*/
71+
* in the RCC_OscInitTypeDef structure. */
7872
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
7973
RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS;
8074
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
@@ -91,8 +85,7 @@ static inline void board_clock_init(void)
9185
PeriphClkInitStruct.UsbClockSelection = RCC_USBCLKSOURCE_PLL;
9286
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
9387

94-
/** Initializes the CPU, AHB and APB buses clocks
95-
*/
88+
/** Initializes the CPU, AHB and APB buses clocks */
9689
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
9790
|RCC_CLOCKTYPE_PCLK1;
9891
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;

hw/bsp/stm32g0/family.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ UART_HandleTypeDef UartHandle;
4444

4545
void board_init(void)
4646
{
47+
HAL_Init(); // required for HAL_RCC_Osc TODO check with freeRTOS
4748
board_clock_init();
4849

4950
// Enable All GPIOs clocks
@@ -162,6 +163,7 @@ volatile uint32_t system_ticks = 0;
162163
void SysTick_Handler (void)
163164
{
164165
system_ticks++;
166+
HAL_IncTick();
165167
}
166168

167169
uint32_t board_millis(void)

hw/bsp/stm32g0/family.cmake

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
include_guard()
2+
3+
if (NOT BOARD)
4+
message(FATAL_ERROR "BOARD not specified")
5+
endif ()
6+
7+
set(ST_FAMILY g0)
8+
set(ST_PREFIX stm32${ST_FAMILY}xx)
9+
10+
set(ST_HAL_DRIVER ${TOP}/hw/mcu/st/stm32${ST_FAMILY}xx_hal_driver)
11+
set(ST_CMSIS ${TOP}/hw/mcu/st/cmsis_device_${ST_FAMILY})
12+
set(CMSIS_5 ${TOP}/lib/CMSIS_5)
13+
14+
# enable LTO
15+
#set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
16+
17+
# toolchain set up
18+
set(CMAKE_SYSTEM_PROCESSOR cortex-m0plus CACHE INTERNAL "System Processor")
19+
set(CMAKE_TOOLCHAIN_FILE ${TOP}/tools/cmake/toolchain/arm_${TOOLCHAIN}.cmake)
20+
21+
set(FAMILY_MCUS STM32G0 CACHE INTERNAL "")
22+
23+
# include board specific
24+
include(${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}/board.cmake)
25+
26+
27+
#------------------------------------
28+
# BOARD_TARGET
29+
#------------------------------------
30+
# only need to be built ONCE for all examples
31+
set(BOARD_TARGET board_${BOARD})
32+
if (NOT TARGET ${BOARD_TARGET})
33+
add_library(${BOARD_TARGET} STATIC
34+
${ST_CMSIS}/Source/Templates/system_${ST_PREFIX}.c
35+
${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal.c
36+
${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal_cortex.c
37+
${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal_pwr_ex.c
38+
${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal_rcc.c
39+
${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal_rcc_ex.c
40+
${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal_gpio.c
41+
${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal_uart.c
42+
${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal_uart_ex.c
43+
)
44+
target_include_directories(${BOARD_TARGET} PUBLIC
45+
${CMAKE_CURRENT_LIST_DIR}
46+
${CMSIS_5}/CMSIS/Core/Include
47+
${ST_CMSIS}/Include
48+
${ST_HAL_DRIVER}/Inc
49+
)
50+
target_compile_options(${BOARD_TARGET} PUBLIC
51+
)
52+
target_compile_definitions(${BOARD_TARGET} PUBLIC
53+
)
54+
update_board(${BOARD_TARGET})
55+
56+
target_sources(${BOARD_TARGET} PUBLIC
57+
${STARTUP_FILE_${TOOLCHAIN}}
58+
)
59+
60+
if (TOOLCHAIN STREQUAL "gcc")
61+
target_link_options(${BOARD_TARGET} PUBLIC
62+
"LINKER:--script=${LD_FILE_gcc}"
63+
-nostartfiles
64+
# nanolib
65+
--specs=nosys.specs
66+
--specs=nano.specs
67+
)
68+
else ()
69+
# TODO support IAR
70+
target_link_options(${BOARD_TARGET} PUBLIC
71+
"LINKER:--config=${LD_FILE_iar}"
72+
)
73+
endif ()
74+
endif () # BOARD_TARGET
75+
76+
77+
#------------------------------------
78+
# Functions
79+
#------------------------------------
80+
function(family_configure_example TARGET)
81+
family_configure_common(${TARGET})
82+
83+
#---------- Port Specific ----------
84+
# These files are built for each example since it depends on example's tusb_config.h
85+
target_sources(${TARGET} PUBLIC
86+
# TinyUSB Port
87+
${TOP}/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c
88+
# BSP
89+
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/family.c
90+
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../board.c
91+
)
92+
target_include_directories(${TARGET} PUBLIC
93+
# family, hw, board
94+
${CMAKE_CURRENT_FUNCTION_LIST_DIR}
95+
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../../
96+
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/boards/${BOARD}
97+
)
98+
99+
#---------- TinyUSB ----------
100+
# tinyusb target is built for each example since it depends on example's tusb_config.h
101+
set(TINYUSB_TARGET_PREFIX ${TARGET}-)
102+
add_library(${TARGET}-tinyusb_config INTERFACE)
103+
104+
target_include_directories(${TARGET}-tinyusb_config INTERFACE
105+
${CMAKE_CURRENT_SOURCE_DIR}/src
106+
)
107+
target_compile_definitions(${TARGET}-tinyusb_config INTERFACE
108+
CFG_TUSB_MCU=OPT_MCU_STM32G0
109+
)
110+
111+
# tinyusb's CMakeList.txt
112+
add_subdirectory(${TOP}/src ${CMAKE_CURRENT_BINARY_DIR}/tinyusb)
113+
114+
# Link dependencies
115+
target_link_libraries(${TARGET} PUBLIC ${BOARD_TARGET} ${TARGET}-tinyusb)
116+
117+
# group target (not yet supported by clion)
118+
set_target_properties(${TARGET}-tinyusb ${TARGET}-tinyusb_config
119+
PROPERTIES FOLDER ${TARGET}_sub
120+
)
121+
122+
#---------- Flash ----------
123+
family_flash_jlink(${TARGET})
124+
endfunction()
125+
126+
127+
function(family_configure_device_example TARGET)
128+
family_configure_example(${TARGET})
129+
endfunction()
130+
131+
function(family_configure_host_example TARGET)
132+
family_configure_example(${TARGET})
133+
endfunction()
134+
135+
function(family_configure_dual_usb_example TARGET)
136+
family_configure_example(${TARGET})
137+
endfunction()

tools/cmake/cpu/cortex-m0plus.cmake

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
if (TOOLCHAIN STREQUAL "gcc")
2+
list(APPEND TOOLCHAIN_COMMON_FLAGS
3+
-mthumb
4+
-mcpu=cortex-m0plus
5+
-mfloat-abi=soft
6+
)
7+
8+
set(FREERTOS_PORT GCC_ARM_CM0 CACHE INTERNAL "")
9+
else ()
10+
# TODO support IAR
11+
endif ()

0 commit comments

Comments
 (0)