Community-PIO-CH32V / platform-ch32v

PlatformIO platform for CH32V RISC-V chips (CH32V003, CH32V103, CH32V20x, CH32V30x, CH32X035) and CH56x, CH57x, CH58x, CH59x
Apache License 2.0
178 stars 26 forks source link

Make clock settings easily selectible #21

Open maxgerhardt opened 1 year ago

maxgerhardt commented 1 year ago

With the default settings, we compile the system_ch32v....c file of the NoneOS SDK, which is default-configured for the development boards, requiring a HSE (external crystal oscillator of e.g. 8MHz) to work correctly.

We need to adapt the .c file so that the user has the chance to select the appropriate clock for their board nicely and document it.

tmolteno commented 1 year ago

Note to others :

I had to modify these settings to get my code to work properly when I chose my own target...

To modify your clock settings for your own board. You have to change the appropriate file. For the ch32v003, this file is

system_ch32v00x.c

At the top of the file, uncomment the appropriate line. I changed to the 48 MHz HSI clock using the following:

//#define SYSCLK_FREQ_8MHz_HSI    8000000
//#define SYSCLK_FREQ_24MHZ_HSI   HSI_VALUE
#define SYSCLK_FREQ_48MHZ_HSI   48000000
//#define SYSCLK_FREQ_8MHz_HSE    8000000
//#define SYSCLK_FREQ_24MHz_HSE   HSE_VALUE
//#define SYSCLK_FREQ_48MHz_HSE   48000000

To get to this file in VsCode, right click on the function SystemCoreClockUpdate() in your main.c. Then choose "go to definition". This will take you to the right file.

ldab commented 6 days ago

One could simply add something like this to platformio.ini:

build_flags = 
  -DSYSCLK_FREQ_8MHz_HSI=8000000
  -USYSCLK_FREQ_48MHz_HSE