13 ms·
Baremetal programming on the tinyAVR 0 micro-controllers
- madengr 6y agoOnly in the 21st century does bare metal programming mean C. Back in the 20th century we used assembly, or microcode if we were doing the actual processor. C was a high level language.
- DoingIsLearning 6y agoI think it's a really cool tutorial but one thing I don't often see discussed about the 'benefits' of 8bit AVRs (and this tutorial misses that) is that there are still through-hole form factors available for those chips. I think most everyone has the technical skills to go through this tutorial but a large chunk of the developing world will not be able to afford pcb manufacturing and all the tooling for SMD components. Having an 8bit AVR with a through hole form factor democratizes access to electronics for a lot of people around the world. Any maker can take a 1$ veroboard and build a semi-permanent circuit board with a very crude soldering iron. Whereas if you miniaturize further with SMD formats, then the access to materials and tools becomes an economic barrier.
- rcxdude 6y agoI think the through-hole vs SMD difference is mostly psychological. 'large' SMD devices where you can see the pins (not BGA and such) are often easier to solder (and easier to fabricate PCBs for, because you don't need to drill holes precisely).
- DoingIsLearning 6y agoThe issue I am refering to is not the technical barriers with SMD but the cost both for low-volume PCB manufacturing and SMD tooling. For a lot of economies an SMD design immediately prices out a lot first-time makers. Specially if you compare that with a $1 veroboard and a $10 soldering iron.
- foldr 6y agoYou can get simple two layer PCBs made for virtually nothing these days (even at low volumes). There's no cost-related reason to avoid using a PCB. You'll probably save money overall by being able to use cheaper SMD components. You don't need any special tooling to solder SMD components, either. A temperature controlled soldering iron and a cheap hot air station are perfectly sufficient. To make this a bit more concrete, consider that you can get 10 custom two-layer PCBs made for $2: https://cart.jlcpcb.com/quote?orderType=1&stencilWidth=100&stencilLength=100&stencilCounts=5&stencilLayer=2&stencilPly=1.6&steelmeshSellingPriceRecordNum=A8256537-5522-491C-965C-646F5842AEC9&purchaseNumber= https://cart.jlcpcb.com/quote?orderType=1&stencilWidth=100&s...
- DoingIsLearning 6y agoThis largely ignores the reality in much of the world outside North America, Europe, and some parts of Asia. > You can get simple two layer PCBs made for virtually nothing Sure you can produce them in Shenzhen for virtually nothing but try getting it shipped to Cartagena, Colombia, or Maxixe, Mozambique and then tell me how cheap they get. > A temperature controlled soldering iron and a cheap hot air station That is a 'cheap' under $100 setup in a lot of places, but $100 is also the monthly paycheck for a lot of people. Compare that with a $10 soldering iron and honestly consider how are they equivalent outside a developed country.
- foldr 6y ago>try getting it shipped to Cartagena, Colombia, or Maxixe, Mozambique and then tell me how cheap they get. Sure, but components and all of your other equipment also have to be shipped. >That is a 'cheap' under $100 setup in a lot of places, but $100 is also the monthly paycheck for a lot of people. I'm fully aware of that, but you at least need a decent soldering iron whatever kind of components you're using. The hot air station is optional if you avoid QFN. These days you only save a little by getting a non-temperature-controlled iron, and it's a massive reduction in utility.
- 6y ago
- yitchelle 6y agoI think that you are mostly correct for those who has the correct soldering iron and skills. One thing that I have found is PTH is much more forgiving than SMD. The copper tracks and pads are typically much heavier and can tolerate a lot more abuse from the less skilled.
- LIV2 6y agoYou can get pcbs made for peanuts and soldering through hole components requires hardly any coordination at all. People who have been soldering their whole life find it easy to solder SMD because they have the coordination to do it and the temperature controlled station too. I can solder qfps and tssop no problem but it's still easier to solder a dip package, they can go in breadboards or perf board and you can bang together a circuit without temperature controlled stations or cad software
- mytailorisrich 6y agoAs a DIY'er SMDs are a massive pain as they are hard to impossible to solder and need special PCBs, which I think is what DoingIsLearning is getting at. Holes are already drilled in your veroboard, that's what they are for, your job is to solder and you want it to be easy and simple.
- sokoloff 6y agoSMDs with leads and 0603 or larger are quite easy to solder in my experience, at least on a factory-made PCB with solder mask. I can hand assemble SMD faster than thorough-hole, using a temp-controlled iron for both. (I have hot air rework station as well, but most of my SMD assembly is with a fairly inexpensive iron.) SMD is a pain during prototyping and experimenting because they’re harder to use on breadboards (breakout boards are an additional step and possible point of failure). After the breadboarding stage, I think SMD is easier and faster.
- kps 6y ago> in my experience In your experience. I solder under a stereo microscope, but I don't go smaller than 1206.
- foldr 6y agoEveryone's different, but my experience tallies with sokoloff's. With the right technique it's no problem to solder 0603 with the naked eye. 0402 is possible but very fiddly. 0201 is really pushing it. A microscope is a useful aid, especially if you're longsighted.
- foldr 6y agoIt's really not difficult to solder SMD components. See e.g. https://www.youtube.com/watch?v=b9FC9fAlfQE&t=1518s https://www.youtube.com/watch?v=b9FC9fAlfQE&t=1518s for a good introduction to the relevant techniques.
- JAlexoid 6y ago
- JAlexoid 6y agoIt's not psychological. You're completely ignoring the cost of equipment. SMD only is a huge no-go for someone at the lower bracket of income. The cost of a perfboard, with a cheap soldering iron and components is a fraction of any kind of equipment you need to create a circuit board from scratch. I built voltage regulators for my electronics projects, because a regulated lab supply was completely out of financial reach. I couldn't have done it with a breadboard - I needed a permanent fixed board. I couldn't have done it with a copper laminate and etcher - because I couldn't afford $10 for the etch or a $40 dremel drill for the holes. I didn't have a programmer and I had to reuse the RS232 chips to program ATTiny2313. If people like you had their way, I would have probably been a barista...
- numpad0 6y agoChinese iPhone repair guys are hand soldering SMDs all the time, you can definitely solder SMDs on THT perfs or get SMD perfs. It's more of the matters of your motor skills and perhaps whether you have a good video microscope if it gets really small.
- rhn_mk1 6y agoSure, but that doesn't make it easy, which was the point.
- JAlexoid 6y ago1. That's racist. 2. They make money off it - thus higher value equipment. Definitely not a $10 soldering iron. 3. Building from scratch is about 100x easier and less error prone with through hole construction, than SMD. Soldering onto an existing PCB is not an issue at all here. 4. When you can't afford to scrap a $4 MCU, because you overheated it with your $5 soldering iron - DIP package can be mounted into a special socket. SMD - cannot.
- numpad0 6y ago1) I said Chinese because not many people with other nationalities do PCB repairs on iPhone. People who aren’t trained by Chinese repair ... artists? are exceptionally rare. 2) 3) https://hackaday.com/2016/10/10/ne555s-smd-prototyping-is-a-work-of-art/ https://hackaday.com/2016/10/10/ne555s-smd-prototyping-is-a-... https://twitter.com/idzuna_tan/status/741895788469485569 https://twitter.com/idzuna_tan/status/741895788469485569 https://mitxela.com/projects/soldering_msop https://mitxela.com/projects/soldering_msop 4) https://www.adafruit.com/product/1280 https://www.adafruit.com/product/1280 0.65mm is def doable, 0602 caps are hard, below or BGA needs microscope but only from there you need proper equipments
- mNovak 6y ago>> access to materials and tools becomes an economic barrier I'm not sure that's true anymore. PCB fabrication is dirt cheap from the Chinese fabs. In terms of design, KiCAD is free and perfectly usable. Both design and assembly take some practice, sure, but they are valuable skills to learn. There's value in DIP packages for breadboarding, so you can get going quickly and iterate the design, but for anything permanent or semi-permanent, I don't see a big impact.
- JAlexoid 6y agoIf you need a few things in your makeshift lab - perfboard/veroboard is perfect. You can go to your local electronics components store get a few bits and start programming AVR chips within a day. Using KiCAD, then waiting for the equipment and then soldering - that is already a barrier. Imagine you need a small voltage regulator on your DC supply line, because your cheap power supply spikes randomly... Are you going to wait for your PCB to be printed and a month for delivery(sometimes 2 months) and pay $6+ for a single board for delivery(components excluded, obv)... or you're getting a 10 pack of perfboards for $5, cut our the right size and have your voltage regulator within 10 minutes at a fraction of the cost...
- deleted 6y ago[deleted]
- DoingIsLearning 6y agoI think the issue in this whole thread is that a lot of the people commenting on the benefits and merits of SMD development are failing to see the reality that the $6 for a board or $40 for a temperature controlled soldering iron are actually too much money in far too many parts of the world. Sure as professionals you might work with $20K oscilloscopes and relatively speaking spending less than $100 on a basic SMD soldering station is peanuts, but we need to appreciate this is simply not the reality for a lot of the world out there. This has nothing to do with the technical merits of SMD or how easy/hard it is to solder versus through-hole. For a lot of kids and makers in developing countries dip packages and veroboard are the only economically feasible gateway to start to make electronics. I don't understand why everybody is struggling to accept this. Perhaps it is just a failure to appreciate the economic lottery of where in the world we are born. To me it is sad that there are kids out there who would stop their curiousity just because of economic barriers, I hope AVR's dip packages continue to be produced for a long time to come.
- turbinerneiter 6y agoNice article! A question to the fellow Embedded Developers? How often do you encounter tutorials and "getting-started-guides" of similar quality than you see here (and in similar blog-posts) FROM THE ACTUAL CHIP VENDOR. I often feel stuck between a rock and hard place with vendor docs and it feels like there is only the choice between marketing material and transistor-level technical docs (excuse the hyperbole).
- ah27182 6y agoThis probably already exists, but i really wish there was some kind of Wikipedia or something for all the random microcontrollers out there. Some kind of go-to place to find just enough info on an mC to get going and maybe a link to the actual tech docs if one needs it.
- contingencies 6y agohttps://platformio.org/platforms https://platformio.org/platforms
- ah27182 6y agoWow that’s awesome! Thanks so much
- pantalaimon 6y agoVendors often try to push their fully integrated toolchain that makes everything feel like a black box (and encourages lock in). Funnily enough some Chinese Semiconductor companies who can't effort to develop such fancy SDK Wizards tend to have the more digestible SDKs (just a bunch of simple periph drivers with a Makefile) Unfortunately they also don't afford good / English documentation :\
- bradstewart 6y agoNot often. For what it's worth, I am currently working on a project within a semiconductor company to improve this situation. Semiconductor companies (in my experience) are finally starting to accept the importance of software, so documentation is the next battle. It's coming, but slowly.
- ah27182 6y agoI really enjoyed working on microcontrollers and embedded systems back when i was interning at an aerospace company. It was so fun getting into the nitty gritty of these tiny controllers. Spending hours at the lab bench, messing with clock settings and registers. Ended up going towards software after college though, mainly for the money tbh. I still wonder to myself how i can back into this hobby. These kinds of tutorials are nice but they always kind of leave you wondering what else one can do. IMO it takes so much more than just the mC to make something useful/interesting, as it's just the brains of the operation. One still needs to give their project the arms and legs to really do something.
- turbinerneiter 6y agoadafruit.com They have a bunch of tutorials, aimed at absolute beginners, but they also have a lot of great breakout boards for different sensors and their store is well stocked with weird little trinkets that inspire creativity. Blinking stuff, actuators, sensors, all there. sparkfun.com is a similar shop. It's a bit like shopping individual lego parts.
- chasd00 6y agoadafruit is great. also, they have circuitpython support for most of their stuff. circuitpython is nice for getting LEDs flashing without having to setup a large toolchain. micropythin deserves a shout-out too for getting something happening with minimal toolchain setup overhead.
- andruby 6y agoI recently got back into it. There are tons of youtube videos that provide tutorials. What helped me most was having concrete and doable projects that you'll want to finish. My first project was a digital dice (attiny85, 7 leds, CR2032, button and a small perfboard). Now it's a led strip for a camper (esp8266 w WLED firmware, potentiometer, 5V stepdown converter). I'm also toying with radio transmission over 433Mhz so I can have battery powered sensors (water-well depth, temperature, etc)
- pkaye 6y ago
- Markxr 6y agoThere is just one - ATmega4809-PF - which is available in a pin-through-hole 40-pin DIP package. But I don't really see why to use that, there are loads of breakout boards for the others in the similar series, attiny3217 is good.
- jdmoreira 6y agoif I want proper debugging what are my options with these? Embed a gdb-stub? some kind of JTAG?
- unwind 6y ago"Proper" is in the eye of the beholder I guess ... remember that this is an 8-bit part with 4 KB of program space and 256 bytes of RAM. You are probably not implementing a gdb stub on that while still having meaningful resources (memory, peripherals, execution time) left for your an application complex enough to warrant that level of debugging support. :) That said, it seems these cores have some on-chip hardware debugging support. See the data sheet [1] section 30 ("Unified Program and Debug Interface (UPDI)"). Features include: - Memory mapped access to device address space - Unlimited number of user program breakpoints - Two hardware breakpoints - Run-time readout of CPU Program Counter (PC), Stack Pointer (SP), and Status register(SREG) for code profiling - Program flow control (Go, Stop, Reset, Step Into) - Non-intrusive run-time chip monitoring without accessing system registers This interface is the one that is described in the article, and accessed over a single pin on the chip package. I think it sounds pretty neat, makes me want to have a look at AVRs again! :) [1] http://ww1.microchip.com/downloads/en/DeviceDoc/ATtiny406-DataSheet-DS40001976B.pdf http://ww1.microchip.com/downloads/en/DeviceDoc/ATtiny406-Da...
- helsinkiandrew 6y agoAnyone who wants to try this out cheaply - search for "Arduino Nano Clone ATMEGA328p" boards. They use a similar (but more powerful chip) and cost less than cost of shipping: a couple of dollars/euros each. They come with a USB boot loader (so you don't need a USB to serial cable). Get 2 and you can also use one as a programmer (probably cheaper than a USB to serial cable). They're also compatible with the Arduino IDE if get fed up with the low level stuff
- pantalaimon 6y agoYou can get stm32 boards with more memory for a similar price. I really don't get the appeal of those AVRs.
- contingencies 6y agoArduino support (STM32 has it now but only relatively recently and with substantially less libraries), better availability, less of a confusing hardware landscape with numerous minor chip variants and 'pill' form-factor hardware versions with wacky incompatibilities, more open source PCB designs available, inertia...
- dragontamer 6y agoIts not about CPU-power, its about electronic flexibility. AVR has 1.8V to 5V power tolerances. STM32 boards have 1.8 to 3.6V tolerance. (Yes, STM32 boards can have 5V I/O tolerances, but you need the power line to be ~3.3Vs) This means that you can run an AVR system from 3xAA batteries or Li-Ion without much more thought involved. STM32 is more complex: 2xAA works, but that's much less energy than 3xAA. Lithium Ion is nominally 3.6Vs, but when charging Li-Ion can be 4.2Vs IIRC, so you're going to need to protect the STM32 from the higher charge voltages, because 4.2Vs is out-of-spec. This means that STM32 needs an external voltage-regulator module, while the AVR can just happily accept the 4.2V voltage-under-charge under a Li-Ion setup. ------- The 5V that ATTiny or ATMega supports can also deliver more power from its I/O pins. STM32 is pretty impressive with 15mA source/sink from 3.3Vs, but ATTiny and ATMegas are specified with up to 20mA at 5Vs, both source and sink. That's a lot more potential wattage you can source (and sink) from a raw I/O pin. ---------- So consider what you need to do if you have a 5V line (3x AA batteries): you'll need to create a safe 3.3V line for your STM32, you'll need to have a reference 5V voltage that your ADCs are based off of, and you'll need a voltage-converter to handle all of your 5V electronics. Or, you can just throw an ATMega or ATTiny at the problem, and just run your entire system off of 5V (ADC, I/O pins, everything). In my experience, the higher voltage (5V instead of 3V) has a lot better op-amps, and other such devices, that you can work with. Having more voltage is an advantage in electronics design: it really makes things a bit easier to design electrically. (Less noise, less hysteresis issues, etc. etc). A rail-to-rail OpAmp still only has +/- 2.5Vs at the 5V level, but that's a lot more voltage to work with than +/- 1.65Vs at 3.3Vs, especially if the rail is losing 0.2Vs as is typical. (+/-2.3V once you lose 0.2Vs, but only +/-1.45V on the 3.3V system). Traditionally, OpAmps operated at +/- 12Vs for a reason, the larger voltage just gives you more room to play with. Throw down 100mV to noise 5V also opens up the possibility of running off of a USB line without any voltage-regulation. An important-trick for sure.
- mark254 6y agoThat's not so tiny... 256 Bytes RAM, 4K Flash, that's quite a bit bigger than the smaller ATtiny25 (128B RAM, 2K Flash, 6 I/O, much less hardware on board)
- makapuf 6y agoAttiny4 has 32B RAM, 6 pins and 0.5KB of flash ... see the whole product range here (pdf link) http://ww1.microchip.com/downloads/en/DeviceDoc/30010135E.pdf http://ww1.microchip.com/downloads/en/DeviceDoc/30010135E.pd...
- JAlexoid 6y agoWhy would you need more? I prefer with PIC, as they offer real time very predictable execution. All instructions have same execution time.
- rramadass 6y agoPSA: tinyAVR Microcontroller Projects for the Evil Genius is a very good book on this family of MCUs.
- jepler 6y agoI continue to be dismayed by how Microchip treats developers. Want a toolchain? You have to create an account. Of course, it's freeloading off of the Free software gcc toolchain. Even worse, when it comes to their microcontrollers that use the START or ASF4 system, you get headers that are incompatible with Free software (I haven't checked how they license the headers of the new tinyAVR series MCUs). At least when it was Atmel it was just a few pieces of IP that were guarded with stupidity like this (their touch interface is the only one I recall)
- justinclift 6y agoYeah, noticed similar with ActiveState yesterday. Went to download ActiveState TCL just to do a 1-off compile of SQLite on a windows box... and now they require people to create an account to even download TCL. Instead, I just deleted the SQLite requirement and avoided the whole thing. The only way to win is not play their game. :(
- kevin_thibedeau 6y agoYou could just use Cygwin or Msys Tcl. Or just build it yourself. It has always been an embedded language and the build process isn't problematic.
- justinclift 6y agoWasn't worth the effort for this one off case. It's actually ironic, as I had learning TCL on my todo list due to interest in CNC machining (some older stuff used TCL). But not any more. Even going to the TCL language home page, they push people towards ActiveState. That's killed my interest in TCL entirely, and likely permanently.
- deelowe 6y agoJust typical hardware manufacture stuff. They all do this sort of thing. I still remember trying to modify and build intel's yocto image a few years ago. It was completely impossible.
- 6y ago