Let's take a look at what makes 'main()' feel so cozy and welcoming - what has to happen to have variables initialized, objects constructed and stacks a-stackin?
by
Liquid Soulder
January 2, 2020 2:00 pm UTC
2
Favorited
Favorite
2
Artemis, my close friend, has urged me to learn much more about the bare-metal details of getting code running and supporting the familiar features that we often take for granted in C++. It is actually a very interesting topic and a beneficial thing to understand when working on embedded systems. Sadly, however, it is a fairly challenging topic to find information about on the internet - and what you can find is daunting, to say the least.
Since we are not fans of reinventing the wheel we've developed some examples you can follow along with using an Artemis board. After doing so you will know:
- How the linker organizes compiled code
- How startup code initializes variables
- How the stack and heap are managed
- How global/static object constructors are conveniently called before you get to
main()
Check out the examples, explanation and instructions on the embedded-startup exploration repo!
Here are some useful tools to have along the way:
Artemis Boards
In stock
DEV-15443
The RedBoard Artemis Nano is a miniature extremely versatile implementation of the Artemis module.
6
Only 1 left!
DEV-15444
The RedBoard Artemis takes the incredibly powerful Artemis module from SparkFun and wraps it up in an easy to use and familia…
10
Out of stock
KIT-17071
This Kit includes the SparkFun Artemis DK board as well as the accessories (Himax camera & USB-C cable) needed to get started…
1
In stock
KIT-20684
The Air Quality Monitoring version of the OpenLog Data Collector Kit with Machinechat allows you to display your data with th…
Debuggers
In stock
WRL-17354
SparkFun has teamed up with CircuitDojo to bring you the nRF9160 Thing Plus, featuring the powerful Nordic nRF9160 in a Feath…
33 available
DEV-17588
The BGM220 Explorer Kit is an ultra-low cost, small form factor development and evaluation platform for the BGM220P Wireless …
1
27 available
PGM-24078
The J-Link EDU Mini is a stripped-down, budget-friendly model of the J-Link debug probe created for educational use.
Accessories
In stock
DEV-15096
This SparkFun Serial Basic Breakout is an easy-to-use USB-to-Serial adapter based on the CH340G and takes advantage of the ha…
9
Retired
CAB-15092
USB C is fantastic. But until we have converted all our hubs, chargers, and ports over to USB C this is the cable you're goin…
Retired
I don't have time at the moment to go through it in great detail, but it looks pretty good! BTW, it's sort of a "walk down memory lane" (hmm... there's an unintended pun there) as it takes me back to the days when we had to use a computer's "front panel" switches to "toggle" the initial program into it, e.g., to get it to load the assembler, linker, or one's object code off either mag tape or paper tape! Back in those days we had to allocate stack space, heap, program space, arrange the interrupt vectors, etc., by hand for every program.
One very minor nit to pick (one letter!): Under "How Computers Work (quickly)", in a point numbered 3, it says "volatile memory pace" -- I think it should be "space", not "pace" (don't have time at the moment to do a correction in the Git stuff...
Wow! As you can probably tell my perspective is very different - coming from the side where I've never had to think about such things until just recently. The barrier to entry today is so wonderfully low - I can get my brother to learn the basics as long as he has a web browser! Thanks for the story. (And thanks for the typo catch - I'll go ahead and fix it)