cancel
Showing results for 
Search instead for 
Did you mean: 

Issue when programming S29GL064S NOR flash using STM32 HAL libraries (HAL_NOR_Program & HAL_NOR_Read functions)

HLaro.2
Associate

Hello everyone,

Using a custom board designed by myself, I can't manage to program the content of an S29GL064S NOR Flash. I'm pretty confident with the schematics and layout as, when calling the function

HAL_NOR_Read_ID(&hnor1, &NOR_Id)

I get the following result

0693W00000APelCQAT.png 

These values seem to match what's expected according to the NOR Flash datasheet (link here)

When I try to program the memory content using the small piece of code written here:

#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 */
}

When I run this piece of code, here are the results I'm getting:

0693W00000APenDQAT.png 

For some reason, I seem to be getting the value of "ii" in each cell of my "Array" while that's obviously what's not requested in my code. I never manage to read back the value "0xbeef". I went through the content of the functions "HAL_NOR_Program" and "HAL_NOR_Read" and they seem to be pretty consistent with what's requested in the datasheet (Table 10.17 "Command Definitions").

I really tried to go to the bottom of this to make sure I did everything correctly before asking for help but I'm really lost here. Would anybody know what's wrong with my code and can help me fixing it?

Here is a print screen of my NOR Flash configuration in STM32CubeMX: 

0693W00000APdhZQAT.png 

I hope it's clear enough, don't hesitate if you need more details.

Thanks in advance for your help!

0 REPLIES 0