diff --git a/CMakeLists.txt b/CMakeLists.txt index 2f5c156..04ae673 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,11 @@ cmake_minimum_required(VERSION 3.10) -project(bacstat) +project(hello-world) # set(CMAKE_VERBOSE_MAKEFILE ON) -set(CMAKE_C_COMPILER riscv-none-embed-gcc) -set(CMAKE_CXX_COMPILER riscv-none-embed-gcc) -set(CMAKE_OBJCOPY riscv-none-embed-objcopy) -set(CMAKE_SIZE riscv-none-embed-size) +set(CMAKE_C_COMPILER riscv-none-elf-gcc) +set(CMAKE_CXX_COMPILER riscv-none-elf-gcc) +set(CMAKE_OBJCOPY riscv-none-elf-objcopy) +set(CMAKE_SIZE riscv-none-elf-size) 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(-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") @@ -34,5 +34,6 @@ add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}.siz COMMAND ${CMAKE_SIZE} ARGS --format=berkeley ${CMAKE_PROJECT_NAME}.elf) - 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) +add_executable(${CMAKE_PROJECT_NAME}.elf ${SOURCES}) + +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) diff --git a/Debug/debug.c b/Debug/debug.c index 89117bd..9acbb87 100644 --- a/Debug/debug.c +++ b/Debug/debug.c @@ -182,7 +182,7 @@ void USART_Printf_Init(uint32_t baudrate) * @return size: Data length */ __attribute__((used)) -int _write(int fd, char *buf, int size) +int _write(__attribute__((unused)) int fd, char *buf, int size) { int i; diff --git a/Peripheral/src/ch32v20x_adc.c b/Peripheral/src/ch32v20x_adc.c index 4d642cf..f782679 100644 --- a/Peripheral/src/ch32v20x_adc.c +++ b/Peripheral/src/ch32v20x_adc.c @@ -185,6 +185,8 @@ void ADC_StructInit(ADC_InitTypeDef *ADC_InitStruct) ADC_InitStruct->ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1; ADC_InitStruct->ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStruct->ADC_NbrOfChannel = 1; + ADC_InitStruct->ADC_OutputBuffer = DISABLE; + ADC_InitStruct->ADC_Pga = ADC_Pga_1; } /********************************************************************* diff --git a/User/ch32v20x_it.c b/User/ch32v20x_it.c index c997d9e..092e9a0 100644 --- a/User/ch32v20x_it.c +++ b/User/ch32v20x_it.c @@ -9,8 +9,12 @@ *******************************************************************************/ #include "ch32v20x_it.h" -void NMI_Handler(void) __attribute__((interrupt("WCH-Interrupt-fast"))); -void HardFault_Handler(void) __attribute__((interrupt("WCH-Interrupt-fast"))); +// Upstream GCC as of version 12 does not support these, use normal ones instead :( +// 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 diff --git a/User/main.c b/User/main.c index 53c22f4..a6c64b3 100644 --- a/User/main.c +++ b/User/main.c @@ -36,7 +36,7 @@ int main(void) NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); Delay_Init(); USART_Printf_Init(115200); - printf("SystemClk:%d\r\n", SystemCoreClock); + printf("SystemClk:%ld\r\n", SystemCoreClock); printf("This is printf example\r\n");