How to program simple data to OCTOSPI external flash?
Hi!
I have a custom board with a STM32H725. The board has an external OCTOSPI flash memory from Infineon's S26KL/S26KS-series. I can read/write data back and fourth in memory-mapped-mode and now I want to be able to program persistent data using the indirect mode.
I am not sure I got the pointers right, but the prgramming sequence is given from Infineo's memory docmentation as below.
After the programming, I switch to memory-mapped-mode and use the memory debugger to read data at 0x70000000, but there is no data there...
My implementation of above sequence:
char* Buffer = "Data to be programmed into flash";
uint32_t Size = 32;
uint32_t base_addr = 0x70000000;
uint32_t sector_addr = 0x00000000;
ProgramFlashWithBuffer(base_addr, sector_addr, Size, (uint8_t*)Buffer);
EnableMemMapped();
void ProgramFlashWithBuffer(uint32_t base_addr, uint32_t sector_addr, uint32_t buf_size, uint8_t* buffer)
{
// Programming sequence for S26KL/S26KS
// -------------------------------------
WriteCommand(0x555, 1,(uint8_t*)0xAA); // Write unlock cycle 1
WriteCommand(0x2AA, 1, (uint8_t*)0x55); // Write unlock cycle 2
WriteCommand(sector_addr, 1, (uint8_t*)0x55); // Write buffer load command
WriteCommand(sector_addr, buf_size-1, buffer); // Transfer the actual buffer (count -1)
WriteCommand(sector_addr,1, (uint8_t*)0x29); // Finally, send write confirm command
}
void WriteCommand(uint32_t addr, uint32_t size, uint8_t* data)
{
OSPI_HyperbusCmdTypeDef sCommand;
// Memory command config
sCommand.AddressSpace =HAL_OSPI_MEMORY_ADDRESS_SPACE;
sCommand.AddressSize = HAL_OSPI_ADDRESS_32_BITS;
sCommand.DQSMode = HAL_OSPI_DQS_ENABLE;
sCommand.NbData = size;
sCommand.Address = addr;
// Send command and data in indirect mode
if (HAL_OSPI_HyperbusCmd(&hospi2, &sCommand, HAL_OSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
Error_Handler();
}
if (HAL_OSPI_Transmit(&hospi2, (uint8_t*)&data, HAL_OSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
Error_Handler();
}
}Please, I am really stuck here and any help would be highly appreciated
Thanks in advance