Thanks to visit codestin.com
Credit goes to github.com

Skip to content

EZ32Inc/start-stm32

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

How to Debug STM32 (or Any ARM MCU) Using ESP32JTAG + VSCode + Cortex-Debug

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


1. Install Prerequisites

Visual Studio Code

Download and install VSCode from: 👉 https://code.visualstudio.com/

Cortex-Debug Extension

In VSCode, open the Extensions view (Ctrl+Shift+X), search for “Cortex-Debug”, and install it.

  • Extension ID: marus25.cortex-debug

2. ARM Toolchain

You need the GNU Arm Embedded Toolchain to build and debug firmware.

Windows

Download and install: 👉 Arm Developer - GNU Arm Toolchain

Make sure arm-none-eabi-gdb.exe is in your system PATH.

Linux / macOS

sudo apt install gcc-arm-none-eabi gdb-multiarch

Verify:

arm-none-eabi-gcc --version
arm-none-eabi-gdb --version

3. Preparing the Code

It 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
make

4. About the Code

This 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 */

4. Board Info

Boot Modes

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

Pinout

image

Schematics

image

Resources

5. Credit goes to:

https://github.com/m3y54m/start-stm32

Thank you!

About

stm32f103c8t6 Bluepill board demo project for ESP32JTAG to use with VS Code + Cortex-debug

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages