// MMC card insertion event static void InsertHandler(eventid_t id) { FRESULT err; (void) id; if(mmcConnect(&MMCD1)) { chprintf((BaseChannel *) &SD2, "SD: Failed to connect to card\r\n"); return; } else { chprintf((BaseChannel *) &SD2, "SD: Connected to card\r\n"); } err = f_mount(0, &MMC_FS); if(err != FR_OK) { chprintf((BaseChannel *) &SD2, "SD: f_mount() failed %d\r\n", err); mmcDisconnect(&MMCD1); return; } else { chprintf((BaseChannel *) &SD2, "SD: File system mounted\r\n"); } fs_ready = TRUE; // quick and dirty // directly decode all mp3's in the // cards root in a loop (assuming the card is never pulled) while(1) { Mp3PlayAllFiles("/"); } }
/* * MMC card insertion event. */ static void InsertHandler(eventid_t id) { FRESULT err; (void)id; buzzPlayWait(1000, MS2ST(100)); buzzPlayWait(2000, MS2ST(100)); chprintf((BaseSequentialStream *)&SD1, "MMC: inserted\r\n"); /* * On insertion MMC initialization and FS mount. */ chprintf((BaseSequentialStream *)&SD1, "MMC: initialization "); if (mmcConnect(&MMCD1)) { chprintf((BaseSequentialStream *)&SD1, "failed\r\n"); return; } chprintf((BaseSequentialStream *)&SD1, "ok\r\n"); chprintf((BaseSequentialStream *)&SD1, "FS: mount "); err = f_mount(0, &MMC_FS); if (err != FR_OK) { chprintf((BaseSequentialStream *)&SD1, "failed\r\n"); mmcDisconnect(&MMCD1); return; } fs_ready = TRUE; chprintf((BaseSequentialStream *)&SD1, "ok\r\n"); buzzPlay(440, MS2ST(200)); }
/* * MMC card removal event. */ static void RemoveHandler(eventid_t id) { (void)id; chprintf((BaseSequentialStream *)&SD1, "MMC: removed\r\n"); mmcDisconnect(&MMCD1); fs_ready = FALSE; buzzPlayWait(2000, MS2ST(100)); buzzPlayWait(1000, MS2ST(100)); }
// MMC card removal event. static void RemoveHandler(eventid_t id) { (void)id; chprintf(chp1, "MMC: removed\r\n"); mmcDisconnect(&MMCD1); fs_ready = FALSE; // buzzPlayWait(2000, MS2ST(100)); // buzzPlayWait(1000, MS2ST(100)); palSetPad(GPIO0, GPIO0_MMC_PWR); }
/* * MMC card insertion event. */ static void InsertHandler(eventid_t id) { FRESULT err; (void)id; /* * On insertion MMC initialization and FS mount. */ if (mmcConnect(&MMCD1)) { return; } err = f_mount(0, &MMC_FS); if (err != FR_OK) { mmcDisconnect(&MMCD1); return; } fs_ready = TRUE; }
/** * Mount a default filesystem on the root FS **/ static int mountFS(void) { FRESULT err; if (mmcConnect(&MMCD1)) { chprintf((BaseSequentialStream *)&SERIAL_DRIVER, "Can not connect to MMC!\r\n"); return 0; } err = f_mount(0, &MMC_FS); if (err != FR_OK) { mmcDisconnect(&MMCD1); return 0; } chprintf((BaseSequentialStream *)&SERIAL_DRIVER, "Card mounted!\r\n"); fs_ready = TRUE; return 1; }
// MMC card insertion event static void InsertHandler(eventid_t id) { FRESULT err; (void) id; if(mmcConnect(&MMCD1)) { chprintf((BaseChannel *) &SD2, "SD: Failed to connect to card\r\n"); return; } else { chprintf((BaseChannel *) &SD2, "SD: Connected to card\r\n"); } err = f_mount(0, &MMC_FS); if(err != FR_OK) { chprintf((BaseChannel *) &SD2, "SD: f_mount() failed %d\r\n", err); mmcDisconnect(&MMCD1); return; } else { chprintf((BaseChannel *) &SD2, "SD: File system mounted\r\n"); } fs_ready = TRUE; // quick and dirty // directly decode all mp3's in the // cards root in a loop (assuming the card is never pulled) { rc = f_open(&Fil, "Quad_Handler.TXT", FA_WRITE | FA_CREATE_ALWAYS); // rc = f_printf(&Fil, "moin\r\n"); rc = f_sync(&Fil); } }
/* * MMC card insertion event. */ static void InsertHandler(eventid_t id) { (void)id; /* * On insertion MMC initialization and FS mount. */ tried = 1; connected = 5; if (mmcConnect(&MMCD1)) { connected = 2; return; } connected = 6; err = f_mount(0, &MMC_FS); connected = 7; if (err != FR_OK) { connected = 3; mmcDisconnect(&MMCD1); return; } connected = 1; fs_ready = TRUE; }
void cmd_sdiotest(BaseSequentialStream *chp, int argc, char *argv[]){ (void)argc; (void)argv; FRESULT err; uint32_t clusters; FATFS *fsp; FIL FileObject; //FILINFO FileInfo; size_t bytes_written; struct tm timp; // set time to 2011-03-13 07:06:40 //rtcSetTimeUnixSec(&RTCD1, 1300000000); #if !HAL_USE_RTC chprintf(chp, "ERROR! Chibios compiled without RTC support."); chprintf(chp, "Enable HAL_USE_RCT in you halconf.h"); chThdSleepMilliseconds(100); return; #endif chprintf(chp, "Trying to connect SDIO... "); chThdSleepMilliseconds(100); if (!mmcConnect(&MMCD1)) { chprintf(chp, "OK\r\n"); chprintf(chp, "Register working area for filesystem... "); chThdSleepMilliseconds(100); err = f_mount(0, &MMC_FS); if (err != FR_OK){ chSysHalt(); } else{ fs_ready = TRUE; chprintf(chp, "OK\r\n"); } chprintf(chp, "Mounting filesystem... "); chThdSleepMilliseconds(100); err = f_getfree("/", &clusters, &fsp); if (err != FR_OK) { chSysHalt(); } chprintf(chp, "OK\r\n"); chprintf(chp, "FS: %lu free clusters, %lu sectors per cluster, %lu bytes free\r\n", clusters, (uint32_t)MMC_FS.csize, clusters * (uint32_t)MMC_FS.csize * (uint32_t)MMCSD_BLOCK_SIZE); rtcGetTimeTm(&RTCD1, &timp); chprintf(chp, "Current RTC time is: "); chprintf(chp, "%u-%u-%u %u:%u:%u\r\n", timp.tm_year+1900, timp.tm_mon+1, timp.tm_mday, timp.tm_hour, timp.tm_min, timp.tm_sec); chprintf(chp, "Creating empty file 'tmstmp.tst'... "); chThdSleepMilliseconds(100); err = f_open(&FileObject, "0:tmstmp.tst", FA_WRITE | FA_OPEN_ALWAYS); if (err != FR_OK) { chSysHalt(); } chprintf(chp, "OK\r\n"); chprintf(chp, "Write some data in it... "); chThdSleepMilliseconds(100); err = f_write(&FileObject, "tst", sizeof("tst"), (void *)&bytes_written); if (err != FR_OK) { chSysHalt(); } else chprintf(chp, "OK\r\n"); chprintf(chp, "Closing file 'tmstmp.tst'... "); chThdSleepMilliseconds(100); err = f_close(&FileObject); if (err != FR_OK) { chSysHalt(); } else chprintf(chp, "OK\r\n"); // chprintf(chp, "Obtaining file info ... "); // chThdSleepMilliseconds(100); // err = f_stat("0:tmstmp.tst", &FileInfo); // if (err != FR_OK) { // chSysHalt(); // } // else{ // chprintf(chp, "OK\r\n"); // chprintf(chp, " Timestamp: %u-%u-%u %u:%u:%u\r\n", // ((FileInfo.fdate >> 9) & 127) + 1980, // (FileInfo.fdate >> 5) & 15, // FileInfo.fdate & 31, // (FileInfo.ftime >> 11) & 31, // (FileInfo.ftime >> 5) & 63, // (FileInfo.ftime & 31) * 2); // } chprintf(chp, "Umounting filesystem... "); f_mount(0, NULL); chprintf(chp, "OK\r\n"); chprintf(chp, "Disconnecting from SDIO..."); chThdSleepMilliseconds(100); if (mmcDisconnect(&MMCD1)) chSysHalt(); chprintf(chp, " OK\r\n"); chprintf(chp, "------------------------------------------------------\r\n"); chprintf(chp, "Now you can remove memory card and check timestamp on PC.\r\n"); chThdSleepMilliseconds(100); } else{ chSysHalt(); } }
/* * MMC card removal event. */ static void RemoveHandler(eventid_t id) { (void)id; mmcDisconnect(&MMCD1); fs_ready = FALSE; }
bool_t bnapStorageDisconnect(BnapStorage_t *bsp){ return mmcDisconnect(bsp->mmcp); }
/* * Application entry point. */ int main(void) { float nick, roll, yaw; static const evhandler_t evhndl[] = {InsertHandler, RemoveHandler}; struct EventListener el0, el1; FRESULT err; /* * System initializations. * - HAL initialization, this also initializes the configured device drivers * and performs the board-specific initializations. * - Kernel initialization, the main() function becomes a thread and the * RTOS is active. */ halInit(); chSysInit(); /* * Activates the serial driver 2 using the driver default configuration. * PA2(TX) and PA3(RX) are routed to USART2. */ sdStart(&SD2, NULL); palSetPadMode(GPIOD, 5, PAL_MODE_ALTERNATE(7)); palSetPadMode(GPIOD, 6, PAL_MODE_ALTERNATE(7)); setup_IMU(); setup_Fernsteuerung(); setup_Motoren(); setup_Regelung(); // initialize MMC driver // setup pads to SPI1 function (connect these pads to your SD card accordingly) palSetPadMode(GPIOC, 4, PAL_MODE_OUTPUT_PUSHPULL | PAL_STM32_OSPEED_HIGHEST); // NSS palSetPadMode(GPIOA, 5, PAL_MODE_ALTERNATE(5) | PAL_STM32_OSPEED_HIGHEST); // SCK palSetPadMode(GPIOA, 6, PAL_MODE_ALTERNATE(5)); // MISO palSetPadMode(GPIOA, 7, PAL_MODE_ALTERNATE(5) | PAL_STM32_OSPEED_HIGHEST); // MOSI palSetPad(GPIOC, 4); // set NSS high // initialize MMC driver mmcObjectInit(&MMCD1, &SPID1, &ls_spicfg, &hs_spicfg, mmc_is_protected, mmc_is_inserted); mmcStart(&MMCD1, NULL); chEvtRegister(&MMCD1.inserted_event, &el0, 0); chEvtRegister(&MMCD1.removed_event, &el1, 1); chThdSleepMilliseconds(7000); if(mmcConnect(&MMCD1)) { chprintf((BaseChannel *) &SD2, "SD: Failed to connect to card\r\n"); return; } else { chprintf((BaseChannel *) &SD2, "SD: Connected to card\r\n"); } err = f_mount(0, &MMC_FS); if(err != FR_OK) { chprintf((BaseChannel *) &SD2, "SD: f_mount() failed %d\r\n", err); mmcDisconnect(&MMCD1); return; } else { chprintf((BaseChannel *) &SD2, "SD: File system mounted\r\n"); } fs_ready = TRUE; rc = f_open(&Fil, "Quad.TXT", FA_WRITE | FA_CREATE_ALWAYS); /* * Normal main() thread activity, in this demo it does nothing except * sleeping in a loop and check the button state, when the button is * pressed the test procedure is launched with output on the serial * driver 2. */ while (TRUE) { update_IMU(); //Ersetzen durch Interrupt Handler!!!!!! nick = getEuler_nick(); roll = getEuler_roll(); yaw = getEuler_yaw(); f_printf(&Fil, "%d;%d;%d\r\n",(int)(nick*100),(int)(roll*100),(int)(yaw*100)); rc = f_sync(&Fil); chThdSleepMilliseconds(10); } }