Electoday 2025

ไมโครคอนโทรลเลอร์ => ARM Processors => Topic started by: tha on June 17, 2021, 02:42:38 PM

Title: STM32F1 DEBUG
Post by: tha on June 17, 2021, 02:42:38 PM
31 Debug support (DBG)

Low-density devices คือ STM32F101xx, STM32F102xx and STM32F103xx microcontrollers ที่ the Flash memory density ย่านระหว่าง 16 and 32 Kbytes.

Medium-density devices คือ STM32F101xx, STM32F102xx and STM32F103xx microcontrollers ที่ the Flash memory density ย่านระหว่าง 64 and 128 Kbytes.

High-density devices คือ STM32F101xx and STM32F103xx microcontrollers ที่ the Flash memory density ย่านระหว่าง 256 and 512 Kbytes.

XL-density devices คือ STM32F101xx and STM32F103xx microcontrollers ที่ the Flash memory density ย่านระหว่าง 768 Kbytes and 1 Mbyte.

Connectivity line devices คือ STM32F105xx and STM32F107xx microcontrollers.

Section นี้ใช้กับตระกูล STM32F10xxx ทั้งหมด เว้นแต่จะระบุไว้เป็นอย่างอื่น
Title: Re: STM32F1 DEBUG
Post by: tha on June 17, 2021, 03:06:32 PM
31.1 Overview

The STM32F10xxx ถูกสร้างขึ้นจาก a Cortex®-M3 core ซึ่งบรรจุ hardware extensions สำหรับr advanced debugging features. The debug extensions ยอมให้ the core ถูกหยุดทั้งบน a given instruction fetch (breakpoint) หรือ data access (watchpoint). เมื่อถูกหยุด, the core's internal state และ the system's external state อาจถูกตรวจสอบ. เมื่อการตรวจสอบเสร็จสมบูรณ์, the core และ the system อาจถูกคืนค่าและ program execution กลับมาทำงานต่อ.

The debug features ถูกใช้โดย the debugger host เมื่อเชื่อมต่อถึงและดีบัก the STM32F10xxx MCUs.

มีอินเทอร์เฟซสองแบบสำหรับการดีบักให้ได้ใช้งาน:
•    Serial wire
•    JTAG debug port

(https://i.imgur.com/4ZQJU0W.png)

Note: The debug features ที่ฝังใน the Cortex®-M3 core เป็นส่วนย่อยของ the Arm® CoreSight Design Kit.
Title: Re: STM32F1 DEBUG
Post by: tha on June 17, 2021, 04:03:26 PM
The Arm® Cortex®-M3 core จัดให้มี integrated on-chip debug support. ประกอบด้วย :
•    SWJ-DP: Serial wire / JTAG debug port
•    AHP-AP: AHB access port
•    ITM: Instrumentation trace macrocell
•    FPB: Flash patch breakpoint
•    DWT: Data watchpoint trigger
•    TPUI: Trace port unit interface (มีให้ใช้ในแพ็คเกจขนาดใหญ่กว่า, ที่พินที่ตรงกันถูกแม็ป)
•    ETM: Embedded Trace Macrocell (มีให้ใช้ในแพ็คเกจขนาดใหญ่กว่า, ที่พินที่ตรงกันถูกแม็ป)

มันยังรวมถึง debug features ที่ทุ่มเทให้ the STM32F10xxx อีกด้วย:
•    Flexible debug pinout assignment
•    MCU debug box (รองรับสำหรับ low-power modes, ควบคุมเหนือ peripheral clocks, ฯลฯ)

หมายเหตุ: สำหรับข้อมูลเพิ่มเติมเกี่ยวกับ debug functionality ที่รองรับโดย the Arm® Cortex®-M3 core, อ้างอิงถึง the Cortex®-M3 -r1p1 Technical Reference Manual และถึง the CoreSight Design Kit-r1p0 TRM (ดู Section 31.2).
Title: Re: STM32F1 DEBUG
Post by: tha on June 18, 2021, 08:50:34 AM
31.2 Reference Arm® documentation

•    Cortex®-M3 r1p1 Technical Reference Manual (TRM)
      มันมีให้ใช้ประโยชน์ได้จาก:
      http://infocenter.arm.com/
•    Arm® Debug Interface V5
•    Arm® CoreSight Design Kit revision r1p1 Technical Reference Manual

31.3 SWJ debug port (serial wire and JTAG)

The core ของ the STM32F10xxx รวม the Serial Wire / JTAG Debug Port (SWJ-DP). มันคือ an Arm® standard CoreSight debug port ที่รวม a JTAG-DP (5-pin) interface และ a SW-DP (2-pin) interface.
•    The JTAG Debug Port (JTAG-DP) จัดให้มี a 5-pin standard JTAG interface ให้กับ the AHP-AP port.
•    The Serial Wire Debug Port (SW-DP) จัดให้มี a 2-pin (clock + data) interface ให้กับ the AHP-AP port.
ใน the SWJ-DP, the two JTAG pins of the SW-DP นั้นถูกมัลติเพล็กซ์กับบางขาของ the five JTAG pins of the JTAG-DP.

(https://i.imgur.com/61cjlJo.png)

Figure 362 แสดงว่า the asynchronous TRACE output (TRACESWO) ถูกมัลติเพล็กซ์กับ TDO. นี้หมายความว่า the asynchronous trace สามารถถูกใช้เฉพาะกับ SW-DP, ไม่ JTAG-DP.
Title: Re: STM32F1 DEBUG
Post by: tha on June 18, 2021, 10:02:41 AM
31.3.1 Mechanism to select the JTAG-DP or the SW-DP

โดยค่าเริ่มต้น, the JTAG-Debug Port จะทำงาน.

ถ้า the debugger host ต้องการที่จะสวิทช์ไปยัง the SW-DP, มันต้องจัดให้มี a dedicated JTAG sequence บน TMS/TCK (แม็ปถึง SWDIO และ SWCLK ตามลำดับ) ซึ่งปิดการใช้งาน the JTAG-DP และเปิดการใช้งาน the SW-DP. วิธีนี้เป็นไปได้ที่จะเปิดใช้งาน the SWDP โดยใช้เฉพาะ the SWCLK และ SWDIO pins.

ลำดับมีดังนี้คือ:
1. ส่งมากว่า 50 TCK cycles โดยที่ TMS (SWDIO) =1
2. ส่ง the 16-bit sequence บน TMS (SWDIO) = 0111100111100111 (MSB ถูกส่งก่อน)
3. ส่งมากว่า 50 TCK cycles โดยที่ TMS (SWDIO) =1
Title: Re: STM32F1 DEBUG
Post by: tha on June 18, 2021, 10:32:19 AM
31.4 Pinout and debug port pins

The STM32F10xxx MCUs มีให้ใช้ประโยชน์ในแพ็คเกจต่างๆที่มีจำนวนที่ต่างกันของขาที่มีให้ใช้ประโยชน์. ด้วยเหตุนี้, บางฟังชั่น (ETM) ที่เกี่ยงข้องกับขาที่มีให้ใช้ประโยชน์อาจแตกต่างกันในระหว่างแพ็คเกจ.

31.4.1 SWJ debug port pins

ห้าขาถูกใช้เป็น outputs จาก the STM32F10xxx สำหรับ the SWJ-DP เป็น alternate functions ของ general-purpose I/Os. ขาเหล่านี้มีให้ใช้ประโยชน์บนทุกแพ็คเกจ.

(https://i.imgur.com/m6bkIZY.png)
Title: Re: STM32F1 DEBUG
Post by: tha on June 18, 2021, 11:43:34 AM
31.4.2 Flexible SWJ-DP pin assignment

หลังจาก RESET (SYSRESETn หรือ PORESETn), ห้าขาทั้งหมดถูกใช้สำหรับ the SWJ-DP ถูกรับมอบหมายเป็นขาที่อุทิศให้สามารถใช้ได้ทันทีโดย the debugger host (บันทึกไว้ว่า the trace outputs ไม่ถูกมอบหมายยกเว้นหากถูกโปรแกรมอย่างขัดเจนโดย the debugger host).

อย่างไรก็ตาม, the STM32F10xxx MCU จัดให้มีใช้ the AF remap and debug I/O configuration register (AFIO_MAPR) register เพื่อปิดการใช้งานบางส่วนหรือทั้งหมดของ the SWJ-DP port และดังนั้นปลดปล่อยขาที่เกี่ยวข้องนี้สำหรับ General Purpose IOs usage.  register นี้ถูกแม็ปบน an APB bridge ที่เชื่อมต่อถึง the Cortex®-M3 System Bus. การโปรแกรมของ register นี้ถูกทำโดย the user software program และไม่ใช่ the debugger host.

สามบิตควบคุมยอมให้การกำหนดค่าของ the SWJ-DP pin assignments. บิตเหล่านี้ถูกรีเซ็ตโดย the System Reset.
•    AFIO_MAPR (@ 0x40010004 in the STM32F10xxx MCU)
      –    READ: APB - No Wait State
      –    WRITE: APB - 1 Wait State ถ้า the write buffer ของ the AHB-APB bridge เต็ม.
      Bit 26:24= SWJ_CFG[2:0]
      ถูกเซ็ตและถูกเคลียร์โดย software.

บิตเหล่านี้ถูกใช้เพื่อกำหนดค่าจำนวนของขาที่ถูกมอบหมายต่อ the SWJ debug port. จุดมุ่งหมายก็คือปลดปล่อยมากที่สุดเท่าที่เป็นได้จำนวนของขาให้ถูกใช้เป็น General Purpose IOs ถ้ามีการใช้ขนาดเล็กสำหรับ the debug port.

สถานะเริ่มต้นหลังจากรีเซ็ตคือ "000" (พินทั้งหมดถูกกำหนดสำหรับ a full JTAG-DP connection). มีเพียงหนึ่งของ the 3 bits สามารถถูกเซ็ต (ห้ามเซ็ตมากกว่าหนึ่งบิต).

(https://i.imgur.com/CXt7VZ8.png)

Note: เมื่อ the APB bridge write buffer เต็ม, จะต้องใช้ one extra APB cycle เมื่อเขียน the AFIO_MAPR register. นี้เป็นเพราะว่าการปิดใช้งานของ the JTAGSW pins ถูกทำในสองไซเคิลเพื่อรับประกัน a clean level บน the nTRST และ TCK input signals ของ the core.
•    Cycle 1: the JTAGSW input signals ไปยัง the core ถูกผูกกับ 1 หรือ 0 (กับ 1 สำหรับ nTRST, TDI และ TMS, กับ 0 สำหรับ
      TCK)
•    Cycle 2: the GPIO controller รับ the control signals ของ the SWJTAG IO pins (เช่น controls of direction, pull-
      up/down, Schmitt trigger activation, ฯลฯ.).
Title: Re: STM32F1 DEBUG
Post by: tha on June 18, 2021, 05:25:42 PM
31.4.3 Internal pull-up and pull-down on JTAG pins

มันจำเป็นเพื่อให้แน่ใจว่า the JTAG input pins ไม่ได้ลอยเนื่องจากพวกมันถูกต่อโดยตรงถึง flip-flops เพื่อควบคุม the debug mode features. ความระมัดระวังเป็นพิเศษต้องถูกใช้กับ the SWCLK/TCK pin ซึ่งถูกต่อโดยตรงถึง the clock ของบาง flip-flops เหล่านี้.

เพื่อหลีกเลี่ยงระดับ IO ที่ไม่มีการควบคุมใดๆ, the device ฝัง internal pull-ups และ pull-downs บน the JTAG input pins:
•    NJTRST: Internal pull-up
•    JTDI: Internal pull-up
•    JTMS/SWDIO: Internal pull-up
•    TCK/SWCLK: Internal pull-down

เมื่อ a JTAG IO ถูกปลดปล่อยโดย the user software, the GPIO controller จะควบคุมอีกครั้ง. The reset states ของ the GPIO control registers ทำให้ the I/Os อยู่ใน the equivalent state:
•    NJTRST: Input pull-up
•    JTDI: Input pull-up
•    JTMS/SWDIO: Input pull-up
•    JTCK/SWCLK: Input pull-down
•    JTDO: AF output floatingInput floating

The software สามารถจากนั้นใช้ I/Os เหล่านี้เป็น standard GPIOs.

Note: The JTAG IEEE standard แนะนำให้เพิ่ม pull-ups บน TDI, TMS and nTRST แต่ไม่มีคำแนะนำพิเศษสำหรับ TCK. อย่างไรก็ตาม, สำหรับ JTCK, the device จำเป็นต้องมี an integrated pull-down.

การมี embedded pull-ups and pull-downs ทำให้ไม่จำเป็นต้องเพิ่ม external resistors.
Title: Re: STM32F1 DEBUG
Post by: tha on June 19, 2021, 07:59:20 AM
31.4.4 การใช้ serial wire และการปลดปล่อย the unused debug pins ไปเป็น GPIOs

เพื่อใช้ the serial wire DP เพื่อปลดปล่อยบาง GPIOs, the user software ต้องเซ็ต SWJ_CFG=010 เพียงหลังจากรีเซ็ต. นี้ปลดปล่อย PA15, PB3 and PB4 ซึ่งบัดนี้มาเป็นมีให้ใช้ประโยชน์เป็น GPIOs.

เมื่อทำการดีบัก, the host จะดำเนินการดังต่อไปนี้:
•    ภายใต้ system reset, ทุก SWJ pins ถูกกำหนด (JTAG-DP + SW-DP).
•    ภายใต้ system reset, the debugger host ส่ง the JTAG sequence เพื่อสวิทช์จาก the JTAG-DP ไปเป็น the SW-DP.
•    ยังคงอยู่ภายใต้ system reset, the debugger เซ็ต a breakpoint บน vector reset.
•    The system reset ถูกปลดปล่อยและ the Core หยุดทำงาน.
•    the debug communications ทั้งหมดจากจุดนี้ถูกทำโดยใช้ the SW-DP. JTAG pins อื่นๆสามารถถูกกำหนดใหม่เป็น GPIOs โดย
      the user software.

Note: สำหรับ user software designs, โปรดทราบว่า :
เพื่อปลดปล่อย the debug pins, โปรดจำไว้ว่าพวกมันจะถูกกำหนดค่าเป็นอันดับแรกทั้งใน input-pull-up (nTRST, TMS, TDI) หรือ pull-down (TCK) หรือ output tristate (TDO) เป็นระยะเวลาหนึ่งหลังจากรีเซ็ตจนกระทั่งทันทีที่ the user software ปลดปล่อย the pins.
เมื่อ debug pins (JTAG or SW or TRACE) ถูกแม็ป, การเปลี่ยน the corresponding IO pin configuration ใน the IOPORT controller จะไม่มีผลอะไร.
Title: Re: STM32F1 DEBUG
Post by: tha on June 20, 2021, 07:43:00 AM
31.5 STM32F10xxx JTAG TAP connection

The STM32F10xxx MCUs รวม two serially connected JTAG TAPs, the boundary scan TAP (IR เป็น 5-bit wide) และ the Cortex®-M3 TAP (IR เป็น 4-bit wide).

เพื่อเข้าถึง the TAP ของ the Cortex®-M3 สำหรับ debug purposes:
1.    อันดับแรก, จำเป็นต้องเลื่อน the BYPASS instruction ของ the boundary scan TAP.
2.    จากนั้น, สำหรับแต่ละ IR shift, the scan chain บรรจุ 9 bits (=5+4) และ the unused TAP instruction ต้องถูกเลื่อนในการ
       ใช้ the BYPASS instruction
3.    สำหรับแต่ละ data shift, the unused TAP, ซึ่งอยู่ใน BYPASS mode, เพิ่ม 1 extra data bit ใน the data scan chain.

Note: สำคัญ: เมื่อ Serial-Wire ถูกเลือกโดยใช้ the dedicated Arm® JTAG sequence, the boundary scan TAP จะถูกปิดการใช้งานโดยอัตโนมัติ (JTMS ถูกบังคับ high).

(https://i.imgur.com/sMbuEsY.png)
Title: Re: STM32F1 DEBUG
Post by: tha on June 20, 2021, 09:48:24 AM
31.6 ID codes and locking mechanism

มีหลาย ID codes ภายใน the STM32F10xxx MCUs. ST แนะนำอย่างแข็งขัน tools designers ให้ล็อค debuggers ของพวกมันโดยใช้ the MCU DEVICE ID code มีตำแหน่งใน the external PPB memory แม็ปที่ address 0xE0042000

31.6.1 MCU device ID code

The STM32F10xxx MCUs รวม an MCU ID code. ID นี้ระบุ the ST MCU partnumber และ the die revision. มันเป็นส่วนหนึ่งของ the DBG_MCU component และถูกแม็ปบน the external PPB bus (ดู Section 31.16). code นี้เข้าถึงได้โดยใช้ the JTAG debug port (สี่หรือห้า pins) หรือ the SW debug port (สอง pins) หรือโดย the user software. มันเข้าถึงได้แม้ในขณะที่ the MCU อยู่ภายใต้ system reset.

มีเพียง the DEV_ID[11:0] ที่ถูกใช้สำหรับระบุตัวตนโดย the debugger/programmer tools.

(https://i.imgur.com/tf50WLH.png)

Bits 31:16 REV_ID[15:0] Revision identifier
ฟิลด์นี้แสดงให้เห็น the revision of the device:
In low-density devices:
   – 0x1000 = Revision A
In medium-density devices:
   – 0x0000 = Revision A
   – 0x2000 = Revision B
   – 0x2001 = Revision Z
   – 0x2003 = Revision 1, 2, 3, X or Y
In high-density devices:
   – 0x1000 = Revision A or 1
   – 0x1001 = Revision Z
   – 0x1003 = Revision 1, 2, 3, X or Y
In XL-density devices:
   – 0x1000 = Revision A or 1
In connectivity line devices:
   – 0x1000 = Revision A
   – 0x1001 = Revision Z

Bits 15:12 Reserved, must be kept at reset value.

Bits 11:0 DEV_ID[11:0]: Device identifier
ฟิลด์นี้แสดงให้เห็น the device ID.
For low-density devices, the device ID is 0x412
For medium-density devices, the device ID is 0x410
For high-density devices, the device ID is 0x414
For XL-density devices, the device ID is 0x430
For connectivity devices, the device ID is 0x418
Title: Re: STM32F1 DEBUG
Post by: tha on June 20, 2021, 10:18:52 AM
31.6.2 Boundary scan TAP

JTAG ID code


The TAP ของ the STM32F10xxx BSC (boundary scan) รวม a JTAG ID code เท่ากับ
•    In low-density devices:
      –    0x06412041 = Revision A
•    In medium-density devices:
      –    0x06410041 = Revision A
      –    0x16410041 = Revision B, Revision Z and Revision Y
•    In high-density devices:
      –    0x06414041 = Revision A, Revision Z and Revision Y
•    In XL-density devices
      –    0x06430041 = Revision A
•    In connectivity line devices:
      –    0x06418041 = Revision A and Revision Z
Title: Re: STM32F1 DEBUG
Post by: tha on June 20, 2021, 10:50:22 AM
31.6.3 Cortex®-M3 TAP

The TAP ของ the Arm® Cortex®-M3 รวม a JTAG ID code. ID code นี้คือ the Arm® default one และยังไม่ถูกแก้ไขเลย. code นี้เข้าถึงได้เฉพาะโดย the JTAG Debug Port, มันคือ 0x3BA00477 (ตรงกันกับ Cortex®-M3 r1p1-01rel0, ดู Section 31.2).

31.6.4 Cortex®-M3 JEDEC-106 ID code

The Arm® Cortex®-M3 รวม a JEDEC-106 ID code. มันอยู่ในตำแหน่งใน the 4 KB ROM table ที่แม็ปบน the internal PPB bus ที่ address 0xE00FF000_0xE00FFFFF.

code นี้เข้าถึงได้โดย the JTAG Debug Port (4 to 5 pins) หรือโดย the SW Debug Port (two pins) หรือโดย the user software.
Title: Re: STM32F1 DEBUG
Post by: tha on June 20, 2021, 11:22:25 AM
31.7 JTAG debug port

A standard JTAG state machine ถูกจัดให้มีใช้กับ a 4-bit instruction register (IR) และ five data registers (สำหรับรายละเอียดเต็ม, อ้างอิงถึง the Cortex®-M3 r1p1 Technical Reference Manual (TRM), สำหรับการอ้างอิง, ดู Section 31.2).

(https://i.imgur.com/HSejC2v.png)

(https://i.imgur.com/xC6qPtP.png)
Title: Re: STM32F1 DEBUG
Post by: tha on June 23, 2021, 07:40:21 AM
31.8 SW debug port

31.8.1 SW protocol introduction

synchronous serial protocol นี้ใช้สองขา :
•    SWCLK: clock จาก host ถึง target
•    SWDIO: bidirectional

The protocol ยอมให้ two banks of registers (DPACC registers and APACC registers) ถูกอ่านและเขียนถึง.

Bits ถูกส่งถ่าย LSB-first บน the wire.

สำหรับ SWDIO bidirectional management, the line ต้องถูก pulled-up บน the board (100 KΩ ถูกแนะนำโดย Arm®).

แต่ละครั้งที่ทิศทางของ SWDIO เปลี่ยนใน the protocol, a turnaround time ถูกใส่ตรงที่ the line ไม่ถูกขับโดย the host หรือ the target. โดยค่าเริ่มต้น, turnaround time นี้คือ one bit time, อย่างไรก็ตามสามารถที่จะปรับโดยการกำหนดค่า the SWCLK frequency.
Title: Re: STM32F1 DEBUG
Post by: tha on June 23, 2021, 08:58:13 AM
31.8.2 SW protocol sequence

แต่ละลำดับประกอบด้วย three phases:
1.    Packet request (8 bits) ถูกส่งโดย the host
2.    Acknowledge response (3 bits) ถูกส่งโดย  the target
3.    Data transfer phase (33 bits) ถูกส่งโดย the host หรือ the target

(https://i.imgur.com/E5tF5MI.png)

อ้างอิงถึง the Cortex®-M3 r1p1 TRM สำหรับคำอธิบายโดยละเอียดของ DPACC and APACC registers.

The packet request ถูกตามด้วย the turnaround time เสมอ(ค่าเริ่มต้น 1 bit) ตรงที่ไม่ทั้ง the host หรือ target ขับ the line.

(https://i.imgur.com/TWOxMPz.png)

The ACK Response ต้องถูกตามด้วย a turnaround time เฉพาะถ้ามันเป็น a READ transaction หรือถ้า a WAIT หรือ FAULT acknowledge ถูกรับแล้ว.

(https://i.imgur.com/3FR519J.png)

The DATA transfer ต้องถูกตามด้วย a turnaround time เฉพาะถ้ามันเป็น a READ transaction.
Title: Re: STM32F1 DEBUG
Post by: tha on June 23, 2021, 10:23:19 AM
31.8.3 SW-DP state machine (reset, idle states, ID code)

The State Machine ของ the SW-DP มี an internal ID code ซึ่งระบุ the SW-DP. มันเป็นไปตาม the JEP-106 standard. ID code นี้เป็นระหัสเริ่มต้นของ Arm® ตัวหนึ่งและถูกเซ็ตเป็น 0x1BA01477 (ตรงกันกับ Cortex®-M3 r1p1).

Note: บันทึกไว้ว่า the SW-DP state machine จะไม่ทำงานจนกระทั่ง the target อ่าน ID code นี้.

•    The SW-DP state machine อยู่ใน RESET STATE อย่างใดอย่างหนึ่งหลังจาก power-on reset, หรือหลังจาก the DP ได้สวิทช์
      จาก JTAG ไปยัง SWD หรือหลังจาก the line เป็น high เป็นเวลามากกว่า 50 cycles
•    The SW-DP state machine อยู่ใน IDLE STATE ถ้า the line เป็น low เป็นเวลาอย่างน้อยสองไซเคิลหลังจาก RESET state.
•    After RESET state, จำเป็นต้องเข้าสู่ไปใน an IDLE state ก่อนและเพื่อดำเนินการ a READ เข้าถึงของ the DP-SW ID CODE
      register. มิฉะนั้น, the target จะปล่อยออก a FAULT acknowledge response บนการส่งถ่ายอื่น.

รายละเอียดที่มากขึ้นของ the SW-DP state machine สามารถถูกพบใน the Cortex®-M3 r1p1 TRM และ the CoreSight Design Kit r1p0 TRM.
Title: Re: STM32F1 DEBUG
Post by: tha on June 24, 2021, 08:33:02 AM
31.8.4 DP and AP read/write accesses

•    Read เข้าถึงไปยัง the DP ไม่ถูกโพสต์: the target response สามารถถูกทำทันที (ถ้า ACK=OK) หรือสามารถถูกหน่วงเวลา (ถ้า
      ACK=WAIT).
•    Read เข้าถึงไปยัง the AP ถูกโพสต์. นี้หมายความว่าผลของ the access ถูกส่งคืนบน the next transfer. ถ้า the next access ที่
      ถูกทำไม่ใช่ an AP access, ดังนั้น the DP-RDBUFF register ต้องถูกอ่านเพื่อให้ได้ the result.
      The READOK flag ของ the DP-CTRL/STAT register ถูกอัปเดตบนทุกๆ AP read access หรือ RDBUFF read request เพื่อ
      ให้ทราบหาก the AP read access สำเร็จแล้ว.
•    The SW-DP จัดให้มีใช้ a write buffer (สำหรับทั้ง DP หรือ AP writes), ที่เปิดการใช้งานมันเพื่อยอมรับ a write operation แม้ว่า
      เมื่อ transactions อื่นยังคงค้างอยู่. ถ้า the write buffer เต็ม, the target acknowledge response จะเป็น "WAIT". ด้วยข้อ
      ยกเว้นของ IDCODE read หรือ CTRL/STAT read หรือ ABORT write ซึ่งถูกยอมรับถึงแม้ว่า the write buffer เต็ม.
•    เนื่องจาก the asynchronous clock domains SWCLK and HCLK, สอง extra SWCLK cycles ถูกต้องการหลังจาก a write
      transaction (หลังจาก the parity bit) เพื่อทำให้การเขียนเป็นผลภายใน. ไซเคิลเหล่านี้ควรถูกใช้ในขณะที่กำลังขับ the line low
      (IDLE state)
      สิ่งนี้มีความสำคัญอย่างยิ่งเมื่อเขียน the CTRL/STAT สำหรับ a power-up request. ถ้า the next transaction (ต้องการ a
      power-up) เกิดขึ้นทันที, มันจะล้มเหลว.
Title: Re: STM32F1 DEBUG
Post by: tha on June 24, 2021, 09:52:07 AM
31.8.5 SW-DP registers

เข้าถึง registers เหล่านี้ถูกเริ่มต้นเมื่อ APnDP=0

(https://i.imgur.com/kM4rWYs.png)

(https://i.imgur.com/iI9mSGQ.png)

31.8.6 SW-AP registers

เข้าถึง registers เหล่านี้ถูกเริ่มต้นเมื่อ APnDP=1
มี AP Registers จำนวนมาก (ดู AHB-AP) ที่ถูกติดต่อที่อยู่เป็นการรวมของ:
•    The shifted value A[3:2]
•    ค่าปัจจุบันของ the DP SELECT register
Title: Re: STM32F1 DEBUG
Post by: tha on June 25, 2021, 09:13:24 AM
31.9 AHB-AP (AHB access port) - ใช้ได้สำหรับทั้ง JTAG-DP and SW-DP

คุณสมบัติ:
•    System access ไม่ขึ้นอยู่กับ the processor status.
•    อยางใดอย่างหนึ่ง SW-DP หรือ JTAG-DP เข้าถึง AHB-AP.
•    The AHB-AP เป็น an AHB master ใน the Bus Matrix. ดังนั้น, มันสามารถเข้าถึงทุก the data buses (Dcode Bus, System
      Bus, internal and external PPB bus) แต่ the ICode bus.
•    Bitband transactions ถูกรองรับ.
•    AHB-AP transactions ข้าม the FPB.

The address ของ the 32-bits AHP-AP resisters เป็น 6-bits wide (มากถึง 64 words หรือ 256 bytes) และประกอบด้วย :
   c)    Bits [7:4] = the bits [7:4] APBANKSEL ของ the DP SELECT register
   d)    Bits [3:2] = the 2 address bits ของ A[3:2] ของ the 35-bit packet ร้องขอสำหรับ SW-DP.

The AHB-AP ของ the Cortex®-M3 ประกอบด้วย 9 x 32-bits registers:

(https://i.imgur.com/m0ravB7.png)
Title: Re: STM32F1 DEBUG
Post by: tha on June 25, 2021, 09:48:16 AM
31.10 Core debug

Core debug ถูกเข้าถึงผ่านทาง the core debug registers. Debug เข้าถึง registers เหล่านี้โดยทาง the Advanced High-performance Bus (AHB-AP) port. The processor สามารถเข้าถึง registers เหล่านี้โดยตรงบน the internal Private Peripheral Bus (PPB).

มันประกอบด้วย 4 registers:

(https://i.imgur.com/9Gq9P9d.png)

Note: สำคัญ: registers เหล่านี้ไม่ถูกรีเซ็ตโดย a system reset. พวกมันถูกรีเซ็ตเฉพาะโดย a power-on reset.

อ้างอิงถึง the Cortex®-M3 r1p1 TRM สำหรับรายละเอียดที่มากขึ้น.

เพื่อ Halt บน reset, จำเป็นต้อง:
•    เปิดการใช้งาน the bit0 (VC_CORRESET) of the Debug and Exception Monitor Control Register
•    เปิดการใช้งาน the bit0 (C_DEBUGEN) of the Debug Halting Control and Status Register.
Title: Re: STM32F1 DEBUG
Post by: tha on June 26, 2021, 07:38:00 AM
31.11 ความสามารถของ the debugger host ในการเชื่อมต่อภายใต้ system reset

The reset system ของ the STM32F10xxx MCU ประกอบด้วยแหล่งการรีเซ็ตต่อไปนี้ :
•    POR (power-on reset) ซึ่งถือสิทธิ์ a RESET ทุกครั้งที่ power-up.
•    Internal watchdog reset
•    Software reset
•    External reset

The Cortex®-M3 ทำให้ต่างกันในการรีเซ็ตของ the debug part (โดยทั่วไปคือ PORRESETn) และอีกตัว (SYSRESETn)

ด้วยวิธีนี้ , มันสามารถเป็นได้สำหรับ the debugger ที่จะเชื่อมต่อภายใต้ System Reset, การโปรแกรม the Core Debug Registers เพื่อหยุด the core เมื่อมีการเฟทช์ the reset vector. ดังนั้น the host สามารถปลดปล่อย the system reset และ the core จะหยุดโดยทันทีโดยไม่มีการปฏิบัติคำสั่งใดๆ. นอกจากนี้, มันสามารถเป็นได้ที่จะโปรแกรมคุณลักษณะการดีบักใดๆภายใต้ System Reset.

Note: ขอแนะนำอย่างยิ่งให้ the debugger host เชื่อมต่อ (เซ็ต a breakpoint ใน the reset vector) ภายใต้ system reset.
Title: Re: STM32F1 DEBUG
Post by: tha on June 28, 2021, 07:34:11 AM
31.12 FPB (Flash patch breakpoint)

The FPB unit:
•    จัดให้มีใช้ hardware breakpoints
•    patches code และ data จาก code space ไปยัง system space. คุณลักษณะนี้ช่วยให้ความเป็นไปได้ในการแก้ไข software
      bugs ที่อยู่ใน the Code Memory Space.

การใช้ a Software Patch หรือ a Hardware Breakpoint เป็นเอกสิทธิ์เฉพาะตัว.

The FPB ประกอบด้วย:
•    2 literal comparators สำหรับจับคู่กับ literal ที่โหลดจาก Code Space และแม็ปซ้ำไปยัง a corresponding area ใน the
      System Space.
•    6 instruction comparators สำหรับจับคู่กับ instruction ที่เฟทช์จาก Code Space. พวกมันสามารถถูกใช้อย่างใดอย่างหนึ่งเพื่อ
      แม็บซ้ำไปยัง a corresponding area ใน the System Space หรือเพื่อสร้าง a Breakpoint Instruction ไปยัง the core.
Title: Re: STM32F1 DEBUG
Post by: tha on June 28, 2021, 07:53:43 AM
31.13 DWT (data watchpoint trigger)

The DWT unit ประกอบด้วย four comparators. พวกมันสามารถกำหนดค่าเป็น :
•    a hardware watchpoint or
•    a trigger to an ETM or
•    a PC sampler or
•    a data address sampler

The DWT จัดให้มีบางวิธีการเพื่อให้บาง profiling informations อีกด้วย. สำหรับสิ่งนี้, บาง counters สามารถเข้าถึงได้เพื่อให้จำนวนของ:
•    Clock cycle
•    Folded instructions
•    Load store unit (LSU) operations
•    Sleep cycles
•    CPI (clock per instructions)
•    Interrupt overhead