Difference between revisions of "Nucleo Boards for Control Systems"

From RobolaboWiki
Jump to: navigation, search
(Created page with "__TOC__ <!-- <h1> Configuring environment </h1> <h2> Linux </h2> <h3> Installing dependencies </h3> <h4>Dependencies for compilling </h4> In a command line, execute: <pre>...")
 
(Replaced content with "__TOC__ <!-- <h1> Lectura y escritura de pines </h1> <h2> Encoder </h2> <h3> PWM </h3>")
Line 2: Line 2:
  
 
<!--
 
<!--
<h1> Configuring environment </h1>
+
<h1> Lectura y escritura de pines </h1>
<h2> Linux </h2>
+
<h2> Encoder </h2>
<h3> Installing dependencies </h3>
+
<h3> PWM </h3>
 
+
<h4>Dependencies for compilling </h4>
+
In a command line, execute:
+
<pre>
+
sudo apt-get install build-essential gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib
+
</pre>
+
 
+
<h4> Dependencies for flashing the microcontroller </h4>
+
In a command line, execute:
+
<pre>
+
sudo apt-get install git cmake libusb-1.0-0-dev dfu-util
+
</pre>
+
 
+
<h4> Dependencies for debugging the microcontroller </h4>
+
In a command line, execute:
+
<pre>
+
sudo apt-get install gdb
+
</pre>
+
 
+
Moreover, stlink utility is mandatory to debug in a nucleo board.
+
In a command line, execute:
+
<pre>
+
git clone https://github.com/texane/stlink.git
+
cd stlink
+
make
+
cd build/Release
+
sudo make install
+
</pre>
+
 
+
<h3> References </h3>
+
https://nebkelectronics.wordpress.com/2016/12/19/the-stm32cube-library-part-1-toolchain/ <br>
+
https://nebkelectronics.wordpress.com/2016/12/24/stm32cube-library-part-2-hello-world/ <br>
+
https://nebkelectronics.wordpress.com/2017/10/08/stm32cube-library-part-3-compiling/
+
 
+
 
+
-->
+
 
+
<h1> STM32CubeIDE </h1>
+
<h2> Installation </h2>
+
 
+
<h3> Linux </h3>
+
 
+
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.
+
 
+
Unzip the file (e.g. <FILE> = en.st-stm32cubeide_1.0.1_3139_20190612_1256_amd64.deb_bundle)
+
 
+
<pre>
+
unzip <FILE>.sh.zip
+
</pre>
+
 
+
It will generate a .sh file.
+
Give it permits for execution.
+
 
+
<pre>
+
chmod 777 <FILE>.sh
+
</pre>
+
 
+
Finally, execute the installation
+
<pre>
+
sudo ./<FILE>.sh
+
</pre>
+
 
+
You must accept all license agreements.
+
 
+
 
+
<h3> Windows </h3>
+
 
+
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.
+
 
+
Unzip the file and execute the binary. Follow all steps and accept all conditions.
+
 
+
<h3> MAC </h3>
+
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.
+
 
+
Unzip the file and execute the binary. Follow all steps and accept all conditions.
+
 
+
<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.
+
 
+
<h2> Hello World </h2>
+
In this Section a Hellow World (led blinking) example will be programmed on a NUCLEO-F446RE board:
+
 
+
<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>
+
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 */
+
 
+
</pre> </li>
+
 
+
<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>
+
 
+
<h2> Problems with STM32CUBEIDE </h2>
+
<h3> sprintf %f </h3>
+
 
+
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>
+
<li> Remove heapX.c form Middlewares->Thirs_Party->FreeRTOS->Source->CMSIS_RTOS_V2->portable->MemMang->heap_X.c </li>
+
<li> Add this file to the Src directory: [[media:heap_useNewlib.txt | heap_useNewlib]] and rename it as heap_useNewlib.c</li>
+
<li> Comment _sbrk function on sysmem.c file; it is already implemented on heap_useNewlib.c </li>
+
<li> Include in FreeRTOSConfig.h the folowing directive: </li>
+
<pre>
+
#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>
+
 
+
<h3> IDE Flickering </h3>
+
 
+
First check the value of GTK_IM_MODULE in your environment by executing
+
 
+
<pre>
+
echo $GTK_IM_MODULE
+
</pre>
+
 
+
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>
+
export GTK_IM_MODULE="ibus"
+
</pre>
+
 
+
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>
+
env GTK_IM_MODULE=ibus
+
</pre>
+
 
+
E.g. Exec=env GTK_IM_MODULE=ibus /opt/st/stm32cubeide_1.6.1/stm32cubeide %F
+

Revision as of 18:43, 5 February 2023