First steps with my Nucleo-F401RE

Hi folks,

today I wanna share my first experiences with my new gadget, a STM32 Nucleo-F401RE (www.st.com/stm32nucleo). I got mine when I visited Embedded World exhibition in Nürnberg this year, but you can order one online for about 10€, e.g. from http://www.watterott.com/de/NUCLEO-F401RE

In this post I share how I got started and how to get a first “Hello World” program running.

Nucleo-F401RE with mbed online IDE

Nucleo-F401RE with mbed online IDE

Since the Nucleo board is advertised with “mbed enabled”, I thought let’s check that. So I visited http://mbed.org.

Starting with Windows

First, I started using Windows, because while checking the Nucleo web page I found the recommendation to update the firmware of the chip to the latest version using some Windows based flashing tool (http://mbed.org/platforms/ST-Nucleo-F401RE/). Scroll down to the point “Firmware update required”, follow the link and the instructions, it is really easy and straight forward.

Next, using the online compiler of mbed, you need to register on the mbed web page (http://mbed.org), find the “Sign in / Register” button in the top right corner. After registration you find “Compiler” in the top right corner of your browser, which brings you to a web based IDE to write source code for your development board. In order to write source code for the Nucleo board, you have to add the board to the compiler environment. Visit the boards web page (http://mbed.org/platforms/ST-Nucleo-F401RE/) and klick on “Add to Compiler” on the right side. If you switch now to the Compiler page, you can create a new project with “New” in the top left corner and in the pop up window you can select supported platforms (ST Nucleo F401RE). You can start from scratch or select one of the many already available templates to start with.

I selected the template “Display a message on PC using UART”. Click “Compile” and you are offered to download a “Nucleo_p.bin” file. Connect your Nucleo board with USB to your PC and a USB flash storage device is detected. Copy the “Nucleo_p.bin” file to this USB storage. Now you need to open a serial terminal software like HTerm (http://www.heise.de/download/hterm.html), select the COM port your Nucleo has been assigned to (check your Windows “Device manager”, select “Ports”), baud rate is 9600 and click “Connect”.

Now press the RESET button on your board and you should see a first message (“Hello World”) appearing in the HTerm software.

I found the function “wait(float sec)” seems to be broken or at least buggy, because no further messages are printed. Therefore, I replaced “wait(1)” by “wait_ms(1000)”, which seems to work as expected.

UPDATE:

Fix: you need to update the mbed library in the online compiler. I first hat rev 78 and after updating to the latest rev (rev 83) the wait function works as expected (http://mbed.org/forum/platform-34-ST-Nucleo-F401RE-community/post/24351/)

The source of my first application looks like this:

#include "mbed.h"
//------------------------------------
// Hyperterminal configuration
// 9600 bauds, 8-bit data, no parity
//------------------------------------

Serial pc(SERIAL_TX, SERIAL_RX);

DigitalOut myled(LED1);
int main() {
  int i = 1;
  pc.printf("Hello World !\n");
  while(1) {
    wait_ms(1000);
    pc.printf("This program runs since %d seconds.\n", i++);
    myled = !myled;
  }
}

Next, I wanted to try out the buttons, and created a new project based on the template “Read the board user button state”. I changed the source so output on the serial terminal is generated, reporting if the button is pressed or not.
The source looks like this:

#include "mbed.h"
//------------------------------------
// Hyperterminal configuration
// 9600 bauds, 8-bit data, no parity
//------------------------------------

DigitalIn mybutton(USER_BUTTON);
Serial pc(SERIAL_TX, SERIAL_RX);

int main() {
  pc.printf("Hello World !\n");

  while(true) {
    if (mybutton == 0) { // Button is pressed
      pc.printf("button pressed\n");
    } else {
      pc.printf("button released\n");
    }
    wait_ms(200); // 200 ms
  }
}

After compiling and copying the “Nucleo_r.bin” file to the USB storage partition of the Nucleo, I received the button state in the HTerm serial terminal.

Moving to Linux

Since I usually work with Linux, I wanna move this all to Linux. The web based IDE is also usable in Firefox in Linux, great, and it generates the same *.bin files and offers them to download. Connecting the Nucleo using USB to Linux mounts to USB storage partition. Copy the *.bin file of the web IDE to this storage like on Windows. As serial terminal you can use microcom (sudo microcom -p /dev/ttyACM0 -s 9600). Here it is important to check how your Nucleo is register as device. Check /dev folder for ttyUSB and ttyACM. Like any other Arduino platform it is very likely that your Nucleo is registered as ttyACM0

I hope this was useful for you. If you also have such a board and any further advice for me, let me know 🙂

Advertisements

4 thoughts on “First steps with my Nucleo-F401RE

  1. Hi,

    I’m having big trouble copying bin file (downloaded from mbed compiler) to this board on either Ubuntu 14.04 or Fedora 20. The board is has been updated with latest firmware on a Windows machine. On Linux, it’s detected as a mass storage device. However, when a bin file is copied to it, the LD1 flashing red and green then stays on green. Nothing happens after than, even when unpluging and re-plugging the USB cable.
    This is very stressing me out. I only have Windows 7 running as a VM on my Linux box, so using a Windows machine for developing this board is out of question for me.

    Did you have this problem too? My board is rev C.

    Thanks.

    • Hello there,
      yes, I also had problems in the beginning. After some time I figured out, that the wait function I used was buggy. I used version 73 and after upgrading to version 83 (or latest) it worked as expected. In order to upgrade, open the online compiler and select “mbed” point in your project tree on the left. The on the very right you find the option “update” next to “revisions”, “Homepage” and “Ask a question”.
      for further information you can also have a look on this thread: https://mbed.org/forum/platform-34-ST-Nucleo-F401RE-community/post/24351/
      So, I hope this helps … have fun 🙂

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