• Stars
    star
    929
  • Rank 49,172 (Top 1.0 %)
  • Language
    C
  • License
    Other
  • Created almost 10 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Build a minimal multi-tasking OS kernel for ARM from scratch

Build a minimal multi-tasking OS kernel for ARM from scratch

Prerequisites

./configure --disable-werror --enable-debug \
    --target-list="arm-softmmu" \
    --extra-cflags=-DSTM32_UART_NO_BAUD_DELAY \
    --extra-cflags=-DSTM32_UART_ENABLE_OVERRUN \
    --disable-gtk
make

Steps

  • 00-Semihosting
    • Minimal semihosted ARM Cortex-M "Hello World"
  • 00-HelloWorld
    • Enable STM32 USART to print trivial greetings
  • 01-HelloWorld
    • Almost identical to the previous one but improved startup routines
  • 02-ContextSwitch-1
    • Basic switch between user and kernel mode
  • 03-ContextSwitch-2
    • system call is introduced as an effective method to return to kernel
  • 04-Multitasking
    • Two user tasks are interatively switching
  • 05-TimerInterrupt
    • Enable SysTick for future scheduler implementation
  • 06-Preemptive
    • Basic preemptive scheduling
  • 07-Threads
    • Implement user-level threads
  • 08-CMSIS
    • Illustrate hardware abstraction layer (HAL) by introducing CMSIS
    • Both emulator (based on stm32-p103) and real device (STM32F429i discovery) are supported.

Building and Verification

  • Changes the current working directory to the specified one and then
make
make qemu

Guide to Hacking 08-CMSIS

08-CMSIS implements preemptive round-robin scheduling with user-level threads for STM32F429i-Discovery (real device) and STM32-P103 (qemu).

Get the dependencies:

git submodule init
git submodule update

Install additional utilities:

Quick Start / Support Devices:

  • STM32F429i-Discovery(physical devices)
    • Details in Chinese by NCKU
    • STM32F429i-Discovery uses USART1(Tx=PA9,Rx=PA10,baud rate=115200) as default serial port here.
      • You would need a terminal emulator, such as screen
        • Installation on Ubuntu / Debian based systems: sudo apt-get install screen
        • Then, attach the device file where a serial to USB converter is attached: screen /dev/ttyUSB0 115200 8n1
        • Once you want to quit screen, press: Ctrl-a then k

Available commands:

Overall

  • make all
    • Build all target's bin,elf,objdump files in the "release" directory.
    • NOTE: make doe NOT equal to make all here because Makefile uses eval for targets.
  • make clean
    • Remove the entire "release" directory.

STM32-P103(QEMU)

  • make p103 or make target PLAT=p103
    • Build "p103.bin"
  • make qemu
    • Build "p103.bin" and run QEMU automatically.
  • make qemu_GDBstub
    • Build "p103.bin" and run QEMU with GDB stub and wait for remote GDB automatically.
  • make qemu_GDBconnect
    • Open remote GDB to connect to the QEMU GDB stub with port:1234 (the default port).

STM32F429i-Discovery(physical device)

  • make f429disco or make target PLAT=f429disco
    • Build "f429disco.bin"
  • make st-flash
    • Build "f429disco.bin" and flash the binary into STM32F429 with st-link.
  • make st-erase
    • Sometimes, STM32F429i-Discovery will not be able to flash new binary file, then you will need to erase flash memory with st-link.
    • Erase the entire flash on STM32F429.
  • make gdb_ST-UTIL
    • Using GDB with ST-LINK on STM32F429.
    • Remember to open another terminal,and type "st-util" to open "STLINK GDB Server"

Directory Tree:

  • core
    • Hardware independent source and header files.
  • platform
    • Hardware dependent source and header files.
  • cmsis
    • With cmsis,porting would be much easier!
  • release
    • This directory will be created after "Target" in Makefile is called.
    • Containing the elf,bin,objdump files in corresponding directory.
    • make clean will remove the entire directory,do not put personal files inside it!

Porting Guide:

You should know what CMSIS is and why it saves us a lot of efforts.

cmsis is a submodule from TibaChang/cmsis, maintained by Jia-Rung Chang.

The full project can be divided into two layer:

  • hardware-dependent part (HAL)
    • "platform" directory
  • hardware-indepentent part
    • "core" directory

Steps to launch the kernel on real devices:

STEP 1

Select a target name for your device, such as f429disco.

In this guide, we assume its name is example_device with vendor name "f429disco".

Create example_device directory in "platform" and f429disco directory in "cmsis" directory.

Create "include" and "src" directory in platform/example_device/

STEP 2

Introducing your CMSIS for your target, where it should be in the mbed repo.

For example, the CMSIS for STM32F429i-discovery could be found here.

We only need ".h" files, do not copy any ".c" files.

Put the header files into cmsis/f429discoexample_device.

cmsis is a submodule in this project, maintianed by Tiba Chang.

NOTE: You may encounter some error messages during building binary for your target. You need to solve it mannually. Usually, some files may be missing caused by some specific "define". You could just comment out that definition to resolve this problem.

STEP 3

This is the most difficult part.

You have to implement the files in platform/example_device/include/ and platform/example_device/src/.

According to different device vendor(such as STMicroelectronics, NXP, etc), the implementation is very different.

Please look into the current example:f429disco,and you will figure it out!

The function interface must be as same as the function interface in "platform/STM32F429/inc/" due to this is HAL for the entire project.

STEP 4

Add your target rules into Makefile.

Please look the example f429disco in the Makefile.

Most of the rules are reusable,so all you need is copy-n-paste, modifying the variable/target name and knowing what gcc arguments suit your target!

  • rules.mk
    • You should NOT modify this file!  - All of the rules are encapsulated into macro, used in Makefile.
  • Makefile:
    • If your device vendor name does not exist, create new variable and assign a name to it!
      • E.g.STM32 := STM32
    • Add your device name
      • E.g.STM32F429_DEVICE := f429disco
    • Check your device CPU type(Cortex-M3/4)
      • In target_using_CM4_list
    • Will you use CMSIS?
      • If NOT,add to target_NOT_using_CMSIS_list
    • Use the predefined macro to produce the corresponding directory and device specific variable(device name,vendor name)
      • E.g. $(eval $(call eval_all_variable,$(STM32F429_DEVICE),$(STM32)))
      • The vendor name is used in the cmsis directory name. They must be associated with each other.
    • Use the predefined macro to produce the corresponding GCC commands
      • E.g.: $(eval $(call eval_build_command,$(STM32F429_DEVICE)))
      • This will derive lots of variables that you don't see in the Makefile.
    • Add your device name to all
      • In the specific form:$($(YOUR_DEVICE_NAME)_TARGET) , this variable will be automatic derived by rules.mk
      • E.g.: $($(STM32F429_DEVICE)_TARGET)

STEP 5

Congratulations!

Now, you can try the "Available commands" in this README.

Licensing

mini-arm-os is freely redistributable under the two-clause BSD License. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Reference

More Repositories

1

amacc

Small C Compiler generating ELF executable Arm architecture, supporting JIT execution
C
997
star
2

facebooc

Yet another Facebook clone written in C
C
553
star
3

MazuCC

A minimalist C compiler with x86_64 code generation
C
502
star
4

talks

schedule and materials about my presentations
338
star
5

nstack

Userspace TCP/IP stack for Linux
C
314
star
6

unix-v1

Restoration of 1st Edition UNIX kernel sources from Bell Laboratories
C
193
star
7

kernel-in-kernel

Develop your own OS kernel by reusing Linux infrastructure
C
171
star
8

min-dl

minimal dynamic linker implementation for ELF, supporting x86_64 and Arm/Aarch64
C
162
star
9

tetris

A text-mode tetris game
C
144
star
10

xv6-x86_64

re-implementation of UNIX v6 in ANSI C for x86_64 SMP
C
143
star
11

stm32f429-linux-builder

create a uClinux distribution for STM32f429 Discovery board
Makefile
133
star
12

full-stack-hello

minimal instruction set and assembler/compiler for "Hello World" execution
C
114
star
13

mazu-editor

a minimalist text editor with syntax highlight, copy/paste, and search
C
108
star
14

codezero

Codezero Microkernel
C
102
star
15

cregex

A small implementation of regular expression matching engine in C
C
80
star
16

tlsf-bsd

Two Level Segregated Fit (TLSF) memory allocator implementation, BSD License
C
74
star
17

simple-dvm

A simplified educational Dalvik virtual machine implementation
C
58
star
18

armv8-hello

Hello World for bare metal ARMv8 using QEMU
Makefile
51
star
19

lsd_slam

LSD-SLAM
C++
48
star
20

tinygl

TinyGL: a Small, Free and Fast Subset of OpenGL
C
44
star
21

ogc

A minimal mark-and-sweep garbage collector
C
43
star
22

x-compressor

A minimalist lossless data compressor
C
42
star
23

jit-construct

JIT compiler from scratch, derived from Nick Desaulniers' great work
Lua
37
star
24

svgirl

SVG Instant Rendering Library with focus on embedded systems
C
36
star
25

ttt

An implementation of tic-tac-toe in C, featuring an AI powered by the negamax algorithm
C
30
star
26

rv32jit

JIT-accelerated RISC-V instruction set simulator
C++
30
star
27

stm32f429-r3d

small software 3D rendering program on STM32F429-Discovery
C
26
star
28

kvm-user-x86

A simple userspace program to interact with Linux KVM
C
23
star
29

uThreads

A concurrent library based on cooperative scheduling of user-level threads(fibers) implemented in C++
C++
22
star
30

tvision

GCC/Linux port of Turbo Vision
C++
21
star
31

hungry-birds

classical example of concurrent producer/consumer problem
C
20
star
32

nalloc

structure aware memory allocator
C
19
star
33

stm32f429-lcd-demo

Simple STM32F429 Discovery LCD demo program using emWin library
C
18
star
34

jamvm

JamVM 2 + OpenJDK
C
18
star
35

littlefs-fuse

A FUSE wrapper that puts the littlefs in user-space
C
17
star
36

linsched

Restoration of The Linux Scheduler Simulator (LinSched)
C
16
star
37

stm32f429-demos

Collection of demo program for STM32F429 Discovery
Makefile
15
star
38

auto-tetris

Play Tetris game automatically!
C
15
star
39

skin-deep

Generate faces with smoother skin
C
14
star
40

matrix_oo

Object-oriented matrix implementation in C99
C
14
star
41

tic-tac-toe

An implementation of classical tic-tac-toe game for terminal I/O
C
12
star
42

dummy-driver

dummy Linux kernel module for education purpose
C
11
star
43

Taunix

Realtime operating system kernel for TI TMS320F24x DSP
C
11
star
44

MathEX

An embedded mathematical expression evaluator in C99
C
10
star
45

fizzbuzz

Implement Fizzbuzz without loop-internal conditionals, or arithmetic operators.
C
10
star
46

cjit

A tiny JIT compiler based on MIR
C++
9
star
47

anrmalloc

A new embedded-friendly memory allocator
C
9
star
48

arith_register

Use ELF linker set to construct lists of arithmetic implementations automatically
C
8
star
49

membroker

Memory Broker is a library that helps balance memory load between processes in user space using IPC
C
6
star
50

scalable-font-editor

A scalable font editor, which produces the fonts for embedded environments
C
5
star
51

bubble-sort-arm

Bubble sort in ARM assembly (incomplete)
Assembly
4
star
52

doxygen-oop-in-c

C
4
star
53

iota-whitepaper

IOTA whitepaper
TeX
4
star
54

micronaut-from-scratch

Ahead-of-Time compilation with Micronaut and GraalVM
Java
1
star
55

git-hook-tests

Tests for Git Hooks
Shell
1
star
56

ci-test-public

(TMP) A repository for testing CI pipeline
1
star
57

muxleq

16-bit virtual machine with a two-instruction set CPU capable of running Forth
Forth
1
star