-
-
Notifications
You must be signed in to change notification settings - Fork 9
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
SdFat failing using SPI or SPI1 (after updating overlay). #4
Comments
Debugging journal How to debug this issue:
diff --git a/libraries/SPI/SPI.cpp b/libraries/SPI/SPI.cpp
index cfea9af..f55c17c 100644
--- a/libraries/SPI/SPI.cpp
+++ b/libraries/SPI/SPI.cpp
@@ -79,9 +79,13 @@ void arduino::ZephyrSPI::usingInterrupt(int interruptNumber) {
void arduino::ZephyrSPI::notUsingInterrupt(int interruptNumber) {
}
+#ifndef SPI_MIN_CLOCK_FEQUENCY
+#define SPI_MIN_CLOCK_FEQUENCY 1000000
+#endif
+
void arduino::ZephyrSPI::beginTransaction(SPISettings settings) {
memset(&config, 0, sizeof(config));
- config.frequency = settings.getClockFreq();
+ config.frequency = settings.getClockFreq() > SPI_MIN_CLOCK_FEQUENCY ? settings.getClockFreq() : SPI_MIN_CLOCK_FEQUENCY;
auto mode = SPI_MODE_CPOL | SPI_MODE_CPHA;
switch (settings.getDataMode()) {
case SPI_MODE0: Finally
Patches incoming |
Thanks, Learning some new stuff. My SPI test to ILI9341 display is also failing as mentioned on the thread and hit the same first error |
#6 should contain all the needed fixes and a prebuilt loader based on the "old" device tree (so with 2 spi, SPI object on ICSP header). Maybe these fixes also allow ILI9341 to run (the min_frequency could be the culprit). Hope the debugging journal will help a bit future contributors, it might be nice to transform it in something more structured |
Going to agree with @KurtE - learning a lot now with using zephyr |
Sorry, I am new to this system. So when you say:
How do you do this? Note: I see those defines in several files
I am assuming if I change one of these files, I probably at least have to do the Do I then need to then do the burn bootloader and then rebuild and program the GIGA? Thanks, I know that this is probably a pain to explain, but then others hopefully will learn as well. |
Just tried your updates in the PR, still getting |
Quick update: I also tried out using your Pull Request code. I do think some things are working better, I am still having some issues, but learning. Couple questions and observations:
SPI.begin();
beginTransaction(SPISettings());
|
Answering in order:
This requires modifying the loader's .conf for the given board, a run of
Good catch, preparing a PR for this too
Not an issue, this will be needed to create a production-ready hex file with loader+sketch in a single flashable |
A bit confused since for the giga_r1 conf those configure parameters are not in the Going to add them - deleted what was here because I have had coffee now. |
went ahead and added
No more hangs. Great news but what will the permanent fix be? Good news is that SPI works but SPI1 works. Probably have to add:
or something like it. UPDATE: Added the SPI5 definition just in case but SPI1 is not working with SDfat. Update2: swapped breadboards just in case. Tested the 2 sketches posted up to 50Mhz and ithey worked. However, something strange with CS Pin. In one of test sketches I changed the CSpin to pin 6 and it works recognizing the drive and printing sdcard files. However, if I switch the cspin to pin 10 (no change to sketch) it still works to dump the drive contents even though the sketch specified the CS PIN as 6. Happens if I change the CSPIN in the sketch to other pins. PIN10 is always act as a CSPIN as well as the pin selected. |
I also added the above, and getting some better luck...
Quick note: with one of the SDFat examples I tried (SDInfo), I found that it appeared to use the
ENABLE_DEDICATED_SPI section... Not sure why. With the display stuff not sure what is going on. I have it setup for SPI1, currently, may try it on SPI The real simple TFT sketch, runs on it. However one where I stripped out stuff from my MBED Giga display code, does not load: But once resolved and I try to load the sketch, the monitor window does not show anything EDIT: Forgot to mention that the sketch does run on MBED. |
Is this going to even be possible using Zephyr, i.e., specifing CS pin to us at run time. Was doing a bit of reading and it appears that you have to identify the pins you will be using for SPI including the CSPin in the overlay file and if you do that you have to recompile the loader etc. Which is not really what you want to do for normal users. See https://blog.golioth.io/how-to-use-generic-spi-devices-with-zephyr/ there are others but anything I looked was a variation on the theme. thanks mike |
@mjs513, @facchinm - Not sure about the CS pin, here. That is, you are probably right, if you are trying to setup that That is, I don't believe the SPI library here does anything with CS pins. In the Teensy SPI code, we do have a method to set a specific pin into SPI CS configuration, but we actually don't have any code in the library that sets the appropriate registers in the hardware to use that pin for hardware CS. However, we do have several libraries that do this, especially on the T3.x boards, I probably need to look, but I believe that the STM32... has the ability to set SPI to say something like, let GPIO handle this... I do wonder about, one the spi5(SPI1) object, the .dts file does specify a CS pin (pin 10), wonder if we can/should not specify this |
Take a look at this link. https://devzone.nordicsemi.com/f/nordic-q-a/102776/does-zephyr-spi-apis-support-two-chip-select-pins the Key seems to be you have to set up the overlay to handle multiple cs-pins - 1 per device? |
Was doing a bunch more reading on spi api and overlays. Looks like if the CS Pin is not defined in the overlay it won't hardwire it in the driver so a the format for spi1 for example would be: &spi5 {
status = "okay";
pinctrl-0 = <&spi5_sck_ph6
&spi5_miso_pj11 &spi5_mosi_pj10>;
pinctrl-names = "default";
}; Note the nss pin is no longer defined. I tried the SDInfo example in sdfat with a CSpin defined as 4 and it worked as expected:
now if I repeat the run with swapping the jumper to pin 10 (previously hard coded):
Still have to try SPI but assume it will work. This was also something that @KurtE and myself discussed earlier. |
I was actually going to propose to remove the hardcoded CS from the dts entry since in arduino it's always handled as a gpio via digitalWrite(), if it's the solution we'll just remove it. |
I was going to reply, I had better luck without it being defined, As you mentioned, the SPI library does not use the idea of hardware CS support. |
Question: would you prefer more generic questions on Device tree usage DTS/Overlay/Sketch??? here or new Issue or forum? Things like: Status of OKAY versus disabled? What does OKAY mean? Device object created and initiated? In particular, if multiple OKAY objects exist who use the same objects in a phandle-array? More specific refer to the same IO pin. Sorry last time I played with Device trees, was back in the early Beagle Bone Black days... And I did not spend a lot of time on it, as I had migrated to experimenting with ODroid boards... |
Decided to try another Spi device (Sparkfun BMI270) on SPI1 while it compiles and uploads it hangs the Giga again. Running in debug mode getting the same error as when we started on SDFat
I know the BMI270 uses a wrapper to the Bosch API so probably large
|
Quick update to previous post. To avoid having to recompile the core I switched to a MPU-9250 using the Bolderflight MPU-9250 library. Tested in same way as sd fat. CSPin selected in sketch = pin4: Swapped jumper to pin10 from pin4 reran sketch received: So I would say its probably a good fix to just remove nss pin from list for spiX pins. |
@facchinm @mjs513 I have a version of the GraphicTest running... Still some issues in the code, like the DeadBeef test page is not correct.. The main issue is/was, there appears to be some form of problem with object constructors. Not sure if there is enough
I now have it like:
And I initialized all of the member variables. Some probably wrong... but. I also could not leave the constructor as constexpr as it left a linker error (both for zephyr as well as MBED) But it now runs. Secondary or tertiary comment for this. With the current setup. This as well as 2.3.4 IDE, I have finding I have to more often
The library and example sketch are up on my github project: |
As a quick and dirty test I put together a simple datalogger using the SdFat lib an the MPU9250 with the giga - used cspin 7 for the sdcard and cspin 4 for the 9250. Everything seems to be working at least with 2 spi devices on the same bus.
as nothing fancy just a test of 2 devices on the same bus. Going to repeat what @KurtE said
For this sketch I had to add:
Not sure if you are planning on changing this so it matches up with Arduino so you don't have to forward declare references. |
@KurtE and myself tried running a couple of sdfat test cases that work when using Giga Mbed.
Output of Serial Monitor
What happens they compile no issue and load no issued using zephyr. Howver, immediately after upload it hangs. Did try looking as serial1 output but no output.
Using spi:
Example Sketch
SDFat_Giga_zephyr-241209a.zip
Target board + cli verbose compilation output
Full verbose compilation output, ideally with arduino-cli invocation or from IDE 2.3.3+
SDFat_compile.txt
Using SPI1 we used a method to specify our own SPI driver just in case but the same thing occurs:
Example Skectch
sketch_dec6a.ino.zip
Overlay was updated to specify:
Not sure what else you need.
EDIT: I am using as SDCARD adapter from Adafruit: https://learn.adafruit.com/adafruit-microsd-spi-sdio/overview
The text was updated successfully, but these errors were encountered: