cancel
Showing results for 
Search instead for 
Did you mean: 

Stm32l4r9 octospi mode is configured as Quad SPI and memory mapping is enabled, but it cannot be accessed by address. Once the address of 0x90000000 is read, MCU will make hardware error??

Zlian.1
Associate II

1. It is correct to read and write flash through command function when there is no memory mapping enabled( flash:MX25R6435F )

2. After memory mapping is enabled, after accessing the address of 0x90000000, the MCU crashes and cannot recognize the chip. I suspect that there is a problem with the configuration memory mapping?? Please help me!!!

-----------------------------------------------------------------------------------------------------------------------------------

//Enable memory mapping

uint8_t BSP_OSPI_NOR_EnableMemoryMappedMode(void)

{

 OSPI_RegularCmdTypeDef  s_command;

 OSPI_MemoryMappedTypeDef s_mem_mapped_cfg = {0};

 /* Initialize the read command */

if (OSPI_NOR_WriteEnable(&hospi1) != HAL_OK)

 {

  return HAL_ERROR;

 }

 s_command.OperationType     = HAL_OSPI_OPTYPE_READ_CFG;

 s_command.FlashId        = HAL_OSPI_FLASH_ID_1;

 s_command.InstructionMode    = HAL_OSPI_INSTRUCTION_1_LINE;

 s_command.InstructionSize    = HAL_OSPI_INSTRUCTION_8_BITS;

 s_command.AddressMode      = HAL_OSPI_ADDRESS_1_LINE;

 s_command.AddressSize      = HAL_OSPI_ADDRESS_24_BITS;

 s_command.AlternateBytesMode  = HAL_OSPI_ALTERNATE_BYTES_NONE;

 s_command.DataMode       = HAL_OSPI_DATA_4_LINES;

 s_command.DummyCycles      = 8;

 s_command.SIOOMode       = HAL_OSPI_SIOO_INST_EVERY_CMD;

 s_command.Instruction      = MX25R6435F_FLASH_CMD_FAST_READ;//MX25R6435F_FLASH_CMD_4READ;

s_command.Address = 0;

s_command.NbData = 1;

 s_command.DQSMode        = HAL_OSPI_DQS_DISABLE;

/* Send the read command */

if (HAL_OSPI_Command(&hospi1, &s_command, HAL_OSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)

{

mprintf("BSP_OSPI_NOR_Read %d",__LINE__);

  return HAL_ERROR;

}

s_command.OperationType = HAL_OSPI_OPTYPE_WRITE_CFG;

 s_command.Instruction      = MX25R6435F_FLASH_CMD_4PP;

 s_command.InstructionMode    = HAL_OSPI_INSTRUCTION_1_LINE;

 s_command.InstructionSize    = HAL_OSPI_INSTRUCTION_8_BITS;

 s_command.AddressMode      = HAL_OSPI_ADDRESS_4_LINES;

 s_command.AddressSize      = HAL_OSPI_ADDRESS_24_BITS;

 s_command.DataMode       = HAL_OSPI_DATA_4_LINES;

 s_command.DummyCycles      = 0;

s_command.DQSMode        = HAL_OSPI_DQS_ENABLE;

/* Send the write command */

if (HAL_OSPI_Command(&hospi1, &s_command, HAL_OSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)

{

mprintf("BSP_OSPI_NOR_Read %d",__LINE__);

  return HAL_ERROR;

}

/* Configure the memory mapped mode */

s_mem_mapped_cfg.TimeOutActivation = HAL_OSPI_TIMEOUT_COUNTER_DISABLE;

if (HAL_OSPI_MemoryMapped(&hospi1, &s_mem_mapped_cfg) != HAL_OK)

{

mprintf("BSP_OSPI_NOR_Read %d",__LINE__);

  return HAL_ERROR;

}

//uint8_t * psram = (uint8_t *)0x90000000;

//mprintf("psram[0]=%d [1]=%d [2]=%d [3]=%d",psram[0],psram[1],psram[2],psram[3]);

 return HAL_OK;

}

1 ACCEPTED SOLUTION

Accepted Solutions

1) You should do the read/write/erase operations in command mode. An equivalent read command that works properly in command mode should also be viable when you switch into memory-mapped mode.

2) What exactly is happening? It Hard Faults?

Unfortunately the provided code lacks a lot of detail/context to determine what it wrong.

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

View solution in original post

2 REPLIES 2

1) You should do the read/write/erase operations in command mode. An equivalent read command that works properly in command mode should also be viable when you switch into memory-mapped mode.

2) What exactly is happening? It Hard Faults?

Unfortunately the provided code lacks a lot of detail/context to determine what it wrong.

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

Thank you. I have settled it