Nut/OS  4.10.3
API Reference
AVR Target Programming

AVR target programming via SPI. More...

Collaboration diagram for AVR Target Programming:

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.

Detailed Description

AVR target programming via SPI.


Define Documentation

#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:

  • Least significant byte is fuse low byte.
  • Second byte is fuse high byte.
  • Third byte is fuse extended byte.
  • Most significant byte is not used.

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:

  • Least significant byte is fuse low byte.
  • Second byte is fuse high byte.
  • Third byte is fuse extended byte.
  • Most significant byte is not used.

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.


Function Documentation

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.

Returns:
0 on success, -1 otherwise.

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.

Parameters:
actWhen 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.

Parameters:
onWhen not 0, the reset line will be activated.

Definition at line 276 of file avrtarget.c.

uint32_t AvrTargetCmd ( uint32_t  cmd)

Send programming command and return response.

Parameters:
cmd4-byte command.
Returns:
4-byte response.

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.

Returns:
0 on success, -1 otherwise.

Definition at line 310 of file avrtarget.c.

References AVRCMD_PROG_ENABLE, and AvrTargetCmd().

Here is the call graph for this function:

uint32_t AvrTargetSignature ( void  )

Retrieve the target's signature.

Returns:
Signature in the 3 least significant bytes.

Definition at line 327 of file avrtarget.c.

References AVRCMD_READ_SIGNATURE_BYTE, and AvrTargetCmd().

Here is the call graph for this function:

uint32_t AvrTargetFusesRead ( void  )

Retrieve the target's fuses.

Returns:
Fuse bits in the 3 least significant bytes.

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().

Here is the call graph for this function:

uint32_t AvrTargetFusesWriteSafe ( uint32_t  fuses)

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.

Parameters:
fusesFuse 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().

Here is the call graph for this function:

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.

Parameters:
tmoMaximum number of milliseconds to wait.
Returns:
0 on success, -1 on time out.

Definition at line 398 of file avrtarget.c.

References AVRCMD_POLL_READY, AvrTargetCmd(), and NutSleep().

Referenced by AvrTargetChipErase(), and AvrTargetPageWrite().

Here is the call graph for this function:

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.

Returns:
0 on success, -1 on time out.

Definition at line 421 of file avrtarget.c.

References AVRCMD_CHIP_ERASE, AVRTARGET_CHIPERASE_TIMEOUT, AvrTargetCmd(), and AvrTargetPollReady().

Here is the call graph for this function:

void AvrTargetPageLoad ( uint32_t  page,
CONST uint8_t data 
)

Load target's program memory page buffer.

Parameters:
pageProgram memory page number.
dataPoints 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().

Here is the call graph for this function:

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.

Parameters:
pageProgram memory page number.
Returns:
0 on success, -1 on time out.

Definition at line 459 of file avrtarget.c.

References AVRCMD_WRITE_PROG_MEM_PAGE, AVRTARGET_PAGEWRITE_TIMEOUT, AvrTargetCmd(), and AvrTargetPollReady().

Here is the call graph for this function:

int AvrTargetPageVerify ( uint32_t  page,
CONST uint8_t data 
)

Verify program memory page contents.

Parameters:
pageProgram memory page number.
dataPoints to a buffer with the expected contents.
Returns:
0 if the buffer contents equals the memory page contents or -1 if it doesn't.

Definition at line 475 of file avrtarget.c.

References AVRCMD_READ_PROG_MEM_HI, AVRCMD_READ_PROG_MEM_LO, AVRTARGET_PAGESIZE, and AvrTargetCmd().

Here is the call graph for this function: