8 years, 7 months ago.

Using QSPI on STM32F746 Disco

The STM32F746NG-Disco is equipped with a quad spi (QSPI) Flash memory unit. I am trying to read an integer from a certain adres, incrementing it and storing it at the same adres. For one or other reason either the read or write (perhaps both) do not seem to work. When reading from an adres I retrieve value 0 (I get a succes value). After incrementing with 1 I try to store it (again with positive feedback that it should have stored 1. Now, on the next iteration, I try to read the new value, but the value appears to be equal to 0...

I am using the following code:

My code

#include "mbed.h"
#include "QSPI_DISCO_F746NG.h"

QSPI_DISCO_F746NG qspi;
Serial pc(USBTX, USBRX);

#define BUFFER_SIZE         ((uint32_t)32)
#define WRITE_READ_ADDR     ((uint32_t)0x0050)
#define QSPI_BASE_ADDR      ((uint32_t)0x90000000)

int main()
{
    QSPI_Info pQSPI_Info;
    uint8_t Counter = 0;

    pc.printf("\n\nQSPI demo started\n");

    // Check initialization
    if (qspi.Init() != QSPI_OK) {
        error("Initialization FAILED\n");
    } else {
        pc.printf("Initialization PASSED\n");
    }
    
    qspi.Erase_Block(WRITE_READ_ADDR);

    // Check memory informations
    qspi.GetInfo(&pQSPI_Info);
    if ((pQSPI_Info.FlashSize          != N25Q128A_FLASH_SIZE) ||
            (pQSPI_Info.EraseSectorSize    != N25Q128A_SUBSECTOR_SIZE) ||
            (pQSPI_Info.ProgPageSize       != N25Q128A_PAGE_SIZE) ||
            (pQSPI_Info.EraseSectorsNumber != N25Q128A_SUBSECTOR_SIZE) ||
            (pQSPI_Info.ProgPagesNumber    != N25Q128A_SECTOR_SIZE)) {
        error("Get informations FAILED\n");
    } else {
        pc.printf("Get informations PASSED\n");
    }

    // Read memory
    if (qspi.Read(&Counter, WRITE_READ_ADDR, 1) != QSPI_OK) {
        error("Read FAILED\r\n");
    } else {
        pc.printf("Initial Counter Value: %d\r\n", Counter);
    }

    while(1) {
        if (qspi.Read(&Counter, WRITE_READ_ADDR, 1) != QSPI_OK) {
            error("Read FAILED\r\n");
        } else {
            pc.printf("Counter after read: %d\r\n", Counter);
        }
        wait(1);
        Counter++;
        pc.printf("Local counter after increment: %d\r\n", Counter);

        // write memory
        if (qspi.Write(&Counter, WRITE_READ_ADDR, 1) != QSPI_OK) {
            error("Store procedure failed\r\n");
        } else {
            pc.printf("Stored succesfully the following counter: %d\r\n", Counter);
        }
    }
}

1 Answer

8 years, 7 months ago.

Hi, I think that qspi write only once after erase. if you write 0xaa and after that you write 0x55 then qspi value is 0.

Accepted Answer

Thanks a million times, that seems to work. But could you explain why an adress first needs to be cleared before writing a new value? This does not seem intuitive for me.

posted by Alex van Rijs 26 May 2016

Hi, See "Memory Configuration and Block Diagram" of the datasheet. There are "Bits are programmed from one through zero" and "Bits are erased from zero through one".

posted by Yoshitsugu Kikuchi 27 May 2016