Comments (10)
Hmm... there's a few trade-offs that I've worked through.
- It should be in a .c file, so that ch32v003fun can be included with only one .c file. Simplifies inclusion for people on other build systems.
- HPE should not be enabled by default. Users should choose if they want it or not. It is not a clear win for many situations.
- What about BSS?
- What about _data initialization?
- Other than that, this is great. Would you consider making some changes to make the default ch32v003fun implementation a little tighter?
I don't understand how .rodata being before .text is helpful, but that would be interesting.
I would like to integrate several of the principles.
Would you consider making a PR for ch32v003fun.c?
from ch32v003fun.
cruuuuuud... I guess I was turning HPE on in my code. I really should not.
from ch32v003fun.
First thing is to resolve the wanted naming for linker symbols as there is literally no standardization.
There are also instances relying on .srodata (aka small rodata) being in SRAM.
I don't understand how .rodata being before .text is helpful, but that would be interesting.
Anything within bottom 2 KiB can be addressed by single addi
(or lw
) instruction instead of c.lui
+ addi
.
The code uses relative offsets and function pointer making is less common than stuff in .rodata
- What about BSS?
- What about _data initialization?
do you mean .data and .bss sections? Those are done in L_51 and L_113 loops
cruuuuuud... I guess I was turning HPE on in my code. I really should not.
BTW, only bit 0 of 0x804 is HPE, bit 1 enables interrupt nesting
from ch32v003fun.
by making assumption that mtvec is always initialized to starting address (bootloader sets up mtvec to app address without mode bits), there should be no size diff caused by app offset.
-2 bytes if relying on reset state of mtvec
from ch32v003fun.
wait, are you sure that this area at 0x1ffff000 can actually be used? datasheet only says it's "factory-cured bootloader" and those areas tend to be read only (and write once only).
from ch32v003fun.
by making assumption that mtvec is always initialized to starting address (bootloader sets up mtvec to app address without mode bits), there should be no size diff caused by app offset.
-2 bytes if relying on reset state of mtvec
That makes me anxxxxiousssss
wait, are you sure that this area at 0x1ffff000 can actually be used? datasheet only says it's "factory-cured bootloader" and those areas tend to be read only (and write once only).
Absolutely! That's what I have been using on my 1920-byte-USB thing. I sometimes use it, sometimes flash, but I can definitely reprogram the bootloader.
from ch32v003fun.
looking at the openwch repo, the reprogramming of the bootloader is a documented use case
The expected way of entering bootloader is by system reset after setting the bit 14 of FLASH->STATR
https://github.com/openwch/ch32v003/blob/main/EVT/EXAM/IAP/V00x_APP/User/main.c#LL32C5-L32C18
In this way the bootloader experiences the full reset and 0x00000000 remap.
Exiting to APP probably also requires this procedure (though some of the keying should be already done for flash programming).
Because of system reset there seems to be no need for cleanup in peripheral registers.
That's quite different from stm32 "system" bootloaders
That makes me anxxxxiousssss
If the bootloader is in separate flash bank, that's entered/exit by system reset, I think that this -2 bytes is safe
Absolutely! That's what I have been using on my 1920-byte-USB thing. I sometimes use it, sometimes flash, but I can definitely reprogram the bootloader.
minichlink is offsetting the binaries to 0x1ffff000/0x08000000 from 0x00000000 based on command param.
I'll try to figure out how this works in the cursed openocd fork
from ch32v003fun.
BTW: https://github.com/cnlohr/ch32v003fun/blob/master/ch32v003fun/ch32v003fun.c#L817
This may break if the compiler decides to prepare address/immediate before the assembly blocks.
GCC is biased to allocate from a5 down (accidentally no break yet), but llvm is going from a0 up.
Those inline asm blocks need register clobbers to be safe.
from ch32v003fun.
A small side track, does stack grow toward .code instead of global vars in the original linker script?
from ch32v003fun.
it's always from top towards .heap then .bss and .data
from ch32v003fun.
Related Issues (20)
- Wrong definition of funPinMode? HOT 2
- FUN_HIGH and FUN_LOW behave reversed for funDigitalWrite HOT 1
- Convoluted UART_BRR calculation HOT 3
- Redundant `blink[_raw].bin` files source controlled in repo? HOT 11
- TODO For new updates
- Configurable RAM sizes for V20x, V30x HOT 8
- Compilation results in no code HOT 1
- Make minichlink print flash amount HOT 1
- Make semihosting printf speed along if it times out.
- Empty LD file on missing build tools HOT 2
- prebuilt blink.bin example doesn't seem to work on a CH32V003 board HOT 1
- PWM 8 KHz 16 bit HOT 11
- Onewire slave
- CH32V003A4M6 SPI? HOT 2
- Is this board right for me? HOT 5
- Are there defined symbolic constants for AFIO_EXTICR register values? HOT 5
- minichlink not detecting esp32 programmer on MacOS. HOT 1
- DISCUSSION - Could this run Klipper ? I think it really could omg HOT 8
- Why does my code stop when I connect minichlink terminal? HOT 8
- v30x blink example don't run if TARGET_MCU_PACKAGE sets to CH32V307VCT6 HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ch32v003fun.