Skip to content
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

RPi 2040 with Maker Pi Pico board #1

Open
kwpodolsky opened this issue Sep 11, 2022 · 13 comments
Open

RPi 2040 with Maker Pi Pico board #1

kwpodolsky opened this issue Sep 11, 2022 · 13 comments

Comments

@kwpodolsky
Copy link

I am using a stock RPi 2040 board on a Maker Pi Pico breakout.
The Maker board has a built on uSD card reader.
The Maker uSD uses the SD1 pins (SCLK-GP10, MISO-GP11, MOSI-GP13, SS-GP15).

I've tried modifying the "pico_sd.h" file to change the SPI pins, but every time I run, it keeps failing to init the SD card and the debug output tells me it is using the original pins defined in the header file (even tho they are commented out).

Also, in enabling the debug output, the compile fails on the "BOARD" not being defined.
I even added a define for it in the "pico_sd.h" file and... no joy.

WHAT am I doing wrong (or not doing) that is needed to fix this problem?

@guidol70
Copy link
Owner

guidol70 commented Sep 11, 2022

Hi,
I dont know why the Cytron Maker Pi Pico Board doenst use the SPI-Pins like in the Pinout:

Normal RPi Pico SPI0
// Pin 19 - GPIO 14 - SCK/Clock
// Pin 16 - GPIO 12 - MISO
// Pin 15 - GPIO 11 - MOSI
// Pin 17 - GPIO 13 - CS/SS

MicroSD Pin Definition for Maker Pico SPI1
// Pin 14 - GPIO 10 - SCK/Clock
// Pin 15 - GPIO 11 - MISO
// Pin 16 - GPIO 12 - MOSI
// Pin 20 - GPIO 15 - CS/SS

but I attached a maker_pico_sd.h for your reference.

In your .ino you need to define
#include "hardware/pico/maker_pico_sd.h"

Also check if you have changed SdFatConfig.h like described at the page
https://github.com/MockbaTheBorg/RunCPM
in the section "SdFat library change"

And please tell me which version do you use from github?
This should be the last/newest available source on github:
https://github.com/guidol70/RunCPM_RPi_Pico/raw/main/GL20220821_Source_RunCPM_v5_7_RPi_Pico.zip

I hope you will get its working...

Maybe the SPI-Pinout in the Maker Pi Pico is wrong and you have to use the original Pinout?

Let me know :)

Kind regards
Guido

Arduino-IDE_Settings_for_flashing
Maker_Pico_SPI
PIco_normal_Pinout
SdFatConfig.zip
maker_pico_sd.zip

@guidol70
Copy link
Owner

guidol70 commented Sep 11, 2022

There is a Board-definition Cytron Maker Pi in the RP2040 arduino-core package (Board Support),
but in the pin-definition the SDCard SPI isnt defined :(

You can try to edit this file - like below...

Path:
C:\Users\[username]\AppData\Local\Arduino15\packages\rp2040\hardware\rp2040\2.5.2\variants\cytron_maker_pi_rp2040\pins_arduino.h

from these lines

// SPI (Not pinned out)
#define PIN_SPI1_MISO       (31u)
#define PIN_SPI1_MOSI       (31u)
#define PIN_SPI1_SCK        (31u)
#define PIN_SPI1_SS         (31u)

that should be changed to

#define PIN_SPI1_MISO       (11u)
#define PIN_SPI1_MOSI       (12u)
#define PIN_SPI1_SCK        (10u)
#define PIN_SPI1_SS         (15u)
#define SPI_HOWMANY         (1u)

Do you have RP2040 arduino-core v2.5.2 installed?
Do you use Arduino IDE v2.0.0 or v1.8.19?

Maker_Pi_Board_Support
RP2040_v_2_5_2

@guidol70
Copy link
Owner

guidol70 commented Sep 15, 2022

@kwpodolsky
could you please check the following code (you can insert/change it - or use the zipped complete .ino-source) in the .ino for using your pins with SPI1
Does compile successfully - but I cant test it -> you got the hardware ;)

// =============================================================
// Set the SPI1 Pins
// =============================================================
 SPI1.setRX(11);   // MISO
 SPI1.setCS(15);   // Card Select
 SPI1.setSCK(10);  // Clock
 SPI1.setTX(12);   // MOSI

// =============================================================
// Setup SD card writing settings
// =============================================================
#define SPI_SPEED SPI_FULL_SPEED  
#define SD_CONFIG SdSpiConfig(15, DEDICATED_SPI, SPI_FULL_SPEED, &SPI1)

// =============================================================
// Start accessing the SD card
// =============================================================
if (SD.begin(SD_CONFIG)) {

RunCPM_MakerPiPico_SPI1_15092022.zip

@guidol70
Copy link
Owner

guidol70 commented Sep 16, 2022

SPI_FULL_SPEED is 50Mhz - which is too fast :(
replace this line with

// select required SPI-Bus : (&SPI) = SPI0 / (&SPI1) = SPI1
#define SD_CONFIG SdSpiConfig(SS, DEDICATED_SPI, SD_SCK_MHZ(SDMHZ), &SPI1)

because of

// ====================================================================
// NEW SD_CONFIG formerly SDINIT
// ====================================================================
#define SDFAT_FILE_TYPE 1           // Uncomment for Due, Teensy or RPi Pico
#define ENABLE_DEDICATED_SPI 1      // Dedicated SPI 1=ON 0=OFF
#define SDMHZ_TXT "19"              // for outputing SDMHZ-Text
#define SDMHZ 19                    // setting 19 Mhz for SPI-Bus
#define SS 15

@guidol70
Copy link
Owner

@kwpodolsky
here the latest version with the changes for 19Mhz as complete source ;)
RunCPM_MakerPiPico_SPI1_17092022.zip

@kwpodolsky
Copy link
Author

kwpodolsky commented Sep 17, 2022 via email

@kwpodolsky
Copy link
Author

kwpodolsky commented Oct 11, 2022 via email

@Jimbob-B
Copy link

Just leaving my thoughts as I did get it to work with the Maker Pi Pico board but I had to make changes to the source code to get the SD card reading / writing to work. I can't remember exactly what I changed but here's some bits from my source folder. The trick is switching to the softSpi driver to get it to work, I think.

in RunCPM.ino (or whatever filename you have), change the SD_CONFIG define to,

#define SD_CONFIG SdSpiConfig(SS, DEDICATED_SPI, SD_SCK_MHZ(SDMHZ), &softSpi)

The code for softSpi is added after the includes at the top of the same ino file and I used,

SoftSpiDriver<SOFT_MISO_PIN, SOFT_MOSI_PIN, SOFT_SCK_PIN> softSpi;

Can't seem to find where I defined SOFT_MISO_PIN, SOFT_MOSI_PIN and SOFT_SCK_PIN ... they may be pre-defined in the arduino library somewhere.

I commented out the 4 lines beginning SPI1.setRX(12); // MISO in the ino file as they didn't work for me - the &SPI1 changes wouldn't compile at all. Google helped with the changes to get it working.

@kwpodolsky
Copy link
Author

kwpodolsky commented Oct 17, 2022 via email

@Jimbob-B
Copy link

@guidol70 Any chance of an updated source release for this? I can then try again and this time make a proper note of the changes I make for the Maker Pi Pico board ...

@guidol70
Copy link
Owner

@guidol70 Any chance of an updated source release for this? I can then try again and this time make a proper note of the changes I make for the Maker Pi Pico board ...

As attachment a v6.0 of my Maker-Pico version, but as I wrote I didnt have a Maker-Pico to test it.
You have to add your changes like before.

Did you change the SdFatConfig.h from the SdFat-Library for SoftSPI like on a STM32-board (which also need SoftSPI)?

#ifndef SPI_DRIVER_SELECT
// #define SPI_DRIVER_SELECT 0  // Normal
#define SPI_DRIVER_SELECT 2  // STM32
#endif  // SPI_DRIVER_SELECT

I will also attach a SoftSPI STM32 (pyBoard v1.1) Source-version for reference, how I did use SoftSPI on the STM32

RunCPM_v6_0_Maker_Pico_26102022.zip
RunCPM_v6_0_PyBoard11_08102022.zip

@Jimbob-B
Copy link

Jimbob-B commented Nov 14, 2022

No, I didn't do anything like that.

Finally found 5 minutes to have another go and I've managed to get it to work on my Maker Pi Pico board with minimal edits to the source code. To get it to work I did the following,

  1. Commented out the Pi Pico board at line 38 and added the following
    // Maker Pi Pico board
    #include "hardware/pico/maker_pico_sd_spi1.h"
  2. Comment out the SPI. lines 172 to 175 because they aren't needed
  3. Change the SD_CONFIG declaration on line 203 (my line numbers might be slightly different) to #define SD_CONFIG SdSpiConfig(SS, DEDICATED_SPI, SD_SCK_MHZ(SDMHZ), &SPI1)
  4. I moved the definition for SS into the maker_pico_sd_spi1.h file because it was defined after some of the lines using it in the INO file
  5. I used the ESP8266SdFat fix from the main Github page

I think that was all the changes I made. This should compile and load files from the micro-sd card, hopefully.

Edit: forgot to say thank you :-)

@guidol70
Copy link
Owner

guidol70 commented Nov 15, 2022

Edit: forgot to say thank you :-)

Fine that it worked for you. I thought I had made the most changes already in the archive RunCPM_v6_0_Maker_Pico_26102022.zip
like the Points 1) 3)

SS could be moved to the hardware/pico/maker_pico_sd_spi1.h
and it also should work with normal SdFat or ESP8266SdFat

For 2) I had no SPI. but SPI1. defined:

  SPI1.setRX(11);   // MISO
  SPI1.setCS(15);   // Card Select
  SPI1.setSCK(10);  // Clock
  SPI1.setTX(12);   // MOSI

Cool that no SoftwareSPI is needed and the PinOut-Numbers are OK (without having this board here) :)

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

No branches or pull requests

3 participants