[笔记]STM32基于HAL库的SDIO+FATFS文件系统_stm32f103 hal sdio fatfs-程序员宅基地

技术标签: stm32  sdio  STM32  单片机  

1、背景

        要用到Bootloader升级,APP部分要写运行日志。所以在Bootloader部分的FATFS要做裁剪,裁剪到只剩只读的操作就可以了,而APP端做可读可写。

2、开发板

        用的是野火的STM32F103VETx指南者

3、工具

        STM32CubeMx 和 Keil5

4、制作只读的FATFS文件系统

        我用的是4线 Bit的配置,时钟尽量不要太高,我这里用了36分频,最终具体的频率要自己算一下。

 

然后配置FATFS,User-defined我建议是选上,对初学者的一次成功概率要更高一点。

        要使能第二行的FS_READONLY的话,要让最后一行的FS_LOCK设置成0才能看到选项(这个是设置成只读的配置,其他的写啥的f_write,基本都不能用,为了省空间)

        第二、三行我就不做解释,后面我会放个链接,你们可以看看大概是做什么的。

        从CODE_PAGE开始,按照顺序,设置英文、使能栈的缓存,最大的LFN为64(默认是255,如果跟我一样设置为64,那么SD里面的文件名超过64字的长度的话,可能会出现f_open失败的情况,请按照个人情况设置)

STM32笔记之 Fatfs(文件系统移植)_夏沫的杂物间-程序员宅基地写在前面:本文章旨在总结备份、方便以后查询,由于是个人总结,如有不对,欢迎指正;另外,内容大部分来自网络、书籍、和各类手册,如若侵权请告知,马上删帖致歉。一、介绍FatFs是用于小型嵌入式系统的通用 FAT / exFAT文件系统模块。FatFs模块是按照 ANSI C(C89)编写的,并且与磁盘 I / O层完全分开。因此,它独立于平台。它可以并入资源有限的小型微控制器中,例如8...https://blog.csdn.net/qq_42992084/article/details/105717906

FatFs模块功能配置选项_朱工的专栏-程序员宅基地Fatfs模块的功能可以裁剪,通过配置宏定义实现,宏定义位于文件ffconf.h中。1.功能配置1.1 _FS_READONLY使能或禁用与写相关函数。当设置为只读(1)时,API函数f_write、f_sync、f_unlink、f_mkdir、f_chmod、f_rename、f_truncate、f_getfree。1.2 _FS_MINIMIZE函数功能裁剪。1.3 _USE_STRhttps://blog.csdn.net/zhzht19861011/article/details/52910541

        这两个链接里面有涉及到FATFS的裁剪部分的说明,其实占空间最大的是这个选项,如果你选择了兼容汉字的话,我编译出来是190K左右,基本玩不了的。

还有一些其他的配置,基本都懂的

 

 最后的栈空间最好设置大一下,保证SDIO不会溢出

最后附上代码,有点长。如果你的CubeMx的设置跟我一样的话,可以直接复制。记得要勾上微库选项,以及printf的重定向。

/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : main.c
  * @brief          : Main program body
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
  * All rights reserved.</center></h2>
  *
  * This software component is licensed by ST under Ultimate Liberty license
  * SLA0044, the "License"; You may not use this file except in compliance with
  * the License. You may obtain a copy of the License at:
  *                             www.st.com/SLA0044
  *
  ******************************************************************************
  */
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "fatfs.h"
#include "sdio.h"
#include "usart.h"
#include "gpio.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "stdio.h"
/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
FATFS fs;													/* FatFs文件系统对象 */
FIL file;													/* 文件对象 */
FRESULT f_res;                    /* 文件操作结果 */
UINT fnum;            					  /* 文件成功读写数量 */
BYTE ReadBuffer[1024]={0};        /* 读缓冲区 */
BYTE WriteBuffer[]= "Welcome to the wildfire STM32 development board. Today is a good day to create new file system test files\r\n";

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
#define DBGPRINTF printf
/**
  * @brief  打印输出信息
  * @param  无
  * @retval 无
  */
 void printf_fatfs_error(FRESULT fresult)
{
  switch(fresult)
  {
    case FR_OK:
      DBGPRINTF("!!The operation was successful.\r\n");
    break;
    case FR_DISK_ERR:
    	DBGPRINTF("!!Hardware I / O driver error.\r\n");
    break;
    case FR_INT_ERR:
    	DBGPRINTF("!!Assertion error.\r\n");
    break;
    case FR_NOT_READY:
    	DBGPRINTF("!!The physical device is not working.\r\n");
    break;
    case FR_NO_FILE:
    	DBGPRINTF("!!Unable to find file.\r\n");
    break;
    case FR_NO_PATH:
    	DBGPRINTF("!!The path could not be found.\r\n");
    break;
    case FR_INVALID_NAME:
    	DBGPRINTF("!!Invalid pathname.\r\n");
    break;
    case FR_DENIED:
    case FR_EXIST:
    	DBGPRINTF("!!Access denied.\r\n");
    break;
    case FR_INVALID_OBJECT:
    	DBGPRINTF("!!Invalid file or path.\r\n");
    break;
    case FR_WRITE_PROTECTED:
    	DBGPRINTF("!!Logical device write protection.\r\n");
    break;
    case FR_INVALID_DRIVE:
    	DBGPRINTF("!!Invalid logical device.\r\n");
    break;
    case FR_NOT_ENABLED:
    	DBGPRINTF("!!Invalid workspace.\r\n");
    break;
    case FR_NO_FILESYSTEM:
    	DBGPRINTF("!!Invalid file system.\r\n");
    break;
    case FR_MKFS_ABORTED:
    	DBGPRINTF("!!Fmkfs function operation failed due to function parameter problem.\r\n");
    break;
    case FR_TIMEOUT:
    	DBGPRINTF("!!The operation timed out.\r\n");
    break;
    case FR_LOCKED:
    	DBGPRINTF("!!The file is protected.\r\n");
    break;
    case FR_NOT_ENOUGH_CORE:
    	DBGPRINTF("!!Long file name support failed to get heap space.\r\n");
    break;
    case FR_TOO_MANY_OPEN_FILES:
    	DBGPRINTF("!!Too many files open.\r\n");
    break;
    case FR_INVALID_PARAMETER:
    	DBGPRINTF("!!Invalid parameter.\r\n");
    break;
  }
}
/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/

/* USER CODE BEGIN PV */

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
/* USER CODE BEGIN PFP */

/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */

/* USER CODE END 0 */

/**
  * @brief  The application entry point.
  * @retval int
  */
int main(void)
{
  /* USER CODE BEGIN 1 */

  /* 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_SDIO_SD_Init();
  MX_USART1_UART_Init();
  MX_FATFS_Init();
  /* USER CODE BEGIN 2 */
 
  DBGPRINTF("\r\r\n****** This is a SD card file system experiment ******\r\n");
 
  	 // 注册一个FatFS设备:SD卡 //
    if(FATFS_LinkDriver(&SD_Driver, SDPath) == 0)
    {
      //在SD卡挂载文件系统,文件系统挂载时会对SD卡初始化
      f_res = f_mount(&fs,(TCHAR const*)SDPath,1);
      printf_fatfs_error(f_res);
      //----------------------- 格式化测试 ---------------------------//
      // 如果没有文件系统就格式化创建创建文件系统 */
      if(f_res!=FR_OK)
      {
        DBGPRINTF("The SD card failed to mount the file system.(%d)\r\n",f_res);
        printf_fatfs_error(f_res);
        while(1);
      }
      else
      {
        DBGPRINTF("The file system is mounted successfully and can be read and written\r\n");
      }
 
      //------------------- 文件系统测试:读测试 ------------------------------------//
      DBGPRINTF("****** File read test is about to take place... ******\r\n");
      f_res = f_open(&file, "FatFsRWFiles.txt", FA_OPEN_EXISTING | FA_READ);
	  printf_fatfs_error(f_res);
      if(f_res == FR_OK)
      {
        DBGPRINTF("File opened successfully.\r\n");
        f_res = f_read(&file, ReadBuffer, sizeof(ReadBuffer), &fnum);
        if(f_res==FR_OK)
        {
          DBGPRINTF("File read successfully, read byte data: %d\r\n",fnum);
          DBGPRINTF("The obtained file data are as follows:\r\n%s \r\n", ReadBuffer);
        }
        else
        {
          DBGPRINTF("File read failure:(%d)\r\n",f_res);
        }
      }
      else
      {
        DBGPRINTF("Failed to open file.\r\n");
      }
      // 不再读写,关闭文件 //
      f_close(&file);
 
      // 不再使用,取消挂载 //
      f_res = f_mount(NULL,(TCHAR const*)SDPath,1);
    }
    // 注销一个FatFS设备:SD卡 //
    FATFS_UnLinkDriver(SDPath);
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

/**
  * @brief System Clock Configuration
  * @retval None
  */
void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

  /** Initializes the RCC Oscillators according to the specified parameters
  * in the RCC_OscInitTypeDef structure.
  */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }
  /** Initializes the CPU, AHB and APB buses clocks
  */
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  {
    Error_Handler();
  }
}

/* USER CODE BEGIN 4 */

/* USER CODE END 4 */

/**
  * @brief  This function is executed in case of error occurrence.
  * @retval None
  */
void Error_Handler(void)
{
  /* USER CODE BEGIN Error_Handler_Debug */
  /* User can add his own implementation to report the HAL error return state */
  __disable_irq();
  while (1)
  {
  }
  /* USER CODE END Error_Handler_Debug */
}

#ifdef  USE_FULL_ASSERT
/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t *file, uint32_t line)
{
  /* USER CODE BEGIN 6 */
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  /* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

 如果没有玩过linux/windows开发的话,这里可以更改你想读SD里面的哪个文件。当然前提是,你SD里面有这个文件才行。

需要注意的是,里面的并非是字符,而是十六进制,可以看到最后的0d 0a 00是不是很熟悉,不就是\r\n吗。 

5、制作可读可写的FATFS文件系统

在上面的基础上,只需要更改FATFS部分的配置即可。

/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : main.c
  * @brief          : Main program body
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
  * All rights reserved.</center></h2>
  *
  * This software component is licensed by ST under Ultimate Liberty license
  * SLA0044, the "License"; You may not use this file except in compliance with
  * the License. You may obtain a copy of the License at:
  *                             www.st.com/SLA0044
  *
  ******************************************************************************
  */
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "fatfs.h"
#include "sdio.h"
#include "usart.h"
#include "gpio.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "stdio.h"
/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
FATFS fs;													/* FatFs文件系统对象 */
FIL file;													/* 文件对象 */
FRESULT f_res;                    /* 文件操作结果 */
UINT fnum;            					  /* 文件成功读写数量 */
BYTE ReadBuffer[1024]={0};        /* 读缓冲区 */
BYTE WriteBuffer[]= "Welcome to the wildfire STM32 development board. Today is a good day to create new file system test files\r\n";
#define DBGPRINTF printf
 void printf_fatfs_error(FRESULT fresult)
{
  switch(fresult)
  {
    case FR_OK:
      DBGPRINTF("!!The operation was successful.\r\n");
    break;
    case FR_DISK_ERR:
    	DBGPRINTF("!!Hardware I / O driver error.\r\n");
    break;
    case FR_INT_ERR:
    	DBGPRINTF("!!Assertion error.\r\n");
    break;
    case FR_NOT_READY:
    	DBGPRINTF("!!The physical device is not working.\r\n");
    break;
    case FR_NO_FILE:
    	DBGPRINTF("!!Unable to find file.\r\n");
    break;
    case FR_NO_PATH:
    	DBGPRINTF("!!The path could not be found.\r\n");
    break;
    case FR_INVALID_NAME:
    	DBGPRINTF("!!Invalid pathname.\r\n");
    break;
    case FR_DENIED:
    case FR_EXIST:
    	DBGPRINTF("!!Access denied.\r\n");
    break;
    case FR_INVALID_OBJECT:
    	DBGPRINTF("!!Invalid file or path.\r\n");
    break;
    case FR_WRITE_PROTECTED:
    	DBGPRINTF("!!Logical device write protection.\r\n");
    break;
    case FR_INVALID_DRIVE:
    	DBGPRINTF("!!Invalid logical device.\r\n");
    break;
    case FR_NOT_ENABLED:
    	DBGPRINTF("!!Invalid workspace.\r\n");
    break;
    case FR_NO_FILESYSTEM:
    	DBGPRINTF("!!Invalid file system.\r\n");
    break;
    case FR_MKFS_ABORTED:
    	DBGPRINTF("!!Fmkfs function operation failed due to function parameter problem.\r\n");
    break;
    case FR_TIMEOUT:
    	DBGPRINTF("!!The operation timed out.\r\n");
    break;
    case FR_LOCKED:
    	DBGPRINTF("!!The file is protected.\r\n");
    break;
    case FR_NOT_ENOUGH_CORE:
    	DBGPRINTF("!!Long file name support failed to get heap space.\r\n");
    break;
    case FR_TOO_MANY_OPEN_FILES:
    	DBGPRINTF("!!Too many files open.\r\n");
    break;
    case FR_INVALID_PARAMETER:
    	DBGPRINTF("!!Invalid parameter.\r\n");
    break;
  }
}
/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/

/* USER CODE BEGIN PV */

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
/* USER CODE BEGIN PFP */

/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */

/* USER CODE END 0 */

/**
  * @brief  The application entry point.
  * @retval int
  */
int main(void)
{
  /* USER CODE BEGIN 1 */

  /* 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_SDIO_SD_Init();
  MX_USART1_UART_Init();
  MX_FATFS_Init();
  /* USER CODE BEGIN 2 */
 
  DBGPRINTF("\r\r\n****** This is a SD card file system experiment ******\r\n");
 
  	 // 注册一个FatFS设备:SD卡 //
    if(FATFS_LinkDriver(&SD_Driver, SDPath) == 0)
    {
      //在SD卡挂载文件系统,文件系统挂载时会对SD卡初始化
      f_res = f_mount(&fs,(TCHAR const*)SDPath,1);
      printf_fatfs_error(f_res);
      //----------------------- 格式化测试 ---------------------------//
      // 如果没有文件系统就格式化创建创建文件系统 */
   if(f_res == FR_NO_FILESYSTEM)
      {
        DBGPRINTF("The SD card does not have a file system yet and will be formatted...\r\n");
        // 格式化 //
        f_res=f_mkfs((TCHAR const*)SDPath,0,0);
 
        if(f_res == FR_OK)
        {
          DBGPRINTF("The SD card has successfully formatted the file system\r\n");
          // 格式化后,先取消挂载 //
          f_res = f_mount(NULL,(TCHAR const*)SDPath,1);
          // 重新挂载	//
          f_res = f_mount(&fs,(TCHAR const*)SDPath,1);
        }
        else
        {
          DBGPRINTF("Format failed\r\n");
          while(1);
        }
      }
      else if(f_res!=FR_OK)
      {
        DBGPRINTF("The SD card failed to mount the file system.(%d)\r\n",f_res);
        printf_fatfs_error(f_res);
        while(1);
      }
      else
      {
        DBGPRINTF("The file system is mounted successfully and can be read and written\r\n");
      }
 
      //----------------------- 文件系统测试:写测试 -----------------------------//
      // 打开文件,如果文件不存在则创建它 //
      DBGPRINTF("****** A file write test will be performed... ******\r\n");
      f_res = f_open(&file, "unit_sd_rw_test.txt",FA_CREATE_ALWAYS | FA_WRITE );
      if ( f_res == FR_OK )
      {
        DBGPRINTF("Open / create FatFs read / write test file. TXT file successfully, write data to the file.\r\n");
        // 将指定存储区内容写入到文件内 //
        f_res=f_write(&file,WriteBuffer,sizeof(WriteBuffer),&fnum);
        if(f_res==FR_OK)
        {
          DBGPRINTF("File write success, write byte data:%d\r\n",fnum);
          DBGPRINTF("The data written to the file is: \r\n%s\r\n",WriteBuffer);
        }
        else
        {
          DBGPRINTF(" File write failure:(%d)\r\n",f_res);
        }
        // 不再读写,关闭文件 //
        f_close(&file);
      }
      else
      {
        DBGPRINTF("Failed to open / create file.\r\n");
      }
 
      //------------------- 文件系统测试:读测试 ------------------------------------//
      DBGPRINTF("****** File read test is about to take place... ******\r\n");
      f_res = f_open(&file, "unit_sd_rw_test.txt", FA_OPEN_EXISTING | FA_READ);
      if(f_res == FR_OK)
      {
        DBGPRINTF("File opened successfully.\r\n");
        f_res = f_read(&file, ReadBuffer, sizeof(ReadBuffer), &fnum);
        if(f_res==FR_OK)
        {
          DBGPRINTF("File read successfully, read byte data: %d\r\n",fnum);
          DBGPRINTF("The obtained file data are as follows:\r\n%s \r\n", ReadBuffer);
        }
        else
        {
          DBGPRINTF("File read failure:(%d)\r\n",f_res);
        }
      }
      else
      {
        DBGPRINTF("Failed to open file.\r\n");
      }
      // 不再读写,关闭文件 //
      f_close(&file);
 
      // 不再使用,取消挂载 //
      f_res = f_mount(NULL,(TCHAR const*)SDPath,1);
    }
    // 注销一个FatFS设备:SD卡 //
    FATFS_UnLinkDriver(SDPath);
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

/**
  * @brief System Clock Configuration
  * @retval None
  */
void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

  /** Initializes the RCC Oscillators according to the specified parameters
  * in the RCC_OscInitTypeDef structure.
  */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }
  /** Initializes the CPU, AHB and APB buses clocks
  */
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  {
    Error_Handler();
  }
}

/* USER CODE BEGIN 4 */

/* USER CODE END 4 */

/**
  * @brief  This function is executed in case of error occurrence.
  * @retval None
  */
void Error_Handler(void)
{
  /* USER CODE BEGIN Error_Handler_Debug */
  /* User can add his own implementation to report the HAL error return state */
  __disable_irq();
  while (1)
  {
  }
  /* USER CODE END Error_Handler_Debug */
}

#ifdef  USE_FULL_ASSERT
/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t *file, uint32_t line)
{
  /* USER CODE BEGIN 6 */
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  /* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

只要你没有去选择兼容汉字的选项,基本上这个文件系统不会太大。只读和可读可写,在占用空间上相差并不会太大,但MCU上的空间是金子呀【笑哭】。FATFS的选项可能有点选的不太合适,发现的可以在评论区补充一下,

就介绍到这里了!!!有问题可以私聊或在评论区留言

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_33591039/article/details/121611426

智能推荐

攻防世界_难度8_happy_puzzle_攻防世界困难模式攻略图文-程序员宅基地

文章浏览阅读645次。这个肯定是末尾的IDAT了,因为IDAT必须要满了才会开始一下个IDAT,这个明显就是末尾的IDAT了。,对应下面的create_head()代码。,对应下面的create_tail()代码。不要考虑爆破,我已经试了一下,太多情况了。题目来源:UNCTF。_攻防世界困难模式攻略图文

达梦数据库的导出(备份)、导入_达梦数据库导入导出-程序员宅基地

文章浏览阅读2.9k次,点赞3次,收藏10次。偶尔会用到,记录、分享。1. 数据库导出1.1 切换到dmdba用户su - dmdba1.2 进入达梦数据库安装路径的bin目录,执行导库操作  导出语句:./dexp cwy_init/[email protected]:5236 file=cwy_init.dmp log=cwy_init_exp.log 注释:   cwy_init/init_123..._达梦数据库导入导出

js引入kindeditor富文本编辑器的使用_kindeditor.js-程序员宅基地

文章浏览阅读1.9k次。1. 在官网上下载KindEditor文件,可以删掉不需要要到的jsp,asp,asp.net和php文件夹。接着把文件夹放到项目文件目录下。2. 修改html文件,在页面引入js文件:<script type="text/javascript" src="./kindeditor/kindeditor-all.js"></script><script type="text/javascript" src="./kindeditor/lang/zh-CN.js"_kindeditor.js

STM32学习过程记录11——基于STM32G431CBU6硬件SPI+DMA的高效WS2812B控制方法-程序员宅基地

文章浏览阅读2.3k次,点赞6次,收藏14次。SPI的详情简介不必赘述。假设我们通过SPI发送0xAA,我们的数据线就会变为10101010,通过修改不同的内容,即可修改SPI中0和1的持续时间。比如0xF0即为前半周期为高电平,后半周期为低电平的状态。在SPI的通信模式中,CPHA配置会影响该实验,下图展示了不同采样位置的SPI时序图[1]。CPOL = 0,CPHA = 1:CLK空闲状态 = 低电平,数据在下降沿采样,并在上升沿移出CPOL = 0,CPHA = 0:CLK空闲状态 = 低电平,数据在上升沿采样,并在下降沿移出。_stm32g431cbu6

计算机网络-数据链路层_接收方收到链路层数据后,使用crc检验后,余数为0,说明链路层的传输时可靠传输-程序员宅基地

文章浏览阅读1.2k次,点赞2次,收藏8次。数据链路层习题自测问题1.数据链路(即逻辑链路)与链路(即物理链路)有何区别?“电路接通了”与”数据链路接通了”的区别何在?2.数据链路层中的链路控制包括哪些功能?试讨论数据链路层做成可靠的链路层有哪些优点和缺点。3.网络适配器的作用是什么?网络适配器工作在哪一层?4.数据链路层的三个基本问题(帧定界、透明传输和差错检测)为什么都必须加以解决?5.如果在数据链路层不进行帧定界,会发生什么问题?6.PPP协议的主要特点是什么?为什么PPP不使用帧的编号?PPP适用于什么情况?为什么PPP协议不_接收方收到链路层数据后,使用crc检验后,余数为0,说明链路层的传输时可靠传输

软件测试工程师移民加拿大_无证移民,未受过软件工程师的教育(第1部分)-程序员宅基地

文章浏览阅读587次。软件测试工程师移民加拿大 无证移民,未受过软件工程师的教育(第1部分) (Undocumented Immigrant With No Education to Software Engineer(Part 1))Before I start, I want you to please bear with me on the way I write, I have very little gen...

随便推点

Thinkpad X250 secure boot failed 启动失败问题解决_安装完系统提示secureboot failure-程序员宅基地

文章浏览阅读304次。Thinkpad X250笔记本电脑,装的是FreeBSD,进入BIOS修改虚拟化配置(其后可能是误设置了安全开机),保存退出后系统无法启动,显示:secure boot failed ,把自己惊出一身冷汗,因为这台笔记本刚好还没开始做备份.....根据错误提示,到bios里面去找相关配置,在Security里面找到了Secure Boot选项,发现果然被设置为Enabled,将其修改为Disabled ,再开机,终于正常启动了。_安装完系统提示secureboot failure

C++如何做字符串分割(5种方法)_c++ 字符串分割-程序员宅基地

文章浏览阅读10w+次,点赞93次,收藏352次。1、用strtok函数进行字符串分割原型: char *strtok(char *str, const char *delim);功能:分解字符串为一组字符串。参数说明:str为要分解的字符串,delim为分隔符字符串。返回值:从str开头开始的一个个被分割的串。当没有被分割的串时则返回NULL。其它:strtok函数线程不安全,可以使用strtok_r替代。示例://借助strtok实现split#include <string.h>#include <stdio.h&_c++ 字符串分割

2013第四届蓝桥杯 C/C++本科A组 真题答案解析_2013年第四届c a组蓝桥杯省赛真题解答-程序员宅基地

文章浏览阅读2.3k次。1 .高斯日记 大数学家高斯有个好习惯:无论如何都要记日记。他的日记有个与众不同的地方,他从不注明年月日,而是用一个整数代替,比如:4210后来人们知道,那个整数就是日期,它表示那一天是高斯出生后的第几天。这或许也是个好习惯,它时时刻刻提醒着主人:日子又过去一天,还有多少时光可以用于浪费呢?高斯出生于:1777年4月30日。在高斯发现的一个重要定理的日记_2013年第四届c a组蓝桥杯省赛真题解答

基于供需算法优化的核极限学习机(KELM)分类算法-程序员宅基地

文章浏览阅读851次,点赞17次,收藏22次。摘要:本文利用供需算法对核极限学习机(KELM)进行优化,并用于分类。

metasploitable2渗透测试_metasploitable2怎么进入-程序员宅基地

文章浏览阅读1.1k次。一、系统弱密码登录1、在kali上执行命令行telnet 192.168.26.1292、Login和password都输入msfadmin3、登录成功,进入系统4、测试如下:二、MySQL弱密码登录:1、在kali上执行mysql –h 192.168.26.129 –u root2、登录成功,进入MySQL系统3、测试效果:三、PostgreSQL弱密码登录1、在Kali上执行psql -h 192.168.26.129 –U post..._metasploitable2怎么进入

Python学习之路:从入门到精通的指南_python人工智能开发从入门到精通pdf-程序员宅基地

文章浏览阅读257次。本文将为初学者提供Python学习的详细指南,从Python的历史、基础语法和数据类型到面向对象编程、模块和库的使用。通过本文,您将能够掌握Python编程的核心概念,为今后的编程学习和实践打下坚实基础。_python人工智能开发从入门到精通pdf

推荐文章

热门文章

相关标签