之前求助的结果
就是用MCU的片内FLASH做文件系统存放数据
我就想到官方的Nucleo板不就是这样的吗?!
我目前只能做到显示出有U盘的盘符(因为用CubeMX配置的USB_device_Only MSC),但是接入电脑后马上提示要格式化才能用
官方的Nucleo板插入后能正常显示U盘,而且能够像U盘一样往里面放文件(但是下次插入电脑时自动清除)
了解到现在要改的关键部分代码或函数有以下这几个(求教怎么修改带能正常,MCU:
STM32F107VCT6,FLASH是256K,每页2K):
usbd_storage_if.c文件中的
int8_t STORAGE_Init_FS (uint8_t lun)
{
/* USER CODE BEGIN 2 */
HAL_FLASH_Unlock();
/* Fill EraseInit structure*/
EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES;
EraseInitStruct.PageAddress = FLASH_USER_START_ADDR;
EraseInitStruct.NbPages = (FLASH_USER_END_ADDR - FLASH_USER_START_ADDR) / FLASH_PAGE_SIZE;
return (USBD_OK);
/* USER CODE END 2 */
}
int8_t STORAGE_GetCapacity_FS (uint8_t lun, uint32_t *block_num, uint16_t *block_size)
{
/* USER CODE BEGIN 3 */
// *block_num = STORAGE_BLK_NBR;
// *block_size = STORAGE_BLK_SIZ;
*block_num = 0x20;
*block_size = 0x800;
return (USBD_OK);
/* USER CODE END 3 */
}
int8_t STORAGE_Read_FS (uint8_t lun,
uint8_t *buf,
uint32_t blk_addr,
uint16_t blk_len)
{
/* USER CODE BEGIN 6 */
if(lun == 0)
{
for(uint16_t i=0;i<blk_len;i+=4)
{
buf[i>>2] = *(__IO uint32_t *)(FLASH_START_ADDR + blk_addr);
// buf = *(vu32*)(FLASH_START_ADDR + blk_addr);
}
}
return (USBD_OK);
/* USER CODE END 6 */
}
int8_t STORAGE_Write_FS (uint8_t lun,
uint8_t *buf,
uint32_t blk_addr,
uint16_t blk_len)
{
/* USER CODE BEGIN 7 */
if(lun == 0)
{
for(uint16_t i=0; i<blk_len;i+=FLASH_PAGE_SIZE)
{
// FLASH_
tiMEOUT_VALUE
if(FLASH_WaitForLastOperation(FLASH_WAIT_TIMEOUT)!=FLASH_TIMEOUT_VALUE)
{
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP|FLASH_FLAG_PGERR|FLASH_FLAG_WRPERR);
}
FLASH_PageErase(FLASH_START_ADDR + blk_addr + i);
}
for(uint16_t i=0;i<blk_len;i+=4)
{
if(FLASH_WaitForLastOperation(FLASH_WAIT_TIMEOUT)!=FLASH_TIMEOUT_VALUE)
{
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP|FLASH_FLAG_PGERR|FLASH_FLAG_WRPERR);
}
HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD,FLASH_START_ADDR + blk_addr + i , buf[i>>2]);
}
}
return (USBD_OK);
/* USER CODE END 7 */
}
我之前找过,麻烦你指出在哪个目录下
en.stm32cubef1STM32Cube_FW_F1_V1.4.0Projects
再下一层的什么路径?
并没有找到
一周热门 更多>