/* * (c) Copyright 2020 NXP * * NXP Confidential. This software is owned or controlled by NXP and may only be used strictly * in accordance with the applicable license terms. By expressly accepting * such terms or by downloading, installing, activating and/or otherwise using * the software, you are agreeing that you have read, and that you agree to * comply with and are bound by, such license terms. If you do not agree to * be bound by the applicable license terms, then you may not retain, * install, activate or otherwise use the software. * * This file contains sample code only. It is not part of the production code deliverables. */ #ifdef __cplusplus extern "C" { #endif /*================================================================================================== * INCLUDE FILES * 1) system and project includes * 2) needed interfaces from external units * 3) internal and external interfaces from this unit ==================================================================================================*/ #include "Clock_Ip.h" #include "Power_Ip.h" #include "S32K344_SIUL2.h" #include "Qspi_Ip.h" #include "Qspi_Ip_Cfg.h" #include "check_example.h" /*================================================================================================== * LOCAL TYPEDEFS (STRUCTURES, UNIONS, ENUMS) ==================================================================================================*/ /*================================================================================================== * LOCAL MACROS ==================================================================================================*/ #define SIUL2_MSCR_SSS(x) (SIUL2_MSCR_SSS_0((x) & 1U) | SIUL2_MSCR_SSS_1(((x) >> 1U) & 1U) | SIUL2_MSCR_SSS_2(((x) >> 2U) & 1U)) #define FLS_JOB_SIZE 128U #define FLS_JOB_ADDRESS 4096U #define FLS_SECTOR_SIZE 4096U #define FLS_TIME_OUT 32768U /*================================================================================================== * LOCAL CONSTANTS ==================================================================================================*/ /*================================================================================================== * LOCAL VARIABLES ==================================================================================================*/ /*================================================================================================== * GLOBAL CONSTANTS ==================================================================================================*/ uint8 Txdata[FLS_JOB_SIZE]; uint8 Rxdata_IP[FLS_JOB_SIZE]; uint8 Rxdata_AHB[FLS_JOB_SIZE]; /*================================================================================================== * GLOBAL VARIABLES ==================================================================================================*/ /*================================================================================================== * LOCAL FUNCTION PROTOTYPES ==================================================================================================*/ void Fls_PinSetup(void); void Fls_InitBuffers(void); boolean Fls_VerifyBuffers(void); /*================================================================================================== * LOCAL FUNCTIONS ==================================================================================================*/ void Fls_PinSetup(void) { /* QuadSPI_SCKFA - PTD10 */ IP_SIUL2->MSCR[106] = SIUL2_MSCR_OBE(0U) | SIUL2_MSCR_IBE(1U) | SIUL2_MSCR_SSS(7U) | SIUL2_MSCR_DSE(1U); IP_SIUL2->IMCR[821 - 512] = SIUL2_IMCR_SSS(1U); /* QuadSPI_PCSFA - PTC3 */ IP_SIUL2->MSCR[67] = SIUL2_MSCR_OBE(0U) | SIUL2_MSCR_IBE(1U) | SIUL2_MSCR_SSS(6U) | SIUL2_MSCR_DSE(1U); /* QuadSPI_IOFA0 - PTD11 */ IP_SIUL2->MSCR[107] = SIUL2_MSCR_OBE(0U) | SIUL2_MSCR_IBE(1U) | SIUL2_MSCR_SSS(7U) | SIUL2_MSCR_DSE(1U); IP_SIUL2->IMCR[817 - 512] = SIUL2_IMCR_SSS(1U); /* QuadSPI_IOFA1 - PTD7 */ IP_SIUL2->MSCR[103] = SIUL2_MSCR_OBE(0U) | SIUL2_MSCR_IBE(1U) | SIUL2_MSCR_SSS(7U) | SIUL2_MSCR_DSE(1U); IP_SIUL2->IMCR[818 - 512] = SIUL2_IMCR_SSS(1U); /* QuadSPI_IOFA2 - PTD12 */ IP_SIUL2->MSCR[108] = SIUL2_MSCR_OBE(0U) | SIUL2_MSCR_IBE(1U) | SIUL2_MSCR_SSS(7U) | SIUL2_MSCR_DSE(1U); IP_SIUL2->IMCR[819 - 512] = SIUL2_IMCR_SSS(1U); /* QuadSPI_IOFA3 - PTC2 */ IP_SIUL2->MSCR[66] = SIUL2_MSCR_OBE(0U) | SIUL2_MSCR_IBE(1U) | SIUL2_MSCR_SSS(7U) | SIUL2_MSCR_DSE(1U); IP_SIUL2->IMCR[820 - 512] = SIUL2_IMCR_SSS(1U); } void Fls_InitBuffers(void) { uint32 i; for (i = 0U; i < FLS_JOB_SIZE; i++) { Txdata[i] = (uint8)i; Rxdata_IP[i] = 0U; Rxdata_AHB[i] = 0U; } } boolean Fls_VerifyBuffers() { uint32 i; volatile uint8 temp; boolean retVal = TRUE; for (i = 0U; i < FLS_JOB_SIZE; i++) { temp = Txdata[i]; if ( (Rxdata_IP[i] != temp) || (Rxdata_AHB[i] != temp) ) { retVal = FALSE; break; } } return retVal; } /* testAHBFunc() S31568001000 054A064B013BFDD192F81E33DB43DBB2 42 S31568001010 82F81E33F5E700BF0010294080969800 D5 */ uint8 CodeData[128] = { 0x05, 0x4A, 0x06, 0x4B, 0x01, 0x3B, 0xFD, 0xD1, 0x92, 0xF8, 0x1E, 0x33, 0xDB, 0x43, 0xDB, 0xB2, 0x82, 0xF8, 0x1E, 0x33, 0xF5, 0xE7, 0x00, 0xBF, 0x00, 0x10, 0x29, 0x40, 0x80, 0x96, 0x98, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xaa, 0xbb, 0xcc, 0xdd, 0xaa, 0xbb, 0xcc, 0xdd, 0xaa, 0xbb, 0xcc, 0xdd, 0xaa, 0xbb, 0xcc, 0xdd, 0xaa, 0xbb, 0xcc, 0xdd, 0xaa, 0xbb, 0xcc, 0xdd, 0xaa, 0xbb, 0xcc, 0xdd, 0xaa, 0xbb, 0xcc, 0xdd, 0xaa, 0xbb, 0xcc, 0xdd, 0xaa, 0xbb, 0xcc, 0xdd, 0xaa, 0xbb, 0xcc, 0xdd, 0xaa, 0xbb, 0xcc, 0xdd, 0xaa, 0xbb, 0xcc, 0xdd, 0xaa, 0xbb, 0xcc, 0xdd, 0xaa, 0xbb, 0xcc, 0xdd, 0xaa, 0xbb, 0xcc, 0xdd, 0xaa, 0xbb, 0xcc, 0xdd, 0xaa, 0xbb, 0xcc, 0xdd, 0xaa, 0xbb, 0xcc, 0xdd, 0xaa, 0xbb, 0xcc, 0xdd, }; uint32 __attribute__ ((section(".my_qspi_flash"))) testAHBFunc(void){ uint32 i,j; while(1){ for(i=0;i<10000000;i++) for(j=0;j<8000000;j++){ } IP_SIUL2->GPDO29 = ~IP_SIUL2->GPDO29 ; } } /*================================================================================================== * GLOBAL FUNCTIONS ==================================================================================================*/ /** * @brief Main function of the example * @details Initializez Fls IP C40 driver and * erase, write, read internal fls memory */ int main(void) { boolean exampleStatus = TRUE; uint32 timeout = FLS_TIME_OUT; uint32 instance = QspiConfigSet_VS_0_paFlashConnectionCfg[0].qspiInstance; Qspi_Ip_StatusType qspiStatus; Clock_Ip_StatusType clockStatus; /* Initialize clock */ clockStatus = Clock_Ip_Init(&Mcu_aClockConfigPB[0]); if (CLOCK_IP_SUCCESS != clockStatus) { exampleStatus = FALSE; } /* Initialize Power (enable clock gate */ Power_Ip_SetMode(&Power_Ip_aModeConfigPB[0]); /* Initialize QSPI's pins */ Fls_PinSetup(); // PTA[29] as RED LED IP_SIUL2->MSCR[29] = SIUL2_MSCR_OBE(1U) | SIUL2_MSCR_IBE(0U) | SIUL2_MSCR_SSS(0U) | SIUL2_MSCR_DSE(1U); IP_SIUL2->GPDO29 = 1; /* Initialize buffers */ Fls_InitBuffers(); /* Initialize QSPI */ qspiStatus = Qspi_Ip_ControllerInit(instance, &QspiConfigSet_VS_0_paQspiUnitCfg[0]); if (STATUS_QSPI_IP_SUCCESS != qspiStatus) { exampleStatus = FALSE; } qspiStatus = Qspi_Ip_Init(instance, &QspiConfigSet_VS_0_paFlashCfg[0], &QspiConfigSet_VS_0_paFlashConnectionCfg[0]); if (STATUS_QSPI_IP_SUCCESS != qspiStatus) { exampleStatus = FALSE; } /* Erase an external sector which has address is 4096 */ qspiStatus = Qspi_Ip_EraseBlock(instance, FLS_JOB_ADDRESS, FLS_SECTOR_SIZE); if (STATUS_QSPI_IP_SUCCESS != qspiStatus) { exampleStatus = FALSE; } /* Check qspiStatus of external memory */ while ((STATUS_QSPI_IP_BUSY == (qspiStatus = Qspi_Ip_GetMemoryStatus(instance))) && (timeout > 0)) { timeout--; } if (STATUS_QSPI_IP_SUCCESS != qspiStatus) { exampleStatus = FALSE; } /* Verify erase */ if (STATUS_QSPI_IP_SUCCESS != Qspi_Ip_EraseVerify(instance, FLS_JOB_ADDRESS, FLS_SECTOR_SIZE)) { exampleStatus = FALSE; } /* Reset Timeout*/ timeout = FLS_TIME_OUT; /* Write to external flash*/ if (STATUS_QSPI_IP_SUCCESS != Qspi_Ip_Program(instance, FLS_JOB_ADDRESS, CodeData, FLS_JOB_SIZE)) { exampleStatus = FALSE; } /* Check qspiStatus of external memory */ while ((STATUS_QSPI_IP_BUSY == (qspiStatus = Qspi_Ip_GetMemoryStatus(instance))) && (timeout > 0)) { timeout--; } if (STATUS_QSPI_IP_SUCCESS != qspiStatus) { exampleStatus = FALSE; } /* Read data from external flash*/ /* Using IP command read into Rxdata_IP buffer */ if (STATUS_QSPI_IP_SUCCESS != Qspi_Ip_Read(instance, FLS_JOB_ADDRESS, Rxdata_IP, FLS_JOB_SIZE)) { exampleStatus = FALSE; } /* Using AHB command read into Rxdata_AHB buffer */ qspiStatus = Qspi_Ip_AhbReadEnable(instance); if (STATUS_QSPI_IP_SUCCESS == qspiStatus) { uint8 *pAHBExAddr = (uint8*)(FEATURE_QSPI_AMBA_BASE + FLS_JOB_ADDRESS); for (uint32 i = 0U; i < FLS_JOB_SIZE; i++) { Rxdata_AHB[i] = pAHBExAddr[i]; } } else { exampleStatus = FALSE; } testAHBFunc(); for(;;) ; if (! Fls_VerifyBuffers()) { exampleStatus = FALSE; } Exit_Example(exampleStatus); return (0U); } #ifdef __cplusplus } #endif /** @} */