Difference between revisions of "Nucleo Boards"

From RobolaboWiki
Jump to: navigation, search
 
(87 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
__TOC__
 
__TOC__
  
<h1> Configuring the environment </h1>
+
<!--
 +
<h1> Configuring environment </h1>
 +
<h2> Linux </h2>
 +
<h3> Installing dependencies </h3>
  
<h2> Install Compiler gcc-arm-none-eabi </h2>
+
<h4>Dependencies for compilling </h4>  
 
+
In a command line, execute:
Download last version of GCC ARM Embedded from:
+
https://launchpad.net/gcc-arm-embedded/+download
+
 
+
Untar the compiler:
+
 
<pre>
 
<pre>
tar -xvjf gcc-arm-none-eabi-<VERSION>.tar.bz2
+
sudo apt-get install build-essential gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib
 
</pre>
 
</pre>
  
Copy it to a common place:
+
<h4> Dependencies for flashing the microcontroller </h4>
 
+
In a command line, execute:
 
<pre>
 
<pre>
sudo cp -r gcc-arm-none-eabi-<VERSION> /opt/compilerNucleoST
+
sudo apt-get install git cmake libusb-1.0-0-dev dfu-util
 
</pre>
 
</pre>
  
<h2> Install OpenOCD On-Chip Debugger</h2>
+
<h4> Dependencies for debugging the microcontroller </h4>
 
+
In a command line, execute:
Instal dependencies:
+
 
<pre>
 
<pre>
sudo apt-get install flex bison libgmp3-dev libmpfr-dev libncurses5-dev libmpc-dev autoconf texinfo build-essential \\
+
sudo apt-get install gdb
libftdi-dev libusb-1.0-0-dev libexpat1-dev
+
 
</pre>
 
</pre>
  
Download last version of Openocd from:
+
Moreover, stlink utility is mandatory to debug in a nucleo board.
http://openocd.org/
+
In a command line, execute:
 
+
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 connect to the device:
 
<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>
+
-->
 
+
<h2> Download STMCube </h2>
+
  
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)
+
<h1> STM32CubeIDE </h1>
 +
<h2> Installation </h2>
  
Go:
+
<h3> Linux </h3>
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:
+
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.
  
Untar STM32CubeXX:
+
Unzip the file (e.g. <FILE> = en.st-stm32cubeide_1.0.1_3139_20190612_1256_amd64.deb_bundle)
  
 
<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 <STM32_NUCLEO_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/<STM32_NUCLEO_BOARD>/Examples/GPIO/GPIO_IOToggle/Src hellowWorld/src
+
sudo ./<FILE>.sh
cp -r <STM32_CUBE_FW_ROOTDIR>/Projects/<STM32_NUCLEO_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/<STM32_NUCLEO_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/<STM32_NUCLEO_BOARD>/Templates/SW4STM32/<STM32_NUCLEO_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>
+
  
<!--
+
</pre> </li>
Download Makefile from [[media:makefileNucleoST.make | here ]], rename it as "makefile" and copy it to <HELLOWORLD> dir.
+
  
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> startup_<stm32_nucleo_controller>.c </b> with the name of your startup filename. (e.g. startup_stm32f446xx.s)
 
<li> <b> <STM32_MICROCONTROLLER> </b> with the compilation directive of your microcontroller (e.g. STM32F446xx) found in src/system_stm32xxxx.c
 
<li> <b> <STM32_NUCLEO_BOARD> </b> with the nucleo board name (e.g. STM32F4xx).
 
<li> <b> <stm32_nucleo_board>_it.c </b> with the name of your *_it.c filename in src (e.g. stm32f4xx_it.c)
 
<li> <b> system_<strm32_nucleo_board>.c </b> with the name of your system_*.c filename in src (e.g. system_stm32f4xx.c)
 
<li> <b> <STM32_LNKER_FILE> </b> with the name of the linker file in <HELLOWORLD> dir (e.g. STM32F446RETx_FLASH.ld)
 
 
</ul>
 
</ul>
  
After this, everything should be ready.
+
<h2> Problems with STM32CUBEIDE </h2>
Compile with <b> make </b> and copy the bin/<FILE>.bin to the disc that is created when the board is connected to the PC.
+
<h3> sprintf %f </h3>
-->
+
 
+
Download [[media:makefileNucleoST2.make | <i> Makefile</i>]], rename it as "Makefile" and copy it to <HELLOWORLD> dir.
+
  
Open makefile and substitute:
+
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:
  
 
<ul>
 
<ul>
<li> <b> <PROJECT_NAME> </b> with the name you want to give to your project
+
<li> Remove heapX.c form Middlewares->Thirs_Party->FreeRTOS->Source->CMSIS_RTOS_V2->portable->MemMang->heap_X.c </li>
<li> <b> <STM32_NUCLEO_BOARD> </b> with the nucleo board name (e.g. STM32F4xx).
+
<li> Add this file to the Src directory: [[media:heap_useNewlib.txt | heap_useNewlib]] and rename it as heap_useNewlib.c</li>
<li> <b> <STM32_LNKER_FILE> </b> with the name of the linker file in <HELLOWORLD> dir (e.g. STM32F446RETx_FLASH.ld)
+
<li> Comment _sbrk function on sysmem.c file; it is already implemented on heap_useNewlib.c </li>
<li> <b> <STM32_MICROCONTROLLER> </b> with the compilation directive of your microcontroller (e.g. STM32F446xx) found in src/system_stm32xxxx.c
+
<li> Include in FreeRTOSConfig.h the folowing directive: </li>
<li> <b> <CPU_INFO> </b> with the mcpu of the controller (e.g. cortex-m0plus)
+
<pre>
<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).
+
#define configUSE_NEWLIB_REENTRANT 1
 +
</pre>
 +
<li> Go to Project -> Porperties -> MCU Settings -> Tool Settings and select float for printf and scanf from newlib-nano </li>
 
</ul>
 
</ul>
  
After this, everything should be ready:
+
<h3> IDE Flickering </h3>
 +
 
 +
First check the value of GTK_IM_MODULE in your environment by executing
  
Export you <i>PATH</i>
 
 
<pre>
 
<pre>
source env.sh
+
echo $GTK_IM_MODULE
 
</pre>
 
</pre>
  
Compile:
+
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>
make
+
export GTK_IM_MODULE="ibus"
 
</pre>
 
</pre>
  
Copy the bin/<FILE>.bin to the disc that is created when the board is connected to the PC.
+
Now if you launch Eclipse from the same terminal session, you should not experience any flickering issue.
An LED should be blinking.
+
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:
  
<b> NOTE </b> It is interesting to clean the project before submitting to any repository.
+
<pre>
<i> lib </i> dir is full of unusfull information:
+
env GTK_IM_MODULE=ibus
<ul>
+
</pre>
<li> In <i> lib/BSP </i> keep only the dir that refers to your board
+
 
<li> In <i> lib/CMSIS </i> keep only the <i> Device </i> and <i> Include </i> dirs
+
E.g. Exec=env GTK_IM_MODULE=ibus /opt/st/stm32cubeide_1.6.1/stm32cubeide %F
<li< In <i> lib/HAL_DRIVER <i> dir, keep  only the <i> Inc </i> and <i> Src </i> dirs.
+
</ul>
+

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