cancel
Showing results for 
Search instead for 
Did you mean: 

CSP_QSPI_WriteMemory writes data from buffer with offset

AWęgl.1
Associate II

I work on a custom board with STM32H745BITx, and what I'm trying to do is to make external loader using one of ST MOOCs:

https://www.st.com/content/st_com/en/support/learning/stm32-education/stm32-moocs/external_QSPI_loader.html

That's the code that I've used as my base:

https://github.com/STMicroelectronics/stm32-external-loader/tree/contrib

I can confirm that the board is working as I've worked on it using QSPI with IRQ and I have not encountered an issue like this.

  uint8_t buffer_test[MEMORY_SECTOR_SIZE];
  uint8_t tab[MEMORY_SECTOR_SIZE]; // test tab used to check memory that's saved in flash memory
 
  uint32_t var = 0;
 
  CSP_QUADSPI_Init();
 
  for (var = 0; var < MEMORY_SECTOR_SIZE; var++) {
      buffer_test[var] = (var & 0xff);
  }
 
  for (var = 0; var < SECTORS_COUNT; var++) {
 
      if (CSP_QSPI_EraseSector(var * MEMORY_SECTOR_SIZE,
                               (var + 1) * MEMORY_SECTOR_SIZE - 1) != HAL_OK) {
 
          while (1)
              ;  //breakpoint - error detected
      }
 
// +0 is a temporary value that was used to check different offsets of the buffer - explained later in the post
      if (CSP_QSPI_WriteMemory(buffer_test, var * MEMORY_SECTOR_SIZE + 0, sizeof(buffer_test)) != HAL_OK) {
 
          while (1)
              ;  //breakpoint - error detected
      }
 
  }
 
  if (CSP_QSPI_EnableMemoryMappedMode() != HAL_OK) {
 
      while (1)
          ; //breakpoint - error detected
  }
// checking data inside of the memory - this is where I can see the "offset"
  memcpy(tab, (uint8_t*) (0x90000000+ 0 * MEMORY_SECTOR_SIZE) , MEMORY_SECTOR_SIZE);
  for (var = 0; var < SECTORS_COUNT; var++) {
// this memcmp breaks because data on the device does not match what's inside of the buffer
      if (memcmp(buffer_test,
                 (uint8_t*) (0x90000000 + var * MEMORY_SECTOR_SIZE),
                 MEMORY_SECTOR_SIZE) != HAL_OK) {
          while (1)
              ;  //breakpoint - error detected - otherwise QSPI works properly
      }
  }
 
  /* USER CODE END 2 */
 
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */
 
    /* USER CODE BEGIN 3 */
  }

When using memcmp on buffer and data in sectors that were written, it seems as if the data in device's memory starts with an offset of 1.

Buffer consists of numbers starting from 0 up to 255

reading the data, it returns numbers from 1 to 255 and ends at 0

When adding an offset of 1 to the start address of CSP_QSPI_WriteMemory command, it starts from 0 and ends at 255 - when changing the buffer data, it still ended in 255, as if it didn't write any data to the last byte

Setting the offset to 2 results in a similar behavior, but (as expected) it starts with 255, 0 and ends with 253, 255.

If it were to be written to memory with an offset, I'd expect it to end with 253 254.

It seems as if the memory is written with an offset which starts saving the memory one byte before the specified address.

It can be seen by reading the last byte of each sector - it has data from what should be the start of the next sector.

Any help would be greately appreciated as I'm on my wits' end

1 REPLY 1

Likely not in the code shown.

What part are you using?

Failure here is indicative of setting the 3/4-byte mode wrong

Would try 1, 2 and 4-bit reads to confirm that works. Could also try explicit commands with know bit/address sizes

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