Skip to content

Instantly share code, notes, and snippets.

@guywaldman
Last active July 26, 2023 09:49
Show Gist options
  • Save guywaldman/923306575b6d6e848f0a466df3b8ba6e to your computer and use it in GitHub Desktop.
Save guywaldman/923306575b6d6e848f0a466df3b8ba6e to your computer and use it in GitHub Desktop.
STM32 Setup on macOS

Developing for STM32 on macOS

This goes over how to setup a development environment for embedded programming on macOS systems, specifically for the ARM Cortex STM32WB55 board (but probably applies generally for other boards with minor adjustments).

  1. Follow this guide to setup the workfolder: https://gist.github.com/csukuangfj/bfe2be78eda3a24a5164005b1092c94b

    I will add more detailed steps in this guide at a later time, as well as prerequisites for this setup.

  2. Copy /Applications/STMicroelectronics/STM32Cube/STM32CubeProgrammer/STM32CubeProgrammer.app/Contents/MacOs/SVD/STM32WB55_CM4.svd (or the SVD that's appropriate for your specific board) to the root of your workfolder.

  3. Run:

    ln -sv /Applications/STMicroelectronics/STM32Cube/STM32CubeProgrammer/STM32CubeProgrammer.app/Contents/MacOs/bin/STM32_Programmer_CLI /usr/local/bin/
  4. Set up the following files in Visual Studio Code (adapt per your specific project name and folder structure):

    settings.json:

    {
        "stm32-for-vscode.openOCDPath": false
    }

    launch.json:

    {
     "version": "0.2.0",
     "configurations": [
       {
          "name": "ST-Link",
          "cwd": "${workspaceRoot}/build",
          "executable": "HelloWorld.elf",
          "request": "launch",
          "type": "cortex-debug",
          "servertype": "stutil",
          "serverpath": "st-util",
          "device": "STM32WB55",
          "interface": "swd",
          "gdbTarget": ":4242",
          "runToMain": true,
          "preLaunchTask": "build",
          "svdFile": "${workspaceRoot}/STM32WB55_CM4.svd",
          "swoConfig": {}
     	   }
       ]
    }

    tasks.json:

    {
       "version": "2.0.0",
       "tasks": [
          {
             "label": "build",
             "type": "shell",
             "command": "make -j",
             "options": {
                "cwd": "${workspaceFolder}"
             },
             "presentation": {
                "clear": true
             },
             "group": {
                "kind": "build",
                "isDefault": true
             },
             "problemMatcher": {
                "base": "$gcc",
                "fileLocation": [
                   "autoDetect",
                   "${workspaceFolder}"
                ]
             }
          },
          {
             "label": "flash_fw",
             "type": "shell",
             "command": "st-flash write ./build/*.bin 0x08000000",
             "options": {
                "cwd": "${workspaceFolder}"
             },
             "presentation": {
                "clear": true
             },
             "problemMatcher": {
                "base": "$gcc",
                "fileLocation": [
                   "autoDetect",
                   "${workspaceFolder}"
                ]
             }
          }
       ]
    }

    c_cpp_properties.json:

    {
       "version": 4,
       "configurations": [
           {
               "name": "STM32WB55",
               "includePath": [
                   "${workspaceFolder}/**",
                   "${workspaceFolder}/../STM32CubeWB/Drivers",
               ],
               "defines": [
                   "USE_HAL_DRIVER",
                   "STM32WB55xx"
               ],
               "intelliSenseMode": "gcc-arm",
               "compilerPath": "arm-none-eabi-gcc",
               "compilerArgs": [
                   "-mcpu=cortex-m4",
                   "-mthumb"
               ],
               "cStandard": "c11"
           }
       ]
     }

Zigbee

  1. Start the wireless stack:

    STM32_Programmer_CLI -c port=swd -startfus
    STM32_Programmer_CLI -c port=swd mode=UR -fwupgrade stm32wb5x_Zigbee_FFD_fw.bin 0x080A2000 firstinstall=0

Debug logs

Find deviceL: ls -all /dev/*usb* Run screen command: screen /dev/tty.usbmodem143303 115200

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment