123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452 |
- #include "sram.h"
- static void SRAM_GPIO_Config(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
-
-
-
- RCC_AHB1PeriphClockCmd(FSMC_A0_GPIO_CLK | FSMC_A1_GPIO_CLK | FSMC_A2_GPIO_CLK |
- FSMC_A3_GPIO_CLK | FSMC_A4_GPIO_CLK | FSMC_A5_GPIO_CLK |
- FSMC_A6_GPIO_CLK | FSMC_A7_GPIO_CLK | FSMC_A8_GPIO_CLK |
- FSMC_A9_GPIO_CLK | FSMC_A10_GPIO_CLK| FSMC_A11_GPIO_CLK|
- FSMC_A12_GPIO_CLK| FSMC_A13_GPIO_CLK|FSMC_A14_GPIO_CLK|
- FSMC_A15_GPIO_CLK|FSMC_A16_GPIO_CLK|FSMC_A17_GPIO_CLK|FSMC_A18_GPIO_CLK|
-
- FSMC_D0_GPIO_CLK | FSMC_D1_GPIO_CLK | FSMC_D2_GPIO_CLK |
- FSMC_D3_GPIO_CLK | FSMC_D4_GPIO_CLK | FSMC_D5_GPIO_CLK |
- FSMC_D6_GPIO_CLK | FSMC_D7_GPIO_CLK | FSMC_D8_GPIO_CLK |
- FSMC_D9_GPIO_CLK | FSMC_D10_GPIO_CLK| FSMC_D11_GPIO_CLK|
- FSMC_D12_GPIO_CLK| FSMC_D13_GPIO_CLK| FSMC_D14_GPIO_CLK|
- FSMC_D15_GPIO_CLK|
-
- FSMC_CS_GPIO_CLK | FSMC_WE_GPIO_CLK | FSMC_OE_GPIO_CLK |
- FSMC_UDQM_GPIO_CLK|FSMC_LDQM_GPIO_CLK, ENABLE);
-
-
-
- GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
- GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
-
-
- GPIO_InitStructure.GPIO_Pin = FSMC_A0_GPIO_PIN;
- GPIO_Init(FSMC_A0_GPIO_PORT, &GPIO_InitStructure);
- GPIO_PinAFConfig(FSMC_A0_GPIO_PORT,FSMC_A0_GPIO_PinSource,FSMC_GPIO_AF);
-
- GPIO_InitStructure.GPIO_Pin = FSMC_A1_GPIO_PIN;
- GPIO_Init(FSMC_A1_GPIO_PORT, &GPIO_InitStructure);
- GPIO_PinAFConfig(FSMC_A1_GPIO_PORT,FSMC_A1_GPIO_PinSource,FSMC_GPIO_AF);
-
- GPIO_InitStructure.GPIO_Pin = FSMC_A2_GPIO_PIN;
- GPIO_Init(FSMC_A2_GPIO_PORT, &GPIO_InitStructure);
- GPIO_PinAFConfig(FSMC_A2_GPIO_PORT,FSMC_A2_GPIO_PinSource,FSMC_GPIO_AF);
-
- GPIO_InitStructure.GPIO_Pin = FSMC_A3_GPIO_PIN;
- GPIO_Init(FSMC_A3_GPIO_PORT, &GPIO_InitStructure);
- GPIO_PinAFConfig(FSMC_A3_GPIO_PORT,FSMC_A3_GPIO_PinSource,FSMC_GPIO_AF);
-
- GPIO_InitStructure.GPIO_Pin = FSMC_A4_GPIO_PIN;
- GPIO_Init(FSMC_A4_GPIO_PORT, &GPIO_InitStructure);
- GPIO_PinAFConfig(FSMC_A4_GPIO_PORT,FSMC_A4_GPIO_PinSource,FSMC_GPIO_AF);
-
- GPIO_InitStructure.GPIO_Pin = FSMC_A5_GPIO_PIN;
- GPIO_Init(FSMC_A5_GPIO_PORT, &GPIO_InitStructure);
- GPIO_PinAFConfig(FSMC_A5_GPIO_PORT,FSMC_A5_GPIO_PinSource,FSMC_GPIO_AF);
-
- GPIO_InitStructure.GPIO_Pin = FSMC_A6_GPIO_PIN;
- GPIO_Init(FSMC_A6_GPIO_PORT, &GPIO_InitStructure);
- GPIO_PinAFConfig(FSMC_A6_GPIO_PORT,FSMC_A6_GPIO_PinSource,FSMC_GPIO_AF);
-
- GPIO_InitStructure.GPIO_Pin = FSMC_A7_GPIO_PIN;
- GPIO_Init(FSMC_A7_GPIO_PORT, &GPIO_InitStructure);
- GPIO_PinAFConfig(FSMC_A7_GPIO_PORT,FSMC_A7_GPIO_PinSource,FSMC_GPIO_AF);
-
- GPIO_InitStructure.GPIO_Pin = FSMC_A8_GPIO_PIN;
- GPIO_Init(FSMC_A8_GPIO_PORT, &GPIO_InitStructure);
- GPIO_PinAFConfig(FSMC_A8_GPIO_PORT,FSMC_A8_GPIO_PinSource,FSMC_GPIO_AF);
-
- GPIO_InitStructure.GPIO_Pin = FSMC_A9_GPIO_PIN;
- GPIO_Init(FSMC_A9_GPIO_PORT, &GPIO_InitStructure);
- GPIO_PinAFConfig(FSMC_A9_GPIO_PORT,FSMC_A9_GPIO_PinSource,FSMC_GPIO_AF);
-
- GPIO_InitStructure.GPIO_Pin = FSMC_A10_GPIO_PIN;
- GPIO_Init(FSMC_A10_GPIO_PORT, &GPIO_InitStructure);
- GPIO_PinAFConfig(FSMC_A10_GPIO_PORT,FSMC_A10_GPIO_PinSource,FSMC_GPIO_AF);
-
- GPIO_InitStructure.GPIO_Pin = FSMC_A11_GPIO_PIN;
- GPIO_Init(FSMC_A11_GPIO_PORT, &GPIO_InitStructure);
- GPIO_PinAFConfig(FSMC_A11_GPIO_PORT,FSMC_A11_GPIO_PinSource,FSMC_GPIO_AF);
-
- GPIO_InitStructure.GPIO_Pin = FSMC_A12_GPIO_PIN;
- GPIO_Init(FSMC_A12_GPIO_PORT, &GPIO_InitStructure);
- GPIO_PinAFConfig(FSMC_A12_GPIO_PORT,FSMC_A12_GPIO_PinSource,FSMC_GPIO_AF);
-
- GPIO_InitStructure.GPIO_Pin = FSMC_A13_GPIO_PIN;
- GPIO_Init(FSMC_A13_GPIO_PORT, &GPIO_InitStructure);
- GPIO_PinAFConfig(FSMC_A13_GPIO_PORT,FSMC_A13_GPIO_PinSource,FSMC_GPIO_AF);
-
- GPIO_InitStructure.GPIO_Pin = FSMC_A14_GPIO_PIN;
- GPIO_Init(FSMC_A14_GPIO_PORT, &GPIO_InitStructure);
- GPIO_PinAFConfig(FSMC_A14_GPIO_PORT,FSMC_A14_GPIO_PinSource,FSMC_GPIO_AF);
-
- GPIO_InitStructure.GPIO_Pin = FSMC_A15_GPIO_PIN;
- GPIO_Init(FSMC_A15_GPIO_PORT, &GPIO_InitStructure);
- GPIO_PinAFConfig(FSMC_A15_GPIO_PORT,FSMC_A15_GPIO_PinSource,FSMC_GPIO_AF);
-
- GPIO_InitStructure.GPIO_Pin = FSMC_A16_GPIO_PIN;
- GPIO_Init(FSMC_A16_GPIO_PORT, &GPIO_InitStructure);
- GPIO_PinAFConfig(FSMC_A16_GPIO_PORT,FSMC_A16_GPIO_PinSource,FSMC_GPIO_AF);
-
- GPIO_InitStructure.GPIO_Pin = FSMC_A17_GPIO_PIN;
- GPIO_Init(FSMC_A17_GPIO_PORT, &GPIO_InitStructure);
- GPIO_PinAFConfig(FSMC_A17_GPIO_PORT,FSMC_A17_GPIO_PinSource,FSMC_GPIO_AF);
-
- GPIO_InitStructure.GPIO_Pin = FSMC_A18_GPIO_PIN;
- GPIO_Init(FSMC_A18_GPIO_PORT, &GPIO_InitStructure);
- GPIO_PinAFConfig(FSMC_A18_GPIO_PORT,FSMC_A18_GPIO_PinSource,FSMC_GPIO_AF);
-
-
- GPIO_InitStructure.GPIO_Pin = FSMC_D0_GPIO_PIN;
- GPIO_Init(FSMC_D0_GPIO_PORT, &GPIO_InitStructure);
- GPIO_PinAFConfig(FSMC_D0_GPIO_PORT,FSMC_D0_GPIO_PinSource,FSMC_GPIO_AF);
-
- GPIO_InitStructure.GPIO_Pin = FSMC_D1_GPIO_PIN;
- GPIO_Init(FSMC_D1_GPIO_PORT, &GPIO_InitStructure);
- GPIO_PinAFConfig(FSMC_D1_GPIO_PORT,FSMC_D1_GPIO_PinSource,FSMC_GPIO_AF);
-
- GPIO_InitStructure.GPIO_Pin = FSMC_D2_GPIO_PIN;
- GPIO_Init(FSMC_D2_GPIO_PORT, &GPIO_InitStructure);
- GPIO_PinAFConfig(FSMC_D2_GPIO_PORT,FSMC_D2_GPIO_PinSource,FSMC_GPIO_AF);
-
- GPIO_InitStructure.GPIO_Pin = FSMC_D3_GPIO_PIN;
- GPIO_Init(FSMC_D3_GPIO_PORT, &GPIO_InitStructure);
- GPIO_PinAFConfig(FSMC_D3_GPIO_PORT,FSMC_D3_GPIO_PinSource,FSMC_GPIO_AF);
-
- GPIO_InitStructure.GPIO_Pin = FSMC_D4_GPIO_PIN;
- GPIO_Init(FSMC_D4_GPIO_PORT, &GPIO_InitStructure);
- GPIO_PinAFConfig(FSMC_D4_GPIO_PORT,FSMC_D4_GPIO_PinSource,FSMC_GPIO_AF);
-
- GPIO_InitStructure.GPIO_Pin = FSMC_D5_GPIO_PIN;
- GPIO_Init(FSMC_D5_GPIO_PORT, &GPIO_InitStructure);
- GPIO_PinAFConfig(FSMC_D5_GPIO_PORT,FSMC_D5_GPIO_PinSource,FSMC_GPIO_AF);
-
- GPIO_InitStructure.GPIO_Pin = FSMC_D6_GPIO_PIN;
- GPIO_Init(FSMC_D6_GPIO_PORT, &GPIO_InitStructure);
- GPIO_PinAFConfig(FSMC_D6_GPIO_PORT,FSMC_D6_GPIO_PinSource,FSMC_GPIO_AF);
-
- GPIO_InitStructure.GPIO_Pin = FSMC_D7_GPIO_PIN;
- GPIO_Init(FSMC_D7_GPIO_PORT, &GPIO_InitStructure);
- GPIO_PinAFConfig(FSMC_D7_GPIO_PORT,FSMC_D7_GPIO_PinSource,FSMC_GPIO_AF);
-
- GPIO_InitStructure.GPIO_Pin = FSMC_D8_GPIO_PIN;
- GPIO_Init(FSMC_D8_GPIO_PORT, &GPIO_InitStructure);
- GPIO_PinAFConfig(FSMC_D8_GPIO_PORT,FSMC_D8_GPIO_PinSource,FSMC_GPIO_AF);
-
- GPIO_InitStructure.GPIO_Pin = FSMC_D9_GPIO_PIN;
- GPIO_Init(FSMC_D9_GPIO_PORT, &GPIO_InitStructure);
- GPIO_PinAFConfig(FSMC_D9_GPIO_PORT,FSMC_D9_GPIO_PinSource,FSMC_GPIO_AF);
-
- GPIO_InitStructure.GPIO_Pin = FSMC_D10_GPIO_PIN;
- GPIO_Init(FSMC_D10_GPIO_PORT, &GPIO_InitStructure);
- GPIO_PinAFConfig(FSMC_D10_GPIO_PORT,FSMC_D10_GPIO_PinSource,FSMC_GPIO_AF);
-
- GPIO_InitStructure.GPIO_Pin = FSMC_D11_GPIO_PIN;
- GPIO_Init(FSMC_D11_GPIO_PORT, &GPIO_InitStructure);
- GPIO_PinAFConfig(FSMC_D11_GPIO_PORT,FSMC_D11_GPIO_PinSource,FSMC_GPIO_AF);
-
- GPIO_InitStructure.GPIO_Pin = FSMC_D12_GPIO_PIN;
- GPIO_Init(FSMC_D12_GPIO_PORT, &GPIO_InitStructure);
- GPIO_PinAFConfig(FSMC_D12_GPIO_PORT,FSMC_D12_GPIO_PinSource,FSMC_GPIO_AF);
-
- GPIO_InitStructure.GPIO_Pin = FSMC_D13_GPIO_PIN;
- GPIO_Init(FSMC_D13_GPIO_PORT, &GPIO_InitStructure);
- GPIO_PinAFConfig(FSMC_D13_GPIO_PORT,FSMC_D13_GPIO_PinSource,FSMC_GPIO_AF);
-
- GPIO_InitStructure.GPIO_Pin = FSMC_D14_GPIO_PIN;
- GPIO_Init(FSMC_D14_GPIO_PORT, &GPIO_InitStructure);
- GPIO_PinAFConfig(FSMC_D14_GPIO_PORT,FSMC_D14_GPIO_PinSource,FSMC_GPIO_AF);
-
- GPIO_InitStructure.GPIO_Pin = FSMC_D15_GPIO_PIN;
- GPIO_Init(FSMC_D15_GPIO_PORT, &GPIO_InitStructure);
- GPIO_PinAFConfig(FSMC_D15_GPIO_PORT,FSMC_D15_GPIO_PinSource,FSMC_GPIO_AF);
-
-
- GPIO_InitStructure.GPIO_Pin = FSMC_CS_GPIO_PIN;
- GPIO_Init(FSMC_CS_GPIO_PORT, &GPIO_InitStructure);
- GPIO_PinAFConfig(FSMC_CS_GPIO_PORT,FSMC_CS_GPIO_PinSource,FSMC_GPIO_AF);
-
- GPIO_InitStructure.GPIO_Pin = FSMC_WE_GPIO_PIN;
- GPIO_Init(FSMC_WE_GPIO_PORT, &GPIO_InitStructure);
- GPIO_PinAFConfig(FSMC_WE_GPIO_PORT,FSMC_WE_GPIO_PinSource,FSMC_GPIO_AF);
-
- GPIO_InitStructure.GPIO_Pin = FSMC_OE_GPIO_PIN;
- GPIO_Init(FSMC_OE_GPIO_PORT, &GPIO_InitStructure);
- GPIO_PinAFConfig(FSMC_OE_GPIO_PORT,FSMC_OE_GPIO_PinSource,FSMC_GPIO_AF);
-
- GPIO_InitStructure.GPIO_Pin = FSMC_UDQM_GPIO_PIN;
- GPIO_Init(FSMC_UDQM_GPIO_PORT, &GPIO_InitStructure);
- GPIO_PinAFConfig(FSMC_UDQM_GPIO_PORT,FSMC_UDQM_GPIO_PinSource,FSMC_GPIO_AF);
-
- GPIO_InitStructure.GPIO_Pin = FSMC_LDQM_GPIO_PIN;
- GPIO_Init(FSMC_LDQM_GPIO_PORT, &GPIO_InitStructure);
- GPIO_PinAFConfig(FSMC_LDQM_GPIO_PORT,FSMC_LDQM_GPIO_PinSource,FSMC_GPIO_AF);
- }
- void FSMC_SRAM_Init(void)
- {
- FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
- FSMC_NORSRAMTimingInitTypeDef readWriteTiming;
-
- SRAM_GPIO_Config();
-
-
- RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC,ENABLE);
-
- readWriteTiming.FSMC_AddressSetupTime = 0x00;
-
- readWriteTiming.FSMC_AddressHoldTime = 0x00;
-
- readWriteTiming.FSMC_DataSetupTime = 0x02;
-
-
- readWriteTiming.FSMC_BusTurnAroundDuration = 0x00;
-
-
-
- readWriteTiming.FSMC_CLKDivision = 0xf;
-
-
- readWriteTiming.FSMC_DataLatency = 0xf;
-
-
- readWriteTiming.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 = &readWriteTiming;
-
-
- FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &readWriteTiming;
-
- FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
- FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM3, ENABLE);
-
- }
-
- void SRAM_WriteBuffer(uint32_t* pBuffer, uint32_t uwWriteAddress, uint32_t uwBufferSize)
- {
- __IO uint32_t write_pointer = (uint32_t)uwWriteAddress;
-
-
- for (; uwBufferSize != 0; uwBufferSize--)
- {
-
- *(uint32_t *) (Bank1_SRAM3_ADDR + write_pointer) = *pBuffer++;
-
- write_pointer += 4;
- }
-
- }
- void SRAM_ReadBuffer(uint32_t* pBuffer, uint32_t uwReadAddress, uint32_t uwBufferSize)
- {
- __IO uint32_t write_pointer = (uint32_t)uwReadAddress;
-
-
-
- for(; uwBufferSize != 0x00; uwBufferSize--)
- {
- *pBuffer++ = *(__IO uint32_t *)(Bank1_SRAM3_ADDR + write_pointer );
-
-
- write_pointer += 4;
- }
- }
- uint8_t SRAM_Test(void)
- {
-
- uint32_t counter=0;
-
-
- uint8_t ubWritedata_8b = 0, ubReaddata_8b = 0;
-
-
- uint16_t uhWritedata_16b = 0, uhReaddata_16b = 0;
-
- SRAM_INFO("正在检测SRAM,以8位、16位的方式读写sram...");
-
-
-
- for (counter = 0x00; counter < IS62WV51216_SIZE; counter++)
- {
- *(__IO uint8_t*) (Bank1_SRAM3_ADDR + counter) = (uint8_t)0x0;
- }
-
-
- for (counter = 0; counter < IS62WV51216_SIZE; counter++)
- {
- *(__IO uint8_t*) (Bank1_SRAM3_ADDR + counter) = (uint8_t)(ubWritedata_8b + counter);
- }
-
-
- for(counter = 0; counter<IS62WV51216_SIZE;counter++ )
- {
- ubReaddata_8b = *(__IO uint8_t*)(Bank1_SRAM3_ADDR + counter);
-
- if(ubReaddata_8b != (uint8_t)(ubWritedata_8b + counter))
- {
- SRAM_ERROR("8位数据读写错误!");
- return 0;
- }
- }
-
-
-
-
- for (counter = 0x00; counter < IS62WV51216_SIZE/2; counter++)
- {
- *(__IO uint16_t*) (Bank1_SRAM3_ADDR + 2*counter) = (uint16_t)0x00;
- }
-
-
- for (counter = 0; counter < IS62WV51216_SIZE/2; counter++)
- {
- *(__IO uint16_t*) (Bank1_SRAM3_ADDR + 2*counter) = (uint16_t)(uhWritedata_16b + counter);
- }
-
-
- for(counter = 0; counter<IS62WV51216_SIZE/2;counter++ )
- {
- uhReaddata_16b = *(__IO uint16_t*)(Bank1_SRAM3_ADDR + 2*counter);
-
- if(uhReaddata_16b != (uint16_t)(uhWritedata_16b + counter))
- {
- SRAM_ERROR("16位数据读写错误!");
- return 0;
- }
- }
-
- SRAM_INFO("SRAM读写测试正常!");
-
- return 1;
- }
|