ds30 Loader free edition forums
Software UART version running on 18F25K22 [solved] - Printable Version

+- ds30 Loader free edition forums (https://picbootloader.com/forum)
+-- Forum: Support (https://picbootloader.com/forum/forumdisplay.php?fid=3)
+--- Forum: 8-bit firmwares (https://picbootloader.com/forum/forumdisplay.php?fid=7)
+--- Thread: Software UART version running on 18F25K22 [solved] (/showthread.php?tid=184)



Software UART version running on 18F25K22 [solved] - matherp - 2011-06-09

Hi all

I have successfully built versions of the bootloader for both the 18F25K22 and 18F14K22 which are the chips used for the Picaxe 28X2 and 20X2. These have been set up with 64Mhz internal clock and inverted comms to use the standard 22k resistor picaxe download circuit but of course the bootloader uses the hardware UART whereas the picaxe uses different pins (in the case of the 28X2 it uses RA4 for RX and RA5 for TX).

It would be nice to use the bootloader in the standard picaxe development boards so I have coded a software uart at 38400 baud which uses the correct picaxe pins.

This is working to the extent that I get the following messages in the DS30 GUI:
Found PIC18F25K22fw ver. 3.0.0
Waiting for bootloader to be ready...ok

It then says:
Writing flash...bl protection tripped
Write failed

Tx 236 bytes/Rx 10 bytes /4s


The program I'm loading is a simple LED flash coded in Swordfish which works perfectly with the standard UART-based bootloader

When using the standard bootloader the GUI reports 231 bytes but with the SW UART it says 229. However, it seems to pass the checksum test OK as if I patch out the checksum test I get the expected checksum error

I had to increase BLPLP and BLSIZEP to 9 to fit the additional code into the bootloader (I've also tried 10) and have added 4 bytes at the bottom of the variable cblock.

This is my first foray into PIC assembler (my last real use of assembler was on the DEC PDP11 and Motorola 6809!). I would appreciate any insights into where to look for the problem.

I will of course be happy to share the output once this is all working

best regards

Peter


RE: Software UART version running but BL protection issue found - matherp - 2011-06-09

I've now done more work and by removing the timeout in the SW receive got the program into 8 pages the same as the hardware version and the BL protection issue has gone away. The loaded program is now identical in memory in both cases. However in the hardware version it starts and runs but in the software version it doesn't which is because it is the timeout that trips the bootloader into the entry to the loaded program.

Next step was to set BLPLP and BLSIZE back to 8 but not define PROT_BL which saves space and eliminates the error. This works and the program now runs

So the issue is that the blprot routine doesn't seem to work when BLSIZE is 9.

I think this is one for Mikael:Smile
best regards

Peter


RE: Software UART version running but BL protection issue found - Mikael Gustavsson - 2011-06-09

Hi,
It does work! Remove the protection and use size 9 and you will see that the boot loader will get partly overwritten.

You need to configure the custom boot loader size in the GUI under the advanced tab. You need to active advanced mode first.

Mikael


Software UART version running on 18F25K22 - matherp - 2011-06-09

Mikael

Many thanks - that solves that.

For anyone who is interested code to run a 38400 baud software UART on a 64Mhz 18F25K22 (picaxe 28X2) using the standard picaxe download pins (RX = RA4, TX=RA5) is attached. It also works at 19200 baud on a 32Mhz part.

Code:
;------------------------------------------------------------------------------
; CommInit()
;------------------------------------------------------------------------------    
CommInit
        banksel ANSELA
        bcf     ANSELA,4
        bcf     ANSELA,5
        banksel TRISA
        bcf     TRISA,5
        bsf     TRISA,4
        bcf     LATA,5 ; SET PIN TO A "MARK"(-RS232) FOR THE STOP BIT
        return


Receive    movlw     BLDELAY
RcvIni    movwf    cnt1            ;
rpt2    movlw    DELBASE            ;
        movwf    cnt2            ;        
rpt3    clrf     cnt3        
rptc    btfsc     PORTA,4             ; SKIP ON START BIT != "SPACE" (+RS232)
        bra        readbits
notrcv    decfsz     cnt3
        bra     rptc
        decfsz     cnt2
        bra     rpt3
        decfsz     cnt1
        bra     rpt2
        ; Receive timed out if we get here
        bra        exit        
readbits
        movlw     d'08'                 ; START SERIAL INPUT SEQUENCE
        movwf     TEMP                 ; COLLECT 8 DATA BITS
        clrf     serbuf                 ; CLEAR SERIAL CHARACTER BUFFER
        rcall     HALFBAUD             ; WAIT HALF ONE BAUD TIME
        btfss     PORTA,4             ; FALL THRU IF START BIT STILL = "SPACE"
        bra     rpt2                 ; ELSE IT WAS JUST A NOISE SPIKE, LOOP
Receive1
        rcall     BAUD                 ; WAIT ONE BAUD TIME
        bcf     STATUS,0             ; CLEAR THE CARRY BIT
        rrcf     serbuf,F             ; ROTATE CRY -> MSB, ROTATE MSB RIGHT
        btfss     PORTA,4             ; IS INPUT = "SPACE" (+RS232) ?
        bsf     serbuf,7             ; ...SKIP IF YES, ELSE SET BIT TO LOGIC '1'
        decfsz     TEMP,F                 ; EIGHT COUNTS YET?
        bra     Receive1             ; ...NO, GET ANOTHER BIT
        rcall     BAUD                 ; WAIT ONE BAUD TIME
        movf     serbuf,W             ; Put the character in reg 'W'
        addwf     crc, f                ; compute crc
        return                         
;
Send ; THIS ROUTINE USES 8 DATA BITS
        banksel serbuf
        movwf     serbuf                 ; W CONTAINS CHARACTER TO XMT
        movlw     8                     ; THE CHARACTER HAS 8 BITS
        movwf     TEMP
        bsf     LATA,5                 ; SET START-BIT TO A "SPACE"
        rcall     BAUD                 ; WAIT ONE BAUD TIME
Send1
        rrcf     serbuf,F             ; ROTATE THE FIRST BIT INTO CARRY
        btfss     STATUS,0             ; TEST THE CARRY BIT
        bsf     LATA,5                 ; IF BIT IS 0 SET OUTPUT PIN TO A "1" (SPACE)
        btfsc     STATUS,0             ; TEST THE CARRY BIT AGAIN
        bcf     LATA,5                 ; IF BIT IS 1 SET OUTPUT PIN TO A "0" (MARK)
        rcall     BAUD                 ; WAIT ONE BAUD TIME
        decfsz     TEMP,F                 ; IF COUNT IS ZERO THEN XMIT A STOP BIT
        bra     Send1                 ; ...ELSE XMIT NEXT BIT
        rrcf     serbuf,F             ; ROTATE CARRY, GET THE MSB BACK INTO BIT 7
        bcf     LATA,5                 ; SET PIN TO A "MARK"(-RS232) FOR THE STOP BIT
        rcall     BAUD                 ; WAIT ONE BAUD TIME
        rcall     BAUD                 ; WAIT ONE BAUD TIME
        return
;
BAUD                                ;wait loops tuned for 64Mhz 38400 baud use only
        rcall HALFBAUD
        rcall HALFBAUD
        return
;
HALFBAUD
        movlw     0x2
        banksel Delay2
        movwf     Delay2,1
Delay
        banksel Delay1
        decfsz     Delay1,1             ;Decrement Delay1 by 1, skip next instruction if Delay1 is 0
        goto     Delay
        movlw     0x17
        nop                         ;Tune the delay
        nop
        banksel Delay1
        movwf     Delay1,1
        banksel Delay2
        decfsz     Delay2,1
        goto     Delay
        return

CommExit
        return
In addition the variable definitions block need to be amended as follows:
Code:
            #define BUFFERSIZE (ROWSIZEB + 1 ) ;row + checksum
            cblock 0x0
                buffer         :     BUFFERSIZE
                crc            :     1    ;receive checksum
                dcnt        :     1    ;datacount
                dcnt2        :     1    ;datacount
                cnt1        :     1    ;receive timeout timer
                cnt2        :     1    ;receive timeout timer
                cnt3        :     1    ;receive timeout timer
                cntHello    :     1    ;
                rowcnt        :     1    ;row iterator
                rowcnt2        :     1    ;
                cmd            :     1    ;command
                doerase        :     1    ;do erase before next write
                ttblptru    :     1
                ttblptrh    :     1
                ttblptrl    :     1                
                Delay1      :   1                
                Delay2      :   1                
                serbuf      :   1
                TEMP        :   1
            endc

BLPLP and BLSIZEP need to be set to 9 in settings.inc and as per Mikael's note this need to be mirrored in the DS30 GUI and/or command line interface

Best regards

Peter


RE: Software UART version running on 18F25K22 - Mikael Gustavsson - 2011-06-10

Great! Thanks for sharing your code.


RE: Software UART version running on 18F25K22 [solved] - bogdanaioane - 2017-01-29

Hi Peter,
I am very new to all this and am trying to get into programming.
a few months ago i went to this market for second hand electronix and found a few tubes of new PIC18F14K22. since then i started playing arround with them so i had to buy a pickit3 and some other bits and bobs.
then recently i discovered picaxe and i think it's great for beginners like me. and when i saw that the picaxe20x2 chip is actually a 18F14K22 i went crazy happy as i thought "hey i have a bunch of these... so.. great" ofcourse i didnt realize that they are not just plain 18f14k22 chips but rather they have a bootloader installed that make them work with picaxe. 
So off to the internet i went in search for a way to install this bootloader myself.
not much luck... until i found your post about this subject and the spark of hope reignited.

can i please ask you, if at all possible, to help me with the code you wrote for the picaxe20x2 bootloader?
not sure if i can be of any help to you in return but maybe i can send you some PIC's in return? (as i said i have a few)

thanks


RE: Software UART version running on 18F25K22 [solved] - Mikael Gustavsson - 2017-01-29

Start a new thread.