Skip to content

Commit 916909a

Browse files
author
deepikabhavnani
committed
QSPI example for default mode, read-write
1 parent b949532 commit 916909a

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

QSPI/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# QSPI example #
2+
3+
QSPI driver usage example for mbed OS
4+
5+
This is a example showing how to use mbed-OS QSPI driver to access a device interfaced over Quad-SPI
6+
The program does read/write operations on Flash memory connected over Quad-SPI interface using driver APIs in default QSPI mode.
7+
8+
QSPI can be configured into different modes, based on underlying interface support. Refer to QSPI flash block device for more information (https://github.com/ARMmbed/qspif-blockdevice)

QSPI/main.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#if !DEVICE_QSPI
2+
#error [NOT_SUPPORTED] QSPI not supported for this target
3+
#endif
4+
5+
#include "mbed.h"
6+
#include "drivers/QSPI.h"
7+
8+
#define CMD_WRITE 0x02
9+
#define CMD_READ 0x03
10+
#define ADDRESS 0x1000
11+
#define BUF_SIZE 10
12+
13+
// hardware ssel (where applicable)
14+
QSPI qspi_device(QSPI_FLASH1_IO0, QSPI_FLASH1_IO1, QSPI_FLASH1_IO2, QSPI_FLASH1_IO3, QSPI_FLASH1_SCK, QSPI_FLASH1_CSN); // io0, io1, io2, io3, sclk, ssel
15+
16+
int main() {
17+
char tx_buf[] = { 'h', 'e', 'l', 'l', 'o', '\n' };
18+
char rx_buf[BUF_SIZE];
19+
size_t buf_len = sizeof(tx_buf);
20+
qspi_status_t result;
21+
22+
result = qspi_device.configure_format(QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_SINGLE,
23+
QSPI_CFG_ADDR_SIZE_24, QSPI_CFG_BUS_SINGLE,
24+
QSPI_CFG_ALT_SIZE_8, QSPI_CFG_BUS_SINGLE, 0);
25+
if (result != QSPI_STATUS_OK) {
26+
printf("Config format failed\n");
27+
}
28+
29+
qspi_device.set_frequency(10000000);
30+
result = qspi_device.write(CMD_WRITE, 0, ADDRESS, tx_buf, &buf_len);
31+
if (result != QSPI_STATUS_OK) {
32+
printf("Write failed\n");
33+
return result;
34+
}
35+
printf("Write done: %s \n", tx_buf);
36+
37+
result = qspi_device.read(CMD_READ, 0, ADDRESS, rx_buf, &buf_len);
38+
if (result != QSPI_STATUS_OK) {
39+
printf("Read failed\n");
40+
return result;
41+
}
42+
printf ("Data Read = %s\n", rx_buf);
43+
return 0;
44+
}

0 commit comments

Comments
 (0)