Supported platforms: CODESYS 3.5, CODESYS 3.5 SAFETY

 

How to update S series and E series FW/SW with SWDownload  

This section describes how to update an application and firmware to an S Series and E Series control unit using SWDownload V4 library.

 

The following Epec libraries are required:

  • CANVXD API version 4.0.0.1 or above

  • CANopen library version 4.0.0.22 or above

  • SWDownload library version 4.0.1.2 or above

    • SL8X/SM8X requires version 4.1.4.2 or above

 

6000 series device description 1.3.1.X and code template which supports the above library versions is required. These are included in SDK3.0.

 

SL8X/SM8X requires MTC8.2 or newer.

 

S Series and E Series application update requires the .app file which is generated in CODESYS 3.5 using Online > Create boot application.

 

S Series and E Series firmware update requires two binary files: Firmware and eTPU.

 

SL8X/SM8X only requires Firmware.

 

This example uses the following POUs to update SC52 Control Unit:

SWDownload library

 

For SL8X, SM8X or SC4X units use following POUs:

 

SW/FW update is included in code template if "Generate Update functionality to codetemplate" is selected in MultiTool Creator. See also Updating Software from Application (6000 series).

 

A reboot is required after application or a firmware update (see also Updating Firmware).

 

Note that when the firmware version is updated, two reboots are required:

  • First boot-up updates the firmware

  • Second boot-up resumes normal operation

 

The application and firmware updating to an S Series and E Series unit is similar to other control units. Before download is possible, the  firmware's SW protection must be unlocked. The unlock sequence is implemented using the UnlockProtectionSSeries function block. For more details about unlock sequence, see UnlockProtectionSSeries.

 

The following example unlocks an S Series unit using CODESYS node-ID 11 and updates both application and firmware.

 

Definitions:

 

VAR

enableTrigger:BOOL := FALSE;

unlockSSeries: EPEC_SWD.UnlockProtectionSSeries;

loaderSC52App: EPEC_SWD.LoadApplicationSSeries;

loaderSC52FW: EPEC_SWD.LoadFirmwareSSeries;

codesysNodeID: BYTE := BYTE#11;

unlockTimeout: TIME := T#1s;

protectionState: EPEC_SWD.ProtectionState;

loadingstate: EPEC_SWD.ApplicationState;

app_file: STRING(80) := '/opt/user/userapp/example.app';

fw_file: STRING(80) := '/opt/user/userapp/FIRMWARE.BIN';

etpu_file: STRING(80) := '/opt/user/userapp/ETPU.BIN';

progress:BYTE;

abortCode: DWORD;

// password needs to match with safety control unit, by default last 4 digits of serial number

password: STRING(20) := '1234';

gfcRequest:BOOL;

gfcRequestOld: BOOL;

sequenceNumber: BYTE := 1;

END_VAR

VAR CONSTANT

SEQ_UNLOCK:BYTE:=1;

SEQ_APP:BYTE:=2;

SEQ_FW:BYTE:=3;

SEQ_SUCCESS:BYTE:=4;

END_VAR

 

 

Code:

 

CASE sequenceNumber OF

 

SEQ_UNLOCK:

unlockSSeries(

i_Enable := enableTrigger, // set enableTrigger variable to TRUE to start

i_pDevice := ADR(G_CANopen_CAN1.Device), // From code template

i_NodeID := codesysNodeID,

i_Password := password,

i_Timeout := unlockTimeout,

o_State => protectionState,

o_AbortCode => abortCode,

o_GFCRequest => gfcRequest

);

 

IF gfcRequest AND NOT gfcRequestOld THEN

G_CANopen_CAN1.GFC_Handler.Activate(); // GFC protocol from code template

END_IF

gfcRequestOld := gfcRequest;

 

IF protectionState < EPEC_SWD.ProtectionState.Idle THEN

; // application error handling

ELSIF protectionState = EPEC_SWD.ProtectionState.Unlocked THEN

sequenceNumber := SEQ_APP;

END_IF

 

SEQ_APP:

loaderSC52App(

i_Enable := TRUE,

i_pDevice := ADR(G_CANopen_CAN1.Device), // From code template

i_NodeID := codesysNodeID,

i_File := app_file,

i_UseBlockTransfer := TRUE,

o_State => loadingstate,

o_AbortCode => abortCode,

o_Progress => progress

);

 

IF loadingState < EPEC_SWD.ApplicationState.Idle THEN

; // application error handling

ELSIF loadingState = EPEC_SWD.ApplicationState.Idle THEN

loaderSC52App(i_Enable := FALSE);

sequenceNumber := SEQ_FW;

END_IF

 

SEQ_FW:

loaderSC52FW(

i_Enable := TRUE,

i_pDevice := ADR(G_CANopen_CAN1.Device), // From code template

i_NodeID := codesysNodeID,

i_FWFile := fw_file,

i_eTPUFile := etpu_file,

i_UseBlockTransfer := TRUE,

o_State => loadingstate,

o_AbortCode => abortCode,

o_Progress => progress

);

 

IF loadingState < EPEC_SWD.ApplicationState.Idle THEN

; // application error handling

ELSIF loadingState = EPEC_SWD.ApplicationState.Idle THEN

loaderSC52FW(i_Enable := FALSE);

sequenceNumber := SEQ_SUCCESS;

END_IF

 

SEQ_SUCCESS:

;

 

END_CASE

 

See also

 

Source file topic100448.htm

Last updated 21-Feb-2025