AVR Universal Bootloader

Go To Last Post
25 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

Any one succeeded using this bootloader project located on this PAGE

I need to use it with ATmega16, need to know how to setup bootloader parameters such as baudrate and others, and how to use those files to build a successful bootloader.

If an avr freak succeeded using it, create a simple tutorial for us.

Thanks

Signature: We need more peripherals in DIP packages. Namely, USB, 12-bit ADC, 16-bit timer, cheaper tool as a programmer/debugger coz STK600 is expensive! Atmel Studio 5/6 sucks! coz it brings MS visual studio crap to AVR world..

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You did READ the readme.html in the ZIP file didn't you? It explains all the configuration parameters and the author has even had the good sense to break them all out into an easily editable and well documented bootcfg.h - how could it have been made any easier to configure?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

HOW DID I MISS IT :oops:

Signature: We need more peripherals in DIP packages. Namely, USB, 12-bit ADC, 16-bit timer, cheaper tool as a programmer/debugger coz STK600 is expensive! Atmel Studio 5/6 sucks! coz it brings MS visual studio crap to AVR world..

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I know only this bootloader:

https://www.avrfreaks.net/index.p...

The only thing, which you can configure, was the pins which defined as RXD and TXD (any pin allowed) or if only one pin for both.
The baudrate was detected automatically.
No other things must be configured.

Because its written in assembler it need below 256 words of Flash.

Specially care was taken against accidentally lockout (overwriting or disabling) and unintentionally executing (a whole string must match, not only a single character like on other bootloaders).

Peter

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, actually I have been working with this bootloader the latest days and it seems to be working fine.

Create a new project in AVR-studio and add the three bootloader files.

The settings in the bootcfg-file depends on what you want to do, i think it's explained pretty good in the readme-file.

You have to change the startaddress in your make-file
Program the bootloader with AVR-studio and set the correct fuses.

Flash your application hexfile with "AVRUBD"

The software for flashing files it's a little bit strange but it seems to work fine so far.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Its working now, the application crashes sometimes, may be because I am using USB-RS232 dongle... If I had this timer component, I will try to prevent it from crashing while debugging the delphi code.

One thing to mention here:

From the datasheet, lookup the start address of the bootloader after you compile:

For me I had to go to Memory Settings and create memory segment (.text) where bootloader starts. In my case it is 0x1E00 in order to force the bootloader to jump to the main program, if not added, the bootloader loops for ever.

I tried level = 1 instead of 0, but it wrked for the first time, and refused working after that !

Any way, this bootloader is really nice and works fine afterall 8)

Now I am trying the fast bootloader, and it doesn't work for me, I will keep trying and see what I get.

Thank you all for helping me out.

Signature: We need more peripherals in DIP packages. Namely, USB, 12-bit ADC, 16-bit timer, cheaper tool as a programmer/debugger coz STK600 is expensive! Atmel Studio 5/6 sucks! coz it brings MS visual studio crap to AVR world..

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

metal wrote:
Now I am trying the fast bootloader, and it doesn't work for me, I will keep trying and see what I get.

Have you set the right pins for your wiring ?

I have always used PB0/PB1 on my example code.

Peter

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks peter,

I will try with it tonight

Signature: We need more peripherals in DIP packages. Namely, USB, 12-bit ADC, 16-bit timer, cheaper tool as a programmer/debugger coz STK600 is expensive! Atmel Studio 5/6 sucks! coz it brings MS visual studio crap to AVR world..

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

danni wrote:
I know only this bootloader:

https://www.avrfreaks.net/index.p...

The only thing, which you can configure, was the pins which defined as RXD and TXD (any pin allowed) or if only one pin for both.
The baudrate was detected automatically.
No other things must be configured.

Because its written in assembler it need below 256 words of Flash.

Specially care was taken against accidentally lockout (overwriting or disabling) and unintentionally executing (a whole string must match, not only a single character like on other bootloaders).

Peter

Peter, I allready post my appreciate and a question @ http://www.mikrocontroller.net/t... but I want to dublikate it here. It is a really good and stable solution especially 1wire option.

Now I designed DS2450 ADC emulator based on Tiny45 and 1wire bootloading
is especially interesting for me. But in your 1wire variant you excluded
TTL-RS232 level converter, so the data is inverted for 1wire case. It is
not quite suitable. What I need to correct in the bootloader code to
make it work with, say max232?

Thanks again in advance,
Vladimir.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kabron wrote:
But in your 1wire variant you excluded
TTL-RS232 level converter, so the data is inverted for 1wire case. It is
not quite suitable. What I need to correct in the bootloader code to
make it work with, say max232?

You must only change the io level macros:

...
.if ONEWIRE
.macro  IOPortInit
        cbi     SRX_PORT, SRX
;        sbi     SRX_PORT, SRX           ; weak pullup on
        cbi     SRX_DDR, SRX            ; as input
.endmacro
.macro  TXD_0
        sbi     SRX_DDR, SRX            ; strong pullup = 0
.endmacro
.macro  TXD_1
        cbi     SRX_DDR, SRX            ; weak pullup = 1
.endmacro
.macro  SKIP_RXD_0
        sbic    SRX_PIN, SRX
;        sbis    SRX_PIN, SRX            ; low = 1
.endmacro
.macro  SKIP_RXD_1
        sbis    SRX_PIN, SRX
;        sbic    SRX_PIN, SRX            ; high = 0
.endmacro
.else
...

Also watch, that you insert a resistor (e.g. 1k) from the RXD output of the MAX232 to the AVR.

Peter

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks a lot, Peter.
I allow myself to modify in that way:

.if ONEWIRE
.if MAX232
;========= code for use with max232 ============
.macro  IOPortInit 
        cbi     SRX_PORT, SRX 
;        sbi     SRX_PORT, SRX           ; weak pullup on 
        cbi     SRX_DDR, SRX            ; as input 
.endmacro 
.macro  TXD_0 
        sbi     SRX_DDR, SRX            ; strong pullup = 0 
.endmacro 
.macro  TXD_1 
        cbi     SRX_DDR, SRX            ; weak pullup = 1 
.endmacro 
.macro  SKIP_RXD_0 
        sbic    SRX_PIN, SRX 
;        sbis    SRX_PIN, SRX            ; low = 1 
.endmacro 
.macro  SKIP_RXD_1 
        sbis    SRX_PIN, SRX 
;        sbic    SRX_PIN, SRX            ; high = 0 
.endmacro 
.else 
;========= code for use without max232 ============
.macro	IOPortInit
	sbi	SRX_PORT, SRX		; weak pullup on
	cbi	SRX_DDR, SRX		; as input
.endmacro
.macro	TXD_0
	sbi	SRX_DDR, SRX		; strong pullup = 0
.endmacro
.macro	TXD_1
	cbi	SRX_DDR, SRX		; weak pullup = 1
.endmacro
.macro	SKIP_RXD_0
	sbis	SRX_PIN, SRX		; low = 1
.endmacro
.macro	SKIP_RXD_1
	sbic	SRX_PIN, SRX		; high = 0
.endmacro

.endif

.else
.....
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Peter, I have one more question. Trying to simulate bootloader in Proteus I found strange piece in your code:

_rx2:
	rcall	wait_bit_time		;14 + tw
	lsr	a0			;1
	SKIP_RXD_0			;1/2
	ori	a0, 0x80		;1      

There is no rjmp _rx2 command after SKIP_RXD_0. Is it correct?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Vladimir,

The ds2450 is a 16bit adc. How do you get a 16bit adc out of the tiny?

Nick

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kabron wrote:
Peter, I have one more question. Trying to simulate bootloader in Proteus I found strange piece in your code:

_rx2:
	rcall	wait_bit_time		;14 + tw
	lsr	a0			;1
	SKIP_RXD_0			;1/2
	ori	a0, 0x80		;1      

There is no rjmp _rx2 command after SKIP_RXD_0. Is it correct?

Its correct, there is an "ori a0, 0x80" after it.
This shift in the currently data bit.

Peter

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

O, I realise. Very elegant solution.
It's rather difficult to make Proteus correctly simulate bootloader due to numerous bugs in AVRs models. E.g. sbi command do not alter carry etc.
I modify your code by replacing brcc -> BRPL. Now Fboot recognise target. But baud did not measured correctly (I fix it manually) perhaps due to other bug.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

nick-123 wrote:

Hi Vladimir,

The ds2450 is a 16bit adc. How do you get a 16bit adc out of the tiny?

Nick

Really, DS2450 accuracy is 8-bit only (see datasheet) all other resolutions are fiction. Due to the speed of AVR I easily can get 12-14 bits (may be 16 with some delay) by oversampling technique.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kabron wrote:

I modify your code by replacing brcc -> BRPL.

Why?

BRCC was correct, but BRPL was wrong.

BRPL works completely different (only for signed numbers).

Peter

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

danni wrote:
Kabron wrote:

I modify your code by replacing brcc -> BRPL.

Why?

BRCC was correct, but BRPL was wrong.

BRPL works completely different (only for signed numbers).

Peter

Sorry, SBIW command in Proteus do not affect carry.
In your code:

wait_time:
	sbiw	twh:twl, 4	;2 	
;	brcc	wait_time	;2/1	
	BRPL    wait_time	;2/1  my edition
	cpi	twl, 0xFD	;1	
	brcs	_wt1		;2/1 (2)
	breq	_wt1		;2/1 (3)
	cpi	twl, 0xFF	;1	
	breq	_wt1		;2/1 (4/5)
_wt1:
	ret			;4 + 3 (rcall) = 14

BRCC doesn't executed in Proteus because the previous command do not affect carry(Proteus bug). So, infinitive loop ocured. Changing to BRPL (has the same effect i suppose) corrects the situation. On entering wait routine twh:twl is positive. When substraction result became negative (@ the same time carry =1), so skip performed correctly.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Vladimir,

Can you enlighten me on how to do that kind of oversampling?

Thanks

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

nick-123 wrote:
Hi Vladimir,

Can you enlighten me on how to do that kind of oversampling?

Thanks

There are a lot information over the Net. Try search:
"Improving ADC Resolution By Oversampling".

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

nick-123 wrote:
Hi Vladimir,

Can you enlighten me on how to do that kind of oversampling?

Thanks

Why you must hijack a completely different thread :shock: :shock: :shock:

What wrong to open a new thread with the right subject (ADC)?

Peter

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sorry, It's not my idea.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,
I tried to use AVR Universal bootloader for ATMega32. But I faced a problem with this bootloader.

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

The following fuses are programmed.
SPIEN CKOPT BOOTSZ1 BOOTSZ0 BOOTRST

Rest 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 :Flash .text 0x3800

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 byte

Please find my bootcfg.h file generated from AVRUSD.

#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

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As you say it sounds like the bootloader "false started" and erased page 0 using SPM. What is the trigger condition that makes the bootloader go into reprogramming mode?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Clawson,
Thank you for the reply. I am not sure why bootloader is going to reprogramming. I believe some RAM Variable is corrupted which might trigger this problem. I have attached the code for your reference. Please let me know if you can find some reasons from this

Attachment(s):