This guide explains how to set up VSCode and Cortex-Debug to debug an STM32 MCU using ESP32JTAG, a wireless JTAG interface based on ESP32 + FPGA.
For more info on ESP32JTAG, please visit: 👉 https://www.crowdsupply.com/ez32/esp32jtag
Download and install VSCode from: 👉 https://code.visualstudio.com/
In VSCode, open the Extensions view (Ctrl+Shift+X), search for “Cortex-Debug”, and install it.
- Extension ID:
marus25.cortex-debug
You need the GNU Arm Embedded Toolchain to build and debug firmware.
Download and install: 👉 Arm Developer - GNU Arm Toolchain
Make sure arm-none-eabi-gdb.exe is in your system PATH.
sudo apt install gcc-arm-none-eabi gdb-multiarchVerify:
arm-none-eabi-gcc --version
arm-none-eabi-gdb --versionIt should be any GNU Makefile–based project for your target board.
Here we prepared a project for STM32F103C8T6 (BluePill). You can download and try it — it also includes the required configuration files to use with ESP32JTAG + VSCode + Cortex-Debug.
👉 GitHub Repository: https://github.com/EZ32Inc/start-stm32
Code copy:
git clone https://github.com/EZ32Inc/start-stm32.git
cd start-stm32/blinky-hal
make clean
makeThis program is based on the article "Bare Metal STM32 Programming – LED Blink" without using any external libraries (except stdint.h which is only used to define uint32_t).
In order to compile and link this program we need the main program source file main.c, the linker script file linker.ld, and the C run-time assembly file crt.s.
#include <stdint.h>
// register address
#define RCC_BASE 0x40021000
#define GPIOC_BASE 0x40011000
#define RCC_APB2ENR *(volatile uint32_t *)(RCC_BASE + 0x18)
#define GPIOC_CRH *(volatile uint32_t *)(GPIOC_BASE + 0x04)
#define GPIOC_ODR *(volatile uint32_t *)(GPIOC_BASE + 0x0C)
// bit fields
#define RCC_IOPCEN (1<<4)
#define GPIOC13 (1UL<<13)
void main(void)
{
RCC_APB2ENR |= RCC_IOPCEN;
GPIOC_CRH &= 0xFF0FFFFF;
GPIOC_CRH |= 0x00200000;
while(1)
{
GPIOC_ODR |= GPIOC13;
for (int i = 0; i < 500000; i++); // arbitrary delay
GPIOC_ODR &= ~GPIOC13;
for (int i = 0; i < 500000; i++); // arbitrary delay
}
}This program is based on the article "STM32 LED Blink" which uses STM32 HAL to configure the microcontroller and blink the LED.
The project initialization is done by STM32CubeMX.
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
// Toggle the LED
HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13);
// Wait for 500 ms
HAL_Delay(500);
// Rinse and repeat :)
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */A couple of special MCU pins has to be set-up to proper logical values to enter the bootloader. The pins are named BOOT0 and BOOT1 on the STM32 microcontroller. Boot pins can select several modes of bootloader operation:
| BOOT1 | BOOT0 | Boot Mode | Aliasing |
|---|---|---|---|
| X | 0 | Main Flash Memory | Main flash memory is selected as boot space |
| 0 | 1 | System Memory | System memory is selected as boot space |
| 1 | 1 | Embedded SRAM | Embedded SRAM is selected as boot space |
- https://www.crowdsupply.com/ez32/esp32jtag
- https://code.visualstudio.com/
- https://github.com/m3y54m/start-stm32
- Setting-up cross compiler and build tools for STM32
- Bare Metal STM32 Programming – LED Blink
- Bare Metal - From zero to blink
- STM32 toolchain for Windows
- STM32 toolchain for Windows - Part 1 (CubeMX, GCC, Make and OpenOCD)
- Visual Studio Code for STM32 development and debugging - Part 2
- STM32 Startup code, Bare metal - Part 3
- stm32-for-vscode
- Program STM32F4 with UART
- STM32 LED Blink
- Blinking LED with STM32CubeMX and HAL
- UART and new board introduction
- Using the STM32 UART interface with HAL
- st-flash tool
https://github.com/m3y54m/start-stm32
Thank you!