Menu

RS485 Bootloader on PIC18F13K22

2023-03-22
2023-04-12
1 2 3 > >> (Page 1 of 3)
  • Éimear Murphy

    Éimear Murphy - 2023-03-22

    Hi there,

    I'm trying to modify the bootloader to work on RS485 for PIC18F13K22. I originally confirmed my setup of the bootloader and application code (toggle a pin) works over RS232 before modifying the bootloader firmware for RS485. Currently, the check device works and the bootloader GUI is communicating with the PIC:

    Check Device...
    Open COM10 serial port at 19200bd
    Hardware RTS reseting Device
    Device answer: 0x61 0x43='C'
    byte OK, now check ID-code and Family...
    idCode = $61
    family = C
    description = 18F w/8KB flash & 256B EEPROM
    flash mem = 8192 bytes
    EEPROM mem = 256 bytes
    Bootloader size = 260 bytes
    Transfert block size = 8 bytes
    Found: 18F w/8KB flash & 256B EEPROM
    Close COM10 serial port

    However, when I try to write the application code to the PIC I get an error midway through transferring the hex file across.
    Open HEX file: C:\Projects\TESTforBTLR.X\dist\default\production\TESTforBTLR.X.production.hex
    extended address: 0x0000
    :040000000CEF00F011
    0x0000: 0C EF 00 F0
    :1000080004829EA003D09E90010E036E04921100FC
    0x0008: 04 82 9E A0 03 D0 9E 90 01 0E 03 6E 04 92 11 00
    :100018003DEF00F030EC00F00304D8A4FDD78B8C42
    0x0018: 3D EF 00 F0 30 EC 00 F0 03 04 D8 A4 FD D7 8B 8C
    :10002800080E026E9E0E016E4C0E0400E82EFDD7DF
    0x0028: 08 0E 02 6E 9E 0E 01 6E 4C 0E 04 00 E8 2E FD D7
    :10003800012EFBD7022EF9D78B9C080E026E9E0E5E
    0x0038: 01 2E FB D7 02 2E F9 D7 8B 9C 08 0E 02 6E 9E 0E
    :10004800016E4C0E0400E82EFDD7012EFBD7022EC0
    0x0048: 01 6E 4C 0E 04 00 E8 2E FD D7 01 2E FB D7 02 2E
    :10005800F9D7000E036EE0D7700ED36E949C8B9C7C
    0x0058: F9 D7 00 0E 03 6E E0 D7 70 0E D3 6E 94 9C 8B 9C
    :10006800D09E000EF26EF28EF28C9E909D80CD8016
    0x0068: D0 9E 00 0E F2 6E F2 8E F2 8C 9E 90 9D 80 CD 80
    :0E0078001200036A0490049200010EEF00F0E3
    0x0078: 12 00 03 6A 04 90 04 92 00 01 0E EF 00 F0
    extended address: 0x0020
    Warning: User ID bytes found, just writing data
    extended address: 0x0030
    -> Configuration Bytes:
    minMemPos=00000000, maxMemPos=00001F04, blockSize=8
    first 4 words at address 0x1EFC:
    0xEF0C
    0xF000
    0xFFFF
    0xFFFF
    Transferring flash...
    Transferring program memory...
    write mem pos: 0x00000000(byte)
    send: TBLPTRU=0x00, TBLPTRH=0x00, TBLPTRL=0x00, block=8
    82 EF 0F F0 FF FF FF FF
    no answer
    ERROR: problem in writing flash memory!!!
    Close COM10 serial port

    I think it's possible that the hex file is being loaded to the wrong place in memory, but I'm not sure. When I program the PIC with only application code and no bootloader direct from MPLab the hex values appear in the same position in memory as they are when the PIC is programmed with the bootloader and the application code is loaded from the bootloader GUI over RS232. When I try this with my modified RS485 bootloader, the program memory appears different seems to have different bytes stored.

    Attached is the RS485 bootloader firmware and images of the program memory, note RB7 is Tx, RB5 is Rx and RC7 is enable on my PIC- if anyone can help I'd really appreciate it :)

    Thank you,
    Éimear

     

    Last edit: Éimear Murphy 2023-03-22
  • Anobium

    Anobium - 2023-03-22

    Post the LST and ASM source. At the moment - no idea.

    The PC software you are using? How old? It must be the old buggy version.

    This is latest version. Note the corrected spelling - this should be the baseline.


    Checking device
    Open COM2 serial port at 19200 Baud Rate
    Hardware DTR resetting device
    Device answer: 0xAA 0x42='B'
    byte OK, now check ID-code and Family
    idCode = $AA
    family = B
    description = 16F w/8Kw flash & 256BEE (Blk32)
    flash mem = 16384 bytes
    EEPROM mem = 256 bytes
    Bootloader size = 200 bytes
    Transfer block size = 64 bytes
    Device detected:16F w/8Kw flash & 256BEE (Blk32)
    Closed COM2 serial port
    TinyMultiBootLoader+ device check completed

     

    Last edit: Anobium 2023-03-22
  • Anobium

    Anobium - 2023-03-22

    And, you have a transfer block of 'Transfert block size = 8 bytes' - you must have changed PICCODES.INI ?

     
  • Éimear Murphy

    Éimear Murphy - 2023-03-22

    Hello,

    Thank you for getting back to me. I have attached the ASM file to my original post, LST file attached here.
    I think my Bootloader GUI must be very old, it's v0.11.0.
    I modified my piccodes.ini file as since modifying the bootloader for RS485 increased it's size, also write/erase block sizes in the pic18f13k22 data sheet say the write block is 8 bytes. The only modification was to $61, as below:
    $61, C, 18F w/8KB flash & 256B EEPROM, $2000, $100, 260, 8,

     
  • Anobium

    Anobium - 2023-03-22

    Thanks

    Revert the block size. If the block size worked when using RS232 then why change?

    Test and post results.

     
  • Éimear Murphy

    Éimear Murphy - 2023-03-22

    I have tried with 0.14.6.5 of the PC software and default as transfer size.

    Check Device...
    Open COM10 serial port at 19200bd
    Hardware RTS reseting Device
    Device answer: 0x61 0x43='C'
    byte OK, now check ID-code and Family...
    idCode = $61
    family = C
    description = 18F w/8KB flash & 256B EEPROM
    flash mem = 8192 bytes
    EEPROM mem = 256 bytes
    Bootloader size = 260 bytes
    Transfert block size = 64 bytes
    Found: 18F w/8KB flash & 256B EEPROM
    Open HEX file: C:\Projects\TESTforBTLR.X\dist\default\production\TESTforBTLR.X.production.hex
    extended address: 0x0000
    :040000000CEF00F011
    0x0000: 0C EF 00 F0
    :1000080004829EA003D09E90010E036E04921100FC
    0x0008: 04 82 9E A0 03 D0 9E 90 01 0E 03 6E 04 92 11 00
    :100018003DEF00F030EC00F00304D8A4FDD78B8C42
    0x0018: 3D EF 00 F0 30 EC 00 F0 03 04 D8 A4 FD D7 8B 8C
    :10002800080E026E9E0E016E4C0E0400E82EFDD7DF
    0x0028: 08 0E 02 6E 9E 0E 01 6E 4C 0E 04 00 E8 2E FD D7
    :10003800012EFBD7022EF9D78B9C080E026E9E0E5E
    0x0038: 01 2E FB D7 02 2E F9 D7 8B 9C 08 0E 02 6E 9E 0E
    :10004800016E4C0E0400E82EFDD7012EFBD7022EC0
    0x0048: 01 6E 4C 0E 04 00 E8 2E FD D7 01 2E FB D7 02 2E
    :10005800F9D7000E036EE0D7700ED36E949C8B9C7C
    0x0058: F9 D7 00 0E 03 6E E0 D7 70 0E D3 6E 94 9C 8B 9C
    :10006800D09E000EF26EF28EF28C9E909D80CD8016
    0x0068: D0 9E 00 0E F2 6E F2 8E F2 8C 9E 90 9D 80 CD 80
    :0E0078001200036A0490049200010EEF00F0E3
    0x0078: 12 00 03 6A 04 90 04 92 00 01 0E EF 00 F0
    extended address: 0x0020
    Warning: User ID bytes found, just writing data
    extended address: 0x0030
    -> Configuration Bytes:
    minMemPos=00000000, maxMemPos=00001F04, blockSize=64
    first 4 words at address 0x1EFC:
    0xEF0C
    0xF000
    0xFFFF
    0xFFFF
    Transferring flash...
    Transferring program memory...
    write mem pos: 0x00000000(byte)
    send: TBLPTRU=0x00, TBLPTRH=0x00, TBLPTRL=0x00, block=64
    82 EF 0F F0 FF FF FF FF 04 82 9E A0 03 D0 9E 90 01 0E 03 6E 04 92 11 00 3D EF 00 F0 30 EC 00 F0 03 04 D8 A4 FD D7 8B 8C 08 0E 02 6E 9E 0E 01 6E 4C 0E 04 00 E8 2E FD D7 01 2E FB D7 02 2E F9 D7
    no answer
    ERROR: problem in writing flash memory!!!
    Close COM10 serial port


     

    Last edit: Éimear Murphy 2023-03-22
  • Anobium

    Anobium - 2023-03-22

    Can I confirm?
    - this is tbl firmware that works with rs232?
    - this is using rs232 ?

    Go back to the rs232 firmware with a stock PICCODES.INI - does this work?

    I would like to get back to something that works as a baseline.

     
  • Éimear Murphy

    Éimear Murphy - 2023-03-22

    Yes so the hex code, which toggles a pin worked for the bootloader code when I used RS232. The hex is unchanged and is below:

    :020000040000FA
    :040000000CEF00F011
    :1000080004829EA003D09E90010E036E04921100FC
    :100018003DEF00F030EC00F00304D8A4FDD78B8C42
    :10002800080E026E9E0E016E4C0E0400E82EFDD7DF
    :10003800012EFBD7022EF9D78B9C080E026E9E0E5E
    :10004800016E4C0E0400E82EFDD7012EFBD7022EC0
    :10005800F9D7000E036EE0D7700ED36E949C8B9C7C
    :10006800D09E000EF26EF28EF28C9E909D80CD8016
    :0E0078001200036A0490049200010EEF00F0E3
    :020000040020DA
    :08000000FFFFFFFFFFFFFFFF00
    :020000040030CA
    :0E000000FF081F12FF8081FF03C003E00340D2
    :00000001FF

    I have attached the ASM code I used to get the bootloader working with RS232 and this hex.

    The main modification to this code for RS485 was was setting up RC7 as an out and pulling it high before the bootloader transmits and setting it low after a transmission is complete.

    I am not sure what you mean by a stock in piccodes.ini but this file was unchanged in my RS232 bootloader and the important line for my pic is $61, C, 18F w/8KB flash & 256B EEPROM, $2000, $100, default, default,

     
  • Anobium

    Anobium - 2023-03-22

    Ok. As this works and all you need to do is add RC7 control then do this.

    This will reduce the size of the TBL. Make the changes and test, hopefully still works. So, then, you should have the deadroom for your changes with changing the 100 words.

    1. Set the config to the internal oscillator to 16mHz, then, remove the OSSCON instruction
    2. Remove clrf cnt2 & clrf cnt3 as these will be zero after a POR
    3. Remove movlw 0x07 ;clear Analog port 11 bit, rest (8,9,10) as after hard reset movwf ANSELH ; configure as expected. and replace with clrf ANSELH
    4. Remove bcf RCSTA,SPEN ; deactivate UART - having the USART operational is not a bad thing. Turn it off in the main program if not required.

    MPASM shows this with these changes. Many words left.

    0000 : XXXX------------ ---------------- ---------------- ----------------
    1F00 : ---------------- ---------------- ---------------- --------XXXXXXXX
    1F40 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX
    1F80 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX
    1FC0 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXX------------
    0000 : -XXX-XX-XXXXXX-- ---------------- ---------------- ----------------
    

    I think the method in the ASM is not optimised. It uses to much code. Our solution is as follows and this is a generic solution for that chip that could have be even smaller. But, this is not published here as we required donations to the project.

    0000 : XXXX------------ ---------------- ---------------- ----------------
    1F00 : ---------------- ---------------- ---------------- --------XXXXXXXX
    1F40 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX
    1F80 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX
    1FC0 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX ----------------
    0000 : -XXX-XX-XXXXXX-- ---------------- ---------------- ----------------
    

    Anyway, make the changes recommended and then test.

     
  • Éimear Murphy

    Éimear Murphy - 2023-03-24

    Hi Anobium,

    Thanks for your suggestions.

    I have implemented points 2, 3, 4. Unfortunately, removing OSSCON instruction means that I'm operating at the default internal oscillator value of 1MHz. I have tried dividing spbrg_value by whole numbers close to 16 but unfortunately the bit time isn't close enough to the original to allow the GUI to recognise the 0x61 value correctly. I have attached the ASM file.

    Having implemented points 2, 3, and 4, I can confirm that the bootloader is working as expected.

    Kind regards,

     

    Last edit: Éimear Murphy 2023-03-24
    • Anobium

      Anobium - 2023-03-24

      Change the config to a higher frequency. You can change again in your user program.

      Try to get those words removed.

      Let me if you sort.

       
  • Éimear Murphy

    Éimear Murphy - 2023-03-29

    Hi Anobium,

    Unfortunately no baud rate would work to allow communications between the bootloader and the GUI with a manipulated spbrg value.

    I will now look through the code to see if an alternative instruction can be removed to free more space. I will update if I find anything.

    Thanks& regards

     
  • Éimear Murphy

    Éimear Murphy - 2023-03-30

    Hi Anobium,

    I have reduced the size of my program, please see attached .asm file. Now I will begin working on RC7 control.

    Thanks & regards,

     
  • Anobium

    Anobium - 2023-03-30

    Does the TBL still work? That is an important test.

     
  • Éimear Murphy

    Éimear Murphy - 2023-03-30

    Yes TBL still works with code removed

     
  • Anobium

    Anobium - 2023-03-30

    "removed" means "rationalised" :-)

    Before you add the the port control. What is the pusedo code ?

     
  • Éimear Murphy

    Éimear Murphy - 2023-03-30

    Haha yes, rationalised. Very roughly, planning to do the following:
    Set RC7 to digital o/p.
    Replace movwf TXREG with a function.
    Function should set RC7 high, transmit working register, then set RC7 low.
    I'm not sure if I'll need to add a delay.

    Is this the correct approach in your opinion? Please advise. I'm not sure if I'll have enough space.

     
  • Anobium

    Anobium - 2023-03-30

    I dont think so.

    When does RC7 need to go high? and, when low?

     
  • Éimear Murphy

    Éimear Murphy - 2023-03-31

    RC7 is connected to the enable pin of the RS485 chip. It needs to go high when the Pic wants to transmit, and low in order for it to receive data from the GUI.

     
  • Anobium

    Anobium - 2023-03-31

    You need to add four instruction - I believe.

    • Set the port to an output bcf TRISC,7,ACCESS. Just beforeclrf ANSEL ; setup digital I/O
    • Then, in RECEIVE add BCF LATC,7,ACCESS at the start, andBSF LATC,7,ACCESS twice ( befire the return and before WAY_TO_EXIT:).

    Agree > and this will fit within the 100 bytes.

     
  • Éimear Murphy

    Éimear Murphy - 2023-04-03

    Hi Anobium,

    Thanks for your help. I tried your solution and it didn't work but I implemented a different solution and have had some success (see .asm attahced). The application code I posted above can be successfully write to the PIC via TBL.

    The application code above, to toggle a pin/ blink LED, was just a simple test program. My actual application code is a bit longer (having read back the program from my PIC on an ICD 4 the real application code finishes at address 1090 without bootloader code). The TBL GUI starts writing the program to the PIC memory but stops and gives the following error:

    0x1080: D0 EC 07 F0 12 00 A2 0E 04 6E 00 0E 05 6E 12 00
    extended address: 0x0020
    User ID(s) removed from source
    extended address: 0x0030
    -> Configuration Bytes:
    minMemPos=00000000, maxMemPos=00001F40, blockSize=64
    first 4 words at address 0x1F38:
    0xEF7C
    0xF000
    0xFFFF
    0xFFFF
    Uploading PROGMEM
    Uploading program memory
    write mem pos: 0x00000000(byte)
    send: TBLPTRU=0x00, TBLPTRH=0x00, TBLPTRL=0x00, block=64
    A0 EF 0F F0 FF FF FF FF 58 82 D9 CF 02 F0 DA CF 03 F0 9E A0 07 D0 9E 90 B1 0E CF 6E E0 0E CE 6E 01 0E 47 6E A1 A2 62 D0 A1 92 F8 0E B3 6E 30 0E B2 6E 9E AA 5B D0 AB CF 01 F0 06 0E 01 16 D8 B4
    no answer
    ERROR: Problem in uploading HEX file to device
    Closed COM10 serial port
    TinyMultiBootLoader+ completed

    Do you know what my problem might be? Is the real application code too long ?

    Thank you again for your help,
    Eimear

     
  • Anobium

    Anobium - 2023-04-03

    Questions:

    Did you test and get things to work with just the NO EE write operations? So, did you fully test that the removal of the NO EE write operations worked before you changed the the next step. So, no RS485 support and the same Write process. Did this all work ok?

    Then, did you test with just the changes to the Write process. So, building on the NO EE, just the change to call SendW ? Did this all work ok?

    No I dont what the issue is but confirm the two states above may help.

    PS This is why write bootloaders for people. .... this is a tought process of testing.

     
  • Éimear Murphy

    Éimear Murphy - 2023-04-04

    Hi,

    I reverted to the RS232 version of my asm code. I could check device and write the blink application code to the device. However, my real application code does not work in this instance too.

    Re-commenting the EEPROM code, and trying again. check device and the blink code programs, the real application code does not. I tried this also with RS485, again the blink program works and the real application code does not.
    Thanks

     
  • Anobium

    Anobium - 2023-04-04

    Send me the asm and hex fo rTBL and your real application hex.

    Send me a PM to get my email address, if you do not want to post your real application hex

     
  • Anobium

    Anobium - 2023-04-04

    I want to load into PICKitPlus and look at the file.

     
1 2 3 > >> (Page 1 of 3)

Log in to post a comment.