diff --git a/attic/external_crystal_run_from_ram_turbo.c b/attic/external_crystal_run_from_ram_turbo.c index cd2a0bbc47cc7b48969b54d6b6cc430dfeab7fd6..895125285a5c8655773e20d030814416f49d7102 100644 --- a/attic/external_crystal_run_from_ram_turbo.c +++ b/attic/external_crystal_run_from_ram_turbo.c @@ -4,8 +4,6 @@ #include "ch32v003fun.h" #include <stdio.h> -#define APB_CLOCK SYSTEM_CORE_CLOCK - uint32_t count; void RamFunction() __attribute__((naked)); diff --git a/examples/MCOtest/MCOtest.c b/examples/MCOtest/MCOtest.c index aaf3b343dc38f03e6ba062a6140a1ec2b7b6ab25..61002a95f00bddce95316a3185e2f353572041fa 100644 --- a/examples/MCOtest/MCOtest.c +++ b/examples/MCOtest/MCOtest.c @@ -1,6 +1,3 @@ -#define SYSTEM_CORE_CLOCK 48000000 -#define APB_CLOCK SYSTEM_CORE_CLOCK - #include "ch32v003fun.h" #include <stdio.h> diff --git a/examples/bootload/bootload.c b/examples/bootload/bootload.c index 5032b5558096314a1b668fb488de131e51bafb1a..f54ea9d8bda9b6a46c61e6e1d0b1b8a7f7e548b8 100644 --- a/examples/bootload/bootload.c +++ b/examples/bootload/bootload.c @@ -1,11 +1,6 @@ -// Could be defined here, or in the processor defines. -#define SYSTEM_CORE_CLOCK 48000000 - #include "ch32v003fun.h" #include <stdio.h> -#define APB_CLOCK SYSTEM_CORE_CLOCK - uint32_t count; // You can override the interrupt vector this way: diff --git a/examples/cpp_virtual_methods/cpp_virtual_methods.cpp b/examples/cpp_virtual_methods/cpp_virtual_methods.cpp index f6f1fc308f9de3158c840401a8d25449c7d4960f..938377768d421df4cc23d032e9504a28504ddbd1 100644 --- a/examples/cpp_virtual_methods/cpp_virtual_methods.cpp +++ b/examples/cpp_virtual_methods/cpp_virtual_methods.cpp @@ -3,10 +3,6 @@ * 05/21/2023 A. Mandera */ -// Could be defined here, or in the processor defines. -#define SYSTEM_CORE_CLOCK 48000000 -#define APB_CLOCK SYSTEM_CORE_CLOCK - #include "ch32v003fun.h" #include "example.h" #include <stdio.h> diff --git a/examples/dma_gpio/dma_gpio.c b/examples/dma_gpio/dma_gpio.c index 5f7a69886e840872d18f3260f325feb9932b1123..07fcd234c3622f7fb5ef85da299c94a3e88d0091 100644 --- a/examples/dma_gpio/dma_gpio.c +++ b/examples/dma_gpio/dma_gpio.c @@ -8,13 +8,10 @@ // The interrupt fires once at the beginning and // once at the end. // -#define SYSTEM_CORE_CLOCK 48000000 #include "ch32v003fun.h" #include <stdio.h> -#define APB_CLOCK SYSTEM_CORE_CLOCK - volatile uint32_t count; #define MBSAMPS 1024 diff --git a/examples/self_modify_code/self_modify_code.c b/examples/self_modify_code/self_modify_code.c index c0155eaf99c98172820bef8bbe4711b06088e3a1..abb6890a8af780935c81075a97bc09dddc4f754f 100644 --- a/examples/self_modify_code/self_modify_code.c +++ b/examples/self_modify_code/self_modify_code.c @@ -1,7 +1,6 @@ /* Small example showing how to use the SWIO programming pin to do printf through the debug interface */ -#define SYSTEM_CORE_CLOCK 24000000 #include "ch32v003fun.h" #include <stdio.h> diff --git a/examples/spi_24L01_rx/nrf24l01_low_level.c b/examples/spi_24L01_rx/nrf24l01_low_level.c index a69547b35744247efa3c956aba07bc7dc1b0ce26..54096f6f75e13138d47804c9c392ebb8898bcbaf 100644 --- a/examples/spi_24L01_rx/nrf24l01_low_level.c +++ b/examples/spi_24L01_rx/nrf24l01_low_level.c @@ -1,5 +1,3 @@ -#define SYSTEM_CORE_CLOCK 48000000 -#define APB_CLOCK SYSTEM_CORE_CLOCK #include "ch32v003fun.h" diff --git a/examples/spi_24L01_tx/nrf24l01_low_level.c b/examples/spi_24L01_tx/nrf24l01_low_level.c index a69547b35744247efa3c956aba07bc7dc1b0ce26..54096f6f75e13138d47804c9c392ebb8898bcbaf 100644 --- a/examples/spi_24L01_tx/nrf24l01_low_level.c +++ b/examples/spi_24L01_tx/nrf24l01_low_level.c @@ -1,5 +1,3 @@ -#define SYSTEM_CORE_CLOCK 48000000 -#define APB_CLOCK SYSTEM_CORE_CLOCK #include "ch32v003fun.h" diff --git a/examples/standby_autowake/standby_autowake.c b/examples/standby_autowake/standby_autowake.c index 301e163ff3a7bde192c7f2dfeb3262f348d53f00..4cfaaf34c1248cd27cac5e82a3cef6d78d754a5e 100644 --- a/examples/standby_autowake/standby_autowake.c +++ b/examples/standby_autowake/standby_autowake.c @@ -1,12 +1,8 @@ // based on https://paste.sr.ht/blob/b9b4fb45cbc70f2db7e31a77a6ef7dd2a7f220fb -// Could be defined here, or in the processor defines. -#define SYSTEM_CORE_CLOCK 48000000 #include "ch32v003fun.h" #include <stdio.h> -#define APB_CLOCK SYSTEM_CORE_CLOCK - /* somehow this ISR won't get called?? void AWU_IRQHandler( void ) __attribute__((interrupt)); void AWU_IRQHandler( void ) { diff --git a/examples/standby_btn/standby_btn.c b/examples/standby_btn/standby_btn.c index 2c86bc1973dfc0101ff15aaa9095f4fa9627e5be..33f55a89cb8c29e7ae7991cb01c0fac41ed183cb 100644 --- a/examples/standby_btn/standby_btn.c +++ b/examples/standby_btn/standby_btn.c @@ -1,12 +1,8 @@ // based on https://paste.sr.ht/blob/b9b4fb45cbc70f2db7e31a77a6ef7dd2a7f220fb -// Could be defined here, or in the processor defines. -#define SYSTEM_CORE_CLOCK 48000000 #include "ch32v003fun.h" #include <stdio.h> -#define APB_CLOCK SYSTEM_CORE_CLOCK - void EXTI7_0_IRQHandler( void ) __attribute__((interrupt)); void EXTI7_0_IRQHandler( void ) { //GPIOD->OUTDR ^= (1 << 4); diff --git a/examples/ws2812bdemo/ws2812bdemo.c b/examples/ws2812bdemo/ws2812bdemo.c index f1b1a60bf6f839f23a51314c038fd836a9e30815..a931fa22b64e2604fe46f0e063be05f78c124e9f 100644 --- a/examples/ws2812bdemo/ws2812bdemo.c +++ b/examples/ws2812bdemo/ws2812bdemo.c @@ -1,7 +1,3 @@ -// Could be defined here, or in the processor defines. -#define SYSTEM_CORE_CLOCK 48000000 -#define APB_CLOCK SYSTEM_CORE_CLOCK - // NOTE: CONNECT WS2812's to PC6 #include "ch32v003fun.h" diff --git a/extralibs/ch32v003_GPIO_branchless.h b/extralibs/ch32v003_GPIO_branchless.h index 40aa3765c4317eccd70ca7b72d263c37f0142565..c8071e1757c9b95e12ab8c1579d3cb68070c5ef2 100644 --- a/extralibs/ch32v003_GPIO_branchless.h +++ b/extralibs/ch32v003_GPIO_branchless.h @@ -290,14 +290,6 @@ static inline void GPIO_tim2_init(); #define GPIO_timer_prescaler TIM_CKD_DIV2 // APB_CLOCK / 1024 / 2 = 23.4kHz #endif -// maintenance define -#if !defined(SYSTEM_CORE_CLOCK) -#define SYSTEM_CORE_CLOCK 48000000 -#define APB_CLOCK SYSTEM_CORE_CLOCK -#endif - - - //######## define requirements / maintenance defines diff --git a/extralibs/ch32v003_SPI.h b/extralibs/ch32v003_SPI.h index f7263fa934003f734f5767c2254a75677780cfda..83e055d9d172b621507ff07470467ce326932d80 100644 --- a/extralibs/ch32v003_SPI.h +++ b/extralibs/ch32v003_SPI.h @@ -16,6 +16,11 @@ in the .c files that use this library, you'll need to #define some configuration SYSTEM_CORE_CLOCK and APB_CLOCK should be defined already as APB_CLOCK is used by this library + +#ifndef APB_CLOCK + #define APB_CLOCK FUNCONF_SYSTEM_CORE_CLOCK +#endif + to enable using the functions of this library: #define CH32V003_SPI_IMPLEMENTATION