Difference between revisions of "Nucleo Boards"

From RobolaboWiki
Jump to: navigation, search
 
(47 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
__TOC__
 
__TOC__
  
<h1> Configuring the environment </h1>
+
<!--
 
+
<h1> Configuring environment </h1>
<h2> Install Compiler gcc-arm-none-eabi </h2>
+
<h2> Linux </h2>
 
+
<h3> Installing dependencies </h3>
Install the following libraries:
+
  
 +
<h4>Dependencies for compilling </h4>
 +
In a command line, execute:
 
<pre>
 
<pre>
sudo apt-get install lib32z1 lib32ncurses5 lib32bz2-1.0
+
sudo apt-get install build-essential gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib
 
</pre>
 
</pre>
  
Download last version of GCC ARM Embedded from:
+
<h4> Dependencies for flashing the microcontroller </h4>
https://launchpad.net/gcc-arm-embedded/+download
+
In a command line, execute:
 
+
Untar the compiler:
+
 
<pre>
 
<pre>
tar -xvjf gcc-arm-none-eabi-<VERSION>.tar.bz2
+
sudo apt-get install git cmake libusb-1.0-0-dev dfu-util
 
</pre>
 
</pre>
  
Copy it to a common place:
+
<h4> Dependencies for debugging the microcontroller </h4>
 
+
In a command line, execute:
 
<pre>
 
<pre>
sudo cp -r gcc-arm-none-eabi-<VERSION> /opt/compilerNucleoST
+
sudo apt-get install gdb
 
</pre>
 
</pre>
  
<h2> Install OpenOCD On-Chip Debugger</h2>
+
Moreover, stlink utility is mandatory to debug in a nucleo board.
 
+
In a command line, execute:
Instal dependencies:
+
<pre>
+
sudo apt-get install flex bison libgmp3-dev libmpfr-dev libncurses5-dev libmpc-dev autoconf texinfo build-essential \\
+
libftdi-dev libusb-1.0-0-dev libexpat1-dev
+
</pre>
+
 
+
Download last version of Openocd from:
+
http://openocd.org/
+
 
+
Untar openocd:
+
<pre>
+
tar -xvzf openocd-<VERSION>.tar.gz
+
</pre>
+
 
+
Go into the directory:
+
<pre>
+
cd openocd-<VERSION>
+
</pre>
+
 
+
Configure openocd compilation:
+
<pre>
+
./configure --prefix=/opt/openocdNucleoST --enable-maintainer-mode --enable-stlink
+
</pre>
+
 
+
Compile it:
+
 
<pre>
 
<pre>
 +
git clone https://github.com/texane/stlink.git
 +
cd stlink
 
make
 
make
</pre>
+
cd build/Release
 
+
Install:
+
<pre>
+
 
sudo make install
 
sudo make install
 
</pre>
 
</pre>
  
Prepare its use according to udev:
+
<h3> References </h3>
<pre>
+
https://nebkelectronics.wordpress.com/2016/12/19/the-stm32cube-library-part-1-toolchain/ <br>
sudo cp -r contrib/99-openocd.rules /etc/udev/rules.d/
+
https://nebkelectronics.wordpress.com/2016/12/24/stm32cube-library-part-2-hello-world/ <br>
sudo udevadm control --reload-rules
+
https://nebkelectronics.wordpress.com/2017/10/08/stm32cube-library-part-3-compiling/
</pre>
+
  
In order to run openocd as a non root user, you must to add your user name to plugdev group.
 
<ul>
 
<li> Edit /etc/group </li>
 
<li> Find plugdev </li>
 
<li> Add your user after the colon symbol (e.g. plugdev:x:46:user1), or after the last user by adding a coma in between (e.g. plugdev:x:46:user1,user2,user3)
 
</ul>
 
  
For connection, check in [http://wiki.robolabo.etsit.upm.es/index.php/Nucleo_Boards#GDB_Debug  GDB Section]
+
-->
  
 +
<h1> STM32CubeIDE </h1>
 +
<h2> Installation </h2>
  
<!-- In order to connect to the device:
+
<h3> Linux </h3>
<pre>
+
openocd -s /opt/openocdNucleoST/share/openocd/scripts/ -f openocd.cfg -c "init" -c "halt" -c "reset halt"
+
</pre>
+
where openocd.cfg should be on your working dir. -->
+
  
<h1> Hello World experiment  </h1>
+
Last release of STM32CubeIDE can be obtained here: https://www.st.com/en/development-tools/stm32cubeide.html. <br>
 +
For Debian like distributions (e.g. ubuntu), download the STM32CubeIDE-DEB file. To download it, you will need to provide name and a valid email address.
  
<h2> Download STMCube </h2>
+
Unzip the file (e.g. <FILE> = en.st-stm32cubeide_1.0.1_3139_20190612_1256_amd64.deb_bundle)
 
+
STMicroelectronics introduces STMCube as an initiative to ease developers life. They are sharing packages containing libraries, documentation and examples. Packages are delivered per series (such as STM32CubeF4 for STM32F4 series)
+
 
+
Go to:
+
http://www.st.com/web/catalog/tools/FM147/CL1794/SC961/SS1743/LN1897?icmp=tt2930_gl_pron_oct2015&sc=stm32cube-pr14
+
 
+
and select the STMCubeXX according to your microcontroller (e.g. STM32CubeL4 for STM32L4 series) and load it in a prefered directory:
+
 
+
Untar STM32CubeXX:
+
  
 
<pre>
 
<pre>
unzip stm32cubexx.zip
+
unzip <FILE>.sh.zip
 
</pre>
 
</pre>
  
This will create a Firmware directory which will be referred in this tutorial as <STM32_CUBE_FW_ROOTDIR>.
+
It will generate a .sh file.
 
+
Give it permits for execution.
<h2> Create the experiment </h2>
+
The example is done for a toggle led experiment.
+
It will be compiled for a specific nucleo board, named in this tutoral as <BOARD>.
+
 
+
Create experiment dir in your prefered directory:
+
  
 
<pre>
 
<pre>
mkdir helloWorld
+
chmod 777 <FILE>.sh
mkdir helloWorld/bin
+
 
</pre>
 
</pre>
  
Copy experiment sources:
+
Finally, execute the installation
 
+
 
<pre>
 
<pre>
cp -r <STM32_CUBE_FW_ROOTDIR>/Projects/<BOARD>/Examples/GPIO/GPIO_IOToggle/Src helloWorld/src
+
sudo ./<FILE>.sh
cp -r <STM32_CUBE_FW_ROOTDIR>/Projects/<BOARD>/Examples/GPIO/GPIO_IOToggle/Inc helloWorld/include
+
 
</pre>
 
</pre>
  
Copy STM32 libraries:
+
You must accept all license agreements.
  
<pre>
 
cp -r <STM32_CUBE_FW_ROODIR>/Drivers/ helloWorld/lib
 
</pre>
 
  
Copy startup code to src dir:
+
<h3> Windows </h3>
<pre>
+
cp <STM32_CUBE_FW_ROOTDIR>/Projects/<BOARD>/Templates/SW4STM32/startup_<NUCLEO_BOARD>.s helloWorld/src
+
</pre>
+
  
where <NUCLE_BOARD> refers to your nucleo board model.
+
Last release of STM32CubeIDE can be obtained here: https://www.st.com/en/development-tools/stm32cubeide.html. <br>
 +
For Windows like distributions, download the STM32CubeIDE-Win file. To download it, you will need to provide name and a valid email address.
  
<b> Important</b> If SW4STM32 does not exists use TrueStudio instead.
+
Unzip the file and execute the binary. Follow all steps and accept all conditions.
  
<br>
+
<h3> MAC </h3>
Copy linker file:
+
Last release of STM32CubeIDE can be obtained here: https://www.st.com/en/development-tools/stm32cubeide.html. <br>
 +
For MAC like distributions, download the STM32CubeIDE-MAC file. To download it, you will need to provide name and a valid email address.
  
<pre>
+
Unzip the file and execute the binary. Follow all steps and accept all conditions.
cp <STM32_CUBE_FW_ROOTDIR>/Projects/<BOARD>/Templates/SW4STM32/<BOARD>_Nucleo/<NUCLEO_BOARD>_FLASH.ld helloWorld/
+
</pre>
+
where <NUCLE_BOARD> refers to your nucleo board model.
+
  
<b> Important</b> If TrueStudio does not exists use SW4STM32 instead.
+
<b> IMPORTANT </b> Some problems have been reported related to lasts versions of STM32CubeIDE-MAC, where the code generator does not include macro definitions for the peripheral of nucleo-boards. Last version correctly tested is 1.0.0.
  
<br>
+
<h2> Hello World </h2>
Create an environment file to export PATH:
+
In this Section a Hellow World (led blinking) example will be programmed on a NUCLEO-F446RE board:
<pre>
+
cd helloWorld
+
echo $PATH > env.sh
+
</pre>
+
Edit env.sh and at the begining of the line include:
+
  
 +
<ul>
 +
<li> Open STM32CubeIDE </li>
 +
<li> Select where to store the workspace. This will be the folder where different projects could be stored. </li>
 +
<li> Select <b> Start new STM32 project </b> </li>
 +
<li> A microcontroller or board should be selected. In our case, a NUCLEO-F446RE will be used.
 +
Then, select <b> board selector </b>  and search part number <b> Nucleo-F446RE </b>. Once chosen, press <b> Next </b> </li>
 +
<li> Chose a Project name (e.g. ledp) and keep the rest of parameters as they are. Press <b> Finish </b></li>
 +
<li> The STM32CubeIDE will ask if you want  Initialize all peripherals with their default Mode. Answer <b> Yes </b> </li>
 +
<li> The STM32CubeIDE will inform that yhis kind of projects is associated with the STM32CubeMx prespective and will ask if you want to open this perspective now. Answer <b> Yes </b>. <br>
 +
Download of required libraries will start. It could take long for the first time depending on your connection settings.  </li>
 +
<li> Once the project is open, on the left side on the "Project Explorer", look for <i> Src -> main.c </i>. <br>
 +
Inside the code, look for the <i> while(1) </i> sentence in the <i> main(void) </i> function, and fill it as follows:
 
<pre>
 
<pre>
export PATH=/opt/openocdNucleoST/bin:/opt/compilerNucleoST/bin:
+
while (1)
</pre>
+
{
 +
  HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);
 +
  HAL_Delay(100);
 +
/* USER CODE END WHILE */
  
Your file should look like this:
+
/* USER CODE BEGIN 3 */
<pre>
+
}
export PATH=/opt/openocdNucleoST/bin:/opt/compilerNucleoST/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
+
/* USER CODE END 3 */
</pre>
+
  
Download [[media:makefileNucleoST2.make | <i> Makefile</i>]], rename it as "Makefile" and copy it to <HELLOWORLD> dir.
+
</pre> </li>
  
Open makefile and substitute:
+
<li> In order to compile, Go to <i> Project -> Build All (Ctrl+B or Hammer) </i>. It should compile the code without errors. <br>
 +
If any error appears, previous steps should be reviewed. </li>
 +
<li> In order to start the debugger, Go to <i> Run -> Debug (F11 or bug) </i> <br>
 +
Select STM32 MCU C/C++ Application and Press <b> OK </b> </li>
 +
<li> Leave all configuration propeties as they are and Press <b> OK </b> </li>
 +
<li> The STM32CubeIDE will ask if you want to switch to the debug perspective say <b> Switch </b> </li>
 +
<li> In order to execute the code, Go to <i> Run -> Resume (F8 or Green Arrow) </i>. <br>
 +
The led should be blinking at 100 ms. </li>
  
<ul>
 
<li> <b> <PROJECT_NAME> </b> with the name you want to give to your project
 
<li> <b> <STM32_NUCLEO_BOARD> </b> with the nucleo board name (e.g. STM32F4xx).
 
<li> <b> <STM32_LNKER_FILE> </b> with the name of the linker file in <HELLOWORLD> dir (e.g. STM32F446RETx_FLASH.ld)
 
<li> <b> <STM32_MICROCONTROLLER> </b> with the compilation directive of your specific microcontroller (e.g. STM32L053xx) found in your CMSIS STincludes dir (e.g. lib/CMSIS/Device/ST/STM32L0xx/Include/stm32l0xx.h)
 
<li> <b> <CPU_INFO> </b> with the mcpu of the controller found in <i> src/startup_stm32XXX </i> file near the <i> .cpu </i> directive (e.g. cortex-m0plus)
 
<li> <b> <STARTUP_NAME> </b> with the name of your startup filename. (e.g. startup_stm32f446xx) found in src dir (important: name it without extension).
 
 
</ul>
 
</ul>
  
After this, everything should be ready:
+
<h2> Problems with STM32CUBEIDE </h2>
 +
<h3> sprintf %f </h3>
  
Export you <i>PATH</i>
+
All the information on this page is obtained from: http://www.nadler.com/embedded/newlibAndFreeRTOS.html
<pre>
+
There is some errors on the implementation of malloc on STM32CubeMX, so if using some newlib fuctions (e.g. sprintf %f), the following steps must be implemented:
source env.sh
+
</pre>
+
  
Compile:
 
<pre>
 
make
 
</pre>
 
 
Copy the bin/<FILE>.bin to the disc that is created when the board is connected to the PC.
 
An LED should be blinking.
 
 
<b> NOTE </b> It is interesting to clean the project before submitting to any repository.
 
<i> lib </i> dir is full of unusfull information:
 
 
<ul>
 
<ul>
<li> In <i> lib/BSP </i> keep only the dir that refers to your board
+
<li> Remove heapX.c form Middlewares->Thirs_Party->FreeRTOS->Source->CMSIS_RTOS_V2->portable->MemMang->heap_X.c </li>
<li> In <i> lib/CMSIS </i> keep only the <i> Device </i> and <i> Include </i> dirs
+
<li> Add this file to the Src directory: [[media:heap_useNewlib.txt | heap_useNewlib]] and rename it as heap_useNewlib.c</li>
<li> In <i> lib/HAL_DRIVER </i> dir, keep  only the <i> Inc </i> and <i> Src </i> dirs.
+
<li> Comment _sbrk function on sysmem.c file; it is already implemented on heap_useNewlib.c </li>
</ul>
+
<li> Include in FreeRTOSConfig.h the folowing directive: </li>
 
+
<h1> FreeRTOS Port  </h1>
+
 
+
Before proceed with this section, you should have already implemented the [http://wiki.robolabo.etsit.upm.es/index.php/Nucleo_Boards#Hello_World_experiment previous section]
+
 
+
<h2> Download and prepare sources </h2>
+
 
+
Download last version of FreeRTOS from: http://www.freertos.org/
+
 
+
Unzip it:
+
 
<pre>
 
<pre>
unzip FreeRTOS<VERSION>.zip
+
#define configUSE_NEWLIB_REENTRANT 1
 
</pre>
 
</pre>
 
+
<li> Go to Project -> Porperties -> MCU Settings -> Tool Settings and select float for printf and scanf from newlib-nano </li>
Copy FreeRTOS source to your working dir
+
<pre>
+
cp -r <FREERTOS_DIR>/FreeRTOS/ helloWorld/
+
</pre>
+
 
+
Go in <i> helloworld/FreeRTOS </i> dir and remove all but <i> Source </i> dir
+
 
+
Go in <i> helloworld/FreeRTOS/Source/portable </i> dir and remove all but <i> GCC </i> dir and <i> <MemMag> </i> dir
+
 
+
Go in <i> helloworld/FreeRTOS/Source/portable/GCC </i> dir and remove all but your CPU related (e.g. ARM_C0 for Cortex-M0)
+
 
+
 
+
<h2> Configure FreeRTOS </h2>
+
This is the most complex task, but this manual is not intended for it.
+
 
+
If you have a board already supported by FreeRTOS which is provided in the Demo examples, copy the <i> FreeRTOSConfig.h </i> found in those examples to your <i> helloworld/include </i> dir.
+
 
+
If not, download this [[media:FreeRTOSConfig_STM32L0.h | <i> FreeRTOSConfig.h </i>]], rename it as "FreeRTOSConfig.h", copy it to <i> <HELLOWORLD>/include </i> dir and work on it.
+
 
+
Go in your <i> helloworld/src/stmXXXX_it.c </i> file and comment the <i> SVC_Handler, PendSV_Handler and SysTick_Handler </i> functions
+
 
+
Download [[media:makefileNucleoST2FreeRTOS.make | <i> Makefile</i>]], rename it as "Makefile" and copy it to <HELLOWORLD> dir.
+
 
+
Open makefile and substitute:
+
 
+
<ul>
+
<li> <b> <PROJECT_NAME> </b> with the name you want to give to your project
+
<li> <b> <STM32_NUCLEO_BOARD> </b> with the nucleo board name (e.g. STM32F4xx).
+
<li> <b> <STM32_LNKER_FILE> </b> with the name of the linker file in <HELLOWORLD> dir (e.g. STM32F446RETx_FLASH.ld)
+
<li> <b> <STM32_MICROCONTROLLER> </b> with the compilation directive of your specific microcontroller (e.g. STM32L053xx) found in your CMSIS STincludes dir (e.g. lib/CMSIS/Device/ST/STM32L0xx/Include/stm32l0xx.h)
+
<li> <b> <CPU_INFO> </b> with the mcpu of the controller found in <i> src/startup_stm32XXX </i> file near the <i> .cpu </i> directive (e.g. cortex-m0plus)
+
<li> <b> <STARTUP_NAME> </b> with the name of your startup filename. (e.g. startup_stm32f446xx) found in src dir (important: name it without extension).
+
<li> <b> <RTOS_GCC_CPUINFO> </b> with the name of the mcpu of the controller of the FreeRTOS dir (e.g. ARM_CM0) found in <i> RTOS_SOURCE_DIR/portable/GCC/ </i>
+
 
</ul>
 
</ul>
  
<b> Important </b> If working with Cortex-M4 add the following lines to the CFLAGS definition:
+
<h3> IDE Flickering </h3>
 
+
<pre>
+
-mfpu=fpv4-sp-d16 \
+
mfloat-abi=softfp \
+
</pre>
+
 
+
<h2> Create a Basic Task </h2>
+
 
+
Open your <i> main.c </i>
+
  
Include FreeRTOS libs:
+
First check the value of GTK_IM_MODULE in your environment by executing
  
 
<pre>
 
<pre>
/* Scheduler includes. */
+
echo $GTK_IM_MODULE
#include "FreeRTOS.h"
+
#include "task.h"
+
#include "queue.h"
+
#include "semphr.h"
+
 
</pre>
 
</pre>
  
Define a task and its handler
+
If the output is "xim", Eclipse expects it to be “ibus”.
 +
So enter the following command in a terminal session to set it to the value.
  
 
<pre>
 
<pre>
xTaskHandle ledpTask_Handle;
+
export GTK_IM_MODULE="ibus"
void Ledp_Task();
+
 
</pre>
 
</pre>
  
In the <i>main</i> function, comment the while loop and provide instead the following code to create a task and start the scheduler:
+
Now if you launch Eclipse from the same terminal session, you should not experience any flickering issue.
 +
If you launch eclipse from a desktop menu entry, then edit the .desktop file (e.g.  /usr/share/applications/st-stm32cubeide-1.6.1.desktop) and put the following string in the beginning of the Exec command:
  
 
<pre>
 
<pre>
xTaskCreate(Ledp_Task, "Ledp_Task", 70, NULL, 1, &ledpTask_Handle);
+
env GTK_IM_MODULE=ibus
vTaskStartScheduler();
+
 
</pre>
 
</pre>
  
Create a Task (function) with the following code:
+
E.g. Exec=env GTK_IM_MODULE=ibus /opt/st/stm32cubeide_1.6.1/stm32cubeide %F
<pre>
+
void Ledp_Task (void * pvParams)
+
{
+
  while(1)
+
  {
+
    HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
+
    vTaskDelay(1000);
+
  }
+
}
+
 
+
</pre>
+
 
+
After this, everything should be ready:
+
 
+
Export you <i>PATH</i>
+
<pre>
+
source env.sh
+
</pre>
+
 
+
Compile:
+
<pre>
+
make
+
</pre>
+
 
+
Copy the bin/<FILE>.bin to the disc that is created when the board is connected to the PC.
+
An LED should be blinking.
+
 
+
<h1> GDB Debug </h1>
+
 
+
It is mandatory openocd is installed in your system (see [http://wiki.robolabo.etsit.upm.es/index.php/Nucleo_Boards#Install_OpenOCD_On-Chip_Debugger OpenOCD section])
+
 
+
You need an openocd.cfg file which is related to your board and jtag.
+
 
+
[[media:openocdL0.cfg | <i> Here</i>]] we provide a file with the configuration of an stlink and a STM32L053 mcu:
+
 
+
<pre>
+
source [find interface/stlink-v2-1.cfg]
+
 
+
transport select hla_swd
+
 
+
set WORKAREASIZE 0x2000
+
source [find target/stm32l0.cfg]
+
 
+
reset_config srst_only
+
</pre>
+
 
+
However, find your jtag filename in <i>interface</i> of your openocd sources and your mcu filename on the <i>target</i> dir.
+
 
+
Once the file is configured, load the PATH
+
 
+
<pre>
+
source env.sh
+
</pre>
+
 
+
Connect to your board:
+
 
+
<pre>
+
openocd -s /opt/openocdNucleoST/share/openocd/scripts/ -f openocd.cfg -c "init" -c "halt" -c "reset halt"
+
</pre>
+
 
+
Output should be something similar to:
+
 
+
<pre>
+
Open On-Chip Debugger 0.9.0 (2016-07-05-21:42)
+
Licensed under GNU GPL v2
+
For bug reports, read
+
http://openocd.org/doc/doxygen/bugs.html
+
adapter speed: 300 kHz
+
adapter_nsrst_delay: 100
+
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
+
none separate
+
srst_only separate srst_nogate srst_open_drain connect_deassert_srst
+
Info : Unable to match requested speed 300 kHz, using 240 kHz
+
Info : Unable to match requested speed 300 kHz, using 240 kHz
+
Info : clock speed 240 kHz
+
Info : STLINK v2 JTAG v24 API v2 SWIM v11 VID 0x0483 PID 0x374B
+
Info : using stlink api v2
+
Info : Target voltage: 3.246505
+
Info : stm32l0.cpu: hardware has 4 breakpoints, 2 watchpoints
+
Info : Unable to match requested speed 300 kHz, using 240 kHz
+
Info : Unable to match requested speed 300 kHz, using 240 kHz
+
adapter speed: 240 kHz
+
target state: halted
+
target halted due to debug-request, current mode: Thread
+
xPSR: 0xf1000000 pc: 0x08000244 msp: 0x20002000
+
</pre>
+
 
+
If the terminal gets there and does not return, you are now connected to the board.
+
 
+
Open a new terminal and load the PATH
+
 
+
<pre>
+
source env.sh
+
</pre>
+
 
+
Launch ARM GDB
+
<pre>
+
arm-none-eabi-gdb
+
</pre>
+
 
+
Connect GDB to openocd
+
<pre>
+
target remote :3333
+
</pre>
+
 
+
Reset the board
+
<pre>
+
monitor reset halt
+
</pre>
+
 
+
Import the file
+
<pre>
+
file bin/ledp.elf
+
</pre>
+
 
+
Load the binaries into the mcu
+
 
+
<pre>
+
load
+
</pre>
+
 
+
Reset the board
+
<pre>
+
monitor reset halt
+
</pre>
+
 
+
 
+
Run the board
+
<pre>
+
continue
+
</pre>
+
 
+
The board should be blinking at this point
+
 
+
<h1> Eclipse Environment  </h1>
+
It is mandatory to install the Base Environment first
+
 
+
<h2> Install Eclipse </h2>
+
(More info at: http://help.eclipse.org/mars/index.jsp?topic=%2Forg.eclipse.cdt.doc.user%2Fgetting_started%2Fcdt_w_import.htm)
+
 
+
Download last version of Eclipse IDE for C/C++ Developers from: http://www.eclipse.org/downloads/
+
 
+
Untar eclipse:
+
<pre>
+
tar -xvzf eclipse-cpp-mars-1-linux-gtk-x86_64.tar.gz
+
</pre>
+
 
+
Go into directory and execute eclipse:
+
 
+
<pre>
+
cd eclipse
+
./eclipse
+
</pre>
+
 
+
Define workspace (e.g. /home/<USER>/stm32EclipseWorkspace)
+
 
+
<h3> Install C/C++ Developping tools </h3>
+
 
+
Go to Help -> Install New Sofware -> add <br>
+
- Name: CDT-Mars <br>
+
- Location: http://download.eclipse.org/tools/cdt/releases/8.8 <br>
+
 
+
 
+
- Click Ok <br>
+
- Select: CDT Optional Features -> C/C++ GDB Hardware Debugging <br>
+
- Next, Next, Agree, Finish <br>
+
- Restart <br>
+
 
+
<br>
+
<h3> Install GNU ARM Plugins </h3>
+
 
+
Go to Help -> Install New Sofware -> add <br>
+
- Name: GNU ARM Eclipse Plugins <br>
+
- Location: http://gnuarmeclipse.sourceforge.net/updates <br>
+
 
+
 
+
- Click Ok <br>
+
- Select All <br>
+
- Next, Next, Agree, Finish <br>
+
- You will be asked to accept some specific not known content, do it <br>
+
- Restart <br>
+
 
+
 
+
<h2> Import Project </h2>
+
(More info at: http://gnuarmeclipse.github.io/plugins/install/)
+
 
+
Go to File -> New -> C Project <br>
+
- Name: test <br>
+
- Location: Select where the code is <br>
+
- Project type -> Makefile project -> Empty Project -> Cross ARM GCC <br>
+
 
+
- Next, Next <br>
+
 
+
Toolchain: <br>
+
- Name: GNU Tools for ARM Embedded Processors (arm-none-eabi-gcc) <br>
+
- Path: /opt/compilerNucleoST (if installed as in previous section, if not check where did you do it!!) <br>
+
 
+
- Finish <br>
+
 
+
If everything ok, you are able to compile with the hammer.
+
 
+
<h2> Set OpenOCD </h2>
+
(More info at: https://balau82.wordpress.com/2014/02/23/stm32-p152-development-with-eclipse-on-linux/)
+
 
+
- Run -> External tools -> External Tools Configurations <br>
+
- Program -> New <br>
+
- Location: /opt/openocdNucleoST/bin/openocd (if installed as in previous section, if not check where did you do it!!) <br>
+
- Working Directory: A Dir where there is the openocd.cfg (typically where our porject is) <br>
+
- Arguments: -f openocd.cfg -c "init" -c "halt" -c "reset halt"
+
- Apply
+
 
+
<h2> Set GDB </h2>
+
(More info at: https://pixhawk.org/dev/jtag/gdb_eclipse)
+
 
+
Go to Run -> Debug Configurations <br>
+
Create a GDB Hardware Debugging <br>
+
In Main: <br>
+
- Application: The .elf file that will be generated by the project (e.g. helloWorld.elf) <br>
+
- Project: The project location <br>
+
- Use workspace settings <br>
+
- Select legacy GDB Hardware Debugging Launcher by clinking Select other <br>
+
 
+
In Debugger: <br>
+
- GDB Command: /opt/compilerNucleoST/bin/arm-none-eabi-gdb <br>
+
- Standard(Linux) <br>
+
- Version: mi <br>
+
- Use remote target <br>
+
- JTag: TCP/IP <br>
+
- IP: localhost <br>
+
- Port: 3333 <br>
+
 
+
In Startup: <br>
+
- Un-click Reset and Delay <br>
+
- Un-click Halt <br>
+
- In command box type:  <br>
+
- monitor reset halt <br>
+
- Click Load Image <br>
+
- Click Load symbols <br>
+
- In Run Commands write: <br>
+
- set $pc = Reset_Handler <br>
+
- stepi <br>
+
 
+
Finally click Apply
+

Latest revision as of 11:41, 8 February 2023


STM32CubeIDE

Installation

Linux

Last release of STM32CubeIDE can be obtained here: https://www.st.com/en/development-tools/stm32cubeide.html.
For Debian like distributions (e.g. ubuntu), download the STM32CubeIDE-DEB file. To download it, you will need to provide name and a valid email address.

Unzip the file (e.g. <FILE> = en.st-stm32cubeide_1.0.1_3139_20190612_1256_amd64.deb_bundle)

unzip <FILE>.sh.zip

It will generate a .sh file. Give it permits for execution.

chmod 777 <FILE>.sh

Finally, execute the installation

sudo ./<FILE>.sh

You must accept all license agreements.


Windows

Last release of STM32CubeIDE can be obtained here: https://www.st.com/en/development-tools/stm32cubeide.html.
For Windows like distributions, download the STM32CubeIDE-Win file. To download it, you will need to provide name and a valid email address.

Unzip the file and execute the binary. Follow all steps and accept all conditions.

MAC

Last release of STM32CubeIDE can be obtained here: https://www.st.com/en/development-tools/stm32cubeide.html.
For MAC like distributions, download the STM32CubeIDE-MAC file. To download it, you will need to provide name and a valid email address.

Unzip the file and execute the binary. Follow all steps and accept all conditions.

IMPORTANT Some problems have been reported related to lasts versions of STM32CubeIDE-MAC, where the code generator does not include macro definitions for the peripheral of nucleo-boards. Last version correctly tested is 1.0.0.

Hello World

In this Section a Hellow World (led blinking) example will be programmed on a NUCLEO-F446RE board:

  • Open STM32CubeIDE
  • Select where to store the workspace. This will be the folder where different projects could be stored.
  • Select Start new STM32 project
  • A microcontroller or board should be selected. In our case, a NUCLEO-F446RE will be used. Then, select board selector and search part number Nucleo-F446RE . Once chosen, press Next
  • Chose a Project name (e.g. ledp) and keep the rest of parameters as they are. Press Finish
  • The STM32CubeIDE will ask if you want Initialize all peripherals with their default Mode. Answer Yes
  • The STM32CubeIDE will inform that yhis kind of projects is associated with the STM32CubeMx prespective and will ask if you want to open this perspective now. Answer Yes .
    Download of required libraries will start. It could take long for the first time depending on your connection settings.
  • Once the project is open, on the left side on the "Project Explorer", look for Src -> main.c .
    Inside the code, look for the while(1) sentence in the main(void) function, and fill it as follows:
    while (1)
    {
      HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);
      HAL_Delay(100);
     /* USER CODE END WHILE */
    
     /* USER CODE BEGIN 3 */
    }
    /* USER CODE END 3 */
    
    
  • In order to compile, Go to Project -> Build All (Ctrl+B or Hammer) . It should compile the code without errors.
    If any error appears, previous steps should be reviewed.
  • In order to start the debugger, Go to Run -> Debug (F11 or bug)
    Select STM32 MCU C/C++ Application and Press OK
  • Leave all configuration propeties as they are and Press OK
  • The STM32CubeIDE will ask if you want to switch to the debug perspective say Switch
  • In order to execute the code, Go to Run -> Resume (F8 or Green Arrow) .
    The led should be blinking at 100 ms.

Problems with STM32CUBEIDE

sprintf %f

All the information on this page is obtained from: http://www.nadler.com/embedded/newlibAndFreeRTOS.html There is some errors on the implementation of malloc on STM32CubeMX, so if using some newlib fuctions (e.g. sprintf %f), the following steps must be implemented:

  • Remove heapX.c form Middlewares->Thirs_Party->FreeRTOS->Source->CMSIS_RTOS_V2->portable->MemMang->heap_X.c
  • Add this file to the Src directory: heap_useNewlib and rename it as heap_useNewlib.c
  • Comment _sbrk function on sysmem.c file; it is already implemented on heap_useNewlib.c
  • Include in FreeRTOSConfig.h the folowing directive:
  • #define configUSE_NEWLIB_REENTRANT 1
    
  • Go to Project -> Porperties -> MCU Settings -> Tool Settings and select float for printf and scanf from newlib-nano

IDE Flickering

First check the value of GTK_IM_MODULE in your environment by executing

echo $GTK_IM_MODULE

If the output is "xim", Eclipse expects it to be “ibus”. So enter the following command in a terminal session to set it to the value.

export GTK_IM_MODULE="ibus"

Now if you launch Eclipse from the same terminal session, you should not experience any flickering issue. If you launch eclipse from a desktop menu entry, then edit the .desktop file (e.g. /usr/share/applications/st-stm32cubeide-1.6.1.desktop) and put the following string in the beginning of the Exec command:

env GTK_IM_MODULE=ibus

E.g. Exec=env GTK_IM_MODULE=ibus /opt/st/stm32cubeide_1.6.1/stm32cubeide %F