Getting Started with STM32L-Discovery Board
From EdWiki
This article describes about setting up an opensource environment for STMicroelectronics STM32 Cortex-M based Microcontrollers using CodeSourcery toolchain, eclipse, and OpenOCD. In particular, It uses STM32L-Discovery Board and its STM32L1xx_StdPeriph_Driver's Touch Sensing example.
Setting up the ARM Lab
It is Assumed that, youe have setup an Embedded ARM Lab, If not, Please do so before proceeding further.
STM32L-Discovery Blinky Project
Start Eclipse with new workspce. Instead of creating a new project, we will Import an existing Project from the file system. Download STM32L-Discovery Eclipse Project and extract to your home folder. Now Import STM32L-Discovery Blinky Project into the Eclipse workspace
Toolchain Prefix and Path
To make sure that the toolchain Prefix and Path are correct, Select Project > Properties > C/C++ Build > Settings > Cross Settings. The Prefix field is set to arm-none-eabi- and modify the Path field to the folder where you have installed the CodeSourcery toolchain.
/home/USERNAME/MentorGraphics/Sourcery_CodeBench_Lite_for_ARM_EABI
if you have accepted the default installation folder.
Setting Compiler, Assembler and Linker Options
Since we have imported a pre-configured project, various options for compiler, assembler, and linker for Debug Configuration are already set. Then, let's build the project.
Building Project
To Build the Project on demand, click on the Project menu and un-select Build Automatically.
From the main menu, Select Project > Build Project.
If everything goes well, you will see in the console window something like the following:
Build will be completed with some Warning Messages. For the time being we can ignore these warning messages.
GDB, OpenOCD and Eclipse
To use OpenOCD with our projects, we need to do more than just connecting the STM32L-Discovery board to PC through USB cable and then starting the OpenOCD server.
- We need to configure OpenOCD server so that it knows about the adapter(Dongle) and the board(CPU).
- We also need to configure OpenOCD such that it communicates to GDB using Eclipse GUI for flashing the code and debugging.
- The Eclipse GUI environment will also needs to be configured such that both GDB and OpenOCD are integraed with in the IDE
OpenOCD Project Setup
It is assumed that OpenOCD v0.9.0 is compiled and is available in your home folder such as:
/home/USERNAME/openocd-0.9.0-bin
with all the necessary configuration files.
To configure OpenOCD, select Run > External Tools > External Tools Configurations... from the main menu.
In the External Tools Configurations window, enter (browse to the) openocd executable as
- OpenOCD in the Name,
- /home/USERNAME/openocd-0.9.0-bin/openocd in the Location,
- /home/USERNAME/openocd-0.9.0-bin in the Working Directory, and
- -f board/stm32ldiscovery.cfg in the Arguments fields.
Next, Select Common tab in the same External Tools Configurations window and Select Externals Tools to Display in favourite menu as shown in the following screen.
Make sure that Launch in background option is checked.
Next, select Apply followed by Close button.
Configuring the Debugger
To configure the Debugger, select Run > Debug Configurations... from the main menu.
In the Debug Configurations window, select GDB Hardware Debugging from the left pane, and make sure that C/C++ Application, Project and Build Configuration fields are selected properly from the main tab as shown in the following screen.
In the same Debug Configurations window, select Debugger tab. In this window tab, specify :
- /home/USERNAME/CodeSourcery/Sourcery_G++_Lite/bin/arm-none-eabi-gdb as GDB Command,
- Check Use remote target option
- Select Generic TCP/IP for JTAG Device,
- localhost for Host Name and
- 3333 for Port Number as shown in the screen.
Next, Select the Startup tab and enter the following Commands in the text window:
monitor reset init monitor halt monitor flash probe 0 monitor sleep 500 monitor poll on
Next, Select the Common tab and check Debug to Display in favourites menu as shown in the following screen.
That’s it. We have completed the Debug Configurations. Click on Apply followed by Close button to complete the Debug Configurations.
STM32L-Discovery Board
- Check jumper position on the board, JP1 ON, CN3 ON
- Connect the STM32L-Discovery Board to a PC with a Mini-USB cable to power the board. RED LED LD2 (PWR) then lights up.
Running OpenOCD
We have already configured OpenOCD, just select OpenOCD from the External Tools Tool Bar.
Note: OpenOCD will be running in the background, don’t terminate.
Launching the Debugger
To launch the debugger, select the Debug icon from the tool bar.
When we launch the Debugger for the first time, eclipse tries to switch the Perspective from C/C++ to debug, select Remember my decision and click YES.
The Debugger should break at C main function as we have configured it.
Now you can use all the debugging commands like, single step, examine registers, examine data etc.
if Debugger launch gets stuck at "Configuring GDB" then may be 32-bit libncurses library is missing.
To install use following command
sudo apt-get install lib32ncurses5 lib32ncurses5-dev
Resources and References
Sample Projects
- STM32L-Discovery Blinky Eclipse Project
- STM32L-Discovery Current Consuption and TouchSensing Eclipse Project
- STM32L-Discovery Blinky Codelight Project
- Download STM32L-Discovery Blinky & USART Eclipse Projects and unzip. There are 3-Projects (Blinky, StdPeripheral Library and USART), Import all the three Projects into a new eclipse workspace. Select StdPeriph_v1.2.0_Lib Project and Build it first. The other 2-Projects (Blinky and USART) depend upon StdPeriph_v1.2.0_Lib Project.
- You can also clone a codelite STM32L-Discovery Blinky git repository
git clone http://10.114.15.15/stm32l_discovery/blinky.git
Resources
- STM32L1xx Standard Peripherals Library
- STM32L-Discovery Board Documents
- Toolchain for Linux Intel x86 platform
- Eclipse IDE for C/C++ Developers -- Linux 32-bit
- Eclipse IDE for C/C++ Developers -- Linux 64-bit