Forum Discussion
Questions About GSFI, QSPI Flash XIP Boot, and HAL API Support
Hi Wantanabe,
Thank you for the detailed questions. Please see my answers below.
1. XIP boot from QSPI flash together with dual configuration
From a system architecture point of view, this combination should work. On MAX 10, the two configuration images are stored in the internal configuration flash (CFM). The QSPI flash connected through the GSFI is general purpose memory and is not used for FPGA configuration, so FPGA configuration and Nios V XIP boot are independent of each other. Please note that we do not have a documented reference design that combines the two, so I recommend validating it on your board.
One documented requirement for the XIP flow: in the BSP Editor, disable the GSFI driver (intel_generic_serial_flash_interface_top) on the BSP Drivers tab, as described in the Nios V Embedded Processor Design Handbook. If the driver initializes the GSFI while the CPU is fetching code from it, the boot does not complete.
In addition, I would suggest the following considerations for your design:
Each configuration image has its own Nios V system. If both images run the same application, they can share the same software location in QSPI. If they run different applications, we recommend placing each application at a different offset in the QSPI flash and setting the Nios V Reset Agent offset in each image to match.
Reconfiguring the FPGA (for example through the Dual Configuration IP) does not power cycle the external QSPI flash, so the flash should keep its current state, such as the addressing mode. Please make sure the addressing mode setting (bit 8 of the Control Register in the GSFI Default Settings) matches the flash state in both images, and avoid triggering reconfiguration while a flash erase or program operation is in progress.
Our guidance for the MAX 10 FPGA Development Kit, which uses the same N25Q512A83GSF40F device, is that the flash is in 4-byte addressing mode after power cycle, and that the SPI Clock Baud-rate Register should be set to 0x1 (/2) when the GSFI runs on a 50 MHz clock. The default /32 divisor can cause a race condition during XIP. If your 10M50 Evaluation Kit is a different board, please confirm these settings against your board schematic and the flash datasheet.
2. GSFI HAL API with Quartus Prime Lite Edition
That is correct. The GSFI User Guide states that the HAL driver is supported in Quartus Prime Pro Edition software only. MAX 10 devices are supported in Quartus Prime Standard and Lite Edition, so the GSFI HAL API is not available for your setup. The GSFI IP itself supports MAX 10 for general purpose memory. Only the HAL software driver is not available.
Reference: Generic Serial Flash Interface IP User Guide, section Intel HAL Driver
hal-driver
3. N25Q512A83GSF40F support in the HAL API
The HAL API supports only the flash families listed in the same section of the user guide (for Micron, the MT25QL and MT25QU variants). The N25Q512A is not on that list, so it is not a supported device for the HAL driver. Because of point 2, the HAL driver is not an option in Lite Edition in any case. This does not affect the XIP boot itself, since the XIP flow does not use the HAL driver.
4. Recommended way to read and write the QSPI flash
We do not recommend erasing or programming the same QSPI flash that the Nios V is executing from. The GSFI services only one of its two Avalon ports (avl_csr or avl_mem) at a time, and while an erase or program operation is running, the flash is generally not able to return instruction data for the CPU. This can stall or hang the processor. Depending on your requirements, we suggest one of the following approaches:
Read only: If you only need to read data (for example constants or parameters), you can keep XIP and read the data directly through the memory-mapped GSFI avl_mem region, for example with a pointer or memcpy(). No driver is needed for this.
Read and write with a single flash: Use the boot copier method instead of XIP (Nios V processor application copied from general purpose QSPI flash to RAM using Bootloader via GSFI, described in the Nios V Embedded Processor Design Handbook). The application then runs from OCRAM or external RAM, and the flash is free for erase and program commands through the GSFI CSR interface.
Read and write while keeping XIP: Add a second QSPI flash device to your board, connected to FPGA general purpose I/O pins, with its own GSFI instance for data storage, and keep the boot flash read only. Please note that this requires additional hardware, for example an add-on flash on an expansion header or a custom board. A separate GSFI instance is needed because a single GSFI cannot service code fetches from the boot flash while it performs erase or program operations, even if both flashes are connected to it through different chip selects.
Since the HAL driver is not available in Lite Edition, the erase and program operations need to be implemented by accessing the GSFI registers directly. The section "Flash Access Using the Generic Serial Flash Interface IP" in the GSFI IP User Guide describes the register sequences (write enable, erase, program, and reading the status and flag status registers). Please use the command opcodes from the N25Q512A datasheet. As described in the user guide, always issue write enable before any write or erase operation, and read the flag status register after every write or erase command until the operation completes. Also make sure your commands use the same addressing mode (3-byte or 4-byte) as the flash and the GSFI Control Register setting.