I am very new to the arduino, however I am fluent in avr assembly.
I have a very small board with programming pins RX,TX,DTR, 5V, and GND.
I can program code into this board using the arduino IDE with a usbtoTTL interface.
There are no header pins on the board going to MOSI, MISO, SCK and RST,
so if the bootloader is erased, well......
Question:
How can I program my own hex file into this board using avrdude (using the arduino bootloader) while connected to the bootloader pins. I do not want to solder very tiny wires to mosi, miso, sck and rst if I don't have to.
If I try to program my code from the arduino IDE, it always compiles the existing sketch first before programming it,
therefore my hex file won't be programmed, the existing sketch hex will be programmed.
I would like the capability of reading and writing the atmega328P using the arduino bootloader and avrdude. (I don't want to use the arduino IDE to program it)
I searched and I am not certain that avrdude will program the device using the arduino bootloader.
Any help is greatly appreciated.
Why would you need to solder to the ICSP pins? Just stuff some small wires in. Sometimes the upload will fail but you only need to succeed most of the time. In the factory, they use pogo pins.
Are you asking how to program a completely blank part, using only Rx, Tx, and DTR? If so, the answer is "You can't". A blank part can only be programmed using the ICSP (SPI) connection.
If there is time to change your board, the new ATTiny parts, like the 1614, 3216, etc. have a new single-pin programming interface (UPDI) that allows ANYTHING on the chip to be programmed with only GND and one signal connection. They are fabulous! And dirt cheap ($0.65 in qty one for a part with 16K FLASH, 1KRAM, 256bytes EEROM).
Just want to know if there is a way to program and read the chip without using the IDE but still using the bootloader and bootloader programming pins. (DTR, RX,TX, GND, 5V)
newmguy:
Just want to know if there is a way to program and read the chip without using the IDE but still using the bootloader and bootloader programming pins. (DTR, RX,TX, GND, 5V)
Of course! You can either run avrdude from the command line, or write your own download program, provided the bootloader is already loaded into the 328. The protocol is simple, and well documented.
In the Arduino IDE, go to File > Preferences, find the setting "Show verbose output during:" and check "Upload". Compile and upload any sketch and you will see the actually command used for avrdude to upload the hex file. Copy that command and substitute your hex file.
thanks again, I got it working. Avrdude verifies afterwards.
Programs only at 57600 (I was trying with 115200 with no luck).
I did notice that the chip does not erase, only the code in the hex file is programmed, and the other flash space is left as it was (with older code present)
I guess the bootloader will not allow whole flash erase, just a page at a time depending on the incoming hex.
I even tried a totally blank (FF's) flash file, didn't even program one byte.
I am aware that the bootloader is protected (BLB12, BLB11 are programmed), however I was hoping to erase the entire flash (with the exception of the bootloader of course)
This board is using the same ISP pins to do the SPI communication on the max7456,
therefore programming via ISP is not possible due to bus contention.
The board designer should have installed inline resistors on the SPI lines going to the max7456 chip.
Any advice on how I can erase the atmega328p would be appreciated.
If you erase the entire flash, you will erase the bootloader. I doubt that is possible with the bootloader installed, it probably checks to make sure not to erase itself.
The best I've been able to do is erase everything except a single bit, by writing all 0xFF except for 0xFE in memory location 0000, and attempting to write 0xFE within the first page of the bootloader. Avrdude gives a verification error because the bootloader cannot be overwritten, leaving everything blank except for location 0000. This was tested on a Nano loaded with the Uno bootloader, and will program properly afterwards. Attached is the .hex file I used, renamed as .txt because apparently I cannot post hex files.
RayLivingston:
There is a command line option to force a full chip erase, if you bother to take a few seconds to Google for the avrdude user manual....
Regards,
Ray L.
why the attitude?
I am not a novice when it comes to avr and avrdude.
If you knew about bootloaders, then you would know that there are fuses to protect against accidentally erasing the bootloader. This is somehow stopping the flash from being erased.
Do you think I haven't tried the command line option "-e"?
david_2018:
If you erase the entire flash, you will erase the bootloader. I doubt that is possible with the bootloader installed, it probably checks to make sure not to erase itself.
The best I've been able to do is erase everything except a single bit, by writing all 0xFF except for 0xFE in memory location 0000, and attempting to write 0xFE within the first page of the bootloader. Avrdude gives a verification error because the bootloader cannot be overwritten, leaving everything blank except for location 0000. This was tested on a Nano loaded with the Uno bootloader, and will program properly afterwards. Attached is the .hex file I used, renamed as .txt because apparently I cannot post hex files.
Thank you for your response.
Sounds like it should work as long as one byte is not FF, the page will be written.
I tried something like this with a blank file I made. One with zeros, and one with FF's. avrdude does not write the file with FF's to the flash, it will however write it to the eeprom.
The file with all 00's writes to both flash and eeprom.
I did correct this by removing a component on the board that was using the 4 ISP lines (MISO, MOSI, SCK, RST)
Erased the chip and then re-installed the bootloader. Double checked the fuses and bootloader lock bits, everything is good, even when I re-installed the small smd component sharing the ISP lines It still programs in ISP mode or with the bootloader.
If the erase command is executed in avrdude ("-e"), it won't hurt the bootloader since the BLLB's are programmed.