Skip to content

Missing defines #4

@dzanis

Description

@dzanis

I used some examples from your repository (oled_gfx, i2c_dma, uart)
But I needed code for ADC and timer, and it turned out that many defines were missing, for example for timer configuration:

void TIM2_Init(uint32_t frequency)
{
    RCC->APB1PCENR |= RCC_TIM2EN; // Enable clock for TIM2

    TIM2->CTLR1 |= TIM_CounterMode_Up | TIM_CKD_DIV1; // Set counter mode to up and no clock division
    TIM2->CTLR2 = TIM_MMS_1; // Use update event as trigger

    uint32_t prescaler = (SystemCoreClock / 1000000) - 1; // Calculate prescaler for 1 MHz
    TIM2->PSC = prescaler; // Set prescaler

    uint32_t period = (1000000 / frequency) - 1; // Calculate period for the given frequency
    TIM2->ATRLR = period; // Set period

    TIM2->SWEVGR = TIM_PSCReloadMode_Immediate; // Immediate load of the new prescaler value
    TIM2->INTFR = ~TIM_FLAG_Update; // Clear update flag
    TIM2->DMAINTENR |= TIM_IT_Update; // Enable update interrupt
    TIM2->CTLR1 |= TIM_CEN; // Enable TIM2
}

I'm not very familiar with these registers myself. At first I used openwch/ch32v003 and had no problems until I ran out of memory. Your development, on the other hand, turned out to be very compact. In general, due to the lack of these defines (TIM_CounterMode_Up, TIM_PSCReloadMode_Immediate, etc.), they have to be "patched" in somehow, which is not very elegant and creates confusion. I wanted to ask if you are going to expand your development, for example, there are not enough examples of ADC and timers?

I use Windows 11 and VSCode to compile ch32v003 using your development. The platformio.ini file helps with this.

; see https://docs.platformio.org/en/latest/projectconf/index.html
[platformio]
src_dir = .
include_dir = .

[env:genericCH32V003F4P6]
platform = https://github.com/Community-PIO-CH32V/platform-ch32v.git
; or ch32v003f4p6_evt_r0 or whatever, see platform link
board = genericCH32V003F4P6
monitor_speed = 115200

board_build.ldscript = linker/ch32v003.ld
build_flags = -flto -I/usr/include/newlib -I./include -lgcc -D F_CPU=48000000

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