S32K312 cannot get random numbers

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

S32K312 cannot get random numbers

1,714 次查看
MengWang1
Contributor I

S32K312 cannot get random numbers

 

/* Identifier for the only MU instance used in this example (MU0) */
#define MU0_INSTANCE_U8                     ((uint8)0U)

/* Identifier of the MU channel used by HSE to listen for administrative requests (eg. read/write attributes) */
#define MU_ADMIN_CHANNEL_U8                 ((uint8)0U)
 
#define TIMEOUT_TICKS_U32                   ((uint32)10000000U)
 
hseSrvResponse_t getRandomNumReq(hseRngClass_t rngClass, uint32_t rngNumSize, uint8_t *rngNum)
{
    hseSrvResponse_t hseStatus = HSE_SRV_RSP_GENERAL_ERROR;

    hseGetRandomNumSrv_t *pGetRndSrv;
    hseSrvDescriptor_t *pHseSrvDesc  = &Hse_aSrvDescriptor[MU_ADMIN_CHANNEL_U8];
    memset(pHseSrvDesc, 0, sizeof(hseSrvDescriptor_t));
    pHseSrvDesc->srvId = HSE_SRV_ID_GET_RANDOM_NUM;
    pGetRndSrv = &(pHseSrvDesc->hseSrv.getRandomNumReq);
    pGetRndSrv->rngClass = rngClass;
    pGetRndSrv->pRandomNum = (HOST_ADDR)rngNum;
    pGetRndSrv->randomNumLength = rngNumSize;

    /* Build the request to be sent to Hse Ip layer */
    HseIp_aRequest[MU_ADMIN_CHANNEL_U8].eReqType   = HSE_IP_REQTYPE_SYNC;
    HseIp_aRequest[MU_ADMIN_CHANNEL_U8].u32Timeout = TIMEOUT_TICKS_U32;

    // hseStatus = HSE_Send(muIf, muChannelIdx, gSyncTxOption, pHseSrvDesc);
    /* Send the request to Hse Ip layer */
    hseStatus = Hse_Ip_ServiceRequest(MU0_INSTANCE_U8, MU_ADMIN_CHANNEL_U8, &HseIp_aRequest[MU_ADMIN_CHANNEL_U8], pGetRndSrv);

    return hseStatus;
}

hseSrvResponse_t cmd_rnd(uint8_t *rngNum)
{
    return getRandomNumReq(HSE_RNG_CLASS_DRG3, 16U, rngNum);
}
 



0 项奖励
回复
2 回复数

1,516 次查看
AlehTS
Contributor II

In my case the following helped:

1. Disable data cache by deleting D_CACHE_ENABLE in Preprocessor

2. Use channel 1 (in your case MU_ADMIN_CHANNEL_U8 = 0)

1,533 次查看
AlehTS
Contributor II

Hello. I have the same problem. Did you solve it?

My code looks the same as yours.

Hse_Ip_ServiceRequest function returns HSE_SRV_RSP_NOT_ALLOWED.

With demo_app everything is fine. So the HSE is able to regerate randoms.

Before requesting the random numbers I do the same steps, which are performed in Hse_Ip_AesEncAsyncIrq_S32K344 example:

Install and enable the needed interrupt handlers,

Check that HSE is initialized (along with RNG module) by reading the status bits in FSR,

Initialize Hse Ip layer for MU0 instance,

Read HSE FW Capabilities, by sending a request over MU0.

If it is important, the capabilities are: 0x1fdffbdb7

 

Thank you.

 

 

 

 

0 项奖励
回复