这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 行业应用 » 汽车电子 » 【S32K3XX】FLASH的访问锁保护机制

共1条 1/1 1 跳转至

【S32K3XX】FLASH的访问锁保护机制

高工
2026-02-03 20:17:10     打赏

【简介】

             在之前的S32K3XX芯片的 PFLAH/DFLASH 的写入擦除处理前先要解除锁保护,然后才能进行操作。我们先看下解锁函数的的源代码。

/**
 * Function Name    C40_Ip_ClearLockProtect
 * Description      Unlocks the selected sector for the requesting core if possible
 */
void C40_Ip_ClearLockProtect(C40_Ip_VirtualSectorsType VirtualSector)
{
    uint32 RegisterIndex;
#ifdef C40_IP_MULTIPFLASH_FEATURE
    uint32 BlockNumber;
#else
    uint32 SectorIndex;
#endif

    /* All checks passed - set lock bit */
    if ((uint32)VirtualSector < C40_IP_MAX_DATA_SECTOR)
    {
        /* Sector is in the Data Block */
        C40_Ip_pPFlashBaseAddress->PFCBLK_SPELOCK[PFLASH_PFCBLK_DATA_ORDER] &= ~C40_Ip_u32BitPosition;
    }
    else if (C40_IP_MAX_VIRTUAL_SECTOR == (uint32)VirtualSector)
    {
        /* Sector is in Utest */
        C40_Ip_pPFlashBaseAddress->PFCBLKU_SPELOCK[0] &= ~C40_Ip_u32BitPosition;
    }
    /* Sector is in Code Block */
    else
    {
#ifdef C40_IP_MULTIPFLASH_FEATURE
        /* Get block number of sector */
        BlockNumber = C40_Ip_GetCodeBlockNumber(C40_Ip_GetBaseAddressOfSector(VirtualSector));

        /* Identify the index of lock register */
        RegisterIndex = C40_Ip_Transform_Block_Number(BlockNumber);
#else
        /* Get SectorIndex */
        /* For example: VirtualSector = 32 --> SectorIndex = 0 */
        /*              VirtualSector = 33 --> SectorIndex = 1 */
        /*              VirtualSector = 128--> SectorIndex = 96 */
        SectorIndex = (uint32)VirtualSector - C40_IP_MAX_DATA_SECTOR;

        /* Identify the index of lock register */
        RegisterIndex = SectorIndex / C40_IP_NUM_OF_SECTOR_PER_BLOCK;

#endif /* C40_IP_MULTIPFLASH_FEATURE */

#ifdef C40_IP_MULTIPFLASH_FEATURE
        /* Determine the Block is belong to Block 1M */
        if (C40_Ip_IsBlockBelongToPFLASH1(BlockNumber))
        {
            /* Block 1M - Use the PFLASH_1 */
            /* For 1 MB blocks, the first 768KB (96 sectors 8KB) is protected with super sector granularity */
            if (C40_Ip_IsSuperSector(VirtualSector))
            {
                /* Sector is in the Super Sector zone */
                C40_Ip_pPFlashBaseAddress1->PFCBLK_SSPELOCK[RegisterIndex] &= ~ C40_Ip_u32BitPosition;
            }
            else
            {
                /* Sector is in the 8KB Sector zone */
                C40_Ip_pPFlashBaseAddress1->PFCBLK_SPELOCK[RegisterIndex] &= ~ C40_Ip_u32BitPosition;
            }
        }
        else
#endif /* C40_IP_MULTIPFLASH_FEATURE */
        {
            /* Block 2M - Use the PFLASH_0 */
            /* For 2 MB blocks, the first 1792KB (224 sectors 8KB) is protected with super sector granularity */
            if (C40_Ip_IsSuperSector(VirtualSector))
            {
                /* Sector is in the Super Sector zone */
                C40_Ip_pPFlashBaseAddress->PFCBLK_SSPELOCK[RegisterIndex] &= ~ C40_Ip_u32BitPosition;
            }
            else
            {
                /* Sector is in the 8KB Sector zone */
                C40_Ip_pPFlashBaseAddress->PFCBLK_SPELOCK[RegisterIndex] &= ~ C40_Ip_u32BitPosition;
            }
        }
    }
}

   

上述代码主要根据memmory 的类型的不同来操作对应的解锁寄存器。

UTEST 区域的解锁是通过如下的寄存器来配置,reset 后值为1 lock 状态。

image.png

PFLASH 的 sector  也是类似通过如下的寄存器来锁定。

image.png

上述的sector 锁状态默认为1,解锁后对应的值为0,如下为本地解锁sector 0 对应解锁状态bit 为0、

image.png


S32K3 flash 被划分为多个block,对应的而每个block 有一组寄存器来配置对应的sector 锁定配置。

image.png


           


共1条 1/1 1 跳转至

回复

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