Skip to content

Commit

Permalink
Initial MMC support
Browse files Browse the repository at this point in the history
This adds MMC/eMMC interaction. It currently supports 1-bit data bus
width and can be used using BBIO.
  • Loading branch information
Baldanos committed Dec 6, 2020
1 parent 7df0995 commit 532e4ed
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/common/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
};

Expand Down
1 change: 1 addition & 0 deletions src/drv/stm32cube/stm32cube.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion src/drv/stm32cube/stm32f4xx_hal.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
5 changes: 4 additions & 1 deletion src/drv/stm32cube/stm32f4xx_hal/src/stm32f4xx_ll_sdmmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@
/* Includes ------------------------------------------------------------------*/
#include "stm32f4xx_hal.h"

extern void DelayMs(uint32_t delay_ms);

#if defined(SDIO)

/** @addtogroup STM32F4xx_HAL_Driver
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/drv/stm32cube/stm32f4xx_hal/stm32f4xx_hal_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 ##################### */
/**
Expand Down
29 changes: 29 additions & 0 deletions src/hydrabus/commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/hydrabus/commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ enum {
T_PRESCALER,
T_CONVENTION,
T_DELAY,
T_MMC,
/* Developer warning add new command(s) here */

/* BP-compatible commands */
Expand Down
2 changes: 1 addition & 1 deletion src/hydrabus/hydrabus.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static uint8_t sd_scratchpad[512];
/*
* SDIO configuration.
*/
static const SDCConfig sdccfg = {
const SDCConfig sdccfg = {
sd_scratchpad,
SDC_MODE_4BIT
};
Expand Down
4 changes: 3 additions & 1 deletion src/hydrabus/hydrabus.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions src/hydrabus/hydrabus_bbio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions src/hydrabus/hydrabus_bbio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
3 changes: 3 additions & 0 deletions src/hydrabus/hydrabus_mode.c
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand All @@ -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;
Expand All @@ -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";
Expand Down

0 comments on commit 532e4ed

Please sign in to comment.