Warning
This page is located in archive. Go to the latest version of this course pages. Go the latest version of this page.

Lab02 - Nucleo Intro

  • This session is for introducing Nucleo Boards and how to start using them. Nucleo boards used in this course are Nucleo-64 STM32-F401 and Nucleo-64 STM32-F446RE which use ARM Cortex-M4 as microcontroller.
  • There are two ways for uploading code to Nucleo boards: 1) via terminal, 2) via IDE. In this lab session and throughout the course, using the terminal for working for Nucleo board is preferred. However, for your personal interest, instructions for how to work with IDE are also provided on this page.

Using Terminal

  • Download the zip file provided with this link nucleo_by_terminal.zip and unzip it in you PC using terminal.
  • Navigate to the location of the unzipped folder and open a terminal at that location. Write

cd NUCLEO\ by\ Terminal/Debug/
make clean
make

Commands make compiles your code and generates a .bin file which is executable by your Nucleo board. Note that if your machine cannot find the compiler, you may need to add it to append it to your PATH variable:

PATH=$PATH:*PATH TO COMPILER*
In the labs, like this:
PATH=$PATH:/overlay/pivot/opt/Ac6/SystemWorkbench/plugins/fr.ac6.mcu.externaltools.arm-none.linux64_1.17.0.201812190825/tools/compiler/bin

Go ahead and copy NUCLEO\ by\ Terminal.bin file to your Nucleo board. You should know the proper command for this action so try it for yourself. Here is the answer:

cp NUCLEO\ by\ Terminal.bin /media/YOUR_USER_NAME/NODE_F446RE

Replace YOUR_USER_NAME with your PC username. Congratulations, you have uploaded your first code to the Nucleo board. Wait what code?

  • navigate to find file main.c by commands:

cd ../Core/Src/

The file main.c is the file that you just uploaded to the board and your board is now executing this. Lets change this file and make our board blink an LED.

  • Open main.c in an editor (preferably vim but your choice). Replace line 99 of this code by the code below:

HAL_GPIO_TogglePin(GPIOA,GPIO_PIN_5);
HAL_Delay(1000);
The first line toggles your pin value connected to the LED, which means if your LED was on it would turn off and vice versa. The second line makes board wait for 1000ms and then again LED is toggled. As a result, you will see LED blinking every one second.

Go ahead and save the modifications of main.c.

  • Time to recompile! Navigate to the location of makefile by

cd ../../Debug/

  • Before we compile, we need to clear the files that remain from our previous compiling. For that purpose write to terminal:

make clean

  • Now compile your new code and copy it to your Nucleo Board.

make
cp NUCLEO\ by\ Terminal.bin /media/YOUR_USER_NAME/NOD_F446RE

  • Bravo! you should see your board blinking now. Proceed with Lab tasks.

Using IDE

  • To start with working with the Nucleo board through IDE, we need to download the development environment for the board. Click the link stm32cubeide.html.
  • In the website opened scroll down to find the latest version of the IDE.

  • Click and download the latest version of the IDE. If you are asked to make an account, please do so, and don't worry, it's free.
  • After you downloaded the software, go ahead and unzip the downloaded file and you find a file with the extension of .sh
  • open a terminal in the same lcoation that downloaded .sh file exist and write to terminal:

sudo bash FILENAME
Replace FILENAME with the name of the downloaded file.

  • During installation answer y to the first question and n to the second question.
  • Once the installation is finished, search for the program named STMicroelectronics STM32CubeIDE and open it.
  • Click File on the top left corner. Click on New and STM32 Project. A window similar to the picture below must appear.

  • Go to Board Selection tab and in Part Number Search search and click either NUCLEO-F401RE or NUCELO-F446RE. Choose your board in Board List and click Next.
  • The next window should be similar to the photo below.

Choose a project name and click Finish.

  • Click yes in the appeared dialog window.
  • You must be directed to the window like the image below.

  • On the left hand side, find core/src/main.

  • At this point, connect your Nucleo board to the PC.
  • Scroll to line 97 and find the piece of code as shown below.

  • Whatever is written inside the while(1){} block will be repeated by Nucleo board. For the sake of this introduction, we want to make the LED of the board blink. Insert the codes below to line 98.

HAL_GPIO_TogglePin(GPIOA,GPIO_PIN_5);
HAL_Delay(1000);
Any idea how these two lines make an LED blink? Any clue about periods of blinks?

  • Pay attention that your code should always be placed before / otherwise your code will be deleted each time you compile your code.
  • Click on Run, Debug As, STM32 MCU C/C++ Application. In the appeared windows click on OK and Switch. If you face any error at this stage it is most probably because your board is not connected to the PC properly. If this is the case, please don't hesitate to inform instructors of the lab.
  • Click on the play icon on the top left or press F8 key as shown below.

Now your code has been transferred to the Nucleo Board, CONGRATUlATIONS!.

Lab tasks

  • Change frequency of LED blink to 20 HZ.
  • Change code in a way that frequency of blinks duplicates after each blink. The initial blink frequency should be 1 HZ.
courses/be5b99cpl/labs/lab02.txt · Last modified: 2021/10/01 16:41 by amjadara