/**
  * @brief  Initializes the NOR device.
  * @retval NOR memory status
  */
uint8_t BSP_NOR_Init(void)
{ 
  static uint8_t nor_status = NOR_STATUS_ERROR;
  norHandle.Instance  = FMC_NORSRAM_DEVICE;
  norHandle.Extended  = FMC_NORSRAM_EXTENDED_DEVICE;
  
  /* NOR device configuration */
  /* Timing configuration derived from system clock (up to 216Mhz)
     for 108Mhz as NOR clock frequency */  
  Timing.AddressSetupTime      = 4;
  Timing.AddressHoldTime       = 3;
  Timing.DataSetupTime         = 8;
  Timing.BusTurnAroundDuration = 1;
  Timing.CLKDivision           = 2;
  Timing.DataLatency           = 2;
  Timing.AccessMode            = FMC_ACCESS_MODE_A;
  
  norHandle.Init.NSBank             = FMC_NORSRAM_BANK1;
  norHandle.Init.DataAddressMux     = FMC_DATA_ADDRESS_MUX_DISABLE;
  norHandle.Init.MemoryType         = FMC_MEMORY_TYPE_NOR;
  norHandle.Init.MemoryDataWidth    = NOR_MEMORY_WIDTH;
  norHandle.Init.BurstAccessMode    = NOR_BURSTACCESS;
  norHandle.Init.WaitSignalPolarity = FMC_WAIT_SIGNAL_POLARITY_LOW;
  norHandle.Init.WaitSignalActive   = FMC_WAIT_TIMING_BEFORE_WS;
  norHandle.Init.WriteOperation     = FMC_WRITE_OPERATION_ENABLE;
  norHandle.Init.WaitSignal         = FMC_WAIT_SIGNAL_ENABLE;
  norHandle.Init.ExtendedMode       = FMC_EXTENDED_MODE_DISABLE;
  norHandle.Init.AsynchronousWait   = FMC_ASYNCHRONOUS_WAIT_ENABLE;
  norHandle.Init.WriteBurst         = NOR_WRITEBURST;
  norHandle.Init.ContinuousClock    = CONTINUOUSCLOCK_FEATURE;
    
  /* NOR controller initialization */
  BSP_NOR_MspInit(&norHandle, NULL); /* __weak function can be rewritten by the application */
  
  if(HAL_NOR_Init(&norHandle, &Timing, &Timing) != HAL_OK)
  {
    nor_status = NOR_STATUS_ERROR;
  }
  else
  {
    nor_status = NOR_STATUS_OK;
  }
  return nor_status;
}
/**
  * @brief  Initializes the NOR device.
  * @retval NOR memory status
  */
uint8_t BSP_NOR_Init(void)
{
    NorHandle.Instance  = FMC_NORSRAM_DEVICE;
    NorHandle.Extended  = FMC_NORSRAM_EXTENDED_DEVICE;

    /* NOR device configuration */
    Timing.AddressSetupTime      = 8;
    Timing.AddressHoldTime       = 3;
    Timing.DataSetupTime         = 9;
    Timing.BusTurnAroundDuration = 0;
    Timing.CLKDivision           = 2;
    Timing.DataLatency           = 2;
    Timing.AccessMode            = FMC_ACCESS_MODE_A;

    NorHandle.Init.NSBank             = FMC_NORSRAM_BANK1;
    NorHandle.Init.DataAddressMux     = FMC_DATA_ADDRESS_MUX_DISABLE;
    NorHandle.Init.MemoryType         = FMC_MEMORY_TYPE_NOR;
    NorHandle.Init.MemoryDataWidth    = NOR_MEMORY_WIDTH;
    NorHandle.Init.BurstAccessMode    = NOR_BURSTACCESS;
    NorHandle.Init.WaitSignalPolarity = FMC_WAIT_SIGNAL_POLARITY_LOW;
    NorHandle.Init.WrapMode           = FMC_WRAP_MODE_DISABLE;
    NorHandle.Init.WaitSignalActive   = FMC_WAIT_TIMING_BEFORE_WS;
    NorHandle.Init.WriteOperation     = FMC_WRITE_OPERATION_ENABLE;
    NorHandle.Init.WaitSignal         = FMC_WAIT_SIGNAL_ENABLE;
    NorHandle.Init.ExtendedMode       = FMC_EXTENDED_MODE_DISABLE;
    NorHandle.Init.AsynchronousWait   = FMC_ASYNCHRONOUS_WAIT_ENABLE;
    NorHandle.Init.WriteBurst         = NOR_WRITEBURST;
    NorHandle.Init.ContinuousClock    = CONTINUOUSCLOCK_FEATURE;

    /* NOR controller initialization */
    BSP_NOR_MspInit(&NorHandle, NULL);

    if(HAL_NOR_Init(&NorHandle, &Timing, &Timing) != HAL_OK)
    {
        return NOR_STATUS_ERROR;
    }
    else
    {
        return NOR_STATUS_OK;
    }
}