AVR target programming via SPI. More...
Defines | |
#define | AVRTARGET_CHIPERASE_TIMEOUT 200 |
Maximum time (in milliseconds) to wait for chip erase done. | |
#define | AVRTARGET_PAGEWRITE_TIMEOUT 10 |
Maximum time (in milliseconds) to wait for page write done. | |
#define | AVR_FUSES_NEVER_PROG 0x00F88062UL |
Safe fuse programming mask. | |
#define | AVR_FUSES_ALWAYS_PROG 0x0000201DUL |
Safe fuse unprogramming mask. | |
#define | AVRTARGET_SPI_MODE 0 |
#define | AVRTARGET_SPI_RATE 500000 |
#define | AVRTARGET_NO_SPI_DEVICE |
Functions | |
int | AvrTargetInit (void) |
Initialize programming interface. | |
void | AvrTargetSelect (ureg_t act) |
Set or clear the chip select line. | |
void | AvrTargetReset (ureg_t act) |
Set or release the target's reset line. | |
uint32_t | AvrTargetCmd (uint32_t cmd) |
Send programming command and return response. | |
int | AvrTargetProgEnable (void) |
Enable target's programming mode. | |
uint32_t | AvrTargetSignature (void) |
Retrieve the target's signature. | |
uint32_t | AvrTargetFusesRead (void) |
Retrieve the target's fuses. | |
uint32_t | AvrTargetFusesWriteSafe (uint32_t fuses) |
Program the target's fuses in a safe way. | |
int | AvrTargetPollReady (unsigned int tmo) |
Poll target for becoming ready. | |
int | AvrTargetChipErase (void) |
Erase the target chip. | |
void | AvrTargetPageLoad (uint32_t page, CONST uint8_t *data) |
Load target's program memory page buffer. | |
int | AvrTargetPageWrite (uint32_t page) |
Write page buffer contents to program memory. | |
int | AvrTargetPageVerify (uint32_t page, CONST uint8_t *data) |
Verify program memory page contents. |
AVR target programming via SPI.
#define AVRTARGET_CHIPERASE_TIMEOUT 200 |
Maximum time (in milliseconds) to wait for chip erase done.
Definition at line 66 of file avrtarget.c.
Referenced by AvrTargetChipErase().
#define AVRTARGET_PAGEWRITE_TIMEOUT 10 |
Maximum time (in milliseconds) to wait for page write done.
Definition at line 73 of file avrtarget.c.
Referenced by AvrTargetPageWrite().
#define AVR_FUSES_NEVER_PROG 0x00F88062UL |
Safe fuse programming mask.
If a bit is set in this mask, the corresponding fuse should never be programmed to 0.
Used in AvrTargetFusesWriteSafe() to avoid dead chips. However, it is still possible to break hardware. Triple check any new fuse configuration.
This unsigned long value is interpreted as follows:
Definition at line 93 of file avrtarget.c.
Referenced by AvrTargetFusesWriteSafe().
#define AVR_FUSES_ALWAYS_PROG 0x0000201DUL |
Safe fuse unprogramming mask.
If a bit is set in this mask, the corresponding fuse should never be left unprogrammed (set to 1).
Used in AvrTargetFusesWriteSafe() to avoid dead chips. However, it is still possible to break hardware. Triple check any new fuse configuration.
This unsigned long value is interpreted as follows:
Definition at line 112 of file avrtarget.c.
Referenced by AvrTargetFusesWriteSafe().
#define AVRTARGET_SPI_MODE 0 |
Definition at line 115 of file avrtarget.c.
#define AVRTARGET_SPI_RATE 500000 |
Definition at line 119 of file avrtarget.c.
#define AVRTARGET_NO_SPI_DEVICE |
Definition at line 219 of file avrtarget.c.
int AvrTargetInit | ( | void | ) |
Initialize programming interface.
Sets the configured SPI mode and rate. This must be called before using any other routine in this module.
Definition at line 231 of file avrtarget.c.
void AvrTargetSelect | ( | ureg_t | act | ) |
Set or clear the chip select line.
Must be called before sending programming commands to the target device, even if no chip selects are implemented by the hardware. Beside activating an optional chip select, this routine will also properly initialize the SPI hardware.
act | When 0, the chip will be deactivated and the serial peripheral interface may be used to communicate with another device. When not 0, the SPI bus is allocated for the attached AVR target. |
Definition at line 258 of file avrtarget.c.
void AvrTargetReset | ( | ureg_t | act | ) |
Set or release the target's reset line.
The target must be held in reset state during programming.
on | When not 0, the reset line will be activated. |
Definition at line 276 of file avrtarget.c.
Send programming command and return response.
cmd | 4-byte command. |
Definition at line 290 of file avrtarget.c.
Referenced by AvrTargetChipErase(), AvrTargetFusesRead(), AvrTargetFusesWriteSafe(), AvrTargetPageLoad(), AvrTargetPageVerify(), AvrTargetPageWrite(), AvrTargetPollReady(), AvrTargetProgEnable(), and AvrTargetSignature().
int AvrTargetProgEnable | ( | void | ) |
Enable target's programming mode.
Definition at line 310 of file avrtarget.c.
References AVRCMD_PROG_ENABLE, and AvrTargetCmd().
uint32_t AvrTargetSignature | ( | void | ) |
Retrieve the target's signature.
Definition at line 327 of file avrtarget.c.
References AVRCMD_READ_SIGNATURE_BYTE, and AvrTargetCmd().
uint32_t AvrTargetFusesRead | ( | void | ) |
Retrieve the target's fuses.
Definition at line 346 of file avrtarget.c.
References AVRCMD_READ_FUSE_BITS, AVRCMD_READ_FUSE_EXT_BITS, AVRCMD_READ_FUSE_HI_BITS, and AvrTargetCmd().
Program the target's fuses in a safe way.
Fuses with corresponding bits set in AVR_FUSES_NEVER_PROG will never be programmed. Fuses with corresponding bits set in AVR_FUSES_ALWAYS_PROG will always be programmed.
fuses | Fuse bits are expected in the 3 least significant bytes, Lower fuses in the LSB, followed by the high fuses and last no least the extended fuses. |
Definition at line 370 of file avrtarget.c.
References AVR_FUSES_ALWAYS_PROG, AVR_FUSES_NEVER_PROG, AVRCMD_WRITE_FUSE_BITS, AVRCMD_WRITE_FUSE_EXT_BITS, AVRCMD_WRITE_FUSE_HI_BITS, and AvrTargetCmd().
int AvrTargetPollReady | ( | unsigned int | tmo | ) |
Poll target for becoming ready.
May switch to another thread while waiting. After switching back to the calling thread, the SPI is re-selected.
tmo | Maximum number of milliseconds to wait. |
Definition at line 398 of file avrtarget.c.
References AVRCMD_POLL_READY, AvrTargetCmd(), and NutSleep().
Referenced by AvrTargetChipErase(), and AvrTargetPageWrite().
int AvrTargetChipErase | ( | void | ) |
Erase the target chip.
Be aware, that this routine calls AvrTargetPollReady(), which may initiate a context switch while waiting for the erase to finish.
Definition at line 421 of file avrtarget.c.
References AVRCMD_CHIP_ERASE, AVRTARGET_CHIPERASE_TIMEOUT, AvrTargetCmd(), and AvrTargetPollReady().
Load target's program memory page buffer.
page | Program memory page number. |
data | Points to the data. |
Definition at line 435 of file avrtarget.c.
References AVRCMD_LOAD_PROG_MEM_PAGE_HI, AVRCMD_LOAD_PROG_MEM_PAGE_LO, AVRTARGET_PAGESIZE, and AvrTargetCmd().
int AvrTargetPageWrite | ( | uint32_t | page | ) |
Write page buffer contents to program memory.
Calls AvrTargetPollReady(), which may initiate a context switch while waiting for the page write to finish.
page | Program memory page number. |
Definition at line 459 of file avrtarget.c.
References AVRCMD_WRITE_PROG_MEM_PAGE, AVRTARGET_PAGEWRITE_TIMEOUT, AvrTargetCmd(), and AvrTargetPollReady().
Verify program memory page contents.
page | Program memory page number. |
data | Points to a buffer with the expected contents. |
Definition at line 475 of file avrtarget.c.
References AVRCMD_READ_PROG_MEM_HI, AVRCMD_READ_PROG_MEM_LO, AVRTARGET_PAGESIZE, and AvrTargetCmd().