Menu

Is the Bootloader living? dspic33ep64(16)gs506

2024-01-30
2024-02-13
  • Michael Groß-Bölting

    Hello
    i created a firmware for:
    dspic33ep64(16)gs506
    But is the TinyBootloader living?
    Where can i get the SourceCode from the 14.6.5
    Greetings
    Michael

     
  • Anobium

    Anobium - 2024-01-30

    Very much alive.

    See the CODE tab for the source.

     
  • Michael Groß-Bölting

    Ther is SW12.5 the actual is 14.6.5!
    Greetings
    Michael

     
  • Anobium

    Anobium - 2024-02-01

    I will locate the source.

    Re the Windows EXE. What to change you need? we have another application suite for a specfic use cases, like
    1. School usage where the only want to press 'load'. Chip type and hex are predetermined
    2. Factory/manufacturing use where only the HEX is selectable
    3. Encrpyting and decrypting the HEX in two applications to permit the sharing of the HEX but the end user cannot reverse engineer the HEX.

     
  • Michael Groß-Bölting

    I need no change, i only want to have and understand it!

     
  • Anobium

    Anobium - 2024-02-03

    Sure. I have uploaded to the existing Git. https://github.com/Anobium/TinyMultiBootLoader/tree/master

     
  • Michael Groß-Bölting

    Thanks!
    My Firmware is running. But comments/structure is not so good. Can someone help me?
    No time in the moment.

     
    • Anobium

      Anobium - 2024-02-06

      Sure. I know the software and the firmware extremely well.

      What do mean by 'comments/structure'? the application or the firmware?

       
  • Michael Groß-Bölting

    I only changed the firmware. This pics have different EEPROM commands!
    I can send you the firmware. But it is not beautiful!

     
    • Anobium

      Anobium - 2024-02-08

      Any working Bootloader is a thing of beauty!!

       

      Last edit: Anobium 2024-02-08
  • Michael Groß-Bölting

    ; change these lines accordingly to your application
    

    .equ __dspic33ep16gs506, 1
    .include "C:\Program Files\Microchip\xc16\v2.10\support\dsPIC33E\inc\p33ep16gs506.inc"
    ;.equ IdTypePIC, 0xA3 ; Please refer to the table below, must exists in "piccodes.ini"
    .equ IdTypePIC, 0x35
    ;.equ max_flash, 0xAC00 ; 24FJ max address, not bytes!!! (= 'max flash memory' from "piccodes.ini" divided by 2), Please refer to the table below
    .equ max_flash, 0x2B7E
    ;.equ Fcy, 8000000/2 ; you may also want to change: _HS_OSC _XT_OSC
    ;.equ baud, 19200 ; standard TinyBld baud rates: 115200 or 19200
    .equ Fcy, 7372800*12 ; you may also want to change: _HS_OSC _XT_OSC
    .equ baud, 115200 ; standard TinyBld baud rates: 115200 or 19200

    .equ cfg_l, 4 ; Configure length(instr.)
    .equ UART_CH, 1 ; select UART(1/2)
    .equ RX, 9 ; RX Pin = PRn Pin
    .equ TX, 8 ; TX Pin = PRn Pin
    .equ NVMaddrl, 0x72A
    .equ NVMSRCaddrl, 0x730

    ; The above 10 lines can be changed and buid a bootloader for the desired frequency (and PIC type)

    ; +---------+-------------+------------+------------+-------------+--------------+-----------+--------+-------+
    ; |IdTypePIC| Device | Write_Page | Erase_Page | TX port | RX port | max_flash | EEPROM | cfg_l |
    ; +---------+-------------+------------+------------+-------------+--------------+-----------+--------+-------+
    ; | 0xA1 | 24FJ32GB002 | 64 instr. | 512 instr. | RP0~RP15 | RP0~RP15,Vss | 0x5800 | 0 | 4 |
    ; | 0xA1 | 24FJ32GB004 | 64 instr. | 512 instr. | RP0~RP25 | RP0~RP25,Vss | 0x5800 | 0 | 4 |
    ; | 0xA3 | 24FJ64GB002 | 64 instr. | 512 instr. | RP0~RP15 | RP0~RP15,Vss | 0xAC00 | 0 | 4 |
    ; | 0xA3 | 24FJ64GB004 | 64 instr. | 512 instr. | RP0~RP25 | RP0~RP25,Vss | 0xAC00 | 0 | 4 |
    ; +---------+-------------+------------+------------+-------------+--------------+-----------+--------+-------+

    ;max_flash-2048 +---------------+ 1.Copy Flash to RAM +---------------+ +---------------+
    ; | | 2.Rewrite Config or not | | | |
    ; | | 3.Erase upper Flash Page | 0xFFFF | | 0xFFFF |
    ; | User Program1 | 4.Copy RAM to Flash | | | |
    ; | | 5.Move PC to upper Flash | | | |
    ;max_flash-1280 | | 6.Erase lower Flash Page +---------------+ +---------------+
    ; | | 7.Copy RAM to Flash | Bootloader |<-PC | Bootloader |
    ;max_flash-1028 | | 8.Move PC to lower Flash +---------------+ +---------------+
    ; | | 9.Write User Program | Configure1 | | Configure1 |
    ;max_flash-1024 +---------------+ and Vector +---------------+ +---------------+
    ; | | | | | |
    ; | User Program2 | | User Program2 | | 0xFFFF |
    ;max_flash-264 +---------------+ +---------------+ | |
    ; | Vector | <ram> | Vector | | |
    ;max_flash-256 +---------------+ buffer+---------------+ +---------------+ +---------------+
    ; | Bootloader | | Bootloader | | Bootloader | | Bootloader |<-PC
    ;max_flash-4 +---------------+ +---------------+ +---------------+ +---------------+
    ; | Configure0 | | Configure1 | | Configure0 | | Configure1 |
    ;max_flash +---------------+ +---------------+ +---------------+ +---------------+</ram>

    ;PC_flash: L H U 192 ... [DataL DataH DataU]64 ... crc
    ;PC_cfg: L H U 30 ... [CFGDataL CFGDataH 0]
    10 ... crc
    ;PC_cfg_unnecessary: 0 crc
    ;PIC_response: type E

    ;;;;;; PC_cfg Data:[CFGDataL CFGDataH 0]10 (Type E) ;;;;;
    ;max_flash-10instr.
    2 max_flash
    ;+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
    ;| X | X | X | X | X | X | X | X | O | O | for PIC24FJXXXMCXXX, PIC24FJXXXGA0XX
    ;+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
    ;+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
    ;| X | X | X | X | X | X | X | O | O | O | for PIC24FJ(64/128/192/256)(GA/GB)106/108/110
    ;+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
    ;+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
    ;| X | X | X | X | X | X | O | O | O | O | for other PIC24FJ
    ;+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
    ;+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
    ;| O | O | O | O | O | O | O | O | O | O | for PIC24EPXXX(GP/MC)20X
    ;+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
    ;+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
    ;| X | X | O | O | O | O | O | O | O | O | for dsPIC33FJ06GS001/101A/102A/202A/302
    ;+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
    ;+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
    ;| X | X | X | X | X | X | X | X | O | O | for dsPIC33FJ16(GP/MC)101/102,
    ;+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+ dsPIC33FJ32(GP/MC)101/102/104
    ;+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
    ;| O | O | O | O | O | O | O | O | O | O | for dsPIC33EPXXXGP50X, dsPIC33EPXXXMC20X/50X,
    ;+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+ dsPIC33EPXXXGM3XX/6XX/7XX
    ;X:Invalid(recive only), O:Effectiveness, rewrite Config

    .IF (UART_CH == 1)
    .equ UxMODE, U1MODE
    .equ UxSTA, U1STA
    .equ UxBRG, U1BRG
    .equ UxTXREG, U1TXREG
    .equ UxRXREG, U1RXREG
    .equ UxPINR, RPINR18
    .equ UxTX, #3 ;U1TX = #3
    .ELSE
    .equ UxMODE, U2MODE
    .equ UxSTA, U2STA
    .equ UxBRG, U2BRG
    .equ UxTXREG, U2TXREG
    .equ UxRXREG, U2RXREG
    .equ UxPINR, RPINR19
    .equ UxTX, #5 ;U2TX = #5
    .ENDIF

        ;********************************************************************
    ;   Tiny Bootloader     24FJ32GB002/4 24FJ64GB002/4 Size=132words
        ;       claudiu.chiculita@ugal.ro
        ;       http://www.etc.ugal.ro/cchiculita/software/picbootloader.htm
    ;
    ;   This program is only available in Tiny AVR/PIC Bootloader +.
    ;
    ;   Tiny AVR/PIC Bootloader +
    ;   https://sourceforge.net/projects/tinypicbootload/
    ;
    ;   $A1, E, PIC24FJ w/32KB flash,      $B000, 0, default, default,
    ;   $A3, E, PIC24FJ w/64KB flash,     $15800, 0, default, default,
    ;
        ;********************************************************************
    

    ;config __CONFIG4, DSWDTPS_DSWDTPS0 & DSWDTOSC_SOSC & RTCOSC_LPRC & DSBOREN_OFF & DSWDTEN_OFF
    ;config __CONFIG3, WPFP_WPFP0 & SOSCSEL_IO & WUTSEL_LEG & WPDIS_WPDIS & WPCFG_WPCFGDIS & WPEND_WPSTARTMEM
    ;config __CONFIG2, POSCMOD_NONE & I2C1SEL_PRI & IOL1WAY_OFF & OSCIOFNC_ON & FCKSM_CSDCMD & FNOSC_FRC & PLL96MHZ_OFF & PLLDIV_NODIV & IESO_OFF
    ;config __CONFIG1, WDTPS_PS1 & FWPSA_PR32 & WINDIS_OFF & FWDTEN_OFF & ICS_PGx1 & GWRP_OFF & GCP_OFF & JTAGEN_OFF

    ;REGISTRY:
    ;W0 imediat
    ;W1 crc
    ;W2 EA Write
    ;W3 memory buffer pointer
    ;W4
    ;W5
    ;W6
    ;W7
    ;W8
    ;W9
    ;W10 delay1
    ;W11 delay2
    ;W12 for/do
    ;W13
    ;W14 void(black hole)
    ;W15 stack

        .global __reset
    
    
    .section RAM,bss
    

    stack: .space 128 ;stack
    buffer: .space (643)+(643)+(643)+(643)+(643)+(643)+(643)+(643) ;Data
    ;buffer2: .space (643)+(643) ;Data

    .text
    

    .equ bl_size ,132 ;size of bootloader:64*2+4 = 132instr.

    ;.org   max_flash  - bl_size - 0x204
    ;.org   0x275E
    .org    0x2690
    

    first_address:
    NOP
    NOP
    NOP
    NOP

    __reset: ;Start of main code label, initial stack pointer = 0x800
    ; BSET PMD1,#ADC1MD ;A/D module disable
    ; COM AD1PCFG ;All Degital Port
    MOV #OSCCON,W1 ;OSCCON (low byte) Unlock Sequence
    MOV #0x46,W2
    MOV #0x57,W3

    MOV.B   W2,[W1]     ; Write 0x46
    MOV.B   W3,[W1]     ; Write 0x57
    BCLR.B  OSCCON,#IOLOCK  ; Unlock
    ;bclr   INTCON2,#15
    mov #0x01,W0    ;TX PIN zuweisen
    mov W0,RPOR2
    
    mov #62,W0  ;RX PIN zuweisen
    mov W0,RPINR18
    
    
    ;MOV    #RX,W0      ;Set RX port    ;assign TX and RX port
    ;MOV.B  WREG,UxPINR
    
    ;MOV    #UxTX,W0    ;Set TX port
    ;MOV.B  WREG,(RPOR0+TX)
    
    MOV.B   W2,[W1]     ; Write 0x46
    MOV.B   W3,[W1]     ; Write 0x57
    BSET.B  OSCCON,#IOLOCK  ; Relock
    ;MOV     #0x1050,W15
    BCLR.B  TRISC,#TRISC2   ; Output
    BSET.B  LATC,#LATC2 ; Output
    

    init_uart: ;Initialize and Enable UART for Tx and Rx
    bset UxMODE,#UARTEN
    bset UxSTA,#UTXEN
    bset UxMODE,#BRGH
    mov #(((Fcy/baud) / 16) - 1),W0 ;?Initialize Baud rate (divide INSTRUCTION Cycle)
    mov W0,UxBRG ;to 115200 Kbaud #(((7372800/115200) / 16) - 1)

    rcall   Receive             ;wait for computer
    sub.b   #0xC1,W0            ;Expect C1h
    bra NZ,way_to_exit
    mov.b   #IdTypePIC,W0           ;send PIC type
    mov W0,U1TXREG
    

    stx: btsc U1STA,#UTXBF
    bra stx

    mov.b   #'E',W0             ; "-Everything OK, ready and waiting."
    mov     W0,U1TXREG
    
    ;mov    #(((0x2A00)>>16)&0xFFFF),W0 ;set TBLPAG
    ;mov    #0x0,W0
    ;mov    W0,TBLPAG
    ;mov    #((max_flash - bl_size)&0xFFFF),W2      ;W2 = EA
    ;clr    TBLPAG
    mov #0x2A00,W2
    mov #buffer,W3                  ;W3 = Data buffer TOP
    mov #256,W12                    ;W12 = loop counter
    

    cp_bl: ;copy bootloader to RAM
    TBLRDL.B [W2++],[W3++]
    TBLRDL.B [W2--],[W3++]
    TBLRDH.B [W2],[W3++]
    mov.b W0,[W3]
    inc2 W2,W2
    inc W3,W3
    dec W12,W12

    bra     NZ,cp_bl
    

    rcv_cfg:
    clr W1 ;clear chksum
    rcall Receive
    bra Z,chk_crc ;branch if not CFG_Address(L) muss wohl krum am Ende sein!
    mov #(3+(10-cfg_l)3),W12 ;W12 = count 0x15
    rcall dorcv ;recive Config H,U,C and (10-cfg_l)
    3bytes (dummy write)
    rewrite_cfg:
    ;mov #buffer+(bl_size/2-cfg_l)3,W3 ;W3 = Config location in the buffer 0x114A
    mov #buffer,W3
    mov #cfg_l
    3,W12 ;W12 = count 0xc
    rcall dorcv ;recive Config data and rewrite buffer
    chk_crc:
    rcall Receive ;get crc
    bra NZ,way_to_exit ;crc error

    wr_bl1:
    mov #0x02400,W2 ;set EA
    rcall wr_bld ;write bootloader
    bra (wr_bl2 - 1536) ;move PC
    ;goto (wr_bl2 - 1536)
    wr_bl2:
    mov #0x02A00,W2 ;set EA
    ;stop: bra stop
    rcall wr_bld ;write bootloader

    ;bra    (MainLoop + 1536)               ;move PC
    goto    MainLoop
    

    MainLoop:
    mov.b #'E',W0 ; "-Everything OK, ready and waiting."
    mainl:
    mov W0,U1TXREG
    clr W1 ;clear chksum
    rcall Receive ;set EA,TBLPAG,Count
    mov.b WREG,WREG2L
    rcall Receive
    mov.b WREG,WREG2H ;W2 = EA
    rcall Receive
    ;mov W0,TBLPAG ;set TBLPAG
    rcall Receive
    mov W0,W12 ;W12 = count
    mov #buffer,W3 ;W3 = Data buffer TOP
    rcall dorcv ;recive Data
    rcall Receive ;check CRC
    ziieroare:
    mov.b #'N',W0
    ; mov #0x400,W8
    ; cpseq W8,W2
    ; mov.b #'N',W0
    bra NZ,mainl

    ;mov    #buffer,W3          ;W3 = Data buffer TOP
    ;mov    W2,W7           ;W12=B'XXXXXX0000000000'?
    ;and    #0x3FF,W7
    
    
    ;mov    #buffer,W3          ;W3 = Data buffer TOP
    ;rrc    TBLPAG,WREG         ;W12=((TBLPAG:W2>>2)&0xFFFF)
    clr W0
    rrc     W2,W12
    rrc     W0,W0
    rrc W12,W12
    cp0.b   W12             ;W12=B'XXXXXXXX00000000'?
    bra     NZ,noerase          ;Each 512instr.?
    
    
    
    
    ;mov    W2,W12
    

    ;.IF (max_flash == 0x2C00)
    ;mov #0x0A00,W0 ;0x0A00 = ((0x2C00 - 5122)>>2)&0xFFFF
    ; mov #0x2800,W0
    ;.IF (max_flash == 0x2C00)
    ; mov #0x0A80,W0 ;0x0A80 = ((0x2C00 - 512
    2)>>2)&0xFFFF
    ;.ENDIF
    ;.IF (max_flash == 0x5800)
    ; mov #0x1500,W0 ;0x1500 = ((0x5800 - 5122)>>2)&0xFFFF
    ;.ENDIF
    ;.IF (max_flash == 0xAC00)
    ; mov #0x2A00,W0 ;0x2A00 = ((0xAC00 - 512
    2)>>2)&0xFFFF
    ;.ENDIF
    ;mov #0x2800,W0
    ;mov #0x2800,W0
    mov #0x0A00,W0
    cpseq W12,W0 ;skip if Last Erase Page
    rcall Erase_Page
    noerase:
    mov #buffer,W3 ;W3 = Data buffer TOP
    rcall wr_64instr
    bra MainLoop

    ;-----------------------------------------------------
    

    dorcv:
    rcall Receive
    mov.b W0,[W3++]
    dec W12,W12
    bra NZ,skip1
    return

    skip1: rcall Receive
    mov.b W0,[W3++]
    ;mov.b W0,[W3++]
    dec W12,W12
    bra NZ,skip2
    return

    skip2: rcall Receive
    mov.b W0,[W3++]
    mov.b W0,[W3++]
    dec W12,W12
    bra NZ,dorcv
    return

    wr_bld:
    MOV #buffer,W3 ;W3 = Data buffer TOP
    ;mov #0x2400,W2
    ;MOV #0xFA, W0
    ;clr TBLPAG
    RCALL Erase_Page
    RCALL wr_64instr

    mov #0x80,W0
    add     W0,W2,W2
    mov #0x100,W0
    add     W0,W3,W3
    RCALL   wr_64instr
    
    mov #0x80,W0
    add     W0,W2,W2
    mov #0x100,W0
    add     W0,W3,W3
    RCALL   wr_64instr
    
    
    
    mov #0x80,W0
    add     W0,W2,W2
    mov #0x100,W0
    add     W0,W3,W3
    

    wr_64instr:
    ;mov #buffer,W3 ;W3 = Data buffer TOP
    MOV W2,NVMaddrl

    BSET    NVMCON,#RPDF        ; Select uncompressed format
    MOV W3,NVMSRCaddrl
    
    MOV #0x4002,W0
    
    BRA Key_Sequence
    

    Erase_Page:
    ;TBLWTL W0,[W2] ;dummy
    ;MOV NVMADRU

    ;clr    NVMADRH                 ;müßte immer 0 sein
    ;MOV    #tbloffset(PROG_ADDR),W0
    
    MOV W2,NVMaddrl
    ;MOV    #((1<<WREN)|(1<<ERASE)|(1<<NVMOP1)),W0  ;Page Erase:0x4042
    MOV     #0x4003,W0
    

    Key_Sequence: ; Expects a NVMCON value in W0
    MOV W0,NVMCON
    MOV #0x55,W0 ; Write the key sequence
    MOV W0,NVMKEY
    MOV #0xAA,W0
    MOV W0,NVMKEY
    BSET NVMCON,#WR ; Start the write cycle
    NVMCONSet:
    btsc NVMCON,#WR
    bra NVMCONSet
    RETURN

    Receive:
    mov #(8*Fcy/2000000+2),W10 ; ms to wait
    rpt2:
    ; clr W11
    rpt1:
    btss U1STA,#URXDA
    bra norcv
    mov U1RXREG,W0 ;W0 = Data
    add.b W0,W1,W1 ;compute crc
    return
    norcv:
    dec W11,W11
    bra NZ,rpt1
    dec W10,W10
    bra NZ,rpt2
    timeout:
    way_to_exit:
    clr U1MODE ; deactivate UART
    bra first_address

    .end

     
  • Michael Groß-Bölting

    I did not change the comments! It is only for dspic33ep16gs506!

     
  • Michael Groß-Bölting

    I did not change the comments! It is only for dspic33ep16gs506!

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.