这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 行业应用 » 汽车电子 » 【S32K3XX】Cache属性信息代码获取

共1条 1/1 1 跳转至

【S32K3XX】Cache属性信息代码获取

高工
2025-12-28 20:33:39     打赏

【简介】

本地使用jlink 连接到S32K3系列芯片的时候,Jlink 的log 里会有如下的Cache 信息。

image.png

在此贴中(【S32K3】Cache 接口代码解析) 有对M7 的 cache 做过介绍,从 Jlink 的日志中可以看出Cache 的属性信息,Cache 的这些属性信息在芯片设计阶段已经固定了,我们可以通过CM7 的

 SCB->CCSIDR(Cache Size ID Register)

Provides information about the size and behavior of the instruction or datacache selected by the CSSELR. Architecturally, there can be up to eight levels of cache, containing instruction, data, or unified caches. This processor contains L1 instruction and data caches only.

SCB->CCSELR (Cache Size Selection Register)

Holds the value that the processor uses to select the CSSELR to use.

我们可以通过上述的两个寄存器来获取芯片的Cache 属性信息,CCSIDR 寄存器中属性信息说明如下;

image.png

其中寄存器中的WT/WB/RA/WA cache 的缓存策略说明可以查看此贴的说明(【S32K3XX】Cache 缓存策略

SCB->CCSELR  寄存器说明如下:

image.png

我们按照寄存器的说明编写如下的代码 来获取XS32K3XX 芯片的Cache 属性信息。

#if defined (CPU_S32K324)
#include "S32K324_COMMON.h"
#endif
#include "core_cm7.h"
#include "printf.h"

const uint16_t cache_line_size_lookup[8] = {16U, 32U, 64U, 128U, 256U, 512U, 1024U, 2048U};

void cmsis_cache_information(uint32_t cache_type)
{
    if(cache_type) /* Instruction cache. */
    {
        SCB->CSSELR |= SCB_CSSELR_IND_Msk;
    }
    else/* Data cache. */
    {
        SCB->CSSELR &= ~SCB_CSSELR_IND_Msk;
    }

    uint32_t ccsidr = SCB->CCSIDR;
    uint32_t line_size = cache_line_size_lookup[((ccsidr & SCB_CCSIDR_LINESIZE_Msk) >> SCB_CCSIDR_LINESIZE_Pos)];
    uint32_t associativity = ((ccsidr & SCB_CCSIDR_ASSOCIATIVITY_Msk) >> SCB_CCSIDR_ASSOCIATIVITY_Pos) + 1U;
    uint32_t num_sets = ((ccsidr & SCB_CCSIDR_NUMSETS_Msk) >> SCB_CCSIDR_NUMSETS_Pos) + 1U;
    uint32_t cache_size = (line_size * associativity * num_sets);

    PRINTF("%s Information:\r\n", cache_type ? "I-Cache" : "D-Cache");
    PRINTF("  Line Size: %lu bytes\r\n", line_size);
    PRINTF("  Associativity: %lu ways\r\n", associativity);
    PRINTF("  Number of Sets: %lu\r\n", num_sets);
    PRINTF("  Total Cache Size: %lu bytes\r\n", cache_size);
}

上述代码打印的ICACHE 和 DCACHE 的属性信息如下,和JLINK输出的一致。

image.png


           


共1条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]