This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2642R: True random number generator

Part Number: CC2642R
Other Parts Discussed in Thread: CC2640R2F, CC2640

Hi,

I'm porting my application code from CC2640R2F to CC2642. 

In CC2640R2F i used to generate true random number using function TRNGCC26XX_getNumber(NULL,NULL,NULL);

Want to know how to do the same in CC2642. I've tried many things but nothing worked.

Regards,

Madhusudhan

  • Hi,

    Assigning an expert to comment.

  • Hi Madhusudhan,

    You were using quite an old SDK on CC2640, isn't it? And on CC2642, which SDK version are you using?

    I assume you problem is caused by an API modification. You should have a look to the TRNG API documentation of your SDK (docs/tidrivers/doxygen/html/_t_r_n_g_8h.html): a short example is provided.

    I hope this will help,

    Best regards,

  • Hi Clément,

    Yes you are right.I'm using simplelink_cc2640r2_sdk_2_20_00_49 sdk on CC2640 and simplelink_cc13x2_26x2_sdk_3_20_00_68 on CC2642. My requirement is to generate a random uint32 value, 

    Regards,

    Madhusudhan

  • @Clément, I put the following TRNG code in mainThread of CC26x2R uartecho example of simplelink_cc13x2_26x2_sdk_3_20_00_68 and I can see if work.

        TRNG_init();
        handle = TRNG_open(0, NULL);
        if (!handle) {
            // Handle error
            while(1);
        }
        CryptoKeyPlaintext_initBlankKey(&entropyKey, entropyBuffer, KEY_LENGTH_BYTES);
        result = TRNG_generateEntropy(handle, &entropyKey);
        if (result != TRNG_STATUS_SUCCESS) {
            // Handle error
            while(1);
        }
        TRNG_close(handle);

    However, if I put the same code in SimplePeripheral_handleKeys of simple_peripheral and press button to trigger TRNG. I see it get stuck in the "while(1);" of "if (!handle) {...}". Can you try to verify the same code on your side to see why TRNG_open returns handle:0 in simple_peripheral example but not in uartecho example?

  • Hi,

    I also tried the example code and it is getting stuck in while loop.

    TRNG_init();
    trngHandle = TRNG_open(Board_TRNG0, NULL);
    if (!trngHandle) {
    // Handle error
    while(1);
    }

  • Hi YK Chen, hi Madhusudhan,

    I haven't tested it for the moment but this looks like you are opening twice the same TRNG instance. It makes sense as the BLE stack uses the TRNG driver (but the uart example does not). The best way to solve the issue might be to declare a second instance of the TRNG driver by modifying the following pieces of code:

    - in CC26X2R1_LAUNCHXL.h:

    typedef enum CC26X2R1_LAUNCHXL_TRNGName {
        CC26X2R1_LAUNCHXL_TRNG0 = 0,
        CC26X2R1_LAUNCHXL_TRNG1 = 1,
    
        CC26X2R1_LAUNCHXL_TRNGCOUNT
    } CC26X2R1_LAUNCHXL_TRNGName;

    - in CC26X2R1_LAUNCHXL.c:

    const TRNGCC26XX_HWAttrs trngCC26X2HWAttrs[CC26X2R1_LAUNCHXL_TRNGCOUNT] = {
        {
            .intPriority       = ~0,
            .swiPriority       = 0,
            .samplesPerCycle   = 240000,
        },
        {
            .intPriority       = ~0,
            .swiPriority       = 0,
            .samplesPerCycle   = 240000,
        }
    };
    
    const TRNG_Config TRNG_config[CC26X2R1_LAUNCHXL_TRNGCOUNT] = {
        {
             .object  = &trngCC26XXObjects[CC26X2R1_LAUNCHXL_TRNG0],
             .hwAttrs = &trngCC26X2HWAttrs[CC26X2R1_LAUNCHXL_TRNG0]
        },
        {
             .object  = &trngCC26XXObjects[CC26X2R1_LAUNCHXL_TRNG1],
             .hwAttrs = &trngCC26X2HWAttrs[CC26X2R1_LAUNCHXL_TRNG1]
        },
    };

    After this, you can try to open the TRNG driver as following: (Note: if the driver has already been initialized you can skip TRNG_init() even if it does not hurt to do it twice)

    handle = TRNG_open(1, NULL);

    I hope this will help,

    Best regards,

  • @Clément, Yes, it works with TRNG1. Thanks for the hint.

  • Hi Clément,

    It works for me too with TRNG1. Thanks