0

使用自己设计的定制板,我无法对 S29GL064S NOR Flash 的内容进行编程。在调用函数时,我对原理图和布局非常有信心

HAL_NOR_Read_ID(&hnor1, &NOR_Id)

我得到以下结果

在此处输入图像描述

根据 NOR Flash 数据表,这些值似乎符合预期(链接在这里

当我尝试使用此处编写的一小段代码对内存内容进行编程时:

#define NOR_MEMORY_ADRESS1       ((uint32_t)0x60000000)

int main(void)
{
  /* USER CODE BEGIN 1 */
    uint32_t Address = 0;
    uint16_t ReadData = 0;
    uint32_t ii=0;
    uint16_t WriteData =0;
    uint16_t *pWriteData    = &WriteData;
    uint16_t *pReadData     = &ReadData;
    uint32_t *pAddress      = &Address;
  /* USER CODE END 1 */

  /* MCU Configuration--------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_USART2_UART_Init();
  MX_SPI1_Init();
  MX_I2C1_Init();
  MX_FMC_Init();
  MX_USART1_UART_Init();
  MX_UART5_Init();
  MX_USART3_UART_Init();
  MX_SPI2_Init();
  MX_RTC_Init();
  MX_RNG_Init();

    HAL_NOR_Read_ID(&hnor1, &NOR_Id);

    WriteData = 0xbeef;
    for(ii=0; ii < 100; ii++)
    {
        Address = NOR_MEMORY_ADRESS1 + ii;
        HAL_NOR_Program(&hnor1, pAddress, pWriteData);

      if(HAL_NOR_GetStatus(&hnor1, Address, 1000) != HAL_NOR_STATUS_SUCCESS)
      {
        Error_Handler();
      }
    }


    for(ii=0; ii < 100; ii++)
    {
        Address = NOR_MEMORY_ADRESS1 + ii;
        HAL_NOR_Read(&hnor1, pAddress , pReadData);

          if(HAL_NOR_GetStatus(&hnor1, Address, 1000) != HAL_NOR_STATUS_SUCCESS)
          {
            Error_Handler();
          }

        Array[ii] = ReadData;
    }

    while (1)
  {

  }
}

void MX_FMC_Init(void)
{
  /* USER CODE BEGIN FMC_Init 0 */

  /* USER CODE END FMC_Init 0 */

  FMC_NORSRAM_TimingTypeDef Timing = {0};

  /* USER CODE BEGIN FMC_Init 1 */

  /* USER CODE END FMC_Init 1 */

  /** Perform the NOR1 memory initialization sequence
  */
  hnor1.Instance = FMC_NORSRAM_DEVICE;
  hnor1.Extended = FMC_NORSRAM_EXTENDED_DEVICE;
  /* hnor1.Init */
  hnor1.Init.NSBank = FMC_NORSRAM_BANK1;
  hnor1.Init.DataAddressMux = FMC_DATA_ADDRESS_MUX_DISABLE;
  hnor1.Init.MemoryType = FMC_MEMORY_TYPE_NOR;
  hnor1.Init.MemoryDataWidth = FMC_NORSRAM_MEM_BUS_WIDTH_16;
  hnor1.Init.BurstAccessMode = FMC_BURST_ACCESS_MODE_DISABLE;
  hnor1.Init.WaitSignalPolarity = FMC_WAIT_SIGNAL_POLARITY_HIGH;
  hnor1.Init.WaitSignalActive = FMC_WAIT_TIMING_BEFORE_WS;
  hnor1.Init.WriteOperation = FMC_WRITE_OPERATION_ENABLE;
  hnor1.Init.WaitSignal = FMC_WAIT_SIGNAL_DISABLE;
  hnor1.Init.ExtendedMode = FMC_EXTENDED_MODE_DISABLE;
  hnor1.Init.AsynchronousWait = FMC_ASYNCHRONOUS_WAIT_ENABLE;
  hnor1.Init.WriteBurst = FMC_WRITE_BURST_DISABLE;
  hnor1.Init.ContinuousClock = FMC_CONTINUOUS_CLOCK_SYNC_ONLY;
  hnor1.Init.WriteFifo = FMC_WRITE_FIFO_DISABLE;
  hnor1.Init.NBLSetupTime = 0;
  hnor1.Init.PageSize = FMC_PAGE_SIZE_NONE;
  /* Timing */
  Timing.AddressSetupTime = 15;
  Timing.AddressHoldTime = 15;
  Timing.DataSetupTime = 255;
  Timing.DataHoldTime = 0;
  Timing.BusTurnAroundDuration = 15;
  Timing.CLKDivision = 16;
  Timing.DataLatency = 17;
  Timing.AccessMode = FMC_ACCESS_MODE_A;
  /* ExtTiming */

  if (HAL_NOR_Init(&hnor1, &Timing, NULL) != HAL_OK)
  {
    Error_Handler( );
  }

  /* USER CODE BEGIN FMC_Init 2 */

  /* USER CODE END FMC_Init 2 */
}

void Error_Handler(void)
{
  /* USER CODE BEGIN Error_Handler_Debug */
  /* User can add his own implementation to report the HAL error return state */
    while(1)
    {

    }
  /* USER CODE END Error_Handler_Debug */
}

当我运行这段代码时,我得到的结果如下:

在此处输入图像描述

出于某种原因,我似乎在我的“数组”的每个单元格中都得到了“ii”的值,而这显然是我的代码中没有要求的。我从来没有设法读回值“0xbeef”。我浏览了函数“HAL_NOR_Program”和“HAL_NOR_Read”的内容,它们似乎与数据表中的要求非常一致(表 10.17“命令定义”)。

在寻求帮助之前,我真的试图深入了解这一点,以确保我做的一切都是正确的,但我真的迷路了。有人知道我的代码有什么问题并可以帮助我修复它吗?

这是我在 STM32CubeMX 中的 NOR Flash 配置的打印屏幕: 在此处输入图像描述

我希望它足够清楚,如果您需要更多详细信息,请不要犹豫。

在此先感谢您的帮助!

4

0 回答 0