[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] __checksum
From: |
Bob Paddock |
Subject: |
Re: [avr-gcc-list] __checksum |
Date: |
Thu, 29 May 2008 14:13:03 -0400 |
> I have been successfully porting the old code from IAR to AVR GCC except for
> the followings:
> extern flash unsigned short __checksum;
If your 'checksum' is the last thing after your program,
the equivalent in avr-gcc is __data_log_end[1].
You appear to be trying to do the same as this code:
#if( USE_CRC_FLASH_CHECK > 0 )
uint16_t __data_load_end[1]; /* Defined by the linker script. Set to
address of last byte of .text+.data section */
#include <util/crc16.h>
static __inline__ uint16_t crc_flash_check_has_error( void );
static __inline__ uint16_t crc_flash_check_has_error( void )
{
uint8_t byte_u8;
uint16_t crc_u16, i;
uint16_t flash_end_u16 = (uint16_t) &(__data_load_end[0]);
LED_ASSERT();/* Indicate CRC is in progress after putting in new
batteries or bootloading */
for( crc_u16 = i = 0; i < flash_end_u16; i++)
{
WATCHDOG_FEED();
byte_u8 = pgm_read_byte( i );
crc_u16 = _crc_xmodem_update( crc_u16, byte_u8 );
}
LED_DEASSERT();
if( pgm_read_word( flash_end_u16 ) != crc_u16 )
{
return( 1 );/* Bad CRC of memory */
}
else
{
return( 0 );/* Good CRC */
}
}
#endif
In your Makefile use this to populate the CRC your 'Checksum' value:
%.hex: %.elf
@echo
@echo $(MSG_FLASH) $@
$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
ifeq ($(USE_CRC_FLASH_CHECK),1)
mv $@ $(TARGET).org.hex
srec_cat $(TARGET).org.hex -Intel -Little_Endian_CRC16 -max
$(TARGET).org.hex -Intel -Fill 0xFF -Over $(TARGET).org.hex -Intel
-Cyclic_Redundancy_Check_16_XMODEM -Output $(TARGET).hex -Intel
endif
That way the whole mess is automatic, you don't have to figure out the
CRC each time you change the code.