Adventures in AVR ISP Programming - Page 1
Forum section: electronics / general

author: EEVblog
author_rank: Unknown
timestamp: February 18, 2017, 01:09:34 am
content: Dave battles the Atmel/Microchip AVR ISP Mk2 programmer with AVRdude in order to program an ATMEGA328 and get his uRAD radiation monitor working again. Can he do it?http://www.uradmonitor.com

author: VK3DRB
author_rank: Super Contributor
timestamp: February 18, 2017, 02:15:12 am
content: I agree, the AVR Studio is a debacle with installation.If you don't want very annoying vague error messages popping up during installation, you cannot have the AVR studio on any other drive than drive C. This bug has been around for yonks and the programmers at Atmel have not seen it fit to fix it.Also, don't bother with WinAVR. It is olde school. The last release was in 2010. I had problems with WinAVR on Windows 10 and Atmel Studio 7. Atmel Studio 7 comes with a native C compiler built in and from my experience, it is "pin compatible" with WinAVR and it works a treat. I recompiled a major WinAVR project with the native C one and no error messages at all. No adjustments needed. Good one, Atmel.But a real gripe is the PFC ribbon cable Atmel has on their JTAGICE MKII programmer. What pot smoker came up with that idea? They tear and break with ease. Atmel charge a king's ransom to replace the cable - around $40 USD. However I found a MUCH cheaper pin compatible replacement for around $3.50 USD. They are almost impossible to find, but you can get them here...Longer cable (about 8")...http://au.element14.com/wurth-elektronik/687730200002/cable-ffc-rev-0-5mm-200mm-30way/dp/1908559(Only 3 left, sorry, after I bought 3 others two days ago)Shorter cable (about 6")...http://au.element14.com/wurth-elektronik/687730152002/ffc-cable-30pos-152mm-60v-white/dp/2520275(Plenty in stock)You won't find them as cheap anywhere else.

author: Muttley Snickers
author_rank: Unknown
timestamp: February 18, 2017, 02:30:27 am
content: Quote from: VK3DRB on February 18, 2017, 02:15:12 am+1Slightly old school, I found this little beauty below at the local recycle center a while back and couldn’t possibly leave it there, not at $20 anyway with the box half filled with dozens of various unused Atmels still in the wrappers, a good reminder that I’m probably due for an updated version, this thread should be a good guide.

author: HwAoRrDk
author_rank: Super Contributor
timestamp: February 18, 2017, 02:48:13 am
content: Never used avrdude before? Now that's not true, he has!But he probably didn't realise it. The Arduino IDE uses avrdude to program boards. And so, Dave didn't need to bother with installing WinAVR, as he could have just used the copy of avrdude that the Arduino IDE uses - assuming he still had it installed, of course.Although one thing to note is that if he had gone ahead and finished installing Atmel Studio to start with, it would have installed the 'Jungo' driver for his ISP MkII, which avrdude doesn't work with. It only works when the programmer is using the libusb driver. Fortunately, Atmel Studio 7 also plays nicely with libusb-driven programmers.

author: sleemanj
author_rank: Super Contributor
timestamp: February 18, 2017, 03:18:00 am
content: Indeed, the Arduino IDE even has anup to dateversion of the avr toolchain including avrdude these days, instead of the fairly ancient version it was stuck with for a while.Even if you don't ever open the Arduino IDE, it makes for a nice simple install of a working toolchain.

author: TheSteve
author_rank: Unknown
timestamp: February 18, 2017, 05:08:15 am
content: Newer AVR Studio is so terrible. They should be ashamed.

author: james_s
author_rank: Super Contributor
timestamp: February 18, 2017, 08:07:05 am
content: Quote from: Muttley Snickers on February 18, 2017, 02:30:27 amThe STK500 is great, I bought mine around 17 years ago and still use it, it's been rock solid. I forget what version of AVR Studio I use but it's an older one. I also use Bascom AVR which can talk directly to the STK.

author: radhoo
author_rank: Contributor
timestamp: February 18, 2017, 09:11:59 am
content: Quote from: TheSteve on February 18, 2017, 05:08:15 amAt its core, this is more of a Microsoft issue then Atmel's. Especially for the latter, I have nothing but my appreciation, for all the great things they created (that includes Arduino with everything that resulted from it).

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: February 18, 2017, 09:47:38 am
content: Quote from: TheSteve on February 18, 2017, 05:08:15 am+1Especially if all you want to do is program a part.Last time I had to do it, ISTR they'd stopped including the command-line stk500.exe standalone programmer, and the new studio loads firmware into AVRISP that the old STK500.exe won't talk to.Ever since the very earliest days. Atmel just didn't get what was needed for device programming, like including fuse settings in the hex file. And being able to set fuses to disable the programming interface on a device in about 3 different ways. And requiring a clock for programming,. so your programmer has to either program slowly or know what the clock is, or program the clock fuses before speeding up to program the main flash.And did they ever get round to including a disaasembler view in Studio? V4 is the most recent I've used serously and that didn't even have a memory view!

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: February 18, 2017, 09:56:50 am
content: ..and the bigger question is why didn't the urad monitor people bother to include a bootloader to allow easy firmware updates without having to dick about with hardware programmers?If you're doing something that will be used by lots of people all over the place surely that's a total no-brainer.

author: radhoo
author_rank: Contributor
timestamp: February 18, 2017, 10:13:42 am
content: Quote from: mikeselectricstuff on February 18, 2017, 09:56:50 amBecause everything takes a lot of time, and for the size of this project there were other priorities.But good news, not only a boot-loader, but a full OTA firmware upgrade system is one of the upcoming features. One step at a time.

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: February 18, 2017, 10:22:30 am
content: Quote from: radhoo on February 18, 2017, 10:13:42 amA bootloader shouldn't take more than a day to do - for something designed for wide distribution like this, it should be pretty much the first thing that gets done, as it will easily save way more time in the long term.

author: radhoo
author_rank: Contributor
timestamp: February 18, 2017, 10:57:17 am
content: Quote from: mikeselectricstuff on February 18, 2017, 10:22:30 amYears ago, when I started with software development, I had the same drive: "yes, it only takes one day". This almost became the answer for any task, no matter of the complexity. Then I learned there is a big difference between "prototype" and "production", between "proof of concept" and "stable". Then the bugs, which doubled everything beyond initial estimation. I learned that to stay committed to a direction and actually finish something beyond a simple prototype (putting to production for instance), there needs to be a balance in the decisions: some features go first, others are part of future updates.IMO, first thing was to get the system going and do its job, and it took a lot to make that happen (hardware, suppliers, manufacturing, firmware, server infrastructure, API access, frontend, bugs, new features, and then the human part: emails, support).But, I already said this feature is on the list, and will be done when times allows it. Some hardware changes are needed too, like adding a FT232 for USB upgrades and an EEPROM for OTA upgrades. The USB thing triggers a change to the DC connector used, and I'm not happy with that.

author: Jeroen3
author_rank: Super Contributor
timestamp: February 18, 2017, 03:32:31 pm
content: Quote from: mikeselectricstuff on February 18, 2017, 10:22:30 amMike, of all the people you're the last one I was expecting such a comment from.You are right, it takes a day or two... To get it working on your desk with the debugger hooked in.The real world expands beyond your desk though, and challenges your software with various obstacles. To name an example:users.

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: February 18, 2017, 04:12:59 pm
content: Quote from: Jeroen3 on February 18, 2017, 03:32:31 pmWhich is exactly why the first thing you should do is the bootloader, and use it as the method for firmware loading during development as much as possible. That way it gets well tested.Once you have that done reliably, it doesn't matter how flaky the rest of the system is as you always have a way to fix it easily in the field later.

author: radhoo
author_rank: Contributor
timestamp: February 18, 2017, 04:19:45 pm
content: The firmware update, at least on these things, is a feature, not a must have. There is no need for updates in the field. The units are shipped preloaded with the stock firmware, and only the more technical users are approaching the upgrade subject for the new features that are implemented. And they know how to do it, regardless of using an USB cable, or an ISP cable.But generally speaking, having easier tools helps, and I think I say it the third time that I agree with mike's input. It's just that other things went first.

author: james_s
author_rank: Super Contributor
timestamp: February 18, 2017, 08:54:24 pm
content: Maybe I'm in the minority here but I never cared much for bootloaders, more trouble than they're worth with an open project. Just give me a standard 6 or 10 pin programming header so I can plug in my STK500 or USBASP and I can program the device in about 10 seconds, no screwing around with serial cables and bootloaders.Some valid points above though, as much as I like AVR micros, the requirement of a clock for programming is ridiculous, get the clock settings wrong and you can brick the chip and require HV programming which most hardware doesn't support. The programming interface should get a clock from the programmer talking to it and bypass all settings.

author: radhoo
author_rank: Contributor
timestamp: February 18, 2017, 08:58:16 pm
content: Quote from: james_s on February 18, 2017, 08:54:24 pmYou would set a new record, James, as if I recall, the fastest update on one of the units so far was 4 minutes. Because the aluminium enclosure also has some screwsWhat I want the bootloader for is the OTA updates. To be able to push the new firmware from the server directly.That might be tricky over the LoraWAN connections, but will go just fine on Ethernet/Wifi/GSM , these 4 being the communication methods used so far.

author: james_s
author_rank: Super Contributor
timestamp: February 18, 2017, 09:05:42 pm
content: Well, yeah if the firmware needs to be updated regularly then a bootloader is nice. I rarely update things once they work though.

author: radhoo
author_rank: Contributor
timestamp: February 18, 2017, 09:09:56 pm
content: Quote from: james_s on February 18, 2017, 09:05:42 pmWell, it's the same here: Once the device is shipped with its stock firmware, can go like that forever. But the feature is in the (big) TODO list and I'll do it when I get the chance.

author: fki82
author_rank: Contributor
timestamp: February 18, 2017, 09:30:06 pm
content: Wouldn't it be enough to just put the Arduino bootloader there?The device may have a serial port to a PC anyway.I think they are using AVRdude on the PC side, to do the flashing.Add a few scripts to that and you could have a standalone firmware update tool.

author: radhoo
author_rank: Contributor
timestamp: February 18, 2017, 09:33:39 pm
content: Yes that would work, but as said it would also require a FT232 / CH340 for the UART to USB. What I will do is to have it get its firmware via the network (OTA updates).

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: February 18, 2017, 10:00:02 pm
content: Quote from: james_s on February 18, 2017, 08:54:24 pmDepends on your target market. Dave's vid is a classic example - 10 seconds to program, after a couple of hours dicking about to get a programmer to work.Bootloader doesn't necessarily needs a serial cable - the whole point is that the device can use whatever interface is available in the product. If it interfaces to anything you can get a file to, you can get firmware onto it.But a serial cable is probably more widely available than a programmer for a specific micro family, and there are ways to write a serial loader that doesn't need specific host software - just throw a serial file at the device with generic terminal software.Bunnie also showed a neat solution using audio form a web browser.

author: G0HZU
author_rank: Super Contributor
timestamp: February 18, 2017, 10:03:15 pm
content: QuoteI scored a free STK500 kit a few years ago and it has been useful a few times but I still prefer my old homemade LPT based programmer for ISP stuff. It can erase, program and verify a fairly simple program for a MEGA168 in about 2 seconds.I got the STK500 for free at work because nobody (in the SW team) could remember what it was and so it went in the bin during a lab cleanup. I doubt any of them use Atmel AVRs as PICs seem to be the choice where I work. On the version of STK500 I have here, Atmel don't even tell you what this thing is or what it does. It doesn't even say 'STK500' or 'programmer' anywhere on the hardware. The Atmel documentation that I found for the STK500 was a bit odd and vague but I think this is normal for Atmel.

author: Jeroen3
author_rank: Super Contributor
timestamp: February 18, 2017, 10:39:53 pm
content: Long time ago I bought one of these:http://shop.myavr.com/index.php?sp=article.sp.php&artID=200006It's an STK500 in a stick. It served me well. Now I have an mkII, which is better because it does tpi.

author: radhoo
author_rank: Contributor
timestamp: February 18, 2017, 10:45:27 pm
content: I had a DIY lpt1 programmer too, was among the first things I built when I started withAVRs. But newer computers have no parallel port so I wanted something easier to use.Next was the usbAsp which I use a lot these days too.It costs only 2-3 USD and supports both 3.3V/5V.I also use a MKII clone that is great, as it support 3.3V/5V and ISP, PDI and TPI (so can be used with XMEGAs too)

author: westfw
author_rank: Super Contributor
timestamp: February 19, 2017, 12:01:40 am
content: All a very entertaining example of how annoying it can be for even an EE professional to try to do something uncommon, based on fuzzy memories of outdated procedures and environments. This is one reason why Professionals can be enthusiastic about something like Arduino, even with its annoying toy-like simplicity - sometimes (OFTEN!) all you need is something simple. And having something that's easy to install, whose development is "tracking" recent changes in the world and with lots of online community, is frequently ... nice.FWIW:The Atmel Studio 7 install is much better than the AS 6 install. Yes, it still takes a very long time, but with 7 it doesn't stop every <inconvenient time> asking to to checkbox some license for some sub-piece. (On the minus side, AS7 doesn't run on WXP.)WINAVR is long obsolete and no longer being updated. It's closest logical replacement is probably the Atmel command line toolchain download (http://www.atmel.com/tools/ATMELAVRTOOLCHAINFORWINDOWS.aspx) Unfortunately, this is a much smaller set of tools (doesn't include make, doesn't include avrdude, doesn't include the unix shell utilities, etc.) (because even OSSW licenses are a pain, not to mention having to track a half-dozen different projects.)Arduino provides a one-place download and install of a pretty complete and modern toolchain for AVR. It's buried deep inside a convoluted directory structure, but it IS there.There were some Atmel tools that were famous for needing different drivers depending on whether you wanted to use the Atmel tools with them, or the open source tools like avrdude. :-(W8 and W10 have introduced a set of relatively annoying security features that can make unsigned drivers harder to install.AVRDUDE has a fairly high update rate. Not all of the updates have been wonderful things :-( There are some GUI front ends that make using AVRDUDE a lot easier. (AVRDUDESS is one, I think?)The 6-pin vs 10-pin programming connector thing is indeed a thing. More recently, you can add the 1.27mm pitch connectors to the mix, plus SWD and JTAG. And the connectors that look the same aren't necessarily compatible. You'd almost be better off with a set of jumpers that you ALWAYS need to fiddle with.a STK500 is a swell thing, if you've got a serial port and a 12V power supply. Similarly parallel port programmers. If you've got the right computer and have it all set up, you're in good shape. if you have to find a modern computer/OS/hardware/instructions set, you're NOT in good shape... (I'm not even sure that AS7 still supports the STK500.)

author: james_s
author_rank: Super Contributor
timestamp: February 19, 2017, 02:11:03 am
content: As simple as the Arduino is, I found it very frustrating when I first started messing with them and that's coming from years of experience using AVR microcontrollers. There are multiple versions of the Arduino IDE which for some reason cannot be installed concurrently on a system and some of the later versions break large amounts of older code, spitting out cryptic errors. I find this absolutely absurd for a platform aimed at beginners.

author: sleemanj
author_rank: Super Contributor
timestamp: February 19, 2017, 03:57:44 am
content: Getting off topic, butQuote from: james_s on February 19, 2017, 02:11:03 amDon't know about Windows, but on my Linux boxCode:$ ls -ltrd /usr/local/stow/ard*drwxrwxr-x 8 boffin boffin 4096 May 18 2013 /usr/local/stow/arduino-1.0.5drwxrwxr-x 8 boffin boffin 4096 Sep 17 2014 /usr/local/stow/arduino-1.0.6drwxr-xr-x 10 boffin boffin 4096 Aug 28 2015 /usr/local/stow/arduino-1.6.5-r5drwxr-xr-x 11 boffin boffin 4096 Nov 4 2015 /usr/local/stow/arduino-1.6.6drwxr-xr-x 11 boffin boffin 4096 Dec 18 2015 /usr/local/stow/arduino-1.6.7drwxr-xr-x 11 boffin boffin 4096 May 10 2016 /usr/local/stow/arduino-1.6.9drwxr-xr-x 10 boffin boffin 4096 Dec 13 00:02 /usr/local/stow/arduino-1.6.13though to be fair since they all use the same preferences directory, it's a bit iffy to go backwards (usually if I need to check something in an older version I'll move my prefs out of the way first).Quote from: james_s on February 19, 2017, 02:11:03 amWell you can't maintain 100% backwards compatibility all the time, things have to change. But that said the Arduino IDE release QC process is.. well they don't have one, some releases of the IDE (eg 1.6.10) caused all sorts of problems.I wish they would have a proper release cycle, with beta releases, so that the people who are capable of debugging problems can do so, before it got to a stable release for the masses.The whole development of the IDE is a bit... weird really, for a high profile project, I think it boils down to a few "gate keeping" egos in there doing things their way, a lot of good ideas get pooh-poohed, they do IMHO crazy-ass things like writing it's build system (arduino-builder) in what really is a pretty obscure language (Go), the afore-mentioned lackadaisical release cycles...

author: james_s
author_rank: Super Contributor
timestamp: February 19, 2017, 06:07:27 am
content: I see no reason why they couldn't maintain 100% backward compatibility, even if it's at the expense of some forward progress. The Arduino platform is aimed at beginners, and a large part of the draw to the platform is the huge library of existing code. When someone downloads code someone has published and it doesn't work and spits out some cryptic error it's frustrating. A beginner friendly platform should first and foremost "just work" and not require a bunch of screwing around and troubleshooting to use code that was working for someone else. If they are going to change how something works, there should at least be a compatibility mode. I never really got into it but I do keep the IDE around for building/modifying some of the many projects that are out there and I ended up staying at an earlier version.

author: westfw
author_rank: Super Contributor
timestamp: February 19, 2017, 07:06:55 am
content: Quoteyeah, infinite backward compatibility is a nice theory. Come back and tell us how you did when you've tried to support a large project with significant development for 10 years or so...Don't forget that over this time period avr-gcc, java, windows and macos have all changed in ways that have not beenvery backward compatible...

author: james_s
author_rank: Super Contributor
timestamp: February 19, 2017, 08:29:24 am
content: Quote from: westfw on February 19, 2017, 07:06:55 am

author: westfw
author_rank: Super Contributor
timestamp: February 19, 2017, 11:50:41 am
content: QuotePeople can stay at the old version if they want... You can always install new drivers for new OSes manually, and update specific tools that stop working one at a time, and so on. Just like Dave had to do for the simple task of putting a new .hex file on a piece of turn-key hardware, causing all that pain and frustration...QuoteI don't understand the problem. I have multiple versions (on mac. I've also done it on windows, though I don't know whether I've used it enough there to see any problems.) There are some problems with "extensions" because the format of various things have changed (1.0.6 only supports AVR. The latest supports AVR, SAM3X, SAMD, ESP8266, and more), but the base install shouldn't have much of a problem.Oh, and modern versions support a "portable" option that should help. Download the .zip instead of the installer, unzip to \Program Files\Arduino-1.8.0 or wherever, and create a directory \Program Files\Arduino-whatever\portable before the first time you run the IDE. Then, when you run it it will put all its normal per-user and per-installation files under "portable" instead of the normal places in the windows environment (which are weird.) I guess this might qualify as a not-backward-compatible change, though...

author: Gustavo-ar
author_rank: Newbie
timestamp: February 20, 2017, 01:19:00 am
content: Hi!, this is my first post here, recently I have to program an atmega328p and make an programmer using an arduino nano, is very useful.I can use it in two ways: by putting the AVR in the socket, or by connecting it to a cable (leaving the socket empty).http://www.martyncurrey.com/arduino-nano-as-an-isp-programmer/

author: westfw
author_rank: Super Contributor
timestamp: February 20, 2017, 07:09:13 am
content: QuoteSigh. In Windows10, at least, you don't want to put an Arduino tree with "portable" configured into the normal ProgramFiles area, because W10 won't allow it to write anything there, and it won't work (unless you want to run it "as administrator.")It'll be OK in your personal area, or somewhere that isn't protected.Look: 1.6.13 and 1.8.1 not only both installed, but both running simultaneously!

author: westfw
author_rank: Super Contributor
timestamp: February 27, 2017, 09:13:46 pm
content: I went ahead and wrote a little windows batch script that will add the tools included with an Arduino install to your "command prompt" path, so that you can use avrdude, avr-gcc, and so on. Enjoy... (copied from other posts; may have some redundancies.)With WINAVR becoming unmaintained, various people including myself are starting to think that the easiest way of getting a basic set of avr-gcc tools installed on your Windows system is to install Arduino, and use the tools that it includes.But they're buried rather deeply, and a bit of a pain to get to.So I wrote this batch script to go out and look at your Windows (XP, 7, 8, 10) system, find the Arduino tools (1.0.x, 1.6.5+, 1.8.x), and sticks them in the search path for that "Command Prompt" session. It gets avrdude too. It doesn't copy or actually install anything, so it's pretty quick. Now, command-line access to the bare compiler isn't a particularly wonderful development environment, but it might be good for a quick start...>C:\Users\User>e:install-avr-toolsNo avr-gcc currently installed.At least one Arduino install found.Looks like C:\Program Files\Arduino1.8.0 has versionavr-gcc.exe (GCC) 4.9.2Use C:\Program Files\Arduino1.8.0 ? [y/n]>yFound avr-gccChecking tool versionsavr-gcc (GCC) 4.9.2Copyright (C) 2014 Free Software Foundation, Inc.This is free software; see the source for copying conditions. There is NOwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.avrdude: Version 6.3, compiled on Dec 16 2016 at 13:33:19Copyright (c) 2000-2005 Brian Dean,http://www.bdmicro.com/Copyright (c) 2007-2014 Joerg WunschSystem wide configuration file is "C:\Program Files\Arduino1.8.0\hardware\tools\avr\etc\avrdude.conf"C:\Users\User>https://hackaday.io/project/19935-install-avr-tools

author: rrinker
author_rank: Super Contributor
timestamp: February 27, 2017, 09:25:27 pm
content: I just have my library and sketches folders pointed to my OneDrive, that way I can access my projects from any computer, either my main desktop or the workbench computer, or even my lappy at work if I get an idea and want to put it in code while still fresh in my mind. I've done this with other programs as well, like KiCad and my model railroad CAD.

author: Nobody2
author_rank: Contributor
timestamp: March 02, 2017, 09:11:35 am
content: First thing I thought when i saw the image on twitter and the video title was: "Yep, that's why I am still using AVRStudio 4". Using the visual studio base makes it just too bloated in my opinion. Also just talking to a programmer with the newer version is too convoluted imho, but the biggest issue I have with it, is that they removed the ability to use self-build programmers like the ones I use.I'm not use about WinAVR though, I'm pretty sure my version is newer than 2010?

author: SingedFingers
author_rank: Frequent Contributor
timestamp: March 02, 2017, 10:50:41 am
content: Argh this thread makes me angry. Sorry for the rant...About a year ago I needed to program an old PIC16F684 with some code that was lying around that I wrote back in the late 1990s. Didn't want to invest in a programmer for a one off so I dug an Arduino out of the junk box and set up a bodge rig on a breadboard with the software and hardware here:http://rweather.github.io/ardpicprog/. That took about an hour to get working. I had to download and install MPLAB and fix a few things in the code but it all worked which took about an hour. Not too terrible.Then about 9 months ago I needed to use an AVR to replace a bit of relatively complex discrete logic (nothing fancy just PLC grade logic which was trivial to implement in C) in something so I grabbed a cheap USBasp programmer from a local supplier and a couple of AVRs from RS and got to work.5 hours later I was still trying to get bloody Atmel studio working. Now the day job is mainly mud wrestling with Visual Studio, which may have contributed to it because I already had VS2015 installed, and I've been using it for about 15 years now for C++ and C# and I've even built addins for it so I'm no noob when it comes to this sort of stuff. But FMH it just didn't want to work.Eventually I fired up a VirtualBox VM with Debian on it, connected the USB device to that and wrote the code with vim in about 30 minutes, compiled it with avr-gcc, burned it with avrdude and I was done. Joy to platform agility on my partNone of this was ISP programming - I didn't want to bite that one off but I can imagine the difficulty that adds.

author: Fungus
author_rank: Super Contributor
timestamp: March 02, 2017, 12:18:23 pm
content: If it's just a quick job then use the Arduino IDE. It's designed for noobs.Atmel Studio is a huge fail unless you really need to program in assembly language or whatever.

author: SingedFingers
author_rank: Frequent Contributor
timestamp: March 02, 2017, 12:30:56 pm
content: It's OK until you hit something they bastardised. Do they run it through a transpiler or something before they compile it to the final language? It feels like C++ but it's not.

author: Ian.M
author_rank: Super Contributor
timestamp: March 02, 2017, 01:01:05 pm
content: The Arduino IDE runs it through a pre-preprocessor (or bastardizer) that inserts forward declarations for functions etc. Unfortunately it frequently gets stuff wrong if you are trying to use the more advanced features of the GCC C++ language. The easy fix is to ONLY use <sketch_name>.ino to provide a list of headers to include to MAKE as the bastardizer doesn't parse any other files in the sketch. Don't put any code or declarations in the .ino file!You can then create a normal C++ project structure with all .cpp and .h files in the Arduino sketch folder, with a normal main() function and without the Arduino's enforced setup() and loop() functions. You must avoid using the filename <sketch_name>.cpp as the bastardizer will overwrite it. Also don't use the filename main.cpp.SeeGammon.com.au: How to avoid the quirks of the IDE sketch file pre-preprocessingfor details.Project headers listed in the .ino file should be 'pure' (i.e. only declare or #define stuff, not create/initialise any C objects). SeeGamedev.net: Organizing Code Files in C and C++

author: SingedFingers
author_rank: Frequent Contributor
timestamp: March 02, 2017, 01:04:33 pm
content: Thanks for the info - explained. I used a pointer once and it shit itself so I gave up and just used C

author: Ian.M
author_rank: Super Contributor
timestamp: March 02, 2017, 01:30:05 pm
content: N.B. if you are using the ArduinoIDE and are getting mysterious build errors for perfectly good code that go away if you insert a dummy function call or some other crap just before the line with the error, its because the build process can fail randomly if the path to the temp folder is too long or contains spaces,The fix is to give the IDE a temp folder in the root of the drive. Open the Arduino preferences.txt file, close the IDE, then add the lineCode:build.path=C:\tempand create the corresponding temp folder on C, with full access for your username.

author: rrinker
author_rank: Super Contributor
timestamp: March 02, 2017, 02:38:40 pm
content: I am so stealing westfw's script. Doing a one-off it's not so bad drilling through the Arduino install to find the bits, but after the first time, a script like that is a lifesaver.As for the install of the Atmel Studio - at least part of that HAS to be something they've (Atmel) has done, because I've been using Visual Studio for a long time and while the install can be time consuming, it certainly doesn't take hours.Good tip on the temp path Ian. I've come across strange hard to debug issues like that in many other unrelated things and it can be very frustrating to find the cause when everything looks just fine. My favorites are when the software reports something like "file not found" but you can manually open the path and see the file sitting right there in plain sight.

author: Fungus
author_rank: Super Contributor
timestamp: March 02, 2017, 04:47:16 pm
content: Quote from: SingedFingers on March 02, 2017, 12:30:56 pmThey do one thing before it runs: They search the files for function prototypes and insert them at the top of the file. This allows you to call functions below you in the file without adding explicit prototypes. It's usually invisible in practice.Also: The way the IDE works it's best not to try and write separate header/object files for everything. You can do it if you want but all you achieve is double the number of open files in the IDE so it gets messy. The way I do it is to just make everything as .h files (all code inlined in classes) then #include them in the main file. Separating interface from implementation doesn't gain you much in programs this size, so...Apart from that it's perfectly standard C++.PS: If you want to write in assembly language with Arduino IDE you can do that, too, but only in libraries. The IDE doesn't look for .asm files in sketch folders, only in library folders. If you put them library folders it will look for them and assemble them just fine. You have to use an external editor because the IDE won't load them in your sketch, but... you can do it.

author: HwAoRrDk
author_rank: Super Contributor
timestamp: March 02, 2017, 05:42:25 pm
content: Quote from: rrinker on March 02, 2017, 02:38:40 pmI suppose it could take hours if you've downloaded the stub 'web' installer and you have a crappy internet connection. The web installer has to download hundreds of MB of stuff, and it's not very good at giving you feedback on progress.(As an aside, personally, I have a real dislike of 'web' installers. The only advantage I can see for them is it saves on download time in cases where the user is not going to be installing a significant portion of optional modules. And they have a huge downside for if you want to archive the installer, but the vendor does not deign to make a 'full' package available. On more than one occasion I have had to hunt through temp folders to find the actual full installation files.)Another reason that just occurred to me that explains prolonged installation - Atmel Studio and Visual Studio alike - is that the installer creates a system restore point before it begins, which can be a lengthy process sometimes.

author: Fungus
author_rank: Super Contributor
timestamp: March 02, 2017, 06:35:12 pm
content: Quote from: HwAoRrDk on March 02, 2017, 05:42:25 pmSure, but Visual Studio doesn't actually give you any install options at all*. No matter what happens you're in for a 5Gb download.(*) If they did that then people might not install the Windows Phone development platformThe best part of Visual Studio is when you're on site with a client and it suddenly asks you to reconfirm your Microsoft account before it'll compile anything. And you don't have an Internet connection. Yes this happened to me.

author: rrinker
author_rank: Super Contributor
timestamp: March 02, 2017, 07:43:33 pm
content: Since when? I have 2012 Professional on this machine but I just went and ran the online installer for 2015 Professional and you do not have to install the Windows Phone crap. There are a lot of optional components you don't have to install if you don't need.And the whole ISO is only 3.8GB

author: Fungus
author_rank: Super Contributor
timestamp: March 02, 2017, 08:21:25 pm
content: Quote from: rrinker on March 02, 2017, 07:43:33 pmMaybe the "Pro" version is different...Most of the Visual-Studio-based development systems install VS Community though. I don't know about Atmel Studio but I've used a couple of others (eg. Unity) and that requires the full 5Gb-with-Windows-Phone version of VS 2015.

author: westfw
author_rank: Super Contributor
timestamp: March 03, 2017, 03:50:44 am
content: QuoteAh; if you've been using VS before trying to install AS, it can probably skip a lot of the VS-related stuff that you already have.Let's see, six .NET Framework, two SQL-related things, three C++ "redistributables", and VS 2015 Shell (isolated), making it less painful for you to install than for some of us... ("Hours" might be an exaggeration, but it certainly takes long enough that my usual procedure is to start the install, and go do something else for hours, hoping that it will be done when I come back (and not sitting at some "do you want the xyz-sub-installer to modify this computer" prompt. Sigh.)

author: Brumby
author_rank: Unknown
timestamp: March 03, 2017, 05:51:40 am
content: All this hassle in order to use some chips...?Are they actively trying todiscouragepeople??

author: Fungus
author_rank: Super Contributor
timestamp: March 03, 2017, 08:02:28 am
content: Quote from: Brumby on March 03, 2017, 05:51:40 amIt's par for the course.

author: rrinker
author_rank: Super Contributor
timestamp: March 03, 2017, 01:30:24 pm
content: Quote from: Fungus on March 02, 2017, 08:21:25 pmCommunity is exactly the same, I also tried 2015 Community (which is what I would install at home - my work laptop has Pro only because I occasionally write programs for clients) and it is the same way. If you don't click Next too quickly, there is an option to install it all or select what components you want.

author: rrinker
author_rank: Super Contributor
timestamp: March 03, 2017, 01:36:14 pm
content: Quote from: westfw on March 03, 2017, 03:50:44 amNo, I mean a bare, from scratch install of Visual Studio. I have yet to install Atmel Studio anywhere. If I take a new computer that has no version of VS on it and install VS, it takes a little while but certainly not hours. I do have a fast connection at home, but even at work where I am hampered by wireless it didn't take that long. I DO only install select components and not all the languages. If Atmel Studio auto-installs VS it could be that it just does a complete install. And then it depends on where they source the VS download from - if they have an agreement with Microsoft and host it themselves or if it just pulls from the MS download site. If it really does take that long and if it can detect you already have VS installed, the more efficient way may indeed be to just download the ISO from Microsoft and install it. I don;t really have the tools to use Atmel Studio yet but maybe I'll try installing it on an existing VS install and see what happens.

author: Brumby
author_rank: Unknown
timestamp: March 03, 2017, 02:43:41 pm
content: Quote from: Fungus on March 03, 2017, 08:02:28 amThen it would seem an opportunity exists for someone to produce a stable, functional development platform that can be reliably installed in order to attract adopters in preference to other, ratty platforms - so that their chips become first choice of developers..... or am I just dreaming?

author: Ian.M
author_rank: Super Contributor
timestamp: March 03, 2017, 02:50:33 pm
content: You are dreaming. S.O.P. is for a company that's got a usable IDE to be bought out by another that has a crappier IDE, which gets borked even further as they attempt to integrate their new acquisition's chips. Just wait till Microchip start adding AVR support to MPLAB X . . . .

author: Brumby
author_rank: Unknown
timestamp: March 03, 2017, 02:54:13 pm
content: Quote from: Ian.M on March 03, 2017, 02:50:33 pmSomehow, I just knew that was coming.

author: HackedFridgeMagnet
author_rank: Super Contributor
timestamp: March 03, 2017, 03:19:45 pm
content: The problems above have not been my experience.I will just say that I have, (currently installed across three Win 10 machines)Atmel Studio.Visual Studio. 2013 on one, 2015 on another, also 2015 express on my home machineMPLaBEclipse CDT, GCC, Open OCD (about 3 different versions)Altium 16KicadLibre OfficeMS OfficeLabviewThey all work.Altium gives me the most trouble, then maybe MS Office or MPLab.In the form of UI weirdness or very occasional crashes.I just restart the app or the the OS.

author: Brumby
author_rank: Unknown
timestamp: March 03, 2017, 11:34:16 pm
content: Restarting the Application is not so bad. Restarting the OS could be a bit more of a nuisance.The one issue that I would be concerned about is file corruption. How often has that occurred with any of the S/W you have used?

author: Fungus
author_rank: Super Contributor
timestamp: March 04, 2017, 02:33:37 pm
content: Quote from: rrinker on March 03, 2017, 01:30:24 pmYou can addextrastuff, sure, but there's no way to avoid installing a whole load of unwanted crap, eg. Visual Basic, Windows Phone Development Kit, etc.I normally have a fairly small SSD as my main boot disk so this stuff is important. An extra gig here and there soon adds up to no space left.

author: rrinker
author_rank: Super Contributor
timestamp: March 06, 2017, 02:00:01 pm
content: You most definitely do NOT have to install the Windows Phone junk.Quick and dirty screen shot. The difference is a whopping 8GB, too. Default selections under Custom takes 8GB. Add the Phone crap and it goes to 16GB. And some stuff can be pointed to a drive other than C:.SSDs are cheap these days, no sense to constrict yourself anyway. I have all that stuff, plus a full install of SQL Server, plus standard Office apps, KiCAD, Arduino IDE, and more, and it could al fit on a 256GB SSD, though I have a 512GB in this machine. Same stuff plus a few games on my home machine and that one actually DOES only have a 256GB SSD. In fact I have 2 versions of Visual Studio installed on that one because I wanted to use the OLD VB for a project (VS 6.0), but just VB and the IDE out of it.

author: Fungus
author_rank: Super Contributor
timestamp: March 06, 2017, 02:27:16 pm
content: Quote from: rrinker on March 06, 2017, 02:00:01 pmSure, if you trust the OCX Christmas special SSD to look after your important data.

author: rrinker
author_rank: Super Contributor
timestamp: March 06, 2017, 03:18:57 pm
content: All Samsungs here. My original 120GB Kingston from the lappy a few years ago still works fine as an external USB drive though.

author: Ian.M
author_rank: Super Contributor
timestamp: March 06, 2017, 04:45:13 pm
content: Here's a 'vanilla' AVR GCC ANSI C 'Hello World' under the Arduino IDE.There isn't a single Arduino specific function used. See my reply#41for how to 'decrapify' the Arduino build process.Here's "Hello_World.c":Code:/**********************************/ 'Raw' AVR GCC 'Hello World!' ** Arduino UNO ATmega328P specific ***********************************/// *** AVR chip support ***// #include <avr/pgmspace.h>#include <avr/io.h>// #include <avr/interrupt.h>#include "AVR_UART_IO.h"#define FOSC 16000000 // UNO Clock Speed// ************************#include <stdio.h>int main(void){// *** ATmega328P Serial I/O setup ***UART_Init(Baud2UBRR(9600)); //Setup serial port @9600 Baudstdin=stdout=stderr= &UARTstdio; //Assign to standard streams for stdio.h functions()// ***********************************printf("Arduino UNO ATMega328P\n""\n""Hello, world!\n");return 0;}All project files attached as an Arduino archived 'sketch'

author: Fungus
author_rank: Super Contributor
timestamp: March 06, 2017, 05:10:24 pm
content: Quote from: Ian.M on March 06, 2017, 04:45:13 pmYes, you can write a 'main()' function that overrides the one in the Arduino folder.Linkers look for several different flavors of 'main()' so you just add one that's first on the list. You'll lose the 1kHz Timr0 interrupt and millis() will stop working but you can do it.Unfortunately the linker will still include the Timer0 interrupt vector for millis() and there's no way to tell it not to. If you try to use your own interrupt vector you'll get a symbol clash when it links the program.If complete chip control is your thing then just go into %arduino_folder%\hardware\avr\cores\arduino and delete all the files. That way you get a completely clean slate to work with.(you can also create a new board variant with its own empty folder and leave the files in 'core' alone but it's more work - having multiple copies of the Arduino IDE installation is easier and it's not too big if you delete all the unwanted bootloaders, etc. Fortunately it's all in separate folders and the folder names are really obvious, like "lilypad").

author: Ian.M
author_rank: Super Contributor
timestamp: March 06, 2017, 06:22:28 pm
content: Quote from: Fungus on March 06, 2017, 05:10:24 pmYes I've already run into that and had to use a workaround:Code:// Timer0 is already used for millis() - we'll just interrupt as// soon as possible after the Timer 0 overflow ISR and call the// "Compare A" function below#define VFD_INTERRUPT_NUM TIMER0_COMPA_vect_num // to match interrupt selected below#define VFD_CONFIG_INTERRUPT (OCR0A = 0, TIMSK0 |= _BV(OCIE0A)) //Configure selected interruptThanks for the suggestion to create a new board. I don't want to have to keep multiple copies of the IDE or FUBAR the original for Arduino sketches when I'm trying to leverage 3rd party Arduino libraries to bring up new hardware addons quickly.I'll dig into the code and see if its possible to make the timer 0 vector declaration in "wiring.c" overrideable.

author: westfw
author_rank: Super Contributor
timestamp: March 06, 2017, 10:33:41 pm
content: QuoteSo... I had a near-virgin W7 VM around, so I though I'd time it. About 3.5 hours, all together.Admittedly, most of that was trying to figure out how to install the two patches that the AS installer insisted I needed, even though "Windows Update" insisted that my system was "Up to date" and had "no updates available." And a good part of that was that the VM I was going to use initially had a Windows Explorer that was so old that it couldn't download the Update Manual Installer from microsoft, or even ... a new browser :-( So, newer VM, newer Explorer, download the manual patches, let them cogitate and reboot and so on... 2 hours gone.The main part of the AS7 (web) install took a bit under an hour. Then it wanted me to reboot, and took another 20 or 30 minutes to install drivers (with about 6 "trust this content" prompts.)

author: Fungus
author_rank: Super Contributor
timestamp: March 08, 2017, 10:14:09 am
content: FWIW I just installed the new VS2017 on a laptop to see what it was like. I heard it has very fine control over what you choose to install.It's web-installer only at the moment, this is normal for VS releases - the ISO will come later.Bottom line: I chose only C++ and Windows SDK from the long list of options and 5.2Gb of disk disappeared - about the same as VS2015 without the options.I'll have a poke around it today but usually I wait for SP1 before using Visual Studio for critical work.

author: rrinker
author_rank: Super Contributor
timestamp: March 08, 2017, 01:25:14 pm
content: Exactly what I said. Had you checked the Windows Phone bits it would have been 10GB. It even tells you BEFORE you proceed, so if you just wanted to see you could have canceled and not installed.

author: Ian.M
author_rank: Super Contributor
timestamp: March 12, 2017, 11:06:09 am
content: Does anyone know of a free lightweight MS Windows front end for AVR-GDB?I've been experimenting with remote debugging a standard unmodified Arduino Uno over its built in USB serial port using the ATmega328P GDB stub:https://www.codeproject.com/Articles/1037057/Debugger-for-Arduinofrom the GDB command line.I can set breakpoints, list the current file, step and finish executing functions but its <expletive> tedious to do it from a CLI I am not too familiar with.I'm still using the Arduino IDE to build, using a custom boards.txt to add the compiler switches needed for debugging:Code:# See: http://code.google.com/p/arduino/wiki/Platforms# and: https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5-3rd-party-Hardware-specification## Note path: {Sketchbook}\hardware\uno_gdb\avr\boards.txt##############################################################uno_gdb.name=Arduino Uno (GDB debug)uno_gdb.vid.0=0x2341uno_gdb.pid.0=0x0043uno_gdb.vid.1=0x2341uno_gdb.pid.1=0x0001uno_gdb.vid.2=0x2a03uno_gdb.pid.2=0x0043uno_gdb.upload.tool=arduino:avrdudeuno_gdb.upload.protocol=arduinouno_gdb.upload.maximum_size=32256uno_gdb.upload.maximum_data_size=2048uno_gdb.upload.speed=115200uno_gdb.bootloader.tool=arduino:avrdudeuno_gdb.bootloader.low_fuses=0xFFuno_gdb.bootloader.high_fuses=0xDEuno_gdb.bootloader.extended_fuses=0x05uno_gdb.bootloader.unlock_bits=0x3Funo_gdb.bootloader.lock_bits=0x0Funo_gdb.bootloader.file=arduino:optiboot/optiboot_atmega328.hexuno_gdb.build.mcu=atmega328puno_gdb.build.f_cpu=16000000Luno_gdb.build.board=AVR_UNOuno_gdb.build.core=arduino:arduinouno_gdb.build.variant=arduino:standarduno_gdb.build.extra_flags=-g2 -gdwarf-2 -DAVR_DEBUG##############################################################and don't really want to install any all-singing all-dancing IDEs that include the kitchen sink as well.Still to do:- figure out a clean way of overriding the default Arduino AVR core WInterrupts.c so I can get debug builds to use a patched vesion to avoid conflicts when using attachInterrupt().

author: f4eru
author_rank: Super Contributor
timestamp: March 12, 2017, 12:34:46 pm
content: install all AVR-related stuff ?Code:sudo apt-get install gcc-avr gdb-avr build-essential uisp usbprog-gui simulavr avr-libc gdb-avr avrdude avrp avrprog avarice arduinoThen just confirm.And wait about 10 minutes.

author: Fungus
author_rank: Super Contributor
timestamp: March 12, 2017, 12:45:07 pm
content: Quote from: Ian.M on March 12, 2017, 11:06:09 amIf your goal is to write code that compiles onanybody'sIDE then I don't think it's possible.At the very least you'll have to modify WInterrupts.c and add a hint for the linker.(the people at Arduino should really do this...)