Professional Documents
Culture Documents
Firmware manual
March 2012
ds30 Loader
Firmware manual
1 / 20
ds30 Loader
Firmware manual
March 2012
Table of contents
Tableofcontents........................................................................................................................2
Introduction................................................................................................................................4
ds30Loader............................................................................................................................4
PrerequisitesandRequirements............................................................................................4
Toolsuiterequirement.......................................................................................................4
Trademarks.............................................................................................................................4
Supportedcommunication.........................................................................................................5
UART.......................................................................................................................................5
SoftwareUART.......................................................................................................................5
CAN.........................................................................................................................................5
I2C..........................................................................................................................................5
SD............................................................................................................................................5
Thebasics...................................................................................................................................6
Assemblerversion..................................................................................................................6
TheMPLABIDEproject......................................................................................................6
Bootloaderplacement...........................................................................................................6
Cversion.................................................................................................................................7
TheMPLABIDEproject......................................................................................................7
Usage..........................................................................................................................................9
0.Erratas...............................................................................................................................9
1.Selectdevice.......................................................................................................................9
2.Configurebootloadersettings...........................................................................................9
3.Configurationbits.............................................................................................................12
3.1Code,asmversion......................................................................................................13
3.1Code,Cversion...........................................................................................................13
3.2MPLABIDE..................................................................................................................13
4.Addowninitializationcode..............................................................................................13
4.1Analogpins.................................................................................................................14
4.2PPS..............................................................................................................................14
4.3Oscillator....................................................................................................................14
5.Linkerscript......................................................................................................................14
5.1PIC32...........................................................................................................................14
6.Build..................................................................................................................................14
7.Erasedevice......................................................................................................................16
7.1ProgrammersupportedbyMPLABIDE......................................................................16
7.2ProgrammernotsupportedbyMPLABIDE................................................................16
8.WritebootloadertoPIC..................................................................................................16
8.1ProgrammersupportedbyMPLABIDE......................................................................16
8.2ProgrammernotsupportedbyMPLABIDE................................................................16
9.Adapttheuserapplication...........................................................................................16
9.1PIC12andPIC16.........................................................................................................16
9.2PIC18...........................................................................................................................16
2 / 20
ds30 Loader
Firmware manual
March 2012
9.3PIC24FanddsPIC........................................................................................................16
9.4PIC32...........................................................................................................................17
Considerations..........................................................................................................................18
Codeprotection....................................................................................................................18
Datastoredinflashmemory................................................................................................18
Linkerscript..........................................................................................................................18
Oscillator..............................................................................................................................18
Usingdifferentoscillatorsettingsforbootloaderandapplication.................................18
Unplanneddownloadofdifferentoscillatorsetup..........................................................18
Interrupts..............................................................................................................................19
PIC18extendedinstructionset............................................................................................19
PPS........................................................................................................................................19
Registerdefaultvalues.........................................................................................................19
Userapplication...................................................................................................................19
Watchdog.............................................................................................................................19
AppendixALinks...................................................................................................................20
3 / 20
ds30 Loader
Firmware manual
March 2012
Introduction
ds30 Loader
ds30LoaderisabootloadersupportingPIC12,PIC16,PIC18,PIC24,dsPIC,andPIC32families
ofMCUsfromMicrochip.Itsupportsalldevicesineachfamilyoutofthebox(thosein
production).Thefirmwareiswritteninassembler.ThePCclientsrunonWindows,Linux,
andMacOSX.
PIC12
PIC16
PIC18
PIC24FK/FJ/H
dsPIC30F,dsPIC33F
PIC24E,dsPIC33E
PIC32
Assembler
MPASM
MPASM
MPASM
MPLABASM30
MPLABASM30
n/a
n/a
C
n/a
MPLABXC8
MPLABXC8
MPLABC30
MPLABC30
MPLABC30
MPLABC32
Trademarks
Allrightstocopyrights,registeredtrademarks,andtrademarksresidewiththeirrespective
owners.
4 / 20
ds30 Loader
Firmware manual
March 2012
Supported communication
ds30Loadersupportsseveraldifferentwaysofcommunication:
UART
TheUARTbootloaderhasthefollowingfeatures:
Selectablebaudrate
Supportsalternatei/o(PIC24FanddsPIC30F)
Autobaudratedetection
TxenablepinforRS485operation
AvailableforPIC12,PIC16,PIC18,PIC24,dsPIC,andPIC32
WritteninassemblerorC
Software UART
ThesoftwareUARTbootloaderhasthefollowingfeatures:
Selectablebaudrate
AvailableforPIC12,PIC16,PIC18,PIC24,anddsPIC
Writteninassembler
Notavailableinthefreeedition
CAN
TheCANbootloaderhasthefollowingfeatures:
Easytoconfigurebitrate
Selectableid
Selectablemask
Standard/extendedframes
AvailableforPIC18,PIC24H/E,dsPIC30F/33F,andPIC32
WritteninassemblerorC
Notavailableinthefreeedition
I 2C
Seeds30HEXLoader.
SD
Seeds30SDCardLoader.
5 / 20
ds30 Loader
Firmware manual
March 2012
The basics
Assembler version
The MPLAB IDE project
ThefirmwareMPLABIDEprojectconsistsofseveralfiles:
ds30Loader.asm/ds30Loader.s
Thisisthemainfilethatcontainsallfirmwarecode(assemblerinstructions).Normallyno
changesneedtobedoneinthisfile.
can.inc
ThisfilecontainsCANfunctionality.Thisfileisonlyavailableinthecommercialversion.
devices.inc
Thisfilecontainsdevicespecificconstantssuchassizeoftheeeprommemoryandthe
numberofUARTsavailable.
i2c.inc
ThisfilecontainsI2Cfunctionality.Thisfileisonlyavailableinthecommercialversion.
settings.inc
Thisfilecontainsallcommonusercustomizationssuchascommunicationmodule
assignment,baudrate,deviceandmore.Thisfileneedstobemodifiedinordertomakethe
bootloaderworkforeachdifferenthardwaresetup.
uart.inc
ThisfilecontainsUARTfunctionality.
uart_soft.inc
ThisfilecontainssoftwareUARTfunctionality.Thisfileisonlyavailableinthecommercial
version.
user_code.inc
Thisfileholdsusercodethatshouldexecutebeforeandafterbootloaderoperation.
xxx.lkr/xxx.gld
Thisisthedevicespecificlinkerscriptneedbythelinker.Thisdoesnotcomewiththeds30
Loader;itcomeswiththeMicrochiplanguagetoolsuite.
PIC12F
PIC16F
PIC18F
PIC18FJ
PIC24F
Size
256 words*
256 words*
7 pages*
1 page
4 rows*
Placement
end of memory
end of memory
end of memory
2nd last page
end of memory
6 / 20
ds30 Loader
Firmware manual
March 2012
nd
1 page
2 last page
PIC24FJ
1 page
end of memory
PIC24H
1 page
end of memory
PIC24E
end of memory
dsPIC30F 8 rows*
end of memory
dsPIC33FJ 1 page
end of memory
dsPIC33E 1 page
1 page
end of memory
PIC32
*Maydifferfordifferentfirmwareversions
C version
TheCversionisnotavailableinthefreeedition.
Theds30_activity()functioniscalledfromthereceiveloop.Theusermayplacecodehere
suchaskickofthewatchdog.Forheaviertasksitisadvisedtouseatimersothattheheavy
codeisnotexecutedforeachcall.
Theds30_exit()functioniscalledjustbeforetheuserapplicationloaded.Theusermayplace
cleanupcodehere.
uart_xxx.c
ThisfilecontainsUARTfunctionality.Itshouldusuallynotbemodified.
board.h
Thisfileisincludedbyvarioussourcefiles.Itinturnsincludestheboardspecificfile.Thisfile
mayneedtobemodified.
board_xxx.h
Thisfilecontainsallcommonusersettingssuchascommunicationmoduleassignment,baud
rate,andtiming.Thisfileneedstobemodifiedinordertomakethebootloaderworkfor
eachdifferenthardwaresetup.
comm.h
Thisfileisincludedbyvarioussourcefiles.Itshouldusuallynotbemodified.
ds30loader.h
Thisfilecontainstheds30_mainfunctionprototypes.Itshouldusuallynotbemodified.
ds30_Loader_xxx.a
Thisistheds30Loaderenginelibraryfile.
7 / 20
ds30 Loader
Firmware manual
March 2012
xxx.gld
Thisisthedevicespecificlinkerscript,ithasbeenmodifiedtogivethebootloaderaspecific
placementintheflash.
8 / 20
ds30 Loader
Firmware manual
March 2012
Usage
StartbyopeningthefirmwareMPLABIDEprojectlocatedinthefirmwarexxxdirectory.
0. Erratas
Nodevicespecificerrataworkaroundsareimplemented.Theusermustreadthedevice
erratasheetcarefullytomakesuretherearenoproblemsthatcouldinterferewithboot
loaderoperation.
1. Select device
SelectcorrectdeviceonthemenuConfigure>SelectDevice
DEV_MODE
Usedduringdevelopment,deleteorcommentthisline.
.equ
__30F4011, 1
Settoyourdevicename.ThissettingisonlyvalidforthePIC24anddsPICfirmware.
LIST
P=18F2550
Settoyourdevicename.ThissettingisonlyvalidforthePIC12,PIC16,andPIC18firmwares.
FCY
Settoinstructioncycleclockspeed(nrofinstructionspersecond).Thisisonlyaconstantit
doesnotsetupanyoscillatorsettingssuchhasPLL,whichhastobedonemanually.This
settingisonlyvalidforthePIC24anddsPICfirmware.
OSCF/FOSC
Settooscillatorfrequency.Thisisonlyaconstantitdoesnotsetupanyoscillatorsettings
suchhasPLL,whichhastobedonemanually.ThissettingisonlyvalidforthePIC12,PIC16,
andPIC18firmwares.
BLINIT/HELLOTIMEOUT
ThisisthereceivetimeoutinmillisecondsforthefirsthellocommandsentfromthePC
client.Thiscouldbesetlowertodecreasestartuptime.Thereisanupperlimitwhich
dependsontheoscillatorfrequency.
HELLOTRIES
Thisishowmanynonhellocommandsthatarediscardedonstartupbeforethebootloader
isabortedandtheuserapplicationisloaded.
9 / 20
ds30 Loader
Firmware manual
March 2012
BLTIME/TIMEOUT
Thisisthecommunicationreceivetimeoutinmilliseconds.
USE_UARTx
Uncommentthelinematchingtheuartyouareusing.
USE_ALTIO
UncommenttousealternativeI/OforUART1.ThissettingisonlyvalidfordsPIC30Fdevices.
MoreinformationabouttheUSE_ALTIOsettingisavailableinthedevicedatasheet.
BAUDRATE
SettothedesiredUARTbaudrate,thebrgvalueisautomaticallycalculated.Iftheerrorof
thechosenbaudrateexceeds2.5%anerrormessagewillbedisplayedwhenassembling.
USE_ABAUD
Uncommenttouseautobaudratedetection.Pleasereaderratafirsttomakesurethereare
noproblemswhenusingautobaudratedetection.
USE_BRG16
Uncommenttouse16bitbaudrateregister.Pleasereaderratafirsttomakesurethereare
noproblemswhenusingBRG16=1.MoreinformationabouttheBRG16settingsisavailable
inthedevicedatasheet.
USE_BRGH
Uncommenttousehighbaudrates.Pleasereaderratafirsttomakesurethereisno
problemswhenusingBRGH=1.MoreinformationabouttheBRGHsettingsisavailableinthe
devicedatasheet.
USE_TXENABLE
UncommenttouseatransmitenablepinallowingRS485communication.
TXE_DELAY
Timeinstowaitbeforetransmittingafterpullingthetxenablepinhigh.
TRISR_TXE
Settotrisregisteroftransmitenablepin.
LATR_TXE
Settolatregisteroftransmitenablepin.
TRISB_TXE
Settobitintrisregisteroftransmitenablepin.
LATB_TXE
Settobitinlatregisteroftransmitenablepin.
10 / 20
ds30 Loader
Firmware manual
March 2012
USE_SWUART
Uncommenttousethesoftwareuart.Thisoptionisonlyavailableinthecommercialversion.
BITWAITCNT
Thisconstantgivesthebaudrate.Calculateitaccordingtotheformulaavailableinthefile
settings.inc.
TRISR_TX,TRISB_TX,LATR_TX,LATB_TX
Configurationregistersforthetransmitpin.
TRISR_RX,TRISB_RX,PORTR_RX,PORTB_RX
Configurationregistersforthereceivepin.
USE_CANx
UncommenttoselectCANcontroller.Thisoptionisonlyavailableinthecommercialversion.
ID_PIC
CANid/nodenumberforthisunit.
ID_GUI
CANid/nodenumberoftheds30Loaderhostapplication.
ID_MASK
Thissettingisusedtomaskbitsintheidofreceivedframes.Readmoreaboutmaskingin
theCANsectionofthedevicedatasheet.
CAN_EXT
Uncommenttosendandreceiveextendeddataframes.Readmoreaboutextendedframes
intheCANsectionofthedevicedatasheet.
CAN_BRP,CAN_PROP,CAN_SEG1,CAN_SEG2,CAN_SJW,CAN_CKS
CANtimingsettings.Theseneedtobemanuallycalculated.TheCANtimingcalculator.xls
spreadsheetmaybeofhelp.Detailedinformationisfoundinthedevicedatasheet.
TRISR_CRX
OnPIC18theCANreceivepinstoexplicitlybesettoinput.SettotrisregisterofCANreceive
pin.
Example:TRISE
TRISB_CRX
SettobitintrisregisterofCANreceivepin.
Example:TRISE4
USE_I2Cx
11 / 20
ds30 Loader
Firmware manual
March 2012
UncommenttoselectI2Cbuscontroller
ADDR_PIC
The7bitslavedeviceidforthisunitontheI2Cbus.
ADDR_MASK
The7bitidmask.Bit=1=>ignore.Usuallysetto0x00.NotavailablefordsPIC30F.
KICK_WD
Ifthewatchdogisenablea.Uncommentthislinetoenablekickofthewatchdoginthe
receiveloop.Ifthewatchdogisnotenabledthislinemustbedisabled.
USE_READ
Uncommenttoenablereadofflashandeepromcontents.Thisoptionisonlyavailableinthe
commercialversion.
PROT_GOTO
Commenttodisableprotectionofthegotoat0x00.Itisrecommendedtonotdisablegoto
protection.Ifthegotogetscorruptedthebootloaderwillnotbecalledonstartup.
PROT_BL
Commenttodisablebootloaderprotection.Itisnotrecommendedtodisablebootloader
protection.
BLPL
PlacementofthebootloaderinthePICflashmemory,pages/rowsfromtheend.Whenthis
ischangedbytheuserthecustombootloaderoptionds30LoaderGUImustbeenabledand
thenewvaluesenteredinthetextboxes.
BLSIZE
Thesizeofthebootloader,itisusedbybootloaderprotection.Whenthisischangedbythe
userthecustombootloaderoptionds30LoaderGUImustbeenabledandthenewvalues
enteredinthetextboxes.
configxxx
Seethenextsection.
3. Configuration bits
Settingtheconfigurationbitsisarequiredandvitalsteptomakethebootloaderwork.Also
seetheoscillatorconsiderationschapterlaterinthismanual.Informationaboutthe
configurationbitsisfoundinthedevicedatasheet.Theconfigurationbitscanbesetineither
MPLABIDEorinthecode.
12 / 20
ds30 Loader
Firmware manual
March 2012
OnPIC12andPIC16devices,donotforgettothecorrectbankforeachregisteraccess.Use
theBANKSELmacro.
Ifmorespaceisneedthebootloadersizeandplacementneedstobechangedin
settings.inc.IntheGUIyouneedtocheckcustombootloaderundertheadvancedtaband
enterthedetailsofthenewbootloaderproperties.
Words free to use for user code
(varies for different fw versions)
~15
PIC16F
~30
PIC18F
>100
PIC18FJ
~10
PIC24F
>100
PIC24FJ
>100
PIC24H
~10
dsPIC30F
>100
dsPIC33FJ
Herearethemostcommonthingsthatmayneedinitializationthatisnotcovered
automaticallybyds30Loader:
13 / 20
ds30 Loader
Firmware manual
March 2012
4.2 PPS
OnPICs/dsPICswiththeperipheralpinselectfeatureitmustbeconfiguredmanually.There
isatemplateavailableinuser_code.s.MoreinformationaboutPPSisfoundintheI/OPorts
sectionofthedevicedatasheet.
4.3 Oscillator
Iftheinternaloscillatoristobeuseditmayneedtobeconfigureditforahigherfrequency.
Itisoftennotsetfortomaximumfrequencyonstartup.
5. Linker script
5.1 PIC32
ThePIC32bootloaderfirmwareisshippedwithacustomlinkerscriptwhichisplacedinthe
samedirectoryastheMPLABIDEprojectfile(.mcp).TheMPLABprojecthasthebuild
directorypolicysettotheprojectdirectory.Ifitischangedtotheoutputdirectory;thelinker
scriptmustbemovedthere.Thebuilddirectorypolicyisfoundintheprojectbuildoptions
dialogwhichisopenedfromtheProject\Buildoptions\ProjectmenuinMPLABIDE.
6. Build
Select"Release"inmenu"Project>BuildConfiguration"
Startbuildbyclickingmenu"Project>BuildAll"
Noticeanywarnings.
Fixerrors.ds30Loaderitselfmaygenerateerrors,seethetablebelow.Forothererrors,
consulttheMicrochiptoolsuitedocumentation.
Error
Description
Solution
Unknowndevicespecified
Theselecteddevicemay Contacttheauthortoget
benotsupported
devicesupport.
Doyouneedtoconfigure
See4.1
ConfigureA/Difneededand
communicationpinstobe
thenremovethelinethat
digital?Ifnot,removethisline
generatestheerror.
YouneedtoconfigurePPS
See4.2
ConfigurePPSthenremovethe
linethatgeneratestheerror.
BothUARTandCANisspecified ds30Loadercanonly
Selectonlyonecommunication
operatewithone
moduleinsettings.inc
communicationmodule
NeitherUARTnorCANis
Exactlyone
Selectacommunication
specified
communicationmodule moduleinsettings.inc
mustbeselectedin
settings.inc
Copyright 2009-2012 MG Digital Solutions
14 / 20
ds30 Loader
Firmware manual
March 2012
Fcyspecifiedisoutofrange
BothCANportsarespecified
ds30Loadercanonly
operatewithone
communicationmodule
CANisspecifiedforadevice
thatdon'thaveCAN
CAN2specifiedforadevice
thatonlyhasCAN1
Bothuartsarespecified
UART2specifiedforadevice
thatonlyhasuart1
Baudrateerrorismorethan
2.5%.Removethischeckortry
anotherbaudrateand/orclock
speed.
overflowindelaycalculation
Oscillatorfrequencyand
timingsmaybe
incompatible
BLSTART_isoutofrange
Oscillatorfrequencyand
timingsmaybe
incompatible
BLSTART_mightbeoutof
Oscillatorfrequencyand
range
timingsmaybe
incompatible
BLDELAY_isoutofrange
Oscillatorfrequencyand
timingsmaybe
incompatible
BLDELAY_mightbeoutof
Oscillatorfrequencyand
range
timingsmaybe
incompatible
YouneedtoconfigurePPS
See4.2
Nocommunicationisspecified
CanBusspecifiedforadevice
thatonlyhasuart
UART1andCanbusspecified
ChangeFcytobewithinthe
devicesmaximum.
Selectonlyonecommunication
moduleinsettings.inc
Selectacommunication
modulethatisavailableforthe
selecteddevice
Selectacommunication
modulethatisavailableforthe
selecteddevice
Selectonlyonecommunication
moduleinsettings.inc
Selectacommunication
modulethatisavailableforthe
selecteddevice
Tryadifferentbaudrateor
oscillatorfrequency.
ConfigurePPSthenremovethe
linethatgeneratestheerror.
Selectexactlyone
communicationmodulein
settings.inc
Selectacommunication
modulethatisavailableforthe
selecteddevice
Selectonlyonecommunication
moduleinsettings.inc
15 / 20
ds30 Loader
Firmware manual
March 2012
UART2andCanbusspecified
TXenableisnotavailablefor
CAN
UART2specifiedforadevice
thatonlyhasuart1
spbrg_value_isoutofrange
spbrg_value_mightbeoutof
range
Selectonlyonecommunication
moduleinsettings.inc
Disabletxenable
Selectacommunication
modulethatisavailableforthe
selecteddevice
Oscillatorfrequencyand Tryadifferentbaudrateor
baudratemaybe
oscillatorfrequency
incompatible
Oscillatorfrequencyand Tryadifferentbaudrateor
baudratemaybe
oscillatorfrequency
incompatible
7. Erase device
Ifcodeprotectionisusedthedeviceshouldbeerasedcompletely.Thismaybeessentialto
correctbootloaderoperationifcodeprotectionisused.
9.2 PIC18
Theuserapplicationdoesnotneedanyadaptation.
16 / 20
ds30 Loader
Firmware manual
March 2012
9.4 PIC32
Acustomlinkerscriptmustbeused.Itisdeliveredtogetherwithfirmware.Theprocdefs.ld
linkerscriptfilemustbeplacedintheconfiguredbuilddirectory.InMPLABIDEthebuild
directoryisconfiguredfromthemenuProject>BuildOptions...>Project\Directories\Build
DirectoryPolicy.ThefilemustnotberenamedanditmustnotbeincludeintheMPLABIDE
project.Whenthecustomlinkerscriptisplacedinthebuilddirectorytheapplicationwillnot
runwithoutthebootloader.
17 / 20
ds30 Loader
Firmware manual
March 2012
Considerations
Code protection
Dependingonconfiguration,writeverificationandreadoperationmaynotfunction.Write
verificationmustbedisabledinthiscase.
Linker script
Thereisusuallynoneedtoalterthelinkerscriptfords30Loaderfirmware.Insomecases
whenusinglargedataarrays,thelinkerorassemblermayplacetheseinthesameplaceas
thebootloader.Onewaytosolvethisistoreservethebootloaderaddressesinthelinker
script.Anothersolutionistoplacethedataarrayataspecificaddressthatdoesnotinterfere
withthebootloadermemoryspace.
Oscillator
Itisstronglyrecommendedtousethesameoscillatorsetupforboththebootloaderandthe
userapplication.Ifyouhavecodetosetupyouroscillatorand/orpll,itisrecommendedto
movethatcodetothebootloader.
Thesimplestsolutionistousethecommandresetmethod.Thatway,onecanaddclock
switchingcodepriortoloadingthebootloader.Itisstillriskybecauseiftheapplicationgets
corruptedorawritefailedthebootcannotgetloadedwithcompatibleoscillator
configuration.Itcouldlooksomethinglikethisinpseudocode:
if ( ReceivedBlResetCommand )
SwitchToBootloaderOscillatorSetup()
GotoBootloader()
end if
18 / 20
ds30 Loader
Firmware manual
March 2012
Interrupts
Thebootloaderdoesnotuseinterruptbutsomeinterruptflagswillbeset.Alwaysclear
respectiveinterruptsflagpriortoenablinganinterruptinyourapplication.
PPS
ThePPSconfigurationregistersarenotlockedbyds30Loader.
User application
Ifthebootloaderisactivatedbyresettingthedevice,thereisusuallynoneedtoadaptthe
userapplication.Performingadeviceresetispreferredtousingcall,gotoorbranchbecause
thebootloadermayassumeresetvaluesofsomeregisters.
Ifthebootloaderiscalled,gotoed,orbranchedtofromtheuserapplication,interrupts
shouldbedisabledpriortocallingthebootloader.
Watchdog
AClrWdtinstructionisplacedinthereceiveloop.Dependingonconfigurationthismaynot
beenough.Inthiscasethewatchdogshouldbedisabledduringbootloaderoperation.
19 / 20
ds30 Loader
Firmware manual
March 2012
Appendix A Links
ds30Loaderwebsite
http://www.ds30loader.com
ds30Loaderfreeeditionwebsite
http://mrmackey.noip.org/elektronik/ds30loader/
20 / 20