New SdFat library (with and without DMA)

Please do not post requests
zmemw16
Posts: 1491
Joined: Wed Jul 08, 2015 2:09 pm
Location: St Annes, Lancs,UK

Re: New SdFat library (with and without DMA)

Post by zmemw16 » Tue Dec 22, 2015 12:55 pm

apols, i agree.
i'll re-post in problems with libraries.

it was the mention of 'tight' timings and the cs signal being applied earlier that woke me up.
anyways i off to get the devel branch and try it out ... ...

stephen

racemaniac
Posts: 626
Joined: Sat Nov 07, 2015 9:09 am

Re: New SdFat library (with and without DMA)

Post by racemaniac » Sun Apr 17, 2016 6:21 pm

I've recently been playing around with DMA to offload my cpu for an IO intensive project i'm working on, and so far wrote some small libraries of my own so when the DMA is running, i can do other work while it's doing its thing.

I've also been playing around with this library, and was wondering if we could make it even more powerful than it already is by allowing you to do other things while the DMA is working.

My simplest thought so far is: what if you can pass a method it has to loop for you while you're waiting for DMA (could be the main loop method of your arduino project). It hardly takes any changes at all to the library (just allow the user to set that method, and put the call to that method in the loops where you're waiting for the DMA to finish, and you're done). This may not be the most efficient way of doing it, but you'll probably get 80% of the result for 1% of the work :).

Ideally you would start a call, and it would do its thing in the background, and use interrupts to see state changes & react on them, and you can periodically poll it to see if it's done yet and then read your result, but that would be a big redesign of the library :). And it probably won't gain that much compared to the simple solution :).

User avatar
rexnanet
Posts: 209
Joined: Wed Mar 16, 2016 10:34 am

Re: New SdFat library (with and without DMA)

Post by rexnanet » Mon Jun 13, 2016 10:05 am

e-dredon wrote:Good afternoon all.

I didn't have any success yet with the SD module of my ILI9341 LCD display, and the optimized SdFat library.

Now with my STM32F103C8T6 (bluepill)
I tried EVERY digital pins for the SD_CS line.
I've disabled the DMA optimization for initial tests in the config file SdSpiSTM32F1.cpp
#define USE_STM32F1_DMAC 0

I've tried to use SPI1 for both the ILI9341 display and SD module, with a dedicated CS pin for the SD_CS.
I've tried the latest SPI library with the new SPI.setModule(2); in the setup section of my code. In that case I hooked the SD miso/mosi/sck on the SPI2, and specified the SD_CS (I tried the SS of the SPI2 and other pins like 0, 1 because I've seen some users got success with a mapple mini with that configuration)
Last but not least, I've tried various DIV_CLOCK settings (2, 4, 8) with no success too.
const uint8_t spiSpeed = SPI_CLOCK_DIV8;

If I define a pin with the STM32F103C8 naming scheme (PAxx/PBxx/PCxx, etc...), the display works, but, if i compile the sdinfo test sketch, I have a different numbering on the serial monitoring. For exemple, my PB13 has the pin number 33 shown on the serial monitor.

I don't know what else to do now...

Hi,
I'm also trying to get ILI9341 on SPI1 and the SD-Card on SPI2 (only because I can't get both connected using dupont wires :) too lazy...).
I've picked up "ILI9341_draw_bitmap_v2" sketch from "TFT SD bitmap v6" library (don't know if imported from IDE or picked up elsewhere yet...) and started to work on it. SdFat I was using didn't allow to change SPI module so I searched on the forum and found SdFatBeta from greiman https://github.com/greiman/SdFat-beta. It was mentioned that it could work on SPI2.
I've managed to get them working using SPI.setmodule(2) before each SD operation and SPI.setmodule(1) after :D "Nasty sh$%" loool
This is not (clearly) the perfect approach but worked lol
Latter I'll try to get SdFat to be configured for a generic SPI bus...

I'm still having trouble displaying the images. Seems that the SD buffer pointer doesn't increment, but its still WIP.
I've ported pushColors to the ILI9341_STM library (used by drawRAW and drawBMP) to try to get DMA support so it can have some bugs still.

Just an example of the code:

Code: Select all

#include <Adafruit_GFX_AS.h>     // Core graphics library
#include <Adafruit_ILI9341_STM.h> // Hardware-specific library
//#include <SD.h>                // SD card library a bit slower and bigeger than SdFat
#include <SdFat.h>               // More compact and faster than SD
SdFat SD;                        // For SD compatibility
#include <SPI.h>                 // SPI libray obviously!

// These are the pins I use on an UNO, may need chaging for your setup

#define PORTRAIT 0
#define LANDSCAPE 1
#define TFT_DC      PA2 //  PA0      //   (Green) 
#define TFT_CS      PA0 // PA1      //   (Orange) 
#define TFT_RST    PA1 //  PA2      //   (Yellow)

#define TFT_LED        PA3     // Backlight 

// Use hardware SPI lines
//PA5/SPI1_SCK/ADC12_IN5 15
//PA6/SPI1_MISO/ADC12_IN6/TIM3_CH1[TIM1_BKIN] 16
//PA7/SPI1_MOSI/ADC12_IN7/TIM3_CH2[TIM1_CH1N]
#define _sclk PB13//PA5//13
#define _miso PB14//PA6//12 // Needed for SD card, but does not need to be connected to TFT
#define _mosi PB15//PA7//11 // Master Out Slave In to send commands/data to TFT and SD card

// SD chip select
#define _sdcs PB12 //PA4//8

//Adafruit_ILI9341_AS tft = Adafruit_ILI9341_AS(_cs, _dc, _rst); // Invoke custom library
// Create the lcd object
Adafruit_ILI9341_STM tft = Adafruit_ILI9341_STM(TFT_CS, TFT_DC, TFT_RST); // Using hardware SPI

// You can use MS Paint to pick colours off an image and see the RGB values
// This colour is off the mouse image.
#define ILI9341_GREY 0xCE9A // Light grey

// These are used when calling drawBMP() function, see examples in loop()
#define BU_BMP 1 // Temporarily flip the TFT coords for standard Bottom-Up bit maps
#define TD_BMP 0 // Draw inverted Top-Down bitmaps in standard coord frame

uint32_t drawTime = 0; // Variable to save draw times for testing

/***************************************************************************************
** Function name:           setup
** Descriptions:            To set things up
***************************************************************************************/

void setup()
{
  //backlight on...
  pinMode(TFT_LED, OUTPUT);
  digitalWrite(TFT_LED, HIGH);
  
  Serial.begin(115200); // For debug messages

  tft.begin(); // Initialise the display (various parameters configured)

  Serial.println(F("Here we go..."));

  tft.fillScreen(ILI9341_RED);  //test
  tft.fillScreen(ILI9341_GREEN); //test

  // Set text foreground and background colours
  tft.setTextColor(ILI9341_BLACK, ILI9341_WHITE);

  tft.setCursor(0, 0);
  tft.setTextColor(ILI9341_BLACK);  tft.setTextSize(1);
  tft.println("Hello World!");

  Serial.print(F("Initialising SD card..."));
  tft.drawString("Initialising SD card...", 0, 0, 2);

  delay(1000);
  SPI.setModule(2);
    
  if (!SD.begin(_sdcs, SPI_FULL_SPEED )) {  //sdFat library allows speed setting, e.g. SPI_HALF_SPEED
    //if (!SD.begin(_sdcs)) {              // Only needed when standard SD library is used
    SPI.setModule(1);
    Serial.println(F("failed!"));
    tft.drawString("Initialising SD card FAILED!!", 0, 0, 2);
    //return;
  }else {
    SPI.setModule(1);
    tft.drawString("Initialising SD card OK    ", 0, 0, 2);
  }
  delay(1000);
  tft.fillScreen(ILI9341_RED);
  delay(1000);
}

stevestrong
Posts: 1832
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: New SdFat library (with and without DMA)

Post by stevestrong » Mon Jun 13, 2016 11:18 am

It looks like issues are observed with SdFat together with ILI9341 lib.
Shouldn't one start a separate thread for this?
I mean, here I would discuss issues related only to SdFat. Wouldn't make sense?

VadimEL
Posts: 67
Joined: Sat Aug 13, 2016 1:28 pm

Re: New SdFat library (with and without DMA)

Post by VadimEL » Sun Aug 21, 2016 5:00 pm

how to replace one char in position ???

I have 70Kb file f.txt, like

Code: Select all

1234567890qwertyiopasdfghjkl
Need replace 0 in 10 position.
Do not know how to.....

User avatar
martinayotte
Posts: 1229
Joined: Mon Apr 27, 2015 1:45 pm

Re: New SdFat library (with and without DMA)

Post by martinayotte » Sun Aug 21, 2016 6:56 pm

Code: Select all

file.seekSet(10);

VadimEL
Posts: 67
Joined: Sat Aug 13, 2016 1:28 pm

Re: New SdFat library (with and without DMA)

Post by VadimEL » Sun Aug 21, 2016 8:01 pm

martinayotte

ok, thanks work fine, then I change to 1 " #define SD_SPI_CONFIGURATION 1"
I can write to file and SeekSet is work

but led PB1 is lights, and all work fine....

Code: Select all

    pinMode(SD_CS, OUTPUT);
  if (!SD.begin(SD_CS))
  {
    Serial.println("initialization failed!");

    pinMode(PB1, OUTPUT);
    digitalWrite(PB1, HIGH);   // turn the LED on (HIGH is the voltage level)

    return;
  }
  Serial.println("initialization done.");

User avatar
martinayotte
Posts: 1229
Joined: Mon Apr 27, 2015 1:45 pm

Re: New SdFat library (with and without DMA)

Post by martinayotte » Mon Aug 22, 2016 1:03 pm

What do you mean ?
Do you mean it was working with SD_SPI_CONFIGURATION to zero and stop working when 1 ?

VadimEL
Posts: 67
Joined: Sat Aug 13, 2016 1:28 pm

Re: New SdFat library (with and without DMA)

Post by VadimEL » Tue Aug 23, 2016 12:02 pm

#include <SD.h> has no seekSet function, and #include <SdFat.h> has not working with " #define SD_SPI_CONFIGURATION 1"
I change to " #define SD_SPI_CONFIGURATION 1" and it work.

User avatar
martinayotte
Posts: 1229
Joined: Mon Apr 27, 2015 1:45 pm

Re: New SdFat library (with and without DMA)

Post by martinayotte » Wed Aug 24, 2016 12:28 pm

First, the SD library and SdFat library are not the same.
In the first one, the function is simply named seek(), while in the second it is named seekSet().

Of course, for SdFat, you need SD_SPI_CONFIGURATION=1 since it will use the standard SPI.

Post Reply