How to execute get_id_command on STM32H743?

 Executing a "get_id_command" on an STM32H743 typically refers to reading its Device ID through one of two main interfaces:



  1. System Memory Bootloader: Used via UART, I2C, SPI, etc., when the chip is in bootloader mode.

  2. CPU Debug Access Port (DAP): Used via JTAG/SWD with a debugger probe, which is the most common method during development.

I will cover both methods, with a focus on the practical SWD method.


Method 1: Using the System Memory Bootloader (UART)

This method involves putting the chip into a special boot mode where it runs a factory-programmed bootloader. This bootloader has a command to read the device ID.

Step-by-Step Guide:

  1. Enter Bootloader Mode:

    • Power cycle the board.

    • Set the BOOT0 pin high (usually by connecting it to VDD). On many STM32H743 boards, this is a dedicated jumper or button.

    • The BOOT1 (or BOOT_ADD1) pin is typically left low. Check your board's schematic.

    • Reset the chip. It will now run the system bootloader instead of your application.

  2. Connect via UART:

    • Connect a USB-to-UART adapter to the MCU's USART1 (PA9/PA10) or USART3 (PB10/PB11) - these are common defaults.

    • Ensure the connections are:

      • MCU TX -> Adapter RX

      • MCU RX -> Adapter TX

      • Common Ground

  3. Send the "Get ID" Command Sequence:

    • Configure your serial terminal (Tera Term, PuTTY, screen, etc.) for 8N1, with any baud rate initially.

    • The bootloader uses an auto-baud detection mechanism. Send the byte 0x7F to synchronize.

    • The bootloader should respond with an ACK (0x79) byte.

    • Now, send the "Get ID" command byte, which is 0x02.

    • You must also send the checksum, which is XOR of the command byte and 0xFF.

      • Checksum = 0x02 ^ 0xFF = 0xFD

    • The full sequence is: 0x7F -> (wait for 0x79) -> 0x02 -> 0xFD

  4. Interpret the Response:

    • The bootloader will respond with 0x79 (ACK), followed by:

      • One byte: N = number of bytes in the ID minus 1.

      • N+1 bytes: The actual Product ID.

      • One byte: Checksum (XOR of all previous bytes, including N).

    • For STM32H743, you should receive something like:

      • 0x79 (ACK)

      • 0x01 (N=1, meaning 2 bytes follow)

      • 0x04 0x50 (The Device ID for STM32H743/753 parts is 0x450)

      • 0x?? (Checksum)

Example Sequence:

text
You Send:  7F
Chip Responds: 79 (ACK)
You Send:  02 FD
Chip Responds: 79 01 04 50 [Checksum]

Result: Device ID = 0x450


Method 2: Using the Debug Port (SWD/JTAG) - Easiest for Developers

This is the standard method used during development with an IDE or dedicated tools. It reads the CPU's debug peripheral ID.

Option 2A: Using STM32CubeIDE / STM32CubeProgrammer

  1. Connect your ST-Link, J-Link, or DAP-Link debugger to the board via SWD (SWDIO, SWCLK, GND).

  2. Open STM32CubeProgrammer.

  3. Connect to the target. If successful, the Device ID will be displayed directly in the main window under "Device information".

  4. You can also find it in the Help -> About menu under "Target".

Option 2B: Using OpenOCD (Command Line)

If you have OpenOCD installed, you can read the ID register directly.

  1. Start OpenOCD with a config file for your board and debug probe.

    bash
    openocd -f interface/stlink.cfg -f target/stm32h7x.cfg
  2. In a separate terminal, connect to the OpenOCD Telnet interface (telnet localhost 4444) and run:

    text
    > halt
    > mdw 0x5C001000 1

    The address 0x5C001000 is the DBGMCU_IDCODE register for many STM32H7 parts. The value returned will be a 32-bit number where the device ID is in bits [11:0]. For an STM32H743, you should see a value like 0x6BA0 2477, where 0x450 is embedded.

Option 2C: Reading from Software (Your Firmware)

You can read the ID directly from your C code. This is useful for firmware that needs to identify itself.

c
#include "stm32h7xx.h"

uint32_t get_stm32_device_id(void) {
  // The DBGMCU_IDCODE register address for STM32H7
  // (Always check the Reference Manual for the exact address!)
  volatile uint32_t *dbgmcu_idcode = (volatile uint32_t *)0x5C001000;
  uint32_t id = *dbgmcu_idcode;

  // The DEV_ID field is in bits [11:0]
  uint16_t dev_id = (id & 0xFFF);

  return dev_id;
}

int main(void) {
  uint16_t my_id = get_stm32_device_id();
  // my_id should now be 0x450 for STM32H743/753

  // You can print it via UART, etc.
  printf("Device ID: 0x%03X\r\n", my_id);

  while(1) {
    // Your application code
  }
}

Summary of Device IDs

  • STM32H743/753: The Device ID is 0x450. This is the value you are looking for.

Which Method Should You Use?

  • If you have a working debugger (ST-Link): Use Method 2 (STM32CubeProgrammer or OpenOCD). It's the fastest and most reliable.

  • If your chip is bricked or has no program: Use Method 1 (Bootloader). It's a great recovery tool.

  • If you need the ID in your application code: Use the software read method (2C).

The "get_id_command" is a fundamental step for verifying communication with the chip and ensuring you are programming the correct device.

评论

此博客中的热门博文

Detailed Explanation of STM32 HAL Library Clock System

How To Connect Stm32 To PC?

How do you set up ADC (Analog-to-Digital Converter) in STM32?