Microsemi SmartFusion2

Porting Paulus on Microsemi SmartFusion2

File structure

After installation of Paulus the source code is stored in the file structure shown in Table 1 describes the contents.

directory

description

/paulus_smartfusion2

project folder with all necessary Softconsole IDE project files

/bootloader

target independent CANopen sources for Paulus

/eds

Design Tool project of Paulus with generated files, e.g. the EDS file

/ smartfusion2/

target-specific sources of Paulus, e.g., CAN-, Flash-driver, low-level drivers and supporting services from Microsemi

/smartfusion2/smartfusion2_flash.[ch]

target-specific flash routines

/smartfusion2/smartfusion2_can.[ch]

CAN routines

/smartfusion2/smartfusion2_init.c

CPU initialization

/smartfusion2/environ.h

header file for the environment definition

/smartfusion2/bl_config.h

Paulus configuration file

/smartfusion2/CMSIS

/smartfusion2/drivers[config]

/smartfusion2/hal

Microsemi “FirmwareCatalog” generated sources, included CMSIS Cortex-M core layer, Startup and linker files from devices with GCC, HAL- layer e.g., drivers for CAN, GPIO, NVM and other services

/examples

example application for a CANopen slave with all sources and project files

/tools

checksum generator tool for Paulus

main.c

main loop of Paulus

Table 1: description of directories

The initialization of the CAN controller is done in module smartfusion2/ can.c.

In module smartfusion2 / init.c the I/O pins for the CAN interface have to be initialized.

In module smartfusion2/ init.c there must be the functions getBitRate() and getNodeId() available. Usually the CANopen network parameters are provided by reading jumpers or by loading from flash memory.

Development environment

Paulus on the platform of Microsemi SmartFusion2 was developed with the Microchip SoftConsole v2021.1-6.6.0.507. Target Board: Customer specific HW with Device-Type: M2S060.

Paulus configuration

In general the initialization function initializes only the absolutely necessary peripherals like clock system, CAN controller, memory management as needed by Paulus and a timer for Heartbeat or LSS. Nevertheless, there might be situations where it makes sense that Paulus initializes other functionalities which are later used by the application as well. As an example consider the serial interface for debug messages.

CAN bit rate

The CAN bit rate is coded by the index of the CAN bit timing table according to /CiA-305/. The index of the default CAN bit rate is specified about the compiler-define BITRATE_INDEX_<bit_rate> in / smartfusion2 /bl_config.h:

#define BL_USED_BITRATE_INDEX   BITRATE_INDEX_125K

The default CAN bit rate is 125 kbit/s and can be changed by LSS services. The LSS services are described in /Paulus_man/ and base on /CiA-305/. The supported CAN bit rates are depending on the clock of the CAN controller and are listed in /smartfusion2/smartfusion2 _can.c. The value FFh for segment2 marks unsupported CAN bit rates. The clock for the activation of the CAN bit rate is generated by timer Systick with a period of 1 ms.

Heartbeat producer

Timer Systick is also used for the generation of Heartbeat producer messages.

Read Identity object 0x1018 from NVM

If the user needs the values for the identity object from Paulus (Vendor-ID, Product code, Revision number, Serial number) in different devices with different values then the following define must be activated.

#define BL_IDENTITY_OBJECT_1018_READ_FROM_NVM

If this activated, in the startup from Paulus the data for this object are read from a predefined flash area. The address from this area is defined:

#define BL_CONF_IDENTITY_BLOCK     0x60007880u /* default address */

The user must ensure that his desired data is written on this address. This is possible for example with a Flash Programmer tool.

Debug output

By the compiler-define DEBUG a debug output can be activated. The compiler-define is set in file /smartfusion2 /bl_config.h:

#define DEBUG 1

In general the initialization function will initialize only the absolutely necessary peripherals like clock system, CAN controller, memory management as needed by Paulus. Nevertheless, there might be situations where it makes sense that Paulus initializes other functionalities which are later used by the application as well. As an example consider the serial interface for debug messages.

Generating application software

The application software consists of an application header and an application program, see Figure 2.

Figure 1: structure of application software

The application program has to be prepared for download by the following steps:

  •  build the application program in binary format

  • calculate the CRC of the application program, build the application header and generate the application software to download

  • configure the start address of the application software in Paulus

Paulus checksum

The program paulus_cksum calculates the CRC checksum of the binary application program generates the application header and stores the application header and the application program in a new file. This file can be loaded in the device by Paulus.

Unused bytes in the application header are set to 0x00 with the Smartfusion2. The length of the application header is 0x200 bytes. The input file (s1_smartfusion2.bin) for this tool is the generated binary output from the Microchip SoftConsole (build outputfile format “Raw Binary”).

Example: The download file for the application program s1_smartfusion2_download.bin is generated about Windows console:

C:\jsc\Paulus_Microsemi_SmartFusion2\paulus_bootloader\software\tools> paulus_cksum.exe -v -C -l 0x200 -x 0x60008200 s1_smartfusion2.bin -O s1_smartfusion2_download.bin reduce Flash end to file end: 0x00006630 reduce EndAddr to the Flash end 0x0000662f address - crc: 0x00000000, start: 0x00000000, end: 0x0000662f, exec 0x60008200 Flash end: 0x00006630 out: >s1_smartfusion2_download.bin< input: >s1_smartfusion2.bin< calc CRC from 0x00000000 to 0x0000662f size: 0x00006630, crc: 0x145c Writing Appl. to >s1_smartfusion2_download.bin<: length: 26160/0x6630, crc: 0x145c, execadr: 0x60008200

Besides checking the CRC Paulus checks also the size of the application header. A size of 0 is invalid. An application may destroy the ’valid’ information by overwriting the size with 0. That is always possible on the Smartfusion2 FLASH, because the byte content is 0xFF after erasing.

More detailed information from this tool can find in /Paulus_CRC/.

Start address

It is important that the start address of the application software in the flash memory and the information in the Paulus configuration in smartfusion2/smartfusion2_flash.h are identical. The application software is stored as a separate program in the flash memory additionally to the bootloader program. Therefore the application software is flashed to:

#define FLASH_PROGRAM_START_ADR   0x60008000u // default configuration

The length of the application header is 0x200 byte. The real program start of the application is at address (FLASH_PROGRAM_START_ADR + 0x200 bytes).

Memory

Shared RAM

The shared RAM for data exchange between bootloader and application starts at address 0x20000000. The size of the shared RAM is specified in smartfusion2/bl_interface.h by the compiler-define BL_JUMPCODE_SIZE. The shared memory is installed in smartfusion2/bl_interface.h as follow:

/* jumpcode placed on ram adress 0x20000000 */

__attribute__((section (".myRAMSection"))) UNSIGNED8 jumpcode[BL_JUMPCODE_SIZE];

The keyword for the re-start of the application program is set in byte 0-3 of jumpcode. Paulus uses the keyword “APPL” or “BOOT” to start the application program, see /Paulus_man/.

Flash

The total size of the Smartfusion2 flash is 256Kb. The current implementation of Paulus occupies a memory area of 32Kb from this. Therefore 224Kb (less 0x200 byte crc header) flash memory area available for the application software.

Figure 2: Flash memory mapping

On power-on, the eNVM region 0x60000000 is automatically remapped to the Cortex-M3 processor executable region start address (0x00000000). Hence, for every power-on reset the Cortex-M3 processor fetches the initial stack pointer from 0x00000000 (eNVM address 0x60000000) and address of the reset handler from 0x00000004 (eNVM address 0x60000004). Once the execution control goes to the default reset handler, the boot up sequence executes and execution control jumps to the user boot code. The boot code always starts in the paulus bootloader, this decides whether the application is started.

The flash area for LSS configuration data of Paulus is located at address 0x60007800. On this address and the following Paulus stores the node-ID and the CAN bit rate index during the execution of the LSS service “LSS store configuration“. The addresses are configurable in smartfusion2/bl_interface.h:

#define FLASH_ADDRESS_NODEID           0x60007800

#define FLASH_ADDRESS_BITRATE_INDEX    0x60007801

/* additional need some bytes in RAM for NodeId and bitrateIndex saved in a special section */

__attribute__((section (".myRAMSection"))) UNSIGNED8 flashNodeId=0xFF;

__attribute__((section (".myRAMSection"))) UNSIGNED8 bitrateIndex=0xFF;

After the next re-start Paulus uses this node-ID and this CAN bit rate index for communication. The new CAN bit rate cannot be activated by NMT-Command Reset Application. If the LSS services are not used, Paulus uses the node-ID and CAN bit rate index configured in smartfusion2/bl_config.h.

For the additional feature “Read Identity object 0x1018 from NVM” the following struct is prepared:

/* address of identity (object 0x1018) Block in FLASH */ /* DESIGN EXAMPLE! */ typedef struct {     UNSIGNED32 VendorId;        /* u32 hex - object 0x1018:1  */     UNSIGNED32 ProductCode;     /* u32 hex - object 0x1018:2  */     UNSIGNED32 RevisionNumber;  /* u32 hex - object 0x1018:3  */     UNSIGNED32 SerialNumber;    /* u32 hex - object 0x1018:4  */ } BL_IDENTIY_BLOCK_T; static BL_IDENTIY_BLOCK_T identity_block;

The Paulus fills this struct in startup with the data from the predefined flash area.  Starting at address 0x60007880 and following (4 x u32 values). Previously the data was written e.g. via a simple NVM-Writer example project from SoftConsole-IDE:

After reading the data in the struct these are used for CANopen communication (e.g read items from object 0x1018 - especially for the LSS service).

Example application 

CANopenSlave1 is an example for an application program. The directory example/ CANopenSlave1xx/ /examples/s1_smartfusion2 contain the compiler project and the application-specific functions. For compilation the CANopen Library and the suitable driver package is necessary. The CANopen Library and the driver package belong not to the delivery scope of Paulus. The binary application software in example/ CANopenSlave1xx/bin/s1_smartfusion2_download.bin can be used for a quick start.

The linker file of this example project is adapted on these memory requirements.

See settings in linker-file (debug-in-microsemi-smartfusion2-envm.ld) from example:

/******************************************************************************* * Start of board customization. *******************************************************************************/ MEMORY { /* SOFTCONSOLE FLASH USE: microsemi-smartfusion2-envm */ /* LENGTH = eNVM size (256K) - Paulus size (32K) - appl crc-header (0x200) */ rom (rx): ORIGIN = 0x60008200, LENGTH = 223k /* SmartFusion2 internal eNVM mirrored to 0x00008200 */ romMirror (rx): ORIGIN = 0x00008200, LENGTH = 223k /* SmartFusion2 internal eSRAM */ ram (rwx): ORIGIN = 0x20000000, LENGTH = 64k } /* placing my ram section at given address: */ .myBufBlock 0x20000000 (NOLOAD): ALIGN(0x10) { KEEP(*(.myRAMSection)) /* keep my variable even if not referenced */ } > ram

This example has included source files bl_interface.c, bl_interface.h from bootloader. The application program can request an update by jumping back into Paulus by writing of the program control command start application program (value 1) on object 1F51h/1. The application program calls the macro BOOTLOADER_JUMP(APPL). This call is implemented in usr_301.c /sdoWrInd(). The application program stores the keyword “APPL” in the shared RAM and jumps into Paulus. Paulus is re-started and stays running until the application program is started by command.

References

/CiA-305/

CANopen Layer Setting Services and Protocols, CiA

/Paulus_CRC/

manual “Paulus Checksum Tool”, see file  tools/manual_cksum.pdf

/Paulus_man/

manual “Paulus User Manual”, see file  UserMan_Paulus_Bootloader_e.pdf

 Table 2: References