EZdenki / STM32F103-CMSIS-Setup

Procedure to install CMSIS-based command line toolchain to program STM32F103 (Blue Pill) under Linux or Windows
0 stars 0 forks source link

STM32F103-CMSIS-Setup for Linux or Windows

Procedure to install a bare-bones, command-line based, CMSIS-based toolchain to program the STM32F103 (Blue Pill) under Linux or Windows without STM's HAL. Includes a "Blinky" sanity check to confirm the toolchain is properlly installed and working.

Linux Installation Procedure (Click to expand) 1. Install STM32CubeProgrammer
https://www.st.com/en/development-tools/stm32cubeprog.html
Follow the registration and download instructions. Extract the zip file. Enter the new directory, double-click on the linux installer, **SetupSTM32CubeProgrammer-x.xx.x.linux**, and follow the installation instructions. 2. Install "libusb-1.0-0-dev" (From the command line).
```sudo apt install libusb-1.0-0-dev``` 3. Add permissions to use USB ST-Link Programmer.
```sudo cp ~/STMicroelectronics/STM32Cube/STM32CubeProgrammer/Drivers/rules/*.* /etc/udev/rules.d``` 4. Create persistent environment variable to point to the STM32_Programmer_CLI executable (to be used within Makefile). Note that if the path to STM32_Programmer_CLI is different from the default install location of:
**~/STMicroelectronics/STM32Cube/STM32CubeProgrammer/bin**
then the following line must be modified accordingly.
```export STMCUBE_PROG=~/STMicroelectronics/STM32Cube/STM32CubeProgrammer/bin/STM32_Programmer_CLI``` 5. Install "make".
```sudo apt install make``` 6. Install arm-none-eabi toolchain. Note that if the install of gcc-arm-none-eabi gives an error due to lack of disc space, then the command can be run again and may correctly install.
```sudo apt install gcc-arm-none-eabi``` 7. Download and build a simple Blinky project as a sanity check.
Navigate to where you want to keep your STM32 projects.
Then clone the sample blinky project to your PC and move to that directory:
```git clone https://github.com/sandynomike/STM32F103-CMSIS-Blinky && cd STM32F103-CMSIS-Blinky``` 8. Connect the ST-Link programmer to a USB port and connect the ST-Link programmer to your Blue Pill. Note that if the ST-Link programmer was already connected during the installation process, then you should unplug it from the USB port and plug it in again so that is recognized. 9. Build and upload the code to the Blue Pill.
```make clean && make``` 10. ### The LED on the Blue Pill should be blinking!
Windows Installation Procedure (Click to expand) 1. Install Git for Windows
https://gitforwindows.org/
Download and install. Accept default settings, except:
Under the option for **Adjusting the name of the initial branch in new repositories**, select the option to **Override the default branch name for new repositories** and specify the branch name as **main**. 2. Install STM32CubeProgrammer
https://www.st.com/en/development-tools/stm32cubeprog.html
Click **Get Software** and then **Get latest** for **STM32CubePrg-W64**
Accept license agreement and enter your name and email address and click **Download**. Close this page and open the email from STMicroelectronics. Click the **Download now** button in the confirmation email to start the download. (This will open another download webpage, but **don't** click on Get Software again.)
Open the zip file and double-click on the **SetupSTM32CubeProgrammer_win64** program to install.
Follow the installation instructions, including installing the **device software** 3. Add a Path variable to point to the STM32CubeProgrammer_CLI.exe file (to be used within Makefile)
Click the Windows Key and type "environment variables" and select **Edit the system environment variables**
Click on **Environment Variables...**
Under **User variables...**, click **New...**
Under **Variable name:**, type **STMCUBE_PROG**
Click **Browse File...**, and navigate to:
**C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin\STM32_Programmer_CLI** application, and click **Open**, and then click **OK**.
Click **OK** twice more to exit the dialog boxes. 4. Install GNU Make for Windows
https://gnuwin32.sourceforge.net/downlinks/make.php
Run the downloaded make-3.81.exe file. Accept the default installation options.
5. Add a Path ennvironment variable to point to Make.
Click the Windows Key and type "environment variables" and select **Edit the system environment variables**
Click on **Environment Variables...**
Under the **User variables...** section click on the **Path** line and then click **Edit..**
Then click **New** and then **Browse...** Browse to This PC -> Local Disk (C:) -> Program Files (x86) -> GnuWin32 -> bin, then click **OK**. Then click **OK** 3 more times to exit the dialog boxes. 6. Install GNU Arm Embedded Toolchain
https://developer.arm.com/downloads/-/gnu-rm
**Do not** click on the Arm GNU Toolchain at the top of the page. Scroll down to the link for:
**gcc-arm-none-eabi-10.3-2021.10-win32.exe**.
Click on the link to download. Open the downloaded file. Follow the default settings, **except**, under **Completing the GNU Arm Embedded Toolchain 10.3-2021.10 Setup Wizard**, check the box that says **Add path to environment variable** before clicking **Finish**. Close the **readme** document and close the command-line terminal that pops up.
7. Download and build a simple Blinky project as a sanity check.
Open a command-line terminal (by touching the **Windows-Key**, then type ```command prompt```).
From the command prompt:
Navigate to where you want to keep your STM32 projects.
Then clone the sample blinky project to your PC and move to that directory:
```git clone https://github.com/sandynomike/STM32F103-CMSIS-Blinky && cd STM32F103-CMSIS-Blinky``` 8. Connect the ST-Link programmer to a USB port and connect the ST-Link programmer to your Blue Pill.
Note that if the ST-Link programmer was already connected during the installation process, then you should unplug it from the USB port and plug it in again so that is recognized. 9. Build and upload the code to the Blue Pill.
```make clean && make``` 10. ### The LED on the Blue Pill should be blinking! **End of Procedure**