CH32V003 RTOS - Page 1
Forum section: electronics / general

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: February 13, 2025, 12:00:26 pm
content: HiI want to know if there is a tiny or pico OS for ch32V003, guys do you know any?

author: mikerj
author_rank: Super Contributor
timestamp: February 13, 2025, 02:32:33 pm
content: You should be able to get a trivial example running on FreeRTOS orZephyretc. but that micro only has 2kbyte SRAM which an RTOS will eat up pretty quickly.

author: brucehoult
author_rank: Super Contributor
timestamp: February 14, 2025, 12:00:52 am
content: 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.

author: SiliconWizard
author_rank: Super Contributor
timestamp: February 14, 2025, 01:02:28 am
content: Yes. I'm not sure I see the point of using a RTOS on such a "small" MCU. I'd like to understand.

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: February 14, 2025, 12:37:54 pm
content: I have seen this for AVR'shttp://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!

author: tellurium
author_rank: Frequent Contributor
timestamp: February 14, 2025, 04:46:41 pm
content: Sounds easily doable using superloop, without an RTOS. Just code each task as a function that keeps its state, andCode:for (;;) {task1();task2();task3();...}

author: xvr
author_rank: Frequent Contributor
timestamp: February 14, 2025, 04:52:53 pm
content: Superloop (as tellurium recomend) and protothreads -https://dunkels.com/adam/pt/

author: coppice
author_rank: Super Contributor
timestamp: February 14, 2025, 05:02:18 pm
content: 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.

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: February 14, 2025, 06:51:12 pm
content: 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.

author: SiliconWizard
author_rank: Super Contributor
timestamp: February 15, 2025, 12:34:41 am
content: Quote from: ali_asadzadeh on February 14, 2025, 12:37:54 pmI 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.

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: February 15, 2025, 08:39:03 am
content: guys thanks for the feedbacks, I think it can be donecheck this outhttps://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

author: SiliconWizard
author_rank: Super Contributor
timestamp: February 15, 2025, 09:09:32 am
content: Ok, if you really insist on using a RTOS, then I found this one:https://github.com/jnaulet/OpenPicoRTOSThey 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.

author: krish2487
author_rank: Frequent Contributor
timestamp: February 15, 2025, 09:20:13 am
content: Echoing what Telurium said..Also.. if you can make do with a cooperative scheduler.. there is thishttps://www.cs.ucr.edu/~vahid/rios/a very simple implementation of a round robin scheduler that does not depend on premption

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: February 15, 2025, 11:13:35 am
content: QuoteThanks, Nice finding, is there any info about resource usage?

author: brucehoult
author_rank: Super Contributor
timestamp: February 15, 2025, 11:22:57 am
content: Quote from: krish2487 on February 15, 2025, 09:20:13 amPreemption 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.

author: coppice
author_rank: Super Contributor
timestamp: February 15, 2025, 12:35:08 pm
content: Quote from: brucehoult on February 15, 2025, 11:22:57 amCooperative 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.

author: coppice
author_rank: Super Contributor
timestamp: February 15, 2025, 12:50:52 pm
content: Quote from: krish2487 on February 15, 2025, 09:20:13 amWhere 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

author: krish2487
author_rank: Frequent Contributor
timestamp: February 15, 2025, 02:34:30 pm
content: 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..

author: coppice
author_rank: Super Contributor
timestamp: February 15, 2025, 02:46:20 pm
content: Quote from: krish2487 on February 15, 2025, 02:34:30 pmThe 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 fromhttps://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?

author: krish2487
author_rank: Frequent Contributor
timestamp: February 15, 2025, 03:00:07 pm
content: Quote from: coppice on February 15, 2025, 02:46:20 pmAh 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..

author: brucehoult
author_rank: Super Contributor
timestamp: February 15, 2025, 10:06:29 pm
content: Quote from: coppice on February 15, 2025, 12:35:08 pmI'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.

author: coppice
author_rank: Super Contributor
timestamp: February 15, 2025, 10:12:41 pm
content: Quote from: brucehoult on February 15, 2025, 10:06:29 pmDon't get paranoid. I wasn't criticising what you wrote. I was supporting it.

author: brucehoult
author_rank: Super Contributor
timestamp: February 16, 2025, 03:41:18 am
content: Oh ok, fair enough. A "right" or "yes" or "furthermore" something might not go astray :-)

author: SiliconWizard
author_rank: Super Contributor
timestamp: February 16, 2025, 03:50:21 am
content: Quote from: ali_asadzadeh on February 15, 2025, 11:13:35 amI 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.

author: SiliconWizard
author_rank: Super Contributor
timestamp: February 16, 2025, 03:52:18 am
content: 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.

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: February 16, 2025, 12:10:53 pm
content: QuoteI have bought around 1k Units of CH32V003, so I think I should sell them as products first