Advertisement
Guest User

Untitled

a guest
Sep 8th, 2015
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.98 KB | None | 0 0
  1. #define SRAM_MEMORY_WIDTH       FMC_NORSRAM_MEM_BUS_WIDTH_16
  2. #define SRAM_CONTINUOUS_CLOCK   FMC_CONTINUOUS_CLOCK_SYNC_ONLY
  3.  
  4. SRAM_HandleTypeDef hsram;
  5. FMC_NORSRAM_TimingTypeDef SRAM_Timing;
  6.  
  7. void SRAM_Init(void)
  8. {
  9.     GPIO_InitTypeDef GPIO_Init_Structure;
  10.  
  11.     __HAL_RCC_FMC_CLK_ENABLE();
  12.  
  13.     __HAL_RCC_GPIOD_CLK_ENABLE();
  14.     __HAL_RCC_GPIOE_CLK_ENABLE();
  15.     __HAL_RCC_GPIOF_CLK_ENABLE();
  16.     __HAL_RCC_GPIOG_CLK_ENABLE();
  17.  
  18.     GPIO_Init_Structure.Mode      = GPIO_MODE_AF_PP;
  19.     GPIO_Init_Structure.Pull      = GPIO_PULLUP;
  20.     GPIO_Init_Structure.Speed     = GPIO_SPEED_HIGH;
  21.     GPIO_Init_Structure.Alternate = GPIO_AF12_FMC;
  22.  
  23.     GPIO_Init_Structure.Pin   = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 |
  24.                                   GPIO_PIN_7 | GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 |
  25.                                   GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15;
  26.     HAL_GPIO_Init(GPIOD, &GPIO_Init_Structure);
  27.  
  28.     GPIO_Init_Structure.Pin   =   GPIO_PIN_0 | GPIO_PIN_1 |GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 |
  29.                                   GPIO_PIN_7 | GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 |
  30.                                   GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15;
  31.     HAL_GPIO_Init(GPIOE, &GPIO_Init_Structure);
  32.  
  33.     GPIO_Init_Structure.Pin   = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2| GPIO_PIN_3 | GPIO_PIN_4 |
  34.                                   GPIO_PIN_5 | GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15;
  35.     HAL_GPIO_Init(GPIOF, &GPIO_Init_Structure);
  36.  
  37.     GPIO_Init_Structure.Pin   = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2| GPIO_PIN_3 | GPIO_PIN_4 |
  38.                                   GPIO_PIN_5 | GPIO_PIN_9 | GPIO_PIN_10;
  39.     HAL_GPIO_Init(GPIOG, &GPIO_Init_Structure);
  40.  
  41.     hsram.Instance = FMC_NORSRAM_DEVICE;
  42.     hsram.Extended = FMC_NORSRAM_EXTENDED_DEVICE;
  43.  
  44.     SRAM_Timing.AddressSetupTime = 6;
  45.     SRAM_Timing.AddressHoldTime = 7;        //DC
  46.     SRAM_Timing.DataSetupTime = 6;
  47.     SRAM_Timing.BusTurnAroundDuration = 6;  //DC
  48.     SRAM_Timing.CLKDivision = 2;            //DC
  49.     SRAM_Timing.DataLatency = 12;           //DC
  50.     SRAM_Timing.AccessMode = FMC_ACCESS_MODE_A; //DC
  51.  
  52.     hsram.Init.NSBank = FMC_NORSRAM_BANK1;
  53.     hsram.Init.DataAddressMux = FMC_DATA_ADDRESS_MUX_DISABLE;
  54.     hsram.Init.MemoryType = FMC_MEMORY_TYPE_SRAM;
  55.     hsram.Init.MemoryDataWidth = SRAM_MEMORY_WIDTH;
  56.     hsram.Init.BurstAccessMode = FMC_BURST_ACCESS_MODE_DISABLE;
  57.     hsram.Init.WaitSignalPolarity = FMC_WAIT_SIGNAL_POLARITY_LOW;
  58.     hsram.Init.WaitSignalActive = FMC_WAIT_TIMING_BEFORE_WS;
  59.     hsram.Init.WriteOperation = FMC_WRITE_OPERATION_ENABLE;
  60.     hsram.Init.WaitSignal = FMC_WAIT_SIGNAL_DISABLE;
  61.     hsram.Init.ExtendedMode = FMC_EXTENDED_MODE_DISABLE;
  62.     hsram.Init.AsynchronousWait = FMC_ASYNCHRONOUS_WAIT_DISABLE;
  63.     hsram.Init.WriteBurst = FMC_WRITE_BURST_DISABLE;
  64.     hsram.Init.ContinuousClock = SRAM_CONTINUOUS_CLOCK;
  65.     hsram.Init.WriteFifo = FMC_WRITE_FIFO_DISABLE;
  66.  
  67.     /* Initialize the SRAM controller */
  68.     if (HAL_SRAM_Init(&hsram, &SRAM_Timing, &SRAM_Timing) != HAL_OK)
  69.     {
  70.         /* Initialization Error */
  71.         while(1);
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement