diff --git a/src/common/exec.c b/src/common/exec.c index 8487b510..685b1df1 100644 --- a/src/common/exec.c +++ b/src/common/exec.c @@ -213,6 +213,7 @@ static struct cmd_map { { T_WIEGAND, cmd_mode_init }, { T_LIN, cmd_mode_init }, { T_SMARTCARD, cmd_mode_init }, + { T_MMC, cmd_mode_init }, { 0, NULL } }; diff --git a/src/drv/stm32cube/stm32cube.mk b/src/drv/stm32cube/stm32cube.mk index 6e8d6d8c..5a2f014b 100644 --- a/src/drv/stm32cube/stm32cube.mk +++ b/src/drv/stm32cube/stm32cube.mk @@ -14,6 +14,7 @@ STM32CUBESRC = ./drv/stm32cube/bsp.c \ ./drv/stm32cube/bsp_freq.c \ ./drv/stm32cube/bsp_trigger.c \ ./drv/stm32cube/bsp_tim.c \ + ./drv/stm32cube/bsp_mmc.c \ ./drv/stm32cube/bsp_fault_handler.c \ ./drv/stm32cube/bsp_print_dbg.c diff --git a/src/drv/stm32cube/stm32f4xx_hal.mk b/src/drv/stm32cube/stm32f4xx_hal.mk index 1f348fbb..54dea148 100644 --- a/src/drv/stm32cube/stm32f4xx_hal.mk +++ b/src/drv/stm32cube/stm32f4xx_hal.mk @@ -9,7 +9,9 @@ STM32F4XX_HAL_SRC = ./drv/stm32cube/stm32f4xx_hal/stm32f4xx_hal_msp.c \ ./drv/stm32cube/stm32f4xx_hal/src/stm32f4xx_hal_tim.c \ ./drv/stm32cube/stm32f4xx_hal/src/stm32f4xx_hal_tim_ex.c \ ./drv/stm32cube/stm32f4xx_hal/src/stm32f4xx_hal_can.c \ - ./drv/stm32cube/stm32f4xx_hal/src/stm32f4xx_hal_smartcard.c + ./drv/stm32cube/stm32f4xx_hal/src/stm32f4xx_hal_smartcard.c \ + ./drv/stm32cube/stm32f4xx_hal/src/stm32f4xx_hal_mmc.c \ + ./drv/stm32cube/stm32f4xx_hal/src/stm32f4xx_ll_sdmmc.c # Required include directories STM32F4XX_HAL_INC = ./drv/stm32cube \ diff --git a/src/drv/stm32cube/stm32f4xx_hal/src/stm32f4xx_ll_sdmmc.c b/src/drv/stm32cube/stm32f4xx_hal/src/stm32f4xx_ll_sdmmc.c index aac64928..7a50e0a1 100644 --- a/src/drv/stm32cube/stm32f4xx_hal/src/stm32f4xx_ll_sdmmc.c +++ b/src/drv/stm32cube/stm32f4xx_hal/src/stm32f4xx_ll_sdmmc.c @@ -158,6 +158,8 @@ /* Includes ------------------------------------------------------------------*/ #include "stm32f4xx_hal.h" +extern void DelayMs(uint32_t delay_ms); + #if defined(SDIO) /** @addtogroup STM32F4xx_HAL_Driver @@ -313,7 +315,8 @@ HAL_StatusTypeDef SDIO_PowerState_ON(SDIO_TypeDef *SDIOx) /* 1ms: required power up waiting time before starting the SD initialization sequence */ - HAL_Delay(2); + //HAL_Delay(2); + DelayMs(2); return HAL_OK; } diff --git a/src/drv/stm32cube/stm32f4xx_hal/stm32f4xx_hal_conf.h b/src/drv/stm32cube/stm32f4xx_hal/stm32f4xx_hal_conf.h index c15cf015..e3198736 100644 --- a/src/drv/stm32cube/stm32f4xx_hal/stm32f4xx_hal_conf.h +++ b/src/drv/stm32cube/stm32f4xx_hal/stm32f4xx_hal_conf.h @@ -82,7 +82,7 @@ /* #define HAL_SPDIFRX_MODULE_ENABLED */ /* #define HAL_DFSDM_MODULE_ENABLED */ /* #define HAL_LPTIM_MODULE_ENABLED */ -/* #define HAL_MMC_MODULE_ENABLED */ +#define HAL_MMC_MODULE_ENABLED /* ########################## HSE/HSI Values adaptation ##################### */ /** diff --git a/src/hydrabus/commands.c b/src/hydrabus/commands.c index 5f8181e7..cbffa7b5 100644 --- a/src/hydrabus/commands.c +++ b/src/hydrabus/commands.c @@ -161,6 +161,7 @@ const t_token_dict tl_dict[] = { { T_PRESCALER, "prescaler" }, { T_CONVENTION, "convention" }, { T_DELAY, "delay" }, + { T_MMC, "mmc" }, /* Developer warning add new command(s) here */ /* BP-compatible commands */ @@ -1667,6 +1668,29 @@ t_token tokens_flash[] = { { } }; +t_token tokens_mode_mmc[] = { + { + T_SHOW, + .subtokens = tokens_mode_show, + .help = "Show mmc parameters" + }, + /* mmc-specific commands */ + { + T_ID, + .help = "Displays the CID and CSD registers" + }, + /* BP commands */ + { + T_EXIT, + .help = "Exit mmc mode" + }, + { } +}; + +t_token tokens_mmc[] = { + { } +}; + t_token tokens_gpio_mode[] = { { T_IN, @@ -2160,6 +2184,11 @@ t_token tl_tokens[] = { .subtokens = tokens_flash, .help = "NAND flash mode" }, + { + T_MMC, + .subtokens = tokens_mmc, + .help = "MMC/eMMC mode" + }, { T_WIEGAND, .subtokens = tokens_wiegand, diff --git a/src/hydrabus/commands.h b/src/hydrabus/commands.h index afe01e01..80589ad0 100644 --- a/src/hydrabus/commands.h +++ b/src/hydrabus/commands.h @@ -153,6 +153,7 @@ enum { T_PRESCALER, T_CONVENTION, T_DELAY, + T_MMC, /* Developer warning add new command(s) here */ /* BP-compatible commands */ diff --git a/src/hydrabus/hydrabus.c b/src/hydrabus/hydrabus.c index ec33f73f..0e86c80d 100644 --- a/src/hydrabus/hydrabus.c +++ b/src/hydrabus/hydrabus.c @@ -33,7 +33,7 @@ static uint8_t sd_scratchpad[512]; /* * SDIO configuration. */ -static const SDCConfig sdccfg = { +const SDCConfig sdccfg = { sd_scratchpad, SDC_MODE_4BIT }; diff --git a/src/hydrabus/hydrabus.mk b/src/hydrabus/hydrabus.mk index 8e9f2cd4..7a6a980a 100644 --- a/src/hydrabus/hydrabus.mk +++ b/src/hydrabus/hydrabus.mk @@ -37,7 +37,9 @@ HYDRABUSSRC = hydrabus/hydrabus.c \ hydrabus/hydrabus_mode_lin.c \ hydrabus/hydrabus_bbio_aux.c \ hydrabus/hydrabus_aux.c \ - hydrabus/hydrabus_serprog.c + hydrabus/hydrabus_serprog.c \ + hydrabus/hydrabus_mode_mmc.c \ + hydrabus/hydrabus_bbio_mmc.c # Required include directories HYDRABUSINC = ./hydrabus diff --git a/src/hydrabus/hydrabus_bbio.c b/src/hydrabus/hydrabus_bbio.c index a8ea701d..e8cafcc2 100644 --- a/src/hydrabus/hydrabus_bbio.c +++ b/src/hydrabus/hydrabus_bbio.c @@ -37,6 +37,7 @@ #include "hydrabus_bbio_adc.h" #include "hydrabus_bbio_freq.h" #include "hydrabus_bbio_aux.h" +#include "hydrabus_bbio_mmc.h" #ifdef HYDRANFC #include "hydranfc_bbio_reader.h" #endif @@ -93,6 +94,9 @@ int cmd_bbio(t_hydra_console *con) bbio_mode_hydranfc_reader(con); break; #endif + case BBIO_MMC: + bbio_mode_mmc(con); + break; case BBIO_RESET_HW: /* Needed for flashrom detection */ cprint(con, "Hydrabus\r\n", 10); diff --git a/src/hydrabus/hydrabus_bbio.h b/src/hydrabus/hydrabus_bbio.h index b4c15312..d755f352 100644 --- a/src/hydrabus/hydrabus_bbio.h +++ b/src/hydrabus/hydrabus_bbio.h @@ -40,6 +40,7 @@ #define BBIO_FLASH 0b00001010 #define BBIO_SMARTCARD 0b00001011 #define BBIO_NFC_READER 0b00001100 +#define BBIO_MMC 0b00001101 #define BBIO_RESET_HW 0b00001111 #define BBIO_PWM 0b00010010 @@ -192,4 +193,12 @@ #define BBIO_NFC_SET_MODE_ISO_14443A 0b00000110 #define BBIO_NFC_SET_MODE_ISO_15693 0b00000111 +/* + * MMC-specific commands + */ +#define BBIO_MMC_CID 0b00000010 +#define BBIO_MMC_CSD 0b00000011 +#define BBIO_MMC_READ_PAGE 0b00000100 +#define BBIO_MMC_WRITE_PAGE 0b00000101 + int cmd_bbio(t_hydra_console *con); diff --git a/src/hydrabus/hydrabus_mode.c b/src/hydrabus/hydrabus_mode.c index 7b0ca369..644ca120 100644 --- a/src/hydrabus/hydrabus_mode.c +++ b/src/hydrabus/hydrabus_mode.c @@ -52,6 +52,7 @@ extern const mode_exec_t mode_flash_exec; extern const mode_exec_t mode_wiegand_exec; extern const mode_exec_t mode_lin_exec; extern const mode_exec_t mode_smartcard_exec; +extern const mode_exec_t mode_mmc_exec; extern t_token tokens_mode_spi[]; extern t_token tokens_mode_i2c[]; extern t_token tokens_mode_uart[]; @@ -67,6 +68,7 @@ extern t_token tokens_mode_flash[]; extern t_token tokens_mode_wiegand[]; extern t_token tokens_mode_lin[]; extern t_token tokens_mode_smartcard[]; +extern t_token tokens_mode_mmc[]; static struct { int token; @@ -88,6 +90,7 @@ static struct { { T_WIEGAND, tokens_mode_wiegand, &mode_wiegand_exec }, { T_LIN, tokens_mode_lin, &mode_lin_exec }, { T_SMARTCARD, tokens_mode_smartcard, &mode_smartcard_exec }, + { T_MMC, tokens_mode_mmc, &mode_mmc_exec }, }; const char hydrabus_mode_str_cs_enabled[] = "/CS ENABLED\r\n";