Added blink source and compiler options

This commit is contained in:
Jake Goodwin 2025-03-06 17:50:09 -08:00
parent bc8ee016f3
commit 7faa92825f
2 changed files with 91 additions and 5 deletions

View file

@ -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)

View file

@ -1,7 +1,37 @@
#include "stdio.h"
#include "ch32fun.h"
//#include <stdio.h>
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);
}
}