====== 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 {{ :courses:be5b99cpl:labs: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 {{https://www.st.com/content/st_com/en/products/development-tools/software-development-tools/stm32-software-development-tools/stm32-ides/stm32cubeide.html?dl=Mjr3l63YKZyqLkp8DI5pLg%3D%3D%2Cw9xdpbICJMk%2FvZC99JMxUvSzPzglPfCogXVFou5VESyAKG%2Fu6o9p7Ykc4difeURbobO%2Bjj40OPyWO7IaU5Jn3JMis%2FsDUk5PSYG5r5jEUFQmMUZxMd6Kuu2Kp3MGGl3UMnGboB6a6TI3%2FL%2BDe%2BOq5TAyAPv%2BKWqzvE6O8imvl7NxImsjk8HFMukYj6cxlvv9LQLmZJfZkI28Qk2iVGbqGf1Ma88v4PdXzgL9sOQ87riR6vreoXgDocElG36zEfdyvV3JXLHSoNFi3trVCTgsfxwIhjIDGg9lqwV%2FrMYXxGAQV89CZcMWqmCj2fPjKHTaiakcECVHMNZMoKMU6WSZnUlASXdh0SERY24iKtUYZugRsLe%2Fhm0%2BSzxgo05d%2BvvmEcWMVnwWujAtMvfZC%2B0y2q37IajO581DeZ9HKkd18qhqMt%2Bmda8Qb6dO%2BX1qb%2BavEIM32%2BWnLp3gbRNhkn9G8s%2BCDbULqewj45w0AOwhOpU%3D&uid=AP08Q9oc9cQCLUVVnQvVBuCiCKK2v2TWPIhhWqgEU14=#get-software}}. * In the website opened scroll down to find the latest version of the IDE. {{:courses:be5b99cpl:labs:screenshot_2021-09-25_at_21-16-13_stm32cubeide_-_stmicroelectronics.png?400|}} * 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. {{:courses:be5b99cpl:labs:screenshot_from_2021-09-25_21-28-02.png?400|}} * 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. {{:courses:be5b99cpl:labs:screenshot_from_2021-09-25_21-37-14.png?400|}} 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. {{:courses:be5b99cpl:labs:screenshot_from_2021-09-25_21-40-58.png?400|}} * On the left hand side, find ''core/src/main''. {{:courses:be5b99cpl:labs:screenshot_from_2021-09-25_21-46-11.png?400|}} * At this point, connect your Nucleo board to the PC. * Scroll to line 97 and find the piece of code as shown below. {{:courses:be5b99cpl:labs:screenshot_from_2021-09-25_21-49-00.png?400|}} * 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 ''/* USER CODE END WHILE */'' 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. {{:courses:be5b99cpl:labs:screenshot_from_2021-09-25_21-59-35.png?400|}} 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.