diff --git a/examples/adc_polled/README.md b/examples/adc_polled/README.md new file mode 100644 index 0000000000000000000000000000000000000000..ae8f031427f7c9f9f1ffd6a432fc7ef02f8baeb7 --- /dev/null +++ b/examples/adc_polled/README.md @@ -0,0 +1,9 @@ +# Polled ADC example +This example code demonstrates the use of the CH32V003 on-chip ADC in polled mode +wherein a single analog input channel is configured on GPIO and then digitized +under software control. When a sample is needed the ADC is started and the CPU +busy-waits until the conversion is complete before reading the result. + +This is just about the simplest and easiest use-case for the ADC and wastes a lot +of CPU cycles but it does show the basics of doing conversions in a situation +where high performance is not needed. diff --git a/examples/i2c_oled/README.md b/examples/i2c_oled/README.md new file mode 100644 index 0000000000000000000000000000000000000000..b5e92ced88dd6b5d03bbd057b8dc7f618b3699e6 --- /dev/null +++ b/examples/i2c_oled/README.md @@ -0,0 +1,20 @@ +# I2C OLED demonstration +This example code demonstrates use of the CH32V003 I2C peripheral with an SSD1306 +OLED (128x32 pixel type). It provides a generic I2C port initialization and +transmit (write-only) low level interface and a high-level graphics driver with +pixels, lines, circles, rectangles and 8x8 character font rendering. Out of the +box this demo cycles through a few different graphic screens to test out the +various drawing primitives. + +[OLED video](doc/oled.mp4) + +## Use +Connect an SSD1306-based OLED in I2C interface mode to pins PC1 (SCL) and PC2 (SDA) +of the CH32V003 with proper I2C pullup resistors and observe the various graphic +images that cycle at approximately 2 second intervals. + +Note - I used an Adafruit 0.91" 128x32 OLED breakout (stock #4440) for my testing +and found that the built-in 10k pullup resistors were too weak for reliable I2C +bus transactions. I had to add 2.2k resistors to the SCL and SDA pads to allow +proper operation. + diff --git a/examples/i2c_oled/doc/oled.mp4 b/examples/i2c_oled/doc/oled.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..b1fd39e773ad182268144b4dca8fd431e8e94bea Binary files /dev/null and b/examples/i2c_oled/doc/oled.mp4 differ diff --git a/examples/systick_irq/README.md b/examples/systick_irq/README.md new file mode 100644 index 0000000000000000000000000000000000000000..0683b29177269b811a40981d36d2021a50e4579e --- /dev/null +++ b/examples/systick_irq/README.md @@ -0,0 +1,16 @@ +# Systick IRQ demonstration +This example shows how to set up the built-in Systick IRQ to generate periodic +interrupts for timing. Many bare-metal and RTOS based embedded applications will +use the Systick IRQ for timing, periodic housekeeping and task arbitration so +knowing how to set that up is useful. + +Note that this example is *NOT* compatible with the Delay_Ms() function that's +part of the ch32v003fun library - that function uses the Systick counter for +doing busy-wait delays and will interfere with its use in generating predictable +IRQs. Do not use the built-in Delay_Ms() and related functions when using Systick +for IRQs. + +Note also the use of the `__attribute__((interrupt))` syntax in declaring the +IRQ handler. Some of the IRQ examples from the WCH HAL library have slightly +different syntax to make use of a fast IRQ mode but which is not compatible with +generic RISC-V GCC so that feature is not used here. \ No newline at end of file diff --git a/examples/tim1_pwm/.gdbinit b/examples/tim1_pwm/.gdbinit new file mode 100644 index 0000000000000000000000000000000000000000..427595ae0e4d2332e7e580facfd2c4327e8441c6 --- /dev/null +++ b/examples/tim1_pwm/.gdbinit @@ -0,0 +1,2 @@ +file tim1_pwm.elf +target extended-remote localhost:3333 diff --git a/examples/tim1_pwm/README.md b/examples/tim1_pwm/README.md new file mode 100644 index 0000000000000000000000000000000000000000..2cf153a2e142ec2d1a9a19b8a1be034954a307f5 --- /dev/null +++ b/examples/tim1_pwm/README.md @@ -0,0 +1,9 @@ +# Demonstration of PWM using Timer 1 +This example shows how to set up Timer 1 (the Advanced Control Timer) to generate +Pulse-Width Modulation (PWM) on two output pins. PWM is frequently used to do +variable brightness on LEDs or for digital-to-analog conversion when combined with +a suitable lowpass filter. + +## Use +Connect GPIO pins PD0 and PC4 to LEDs (with appropriate current limiting) and +observe that they fade with different cycles. diff --git a/examples/tim1_pwm/debug.sh b/examples/tim1_pwm/debug.sh new file mode 100755 index 0000000000000000000000000000000000000000..bb05a9465959cb153fad95bba4b2175667830528 --- /dev/null +++ b/examples/tim1_pwm/debug.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# before running this you should start OOCD server +#../../../MRS_Toolchain_Linux_x64_V1.70/OpenOCD/bin/openocd -f ../../../MRS_Toolchain_Linux_x64_V1.70/OpenOCD/bin/wch-riscv.cfg + +../../../MRS_Toolchain_Linux_x64_V1.70/RISC-V\ Embedded\ GCC/bin/riscv-none-embed-gdb