guidol70 / RunCPM_RPi_Pico

RunCPM for the Raspberry Pico
74 stars 11 forks source link

RPi 2040 with Maker Pi Pico board #1

Open kwpodolsky opened 2 years ago

kwpodolsky commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

@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 commented 2 years ago

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 commented 2 years ago

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

kwpodolsky commented 2 years ago

Awesome, thanks!

from my Pixel 5a 5G with Android 11

On Sat, Sep 17, 2022, 4:23 AM Guido Lehwalder @.***> wrote:

@kwpodolsky https://github.com/kwpodolsky here the latest version with the changes for 19Mhz as complete source ;) RunCPM_MakerPiPico_SPI1_17092022.zip https://github.com/guidol70/RunCPM_RPi_Pico/files/9591266/RunCPM_MakerPiPico_SPI1_17092022.zip

— Reply to this email directly, view it on GitHub https://github.com/guidol70/RunCPM_RPi_Pico/issues/1#issuecomment-1250028123, or unsubscribe https://github.com/notifications/unsubscribe-auth/AWDP4XY64MQALNLL566S4N3V6V5XBANCNFSM6AAAAAAQJ3BC6U . You are receiving this because you were mentioned.Message ID: @.***>

kwpodolsky commented 1 year ago

I kept trying different things and FINALLY got the debugging code to show me that the code was using the CORRECT GPIO pins, BUT... I still could not get the code to enable the SD interface. I put a separate uSD card reader on the "default" SPI pins that your code and I was able to access the SD card.

Not sure if there is something about the Maker board that has to be done to get the SD card to actually work. I have looked at their example code and I don't see anything different in the setup of pins.

I will try one last time, with the code you just supplied and see if it works. If not... I'm gonna give up the fight. LOL

I appreciate your help and time researching this matter. I WOULD like it to work with the Maker sd card, but... I have other things that could better utilize my time.

BTW, I have an SC2014 Z80 board and I copied the "drives" I have on that SD card and used them with your code. Works fine. Haven't seen any issues running TurboPas 1.0 or MixC, Aztec, MASM80 and a handful of games. Nice job.

On Thu, Sep 15, 2022 at 3:50 AM Guido Lehwalder @.***> wrote:

@kwpodolsky https://github.com/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_Pico_21082025_SD_MakerPiPico.zip https://github.com/guidol70/RunCPM_RPi_Pico/files/9573050/RunCPM_Pico_21082025_SD_MakerPiPico.zip

— Reply to this email directly, view it on GitHub https://github.com/guidol70/RunCPM_RPi_Pico/issues/1#issuecomment-1247715661, or unsubscribe https://github.com/notifications/unsubscribe-auth/AWDP4X2GBAVQTBGKVUJUK33V6LIN5ANCNFSM6AAAAAAQJ3BC6U . You are receiving this because you were mentioned.Message ID: @.***>

Jimbob-B commented 1 year ago

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 commented 1 year ago

Thanks for your effort in regards to the Maker board. I really appreciate your involvement. I will try again with mine to see if I can get it working.

Regards

Kerry

On Mon, Oct 17, 2022 at 2:33 PM Jimbob-B @.***> wrote:

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.

— Reply to this email directly, view it on GitHub https://github.com/guidol70/RunCPM_RPi_Pico/issues/1#issuecomment-1281306708, or unsubscribe https://github.com/notifications/unsubscribe-auth/AWDP4X2X3NPME3SF3KLWD3LWDWLXDANCNFSM6AAAAAAQJ3BC6U . You are receiving this because you were mentioned.Message ID: @.***>

Jimbob-B commented 1 year ago

@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 commented 1 year ago

@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 commented 1 year ago

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 commented 1 year ago

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) :)