gpt4 book ai didi

embedded - 如何在Cortex-M4 MCU上捕获和查看ITM跟踪信息?

转载 作者:行者123 更新时间:2023-12-04 13:38:15 24 4
gpt4 key购买 nike

我想捕获,解码和查看Cortex-M4 MCU(在我的情况下为Atmel SAM4S)的ITM跟踪信息。特别是,我想捕获异常和用户跟踪数据(相对于我板上的其他信号)(即在同一时间线上显示所有信号和跟踪信息)。

最佳答案

可以使用以下步骤完成此操作:

  • 将调试器置于SWD模式下。如果在Linux上使用J-Link Segger,则可以使用JLinkGDBServer -if swd
  • 完成
  • 向MCU添加代码以启用跟踪。将比特率设置为适合您需要的值(我使用8 MHz)。示例Ada代码如下。
  • 使用逻辑分析器从SAM4S处理器捕获TRACESWO线上的跟踪数据。我使用了100 MHz采样率的Saleae Logic Pro 16。
  • 将数据转换为sigrok可用的格式。使用Saleae捕获数据,包括以下步骤:
  • 仅使用前8个 channel 进行捕获(因此每个样本导出一个字节)。
  • 将数据以二进制格式导出到trace.bin,为每个样本写入一个字节。
  • 使用以下命令转换为trace.sr文件:
    sigrok-cli -i trace.bin -I binary:samplerate=100000000,numchannels=4 -o trace.sr
  • 在PulseView中打开trace.sr文件。
  • 将UART解码器添加到TRACESWO channel ,比特率8000000。
  • 堆栈ARM-ITM解码器。

  • 有关更多信息,请参见 http://www.sigrok.org/blog/new-protocol-decoders-arm-tpiu-itm-etmv3

    SAM4S跟踪的示例Ada代码:

    sam4s-trace.ads:
    with Interfaces;

    package SAM4S.Trace is
    pragma Preelaborate;

    type Channel_Type is new Integer range 0 .. 31;
    type Value_Type is new Interfaces.Unsigned_32;

    procedure Initialize;

    procedure Put (Channel : Channel_Type;
    Value : Value_Type);

    procedure Put (Channel : Channel_Type;
    Message : String);
    end SAM4S.Trace;

    sam4s-trace.adb:
    with System;
    with System.Storage_Elements; use System.Storage_Elements;

    package body SAM4S.Trace is
    procedure Initialize is
    ITM_LAR : Interfaces.Unsigned_32
    with Address => System'To_Address (16#E000_0FB0#), Volatile;

    ITM_TCR : Interfaces.Unsigned_32
    with Address => System'To_Address (16#E000_0E80#), Volatile;

    ITM_TER : Interfaces.Unsigned_32
    with Address => System'To_Address (16#E000_0E00#), Volatile;

    ITM_TPR : Interfaces.Unsigned_32
    with Address => System'To_Address (16#E000_0E40#), Volatile;

    DEMR : Interfaces.Unsigned_32
    with Address => System'To_Address (16#E000_EDFC#), Volatile;

    TPIU_SPP : Interfaces.Unsigned_32
    with Address => System'To_Address (16#E004_00F0#), Volatile;

    TPIU_FFCR : Interfaces.Unsigned_32
    with Address => System'To_Address (16#E004_0304#), Volatile;

    TPIU_ACPR : Interfaces.Unsigned_32
    with Address => System'To_Address (16#E004_0010#), Volatile;

    DWT_CTRL : Interfaces.Unsigned_32
    with Address => System'To_Address (16#E000_1000#), Volatile;

    use Interfaces;

    begin
    -- Enable write access via the Lock Access Register.
    ITM_LAR := 16#C5AC_CE55#;
    -- Enable the ITM, enable SWO mode behavior, enable synchronization
    -- packets, enable DWT event submission, enable timestamps.
    ITM_TCR := 16#0001_001F#;
    -- Enable access in user mode to all 32 channels.
    ITM_TPR := 16#0000_0000#;
    -- Enable all 32 trace channels.
    ITM_TER := 16#FFFF_FFFF#;

    -- Set TRCENA bit to 1 in Debug Exception and Monitor Register.
    DEMR := DEMR or 16#0100_0000#;

    -- Select NRZ serial wire output.
    TPIU_SPP := 16#0000_0002#;

    -- Deactivate formatter.
    TPIU_FFCR := 16#0000_0100#;

    -- Set prescalar (/10).
    -- TPIU_ACPR := 16#0000_0009#;

    -- Set prescalar (/15).
    TPIU_ACPR := 14;

    -- Enable exception trace and exception overhead.
    DWT_CTRL := DWT_CTRL or 16#0005_0000#;

    end Initialize;

    procedure Put (Channel : Channel_Type;
    Value : Value_Type) is
    Port_Reg : Value_Type with Address => System'To_Address (16#E000_0000#) +
    4 * Channel_Type'Pos (Channel), Volatile;
    begin
    -- Port register lsb is set when the the FIFO can accept at least one
    -- word.
    while Port_Reg = 0 loop
    null;
    end loop;
    Port_Reg := Value;
    end Put;

    procedure Put (Channel : Channel_Type;
    Message : String) is
    Port_Reg : Value_Type with Address => System'To_Address (16#E000_0000#) +
    4 * Channel_Type'Pos (Channel), Volatile;
    begin
    -- Port register lsb is set when the the FIFO can accept at least one
    -- word.
    for Index in Message'Range loop
    while Port_Reg = 0 loop
    null;
    end loop;
    Port_Reg := Value_Type (Character'Pos (Message (Index)));
    end loop;
    end Put;

    end SAM4S.Trace;

    关于embedded - 如何在Cortex-M4 MCU上捕获和查看ITM跟踪信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32123443/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com