Hot!PIC24FJ128GA204 Bootloader p24qp.exe problem:PICUNKNOWN, referring to AN1157

Author
jojo_nexo
New Member
  • Total Posts : 17
  • Reward points : 0
  • Joined: 2017/09/15 07:59:15
  • Location: 0
  • Status: offline
2017/11/27 09:44:56 (permalink)
0

PIC24FJ128GA204 Bootloader p24qp.exe problem:PICUNKNOWN, referring to AN1157

Hello friends,
 
I am having trouble with getting the bootloader to work, I am referring to the Bootloader presented in AN1157. I was able to to map the UART to the right Pins on my curiosity board and have the oscillator in the right configuration, 16MHz, FCY==8000000.  (It seems the code was written, when the PIC24FJ128GA204 did not yet exist, so some customization had to be done.)
However, when trying to connect the p24qp.exe programm it tells me device unknown. Even more so, after starting p24qp it doesn't ask me to choose a device. When inserting the device PIC24FJ128GA204 into the .ini file, it doesn't recognize it either.
Here there has been a similar discussion, which unfortunately did not get me any further:
http://www.microchip.com/forums/FindPost/630875
This is what I added to the P24qp.ini:
...
4127="PIC24FJ256GB110"
3329="PIC24F16KA101"
3331="PIC24F16KA102"
3336="PIC24F08KA101"
3338="PIC24F08KA102"
3339="PIC24FJ128GA204"

...

[PIC24FJ128GA204]
writeblock=256
readblock=4
eraseblock=2048
devicetype=2
maxpacketsize=261
bytesperaddr=2
pmrangelow="000000"
pmrangehigh="0157FF"
;userresetvector="100"
;bootdelay="102"

 
When looking into the code running on the PIC there doesn't seem to be any option that allows for setting the device type, so how could my computer and the PIC possibly exchange this information (even with a PIC already in the list of known devices)?In the boot.c file there are commands like:
//Constant Defines *****************************************************************
//Protocol Commands
#define RD_VER 0x00
#define RD_FLASH 0x01
#define WT_FLASH 0x02
#define ER_FLASH 0x03
#define RD_EEDATA 0x04
#define WT_EEDATA 0x05
#define RD_CONFIG 0x06
#define WT_CONFIG 0x07
#define VERIFY_OK 0x08

But none that could be used to exchange data about the device type.
Furthermore, when I open a hex file and try to write it to the PIC regardless of the unknown type, nothing much happens.
Any ideas on that? Any help is appreciated.
Thanks,
Jo
post edited by jojo_nexo - 2017/11/27 09:46:26
#1

14 Replies Related Threads

    BobAGI
    Super Member
    • Total Posts : 1650
    • Reward points : 0
    • Joined: 2011/03/09 00:04:35
    • Location: Texas and Sweden
    • Status: offline
    Re: PIC24FJ128GA204 Bootloader p24qp.exe problem:PICUNKNOWN, referring to AN1157 2017/11/27 09:57:17 (permalink)
    4 (1)
    The chipID is hard coded into the controller silicon and the boot loader exchange is to read the value to the PC program which it will use to determine which controller it is dealing with and how to handle the following communication.
    The other defines you show are simply a list of boot loader command bytes to be sent over the wire for different functions in the communication.
    Since I have programmed my own PC program to talk to the boot loader I cannot help you with the p24qp.exe program other than saying that since it is very old and predates your chip chances are that it will never work...
    It looks like it is flexible enough to handle different chips via ini file values selected by the ChipID, so maybe you can tweak the program to actually work, but I think best is if you make your own PC program so you know what is actually going on.

    --
    Bo B
    Sweden & Texas
     
    #2
    jojo_nexo
    New Member
    • Total Posts : 17
    • Reward points : 0
    • Joined: 2017/09/15 07:59:15
    • Location: 0
    • Status: offline
    Re: PIC24FJ128GA204 Bootloader p24qp.exe problem:PICUNKNOWN, referring to AN1157 2017/11/27 10:43:46 (permalink)
    0
    Thanks, but at what point is the information about the chip communicated to the PC? I thought there should be some piece of code that somehow asks the controller the DevId and sends it backt to the PC. And I think it should be a response to some command, right?
    Thanks
    #3
    BobAGI
    Super Member
    • Total Posts : 1650
    • Reward points : 0
    • Joined: 2011/03/09 00:04:35
    • Location: Texas and Sweden
    • Status: offline
    Re: PIC24FJ128GA204 Bootloader p24qp.exe problem:PICUNKNOWN, referring to AN1157 2017/11/27 11:02:10 (permalink)
    3 (1)
    Again, the details of when the PC program uses the command channel is not known by me since I built my own...
    But on the PIC itself the AN1157 code has a function like this in memory.c:
    /********************************************************************
    ; Read the DEVID value from register FF0000
    *********************************************************************/
    unsigned short GetDevID()
    {
        unsigned short devid;
        _memcpy_p2d24((char *)&devid, 0xFF0000, 2);
        return devid;
    }

    And in boot.c inside the function HandleCommand you will find this:
            case RD_DEVID: /*Read device ID*/
                devidreg = GetDevID();
                buffer[2] = devidreg & 0xFF;
                buffer[3] = (devidreg >> 8) & 0xFF;
       responseBytes = 4; //set length of reply*/
                break;

    So when the PC program sends command RD_DEVID it will receive 4 bytes of data back and inside will be the DeviceID.
     

    --
    Bo B
    Sweden & Texas
     
    #4
    jojo_nexo
    New Member
    • Total Posts : 17
    • Reward points : 0
    • Joined: 2017/09/15 07:59:15
    • Location: 0
    • Status: offline
    Re: PIC24FJ128GA204 Bootloader p24qp.exe problem:PICUNKNOWN, referring to AN1157 2017/11/27 11:07:57 (permalink)
    0
    Ah ok,
    I don't have that in my code... Neither in memory.c nor in boot.c. This is strange, What you describe above is exactly what I was searching in the code and which I didn't find.
    Where did you get that code?
    Am I using some wrong code or something? How is this possible, I downloaded it directly from the page where the paper is located.
    Strange...
    That was a great help!
    Jo
     
    #5
    BobAGI
    Super Member
    • Total Posts : 1650
    • Reward points : 0
    • Joined: 2011/03/09 00:04:35
    • Location: Texas and Sweden
    • Status: offline
    Re: PIC24FJ128GA204 Bootloader p24qp.exe problem:PICUNKNOWN, referring to AN1157 2017/11/27 12:26:58 (permalink)
    0
    jojo_nexo
    I don't have that in my code... Neither in memory.c nor in boot.c. This is strange, What you describe above is exactly what I was searching in the code and which I didn't find.
    Where did you get that code?
    Am I using some wrong code or something? How is this possible, I downloaded it directly from the page where the paper is located.

    I looked in my project directory for the BOOT code and the boot.c and memory.c files were there with the Microchip header on top of both files.
    Then I started looking around for some zipfile or similar where they could have come from but the only zip I found was the same as is on the MC AN1157 webpage and this only contains a setup utility probably for the programmer. It escapes me where I have retrieved these sources from, but it was more than 5 years ago now. One forgets...
    I finally found them inside a folder containing files from Microchip and these are dated back in 2010 and 2008 whereas my active files are from 2013. These also have a CVS revision indicating that they are modified by me a number of times, but I cannot check history right now because the CVS server is currently down...
    Since I modified the protocol to make it more robust and also block the use of the Microchip programmer program for security I cannot publish my version either.
     

    --
    Bo B
    Sweden & Texas
     
    #6
    RISC
    Super Member
    • Total Posts : 4645
    • Reward points : 0
    • Status: offline
    Re: PIC24FJ128GA204 Bootloader p24qp.exe problem:PICUNKNOWN, referring to AN1157 2017/11/27 17:05:25 (permalink)
    3 (1)
    Hi,
    AN1157 is a quite old appnote which probably does not support PIC24 which where released later.
    The neweest and much more easier bootloader supporting almost all 16 bits (dsPIC and PIC24) is EZ Bootloader:
    http://www.microchip.com/EZBL
    Regards
     
     
    post edited by RISC - 2017/11/27 17:07:07
    #7
    BobAGI
    Super Member
    • Total Posts : 1650
    • Reward points : 0
    • Joined: 2011/03/09 00:04:35
    • Location: Texas and Sweden
    • Status: offline
    Re: PIC24FJ128GA204 Bootloader p24qp.exe problem:PICUNKNOWN, referring to AN1157 2017/11/27 21:59:16 (permalink)
    4 (1)
    RISC
    AN1157 is a quite old appnote which probably does not support PIC24 which where released later.
    The neweest and much more easier bootloader supporting almost all 16 bits (dsPIC and PIC24) is EZ Bootloader:
    http://www.microchip.com/EZBL

    Not really true...
    Please have a look at the Microchip AN1157 boot-loader webpage!
    The AN itself is titled "A Serial Bootloader for PIC24F Devices"
    And the PIC used by jojo_nexo (PIC24FJ128GA204) is specifically shown in the list of devices.
    Also: I have used it successfully on a PIC24FJ256GB206 device.
    But that does not say it is easy to implement, I had a lot of trouble regarding the AN1157 to get it going. For example I had to hand craft the two GLD files needed for the BL and App respectively. So if the EZBL is more ready to go "out of the box" it is probably a better choice.

    --
    Bo B
    Sweden & Texas
     
    #8
    jojo_nexo
    New Member
    • Total Posts : 17
    • Reward points : 0
    • Joined: 2017/09/15 07:59:15
    • Location: 0
    • Status: offline
    Re: PIC24FJ128GA204 Bootloader p24qp.exe problem:PICUNKNOWN, referring to AN1157 2017/11/28 03:08:42 (permalink)
    4 (1)
    Hi, thanks for your replies.
    Now, I somewhat reverse engineered the protocoll by looking what the first action of the P24qp program is and found, that it first sends a Read_Flash command, reading the adress 0xFF0000, where in memory the device type is located. The PIC answers with its specific device ID correctly, such that I came up with, that I just added the wrong number in the ini file. It has to be not just any number (which I first assumed, as in the thread mentioned before they said that using any number would do, at least this was what I understood) but it has to match the device number. Furthermore, the dSelectDevice.frm you have to extend the for loop for whatever this thing does (I have no clue, what .frm files are used for and what all this is).
    However, after performing the following changes to the .ini and .frm file, at least the correct PIC was recognized and I was able to program something into the PIC (although I have not yet a correct Linker script, such that I propably destroyed my bootloader by overwriting it and messed up everything in the controller. But I was happy, that I was at least finally able to get a step further.)
    Here is the recipe for getting the p24qp to work with the PIC24FJ128GA204 (and I suppose with any device not listed in the known Devices list):
    1. Find out your PICs device ID (for my PIC it is 19539, which is family and devid put together in a 16Bit word, located at registers 0xFF0000).
    2. add the line in the ini file:
     
    ...
    4127="PIC24FJ256GB110"
    3329="PIC24F16KA101"
    3331="PIC24F16KA102"
    3336="PIC24F08KA101"
    3338="PIC24F08KA102"
    19539="PIC24FJ128GA204"
    ...
    [PIC24FJ128GA204]
    writeblock=256
    readblock=4
    eraseblock=2048
    devicetype=2
    maxpacketsize=261
    bytesperaddr=2
    pmrangelow="000000"
    pmrangehigh="0157FF"
    ;userresetvector="100"
    ;bootdelay="102"

    (dont know if the params are actually correct, I just copied something that looked reasonable)
    3. extend the for-loop in the .frm file mentioned above:

    ...
    Private Sub Form_Load()
        DoEvents

        'get the current list of devices
        Cm_DevList.Clear
        Cm_DevList.AddItem ("Auto Detect Device")
        For i = 1024 To 20000 //<- change corresponging to your devid
            TempReturn = GetSetting("DEVICELIST", CStr(i))
            If StrComp(TempReturn, "") <> 0 Then
                Cm_DevList.AddItem TempReturn
                Cm_DevList.ItemData(MyCount) = i
                MyCount = MyCount + 1
            End If
        Next i
    End Sub

     
    Then the p24qp will recognize your PIC. Be sure that your device's id is located in 0xFF0000. If not, adjust it in the code on the PIC.
     
    Now, I used this bootloader instead of the EZBL because I need to heavily customize the code to our needs and this bootloader has all the source files available, which the EZBL hasn't (or am I missing something here?). 
     
    Thanks for your help, you got me on the right track. Now I need to customize the linker scripts (which I havent done yet, such that although I can download some software to the PIC via the p24qp, everything gets messed up of course).
    Lets hope I get this done correctly somehow.
     
    Thanks,
    Jo
    #9
    BobAGI
    Super Member
    • Total Posts : 1650
    • Reward points : 0
    • Joined: 2011/03/09 00:04:35
    • Location: Texas and Sweden
    • Status: offline
    Re: PIC24FJ128GA204 Bootloader p24qp.exe problem:PICUNKNOWN, referring to AN1157 2017/11/28 03:34:52 (permalink)
    4 (1)
    Regarding linker scripts I started with the gld file supplied by the compiler for the actual device I was using.
    Then I made two copies of it, one for the BL and one for the App (named appropriately).
    I then modified the addresses such that in the BL script the code starts at 0x400 and in the App script it starts at 0x1400 (leaving space for the BL code and jump tables).
    My resulting GLD files are published 2013 on this forum in a thread named:
    Anyone has a GLD file for PIC24FJ256GB206 modified for the serial boot loader (AN1157)
    Please have a look and also compare the GLD files.
     

    --
    Bo B
    Sweden & Texas
     
    #10
    jojo_nexo
    New Member
    • Total Posts : 17
    • Reward points : 0
    • Joined: 2017/09/15 07:59:15
    • Location: 0
    • Status: offline
    Re: PIC24FJ128GA204 Bootloader p24qp.exe problem:PICUNKNOWN, referring to AN1157 2017/12/05 05:41:34 (permalink)
    0
    Hi, thanks for your gld files.
    One week down the line with my bootloader, I finally got it to work. I can now put a program that simply blinks an LED via the p24qp.exe program.
     
    However, some more questions have come my way.
    First: Why do you subtract 0x1200 instead of 0x1400? See your original code:
     
     
      data (a!xr) : ORIGIN = 0x0800, LENGTH = 0x18000
      reset : ORIGIN = 0x0000, LENGTH = 0x4
      ivt : ORIGIN = 0x0004, LENGTH = 0xFC
      aivt : ORIGIN = 0x0104, LENGTH = 0xFC
      boottimeout : ORIGIN = 0x1200, LENGTH = 0x2
      app_ivt : ORIGIN = 0x1202, LENGTH = 0x01FC
      program (xr) : ORIGIN = 0x1400, LENGTH = 0x297F6 /* Modified by subtracting 0x1200 from length 2A9F6 */
      CONFIG4 : ORIGIN = 0x2ABF8, LENGTH = 0x2
      CONFIG3 : ORIGIN = 0x2ABFA, LENGTH = 0x2
      CONFIG2 : ORIGIN = 0x2ABFC, LENGTH = 0x2
      CONFIG1 : ORIGIN = 0x2ABFE, LENGTH = 0x2

     
    Secondly, what would I do if I wanted to transmit the code over the air? My idea is to parse the hex file and create some blocks that contain an address and the code located there. Is there any helpful information I can use, to not have to start from scratch.
     
    Anyway, your files Bob helped me very far along, very much appreciated!
    Jo
    #11
    BobAGI
    Super Member
    • Total Posts : 1650
    • Reward points : 0
    • Joined: 2011/03/09 00:04:35
    • Location: Texas and Sweden
    • Status: offline
    Re: PIC24FJ128GA204 Bootloader p24qp.exe problem:PICUNKNOWN, referring to AN1157 2017/12/05 06:26:20 (permalink)
    0
    Subtract by 0x1200?
    Not really sure, it was a while since I did this.
    It might be because the size includes stuff before the program origin (i.e. starting at 0x1200), but then the start should be set as 0x1200 maybe? I'm not really sure....
     
    Sending over air?
    I don't know what you aim at here, but you should not send the hex file over to the boot loader in any case. That would require the functionality of the PC program to be put inside flash...
    The device boot loader should be a very lean code which does not do very much except erase, write and read on command from the PC.

    --
    Bo B
    Sweden & Texas
     
    #12
    jojo_nexo
    New Member
    • Total Posts : 17
    • Reward points : 0
    • Joined: 2017/09/15 07:59:15
    • Location: 0
    • Status: offline
    Re: PIC24FJ128GA204 Bootloader p24qp.exe problem:PICUNKNOWN, referring to AN1157 2017/12/05 07:14:30 (permalink)
    0
    All right, this is what I thought. Therefore I would write a program that would strip away all the hex file overhead.
    Over the air means a wireless reciever that communicates data to the pic via rs232 or something.
    Another question to your gld script:
    why do you only reserve space for 0x1FC for the app_ivt in your application gld but 0x200 in the bootloader for app_ivt. This seems to be intended to skip the reset vector, but I think you are writing it even in the application gld file. So there seems space for one instruction word missing.
    Is that correct?
     
    #13
    BobAGI
    Super Member
    • Total Posts : 1650
    • Reward points : 0
    • Joined: 2011/03/09 00:04:35
    • Location: Texas and Sweden
    • Status: offline
    Re: PIC24FJ128GA204 Bootloader p24qp.exe problem:PICUNKNOWN, referring to AN1157 2017/12/05 10:35:36 (permalink)
    0
    Over the air means a wireless reciever that communicates data to the pic via rs232 or something

    Why should this be any different for the PIC boot loader than having the RS232 wires connected to a PC?
    Serial data arriving on the PIC pins do not have any information on how they traveled there.
    why do you only reserve space for 0x1FC for the app_ivt in your application gld but 0x200 in the bootloader for app_ivt.

    Because I have already placed the boot loader timeout at the first address location 0x1200:
      boottimeout : ORIGIN = 0x1200, LENGTH = 0x2
      app_ivt : ORIGIN = 0x1202, LENGTH = 0x01FC


    --
    Bo B
    Sweden & Texas
     
    #14
    jojo_nexo
    New Member
    • Total Posts : 17
    • Reward points : 0
    • Joined: 2017/09/15 07:59:15
    • Location: 0
    • Status: offline
    Re: PIC24FJ128GA204 Bootloader p24qp.exe problem:PICUNKNOWN, referring to AN1157 2017/12/07 10:58:42 (permalink)
    0
    Ok, thanks, I think I am getting it slowly.
    Another (hopefully my last) question is, what does this line mean:

    SHORT(DEFINED(__IC9Interrupt) ? ABSOLUTE(__IC9Interrupt) : ABSOLUTE(__DefaultInterrupt)); SHORT(0x04); SHORT(DEFINED(__IC9Interrupt) ? (ABSOLUTE(__IC9Interrupt) >> 16) & 0x7F : (ABSOLUTE(__DefaultInterrupt) >> 16) & 0x7F); SHORT(0);
        __DEFAULT_VECTOR = .;
        SHORT(ABSOLUTE(__DefaultInterrupt)); SHORT(0x04); SHORT((ABSOLUTE(__DefaultInterrupt) >> 16) & 0x7F); SHORT(0);

     
    The thing with the DEFAULT_VECTOR. What is that period supposed to mean? My try of making sense out of this is, that you put all Interrupts consecutively together, point the original ivts to them (not in the same spacing, you threw out all unneeded interrupts) and set the DefaultInterrupt of the Bootloader to the DEFAULT_VECTOR, right? I do not fully get it.
    Thanks for your help, you pull me through this...
    Jo
    #15
    Jump to:
    © 2017 APG vNext Commercial Version 4.5