What is max size of mmc supported

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
ep.hobbyiest
Posts: 94
Joined: Sun Jun 26, 2016 5:22 pm
Has thanked: 4 times
Been thanked: 1 time

What is max size of mmc supported

Post by ep.hobbyiest »

What is max. size of memory card is supported by chibios?
i am using nucleoF401 and chibios.3.0 version.

I am using 8 gb but seems to be not detected by system.

here is snap of the debug variable value.Image

and here is code for reference.

Code: Select all

/*
 * mmc.c
 *
 *  Created on: 15-Jan-2017
 *      Author: aaaa
 */

#include "ch.h"
#include "hal.h"
#include "ff.h"
#include "serialif.h"

/*===========================================================================*/
/* MMC_SPI driver related settings.                                          */
/*===========================================================================*/

/**
 * @brief   Delays insertions.
 * @details If enabled this options inserts delays into the MMC waiting
 *          routines releasing some extra CPU time for the threads with
 *          lower priority, this may slow down the driver a bit however.
 *          This option is recommended also if the SPI driver does not
 *          use a DMA channel and heavily loads the CPU.
 */
#if !defined(MMC_NICE_WAITING) || defined(__DOXYGEN__)
#define MMC_NICE_WAITING            TRUE
#endif

/**
 * @brief   Number of positive insertion queries before generating the
 *          insertion event.
 */
#if !defined(MMC_POLLING_INTERVAL) || defined(__DOXYGEN__)
#define MMC_POLLING_INTERVAL        10
#endif

/**
 * @brief   Interval, in milliseconds, between insertion queries.
 */
#if !defined(MMC_POLLING_DELAY) || defined(__DOXYGEN__)
#define MMC_POLLING_DELAY           100
#endif

/**
 * @brief   Block size for MMC transfers.
 */
#if !defined(MMC_SECTOR_SIZE) || defined(__DOXYGEN__)
#define MMC_SECTOR_SIZE             512
#endif


/**
 * @brief FS object.
 */
FATFS MMC_FS;

/**
 * MMC driver instance.
 */
MMCDriver MMCD1;

/**
 * @brief   Card monitor timer.
 */
static virtual_timer_t tmr;

/**
 * @brief   Debounce counter.
 */
static unsigned cnt;
bool fs_ready = FALSE;


static EVENTSOURCE_DECL(inserted_event);
static EVENTSOURCE_DECL(removed_event);

static const SPIConfig hs_spicfg = {NULL, GPIOB, GPIOB_PIN12, 0};
static const SPIConfig ls_spicfg = {NULL, GPIOB, GPIOB_PIN12, SPI_CR1_BR_2 | SPI_CR1_BR_1};

static const MMCConfig mmccfg = {&SPID1, &ls_spicfg, &hs_spicfg};
static void InsertHandler(eventid_t id);
static void RemoveHandler(eventid_t id);

uint8_t fbuff[256];
  evhandler_t evhndl[] = {
              InsertHandler,
              RemoveHandler
    };

static THD_WORKING_AREA(waMmcMonitor,128);
static void MmcMonitor(void *arg);

/**
 * @brief   Insertion monitor timer callback function.
 *
 * @param[in] p         pointer to the @p BaseBlockDevice object
 *
 * @notapi
 */
static void tmrfunc(void *p) {
  BaseBlockDevice *bbdp = p;

  /* The presence check is performed only while the driver is not in a
     transfer state because it is often performed by changing the mode of
     the pin connected to the CS/D3 contact of the card, this could disturb
     the transfer.*/
  blkstate_t state = blkGetDriverState(bbdp);
  chSysLockFromISR();
  if ((state != BLK_READING) && (state != BLK_WRITING)) {
    /* Safe to perform the check.*/
    if (cnt > 0) {
      if (blkIsInserted(bbdp)) {
        if (--cnt == 0) {
          chEvtBroadcastI(&inserted_event);
        }
      }
      else
        cnt = MMC_POLLING_INTERVAL;
    }
    else {
      if (!blkIsInserted(bbdp)) {
        cnt = MMC_POLLING_INTERVAL;
        chEvtBroadcastI(&removed_event);
      }
    }
  }
  chVTSetI(&tmr, MS2ST(MMC_POLLING_DELAY), tmrfunc, bbdp);
  chSysUnlockFromISR();
}

/**
 * @brief   Polling monitor start.
 *
 * @param[in] p         pointer to an object implementing @p BaseBlockDevice
 *
 * @notapi
 */
static void tmr_init(void *p) {
  chSysLock();
  cnt = MMC_POLLING_INTERVAL;
  chVTSetI(&tmr, MS2ST(MMC_POLLING_DELAY), tmrfunc, p);
  chSysUnlock();
}


static FRESULT scan_files(BaseSequentialStream *chp, char *path) {
  FRESULT res;
  FILINFO fno;
  DIR dir;
  int i;
  char *fn;

#if _USE_LFN
  fno.lfname = 0;
  fno.lfsize = 0;
#endif
  res = f_opendir(&dir, path);
  if (res == FR_OK) {
    i = strlen(path);
    for (;;) {
      res = f_readdir(&dir, &fno);
      if (res != FR_OK || fno.fname[0] == 0)
        break;
      if (fno.fname[0] == '.')
        continue;
      fn = fno.fname;
      if (fno.fattrib & AM_DIR) {
        path[i++] = '/';
        strcpy(&path[i], fn);
        res = scan_files(chp, path);
        if (res != FR_OK)
          break;
        path[--i] = 0;
      }
      else {
        chprintf(chp, "%s/%s\r\n", path, fn);
      }
    }
  }
  return res;
}


/*
 * MMC card insertion event.
 */
static void InsertHandler(eventid_t id) {
  FRESULT err;
  char path = 0;

  (void)id;
  /*
   * On insertion MMC initialization and FS mount.
   */
  if (mmcConnect(&MMCD1)) {
    return;
  }
  err = f_mount(&MMC_FS, &path, 1);
  if (err != FR_OK) {
    mmcDisconnect(&MMCD1);
    return;
  }
//  print("MMC Inserted\r\n");
  fs_ready = TRUE;
  palSetPad(GPIOA, GPIOA_LED_GREEN);

}

/*
 * MMC card removal event.
 */
static void RemoveHandler(eventid_t id) {

  (void)id;
  mmcDisconnect(&MMCD1);
//  print("MMC Ejected\r\n");
  fs_ready = FALSE;
  palClearPad(GPIOA, GPIOA_LED_GREEN);
}


void init_mmcfs(void)
{

    struct event_listener el0, el1;
    palSetPadMode(GPIOA, 5, PAL_MODE_ALTERNATE(5) |
                             PAL_STM32_OSPEED_HIGHEST);       /* New SCK.     */
    palSetPadMode(GPIOA, 6, PAL_MODE_ALTERNATE(5) |
                             PAL_STM32_OSPEED_HIGHEST);       /* New MISO.    */
    palSetPadMode(GPIOA, 7, PAL_MODE_ALTERNATE(5) |
                             PAL_STM32_OSPEED_HIGHEST);       /* New MOSI.    */
    palSetPadMode(GPIOB, 6, PAL_MODE_OUTPUT_PUSHPULL |
                             PAL_STM32_OSPEED_HIGHEST);       /* New CS.      */
    palSetPad(GPIOB, 6);

    mmcObjectInit(&MMCD1);
    mmcStart(&MMCD1, &mmccfg);
    chThdCreateStatic(waMmcMonitor,sizeof(waMmcMonitor),NORMALPRIO,MmcMonitor,NULL);

    tmr_init(&MMCD1);
    chEvtRegister(&inserted_event, &el0, 0);
    chEvtRegister(&removed_event, &el1, 1);
}

static void MmcMonitor(void *arg)
{
  while(1)
  {
    chEvtDispatch(evhndl, chEvtWaitOneTimeout(ALL_EVENTS, MS2ST(500)));
  }
}
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: What is max size of mmc supported

Post by Giovanni »

Hi,

The MMC-SPI driver supports up to 2GB if I remember well, high capacity cards are not recognized. It would require an overhaul of the connect procedure, the SDC driver is able to recognize the high capacity ones.

Giovanni
ep.hobbyiest
Posts: 94
Joined: Sun Jun 26, 2016 5:22 pm
Has thanked: 4 times
Been thanked: 1 time

Re: What is max size of mmc supported

Post by ep.hobbyiest »

ohh..my bad.
i have mmc holder pcb with spi connection only.

will fat fs work with 1gb and spi?
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: What is max size of mmc supported

Post by Giovanni »

Yes, it does.

Giovanni
ep.hobbyiest
Posts: 94
Joined: Sun Jun 26, 2016 5:22 pm
Has thanked: 4 times
Been thanked: 1 time

Re: What is max size of mmc supported

Post by ep.hobbyiest »

I am using SDC with 1 bit mode. So, just will be require to alter connection to nucleo.
But, It is not working for me. Here is code for SDC driver and mcuconfig.h and hal_config.h
Here is connection.
Attachments
conf_files.zip
(5 KiB) Downloaded 429 times
sdio_connection.PNG
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: What is max size of mmc supported

Post by Giovanni »

hi,

You need to verify the setup of GPIO pins and make sure that there are no conflicts with board-mounted components.

Long wires could be a problem too, it already happened.

Giovanni
ep.hobbyiest
Posts: 94
Joined: Sun Jun 26, 2016 5:22 pm
Has thanked: 4 times
Been thanked: 1 time

Re: What is max size of mmc supported

Post by ep.hobbyiest »

Thanks,
Problem is solved now.
Post Reply