STM32 MacOS X Environment Setup Table of Contents. Install Eclipse. Option 1: GNU MCU Eclipse IDE for C/C Developers; 3. Cross Compile Toolchain (arm-none-eabi-.)). Posted on April 27, 2016 at 11:41. Hi, Anyone knows how to use STM32 USB as virtual com port under MAC OS? Do ST provide official driver for this?
Every day, the software world is moving away from traditional software and hardware tools by replacing them with better and faster open source alternatives. Today, the most compelling open source alternatives for ARM embedded development are based on Eclipse. Setting up a perfect workflow for embedded software development with no licensing costs can be a daunting task if you don’t know where to start.
As I’m not a fan of Eclipse, I’ll show you how to configure VS Code for this task. I chose this IDE because it’s blazing fast, Intellisense always works and it supports extensive customisation through plugins and configuration files.
In this tutorial we’ll use the ST-Link adapter for programming and debugging. If you want to go completely open-source, black magic probe has you covered.
Should I do this?
Well, it depends. If you are working on a large scale project you’re probably better off using traditional paid IDEs like uVision or IAR because of their wider compatibility across many product versions and operating systems. Also, if you are looking for a method of programming ARM Cortex devices which is royalty free and easier to setup you may want to check out VisualGDB,SW4STM32 or other Eclipse based alternative.
However, if you want the full power of Intellisense at your fingertips and faster build times this is the way to go. Trust me, it makes a whole lot of difference in development.
Prerequisites
A NUCLEO-F303K8 development kit or similar ST board. For other boards you’ll need to update the configuration files with your processor name and series. All the external tools necessary to build and flash ARM Cortex embedded software will be placed in the VSARM folder.
- Create a folder named VSARM in C:/
- Visual Studio Code – https://code.visualstudio.com/
- STM32Cube initialization code generator – https://www.st.com/en/development-tools/stm32cubemx.html
- GNU Embedded Toolchain for ARM – https://developer.arm.com/open-source/gnu-toolchain/gnu-rm/downloads
- Change Install Location to C:VSARMarmcc
- Texane’s ST-Link Tools – https://github.com/texane/stlink/releases
- Get the binaries and extract the release in C:VSARMstlink
- MinGW-W64 – https://sourceforge.net/projects/mingw-w64/
- Change the install location to C:VSARMmingw
- ST-Link drivers – https://www.st.com/en/development-tools/st-link-v2.html
Environment configuration
Open Environment variables setup dialog. Depending on your system configuration and administrative rights you may choose to modify either the User variables or the System variables. Make the following changes:
- Create a new variable named VSARM pointing to C:VSARM
- Add C:VSARMstlinkbin to the Path variable in the variables pane
- Add C:VSARMarmccbin to the Path variable in the variables pane
- Add C:VSARMmingwmingw32bin to the Path in the variables pane
Make sure executable files are present in all of the three sub-folders included above.
VS Code Configuration
After installing Visual Studio Code, open the IDE, navigate to Extensions tab or press Ctrl + Shift + X.
Install the following extensions:
- C/C++ – https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools
- Cortex Debug – https://marketplace.visualstudio.com/items?itemName=marus25.cortex-debug
- Project Manager – https://marketplace.visualstudio.com/items?itemName=alefragnani.project-manager
Press F1 and type user settings json. Select Open Settings (JSON). In the opened file, add the following property and save.
STM32 Workspace Setup
We will create a folder to serve as a workspace for our projects. We will configure two projects to get the development going. As a first step, create a folder named STM32_Projects on your desktop.
Then, create two subfolders, one named template_F3 and one named blink. Within VS Code navigate to files tab or press Ctrl + Shift + E. Click on Add folder to the workspace. Navigate to your STM32_Projects folder and select it.
Press F1 and type save workspace. Select Workspaces: Save Workspace As. Navigate to your STM32_Projects folder and save the file with an appropriate name.
Activesync for mac. Press F1 and type save project. Tap Enter and set the project name to template_F3.
Press F1 to edit projects. Modify the rootPath option to point to the template_F3 subfolder like below.
Duplicate the JSON project entry to create another project named blink pointing to our blink subfolder. Save the file and press F1 to List projects to open and click on the template_F3 project to open it. Your template project is now open.
You will need to update this file when you create new projects to let Project Manager extension know where your stuff is.
STM32 Project Setup
Press F1, type edit config and select C/CPP: Edit Configurations…. Replace the contents of c_cpp_properties.json with the following configuration.
Adjust the defines section to match the microcontroller used and your HSE frequency. To create a release configuration, duplicate the configuration object, remove USE_FULL_ASSERT define and replace DEBUG with NDEBUG in the defines section.
Press F1 and type config task. Select Tasks: Configure tasks. Click on Create tasks.json file from template and select the Other option. The tasks.json file will open. Replace the contents of this file with the following and save the file. Adjust core parameter -j for you processor and change the optimization level with the OPT variable.
The configuration creates two tasks, one to build the project and another one to flash the microcontroller.
Launch configurations
Press F1, type launch and select Debug: Open launch.json. Choose the Cortex Debug option. Replace the contents of launch.json file with the following:
Adjust the device option to for your microcontroller. Cortex-Debug extension for Visual Studio Code requires an SVD file to allow the inspection of peripheral registers. You can find a list of the SVD files for the most used STMicroelectronics microcontrollers here: https://github.com/posborne/cmsis-svd/tree/master/data/STMicro.
Download the appropriate file for your processor and paste it in the template_F3 folder. Then, adjust the sdvFile option in the launch configuration.
CubeMX blink example
Navigate to the template_F3 subfolder. Copy the contents of this folder to your blink folder. If the .vscode folder is not visible, make sure you have the option to Show hidden files and folders checked in Folder and Search options.
Open CubeMX and create a new project. Search for your microcontroller and double click to create the project. Save the project in STM32_Projects/blink/ as blink.ioc.
The GUI to edit peripherals will appear. Check your board schematics to find the pins for the LEDs. For the NUCLEO-F303K8 board, the LED is on PB3 pin. Click on the LED pin to change its function to GPIO_Output.
Save and click on generate the source code from Project / Generate Code menu.
The project settings dialog will appear. Make the following changes.
- Set the project name the same as the folder name (blink)
- Set the location to the workspace folder (STM32_Projects)
- Make sure the Toolchain IDE option is set to Makefile
- In the Code Generator tab, make sure the Delete previously generated files when not re-generated option is unchecked
Click Ok and allow to overwrite. Initialization code is now generated for the project. The first time it generates the code, Cube will delete the .vscode folder. Copy and paste the json files from the template as well as the svd file.
Adding keyboard shortcuts
To make life easier, we’ll add shortcuts for build and flash tasks. Press F1 and search for keybindings. Open the JSON file and add the following shortcuts:
Programming and debugging
Return to Visual Studio Code, press F1 and type list projects. Select the blink project. Edit the main.c file, then add some code to blink the LEDs.
For example: Game dune for mac.
Save and press F5 to build and F6 to flash. If all has gone well, it should work perfectly on the first try. You can now start debugging by going to the debug pane. If the SVD file is present, it will allow you to inspect the state of the peripheral registers.
When your code increases in size, you’ll want to separate it in different modules. For this, you have to add the C files path in the Makefile. STM32Cube does a great job keeping your changes when code is re-generated.
Hex editor mac os x. While this is an experimental approach and it takes some time to configure, I hope that the performance you can get out of it will convince you to consider this approach in production environments.
Happy coding!
(Note: There is no need to install Java to get the installer to run)For those that want to set up the STM33duino using the STM32 Cores on a Mac running Mojave (10.14) here is what worked for me.
Follow the excellent instructions at: https://github.com/stm32duino/wiki/wiki/Getting-Started until the 'Extra Step' portion:
(https://github.com/stm32duino/wiki/wiki .. extra-step) to install the STM32CubeProgrammer)
* Download the STM32Programmer at https://www.st.com/en/development-tools .. eprog.html
* Unzip it
* Right click on SetupSTM32CubeProgrammer-2.4.0.app (app version may be different)
* Select Show Package Contents
* Double click on MacOS
* Double click on “SetupSTM32CubeProgrammer-2_4_0_macos” to execute it
* Follow the instructions on the window that opens
The STM32CubeProgrammer is now installed.
Time to Test:
Connect your STM32 to your USB to Serial:
USB to TTL - STM32
Ground - Ground
5 volts - 5V (make sure USB to TTL is set to 5v, or if 3.3 volt, then connect it to the 3.3 pin)
TX - A10
RX - A9
Move jumper BOOT0 to 1, press reset, load Blink in the Arduino IDE examples.
Under Tools set the following options:
* Board > Generic STM32F1 Series (or what ever you have)
* Board Part Number > BluePill F10C8
* U(S)ART support: Enabled (generic Serial)
* USB Support (if available): None
* Optimize: Smallest (-Os default)
* C Runtime Library: Newlib Nano(default)
* Upload method: STM32CubeProgrammer (Serial)
* Port: (select your USB to TTL serial port)
With everything connected, click upload and you should see a flashing LED.
NOTE: to load the next program, you must press reset on the STM32 or it will error out.