Skip to content

About

bedrock[RTOS] - A nanokernel real-time operating system.

Topics

Resources

Code of conduct

Contributing

Stars

3 stars

Watchers

0 watching

Forks

Repository files navigation

bedrock[RTOS]

CI License: GPL-3.0 with runtime exception

About

bedrock[RTOS] is a tickless nanokernel RTOS in C11 with no dynamic allocation. It is for microcontroller firmware. Supported targets: ARM Cortex-M3 (QEMU LM3S6965, STM32F103C8 Blue Pill), ARM Cortex-M4 (STM32F4-Discovery), ARM Cortex-M0+ (RP2040, Raspberry Pi Pico), RISC-V RV32 (QEMU virt) and 32-bit x86 (QEMU).

Dependencies

  • arm-none-eabi-gcc for Cortex-M3, Cortex-M4, STM32F103 and RP2040
  • riscv64-elf-gcc for RISC-V
  • chorus 1.1.0 or newer
  • gcc with 32-bit support (gcc-multilib on Debian and Ubuntu) for x86
  • avr-gcc with avr-libc for AVR
  • qemu-system-arm, qemu-system-riscv32, qemu-system-i386 and qemu-system-avr to run on QEMU
  • gcc for host tests and for the RP2040 image tools
  • Renode 1.16.1, only to run STM32F103 and RP2040 tests without hardware, plus Renode_RP2040 for RP2040
  • kconfig-tools and zig, only for Kconfig

Arch Linux:

sudo pacman -S arm-none-eabi-gcc qemu-system-arm riscv64-elf-gcc qemu-system-riscv

Ubuntu (Cortex-M only):

sudo apt install gcc-arm-none-eabi qemu-system-arm

Chorus:

sudo curl -L -o /usr/local/bin/chorus https://github.com/z3nnix/chorus/releases/download/1.1.0/chorus.bin
sudo chmod +x /usr/local/bin/chorus

Build

chorus

The result is bedrock_example.elf and the libbedrock_kernel.a, libbedrock_hal.a, libbedrock_lib.a libraries for Cortex-M.

RISC-V:

chorus riscv32

The result is bedrock_example_riscv32.elf, the test_*_riscv32.elf tests and the libbedrock_*_riscv32.a libraries.

RP2040:

chorus rp2040

The result is bedrock_example_rp2040.uf2, bedrock_example_rp2040.elf, the test_*_rp2040.elf tests and the libbedrock_*_rp2040.a libraries.

STM32F103C8:

chorus stm32f103

The result is bedrock_example_stm32f103.bin, bedrock_example_stm32f103.elf and the test_*_stm32f103.elf tests.

STM32F4-Discovery:

chorus stm32f4

The result is bedrock_example_f4.elf and the test_*_f4.elf tests.

x86:

chorus x86

The result is bedrock_example_x86.elf and the test_*_x86.elf tests, 32-bit multiboot images.

AVR (ATmega328P, Arduino Uno), see the AVR guide:

chorus avr

The result is the test_*_avr.elf tests. There is no example for the AVR, the RAM is 2 KiB.

Clean:

chorus clean

Running on QEMU

Cortex-M (LM3S6965):

chorus run

RISC-V (virt):

chorus run-riscv32

x86:

chorus run-x86

STM32F4 (Olimex STM32-H405, the same SoC family as the Discovery):

chorus run-stm32f4

Exit QEMU with Ctrl+A, then X.

Running on RP2040

Hold BOOTSEL, connect the Pico over USB and copy bedrock_example_rp2040.uf2 to the RPI-RP2 drive. Output goes to UART0: TX on GP0, RX on GP1, 115200 8N1. The port has been tested in Renode only, not on hardware yet.

In Renode, with Renode_RP2040 cloned to <path>:

renode --disable-gui --console -e '$rp2040=@<path>; $fw=@'"$PWD"'/test_scheduler_rp2040.elf; $out=@/tmp/uart.txt; include @'"$PWD"'/boards/rpi-pico/renode.resc; emulation RunFor "2"; quit'
cat /tmp/uart.txt

Running on STM32F103C8

Flash bedrock_example_stm32f103.bin at 0x08000000, for example with st-flash write bedrock_example_stm32f103.bin 0x08000000. The board runs at 72 MHz from an 8 MHz crystal. Output goes to USART1: TX on PA9, RX on PA10, 115200 8N1. The port has been tested in Renode only, not on hardware yet.

In Renode:

renode --disable-gui --console -e '$fw=@'"$PWD"'/test_scheduler_stm32f103.elf; $out=@/tmp/uart.txt; include @'"$PWD"'/boards/stm32f103c8-bluepill/renode.resc; emulation RunFor "2"; quit'
cat /tmp/uart.txt

Running on STM32F4-Discovery

Flash bedrock_example_f4.elf at 0x08000000, for example with st-flash write after arm-none-eabi-objcopy -O binary. The core runs from the 16 MHz internal oscillator, the PLL is not set up. Output goes to USART1: TX on PA9, RX on PA10, 115200 8N1. The port has been tested in QEMU and Renode only, not on hardware yet.

The Renode model clocks SysTick at 72 MHz while the board runs at 16 MHz, so the firmware clock runs 4.5 times faster than Renode time. Send console input in the first 0.4 simulated seconds, as the CI does at 0.2.

QEMU (olimex-stm32-h405) runs the example and every test except test_pwm, which stalls in the QEMU timer model during the capture case. CI runs all tests in Renode.

In Renode:

renode --disable-gui --console -e '$fw=@'"$PWD"'/test_scheduler_f4.elf; $out=@/tmp/uart.txt; include @'"$PWD"'/boards/stm32f4-discovery/renode.resc; emulation RunFor "2"; quit'
cat /tmp/uart.txt

Tests

The tests run on Linux x86-64 with a mock HAL:

chorus host
./test_scheduler_host

The binaries are test_task_delete_host, test_scheduler_host, test_semaphore_host, test_mutex_host, test_mqueue_host, test_sleep_list_host, test_pool_host, test_uart_rx_host, test_shell_host, test_console_host, test_task_info_host and test_shell_cmds_host, test_device_host, test_gpio_host, test_spi_host, test_i2c_host, test_pwm_host, test_fs_host, test_shell_fs_host, test_littlefs_host, test_fatfs_host, test_net_host and test_audit_host. Each one prints PASS or FAIL per case and === All Tests Complete === at the end.

test_uart_rx and test_shell wait for the line bedrock on the console: printf 'bedrock\n' | ./test_uart_rx_host, the same pipe into qemu-system-*, or sysbus.uart0 WriteLine "bedrock" (sysbus.usart1 on STM32F103) in Renode after emulation RunFor "0.5".

The same tests under QEMU: chorus test-scheduler, chorus test-semaphore and so on for Cortex-M, chorus test-scheduler-riscv32 and so on for RISC-V. The x86 tests: qemu-system-i386 -kernel test_scheduler_x86.elf -nographic. RP2040, STM32F103 and STM32F4 tests run in Renode, see above.

Configuration

Defaults are in include/bedrock/br_config.h. To use Kconfig instead, put kconfig-tools in 3rd/tools/kconfig and run:

chorus build-tools
chorus defconfig
chorus menuconfig

For RISC-V use chorus defconfig-riscv32, for RP2040 chorus defconfig-rp2040, for STM32F103 chorus defconfig-stm32f103 instead of chorus defconfig.

This generates include/generated/autoconf.h, which takes precedence over the defaults.

Acknowledgments

Documentation

License

/kernel, /arch, /boards, /drivers, /include, /lib, /ports (without upstream) and /examples are under GPL-3.0 with the bedrock[RTOS] runtime exception, see LICENSE.md. Application code linked with the kernel can use any license. Changes to bedrock[RTOS] itself stay under GPL-3.0.

/ports/*/upstream keeps the license of the library it holds, see the license file in each directory.

/docs is under CC BY-SA 4.0, see LICENSE-CC-BY-SA-4.0.md.

About

bedrock[RTOS] - A nanokernel real-time operating system.

Topics

Resources

Code of conduct

Contributing

Stars

3 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages