这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 活动中心 » 板卡试用 » 【分享开发笔记,赚取电动螺丝刀】【S32K3 HSE】MU模块使用

共1条 1/1 1 跳转至

【分享开发笔记,赚取电动螺丝刀】【S32K3 HSE】MU模块使用

高工
2025-07-17 08:45:32     打赏

【简介】

S32K3 系列MCU 内部集成了HSE CORE,HSE CORE 可以对其他核(HOST)  提供安全启动,加密算法等服务,其中host 和 HSE 之间数据信息的交互是通过MU(Messaging Unit)模块来实现的。芯片设计时最多支持MU0-MU4 5个instance,其中MU0/MU1 为固定为HSE 和 HOST 进行通讯数据交互来使用。

image.png

以下的host interface  的实现就是依赖MU模块实现的、

image.png

每个MU 分为A/B 两端,可以通过A 端的TRi 寄存器发送数据 B 端通过RRi 寄存器来读取数据,完成数据的交互,A 端通过FCR 发送事件 B端通过 FSR 来获取到对应的事件,以下时HSE 文档对交互的说明。

image.png

对应的交互流程从下图可以更直接的看出

image.png

image.png

从上述的流程看涉及的寄存器也只有几个对MU 的的封装就是通过上述的寄存器实现host interface 来进行通讯。

【HSE 通讯数据结构】

HSE 和 host 之间通讯通过如下的结构体,其中srvId 和 srvMetaData 为固定的数据,通过srvId  不同对应的hsesrv union 的机构也有差异根据不同的srvId  来解析数据

typedef struct
{
    /** @brief The service ID of the HSE message */
    hseSrvId_t        srvId;
    /** @brief The service metadata (e.g. priority)*/
    hseSrvMetaData_t  srvMetaData;
    /** @brief The service ID will identify a service in the following union */
    union
    {
        /*-------- HSE administrative services --------*/
            hseSetAttrSrv_t                 setAttrReq;             /**< @brief Request to set a HSE attribute (note that some attributes are read only) */
            hseGetAttrSrv_t                 getAttrReq;             /**< @brief Request to get a HSE attribute */
        #ifdef HSE_SPT_SELF_TEST
            hseSelfTestSrv_t                selfTestReq;            /**< @brief Request to execute a HSE self test procedure */
        #endif
            hseCancelSrv_t                  cancelSrvReq;           /**< @brief Request to cancel a one-pass or streaming service on a specific channel */
        #ifdef HSE_SPT_OTA_FIRMWARE_UPDATE
            hseFirmwareUpdateSrv_t          firmwareUpdateReq;      /**< @brief Request to HSE firmware update. */
        #endif
        /*--------System authorization services--------*/
            hseSysAuthorizationReqSrv_t     sysAuthorizationReq;    /**< @brief Perform an SYS Authorization Request */
            hseSysAuthorizationRespSrv_t    sysAuthorizationResp;   /**< @brief Send the SYS Authorization Response */
        #ifdef HSE_SPT_BOOTDATASIGN
            hseBootDataImageSignSrv_t       bootDataImageSignReq;   /**< @brief Request to generate the Signature  for Boot Data images (e.g. for HSE_H/M, IVT/DCD/ST/LPDDR4(ZSE devices)/AppBSB image; for HSE_B, IVT/XRDC/AppBSB image) */
            hseBootDataImageVerifySrv_t     bootDataImageSigVerifyReq;/**< @brief Request to verify the Signature for Boot Data images (e.g. for HSE_H/M, IVT/DCD/ST/LPDDR4(ZSE devices)/AppBSB image; for HSE_B, IVT/XRDC/AppBSB image) */
        #endif
        #ifdef HSE_SPT_STREAM_CTX_IMPORT_EXPORT
            hseImportExportStreamCtxSrv_t   importExportStreamCtx;  /**< @brief Request to import/export a streaming context. */
        #endif
        #ifdef HSE_SPT_FLASHLESS_DEV /* HSE_H/M device */
            hsePublishSysImageSrv_t         publishSysImageReq;     /**< @brief Request to Publish a NVM SYS-IMAGE (only for HSE_H/M). */
            hseGetSysImageSizeSrv_t         getSysImageSizeReq;     /**< @brief Request to get SYS-IMAGE size (only for HSE_H/M). */
            hseVerifySysImageSrv_t          verifySysImageReq;      /**< @brief Request to Verify SYS-IMAGE after it is stored in external flash (only for HSE_H/M). */
            #ifdef HSE_SPT_MONOTONIC_COUNTERS
            hsePublishLoadCntTblSrv_t       publishLoadCntTblReq;   /**< @brief Request to publish/load the NVM container for the  Monotonic Counter table (only for HSE_H/M). */
            #endif/*HSE_SPT_MONOTONIC_COUNTERS*/
            #ifdef HSE_SPT_OTFAD
            hseInstallOtfadContextSrv_t     installOtfadReq;        /**< @brief Request to install an OTFAD context (only for HSE_H/M). */
            hseActivateOtfadContextSrv_t    activateOtfadReq;       /**< @brief Request to activate on-demand an already installed OTFAD context (only for HSE_H/M). */
            hseGetOtfadContextSrv_t         getOtfadCtxReq;         /**< @brief Request to get OTFAD context information (only for HSE_H/M). */
            #endif /* end HSE_SPT_OTFAD */
            hsePrepareForStandBySrv_t       prepareForStandByReq;   /**< @brief Request HSE to prepare for Stand-By mode (only for HSE_H/M). */
            #ifdef HSE_SPT_MSC_KEYSTORE
            hseConfigKHTTSrv_t              configKHTT;            /**< @brief Configure the Key Handle Translation Table (KHTT). */
            hsePushMscKeySrv_t              pushMscKey;            /**< @brief Push one or more HSE keys in ACE key store */
            #endif /* HSE_SPT_MSC_KEYSTORE*/
        #endif /* end HSE_SPT_FLASHLESS_DEV */

        #ifdef HSE_SPT_INTERNAL_FLASH_DEV /* HSE_B device */
            hseEraseNvmDataSrv_t            eraseNvmDataReq;        /**< @brief Request to reset HSE data flash. Only allowed in CUST_DEL LC */

            #ifdef HSE_SPT_OTA_SBAF_UPDATE
            hseSbafUpdateSrv_t              sbafUpdateReq;         /**< @brief Request to SBAF firmware update. */
            #endif /* HSE_SPT_OTA_SBAF_UPDATE */

            #ifdef HSE_SPT_ERASE_FW
            hseEraseFwSrv_t            eraseFwReq;                /**< @brief Request to erase sys-img, backup, current firmware. Only allowed in CUST_DEL LC */
            #endif /* HSE_SPT_ERASE_FW */

        #endif /* HSE_SPT_INTERNAL_FLASH_DEV */

        #ifdef HSE_SPT_TMU_REG_CONFIG
            hseTmuRegConfigSrv_t            tmuRegConfigReq;       /**< @brief TMU register configuration */
        #endif /* HSE_SPT_TMU_REG_CONFIG */

        #ifdef HSE_SPT_TRIM_PASSWORD_PROVISION
            hseTrimPasswordProvision_t        trimPasswordReq;       /**< @brief Request to verify trim password to enable read access for certain system fuses (e.g trim values, MIDR etc). */
        #endif  /* HSE_SPT_TRIM_PASSWORD_PROVISION */

        /*--------HSE key management services--------*/
        #ifdef HSE_SPT_ECC_USER_CURVES
            hseLoadEccCurveSrv_t            loadEccCurveReq;       /**< @brief Request to load an ECC curve */
        #endif
        #ifdef HSE_SPT_FORMAT_KEY_CATALOGS
            hseFormatKeyCatalogsSrv_t       formatKeyCatalogsReq;   /**< @brief Format the key catalogs */
        #endif
            hseEraseKeySrv_t                eraseKeyReq;            /**< @brief Request to erase NVM/RAM key(s). */
        #ifdef HSE_SPT_GET_KEY_INFO
            hseGetKeyInfoSrv_t              getKeyInfoReq;          /**< @brief Request to get key information (flags) */
        #endif
        #ifdef HSE_SPT_IMPORT_KEY
            hseImportKeySrv_t               importKeyReq;           /**< @brief Request to import a key. */
        #endif
        #ifdef HSE_SPT_EXPORT_KEY
            hseExportKeySrv_t               exportKeyReq;           /**< @brief Request to export a key. */
        #endif
        #ifdef HSE_SPT_KEY_VERIFY
            hseKeyVerifySrv_t               verifyKeyReq;           /**< @brief Request to verify a key. */
        #endif
        #ifdef HSE_SPT_KEY_GEN
            hseKeyGenerateSrv_t             keyGenReq;              /**< @brief Request to generate a key (e.g. sym random key, rsa key pair etc.) . */
        #endif
        #ifdef HSE_SPT_COMPUTE_DH
            hseDHComputeSharedSecretSrv_t   dhComputeSecretReq;     /**< @brief Request a ECC Diffie-Hellman Compute shared secret. */
        #endif
        #ifdef HSE_SPT_BURMESTER_DESMEDT
            hseBurmesterDesmedtSrv_t        burmesterDesmedtReq;    /**< @brief Request to perform a Burmester-Desmedt computation. */
        #endif
        #ifdef HSE_SPT_KEY_DERIVE
            hseKeyDeriveSrv_t               keyDeriveReq;           /**< @brief Request key derivation function. */
            hseKeyDeriveCopyKeySrv_t        keyDeriveCopyKeyReq;    /**< @brief Request to copy a key from the derived key material. */
        #endif
        #ifdef HSE_SPT_EXTEND_KEY_CATALOG
            hseExtendKeyCatalogSrv_t        extendKeyCatalogReq;    /**< @brief Request to extend the NVM or RAM key catalog format. */
        #endif
        #ifdef HSE_SPT_SHE
            hseSheLoadKeySrv_t              sheLoadKeyReq;          /**< @brief Request to load a SHE key using memory update protocol (as per SHE specification) */
            hseSheLoadPlainKeySrv_t         sheLoadPlainKeyReq;     /**< @brief Request to load the SHE RAM key from plain text (as per SHE specification) */
            hseSheExportRamKeySrv_t         sheExportRamKeyReq;     /**< @brief Request to export the SHE RAM key (as per SHE specification) */
            hseSheGetIdSrv_t                sheGetIdReq;            /**< @brief Request to get UID (as per SHE specification) */
        #endif

        /*--------HSE crypto services--------*/
        #ifdef HSE_SPT_HASH
            hseHashSrv_t                    hashReq;                /**< @brief Request a HASH */
        #endif
            hseMacSrv_t                     macReq;                 /**< @brief Request to generate/verify a MAC */
        #ifdef HSE_SPT_FAST_CMAC
            hseFastCMACSrv_t                fastCmacReq;            /**< @brief Request to FAST generate/verify a CMAC */
        #endif
        #ifdef HSE_SPT_CMAC_WITH_COUNTER
            hseCmacWithCounterSrv_t         cmacWithCounterReq;     /**< @brief Request to generate/verify a CMAC with counter */
        #endif
            hseSymCipherSrv_t               symCipherReq;           /**< @brief Request a Symmetric Cipher operation */
        #ifdef HSE_SPT_AEAD
            hseAeadSrv_t                    aeadReq;                /**< @brief Request an AEAD operation */
        #endif
        #ifdef HSE_SPT_XTS_AES
            hseXtsAesCipherSrv_t            xtsAesCipherReq;        /**< @brief Request a XTS AES Cipher operation */
        #endif
        #ifdef HSE_SPT_SIGN
            hseSignSrv_t                    signReq;                /**< @brief Request a Digital Signature Generation/Verification */
        #endif
        #ifdef HSE_SPT_RSA
            hseRsaCipherSrv_t               rsaCipherReq;           /**< @brief Request a RSA Cipher (Encryption/Decryption) operation */
        #endif
        #ifdef HSE_SPT_AUTHENC
            hseAuthEncSrv_t                 authEncReq;             /**< @brief Request an AuthEncryption operation (encrypt/decrypt + authenticate) */
        #endif
        #ifdef HSE_SPT_CRC32
            hseCrc32Srv_t                   crc32Req;                /**< @brief Request to initialize an CRC computation */
        #endif
        #ifdef HSE_SPT_SIPHASH
            hseSipHashSrv_t                 sipHashReq;             /**< @brief Request to generate/verify a SipHash */
        #endif
         /*--------HSE random number--------*/
        #ifdef HSE_SPT_RANDOM
            hseGetRandomNumSrv_t            getRandomNumReq;        /**< @brief Request to random number generation */
        #endif
        /*--------HSE monotonic counters--------*/
        #ifdef HSE_SPT_MONOTONIC_COUNTERS
            hseIncrementCounterSrv_t        incCounterReq;          /**< @brief Request to increment a monotonic counter */
            hseReadCounterSrv_t             readCounterReq;         /**< @brief Request to read a monotonic counter */
            hseConfigSecCounterSrv_t        configSecCounter;       /**< @brief Request to configure a secure counter */
        #endif
        /*--------Secure Memory Regions (SMR) management--------*/
        #ifdef HSE_SPT_SMR_CR
            hseSmrEntryInstallSrv_t         smrEntryInstallReq;     /**< @brief Request to install a Secure Memory Region (SMR) table entry. */
            hseSmrVerifySrv_t               smrVerifyReq;           /**< @brief Request to verify a Secure Memory Region (SMR) table entry. */
            hseSmrEntryEraseSrv_t           smrEntryEraseReq;       /**< @brief Request to erase a Secure Memory Region (SMR) table entry */
            hseCrEntryInstallSrv_t          crEntryInstallReq;      /**< @brief Request to install a Core Reset (CR) table entry. */
            hseCrOnDemandBootSrv_t          crOnDemandBootReq;      /**< @brief Request to release a Core Reset (CR) table entry. */
            hseCrEntryEraseSrv_t            crEntryEraseReq;        /**< @brief Request to erase a Core Reset (CR) table entry. */
        #endif
        /*--------IPSEC protocol acceleration--------*/
        #ifdef HSE_SPT_IPSEC
            hseIpsecInitSrv_t               ipsecInitReq;           /**< @brief Request to initialize an IPSEC SA. */
            hseIpsecProcessSrv_t            ipsecProcessReq;        /**< @brief Request to process an IPSEC frame. */
            hseIpsecGetSeqNumSrv_t          ipsecGetSeqNumReq;      /**< @brief Request to get the expected sequence number of an SA. */
            hseIpsecSetSeqNumSrv_t          ipsecSetSeqNumReq;      /**< @brief Request to set an SA's expected sequence number. */
        #endif
        /*-------- HSE CUSTOM SERVICE --------*/
        #if HSE_FWTYPE >= 8U
            HSE_CUSTOM_SERVICES
        #endif

    } hseSrv;
} hseSrvDescriptor_t;


HSE_IP 的驱动接口函数 Hse_Ip_ServiceRequest 函发送数据的实现就是将上述的结构体成员的地址通过TRI 寄存器通知到HSE core

image.png

通过上述简单的MU 寄存器的设定就完成了和HSE CORE 的交互流程

 


共1条 1/1 1 跳转至

回复

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