cancel
Showing results for 
Search instead for 
Did you mean: 

Failing to get an MT25QL128 to run over OCTOSPI2

G_Anastasopoulos
Associate III

Dear All,

I am struggling with getting an MT25QL128 chip to work fully on my board.
The connection of the flash chip to my STM32U599NJH6Q is like this:

G_Anastasopoulos_0-1717436433852.png

On the MCU side this corresponds to this configuration to the CubeMX:

G_Anastasopoulos_1-1717436521590.pngG_Anastasopoulos_2-1717436537327.png

I am quite confident that my custom hardware works, because I am able to read the ID of the chip like this:

 

int main(void)
{

  /* USER CODE BEGIN 1 */

  /* 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();

  /* Configure the System Power */
  SystemPower_Config();

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_ICACHE_Init();
  MX_FDCAN1_Init();
  MX_FLASH_Init();
  MX_USART2_UART_Init();
  MX_I2C1_Init();
  MX_ADC4_Init();
  MX_SDMMC1_SD_Init();
  MX_OCTOSPI2_Init();
  /* USER CODE BEGIN 2 */
  OSPI_RegularCmdTypeDef sCommand = {0};
  uint8_t data[20 /*40*/] ={0}; // Six to read pair of 3-byte ID's from dual banked IC

  sCommand.OperationType      = HAL_OSPI_OPTYPE_COMMON_CFG;
  sCommand.FlashId            = HAL_OSPI_FLASH_ID_1;

  sCommand.Instruction        = 0x9F;

  sCommand.InstructionMode    = HAL_OSPI_INSTRUCTION_1_LINE;
  sCommand.InstructionSize    = HAL_OSPI_INSTRUCTION_8_BITS;
  sCommand.InstructionDtrMode = HAL_OSPI_INSTRUCTION_DTR_DISABLE;

  sCommand.AddressDtrMode     = HAL_OSPI_ADDRESS_DTR_DISABLE;
  sCommand.AlternateBytesMode = HAL_OSPI_ALTERNATE_BYTES_NONE;

  sCommand.DataMode           = HAL_OSPI_DATA_1_LINE;
  sCommand.NbData             = sizeof(data);

  sCommand.DataDtrMode        = HAL_OSPI_DATA_DTR_DISABLE;
  sCommand.DummyCycles        = 0;
  if (HAL_OSPI_Command(&hospi2, &sCommand, HAL_OSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
  {
	  Error_Handler();
  }

  if (HAL_OSPI_Receive(&hospi2, data, HAL_OSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
  {
	  Error_Handler();
  }
  
  while (1) {
	  uint8_t line[128]={0};
	  snprintf(line, sizeof(line), "ID: ");
	  HAL_UART_Transmit(&huart2, line, sizeof(line), HAL_MAX_DELAY);
	  for (int i = 0; i < sizeof(data); i++) {
		memset(line, 0, sizeof(line));
		snprintf(line, sizeof(line), "0x%02X ", data[i]);
		HAL_UART_Transmit(&huart2, line, sizeof(line), HAL_MAX_DELAY);
	  }
	  memset(line, 0, sizeof(line));
	  snprintf(line, sizeof(line), "\r\n");
	  HAL_UART_Transmit(&huart2, line, sizeof(line), HAL_MAX_DELAY);
	  HAL_Delay(10000);
  }
}

 

 I am stuck beyond this point. I have seen on the AN5050 document that there is a sample that interfaces a QSPI PSRAM. I thought that this sample would steer me to the right direction, even though RAM and FLASH are quite different, but so far I have not been able to make any success in writing and reading data to the external flash.
Furthermore, I have seen the OSPI_NOR_MemoryMapped example found in the examples for the STM32U575I-EV in the STM32Cube_FW_U5_V1.5.0. This sample though is meant for an OCTOSPI flash and I am not sure how to modify it to fit my use case (if it can be modified at all to fit this hardware).

So any samples, tutorials or directions on how to tackle this issue would be very helpful.

Ideally I would like a solution configuring the device to Memory mapped mode.

Best regards,
Giannis

10 REPLIES 10

Attachments are hard to annotate / correct

There's a lot of code in here (qspi_flash.c) assuming a DUAL chip configuration, ie TWO of the same chip side-by-side

    sConfig.Match = 0x0202;
    sConfig.Mask = 0x0202;
    sConfig.MatchMode = HAL_OSPI_MATCH_MODE_AND;

This is not the case for a single-up MT25QL128 which is going to report a single byte status register, unlike the MT25TL512 which has a pair of 256Mb die and provides 2-bytes, one from each die, interleaved.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..