Arduino "bare metal" programming

Hey all
Been wondering - how do I start programming "bare metal" for arduino, without using premade drivers, I want to look at datasheet and figure out what registers I need to modify in order to make the LED light up. Any good starting guide about how to begin ?
Sorry if its a stupid question :slight_smile:
Thanks for any help

1 Like

For a good start, look at the datasheet :wink: There's all you need to know. Or just google a AVR tutorial.

Masochism can be a lot of fun. Why use the Arduino and not the bare micro Controller?

Weedpharma

Unlike things like Linux boxes their is no operating system. That is what bare metal means, without operating system.

Where as this is an advantage on a Linux box there is no practical difference in performance on an Arduino. If you must then do not call any function you have not written yourself that is all you need to do.

Eeek! Assembler. :o
BTDT 25 years ago, but why bother when C/C++ is so versatile, easy and so quick to write in?
Is there something you want to do that can't be done in C/C++?

Henry_Best:
Eeek! Assembler. :o
BTDT 25 years ago, but why bother when C/C++ is so versatile, easy and so quick to write in?
Is there something you want to do that can't be done in C/C++?

I do intend to write in C/C++, the arduino drivers are written in C if im not mistaken :slight_smile:

Thanks everyone for the tips i'll do some research and get into it more !

Might even buy a single microcontroller for an even "bare-er" board

Henry_Best:
Is there something you want to do that can't be done in C/C++?

C'mon guys, it's called learning. I'm really surprised you don't get it.

I built a small IR receiver to operate an electromagnet on an Attiny 45 without any PCB because I did not have space for it (and I could not / was not prepared to try to / use surface-mount parts). But I programmed it with C/C++.

Conversely you can certainly program an Arduino Uno using assembler if that is what you want to explore. My first exposure to programming was assembler (and punched cards) on an IBM 360.

Depends what "bare metal" means.

...R

Here is the [u]Instruction set for the chip[/u].

Every microprocessor/microcontroller chip (or family) has a unique set of instructions which are binary numbers. We usually call them "codes" instead of numbers, and when humans read & write them we use hexadecimal instead of binary because hex is easier to read & write. And you can convert between hex & binary in your head, whereas you cannot convert large numbers between binary & decimal in your head.

For each binary machine language instruction, there is a mnemonic. The mnemonics are called Assembly Language Instructions. The programmer normally writes the program in Assembly Language and a tool called an Assembler converts the assembly language to machine language binary codes (analogous to a compiler for C/C, basic, or any high-level programming language.)

In the early-early computer days, the Assembler was a human. Since there is a one-to-one correspondence between the assembly language command and the machine instruction, it's not hard to convert from Assembly language to machine language, but it's very tedious.

I haven't searched, but I'm sure you can download an Assembler from Atmel.

don't forget speed as a reason.

The Arduino delayMicroseconds() function creates the shortest delay possible from within the Arduino language. The shortest delay possible is about 2 us (microseconds).
For shorter delays use assembly language call 'nop' (no operation). Each 'nop' statement executes in one machine cycle (at 16 MHz) yielding a 62.5 ns (nanosecond) delay.

more here : Arduino Playground - AVR

Robin2:
Depends what "bare metal" means.

To me 'bare metal' is more about how you address the hardware than what language you use. Though to get such low level access (no drivers) to the hardware invariably meant resorting to assembler language for me.

Riva:
To me 'bare metal' is more about how you address the hardware than what language you use. Though to get such low level access (no drivers) to the hardware invariably meant resorting to assembler language for me.

the OP did help us understand what he wanted :

how do I start programming "bare metal" for arduino, without using premade drivers,

we do know that when you add safety nets, like the IDE has, you loose speed.
we think digitalWrite(led,LOW);
the IED looks at the element LED, say pin 13
Arduino Reference - Arduino Reference :
Each port is controlled by three registers, which are also defined variables in the arduino language. The DDR register, determines whether the pin is an INPUT or OUTPUT. The PORT register controls whether the pin is HIGH or LOW, and the PIN register reads the state of INPUT pins set to input with pinMode().
so, the IDE knows what you THINK you want to do...
then checks the DDR
then the PORT
then decides if you are creating a conflict and will act accordingly.
alas, you have a safety net that consumes cycles.

most people do not care and actually welcome that the overwhelming majority of errors are the user and are prevented. I believe this is one of the fundamental reasons why the Arduino has been so spectacularly successful.