AnsweredAssumed Answered

CRYP unit not working on ST32F407

Question asked by bauer.johannes on Aug 29, 2012
Latest reply on Aug 23, 2013 by Clive One
Hi forum,

I'm having trouble getting the CRYP unit working on a ST32F407. First I've tried manually (failed) and -- thinking that I did something wrong -- tried with the ST provided libraries (which also don't work). I'm doing something wrong, I'm very sure, but I can't figure out what. First off: Yes, I have the device properly enabled:

[code]
RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_CRYP, ENABLE);
[/code]

then, I use this:

[code]
        CRYP_InitTypeDef x;
        memset(&x, 0, sizeof(x));
        x.CRYP_AlgoDir = CRYP_AlgoDir_Encrypt;
        x.CRYP_AlgoMode = CRYP_AlgoMode_AES_ECB;
        x.CRYP_DataType = CRYP_DataType_32b;
        x.CRYP_KeySize = CRYP_KeySize_128b;
        CRYP_Init(&x);
    }
    {
        CRYP_KeyInitTypeDef x;
        memset(&x, 0, sizeof(x));
        CRYP_KeyInit(&x);
    }

    CRYP_FIFOFlush();

    CRYP_Cmd(ENABLE);

    /* Write input data */
    for (int i = 0; i < 4; i++) {
         CRYP_DataIn(((uint32_t*)aSource)[i]);
    }
    printf("Waiting...\r\n");

    /* Wait until finished */
    while (!CRYP_GetFlagStatus(CRYP_FLAG_OFNE));
[/code]

(this never finishes, i.e. it's not yielding any data). Then I tried the "high level" function, which should do everything for me

[code]
printf("Result: %d\r\n", CRYP_AES_ECB(MODE_ENCRYPT, (unsigned char*)aKey, 128, (unsigned char*)aSource, 16, aDestination));
[/code]

...which fails with error 1.

Any ideas?
Best regards,
Joe

Outcomes