From 7faa92825f7faa205fe4cccf859a4ca4e4315170 Mon Sep 17 00:00:00 2001 From: jake Date: Thu, 6 Mar 2025 17:50:09 -0800 Subject: [PATCH] Added blink source and compiler options --- src/CMakeLists.txt | 58 +++++++++++++++++++++++++++++++++++++++++++++- src/main.c | 38 ++++++++++++++++++++++++++---- 2 files changed, 91 insertions(+), 5 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f9696af..43fffc6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,3 +1,59 @@ -add_executable(main +# Compiler flags +add_compile_options( + -g + -Os + -flto + -ffunction-sections + -fdata-sections + -fmessage-length=0 + -msmall-data-limit=8 + -march=rv32ec + -mabi=ilp32e + -DCH32V003=1 + -static-libgcc + -nostdlib + -Wall +) + +add_executable(${PROJECT_NAME} main.c ) + +target_include_directories(${PROJECT_NAME} PUBLIC + ${CMAKE_SOURCE_DIR}/extralibs + ${CMAKE_SOURCE_DIR}/ch32fun +) + +target_link_libraries(${PROJECT_NAME} + ch32fun + #libgcc + #${CMAKE_SOURCE_DIR}/libgcc.a +) + +target_link_options(${PROJECT_NAME} PRIVATE -static-libgcc) + + +set_target_properties(${PROJECT_NAME} PROPERTIES SUFFIX ".elf") + +# The other "targets" are size, upload, debug, production, etc + +#if(NOT TARGET size) + +#if(NOT TARGET debug) + +#if(NOT TARGET production) + +#if(NOT TARGET upload) + +#endif() + + + +#add_library(libgcc STATIC IMPORTED) +#set_target_properties(libgcc PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/libgcc.a) + + + +add_subdirectory(ch32fun) +#add_subdirectory(extralibs) +add_subdirectory(attic) diff --git a/src/main.c b/src/main.c index f98dddf..fbac698 100644 --- a/src/main.c +++ b/src/main.c @@ -1,7 +1,37 @@ -#include "stdio.h" +#include "ch32fun.h" +//#include -int main(int argc, char **argv) +int main(void) { - printf("Hello!\n"); - return 0; + SystemInit(); + + // Enable GPIOs + RCC->APB2PCENR |= RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOC; + + // GPIO D0 Push-Pull + GPIOD->CFGLR &= ~(0xf << (4 * 0)); + GPIOD->CFGLR |= (GPIO_Speed_10MHz | GPIO_CNF_OUT_PP) << (4 * 0); + + // GPIO D4 Push-Pull + GPIOD->CFGLR &= ~(0xf << (4 * 4)); + GPIOD->CFGLR |= (GPIO_Speed_10MHz | GPIO_CNF_OUT_PP) << (4 * 4); + + // GPIO D6 Push-Pull + GPIOD->CFGLR &= ~(0xf << (4 * 6)); + GPIOD->CFGLR |= (GPIO_Speed_10MHz | GPIO_CNF_OUT_PP) << (4 * 6); + + // GPIO C0 Push-Pull + GPIOC->CFGLR &= ~(0xf << (4 * 0)); + GPIOC->CFGLR |= (GPIO_Speed_10MHz | GPIO_CNF_OUT_PP) << (4 * 0); + + while (1) + { + GPIOD->BSHR = (1 << 0) | (1 << 4) | (1 << 6); // Turn on GPIOs + GPIOC->BSHR = (1 << 0); + Delay_Ms(250); + + GPIOD->BSHR = (1 << 16) | (1 << (16 + 4)) | (1 << (16 + 6)); // Turn off GPIOs + GPIOC->BSHR = (1 << 16); + Delay_Ms(250); + } }