diff --git a/examples/blink/blink.bin b/examples/blink/blink.bin index af4d4a767892ea6c14c592527ecd43cb320b4288..517e40364a5159f4b16fa9abae76d3d8c41ce00f 100755 Binary files a/examples/blink/blink.bin and b/examples/blink/blink.bin differ diff --git a/examples/blink/blink.c b/examples/blink/blink.c index e2d55705c1111b65c428a01c8e4725e2b6c78c59..b12dc6f3a5cf799227e9601deb588388f7228e7d 100644 --- a/examples/blink/blink.c +++ b/examples/blink/blink.c @@ -6,31 +6,24 @@ int main() 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); + funGpioInitAll(); + + funPinMode( PD0, GPIO_Speed_10MHz | GPIO_CNF_OUT_PP ); + funPinMode( PD4, GPIO_Speed_10MHz | GPIO_CNF_OUT_PP ); + funPinMode( PD6, GPIO_Speed_10MHz | GPIO_CNF_OUT_PP ); + funPinMode( PC0, GPIO_Speed_10MHz | GPIO_CNF_OUT_PP ); while(1) { - GPIOD->BSHR = (1<<0) | (1<<4) | (1<<6); // Turn on GPIOs - GPIOC->BSHR = (1<<0); + funDigitalWrite( PD0, FUN_HIGH ); + funDigitalWrite( PD4, FUN_HIGH ); + funDigitalWrite( PD6, FUN_HIGH ); + funDigitalWrite( PC0, FUN_HIGH ); Delay_Ms( 250 ); - GPIOD->BSHR = (1<<16) | (1<<(16+4)) | (1<<(16+6)); // Turn off GPIOs - GPIOC->BSHR = (1<<16); + funDigitalWrite( PD0, FUN_LOW ); + funDigitalWrite( PD4, FUN_LOW ); + funDigitalWrite( PD6, FUN_LOW ); + funDigitalWrite( PC0, FUN_LOW ); Delay_Ms( 250 ); } } diff --git a/examples/blink_raw/Makefile b/examples/blink_raw/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..9fb166e1215468ba2b470990599f90f88b9abacf --- /dev/null +++ b/examples/blink_raw/Makefile @@ -0,0 +1,10 @@ +all : flash + +TARGET:=blink_raw + +include ../../ch32v003fun/ch32v003fun.mk + +flash : cv_flash +clean : cv_clean + + diff --git a/examples/blink_raw/blink_raw.bin b/examples/blink_raw/blink_raw.bin new file mode 100644 index 0000000000000000000000000000000000000000..4c86c4525963d86c0b634527880c398e707f73e6 Binary files /dev/null and b/examples/blink_raw/blink_raw.bin differ diff --git a/examples/blink_raw/blink_raw.c b/examples/blink_raw/blink_raw.c new file mode 100644 index 0000000000000000000000000000000000000000..e2d55705c1111b65c428a01c8e4725e2b6c78c59 --- /dev/null +++ b/examples/blink_raw/blink_raw.c @@ -0,0 +1,36 @@ +#include "ch32v003fun.h" +#include <stdio.h> + +int main() +{ + 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 ); + } +} diff --git a/examples/blink_raw/funconfig.h b/examples/blink_raw/funconfig.h new file mode 100644 index 0000000000000000000000000000000000000000..998cf76fede1479f162c72ef34d3a4d747430093 --- /dev/null +++ b/examples/blink_raw/funconfig.h @@ -0,0 +1,7 @@ +#ifndef _FUNCONFIG_H +#define _FUNCONFIG_H + +#define CH32V003 1 + +#endif +