我用开发板,在外扩的这颗SDRAM想实现FatFS的文件操作,但是一直不成功啊。
代码是用STM32CubeMX生成的,不知道我生成代码时候的配置是否正确:
int main(void)
{
/* USER CODE BEGIN 1 */
unsigned char i ;
FIL MyFile;
uint32_t byteswritten, bytesread;
uint8_t wtext[] = "STM32 with FatFs demo @ std lib"; /* File write buffer */
uint8_t rtext[100]; /* File read buffer */
FRESULT res; /* FatFs function common result code */
/* USER CODE END 1 */
/* MCU Configuration----------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_FMC_Init();
MX_USART1_UART_Init();
MX_FATFS_Init();
/* USER CODE BEGIN 2 */
// if(FATFS_LinkDriver(&SDRAMDISK_Driver, &SDRAMDISKPath[0]) == 0)
// {
if( f_mkfs(&SDRAMDISKPath[0], FM_ANY, 0,&rtext,0) == FR_OK )
{
//表示挂载SDRAM成功
if(f_mount(&SDRAMDISKFatFS,&SDRAMDISKPath[0],1) == FR_OK)
{
if(f_open(&MyFile, "STM32STD.TXT", FA_CREATE_ALWAYS | FA_WRITE) == FR_OK)
{
res = f_write(&MyFile, wtext, sizeof(wtext), (void *)&byteswritten);
f_close(&MyFile);
}
if(f_open(&MyFile, "STM32STD.TXT", FA_READ) == FR_OK)
{
res = f_read(&MyFile, rtext, sizeof(rtext), (UINT*)&bytesread);
if((bytesread != 0) || (res == FR_OK))
{
f_close(&MyFile);
}
}
}
}
// }
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>