[En-Nut-Discussion] EEPROM accessable via Bootloader
PragmaLab
info at pragmalab.nl
Wed Dec 6 18:14:13 CET 2006
Hello Jason,
> Is there a set of EEPROM Access functions (simple read and
> write byte functions would suffice) with very little overhead
> that I can use for the bootloader. Obviously, I could use
> the conventional method used in my main application, but
> would prefer a less costly approach.
I used the 'avr-objdump' tool to extract the assembler code from the libc.a
to be sure to keep the code small and to avoid dependancies with other
routines (bootloader should be 100% self-containing in our case)
See below for the result for a Mega2561 (I used the method for the Mega128
as well). You can use it with GCC and ICC.... disadvantage is that it is
target-dependant.....
Best regards,
Rob van Lieshout
/*********************************************************/
/* EEPROM routines */
/*********************************************************/
/*!
* \brief Write a byte in EEPROM
*
* Extraction and disassembling was done by using the avr-objdump
tool:
*
* WinAVR\bin\avr-objdump -d ..\avr\lib\avr5\libc.a >
disassembled.txt
*
* Copy the ee_wb disassembled code from 'disassembled.txt' and paste
it in this source file,
* (don't copy the last 'ret' since the assembly code is encapsulated
in this 'C'-function)
*
* \note These routines work ONLY for the Mega256 (register addresses)
*/
void Beeprom_write_byte(void* ptAddress, unsigned char DataByte)
{
asm ("\n\t"
"sbic 0x1f, 1\n\t"
"rjmp .-4\n\t"
"out 0x22, r27\n\t"
"out 0x21, r26\n\t"
"out 0x20, r0\n\t"
"adiw r26, 0x01\n\t"
"in r0, 0x3f\n\t"
"cli\n\t"
"sbi 0x1f, 2\n\t"
"sbi 0x1f, 1\n\t"
"out 0x3f, r0\n\t"
);
}
/*!
* \brief Read a byte from EEPROM
*
*/
unsigned char Beeprom_read_byte(void* ptAddress)
{
asm ("\n\t"
"sbic 0x1f, 1\n\t"
"rjmp .-4\n\t"
"out 0x22, r27\n\t"
"out 0x21, r26\n\t"
"sbi 0x1f, 0\n\t"
"adiw r26, 0x01\n\t"
"in r0, 0x20\n\t"
);
}
More information about the En-Nut-Discussion
mailing list