Compact OS for ARM processors
“It seems that perfection is achieved not when there is nothing more to add, but when there is nothing more to remove."
(Antoine de Saint-Exupery)

On the topic of studying the programming of embedded systems, real-time operating systems, assembler and C, let me introduce a very simple StartOS operating system.
Purpose:
- if you need to create a device that starts working 1-2 seconds after turning on the power and is able to respond to signals from the outside world within microseconds;
- for the quick creation of facility management systems with data output to the Internet;
- development of ideas, algorithms, prototyping devices;
- gaining experience in programming embedded systems in C and Assembler;
- getting full access to the hardware of a computer device, for example, for developing self-modifying programs.
Some properties of the system:
Ready time after power-up: <1 sec.
Volume of the binary program code: <40 kB.
The system takes up a small amount in the upper addresses of RAM, providing the user with standard loading of programs in the lower addresses of RAM. Autostart of the user program is present; if the system detects the START.BIN file on the memory card, it starts automatically.
The main functions of the system:
Initialization of SoC (System on Chip, systems on a chip) and other external devices. Loading user programs into memory and providing them with an interface to system functions:
- work with LCD in text and graphic modes (displaying text, pixels, lines, BMP images, saving / restoring a screen area ...);
- Enter the coordinates of the X, Y pen from the touch screen;
- work with real time clock (RTC);
- reading data from analog-to-digital converters (ADC);
- reading data from digital ports;
- read / write characters and lines in the COM port;
- output to pulse-width modulators (PWM, PWM) and piezodynamics;
- input / output of Ethernet packets using the built-in controller;
- reading and writing files;
- server-client for the Internet;
- work with a video camera.
The system is implemented on the boards of Samsung or FriendlyARM developers with Samsung processors. There is full documentation for these processors and boards.
So, a little more clearly. It’s better to see once, so the link to the video:
The system is a bit more complicated for ARM Cortex-A8:
And, of course, the code “Hello, World!” (With a creeping line also):
char txt [ ]={"Hello"};
void Main(void)
{ int i;
for ( i = 134; i > 8; --i )
{
// X Y String
Print_String ( i, 150, "Hello, World!");
Print_String ( i, 170, txt);
Delay (20); // Delay 20 mS
}
Exit (); // Exit to OS
}
This is in Assembler:
; Нужен только один файл, Hello.s. Двоичный код занимает ровно 100 Байт (!)
; номера системных вызовов взяты из файла StartOS.c
_Exit EQU 7 ; SysTrap _Exit
_Delay EQU 10 ; SysTrap _Delay
_Print_String EQU 122 ; SysTrap _Print_String
PRESERVE8 ; выравнивание до 8 Байтов
AREA INIT, CODE, READONLY ; инициал. секция, содержит код
ENTRY ; точка входа программы
;______ нужно для работы ОС __________
LDR r0, =0x33ffff08 ; просьба не редактировать
LDR r1, [r0,#0xE8] ;
STR r1, [r0] ;
; если Вам нужны прерывания, включите след. 4 строки
; MRS r0,cpsr
; BIC r0,r0,#0xDF
; ORR r1,r0,#0x13
; MSR cpsr_cxsf,r1
;___ Программа пользователя начинается здесь
; напечатаем строки текста...
; только-то и нужно поместить параметры в регистры и вызвать системные вызовы
;---- первый способ
LDR r2, text1 ; загружаем адрес текста 1 в регистр r2
MOV r1,#30 ; помещаем Y строки на экране в r1
MOV r0,#25 ; помщаем X на экране в r0
SWI _Print_String ; вызываем систему (Print_String(25,30,text1))
;---- Другой способ ----
ADR r2, text2 ; помещаем адрес строки text 2 в r2
MOV r1,#70 ; Y в r1
MOV r0,#25 ; X вr0
SWI _Print_String ; прерывание (Print_String(25,70,"Hello, ARM Assembler!"))
LDR r0, millis ; загружаем адрес ячейки с числом 5000 в r0
; в случае малых задержек (скажем, 500ms) можно так: MOV r0,#500
SWI _Delay ; вызов (Delay 5s)
SWI _Exit ; вызов выхода из программы в ОС, параметры не нужны
text1 DCD txt ; содержит адрес "Hello"
text2 DCB "Hello, ARM Assembler!",0 ; байты с нулем на конце
DCB 0,0 ; простое выравнивание до 32-бит адреса (*4 байта)
millis DCD 5000 ; равно 5000 мС или 5 секунд
DCB 0,0 ; выравнивание
txt DCB "Hello",0 ; содержит буквы H, e, l, l, o и 0
END ; и это - всё!
The background to the creation of the system is as follows. The author is aware that writing "home" operating systems is a very responsible, risky business (and does not bode down to creators anything but criticism). But, as they say, life made. So how did this come about?
It was like this: a friendlyARM Mini2440 development board was found, which was very cheap and with a large selection of peripherals. After using Atmel AVR controllers in the applicator of self-adhesive labels, I wanted to continue the development of the latter.
At that time (2010), the Mini2440 board cost $ 80, about 2,400 rubles, which was comparable to the cost of sensors in the applicator. Mini2440 was demonstrated to the head of one company, who approved its application and assured that “if it is successful in its programming, we will place orders”. Success in programming meant using the device in real time, when the signals from the sensors were processed in microseconds, and did not take long to wait. After 2 months, the program, wired into NAND memory, successfully controlled the stepper motor and loaded 1 second after turning on the power. But here, as it happens, the head already fell into a stupor and just shut up. While he was silent, time passed, and the author decided to use the moment for some development.
In order not to insert the initialization code into the project each time, it was decided to do this once and for all, and load the application programs into the memory from the SD card directly into the memory and run from there.
There is an approach, for example, in ST732 ARM7 controllers, when a user program is compiled with a proprietary library for working with external devices. At the same time, the company does not disclose its proprietary source code, the user program calls the proprietary routines at addresses in memory.
At the same time, the author knew the "insides" of operating systems, such as RT-11 from DEC, we used on Electronics-60, DVK-2 ... 4 and others. The BIOS of IBM PC AT, MS DOS, Palm OS were also well studied. In all these systems, the classical approach was used - the use of software interrupts. That is, the OS is located in the upper addresses of the memory, and the user program - from the beginning of the memory and called the operating system subprograms, passing the program interrupt number in the command, which actually leads to the interrupt.
Thus, the developed system employs a software interrupt mechanism through the SWI (SVC) command. The system code is located in external addresses, and user programs are loaded directly at the beginning of the memory and run. We will not compare with existing systems, it is enough to say that the system turned out with a minimum volume, the highest possible speed and "hard" real time. We can always know very precisely at what point in time which command is being executed and what is happening.
The name of the system was conceived as an entry-level system, starting. After searching on Google, the choice fell on StartOS and this name was registered (it is sad that some time later a certain Linux clone in some part of the planet was also renamed StartOS).
At the request of users, TCP IP Stack was added to the system and the Server and Client were made. And also added a program for working with a video camera. By the way, after applying power to the board, two seconds later a picture from the camera already appears on the screen.
Examples of programs are presented for working with almost all external devices mounted on the board. You can create programs in the ADS1.2 (Metrowerks CodeWarrior), IAR, Keil, and other environments.
Documentation, examples, and more can be found here and here .
Since the FriendlyARM Mini2440 development board is already outdated (although it is suitable for many projects), the author ported the system to a more modern Mini210s board. By the way, many users have used StartOS on Samsung boards and successfully.
With respect to the community,
Anatoly Besplemennov,
PS engineer : Please take real-time systems seriously, for example, if the system controlling the train “hangs”, the watchdog timer works, it will restart and will work again after 1 second. Not for nothing, the Curiosity rover plows the expanses of Mars under the control of Micrium's uCOS RT system.