Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Bootloader

Status
Not open for further replies.

Berroa Ferenc

New Member
Hi to all:

I kindly ask, if any of you work with the Oshonsoft bootloader, please post an example of how to work with it. In my particular case I use PIC18F4620.

I try with this config but no results.

model:18f4620
flash:65536
eeprom:1024
eraseblock:64
programblock:64
bootloader:007d00

Thank you in advance.

Berroa Ferenc.
 
Last edited:
Hi Ian:

Sorry not working!!

Precisely it download my 17K code (because i see the activity from the bootloader, but it not execute the downloded program

B.F
 
Last edited:
Hi Ian:

Sorry not working!!

B.F

Just saying Sorry not working!!
doesn't help me to help you.

What isn't working.. Compiling the small basic code?.. The uploading to the chip.. or the bootloader AFTER its been programmed...
 
Precisely it download my 17K code (because i see the activity from the bootloader, but it not execute the downloded program

B.F
 
Yes PICKIT 2 ver 2.61, and it works oK. I detect an endless loop at the beginin of the bootloader code, I will work around this now. thanks.

The problem is that when I power up the downloaded code, it is only doing this: Hserout 0x55 and nothing more.

Hardware understack overflow??? in simulator mode!
 
Last edited:
Below is the config file I've used for the 18F1320:
Code:
model:18f1320
flash:8192
eeprom:256
eraseblock:64
programblock:8
bootloader:001d00


Below is the program I've used with 8MHz internal oscillator:
Code:
'* PIC18F1320's Oshonsoft Bootloader*'
'Title: Oshonsoft Bootloader
'Description: This program uses MCU to perform bootloader function
''Author: languer (2011)
'Pin Allocation:
	'PIN# Main_Fn        Secondary_Fn
	'RA0 -> AN0
	'RA1 -> AN1
	'RA2 -> AN2
	'RA3 -> not used
	'RA4 -> not used
	'RA5 -> not used
	'RA6 -> not used
	'RA7 -> not used
	'RB0 -> not used
	'RB1 -> UART-TX
	'RB2 -> not used
	'RB3 -> not used
	'RB4 -> UART-RX
	'RB5 -> not used
	'RB6 -> PGC - Programming clock
	'RB7 -> PGD - Programming data
'Version Info: v1
	'->basic interface

'General Configuration
Define CONFIG1L = 0x00
Define CONFIG1H = 0x09
Define CONFIG2L = 0x1a
Define CONFIG2H = 0x00
Define CONFIG3L = 0x00
Define CONFIG3H = 0x03
Define CONFIG4L = 0x80
Define CONFIG4H = 0x00
Define CONFIG5L = 0x0f
Define CONFIG5H = 0xc0
Define CONFIG6L = 0x0f
Define CONFIG6H = 0xe0
Define CONFIG7L = 0x0f
Define CONFIG7H = 0x40

'Oscillator/Clock Configuration
Define CLOCK_FREQUENCY = 8
'Define SIMULATION_WAITMS_VALUE = 1

'Bootloader Code Start
StartFromZero

Dim i As Byte
Dim j As Byte
Dim total As Word
Dim eraseblock As Byte
Dim programblock As Byte
Dim address As Word
Dim data(64) As Byte
Dim din As Byte

ASM:        BSF RCON,IPEN
Goto bootloader_start

'beginning of user program
ASM:        ORG 0x0008
user_program:
Goto user_program

'beginning of bootloader
ASM:        ORG 0x1C00
'changed from 0x7c00 For 18f452 To 0x1c00 For 18f1320

execute_user_program:
ASM:        BSF RCON,IPEN
ASM:        GOTO 0x0008
ASM:        NOP

ASM:        ORG 0x1d00
'changed from 0x7d00 for 18F452 to 0x1d00 for 18F1320

bootloader_start:
'added oscillator configuration
OSCCON.IRCF2 = 1
OSCCON.IRCF1 = 1
OSCCON.IRCF0 = 1

'added port configuration statement
AllDigital
TRISB = %11111101

Hseropen 19200
WaitMs 100
Hserout 0x55
For i = 1 To 100
	WaitMs 1
	Hserget j
	If j = 0x55 Then
		Goto bootloader_main
	Endif
Next i
Gosub reset_state
Goto execute_user_program

bootloader_main:
Gosub get_byte
total.LB = din
Gosub get_byte
total.HB = din
'total is the last address to be programmed
Gosub get_byte
eraseblock = din
Gosub get_byte
programblock = din
Gosub erase_flash
For address = 0 To total Step programblock
	j = programblock - 1
	Gosub get_data
	Gosub write_flash_memory
Next address
address = 0x1c00  'changed from 0x7c00 for 18F452 to 0x1c00 for 18F1320
Gosub do_erase
j = 7
Gosub get_data
Gosub write_flash_memory
WaitMs 100
Gosub reset_state
Goto execute_user_program
End                                               

get_data:
For i = 0 To j
	Gosub get_byte
	data(i) = din
Next i
Return                                            

get_byte:
Hserin din
Hserout din
Return                                            

write_flash_memory:
TBLPTRU = 0
TBLPTRH = address.HB
TBLPTRL = address.LB
For i = 0 To j
TABLAT = data(i)
ASM:        TBLWT*+
Next i
TBLPTRU = 0
TBLPTRH = address.HB
TBLPTRL = address.LB
ASM:        BSF EECON1,EEPGD
ASM:        BCF EECON1,CFGS
ASM:        BSF EECON1,WREN
ASM:        MOVLW 0x55
ASM:        MOVWF EECON2
ASM:        MOVLW 0xAA
ASM:        MOVWF EECON2
ASM:        BSF EECON1,WR
ASM:        NOP
ASM:        NOP
ASM:        BCF EECON1,WREN
ASM:        BCF EECON1,EEPGD
Return                                            

erase_flash:
For address = 0 To total Step eraseblock
	Gosub do_erase
Next address
Return                                            

do_erase:
TBLPTRU = 0
TBLPTRH = address.HB
TBLPTRL = address.LB
ASM:        BSF EECON1,EEPGD
ASM:        BCF EECON1,CFGS
ASM:        BSF EECON1,WREN
ASM:        BSF EECON1,FREE
ASM:        MOVLW 0x55
ASM:        MOVWF EECON2
ASM:        MOVLW 0xAA
ASM:        MOVWF EECON2
ASM:        BSF EECON1,WR
ASM:        NOP
ASM:        NOP
ASM:        BCF EECON1,WREN
ASM:        BCF EECON1,EEPGD
ASM:        BCF EECON1,FREE
Return                                            

reset_state:
RCSTA = 0
TXSTA = 0
EECON1 = 0
PIR1 = 0
PIR2 = 0
STATUS = 0
AllDigital  'added command to reset all ports
'trisc = 0xff 'commented out for 18F1320
Return
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top