Love UECIDE? Why not consider supporting the development?

We have a new forum system

>> Click here to try it out. <<

chiplit Lenny and SD card on a TFT

chiplit Lenny and SD card on a TFT

Postby AnthonyP » Mon Jun 19, 2017 4:24 am

Hello Matt,

I just purchased a chipkit Lenny and am trying to read the SD on a tft display.
I have the display working...ILI9481...
However the SDinfo demo I use on the PinguinoOTG fails to compile..
Code: Select all
Compiling...
• Preprocessing...
• Compiling sketch...

• Error at line 171 in file Sd2PinMap.h:
‣ #error Boards with PPS must be specifically defined

Compiling Failed

I had a look at the board files and _BOARD_LENNY_ is there, I closed and restarted, I updated all via the plugin manager..
Any help would be much appreciated...
Code: Select all
// include the SD library:
#include <SD.h>

// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;

// Default SD chip select for Pinguino Micro 51, OTG 36
const int chipSelect_SD_default = 12; //36; // Change

// chipSelect_SD can be changed if you do not use default CS pin
const int chipSelect_SD = chipSelect_SD_default;

void setup()
{
  Serial.begin(9600);

  pinMode(chipSelect_SD_default, OUTPUT);
  digitalWrite(chipSelect_SD_default, HIGH);

  pinMode(chipSelect_SD, OUTPUT);
  digitalWrite(chipSelect_SD, HIGH);

}


void loop() {

    Serial.println("\nInitializing SD card...");
   // we'll use the initialization code from the utility libraries
  // since we're just testing if the card is working!
  if (!card.init(SPI_HALF_SPEED, chipSelect_SD)) {
    Serial.println("initialization failed. Things to check:");
    Serial.println("* is a card is inserted?");
    Serial.println("* Is your wiring correct?");
    Serial.println("* did you change the chipSelect pin to match your shield or module?");
    return;
  } else {
   Serial.println("Wiring is correct and a card is present.");
  }

  // print the type of card
  Serial.print("\nCard type: ");
  switch(card.type()) {
    case SD_CARD_TYPE_SD1:
      Serial.println("SD1");
      break;
    case SD_CARD_TYPE_SD2:
      Serial.println("SD2");
      break;
    case SD_CARD_TYPE_SDHC:
      Serial.println("SDHC");
      break;
    default:
      Serial.println("Unknown");
  }

  // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
  if (!volume.init(card)) {
    Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
    return;
  }

  // print the type and size of the first FAT-type volume
  long volumesize;
  Serial.print("\nVolume type is FAT");
  Serial.println(volume.fatType(), DEC);
  Serial.println();
 
  volumesize = volume.blocksPerCluster();    // clusters are collections of blocks
  volumesize *= volume.clusterCount();       // we'll have a lot of clusters
  volumesize *= 512;                            // SD card blocks are always 512 bytes
  Serial.print("Volume size (bytes): ");
  Serial.println(volumesize);
  Serial.print("Volume size (Kbytes): ");
  volumesize /= 1024;
  Serial.println(volumesize);
  Serial.print("Volume size (Mbytes): ");
  volumesize /= 1024;
  Serial.println(volumesize);
 
  Serial.println("\nFiles found on the card (name, date and size in bytes): ");
  root.openRoot(volume);
 
  // list all files in the card with date and size
  root.ls(LS_R | LS_DATE | LS_SIZE);

Serial.println("delaying 10 seconds then looping....");
   delay(10000);
   
}


UECIDE 0.8.9 pre14 on windows
Regards and thanks
Anthony
Regards
Anthony
AnthonyP
 
Posts: 27
Joined: Sat Jan 02, 2016 7:23 am
I use UECIDE on: Windows
 

Re: chiplit Lenny and SD card on a TFT

Postby matt » Mon Jun 19, 2017 2:25 pm

The SD library is rather nasty in places. It has hard coded pins for some things and I really hate it. I have given up on it these days prefering the FatFS library (DFATFS / SDSVOL) instead. It goes hand in hand with the DSPI library for SPI control so can easily select which of the two SPI ports you are using for the SD card.
Why not visit my eBay shop? http://stores.ebay.co.uk/Majenko-Technologies
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".
matt
Site Admin
 
Posts: 1311
Joined: Sun Jul 07, 2013 11:37 am
I use UECIDE on: Linux
 

Re: chiplit Lenny and SD card on a TFT

Postby AnthonyP » Tue Jun 20, 2017 1:26 am

Hello Matt,
Thank you, would you have a simple example, I have looked at the example in DSDVOL but this does not compile either...
Regards
Anthony
AnthonyP
 
Posts: 27
Joined: Sat Jan 02, 2016 7:23 am
I use UECIDE on: Windows
 

Re: chiplit Lenny and SD card on a TFT

Postby matt » Tue Jun 20, 2017 10:06 am

TBH I have never attached an SD card to a Lenny. I'll dig into both SD and DFATFS and look to see what needs modifying.
Why not visit my eBay shop? http://stores.ebay.co.uk/Majenko-Technologies
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".
matt
Site Admin
 
Posts: 1311
Joined: Sun Jul 07, 2013 11:37 am
I use UECIDE on: Linux
 

Re: chiplit Lenny and SD card on a TFT

Postby matt » Tue Jun 20, 2017 10:08 am

Actually, I'm not seeing your error on the SD library. What version of the chipKIT core and SD Library do you have installed?
Why not visit my eBay shop? http://stores.ebay.co.uk/Majenko-Technologies
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".
matt
Site Admin
 
Posts: 1311
Joined: Sun Jul 07, 2013 11:37 am
I use UECIDE on: Linux
 

Re: chiplit Lenny and SD card on a TFT

Postby matt » Tue Jun 20, 2017 10:13 am

As far as DSDVOL goes it's Keith's idiotic idea of having macros in the board definition to define the way a library sets its objects up. This stupid thing:
Code: Select all
DefineSDSPI(dSDSpi);            // Macro from Board_Defs.h to create an SPI object to the uSD
DefineDSDVOL(dSDVol, dSDSpi);   // Macro from Board_Defs.h to create an DSDVOL object to the uSD

I don't know what planet he's living on...

Just delete that **** and do it manually:
Code: Select all
DSPI0 dSDSpi;
DSDVOL dSDVol(dSDSpi, 10);


Choose the right DSPIx class for the port you want to use (the 6 pin header or pins 11-13), and the "10" there is the CS pin number to use.

Also, why he thinks it's a good idea to have the main INO file as just pages of comments and stuff and the actual source code for the example in a completely separate file is beyond me. I think he's on the verge of getting dragged off by the men in white in one of those special reversible shirts.
Why not visit my eBay shop? http://stores.ebay.co.uk/Majenko-Technologies
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".
matt
Site Admin
 
Posts: 1311
Joined: Sun Jul 07, 2013 11:37 am
I use UECIDE on: Linux
 

Re: chiplit Lenny and SD card on a TFT

Postby AnthonyP » Wed Jun 21, 2017 6:27 am

Hello Matt,
Thank you for your troubles, it is sometimes very hard to understand what another person was thinking.....
I have chipkit core 1.4.0 and SD library 1.4.0 however when you mentioned the SDfat library I found and installed the PIC32 version from here....http://chipkit.net/forum/viewtopic.php?t=3262 .....which works for me..
Code: Select all
/*
 * This program attempts to initialize an SD card and analyze its structure.
 */
 #include <DSPI.h>
#include <SPI.h>
#include <SdFat.h>
/*
 * SD chip select pin.  Common values are:
 *
 * Arduino Ethernet shield, pin 4.
 * SparkFun SD shield, pin 8.
 * Adafruit SD shields and modules, pin 10.
 * Default SD chip select is the SPI SS pin.
 */
const uint8_t SD_CHIP_SELECT = 10;
/*
 * Set DISABLE_CHIP_SELECT to disable a second SPI device.
 * For example, with the Ethernet shield, set DISABLE_CHIP_SELECT
 * to 10 to disable the Ethernet controller.
 */
const int8_t DISABLE_CHIP_SELECT = -1;
SdFat sd;

// serial output steam
ArduinoOutStream cout(Serial);

// global for card size
uint32_t cardSize;

// global for card erase size
uint32_t eraseSize;
//------------------------------------------------------------------------------
// store error strings in flash
#define sdErrorMsg(msg) sdErrorMsg_F(F(msg));
void sdErrorMsg_F(const __FlashStringHelper* str) {
  cout << str << endl;
  if (sd.card()->errorCode()) {
    cout << F("SD errorCode: ");
    cout << hex << int(sd.card()->errorCode()) << endl;
    cout << F("SD errorData: ");
    cout << int(sd.card()->errorData()) << dec << endl;
  }
}
//------------------------------------------------------------------------------
uint8_t cidDmp() {
  cid_t cid;
  if (!sd.card()->readCID(&cid)) {
    sdErrorMsg("readCID failed");
    return false;
  }
  cout << F("\nManufacturer ID: ");
  cout << hex << int(cid.mid) << dec << endl;
  cout << F("OEM ID: ") << cid.oid[0] << cid.oid[1] << endl;
  cout << F("Product: ");
  for (uint8_t i = 0; i < 5; i++) {
    cout << cid.pnm[i];
  }
  cout << F("\nVersion: ");
  cout << int(cid.prv_n) << '.' << int(cid.prv_m) << endl;
  cout << F("Serial number: ") << hex << cid.psn << dec << endl;
  cout << F("Manufacturing date: ");
  cout << int(cid.mdt_month) << '/';
  cout << (2000 + cid.mdt_year_low + 10 * cid.mdt_year_high) << endl;
  cout << endl;
  return true;
}
//------------------------------------------------------------------------------
uint8_t csdDmp() {
  csd_t csd;
  uint8_t eraseSingleBlock;
  if (!sd.card()->readCSD(&csd)) {
    sdErrorMsg("readCSD failed");
    return false;
  }
  if (csd.v1.csd_ver == 0) {
    eraseSingleBlock = csd.v1.erase_blk_en;
    eraseSize = (csd.v1.sector_size_high << 1) | csd.v1.sector_size_low;
  } else if (csd.v2.csd_ver == 1) {
    eraseSingleBlock = csd.v2.erase_blk_en;
    eraseSize = (csd.v2.sector_size_high << 1) | csd.v2.sector_size_low;
  } else {
    cout << F("csd version error\n");
    return false;
  }
  eraseSize++;
  cout << F("cardSize: ") << 0.000512*cardSize;
  cout << F(" MB (MB = 1,000,000 bytes)\n");

  cout << F("flashEraseSize: ") << int(eraseSize) << F(" blocks\n");
  cout << F("eraseSingleBlock: ");
  if (eraseSingleBlock) {
    cout << F("true\n");
  } else {
    cout << F("false\n");
  }
  return true;
}
//------------------------------------------------------------------------------
// print partition table
uint8_t partDmp() {
  cache_t *p = sd.vol()->cacheClear();
  if (!p) {
    sdErrorMsg("cacheClear failed");
    return false;
  }
  if (!sd.card()->readBlock(0, p->data)) {
    sdErrorMsg("read MBR failed");
    return false;
  }
  for (uint8_t ip = 1; ip < 5; ip++) {
    part_t *pt = &p->mbr.part[ip - 1];
    if ((pt->boot & 0X7F) != 0 || pt->firstSector > cardSize) {
      cout << F("\nNo MBR. Assuming Super Floppy format.\n");
      return true;
    }
  }
  cout << F("\nSD Partition Table\n");
  cout << F("part,boot,type,start,length\n");
  for (uint8_t ip = 1; ip < 5; ip++) {
    part_t *pt = &p->mbr.part[ip - 1];
    cout << int(ip) << ',' << hex << int(pt->boot) << ',' << int(pt->type);
    cout << dec << ',' << pt->firstSector <<',' << pt->totalSectors << endl;
  }
  return true;
}
//------------------------------------------------------------------------------
void volDmp() {
  cout << F("\nVolume is FAT") << int(sd.vol()->fatType()) << endl;
  cout << F("blocksPerCluster: ") << int(sd.vol()->blocksPerCluster()) << endl;
  cout << F("clusterCount: ") << sd.vol()->clusterCount() << endl;
  cout << F("freeClusters: ");
  uint32_t volFree = sd.vol()->freeClusterCount();
  cout <<  volFree << endl;
  float fs = 0.000512*volFree*sd.vol()->blocksPerCluster();
  cout << F("freeSpace: ") << fs << F(" MB (MB = 1,000,000 bytes)\n");
  cout << F("fatStartBlock: ") << sd.vol()->fatStartBlock() << endl;
  cout << F("fatCount: ") << int(sd.vol()->fatCount()) << endl;
  cout << F("blocksPerFat: ") << sd.vol()->blocksPerFat() << endl;
  cout << F("rootDirStart: ") << sd.vol()->rootDirStart() << endl;
  cout << F("dataStartBlock: ") << sd.vol()->dataStartBlock() << endl;
  if (sd.vol()->dataStartBlock() % eraseSize) {
    cout << F("Data area is not aligned on flash erase boundaries!\n");
    cout << F("Download and use formatter from www.sdsd.card()->org/consumer!\n");
  }
}
//------------------------------------------------------------------------------
void setup() {
  Serial.begin(9600);
  while(!Serial) {}  // wait for Leonardo

  // use uppercase in hex and use 0X base prefix
  cout << uppercase << showbase << endl;

  // pstr stores strings in flash to save RAM
  cout << F("SdFat version: ") << SD_FAT_VERSION << endl;
  if (DISABLE_CHIP_SELECT < 0) {
    cout << F(
           "\nAssuming the SD is the only SPI device.\n"
           "Edit DISABLE_CHIP_SELECT to disable another device.\n");
  } else {
    cout << F("\nDisabling SPI device on pin ");
    cout << int(DISABLE_CHIP_SELECT) << endl;
    pinMode(DISABLE_CHIP_SELECT, OUTPUT);
    digitalWrite(DISABLE_CHIP_SELECT, HIGH);
  }
  cout << F("\nAssuming the SD chip select pin is: ") <<int(SD_CHIP_SELECT);
  cout << F("\nEdit SD_CHIP_SELECT to change the SD chip select pin.\n");
}
//------------------------------------------------------------------------------
void loop() {
  // read any existing Serial data
  while (Serial.read() >= 0) {}

  // pstr stores strings in flash to save RAM
  cout << F("\ntype any character to start\n");
  while (Serial.read() <= 0) {}
  delay(400);  // catch Due reset problem

  uint32_t t = millis();
  // initialize the SD card at SPI_HALF_SPEED to avoid bus errors with
  // breadboards.  use SPI_FULL_SPEED for better performance.
  if (!sd.cardBegin(SD_CHIP_SELECT, SPI_HALF_SPEED)) {
    sdErrorMsg("\ncardBegin failed");
    return;
  }
  t = millis() - t;

  cardSize = sd.card()->cardSize();
  if (cardSize == 0) {
    sdErrorMsg("cardSize failed");
    return;
  }
  cout << F("\ninit time: ") << t << " ms" << endl;
  cout << F("\nCard type: ");
  switch (sd.card()->type()) {
  case SD_CARD_TYPE_SD1:
    cout << F("SD1\n");
    break;

  case SD_CARD_TYPE_SD2:
    cout << F("SD2\n");
    break;

  case SD_CARD_TYPE_SDHC:
    if (cardSize < 70000000) {
      cout << F("SDHC\n");
    } else {
      cout << F("SDXC\n");
    }
    break;

  default:
    cout << F("Unknown\n");
  }
  if (!cidDmp()) {
    return;
  }
  if (!csdDmp()) {
    return;
  }
  uint32_t ocr;
  if (!sd.card()->readOCR(&ocr)) {
    sdErrorMsg("\nreadOCR failed");
    return;
  }
  cout << F("OCR: ") << hex << ocr << dec << endl;
  if (!partDmp()) {
    return;
  }
  if (!sd.fsBegin()) {
    sdErrorMsg("\nFile System initialization failed.\n");
    return;
  }
  volDmp();
}


I am using the SD card on a tft display.
Thank you
Thank you
Regards
Anthony
AnthonyP
 
Posts: 27
Joined: Sat Jan 02, 2016 7:23 am
I use UECIDE on: Windows
 
 

Return to PIC32

Who is online

Users browsing this forum: No registered users and 1 guest

cron