rename examples

This commit is contained in:
R
2024-04-23 16:23:41 +01:00
parent e581daec90
commit a8d630293b
11 changed files with 0 additions and 0 deletions
+2
View File
@@ -0,0 +1,2 @@
tar ext localhost:3333
load
+33
View File
@@ -0,0 +1,33 @@
.PHONY: all clean
RV_ARCH = rv32imacxw
CC = riscv-none-elf-gcc
OBJDUMP = riscv-none-elf-objdump
OBJCOPY = riscv-none-elf-objcopy
CFLAGS = -ggdb3 -Os -march=$(RV_ARCH) -ffunction-sections -fdata-sections
LDFLAGS = -ggdb3 -march=$(RV_ARCH) -Wl,--gc-sections --specs=nosys.specs
all: main.uf2
main.elf: startup.o main.o
%.uf2: %.bin
~/code/uf2/utils/uf2conv.py -c -f 0x699b62ec -b 0x20000000 -o $@.temp $<
xxd $@.temp | sed 's/5546 320a 5751 5d9e 0020 0000/5546 320a 5751 5d9e 0120 0000/g' | xxd -r >$@
%.bin: %.elf
$(OBJCOPY) -O binary $< $@
%.elf: linker.lds
$(CC) -Xlinker -Map=$(@:.elf=.map) -Wl,--script=linker.lds -nostartfiles -o $@ $(filter-out linker.lds,$+)
$(OBJDUMP) -xdsS $@ >$(@:.elf=.dump)
%.o: %.S
$(CC) $(CFLAGS) -c -o $@ $<
%.o: %.c
$(CC) $(CFLAGS) -c -o $@ $<
clean:
rm -f *.o *.elf *.map *.dump *.uf2
+97
View File
@@ -0,0 +1,97 @@
ENTRY( _start )
__stack_size = 512;
PROVIDE( _stack_size = __stack_size );
MEMORY
{
/* CH32V20x_D6 -> 10 KB SRAM */
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 10K
}
SECTIONS
{
.vector :
{
*(.vector);
. = ALIGN(4);
} >RAM
.text :
{
*(.text)
*(.text.*)
*(.rodata)
*(.rodata*)
*(.gnu.linkonce.t.*)
. = ALIGN(4);
} >RAM
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);
} >RAM
.init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
PROVIDE_HIDDEN (__init_array_end = .);
} >RAM
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors))
PROVIDE_HIDDEN (__fini_array_end = .);
} >RAM
PROVIDE(_data_lma = .);
.data :
{
PROVIDE(_data_vma = .);
*(.gnu.linkonce.r.*)
*(.data .data.*)
*(.gnu.linkonce.d.*)
. = ALIGN(4);
PROVIDE( __global_pointer$ = . + 0x800 );
*(.sdata .sdata.*)
*(.sdata2.*)
*(.gnu.linkonce.s.*)
. = ALIGN(4);
*(.srodata.cst16)
*(.srodata.cst8)
*(.srodata.cst4)
*(.srodata.cst2)
*(.srodata .srodata.*)
. = ALIGN(4);
PROVIDE( _edata = .);
} >RAM
.bss :
{
PROVIDE( _sbss = .);
*(.sbss*)
*(.gnu.linkonce.sb.*)
*(.bss*)
*(.gnu.linkonce.b.*)
*(COMMON*)
. = ALIGN(4);
PROVIDE( _ebss = .);
} >RAM
PROVIDE( _end = _ebss);
.stack ORIGIN(RAM) + LENGTH(RAM) - __stack_size :
{
PROVIDE( _heap_end = . );
PROVIDE( _susrstack = . );
. = . + __stack_size;
PROVIDE( _eusrstack = .);
} >RAM
}
BIN
View File
Binary file not shown.
+27
View File
@@ -0,0 +1,27 @@
#include <stdint.h>
#pragma GCC diagnostic ignored "-Wprio-ctor-dtor"
__attribute__((constructor(0))) static void setup_qingke() {
asm volatile(
// Undocumented "Configure pipelining and instruction prediction"
"li t0, 0x1f\n"
"csrw 0xbc0, t0\n"
);
}
#define R32_RCC_APB2PCENR (*(volatile uint32_t*)0x40021018)
#define R32_GPIOA_CFGLR (*(volatile uint32_t*)0x40010800)
#define R32_GPIOA_BSHR (*(volatile uint32_t*)0x40010810)
int main(void) {
R32_RCC_APB2PCENR |= 1 << 2;
R32_GPIOA_CFGLR = (R32_GPIOA_CFGLR & ~0xf) | (0b0010 << 0);
while (1) {
R32_GPIOA_BSHR = 1 << 0;
for (int i = 0; i < 250000; i++)
asm volatile("");
R32_GPIOA_BSHR = 1 << 16;
for (int i = 0; i < 250000; i++)
asm volatile("");
}
}
+67
View File
@@ -0,0 +1,67 @@
.section .vector,"ax",@progbits
.align 1
.global _start
_start:
// Set up global pointer
.option push
.option norelax
la gp, __global_pointer$
.option pop
// Load stack pointer
la sp, _eusrstack
// Clear bss section
la a0, _sbss
la a1, _ebss
bgeu a0, a1, 2f
1:
sw zero, (a0)
addi a0, a0, 4
bltu a0, a1, 1b
2:
// Call preinit array functions
la s0, __preinit_array_start
la s1, __preinit_array_end
bgeu s0, s1, 2f
1:
lw t0, (s0)
jalr t0
addi s0, s0, 4
bltu s0, s1, 1b
2:
// Call init array functions
la s0, __init_array_start
la s1, __init_array_end
bgeu s0, s1, 2f
1:
lw t0, (s0)
jalr t0
addi s0, s0, 4
bltu s0, s1, 1b
2:
// Invoke main with a possible mode switch
la ra, 1f
la t0, main
csrw mepc, t0
mret
1:
// Return from main, call fini array functions
la s0, __fini_array_start
la s1, __fini_array_end
bgeu s0, s1, 2f
1:
lw t0, (s0)
jalr t0
addi s0, s0, 4
bltu s0, s1, 1b
2:
// Finally, loop infinitely
wfi
j 2b