STM32F1 DEBUG

Started by tha, June 17, 2021, 02:42:38 PM

Previous topic - Next topic

tha

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 ทั้งหมด เว้นแต่จะระบุไว้เป็นอย่างอื่น

tha

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



Note: The debug features ที่ฝังใน the Cortex®-M3 core เป็นส่วนย่อยของ the Arm® CoreSight Design Kit.

tha

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).


tha

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.



Figure 362 แสดงว่า the asynchronous TRACE output (TRACESWO) ถูกมัลติเพล็กซ์กับ TDO. นี้หมายความว่า the asynchronous trace สามารถถูกใช้เฉพาะกับ SW-DP, ไม่ JTAG-DP.

tha

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

tha

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. ขาเหล่านี้มีให้ใช้ประโยชน์บนทุกแพ็คเกจ.


tha

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 สามารถถูกเซ็ต (ห้ามเซ็ตมากกว่าหนึ่งบิต).



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, ฯลฯ.).

tha

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.