technoblogy / serpente-core

An Arduino core for the Serpente ARM boards
7 stars 0 forks source link

Add suitable definitions for use with Adafruit SPIFlash library #1

Open phunanon opened 4 years ago

phunanon commented 4 years ago

Hello,
I'm not very good at this stuff, but I think the current variant.h file lacks the configuration needed to use the Adafruit SPIFlash library.

technoblogy commented 4 years ago

Thanks for the comment. I haven't tried the Serpente board with the Adafruit SPIFlash library. Are you referring to definitions for:

#define PIN_QSPI_IO2
#define PIN_QSPI_IO3

As far as I know those pins aren't connected on the Serpente board:

https://serpente.solder.party/r2/schematics_serpente.png

Is that the problem?

phunanon commented 4 years ago

Like I said, not very good at this stuff, but aren't pins PA15-18 for SPI Flash?

technoblogy commented 4 years ago

I think the current variant.h file lacks the configuration needed to use the Adafruit SPIFlash library.

Can you be more specific. What lines do you think are missing? Or did you try it and it didn't work? If so, what was the error message?

phunanon commented 4 years ago

For example, it is the error message given by this example project for manipulating SPI flash.

technoblogy commented 4 years ago

Adafruit appear to have added those directives recently, between versions 1.5.9 and 1.5.10 of their Adafruit SAMD Boards core. The value should be:

EXTERNAL_FLASH_USE_SPI
phunanon commented 4 years ago

How do you mean "the value"? EXTERNAL_FLASH_USE_SPI is apparently of type SPIClass*. I'm not experienced enough to know how to do this myself - just relying information when I try to do it 😅

I've tried playing around with it for a month to get the SPI Flash working, but I can't seem to configure it properly. I thought perhaps a configuration in the variant.h file would be a standard thing to have, judging from the error message.

technoblogy commented 4 years ago

I've added the correct directives, but I'm not able to test it at the moment. Please let me know if it works.

phunanon commented 4 years ago

Apologies for the delay. This might just be an issue with my set-up.

In file included from /home/pat/arduino-1.8.9/hardware/serpente-core-master/samd/cores/arduino/delay.h:24:0,
                 from /home/pat/arduino-1.8.9/hardware/serpente-core-master/samd/cores/arduino/Arduino.h:81,
                 from sketch/flash_manipulator.ino.cpp:1:
/home/pat/arduino-1.8.9/hardware/serpente-core-master/samd/variants/serpente/variant.h:202:34: error: 'SPI1' was not declared in this scope
 #define EXTERNAL_FLASH_USE_SPI   SPI1
                                  ^
/home/pat/Arduino/flash_manipulator/flash_manipulator.ino:15:69: note: in expansion of macro 'EXTERNAL_FLASH_USE_SPI'
   Adafruit_FlashTransport_SPI flashTransport(EXTERNAL_FLASH_USE_CS, EXTERNAL_FLASH_USE_SPI);
                                                                     ^~~~~~~~~~~~~~~~~~~~~~
/home/pat/arduino-1.8.9/hardware/serpente-core-master/samd/variants/serpente/variant.h:202:34: note: suggested alternative: 'SPI'
 #define EXTERNAL_FLASH_USE_SPI   SPI1
                                  ^
/home/pat/Arduino/flash_manipulator/flash_manipulator.ino:15:69: note: in expansion of macro 'EXTERNAL_FLASH_USE_SPI'
   Adafruit_FlashTransport_SPI flashTransport(EXTERNAL_FLASH_USE_CS, EXTERNAL_FLASH_USE_SPI);
                                                                     ^~~~~~~~~~~~~~~~~~~~~~
exit status 1
Error compiling for board Serpente.
technoblogy commented 4 years ago

Sorry, I'm not sure. I think you need to ask the designer of the Serpente board.

arturo182 commented 4 years ago

I'm no Arduino expert but please maybe check the Adafruit core and compare there, they use the same chip and almost the same flash. https://github.com/adafruit/ArduinoCore-samd/blob/master/variants/itsybitsy_m0/variant.h#L139

technoblogy commented 4 years ago

I've added definitions for SPI1 to variant.h and the SPIFlash examples now compile without errors. Let me know how you get on.

phunanon commented 4 years ago

Getting closer, I think!

Adafruit Serial Flash Manipulator example
JEDEC ID: 85
Flash size: 0
Initializing SD card... Card failed, or not present

This uses the (I think now) outdated flash manipulator. Arduino IDE is still pulling this SPIFlash release for now.
The latest version fails to compile as EXTERNAL_FLASH_USE_SPI appears to be SPIClass*, as I mentioned before. I'm unsure how that will be supported in the future mind.

technoblogy commented 4 years ago

Sorry, this goes beyond what I was trying to do with the Serpente core so I don't think I can be of any more help.

arturo182 commented 4 years ago

@phunanon You could try asking on the Adafruit Discord: https://discord.gg/qh2hUjp Limor and the library creators hang out there so they might be able to help.

phunanon commented 4 years ago

@arturo182, unfortunately I've been asking there for over a month with little response. Even Lady Ada herself told me to ping you once, which I did. I've been going in circles...

arturo182 commented 4 years ago

I'm going to ask on Twitter and maybe someone familiar with the topic helps :)

technoblogy commented 4 years ago

Have you had it working with a similar board, such as the Gemma M0? If so, can you describe a simple test case; ie which example program to run? Then I'll have another look at it.

phunanon commented 4 years ago

@technoblogy, unfortunately the Serpente was the first SPI flash board I've ever had 😅

sabas1080 commented 4 years ago

Hi phunanon @arturo182 If you use this core https://github.com/technoblogy/serpente-core/blob/master/samd/variants/serpente/variant.cpp#L42

the pins flash should be PIO_SERCOM and not PIO_DIGITAL, use SPI1 and it should work

phunanon commented 4 years ago

@sabas1080, I've just tried this - replacing all PIO_DIGITAL with PIO_SERCOM for SPI Flash. In the flash manipulator example I used just
Adafruit_FlashTransport_SPI flashTransport(SS1, &SPI1);
for configuration. Unfortunately still getting the same output :/

sabas1080 commented 4 years ago

Test with other library https://github.com/Marzogh/SPIMemory

technoblogy commented 4 years ago

I think I've now got it working with the Adafruit_SPIFlash library. Note that one problem is that the library only supports the flash devices Adafruit uses, and doesn't support the Gigadevice GD25Q32C used on the Serpente board, so I've reported the device as a GD25Q16C.

I was able to get it to work by editing the flash_devices.h file and changing the .capacity code to 0x16.

phunanon commented 4 years ago

Firstly, @arturo182, my Ubuntu machine seems to think the SERPENTBOOT partition is 8.1MB, and isn't persisting new files or modifications after a reset or a power cycle. I'm sure it used to, but somehow something's gone wrong...

@technoblogy, I'm certainly getting different output, though maybe the flash_manipulator sketch is set up incorrectly, or my device is faulty / incorrectly configured, as it's still failing:

Adafruit Serial Flash Manipulator example
JEDEC ID: C84016
Flash size: 2097152
Initializing SD card... Card failed, or not present

Also, what would be the long-term solution? Perhaps it wouldn't be too cheeky to ask for that definition to be included. Does anybody know how CircuitPython accesses the GD25Q32C? I haven't any experience with it.

How are you testing to see if it's working? Are you able to read/write to the FAT fs?

technoblogy commented 4 years ago

Sorry, as I said before this goes beyond what I was trying to do with the Serpente core so I don't think I can be of any more help.

RuKoSAG commented 3 years ago

Hello there! Since this is an old thread, I am not sure if anybody will read this or if the problem has already been solved at another thread or platform. I just recently bought a couple of "Serpente R2" boards from DigiKey as I liked the form factor and the built in 4MB Flash. When running an adapted script that I had written for the ItsyBitsyM4 I ran into the same problems as mentioned above.

I found this thread on GitHub: https://github.com/adafruit/Adafruit_SPIFlash/issues/65 about issues in the SPIRead with the M0 core, which was posted just after your last posts.

Combining advise from your posts with the updated core led me to this solution:

-changed #define EXTRNAL_FLASH_DEVICES in Serpente variant.h to GD25Q32 (old version stated GD25Q16) (updated flash_devices.h in ItsyBitsyM0 core now has definitions for GD25Q32)

-exchanged variant.h and .cpp in the ItsyBisyM0 core for variant.h and .cpp from Serpente core.

-run Serpente Board as ItsyBitsyM0

This is a dirty adaption that should be consolidated into a new Serpente core, as it would not be possible to run an ItsyBitsyM0 again without changing back the variant.xxx files, but for now it works perfectly fine for me!

technoblogy commented 3 years ago

Thanks for reporting this. As far as I know it hadn't already been solved.