platform-ch32v icon indicating copy to clipboard operation
platform-ch32v copied to clipboard

Make clock settings easily selectible

Open maxgerhardt opened this issue 2 years ago • 2 comments

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.

maxgerhardt avatar Mar 03 '23 21:03 maxgerhardt

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.

tmolteno avatar May 01 '23 01:05 tmolteno

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

build_flags = 
  -DSYSCLK_FREQ_8MHz_HSI=8000000
  -USYSCLK_FREQ_48MHz_HSE

ldab avatar Jun 29 '24 09:06 ldab