SD-Card Activity Status

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
Tabulous
Posts: 518
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 18 times

SD-Card Activity Status

Post 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 ?
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: SD-Card Activity Status

Post 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
Tabulous
Posts: 518
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 18 times

Re: SD-Card Activity Status

Post 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
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: SD-Card Activity Status

Post 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
Post Reply