{"id":17032655,"url":"https://github.com/andylokandy/preemptive","last_synced_at":"2025-06-13T06:08:29.267Z","repository":{"id":75790674,"uuid":"171844752","full_name":"andylokandy/preemptive","owner":"andylokandy","description":"A minimum preemptive OS on Cortex-M3 (specially on blue-pill board) written in Rust.","archived":false,"fork":false,"pushed_at":"2019-07-25T14:58:12.000Z","size":38,"stargazers_count":34,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-13T06:08:00.050Z","etag":null,"topics":["cortex-m3","embedded","os","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/andylokandy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-02-21T09:48:00.000Z","updated_at":"2025-03-24T06:50:50.000Z","dependencies_parsed_at":"2023-06-07T18:15:12.208Z","dependency_job_id":null,"html_url":"https://github.com/andylokandy/preemptive","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/andylokandy/preemptive","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andylokandy%2Fpreemptive","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andylokandy%2Fpreemptive/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andylokandy%2Fpreemptive/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andylokandy%2Fpreemptive/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andylokandy","download_url":"https://codeload.github.com/andylokandy/preemptive/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andylokandy%2Fpreemptive/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259592261,"owners_count":22881267,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cortex-m3","embedded","os","rust"],"created_at":"2024-10-14T08:29:36.342Z","updated_at":"2025-06-13T06:08:29.239Z","avatar_url":"https://github.com/andylokandy.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Preemptive-rs\n\nA minimum preemptive OS on Cortex-M3 (specially on blue-pill board) written in Rust. It is for the purpose of\nresearching and showing how the fundamental runtime of Cortex-M3 works.\n\n## What is preemptive OS\n\n\u003e In computing, preemption is the act of temporarily interrupting a task being carried out by a computer system,\nwithout requiring its cooperation, and with the intention of resuming the task at a later time. Such changes of\nthe executed task are known as context switches.   ----  Wikipedia\n\nIn breif, the kernel of non-preemptive OS can not interrupt a task, while the kernel of preemptive OS can take\nthe control back without informing the task.\n\n## Prerequisite\n\n- Make sure you have a `blue-pill` board and a serial port reciever.\n- Make sure you have `arm-none-eabi` toolchain and `openocd` installed on your platform.\n- Install the latest nightly rust toolchain. The compiler version used when this project is beening written is\n`rustc 1.37.0-nightly (17e62f77f 2019-07-01)`.\n\n## Project Structure\n\nThis project is collections of several stages of building a preliminary preemptive OS from sketch. I'll make\nsure all code of each chapter can compile and run on `blue-pill`.\n\n## Build and Run\n\n- Enter `Chapter5-MultiTasking`\n\n```text\ncd Chapter5-MultiTasking\n```\n\n- Connect the `blue-pill` to your laptop.\n\n- Connect pin `PA2` to a serial reciever, with 115200 baudrate, 8 data bits, 1 stop bits, no parity and no flow control.\n\n- Run `openocd`:\n\n```text\n\u003e openocd\n...\nInfo : using stlink api v2\nInfo : Target voltage: 3.175214\nInfo : stm32f1x.cpu: hardware has 6 breakpoints, 4 watchpoints\n```\n\n- Run the application:\n\n```text\n\u003e cargo run\n    Finished dev [unoptimized + debuginfo] target(s) in 0.93s\n    Running `target\\thumbv7m-none-eabi\\debug\\preemptive`\nReading symbols from target\\thumbv7m-none-eabi\\debug\\preemptive...done.\ntarget halted due to debug-request, current mode: Thread\nxPSR: 0x01000000 pc: 0x080008fc msp: 0x20005000\nLoading section .isr_vector, size 0x40 lma 0x8000000\nLoading section .text, size 0x2a08 lma 0x8000040\nStart address 0x80008fc, load size 10824\nTransfer rate: 14 KB/sec, 5412 bytes/write.\n(gdb) continue\nContinuing.\n```\n\nAs the result, you would see the output from the serial reciever like this:\n\n```text\nExecuting task1!\ntask1: fib(0)=1\ntask1: fib(1)=1\ntask1: fib(2)=2\n\nExecuting task2!\ntask2: is_prime(1)=true\ntask2: is_prime(2)=true\ntask2: is_prime(3)=true\n\nExecuting task1!\ntask1: fib(3)=3\ntask1: fib(4)=5\ntask1: fib(5)=8\n\nExecuting task2!\ntask2: is_prime(4)=false\ntask2: is_prime(5)=true\ntask2: is_prime(6)=false\n...\n```\n\n## Reference\n\n- mini-arm-os (https://github.com/jserv/mini-arm-os)\n- tock os (https://github.com/tock/tock)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandylokandy%2Fpreemptive","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandylokandy%2Fpreemptive","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandylokandy%2Fpreemptive/lists"}