CANopen-BootloaderSoftware Manual L-1112e 05
CANopen-BootloaderSoftware Manual L-1112e 05
Software Manual
The designations used in this book for products that are also registered trademarks have
not been separately marked. The missing © sign does not therefore imply that the
designation is a non-registered product name. At the same time, no inference can be
made from the designation used that this refers to any pending patent or that a registered
design is protected.
The information in this manual has been carefully checked and can be assumed to be
correct and accurate. However, we expressly draw your attention to the fact that the
SYS TEC electronic GmbH company neither excepts warranty claims nor legal
responsibility, nor claims of any sort from secondary damages resulting from the use of
this manual or its content. We reserve the right to change the details specified in this
manual without notice. The SYS TEC electronic GmbH company does not thereby
incur any obligations.
Furthermore, we also expressly draw your attention to the fact that the SYS TEC
electronic GmbH company neither excepts warranty claims nor legal responsibility, nor
claims of any sort from secondary damages resulting from the incorrect use or incorrect
application of the hardware or software. The layout and/or design of the hardware may
also be changed without notice. SYS TEC electronic GmbH does not thereby incur any
obligations.
© Copyright 2008 SYS TEC electronic GmbH. All rights reserved. No part of this
manual may be reproduced, edited, copied or distributed in any form b< means of the
appropriate systems without previous written permission from the SYS TEC electronic
GmbH company.
Table of contents
1 Introduction ........................................................................................ 1
2 References............................................................................................ 2
3 Design of data transmission............................................................... 3
3.1 Checksum application................................................................ 11
3.2 Starting the bootloader............................................................... 12
3.3 Software structure of the target.................................................. 14
4 Interfaces ........................................................................................... 17
4.1 Interface to the flash .................................................................. 17
4.1.1 Interface to the timer..................................................... 22
4.1.2 Interface for NodeID .................................................... 25
4.1.3 Application parameter .................................................. 26
4.1.3.1 TgtGetAppInfo .............................................. 26
4.1.3.2 TgtGetAppSize.............................................. 26
4.1.3.3 TgtSetAppSize .............................................. 27
4.1.3.4 TgtGetAppCrc ............................................... 27
4.1.3.5 TgtSetAppCrc................................................ 28
4.1.3.6 TgtCheckAppSig........................................... 28
4.1.3.7 TgtClrAppSig ................................................ 29
4.1.3.8 TgtSetAppSig ................................................ 29
4.1.3.9 TgtGetAppSig ............................................... 29
4.1.3.10 TgtGetSerialNr .............................................. 29
4.1.4 Re-entry in the bootloader ............................................ 29
4.1.5 Interface to the CAN bus .............................................. 30
4.1.6 Debug outputs............................................................... 30
4.2 Configuring the bootloader........................................................ 31
5 Flash tool ........................................................................................... 35
5.1 BinaryBlock-Converter.............................................................. 35
5.2 BinaryBlock-Download............................................................. 38
5.3 Configuring the flash tool software (FtCfg.h) ........................... 40
5.4 Error codes of the flash tool software (FtErrDef.h)................... 42
6 Resources........................................................................................... 45
6.1 Code, data target ........................................................................ 45
6.2 Target interrupts......................................................................... 45
Table of figures
List of tables
1 Introduction
The software package is comprised of two parts: the flash tools and the
bootloader. The flash tools convert the application data (S3, INTEL-Hex)
into a binary format and transfer them to the target hardware. The
bootloader receives the data transmitted by the flash tools, verifies them
and writes the data into the flash; it then starts the application that has been
transferred.
Communication and data transmission between the bootloader and the flash
tools is by means of CANopen SDO transfer.
This manual describes the mode of operation of the bootloader, the format
of the binary data and the interface to adapt the bootloader to the user
hardware.
2 References
The advantage of the use of CANopen SDO transfer to transmit data is that
CANopen tools can be used to programme the application. An EDS file is
required for this that maps the object entries of the CANopen nodes. The
data is transmitted in binary format and must be converted into this format
(e.g. HEX Æ BIN) depending on the development environment.
SDO transfer according to CiA DS-301 is used for data transfer. This
transmission service supports protocols such as segmented transfer and
block transfer. The default setting is segmented transfer because this
service requires less CODE to be run. However, due to the
acknowledgment sequence of the data, which is segment-by-segment, the
transmission time may be slightly longer in comparison to block transfer.
The 0x1F50 object is used to load the programme data. The object-type is
DOMAIN and it can receive data up to a block size defined by the user.
The 0x1F51/1 object is used to run certain commands (deleting the flash,
starting the application, etc.). The 0x1F56 object contains an identification
of the application. The CRC of the application is stored here. The current
error status can be read out by object 0x1F57. Table 1 lists all CANopen
objects and their meaning.
commands (0x1F51/1)
Objects
The status that can be read back in index 0x1F57 can assume the following
states:
n * Data Bytes
Offset 0x000C
Data Size [bytes]
Offset 0x0008
Flash Address
Offset 0x0004
Block Number
Offset 0x0000
Important:
Data is always transmitted in Intel format (Little Endian / LSB first). This
must be considered when creating a block.
then also entered into object 0x1F56/1. The flash tool only starts the
application after this by entering the „Start“ command into object 0x1F51/1.
time
"Clear"
aditional
Status info
Block 0
Status
Block 1
Status Program
SDO SDO Data
Flashtool Bootloader
Client Block 2 Server
. Status
.
. Block -1
Status
size and
"Start" CRC
Procedure in principle
To transfer a new application to the target, the host (flashtools) carries out
the following procedure. In case errors occur, the whole procedure is
stopped.
1. Transforming the application into binary format (e.g. HEX -> BIN).
2. Reading object 0x1000 (devicetype) to observe if the bootloader is
active. If the value detected equals the one of the bootloader
(0x10000000), it is to be proceeded with step 4. In case of faulty
SDO-transfer with timeout, this step is to be repeated.
3. Running the command to return to the bootloader (writing the value
0x80 to object 0x1F51/1). Afterwards step 2 is to be repeated.
4. Running the command to erase the flash (writing the value 0x03 to
object 0x1F51/1).
5. Reading object 0x1F51 to observe if the erasure has been carried out.
In case of faulty SDO-transfer with timeout or if the value BUSY
was delivered back, this step is to be repeated.
6. Loading the first block of data from the binary data file.
7. Downloading the block of data to object 0x1F51/1.
Timeouts
Two timeouts are relevant for transmitting the data from the host (flash tool)
to the target (bootloader). One of these is the timeout for acknowledgement
of the transmitted SDO service (an SDO transfer is always acknowledged).
This timeout is relatively short as only the delay caused by the transmission
path (bit rate, load on bus) must be considered here.
The other timeout must be selected depending on the command transmitted.
In general, a command must be completely transmitted and acknowledged
before being run. The execution time, and therefore the timeout to be
selected at the host, depends on the command in question. If necessary,
other times must be considered for deleting the flash or writing the data
than for writing a signature. The user must configure the correct timeouts.
StartAddress
AppSize
Applikation
reserviert
EndAddress
clear signatur
no
Signature set?
yes
no
CRC ok?
yes
Starting the application presupposes that the CRC via the application area is
identical to the CRC calculated on the host and that is stored on the target,
that there is a valid node number (the node numbers must be within a value
area defined for this application) and that a valid signature has been stored.
If one of these conditions is not fulfilled then the target dwells in the
bootloader.
There are various ways of implementing the signature. The signature can be
stored in the flash or in another non-volatile memory (e.g. EEPROM,
NVRAM).
However, it is also possible to implement the signature using a port pin. In
all cases, if the signature is not set then the bootloader is started.
main.c
BlCop.c
other
CdrvXxx.c
File Meaning
Directory of CANopen_Bootloader
Source\main.c Contains the main() function for the bootloader
Source\BlCop.c Contains the interface functions of the bootloader
Source\Crc32.c Contains functions for calculating a 16 bit CRC
Objdicts\Objdict.* Definition of the object directory, EDS file of the
bootloader
Target\XC16x\Source\FlashDrv.c Contains functions to delete and write the flash and
must be adjusted to the target accordingly
Target\XC16x\Source\Target.c Contains the target-specific functions for deleting
and writing the signature, CRC, application size,
etc.
Target\XXX\Include\BlCopCfg.h Constants for bootloader configuration
Target\XXX\Include\CopCfg.h Constants for CANopen configuration
Target\XXX\Include\CdrvTgt.h Definition of the CAN driver
Directory of CANopen_V5
CopStack\SdosComm.c Functions for the SDO server
CopStack\Obd.c Functions for access to the object directory
CopStack\Cob.c Functions used for generating the communication
objects.
CopStack\AmiXXX.c Contains special functions for memory access
CopStack\LSSS.c Only when supported by LSS
Cdrv\CdrvXXX.c Contains driver functions for access to the CAN
controller
Cdrv\BdiTabXX.c 1 Contains a baud rate table for the CAN interface
Table 4: Source files for the bootloader
4 Interfaces
a) FlsDrvInitialize function
Meaning:
This function initialises the flash driver. If the internal functions can only
be run from the RAM then the required functions are copied into the RAM.
Access to these functions is then implemented by function pointers. The
function call must be implemented from within the flash driver. It is the
responsibility of the user to initialise the function pointer.
Parameters:
none
Response:
This function returns a 0 if initialisation was successful.
b) FlsDrvEraseInitialize function
Meaning:
This function initialises the deletion of an application area. An application
area is designated by its start address and its end address and can be
comprised of one or more flash sectors/page. The start address must be
lower than the end address.
Parameters:
dwStartAddr_p: Start address of the application area
dwEndAddr_p: End address of the application area
Response:
This function returns a 0 if initialisation was successful.
c) FlsDrvEraseSector function
Meaning:
This function deletes a part of the flash within the application area (the
application area was specified by the FlsDrvEraseInitialize function using
the dwStartAddr_p, dwEndAddr_p parameter). An application area can be
comprised of several flash sectors/pages. The value dwSecAddr_p zeigt
points to the first cell to be deleted within the area. The pdwSize_p pointer
points to the size of the area to be deleted. The number of bytes to be
actually deleted is stored in *pdwSize_p.
Parameters:
dwSecAddr_p: Start address of the area to be deleted
*dwSize_p: Pointer to the size of the area
Response:
This function returns a 0 if deletion of the flash sector was successful. The
dwSize_p pointer points to the number of bytes actually deleted.
d) FlsDrvWriteData function
Meaning:
This function writes data in the flash area of the application. If required,
this function also cyclically calls the FlsDrvResetWatchdog function.
Parameters:
pbData_p: This pointer indicates the start address of the
source data to be written to the
flash.
dwStart_p: This parameter indicates the start address of the
flash to which the source data
is to be written.
dwSize_p: This parameter indicates the number of bytes
to be written into the flash.
Response:
This function returns a 0 if writing to the flash was successful.
e) FlsDrvVerifyData function
Meaning:
This data checks the data in the flash area against the transmitted data. The
function cyclically calls the FlsDrvResetWatchdog function.
Parameters:
pbData_p: This pointer indicates the start address of the
source data to be checked against the data
in the flash.
dwStart_p: This parameter indicates the start address of the
flash from where the data
is to be read.
dwSize_p: This parameter indicates the number of bytes
to be checked in the flash.
Response:
This function returns a 0 if checking of the flash was successful.
f) FlsDrvReadData function
Meaning:
This function reads out a data block. The start address is thereby
incremented by the read number of bytes. The pointer *pdwSize_p points
to the number of read bytes when quitting the function.
The function packages special features target-specific when reading the
code memory.
Parameters:
pbData_p: Pointer to the address with the read data
pdwStartAddr_p: Pointer to the start address of the block to be read in
the code memory
pdwSize_p: Pointer to the number of bytes
Response:
This function returns a 0 if deletion of the flash sector was successful.
Additionally, the start address of the next block is calculated
(pdwStartAddr_p) by the function and the actual number of read bytes is
calculated (pdwSize_p).
g) FlsDrvEnterCriticalSection function
Meaning:
This function blocks the global interrupt flag during the time in which the
flash is accessed. This function is required within the flash driver when
running of machine commands is not possible during deletion or when
programming data.
Parameters:
none
Response:
none
h) FlsDrvLeaveCriticalSection function
Meaning:
This function once more releases the global interrupt flag.
Parameters:
none
Response:
none
i) FlsDrvResetWatchdog function
Meaning:
This function resets the watchdog. This function is required when the
execution period of an internal function nears the watchdog timeout.
Parameters:
none
Response:
none
a) TgtInitTimer
Meaning:
This function initialises a system timer for provision of a system timing
clock of 1ms.
Parameters:
none
Response:
none
b) TgtStopTimer
Meaning:
This function stops the system timer and once more releases the used
resources (timer, interrupt).
Parameters:
none
Response:
none
c) TgtTimerIsrHandler
Meaning:
This function is called during an interrupt of the system timer in order to
increment the tick count.
Parameters:
none
Response:
none
d) TgtGetTickCount
Meaning:
This function returns the current value of the system timer, whereby the
return value is sized to a multiple of 100µs.
Parameters:
none
Response:
TickCount * 10 (corresponds to 100µs)
a) TgtGetNodeId
Meaning:
This function returns the NodeId. This may have been set using decode
switches or it is stored permanently in the firmware. When configuring the
NodeId using LSS, this value must be read-out from a non-volatile memory.
To start the LSS service, the function 0xFF must be returned (memory is
invalid Æ start configuration).
Parameters:
pbNodeId_p: Pointer to NodeID
Response:
0: *pbNodeId_p = 1 .. 127, 255
>0: *pbNodeId_p = invalid
b) TgtSetNodeId
Meaning:
This function stores a node number configured with LSS in a non-volatile
memory.
Parameters:
Node-ID = 1 ... 127, 255
Response:
0: no error, storage successful
>0: Error code
4.1.3.1 TgtGetAppInfo
4.1.3.2 TgtGetAppSize
Meaning:
The TgtGetAppSize function reads the application size from the non-
volatile memory of the target.
Parameters:
pdwSize_p: Pointer to the variable for storing the application size
Response:
This function returns the size of the application if the value is valid.
4.1.3.3 TgtSetAppSize
Meaning:
The TgtSetAppSize function is used to store the size of the application in a
non-volatile area of the target. The value is required to calculate the CRC
for the application area before starting the application.
Parameters:
dwSize_p: Size of application for storage
Response:
none
4.1.3.4 TgtGetAppCrc
Meaning:
The function reads the CRC of the application from the non-volatile
memory of the target. The value has been calculated on the host side and
stored on programming the application using the TgtSetAppCrc function.
The value is required to compare the CRC determined with the value at the
host side in order to start the application.
Parameters:
pdwCrc_p: Pointer to the variable for storing the CRC
Response:
This function returns the CRC calculated at the host node and stored at the
target.
4.1.3.5 TgtSetAppCrc
Meaning:
This function stores the CRC in the non-volatile memory of the target. The
CRC was calculated on the host side and transmitted to the target during the
download. The CRC must be stored there non-volatile for later verification
when starting the target.
Parameters:
dwCrc_p: CRC for storage
Response:
none
4.1.3.6 TgtCheckAppSig
BYTE TgtCheckAppSig(void);
Meaning:
The signature declares the state of the application. A valid signature is the
requirement to start the application. The signature is set on request from the
host after the application has been verified. The function checks whether a
valid signature has been stored.
Parameters:
none
Response:
TRUE: The signature is valid
FALSE: The signature is invalid
4.1.3.7 TgtClrAppSig
4.1.3.8 TgtSetAppSig
4.1.3.9 TgtGetAppSig
Meaning:
4.1.3.10 TgtGetSerialNr
The serial number is required in order to uniquely identify the target within
a CANopen network in connection with VendorID, ProductCode and
RevisionCode. The functions package the access to the non-volatile
memory of the target for reading or writing the serial number.
Storage of the serial number in non-volatile memory is not executed by the
bootloader. It is up to the user to implement the required steps.
TgtJumpBootloader
Meaning:
This function must be linked to a fixed address to implement a re-entry to
the bootloader from the application. Before re-entry, all resources must be
released by the application and the global interrupt must be blocked.
Parameters:
none
Response:
none
BLCOP_MAX_PROGRAMS:
This constant indicates the number of applications that can be
programmed into the flash with the bootloader. The current version of
the bootloader only supports one application.
BLCOP_MAX_PROGRAMS:
This constant indicates the number of bytes that can be transmitted to
the bootloader in a block. The block information (block number, flash
address, number of data bytes and block CRC) is included.
BLCOP_MIN_NODEID:
This constant indicates the smallest CANopen node address that is
supported by the bootloader. The smallest possible value for this
constant is 1 (limited by the CANopen Standard CiA 301).
BLCOP_MAX_NODEID:
This constant indicates the largest CANopen node address that is
supported by the bootloader. The largest possible value for this
constant is 127 (limited by the CANopen Standard CiA 301).
BLCOP_MIN_BAUIDX:
This constant indicates the smallest baud rate index that is supported
by the bootloader.
BLCOP_MAX_BAUIDX:
This constant indicates the largest baud rate index that is supported by
the bootloader.
BLCOP_SEND_BOOTUP:
This constant indicates whether or not the CANopen boot-up message
is to be transmitted. In the release version of the bootloader
(NDEBUG is defined), this constant is set to FALSE; the message is
therefore not sent.
BLCOP_BDI_TABLE_PTR:
This constant indicates which baud rate table is to be used. The baud
rate settings in the CAN controller vary when another CPU frequency
is set. The baud rate settings must then be re-determined.
BLCOP_BDI_TABLE_SIZE:
This constant indicates the size of the baud rate table in bytes.
BLCOP_BASE_REQUEST:
This constant indicates the base CAN identifier for the SDO request
that constitutes the actual CAN identifier together with the CANopen
node address.
BLCOP_BASE_RESPONSE:
This constant indicates the base CAN identifier for the SDO response
that constitutes the actual CAN identifier together with the CANopen
node address.
BLCOP_USE_CANCRTL:
This constant indicates which CAN interface is to be used by the
bootloader. The value 0 means CAN_A, value 1 means CAN_B and
value 2 means CAN_C.
BLCOP_USE_CANINTENABLE:
This constant indicates which function must be called to temporarily
block the CAN interrupt.
BLCOP_MAX_CANLOOPS:
This constant indicates the maximum number of CAN messages to be
evaluated from the receive buffer. As deleting the flash sectors takes a
relatively long time, this value should be set to 1.
BLCOP_IDENTITY_VENDORID:
This constant indicates the value for the Vendor ID to be written into
the 0x1018/1 object. The value 0x3F (63 decimal) indicates the SYS
TEC electronic GmbH company.
BLCOP_IDENTITY_PRODUCTID:
This constant indicates the value for the Product ID to be written into
the 0x1018/2 object. The value 0x0610 (value specific to SYS TEC)
indicates the CAN flash bootloader.
BLCOP_IDENTITY_REVISION:
This constant indicates the revision number to be written into the
0x1018/3 object. The value is to be indicated in the format as defined
in the CANopen Standard CiA 301. For example, the value
0x00010002 would indicate Version V1.02.
BLCOP_IDENTITY_SERIALNR:
This constant indicates the serial number to be written into the
0x1018/4 object. According to the CANopen standard, each device
must have a unique serial number. To be able to implement this, the
serial number must be read out from an EEPROM set one time during
production. For this method, the parameter dwSerialNr_p has been
reserved for the BlCopInitialize() function.
BLCOP_MAX_CRC_STEP_SIZE:
This constant indicates the maximum number of bytes should be run
through in the calculation of the CRC when running the
BlCopProcess() function. The external watchdog must be triggered
again after this call.
BLCOP_MAX_FLSWRITE_STEP_SIZE:
This constant indicates the maximum number of bytes should be run
through ifor writing the data in the flash when running the
BlCopProcess() function. The external watchdog must be triggered
again after this call.
BLCOP_BOOTLOADER_START:
This constant indicates the start address in the flash at which the
bootloader starts.
BLCOP_BOOTLOADER_END:
This constant indicates the last address in the flash at which there can
be bootloader code To ensure that the bootloader can be programmed
separately in the flash, this value must end at a flash sector.
BLCOP_BOOTLOADER_RAM:
This constant indicates the start address in RAM at which the interrupt
vector table starts.
BLCOP_APPLICATION_START:
This constant indicates the start address in the flash at which the
application starts. This address is the basis for calling the reset vector
of the application
BLCOP_APPLICATION_END:
This constant indicates the last address in the flash at which the
application can be programmed. This address must also include the
application CRC and the size of the application. Both parameters are
always in the last 8 bytes of the application area in the flash.
BLCOP_APPLICATION_RAM:
This constant indicates the start address in the RAM that is reserved
for the application.
FLSDRV_START_APPLICATION:
Refer to constant BLCOP_APPLICATION_START. The flash driver
receives its own constant for the start address of the application to
ensure that it can also be used in other projects.
FLSDRV_END_APPLICATION:
Refer to constant BLCOP_APPLICATION_END. The flash driver
receives its own constant for the end address of the application to
ensure that it can also be used in other projects.
5 Flash tool
5.1 BinaryBlock-Converter
This tool generates a block-oriented binary format from the output format
specific to the toolchain (S record, hex file, elf file). The following
parameters must be transmitted:
Block 0
Block 1
...
Block N
Block -1
Construction of block 0:
Construction of block 1 .. N:
The CRC is calculated over the entire content of a block according to the
polynomial 0xEDB88320. The start value is 0xFFFFFFFF. The same
algorithm is used to calculate the CRC for the entire application.
5.2 BinaryBlock-Download
This tool transfers the binary blocks from the output file generated by the
BinaryBlockConv. This tool thereby transfers exactly one partial
application that is designated by its programme number. A USB-CAN
module is used as the interface to the CAN-bus.
FT_FLASH_START:
This constant has the same meaning for the flash tool as constant
BLCOP_APPLICATION_START for the bootloader.
FT_FLASH_SIZE:
This constant indicates the number of bytes in the flash area of the
application.
FT_FLASH_DEF_VAL:
This constant indicates the value received in the flash after deletion.
This value is important in the flash tool to calculate the CRC, whereby
non-programmed flash cells must also be considered.
FT_BLOCK_SIZE:
This constant has the same meaning for the flash tool as constant
BLCOP_MAX_PROGRAM_BUFFER for the bootloader.
FT_BLOCK_MAX_GAP:
This constant sets the maximum number of non-programmed bytes
before the flash tool uses a new block for downloading the subsequent
programme data. It is indented to prevent 16384 bytes having to be
transmitted in one block to the bootloader although, e.g. only the fist
and the last byte have to be programmed according to the HEX file.
FT_DEF_NODE_ID:
If the call parameter –N... is not transmitted to the flash tool, then the
HEX file is transmitted to the CANopen node address defined in this
constant. Constants FT_BASE_CANID_SDO_REQUEST ad
FT_BASE_CANID_SDO_RESPONSE are included for the CAN
identifier used.
FT_DEF_NODE_ID:
If call parameter –B... is not transmitted to the flash tool then the baud
rate index of this constant is used.
FT_DEF_RETRY_TIMEOUT:
This constant indicates the number of repetitions that are carried out
during SDO transfer after a timeout.
FT_DEF_RETRY_BUSY:
This constant indicates the number of repetitions carried out by SDO
transfer after the bootloader has returned the BUSY state.
FT_DEF_TIME_DELAY:
This constant indicates the time delay in 100 milliseconds steps that
the flash tool waits between reading object 0x1F57/1. This is intended
to prevent that the flash tool does not fill the CAN bus unnecessarily
with CAN messages while the bootloader is busy.
FT_DEF_SDOC_TIMEOUT:
This constant indicates the time delay in 100 milliseconds steps until
the flash tool determines a timeout during SDO transfer.
FT_BASE_CANID_SDO_REQUEST:
This constant has the same meaning for the flash tool as constant
BLCOP_BASE_REQUEST for the bootloader.
FT_BASE_CANID_SDO_RESPONSE:
This constant has the same meaning for the flash tool as constant
BLCOP_BASE_RESPONSE for the bootloader.
FT_MIN_NODE_ID:
This constant has the same meaning for the flash tool as constant
BLCOP_MIN_NODEID for the bootloader.
FT_MAX_NODE_ID:
This constant has the same meaning for the flash tool as constant
BLCOP_MAX_NODEID for the bootloader.
Error codes from the flash tool software begin from value 0x60000000. All
possible error codes are listed in table X.
However, if for instance the input file could not be opened then the flash
tool reads the error code from the „errno“ variable and returns it to the
console together with an appropriate error message. A list of possible error
codes is contained in the MSDN.
All error codes from 0x60001000 flag an error code from the CANopen
stack. The meaning of the corresponding error code (minus offset
0x60001000) can be looked up in L-1020.
6 Resources
Sent by:
Customer number:
Name:
Company:
Address: