clang g0, g4

This commit is contained in:
hathach
2024-04-23 15:56:22 +07:00
parent 9e7046cbf1
commit 75d376a439
7 changed files with 70 additions and 68 deletions

View File

@@ -49,7 +49,7 @@
/* Cortex M23/M33 port configuration. */ /* Cortex M23/M33 port configuration. */
#define configENABLE_MPU 0 #define configENABLE_MPU 0
#define configENABLE_FPU 1 #define configENABLE_FPU 0
#define configENABLE_TRUSTZONE 0 #define configENABLE_TRUSTZONE 0
#define configMINIMAL_SECURE_STACK_SIZE (1024) #define configMINIMAL_SECURE_STACK_SIZE (1024)

View File

@@ -52,12 +52,6 @@
/* Entry Point */ /* Entry Point */
ENTRY(Reset_Handler) ENTRY(Reset_Handler)
/* Highest address of the user mode stack */
_estack = ORIGIN(RAM) + LENGTH(RAM); /* 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 */ /* Specify the memory areas */
MEMORY MEMORY
{ {
@@ -65,6 +59,13 @@ RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 144K
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 512K FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 512K
} }
/* Highest address of the user mode stack */
_estack = ORIGIN(RAM) + LENGTH(RAM); /* 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 */
/* Define output sections */ /* Define output sections */
SECTIONS SECTIONS
{ {

View File

@@ -179,7 +179,6 @@ void SysTick_Handler(void) {
uint32_t board_millis(void) { uint32_t board_millis(void) {
return system_ticks; return system_ticks;
} }
#endif #endif
void HardFault_Handler(void) { void HardFault_Handler(void) {

View File

@@ -1,9 +1,5 @@
include_guard() include_guard()
if (NOT BOARD)
message(FATAL_ERROR "BOARD not specified")
endif ()
set(ST_FAMILY g0) set(ST_FAMILY g0)
set(ST_PREFIX stm32${ST_FAMILY}xx) set(ST_PREFIX stm32${ST_FAMILY}xx)
@@ -26,52 +22,57 @@ set(FAMILY_MCUS STM32G0 CACHE INTERNAL "")
#------------------------------------ #------------------------------------
# only need to be built ONCE for all examples # only need to be built ONCE for all examples
function(add_board_target BOARD_TARGET) function(add_board_target BOARD_TARGET)
if (NOT TARGET ${BOARD_TARGET}) if (TARGET ${BOARD_TARGET})
# Startup & Linker script return()
set(STARTUP_FILE_GNU ${ST_CMSIS}/Source/Templates/gcc/startup_${MCU_VARIANT}.s) endif ()
set(STARTUP_FILE_IAR ${ST_CMSIS}/Source/Templates/iar/startup_${MCU_VARIANT}.s)
set(LD_FILE_IAR ${ST_CMSIS}/Source/Templates/iar/linker/${MCU_VARIANT}_flash.icf)
add_library(${BOARD_TARGET} STATIC # Startup & Linker script
${ST_CMSIS}/Source/Templates/system_${ST_PREFIX}.c set(STARTUP_FILE_GNU ${ST_CMSIS}/Source/Templates/gcc/startup_${MCU_VARIANT}.s)
${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal.c set(STARTUP_FILE_Clang ${STARTUP_FILE_GNU})
${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal_cortex.c set(STARTUP_FILE_IAR ${ST_CMSIS}/Source/Templates/iar/startup_${MCU_VARIANT}.s)
${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal_pwr.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
${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal_dma.c
${STARTUP_FILE_${CMAKE_C_COMPILER_ID}}
)
target_include_directories(${BOARD_TARGET} PUBLIC
${CMAKE_CURRENT_FUNCTION_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}) set(LD_FILE_Clang ${LD_FILE_GNU})
set(LD_FILE_IAR ${ST_CMSIS}/Source/Templates/iar/linker/${MCU_VARIANT}_flash.icf)
if (CMAKE_C_COMPILER_ID STREQUAL "GNU") add_library(${BOARD_TARGET} STATIC
target_link_options(${BOARD_TARGET} PUBLIC ${ST_CMSIS}/Source/Templates/system_${ST_PREFIX}.c
"LINKER:--script=${LD_FILE_GNU}" ${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal.c
-nostartfiles ${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal_cortex.c
# nanolib ${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal_pwr.c
--specs=nosys.specs ${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal_pwr_ex.c
--specs=nano.specs ${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal_rcc.c
) ${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal_rcc_ex.c
elseif (CMAKE_C_COMPILER_ID STREQUAL "IAR") ${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal_gpio.c
target_link_options(${BOARD_TARGET} PUBLIC ${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal_uart.c
"LINKER:--config=${LD_FILE_IAR}" ${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal_uart_ex.c
) ${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal_dma.c
endif () ${STARTUP_FILE_${CMAKE_C_COMPILER_ID}}
)
target_include_directories(${BOARD_TARGET} PUBLIC
${CMAKE_CURRENT_FUNCTION_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})
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
target_link_options(${BOARD_TARGET} PUBLIC
"LINKER:--script=${LD_FILE_GNU}"
-nostartfiles
--specs=nosys.specs --specs=nano.specs
)
elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang")
target_link_options(${BOARD_TARGET} PUBLIC
"LINKER:--script=${LD_FILE_Clang}"
)
elseif (CMAKE_C_COMPILER_ID STREQUAL "IAR")
target_link_options(${BOARD_TARGET} PUBLIC
"LINKER:--config=${LD_FILE_IAR}"
)
endif () endif ()
endfunction() endfunction()
@@ -112,5 +113,5 @@ function(family_configure_example TARGET RTOS)
# Flashing # Flashing
family_flash_stlink(${TARGET}) family_flash_stlink(${TARGET})
#family_flash_jlink(${TARGET}) family_flash_jlink(${TARGET})
endfunction() endfunction()

View File

@@ -52,12 +52,6 @@
/* Entry Point */ /* Entry Point */
ENTRY(Reset_Handler) ENTRY(Reset_Handler)
/* Highest address of the user mode stack */
_estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */
_Min_Heap_Size = 0x1000 ; /* required amount of heap */
_Min_Stack_Size = 0x1000 ; /* required amount of stack */
/* Memories definition */ /* Memories definition */
MEMORY MEMORY
{ {
@@ -65,6 +59,12 @@ MEMORY
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 512K FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 512K
} }
/* Highest address of the user mode stack */
_estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */
_Min_Heap_Size = 0x1000 ; /* required amount of heap */
_Min_Stack_Size = 0x1000 ; /* required amount of stack */
/* Sections */ /* Sections */
SECTIONS SECTIONS
{ {

View File

@@ -209,7 +209,6 @@ void SysTick_Handler(void) {
uint32_t board_millis(void) { uint32_t board_millis(void) {
return system_ticks; return system_ticks;
} }
#endif #endif
void HardFault_Handler(void) { void HardFault_Handler(void) {

View File

@@ -1,9 +1,5 @@
include_guard() include_guard()
if (NOT BOARD)
message(FATAL_ERROR "BOARD not specified")
endif ()
set(ST_FAMILY g4) set(ST_FAMILY g4)
set(ST_PREFIX stm32${ST_FAMILY}xx) set(ST_PREFIX stm32${ST_FAMILY}xx)
@@ -32,7 +28,10 @@ function(add_board_target BOARD_TARGET)
# Startup & Linker script # Startup & Linker script
set(STARTUP_FILE_GNU ${ST_CMSIS}/Source/Templates/gcc/startup_${MCU_VARIANT}.s) set(STARTUP_FILE_GNU ${ST_CMSIS}/Source/Templates/gcc/startup_${MCU_VARIANT}.s)
set(STARTUP_FILE_Clang ${STARTUP_FILE_GNU})
set(STARTUP_FILE_IAR ${ST_CMSIS}/Source/Templates/iar/startup_${MCU_VARIANT}.s) set(STARTUP_FILE_IAR ${ST_CMSIS}/Source/Templates/iar/startup_${MCU_VARIANT}.s)
set(LD_FILE_Clang ${LD_FILE_GNU})
set(LD_FILE_IAR ${ST_CMSIS}/Source/Templates/iar/linker/${MCU_VARIANT}_flash.icf) set(LD_FILE_IAR ${ST_CMSIS}/Source/Templates/iar/linker/${MCU_VARIANT}_flash.icf)
add_library(${BOARD_TARGET} STATIC add_library(${BOARD_TARGET} STATIC
@@ -59,9 +58,12 @@ function(add_board_target BOARD_TARGET)
target_link_options(${BOARD_TARGET} PUBLIC target_link_options(${BOARD_TARGET} PUBLIC
"LINKER:--script=${LD_FILE_GNU}" "LINKER:--script=${LD_FILE_GNU}"
-nostartfiles -nostartfiles
# nanolib
--specs=nosys.specs --specs=nano.specs --specs=nosys.specs --specs=nano.specs
) )
elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang")
target_link_options(${BOARD_TARGET} PUBLIC
"LINKER:--script=${LD_FILE_Clang}"
)
elseif (CMAKE_C_COMPILER_ID STREQUAL "IAR") elseif (CMAKE_C_COMPILER_ID STREQUAL "IAR")
target_link_options(${BOARD_TARGET} PUBLIC target_link_options(${BOARD_TARGET} PUBLIC
"LINKER:--config=${LD_FILE_IAR}" "LINKER:--config=${LD_FILE_IAR}"