This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] RM46L852:在 TI Hercules MCU 上启用 ARM 性能计数器

Guru**** 2388050 points
Other Parts Discussed in Thread: HALCOGEN
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/1191603/rm46l852-enabling-the-arm-performance-counter-on-ti-hercules-mcu

器件型号:RM46L852

您好!

据我了解、基于 Cortex-A 和 Cortex-R 的高端 ARM 处理器包含性能监控单元(PMU)、可提供周期计数等信息。
是否有办法在 TI RM46上激活此性能计数器?  

参考: ARM Cortex-R4参考 

遵循此应用手册: https://www.ti.com/lit/fs/spna138a/spna138a.pdf?ts=1675176362803
我得到以下结果

_pmuInit_();
_pmuEnableCountersGlobal_();
_pmuSetCountEvent_(pmuCOUNTER0, PMU_CYCLE_COUNT); // PMU_INST_ARCH_EXECUTED

_pmuResetCounters_();
_pmuStartCounters_(pmuCOUNTER0);
cycles_PMU_start = _pmuGetEventCount_(pmuCOUNTER0);

code_to_be_measured();

_pmuStopCounters_(pmuCOUNTER0);
cycles_PMU_end = _pmuGetEventCount_(pmuCOUNTER0);
cycles_PMU_measure = cycles_PMU_end - cycles_PMU_start;

也就是说、当我将这个代码放置在 sys_main.c 中时、它看起来不起作用:cycles_PMU_measure 仍然为0。

感谢您的任何帮助。

最棒的
Gabriel

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好 Gabriel、

    请使用周期计数器对 PMU 周期进行计数:

        /*Reset Cycle Counter */
        _pmuResetCounters_();
    
        /*Start Cycle Counter */
        _pmuStartCounters_(pmuCYCLE_COUNTER);
    
        code_to_be_measured();
    
        /*Stop Cycle Counter */
        _pmuStopCounters_(pmuCYCLE_COUNTER);
    
        /* read the CNNT cycle */
        cycles= _pmuGetCycleCount_();
  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    请参考我的备注和示例:

    https://software-dl.ti.com/hercules/hercules_docs/latest/hercules/Examples/Examples.html#using-performance-monitoring-unit-pmu-to-evaluate-code-efficiency

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好 QJ、

    你是对的、这是有效的! 我觉得我发现的应用手册已经过时了。

    我唯一的问题是、在用户模式(CPRS M:10000)下、调用_pmuGetCyclCount 会使我的 MCU 崩溃。
    我假设这是因为 MRC 指令接触 P15 (这与 CP15是一样吗?) P15必须受到 MPU 的保护。

    您知道 P15在内存中的位置吗、我在 参考手册中找不到它。

    我刚刚注意到您的指南提到了_pmuEnableUserMode_();
    这正是我需要的! 唯一的问题是、它在我的 HalCoGen 生成的 sys_PMU.h 中似乎不存在

    您有用于此函数的汇编文件吗?

    感谢您的帮助、
    Gabriel

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    [引用 userid="550002" URL"~/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/1191603/rm46l852-enabling-the-arm-performance-counter-on-ti-hercules-mcu/4492106 #4491106"]这是否与 CP15相同?

    是的、MRC/MCR 指令中的 P15代表 CP15寄存器。

    在特权模式下、PMU 寄存器始终可访问。 您可以使用用户使能(PMUSERENR) 寄存 器使所有 PMU 寄存器(除了中断使能置位(PMINTENSET)和中断使能清零(PMINTENCLR)寄存器、这些寄存器在用户模式下均可访问。

    [引用 userid="550002" URL"~/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/1191603/rm46l852-enabling-the-arm-performance-counter-on-ti-hercules-mcu/4492106 #4491106"]您是否知道 P15在内存中的位置,我在 参考手册中找不到它。[/quot]

    它不在 ARM Cortex-R TRM 中:ARM DDI 0363C

    https://developer.arm.com/documentation/ddi0363/g/Events-and-Performance-Monitor

    [引用 userid="550002" URL"~/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/1191603/rm46l852-enabling-the-arm-performance-counter-on-ti-hercules-mcu/4492106 #4491106"]您是否具有此函数的汇编?

    您可以从链接下载示例项目。

    /* Enables User mode access to the PMU (must be called in a privileged mode)
     ***/
    void _pmuEnableUserMode_(void)
    {
        asm(" MRC     p15, #0, r0, c9, c14, #0"); //Read PMUSERENR Register
        asm(" ORR     r0, r0, #0x01");            //Set EN bit (bit 0)
        asm(" MCR     p15, #0, r0, c9, c14, #0"); //Write PMUSERENR Register
        asm(" ISB");                              //Synchronize context
    }
  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好 QJ、  

    我已经做了一些测试、这完全解决了我的问题。
    感谢你能抽出时间。

    此致、
    Gabriel