cancel
Showing results for 
Search instead for 
Did you mean: 

QSPI: Write/Read strings from QSPI memory

Rick MC
Associate III
Posted on June 06, 2018 at 14:23

Hello,

I implemented some functions to read and write the QSPI memory by using functions HAL_QSPI_Transmit() and HAL_QSPI_Receive() provided by the libraries.

Everything works fine. I just wonder how I can write and read strings using these functions.

I want to write:

   char myString[100][50];

but the above functions have a uint8_t as an input!

Is there any way to do so, other than passing a single character at a time?

Thanks,

#read #strings #write #qspi
1 ACCEPTED SOLUTION

Accepted Solutions
Posted on June 06, 2018 at 17:21

Use a cast?

char myString[50];

BSP_QSPI_Write((void *)myString, Address, sizeof(myString));

BSP_QSPI_Write((uint8_t *)&myString[0], Address, sizeof(myString));

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

7 REPLIES 7
Posted on June 06, 2018 at 16:56

>>Is there any way to do so, other than passing a single character at a time?

Clearly there would be a means to achieving it.

STM32Cube_FW_F7_V1.11.0\Drivers\BSP\STM32F769I-Discovery\stm32f769i_discovery_qspi.c

BSP_QSPI_Write(Buffer, Address, Size)

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on June 06, 2018 at 17:16

Thanks!

But how can I put my string (let's say char myString[50]) inside the Buffer in 

BSP_QSPI_Write()?

This function only accepts uint8_t as a buffer and I have a chars!

Posted on June 06, 2018 at 17:21

Use a cast?

char myString[50];

BSP_QSPI_Write((void *)myString, Address, sizeof(myString));

BSP_QSPI_Write((uint8_t *)&myString[0], Address, sizeof(myString));

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on June 06, 2018 at 17:28

Thank you very much! I was casting in a wrong way.. 

Posted on June 06, 2018 at 17:49

>>Thank you very much! I was casting in a wrong way.. 

C can be like that, and the cast frequently stops the compiler complaining when it would be helpful that it did.

char myString[100][50];

BSP_QSPI_Write((void *)&myString[0][0], Address, sizeof(myString)); // Base address of my array - writing to QSPI FLASH as a binary blob

Several ways to do this, the form like this might be clearer to a subsequent reader of the code, or future self, that you really want the address of the base elements of the array as the starting point.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on June 08, 2018 at 14:45

I have an additional question that comes to mind. 

Instead of writing and reading the QSPI memory, can I use a variable to point to one of its block addresses? 

For example, I want to point to the QSPI memory with a variable like this:

   char myVariable[50]

I need an alternative to Write and Read because I need to write a lot and it takes to much time...

Thanks!

Posted on June 08, 2018 at 17:27

I don't believe you can write-in-place

Reading

char *myVariable = (char *)0x90001234;

You could do similar things using the linker script, or scatter file, to create a NOINIT region where you direct QSPI structures into.

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