Advertisement
Guest User

Untitled

a guest
Sep 8th, 2015
400
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.29 KB | None | 0 0
  1. NOR_HandleTypeDef hnor;
  2. FMC_NORSRAM_TimingTypeDef NOR_Timing;
  3.  
  4. void NOR_Init(void)
  5. {
  6.     GPIO_InitTypeDef GPIO_Init_Structure;
  7.  
  8.     __HAL_RCC_FMC_CLK_ENABLE();
  9.     __HAL_RCC_FMC_FORCE_RESET();
  10.     __HAL_RCC_FMC_RELEASE_RESET();
  11.     __HAL_RCC_GPIOD_CLK_ENABLE();
  12.     __HAL_RCC_GPIOE_CLK_ENABLE();
  13.     __HAL_RCC_GPIOF_CLK_ENABLE();
  14.     __HAL_RCC_GPIOG_CLK_ENABLE();
  15.  
  16.  
  17.     GPIO_Init_Structure.Mode      = GPIO_MODE_AF_PP;
  18.     GPIO_Init_Structure.Pull      = GPIO_PULLUP;
  19.     GPIO_Init_Structure.Speed     = GPIO_SPEED_HIGH;
  20.     GPIO_Init_Structure.Alternate = GPIO_AF12_FMC;
  21.  
  22.     GPIO_Init_Structure.Pin   = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 |
  23.                                   GPIO_PIN_7 |
  24.                                   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.     hnor.Instance = FMC_NORSRAM_DEVICE;
  42.     hnor.Extended = FMC_NORSRAM_EXTENDED_DEVICE;
  43.  
  44.     NOR_Timing.AddressSetupTime = 15;
  45.     NOR_Timing.AddressHoldTime = 0;
  46.     NOR_Timing.DataSetupTime = 15;
  47.     NOR_Timing.BusTurnAroundDuration = 3;
  48.     NOR_Timing.CLKDivision = 0;
  49.     NOR_Timing.DataLatency = 0;
  50.     NOR_Timing.AccessMode = FMC_ACCESS_MODE_A;
  51.  
  52.     hnor.Init.NSBank = FMC_NORSRAM_BANK3;
  53.     hnor.Init.DataAddressMux = FMC_DATA_ADDRESS_MUX_DISABLE;
  54.     hnor.Init.MemoryType = FMC_MEMORY_TYPE_NOR;
  55.     hnor.Init.MemoryDataWidth = FMC_NORSRAM_MEM_BUS_WIDTH_16;
  56.     hnor.Init.BurstAccessMode = FMC_BURST_ACCESS_MODE_DISABLE;
  57.     hnor.Init.WaitSignalPolarity = FMC_WAIT_SIGNAL_POLARITY_LOW;
  58.     hnor.Init.WaitSignalActive = FMC_WAIT_TIMING_BEFORE_WS;
  59.     hnor.Init.WriteOperation = FMC_WRITE_OPERATION_ENABLE;
  60.     hnor.Init.WaitSignal = FMC_WAIT_SIGNAL_DISABLE;
  61.     hnor.Init.ExtendedMode = FMC_EXTENDED_MODE_DISABLE;
  62.     hnor.Init.AsynchronousWait = FMC_ASYNCHRONOUS_WAIT_DISABLE;
  63.     hnor.Init.WriteBurst = FMC_WRITE_BURST_DISABLE;
  64.     hnor.Init.ContinuousClock = FMC_CONTINUOUS_CLOCK_SYNC_ONLY;
  65.     hnor.Init.WriteFifo = FMC_WRITE_FIFO_DISABLE;
  66.  
  67.     /* Initialize the NOR controller */
  68.     if (HAL_NOR_Init(&hnor, &NOR_Timing, &NOR_Timing) != HAL_OK)
  69.     {
  70.         /* Initialization Error */
  71.         while(1);
  72.     }
  73.  
  74.     HAL_Delay(1000);
  75.  
  76. }
  77.  
  78. int main(void)
  79. {
  80.     MPU_Config();
  81.     CPU_CACHE_Enable();
  82.  
  83.     NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
  84.  
  85.     SystemClock_Config();
  86.     HAL_Init();
  87.     CLI_Init();
  88.     LED_Init();
  89.     NOR_Init();
  90.  
  91.     NOR_IDTypeDef norID;
  92.     HAL_NOR_Read_ID(&hnor, &norID);
  93.  
  94.     UartPort_Printf("ID: %u | %u\n", norID.Manufacturer_Code, norID.Device_Code1);
  95.  
  96.     while(1)
  97.     {
  98.         LED_Task();
  99.         CLI_Task();
  100.     }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement