📖 中文文档: README_CN.md
dumyOS is a lightweight real-time operating system (RTOS) designed for ARM Cortex-M3 and Cortex-M4 microcontrollers. It provides essential multitasking capabilities including task scheduling, priority management, and task delays, making it ideal for learning embedded systems development and small-scale projects across various MCU platforms.
- 🚀 Lightweight Design - Clean code with minimal memory footprint
- 📋 Preemptive Scheduling - Priority-based task scheduling
- ⏰ Task Delays - Millisecond-precision task delays
- 🔄 Task Yielding - Support for voluntary CPU yielding
- 💾 Static Memory Management - All task stacks are statically allocated
- 🎯 Hardware Abstraction - Optimized for Cortex-M3 core
- MCU: ARM Cortex-M3 or Cortex-M4 based microcontrollers
- STM32F1xx, STM32F4xx series
- NXP LPC series
- Atmel SAM series
- TI Tiva/Stellaris series
- And other Cortex-M3/M4 based MCUs
- Flash: Minimum 16KB
- RAM: Minimum 8KB
- Peripherals: SysTick timer, PendSV exception
dumyOS/
├── dumyos/ # Operating system core code
│ ├── os.h # System header file
│ └── os.c # System implementation
├── src/ # Application code
│ ├── main.c # Main program file
│ └── system_stm32f1xx.c # System initialization
├── startup/ # Startup code
├── linker/ # Linker scripts
├── lib/ # CMSIS library files
├── inc/ # Header file directory
└── Makefile # Build configuration
Ensure the following tools are installed:
arm-none-eabi-gcc- ARM cross-compilermake- Build toolopenocd- Programming tool (optional)
# Clone the project
git clone <repository-url>
cd dumyOS
# Build the project
make
# Check binary size
make size
# Clean build artifacts
make clean# Flash using OpenOCD (requires ST-Link)
make flashvoid OS_Init(void); // Initialize the operating system
void OS_Start(void); // Start the schedulerint OS_CreateTask(void (*task)(void *), // Task function pointer
void *param, // Task parameter
uint8_t priority, // Task priority (0-31, lower number = higher priority)
uint32_t *stack_mem, // Task stack memory
uint32_t stack_size_words); // Stack size in words
void OS_Delay(uint32_t ticks); // Task delay (milliseconds)
void OS_Yield(void); // Voluntarily yield CPUtypedef enum {
TASK_STATE_READY = 0, // Ready state
TASK_STATE_RUNNING, // Running state
TASK_STATE_SLEEPING, // Sleeping state
TASK_STATE_UNUSED // Unused state
} task_state_t;#include "dumyos/os.h"
// Define task stacks
static uint32_t task1_stack[128];
static uint32_t task2_stack[128];
// Task function 1 - High priority task
void high_priority_task(void *param) {
while (1) {
// Critical task operations
// GPIO toggle or other time-sensitive operations
OS_Delay(100); // Delay 100ms
}
}
// Task function 2 - Low priority task
void low_priority_task(void *param) {
while (1) {
// Background task operations
// Data processing, logging, etc.
OS_Delay(1000); // Delay 1 second
}
}
int main(void) {
// System initialization (MCU specific)
SystemClock_Config(); // Configure system clock
peripheral_init(); // Initialize peripherals
// Operating system initialization
OS_Init();
// Create tasks
OS_CreateTask(high_priority_task, NULL, 2, task1_stack, 128); // High priority
OS_CreateTask(low_priority_task, NULL, 4, task2_stack, 128); // Low priority
// Start scheduler
OS_Start();
// Never reached
while(1);
}The following parameters can be configured in os.h:
#define OS_MAX_TASKS 16 // Maximum number of tasks
#define OS_MAX_PRIO 32 // Maximum priority levels (0-31)dumyOS uses preemptive priority scheduling:
- Priority Scheduling: Lower numbers have higher priority (0 is highest)
- Preemptive: High-priority tasks can preempt low-priority tasks
- Same Priority: Uses FIFO (First In, First Out) strategy
- Idle Task: System automatically creates lowest priority idle task
- Uses SysTick timer for system clock interrupts (1ms) - available on all Cortex-M3/M4
- Uses PendSV exception for context switching - standard ARM Cortex-M feature
- Fast task selection algorithm based on priority bitmap
- All task stack space is statically allocated by user
- Task Control Blocks (TCB) managed using fixed-size arrays
- Ready queue uses linked list structure, supporting O(1) insertion and deletion
- Hardware automatically saves/restores R0-R3, R12, LR, PC, PSR
- Software saves/restores R4-R11
- Based on ARM Cortex-M3/M4 PendSV mechanism
- Stack Size: Ensure sufficient stack space for each task to avoid stack overflow
- Priority: Avoid priority inversion issues, design task priorities carefully
- Critical Sections: Use
__disable_irq()and__enable_irq()when modifying shared resources - Task Functions: Task functions should be infinite loops and should not return
- Platform Specific: Adapt system initialization and peripheral access for your specific MCU
- Stack Overflow Detection: Fill stack bottom with special values, check periodically for corruption
- Task State Monitoring: Observe task state changes in debugger
- System Load: Monitor idle task runtime to assess system load
- Context Switch Time: < 5μs (typical at 72-100MHz)
- Memory Usage:
- System code: ~2KB Flash
- System RAM: ~1KB
- Per task: 32 bytes TCB + user-defined stack space
- Supported Platforms: Any Cortex-M3/M4 based microcontroller
- Add Mutex support
- Implement Semaphores
- Add message queue functionality
- Support software timers
- Memory pool management
- Task statistics
This project is licensed under the MIT License - see the LICENSE file for details
Issues and Pull Requests are welcome!
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
For questions or suggestions, please contact us through Issues.
⭐ If this project helps you, please give it a Star!