unreal_himan 0 2 ноября, 2020 Опубликовано 2 ноября, 2020 · Жалоба Здравствуйте, форумчане. Проблема с флешками. В качестве основы для проекта брал ASF от атмел для работы с SD/MMC, есть учебная плата SAM E70 XPLD с флешкой SDHC на 32 гб и кастомная плата с emmc того же объема и работают одинаково. Почему-то при записи/чтении получаются одинаковые данные по 512 байт. Причем повторяющиеся данные получаются и при односекторном режиме и мультисекторном. проекты Iar и atmel studio работают тоже одинаково. Может кто сталкивался с таким? Что я делаю не так?.Помогите пожалуйста Полный код во вложении #define blocks_8k_in_file 5730 // SD_MMC_BLOCK_SIZE #define SD_MMC_BLOCK_count 8192 / SD_MMC_BLOCK_SIZE // write_buffer COMPILER_ALIGNED(32) static uint8_t write_buf_pack_1[SD_MMC_BLOCK_count * SD_MMC_BLOCK_SIZE] = {0}; COMPILER_ALIGNED(32) static uint8_t write_buf_pack_2[SD_MMC_BLOCK_count * SD_MMC_BLOCK_SIZE] = {0}; 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++; } } /** * \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("Unknow\n\r"); return; } printf("\n\r %d MB\n\r", (uint16_t)(sd_mmc_get_capacity(slot)/1024)); } uint8_t read_fram_file(uint16_t num_of_file, uint32_t num_of_page_file, uint8_t *buf_read) { uint32_t t_num_page = 0; t_num_page = (num_of_file-1)*blocks_8k_in_file+num_of_page_file; for (uint8_t i = 0;i<SD_MMC_BLOCK_count-1;i++) { if (SD_MMC_OK != sd_mmc_init_read_blocks(0, t_num_page+i, 1/*SD_MMC_BLOCK_count*/)) { printf("[FAIL]\n\r"); return 1; } if (SD_MMC_OK != sd_mmc_start_read_blocks(buf_read+i*512, 1/*SD_MMC_BLOCK_count*/)) { printf("[FAIL]\n\r"); return 1; } if (SD_MMC_OK != sd_mmc_wait_end_of_read_blocks(false)) { printf("[FAIL]\n\r"); return 1; } } return 0; } uint8_t write_fram_file(uint16_t num_of_file, uint32_t num_of_page_file, uint8_t *buf_write) { uint32_t t_num_page = (num_of_file-1)*blocks_8k_in_file+num_of_page_file; for (uint8_t i = 0;i<SD_MMC_BLOCK_count;i++) { if (SD_MMC_OK != sd_mmc_init_write_blocks(0, t_num_page+i, 1/*SD_MMC_BLOCK_count*/)) { printf("[FAIL] init write flash \n\r"); return 1; } if (SD_MMC_OK != sd_mmc_start_write_blocks(buf_write+i*512, 1/*SD_MMC_BLOCK_count*/)) { printf("[FAIL] write flash \n\r"); return 1; } if (SD_MMC_OK != sd_mmc_wait_end_of_write_blocks(false)) { printf("[FAIL] wait write flash \n\r"); return 1; } } return 0; } /** * \brief Card R/W tests * * \param slot SD/MMC slot to test */ static void main_test_memory(uint8_t slot) { for (uint32_t i=1; i<100; i++) { for (uint32_t j = 0; j < (8192/4 ); j+=4) { write_buf_pack_1[j] = 0x55; write_buf_pack_1[j+1] = 0xBB; write_buf_pack_1[j+2] = 0xAA; write_buf_pack_1[j+3] = 0xEE; if (j%512==0) { uint8_t tmp1 = j/128 + 1; write_buf_pack_1[j] = tmp1; write_buf_pack_1[j+1] = 0x0; write_buf_pack_1[j+2] = 0x0; write_buf_pack_1[j+3] = 0x0; } } write_fram_file(40, i, write_buf_pack_1); for (uint32_t k = 0; k < (8192); k++) { write_buf_pack_1[k] = 0x00000000; } } for (uint32_t i=1; i<100; i++) { read_fram_file(40, i, write_buf_pack_2); //здесь write_buf_pack_2 совпадает с write_buf_pack_1 только первыми 512 байтами for (uint32_t k = 0; k < (8192); k++) { write_buf_pack_2[k] = 0x00000000; } } } SD_MMC_EXAMPLE777777.rar Цитата Поделиться сообщением Ссылка на сообщение Поделиться на другие сайты Поделиться