100% found this document useful (1 vote)
266 views20 pages

Ds30 Loader - Firmware Manual

manual

Uploaded by

SamPolancos
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
266 views20 pages

Ds30 Loader - Firmware Manual

manual

Uploaded by

SamPolancos
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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
[Link]...............................................................................................................................9
[Link].......................................................................................................................9
[Link]...........................................................................................9
[Link].............................................................................................................12
3.1Code,asmversion......................................................................................................13
3.1Code,Cversion...........................................................................................................13
3.2MPLABIDE..................................................................................................................13
[Link]..............................................................................................13
4.1Analogpins.................................................................................................................14
4.2PPS..............................................................................................................................14
4.3Oscillator....................................................................................................................14
[Link]......................................................................................................................14
5.1PIC32...........................................................................................................................14
[Link]..................................................................................................................................14
[Link]......................................................................................................................16
7.1ProgrammersupportedbyMPLABIDE......................................................................16
7.2ProgrammernotsupportedbyMPLABIDE................................................................16
[Link]..................................................................................................16
8.1ProgrammersupportedbyMPLABIDE......................................................................16
8.2ProgrammernotsupportedbyMPLABIDE................................................................16
[Link]...........................................................................................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
[Link](thosein
production).[Link],Linux,
andMacOSX.

Prerequisites and Requirements


Dependingonwhichfirmwareisused,MPLABC32,MPLABASM30orMPASMassembleris
[Link],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:

[Link]/ds30Loader.s
Thisisthemainfilethatcontainsallfirmwarecode(assemblerinstructions).Normallyno
changesneedtobedoneinthisfile.
[Link]
[Link].
[Link]
Thisfilecontainsdevicespecificconstantssuchassizeoftheeeprommemoryandthe
numberofUARTsavailable.
[Link]
[Link].
[Link]
Thisfilecontainsallcommonusercustomizationssuchascommunicationmodule
assignment,baudrate,[Link]
bootloaderworkforeachdifferenthardwaresetup.
[Link]
ThisfilecontainsUARTfunctionality.
uart_soft.inc
[Link]
version.
user_code.inc
Thisfileholdsusercodethatshouldexecutebeforeandafterbootloaderoperation.
[Link]/[Link]
Thisisthedevicespecificlinkerscriptneedbythelinker.Thisdoesnotcomewiththeds30
Loader;itcomeswiththeMicrochiplanguagetoolsuite.

Boot loader placement


[Link]
[Link]
[Link]
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()[Link]
[Link],I/O,[Link]
suitableforstorageoftheconfigurationbits.
can_xxx.c
[Link].
main.c
Thisfilecontainsthemain()functionwhichistheentrypointandfromwhichtheboardand
[Link]
needed.

Theds30_activity()[Link]
[Link]
codeisnotexecutedforeachcall.

Theds30_exit()[Link]
cleanupcodehere.
uart_xxx.c
[Link].
board.h
[Link]
mayneedtobemodified.
board_xxx.h
Thisfilecontainsallcommonusersettingssuchascommunicationmoduleassignment,baud
rate,[Link]
eachdifferenthardwaresetup.
comm.h
[Link].
ds30loader.h
Thisfilecontainstheds30_mainfunctionprototypes.Itshouldusuallynotbemodified.
ds30_Loader_xxx.a
Thisistheds30Loaderenginelibraryfile.

Copyright 2009-2012 MG Digital Solutions

7 / 20

ds30 Loader
Firmware manual

March 2012

[Link]
Thisisthedevicespecificlinkerscript,ithasbeenmodifiedtogivethebootloaderaspecific
placementintheflash.

Copyright 2009-2012 MG Digital Solutions

8 / 20

ds30 Loader
Firmware manual

March 2012

Usage
StartbyopeningthefirmwareMPLABIDEprojectlocatedinthefirmwarexxxdirectory.

0. Erratas
[Link]
erratasheetcarefullytomakesuretherearenoproblemsthatcouldinterferewithboot
loaderoperation.

1. Select device
SelectcorrectdeviceonthemenuConfigure>SelectDevice

2. Configure boot loader settings


[Link](assemblerfirmwares)or
board_xxx.h(Cfirmwares).Alllinescommentedwithxxxneedstobeverified/[Link]
[Link].

DEV_MODE
Usedduringdevelopment,deleteorcommentthisline.

.equ
__30F4011, 1
Settoyourdevicename.ThissettingisonlyvalidforthePIC24anddsPICfirmware.

LIST
P=18F2550
Settoyourdevicename.ThissettingisonlyvalidforthePIC12,PIC16,andPIC18firmwares.

FCY
Settoinstructioncycleclockspeed(nrofinstructionspersecond).Thisisonlyaconstantit
doesnotsetupanyoscillatorsettingssuchhasPLL,[Link]
settingisonlyvalidforthePIC24anddsPICfirmware.

OSCF/FOSC
[Link]
suchhasPLL,whichhastobedonemanually.ThissettingisonlyvalidforthePIC12,PIC16,
andPIC18firmwares.

BLINIT/HELLOTIMEOUT
ThisisthereceivetimeoutinmillisecondsforthefirsthellocommandsentfromthePC
[Link]
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,[Link]
thechosenbaudrateexceeds2.5%anerrormessagewillbedisplayedwhenassembling.

USE_ABAUD
[Link]
noproblemswhenusingautobaudratedetection.

USE_BRG16
[Link]
noproblemswhenusingBRG16=1.MoreinformationabouttheBRG16settingsisavailable
inthedevicedatasheet.

USE_BRGH
[Link]
problemswhenusingBRGH=[Link]
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
[Link].

BITWAITCNT
[Link]
[Link].

TRISR_TX,TRISB_TX,LATR_TX,LATB_TX
Configurationregistersforthetransmitpin.

TRISR_RX,TRISB_RX,PORTR_RX,PORTB_RX
Configurationregistersforthereceivepin.

USE_CANx
[Link].

ID_PIC
CANid/nodenumberforthisunit.

ID_GUI
CANid/nodenumberoftheds30Loaderhostapplication.

ID_MASK
[Link]
theCANsectionofthedevicedatasheet.

CAN_EXT
[Link]
intheCANsectionofthedevicedatasheet.

CAN_BRP,CAN_PROP,CAN_SEG1,CAN_SEG2,CAN_SJW,CAN_CKS
[Link]
[Link].

TRISR_CRX
[Link]
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
[Link]=1=>ignore.Usuallysetto0x00.NotavailablefordsPIC30F.

KICK_WD
[Link]
[Link].

USE_READ
[Link]
commercialversion.

PROT_GOTO
[Link]
[Link].

PROT_BL
[Link]
protection.

BLPL
PlacementofthebootloaderinthePICflashmemory,pages/[Link]
ischangedbytheuserthecustombootloaderoptionds30LoaderGUImustbeenabledand
thenewvaluesenteredinthetextboxes.

BLSIZE
Thesizeofthebootloader,[Link]
userthecustombootloaderoptionds30LoaderGUImustbeenabledandthenewvalues
enteredinthetextboxes.

configxxx
Seethenextsection.

3. Configuration bits
[Link]
[Link]
[Link]
MPLABIDEorinthecode.

Copyright 2009-2012 MG Digital Solutions

12 / 20

ds30 Loader
Firmware manual

March 2012

3.1 Code, asm version


[Link]
checkboxlabeledConfigurationBitssetincodeonthemenuConfigure>Configuration
bits....[Link]
locations:
PIC12,PIC16,andPI[Link]\ProgramFiles\Microchip\MPASMSuite\
PIC24anddsPI[Link]\Programfiles\Microchip\MPLABASM30Suite\Support\family\inc
[Link]>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.[Link]
firmwares,[Link]
[Link]
enabled.

OnPIC12andPIC16devices,[Link]
theBANKSELmacro.

Ifmorespaceisneedthebootloadersizeandplacementneedstobechangedin
[Link]
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/[Link]
thosepinsthataretobeusedbythecommunicationmoduletheyneedtobeconfiguredto
[Link],sectionsI/OPortsandA/Dmodule.

4.2 PPS
OnPICs/[Link]
isatemplateavailableinuser_code.[Link]/OPorts
sectionofthedevicedatasheet.

4.3 Oscillator
Iftheinternaloscillatoristobeuseditmayneedtobeconfigureditforahigherfrequency.
Itisoftennotsetfortomaximumfrequencyonstartup.

5. Linker script
5.1 PIC32
ThePIC32bootloaderfirmwareisshippedwithacustomlinkerscriptwhichisplacedinthe
samedirectoryastheMPLABIDEprojectfile(.mcp).TheMPLABprojecthasthebuild
[Link];thelinker
[Link]
dialogwhichisopenedfromtheProject\Buildoptions\ProjectmenuinMPLABIDE.

6. Build
Select"Release"inmenu"Project>BuildConfiguration"
Startbuildbyclickingmenu"Project>BuildAll"
Noticeanywarnings.
Fixerrors.ds30Loaderitselfmaygenerateerrors,[Link],
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
[Link]
communicationmodule
NeitherUARTnorCANis
Exactlyone
Selectacommunication
specified
communicationmodule [Link]
mustbeselectedin
[Link]
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
[Link]
Selectacommunication
modulethatisavailableforthe
selecteddevice
Selectacommunication
modulethatisavailableforthe
selecteddevice
Selectonlyonecommunication
[Link]
Selectacommunication
modulethatisavailableforthe
selecteddevice
Tryadifferentbaudrateor
oscillatorfrequency.

ConfigurePPSthenremovethe
linethatgeneratestheerror.
Selectexactlyone
communicationmodulein
[Link]
Selectacommunication
modulethatisavailableforthe
selecteddevice
Selectonlyonecommunication
[Link]

15 / 20

ds30 Loader
Firmware manual

March 2012

UART2andCanbusspecified

TXenableisnotavailablefor
CAN
UART2specifiedforadevice
thatonlyhasuart1

spbrg_value_isoutofrange

spbrg_value_mightbeoutof
range

Selectonlyonecommunication
[Link]
Disabletxenable

Selectacommunication
modulethatisavailableforthe
selecteddevice
Oscillatorfrequencyand Tryadifferentbaudrateor
baudratemaybe
oscillatorfrequency
incompatible
Oscillatorfrequencyand Tryadifferentbaudrateor
baudratemaybe
oscillatorfrequency
incompatible

7. Erase device
[Link]
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
[Link]
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
[Link]
[Link]
directoryisconfiguredfromthemenuProject>BuildOptions...>Project\Directories\Build
[Link]
[Link]
runwithoutthebootloader.

Copyright 2009-2012 MG Digital Solutions

17 / 20

ds30 Loader
Firmware manual

March 2012

Considerations

Code protection
Dependingonconfiguration,[Link]
verificationmustbedisabledinthiscase.

Data stored in flash memory


Iftheuserapplicationstoresdatainflashmemory,thisdatamustplacedinaseparate
page/rowthatdoesnotcontainanyactualcodeoritwillbeoverwrittenonthenextwrite.

Linker script
[Link]
whenusinglargedataarrays,thelinkerorassemblermayplacetheseinthesameplaceas
[Link]
[Link]
withthebootloadermemoryspace.

Oscillator
Itisstronglyrecommendedtousethesameoscillatorsetupforboththebootloaderandthe
[Link]/orpll,itisrecommendedto
movethatcodetothebootloader.

Using different oscillator settings for boot loader and application


Iftheuserapplicationistoberunonabatterypowereddevice,theoscillatormaybe
[Link],onemightwantto
[Link]
switching/pllinitializationcodeinthebootloaderfirmware.

Unplanned download of different oscillator setup


Ifoneneedtodownloadadifferentoscillatorsetupandthebootloaderdoesnotalready
haveclockswitchingcode,greatcaremustbetakentomakesurethatthebootloaderwill
[Link]

[Link],onecanaddclock
[Link]
corruptedorawritefailedthebootcannotgetloadedwithcompatibleoscillator
[Link]:

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

Copyright 2009-2012 MG Digital Solutions

18 / 20

ds30 Loader
Firmware manual

March 2012

Interrupts
[Link]
respectiveinterruptsflagpriortoenablinganinterruptinyourapplication.

PIC18 extended instruction set


ds30Loaderdoesnotrelyontheextendedinstructionset,howeverthebootloaderandthe
applicationshouldusethesamesettingwhencompiledtoensurecorrectoperation.
ExtendedinstructionsetisnotsupportedafterthetrialperiodoftheC18evaluationversion.

PPS
ThePPSconfigurationregistersarenotlockedbyds30Loader.

Register default values


[Link],examinethe
code.

User application
Ifthebootloaderisactivatedbyresettingthedevice,thereisusuallynoneedtoadaptthe
[Link],gotoorbranchbecause
thebootloadermayassumeresetvaluesofsomeregisters.

Ifthebootloaderiscalled,gotoed,orbranchedtofromtheuserapplication,interrupts
shouldbedisabledpriortocallingthebootloader.

Watchdog
[Link]
[Link].

Copyright 2009-2012 MG Digital Solutions

19 / 20

ds30 Loader
Firmware manual

March 2012

Appendix A Links
ds30Loaderwebsite
[Link]

ds30Loaderfreeeditionwebsite
[Link]

Copyright 2009-2012 MG Digital Solutions

20 / 20

You might also like