(updates at end)
Qualifier: I am posting this here and not on the Arduino Stack Exchange because my question is about firmware development and not Arduino development.
Project: I am designing a PCB that will use an ATmega2560 as the CPU.
Why: I am a recently minted BSEE with much more experience and knack for hardware than firmware so I'm challenging myself with the limited resources I have available to better my understanding of uCs and firmware development.
Resources: a bunch of Arduino Megas, some LEDs, jumper wires, Atmel Studio 7 (AS7), Arduino IDE, WinAVR, the internet.
Done so far: I have gone through the ArduinoISP process successfully. These are the steps I followed using the Arduino IDE...
- Uploaded ArduinoISP sketch to Programmer Mega.
- Attached 10uF cap between reset & gnd on Programmer Mega.
- Wired Target Mega ICSP connections to Programmer Mega.
- Left COMM port set to Programmer Mega.
- Choose "Arduino as ISP" as programmer and clicked "Burned Bootloader".
Thoughts: I realize now as I was typing this that all I did was re-burn the Arduino Bootloader onto the Target Mega using the "Arduino as ISP" Programmer Mega.
Done so Far Again: Written simple "Blink" program in AS7. It builds.
Wanted Outcome: My Target Mega to no longer be an Arduino Mega and be an ATmega2560 development board so that I can do pure AVR firmware development forcing me to do all the hard stuff that Arduino takes care of. I am trying to eliminate everything Arduino from the development process other than the hardware used for firmware development and "Arduino as ISP" for flash programming.
Research: Everything I have found online has to do with using AS7 to code an "Arduino" AVR uC.
- Can I used the "Arduino as ISP" Mega programmer to flash an ATMega2560 on an Arduino Mega without the Arduino Bootloader on said ATMega2560?
- Is AVR-GCC what I'll use to generate the binary file from the C source code that I will then flash?
- Is my "Blink" example above using anything "Arduino"?
- Am I correct in my thinking that if I can get my Arduino Mega to not be recognized by the Arduino IDE but still successfully flash code to it and control it I've achieved my "wanted outcome"?
UPDATE: I was having issues setting up AVRDude as an External Tool on AS7. I followed all the directions I could find carefully and the output would just be blank. I figured out it was because I had the Arduino IDE installed as a Windows App so AS7 could not follow the AVRdude.exe path. I'm now having issues with opening AVRdude.conf but ecstatic I at least had one small success.
UPDATE2: Had the path wrong for AVRdude.conf. Using the Arduino IDE with "verbose output for upload" selected I uploaded blank code and the top line of the output message contained the paths I needed.
UPDATE3: I was getting the classic stk500_getsync():not in sync error and it was a baud rate issue. I had 115200 which I'm pretty sure is the baud rate that Arduino IDE uses to upload a sketch to a Mega but the bootloader is burned at a 19200 baud rate. Since I'm using "Arduino as ISP" it's burning the entire flash memory not just uploading the source code. (note:I was still having issues syncing even after changing the baud rate and it was because the decoupling cap connections on the reset pin of the Programmer Mega were sketchy. Bent the ends of the legs so it would fit more snuggly in the Mega headers.)
UPDATE4: My ArduinoISP programmer runs but my target still isn't blinking. Studied the AVRdude output and saw that it could not find the main.hex file. I looked in the project directory of Atmel studio and there is no main.hex file. In the external tool argument had to change ItemFileName.hex to TargetName.hex. So upload successful but my target still doesn't blink.
UPDATE5: IT BLINKS!!!!! So I gave up on my initial pursuit and attempted to just make one Arduino Mega blink using the other as an ISP programmer. I noticed that AVRdude reads the fuse values before it writes to them so I took an Arduino Mega that I knew was still configured as an Arduino and uploaded my blink program to it. It didn't start blinking, but I took the fuse values it read and included those in my external tool argument. Re-uploaded and huzzah my mega blinks. This is my argument (also found this great link that helps to understand everything in the argument)
-U lfuse:w:0xFF:m -U hfuse:w:0xD8:m -U efuse:w:0xFD:m -e -v -patmega2560 -carduino -PCOM11 -b19200 -D -Uflash:w:"$(ProjectDir)Debug\$(TargetName).hex":i -C"C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"
Next Steps: Figure out how to get an active debugging session in AS7 with on-chip debugger of ATmega2560 (heading to datasheet now)