CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug Reports on this forum. Send them to support@ccsinfo.com

PIC24 pcd bootlader
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
georpo



Joined: 18 Nov 2008
Posts: 253
Location: Athens, Greece.

View user's profile Send private message

PIC24 pcd bootlader
PostPosted: Mon Oct 05, 2020 5:36 am     Reply with quote

Hello,

I have used the ex_pcd_bootloader.c example with success on a PIC24FJ16GA002.

Now, when I try the same example with a PIC24FJ48GA002, TeraTerm sends the file very fast. I get the message "Resetting" from the bootlader code but nothing happens.

Of course I changed the #include <24FJ48GA002.h> and #pin_select according the device used.
Compiler v5.049

Bootloader:

Code:

///////////////////////////////////////////////////////////////////////////
////                      EX_PCD_BOOTLOADER.C                          ////
////                                                                   ////
////  This program is an example standalone bootloader.                ////
////                                                                   ////
////  This program must be loaded into a target chip using a device    ////
////  programmer.  Afterwards this program may be used to load new     ////
////  versions of the application program.                             ////
////                                                                   ////
////  This bootloader is designed to detect a pushbutton low on reset. ////
////  It will then use the RS232 link to download a new program.       ////
////  Otherwise the application program is started.                    ////
////                                                                   ////
////  Use an RS232 link and the SIOW.EXE program to load a new HEX     ////
////  file into the target chip. See example EX_PCD_BOOTLOAD.C.        ////
////                                                                   ////
////  This example will work with the PCD compiler.  The               ////
////  following conditional compilation lines are used to include a    ////
////  valid device for the compiler.  Change the device, clock,        ////
////  push button, and RS232 pins for your hardware if needed.         ////
///////////////////////////////////////////////////////////////////////////
////        (C) Copyright 1996,2013 Custom Computer Services           ////
//// This source code may only be used by licensed users of the CCS    ////
//// C compiler.  This source code may only be distributed to other    ////
//// licensed users of the CCS C compiler.  No other use,              ////
//// reproduction or distribution is permitted without written         ////
//// permission.  Derivative programs created using this software      ////
//// in object code form are not restricted in any way.                ////
///////////////////////////////////////////////////////////////////////////


#include <24FJ48GA002.h>
#fuses NOWDT
#use delay(32MHz,int)
#pin_select U1RX    = PIN_B2
#pin_select U1TX   = PIN_B4
#use rs232(BAUD=57600,UART1)
#define PUSH_BUTTON PIN_B11

#define _bootloader

#include <pcd_bootloader.h>
#include <loader_pcd.c>

#org LOADER_END+1,LOADER_END+5
void application(void)
{
   while(TRUE);
}


#word CNPU1=getenv("SFR:CNPU1")
#word CNPU2=getenv("SFR:CNPU2")


void main(void){

   CNPU1=0b1100000000000000;    //CN14,CN15 pull up
   CNPU2=0b0000000000000001;    //CN16 pull up

   if(!input(PUSH_BUTTON)) {
      printf("\r\nBootloader Version 1.0\r\n");

      // Let the user know it is ready to accept a download
      printf("\r\nWaiting for download...");

      // Load the program
      load_program();
   }

   application();
}

#int_default
void isr(void)
{
   jump_to_isr(LOADER_END+5);
}





Firmware:
Code:



#include <24FJ48GA002.h>
#fuses NOWDT
#use delay(32MHz,int)
#pin_select U1RX    = PIN_B2
#pin_select U1TX   = PIN_B4
#use rs232(BAUD=57600,UART1)


//This is a necessary include file.  It reserves space so that the
//bootloader is not overwritten.
#include <pcd_bootloader.h>


void main(void){
      

   while(1){
     printf("\r\nVersion 10.0\r\n");
    delay_ms(500);
   }

}



Thanks for any help!
_________________
George.
temtronic



Joined: 01 Jul 2010
Posts: 8057
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Oct 05, 2020 10:50 am     Reply with quote

I don't use them, but my 'gut guess' is that you have to change the memory locations ? I'm assuming, by the part numbers the ...48... PIC is 4X bigger than the ...16... version, though essentially the same family ??
georpo



Joined: 18 Nov 2008
Posts: 253
Location: Athens, Greece.

View user's profile Send private message

PostPosted: Mon Oct 05, 2020 11:19 pm     Reply with quote

Yes they are in the same family, in the same pdf.
I thought the bootloader code handled the memory location automatically.
_________________
George.
georpo



Joined: 18 Nov 2008
Posts: 253
Location: Athens, Greece.

View user's profile Send private message

PostPosted: Tue Oct 06, 2020 2:54 am     Reply with quote

Still no luck
_________________
George.
Ttelmah



Joined: 11 Mar 2010
Posts: 17110

View user's profile Send private message

PostPosted: Tue Oct 06, 2020 3:03 am     Reply with quote

Yes, it should do, except in some very 'odd' situations.

OK. Questions.

Same serial hardware?.
Same baud rate?.
How is pin B11 actually wired?. What pull up is on this?.
Is the board being used the same?.
Except for the port changes, is the code the same?.

Can you do a test, programming the board with the same fuses, and
pin_select etc., using the physical programmer, and verify that the
serial is correctly working both ways. Your message, says that the
output is working, but it'd be nice to test the input as well, and the
full operation of the board.
georpo



Joined: 18 Nov 2008
Posts: 253
Location: Athens, Greece.

View user's profile Send private message

PostPosted: Tue Oct 06, 2020 3:16 am     Reply with quote

Ttelmah to the rescue Very Happy

Same serial hardware.
Different board.
Same code.
Pin B11 has pullup resistor (external on the working board, internal on the other) but it works OK because if pressed it sends the correct prompt to the terminal.
I have tested that the serial is working both ways. Usually I do:

Code:

while(1){
 putc(getc()+1);
}


So if I type 'A' I get back 'B' etc.

On the working board I have 57600 but on the other I tried 57600 and 9600. No luck.

Of course I set handshake to XON/XOFF in Tera Term and correct baudrate.

And I have tested using the physical programmer both bootloader and firmware codes and they are working on the board. Of course in order to work in the firmware code I have to comment out //#include <pcd_bootloader.h>

I have spent 2 days busting my head Sad

Now I tried:
Code:

#include <24FJ48GA002.h>
#fuses NOWDT
#use delay(32MHz,int)
#pin_select U1RX    = PIN_B2
#pin_select U1TX   = PIN_B4
#use rs232(BAUD=9600,UART1)
#define PUSH_BUTTON PIN_B11

#define _bootloader
#include <pcd_bootloader.h>
#include <loader_pcd.c>

#org LOADER_END+1,LOADER_END+5
void application(void)
{
   while(TRUE);
}


#word CNPU1=getenv("SFR:CNPU1")
#word CNPU2=getenv("SFR:CNPU2")


void main(void){

   CNPU1=0b1100000000000000;    //CN14,CN15 pull up
   CNPU2=0b0000000000000001;    //CN16 pull up

   if(!input(PUSH_BUTTON)) {
      printf("\r\nBootloader Version 1.0\r\n");
      printf("\r\nWaiting for download...");
      load_program();
   }

   printf("\r\nStarting Application...");

   application();
}

#int_default
void isr(void)
{
   jump_to_isr(LOADER_END+5);
}


and this is what I see in Tera Term:
Code:

Waiting for download...
Resetting
Starting Application...


But the application never starts.
_________________
George.
Ttelmah



Joined: 11 Mar 2010
Posts: 17110

View user's profile Send private message

PostPosted: Tue Oct 06, 2020 3:58 am     Reply with quote

OK. My only thought would be that possibly your compiler version is
misreporting one of the preset values the code uses. So (for example), the
program memory size. Or the page size. A bit of diagnostics would be
needed, perhaps printing out these values. This is the only thing I can
think of that would result in a problem like this. Obviously the chip is
quite 'unusual' having the 48K memory size, rather than the more common
16/64 etc., and if one of these values was wrong in the device database
for the compiler, this might be the problem....
georpo



Joined: 18 Nov 2008
Posts: 253
Location: Athens, Greece.

View user's profile Send private message

PostPosted: Tue Oct 06, 2020 4:07 am     Reply with quote

OK,
I did in both microcontrollers:
Code:

   printf("\r\nPROGRAM_MEMORY:%lu",getenv("PROGRAM_MEMORY"));
   printf("\r\nFLASH_ERASE_SIZE:%lu",getenv("FLASH_ERASE_SIZE"));


PIC24FJ48GA002:
PROGRAM_MEMORY:33788
FLASH_ERASE_SIZE:2048

PIC24FJ16GA002:
PROGRAM_MEMORY:11260
FLASH_ERASE_SIZE:2048


Based on the device h files:
The FJ16 has Program memory: 5630x24.
5630*2=11260 reported correctly.

The FJ48 has Program memory: 16894x24.
16894*2=33788 reported correctly.

Any thought?
_________________
George.
Ttelmah



Joined: 11 Mar 2010
Posts: 17110

View user's profile Send private message

PostPosted: Tue Oct 06, 2020 6:30 am     Reply with quote

Can you read the program memory with the programmer after the
bootloader has been used?. Have a look and see if the code has been programmed, and if it is in the right place.
georpo



Joined: 18 Nov 2008
Posts: 253
Location: Athens, Greece.

View user's profile Send private message

PostPosted: Tue Oct 06, 2020 6:31 am     Reply with quote

Good idea....but where is the right place??? Embarassed

I first tried reading the bootloader of the FJ16 device.
It ends at 0x80A with pwrsav #0 and nothing else down to the bottom of the list.

After downloading the FW with the bootloader it also has data after bootloader ends.
_________________
George.


Last edited by georpo on Tue Oct 06, 2020 6:58 am; edited 1 time in total
Ttelmah



Joined: 11 Mar 2010
Posts: 17110

View user's profile Send private message

PostPosted: Tue Oct 06, 2020 6:57 am     Reply with quote

0x1000 (if you look at the bootloader.h, it reserved two erase pages for
the bootloader, so 4096 bytes). It should have a jump there to the main
code.
You can actually 'load' the bootloader ready application code, into your
programmer, and see exactly what should be here. Then load it with the
bootloader, and compare.
georpo



Joined: 18 Nov 2008
Posts: 253
Location: Athens, Greece.

View user's profile Send private message

PostPosted: Tue Oct 06, 2020 11:35 pm     Reply with quote

Hello!

First I am doing this test on the working board with the FJ16 to verify locations based on something that works.
I have changed to #define LOADER_PAGES 3 in order to fit the printf commands. Of course it is working normally.
So, 3 pages*2048=6144 + 1 =6145 = 0x1801

After programming with the bootloader, I read back the program but there is nothing at 0x1801. 0x1801 is far beyond anything.
First command (after bootloader) is at 0x0DFC opcode 0xEF2032

I also load the bootloader ready application code in pickit2 software and verify that first command is at 0x0DFC opcode 0xEF2032.

So, the calculation of pages is not correct.
_________________
George.
Ttelmah



Joined: 11 Mar 2010
Posts: 17110

View user's profile Send private message

PostPosted: Wed Oct 07, 2020 1:30 am     Reply with quote

Two separate things.

0xDFC, sounds like the word address, not the byte address. This is down
to your programmer software. In CCSload, there is a selector for the
address when looking at the memory or file, which has a tick box for
int8 or int16 addressing. This needs to be in the int8 'position', or
you need to halve the address. Even with this though, 0xDFC is wrong.
With the page size give (2048), and pages set to 3, the first thing
loaded should be at 0x1800 (0xC00 as a word address). The bootloader
can't actually load starting at 0xDFC, since this is not a page boundary.

The calculation for the 'loader size' (in words), is:

#define LOADER_SIZE ((LOADER_PAGES * (getenv("FLASH_ERASE_SIZE")/2)) - 1)

Which with the '2048' you have read, and '3', gives:

(3*1024)-1 = 3071

and 'application start' is this +1.

So it should be loading at a word address of 0xC00.

Next thing to do is post the hex file for the 'application' code on
the chip that doesn't work. We can then see what it's load address
actually is.
georpo



Joined: 18 Nov 2008
Posts: 253
Location: Athens, Greece.

View user's profile Send private message

PostPosted: Wed Oct 07, 2020 1:58 am     Reply with quote

OK,
The hex of the working board with FJ16:
Code:

:081800005E0E04000000000070
:081860001A0E04000000000054
:081BF8003220EF0083E0200021
:101C0000008041001040BA000160EF0000000600B3
:101C10000D0A00005665000072730000696F000035
:101C20006E200000313500002E3000000D0A00004B
:101C3000000000004200F8003600F8003200F80012
:101C4000801F7800200020000C000900B01F7800E1
:101C50000008E20005003A00C922A900CD22A80030
:101C6000140020000440880003003700C922A900A6
:101C7000CD22A9000028EF008460A900A001200067
:101C80000C0009004F1078004F0078003200F90076
:101C90003600F9004200F900004006000000E000B4
:101CA0004220AF00040037009B0F09000000000035
:101CB0000000E900FCFF3A00000006000F78210058
:101CC000F07F210020A0B700000000004044240065
:101CD0002005880081E0A8006004200042E7B700EA
:101CE0007005200042E7B70042C7A90080F023003A
:101CF000A4A6B70030002000CEA6B70060042000E4
:101D000042E7B7007005200042E7B70042C7A800CD
:101D10004427EF000400280004118800044020003C
:101D2000141188002062A8000401200044118800DA
:101D30000028EF002CA3EF000421EF0002A1EF0028
:101D400004012800240888009460A80081E0A9000C
:101D50004220EF0081E0A80001002000010078008F
:101D60000160EF00FC0D0200000000008100E800AF
:101D70002322AF00FEFF370024A2B700F0002000AE
:101D80000008E600F5FF3700401F20004E0E02005D
:0C1D900000000000F0FF37000040FE00E3
:0857F800F7FF00FF7F3F00FFF7
:00000001FF
;PIC24FJ16GA002
;CRC=3893  CREATED="06-Oct-20 13:47"


and from MPLAD IDE Program Memory tab 1st command is indeed at 0x0C00 and says "goto 0x000E5E"

So I guess the address for the working FJ16 is correct at 0x1800 (0x0C00).

Now I will check the FJ48...

So, The hex of the FJ48

Code:

:081800005C0E04000000000072
:081860001A0E04000000000054
:081BF8003220EF0083E0200021
:101C0000008041001040BA000160EF0000000600B3
:101C10000D0A00005665000072730000696F000035
:101C20006E200000313000002E3000000D0A000050
:101C3000000000004200F8003600F8003200F80012
:101C4000801F7800200020000C000900B01F7800E1
:101C50000008AF0004003700C022A900C422A80079
:101C60000008A80003003700C022A900C422A90070
:101C70000008A9008460A900A00120000C00090050
:101C80004F1078004F0078003200F9003600F9005C
:101C90004200F900004006000000E0004220AF00D2
:101CA000040037009B0F0900000000000000E9005D
:101CB000FCFF3A00000006000F782200F07F2200AF
:101CC00020A0B70000000000404424002005880048
:101CD00081E0A8006004200042E7B7007005200002
:101CE00042E7B70042C7A90020F02300A4A6B7002E
:101CF00030002000C4A6B7006004200042E7B7000F
:101D00007005200042E7B70042C7A8004427EF0053
:101D100004002800041188000440200014118800E9
:101D20002062A80004012000441188000008A900D6
:101D30002CA3EF000421EF0002A1EF000401280012
:101D4000240888009460A80081E0A9004220EF00E8
:101D500081E0A80001002000010078000160EF0090
:101D6000FC0D0200000000008100E8002322AF000B
:101D7000FEFF370024A2B700F00020000008E600B4
:101D8000F5FF3700C042A900C442A800401F200050
:101D90004C0E020000000000C042A900C442A9008D
:101DA000401F20004C0E020000000000E9FF370039
:041DB0000040FE00F1
:020000040001F9
:0807F800F7FF00FF7F3F00FF47
:00000001FF
;PIC24FJ48GA002
;CRC=64FE  CREATED="07-Oct-20 11:02"



It has correct starting adress 0x1800 (0x0C00).
But if I read back the programmed FJ48 at address 0x0C00 it has command "bra 0x000C00" doesn't this mean loop for ever...?
_________________
George.
georpo



Joined: 18 Nov 2008
Posts: 253
Location: Athens, Greece.

View user's profile Send private message

PostPosted: Wed Oct 07, 2020 2:16 am     Reply with quote

EDIT:

The bra 0x000C00 at address 0x0C00 was there from the beginning when the bootloader was first programmed and nothing else was after that all the way to the end.

After downloading the firmware with teraterm there was indeed more data with first command starting at 0x0C30 command goto 0x000e1a
_________________
George.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2, 3  Next
Page 1 of 3

 
Jump to:  
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