SD ATmega and Tiny program loading code . Help

Thread Starter

ExpL0siV3Man79

Joined Jun 4, 2018
93
.ino file compiles and converts into a .hex file , the I copy the ones and zeros to a .txt file and load it on the SD card . The Attiny85 reads those values from the SD and by using SPI programs the ATmega . Is this even doable? I ve seen people discussing about it online but no one ever gave a clear answer . Is there any modification needed so this concept works ? What about the file types ? Is txt okay for programming ? I m using the arduino IDE for programming
 

Thread Starter

ExpL0siV3Man79

Joined Jun 4, 2018
93
The .hex file's values should be written to the ATmega EEPROM as code . How can I do this with arduino IDE?
I mean the ATtiny85 will use the SD library , SPI library , read a file from SD card and then write the same file to the ATmega . I dont understand the writting process
 

Thread Starter

ExpL0siV3Man79

Joined Jun 4, 2018
93
So the process is going like this
1) Load the .hex file to the SD card via the computer (included file)
2)Use an Arduino (instead of the ATtiny85 for testing) to erase all data from the ATmega using code (target microcontroller)
3)Plug the SD card and make the arduino read each row of the file independently and load it to the target micro (row by row)
4)I should be done here I think :/ . I am just having trouble with the code . I cant find something online using the arduino IDE

P.S. Is there a way I can erase all data from a micro controller's flash using hardware? shorting some pins or something ? I am talking about ATmega328p if this is helpful
 

Attachments

Last edited:

danadak

Joined Mar 10, 2018
4,057
Not aware of any internal HW that can be used to erase FLASH.

You could work up an external ATTINY to load the erase flash command, page 347
onward discusses programming etc...of datasheet.

Regards, Dana.
 

LesJones

Joined Jan 8, 2017
4,511
I think the Arduino compiler produces a source file and .HEX file that does not load to location zero in the ATmega as location zero would normaly contain the boot loader. (Or just a jump to the start of the boot loader at some other memory address.) Normaly you would load the hex file starting at location zero if you were programming the ATmega using AVRdude or similar programming software. Also you talk about loading the .HEX file into EEPROM. The program code would normally be loaded into flash memory.

Les.
 

Thread Starter

ExpL0siV3Man79

Joined Jun 4, 2018
93
yes forget about the eeprom thing . I will download the AVRdude app and see what i can do with it

EDITED : I cant download the AVRdude app :( every site that google gives me is total junk , please give me a valid link for download
 
Last edited:

MrSoftware

Joined Oct 29, 2013
2,273
I haven't done it myself, but I believe you can do it with a properly written bootloader. When chip boots, write your bootloader to check for an SD card and if present copy the contents to a specific location in the EEPROM. If there is no SD card then jump execution to that same location in EEPROM. I may have missed some details, but I think this general idea would work.

As for files on the SD card; it doesn't matter what you name the file, the name has no effect whatsoever on the data in the file. But if you use a file system then your bootloader will need to know how to read the file system to figure out where the actual data is. The cheap and dirty way out may be to just dump data to the SD card starting at some specific address, then have your bootloader look at that address for data. Maybe make the first few bytes something specific so you can tell if it's actually data that you're expecting, or just some random SD card that the user inserted.
 

Thread Starter

ExpL0siV3Man79

Joined Jun 4, 2018
93
there seems to be this kind of command that allows me to write on the microcontroller flash memory . But as far as I am concerned this command would write on the flash memory of the programmer micro , not the target . How can I write on the flash of the target micro?
 

LesJones

Joined Jan 8, 2017
4,511
You do not specify what "this kind of command" is so it is not possible to say what it does.
1 - Are you just trying to write a .HEX file into the flash memory of an ATmega microcontroller ?
2 - Must this be done from an SD card ?

Les.
 

LesJones

Joined Jan 8, 2017
4,511
This is what I use to program 8 bit Atmel microcontrollers.

IMG_1540 (Medium).JPG

The small board at the top is a USBASP programmer bought from Ebay. The board below contains a home built version of the USBASP programmer using an ATmega8 on the top part. The bottom is just sockets to plug in the chips to be programmed. the 10 way cable at the left just connects the sockets with the programmer part using the standard 10 pin programming connector. So I can also use this board to program a chip in circuit or connect the sockets to an external programmer. (Such as the one from ebay.) Bothe of these programmers connect to the PC with a USB cable and I use the AVRDUDE program with them .

Les.
 

Thread Starter

ExpL0siV3Man79

Joined Jun 4, 2018
93
yeah sorry my mistake i forgot to paste the link from the arduino site : https://www.arduino.cc/reference/en/language/variables/utilities/progmem/
Yes I want to write a .hex file to the target uC 's flash
It would be really nice if I can do it from an SD card , if not I am open to every other opinion
Remember the process goes like this SD => Attiny85 reads the file and sends it to target bit by bit => Atmega has the file(code) in its flash and executes the code until new code comes in
 
Top