EDIT: I tried to change the values of the OTFAD control registers from my application (stored in internal flash):
------
#define OTFAD_CR (uint8_t*)0x400DB800
#define OTFAD_SR (uint8_t*)0x400DB804
#define OTFAD_CTX0_KEY_W0 (uint8_t*)0x400DB900
#define OTFAD_CTX0_KEY_W1 (uint8_t*)0x400DB904
#define OTFAD_CTX0_KEY_W2 (uint8_t*)0x400DB908
#define OTFAD_CTX0_KEY_W3 (uint8_t*)0x400DB90C
#define OTFAD_CTX0_CTR_W0 (uint8_t*)0x400DB910
#define OTFAD_CTX0_CTR_W1 (uint8_t*)0x400DB914
#define OTFAD_CTX0_RGD_W0 (uint8_t*)0x400DB918
#define OTFAD_CTX0_RGD_W1 (uint8_t*)0x400DB91C
int qspi_init()
{
uint32_t clockSourceFreq = 0;
qspi_config_t config = {0};
/*Get QSPI default settings and configure the qspi */
QSPI_GetDefaultQspiConfig(&config);
/*Set AHB buffer size for reading data through AHB bus */
config.AHBbufferSize[3] = FLASH_PAGE_SIZE;
clockSourceFreq = CLOCK_GetFreq(QSPI_CLOCK_SOURCE);
QSPI_Init(EXAMPLE_QSPI, &config, clockSourceFreq);
/* According to serial flash feature to configure flash settings */
QSPI_SetFlashConfig(EXAMPLE_QSPI, &single_config);
enable_quad_mode();
}
void otfad_init()
{
uint32_t otfad_cr_value = 0x80300000;
uint8_t test_aes_key[16] = { 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F};
uint8_t test_ctr[8] = {0x01,0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF};
uint32_t start_addr = 0x68000000;
uint32_t end_addr = 0x68fffffb;
uint32_t otfad_status = 0;
memcpy(OTFAD_CR, (uint8_t*)otfad_cr_value, 4);
memcpy(OTFAD_CTX0_KEY_W0, test_aes_key, 4);
memcpy(OTFAD_CTX0_KEY_W1, test_aes_key + 4, 4);
memcpy(OTFAD_CTX0_KEY_W2, test_aes_key + 8, 4);
memcpy(OTFAD_CTX0_KEY_W3, test_aes_key + 12, 4);
memcpy(OTFAD_CTX0_CTR_W0, test_ctr, 4);
memcpy(OTFAD_CTX0_CTR_W1, test_ctr + 4, 4);
memcpy(OTFAD_CTX0_RGD_W0, (uint8_t*)start_addr, 4);
memcpy(OTFAD_CTX0_RGD_W1, (uint8_t*)end_addr, 4);
memcpy((uint8_t*)otfad_status, OTFAD_SR, 4);
logger_debug("OTFAD status: 0x%x\r\n", otfad_status);
}
but it gives a hard fault from the very first memcpy. If I'm doing it correctly, I am at this point already initializing the QSPI, so I'm unsure on why the hard fault is there, or the reading problems. No luck yet.