Electronics > Microcontrollers

CH32V307VCT6 with Freertos and us delay

(1/2) > >>

ali_asadzadeh:
Hi,
I'm starting to do some projects in CH32V307VCT6, I'm using MounRiver Studio and FreeRTOS, there is Delay_Us function in debug.c file, But it seems this function is modifying the systick and when I use it, it would ruin the FreeRTOS,

How can I reimplement the Delay_Us  function without modifying the systick, Also I could not find any info about the systick regs or any other system peripherals like NVIC in CH32V parts, the peripherals window in debug mode also would not show them, so I wonder where the info is hidden?

this is the original Delay_Us   function in debug.c


--- Code: ---void Delay_Us(uint32_t n)
{
    uint32_t i;

    SysTick->SR &= ~(1 << 0);
    i = (uint32_t)n * p_us;

    SysTick->CMP = i;
    SysTick->CTLR |= (1 << 4) | (1 << 5) | (1 << 0);

    while((SysTick->SR & (1 << 0)) != (1 << 0))
        ;
    SysTick->CTLR &= ~(1 << 0);
}
--- End code ---

brucehoult:
Well, just get the current time, add the delay you want, and then loop while (endTime - currentTime) > 0. Using signed integers, obviously. No need to modify the counter.

ali_asadzadeh:
Thanks  brucehoult, do you know the register defs? Also How can I see the systick registers when I'm debugging, I can not find them in the peripherals dialog, is it some where else that I can not find?

Christe4nM:
SysTick and NVIC are ARM Cortex-M specific, wheras your part is RISC-V based. With ARM the SysTick and NVIC registers are part of the ARM core, and usually don't show up in any peripheral register views from the vendor. Perhaps the same applies to your RISC-V part?

With ARM you'd need the ARM Cortex-Mx Reference Manual to know which registers are at play. The SysTick is also implemented by the vendor, and IIRC you'd need the register map for your part to see where it sits in the address space.

I am unfamiliar with RISC-V, but seeing as that the vendor of the CH32V parts uses both cores within their product family - could it be that the code was written with ARM in mind and later modified for use with the RISC-V parts? So when used with a RISC-V part it stills uses the ARM names SysTick and NVIC, but it maps to the RISC-V specific implementations of those? Perhaps if you find out what actual (core) peripherals they are in RISC-V, you could find them in your part's RM

brucehoult:

--- Quote from: ali_asadzadeh on June 10, 2023, 09:37:44 am ---Thanks  brucehoult, do you know the register defs? Also How can I see the systick registers when I'm debugging, I can not find them in the peripherals dialog, is it some where else that I can not find?

--- End quote ---

I don't know what custom registers WCH might have, but every RISC-V core is supposed to include mtime and mcycles CSRs which can be read using the normal CSRR instruction e.g. CSRR dstReg,mtime or its alias RDTIME dstReg. That's on a 64 bit CPU. On a 32 bit CPU you use RDTIMEH; RDTIMEL; RDTIMEH and check that both RDTIMEH returned the same value, or else loop and try again. Or similarly for clock cycles. For delays of less than 2^31 units you can just read the L value.

Navigation

[0] Message Index

[#] Next page

There was an error while thanking
Thanking...
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod