STM32

SimplePublish for NUCLEO-L053R8

The QSL includes a SimplePublish example for the STMicroelectronics NUCLEO-L053R8 development board. This is given as a project for the Eclipse/GCC based System Workbench for STM32, where STM32CubeMX has been used to generate the necessary Hardware Abstraction Layer (HAL) code.

The application behaves just like SimplePublish for the other platforms, and like the example for SAM C21; debug prints are re-targeted through a second serial port. A green LED on the Nucleo board is also toggled to indicate whether the mote has connected to a network or not.

The example was developed on System Workbench for STM32 v1.8 with STM32CubeMX version 4.16.0

Download System Workbench

Go to the OpenSTM32 community webpage and download the System Workbench for STM32. The IDE is free and available for all platforms that support Eclipse, but you will have to register and validate a user to get access to the download and accompanying installation instructions. The standard installation should include any necessary drivers for the integrated ST-LINK/V2-1 debugger.

Make sure to check your spam filter if you don't receive a validation email after registering.


Prepare the NUCLEO-L053R8

Connect to Mote

Figure 7: Mote connected to the NUCLEO-L053R8.

The extension connectors of the NUCLEO-L053R8 is pictured in Figure 8, with the relevant pins marked. As you can see, there are both a set of Morpho and Arduino connectors. Connect the mote to the Nucleo board as per the mapping in Table 12, either through the CN7 and CN10 headers (Table 10 and Table 11) or the corresponding pins on the Arduino headers. Note that you can of course just connect the RX RTSn and TX CTSn to GND on the mote itself, as can be seen in the example in Figure 7.

Long cables between the mote and Xplained Pro may corrupt the API bus communication.

Note the +5V pin right below the +3V3 pin: You will fry your mote if you mistakenly connect to this!


Figure 8: NUCLEO-L053R8 extension connectors.


NamePin #

Name

PC1012PC11
PC1234PD2
VDD56E5V
BOOT078GND
NC910NC
NC1112IOREF
PA131314RESET
PA141516+3V3
PA151718+5V
GND1920GND
PB72122GND
PC132324VIN
PC142526NC
PC152728PA0
PH02930PA1
PH13132PA4
VLCD3334PB0
PC23536PC1
PC33738PC0

Table 10: NUCLEO-L053R8 CN7 header.

NamePin #

Name

PC912PC8
PB834PC6
PB956PC5
AVDD78U5V
GND910NC
PA51112PA12
PA61314PA11
PA71516PB12
PB61718PB11
PC71920GND
PA92122PB2
PA82324PB1
PB102526PB15
PB42728PB14
PB52930PB13
PB33132AGND
PA103334PC4
PA23536NC
PA33738NC

Table 11: NUCLEO-L053R8 CN10 header.

NUCLEO-L053R8

Mote

+3V3VBAT
GNDGND
PA9RX
PA10TX
GNDRX RTSn
GNDTX CTSn

Table 12: NUCLEO-L053R8 to mote pin mapping.

Connect a USB cable from your computer to the USB-mini B port labeled CN1: This is the port at the top of the NUCLEO-L053R8 (visible on the right side of Figure 7), which connects the integrated ST-LINK/V2-1 debugger to your computer, and is used to power, program and debug the board.

ST-LINK also spawns a serial port that we will open a terminal on to see debug prints, so you need to find its identity:

  • Windows: Look for a virtual COM port named STMicroelectronics STLink in the Device Manager (e.g. COM6 in the example below).
     
  • Mac OS X: Use the command ls /dev/tty.usbmodem*
  • Linux: Use the command ls /dev/ttyACM*

Open Debug Terminal

The SimplePublish example code will send all standard output (e.g. debug prints) through the serial port you identified in the previous section. Open your favourite serial terminal (e.g. Putty or Minicom) and connect to said serial port with the following configuration:

  • Baudrate: 115200
  • Data Bits: 8
  • Parity: None
  • Stop Bits: 1

You can (de)activate debug and log messages with the NDEBUG and NLOG defines in dn_debug.h (located in sm_qsl/).

Console Output Issue

The output from the debug terminal has been shown to periodically stop working on Windows (although this does not affect execution of the application itself). Disconnecting and reconnecting the ST-LINK USB seem to make it work again (although this will of course reset both the Nucleo board and connected mote). If you still don't see any output when you should you can try the following:

Compile and Run

Open Workspace

Start up the System Workbench for STM32 and browse to examples/nucleo-l053r8/ when promted to select a workspace.

Import Project

  1. File > Import... > General > Existing Projects into Workspace and press Next >.
  2. Select root directory: Click Browse... and navigate to the SimplePublish example: examples/nucleo-l053r8/SimplePublish/
  3. Press OK
  4. Select SimplePublish that appears in the Projects list.
  5. Make sure to leave the option Copy projects into workspace unchecked
  6. Press Finish.

The System Workbench project expects to find the sm_clib and sm_qsl as they appear in the Directory Structure. If you chose the zip download or subversion checkout, the sm_clib/ directory from the separate unzipped folder/svn checkout need to be copied into the QSL repository to achieve the same structure.

By default Eclipse will index unused headers, causing some errors that don't affect compilation. You can remove these by disabling the option in project properties:
Project > Properties > C/C++ General > Indexer > Indexer Options > Index unused headers

Build

Project > Build Project (or press the  icon) to build the project.

Debug/Run

The first time you run the project, you have to select the correct debug configuration:

  1. Run > Debug (F11)
  2. Select Ac6 STM32 C/C++ Application and press OK.
  3. Eclipse should now prompt you to change to a Debug perspective, before starting a debug session.

After this you will be able to debug/run the project with Run > Debug (F11) and Run > Run (Ctrl+F11) (or press the icons: ) without any configuration.

STM32CubeMX and Customization

Other than the files that implement the necessary porting functions (i.e. dn_uart.c, dn_lock.c, dn_endianness.cdn_time.c and dn_watchdog.c), all the platform specific source and header files have been generated with STM32CubeMX. In addition, any user code added to these generated files has been placed between "USER CODE BEGIN xxx" and "USER CODE END xxx" comments, which is left unchanged if you make changes to the STM32CubeMX project and generate new code. Therefore, the STM32CubeMX project files used to generate code for the example has been included in the repository:

  • SimplePublish.ioc - Configuration settings, defining the STM32CubeMX project.
  • .mxproject - Used to track previously generated files and directories.

This means that you can add or change features included in the generated HAL code by simply opening SimplePublish.ioc in STMCubeMX, make the necessary changes and generate new code.

STM32CubeMX is available for Windows, Linux and OS X.

Absolute Path Issue

There are 3 paths saved in the above STM32CubeMX files that are saved as absolute paths:

  • ProjectManager.ToolChainLocation in SimplePublish.ioc
  • HeaderPath and SourcePath in .mxproject

These have been manually changed to relative paths, which allows you to run them from wherever you extracted the repository. However, whenever you use them to generate code, the paths will be resolved back to absolute paths.

Change Toolchain/IDE

If you have a look at the project settings in STM32CubeMX, you will see that you can generate project files for other toolchains than the System Workbench (SW4STM32), e.g.:

  • IAR Embedded Workbench for ARM
  • Keil MDK
  • TrueSTUDIO

Again, this will preserve the user code entered between the "USER CODE BEGIN xxx" and "USER CODE END xxx" comments, but you will have to manually add the files that are not auto-generated:

  • The porting functions: dn_uart.cdn_lock.cdn_endianness.cdn_time.c and dn_watchdog.c
  • The QSL and C Library: sm_qsl and sm_clib

Port to Similar Platforms

Unfortunately, you can not generate code for another platform by changing the STM32CubeMX settings for an existing project. What you can do instead is to create a new STM32CubeMX project, select the platform of your choice and configure the same settings as in the provided project. Other than activating the two USARTs and correctly configuring their parameters, the default settings should do the trick (make sure to also have a look at the project settings before generating code).

After generating the code, libraries and project files, you will again have to add the files that are not auto-generated (see the previous section). You will also have to copy the user code from the auto-generated files in the original project and into the corresponding files in the new project. Auto-generated files with user code in SimplePublish:

  • main.c
  • usart.c/.h
  • stm32l0xx_it.c