mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Use MicroPython's SD Card Module.
This commit is contained in:
parent
8e503f4145
commit
ba73787c8a
11
src/Makefile
11
src/Makefile
@ -125,16 +125,6 @@ FIRM_OBJ += $(addprefix $(BUILD)/$(OMV_DIR)/, \
|
||||
mutex.o \
|
||||
)
|
||||
|
||||
ifeq ($(TARGET), OPENMV1)
|
||||
FIRM_OBJ += $(addprefix $(BUILD)/$(OMV_DIR)/, \
|
||||
sdcard_spi.o \
|
||||
)
|
||||
else
|
||||
FIRM_OBJ += $(addprefix $(BUILD)/$(OMV_DIR)/, \
|
||||
sdcard_sdio.o \
|
||||
)
|
||||
endif
|
||||
|
||||
FIRM_OBJ += $(addprefix $(BUILD)/$(OMV_DIR)/img/,\
|
||||
blob.o \
|
||||
fmath.o \
|
||||
@ -235,6 +225,7 @@ FIRM_OBJ += $(addprefix $(BUILD)/$(MICROPY_DIR)/,\
|
||||
rng.o \
|
||||
led.o \
|
||||
mphalport.o \
|
||||
sdcard.o \
|
||||
fatfs_port.o \
|
||||
builtin_open.o \
|
||||
extint.o \
|
||||
|
||||
@ -1 +1 @@
|
||||
Subproject commit 6a0c5ee924cc46a041a2b308031c994113489453
|
||||
Subproject commit 8a1d816be1f85feba4362fac87f421cd340a9f57
|
||||
@ -16,16 +16,6 @@ SRCS += $(addprefix , \
|
||||
mutex.c \
|
||||
)
|
||||
|
||||
ifeq ($(TARGET), OPENMV1)
|
||||
SRCS += $(addprefix , \
|
||||
sdcard_spi.c \
|
||||
)
|
||||
else
|
||||
SRCS += $(addprefix , \
|
||||
sdcard_sdio.c \
|
||||
)
|
||||
endif
|
||||
|
||||
SRCS += $(addprefix img/, \
|
||||
blob.c \
|
||||
fmath.c \
|
||||
|
||||
@ -96,8 +96,4 @@
|
||||
|
||||
#define DCMI_FSIN_LOW() HAL_GPIO_WritePin(DCMI_FSIN_PORT, DCMI_FSIN_PIN, GPIO_PIN_RESET)
|
||||
#define DCMI_FSIN_HIGH() HAL_GPIO_WritePin(DCMI_FSIN_PORT, DCMI_FSIN_PIN, GPIO_PIN_SET)
|
||||
|
||||
#define SD_CD_PIN (GPIO_PIN_15)
|
||||
#define SD_CD_PORT (GPIOA)
|
||||
|
||||
#endif //__OMV_BOARDCONFIG_H__
|
||||
|
||||
@ -365,10 +365,10 @@ soft_reset:
|
||||
vfs->str = "1:";
|
||||
vfs->len = 2;
|
||||
vfs->flags = 0;
|
||||
//sdcard_init_vfs(vfs);
|
||||
sdcard_init_vfs(vfs);
|
||||
|
||||
// put the sdcard device in slot 0 (it will be unused at this point)
|
||||
MP_STATE_PORT(fs_user_mount)[0] = vfs;
|
||||
// put the sdcard device in slot 1 (it will be unused at this point)
|
||||
MP_STATE_PORT(fs_user_mount)[1] = vfs;
|
||||
|
||||
// try to mount the flash
|
||||
FRESULT res = f_mount(&vfs->fatfs, vfs->str, 1);
|
||||
|
||||
@ -56,7 +56,7 @@ void HAL_MspInit(void)
|
||||
/* Enable DMA clocks */
|
||||
__DMA2_CLK_ENABLE();
|
||||
|
||||
/* Conigure DCMI GPIO */
|
||||
/* Configure DCMI GPIO */
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
GPIO_InitStructure.Pull = GPIO_PULLDOWN;
|
||||
GPIO_InitStructure.Speed = GPIO_SPEED_LOW;
|
||||
@ -70,13 +70,6 @@ void HAL_MspInit(void)
|
||||
|
||||
GPIO_InitStructure.Pin = DCMI_FSIN_PIN;
|
||||
HAL_GPIO_Init(DCMI_FSIN_PORT, &GPIO_InitStructure);
|
||||
|
||||
/* Configure SD CD PIN */
|
||||
GPIO_InitStructure.Pin = SD_CD_PIN;
|
||||
GPIO_InitStructure.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStructure.Speed = GPIO_SPEED_LOW;
|
||||
GPIO_InitStructure.Mode = GPIO_MODE_INPUT;
|
||||
HAL_GPIO_Init(SD_CD_PORT, &GPIO_InitStructure);
|
||||
}
|
||||
|
||||
void HAL_I2C_MspInit(I2C_HandleTypeDef *hi2c)
|
||||
@ -142,68 +135,6 @@ void HAL_DCMI_MspInit(DCMI_HandleTypeDef* hdcmi)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef OPENMV1
|
||||
void HAL_SPI_MspInit(SPI_HandleTypeDef *hspi)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
if (hspi->Instance == SD_SPI) {
|
||||
/* Enable clock */
|
||||
SD_SPI_CLK_ENABLE();
|
||||
|
||||
/* Configure SPI GPIOs */
|
||||
GPIO_InitStructure.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStructure.Speed = GPIO_SPEED_MEDIUM;
|
||||
GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStructure.Alternate = SD_SPI_AF;
|
||||
|
||||
GPIO_InitStructure.Pin = SD_MOSI_PIN;
|
||||
HAL_GPIO_Init(SD_MOSI_PORT, &GPIO_InitStructure);
|
||||
|
||||
GPIO_InitStructure.Pin = SD_MISO_PIN;
|
||||
HAL_GPIO_Init(SD_MISO_PORT, &GPIO_InitStructure);
|
||||
|
||||
GPIO_InitStructure.Pin = SD_SCLK_PIN;
|
||||
HAL_GPIO_Init(SD_SCLK_PORT, &GPIO_InitStructure);
|
||||
|
||||
GPIO_InitStructure.Pin = SD_CS_PIN;
|
||||
GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
HAL_GPIO_Init(SD_CS_PORT, &GPIO_InitStructure);
|
||||
|
||||
/* De-select the Card: Chip Select high */
|
||||
SD_DESELECT();
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef OPENMV2
|
||||
void HAL_SD_MspInit(SD_HandleTypeDef *hsd)
|
||||
{
|
||||
/* Enable SDIO clock */
|
||||
__SDIO_CLK_ENABLE();
|
||||
|
||||
/* SDIO GPIOs configuration */
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
GPIO_InitStructure.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStructure.Speed = GPIO_SPEED_MEDIUM;
|
||||
GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStructure.Alternate = GPIO_AF12_SDIO;
|
||||
|
||||
/* SDIO_D0..D3, SDIO_CLK */
|
||||
GPIO_InitStructure.Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12;
|
||||
HAL_GPIO_Init(GPIOC, &GPIO_InitStructure);
|
||||
|
||||
/* SDIO_CMD */
|
||||
GPIO_InitStructure.Pin = GPIO_PIN_2;
|
||||
HAL_GPIO_Init(GPIOD, &GPIO_InitStructure);
|
||||
}
|
||||
|
||||
void HAL_SD_MspDeInit(SD_HandleTypeDef *hsd)
|
||||
{
|
||||
__SDIO_CLK_DISABLE();
|
||||
}
|
||||
#endif //OPENMV2
|
||||
|
||||
void HAL_MspDeInit(void)
|
||||
{
|
||||
|
||||
|
||||
@ -630,8 +630,9 @@ void HAL_SD_MspDeInit(SD_HandleTypeDef *hsd);
|
||||
* @{
|
||||
*/
|
||||
/* Blocking mode: Polling */
|
||||
HAL_SD_ErrorTypedef HAL_SD_ReadBlocks(SD_HandleTypeDef *hsd, uint32_t *pReadBuffer, uint64_t ReadAddr, uint32_t BlockSize, uint32_t NumberOfBlocks);
|
||||
HAL_SD_ErrorTypedef HAL_SD_WriteBlocks(SD_HandleTypeDef *hsd, uint32_t *pWriteBuffer, uint64_t WriteAddr, uint32_t BlockSize, uint32_t NumberOfBlocks);
|
||||
// dpgeorge: read/write functions renamed to emphasise that address is given by block number
|
||||
HAL_SD_ErrorTypedef HAL_SD_ReadBlocks_BlockNumber(SD_HandleTypeDef *hsd, uint32_t *pReadBuffer, uint32_t BlockNumber, uint32_t BlockSize, uint32_t NumberOfBlocks);
|
||||
HAL_SD_ErrorTypedef HAL_SD_WriteBlocks_BlockNumber(SD_HandleTypeDef *hsd, uint32_t *pWriteBuffer, uint32_t BlockNumber, uint32_t BlockSize, uint32_t NumberOfBlocks);
|
||||
HAL_SD_ErrorTypedef HAL_SD_Erase(SD_HandleTypeDef *hsd, uint64_t startaddr, uint64_t endaddr);
|
||||
|
||||
/* Non-Blocking mode: Interrupt */
|
||||
@ -646,8 +647,9 @@ void HAL_SD_XferCpltCallback(SD_HandleTypeDef *hsd);
|
||||
void HAL_SD_XferErrorCallback(SD_HandleTypeDef *hsd);
|
||||
|
||||
/* Non-Blocking mode: DMA */
|
||||
HAL_SD_ErrorTypedef HAL_SD_ReadBlocks_DMA(SD_HandleTypeDef *hsd, uint32_t *pReadBuffer, uint64_t ReadAddr, uint32_t BlockSize, uint32_t NumberOfBlocks);
|
||||
HAL_SD_ErrorTypedef HAL_SD_WriteBlocks_DMA(SD_HandleTypeDef *hsd, uint32_t *pWriteBuffer, uint64_t WriteAddr, uint32_t BlockSize, uint32_t NumberOfBlocks);
|
||||
// dpgeorge: read/write functions renamed to emphasise that address is given by block number
|
||||
HAL_SD_ErrorTypedef HAL_SD_ReadBlocks_BlockNumber_DMA(SD_HandleTypeDef *hsd, uint32_t *pReadBuffer, uint32_t BlockNumber, uint32_t BlockSize, uint32_t NumberOfBlocks);
|
||||
HAL_SD_ErrorTypedef HAL_SD_WriteBlocks_BlockNumber_DMA(SD_HandleTypeDef *hsd, uint32_t *pWriteBuffer, uint32_t BlockNumber, uint32_t BlockSize, uint32_t NumberOfBlocks);
|
||||
HAL_SD_ErrorTypedef HAL_SD_CheckWriteOperation(SD_HandleTypeDef *hsd, uint32_t Timeout);
|
||||
HAL_SD_ErrorTypedef HAL_SD_CheckReadOperation(SD_HandleTypeDef *hsd, uint32_t Timeout);
|
||||
/**
|
||||
|
||||
@ -449,13 +449,13 @@ __weak void HAL_SD_MspDeInit(SD_HandleTypeDef *hsd)
|
||||
* is managed by polling mode.
|
||||
* @param hsd: SD handle
|
||||
* @param pReadBuffer: pointer to the buffer that will contain the received data
|
||||
* @param ReadAddr: Address from where data is to be read
|
||||
* @param BlockNumber: Block number from where data is to be read (byte address = BlockNumber * BlockSize)
|
||||
* @param BlockSize: SD card Data block size
|
||||
* This parameter should be 512
|
||||
* @param NumberOfBlocks: Number of SD blocks to read
|
||||
* @retval SD Card error state
|
||||
*/
|
||||
HAL_SD_ErrorTypedef HAL_SD_ReadBlocks(SD_HandleTypeDef *hsd, uint32_t *pReadBuffer, uint64_t ReadAddr, uint32_t BlockSize, uint32_t NumberOfBlocks)
|
||||
HAL_SD_ErrorTypedef HAL_SD_ReadBlocks_BlockNumber(SD_HandleTypeDef *hsd, uint32_t *pReadBuffer, uint32_t BlockNumber, uint32_t BlockSize, uint32_t NumberOfBlocks)
|
||||
{
|
||||
SDIO_CmdInitTypeDef sdio_cmdinitstructure;
|
||||
SDIO_DataInitTypeDef sdio_datainitstructure;
|
||||
@ -465,10 +465,16 @@ HAL_SD_ErrorTypedef HAL_SD_ReadBlocks(SD_HandleTypeDef *hsd, uint32_t *pReadBuff
|
||||
/* Initialize data control register */
|
||||
hsd->Instance->DCTRL = 0;
|
||||
|
||||
uint32_t ReadAddr;
|
||||
if (hsd->CardType == HIGH_CAPACITY_SD_CARD)
|
||||
{
|
||||
BlockSize = 512;
|
||||
ReadAddr /= 512;
|
||||
ReadAddr = BlockNumber;
|
||||
}
|
||||
else
|
||||
{
|
||||
// should not overflow for standard-capacity cards
|
||||
ReadAddr = BlockNumber * BlockSize;
|
||||
}
|
||||
|
||||
/* Set Block Size for Card */
|
||||
@ -507,7 +513,7 @@ HAL_SD_ErrorTypedef HAL_SD_ReadBlocks(SD_HandleTypeDef *hsd, uint32_t *pReadBuff
|
||||
sdio_cmdinitstructure.CmdIndex = SD_CMD_READ_SINGLE_BLOCK;
|
||||
}
|
||||
|
||||
sdio_cmdinitstructure.Argument = (uint32_t)ReadAddr;
|
||||
sdio_cmdinitstructure.Argument = ReadAddr;
|
||||
SDIO_SendCommand(hsd->Instance, &sdio_cmdinitstructure);
|
||||
|
||||
/* Read block(s) in polling mode */
|
||||
@ -633,13 +639,13 @@ HAL_SD_ErrorTypedef HAL_SD_ReadBlocks(SD_HandleTypeDef *hsd, uint32_t *pReadBuff
|
||||
* transfer is managed by polling mode.
|
||||
* @param hsd: SD handle
|
||||
* @param pWriteBuffer: pointer to the buffer that will contain the data to transmit
|
||||
* @param WriteAddr: Address from where data is to be written
|
||||
* @param BlockNumber: Block number to where data is to be written (byte address = BlockNumber * BlockSize)
|
||||
* @param BlockSize: SD card Data block size
|
||||
* This parameter should be 512.
|
||||
* @param NumberOfBlocks: Number of SD blocks to write
|
||||
* @retval SD Card error state
|
||||
*/
|
||||
HAL_SD_ErrorTypedef HAL_SD_WriteBlocks(SD_HandleTypeDef *hsd, uint32_t *pWriteBuffer, uint64_t WriteAddr, uint32_t BlockSize, uint32_t NumberOfBlocks)
|
||||
HAL_SD_ErrorTypedef HAL_SD_WriteBlocks_BlockNumber(SD_HandleTypeDef *hsd, uint32_t *pWriteBuffer, uint32_t BlockNumber, uint32_t BlockSize, uint32_t NumberOfBlocks)
|
||||
{
|
||||
SDIO_CmdInitTypeDef sdio_cmdinitstructure;
|
||||
SDIO_DataInitTypeDef sdio_datainitstructure;
|
||||
@ -651,10 +657,16 @@ HAL_SD_ErrorTypedef HAL_SD_WriteBlocks(SD_HandleTypeDef *hsd, uint32_t *pWriteBu
|
||||
/* Initialize data control register */
|
||||
hsd->Instance->DCTRL = 0;
|
||||
|
||||
uint32_t WriteAddr;
|
||||
if (hsd->CardType == HIGH_CAPACITY_SD_CARD)
|
||||
{
|
||||
BlockSize = 512;
|
||||
WriteAddr /= 512;
|
||||
WriteAddr = BlockNumber;
|
||||
}
|
||||
else
|
||||
{
|
||||
// should not overflow for standard-capacity cards
|
||||
WriteAddr = BlockNumber * BlockSize;
|
||||
}
|
||||
|
||||
/* Set Block Size for Card */
|
||||
@ -684,7 +696,7 @@ HAL_SD_ErrorTypedef HAL_SD_WriteBlocks(SD_HandleTypeDef *hsd, uint32_t *pWriteBu
|
||||
sdio_cmdinitstructure.CmdIndex = SD_CMD_WRITE_SINGLE_BLOCK;
|
||||
}
|
||||
|
||||
sdio_cmdinitstructure.Argument = (uint32_t)WriteAddr;
|
||||
sdio_cmdinitstructure.Argument = WriteAddr;
|
||||
SDIO_SendCommand(hsd->Instance, &sdio_cmdinitstructure);
|
||||
|
||||
/* Check for error conditions */
|
||||
@ -851,13 +863,13 @@ HAL_SD_ErrorTypedef HAL_SD_WriteBlocks(SD_HandleTypeDef *hsd, uint32_t *pWriteBu
|
||||
* to check the completion of the read process
|
||||
* @param hsd: SD handle
|
||||
* @param pReadBuffer: Pointer to the buffer that will contain the received data
|
||||
* @param ReadAddr: Address from where data is to be read
|
||||
* @param BlockNumber: Block number from where data is to be read (byte address = BlockNumber * BlockSize)
|
||||
* @param BlockSize: SD card Data block size
|
||||
* This paramater should be 512.
|
||||
* @param NumberOfBlocks: Number of blocks to read.
|
||||
* @retval SD Card error state
|
||||
*/
|
||||
HAL_SD_ErrorTypedef HAL_SD_ReadBlocks_DMA(SD_HandleTypeDef *hsd, uint32_t *pReadBuffer, uint64_t ReadAddr, uint32_t BlockSize, uint32_t NumberOfBlocks)
|
||||
HAL_SD_ErrorTypedef HAL_SD_ReadBlocks_BlockNumber_DMA(SD_HandleTypeDef *hsd, uint32_t *pReadBuffer, uint32_t BlockNumber, uint32_t BlockSize, uint32_t NumberOfBlocks)
|
||||
{
|
||||
SDIO_CmdInitTypeDef sdio_cmdinitstructure;
|
||||
SDIO_DataInitTypeDef sdio_datainitstructure;
|
||||
@ -898,10 +910,16 @@ HAL_SD_ErrorTypedef HAL_SD_ReadBlocks_DMA(SD_HandleTypeDef *hsd, uint32_t *pRead
|
||||
/* Enable the DMA Stream */
|
||||
HAL_DMA_Start_IT(hsd->hdmarx, (uint32_t)&hsd->Instance->FIFO, (uint32_t)pReadBuffer, (uint32_t)(BlockSize * NumberOfBlocks));
|
||||
|
||||
uint32_t ReadAddr;
|
||||
if (hsd->CardType == HIGH_CAPACITY_SD_CARD)
|
||||
{
|
||||
BlockSize = 512;
|
||||
ReadAddr /= 512;
|
||||
ReadAddr = BlockNumber;
|
||||
}
|
||||
else
|
||||
{
|
||||
// should not overflow for standard-capacity cards
|
||||
ReadAddr = BlockNumber * BlockSize;
|
||||
}
|
||||
|
||||
/* Set Block Size for Card */
|
||||
@ -941,7 +959,7 @@ HAL_SD_ErrorTypedef HAL_SD_ReadBlocks_DMA(SD_HandleTypeDef *hsd, uint32_t *pRead
|
||||
sdio_cmdinitstructure.CmdIndex = SD_CMD_READ_SINGLE_BLOCK;
|
||||
}
|
||||
|
||||
sdio_cmdinitstructure.Argument = (uint32_t)ReadAddr;
|
||||
sdio_cmdinitstructure.Argument = ReadAddr;
|
||||
SDIO_SendCommand(hsd->Instance, &sdio_cmdinitstructure);
|
||||
|
||||
/* Check for error conditions */
|
||||
@ -968,13 +986,13 @@ HAL_SD_ErrorTypedef HAL_SD_ReadBlocks_DMA(SD_HandleTypeDef *hsd, uint32_t *pRead
|
||||
* to check the completion of the write process (by SD current status polling).
|
||||
* @param hsd: SD handle
|
||||
* @param pWriteBuffer: pointer to the buffer that will contain the data to transmit
|
||||
* @param WriteAddr: Address from where data is to be read
|
||||
* @param BlockNumber: Block number to where data is to be written (byte address = BlockNumber * BlockSize)
|
||||
* @param BlockSize: the SD card Data block size
|
||||
* This parameter should be 512.
|
||||
* @param NumberOfBlocks: Number of blocks to write
|
||||
* @retval SD Card error state
|
||||
*/
|
||||
HAL_SD_ErrorTypedef HAL_SD_WriteBlocks_DMA(SD_HandleTypeDef *hsd, uint32_t *pWriteBuffer, uint64_t WriteAddr, uint32_t BlockSize, uint32_t NumberOfBlocks)
|
||||
HAL_SD_ErrorTypedef HAL_SD_WriteBlocks_BlockNumber_DMA(SD_HandleTypeDef *hsd, uint32_t *pWriteBuffer, uint32_t BlockNumber, uint32_t BlockSize, uint32_t NumberOfBlocks)
|
||||
{
|
||||
SDIO_CmdInitTypeDef sdio_cmdinitstructure;
|
||||
SDIO_DataInitTypeDef sdio_datainitstructure;
|
||||
@ -1015,10 +1033,16 @@ HAL_SD_ErrorTypedef HAL_SD_WriteBlocks_DMA(SD_HandleTypeDef *hsd, uint32_t *pWri
|
||||
/* Enable SDIO DMA transfer */
|
||||
__HAL_SD_SDIO_DMA_ENABLE();
|
||||
|
||||
uint32_t WriteAddr;
|
||||
if (hsd->CardType == HIGH_CAPACITY_SD_CARD)
|
||||
{
|
||||
BlockSize = 512;
|
||||
WriteAddr /= 512;
|
||||
WriteAddr = BlockNumber;
|
||||
}
|
||||
else
|
||||
{
|
||||
// should not overflow for standard-capacity cards
|
||||
WriteAddr = BlockNumber * BlockSize;
|
||||
}
|
||||
|
||||
/* Set Block Size for Card */
|
||||
@ -1049,7 +1073,7 @@ HAL_SD_ErrorTypedef HAL_SD_WriteBlocks_DMA(SD_HandleTypeDef *hsd, uint32_t *pWri
|
||||
sdio_cmdinitstructure.CmdIndex = SD_CMD_WRITE_MULT_BLOCK;
|
||||
}
|
||||
|
||||
sdio_cmdinitstructure.Argument = (uint32_t)WriteAddr;
|
||||
sdio_cmdinitstructure.Argument = WriteAddr;
|
||||
SDIO_SendCommand(hsd->Instance, &sdio_cmdinitstructure);
|
||||
|
||||
/* Check for error conditions */
|
||||
@ -1578,7 +1602,7 @@ HAL_SD_ErrorTypedef HAL_SD_Get_CardInfo(SD_HandleTypeDef *hsd, HAL_SD_CardInfoTy
|
||||
/* Byte 10 */
|
||||
tmp = (uint8_t)((hsd->CSD[2] & 0x0000FF00) >> 8);
|
||||
|
||||
pCardInfo->CardCapacity = ((pCardInfo->SD_csd.DeviceSize + 1)) * 512 * 1024;
|
||||
pCardInfo->CardCapacity = ((pCardInfo->SD_csd.DeviceSize + 1ULL)) * 512 * 1024;
|
||||
pCardInfo->CardBlockSize = 512;
|
||||
}
|
||||
else
|
||||
|
||||
Loading…
Reference in New Issue
Block a user