You are on page 1of 20

ds30 Loader

Firmware manual

March 2012

ds30 Loader
Firmware manual

Copyright 2009-2012 MG Digital Solutions

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

Copyright 2009-2012 MG Digital Solutions

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

Copyright 2009-2012 MG Digital Solutions

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.

Prerequisites and Requirements


Dependingonwhichfirmwareisused,MPLABC32,MPLABASM30orMPASMassembleris
needed.Althoughnotrequired,MPLABIDEisrecommendedandisusedduring
development.

Tool suite requirement

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.

Copyright 2009-2012 MG Digital Solutions

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.

Copyright 2009-2012 MG Digital Solutions

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.

Boot loader placement


Thebootloaderisnormallyplacedattheveryendofflashmemory.Thiswaythereisusually
noneedtoreservespaceforthebootloaderinthelinkerscript.Insomedevicefamiliesthe
configurationwordsarelocatedattheendoftheflashmemory.Forthosefamiliestheboot
loaderisplacedinthesecondlastpage.

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

Copyright 2009-2012 MG Digital Solutions

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.

The MPLAB IDE project


ThefirmwareMPLABIDEprojectconsistsofseveralfiles:
board_xxx.c
Thisfilecontainstheboard_init()functionthatiscalledfrommain()onstartup.Theuseris
responsiblemodifyitwithcodetosetuptheboard.Oscillator,I/O,PPSetc.Thisfileisalso
suitableforstorageoftheconfigurationbits.
can_xxx.c
ThisfilecontainsCANfunctionality.Itshouldusuallynotbemodified.
main.c
Thisfilecontainsthemain()functionwhichistheentrypointandfromwhichtheboardand
communicationinitializationroutinesarecalled.Itmaybemodifiedbutitisusuallynot
needed.

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.

Copyright 2009-2012 MG Digital Solutions

7 / 20

ds30 Loader
Firmware manual

March 2012

xxx.gld
Thisisthedevicespecificlinkerscript,ithasbeenmodifiedtogivethebootloaderaspecific
placementintheflash.

Copyright 2009-2012 MG Digital Solutions

8 / 20

ds30 Loader
Firmware manual

March 2012

Usage
StartbyopeningthefirmwareMPLABIDEprojectlocatedinthefirmwarexxxdirectory.

0. Erratas
Nodevicespecificerrataworkaroundsareimplemented.Theusermustreadthedevice
erratasheetcarefullytomakesuretherearenoproblemsthatcouldinterferewithboot
loaderoperation.

1. Select device
SelectcorrectdeviceonthemenuConfigure>SelectDevice

2. Configure boot loader settings


Mostifnotallsettingsarelocatedinthefilesettings.inc(assemblerfirmwares)or
board_xxx.h(Cfirmwares).Alllinescommentedwithxxxneedstobeverified/changed.Not
allsettingsareavailableinanyfirmware.Herefollowsadescriptionofallavailablesettings.

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.

Copyright 2009-2012 MG Digital Solutions

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.

Copyright 2009-2012 MG Digital Solutions

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

Copyright 2009-2012 MG Digital Solutions

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.

Copyright 2009-2012 MG Digital Solutions

12 / 20

ds30 Loader
Firmware manual

March 2012

3.1 Code, asm version


Thereisatemplatetouseinthelastsectionofthefilesettings.inc.Makesuretocheckthe
checkboxlabeledConfigurationBitssetincodeonthemenuConfigure>Configuration
bits....Allavailablecanbefoundattheendofthedevicesincludefile.Defaultincludefile
locations:
PIC12,PIC16,andPIC18:c:\ProgramFiles\Microchip\MPASMSuite\
PIC24anddsPIC:c:\Programfiles\Microchip\MPLABASM30Suite\Support\family\inc
ForPIC18thereisalsodocumentationavailableinMPLABIDE.ClickmenuHelp>Topicsthen
choosePIC18ConfigSettingsandclickOK.

3.1 Code, C version


Thereisatemplateintheboard_xxx.cfile.

3.2 MPLAB IDE


TheconfigurationsarefoundonthemenuConfigure>Configurationbits....Makesureto
uncheckthecheckboxlabeledConfigurationBitssetincode.

4. Add own initialization code


Ifneeded,addinitializationand/orexitcodeinuser_code.inc/board_xxx.c.Insome
firmwares,thespaceavailableforusercodeisrestrictedtoafewinstructions.Seetable
belowfordetails.Theexactnumberdependsonfirmwareversionandwhichfeaturesare
enabled.

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:

Copyright 2009-2012 MG Digital Solutions

13 / 20

ds30 Loader
Firmware manual

March 2012

4.1 Analog pins


PinsthatcanbeusedbytheA/Daremanytimesconfiguredasanalogonstartup.Ifanyof
thosepinsthataretobeusedbythecommunicationmoduletheyneedtobeconfiguredto
bedigital.Readmoreaboutthisinthedevicedatasheet,sectionsI/OPortsandA/Dmodule.

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

Copyright 2009-2012 MG Digital Solutions

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.

7.1 Programmer supported by MPLAB IDE


OnthemenuProgrammer>EraseFlashDevice

7.2 Programmer not supported by MPLAB IDE


Consulttheprogrammermanual.

8. Write boot loader to PIC


8.1 Programmer supported by MPLAB IDE
OnthemenuProgrammer>Program
NoticethatthissteprequiresanordinaryprogrammersuchastheICD2.Thebootloader
itselfcannotbeusedtowritethebootloader.

8.2 Programmer not supported by MPLAB IDE


Consulttheprogrammermanual.

9. Adapt the user application


9.1 PIC12 and PIC16
Theuserapplicationdoesnotneedanyadaptation.

9.2 PIC18
Theuserapplicationdoesnotneedanyadaptation.

9.3 PIC24F and dsPIC


Theuserapplicationdoesnotneedanyadaptation.

Copyright 2009-2012 MG Digital Solutions

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.

Copyright 2009-2012 MG Digital Solutions

17 / 20

ds30 Loader
Firmware manual

March 2012

Considerations

Code protection
Dependingonconfiguration,writeverificationandreadoperationmaynotfunction.Write
verificationmustbedisabledinthiscase.

Data stored in flash memory


Iftheuserapplicationstoresdatainflashmemory,thisdatamustplacedinaseparate
page/rowthatdoesnotcontainanyactualcodeoritwillbeoverwrittenonthenextwrite.

Linker script
Thereisusuallynoneedtoalterthelinkerscriptfords30Loaderfirmware.Insomecases
whenusinglargedataarrays,thelinkerorassemblermayplacetheseinthesameplaceas
thebootloader.Onewaytosolvethisistoreservethebootloaderaddressesinthelinker
script.Anothersolutionistoplacethedataarrayataspecificaddressthatdoesnotinterfere
withthebootloadermemoryspace.

Oscillator
Itisstronglyrecommendedtousethesameoscillatorsetupforboththebootloaderandthe
userapplication.Ifyouhavecodetosetupyouroscillatorand/orpll,itisrecommendedto
movethatcodetothebootloader.

Using different oscillator settings for boot loader and application


Iftheuserapplicationistoberunonabatterypowereddevice,theoscillatormaybe
runningatverylowspeed.Tostillachievelowbootloaderwritetime,onemightwantto
havedifferentoscillatorsetupsforbootloaderandapplication.Thesolutionistoaddclock
switching/pllinitializationcodeinthebootloaderfirmware.

Unplanned download of different oscillator setup


Ifoneneedtodownloadadifferentoscillatorsetupandthebootloaderdoesnotalready
haveclockswitchingcode,greatcaremustbetakentomakesurethatthebootloaderwill
stillbeoperablewiththenewoscillatorsetup.Thereisonlyafewwaystodothis

Thesimplestsolutionistousethecommandresetmethod.Thatway,onecanaddclock
switchingcodepriortoloadingthebootloader.Itisstillriskybecauseiftheapplicationgets
corruptedorawritefailedthebootcannotgetloadedwithcompatibleoscillator
configuration.Itcouldlooksomethinglikethisinpseudocode:

if ( ReceivedBlResetCommand )
SwitchToBootloaderOscillatorSetup()
GotoBootloader()
end if

Copyright 2009-2012 MG Digital Solutions

18 / 20

ds30 Loader
Firmware manual

March 2012

Interrupts
Thebootloaderdoesnotuseinterruptbutsomeinterruptflagswillbeset.Alwaysclear
respectiveinterruptsflagpriortoenablinganinterruptinyourapplication.

PIC18 extended instruction set


ds30Loaderdoesnotrelyontheextendedinstructionset,howeverthebootloaderandthe
applicationshouldusethesamesettingwhencompiledtoensurecorrectoperation.
ExtendedinstructionsetisnotsupportedafterthetrialperiodoftheC18evaluationversion.

PPS
ThePPSconfigurationregistersarenotlockedbyds30Loader.

Register default values


Someregistervaluesarenotrestoredwhendownloadiscomplete.Fordetails,examinethe
code.

User application
Ifthebootloaderisactivatedbyresettingthedevice,thereisusuallynoneedtoadaptthe
userapplication.Performingadeviceresetispreferredtousingcall,gotoorbranchbecause
thebootloadermayassumeresetvaluesofsomeregisters.

Ifthebootloaderiscalled,gotoed,orbranchedtofromtheuserapplication,interrupts
shouldbedisabledpriortocallingthebootloader.

Watchdog
AClrWdtinstructionisplacedinthereceiveloop.Dependingonconfigurationthismaynot
beenough.Inthiscasethewatchdogshouldbedisabledduringbootloaderoperation.

Copyright 2009-2012 MG Digital Solutions

19 / 20

ds30 Loader
Firmware manual

March 2012

Appendix A Links
ds30Loaderwebsite
http://www.ds30loader.com

ds30Loaderfreeeditionwebsite
http://mrmackey.noip.org/elektronik/ds30loader/

Copyright 2009-2012 MG Digital Solutions

20 / 20

You might also like