fix booting ram, commit to new size

This commit is contained in:
R
2024-04-14 18:29:09 +01:00
parent b490e6917d
commit ef659206e2
8 changed files with 11 additions and 12 deletions
+2 -2
View File
@@ -119,7 +119,7 @@ const uint8_t BOOT_SECTOR[0x3e] __attribute__((aligned(2))) = {
const uint8_t INFO_UF2[70] __attribute__((aligned(2))) = "UF2 Bootloader v0.0.0\nModel: CH32V Generic\nBoard-ID: CH32Vxxx-Generic\n";
const uint8_t INDEX_HTM[119] __attribute__((aligned(2))) = "<!doctype html>\n<html><body><script>location.replace(\"https://github.com/ArcaneNibble/wch-uf2\")</script></body></html>\n";
#define THIS_CHIP_FLASH_MAX_SZ_BYTES (224 * 1024)
#define BOOTLOADER_RESERVED_SZ_BYTES (8 * 1024)
#define BOOTLOADER_RESERVED_SZ_BYTES (4 * 1024)
#define THIS_CHIP_RAM_MAX_SZ_BYTES (20 * 1024)
#define FAMILY_ID 0xdeadbeef
@@ -864,7 +864,7 @@ __attribute__((naked)) int main(void) {
// ram boot
R32_RCC_CFGR0 = (R32_RCC_CFGR0 & ~0b11) | 0b00;
while ((R32_RCC_CFGR0 & 0b1100) != 0b0000) {}
((void (*)())0x20000000)();
asm volatile("la t0, 0x20000000\njr t0\n1:\nj 1b\n");
} else {
// wtf why does this work and the other stuff doesn't?
R16_BKP_DATAR10 = 0x4170;
+1 -1
View File
@@ -3,7 +3,7 @@ ENTRY( _start )
MEMORY
{
/* Try to squeeze down to this target size */
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 8K
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 4K
LOL_NO_RAM (rw) : ORIGIN = 0x400060c0, LENGTH = 0
}
+1 -1
View File
@@ -30,4 +30,4 @@ main.elf: startup.o main.o
$(CC) $(CFLAGS) -c -o $@ $<
clean:
rm -f *.o *.elf *.map *.dump
rm -f *.o *.elf *.map *.dump *.uf2
Binary file not shown.
+2 -2
View File
@@ -18,10 +18,10 @@ int main(void) {
R32_GPIOA_CFGLR = (R32_GPIOA_CFGLR & ~0xf) | (0b0010 << 0);
while (1) {
R32_GPIOA_BSHR = 1 << 0;
for (int i = 0; i < 500000; i++)
for (int i = 0; i < 250000; i++)
asm volatile("");
R32_GPIOA_BSHR = 1 << 16;
for (int i = 0; i < 500000; i++)
for (int i = 0; i < 250000; i++)
asm volatile("");
}
}
+2 -2
View File
@@ -13,7 +13,7 @@ all: main.uf2
main.elf: startup.o main.o
%.uf2: %.bin
~/code/uf2/utils/uf2conv.py -c -f 0xdeadbeef -b 0x08002000 -o $@ $<
~/code/uf2/utils/uf2conv.py -c -f 0xdeadbeef -b 0x08001000 -o $@ $<
%.bin: %.elf
$(OBJCOPY) -O binary $< $@
@@ -29,4 +29,4 @@ main.elf: startup.o main.o
$(CC) $(CFLAGS) -c -o $@ $<
clean:
rm -f *.o *.elf *.map *.dump
rm -f *.o *.elf *.map *.dump *.uf2
+1 -1
View File
@@ -7,7 +7,7 @@ MEMORY
{
/* CH32V20x_D6 -> 10 KB SRAM */
/* allow full flash (incl. non-zero-wait) */
FLASH (rx) : ORIGIN = 0x00002000, LENGTH = (224K - 8K)
FLASH (rx) : ORIGIN = 0x00001000, LENGTH = (224K - 4K)
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 10K
}
+2 -3
View File
@@ -100,6 +100,5 @@ _enter_bootloader:
csrw 0xbc0, t0
// Invoke main
la t0, main
csrw mepc, t0
mret
// XXX the mepc thing does something really weird
j main