Help required : AVR Universal Bootloader : ATMega32 : Not Booting Application after Power OFF/ON

188 views
Skip to first unread message

Dinesh P.R.

unread,
May 18, 2011, 1:38:34 PM5/18/11
to avrub, shy...@gmail.com
Dear Shaoziyang,

Thank you very much for the wonderful bootloader for AVR.
I tried to use this bootloader for ATMega32. But I faced a problem
with this.

The following are my configurations
1. MCU - ATMega32
2. External Crystal - 11.0592MHz
3. Fuse Settings :

SPIEN CKOPT BOOTSZ1 BOOTSZ0 BOOTRST

Reset all other fuses are zero.

My intention is to have the following configuration
1. External Cystal / Resonator High Freq: Startup Time : 16CK + 64ms;
[CKSEL=1111 SUT = 11]
2. Boot Reset Vector Enabled
3. CKOPT Fuse programmed.
4. Serial Program Downloading Enabled.

I have generated the config file using AVRUBD. I compiled the
bootloader with the following settings
Freq = 11059200Hz.
Memory : 0x3800, .text section.

The project compiled successfully and I could see some codes from the
address 0x7000.

I downloaded this bootloader hex using ponyprog. After that I
downloaded an Application program using AVRUBD.
The application dowloaded successfully. On giving Reset the
Bootloader waits for some seconds and then transfers the control to
Application program successfully. The application also runs
correctly.
Later I switched off the power and then switched on after which the
application is not loading at all. Then I read the Program flash
content and saw that the first sector of the flash(0x0000 to 0x007F)
is overwritten to 0xFF(or 0x00 - I dont remember correctly). I am not
sure whether the bootloader overwrites this sector or whats happening.

Could you please provide me some guidance to debug this problem.


Also I have one more query. Currently I have set the bootloader start
address as 0x3800 (both BOOTSZ1 and BOOTSZ0 are '0' programmed. Its
my careless mistake, I assume I have to use this configuration for 2K
bytes of Bootloader where as the reality is for 2K Words. This means
I could use option BOOTSZ1 = 0 and BOOTSZ0 = 1 which will give my
bootloader start address as 0x3C00.

Is it a problem to use 0x3800 as start address for a Bootloader of
less than 2K bytes.


<<bootcfg.h>>

#ifndef _BOOTCFG_H_
#define _BOOTCFG_H_ 1

//define uart buffer's length
#define BUFFERSIZE 128

//system clock(Hz)
#ifndef F_CPU
#define F_CPU 11059200UL
#endif

//baudrate
#define BAUDRATE 57600

//Boot section start address(byte)
//define BootStart to 0 will disable this function
#define BootStart 0x7000UL

//verify flash's data while write
//ChipCheck will only take effect while BootStart enable also
#define ChipCheck 0

//In SafeMode, it will not jump to user application till update
successfully
#define SafeMode 1

//In SafeMode, it will set a flag in EEPROM
#define FlagAddr E2END

//Bootloader launch 0:comport password 1:port level
#define LEVELMODE 0

#define LEVELPORT D
#define LEVELPIN PD7
//port level 1:High 0:Low
#define PINLEVEL 0

//max wait password time = TimeOutCnt * timeclk
//timeout count
#define TimeOutCnt 10

//basic timer interval(ms)
#define timeclk 200

//max wait data time = TimeOutCntC * timeclk
//send 'C' command count
#define TimeOutCntC 50

//password length
#define CONNECTCNT 1

//password
#if LEVELMODE == 0
unsigned char ConnectKey[] = {0x64};
#endif

//comport number: 0/1/2..
#define COMPORTNo 0

//enable watchdog
#define WDG_En 0

//enable RS485/RS422 mode
#define RS485 0
//RS485/RS422 send control port
#define RS485PORT D
#define RS485TXEn PD5

//enable LED indication
#define LED_En 1
//LED control port
#define LEDPORT B
#define LEDPORTNo PB0

//some old kind of AVR need special delay after comport initialization
#define InitDelay 0

//communication checksum method 0:CRC16 1:add up
#define CRCMODE 0

//Verbose mode: display more prompt message
#define VERBOSE 1

//prompt messages
#if VERBOSE
#if LEVELMODE
const char msg6[] = "bootloader mode.";
const char msg7[] = "application mode.";
#else
//waiting for password
const char msg1[] = "waiting for password.";
#endif
//timeout
const char msg2[] = "timeout.";
//waiting for data
const char msg3[] = "waiting for data.";
//update success
const char msg4[] = "update success.";
//update fail
const char msg5[] = "update fail.";
#endif

//enable decrypt buffer
#define Decrypt 0

//crypt algorithm
//PC1_128, PC1 Cipher Algorithm with 128 bits key
#define PC1_128 1
//PC1_256, PC1 Cipher Algorithm with 256 bits key
#define PC1_256 2
//AES_128, AES Cipher Algorithm with 128 bits key
#define AES_128 3
//AES_256, AES Cipher Algorithm with 256 bits key
#define AES_256 4

#define Algorithm PC1_128

#if Decrypt

#if (Algorithm == PC1_128) || (Algorithm == AES_128)
//Define decrypt key: 128b
unsigned char DecryptKey[16] ={
0xD0, 0x94, 0x3F, 0x8C, 0x29, 0x76, 0x15, 0xD8,
0x20, 0x40, 0xE3, 0x27, 0x45, 0xD8, 0x48, 0xAD
};
#elif (Algorithm == PC1_256) || (Algorithm == AES_256)
//Define decrypt key: 256b
unsigned char DecryptKey[32] ={
0xD0, 0x94, 0x3F, 0x8C, 0x29, 0x76, 0x15, 0xD8,
0x20, 0x40, 0xE3, 0x27, 0x45, 0xD8, 0x48, 0xAD,
0xEA, 0x8B, 0x2A, 0x73, 0x16, 0xE9, 0xB0, 0x49,
0x45, 0xB3, 0x39, 0x28, 0x0A, 0xC3, 0x28, 0x3C
};

#endif

#endif

#endif

<<bootcfg.h ends>>

Thank you
Reply all
Reply to author
Forward
0 new messages