Skip to content

Commit 9f627f6

Browse files
open the QSPI for Seeed XIAO BLE and add example code of it
how to compile the libmbed.a for QSPI: 1 git clone https://github.com/Seeed-Studio/ArduinoCore-mbed.git 2 git clone https://github.com/arduino/mbed-os.git 3 cd mbed-os/ 4 git apply /path/of/ArduinoCore-mbed/patch/0091-add-support-for-Seeed-XIAO-BLE.patch 5 git apply /path/of/ArduinoCore-mbed/patch/0092-open-the-QSPI-for-Seeed-XIAO-BLE.patch 6 cd ArduinoCore-mbed/ 7 ./mbed-os-to-arduino -r /absolute/path/of/mbed-os/ SEEED_XIAO_NRF52840_SENSE:SEEED_XIAO_NRF52840_SENSE
1 parent 8947d24 commit 9f627f6

File tree

2 files changed

+133
-0
lines changed

2 files changed

+133
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
Spi Flash write read demo
3+
This demo is based on Seeed XIAO BLE.
4+
The spi flash chip is P25Q16H(https://www.puyasemi.com/uploadfiles/2018/08/20180807152503253.pdf)
5+
*/
6+
7+
#include "QSPIFBlockDevice.h"
8+
9+
using namespace mbed;
10+
11+
QSPIFBlockDevice root(QSPI_FLASH1_IO0, QSPI_FLASH1_IO1, QSPI_FLASH1_IO2, QSPI_FLASH1_IO3, QSPI_FLASH1_SCK, QSPI_FLASH1_CSN, QSPIF_POLARITY_MODE_1, MBED_CONF_QSPIF_QSPI_FREQ);
12+
13+
void setup() {
14+
15+
Serial.begin(115200);
16+
while (!Serial);
17+
18+
Serial.println("init the spi flash...");
19+
int ret = root.init();
20+
if(ret) {
21+
Serial.print("init error. err code=");
22+
Serial.println(ret);
23+
}
24+
25+
Serial.print("QSPIF BD size:");
26+
Serial.println(root.size());
27+
Serial.print("QSPIF read size:");
28+
Serial.println(root.get_read_size());
29+
Serial.print("QSPIF program size:");
30+
Serial.println(root.get_program_size());
31+
uint64_t sector_size_at_address_0 = root.get_erase_size(0);
32+
Serial.print("QSPIF erase size:");
33+
Serial.println(sector_size_at_address_0);
34+
35+
// Init the buffer for write and read
36+
char *write_buffer = (char *) malloc(sector_size_at_address_0);
37+
char *read_buffer = (char *) malloc(sector_size_at_address_0);
38+
memset(write_buffer, 0x00, sector_size_at_address_0);
39+
memset(read_buffer, 0x00, sector_size_at_address_0);
40+
41+
// Write the data to the spi flash
42+
sprintf(write_buffer, "Hello World!\n");
43+
Serial.println("writing data to spi flash...");
44+
root.erase(0, sector_size_at_address_0);
45+
root.program(write_buffer, 0, sector_size_at_address_0);
46+
47+
// Read back what was stored
48+
Serial.println("Reading data from spi flash...");
49+
root.read(read_buffer, 0, sector_size_at_address_0);
50+
Serial.println(read_buffer);
51+
52+
if(!memcmp(write_buffer, read_buffer, sector_size_at_address_0)){
53+
Serial.println("spi flash read write success");
54+
} else {
55+
Serial.println("spi flash read write failed");
56+
}
57+
58+
root.deinit();
59+
}
60+
61+
void loop() {
62+
63+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
From 61180bcbb9bf8f9b139cff3a1fe625890e49fe2f Mon Sep 17 00:00:00 2001
2+
From: bbear <953308023@qq.com>
3+
Date: Wed, 26 Jan 2022 08:50:29 +0000
4+
Subject: [PATCH] open the QSPI for Seeed XIAO BLE
5+
6+
---
7+
storage/blockdevice/COMPONENT_QSPIF/mbed_lib.json | 3 ++-
8+
.../TARGET_SEEED_XIAO_NRF52840_SENSE/PinNames.h | 15 +++++++++++++++
9+
targets/targets.json | 4 ----
10+
3 files changed, 17 insertions(+), 5 deletions(-)
11+
12+
diff --git a/storage/blockdevice/COMPONENT_QSPIF/mbed_lib.json b/storage/blockdevice/COMPONENT_QSPIF/mbed_lib.json
13+
index ca461079..24c86d6e 100644
14+
--- a/storage/blockdevice/COMPONENT_QSPIF/mbed_lib.json
15+
+++ b/storage/blockdevice/COMPONENT_QSPIF/mbed_lib.json
16+
@@ -37,7 +37,8 @@
17+
"MCU_NRF52840": {
18+
"QSPI_FREQ": "32000000",
19+
"QSPI_MIN_READ_SIZE": "4",
20+
- "QSPI_MIN_PROG_SIZE": "4"
21+
+ "QSPI_MIN_PROG_SIZE": "4",
22+
+ "qspif.direct-reset": true
23+
},
24+
"MCU_PSOC6": {
25+
"QSPI_FREQ": "50000000"
26+
diff --git a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52840/TARGET_SEEED_XIAO_NRF52840_SENSE/PinNames.h b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52840/TARGET_SEEED_XIAO_NRF52840_SENSE/PinNames.h
27+
index e2b1cbad..3fc2080d 100644
28+
--- a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52840/TARGET_SEEED_XIAO_NRF52840_SENSE/PinNames.h
29+
+++ b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52840/TARGET_SEEED_XIAO_NRF52840_SENSE/PinNames.h
30+
@@ -179,6 +179,21 @@ typedef enum {
31+
I2C_SDA0 = p4,
32+
I2C_SCL0 = p5,
33+
34+
+ /**** QSPI pins ****/
35+
+ QSPI1_IO0 = P0_20,
36+
+ QSPI1_IO1 = P0_24,
37+
+ QSPI1_IO2 = P0_22,
38+
+ QSPI1_IO3 = P0_23,
39+
+ QSPI1_SCK = P0_21,
40+
+ QSPI1_CSN = P0_25,
41+
+
42+
+ QSPI_FLASH1_IO0 = P0_20,
43+
+ QSPI_FLASH1_IO1 = P0_24,
44+
+ QSPI_FLASH1_IO2 = P0_22,
45+
+ QSPI_FLASH1_IO3 = P0_23,
46+
+ QSPI_FLASH1_SCK = P0_21,
47+
+ QSPI_FLASH1_CSN = P0_25,
48+
+
49+
#ifndef ARDUINO_ARCH_MBED
50+
// Digital Pins
51+
D0 = P0_2,
52+
diff --git a/targets/targets.json b/targets/targets.json
53+
index fff0bf72..725509ba 100644
54+
--- a/targets/targets.json
55+
+++ b/targets/targets.json
56+
@@ -6447,11 +6447,7 @@
57+
"features_add": [
58+
"STORAGE"
59+
],
60+
- "components_remove": [
61+
- "QSPIF"
62+
- ],
63+
"device_has_remove": [
64+
- "QSPI",
65+
"ITM"
66+
],
67+
"macros_add": [
68+
--
69+
2.20.1
70+

0 commit comments

Comments
 (0)