PEmicro Blog

Cyclone Control SDK: Automated Flash Programming with Python

Aug 18, 2020

The Cyclone Control SDK is a software development kit with a comprehensive API that allows developers to seamlessly integrate Cyclone LC and Cyclone FX programmers into their applications. They can manipulate SAP images, launch SAP images, retrieve programming results, and update settings. This blog post demonstrates the use of the SDK in a Python application.

NOTE: The examples in this blog post are developed in Python. The Cyclone Control SDK also includes interface code and example applications for GCC, Microsoft Visual C, Microsoft Visual C#, Delphi/FPC, Labview, Rust, and Microsoft Visual Basic.

Cyclone Control Suite: Cyclone Control SDK

The Cyclone Control SDK is one of the three main components of the Cyclone Control Suite.

The Cyclone LC and Cyclone FX user manuals contain detailed descriptions of the Cyclone Control SDK application programming interface.

Contents

What files are provided?

Introduction to the Python interface

Example - Connecting to a Cyclone

Example - Managing SAP Images

Example - Launching a SAP Image

Example - Gang Operation of Multiple Cyclones

Example - Serial Numbers and other Dynamic Data

Example - Reading and Writing Properties

Using api_example.py

Cyclone Control SDK and Licensing

Conclusion

-----------------------------------------------------------------------------------------------------------------

What files are provided?

The following files are provided by the Cyclone Control SDK as part of the Cyclone installation software.

  • Python interface (cycloneControlSDK.py)
  • Interface constants (cycloneControlSDKConstants.py)
  • Example application (api_example.py)

The source has also been uploaded to GitHub but the most up to date version will be in the Cyclone installation software. 

Introduction to the Python interface

This article assumes that the reader is already familiar with the process of creating stand alone programming (SAP) images. If not, the reader should please refer to the Image Creation Utility section of the Cyclone user manual.

The Python interface and example application are developed using 32-bit Python 3.6.3. The example application is currently Windows-only. Support for 64-bit Python, Linux, and MacOS will be added in the future.

The application loads the cycloneControlSDK.dll in the following section of code within the cycloneControlSDK class.


Each function of the DLL is set up as a member of the cycloneControlSDK class. The user can create a cycloneControlSDK object to load the DLL and to gain access to its exported functions.

cycloneControlSDKObj = cycloneControlSDK()

As functions are a member of the class, you can access each function with the syntax cycloneControlSDKObj.function_name after the DLL is successfully loaded. 

The first step is to scan and initialize all the Cyclones that are connected to your ports.

cycloneControlSDKObj.enumerateAllPorts()

Then it is possible to connect to a Cyclone to erase SAP images, add SAP images, start programming, retrieve error codes, and to perform any other functionality provided by the SDK. When the program is complete, the DLL can be unloaded from memory.

cycloneControlSDKObj.unloadLibrary()

Example - Connecting to a Cyclone

The user can connect to a Cyclone to get a handle using the connectToCyclone() function. A typical way to do this is to connect to it by its name ("Fixture1Cyclone1").

handle = cycloneControlSDKObj.connectToCyclone("Fixture1Cyclone1")

The handle of the Cyclone identifies the Cyclone in all subsequent function calls. The Cyclone can also be opened by its port number, also known as port identifier, ("USB1", "ETHERNET1", or "COM1") or the IP address ("192.168.1.10") of the Cyclone if the connection is Ethernet. There is no guarantee that a Cyclone will always enumerate with the same port number. When managing multiple units, we recommend identifying them by name or IP address.

Example - Launching a SAP Image

For this example, the user will connect to a Cyclone and execute a SAP image that has been configured with the Image Creation utility.

  1. Open the desired Cyclone by specifying its name (“Fixture1Cyclone1”).
  2. Send a command to the Cyclone to begin the programming operations specified in image with ID# 1.
  3. Wait for the Cyclone to complete the programming operations before proceeding.
  4. Check to see if any errors occurred during programming and display the error code.
  5. Terminate connection to Cyclone.

 Example - Managing SAP Images

For this example, the user will connect to a Cyclone and add a SAP image that has been configured with the Image Creation utility

  1. Open the desired Cyclone by specifying its name (“Fixture1Cyclone1”).
  2. Compare the SAP file ("C:\PEmicro\cyclone\workspace\KL25Z128.SAP") with image ID# 1.
  3. If the image is different, erase image ID#1.
  4. Add the new image to the Cyclone.
  5. Check to see if any errors occurred while adding the image and display the error code.

Example - Gang Operation of Multiple Cyclones

The discussion has been on how to control a single Cyclone up to this point. Since the host PC only sends a minimal amount of control data, it is capable of controlling multiple Cyclones simultaneously.

For this example, the user will connect to 3 separate Cyclone units. The same SAP image (although they could be different) is added to each Cyclone and then programming is started simultaneously. The while loop waits for their completion before proceeding to check for errors. In essence, you are programming 3 separate devices in parallel. This will work if the 3 Cyclones are connected on a mix of different ports, and the setup can be extended to up to 100 Cyclones on a network. 

Example - Serial Numbers and other Dynamic Data

The SDK can also program dynamic data such as serial numbers, manufacturing dates, encryption keys, etc. after the static data has been programmed by the SAP image. In this example, the application calls the startDynamicDataProgram() function to program a 3 byte serial number.

There are three placeholder functions that are used to simplify the example but are not provided by the SDK - getSerialNumberFromFile(), incrementSerialNumber(), and saveSerialNumberToFile(). Similar to the first example, the application connects to one Cyclone and executes a SAP image. After the programming is finished, the error code is checked. Then a serial number list is created with getSerialNumberFromFile(). The list is turned into a string to pass to startDynamicDataProgram() and programmed to address 0x2100 of the target. The serial number is then incremented and written back to the file.

  1. Open the desired Cyclone by specifying its name (“Fixture1Cyclone1”). 
  2. Send a command to the Cyclone to begin the programming operations specified in image with ID# 1.
  3. Wait for the Cyclone to complete the programming operations before proceeding.
  4. Check to see if any errors occurred during programming and display the error code.
  5. Retrieve serial number and program dynamic data array.
  6. Check to see if any errors occurred during serialization and display the error code.
  7. Increment and save the new serial number.

Example - Reading and Writing Properties

Your Cyclone and its resident SAP images have settings, configuration, and other information stored as properties. The getPropertyList function returns a list of properties that are available for a category. Properties can be viewed with the getPropertyValue function. Some properties can also be modified with the setPropertyValue function.

In this example, the user will connect to a Cyclone, get a list of CycloneProperties, retrieve the nameProperty, and then change the name of the Cyclone.

Using api_example.py

The api_example.py application shows the usage of the python interface. Many of the typical functions that the user will need are already implemented, such as connecting to a Cyclone, adding a SAP image, retrieving a list of SAP images, launching a SAP image, programming dynamic data, and getting the checksum of a SAP image. The application can be further modified to suit specific needs.

Cyclone Control SDK and Licensing

PEmicro's Cyclone Control SDK is part of the Cyclone Control Suite, which is included as a standard feature with all models of Cyclone. No additional license is required.

Conclusion

Developers have been requesting the ability to control their Cyclones from their Python applications. We anticipate that the addition of this Python interface and project to the Cyclone Control SDK will allow developers to decrease their development time and bring their production online much more quickly.

Tags related to this Blog Post

Cyclone     Cyclone FX     ARM     NXP     Production Programming     Debug