Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bootloader/funconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#define FUNCONF_USE_DEBUGPRINTF 0
#define CH32V003 1
#define FUNCONF_SYSTICK_USE_HCLK 1
#define FUNCONF_TINYVECTOR 1

#endif

2 changes: 1 addition & 1 deletion bootloader_v006/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ CH32FUN:=../ch32fun/ch32fun
TARGET_MCU:=CH32V006

ADDITIONAL_C_FILES+=../rv003usb/rv003usb.S ../rv003usb/rv003usb.c
EXTRA_CFLAGS:=-I. -I../lib -I../rv003usb
EXTRA_CFLAGS:=-I. -I../lib -I../rv003usb -DUSE_TINY_BOOT

LINKER_SCRIPT:=ch32v006-usb-bootloader.ld
# LINKER_SCRIPT:=ch32v005-usb-bootloader.ld
Expand Down
3 changes: 3 additions & 0 deletions bootloader_v006/bootloader.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ void boot_usercode()

int main()
{
// This is not set in the assembly code before-hand.
SysTick->CTLR = 5;

SystemInit();
usb_setup();
runwordpad = 0;
Expand Down
4 changes: 3 additions & 1 deletion bootloader_v006/ch32v006-usb-bootloader.ld
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ENTRY( InterruptVector )
ENTRY( Init )

MEMORY
{
Expand Down Expand Up @@ -123,6 +123,8 @@ SECTIONS
{
. = ALIGN(4);
__global_pointer$ = . + 0x3fc;
*(.beginning_of_ram)
KEEP(*(SORT_NONE(.beginning_of_ram)))
*(.gnu.linkonce.r.*)
*(.data .data.*)
*(.gnu.linkonce.d.*)
Expand Down
3 changes: 3 additions & 0 deletions bootloader_v006/funconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@
#define FUNCONF_USE_DEBUGPRINTF 0
#define FUNCONF_SYSTICK_USE_HCLK 1

#define FUNCONF_OVERRIDE_STARTUP 1
#define FUNCONF_TINYVECTOR 1

#endif

2 changes: 1 addition & 1 deletion ch32fun
Submodule ch32fun updated 47 files
+70 −50 ch32fun/ch32fun.c
+17 −6 ch32fun/ch32fun.h
+2 −0 ch32fun/ch32fun.mk
+16 −0 ch32fun/ch32v30xhw.h
+12 −7 ch32fun/ch32x00xhw.h
+199 −6 ch32fun/ch5xxhw.h
+58 −20 examples/cap_touch_adc/cap_touch_adc.c
+13 −0 examples/dma_scheduled_io/Makefile
+235 −0 examples/dma_scheduled_io/dma_scheduled_io.c
+10 −0 examples/dma_scheduled_io/funconfig.h
+11 −0 examples/vector_free_table_irq/Makefile
+13 −0 examples/vector_free_table_irq/funconfig.h
+80 −0 examples/vector_free_table_irq/vector_free_table_irq.c
+3 −3 examples_ch5xx/uart_send_receive/fun_uart_ch5xx.h
+3 −3 examples_usb/USBFS/usbfs_cdc_uart/uart.c
+0 −17 examples_usb/USBFS/usbfs_cdc_uart/uart.h
+11 −0 examples_usb/USBFS/usbfs_device/Makefile
+40 −2 examples_usb/USBFS/usbfs_device/usbfs_device.c
+21 −0 examples_usb/USBFS/usbfs_device/usbhidtool/Makefile
+122 −0 examples_usb/USBFS/usbfs_device/usbhidtool/usbhidtool.c
+1 −0 examples_usb/USBFS/usbfs_device/usbhidtool/winbuild.bat
+44 −4 extralibs/ch32v00x_touch.h
+5 −0 extralibs/fsusb.c
+1 −1 extralibs/iSLER.h
+13 −3 extralibs/ssd1306.h
+4 −0 minichlink/99-minichlink.rules
+3 −2 minichlink/microgdbstub.h
+7 −5 minichlink/minichlink.c
+ minichlink/minichlink.exe
+1 −1 minichlink/minichlink.h
+0 −0 minichlink/os_generic.h
+68 −26 minichlink/pgm-b003fun.c
+29 −7 minichlink/pgm-esp32s2-ch32xx.c
+20 −12 minichlink/pgm-wch-isp.c
+7 −7 minichlink/version
+34 −0 misc/attic/rv003usb_bootloader_stubs_for_minichlink/erase_block.asm
+67 −0 misc/attic/rv003usb_bootloader_stubs_for_minichlink/write_block.asm
+14 −0 projects/ch32v00x_inductance_tester/Makefile
+49 −0 projects/ch32v00x_inductance_tester/README.md
+274 −0 projects/ch32v00x_inductance_tester/ch32v00x_inductance_tester.c
+12 −0 projects/ch32v00x_inductance_tester/funconfig.h
+9 −0 projects/hx711_load_cell_amplifier/Makefile
+25 −0 projects/hx711_load_cell_amplifier/README.md
+10 −0 projects/hx711_load_cell_amplifier/funconfig.h
+178 −0 projects/hx711_load_cell_amplifier/hx711.h
+118 −0 projects/hx711_load_cell_amplifier/hx711_load_cell_amplifier.c
+ projects/hx711_load_cell_amplifier/schematic.png
45 changes: 41 additions & 4 deletions rv003usb/rv003usb.S
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ Compressed:
#warning "CH32V003"
.section .text.vector_handler
#else
.section .srodata, "ax"
// To force 1024-byte-alignment.
.section .beginning_of_ram, "ax"
#endif
.global EXTI7_0_IRQHandler

Expand Down Expand Up @@ -1036,8 +1037,8 @@ insert_stuffed_bit:
// into main... as well as providing EXTI7_0_IRQHandler jump at interrupt

.section .init
.global InterruptVector
InterruptVector:
.global Init
Init:
.align 2
.option push
.option norelax
Expand All @@ -1047,17 +1048,47 @@ InterruptVector:
la sp, _eusrstack // sp = 0x20000800
li a0, 0x80
csrw mstatus, a0
#if !defined(CH32V00x) || !CH32V00x
csrw mtvec, 3
addi a0, sp, -2048 // a0 = 0x20000000
addi gp, a0, 0x3fc // gp = 0x200003fc
addi gp, a0, 0x3fc // gp = 0x200003fc // The fast way.
#else
la a0, EXTI7_0_IRQHandler
csrw mtvec, a0 // VEctor will be at beginning of RAM.
la gp, __global_pointer$ // The slow, clean way.
#endif

#if CH32V00x
la a0, _sbss
la a1, _ebss
li a2, 0
bge a0, a1, 2f
1: sw a2, 0(a0)
addi a0, a0, 4
blt a0, a1, 1b

// This loads DATA from FLASH to RAM.
la a0, _data_lma
la a1, _data_vma
la a2, _edata
1: beq a1, a2, 2f
lw a3, 0(a0)
sw a3, 0(a1)
addi a0, a0, 4
addi a1, a1, 4
bne a1, a2, 1b
2:
#else
c.li a4, 0
1: c.sw a4, 0(a0) // Clear RAM
c.addi a0, 4
blt a0, sp, 1b // Iterate over RAM until it's cleared.
2:

//XXX WARNING: NO .DATA SECTION IS AVAILABLE HERE!
/* SystemInit48HSI */

// Setup clocks here on 003.
// RCC_BASE = 0x40021000
// FLASH_R_BASE = 0x40022000
// EXTEND = 0x40023800
Expand All @@ -1069,14 +1100,20 @@ InterruptVector:
c.sw a1, 0(a3) /* FLASH->ACTLR = FLASH_ACTLR_LATENCY_1 */
c.li a1, 0x00000002 /* RCC->CFGR0 = RCC_SW_PLL */
c.sw a1, 4(a2)
#endif

la a1, main
csrw mepc, a1
.option pop
mret

// CAREFUL THIS MUST BE EXACTLY AT 0x50

#if !CH32V00x
. = 0x52 // Weird... I don't know why this has to be 0x52, for it to be at 0x50.
.word EXTI7_0_IRQHandler /* EXTI Line 7..0 */
#endif

always0:
.byte 0x00 // Automatically expands out to 4 bytes.

Expand Down
Loading