How I ended up writing a new real-time kernel
FreeA well-formed and carefully tested real-time kernel for 16- and 32-bit MCUs
FreeFree tier
About How I ended up writing a new real-time kernel
A detailed technical article by Dmitry Frank documenting the creation of TNeo, a well-formed and carefully tested real-time kernel for 16- and 32-bit microcontrollers. The article covers the motivation for building a custom kernel, the inner workings of preemptive multitasking, context switching, interrupt handling, and timer management. It also includes comparisons to other RTOSes like FreeRTOS and discusses the design philosophy, implementation details, and unit testing approach.
Key Features
Preemptive multitasking
Context switching with interrupt handling
Multiple interrupt stack support
Static and dynamic tick timers
Idle task for low-power modes
Well-formed and maintainable code
Extensive unit testing (Ceedling)
Pros & Cons
Pros
- Carefully tested and well-formed code
- Designed for small memory footprints
- Clear documentation of internal mechanisms
- Open source and free to use
Cons
- Limited to 16- and 32-bit MCUs
- Less ecosystem and community support compared to FreeRTOS
- Not as widely adopted, may lack third-party integrations
Best For
Embedded systems developmentReal-time control applicationsMicrocontroller projects with 16/32-bit MCUsMemory-constrained devices (e.g., 16KB RAM)
FAQ
How does TNeo handle interrupts?
TNeo uses a two-stack model: one for each thread's stack and a separate interrupt stack. It manages context switches carefully to avoid corrupting interrupt state, and uses a 'one entry point, one exit point' strategy for interrupt handlers to ensure correct nesting and priority handling.
Why not just use FreeRTOS?
The author started with TNKernel but found its implementation flawed (e.g., unsafe interrupt handling during context switches). TNeo was written from scratch with a cleaner design, better code organization, and comprehensive unit tests. It is not necessarily intended to replace FreeRTOS but to provide an alternative for those who value code quality and specific design choices.