STM32 manual

STM32

hardware setup

ST-LINK v2

SWCLK (clock) ; SWDIO (data input & output) ; power supply (for the micro chip) you can find the corresponding pins on stm32 chip (SWCLK SWDIO)

SWCLK pull low externally (link to GND); SWDIO pull high

for JTAG, pins are same (Punctual Atom STM32F1 board)

Insert picture description here

you can also find SWDIO is pulled up while SWCLK is pulled down.

Degub protoptype (JTAG / SWD)

https://blog.csdn.net/LEON1741/article/details/72846434

JTAG is the test protocol inside the chip. The standard JTAG interface is 4 wires: TMS, TCK, TDI, TDO, which are the mode selection, clock, data input and data output lines respectively. The definition of the relevant JTAG pins is:

TMS: Test mode selection, TMS is used to set the JTAG interface in a specific test mode;

TCK: Test clock input;

TDI: Test data input, the data is input to the JTAG interface through the TDI pin;

TDO: Test data output, the data is output from the JTAG interface through the TDO pin;

SWD, Serial Wire Debug, fewer pins (4), more stable under big data.

Insert picture description here

You can see that SWD and JTAG share the same port for the punctual atom board above.

SWD uses fewer interfaces than JTAG, only four wires SWDIO, SWCLK, VCC, GND (four excuses on stm32f103-minimum)

Emulator

jlink

Based on JTAG simulation, the USB port is used for the computer, and the JTAG port is still used for the board

ST - link

It is specially designed for ST company chips, which can be programmed, simulated, and downloaded. st-link v2 is common to JTAG and SWD, and you can choose it at Keil.

Burn

  • openocd

See how to install and program openocd in nuttx

openocd -f interface/stlink-v2.cfg -f target/stm32f1x.cfg -c init -c "reset halt" -c "flash write_image erase nuttx.bin 0x08000000"

openocd can also be used to connect with the chip to provide a local port for debugging.

openocd -f interface/stlink-v2.cfg -f target/stm32f1x.cfg

openocd profile /usr/local/share/openocd/scriptsunder. interfaceCorresponds to the debugger hardware (stlink-v2, …) targetCorresponds to the board

  • stlink

Use stlink driver to burn. At this point BOOT0the BOOT1pin is pulled low, start from FLASH.

  • Serial port programming program

In STM32CubeProgrammerthe

Insert picture description here
Select the serial port mode, then select the startup mode, and then System Memoryburn the program after connecting with the serial port.

  • BOOT pin setting during programming.
BOOT0 BOOT1 Start method
0 Irrelevant User Flash memory startup (User Flash memory)
1 0 Boot from system memory (System memory)
1 1 Boot from Embedded SRAM (Embedded SRAM)
  • User Flag memory

Normal working mode

  • System Memory

The system memory is a specific area inside the chip. When ST leaves the factory, a section of bootloader (ROM) is preset inside. With the help of bootloader, download the program to the flash through the serial port.

  • Embedded SRAM

This mode is used to debug code (do not need to erase all from)

2020.5.30 The reason why stlink-v2 cannot connect to the chip through openocd has been unclear at night. Later, it was discovered that the Boot wiring was incorrect, which caused the driver to fail to detect the chip.

If booting from the main flash memory, access from address 0x0800 0000, which is to program the specified address through openocd.

The built-in SRAM is at 0x2000 0000

Debug

Currently debugging can be done with openocd. Pay attention to modify the size of the programming file area in the startup file.

arm-none-eabi-gdb nuttx # program name

# gdb interface
target remote localhost:3333 # connect to the localhost port provided by openocd
monitor reset # reset chip
monitor halt  # halt the program

load nuttx    # load binary file

monitor It is a command sent to the chip locally and remotely.

Custom Board

Here is a record of some boards you have seen and HALprecautions when using them.

STM32F407G-DISC1

STM32 official board. The interesting part of this board is that it integrates a stlink-v2 debugger, so you don't need to buy another one yourself. CN3Control the debugger selection. When jumping, select the debugger integrated on the board. Otherwise, you can use your own debugger to connect directly to the GPIO pins.

STM32F103ZET6 (punctual atomic warship board)

Die configuration:

  1. RCCSelect the inside HSE, LSE.
  2. sysInside Debugchoose Serial Wire. (Otherwise ST-Link cannot be used for debugging)
  3. Checking NVIC-> Code Generation-> System Tick Timerwhether to generate an interrupt response function IRQand call HALhandler ( HAL_Handler).

Remember to plug in the power connector on the left side of the board.

communication

UART

Asynchronous transceiver serial communication <--> synchronous mode (USART)

Standards: RS232. RS449

COM is the asynchronous serial communication port RS232 on the PC

UART protocol

Keeping the low level at the beginning is to ensure that the data line is normal. The low level indicates the start of data transmission. After the UART accepts, it sets a flag to indicate that the data is available (checked in the interrupt processing function), and generates a processor interrupt. Use UARTwill be a time Hard Ware Control Flowoption is corresponding to RTSthe CTSpin for transmission of auxiliary data. Correspondingly, read the register in the HAL library and compare it with the flag to determine whether the next transmission is to be made. (Function UART_WaitOnFlagUntilTimeout) in minicomthe same need to configure the Hardware control flowoptions.

CTS <--->  RTS
RTS <---> CTS

CAN

The CAN protocol communicates through the following five data frames.

chip Reg

CLOCK

RCC (Reset Clock Control)

AHB (Advanced High performance Bus)

GPIO

MODER (mode register)

OTYPER (output type register)

HERE

Program

stmf4xx.h has defines about registers

RCC -> AHBENR |= RCC_AHBENR_GPIOCEN ; // or (1 << 19) specify the bits

// set zero

GPIOC -> OTYPER &= ~(...)

ASSEMBLY CODE

eg. inline assembly code

int x = 1, y = 2 ;
int res = 0;
__asm ("ADD %[result], %[input_x], %[input_y]"
    : [result] "=r" (res)
    : [input_x] "r" (x), [input_j] "r" (y)
)

The format is

Stem Type> STM32 Peripheral Support to determine the peripheral used

> System Type> Alternate Pin Mapping to determine the remapping relationship

PWM

Configure pwm Timer and output channel in stm32f103-minimum config under boards. Confirm in stm32f103-minimum.h that the defined channels and timers are consistent with those in config

> System Type> Timer Configuration Configure timer usage mode and output channel

Guess you like

Origin blog.csdn.net/lib0000/article/details/112346210