Author Topic: CH32V003 RTOS  (Read 7134 times)

0 Members and 1 Guest are viewing this topic.

Offline ali_asadzadehTopic starter

  • Super Contributor
  • ***
  • Posts: 2155
  • Country: ca
CH32V003 RTOS
« on: February 13, 2025, 12:00:26 pm »
Hi
I want to know if there is a tiny or pico OS for ch32V003, guys do you know any?
ASiDesigner, Stands for Application specific intelligent devices
I'm a Digital Expert from 8-bits to 64-bits
 

Offline mikerj

  • Super Contributor
  • ***
  • Posts: 3671
  • Country: gb
Re: CH32V003 RTOS
« Reply #1 on: February 13, 2025, 02:32:33 pm »
You should be able to get a trivial example running on FreeRTOS or Zephyr etc. but that micro only has 2kbyte SRAM which an RTOS will eat up pretty quickly.
 

Offline brucehoult

  • Super Contributor
  • ***
  • Posts: 6464
  • Country: nz
Re: CH32V003 RTOS
« Reply #2 on: February 14, 2025, 12:00:52 am »
NuttX, FreeRTOS, Zephyr all say 8k RAM minimum.

They might be able to be cut down to run in less, but it won't be fun!

For example I think both FreeRTOS and Zephyr have a default stack size of 2k per thread. I don't know how much they have of globals.
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 17872
  • Country: fr
Re: CH32V003 RTOS
« Reply #3 on: February 14, 2025, 01:02:28 am »
Yes. I'm not sure I see the point of using a RTOS on such a "small" MCU. I'd like to understand.
 

Offline ali_asadzadehTopic starter

  • Super Contributor
  • ***
  • Posts: 2155
  • Country: ca
Re: CH32V003 RTOS
« Reply #4 on: February 14, 2025, 12:37:54 pm »
I have seen this for AVR's
http://www.femtoos.org/
If we have something similar for this RISC V part or could use AI to port it would be very nice, basically I need a few tasks, one for Updating 7 segments, one for reading a sensor from I2C, and one for handling simple mod-bus commands and a task for handling keys and the config menu,
I have a product that uses freertos on stm32G030K part, Now I want to port it to this puppy so I could make it even more profitable! >:D
ASiDesigner, Stands for Application specific intelligent devices
I'm a Digital Expert from 8-bits to 64-bits
 

Offline tellurium

  • Frequent Contributor
  • **
  • Posts: 345
  • Country: ua
Re: CH32V003 RTOS
« Reply #5 on: February 14, 2025, 04:46:41 pm »
Sounds easily doable using superloop, without an RTOS. Just code each task as a function that keeps its state, and

Code: [Select]
for (;;) {
  task1();
  task2();
  task3();
  ...
}
Mongoose - a full-stack embedded network library for STM32, NXP and other - https://mongoose.ws
TCP/IP stack + drivers + TLS1.3 + HTTP/WebSocket/MQTT + OTA in a single file
 

Offline xvr

  • Frequent Contributor
  • **
  • Posts: 947
  • Country: ie
    • LinkedIn
Re: CH32V003 RTOS
« Reply #6 on: February 14, 2025, 04:52:53 pm »
Superloop (as tellurium recomend) and protothreads - https://dunkels.com/adam/pt/
 

Offline coppice

  • Super Contributor
  • ***
  • Posts: 10289
  • Country: gb
Re: CH32V003 RTOS
« Reply #7 on: February 14, 2025, 05:02:18 pm »
An RTOS on an MCU is typically a problem due to limited RAM. With only 16k of Flash the ch32V003 it limited on both kinds of memory. Can you fit an RTOS in 16k? Sure. Can you fit it, and leave room for any meaningful applications code? Maybe not.

Some form of round robin operation is usually the practical way to go on small MCUs. In some cases you can put lots of work into interrupt routines, and treat them almost like tasks. People indoctrinated by real time courses at college hate this, but it  works really well in many applications You can put all your time constrained code in interrupt routines, and the none interrupt code can be mostly a UI and monitoring loop. Note that it can also work pretty badly when the problem isn't amenable to that kind of architecture.
 

Offline mikeselectricstuff

  • Super Contributor
  • ***
  • Posts: 14860
  • Country: gb
    • Mike's Electric Stuff
Re: CH32V003 RTOS
« Reply #8 on: February 14, 2025, 06:51:12 pm »
if you're looking for an RTOS on a cheap MCU, you should probably be looking at something like a Pi Pico

..Or ask yourself why you think you need an RTOS, as opposed to a polling loop, state machines  & interrupts for time-critical stuff.

Youtube channel:Taking wierd stuff apart. Very apart.
Mike's Electric Stuff: High voltage, vintage electronics etc.
Day Job: Mostly LEDs
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 17872
  • Country: fr
Re: CH32V003 RTOS
« Reply #9 on: February 15, 2025, 12:34:41 am »
I have seen this for AVR's
http://www.femtoos.org/
If we have something similar for this RISC V part or could use AI to port it would be very nice, basically I need a few tasks, one for Updating 7 segments, one for reading a sensor from I2C, and one for handling simple mod-bus commands and a task for handling keys and the config menu,
I have a product that uses freertos on stm32G030K part, Now I want to port it to this puppy so I could make it even more profitable! >:D

I had a quick look at femtoos, it's made for 8-bit AVRs (exclusively from what I saw?) and porting it should be doable but possibly not worth it.
Still not sure why you think you need a RTOS for what your described above.
Unless running one is part of your marketing strategy. Then, what can we say. If it sells.
 

Offline ali_asadzadehTopic starter

  • Super Contributor
  • ***
  • Posts: 2155
  • Country: ca
Re: CH32V003 RTOS
« Reply #10 on: February 15, 2025, 08:39:03 am »
guys thanks for the feedbacks, I think it can be done
check this out
https://www.segger.com/products/rtos/embos/supported-cores-compiler/sifive/risc-v/embos-ultra-risc-v-embedded-studio/
It only needs 2100bytes of flash and around 200Bytes of ram for a single task! unfortunately they do not support wch parts yet,

I know it can be done with super loop, But maintaining the software and updates are pain in the ass, also Please note that I have done it on STM32G030K too, I know it has more flash and ram, But, my application does not take that much flash and ram.
I wonder if any one has access to the top of the line AI chatbots, so it could help port femto os to CH32V003 ^-^
ASiDesigner, Stands for Application specific intelligent devices
I'm a Digital Expert from 8-bits to 64-bits
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 17872
  • Country: fr
Re: CH32V003 RTOS
« Reply #11 on: February 15, 2025, 09:09:32 am »
Ok, if you really insist on using a RTOS, then I found this one: https://github.com/jnaulet/OpenPicoRTOS
They claim a relatively wide range of supported MCUs, including RV32IMAC and RV32EC, so that shouldn't need much effort. They even claim support for the WCH CH32V003 in particular.
 

Online krish2487

  • Frequent Contributor
  • **
  • Posts: 811
  • Country: dk
Re: CH32V003 RTOS
« Reply #12 on: February 15, 2025, 09:20:13 am »
Echoing what Telurium said..

Also.. if you can make do with a cooperative scheduler.. there is this
https://www.cs.ucr.edu/~vahid/rios/

a very simple implementation of a round robin scheduler that does not depend on premption
If god made us in his image,
and we are this stupid
then....
 

Offline ali_asadzadehTopic starter

  • Super Contributor
  • ***
  • Posts: 2155
  • Country: ca
Re: CH32V003 RTOS
« Reply #13 on: February 15, 2025, 11:13:35 am »
Quote
Ok, if you really insist on using a RTOS, then I found this one: https://github.com/jnaulet/OpenPicoRTOS
Thanks, Nice finding, is there any info about resource usage?
ASiDesigner, Stands for Application specific intelligent devices
I'm a Digital Expert from 8-bits to 64-bits
 

Offline brucehoult

  • Super Contributor
  • ***
  • Posts: 6464
  • Country: nz
Re: CH32V003 RTOS
« Reply #14 on: February 15, 2025, 11:22:57 am »
Echoing what Telurium said..

Also.. if you can make do with a cooperative scheduler.. there is this
https://www.cs.ucr.edu/~vahid/rios/

a very simple implementation of a round robin scheduler that does not depend on premption

Preemption doesn't really make too much difference. You have to be a little more careful implementing locks / semaphones. The main other difference is that a preemptive scheduler needs to have an area to save all registers plus PC for each thread, while a cooperative one only needs space to store RA, SP, S0, S1 on the CH32V003 with the current ilp32e ABI because any function call, including yield(), assumes all the rest are nuked.
 
The following users thanked this post: krish2487

Offline coppice

  • Super Contributor
  • ***
  • Posts: 10289
  • Country: gb
Re: CH32V003 RTOS
« Reply #15 on: February 15, 2025, 12:35:08 pm »
Echoing what Telurium said..

Also.. if you can make do with a cooperative scheduler.. there is this
https://www.cs.ucr.edu/~vahid/rios/

a very simple implementation of a round robin scheduler that does not depend on premption

Preemption doesn't really make too much difference. You have to be a little more careful implementing locks / semaphones. The main other difference is that a preemptive scheduler needs to have an area to save all registers plus PC for each thread, while a cooperative one only needs space to store RA, SP, S0, S1 on the CH32V003 with the current ilp32e ABI because any function call, including yield(), assumes all the rest are nuked.
Cooperative multi-tasking schemes can be pretty annoying to work with on larger machines, with a need to perform a flexible array of functions. However, for en embedded system that needs to do only one thing, and do it well, there are very few downsides, and the developers job is quite straightforward. I think people who put down the cooperative approach forget that MS built their entire business on cooperative multi-tasking. It wasn't until Windows NT that they moved beyond it, yet Windows 3.11, 95, and 98 did remarkably well.
 

Offline coppice

  • Super Contributor
  • ***
  • Posts: 10289
  • Country: gb
Re: CH32V003 RTOS
« Reply #16 on: February 15, 2025, 12:50:52 pm »
Echoing what Telurium said..

Also.. if you can make do with a cooperative scheduler.. there is this
https://www.cs.ucr.edu/~vahid/rios/

a very simple implementation of a round robin scheduler that does not depend on premption
Where is the actual code? I couldn't see a link to it. The only link seems to be to a site that no longer exists - www.programmingembeddedsystems.com
 

Online krish2487

  • Frequent Contributor
  • **
  • Posts: 811
  • Country: dk
Re: CH32V003 RTOS
« Reply #17 on: February 15, 2025, 02:34:30 pm »
Thats weird..
The link I pasted contains two flavours of the scheduler right there on the page..
Its just code for a barebones task scheduler..
If god made us in his image,
and we are this stupid
then....
 

Offline coppice

  • Super Contributor
  • ***
  • Posts: 10289
  • Country: gb
Re: CH32V003 RTOS
« Reply #18 on: February 15, 2025, 02:46:20 pm »
Thats weird..
The link I pasted contains two flavours of the scheduler right there on the page..
Its just code for a barebones task scheduler..
The page contains 2 example programs that use RIOS. I can't find any actual RIOS code. They include RIMS.h, and no other header files. The page that is supposed to be for RIMS doesn't seem to exist. There appears to be more than the presented simple framework for cooperative multi-tasking, as the example code calls TimerOn() and TimerSet(), which aren't there. Every cooperative multi-tasking framework I have used has been simple, but there is code which does some of the donkey work.

Looking further it seems you can download a Windows installer for RIMS from https://www.cs.ucr.edu/~vahid/pes/RITools/, which will give you the RIMS.h files, which is very elementary. The TimerOn and TimerSet  routines appear to be user supplied. There is a link which will take you to an AVR specific page, with versions of those routines for an AVR chip. So, what they are calling RIOS 1.2 is nothing more than the kind of outline of how you might implement simple cooperative multi-tasking in a number of text books. They appear to have received grants to produce this. Is that what counts for a funded project these days?
« Last Edit: February 15, 2025, 02:59:50 pm by coppice »
 

Online krish2487

  • Frequent Contributor
  • **
  • Posts: 811
  • Country: dk
Re: CH32V003 RTOS
« Reply #19 on: February 15, 2025, 03:00:07 pm »
Thats weird..
The link I pasted contains two flavours of the scheduler right there on the page..
Its just code for a barebones task scheduler..
The page contains 2 example programs that use RIOS. I can't find any actual RIOS code. They include RIMS.h, and no other header files. The page that is supposed to be for RIMS doesn't seem to exist. There appears to be more than the presented simple framework for cooperative multi-tasking, as the example code calls TimerOn() and TimerSet(), which aren't there. Every cooperative multi-tasking framework I have used has been simple, but there is code which does some of the donkey work.

Ah right... that would be under the "Porting to AVR microcontrollers" section.
AFAICS I m not seeing the need for the RIMS.h file.. you need to setup a timer and round robin on every tick.
thats what the TimerOn and TimerSet do... and of course the interrupt handler..

Edit: beat me by a few seconds.. :-)
you are right.. its a very simple implementation.. but it also is very lightweight and suits the OP's purpose no... without any additional code..

« Last Edit: February 15, 2025, 03:04:09 pm by krish2487 »
If god made us in his image,
and we are this stupid
then....
 

Offline brucehoult

  • Super Contributor
  • ***
  • Posts: 6464
  • Country: nz
Re: CH32V003 RTOS
« Reply #20 on: February 15, 2025, 10:06:29 pm »
Echoing what Telurium said..

Also.. if you can make do with a cooperative scheduler.. there is this
https://www.cs.ucr.edu/~vahid/rios/

a very simple implementation of a round robin scheduler that does not depend on premption

Preemption doesn't really make too much difference. You have to be a little more careful implementing locks / semaphones. The main other difference is that a preemptive scheduler needs to have an area to save all registers plus PC for each thread, while a cooperative one only needs space to store RA, SP, S0, S1 on the CH32V003 with the current ilp32e ABI because any function call, including yield(), assumes all the rest are nuked.
Cooperative multi-tasking schemes can be pretty annoying to work with on larger machines, with a need to perform a flexible array of functions. However, for en embedded system that needs to do only one thing, and do it well, there are very few downsides, and the developers job is quite straightforward. I think people who put down the cooperative approach forget that MS built their entire business on cooperative multi-tasking. It wasn't until Windows NT that they moved beyond it, yet Windows 3.11, 95, and 98 did remarkably well.

I'm not sure in what sense that is a response to what I wrote, especially as I certainly have not "put down" cooperative multi-tasking.. Perhaps it's really to the message I was replying to?

I've never used Windows but I spent more than 15 years programming the cooperatively scheduled MacOS pre Mac OS X.

I also spent a decade or so working on a stockbroking software system with quite a number of users (couple of dozen) on a very low powered minicomputer that used entirely cooperative multitasking. The COBOL compiler generated code that called yield() on every backwards branch. Programming in assembly language was highly restricted because it was essential that all programs called yield() frequently enough.

I also implemented from scratch a cooperative threading library, scheduler, semaphores etc, and garbage collector for a Java native compiler running on ARM7TDMI processors in Qualcomm "BREW" mobile phones (used on the Verizon network), which was very successful for several years before iPhone and Android took over the world. We did projects helping 9 or the top 10 mobile game companies (all but EA) port Java software to BREW, plus Amazon, Disney, Yahoo! and some companies with for example medical or logistics software.
 

Offline coppice

  • Super Contributor
  • ***
  • Posts: 10289
  • Country: gb
Re: CH32V003 RTOS
« Reply #21 on: February 15, 2025, 10:12:41 pm »
Echoing what Telurium said..

Also.. if you can make do with a cooperative scheduler.. there is this
https://www.cs.ucr.edu/~vahid/rios/

a very simple implementation of a round robin scheduler that does not depend on premption

Preemption doesn't really make too much difference. You have to be a little more careful implementing locks / semaphones. The main other difference is that a preemptive scheduler needs to have an area to save all registers plus PC for each thread, while a cooperative one only needs space to store RA, SP, S0, S1 on the CH32V003 with the current ilp32e ABI because any function call, including yield(), assumes all the rest are nuked.
Cooperative multi-tasking schemes can be pretty annoying to work with on larger machines, with a need to perform a flexible array of functions. However, for en embedded system that needs to do only one thing, and do it well, there are very few downsides, and the developers job is quite straightforward. I think people who put down the cooperative approach forget that MS built their entire business on cooperative multi-tasking. It wasn't until Windows NT that they moved beyond it, yet Windows 3.11, 95, and 98 did remarkably well.

I'm not sure in what sense that is a response to what I wrote, especially as I certainly have not "put down" cooperative multi-tasking.. Perhaps it's really to the message I was replying to?

I've never used Windows but I spent more than 15 years programming the cooperatively scheduled MacOS pre Mac OS X.

I also spent a decade or so working on a stockbroking software system with quite a number of users (couple of dozen) on a very low powered minicomputer that used entirely cooperative multitasking. The COBOL compiler generated code that called yield() on every backwards branch. Programming in assembly language was highly restricted because it was essential that all programs called yield() frequently enough.

I also implemented from scratch a cooperative threading library, scheduler, semaphores etc, and garbage collector for a Java native compiler running on ARM7TDMI processors in Qualcomm "BREW" mobile phones (used on the Verizon network), which was very successful for several years before iPhone and Android took over the world. We did projects helping 9 or the top 10 mobile game companies (all but EA) port Java software to BREW, plus Amazon, Disney, Yahoo! and some companies with for example medical or logistics software.
Don't get paranoid. I wasn't criticising what you wrote. I was supporting it.
 

Offline brucehoult

  • Super Contributor
  • ***
  • Posts: 6464
  • Country: nz
Re: CH32V003 RTOS
« Reply #22 on: February 16, 2025, 03:41:18 am »
Oh ok, fair enough. A "right" or "yes" or "furthermore" something might not go astray :-)
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 17872
  • Country: fr
Re: CH32V003 RTOS
« Reply #23 on: February 16, 2025, 03:50:21 am »
Quote
Ok, if you really insist on using a RTOS, then I found this one: https://github.com/jnaulet/OpenPicoRTOS
Thanks, Nice finding, is there any info about resource usage?

I don't know, didn't see this directly, but they claim under 400 total LOC, so that sounds much lower than FreeRTOS (and they claim following strict coding rules.
They give an example for the CH32V003 in the 'staging' directory. Worth a shot.
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 17872
  • Country: fr
Re: CH32V003 RTOS
« Reply #24 on: February 16, 2025, 03:52:18 am »
Note that the chinese WCH website shows new models in the same series (CH32V002, CH32V004..8 ), with up to 8KB of RAM.
They're not listed on the usual distributors though and haven't see them on Aliex yet either.
 
The following users thanked this post: ali_asadzadeh


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

- - -
-->