Unable to boot correct code from QSPI flash

Hi,

Recently i encountered booting problem with my bare metal application and my custom Cyclone V board.

My app is running correctly when loaded via JTAG directly to SDRAM, but im unable to make it running from QSPI flash memory (or any external non-volatile memory).

The most scary part is that i made it run (and properly boot) a couple of times just by changing application code debug messages (for example from “Init” to “Initxxxxxxxx”). So i assume that problem is somehow related maybe to linker script or final app image (note that changes that made app running probably doesnt have any side effects). Sometimes it starts to work by adding couple of spaces at the end of debug message. Sometimes it starts running just by adding a random for loop doin nothing :open_mouth:

I tested that issue on couple dev boards (Cyclone V SoC Developement Kit, De0 nano SoC and custom board), while booting from QSPI Flash and SD card. Results were the same.

Any of u guys encountered this kind of problem ?

Hey en2,

I experienced similar things in past but on a completely different Platform ( non FPGA )

It ended up with a timing issue…

basically i would look into data transfer between qspi and fpga. Clocks are vital here.

I had an issue with the SD Card and arria 10, randomly block read errors in linux.
It scrapped my whole OS… I looked into it and the Clock setup was not valid. I changed the clocks and it worked…

baasically similar with a non synced uart, ( 9600 baud vs 9620 baud ) at some point it can not catch valid data.

( the reason why it worked for you by randomly add space and co is that it had time to resync or just to overpass the non valid read.)

If You write direct to SDRAM You overjump the QSPI.

My recomend… try a working linux image for the de0 nano soc which has a propper qspi working and then check the quartus project settings there for the qspi. ( clocks, bits, connection, etc. IMPORTANT also look into the dts for additional settings. )

Greetings

Thomas

Hi Thomas.

Thanks for your fast and detailed answer.

I got your point but im not initializing any hardware by myself. The preloader is doing everything for me. When execution Is beeing passed to my program in sdram im just using peripherals as usual. Note that i was facing same issue on altera board where preloader and whole handoff folder was prepared by vendor. And it was hapening both with qspi and sd card.

Is it possible that uboot Is initializing clocks with wrong values ?

Going to compare axf files with and without extra spaces tomorrow to see where the difference really Is.