/***************************************************************************** * Private functions ****************************************************************************/ static SPIFI_HANDLE_T *initializeSpifi(void) { int idx; int devIdx; uint32_t memSize; SPIFI_HANDLE_T *pReturnVal; /* Initialize LPCSPIFILIB library, reset the interface */ spifiInit(LPC_SPIFI_BASE, true); /* register support for the family(s) we may want to work with (only 1 is required) */ spifiRegisterFamily(SPIFI_REG_FAMILY_SpansionS25FLP); spifiRegisterFamily(SPIFI_REG_FAMILY_SpansionS25FL1); spifiRegisterFamily(SPIFI_REG_FAMILY_MacronixMX25L); /* Return the number of families that are registered */ idx = spifiGetSuppFamilyCount(); /* Show all families that are registered */ for (devIdx = 0; devIdx < idx; ++devIdx) { DEBUGOUT("FAMILY: %s\r\n", spifiGetSuppFamilyName(devIdx)); } /* Get required memory for detected device, this may vary per device family */ memSize = spifiGetHandleMemSize(LPC_SPIFI_BASE); if (memSize == 0) { /* No device detected, error */ test_suiteError("spifiGetHandleMemSize", SPIFI_ERR_GEN); } /* Initialize and detect a device and get device context */ pReturnVal = spifiInitDevice(&lmem, sizeof(lmem), LPC_SPIFI_BASE, SPIFLASH_BASE_ADDRESS); if (pReturnVal == NULL) { test_suiteError("spifiInitDevice", SPIFI_ERR_GEN); } return pReturnVal; }
platform_result_t platform_spifi_init( const platform_spifi_t* spifi ) { uint32_t spifiBaseClockRate; uint32_t maxSpifiClock; /* if( spi_ptr->semaphore_is_inited == WICED_FALSE ) { host_rtos_init_semaphore( &spi_ptr->in_use_semaphore ); spi_ptr->semaphore_is_inited = WICED_TRUE; } else { host_rtos_get_semaphore( &spi_ptr->in_use_semaphore, NEVER_TIMEOUT, WICED_FALSE ); } */ /* Mux the port and pin to direct it to SPIFI */ platform_pin_set_alternate_function( &spifi->clock ); platform_pin_set_alternate_function( &spifi->miso ); platform_pin_set_alternate_function( &spifi->mosi ); platform_pin_set_alternate_function( &spifi->sio2 ); platform_pin_set_alternate_function( &spifi->sio3 ); platform_pin_set_alternate_function( &spifi->cs ); /* SPIFI base clock will be based on the main PLL rate and a divider */ spifiBaseClockRate = Chip_Clock_GetClockInputHz(CLKIN_MAINPLL); /* Setup SPIFI clock to run around 1Mhz. Use divider E for this, as it allows * higher divider values up to 256 maximum) */ Chip_Clock_SetDivider(CLK_IDIV_E, CLKIN_MAINPLL, ((spifiBaseClockRate / 1000000) + 1)); Chip_Clock_SetBaseClock(CLK_BASE_SPIFI, CLKIN_IDIVE, true, false); /* Initialize LPCSPIFILIB library, reset the interface */ spifiInit( ( uint32_t )spifi->spifi_base, true); /* register support for the family(s) we may want to work with */ spifiRegisterFamily( SPIFI_REG_FAMILY_MacronixMX25L ); /* Initialize and detect a device and get device context */ spifi_handle = spifiInitDevice( &lmem, sizeof(lmem), ( uint32_t ) spifi->spifi_base, SPIFLASH_BASE_ADDRESS ); /* Get some info needed for the application */ maxSpifiClock = spifiDevGetInfo(spifi_handle, SPIFI_INFO_MAXCLOCK); /* Setup SPIFI clock to at the maximum interface rate the detected device can use. This should be done after device init. */ Chip_Clock_SetDivider(CLK_IDIV_E, CLKIN_MAINPLL, ((spifiBaseClockRate / maxSpifiClock) + 1)); /* start by unlocking the device */ if (spifiDevUnlockDevice(spifi_handle) != SPIFI_ERR_NONE) { return WICED_ERROR; } /* Enable quad. If not supported it will be ignored */ spifiDevSetOpts(spifi_handle, SPIFI_OPT_USE_QUAD, true); /* Enter memMode */ spifiDevSetMemMode(spifi_handle, true); /* Just a test */ maxSpifiClock = *( (uint32_t *)SPIFLASH_BASE_ADDRESS ); return spifi_handle == NULL ? WICED_ERROR : WICED_SUCCESS; }