Stair56E UART project
This commit is contained in:
@@ -1,231 +1,254 @@
|
||||
/*!
|
||||
* \file diskio.c
|
||||
*
|
||||
* \brief Target disk I/O implementation
|
||||
*
|
||||
* \copyright Revised BSD License, see section \ref LICENSE.
|
||||
*
|
||||
* \code
|
||||
*
|
||||
* _ __ _ ________ _
|
||||
* | |/ /(_)___ / ____/ /_ (_)___
|
||||
* | // / __ \/ / / __ \/ / __ \
|
||||
* / |/ / / / / /___/ / / / / /_/ /
|
||||
* /_/|_/_/_/ /_/\____/_/ /_/_/ .___/
|
||||
* /_/
|
||||
* (C) 2022-2025 XinChip
|
||||
*
|
||||
* \endcode
|
||||
*
|
||||
* \author ( XinChip ) Alex-J
|
||||
*
|
||||
* \author ( XinChip )
|
||||
*/
|
||||
|
||||
/*-----------------------------------------------------------------------------------
|
||||
INCLUDE HEADE FILES
|
||||
------------------------------------------------------------------------------------*/
|
||||
#include "diskio.h"
|
||||
#include "ff_gen_drv.h"
|
||||
#include "msc_flash.h"
|
||||
|
||||
#include "time_conv.h"
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
Macros
|
||||
-------------------------------------------
|
||||
-----------------------------------------*/
|
||||
#if defined(__GNUC__)
|
||||
#ifndef __weak
|
||||
#define __weak __attribute__((weak))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define DEV_USB 0 /* Example: Map USB MSD to physical drive 0 */
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
Global Variables
|
||||
-------------------------------------------
|
||||
-----------------------------------------*/
|
||||
extern Disk_drvTypeDef disk;
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
Functions
|
||||
-------------------------------------------
|
||||
-----------------------------------------*/
|
||||
/**
|
||||
* @brief Gets Disk Status
|
||||
* @param pdrv: Physical drive number (0..)
|
||||
* @retval DSTATUS: Operation status
|
||||
*/
|
||||
DSTATUS disk_status(BYTE pdrv /* Physical drive number to identify the drive */
|
||||
)
|
||||
{
|
||||
DSTATUS stat = STA_NOINIT;
|
||||
|
||||
// stat = disk.drv[pdrv]->disk_status(disk.lun[pdrv]);
|
||||
if (FAT_FLASH_ID == Fat_Flash_ReadID()) {
|
||||
stat = RES_OK;
|
||||
} else {
|
||||
stat = STA_NOINIT;
|
||||
}
|
||||
|
||||
return stat;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initializes a Drive
|
||||
* @param pdrv: Physical drive number (0..)
|
||||
* @retval DSTATUS: Operation status
|
||||
*/
|
||||
DSTATUS
|
||||
disk_initialize(BYTE pdrv /* Physical drive nmuber to identify the drive */
|
||||
)
|
||||
{
|
||||
DSTATUS stat = STA_NOINIT;
|
||||
|
||||
switch (pdrv) {
|
||||
case DEV_USB: {
|
||||
if (true == Disk_Init())
|
||||
stat = RES_OK;
|
||||
} break;
|
||||
}
|
||||
|
||||
// if(disk.is_initialized[pdrv] == 0)
|
||||
// {
|
||||
// disk.is_initialized[pdrv] = 1;
|
||||
// stat = disk.drv[pdrv]->disk_initialize(disk.lun[pdrv]);
|
||||
// }
|
||||
return stat;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reads Sector(s)
|
||||
* @param pdrv: Physical drive number (0..)
|
||||
* @param *buff: Data buffer to store read data
|
||||
* @param sector: Sector address (LBA)
|
||||
* @param count: Number of sectors to read (1..128)
|
||||
* @retval DRESULT: Operation result
|
||||
*/
|
||||
DRESULT disk_read(BYTE pdrv, /* Physical drive nmuber to identify the drive */
|
||||
BYTE *buff, /* Data buffer to store read data */
|
||||
DWORD sector, /* Sector address in LBA */
|
||||
UINT count /* Number of sectors to read */
|
||||
)
|
||||
{
|
||||
DRESULT res = RES_ERROR;
|
||||
|
||||
switch (pdrv) {
|
||||
case DEV_USB: {
|
||||
if (Disk_UnitRead(sector, count, buff) == true) {
|
||||
res = RES_OK;
|
||||
}
|
||||
} break;
|
||||
}
|
||||
|
||||
// res = disk.drv[pdrv]->disk_read(disk.lun[pdrv], buff, sector, count);
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Writes Sector(s)
|
||||
* @param pdrv: Physical drive number (0..)
|
||||
* @param *buff: Data to be written
|
||||
* @param sector: Sector address (LBA)
|
||||
* @param count: Number of sectors to write (1..128)
|
||||
* @retval DRESULT: Operation result
|
||||
*/
|
||||
#if _USE_WRITE == 1
|
||||
DRESULT disk_write(BYTE pdrv, /* Physical drive nmuber to identify the drive */
|
||||
const BYTE *buff, /* Data to be written */
|
||||
DWORD sector, /* Sector address in LBA */
|
||||
UINT count /* Number of sectors to write */
|
||||
)
|
||||
{
|
||||
DRESULT res = RES_ERROR;
|
||||
|
||||
switch (pdrv) {
|
||||
case DEV_USB: {
|
||||
if (Disk_UnitWrite(sector, count, (uint8_t *)buff) == true) {
|
||||
res = RES_OK;
|
||||
}
|
||||
} break;
|
||||
}
|
||||
// res = disk.drv[pdrv]->disk_write(disk.lun[pdrv], buff, sector, count);
|
||||
return res;
|
||||
}
|
||||
#endif /* _USE_WRITE == 1 */
|
||||
|
||||
/**
|
||||
* @brief I/O control operation
|
||||
* @param pdrv: Physical drive number (0..)
|
||||
* @param cmd: Control code
|
||||
* @param *buff: Buffer to send/receive control data
|
||||
* @retval DRESULT: Operation result
|
||||
*/
|
||||
#if _USE_IOCTL == 1
|
||||
DRESULT disk_ioctl(BYTE pdrv, /* Physical drive nmuber (0..) */
|
||||
BYTE cmd, /* Control code */
|
||||
void *buff /* Buffer to send/receive control data */
|
||||
)
|
||||
{
|
||||
DRESULT res = RES_PARERR;
|
||||
|
||||
switch (pdrv) {
|
||||
case DEV_USB: {
|
||||
switch (cmd) {
|
||||
case CTRL_SYNC:
|
||||
res = RES_OK;
|
||||
break;
|
||||
|
||||
case GET_SECTOR_COUNT: {
|
||||
*(DWORD *)buff = Disk_UnitCount();
|
||||
res = RES_OK;
|
||||
break;
|
||||
}
|
||||
|
||||
case GET_SECTOR_SIZE: {
|
||||
*(DWORD *)buff = Disk_UnitSize();
|
||||
res = RES_OK;
|
||||
break;
|
||||
}
|
||||
|
||||
case GET_BLOCK_SIZE: {
|
||||
*(DWORD *)buff = 1;
|
||||
res = RES_OK;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
res = RES_PARERR;
|
||||
break;
|
||||
}
|
||||
} break;
|
||||
}
|
||||
|
||||
// res = disk.drv[pdrv]->disk_ioctl(disk.lun[pdrv], cmd, buff);
|
||||
return res;
|
||||
}
|
||||
#endif /* _USE_IOCTL == 1 */
|
||||
|
||||
/**
|
||||
* @brief Gets Time from RTC
|
||||
* @param None
|
||||
* @retval Time in DWORD
|
||||
*/
|
||||
__weak DWORD get_fattime(void)
|
||||
{
|
||||
uint32_t fattime;
|
||||
// utc sec convert to utc date
|
||||
DateTime_t tmp_date = UTC_SecToDate(Utc_TotalSec);
|
||||
tmp_date = UTC_DateToZoneDate(TIME_ZONE, YEAR_BASE, tmp_date.year,
|
||||
tmp_date.month, tmp_date.day, tmp_date.hour,
|
||||
tmp_date.min, tmp_date.sec, tmp_date.week);
|
||||
fattime = ((YEAR_BASE + tmp_date.year - 1980) << 25) |
|
||||
(tmp_date.month << 21) | (tmp_date.day << 16) |
|
||||
(tmp_date.hour << 11) | (tmp_date.min << 5) | (tmp_date.sec >> 1);
|
||||
|
||||
return fattime;
|
||||
}
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
/*!
|
||||
* \file diskio.c
|
||||
*
|
||||
* \brief Target disk I/O implementation
|
||||
*
|
||||
* \copyright Revised BSD License, see section \ref LICENSE.
|
||||
*
|
||||
* \code
|
||||
*
|
||||
* _ __ _ ________ _
|
||||
* | |/ /(_)___ / ____/ /_ (_)___
|
||||
* | // / __ \/ / / __ \/ / __ \
|
||||
* / |/ / / / / /___/ / / / / /_/ /
|
||||
* /_/|_/_/_/ /_/\____/_/ /_/_/ .___/
|
||||
* /_/
|
||||
* (C) 2022-2025 XinChip
|
||||
*
|
||||
* \endcode
|
||||
*
|
||||
* \author ( XinChip ) Alex-J
|
||||
*
|
||||
* \author ( XinChip )
|
||||
*/
|
||||
|
||||
/*-----------------------------------------------------------------------------------
|
||||
INCLUDE HEADE FILES
|
||||
------------------------------------------------------------------------------------*/
|
||||
#include "diskio.h"
|
||||
#include "ff_gen_drv.h"
|
||||
#include "usbd_msc_flash.h"
|
||||
|
||||
#include "time_conv.h"
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
Macros
|
||||
------------------------------------------- -----------------------------------------*/
|
||||
#if defined ( __GNUC__ )
|
||||
#ifndef __weak
|
||||
#define __weak __attribute__((weak))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define DEV_USB 0 /* Example: Map USB MSD to physical drive 0 */
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
Global Variables
|
||||
------------------------------------------- -----------------------------------------*/
|
||||
extern Disk_drvTypeDef disk;
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
Functions
|
||||
------------------------------------------- -----------------------------------------*/
|
||||
/**
|
||||
* @brief Gets Disk Status
|
||||
* @param pdrv: Physical drive number (0..)
|
||||
* @retval DSTATUS: Operation status
|
||||
*/
|
||||
DSTATUS disk_status (
|
||||
BYTE pdrv /* Physical drive number to identify the drive */
|
||||
)
|
||||
{
|
||||
DSTATUS stat = STA_NOINIT;
|
||||
|
||||
// stat = disk.drv[pdrv]->disk_status(disk.lun[pdrv]);
|
||||
if( FAT_FLASH_ID == Fat_Flash_ReadID( ) )
|
||||
{
|
||||
stat = RES_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
stat = STA_NOINIT;
|
||||
}
|
||||
|
||||
return stat;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initializes a Drive
|
||||
* @param pdrv: Physical drive number (0..)
|
||||
* @retval DSTATUS: Operation status
|
||||
*/
|
||||
DSTATUS disk_initialize (
|
||||
BYTE pdrv /* Physical drive nmuber to identify the drive */
|
||||
)
|
||||
{
|
||||
DSTATUS stat = STA_NOINIT;
|
||||
|
||||
switch(pdrv)
|
||||
{
|
||||
case DEV_USB:
|
||||
{
|
||||
if( true == Disk_Init() )
|
||||
stat = RES_OK;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// if(disk.is_initialized[pdrv] == 0)
|
||||
// {
|
||||
// disk.is_initialized[pdrv] = 1;
|
||||
// stat = disk.drv[pdrv]->disk_initialize(disk.lun[pdrv]);
|
||||
// }
|
||||
return stat;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reads Sector(s)
|
||||
* @param pdrv: Physical drive number (0..)
|
||||
* @param *buff: Data buffer to store read data
|
||||
* @param sector: Sector address (LBA)
|
||||
* @param count: Number of sectors to read (1..128)
|
||||
* @retval DRESULT: Operation result
|
||||
*/
|
||||
DRESULT disk_read (
|
||||
BYTE pdrv, /* Physical drive nmuber to identify the drive */
|
||||
BYTE *buff, /* Data buffer to store read data */
|
||||
DWORD sector, /* Sector address in LBA */
|
||||
UINT count /* Number of sectors to read */
|
||||
)
|
||||
{
|
||||
DRESULT res = RES_ERROR;
|
||||
|
||||
switch (pdrv)
|
||||
{
|
||||
case DEV_USB:
|
||||
{
|
||||
if( Disk_UnitRead(sector, count, buff) == true )
|
||||
{
|
||||
res = RES_OK;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// res = disk.drv[pdrv]->disk_read(disk.lun[pdrv], buff, sector, count);
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Writes Sector(s)
|
||||
* @param pdrv: Physical drive number (0..)
|
||||
* @param *buff: Data to be written
|
||||
* @param sector: Sector address (LBA)
|
||||
* @param count: Number of sectors to write (1..128)
|
||||
* @retval DRESULT: Operation result
|
||||
*/
|
||||
#if _USE_WRITE == 1
|
||||
DRESULT disk_write (
|
||||
BYTE pdrv, /* Physical drive nmuber to identify the drive */
|
||||
const BYTE *buff, /* Data to be written */
|
||||
DWORD sector, /* Sector address in LBA */
|
||||
UINT count /* Number of sectors to write */
|
||||
)
|
||||
{
|
||||
DRESULT res = RES_ERROR;
|
||||
|
||||
switch(pdrv)
|
||||
{
|
||||
case DEV_USB:
|
||||
{
|
||||
if( Disk_UnitWrite(sector, count, (uint8_t *)buff) == true )
|
||||
{
|
||||
res = RES_OK;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
// res = disk.drv[pdrv]->disk_write(disk.lun[pdrv], buff, sector, count);
|
||||
return res;
|
||||
}
|
||||
#endif /* _USE_WRITE == 1 */
|
||||
|
||||
/**
|
||||
* @brief I/O control operation
|
||||
* @param pdrv: Physical drive number (0..)
|
||||
* @param cmd: Control code
|
||||
* @param *buff: Buffer to send/receive control data
|
||||
* @retval DRESULT: Operation result
|
||||
*/
|
||||
#if _USE_IOCTL == 1
|
||||
DRESULT disk_ioctl (
|
||||
BYTE pdrv, /* Physical drive nmuber (0..) */
|
||||
BYTE cmd, /* Control code */
|
||||
void *buff /* Buffer to send/receive control data */
|
||||
)
|
||||
{
|
||||
DRESULT res = RES_PARERR;
|
||||
|
||||
switch(pdrv)
|
||||
{
|
||||
case DEV_USB:
|
||||
{
|
||||
switch(cmd)
|
||||
{
|
||||
case CTRL_SYNC:
|
||||
res = RES_OK;
|
||||
break;
|
||||
|
||||
case GET_SECTOR_COUNT:
|
||||
{
|
||||
*(DWORD *)buff = Disk_UnitCount( );
|
||||
res = RES_OK;
|
||||
break;
|
||||
}
|
||||
|
||||
case GET_SECTOR_SIZE:
|
||||
{
|
||||
*(DWORD *)buff = Disk_UnitSize( );
|
||||
res = RES_OK;
|
||||
break;
|
||||
}
|
||||
|
||||
case GET_BLOCK_SIZE:
|
||||
{
|
||||
*(DWORD *)buff = 1;
|
||||
res = RES_OK;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
res = RES_PARERR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// res = disk.drv[pdrv]->disk_ioctl(disk.lun[pdrv], cmd, buff);
|
||||
return res;
|
||||
}
|
||||
#endif /* _USE_IOCTL == 1 */
|
||||
|
||||
/**
|
||||
* @brief Gets Time from RTC
|
||||
* @param None
|
||||
* @retval Time in DWORD
|
||||
*/
|
||||
__weak DWORD get_fattime (void)
|
||||
{
|
||||
uint32_t fattime;
|
||||
// utc sec convert to utc date
|
||||
DateTime_t tmp_date = UTC_SecToDate(Utc_TotalSec);
|
||||
tmp_date = UTC_DateToZoneDate(TIME_ZONE, YEAR_BASE, tmp_date.year, tmp_date.month,
|
||||
tmp_date.day, tmp_date.hour, tmp_date.min,
|
||||
tmp_date.sec, tmp_date.week);
|
||||
fattime = ((YEAR_BASE + tmp_date.year - 1980) << 25) | (tmp_date.month << 21) |
|
||||
(tmp_date.day << 16) | (tmp_date.hour <<11) | (tmp_date.min << 5) |
|
||||
(tmp_date.sec >> 1);
|
||||
|
||||
return fattime;
|
||||
}
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
|
||||
@@ -1,91 +1,78 @@
|
||||
/*!
|
||||
* \file fatfs.c
|
||||
*
|
||||
* \brief Target FatFS implementation
|
||||
*
|
||||
* \copyright Revised BSD License, see section \ref LICENSE.
|
||||
*
|
||||
* \code
|
||||
*
|
||||
* _ __ _ ________ _
|
||||
* | |/ /(_)___ / ____/ /_ (_)___
|
||||
* | // / __ \/ / / __ \/ / __ \
|
||||
* / |/ / / / / /___/ / / / / /_/ /
|
||||
* /_/|_/_/_/ /_/\____/_/ /_/_/ .___/
|
||||
* /_/
|
||||
* (C) 2022-2025 XinChip
|
||||
*
|
||||
* \endcode
|
||||
*
|
||||
* \author ( XinChip ) Alex-J
|
||||
*
|
||||
* \author ( XinChip )
|
||||
*/
|
||||
|
||||
/*-----------------------------------------------------------------------------------
|
||||
INCLUDE HEADE FILES
|
||||
------------------------------------------------------------------------------------*/
|
||||
#include "fatfs.h"
|
||||
#include "xc6xxx.h"
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
Local Variables
|
||||
-------------------------------------------------------------------------------------*/
|
||||
char Path[4]; /* Logical drive path */
|
||||
FATFS FatFS; /* File system object for Logical drive */
|
||||
FIL File; /* File object */
|
||||
DIR Dir;
|
||||
uint8_t buffer[_MAX_SS];
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
Functions
|
||||
------------------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief FatFS Initalization
|
||||
* @param void
|
||||
* @retval void
|
||||
*/
|
||||
void FATFS_Init(void)
|
||||
{
|
||||
FRESULT res;
|
||||
|
||||
SPI_InitCfg_t spi_cfg = {0};
|
||||
|
||||
spi_cfg.Mode = SPI_MODE_MASTER;
|
||||
spi_cfg.DataSize = SSI_CTRL0_DFS_LEN_8BIT;
|
||||
spi_cfg.Direction = SSI_CTRL0_TMOD_WR;
|
||||
spi_cfg.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
|
||||
spi_cfg.CLKPolarity = SSI_CTRL0_SCPOL_LOW;
|
||||
spi_cfg.CLKPhase = SPI_CPHA_LEAD;
|
||||
spi_cfg.FirstBit = SPI_FirstBit_MSB;
|
||||
|
||||
xc_spi_init(XC_SPI0, &spi_cfg);
|
||||
xc_spi_flash_wake_up(XC_SPI0);
|
||||
|
||||
DEBUG("FatFS Init\r\n");
|
||||
res = f_mount(&FatFS, "0:", 1);
|
||||
DEBUG("Mount FRESULT: %d\r\n", res);
|
||||
|
||||
res = f_opendir(&Dir, "0:");
|
||||
DEBUG("Read Dir: %d\r\n", res);
|
||||
|
||||
if (FR_NO_FILESYSTEM == res) {
|
||||
res = f_mkfs("0:", FM_FAT, _MAX_SS, buffer, sizeof(buffer));
|
||||
DEBUG("Format FRESULT: %d\r\n", res);
|
||||
|
||||
res = f_unmount("0:");
|
||||
DEBUG("Umount FRESULT: %d\r\n", res);
|
||||
|
||||
// res = f_setlabel( "XinChip" );
|
||||
// DEBUG("Set label: %d\r\n", res);
|
||||
|
||||
res = f_mount(&FatFS, "0:", 1);
|
||||
DEBUG("Remount FRESULT: %d\r\n", res);
|
||||
|
||||
res = f_unmount("0:");
|
||||
DEBUG("Umount FRESULT: %d\r\n", res);
|
||||
} else {
|
||||
res = f_unmount("0:");
|
||||
DEBUG("Umount FRESULT: %d\r\n", res);
|
||||
}
|
||||
}
|
||||
/*!
|
||||
* \file fatfs.c
|
||||
*
|
||||
* \brief Target FatFS implementation
|
||||
*
|
||||
* \copyright Revised BSD License, see section \ref LICENSE.
|
||||
*
|
||||
* \code
|
||||
*
|
||||
* _ __ _ ________ _
|
||||
* | |/ /(_)___ / ____/ /_ (_)___
|
||||
* | // / __ \/ / / __ \/ / __ \
|
||||
* / |/ / / / / /___/ / / / / /_/ /
|
||||
* /_/|_/_/_/ /_/\____/_/ /_/_/ .___/
|
||||
* /_/
|
||||
* (C) 2022-2025 XinChip
|
||||
*
|
||||
* \endcode
|
||||
*
|
||||
* \author ( XinChip ) Alex-J
|
||||
*
|
||||
* \author ( XinChip )
|
||||
*/
|
||||
|
||||
/*-----------------------------------------------------------------------------------
|
||||
INCLUDE HEADE FILES
|
||||
------------------------------------------------------------------------------------*/
|
||||
#include "fatfs.h"
|
||||
#include "xc6xxx.h"
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
Local Variables
|
||||
-------------------------------------------------------------------------------------*/
|
||||
char Path[4]; /* Logical drive path */
|
||||
FATFS FatFS; /* File system object for Logical drive */
|
||||
FIL File; /* File object */
|
||||
DIR Dir;
|
||||
uint8_t buffer[_MAX_SS];
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
Functions
|
||||
------------------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief FatFS Initalization
|
||||
* @param void
|
||||
* @retval void
|
||||
*/
|
||||
void FATFS_Init(void)
|
||||
{
|
||||
FRESULT res;
|
||||
|
||||
DEBUG("FatFS Init\r\n");
|
||||
res = f_mount(&FatFS, "0:", 1);
|
||||
DEBUG("Mount FRESULT: %d\r\n", res);
|
||||
|
||||
res = f_opendir(&Dir, "0:");
|
||||
DEBUG("Read Dir: %d\r\n", res);
|
||||
|
||||
if (FR_NO_FILESYSTEM == res) {
|
||||
res = f_mkfs("0:", FM_FAT, _MAX_SS, buffer, sizeof(buffer));
|
||||
DEBUG("Format FRESULT: %d\r\n", res);
|
||||
|
||||
res = f_unmount("0:");
|
||||
DEBUG("Umount FRESULT: %d\r\n", res);
|
||||
|
||||
// res = f_setlabel( "XinChip" );
|
||||
// DEBUG("Set label: %d\r\n", res);
|
||||
|
||||
res = f_mount(&FatFS, "0:", 1);
|
||||
DEBUG("Remount FRESULT: %d\r\n", res);
|
||||
|
||||
res = f_unmount("0:");
|
||||
DEBUG("Umount FRESULT: %d\r\n", res);
|
||||
} else {
|
||||
res = f_unmount("0:");
|
||||
DEBUG("Umount FRESULT: %d\r\n", res);
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,116 +1,122 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file ff_gen_drv.c
|
||||
* @author MCD Application Team
|
||||
* @brief FatFs generic low level driver.
|
||||
*****************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics. All rights reserved.
|
||||
*
|
||||
* This software component is licensed by ST under BSD 3-Clause license,
|
||||
* the "License"; You may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at:
|
||||
* opensource.org/licenses/BSD-3-Clause
|
||||
*
|
||||
******************************************************************************
|
||||
**/
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "ff_gen_drv.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
Disk_drvTypeDef disk = {{0}, {0}, {0}, 0};
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @brief Links a compatible diskio driver/lun id and increments the number of
|
||||
active
|
||||
* linked drivers.
|
||||
* @note The number of linked drivers (volumes) is up to 10 due to FatFs
|
||||
limits.
|
||||
* @param drv: pointer to the disk IO Driver structure
|
||||
* @param path: pointer to the logical drive path
|
||||
* @param lun : only used for USB Key Disk to add multi-lun management
|
||||
else the parameter must be equal to 0
|
||||
* @retval Returns 0 in case of success, otherwise 1.
|
||||
*/
|
||||
uint8_t FATFS_LinkDriverEx(const Diskio_drvTypeDef *drv, char *path,
|
||||
uint8_t lun)
|
||||
{
|
||||
uint8_t ret = 1;
|
||||
uint8_t DiskNum = 0;
|
||||
|
||||
if (disk.nbr < _VOLUMES) {
|
||||
disk.is_initialized[disk.nbr] = 0;
|
||||
disk.drv[disk.nbr] = drv;
|
||||
disk.lun[disk.nbr] = lun;
|
||||
DiskNum = disk.nbr++;
|
||||
path[0] = DiskNum + '0';
|
||||
path[1] = ':';
|
||||
path[2] = '/';
|
||||
path[3] = 0;
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Links a compatible diskio driver and increments the number of active
|
||||
* linked drivers.
|
||||
* @note The number of linked drivers (volumes) is up to 10 due to FatFs
|
||||
* limits
|
||||
* @param drv: pointer to the disk IO Driver structure
|
||||
* @param path: pointer to the logical drive path
|
||||
* @retval Returns 0 in case of success, otherwise 1.
|
||||
*/
|
||||
uint8_t FATFS_LinkDriver(const Diskio_drvTypeDef *drv, char *path)
|
||||
{
|
||||
return FATFS_LinkDriverEx(drv, path, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Unlinks a diskio driver and decrements the number of active linked
|
||||
* drivers.
|
||||
* @param path: pointer to the logical drive path
|
||||
* @param lun : not used
|
||||
* @retval Returns 0 in case of success, otherwise 1.
|
||||
*/
|
||||
uint8_t FATFS_UnLinkDriverEx(char *path, uint8_t lun)
|
||||
{
|
||||
uint8_t DiskNum = 0;
|
||||
uint8_t ret = 1;
|
||||
|
||||
if (disk.nbr >= 1) {
|
||||
DiskNum = path[0] - '0';
|
||||
if (disk.drv[DiskNum] != 0) {
|
||||
disk.drv[DiskNum] = 0;
|
||||
disk.lun[DiskNum] = 0;
|
||||
disk.nbr--;
|
||||
ret = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Unlinks a diskio driver and decrements the number of active linked
|
||||
* drivers.
|
||||
* @param path: pointer to the logical drive path
|
||||
* @retval Returns 0 in case of success, otherwise 1.
|
||||
*/
|
||||
uint8_t FATFS_UnLinkDriver(char *path) { return FATFS_UnLinkDriverEx(path, 0); }
|
||||
|
||||
/**
|
||||
* @brief Gets number of linked drivers to the FatFs module.
|
||||
* @param None
|
||||
* @retval Number of attached drivers.
|
||||
*/
|
||||
uint8_t FATFS_GetAttachedDriversNbr(void) { return disk.nbr; }
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file ff_gen_drv.c
|
||||
* @author MCD Application Team
|
||||
* @brief FatFs generic low level driver.
|
||||
*****************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics. All rights reserved.
|
||||
*
|
||||
* This software component is licensed by ST under BSD 3-Clause license,
|
||||
* the "License"; You may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at:
|
||||
* opensource.org/licenses/BSD-3-Clause
|
||||
*
|
||||
******************************************************************************
|
||||
**/
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "ff_gen_drv.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
Disk_drvTypeDef disk = {{0},{0},{0},0};
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @brief Links a compatible diskio driver/lun id and increments the number of active
|
||||
* linked drivers.
|
||||
* @note The number of linked drivers (volumes) is up to 10 due to FatFs limits.
|
||||
* @param drv: pointer to the disk IO Driver structure
|
||||
* @param path: pointer to the logical drive path
|
||||
* @param lun : only used for USB Key Disk to add multi-lun management
|
||||
else the parameter must be equal to 0
|
||||
* @retval Returns 0 in case of success, otherwise 1.
|
||||
*/
|
||||
uint8_t FATFS_LinkDriverEx(const Diskio_drvTypeDef *drv, char *path, uint8_t lun)
|
||||
{
|
||||
uint8_t ret = 1;
|
||||
uint8_t DiskNum = 0;
|
||||
|
||||
if(disk.nbr < _VOLUMES)
|
||||
{
|
||||
disk.is_initialized[disk.nbr] = 0;
|
||||
disk.drv[disk.nbr] = drv;
|
||||
disk.lun[disk.nbr] = lun;
|
||||
DiskNum = disk.nbr++;
|
||||
path[0] = DiskNum + '0';
|
||||
path[1] = ':';
|
||||
path[2] = '/';
|
||||
path[3] = 0;
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Links a compatible diskio driver and increments the number of active
|
||||
* linked drivers.
|
||||
* @note The number of linked drivers (volumes) is up to 10 due to FatFs limits
|
||||
* @param drv: pointer to the disk IO Driver structure
|
||||
* @param path: pointer to the logical drive path
|
||||
* @retval Returns 0 in case of success, otherwise 1.
|
||||
*/
|
||||
uint8_t FATFS_LinkDriver(const Diskio_drvTypeDef *drv, char *path)
|
||||
{
|
||||
return FATFS_LinkDriverEx(drv, path, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Unlinks a diskio driver and decrements the number of active linked
|
||||
* drivers.
|
||||
* @param path: pointer to the logical drive path
|
||||
* @param lun : not used
|
||||
* @retval Returns 0 in case of success, otherwise 1.
|
||||
*/
|
||||
uint8_t FATFS_UnLinkDriverEx(char *path, uint8_t lun)
|
||||
{
|
||||
uint8_t DiskNum = 0;
|
||||
uint8_t ret = 1;
|
||||
|
||||
if(disk.nbr >= 1)
|
||||
{
|
||||
DiskNum = path[0] - '0';
|
||||
if(disk.drv[DiskNum] != 0)
|
||||
{
|
||||
disk.drv[DiskNum] = 0;
|
||||
disk.lun[DiskNum] = 0;
|
||||
disk.nbr--;
|
||||
ret = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Unlinks a diskio driver and decrements the number of active linked
|
||||
* drivers.
|
||||
* @param path: pointer to the logical drive path
|
||||
* @retval Returns 0 in case of success, otherwise 1.
|
||||
*/
|
||||
uint8_t FATFS_UnLinkDriver(char *path)
|
||||
{
|
||||
return FATFS_UnLinkDriverEx(path, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets number of linked drivers to the FatFs module.
|
||||
* @param None
|
||||
* @retval Number of attached drivers.
|
||||
*/
|
||||
uint8_t FATFS_GetAttachedDriversNbr(void)
|
||||
{
|
||||
return disk.nbr;
|
||||
}
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
|
||||
Reference in New Issue
Block a user