Random Generated Number and Data cache

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Random Generated Number and Data cache

824 Views
sobo
Contributor III

Hello,

We need to generate a Random number on S32K358

This post https://community.nxp.com/t5/S32K/random-number/m-p/1645343 help us a lot.

Now, we want to enable the DATA cache for the whole project so we try to force the data structure to non cacheable memory but without success.

We can't figure out which struct needed to be in non cachaeable memory and in which section add the strut ( .mcal_data_no_cacheable ? )

Does anyone have an working example ?

0 Kudos
7 Replies

774 Views
lukaszadrapa
NXP TechSupport
NXP TechSupport

Hi @sobo 

Any variable (hseSrvDescriptor, input/output length/size pointer , data pointer…) used in the interaction between the core and HSE need to be placed in a non-cacheable area (DTCM, non-cacheable SRAM…). You can take a look at Crypto examples in RTD. You will always see something like this - and that will do the job:

lukaszadrapa_0-1692791550155.png

 

lukaszadrapa_1-1692791585508.png


Regards,
Lukas

0 Kudos

739 Views
sobo
Contributor III

hello,

it works for a s32K344 with RTD version 1.0.0 but the same code doesn't works with a s32k358 with RTD v3.0.0 HF01.

In the first case we receive a Random number from the HSE, in the second case we have a error return by the HSE. The error is unknown from Crypto_Hse_TranslateHseResponse function(goes to default switch).

However, on the s32k358 we can get a random number, if before calling crypto/HSE function we clear the cache and disable it but It is not a good solution for us.

Do you have any idea why ?

@IAussman 

0 Kudos

704 Views
lukaszadrapa
NXP TechSupport
NXP TechSupport

Not all variables/structures are obviously forced to non-cacheable area. Could you share your code? Did you define the variables as shown on the screenshot above?

Regards,

Lukas

0 Kudos

693 Views
IAussman
Contributor III

Hi @lukaszadrapa ,

Please find below the source code we use for generating the random number:

 

int main()
{
    static StaticTask_t     DummyTaskTCBBuffer;
    static StackType_t      DummyTaskStackBuffer[dummy_TASK_STACK_SIZE];
    Std_ReturnType          RetVal;

    /* Hardware board initialization */
    HwBoardInit();

    xTaskCreateStatic(DummyTask,                        /* The function that implements the task being created. */
                      (const char * const) "DummyTask", /* Text name for the task - not used by the RTOS, its just to assist debugging. */
                      dummy_TASK_STACK_SIZE,            /* Size of the buffer passed in as the stack - in words, not bytes! */
                      NULL,                             /* Parameter passed into the task - not used in this case. */
                      dummy_TASK_PRIORITY,              /* Priority of the task. */
                      DummyTaskStackBuffer,             /* The buffer to use as the task's stack. */
                      &DummyTaskTCBBuffer);             /* The variable that will hold the task's TCB. */

    #pragma default_variable_attributes = @ ".mcal_data_no_cacheable"
    static uint8_t  au8GeneratedRandomNumber[UDS_RANDOM_NUMBER_SIZE] = {0};
    static uint32_t u32RandomNumberSz16 = 16;

    /** Job TRNG ID and priority */
    static Crypto_JobInfoType AppJobTrngInfo = {SEC_JOB_TRNG_ID, SEC_JOB_TRNG_PRIORITY};

    static Crypto_PrimitiveInfoType AppTrngPrimitiveInfo = {
            16,
            CRYPTO_RANDOMGENERATE,
            {CRYPTO_ALGOFAM_RNG, CRYPTO_ALGOFAM_NOT_SET, 16, (Crypto_AlgorithmModeType) CRYPTO_ALGOMODE_CUSTOM_DRBG_RS}
        };

        /** Structure which contains further information on True Random Number Generator Job */
        static Crypto_JobPrimitiveInfoType AppJobTrngPrimitiveInfo = {0U, &AppTrngPrimitiveInfo, 0U, CRYPTO_PROCESSING_SYNC, FALSE};

        /** Structure of the job to be passed to Crypto driver, request true random number from TRNG module */
        static Crypto_JobType AppJobTrng = {
            SEC_JOB_TRNG_ID,
            CRYPTO_JOBSTATE_IDLE,
            {
              NULL_PTR, 0,
              NULL_PTR, 0U,
              NULL_PTR, 0U,
              au8GeneratedRandomNumber, &u32RandomNumberSz16,
              NULL_PTR, NULL_PTR,
              0U, NULL_PTR,
              NULL_PTR, CRYPTO_OPERATIONMODE_SINGLECALL,
              0U, 0U,
              },
            &AppJobTrngPrimitiveInfo,
            &AppJobTrngInfo,
            NULL_PTR,
        };
    #pragma default_variable_attributes =

        Crypto_ProcessJob(CryptoConf_CryptoDriverObject_CryptoDriverObject_1, &AppJobTrng);

    vTaskStartScheduler();

    for (;;)
    {
    }

    return 0;
}
0 Kudos

682 Views
lukaszadrapa
NXP TechSupport
NXP TechSupport

Can I ask you to submit this as a new ticket here?

https://support.nxp.com/s/?language=en_US

We will assign it directly to SW team.

Thanks,

Lukas

0 Kudos

671 Views
IAussman
Contributor III
Done. Thanks.
0 Kudos

815 Views
sobo
Contributor III
0 Kudos