STM32 Nucleo Hello World…Part 2

So after successfully managing to get a simple hello work program up and running on my new STM32 Nucleo development board using mbed I decided I would try some of the other tool chains available. Don’t get me wrong mbed is an awesome platform and offers some really great features but when it comes to development I want to get down and dirty with the micro controller and mbed doesn’t offer that flexibility.

There are a number of other tool chains that support the nucleo boards including IAR Embedded Workbench for ARM from IAR Systems,  Microcontroller Development Kit for ARM from Keil and TrueSTUDIO from Atollic. Not sure about TrueSTUDIO but both EWARM and MDK-ARM are available as free 32K code limited versions. This should be more than enough for modest developments. There are other limitations. I don’t think the limited version of EWARM offers any optimization for instance but I can live with that.

Because I use IAR Embedded Workbench a lot at work (not the ARM version I might add) I decided to try out the Keil MDK-ARM tool chain to see how it compares with the IARs. Below are the steps I took to install it and get the blinky example up and running.

Installing Keil MDK-ARM

  1. Firstly download and install the latest version of MDK-ARM from here. You will need to fill in a few details before downloading but you wont need to apply for a evaluation license.
  2. After the installation has completed launch the newly installed Keil uVision IDE.
  3. Next you need to make sure the middle ware and other packages are up to date. Go to the “Project” menu, select “Manage” and then “Pack Installer”.
  4. Select the “Boards” tab on the right hand side and highlight the “NUCLEO-F401RE” board.
  5. A list of available packs should now appear on the left hand side.
  6. To update the packs click on the install button in the “Action” column of each pack in turn. Ensure the following are up to date. “ARM::CMSIS”, “Keil::MDK-Middleware”, “Keil::STM32F4xx_DFP” and “Keil::STM32NUCLEO_BSP”.
    keil_mdk2
  7. When complete close the pack installer.

Install the STLink USB driver

If you haven’t already done so you will need to download and install the STLink/V2-1 USB drivers from here.

Upgrade STLink

Although not essential its probably a good idea to update the STLink firmware on the STM32 Nucleo board to the latest version by downloading and running the STLink upgrade tool here.

  1. Connect your STM32 Nucleo board to your PC via the USB connector CN1.
  2. Run ST-LinkUpgrade.exe.
  3. Press the “Device Connect” button to connect to your STM32 Nucleo board.
  4. The current firmware version should be displayed and if older than the latest version the message “Upgrade the firmware to VX.XXX.XX” should be shown.stlink_upgrade
  5. Click “Yes>>>>” to perform the upgrade.

Copy the Blinky example

  1. Open the Keil uVision IDE and go to the “Project” menu, select “Manage” and then “Pack Installer”.
  2. Select the “Boards” tab on the right hand side and highlight the “NUCLEO-F401RE” board.
  3. Select the “Examples” tab on the left hand side. The “Blinky” example should appear.
  4. Under the action tab click “Copy” to copy the blinky example project. You will need to provide a path to the destination folder.Blinky
  5. Uncheck the option “Launch uVision” to avoid relaunching the IDE since it is already open.
  6. Press the “OK” button and then close the pack installer.
  7. Open the example project by going to the “Project” menu, select “Open Project…” and navigating to your destination folder. Navigate to the “Blinky” project.
  8. Select and open the Keil uVision project file “Blinky.uvprojx”.
  9. The project will be opened and the “Project” pane on the left hand side should show all of the individual files grouped into folders.Blinky_Project
  10. Go to the “Project” menu and select “Rebuild all targets… ” to build the project. Assuming everything is set up correctly this should build with no errors and no warnings.
  11. Connect your STM32 Nucleo board to your PC via the USB connector CN1.
  12. Go to the “Debug” menu and select “Start/Stop Debug Session”. The generated image will now be programmed to the board.
  13. The debugger will now break at the start of the program (the first instruction in main()  which in this case is initialise the variable num with -1).
  14. Press F5 to start execution. LED “LD2” on the STM32 Nucleo board should start flashing. Using a terminal program connected to the enumerated COM port at 115200 you should also see the phrase “Hello World” being continually output.

So my first outing with the Keil MDK-ARM tool chain has been a success. First impressions of the IDE are very good. Well laid out and reasonably intuitive. However only once you start using a tool in anger do you start to realise its strengths and weaknesses so I guess only time will tell.

Advertisements

3 thoughts on “STM32 Nucleo Hello World…Part 2

  1. Simon Burkhardt

    This worked like a charm, thank you so much!
    I only worked with Arduino and Microchip PIC so far. Now I’ve been assigned a project using STM32 Microcontrollers. Gladly I had this Nucleo board lying around, and thanks to this tutorial I can now mess around with it in a “real” offline IDE.

    Reply
  2. Alex Stavin

    Hi Mike, thank you for the tutorial. Before finding your post, I watched an STM32 tutorial using a different board and decided to get it. How different is the code for the stm32 keil getting started? My board has the STM32F0 controller.

    Thanks,
    Alex

    Reply
    1. mikesmodz Post author

      Hi Alex, I don’t own that board and I haven’t seen your code but I can’t imagine it will be much different. The project I generated was for an F4 device whereas you have been using an F0. They are both using the CMSIS library so your only working with the abstraction layer. In my tutorial I used the example project which generates code to toggle the LED whereas you would have had to add the code to toggle the pins yourself.

      Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s