Ray Ellam - 2016-04-10

Some help is required from anyone who has had sucsess cofiguring different PIC parts? I am trying to add a PIC24EP256GP204 and what follows is the process i have used.

  1. looking at the momory map details i assumed that the 24E falls in the type D family?
  2. I added the new part to the PICini file but then found there was an existing entry for PIC24E, device ID $70
  3. I started with an existing D family PIC24 source file, TinyBld_PIC24F32KA301.s
  4. I modified the file for PIC24EP256GP204
  5. I built the project but it return 2 asm errors, undefined symbol ERASE' in operation: undefined symbolNVMOP4' in operation.
  6. I looked at the p24EP256GP204.inc file and see there are no references to the above 2 symbols.

Can any one help me out here? there is a virtual cold beer for help :-) and i will post the working files to this forum. Below is my .s file

    ; change these lines accordingly to your application    
.equ __24EP256GP204, 1
.include "p24EP256GP204.inc"
.equ IdTypePIC, 0x70        ; Please refer to the table below, must exists in "piccodes.ini"    
.equ max_flash, 0x55800     ; PIC max address, not bytes!!! (= 'max flash memory' from "piccodes.ini" divided by 2), Please refer to the table below

.equ Fcy,  140030000/2      ; PIC24E, Fcy=Fosc/2
.equ baud, 19200            ; standard TinyBld baud rates: 115200 or 19200
.equ UART_CH, 1             ; select UART(1/2)

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

; +---------+------------+------------+------------+---------------+---------------+-----------+--------+
; |IdTypePIC|   Device   | Write_Page | Erase_Page | TX port(U1/U2)| RX port(U1/U2)| max_flash | EEPROM |
; +---------+------------+------------+------------+---------------+---------------+-----------+--------+
; |   0x14  | 24F16KA301 |  32 instr. |  32 instr. | B7(11)/B0(4)  |  B2(6)/B1(5)  |   0x2C00  |  512   |
; |   0x15  | 24F32KA301 |  32 instr. |  32 instr. | B7(11)/B0(4)  |  B2(6)/B1(5)  |   0x5800  |  512   |
; |   0x14  | 24F16KA302 |  32 instr. |  32 instr. | B7(16)/B0(4)  |  B2(6)/B1(5)  |   0x2C00  |  512   |
; |   0x15  | 24F32KA302 |  32 instr. |  32 instr. | B7(16)/B0(4)  |  B2(6)/B1(5)  |   0x5800  |  512   |
; |   0x14  | 24F16KA304 |  32 instr. |  32 instr. |  C7(3)/B0(21) |  C6(2)/B1(22) |   0x2C00  |  512   |
; |   0x15  | 24F32KA304 |  32 instr. |  32 instr. |  C7(3)/B0(21) |  C6(2)/B1(22) |   0x5800  |  512   |
; +---------+------------+------------+------------+---------------+---------------+-----------+--------+
; |   0x14  | 24FV16KA301|  32 instr. |  32 instr. | B7(11)/B0(4)  |  B2(6)/B1(5)  |   0x2C00  |  512   |
; |   0x15  | 24FV32KA301|  32 instr. |  32 instr. | B7(11)/B0(4)  |  B2(6)/B1(5)  |   0x5800  |  512   |
; |   0x14  | 24FV16KA302|  32 instr. |  32 instr. | B7(16)/B0(4)  |  B2(6)/B1(5)  |   0x2C00  |  512   |
; |   0x15  | 24FV32KA302|  32 instr. |  32 instr. | B7(16)/B0(4)  |  B2(6)/B1(5)  |   0x5800  |  512   |
; |   0x14  | 24FV16KA304|  32 instr. |  32 instr. |  C7(3)/B0(21) |  C6(2)/B1(22) |   0x2C00  |  512   |
; |   0x15  | 24FV32KA304|  32 instr. |  32 instr. |  C7(3)/B0(21) |  C6(2)/B1(22) |   0x5800  |  512   |
; +---------+------------+------------+------------+---------------+---------------+-----------+--------+

;PC_flash:  L       H       U      96       ...  [DataL DataH DataU]*32   ...          crc
;PC_cfg:        L       H       U      18       ...  [CFGDataL CFGDataH]*9    ...          crc
;PIC_response:  type `D`

;;;;;;  PC_cfg Data:[CFGDataL CFGDataH 0]*9 (Type D) ;;;;;
;0xF80000                0xF80008                      0xF80012
;+-----+-----+-----+-----+-----+-----+-----+-----+-----+
;|  O  |  O  |  O  |  O  |  O  |  O  |  O  |  O  |  X  | for dsPIC30F
;+-----+-----+-----+-----+-----+-----+-----+-----+-----+
;+-----+-----+-----+-----+-----+-----+-----+-----+-----+
;|  X  |  X  |  O  |  O  |  O  |  O  |  O  |  O  |  O  | for PIC24FXXKA201/202
;+-----+-----+-----+-----+-----+-----+-----+-----+-----+
;+-----+-----+-----+-----+-----+-----+-----+-----+-----+
;|  O  |  O  |  O  |  O  |  O  |  O  |  O  |  O  |  O  | for PIC24FXXKA3XX, PIC24FXXKA101/102
;+-----+-----+-----+-----+-----+-----+-----+-----+-----+
;+-----+-----+-----+-----+-----+-----+-----+-----+-----+
;|  O  |  O  |  O  |  O  |  O  |  O  |  O  |  O  |  X  | for PIC24FXXKLXXX, PIC24FXXKMXXX
;+-----+-----+-----+-----+-----+-----+-----+-----+-----+
;+-----+-----+-----+-----+-----+-----+-----+-----+-----+
;|  O  |  O  |  O  |  O  |  O  |  O  |  O  |  O  |  X  | for PIC24H
;+-----+-----+-----+-----+-----+-----+-----+-----+-----+
;+-----+-----+-----+-----+-----+-----+-----+-----+-----+
;|  O  |  O  |  O  |  O  |  O  |  O  |  O  |  O  |  O  | for PIC24EPXXXGU810/814,PIC24EP512GP806
;+-----+-----+-----+-----+-----+-----+-----+-----+-----+
;+-----+-----+-----+-----+-----+-----+-----+-----+-----+
;|  O  |  O  |  O  |  O  |  O  |  O  |  O  |  O  |  O  | for dsPIC33FJ32GS406/606/608/610, 33FJ64GS406/606/608/610
;+-----+-----+-----+-----+-----+-----+-----+-----+-----+
;+-----+-----+-----+-----+-----+-----+-----+-----+-----+
;|  O  |  O  |  O  |  O  |  O  |  O  |  O  |  O  |  X  | for other dsPIC33F
;+-----+-----+-----+-----+-----+-----+-----+-----+-----+
;+-----+-----+-----+-----+-----+-----+-----+-----+-----+
;|  O  |  O  |  O  |  O  |  O  |  O  |  O  |  O  |  O  | for dsPIC33EP256MU806, dsPIC33EPXXXMU810/814,
;+-----+-----+-----+-----+-----+-----+-----+-----+-----+     dsPIC33EP512(MC/GP)806
;X:Invalid(recive only), O:Effectiveness, rewrite Config

.IF (UART_CH == 2)
 .equ UxMODE, U2MODE
 .equ UxSTA, U2STA
 .equ UxBRG, U2BRG
 .equ UxTXREG, U2TXREG
 .equ UxRXREG, U2RXREG
.ELSE
 .equ UxMODE, U1MODE
 .equ UxSTA, U1STA
 .equ UxBRG, U1BRG
 .equ UxTXREG, U1TXREG
 .equ UxRXREG, U1RXREG
.ENDIF

        ;********************************************************************
    ;   Tiny Bootloader PIC 24F(V)16KA30X 24F(V)32KA30X Size=100words
    ;
        ;       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/
    ;
    ;
        ;********************************************************************

config          __FICD, ICS_PGD1 & JTAGEN_OFF
config          __FPOR, ALTI2C1_ON & ALTI2C2_OFF
config          __FWDT, WDTPOST_PS256 & WINDIS_OFF & PLLKEN_ON & FWDTEN_OFF
config          __FOSC, POSCMD_NONE & OSCIOFNC_ON & IOL1WAY_OFF & FCKSM_CSECME
config          __FOSCSEL, FNOSC_FRCPLL & IESO_ON
config          __FGS, GWRP_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 64       ;stack
buffer: .space 32*3     ;Data

    .text
.equ    bl_size ,32*3*2                     ;size of bootloader:32*3+4 = 100instr.

    .org    max_flash - 0x200 - bl_size - 4*2
first_address:
    NOP
    NOP
    NOP
    NOP
__reset:                                    ;Start of main code label, initial stack pointer = 0x800
    BCLR    AD1CON1,#ADON                   ;A/D Converter is off
    COM ANSB                                ;All Degital Port
init_uart:                                  ;Initialize and Enable UART1 for Tx and Rx
    bset    UxMODE,#UARTEN
    bset    UxSTA,#UTXEN
        mov     #(((Fcy/baud) / 16) - 1),W0 ;?Initialize Baud rate (divide INSTRUCTION Cycle)
        mov     W0,UxBRG                    ;to 115200 Kbaud #(((8000000/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,UxTXREG

MainLoop:
    mov.b   #'D',W0                         ; "-Everything OK, ready and waiting."
mainl:
    mov     W0,UxTXREG
    clr     W1                              ;clear chksum
    rcall   Receive                         ;set EA,TBLPAG,Count
    mov.b   WREG,WREG2L
    rcall   Receive
    mov.b   WREG,WREG2H
;;;;;
    mov WREG2,W2                            ;W2 = EA
;;;;;
    rcall   Receive
    mov     W0,TBLPAG                       ;set TBLPAG
    rcall   Receive
    mov W0,W12                              ;W12 = count
    mov     #buffer,W3                      ;W3 = Data buffer TOP
dorcv:
    rcall   Receive
    mov.b   W0,[W3++]
    dec     W12,W12
    bra     NZ,dorcv

    rcall   Receive                         ;check CRC
ziieroare:
    mov.b   #'N',W0
    bra     NZ,mainl

    mov #buffer,W3                          ;W3 = Data buffer TOP
    btss    TBLPAG,#7                       ;is CFG data?
    bra noconfig

wr_cfg:
    mov #8,W12                              ; W12 = loop counter
wr_cfg_lp:
    TBLWTL  [W3++],[W2]                     ; write into program latch
    MOV     #((1<<WREN)|(1<<NVMOP2)),W0     ; write Config:0x4004
    rcall   Key_Sequence
    inc2    W2,W2
    dec     W12,W12
    bra NZ,wr_cfg_lp
    bra     MainLoop

noconfig:
    btss    TBLPAG,#6                       ; is EEPROM data?
    bra wr_flash

wr_EEPROM:
    TBLWTL  [W3],[W2]                       ; write into program latch
    MOV     #((1<<WREN)|(1<<NVMOP2)),W0     ; write EEPROM:0x4004
    rcall   Key_Sequence
    bra     MainLoop

wr_flash:
    TBLWTL  W0,[W2]                 ; dummy
    MOV     #((1<<WREN)|(1<<ERASE)|(1<<NVMOP4)|(1<<NVMOP3)),W0  ;Page Erase:0x4058
    rcall   Key_Sequence
    mov #32,W12                         ; W12 = loop counter
w_l:
    TBLWTL.B [W3++],[W2++]              ; Write PM low word into program latch
    TBLWTL.B [W3++],[W2--]              ; Write PM high byte into program latch
    TBLWTH.B [W3++],[W2]                ; Write PM middle word into program latch
    inc2    W2,W2
    dec W12,W12
    bra     NZ,w_l
    MOV #((1<<WREN)|(1<<NVMOP2)),W0     ;Page Write:0x4004
    rcall   Key_Sequence
    bra MainLoop

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

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
    NOP
    NOP
Key_Wait:
    btsc    NVMCON,#15
    bra     Key_Wait
    RETURN

Receive:
    mov     #(2*Fcy/2000000+1),W10  ; ms to wait
rpt2:
    clr     W11
rpt1:
    btss    UxSTA,#URXDA
    bra     norcv
    mov     UxRXREG,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     UxMODE              ; deactivate UART
    bra     first_address

.end