Hi everyone, welcome to the Hack Chat today. My name is Dan and I'll be moderating today along with Dusan. We're joined by Uri Shaked today, who's doing a HackadayU course soon on RaspPi 2040 and Pico, and completed a course earlier in the year on AVR programming.
Welcome Uri! Can you start us off with a little about yourself?
Is there audio?
@rjtescher - No, just text. Old school, like IRC
no audio today, but here's a recommended soundtrack for this hackchat:
- Atom heart mother by Pink Floyd
- Court of the Crimson King by King Crimson
Software engineer by passion, and in the recent year, this passion has grown for projects that also involved hardware
Especially ones that challenge my gray cells and teach me new skills. Like building an in-real-life version of the Chrome T-Rex game
I feel like I wrote an article on that...
or trying to decipher encrypted 3D printer firmware for weeks
@Uri Shaked do you remember a revelation you experienced when diving deeper into MCU programming, (like "wow now I can do something really cool").
About the 🦖?
decypher files on PC or reverse engineer a code dump that just doesn't have symbol tables?
I knew it:
Simple to learn, hard to master, a lifetime to kick the habit. This applies to a lot of computer games, but the T-rex Runner game for Chrome and its various online versions are particularly insidious. So much so that the game drove one couple to build a real-world version of the digital game.
(re: printer fimrware)
@Inne that's a great question.
I think that 3 days into writing a simulator for AVR, when I got "blink" to work for the first time, I realized how little of the MCU features most code actually uses
What’s up ;)
The AVR instructins or the specific hardware extra IO ?
Mostly the hardware extra IO. I don't remember exact numbers, but I think Arduino's blink used between 50% to 80% to the overall instructions.
It that a comment on what programs use, or the boat of Arduino?
but that instructions was really the easier part about the emulator. The peripherals, especially the timers, took a lot longer to write. But for blink, I initially faked the timer with a few lines of code
Friend of mine was using the library to time a pulse, there is a specific way to do it. He couldnt get it to work for two inputs. So I looked at the code and found there was a special hardware register setup for that - which I then found in the specs, whch is limited to one pin (on the 328)
@Dave Blundell decrypt the firmware on the PC, using python + numpy/scipy and jupyter:
@Nathan Brown what programs actually use.
@uri - Was your simulator written in HLL ? And what assembler package (s) do you use to code AVR?
The ATmega328p has 3 hardware timers. Most programs run fine with just Timer 0.
https://wokwi.com/arduino/projects/289908049496244744 - look at simon.S)When I need I just use the GNU assembler. You can use it from directly in Arduino projects, e.g.
Other than being a maker with passion for software (especially everything web), electronics and hardware, I also used to be a Salsa dance teacher
and that's also how I met my life partner
Nice ; )
@Michael Möller you could probably also do that with INT2/INT3, or even with PCINT which would support any number of pins
unless the inputs would fire almost simultaneously, and then you won't be able which one fired first
Salsa dancer by night. AVR hacker.. also by night. Cool :)
I'm trying to find the original reference, but lets not derail the chat with my old (and solved) problem.
What kind of environments do you like to use? Text editor and makefile?
Salsa. Hold on, I'll find something for you...
Nights can be busy, I guess
I was wondering when reading the Datasheet for the RP2040 (for HaDU) for instance, do you have a strategy or read the whole thing mostly chronologically.
I have another question about writing a simulator. What do you use to simulate the "rest" of the hardware? Thinks like I2C components, etc.
@Michael Möller . Me, 12 years ago:there you go,
@Christopher nowadays? mostly Visual Studio code. Working on Windows machine, and heavily using WSL (Linux integrated into windows).
Then for most stuff that involves compiling things I use docker.
Whoa - that is energetic dancing!!
@Uri Shaked (sidetracking issue: "input Capture Unit", on pin 8 (Portb0), The FreqMeasure library)
What about code visualisation, for static analysis? Some way to show the instructions in a way molecular modeling shows protein structure, show how the code flows in a "folded together" way as a 3d model, more compact than the usual 2d approach?
@Inne RP2040 is a great example. I got a series when I'm building an emulator for it in a live stream, so you can actually see how I read the data sheet. Also, I showed which parts I focus on in the AVR course (you can find it on Hackaday's YouTube)
@Thomas Shaddack protein folding on an AVR?
Cool I'll look them up.
but in general, there's always a section talking about the general architecture. memory map, registers, etc. I usually start there to understand where the code is loaded, where the RAM starts, how is the stack managed, etc.
FYI, I'll post a full transcript after the chat in case anyone needs to refer back for links, etc.
Some architectures have weird features. For example, ESP32 uses Xtensa, which has something called Windowed Registers
Do you have a link to Uri's course?
It's like a micro-stack implemented inside the MCU. It confused me much!
@Mark J Hughes - the playlist above is Uri's AVR course.
His RP2040/Pico course is coming up in May
http://ww1.microchip.com/downloads/en/devicedoc/atmel-0856-avr-instruction-set-manual.pdf. But, because they limited the language to a specfic set of hardware, it is not generalizable. Maybe I am wrong about the limited nature of AVR language.Isn't AVR a generic concept of programming, not a particular piece of hardware or software? I found an AVR instruction set manual at
@rjtescher Nope. Folding the AVR code in a protein model like way. Or the RNA or DNA structure. Instruction is like an atom, with "bonds" to the previous/next one (and calls and jumps).
@Thomas Flummer for the most part, I don't use code visualizations. I did use some visuals when trying to dechiper the 3D printed firmware, e.g. https://medium.com/@urish/visualizing-repetitions-in-string-using-python-and-matplotlib-5e4e1ddff0c9
@RichardCollins that's a good question. AVR is an architecture. It's not a concept - it's a specific set of instructions and defined behaviors that are implemented by a family of Microcontrollers.
@Thomas Shaddack Oh! Okay
Other examples for architectures include ARM, x86 (intel), Xtensa (which I mentioned before, used by ESP8266/ESP32), SPARC, and RISC-V that everyone is talking about
Hi Galia! Very nice visuals, thanks ;-)
It is my art.🙏
Hi hi :)
But your emulator would allow one to add "128 bit memory space" to some example project. Those instructions would show up in the language, You compile and send HDL to the chip maker and run a big memory project. Simulate to design and test, then get a particular language for particular needs?
@Uri Shaked have you done much in the way of glitching or attacks on fuse bits on avr?
@rjtescher The disassembler gives us the primary structure, the chain of instructions. Then apply rules that'd "fold" the 1d-structure to something 3d where the stuff that belongs together naturally clusters. Essentially a 3d graph. With molecules, the rules are the laws of physics governing attraction/repulsion and bond length. Here the rules would be set to make the code structure as obvious as possible, allow us to see the entire code size at once while zooming into the individual sections to the chain of instructions. Without it it is like looking at a map through a thin tube and seeing only a little area - but seeing it in detail.
Speaking of protein folding, I found Microbiology really intriguing as well. Two years ago I organized an intense 6-week microbiology training program for software hackers
@Thomas Shaddack I have never heard of this approach. Is there any software package that already does something like this? Or is it a new concept?
I took a course in bioinformatics a dozen or so years ago, interesting. Searching genetic codes with various data structures.
It is one of my pet ideas.
Last year I went through many of the protein folding groups for covid on the Internet. They could have used purpose-built massively parallel computers. But no way to design the hardware from the software emulation.
I know IDA has a graph visualization feature, but I rarely found it useful
Organizing a biology course for hackers, the most challenging part (which I didn't anticipate), was to shift their way of thinking from asking: "Why is it like that? What are the rules? Where's the manual?" to simply accept what they observe as given.
The bioprinting is fun! :D The gene-engineering of bacteria with the kit is even more fun. On the wishlist it goes.
Biology research is reverse-engineering nature.
The other big challenge is dealing with the fact that in biology, every rule has at least one exception.
Sometimes more exceptions than rules, yeah.
Unlike software / hardware, where everything was designed by a human, and if you dig deep enough, you'll probably find the reason why it works in a weird way (e.g. why the A20 line of the system bus is disabled on boot by x86, and you have to tell the keyboard controller to switch it on)
B^) sort of like UN*X then?
Anthropology, economics, finance, government, education - every field has infinite exceptions because our models are finite and the universe unlimited.
Nature is like a codebase maintained by short-term interns, low paid, unmotivated, doing last minute patches with the least effort necessary before going home. Repeat for couple million years.
But then you find fascinating stuff like virus fragments hidden in bacteria.
That's the result of that sleepy 4AM cut/paste.
And you start wondering how they even got there....
Thomas Shaddack: Billion years. And rather large numbers of replicas.
Interviewer: And how did you get there?
Nature, exhausted: Trial and error. And error and error.
I think for me, one of the biggest revelations in the biology course, was that what I thought to be junk DNA, is just a piece of code the replicated itself many time
(google SINE / LINE in human DNA)
And error. And error.
What do you guys want to build? Solar system colonization, warp drives, green the deserts, terraform earths poor regions, lift to orbit, atomic energy (original meaning), education for all? I have a list of abou 20,000 topics that need people working hard and efficiently.
Early DNA biologists: Doesnt code for protein, must be junk.
Current theories: It is oart of the folding system, thus control which pieces are exposed, ie which genes are expressed.
Software analogy: Indirect jump
Interviewer: So why does a giraffe have that nerve going all across its neck and back?
Nature: *sobs loudly*
Well, who knows? Maybe "Junk DNA" was needed at one time for a particular solution, sort of like the "light pen" driver in x86 software.
Yes, if it works, then that is the answer for now, never mind the gadzillions of low cost random previous tries that did not work
fascinating stuff. Unfortunately, it's not really accessible for us, hackers (yet?)
@RichardCollins Get out of this stupid rock. The meek shall inherit the Earth, and they can keep it.
@Rob Ward Best to remember every experiment and optimize the whole set, not just one particular sequence or outcome.
a lot of junk dna seems to serve structural or regulatory function. My hunch is that the function was gradually gained by that piece of code being there and having that particular shape that modulates access to some other shape a bit nearby.
Nature: I was young and clueless.
Interviewer: You were millions of years old!
Interviewer: So did you learn anything from it? Will you get more efficient now?
Nature: ... No?
...and then comes epigenetics...
Yes. I also really liked some of the methods people use nowadays to brute-force reverse engineer genes.
Nature: "Yes, I evolved gene engineers."
for instance, there's yeast. it exists. but does it needs all genes? apparently, not.
The Internet is going through that kind of random experimentation and evolution. It is possible to measure and guide or modulate part of the process. And most of the pieces are visible.
Interviewer: How did you evolve gene engineers?
Nature: They sort of... happened?
I have a few AVR chips of various types I bought years ago.
I also have an ST-500 programmer from before then.
What do I need / need to do to do assy lang. on my AVRs?
But yeah. And it's fascinating, how things evolved to us talking about it - and more
The ones that keep their heads down and concentrate on reproducing will inherit the earth. Obsession with money is a dangerous distraction.
@rjtescher Alcohol. Significant amount. And assembler.
how do we figure out which genes can be omitted? brute-force search
@Uri Shaked Muntz did that with Televisions
Yes, GNU assembler should do.
If you need to exact command line ping me after, I'll look it up for you
The "useful" or "necessary" genes depend on the context. A better field equation is not needed if you are building water supplies for Mars.
@rjtescher And some hello-world examples. I usually start learning with modding something that already exists, even if small.
yes, actually the AVR course has some pieces you can use to stich together an hello world in assembly
@rjtescher But consider writing it in C. If you don't need clock-tight timing or save every possible byte, C is the lazier option. I swear on (and sometimes at) avr-gcc.
Definitely do it.
And come back with questions, many, please :)
Questions are fun. The only stupid question is the one that was not asked, but should.
Are you a unicorn?
Me? Do I like barfing rainbows? :P
...do I *look* like...
@Uri, I am a Unique Orn(ery) S.O.B. B^)
Programming is a mainly hard slog with deterministic expectations, interspersed with random genius events, teasing them apart is much harder. Nature is entirely random, so much, much harder to "follow any logic".
another fun chip is the ESP8266/ESP32. With C you can share big chunks code between the platforms, and the embedded approach is similar.
But if you do like torturing yourself with hardcore AVR internals, there's also my latest hardware project, The Skull
Though NNs kind of throw some arbitrariness / randomness into the hot mess
Nature has a lot of logic. The problem is that it has so much logic it appears chaotic. (Chaotic. Not random.)
Today someone from Brasil actually managed to solve all the 3 parts of the challenge for the first time
Is that compiler on Github?
Printing hardware... that'd be royal fun. 3d nanoprinting of organic semiconductors...
I'd love to take a look
No, he wants to commercialize it. I begged him to make it open, but he would rather make LOTS of money.