Skip to content

How can I make the external QSPI flash work with Arduino NANO 33 BLE? #377

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bigbearishappy opened this issue Jan 3, 2022 · 5 comments
Closed
Labels
question Further information is requested

Comments

@bigbearishappy
Copy link

Hello, I am working with my arduino 33 ble.
And I want to make it work fine with a QSPI flash.
I find a demo code in this project.
But it's based on the nrf52840's internal flash.

What should I do if I want to make the external QSPI flash works with nano 33 BLE?

@facchinm
Copy link
Member

Hi @bigbearishappy ,
to use mbed classes you first need to modify nano33 config file adding "target.components_add" : ["QSPIF"], (like https://github.com/arduino/ArduinoCore-mbed/blob/master/variants/NICLA/conf/mbed_app.json#L20 ) and recompile libmbed using mbed-os-to-arduino script (https://github.com/arduino/ArduinoCore-mbed#adding-an-mbed-target) .

Once done, you can replace this line https://github.com/arduino/ArduinoCore-mbed/blob/master/libraries/USBMSD/src/Singleton.cpp#L82 with an object of type QSPIFBlockDevice, with the correct pins as you wired them.

Let me know if you need any help with these steps

@facchinm facchinm added the question Further information is requested label Jan 10, 2022
@bigbearishappy
Copy link
Author

bigbearishappy commented Jan 10, 2022

Thank you so much for you reply.
I tried to follow you steps.
After I add "target.components_add" : ["QSPIF"], to /variants/ARDUINO_NANO33BLE/conf/mbed_app.json.
I compiled the libmbed.a with command:

./mbed-os-to-arduino -r  /home/pi/work/mbed-os/ ARDUINO_NANO33BLE:ARDUINO_NANO33BLE

it compiled failed when compiling the QSPIFBlockDevice.cpp.Here is the error log:

Compile [ 88.3%]: SlicingBlockDevice.cpp
Compile [ 88.4%]: ObservingBlockDevice.cpp
Compile [ 88.5%]: ffunicode.cpp
Compile [ 88.5%]: QSPIFBlockDevice.cpp
[mbed] ERROR: "/usr/bin/python3" returned error.
       Code: 1
       Path: "/tmp/mbed-os-program"
       Command: "/usr/bin/python3 -u /tmp/mbed-os-program/mbed-os/tools/make.py -t GCC_ARM -m ARDUINO_NANO33BLE --source . --build ./BUILD/ARDUINO_NANO33BLE/GCC_ARM -v"

 done.
Generating defines... done.
Generating includes... copying to destination... /tmp/mbed-os-program
 done.
Generating libs... done.
Generating flags... done.
Copying generic MbedOS headers to core...  done.
Patching 'mbed.h'... done.
Patching SPI headers... done.

[mbed-os-to-arduino] MbedOS core generation ended succesfully.

I tried to run the command:

/usr/bin/python3 -u /tmp/mbed-os-program/mbed-os/tools/make.py -t GCC_ARM -m ARDUINO_NANO33BLE --source . --build ./BUILD/ARDUINO_NANO33BLE/GCC_ARM -v

here is the output of it:

pi@raspberrypi:~/work/ArduinoCore-mbed $ /usr/bin/python3 -u /tmp/mbed-os-program/mbed-os/tools/make.py -t GCC_ARM -m ARDUINO_NANO33BLE --source . --build ./BUILD/ARDUINO_NANO33BLE/GCC_ARM -v
/usr/lib/python3/dist-packages/requests/__init__.py:91: RequestsDependencyWarning: urllib3 (1.26.7) or chardet (3.0.4) doesn't match a supported version!
  RequestsDependencyWarning)
[Warning] @,: Compiler version mismatch: Have 7.3.1; expected version >= 9.0.0 and < 10.0.0
Building project ArduinoCore-mbed (ARDUINO_NANO33BLE, GCC_ARM)
Scan: ArduinoCore-mbed
No Linker Script found

Could not compile for ARDUINO_NANO33BLE: No Linker Script found

I am wondering if you can give me some help to fix this problem.
Thanks~

@facchinm
Copy link
Member

facchinm commented Jan 10, 2022

You procedure was correct but I forgot one modification 🙂

Here's the full patch for mbed_app.json

+++ b/variants/ARDUINO_NANO33BLE/conf/mbed_app.json
@@ -1,6 +1,12 @@
 {
   "macros": [
-    "NRFX_GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS=8"
+    "NRFX_GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS=8",
+    "QSPI_FLASH1_IO0=p1",
+    "QSPI_FLASH1_IO1=p1",
+    "QSPI_FLASH1_IO2=p1",
+    "QSPI_FLASH1_IO3=p1",
+    "QSPI_FLASH1_CSN=p1",
+    "QSPI_FLASH1_SCK=p1"
   ],
   "target_overrides": {
     "*": {
@@ -12,7 +18,9 @@
       "rtos.main-thread-stack-size": 32768,
       "cordio.max-connections": 5,
       "platform.all-stats-enabled": true,
-      "target.mbed_app_start": "0x10000"
+      "target.mbed_app_start": "0x10000",
+      "target.components_add" : ["QSPIF"],
+      "target.device_has_add" : ["QSPI"]
     }
   }

Of course replace p1 with the pins you are actually using to connect the external QSPI flash

@bigbearishappy
Copy link
Author

You procedure was correct but I forgot one modification 🙂

Here's the full patch for mbed_app.json

+++ b/variants/ARDUINO_NANO33BLE/conf/mbed_app.json
@@ -1,6 +1,12 @@
 {
   "macros": [
-    "NRFX_GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS=8"
+    "NRFX_GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS=8",
+    "QSPI_FLASH1_IO0=p1",
+    "QSPI_FLASH1_IO1=p1",
+    "QSPI_FLASH1_IO2=p1",
+    "QSPI_FLASH1_IO3=p1",
+    "QSPI_FLASH1_CSN=p1",
+    "QSPI_FLASH1_SCK=p1"
   ],
   "target_overrides": {
     "*": {
@@ -12,7 +18,9 @@
       "rtos.main-thread-stack-size": 32768,
       "cordio.max-connections": 5,
       "platform.all-stats-enabled": true,
-      "target.mbed_app_start": "0x10000"
+      "target.mbed_app_start": "0x10000",
+      "target.components_add" : ["QSPIF"],
+      "target.device_has_add" : ["QSPI"]
     }
   }

Of course replace p1 with the pins you are actually using to connect the external QSPI flash

Great, I can compile the libmbed.a successfully now.
I am going to make the change and try Nano33BLE_FlashMassStorage.ino now.
Before that I have a question.
Do I need to format the external QSPI flash before I run the Nano33BLE_FlashMassStorage.ino ???
I ask this question because I find that the arduino edge control support the external QSPI flash and in it's relative demo code.
it's need to be format before use as a U disk.

@facchinm
Copy link
Member

Edge Control flash is being formatted in factory; anyway, adding the formatting phase is very easy (just add this line https://github.com/arduino-libraries/Arduino_EdgeControl/blob/master/examples/Storage/StoragePartitions/StoragePartitions.ino#L92 ) . format() will also mount the partition so the flow doesn't need many modifications.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants