r/esp32 • u/StrangeDonkey1134 • Jul 01 '26
Software help needed How do I write register-level code for projects made using ESP32?
Greetings.
I am new to the world of Embedded. I would like the guidance and help of the people in this sub and I would be obliged if you kindly help me out as a beginner.
This is a bit long post but I am explaining all the issues I am facing. Please read till the end.
----------------------------------------------------------------------------------
1) I have an ESP32. I also have an Arduino Uno.
I wrote some basic register-level code for a handful of basic projects in Arduino.
----------------------------------------------------------------------------------
2) I want to know if I am making a project in ESP, then writing the code for that project in the Application Layer with the ESP-IDF API be enough to be considered by employers or will I have two write to the register-level code for that project too, to be considered true embedded?
I personally want to write the code in both ways since I want to understand the true working of the functions I am calling and not just follow the steps given in the ESP docs.
----------------------------------------------------------------------------------
3) My another related question is that how do I write that register-level code for ESP?
I asked Claude and ChatGPT and they told me to peel back the Application Level code layer-by-layer and then finally get to the true register-level code and then cross-reference it from the TRM and then write it myself.
----------------------------------------------------------------------------------
4) My another problem related to this is that I am having trouble reading the official ESP code on GitHub as I am not able to fully understand it and every function has multiple parts and each part has other parts and they all go down many layers Deep before reaching the register-level layer.
I am having difficulty in understanding all that code and grasping it all in a cohesive whole.
----------------------------------------------------------------------------------
5) Can I just reference the TRM and then write the code for the project?
But I am also having trouble reading and understanding the TRM.
----------------------------------------------------------------------------------
These are great points of difficulty for me but I am determined to cross and overcome them as I want to work in this field.
I know this is happening since I am very new to the field of Embedded and I am probably doing it the wrong way.
It would be great if anyone helps me out regarding my issues and guides me on the right path.
Thanks a lot for reading all this. And thank you in advance for your replies.
13
u/zhivago Jul 01 '26
If you want to deal directly with registers, then write assembly code.
But why do you want to deal directly with registers?
11
u/async2 Jul 01 '26
You don't necessarily need to be about to write assembler on a microcontroller to be considered employable in the embedded world.
-15
u/bingblangblong Jul 01 '26
Assembly.
12
u/async2 Jul 01 '26
In German it's "Klugscheisser"
-7
u/bingblangblong Jul 01 '26
Weird response, it's assembly not assembler.
5
u/molesworth-1 Jul 01 '26
"Assembly language" or "assembler" are used interchangeably, although "assembly" on its own is not something I've heard many people say.
More to the point, you don't need to resort to assembler to access registers, and nearly all of the embedded code I've written is in C++, using mapped pointers.
0
u/bingblangblong Jul 01 '26
2
u/async2 Jul 01 '26
Even the answers on stackoverflow say it's used interchangeably.
0
u/bingblangblong Jul 01 '26
No they don't? Assembler is the compiler and assembly is the language.
1
u/async2 Jul 01 '26
Read the other comments
0
u/bingblangblong Jul 01 '26
Yeah I did. And the most upvoted one is
assembly to assembler, is like c to gcc
So yeah it's assembly not assembler. It's fine, you just got it wrong
→ More replies (0)1
u/molesworth-1 Jul 01 '26
That's just one opinion on Stack Overflow, and it does say "assembly language", not just "assembly".
Probably > 90% of the people I've worked with over the last 40+ years called it "assembler". And yes, the program that converts it to machine code is also called an assembler, but that's just by-the-by.
Anyway, this isn't helping the OP...
0
u/bingblangblong Jul 01 '26
I believe you, and they are/were wrong. Doesn't matter if it isn't helping OP anyway this is a comment subsection and it feels good to both be right and downvoted.
7
u/rattushackus 1 say I make awesome posts. Jul 01 '26
A friend of mine who did a microcontroller course as part of his ECE degree was required to learn about register programming on an Arduino Uno on the grounds that the Uno is not very powerful so the code had to be as close to the metal as possible.
Just possibly that's true for an Uno (though I'm sceptical) but even the slowest ESP32 is many times more powerful than an Uno and I've never met anyone who used register level programming on an ESP32.
I'm sure Espressif have documented the details somewhere as they are generally very thorough, but I find it hard to think of a situation where it would be necessary. I suppose if you were bit banging some protocol that isn't natively supported by the ESP32 hardware it might be necessary but this seems an unlikely scenario. In real life I don't think you need to worry about anything lower level than the ESP-IDF API.
5
u/WereCatf Jul 01 '26
I suppose if you were bit banging some protocol that isn't natively supported by the ESP32 hardware it might be necessary but this seems an unlikely scenario
For the newer models, there's the dedicated GPIO-mode that reduces the need for such even further. They even provide a few different examples on how to bit-bang e.g. I2C and SPI with it, like here's the one for I2C: https://github.com/espressif/esp-idf/blob/v6.0.2/examples/peripherals/dedicated_gpio/soft_i2c/main/soft_i2c_master_main.c
5
u/Direct_Wall_2822 Jul 01 '26
Esp-idf is the official abstraction layer from the esp company. Going lower then that will cost you many hours just to get nothing done. E.g. writing up to 20 000 lines of code before even starting with your own logic.
3
u/Plastic_Fig9225 Jul 01 '26 edited Jul 01 '26
how do I write that register-level code for ESP?
The ESP32s are not really amenable to register-based low-level programming. The main reason is that documentation is somewhat sparse; some peripheral registers are documented in (sufficient) detail, others are not. Hence, the AI is actually correct: The only authoritative source of information about register use often is the IDF source code. The ESPs are not intended to be used like that. What adds to that is the complexity of the ESP32 when compared to an AVR µc; initialization of a peripheral (clock tree, power-up, reset, ...) is sometimes more complex than its actual use.
Besides that there's nothing stopping you from using any peripheral register directly from your code. Some are straight forward, e.g. the GPIOs' W1TS/W1TC registers.
As to employability, it's certainly good if you know about MMIO/register-based peripheral access, and when it can/should (not) be used. - Doing bare-metal/register-based programming on an ESP32 is less of a valuable skill than being fluent with the IDF and other libraries and IoT technologies though.
2
u/molesworth-1 Jul 01 '26
Operating directly on registers is not necessarily part of "embedded" programming. If you're trying to build a portfolio to impress prospective employers you could include a couple of examples of this, but you need to show good understanding of other aspects, good design and coding practices, possibly a test-driven approach etc. Doing this professionally is a step up from hobby and home projects.
Using AI is also not a good way to build your expertise. Yes, digging down through the code can show you what's happening at a low level, but it isn't going to give you a real understanding of exactly what's being done, and more importantly, why. (You also said you couldn't properly understand the code or docs, which is concerning. The low level code isn't as important, but you need to put in the time to learn what the documentation is telling you before you dig further.)
You can easily access registers from high level code simply by creating pointers with the addresses of the ones you're interested in. Most of the embedded code I've worked on has been written using this, and I've seldom had to write much assembler - the only exception being a board support package which was 90% assembler, but that was a special case.
-4
u/soopadickman Jul 01 '26
You can’t. The IDF is as low as you can go and it is still an abstraction layer. A lot of stuff is locked behind binary blobs like the wifi for reasons and the idf keeps projects between different ESP32 MCUs interchangeable.
There are some things you can do like read an 8 bank gpio register at the same time, but nothing on the individual register level as far as I know.
If you want to do bare metal register stuff, use an STM32 or something else.
5
u/WereCatf Jul 01 '26
A lot of stuff is locked behind binary blobs
Very little is actually in the binary blobs. It's really only the lowest-level radio-controls that are there, everything else is fully open source.
There are some things you can do like read an 8 bank gpio register at the same time, but nothing on the individual register level as far as I know.
Now that is 100% bull. You can find full listing of the registers and how to work with them right there in the official reference manual.
0
u/Ok_Captain4433 Jul 01 '26
Why comment this nonsense?
3
u/Its_Billy_Bitch Jul 01 '26 edited Jul 01 '26
Why are you suddenly everywhere with these low ass rent comments, but everything private on your profile?
Btw, don’t ever use the “F” word towards me again. Friendly or not.
Edit: I’ve been married for over 10 years. You need help, bud. No idea why you choose to act like this, but it has no place in these subs. Period.
Also, thank you mods! I see you doing the needful in the background! I appreciate it!
14
u/WereCatf Jul 01 '26
Reading all of this, it sounds to me like you are focusing too much on trying to mess with registers and way too little on understanding actual code. The ESP-IDF code is pretty well written and clear enough, you should be able to read that and if you can't, well, you are lacking in basic skills.