Change the world

The ARMmbed online IDE can be accessed by clicking on the Compiler button in the top right of the Developer site.  In this section the layout and operating procedures for the online IDE will be explained briefly.  For a detailed description and more information, go to the Explore mbed page (developer.mbed.org/explore/). 

For this particular explanation we will use the STM32F4-Discovery and therefore would have added the Seeed Arch Max platform to our compiler as described on the Requirements page.

 

IDE Layout

A typical layout for the online IDE is as shown below:

  1. Toolbar

Gives the programmer access to the online IDE’s functions (e.g. New Program, Compile, etc.)

  1. Program Workspace

Lists the programs that you developed before and the one that you are currently working on.  The programs shown here are stored in the cloud and not locally on the computer.

  1. Code window

Here is where you are going to type the code.

  1. Compile output

Provides information about the compiling process and indicates any errors/warnings that there may be.

 

Create a new program

To create a program:

  1. Select New -> New Program

          

  1. Select a hardware platform for your program in the Platform drop box.  If you haven’t added any hardware platforms to your compiler yet, click Cancel and follow the instructions on the Requirements page.
  2. Select a template program from the Template drop box.  It is best to always select the “Blinky LED …” template, as most platforms have this as a default.  If you select and empty program you will have to manually add the mbed library at a later stage.
  3. Enter a name for the program in the Program Name text box.  Refrain from using spaces or special characters (!, %, &, @, etc.) in the name.  Rather use the underscore (_) character or capital letters to separate words in the program name.
  4. Click on the main.cpp source file for your new program in the Program Workspace to open it in the code window.  All programs will have main.cpp source file where the main code will reside.

          

For this example we need to change “LED1” in the code to “PD_15” to flash the correct LED for the STM32F4-Discovery. 

The asterix (*) next to main.cpp in the Program Workspace just indicates that changes has been made to the source file and haven’t been saved yet.  Select Save from the Toolbar to save the program (although it will be saved automatically every time you compile the code).

 

Compiling code

To compile the code:

  1. Select Compile -> Compile or use the short-cut keys Ctrl-D
  2. The Compile output window should indicate that the compilation was a success, otherwise it will show errors/warnings that should be attended to:

          

  1. Note that your internet browser will automatically download a binary (.bin) file to your local computer which is the programming file.  Make sure that you know where the default download folder for your browser is (usually \Downloads).  The name of the program along with the platform used will automatically be used as a filename for the binary file (e.g. My_First_ARCH_MAX.bin).

Depending on your browser, every time you compile code it will a) either replace the previous downloaded binary file completely, or b) attach an incrementing number in brackets to the binary filename (e.g. My_First_ARCH_MAX(1).bin, My_First_ARCH_MAX(4).bin, etc.) of which the highest number is the latest binary file.

 

Programming a device

There are two different methods for programming the device on the hardware platform based on the ST-LINK hardware available:

 

ST-LINK/V2-1 based platforms (e.g. STM32F746NG-Discovery)

  1. Open your internet browser’s default download folder (usually \Downloads) and drag the required .bin programming file to the hardware platform “drive” that was created when the platform was connected to a USB port.
  2. Depending on the browser used, you can also drag the binary file directly from the browser’s downloaded files bar without opening the default download folder.
  3. The programming LED on platform will flash a few times and then the board will reset to make the new source code take effect.

 

ST-LINK/V2 based platforms (e.g. STM32F4-Discovery, STM32F429I-Discovery, etc.)

  1. Open the STM32 ST-Link Utility application.

          

  1. Select File -> Open file and select the binary file from the browser’s default download folder and click Open.

          

  1. Select Target -> Program and then click Start.  The status area will indicate if it was programmed successfully:

          

  1. Unfortunately steps 2 to 3 needs to be repeated for every new compilation of the same program.  The ST-LINK Utility does not automatically “reload” the current binary file with the newer compiled version. 

 

Working in the Program Workspace

The Program Workspace lists all your programs that are currently stored in the cloud.  The following can be done:

  • You can expand (click on the +) or collapse (click on the -) each of the programs to work on it or to make the workspace a bit more organized.
  • Rename a program or source file (not the main.cpp!) by right-clicking on the program name\source file and selecting Rename.
  • Delete a program or source file from the program list by right-clicking on it and selecting Delete.  Just keep in mind that this will remove a program from the cloud storage and you will have to export it to your local computer to permanantly keep it.

 

Changing the hardware platform for a program

All your programs that use only the mbed library will be hardware platform independent which means you can change the platform for any of your programs without chaning the code.  You might just have to change pin names in the code to adapt to the new platform's pin layout.

If additional libraries are used in your program (e.g. LCD drivers etc.), you just have to read the API documentation for that library to see how you can make it compatible with the new platform.  Here at Nelson Mandela University we will write libraries in such a way to make sure that they can be ported between any of the STM32 Discovery boards that we support.

To change the hardware platform for program:

  1. Click on the current platform's name in the top right corner.

          

  1. Select the new platform from the list of platforms that you added before to your compiler (as explained on the Requirements page) and click on Select Platform.

          

  1. Make the necessary code changes to make the program compatible with new platform.  We used the DISCO-F429ZI (which is the STM32F429I-Discovery) in this example and from the User Manual we can see that there is no LED on PD15, but on PG13 or PG14.

          

  1. Once the changes are made, you can carry on and compile, program and develop code as before.

 

Loading my other programs

With the ARMmbed online IDE all programs listed in the Program Workspace can be seen as being "loaded".  When you compile code it only compiles the program for the current selected main.cpp file.  

You can use the (+) and (-) to expand and collapse the folders to open the main.cpp for other programs which you might want to compile and run from the Program Workspace.

 

Exporting my programs

All the programs in the Program Workspace is stored in the cloud, which means that they are not stored offline on a local computer.  To store a program on a local computer or external drive, you can:

  1. Right-click on the program name (not main.cpp) you wish to store and select Export Program.

          

  1. Select Zip Archive from the Export Toolchain drop box and click Export.

          

The internet browser will then download a .zip file to the default download folder which contains all the source files and support files required by the ARMmbed compiler.  You can then archive this file for later use.

If the Program Workspace becomes too cluttered, you can always export some of the programs, save them on a local computer or external drive, and then delete them from the Program Workspace.

 

Importing a program from a local computer

If you want to add a program to the Program Workspace that you previously stored as .zip on the local computer, you can:

  1. Click on Import on the Toolbar.
  2. Select the Upload tab on the Import Wizard page and click on Choose File at the bottom of the page.

          

  1. Select the .zip file from the local computer for the program that you want to import and click Open.
  2. Click the Import! button in the top right of the Import Wizard page.
  3. You can change the name of the program in the next window, or do it at a later stage as explained before.  Click Import.

          

The program will now be part of the Program Workspace and will be uploaded to the cloud again.

 

Importing libraries

Often you will need to use libraries for sensors, displays, etc. that you want to use in a project.  Rather than having to design these libraries yourself, you can go and search among the user and vendor libraries that are available from the ARMmbed community.  

As an example we will add a library to use the Serial Wire Viewer (SWO library) with our My_first program for the STM32F4-Discovery.  The principle of the SWO will be explained in later examples.

To import a library to use with a program:

  1. Click on Import on the Toolbar.
  2. Select the Libraries tab on the Import Wizard, type a description for the library you are searching for ("serial wire viewer" in this example) and click on Search.

  1. A few results for the search will then be displayed (in our example there is only one result).  Select the library by clicking on the library in the name field.  Information regarding the library is displayed on the right.  You can even go the the homepage for the library where more information on how to use it will be given.  We won't need that for this example.  Click the Import! button in the top right of the Import Wizard page.

  1. Select the program name for which the library must be imported and click Import.

 

The library will consist of a .h file and a .cpp file which will be grouped under the program folder in the Program Workspace.  You can collapse (-) this folder to make it less cluttered.  You will then have to include the library in your main.cpp code by using the #include directive (in our example: #include "SWO.h") and start using the library in your code.  Note the changes to our My_First program indicated with red dots.