## How does an embedded system OS work? LPC3250 ARM9

Started by 2 years ago6 replieslatest reply 2 years ago116 views

Hi,

I am new to the embedded system world and can't figure out how some devices are bare metal (no OS) and some have an operating system. I understand that a bare metal system is made from scratch but devices running on an operating system use the OS prebuilt code as functions in their projects.

I am currently working on a bare metal  LPC3250 ARM9 project on Keil v4. My current goal is to create a secure SMTP function. I am trying to import mbedTLS but it requires an OS to run or I would have to create my own functions for networking and entropy.

My questions are:

1. How do embedded systems get the operating systems?

2. What happens when you download the code to your device, do only the project required parts used from the OS go to the board?

3. How can I use an OS with my bare metal project?

4. Lets say I wanted to use only some functions, like the networking and entropy functions, from the Windows API, can I find the source code from the windows OS and import it to my project?

5. If an OS is just C code, can I just import that code into my C embedded project?

Thanks.

[ - ]

A bare metal app is basically an init followed by a loop. The OS version supplies the ability to have several processes running at "the same time". (in reality, the processes should actually cooperate with each other, or at least not stomp on its peers.) (And I am going to assume an RTOS, although Linux or a light-weight non-RTOS will work for many applications).

The basic choice of command loop vs RTOS come down to how much stuff you need to do, timing constraints, and how independent your tasks are.

My questions are:

1. How do embedded systems get the operating systems?

Magic fairies.

Just kidding - your question is a bit ambiguous. Depends on what you mean by "get". The OS is just another set of code that gets loaded like any other code. Now, there are a number of RTOS's out there, from pretty heavyweight (VxWorks, Ubuntu & other Linux varients) to fairly light-weight (uC/OS, FreeRTOS). You can run FreeRTOS on an Arduino (Atmel) according to a brief google search "freertos tutorial arduino".

If your goal is to learn about RTOS's, Micrium has good books on the inner workings of uC/OS. And - you can download the code and use it for free to learn. He only wants  when you use it in a commercial product (which is quite reasonable). uC/OS happens to be my favorite. Clean code. Good documentation. If I ever taught an RTOS class, I would use his book && code (after chatting with him).

If that is your goal, possibly get a NetBurner board && pay for the source. (Actually, NetBurner may have changed a bit since I last used them, although you can get a legacy dev board. Stay tuned... I have a nerd-level call into their tech support.)

(Full disclosure: I am not, nor ever have been a Netburner employee or contractor, just user. I liked their stuff from 20+ years ago. I have not used them since about 2005.)

Another good option is FreeRTOS. Google "freertos tutorial" for good info. Source is free and open. Book: https://www.freertos.org/Documentation/RTOS_book.html

2. What happens when you download the code to your device, do only the project required parts used from the OS go to the board?

Generally, you need to trim down the code yourself. If there is a call to a subsystem, it will get sucked in. But many RTOS packages are modular. Look at Micrium for an example. You should always look at the linker map to make sure something has not snuck in - you would be surprised what can get sucked in.

3. How can I use an OS with my bare metal project?

Generally speaking, you are either bare iron or an OS. Not sure how to give a better answer.

4. Lets say I wanted to use only some functions, like the networking and entropy functions, from the Windows API, can I find the source code from the windows OS and import it to my project?

Hmm... Not sure how you can get the Windows code. Also, it might be somewhat bound with the Windows OS.

Look again at Micruim && FreeRTOS. They are modular.

Netburner specifically focuses on networking.

5. If an OS is just C code, can I just import that code into my C embedded project?

Short answer, yes. Longer answer, might take a bit of work, depending on whatever cruft rears its ugly head. Depends on the port to the specific MPU, to handle the mutex/timers/etc for a given micro.

FreeRTOS should have a port to your ARM 9.

You are really importing your code into the RTOS, not the other way around.

Thanks.

One of the decisions an embedded engineer must make is when to do bare iron vs RTOS. You get a lot of power with an RTOS, at the cost of some-to-much complexity. I have done quite complex systems with bare iron. A fundamental understanding of state machines/finite automata is critical. (I prefer the circles & arrows form myself.) This is what makes a loop work properly and predictably.

Success to you!

[ - ]

It seems that you are trying to do too much in the very first step. You are moving from bare-metal to operating system and you immediately want to deal with networking, SMTP and mbedTLS.

I would recommend to start a bit slower and first try to understand what an embedded (real-time) operating system (RTOS) is and how it relates to bare-metal architecture. To this end, I would recommend the free YouTube video course, which in the last 7 lessons explains the RTOS:

[ - ]

I truly appreciate what you are asking.

I know you are on a journey, the same journey I was on a few years ago.

I was struggling with how the USB code got executed on a STM32 F4 Discovery, running FreeRTOS. I couldn't figure out how the USB code got started and how it got executed and no matter who I asked and where I looked, I never ever, got the answer I needed.

Then, one day, it clicked and the whole picture started to come together.

FWIW, in main.c, the USB driver was started and in there was construct to start a new Thread and from then on FreeRTOS called the USB code on a regular basis as part of the OS scheduler. It was easy and given my very weak knowledge at the time, extremely hard to recognize what was going on.

OK, so where are you at now?

mr_bandit has given you a great response, the piece of the puzzle that I had been looking for oh so very long ago, well done and thank you mr_bandit.

FWIW, I prefer to work with ST Microelectronics STM32 MCU's, really low costs development modules, an STM32 F4 Discovery board can be had for around \$50.00 CAD and a complete and free development environment that is every bit as good or better than all the others, they have licensed your free use of various SEGGER IP (Intellectual Property), DSP Concepts, and provide so much free working source code as building blocks you can drown with what they give you.

Their documentation is truly magnificent and their support staff work hard to make your successful. They will not hold your hand, but the community will work with you to help you over the humps.

Cheers

[ - ]

some years ago, I asked a friend how he woud define an embedded system.  The answer was "any system where the user doesn't have access to a reset button or power switch"

[ - ]