CMSIS-Pack  Version 1.6.1
Delivery Mechanism for Software Packs
 All Pages
Flash Programming

Flash Programming Algorithms are a piece of software to erase or download applications to Flash devices. A Pack with Device Support usually contains predefined Flash algorithms for programming the devices that are supported by the DFP. A template for creating new algorithms are available in the ARM:CMSIS Pack. The following section describes the process in more detail.

Creating a new Algorithm

Flash programming algorithms are defined with functions to erase and program the Flash device. Special compiler and linker settings are required. Follow these steps to create and configure a new Flash programming algorithm:

  1. Copy the content from the ARM:CMSIS Pack folder (usually C:\Keil\ARM\Pack\ARM\CMSIS\version\Device\_Template_Flash) to a new folder.
  2. Rename the project file NewDevice.uvprojx to represent the new Flash ROM device name, for example MyDevice.uvprojx.
  3. Open the project with uVision. From the toolbar, use the drop-down Select Target to define the processor architecture. Cortex-M fits for all Cortex-M0/M0+, M3, and M4 devices. The configuration assumes a little-endian microcontroller. In case of a big-endian microcontroller, select the correct processor core with Project - Options for Target - Device.
  4. Open the dialog Project - Options for Target - Output and change the content of the field Name of Executable to represent the device, for example MyDevice.
  5. Adapt the programming algorithms in the file FlashPrg.
  6. Adapt the device parameters in the file FlashDev.
  7. Use Project - Build Target to generate the new Flash programming algorithm. The output file (for example MyDevice.FLM) has to be added to the DFP.
Note
  • Creating a Flash programming algorithm with MDK-Lite is not supported.
  • Flash programming algorithms use Read-Only Position Independent and Read-Write Position Independent program code. These options are set in the dialogs Project - Options for Target - C/C++ and Project - Options for Target - Asm.
  • The dialog Project - Options for Target - Linker defines the linker scatter file Target.lin. The error L6305 is disabled with –diag_suppress L6305.
  • The Flash Algorithm Functions section contains reference for all the available functions.

FlashPrg.c

The file FlashPrg.c contains the mandatory Flash programming functions Init, UnInit, EraseSector, and ProgramPage. Optionally, depending on the device features (or to speed-up execution), the functions EraseChip, BlankCheck, and Verify can be implemented.

FlashDev.c

The file FlashDev.c contains parameter definitions for:

  1. the Flash programming functions.
  2. the FlashDevice structure:
    struct FlashDevice const FlashDevice = {
    FLASH_DRV_VERS, // Driver Version, do not modify!
    "New Device 256kB Flash", // Device Name
    ONCHIP, // Device Type
    0x00000000, // Device Start Address
    0x00040000, // Device Size in Bytes (256kB)
    1024, // Programming Page Size
    0, // Reserved, must be 0
    0xFF, // Initial Content of Erased Memory
    100, // Program Page Timeout 100 mSec
    3000, // Erase Sector Timeout 3000 mSec
    // Specify Size and Address of Sectors
    0x002000, 0x000000, // Sector Size 8kB (8 Sectors)
    0x010000, 0x010000, // Sector Size 64kB (2 Sectors)
    0x002000, 0x030000, // Sector Size 8kB (8 Sectors)
    SECTOR_END
    };
Note
The Device Name is usually be shown in tools to identify the Flash algorithm. Make sure that this name reflects the device name.
The Programming Page Size specifies the block size for programming using the function ProgramPage. For devices with small block sizes it might be better to specify a multiple of the physical block size as this reduces the communication overhead to the target. An optimal block size for fast programming is 1024 bytes, however the system itself does not restrict this size value.

Adding an Algorithm to a Pack

The generated *.FLM file needs to be added to the Pack with Device Support, so that it is available to the tool user for programming his device. Usually, a directory Flash is created and the algorithm is saved in this directory.

The algorithm is specified within the the /package/devices/family level:

<family Dfamily="STM32F4" Dvendor="STMicroelectronics:13">
...
<algorithm name="Flash/STM32F2xx_512.flm" start=0x08000000 size=0x10000 default="1"/> <!-- valid for all devices of the family -->
<subFamily DsubFamily="STM32F405">
<algorithm name="Flash/STM32F2xx_1024.flm" start=0x08000000 size=0x20000 default="1"/> <!-- valid for all devices of a subFamily -->
<device Dname="STM32F405OE">
<algorithm name="Flash/STM32F2xx_2048.flm" start=0x08000000 size=0x40000 default="1"/> <!-- finally, this is the default for the device -->
</device>
...
</family>

The argument start specifies the base address for the Flash programming algorithm.

The argument size specifies the size covered by the Flash programming algorithm. End address = start + size - 1.

The argument default specifies whether a Flash programming algorithm is set as the default algorithm in a project (when true). If default is not set or false, the Flash programming algorithm can be configured on a lower level. However, the Flash programming algorithm of a project can be changed manually at any time during development.