Skip to main content
RLein.1
Associate III
July 29, 2022
Solved

Preloading a QSPI with STM32CubeIDE

  • July 29, 2022
  • 2 replies
  • 993 views

I'm working on a project using an STM32H753XI MCU with a touch display. I am not currently using TouchGFX. I would like to preload images into the onboard QSPI during the project load. How do I go about doing this? I have used TouchGFX designer on other projects and know this is automated while loading the project onto the PCA.

This topic has been closed for replies.
Best answer by Pavel A.

Either you can use the CubeProgrammer with a suitable "external loader", or make a simple utility to copy the data from your PC using semihosting I/O.

The latter is slow, not good for large amount of data.

A small example below:

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
extern void initialise_monitor_handles(void);
 
 
void load_stuff(void)
{
 printf("Semihosting! read big file from host\n");
 initialise_monitor_handles();
 
 const char * fname = "C:/TMP/stuff.bin";
 // if NO path: opens relative to openocd.exe (.../STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.openocd.../tools/bin/)
 int fd = open(fname, O_RDONLY|O_BINARY);
 if (fd <= 0) {
	 printf("Error open file!\n");
	 return;
 }
 
 static char buf[4096];
 unsigned offset = 0;
 while (1)
 {
 int rc = read(fd, buf, sizeof(buf));
 if (rc < 0) {
 	 printf("Error read!\n");
 	 break;
 }
 if (rc == 0) {
 	 printf("Read: normal end!\n");
 	 break;
 }
 
 QSPI_FlashWrite(offset , buf, rc);
 
 offset += (unsigned)rc;
 }
 printf("Read total: %u\n", offset );
 close(fd);
}

2 replies

Pavel A.
Pavel A.Best answer
July 29, 2022

Either you can use the CubeProgrammer with a suitable "external loader", or make a simple utility to copy the data from your PC using semihosting I/O.

The latter is slow, not good for large amount of data.

A small example below:

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
extern void initialise_monitor_handles(void);
 
 
void load_stuff(void)
{
 printf("Semihosting! read big file from host\n");
 initialise_monitor_handles();
 
 const char * fname = "C:/TMP/stuff.bin";
 // if NO path: opens relative to openocd.exe (.../STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.openocd.../tools/bin/)
 int fd = open(fname, O_RDONLY|O_BINARY);
 if (fd <= 0) {
	 printf("Error open file!\n");
	 return;
 }
 
 static char buf[4096];
 unsigned offset = 0;
 while (1)
 {
 int rc = read(fd, buf, sizeof(buf));
 if (rc < 0) {
 	 printf("Error read!\n");
 	 break;
 }
 if (rc == 0) {
 	 printf("Read: normal end!\n");
 	 break;
 }
 
 QSPI_FlashWrite(offset , buf, rc);
 
 offset += (unsigned)rc;
 }
 printf("Read total: %u\n", offset );
 close(fd);
}

Andreas Bolsch
Lead III
July 30, 2022

Depends on whether you use CubeProgrammer or OpenOCD inside CubeIDE.

For the former, everything had been said above. For the latter: Use stmqspi driver which comes with OpenOCD. For a sample setup see the cfg-files for stm32h754i-disco.