123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- #include "ext_sram.h"
- #include <inttypes.h>
- void ext_sram_init(void)
- {
- FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
- FSMC_NORSRAMTimingInitTypeDef p;
-
-
- p.FSMC_AddressSetupTime = 3;
- p.FSMC_AddressHoldTime = 0;
- p.FSMC_DataSetupTime = 2;
- p.FSMC_BusTurnAroundDuration = 1;
- p.FSMC_CLKDivision = 0;
- p.FSMC_DataLatency = 0;
- p.FSMC_AccessMode = FSMC_AccessMode_A;
- FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM3;
- FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;
- FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM;
- FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b;
- FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
- FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable;
- FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
- FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable;
- FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
- FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable;
- FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;
- FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
- FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
- FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;
- FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p;
- FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
-
- FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM3, ENABLE);
- }
- uint8_t test_ext_sram(void)
- {
- uint32_t i;
- uint32_t *pSRAM;
- uint8_t *pBytes;
- uint32_t err;
- const uint8_t ByteBuf[4] = {0x55, 0xA5, 0x5A, 0xAA};
-
- pSRAM = (uint32_t *)EXT_SRAM_ADDR;
- for (i = 0; i < EXT_SRAM_SIZE / 4; i++)
- {
- *pSRAM++ = i;
- }
-
- err = 0;
- pSRAM = (uint32_t *)EXT_SRAM_ADDR;
- for (i = 0; i < EXT_SRAM_SIZE / 4; i++)
- {
- if (*pSRAM++ != i)
- {
- err++;
- }
- }
- if (err > 0)
- {
- return (4 * err);
- }
-
- pSRAM = (uint32_t *)EXT_SRAM_ADDR;
- for (i = 0; i < EXT_SRAM_SIZE / 4; i++)
- {
- *pSRAM = ~*pSRAM;
- pSRAM++;
- }
-
- err = 0;
- pSRAM = (uint32_t *)EXT_SRAM_ADDR;
- for (i = 0; i < EXT_SRAM_SIZE / 4; i++)
- {
- if (*pSRAM++ != (~i))
- {
- err++;
- }
- }
- if (err > 0)
- {
- return (4 * err);
- }
-
- pBytes = (uint8_t *)EXT_SRAM_ADDR;
- for (i = 0; i < sizeof(ByteBuf); i++)
- {
- *pBytes++ = ByteBuf[i];
- }
-
- err = 0;
- pBytes = (uint8_t *)EXT_SRAM_ADDR;
- for (i = 0; i < sizeof(ByteBuf); i++)
- {
- if (*pBytes++ != ByteBuf[i])
- {
- err++;
- }
- }
- if (err > 0)
- {
- return err;
- }
- return 0;
- }
|