|
|
View previous topic :: View next topic |
Author |
Message |
mnoumanmehtab
Joined: 13 Apr 2020 Posts: 4 Location: Pakistan
|
Bootloader At the end Topic |
Posted: Mon Apr 13, 2020 7:47 am |
|
|
Dear Experts, I have been developing firmware on PIC and other microcontrollers. I never developed bootloader. For a task i need to incorporate a bootloader in the system that can be used to upgrade firmware over rs485/ rs232. I successfully compiled the bootloader. System goes into load firmware and starts receiving hex ASCII string from hex file and writes it to the address. My question is when we start writing an application hex in the system, I get timeout in serial utility of CCS. I check software flow control, etc, everything is OK. Then I copy and paste data from hex file one by one line. At certain stage system hangs up. What i need to do ? _________________ mnoumanm |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9272 Location: Greensville,Ontario
|
|
Posted: Mon Apr 13, 2020 8:01 am |
|
|
1st I would increase the 'timeout' value in the PC communications program. Though I haven't used bootloaders for a decade or so, most will download a line of code, process it, then repeat. The 'processing' action may take longer than whatever 'timeout' the PC program is set for.
Increase the value to say 150% of the default, see what happens. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19592
|
|
Posted: Mon Apr 13, 2020 11:06 am |
|
|
Questions:
What chip?.
What compiler version?.
Is this the CCS bootloader?.
Are you using RS232 or RS485?. There are significant differences.
How is this connected?. |
|
|
mnoumanmehtab
Joined: 13 Apr 2020 Posts: 4 Location: Pakistan
|
|
Posted: Tue Apr 14, 2020 4:32 am |
|
|
Ttelmah wrote: | Questions:
What chip?.
What compiler version?.
Is this the CCS bootloader?.
Are you using RS232 or RS485?. There are significant differences.
How is this connected?. |
Thank you Ttelmah. It is rs232 usb-to-serial. The chip is 18f452. Due to Corona virus situation i have this controller with me but later on it will be 18F46k80. Let me ask you critically what exactly i need to know.
This is hex file of my code including bootloader routine in it.
Code: |
:0400000050EF00F0CD
:08000800204170706C69636116
:1000100074696F6E20506572666563742121206F6C
:100020006B200D0A0000436F6465200D0A00446FC9
:10003000776E6C6F61640D0A00000D0A4170706C80
:1000400069636174696F6E2E2E2E00000900F552EF
:100050000DE0F6CF49F0F7CF4AF0F5509EA8FED755
:10006000AD6E49C0F6FF4AC0F7FFF0D712009EA858
:10007000FED7AD6E1200EA6A490EE96EEF500EE04F
:10008000030E016E006A002EFED7012EFBD7E30E91
:10009000006E002EFED70000EF2EF2D708EF01F021
:1000A000F86AD09E4D0EAF6EA60EAC6E900EAB6E83
:1000B000046A056A486A476AC180C182C184C196E0
:1000C000800E946E260EF66E000EF76EBFDF9EAAAF
:1000D000FED7AE504C0807E12E0EF66E000EF76EFE
:1000E000B5DF80EC3BF03A0EF66E000EF76EAEDF39
:0600F00087D8FED70300D3
:10020000080EF66E000EF76E21DF640E496E33D7CE
:020210001200DA
:107700008CD812004D656D6F727920656C736520A1
:107710000D0A00005265736574204350550D0A0030
:10772000816B826B825101082BE380C003F07FC024
:10773000E9FF80C0EAFFEF50400810E28151100DD0
:10774000F3CF83F080C003F07FC0E9FF80C0EAFF81
:10775000EF508325BF0F0A0F816F0CD08151100DA0
:10776000F3CF83F07FC0E9FF80C0EAFFEF508325AD
:10777000D00F816F8251822B7F2AD8B4802BD2D731
:1077800081C001F01200F250036EF29EA68EA68414
:107790000F01550EA76EAA0EA76EA6820000035019
:1077A000F212000112000900F5520DE0F6CF7BF055
:1077B000F7CF7CF0F5509EA8FED7AD6E7BC0F6FFEC
:1077C0007CC0F7FFF0D71200D08CA69CF650070BB8
:1077D000006EF80EF6160A007BC001F0006608D0B5
:1077E000F650010F3F0B04E1A6880900CCDF0A0028
:1077F000006607D0EECFF5FF015204E00F0001064E
:1078000003D000060B000C00070EF614070AE6E191
:10781000BADF0166E3D7F86A120049924F6A4E6AEE
:1078200049B24FD1066A9EAAFED7AECF05F00550E9
:107830000A0804E1065202E1F6D709D0036A0650AD
:10784000070FE96E000E0320EA6E05C0EFFF065039
:10785000062A036A070FE96E000E0320EA6EEF5056
:107860000D0803E006504008DEE2130E37EC00F08E
:10787000498007503A08D8A41BD1806B080E7F6E50
:107880004FDF01C05AF0806B0A0E7F6E49DF01C0E6
:107890007BF0806B0C0E7F6E43DF7BC04DF001C030
:1078A0004CF0806B0E0E7F6E3BDF01C04BF04EC084
:1078B00052F04FC053F04CC050F04DC051F04A6AE6
:1078C000010E596E030E065C595C14E2036A5950AE
:1078D000070F016E000E032201C07BF003C07CF095
:1078E00003C080F001C07FF01BDF01504A26020E6A
:1078F0005926E8D7FF0ED8804A54010F4A6E030E6E
:10790000065C036A070F016E000E032201C07BF0C4
:1079100003C07CF003C080F001C07FF001DF0150A4
:107920004A5C02E04990C4D04B2C02D04982C0D0BE
:107930004B50040811E1806B100E7F6EF1DE01C028
:107940007BF0806B120E7F6EEBDE01C07CF07BC0A3
:107950004FF001C04EF0ACD04B52D8A4A9D0535236
:1079600005E1525203E15150760808E2535206E114
:10797000525204E151507F08D8B09AD05352D8A443
:1079800097D05252D8A494D051507F08D8A090D00C
:10799000090E596E586A030E065C595C23E2585072
:1079A000582A036A5B0F016E000E032201C07BF0B0
:1079B00003C07CF0036A5950070F016E000E0322CA
:1079C00001C07DF003C07EF003C080F001C07FF0F5
:1079D000A7DE7CC0EAFF7BC0E9FF01C0EFFF020E1B
:1079E0005926D9D75450505C09E15550515C06E1F5
:1079F0005650525C03E15750535C3DE054503F0BEE
:107A0000006E016A026A036A400ED8800056000EBA
:107A10000156025603565450002655500122565026
:107A20000222575003220350535C25E30BE102501E
:107A3000525C21E307E10150515C1DE303E150502A
:107A4000005C19E250503F0B7B6E7C6A7D6A7E6A57
:107A50007B5206E17C5204E17D5202E17E520BE052
:107A6000D08C52C0F8FF51C0F7FF50C0F6FFA68877
:107A7000A69C89DEF86A5A505024546E000E51209C
:107A8000556E000E5220566E000E5320576E040E97
:107A9000F66E770EF76E87DE52C0F8FF51C0F7FF23
:107AA00050C0F6FFEA6A5B0EE96E5AC07BF08CDECE
:107AB00049A003D0060E37EC00F0110E37EC00F0B1
:107AC000AFD6060E37EC00F0110E37EC00F0140EB6
:0C7AD000F66E770EF76E67DEFF00120006
:020000040030CA
:0E00000000220E0E000181000FC00FE00F4025
:00000001FF
;PIC18F452
;CRC=E021 CREATED="13-Apr-20 18:21"
|
This line is start bootloader routine:
Code: | :107700008CD812004D656D6F727920656C736520A1
|
and my application function in the code is @ 0x000200, 0x007700-1. You can see this is the code i used:
Code: |
#include "lloaderv1.c"
//#define PUSH_BUTTON PIN_B0
#ORG 0x000200 ,0x007700-1 //DEFAULT
void user_application()
{
printf(" Application working!!\r\n");
delay_ms(100);
}
void main()
{
set_tris_c(0x80);
printf("Code \r\n");
if(getc()=='L')
{
printf("Download\r\n");
load_program();
}
printf("\r\nApplication...");
while(TRUE)
{
user_application();
}
}
|
lloaderv1.c is file that i edited and it works good. I intend to write a Python code to send hex file to the controller line by line and it works ok.
And now this is the application code that i created. According to my understanding i should have been able to send this hex file serially line by line slowly and after completing this code should run. Below is my hex file generated and code of application:
Code: |
:0400000000EF01F01C
:08000800416C6C616820697312
:1000100020477265617465737420200D0A00090021
:10002000F5520DE0F6CF08F0F7CF09F0F5509EA895
:10003000FED7AD6E08C0F6FF09C0F7FFF0D712007B
:10004000EA6A080EE96EEF500EE0030E016E006AD8
:10005000002EFED7012EFBD7E30E006E002EFED73A
:0A0060000000EF2EF2D718EF01F0B8
:10020000F86AD09E046A4D0EAF6EA60EAC6E900ECC
:10021000AB6E066A056AC180C182C184C196076A55
:10022000080EF66E000EF76EFADE640E086E08D742
:04023000F7D70300F9
:00000001FF
;PIC18F452
;CRC=AB70 CREATED="11-Apr-20 20:46"
|
Code: |
#include <18F452.h>
#ORG 0x000200 ,0x007700-1 //DEFAULT
#fuses None//HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=12MHz)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,bits=8,parity=N,stop=1, stream = UART1,ERRORS)
void main()
{
int i=0;
//printf("get erase size %li \r\n",getenv("FLASH_ERASE_SIZE"));
while(1)
{
printf("Working application code yesss \r\n");
delay_ms(100);
}
}
|
I upload the code of bootloader with Pickit and then send L on serial port. The system goes into bootloader routine and i start copy and paste from hex file line by line like this:
Code: |
1. :0400000000EF01F01C reply ok written
3. :08000800416C6C616820697312 ok
4. :1000100020477265617465737420200D0A00090021 ok
5. :10002000F5520DE0F6CF08F0F7CF09F0F5509EA895 ok
6. :10003000FED7AD6E08C0F6FF09C0F7FFF0D712007B system goes bananas hangs and on reset it just won't work. |
I can read the flash of controller and now it gets modified so writing is OK. My problem is that i am now aware of what to write from the hex or leave and at some location i should avoid writing. Kindly shed some light on it. Thank you. What i am doing wrong ? _________________ mnoumanm |
|
|
mnoumanmehtab
Joined: 13 Apr 2020 Posts: 4 Location: Pakistan
|
|
Posted: Tue Apr 14, 2020 4:34 am |
|
|
temtronic wrote: | 1st I would increase the 'timeout' value in the PC communications program. Though I haven't used bootloaders for a decade or so, most will download a line of code, process it, then repeat. The 'processing' action may take longer than whatever 'timeout' the PC program is set for.
Increase the value to say 150% of the default, see what happens. |
Thank you temtronic, my issue is this basically, sorry for long query.
It is rs232 usb-to-serial. The chip is 18f452. Due to Corona virus situation i have this controller with me but later on it will be 18f46k80. Let me ask you critically what exactly i need to know.
This is hex file of my code including bootloader routine in it.
Code: |
:0400000050EF00F0CD
:08000800204170706C69636116
:1000100074696F6E20506572666563742121206F6C
:100020006B200D0A0000436F6465200D0A00446FC9
:10003000776E6C6F61640D0A00000D0A4170706C80
:1000400069636174696F6E2E2E2E00000900F552EF
:100050000DE0F6CF49F0F7CF4AF0F5509EA8FED755
:10006000AD6E49C0F6FF4AC0F7FFF0D712009EA858
:10007000FED7AD6E1200EA6A490EE96EEF500EE04F
:10008000030E016E006A002EFED7012EFBD7E30E91
:10009000006E002EFED70000EF2EF2D708EF01F021
:1000A000F86AD09E4D0EAF6EA60EAC6E900EAB6E83
:1000B000046A056A486A476AC180C182C184C196E0
:1000C000800E946E260EF66E000EF76EBFDF9EAAAF
:1000D000FED7AE504C0807E12E0EF66E000EF76EFE
:1000E000B5DF80EC3BF03A0EF66E000EF76EAEDF39
:0600F00087D8FED70300D3
:10020000080EF66E000EF76E21DF640E496E33D7CE
:020210001200DA
:107700008CD812004D656D6F727920656C736520A1
:107710000D0A00005265736574204350550D0A0030
:10772000816B826B825101082BE380C003F07FC024
:10773000E9FF80C0EAFFEF50400810E28151100DD0
:10774000F3CF83F080C003F07FC0E9FF80C0EAFF81
:10775000EF508325BF0F0A0F816F0CD08151100DA0
:10776000F3CF83F07FC0E9FF80C0EAFFEF508325AD
:10777000D00F816F8251822B7F2AD8B4802BD2D731
:1077800081C001F01200F250036EF29EA68EA68414
:107790000F01550EA76EAA0EA76EA6820000035019
:1077A000F212000112000900F5520DE0F6CF7BF055
:1077B000F7CF7CF0F5509EA8FED7AD6E7BC0F6FFEC
:1077C0007CC0F7FFF0D71200D08CA69CF650070BB8
:1077D000006EF80EF6160A007BC001F0006608D0B5
:1077E000F650010F3F0B04E1A6880900CCDF0A0028
:1077F000006607D0EECFF5FF015204E00F0001064E
:1078000003D000060B000C00070EF614070AE6E191
:10781000BADF0166E3D7F86A120049924F6A4E6AEE
:1078200049B24FD1066A9EAAFED7AECF05F00550E9
:107830000A0804E1065202E1F6D709D0036A0650AD
:10784000070FE96E000E0320EA6E05C0EFFF065039
:10785000062A036A070FE96E000E0320EA6EEF5056
:107860000D0803E006504008DEE2130E37EC00F08E
:10787000498007503A08D8A41BD1806B080E7F6E50
:107880004FDF01C05AF0806B0A0E7F6E49DF01C0E6
:107890007BF0806B0C0E7F6E43DF7BC04DF001C030
:1078A0004CF0806B0E0E7F6E3BDF01C04BF04EC084
:1078B00052F04FC053F04CC050F04DC051F04A6AE6
:1078C000010E596E030E065C595C14E2036A5950AE
:1078D000070F016E000E032201C07BF003C07CF095
:1078E00003C080F001C07FF01BDF01504A26020E6A
:1078F0005926E8D7FF0ED8804A54010F4A6E030E6E
:10790000065C036A070F016E000E032201C07BF0C4
:1079100003C07CF003C080F001C07FF001DF0150A4
:107920004A5C02E04990C4D04B2C02D04982C0D0BE
:107930004B50040811E1806B100E7F6EF1DE01C028
:107940007BF0806B120E7F6EEBDE01C07CF07BC0A3
:107950004FF001C04EF0ACD04B52D8A4A9D0535236
:1079600005E1525203E15150760808E2535206E114
:10797000525204E151507F08D8B09AD05352D8A443
:1079800097D05252D8A494D051507F08D8A090D00C
:10799000090E596E586A030E065C595C23E2585072
:1079A000582A036A5B0F016E000E032201C07BF0B0
:1079B00003C07CF0036A5950070F016E000E0322CA
:1079C00001C07DF003C07EF003C080F001C07FF0F5
:1079D000A7DE7CC0EAFF7BC0E9FF01C0EFFF020E1B
:1079E0005926D9D75450505C09E15550515C06E1F5
:1079F0005650525C03E15750535C3DE054503F0BEE
:107A0000006E016A026A036A400ED8800056000EBA
:107A10000156025603565450002655500122565026
:107A20000222575003220350535C25E30BE102501E
:107A3000525C21E307E10150515C1DE303E150502A
:107A4000005C19E250503F0B7B6E7C6A7D6A7E6A57
:107A50007B5206E17C5204E17D5202E17E520BE052
:107A6000D08C52C0F8FF51C0F7FF50C0F6FFA68877
:107A7000A69C89DEF86A5A505024546E000E51209C
:107A8000556E000E5220566E000E5320576E040E97
:107A9000F66E770EF76E87DE52C0F8FF51C0F7FF23
:107AA00050C0F6FFEA6A5B0EE96E5AC07BF08CDECE
:107AB00049A003D0060E37EC00F0110E37EC00F0B1
:107AC000AFD6060E37EC00F0110E37EC00F0140EB6
:0C7AD000F66E770EF76E67DEFF00120006
:020000040030CA
:0E00000000220E0E000181000FC00FE00F4025
:00000001FF
;PIC18F452
;CRC=E021 CREATED="13-Apr-20 18:21"
|
This line is start of bootloader routine:
Code: |
:107700008CD812004D656D6F727920656C736520A1
|
and my application function in the code is @ 0x000200, 0x007700-1. You can see this is the code i used:
Code: |
#include "lloaderv1.c"
//#define PUSH_BUTTON PIN_B0
#ORG 0x000200 ,0x007700-1 //DEFAULT
void user_application()
{
printf(" Application working!!\r\n");
delay_ms(100);
}
void main()
{
set_tris_c(0x80);
printf("Code \r\n");
if(getc()=='L')
{
printf("Download\r\n");
load_program();
}
printf("\r\nApplication...");
while(TRUE)
{
user_application();
}
}
|
lloaderv1.c is file that i edited and it works good. I intend to write a Python code to send hex file to the controller line by line and it works ok.
And now this is the application code that i created. According to my understanding i should have been able to send this hex file serially line by line slowly and after completing this, the code should run. Below is my hex file generated and code of application:
Code: |
:0400000000EF01F01C
:08000800416C6C616820697312
:1000100020477265617465737420200D0A00090021
:10002000F5520DE0F6CF08F0F7CF09F0F5509EA895
:10003000FED7AD6E08C0F6FF09C0F7FFF0D712007B
:10004000EA6A080EE96EEF500EE0030E016E006AD8
:10005000002EFED7012EFBD7E30E006E002EFED73A
:0A0060000000EF2EF2D718EF01F0B8
:10020000F86AD09E046A4D0EAF6EA60EAC6E900ECC
:10021000AB6E066A056AC180C182C184C196076A55
:10022000080EF66E000EF76EFADE640E086E08D742
:04023000F7D70300F9
:00000001FF
;PIC18F452
;CRC=AB70 CREATED="11-Apr-20 20:46" |
Code: |
#include <18F452.h>
#ORG 0x000200 ,0x007700-1 //DEFAULT
#fuses None//HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=12MHz)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,bits=8,parity=N,stop=1, stream = UART1,ERRORS)
void main()
{
int i=0;
//printf("get erase size %li \r\n",getenv("FLASH_ERASE_SIZE"));
while(1)
{
printf("Working application code yesss \r\n");
delay_ms(100);
}
}
|
I upload the code of bootloader with Pickit and then send L on serial port. The system goes into bootloader routine and i start copy and paste from hex file line by line like this:
Code: |
1. :0400000000EF01F01C reply ok written
3. :08000800416C6C616820697312 ok
4. :1000100020477265617465737420200D0A00090021 ok
5. :10002000F5520DE0F6CF08F0F7CF09F0F5509EA895 ok
6. :10003000FED7AD6E08C0F6FF09C0F7FFF0D712007B system goes bananas hangs and on reset it just won't work
|
I can read the flash of controller and now it gets modified so writing is OK. My problem is that i am now aware of what to write from the hex or leave and at some location i should avoid writing. Kindly shed some light on it. Thank you. What i am doing wrong ? _________________ mnoumanm |
|
|
mnoumanmehtab
Joined: 13 Apr 2020 Posts: 4 Location: Pakistan
|
|
Posted: Tue Apr 14, 2020 4:37 am |
|
|
Ttelmah wrote: | Questions:
What chip?.
What compiler version?.
Is this the CCS bootloader?.
Are you using RS232 or RS485?. There are significant differences.
How is this connected?. |
pch
pcd
all version 5.048 _________________ mnoumanm |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19592
|
|
Posted: Tue Apr 14, 2020 6:29 am |
|
|
Major glaring fault
#ORG 0x000200 ,0x007700-1 //DEFAULT
It needs the 'default' enabled. Otherwise it'll write it's basic
background routines into the areas where the bootloader resides...
Your 'application' is putting the whole of the printf and delay functions
into the area from 0x00 to 0x69.
Wrong.
'default' specifies to put it's internal 'default' routines into the area.
Without this these will be placed at the ends of memory (routines at
the bottom, and const's at the top).
The timeout is almost certainly where the bootloader refuses to load
the data that is clashing with itself.... |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|