The W25Q32 (32M-bit) Serial Flash memory provide a storage solution for systems with limited space, pins and power. It offers flexibility and performance well beyond ordinary Serial Flash devices. It is ideal for code shadowing to RAM, executing code directly from Dual/Quad SPI and storing voice, text and data. The devices operate on a single 2.7V to 3.6V power supply with current consumption as low as 5mA active and 1µA for power-down.
Protocol:
The W25Q32 supports the standard Serial Peripheral Interface (SPI). SPI clock frequencies of up to 80MHz are supported allowing equivalent clock rates of 160MHz for Dual Output and 320MHz for Quad Output when using the Fast Read Dual/Quad Output instructions. These transfer rates are comparable to those of 8 and 16-bit Parallel Flash memories.
Step 1: What You Will Need
- Arty7 35t/100t board with either
pinaka, parashu or vajra
programmed - W25Q32 Sensor.
- Micro USB Cable.
- Jumper Wires.
- shakti-sdk and shakti-tools installed or Platform IO installed and ready
Note: shakti-sdk
and shakti-tools
are currently a private repository. Please login or sign up to Gitlab and request access here before using it.
Step 2: The Circuit
Connection of W25Q32 sensors:
- d1 to SPI MOSI
- d0 to SPI MISO.
- clk to SPI CLK.
- cs to SPI CS.
Step 3: Code
Please click here to have a look at the code of w25q32_write.
Please click here to have a look at the code of w25q32_read.
Code can be compiled and run using the following ways,
- Using terminal on a system with shakti-sdk and shakti-tools installed (Manual method).
- Using Platform IO IDE.
Step 4.1: Manual Method
4.1.1 Compile and build
- Move to
shakti-sdk
cd shakti-sdk
- Compile using
make software PROGRAM=? TARGET=?
. Typemake list_applns
to list all the applications available in the SDK. Target can be eitherparashu, pinaka or vajra
.
For instance, Use target as parashu
,
make software PROGRAM=w25q32_write TARGET=parashu
make software PROGRAM=w25q32_read TARGET=parashu
4.1.2 Execution:
Once the application is built, the executable is generated in the output folder. The executable is in ELF
file format and they have the extension .shakti
. Now, open three terminals, one for each of the following,
- One terminal for UART terminal display
(miniterm)
- Another for
OpenOCD
. - And the last one for
GDB server
.
Terminal 1: Firstly, Connect to serial output by using miniterm or gtkterm with the baud rate of 19200.
For instance,
$ sudo miniterm.py /dev/ttyUSB1 19200
Note:
- “/dev/ttyUSB1” – ttyUSB means “USB serial port adapter”
- The “1” (“0” or “1” or “2”“here means the USB device number on your system. The FPGA board is connected to that USB device number.
Terminal 2: After that, Connect to the FPGA board by using the OpenOCD provided by shakti-tools and its respective configuration file. (Read how OpenOCD and RISC-V GDB work together to establish a connection between our PC and the Microprocessor)
For instance, if we use parashu,
$ cd shakti-sdk $ cd ./bsp/third_party/parashu $ sudo $(which openocd) -f ftdi.cfg
For pinaka and vajra, Goto cd ./bsp/third_party/<pinaka
or vajra
>
Terminal 3: Now, open either 32-bit or 64-bit RISC-V GDB based on your architecture i.e riscv32-unknown-elf-gdb
or riscv64-unknown-elf-gdb
respectively from shakti-tools.
The output executable is created in,
For write: <path-to-shakti-sdk>/software/examples/spi_applns/w25q32_write/output
as w25q32_write.shakti
.
For read: <path-to-shakti-sdk>/software/examples/spi_applns/w25q32_read/output
as w25q32_read.shakti
.
Load up the .shakti
file by following the below steps. For Parashu,
$ riscv32-unknown-elf-gdb
(gdb) set remotetimeout unlimited (gdb) target remote localhost:3333 (gdb) file path/to/executable (gdb) load (gdb) c
4.1.3 Upload to flash
Steps to generate standalone user application:
The SHAKTI-SDK has a uploader tool that is used to load a content (such as ELF) to flash, after building the image.
- Goto the right directory.
cd shakti-sdk
- The make upload command is used to build and upload the application to the flash automatically.
make upload PROGRAM=w25q32_write TARGET=parashu
make upload PROGRAM=w25q32_read TARGET=parashu
PROGRAM is the new bare metal user application that is created. Type make list_applns
to list all the applications available in the SDK.
Step 4.2: Using Platform IO
We can use IDE’s like Platform IO to compile, build, run, upload and debug. Please read the article on Platform IO on SHAKTI to understand the steps.
Miniterm Output for WRITE:
--- Miniterm on /dev/ttyUSB1: 19200,8,N,1 --- --- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H --- (( ,((((( *(((((( ./((((((( ./(((((((( *((((((((( .((((((((((( ,(((((((((((( (((((((((((((( .(((((((((((((( *((((((((((( /((((((( *(((((((( *((((((( ((((((((( (((((((((( ((((((((((((( (((((((((((((( (((((((((((( *(((((((((( ((((((((( *((((((( *(((((( .((((( ./((( SHAKTI PROCESSORS Booting… vspi1.0 Booting on Parashu! hart 0 Parashu is a SoC build on top of Artix7 100T. The core belongs to Shakti E class, 32 bit. Supported ISA: RV32ACIMNU. Processor Arch ID: 0. Device ID 1 extracted device id 2018 . . . . . . . Control transferred to RAM period Register of module number 0 set to 0 Duty Register of module number 0 set to 0 Control Register of module number 0 set to 0 All registers of module number 0 cleared Period Register of module number 1 set to 0 Duty Register of module number 1 set to 0 Control Register of module number 1 set to 0 All registers of module number 1 cleared Period Register of module number 2 set to 0 Duty Register of module number 2 set to 0 Control Register of module number 2 set to 0 All registers of module number 2 cleared Period Register of module number 3 set to 0 Duty Register of module number 3 set to 0 Control Register of module number 3 set to 0 All registers of module number 3 cleared Period Register of module number 4 set to 0 Duty Register of module number 4 set to 0 Control Register of module number 4 set to 0 All registers of module number 4 cleared Period Register of module number 5 set to 0 Duty Register of module number 5 set to 0 Control Register of module number 5 set to 0 All registers of module number 5 cleared All Register values of all modules clearedinit entered trap_init entered trap_init exited SPI init done Device ID ef extracted device id 4016 Cypress erase Erase dr1 Cypress erase done Flash write done on address 100 and tmp 0 Cypress erase Erase dr1 Cypress erase done Flash write done on address 104 and tmp 1 . . . . . . Cypress erase Erase dr1 Cypress erase done Flash write done on address 290 and tmp 64 SPI Write Success
Miniterm Output for READ:
--- Miniterm on /dev/ttyUSB1: 19200,8,N,1 --- --- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H --- (( ,((((( *(((((( ./((((((( ./(((((((( *((((((((( .((((((((((( ,(((((((((((( (((((((((((((( .(((((((((((((( *((((((((((( /((((((( *(((((((( *((((((( ((((((((( (((((((((( ((((((((((((( (((((((((((((( (((((((((((( *(((((((((( ((((((((( *((((((( *(((((( .((((( ./((( SHAKTI PROCESSORS Booting… vspi1.0 Booting on Parashu! hart 0 Parashu is a SoC build on top of Artix7 100T. The core belongs to Shakti E class, 32 bit. Supported ISA: RV32ACIMNU. Processor Arch ID: 0. Device ID 1 extracted device id 2018 . . . . . . . Control transferred to RAM Reading from adddress 100 and data 0 Reading from adddress 104 and data 1 Reading from adddress 108 and data 2 Reading from adddress 10c and data 3 Reading from adddress 110 and data 4 Reading from adddress 114 and data 5 Reading from adddress 118 and data 6 ... ... ... Reading from adddress 284 and data 61 Reading from adddress 288 and data 62 Reading from adddress 28c and data 63 SPI Read Success
Akshaya currently works at the RISE labs. Her favorite subjects are Web designing and Microprocessors. She loves learning about new things and writing about them!