Skip to content

Clock selection using Arduino IDE menu #27

Closed
@maxint-rd

Description

@maxint-rd

While testing this Arduino core on my CH32V003, I found that using a bare CH32V003 TSSOP20 chip without external crystal requires a change of clock selection in system_ch32v00x.c. Not having the correct clock selected resulted in incorrect timing of millis() and micros(). In my test using the timestamp feature of the IDE, I saw that 500ms actually took a second, which illustrated that the default fallback clock is the 24MHz internal oscillator. Having the internal clock as automatic fallback is a nice feature, but having an IDE user changing core code should be avoided.

To make clock selection easier I modified the files boards.txt, platform.txt and system_ch32v00x.c. I now can select the clock using the menu of the Arduino IDE. I don't have other type of chips for testing, but perhaps you may want to make a similar change.


Changes made:

/packages/WCH/hardware/ch32/1.0.3/system/CH32V00x/USER/system_ch32v00x.c :
=> all clock related defines commented out

/packages/WCH/hardware/ch32/1.0.3/boards.txt :

# added Clock selection to menu
menu.clock=Clock

# added flags for Clock selection
CH32V00x_EVT.menu.clock.48MHzE=48 MHz External
CH32V00x_EVT.menu.clock.48MHzE.build.flags.clock=-DSYSCLK_FREQ_48MHz_HSE=48000000
CH32V00x_EVT.menu.clock.24MHzE=24 MHz External
CH32V00x_EVT.menu.clock.24MHzE.build.flags.clock=-DSYSCLK_FREQ_24MHz_HSE=HSE_VALUE
CH32V00x_EVT.menu.clock.8MHzE=8 MHz External
CH32V00x_EVT.menu.clock.8MHzE.build.flags.clock=-DSYSCLK_FREQ_8MHz_HSE=8000000
CH32V00x_EVT.menu.clock.48MHz=48 MHz Internal
CH32V00x_EVT.menu.clock.48MHz.build.flags.clock=-DSYSCLK_FREQ_48MHZ_HSI=48000000
CH32V00x_EVT.menu.clock.24MHz=24 MHz Internal
CH32V00x_EVT.menu.clock.24MHz.build.flags.clock=-DSYSCLK_FREQ_24MHZ_HSI=HSI_VALUE
CH32V00x_EVT.menu.clock.8MHz=8 MHz Internal
CH32V00x_EVT.menu.clock.8MHz.build.flags.clock=-DSYSCLK_FREQ_8MHz_HSI=8000000

/packages/WCH/hardware/ch32/1.0.3/platform.txt "

# added Clock flag to various compiler flags
compiler.S.flags={build.flags.clock} {compiler.extra_flags} -x assembler-with-cpp "-I{build.system.path}/{build.series}/SRC/Startup/" "-I{build.core.path}/ch32/"

compiler.c.flags={build.flags.clock} {compiler.extra_flags} -c {build.flags.optimize} {build.flags.debug} {compiler.warning_flags} -std=gnu99 -MMD {compiler.ch.extra_include}

compiler.cpp.flags={build.flags.clock} {compiler.extra_flags} -c {build.flags.optimize} {build.flags.debug} {compiler.warning_flags} -std={compiler.cpp.std}  -fno-threadsafe-statics  -fno-rtti -fno-exceptions -fno-use-cxa-atexit -MMD {compiler.ch.extra_include} -fpermissive

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions