Skip to content

Commit

Permalink
Switch blink example to using easy mode
Browse files Browse the repository at this point in the history
  • Loading branch information
cnlohr committed Jan 22, 2024
1 parent 41dbf67 commit 49d8791
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 21 deletions.
Binary file modified examples/blink/blink.bin
Binary file not shown.
35 changes: 14 additions & 21 deletions examples/blink/blink.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}
10 changes: 10 additions & 0 deletions examples/blink_raw/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
all : flash

TARGET:=blink_raw

include ../../ch32v003fun/ch32v003fun.mk

flash : cv_flash
clean : cv_clean


Binary file added examples/blink_raw/blink_raw.bin
Binary file not shown.
36 changes: 36 additions & 0 deletions examples/blink_raw/blink_raw.c
Original file line number Diff line number Diff line change
@@ -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 );
}
}
7 changes: 7 additions & 0 deletions examples/blink_raw/funconfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef _FUNCONFIG_H
#define _FUNCONFIG_H

#define CH32V003 1

#endif

0 comments on commit 49d8791

Please sign in to comment.