根据经验,FSMC不难操作。下面给出一些代码,代码可用于ST的官方评估板STM3210E-EVAL,仅供参考:
// Note: NOR /CS is CE1 - Bank 1 of 0~3 #define EVAL_NOR_BASE ((u32)(0x60000000 | 0x04000000)) #define EVAL_NOR ((EVAL_NOR_TypeDef *) EVAL_NOR_BASE)
//...
//----------------------------------------------------------------- // NOR(M29W128, /CS1-of 0~3) initialization //----------------------------------------------------------------- void NOR_Test_Init(void) { // NOR IO configuration --------------------------------------// // Enable FSMC, GPIOD~G & AFEN(Alternate Function) clock // RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE | RCC_APB2Periph_GPIOF | RCC_APB2Periph_GPIOG | RCC_APB2Periph_AFIO, ENABLE); // Set PD0,1, 4~5, 8~15 as PP AF - D2,3, OE,WE, D13~15, A16~18, D0~1 //... // Set PE3~6, 7~15 as PP AF - A19~22, D4~12 //... // Set PF0~5, 12~15 as PP AF - A0~5, A6~9 //... // Set PG0~5, 9 as PP AF - A10~15, CE1 //...
// NOR configuration ------------------------------------------// // NOR configured as follow: // - Data/Address MUX = Disable // - Memory Type = NOR // - Data Width = 16bit // - Reset Pin Level = High (needed for Flash memory) // - Wait Signal Polarity = Low // - Write Operation = Enable // - Extended Mode = Disable // - Asynchronous Wait = Disable // for test purpose only // FSMC_Bank1->BTCR[2] = FSMC_DataAddressMux_Disable | FSMC_MemoryType_SRAM | // FSMC_MemoryDataWidth_16b | FSMC_WaitSignalPolarity_Low | // FSMC_WriteOperation_Enable | // FSMC_ExtendedMode_Disable | FSMC_AsyncWait_Disable;
FSMC_Bank1->BTCR[2] = FSMC_DataAddressMux_Disable | FSMC_MemoryType_NOR | FSMC_MemoryDataWidth_16b | FSMC_FlashResetPinLevel_High | FSMC_WaitSignalPolarity_Low | FSMC_WriteOperation_Enable | FSMC_ExtendedMode_Disable | FSMC_AsyncWait_Disable;
// and as follow (NOR cycle time is <= 80ns): // - Address Setup Time = 0x03 // - Address Hold Time = 0x00 // - Data Setup Time = 0x04 // - Bus Turn around Duration = 0x05 FSMC_Bank1->BTCR[3] = 0x00050403; // - BANK 1 (of NOR/SRAM Bank 0~3) is enabled FSMC_Bank1->BTCR[2] |= 0x0001; }
随后就可以对 NOR 进行读写了: //----------------------------------------------------------------- // NOR(M29W128) test // return NOR_TEST_FAIL_xx - Fail // return NOR_TEST_PASS - PASS //----------------------------------------------------------------- u8 NOR_Test(u32 address) { //... } |