Update template to modern GCC #1

Merged
thomas merged 8 commits from logan/CH32V203:master into master 2023-11-25 01:59:18 -05:00
5 changed files with 19 additions and 12 deletions

View file

@ -1,11 +1,11 @@
cmake_minimum_required(VERSION 3.10) cmake_minimum_required(VERSION 3.10)
project(bacstat) project(hello-world)
# set(CMAKE_VERBOSE_MAKEFILE ON) # set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_C_COMPILER riscv-none-embed-gcc) set(CMAKE_C_COMPILER riscv-none-elf-gcc)
set(CMAKE_CXX_COMPILER riscv-none-embed-gcc) set(CMAKE_CXX_COMPILER riscv-none-elf-gcc)
set(CMAKE_OBJCOPY riscv-none-embed-objcopy) set(CMAKE_OBJCOPY riscv-none-elf-objcopy)
set(CMAKE_SIZE riscv-none-embed-size) set(CMAKE_SIZE riscv-none-elf-size)
set_property(SOURCE Startup/startup_ch32v20x_D6.S PROPERTY LANGUAGE C) set_property(SOURCE Startup/startup_ch32v20x_D6.S PROPERTY LANGUAGE C)
@ -21,7 +21,7 @@ include_directories(Peripheral/inc)
add_definitions(-finline-functions-called-once -g) add_definitions(-finline-functions-called-once -g)
add_definitions(-Wall -march=rv32ec -mabi=ilp32e -msmall-data-limit=0 -msave-restore -Os -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -fno-common) add_definitions(-Wall -Wextra -march=rv32imac_zicsr_zifencei -mabi=ilp32 -msmall-data-limit=0 -msave-restore -Os -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -fno-common -mcmodel=medany)
file(GLOB SOURCES "Debug/*.c" "Core/*.c" "User/*.c" "Peripheral/src/*.c" "Startup/*.S") file(GLOB SOURCES "Debug/*.c" "Core/*.c" "User/*.c" "Peripheral/src/*.c" "Startup/*.S")
@ -35,4 +35,5 @@ add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}.siz
ARGS --format=berkeley ${CMAKE_PROJECT_NAME}.elf) ARGS --format=berkeley ${CMAKE_PROJECT_NAME}.elf)
add_executable(${CMAKE_PROJECT_NAME}.elf ${SOURCES}) add_executable(${CMAKE_PROJECT_NAME}.elf ${SOURCES})
target_link_options(${CMAKE_PROJECT_NAME}.elf PRIVATE -T ${CMAKE_SOURCE_DIR}/Ld/Link.ld -Os -march=rv32ec -mabi=ilp32e -nostartfiles -Xlinker -gc-sections -static --specs=nano.specs --specs=nosys.specs)
target_link_options(${CMAKE_PROJECT_NAME}.elf PRIVATE -T ${CMAKE_SOURCE_DIR}/Ld/Link.ld -Os -march=rv32imac_zicsr_zifencei -mabi=ilp32 -nostartfiles -Xlinker -gc-sections -static --specs=nano.specs --specs=nosys.specs -mcmodel=medany)

View file

@ -182,7 +182,7 @@ void USART_Printf_Init(uint32_t baudrate)
* @return size: Data length * @return size: Data length
*/ */
__attribute__((used)) __attribute__((used))
int _write(int fd, char *buf, int size) int _write(__attribute__((unused)) int fd, char *buf, int size)
{ {
int i; int i;

View file

@ -185,6 +185,8 @@ void ADC_StructInit(ADC_InitTypeDef *ADC_InitStruct)
ADC_InitStruct->ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1; ADC_InitStruct->ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1;
ADC_InitStruct->ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStruct->ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStruct->ADC_NbrOfChannel = 1; ADC_InitStruct->ADC_NbrOfChannel = 1;
ADC_InitStruct->ADC_OutputBuffer = DISABLE;
ADC_InitStruct->ADC_Pga = ADC_Pga_1;
} }
/********************************************************************* /*********************************************************************

View file

@ -9,8 +9,12 @@
*******************************************************************************/ *******************************************************************************/
#include "ch32v20x_it.h" #include "ch32v20x_it.h"
void NMI_Handler(void) __attribute__((interrupt("WCH-Interrupt-fast"))); // Upstream GCC as of version 12 does not support these, use normal ones instead :(
void HardFault_Handler(void) __attribute__((interrupt("WCH-Interrupt-fast"))); // If you are using a compiler that supports these, uncomment these lines instead, and use WCH-Interrupt-fast for new handlers
//void NMI_Handler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
//void HardFault_Handler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
void NMI_Handler(void) __attribute__((interrupt));
void HardFault_Handler(void) __attribute__((interrupt));
/********************************************************************* /*********************************************************************
* @fn NMI_Handler * @fn NMI_Handler

View file

@ -36,7 +36,7 @@ int main(void)
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
Delay_Init(); Delay_Init();
USART_Printf_Init(115200); USART_Printf_Init(115200);
printf("SystemClk:%d\r\n", SystemCoreClock); printf("SystemClk:%ld\r\n", SystemCoreClock);
printf("This is printf example\r\n"); printf("This is printf example\r\n");