Ejemplo n.º 1
0
/**
 * \brief SD/MMC/SDIO card read and write test.
 *
 * \param test Current test case.
 */
static void run_sd_mmc_sdio_rw_test(const struct test_case *test)
{
	test_assert_true(test, SD_MMC_OK == sd_mmc_check(0),
			"SD/MMC card is not initialized OK.");

	if (sd_mmc_get_type(0) & (CARD_TYPE_SD | CARD_TYPE_MMC)) {
		run_sd_mmc_rw_test(test);
	}
	if (sd_mmc_get_type(0) & CARD_TYPE_SDIO) {
		run_sdio_rw_test(test);
	}
}
Ejemplo n.º 2
0
/**
 * \brief Display basic information of the card.
 * \note This function should be called only after the card has been
 *       initialized successfully.
 *
 * \param slot   SD/MMC slot to test
 */
static void main_display_info_card(uint8_t slot)
{
    printf("Card information:\n\r");

    printf("    ");
    switch (sd_mmc_get_type(slot)) {
    case CARD_TYPE_SD | CARD_TYPE_HC:
        printf("SDHC");
        break;
    case CARD_TYPE_SD:
        printf("SD");
        break;
    case CARD_TYPE_MMC | CARD_TYPE_HC:
        printf("MMC High Density");
        break;
    case CARD_TYPE_MMC:
        printf("MMC");
        break;
    case CARD_TYPE_SDIO:
        printf("SDIO\n\r");
        return;
    case CARD_TYPE_SD_COMBO:
        printf("SD COMBO");
        break;
    case CARD_TYPE_UNKNOWN:
    default:
        printf("Unknown\n\r");
        return;
    }
    printf("\n\r    %d MB\n\r", (uint16_t)(sd_mmc_get_capacity(slot)/1024));
}
Ejemplo n.º 3
0
Ctrl_status sd_mmc_test_unit_ready(uint8_t slot)
{
	switch (sd_mmc_check(slot))
	{
	case SD_MMC_OK:
		if (sd_mmc_ejected[slot]) {
			return CTRL_NO_PRESENT;
		}
		if (sd_mmc_get_type(slot) & (CARD_TYPE_SD | CARD_TYPE_MMC)) {
			return CTRL_GOOD;
		}
		// It is not a memory card
		return CTRL_NO_PRESENT;

	case SD_MMC_INIT_ONGOING:
		return CTRL_BUSY;

	case SD_MMC_ERR_NO_CARD:
		sd_mmc_ejected[slot] = false;
		return CTRL_NO_PRESENT;

	default:
		return CTRL_FAIL;
	}
}
Ejemplo n.º 4
0
void AtmelMemTest(void)
{
    uint8_t slot = 0;
    sd_mmc_err_t err;
    REDSTATUS ret;

    printf("\x0C\n\r-- SD/MMC/SDIO Card Example --\n\r");
    printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__);

    printf("Please plug an SD, MMC or SDIO card in slot %d.\n\r", slot+1);

    // Wait for a card and ready
    do {
        err = sd_mmc_check(slot);
        if ((SD_MMC_ERR_NO_CARD != err)
        && (SD_MMC_INIT_ONGOING != err)
        && (SD_MMC_OK != err)) {
            printf("Card install FAILED\n\r");
            printf("Please unplug and re-plug the card.\n\r");
            while(SD_MMC_ERR_NO_CARD != sd_mmc_check(slot)) {
            }
        }
    } while (SD_MMC_OK != err);

    // Display basic card information
    main_display_info_card(slot);

    ret = RedOsTimestampInit();
    if (ret != 0) {
        printf("Unable to initialize timestamps, err=%d\n\r", (int)ret);
        return;
    }

    /* Test the card */
    if (sd_mmc_get_type(slot) & CARD_TYPE_SDIO) {
        // Test CIA of SDIO card
        main_test_sdio(slot);
    }
    if (sd_mmc_get_type(slot) & (CARD_TYPE_SD | CARD_TYPE_MMC)) {
        // SD/MMC Card R/W
        main_test_memory(slot);
    }

    (void)RedOsTimestampUninit();

    printf("SD/MMC card test finished.\n\r");
}
Ejemplo n.º 5
0
Archivo: example.c Proyecto: marekr/asf
/**
 * \brief Application entry point.
 *
 * \return Unused (ANSI-C compatibility).
 */
int main(void)
{
	uint8_t slot = 0;
	sd_mmc_err_t err;

	system_init();
	delay_init();
	cdc_uart_init();

	irq_initialize_vectors();
	cpu_irq_enable();

	time_tick_init();

	// Initialize SD MMC stack
	sd_mmc_init();

	printf("\x0C\n\r-- SD/MMC Card Example --\n\r");
	printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__);
	while (1) {
		if (slot == sd_mmc_nb_slot()) {
			slot = 0;
		}
		printf("Please plug an SD/MMC card in slot %d.\n\r", slot+1);

		// Wait for a card and ready
		do {
			err = sd_mmc_check(slot);
			if ((SD_MMC_ERR_NO_CARD != err)
					&& (SD_MMC_INIT_ONGOING != err)
					&& (SD_MMC_OK != err)) {
				printf("Card install FAILED\n\r");
				printf("Please unplug and re-plug the card.\n\r");
				while (SD_MMC_ERR_NO_CARD != sd_mmc_check(slot)) {
				}
			}
		} while (SD_MMC_OK != err);
	
		// Display basic card information
		main_display_info_card(slot);
	
		/* Test the card */
		if (sd_mmc_get_type(slot) & (CARD_TYPE_SD | CARD_TYPE_MMC)) {
			// SD/MMC Card R/W
			main_test_memory(slot);
		}	

		printf("Test finished, please unplugged the card.\n\r");
		while (SD_MMC_OK == sd_mmc_check(slot)) {
		}
		slot++;
	}
}
Ejemplo n.º 6
0
Archivo: example.c Proyecto: Dewb/mod
/**
 * \brief Application entry point.
 *
 * \return Unused (ANSI-C compatibility).
 */
int main(void)
{
	uint8_t slot = 0;
	sd_mmc_err_t err;

	const usart_serial_options_t usart_serial_options = {
		.baudrate   = CONF_TEST_BAUDRATE,
		.charlength = CONF_TEST_CHARLENGTH,
		.paritytype = CONF_TEST_PARITY,
		.stopbits   = CONF_TEST_STOPBITS,
	};

	irq_initialize_vectors();
	cpu_irq_enable();

	sysclk_init();
	board_init();
	stdio_serial_init(CONF_TEST_USART, &usart_serial_options);

	time_tick_init();

	// Initialize SD MMC stack
	sd_mmc_init();

	printf("\x0C\n\r-- SD/MMC/SDIO Card Example --\n\r");
	printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__);
	while (1) {
		if (slot == sd_mmc_nb_slot()) {
			slot = 0;
		}
		printf("Please plug an SD, MMC or SDIO card in slot %d.\n\r", slot+1);

		// Wait for a card and ready
		do {
			err = sd_mmc_check(slot);
			if ((SD_MMC_ERR_NO_CARD != err)
					&& (SD_MMC_INIT_ONGOING != err)
					&& (SD_MMC_OK != err)) {
				printf("Card install FAILED\n\r");
				printf("Please unplug and re-plug the card.\n\r");
				while (SD_MMC_ERR_NO_CARD != sd_mmc_check(slot)) {
				}
			}
		} while (SD_MMC_OK != err);
	
		// Display basic card information
		main_display_info_card(slot);
	
		/* Test the card */
		if (sd_mmc_get_type(slot) & CARD_TYPE_SDIO) {
			// Test CIA of SDIO card
			main_test_sdio(slot);
		}
		if (sd_mmc_get_type(slot) & (CARD_TYPE_SD | CARD_TYPE_MMC)) {
			// SD/MMC Card R/W
			main_test_memory(slot);
		}	

		printf("Test finished, please unplugged the card.\n\r");
		while (SD_MMC_OK == sd_mmc_check(slot)) {
		}
		slot++;
	}
}
Ejemplo n.º 7
0
/**
 * \brief Show SD card status on the OLED screen.
 */
static void display_sd_info(void)
{
	FRESULT res;
	uint8_t card_check;
	uint8_t sd_card_type;
	uint32_t sd_card_size;
	char size[64];

	/* Is SD card present? */
	if (gpio_pin_is_low(SD_MMC_0_CD_GPIO) == false) {
		multi_language_show_no_sd_info();
	} else {
		multi_language_show_sd_info();

		sd_mmc_init();
		card_check = sd_mmc_check(0);
		while (card_check != SD_MMC_OK) {
			card_check = sd_mmc_check(0);
			delay_ms(1);
		}

		if (card_check == SD_MMC_OK) {
			sd_card_type = sd_mmc_get_type(0);
			sd_card_size = sd_mmc_get_capacity(0);

			/* Card type */
			switch (sd_card_type) {
			case CARD_TYPE_SD:
				multi_language_show_normal_card_info();
				break;

			case CARD_TYPE_SDIO:
				break;

			case CARD_TYPE_HC:
				multi_language_show_high_capacity_card_info();
				break;

			case CARD_TYPE_SD_COMBO:
				break;

			default:
				multi_language_show_unknow_card_info();
			}

			multi_language_show_card_size_info(size, sd_card_size);

			/* Try to mount file system. */
			memset(&fs, 0, sizeof(FATFS));
			res = f_mount(LUN_ID_SD_MMC_0_MEM, &fs);
			if (FR_INVALID_DRIVE == res) {
				multi_language_show_no_fatfs_info();
				sd_fs_found = 0;
			} else {
				get_num_files_on_sd();
				if (sd_num_files == 0) {
					multi_language_show_no_files_info();
					sd_fs_found = 1;
				} else {
					multi_language_show_browse_info();
					sd_fs_found = 1;
				}
			}
		}
	}
}
Ejemplo n.º 8
0
/**
 * \brief Show SD card status on the OLED screen.
 */
static void display_sd_info(void)
{
	uint8_t card_check;
	uint8_t sd_card_type;
	uint8_t sd_card_version;
	uint32_t sd_card_size;
	uint8_t size[10];

	// Is SD card present?
	if (gpio_pin_is_low(SD_MMC_0_CD_GPIO) == false)
	{
		ssd1306_write_text("Please insert SD card...");
	}
	else
	{
		ssd1306_write_text("SD card information:");

		sd_mmc_init();
		card_check = sd_mmc_check(0);
		while (card_check != SD_MMC_OK)
		{
			card_check = sd_mmc_check(0);
			delay_ms(1);
		}

		if (card_check == SD_MMC_OK)
		{
			sd_card_type = sd_mmc_get_type(0);
			sd_card_version = sd_mmc_get_version(0);
			sd_card_size = sd_mmc_get_capacity(0);

			ssd1306_set_page_address(1);
			ssd1306_set_column_address(0);

			// Card type
			switch(sd_card_type)
			{
				case CARD_TYPE_SD:
				ssd1306_write_text("- Type: Normal SD card");
				break;
				case CARD_TYPE_SDIO:
				ssd1306_write_text("- Type: SDIO card");
				break;
				case CARD_TYPE_HC:
				ssd1306_write_text("- Type: High Capacity card");
				break;
				case CARD_TYPE_SD_COMBO:
				ssd1306_write_text("- Type: SDIO/Memory card");
				break;
				default:
				ssd1306_write_text("- Type: unknown");
			}

			ssd1306_set_page_address(2);
			ssd1306_set_column_address(0);

			// SD card version
			switch(sd_card_version)
			{
				case CARD_VER_SD_1_0:
				ssd1306_write_text("- Version: 1.0x");
				break;
				case CARD_VER_SD_1_10:
				ssd1306_write_text("- Version: 1.10");
				break;
				case CARD_VER_SD_2_0:
				ssd1306_write_text("- Version: 2.00");
				break;
				case CARD_VER_SD_3_0:
				ssd1306_write_text("- Version: 3.0x");
				break;
				default:
				ssd1306_write_text("- Version: unknown");
			}

			ssd1306_set_page_address(3);
			ssd1306_set_column_address(0);

			sprintf(size, "- Total size: %lu KB", sd_card_size);
			ssd1306_write_text(size);
		}
	}
}
Ejemplo n.º 9
0
// Mount the specified SD card, returning true if done, false if needs to be called again.
// If an error occurs, return true with the error message in 'reply'.
// This may only be called to mount one card at a time.
GCodeResult MassStorage::Mount(size_t card, const StringRef& reply, bool reportSuccess)
{
	if (card >= NumSdCards)
	{
		reply.copy("SD card number out of range");
		return GCodeResult::error;
	}

	SdCardInfo& inf = info[card];
	MutexLocker lock1(fsMutex);
	MutexLocker lock2(inf.volMutex);
	if (!inf.mounting)
	{
		if (inf.isMounted)
		{
			if (AnyFileOpen(&inf.fileSystem))
			{
				// Don't re-mount the card if any files are open on it
				reply.copy("SD card has open file(s)");
				return GCodeResult::error;
			}
			(void)InternalUnmount(card, false);
		}

		inf.mountStartTime = millis();
		inf.mounting = true;
		delay(2);
	}

	if (inf.cardState == CardDetectState::notPresent)
	{
		reply.copy("No SD card present");
		inf.mounting = false;
		return GCodeResult::error;
	}

	if (inf.cardState != CardDetectState::present)
	{
		return GCodeResult::notFinished;						// wait for debounce to finish
	}

	const sd_mmc_err_t err = sd_mmc_check(card);
	if (err != SD_MMC_OK && millis() - inf.mountStartTime < 5000)
	{
		delay(2);
		return GCodeResult::notFinished;
	}

	inf.mounting = false;
	if (err != SD_MMC_OK)
	{
		reply.printf("Cannot initialise SD card %u: %s", card, TranslateCardError(err));
		return GCodeResult::error;
	}

	// Mount the file systems
	const char path[3] = { (char)('0' + card), ':', 0 };
	const FRESULT mounted = f_mount(&inf.fileSystem, path, 1);
	if (mounted != FR_OK)
	{
		reply.printf("Cannot mount SD card %u: code %d", card, mounted);
		return GCodeResult::error;
	}

	inf.isMounted = true;
	if (reportSuccess)
	{
		float capacity = ((float)sd_mmc_get_capacity(card) * 1024) / 1000000;		// get capacity and convert from Kib to Mbytes
		const char* capUnits;
		if (capacity >= 1000.0)
		{
			capacity /= 1000;
			capUnits = "Gb";
		}
		else
		{
			capUnits = "Mb";
		}
		reply.printf("%s card mounted in slot %u, capacity %.2f%s", TranslateCardType(sd_mmc_get_type(card)), card, (double)capacity, capUnits);
	}

	return GCodeResult::ok;
}