I'm migrating from the ds30Loader and moving from 16F1783 to 16F1786. I'm using a manual reset (for now) and a FT232RL USB/serial converter. I have not been able to get the pic to respond to the 0xC1. I'm blinking an LED while waiting in the serial receive. The dc30Loader works in this configuration for the 16F1783 so I think the hardware is okay. Also, I expanded the bootloader size 10 words to fit my extra code. Does anyone see what I need to change / add to get the serial connection going?
Thanks,
radixDEC;changetheselinesaccordinglytoyourapplication#include"p16f1786.inc"IdTypePIC=0x2A;Pleaserefertothetablebelow,mustexistsin"piccodes.ini"#define max_flash 0x2000 ; in WORDS, not bytes!!! (= 'max flash memory' from "piccodes.ini" divided by 2), Please refer to the table belowxtalEQU16000000;youmayalsowanttochange:_HS_OSC_XT_OSCbaudEQU19200;standardTinyBldbaudrates:115200or19200;#defineCHANGE_TX;TXBitChangefromdefault,Pleaserefertothetable;#defineCHANGE_RX;RXBitChangefromdefault,Pleaserefertothetable;Theabove7linescanbechangedandbuidabootloaderforthedesiredfrequency(andPICtype);+---------+--------+------------+-------------+-------------+-----------+-----------+--------+-----------+------+;|IdTypePIC|Device|Erase_Page|TXbit:RXbit|TXSEL|RXSEL|EEPROM|max_flash|PDIP|;||||default(Pin)/changed(Pin)||||||;+---------+--------+------------+-------------+-------------+-----------+-----------+--------+-----------+------+;|0x26|16F1782|32words|C6(17)/B6(27)|C7(18)/B7(28)|APFCON,2|APFCON,1|256|0x0800|28|;|0x28|16F1783|32words|C6(17)/B6(27)|C7(18)/B7(28)|APFCON,2|APFCON,1|256|0x1000|28|;|0x28|16F1784|32words|C6(25)/B6(39)|C7(26)/B7(40)|APFCON1,2|APFCON1,1|256|0x1000|40|;|0x2A|16F1786|32words|C6(17)/B6(27)|C7(18)/B7(28)|APFCON1,2|APFCON1,1|256|0x2000|28|;|0x2A|16F1787|32words|C6(25)/B6(39)|C7(26)/B7(40)|APFCON1,2|APFCON1,1|256|0x2000|40|;|0x2C|16F1788|32words|C6(17)/B6(27)|C7(18)/B7(28)|APFCON1,2|APFCON1,1|256|0x4000|28|;|0x2C|16F1789|32words|C6(25)/B6(39)|C7(26)/B7(40)|APFCON1,2|APFCON1,1|256|0x4000|40|;+---------+--------+------------+-------------+-------------+-----------+-----------+--------+-----------+------+;********************************************************************;TinyBootloader16F17xxseriesSize=100words;claudiu.chiculita@ugal.ro;http://www.etc.ugal.ro/cchiculita/software/picbootloader.htm;;(2014.02.07Revision6);;ThisprogramisonlyavailableinTinyPICBootloader+.;;TinyPICBootloader+;https://sourceforge.net/projects/tinypicbootload/;;********************************************************************#include"../spbrgselect.inc"#define first_address max_flash-110 ; 100 word in size__CONFIG_CONFIG1,_FOSC_INTOSC&_BOREN_OFF&_WDTE_OFF&_CP_OFF&_PWRTE_ON&_CPD_OFF&_MCLRE_OFF__CONFIG_CONFIG2,_LVP_OFF&_STVREN_OFF&_BORV_LO&_PLLEN_ONerrorlevel1,-305;suppresswarningmsgthattakesfasdefaultcblock0x20buffer:80endccblock0x78crccontoricnt1cnt2cnt3flagendc;0000000000000000000000000RESET00000000000000000000000000org0x0000;pageselIntrareBootloader;gotoIntrareBootloaderDW0x339F;bra$-0x60;viewwithTabSize=4;&&&&&&&&&&&&&&&&&&&&&&&START&&&&&&&&&&&&&&&&&;----------------------Bootloader----------------------;;PC_flash:C1hAddrHAddrLnr...(DataLoDataHi)...crc;PC_EEPROM:C1hEEADRHEEADRL2EEDATLEEDATH(=0)crc;PIC_response:idKKorgfirst_address;nop;nop;nop;noporgfirst_address+4IntrareBootloader:;initintclock&serialportmovlp(max_flash>>8)-1;thisisthepageselectmovlwPIR1;FSR1=PIR1movwfFSR1LbankselOSCCON;movlb0x01;BANK1;thisnextlineiswrong!;bsfOSCCON,6;internalclock16MHz;shouldbe0b01111000movlw0x78;0b'01111000'movwfOSCCON;setupi/obankselTRISCbsfTRISC,7;1=input,setasinputforserialbcfTRISC,0;0=output,makesurewecandriveanledonRC0movlb0x02;BANK2bsfLATC,0#ifdef CHANGE_TXbsfFVRCON+6,TXSEL;APFCON.or.APFCON1#elsebcfFVRCON+6,TXSEL#endif#ifdef CHANGE_RXbsfFVRCON+6,RXSEL;APFCON.or.APFCON1#elsebcfFVRCON+6,RXSEL#endifmovlb0x03;BANK3clrfANSELA;turnoffanalogclrfANSELB;debugledonLATC0bankselLATCbsfLATC,0;baudbankselSPBRGmovlwspbrg_valuemovwfSPBRG;transmitmovlwb'00100100';BRGH=1,TXEN=1movwfTXSTA;receivemovlwb'10010000'movwfRCSTA;allsetupandreadytogo;waitforcomputercallReceivesublw0xC1;ExpectC1skpzbraway_to_exitmovlwIdTypePIC;PICtypemovwfTXREG;SendLIdSoftVer;firmwareverxMainLoop:movlw'B'mainl:movwfTXREGclrfcrccallReceive;HmovwfEEADRHmovwfflagcallReceive;LmovwfEEADRcallFSReceive;countmovwfcontormovwfi;movlwbuffer;movwfFSR0Lrcvoct:callReceive;datamovwiINDF0++decfszi,fbrarcvoctcallFSReceive;crcziieroare:movlw'N'skpzbramainl;write;movlwbuffer;movwfFSR0Lwriteloop:;write2bytes=1instructionmoviwINDF0++movwfEEDATLmoviwINDF0++movwfEEDATHbtfsccontor,6;ifwritingtoEEPROM,skiperaseoperation.callwr_e;eraseoperationcallwr_w;writeoperationincfEEADRL,f;doesnotcrosszonesdecfcontor,fdecfszcontor,fbrawriteloopbraMainLoopFSReceivemovlwbuffermovwfFSR0LReceivemovlwxtal/2000000+1;for20MHz=>11=>1secondmovwfcnt1rpt2clrfcnt2;debugledbankselLATCmovlw0x01;setupxorfortogglingRC0xorwfLATC,f;toggleRC0-XORWwiththePORTCregisterandstoreinPORTCbankselRCREGrpt3clrfcnt3rptc;btfssINDF1,RCIF;testRXbtfssPIR1,RCIF;testRXbra$+4;notrecivemovfRCREG,w;returninwaddwfcrc,f;computechecksumreturndecfszcnt3,fbrarptcdecfszcnt2,fbrarpt3decfszcnt1,fbrarpt2;timeout:way_to_exit;exitinallothercases;mustbeBANK3bcfRCSTA,SPEN;deactivateUARTmovlb0x00;BANK0clrfPCLATHbrafirst_address;PCLATH=0,PleasedonotchangetheGOTOinstruction.wr_ebsfEECON1,FREEwr_w;bcfEECON1,CFGS;DeselectConfigspace;bcfEECON1,EEPGDbtfssflag,6;iseeprom(orflash)bsfEECON1,EEPGDbsfEECON1,WRENmovlw0x55movwfEECON2movlw0xaamovwfEECON2bsfEECON1,WRnopnopclrfEECON1return;*************************************************************;Afterreset;Donotexpectthememorytobezero,;Donotexpectregisterstobeinitialisedlikeincatalog.end
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank you Dan. I will make that change tonight. I have enough flash to hold my program and a larger bootloader. More questions though ... of course...
The calculations for the PIC18F26K22 are
(32x2)x3+4x2=200 (bytes)
(32x2)x4+4x2=264 (bytes)
What are the correct calculations for the 16F178x series? (32)x3+4=100, or (32)x4+4=132, or (32)x5+4=164?
Also, would using the wrong first_address affect the initial serial communications?
Thanks.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Just to follow up for anyone who reads this thread.
The problem with the serial connection was in code I changed (of course). Dan uses the FSR register to get to the PIR register in the serial read. I tried to directly address the PIR1 register without first setting the bank. The fix is to leave Dan's code alone. And now I know how to use the FSR registers.
The bootloader connects and loads a hex file, but there are still a few issues in that my user code (written in C) won't run and the bootloader runs very slow after a bootload. I'll keep working and will eventually figure it out. I only have about an hour/day to work on this so it will be slow progress.
Dan, thank you for publishing your bootloader. It is extremely helpful.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Dan, another question on the size calculation...
the PIC16 formula is nP+4 words.
The math for three pages is 32×3+4=100 (words) or (32x2)x3+(4x2)=200 (bytes)
the code for the default size loader first address is
max_flash - 100 (this is words, yes?)
so to increase the bootloader size by one page I need to use
(32x2)x4+(4x2) = 264 (bytes) and the calculation in the code should be
max_flash - 132 (words). Yes?
Thanks.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I answered my own questions...
the size in the .asm file is in words (132 words)
the size in the .ini file is in bytes (264 bytes)
It's all good now.
The only change I had to make from the baseline was setting OSCCON. Setting only bit6 does not generate 16MHz. Need to set bits <6:3> to get 16MHz. And I turned PLL OFF.
Thank you again Dan.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm migrating from the ds30Loader and moving from 16F1783 to 16F1786. I'm using a manual reset (for now) and a FT232RL USB/serial converter. I have not been able to get the pic to respond to the 0xC1. I'm blinking an LED while waiting in the serial receive. The dc30Loader works in this configuration for the 16F1783 so I think the hardware is okay. Also, I expanded the bootloader size 10 words to fit my extra code. Does anyone see what I need to change / add to get the serial connection going?
Thanks,
Hi,Doug C
define first_address max_flash-110 ; 100 word in size
16F1786's "Erase Page" is "32Words" So 110 is not allowed.
reference
PIC18F26k22 hex file not sent
https://sourceforge.net/p/tinypicbootload/discussion/help/thread/9b344cbe/#d7f6
Best regards,
Dan
Thank you Dan. I will make that change tonight. I have enough flash to hold my program and a larger bootloader. More questions though ... of course...
The calculations for the PIC18F26K22 are
(32x2)x3+4x2=200 (bytes)
(32x2)x4+4x2=264 (bytes)
What are the correct calculations for the 16F178x series? (32)x3+4=100, or (32)x4+4=132, or (32)x5+4=164?
Also, would using the wrong first_address affect the initial serial communications?
Thanks.
Hi,Doug C
(32x2)×3+4×2=200 (bytes)
The configuration of the firmware is a combination of "the not write-protected area" and "the write-protected area".
4 words of the beginning of the firmware will be rewritten when writing the user program.
Since the second half of the 96 words is the body of the boot loader, rewrite the boot loader is broken.
reference
http://tinypicbootload.sourceforge.net/pic16_firmwares.html
Correct formula for PIC16F is shown by the following formula when the size of the erase page P.
nP+4 (words)
PIC16 will PIC18F equivalent and regarded as a 14-bit = 2 bytes because it is 14-bit.
Best regards,
Dan
Last edit: Dan 2016-03-15
Just to follow up for anyone who reads this thread.
The problem with the serial connection was in code I changed (of course). Dan uses the FSR register to get to the PIR register in the serial read. I tried to directly address the PIR1 register without first setting the bank. The fix is to leave Dan's code alone. And now I know how to use the FSR registers.
The bootloader connects and loads a hex file, but there are still a few issues in that my user code (written in C) won't run and the bootloader runs very slow after a bootload. I'll keep working and will eventually figure it out. I only have about an hour/day to work on this so it will be slow progress.
Dan, thank you for publishing your bootloader. It is extremely helpful.
Dan, another question on the size calculation...
the PIC16 formula is nP+4 words.
The math for three pages is 32×3+4=100 (words) or (32x2)x3+(4x2)=200 (bytes)
the code for the default size loader first address is
max_flash - 100 (this is words, yes?)
so to increase the bootloader size by one page I need to use
(32x2)x4+(4x2) = 264 (bytes) and the calculation in the code should be
max_flash - 132 (words). Yes?
Thanks.
I answered my own questions...
the size in the .asm file is in words (132 words)
the size in the .ini file is in bytes (264 bytes)
It's all good now.
The only change I had to make from the baseline was setting OSCCON. Setting only bit6 does not generate 16MHz. Need to set bits <6:3> to get 16MHz. And I turned PLL OFF.
Thank you again Dan.