Page 1 of 1

SD-Card Activity Status

Posted: Fri Oct 24, 2014 11:29 am
by Tabulous
Hi Giovanni,
do you have any objections for me submitting a patch/change to the sd-card driver.

Basically i would like to add the functionality to show disk activity. i.e read and writing.

At the moment i do it like this

Code: Select all

bool_t sdcRead(SDCDriver *sdcp, uint32_t startblk,
               uint8_t *buf, uint32_t n) {
  bool_t status;

  chDbgCheck((sdcp != NULL) && (buf != NULL) && (n > 0), "sdcRead");
  chDbgAssert(sdcp->state == BLK_READY, "sdcRead(), #1", "invalid state");

  if ((startblk + n - 1) > sdcp->capacity){
    sdcp->errors |= SDC_OVERFLOW_ERROR;
    return CH_FAILED;
  }

  /* Read operation in progress.*/
  sdcp->state = BLK_READING;

  [b]palClearPad(GPIOG, GPIOG_LED_STATUS_GRN);[/b]

  status = sdc_lld_read(sdcp, startblk, buf, n);

  [b]palSetPad(GPIOG, GPIOG_LED_STATUS_GRN);[/b]

  /* Read operation finished.*/
  sdcp->state = BLK_READY;
  return status;
}


Bold type showing calls to my LED's

For me this is not a very elegant solution, and also if i change versions i have to go and redo the changes to the new version.

So my thoughts where, to have this work abit like the "sdc_lld_is_card_inserted(SDCDriver *sdcp)"

Where you can have disk activity functions in board.c, these would be called from the sdc.c read and write routines.


Also the addition of this functionality would be controlled by conditional selections i.e #if SDC_READ_ACTIVITY etc etc


What are your thoughts ?

Re: SD-Card Activity Status

Posted: Fri Oct 24, 2014 12:36 pm
by Giovanni
Hi,

Can't you simply put that code outside the sdcRead() function? if you are using FatFS then I would put that in the FatFS wrapper code.

Giovanni

Re: SD-Card Activity Status

Posted: Sun Oct 26, 2014 1:52 pm
by Tabulous
Giovanni wrote:Hi,

Can't you simply put that code outside the sdcRead() function? if you are using FatFS then I would put that in the FatFS wrapper code.

Giovanni


Putting it in the fatfs wrapper is ok, but i would still need to add a macro to sdc.h to make it comply with how the card detection is implemented.


ie have this in the fatfs wrapper

Code: Select all

  case SDC:
    if (blkGetDriverState(&SDCD1) != BLK_READY)
      return RES_NOTRDY;

    sdcActivityStart( DISK_READ or DISK_WRITE );

    status = sdcRead(&SDCD1, sector, buff, count);

    sdcActivityFinish( DISK_READ or DISK_WRITE );

    if (status == CH_FAILED)
      return RES_ERROR;

    return RES_OK;



And then a macro in sdc.h

Code: Select all


#define sdcActivityStart(x) (sdc_lld_disk_activity(x))



If its not implemented along these lines, everytime i pull the latest version, i have to go back and edit things.....


Also can i suggest you lower the default STM32_SDIO_DIV_HS from 0 to 2 even on a very good layout the SDIO CLK/Signals are not the best..... Should help with reliability out of the box

Re: SD-Card Activity Status

Posted: Sun Oct 26, 2014 2:48 pm
by Giovanni
Hi,

The LED handling should go in the wrapper without affecting the driverS (mmc_spi, sdc and possibly others), any LED abstraction should go in the wrapper.

Giovanni