STM32存储左右互搏 SPI总线FATS文件读写FLASH W25QXX

STM32存储左右互搏 SPI总线FATS文件读写FLASH W25QXX

FLASH是常用的一种非易失存储单元,W25QXX系列Flash有不同容量的型号,如W25Q64的容量为64Mbit,也就是8MByte。这里介绍STM32CUBEIDE开发平台HAL库实现FATS文件操作W25Q各型号FLASH的例程。非FATS直接操作W25QXX FLASH的方式见《STM32存储左右互搏 SPI总线读写FLASH W25QXX》

W25QXX介绍

W25QXX的SOIC封装如下所示,在采用SPI而不是QUAL SPI时,管脚定义为:
在这里插入图片描述
即由片选(/CS), 时钟(CLK), 数据输出(DO)和数据输入(DI)的组成4线SPI信号接口。VCC和GND提供电源和接地连接。

例程采用STM32H750VBT6芯片, FLASH可以选择为8/16/32/64/128/256/512/1024 Mbit的W25Q型号。

STM32工程配置

首先建立基本工程并设置时钟:
在这里插入图片描述

在这里插入图片描述

选择硬件接口SPI2为FLASH连接接口,片选采用软件代码控制方式,单独设置为输出GPIO:
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
不采用中断和DMA方式,需要时可以再添加,调用相对应的操作库函数及补充中断处理函数即可。
在这里插入图片描述
在这里插入图片描述
配置FATS参数:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
配置UART1用于控制打印:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
保存并生成初始工程代码:
在这里插入图片描述

STM32工程代码

UART串口printf打印输出实现参考:STM32 UART串口printf函数应用及浮点打印代码空间节省 (HAL)

建立W25Q访问的库头文件W25QXX.h:

#ifndef INC_W25QXX_H_
#define INC_W25QXX_H_#include "main.h"uint8_t SPI2_ReadWriteByte(uint8_t TxData);//W25QXX serial chip list:
#define W25Q80_ID 	0XEF13
#define W25Q16_ID 	0XEF14
#define W25Q32_ID 	0XEF15
#define W25Q64_ID 	0XEF16
#define W25Q128_ID	0XEF17
#define W25Q256_ID  0XEF18
#define W25Q512_ID  0XEF19
#define W25Q1024_ID 0XEF20extern uint16_t W25QXX_TYPE; //To indicate W25QXX type used in this procedure//W25QXX chip select control function
#define W25QXX_CS(n)  ( n ? HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_SET) : HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_RESET) )//command table for W25QXX access
#define W25X_WriteEnable		0x06
#define W25X_WriteDisable		0x04
#define W25X_ReadStatusReg1		0x05
#define W25X_ReadStatusReg2		0x35
#define W25X_ReadStatusReg3		0x15
#define W25X_WriteStatusReg1    0x01
#define W25X_WriteStatusReg2    0x31
#define W25X_WriteStatusReg3    0x11
#define W25X_ReadData			0x03
#define W25X_FastReadData		0x0B
#define W25X_FastReadDual		0x3B
#define W25X_PageProgram		0x02
#define W25X_BlockErase			0xD8
#define W25X_SectorErase		0x20
#define W25X_ChipErase			0xC7
#define W25X_PowerDown			0xB9
#define W25X_ReleasePowerDown	0xAB
#define W25X_DeviceID			0xAB
#define W25X_ManufactDeviceID	0x90
#define W25X_JedecDeviceID		0x9F
#define W25X_Enable4ByteAddr    0xB7
#define W25X_Exit4ByteAddr      0xE9uint8_t W25QXX_Init(void);
uint16_t  W25QXX_ReadID(void);  	    		  //Read W25QXX ID
uint8_t W25QXX_ReadSR(uint8_t reg_num);           //Read from status register
void W25QXX_4ByteAddr_Enable(void);               //Enable 4-byte address mode
void W25QXX_Write_SR(uint8_t reg_num,uint8_t d);  //Write to status register
void W25QXX_Write_Enable(void);  		          //Write enable
void W25QXX_Write_Disable(void);		          //Write disable
void W25QXX_Write_NoCheck(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite); //Write operation w/o check
void W25QXX_Read(uint8_t* pBuffer,uint32_t ReadAddr,uint16_t NumByteToRead);            //Read operation
void W25QXX_Write(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite);         //Write operation
void W25QXX_Erase_Chip(void);    	  	                                                //Erase whole chip
void W25QXX_Erase_Sector(uint32_t Sector_Num);	                                        //Erase sector in specific sector number
void W25QXX_Wait_Busy(void);           	       //Wait idle status before next operation
void W25QXX_PowerDown(void);        	       //Enter power-down mode
void W25QXX_WAKEUP(void);				       //Wake-up#endif /* INC_W25QXX_H_ */

建立W25Q访问的库源文件W25QXX.c:

#include "W25QXX.h"extern SPI_HandleTypeDef hspi2;
extern void PY_Delay_us_t(uint32_t Delay);
//Write and read one byte in SPI2
uint8_t SPI2_ReadWriteByte(uint8_t TxData)
{uint8_t Rxdata;HAL_SPI_TransmitReceive(&hspi2,&TxData,&Rxdata,1, 1000);return Rxdata;
}uint16_t W25QXX_TYPE=W25Q64_ID;//W25QXX initialization
uint8_t W25QXX_Init(void)
{uint8_t temp;W25QXX_CS(1);W25QXX_TYPE=W25QXX_ReadID();if((W25QXX_TYPE==W25Q256_ID)||(W25QXX_TYPE==W25Q512_ID)||(W25QXX_TYPE==W25Q1024_ID)){temp=W25QXX_ReadSR(3);              //read status register 3if((temp&0X01)==0)			        //judge address mode and configure to 4-byte address mode{W25QXX_CS(0);SPI2_ReadWriteByte(W25X_Enable4ByteAddr);W25QXX_CS(1);}}if((W25QXX_TYPE==0x0000)||(W25QXX_TYPE==0xFFFF)) return 0;else return 1;
}//Read status registers of W25QXX
//reg_num: register number from 1 to 3
//return: value of selected register//SR1 (default 0x00):
//BIT7  6   5   4   3   2   1   0
//SPR   RV  TB BP2 BP1 BP0 WEL BUSY
//SPR: default 0, status register protection bit used with WP
//TB,BP2,BP1,BP0: FLASH region write protection configuration
//WEL: write enable lock
//BUSY: busy flag (1: busy; 0: idle)//SR2:
//BIT7  6   5   4   3   2   1   0
//SUS   CMP LB3 LB2 LB1 (R) QE  SRP1//SR3:
//BIT7      6    5    4   3   2   1   0
//HOLD/RST  DRV1 DRV0 (R) (R) WPS ADP ADS
uint8_t W25QXX_ReadSR(uint8_t reg_num)
{uint8_t byte=0,command=0;switch(reg_num){case 1:command=W25X_ReadStatusReg1;    //To read status register 1break;case 2:command=W25X_ReadStatusReg2;    //To read status register 2break;case 3:command=W25X_ReadStatusReg3;    //To read status register 3break;default:command=W25X_ReadStatusReg1;break;}W25QXX_CS(0);SPI2_ReadWriteByte(command);    //send commandbyte=SPI2_ReadWriteByte(0Xff);  //read dataW25QXX_CS(1);return byte;
}//Write status registers of W25QXX
//reg_num: register number from 1 to 3
//d: data for updating status register
void W25QXX_Write_SR(uint8_t reg_num,uint8_t d)
{uint8_t command=0;switch(reg_num){case 1:command=W25X_WriteStatusReg1;    //To write status register 1break;case 2:command=W25X_WriteStatusReg2;    //To write status register 2break;case 3:command=W25X_WriteStatusReg3;    //To write status register 3break;default:command=W25X_WriteStatusReg1;break;}W25QXX_CS(0);SPI2_ReadWriteByte(command);            //send commandSPI2_ReadWriteByte(d);                  //write dataW25QXX_CS(1);
}
//W25QXX write enable
void W25QXX_Write_Enable(void)
{W25QXX_CS(0);SPI2_ReadWriteByte(W25X_WriteEnable);W25QXX_CS(1);
}
//W25QXX write disable
void W25QXX_Write_Disable(void)
{W25QXX_CS(0);SPI2_ReadWriteByte(W25X_WriteDisable);W25QXX_CS(1);
}//Read chip ID
//return:
//0XEF13 for W25Q80
//0XEF14 for W25Q16
//0XEF15 for W25Q32
//0XEF16 for W25Q64
//0XEF17 for W25Q128
//0XEF18 for W25Q256
uint16_t W25QXX_ReadID(void)
{uint16_t Temp = 0;W25QXX_CS(0);SPI2_ReadWriteByte(0x90);          //send commandSPI2_ReadWriteByte(0x00);SPI2_ReadWriteByte(0x00);SPI2_ReadWriteByte(0x00);Temp|=SPI2_ReadWriteByte(0xFF)<<8; //read high byte dataTemp|=SPI2_ReadWriteByte(0xFF);    //read low byte dataW25QXX_CS(1);return Temp;
}
//Read W25QXX from specific address for specific byte length
//pBuffer: data buffer
//ReadAddr: specific address
//NumByteToRead: specific byte length (max 65535)
void W25QXX_Read(uint8_t* pBuffer,uint32_t ReadAddr,uint16_t NumByteToRead)
{uint16_t i;W25QXX_CS(0);SPI2_ReadWriteByte(W25X_ReadData);                   //send read commandif((W25QXX_TYPE==W25Q256_ID)||(W25QXX_TYPE==W25Q512_ID)||(W25QXX_TYPE==W25Q1024_ID))  //send highest 8-bit address{SPI2_ReadWriteByte((uint8_t)((ReadAddr)>>24));}SPI2_ReadWriteByte((uint8_t)((ReadAddr)>>16));       //send 24-bit addressSPI2_ReadWriteByte((uint8_t)((ReadAddr)>>8));SPI2_ReadWriteByte((uint8_t)ReadAddr);for(i=0;i<NumByteToRead;i++){pBuffer[i]=SPI2_ReadWriteByte(0XFF);             //read data}W25QXX_CS(1);
}//Write W25QXX not more than 1 page (256 bytes)
//pBuffer: data buffer
//WriteAddr: specific address
//NumByteToWrite: specific byte length (max 256)
void W25QXX_Write_Page(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite)
{uint16_t i;W25QXX_Write_Enable();                                       //write enableW25QXX_CS(0);SPI2_ReadWriteByte(W25X_PageProgram);                        //send write commandif((W25QXX_TYPE==W25Q256_ID)||(W25QXX_TYPE==W25Q512_ID)||(W25QXX_TYPE==W25Q1024_ID)) //send highest 8-bit address{SPI2_ReadWriteByte((uint8_t)((WriteAddr)>>24));}SPI2_ReadWriteByte((uint8_t)((WriteAddr)>>16));               //send 24-bit addressSPI2_ReadWriteByte((uint8_t)((WriteAddr)>>8));SPI2_ReadWriteByte((uint8_t)WriteAddr);for(i=0;i<NumByteToWrite;i++)SPI2_ReadWriteByte(pBuffer[i]);  //write dataW25QXX_CS(1);W25QXX_Wait_Busy();
}//Write W25QXX w/o erase check and w/o byte number restriction
//pBuffer: data buffer
//WriteAddr: specific address
//NumByteToWrite: specific byte length (max 65535)
void W25QXX_Write_NoCheck(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite)
{uint16_t remained_byte_num_in_page;remained_byte_num_in_page=256-WriteAddr%256;                                                       //remained byte number in pageif( NumByteToWrite <= remained_byte_num_in_page ) remained_byte_num_in_page = NumByteToWrite;      //data can be written in single pagewhile(1){W25QXX_Write_Page(pBuffer,WriteAddr,remained_byte_num_in_page);if(NumByteToWrite==remained_byte_num_in_page)break;                                            //end write operationelse                                                                                           //NumByteToWrite>remained_byte_num_in_page{pBuffer+=remained_byte_num_in_page;WriteAddr+=remained_byte_num_in_page;NumByteToWrite-=remained_byte_num_in_page;if(NumByteToWrite>256)remained_byte_num_in_page=256;                                       //for whole page writeelse remained_byte_num_in_page=NumByteToWrite; 	                                           //for non-whole page write}};
}//Write W25QXX w/ erase after check and w/o byte number restriction
//pBuffer: data buffer
//WriteAddr: specific address
//NumByteToWrite: specific byte length (max 65535)
uint8_t W25QXX_BUFFER[4096];
void W25QXX_Write(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite)
{uint32_t secpos;uint16_t secoff;uint16_t secremain;uint16_t i;uint8_t * W25QXX_BUF;W25QXX_BUF=W25QXX_BUFFER;secpos=WriteAddr/4096;                                        //sector number (16 pages for 1 sector) for destination addresssecoff=WriteAddr%4096;                                        //offset address in sector for destination addresssecremain=4096-secoff;                                        //remained space for sectorif(NumByteToWrite<=secremain)secremain=NumByteToWrite;        //data can be written in single sectorwhile(1){W25QXX_Read(W25QXX_BUF,secpos*4096,4096);                 //read sector data for ease necessity judgmentfor(i=0;i<secremain;i++)                                  //check sector data status{if(W25QXX_BUF[secoff+i]!=0XFF) break;                 //ease necessary}if(i<secremain)                                           //for ease{W25QXX_Erase_Sector(secpos);                          //ease sectorfor(i=0;i<secremain;i++)	                          //data copy{W25QXX_BUF[i+secoff]=pBuffer[i];}W25QXX_Write_NoCheck(W25QXX_BUF,secpos*4096,4096);     //write sector}else W25QXX_Write_NoCheck(pBuffer,WriteAddr,secremain);   //write data for sector unnecessary to eraseif(NumByteToWrite==secremain)break;                        //for operation endelse                                                       //for operation continuing{secpos++;                                              //sector number + 1secoff=0;                                              //offset address from 0pBuffer+=secremain;                                    //pointer adjustmentWriteAddr+=secremain;                                  //write address adjustmentNumByteToWrite-=secremain;				               //write number adjustmentif(NumByteToWrite>4096) secremain=4096;	               //not last sectorelse secremain=NumByteToWrite;			               //last sector}};
}//Erase whole chip, long waiting...
void W25QXX_Erase_Chip(void)
{W25QXX_Write_Enable();                  //write enableW25QXX_Wait_Busy();W25QXX_CS(0);SPI2_ReadWriteByte(W25X_ChipErase);     //send erase commandW25QXX_CS(1);W25QXX_Wait_Busy();   				    //wait for erase complete
}//Erase one sector
//Sector_Num: sector number
void W25QXX_Erase_Sector(uint32_t Sector_Num)
{Sector_Num*=4096;W25QXX_Write_Enable();                                     //write enableW25QXX_Wait_Busy();W25QXX_CS(0);SPI2_ReadWriteByte(W25X_SectorErase);                      //send erase commandif((W25QXX_TYPE==W25Q256_ID)||(W25QXX_TYPE==W25Q512_ID)||(W25QXX_TYPE==W25Q1024_ID)) //send highest 8-bit address{SPI2_ReadWriteByte((uint8_t)((Sector_Num)>>24));}SPI2_ReadWriteByte((uint8_t)((Sector_Num)>>16));           //send 24-bit addressSPI2_ReadWriteByte((uint8_t)((Sector_Num)>>8));SPI2_ReadWriteByte((uint8_t)Sector_Num);W25QXX_CS(1);W25QXX_Wait_Busy();   				                       //wait for erase complete
}//Wait idle status before next operation
void W25QXX_Wait_Busy(void)
{while((W25QXX_ReadSR(1)&0x01)==0x01);    //wait for busy flag cleared
}//Enter power-down mode
#define tDP_us 3
void W25QXX_PowerDown(void)
{W25QXX_CS(0);SPI2_ReadWriteByte(W25X_PowerDown);      //send power-down commandW25QXX_CS(1);PY_Delay_us_t(tDP_us);                   //tDP
}
//Wake-up
#define tRES1_us 3
void W25QXX_WAKEUP(void)
{W25QXX_CS(0);SPI2_ReadWriteByte(W25X_ReleasePowerDown);//send release power-down commandW25QXX_CS(1);PY_Delay_us_t(tRES1_us);                  //tRES1
}

对ffconf.h添加包含信息:
在这里插入图片描述

#include "main.h"
#include "stm32h7xx_hal.h"

修改user_diskio.c,对文件操作函数与底层FLASH读写提供连接:

/* USER CODE BEGIN Header */
/********************************************************************************* @file    user_diskio.c* @brief   This file includes a diskio driver skeleton to be completed by the user.******************************************************************************* @attention** Copyright (c) 2023 STMicroelectronics.* All rights reserved.** This software is licensed under terms that can be found in the LICENSE file* in the root directory of this software component.* If no LICENSE file comes with this software, it is provided AS-IS.********************************************************************************//* USER CODE END Header */#ifdef USE_OBSOLETE_USER_CODE_SECTION_0
/** Warning: the user section 0 is no more in use (starting from CubeMx version 4.16.0)* To be suppressed in the future.* Kept to ensure backward compatibility with previous CubeMx versions when* migrating projects.* User code previously added there should be copied in the new user sections before* the section contents can be deleted.*/
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
#endif/* USER CODE BEGIN DECL */
/**************************SELF DEFINITION PART************/
#include "diskio.h"		/* Declarations of disk functions */
#include "W25QXX.h"
/**********************************************************/
/* Includes ------------------------------------------------------------------*/
#include <string.h>
#include "ff_gen_drv.h"/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*//* Private variables ---------------------------------------------------------*/
/* Disk status */
static volatile DSTATUS Stat = STA_NOINIT;/* USER CODE END DECL *//* Private function prototypes -----------------------------------------------*/
DSTATUS USER_initialize (BYTE pdrv);
DSTATUS USER_status (BYTE pdrv);
DRESULT USER_read (BYTE pdrv, BYTE *buff, DWORD sector, UINT count);
#if _USE_WRITE == 1DRESULT USER_write (BYTE pdrv, const BYTE *buff, DWORD sector, UINT count);
#endif /* _USE_WRITE == 1 */
#if _USE_IOCTL == 1DRESULT USER_ioctl (BYTE pdrv, BYTE cmd, void *buff);
#endif /* _USE_IOCTL == 1 */Diskio_drvTypeDef  USER_Driver =
{USER_initialize,USER_status,USER_read,
#if  _USE_WRITEUSER_write,
#endif  /* _USE_WRITE == 1 */
#if  _USE_IOCTL == 1USER_ioctl,
#endif /* _USE_IOCTL == 1 */
};/* Private functions ---------------------------------------------------------*//*** @brief  Initializes a Drive* @param  pdrv: Physical drive number (0..)* @retval DSTATUS: Operation status*/
DSTATUS USER_initialize (BYTE pdrv           /* Physical drive nmuber to identify the drive */
)
{/* USER CODE BEGIN INIT *//**************************SELF DEFINITION PART************/uint8_t res;res = W25QXX_Init();if(res) return RES_OK;else return  STA_NOINIT;/**********************************************************//*Stat = STA_NOINIT;return Stat;*//* USER CODE END INIT */
}/*** @brief  Gets Disk Status* @param  pdrv: Physical drive number (0..)* @retval DSTATUS: Operation status*/
DSTATUS USER_status (BYTE pdrv       /* Physical drive number to identify the drive */
)
{/* USER CODE BEGIN STATUS *//**************************SELF DEFINITION PART************/switch (pdrv){case 0 :return RES_OK;case 1 :return RES_OK;case 2 :return RES_OK;default:return STA_NOINIT;}/**********************************************************//*Stat = STA_NOINIT;return Stat;*//* USER CODE END STATUS */
}/*** @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 USER_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 */
)
{/* USER CODE BEGIN READ *//**************************SELF DEFINITION PART************/uint16_t len;if( !count ){return RES_PARERR;  /* count不能等于0,否则返回参数错误*/}switch (pdrv){case 0:sector <<= 9; //Convert sector number to byte addresslen = count*512;W25QXX_Read(buff, sector, len);return RES_OK;default:return RES_ERROR;}/**********************************************************//*return RES_OK;*//* USER CODE END READ */
}/*** @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 USER_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 */
)
{/* USER CODE BEGIN WRITE *//* USER CODE HERE *//**************************SELF DEFINITION PART************/uint16_t len;if( !count ){return RES_PARERR;  /* count不能等于0,否则返回参数错误*/}switch (pdrv){case 0:sector <<= 9; //Convert sector number to byte addresslen = count*512;W25QXX_Write((uint8_t *)buff, sector, len);return RES_OK;default:return RES_ERROR;}/*********************************************************//*return RES_OK;*//* USER CODE END WRITE */
}
#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 USER_ioctl (BYTE pdrv,      /* Physical drive nmuber (0..) */BYTE cmd,       /* Control code */void *buff      /* Buffer to send/receive control data */
)
{/* USER CODE BEGIN IOCTL *//**************************SELF DEFINITION PART************/#define user_sector_byte_size 512DRESULT res;switch(cmd){case CTRL_SYNC:W25QXX_Wait_Busy();res=RES_OK;break;case GET_SECTOR_SIZE:*(WORD*)buff = user_sector_byte_size;res = RES_OK;break;case GET_BLOCK_SIZE:*(WORD*)buff = 4096/user_sector_byte_size;res = RES_OK;break;case GET_SECTOR_COUNT:W25QXX_TYPE=W25QXX_ReadID();if(W25QXX_TYPE==W25Q80_ID) *(DWORD*)buff = (8*1024*1024/512);else if(W25QXX_TYPE==W25Q16_ID) *(DWORD*)buff = (16*1024*1024/512);else if(W25QXX_TYPE==W25Q32_ID) *(DWORD*)buff = (32*1024*1024/512);else if(W25QXX_TYPE==W25Q64_ID) *(DWORD*)buff = (64*1024*1024/512);else if(W25QXX_TYPE==W25Q128_ID) *(DWORD*)buff = (128*1024*1024/512);else if(W25QXX_TYPE==W25Q256_ID) *(DWORD*)buff = (256*1024*1024/512);else if(W25QXX_TYPE==W25Q512_ID) *(DWORD*)buff = (512*1024*1024/512);else if(W25QXX_TYPE==W25Q1024_ID) *(DWORD*)buff = (1024*1024*1024/512);else *(DWORD*)buff = (8*1024*1024/512);res = RES_OK;break;default:res = RES_PARERR;break;}return res;/**********************************************************//*DRESULT res = RES_ERROR;return res;*//* USER CODE END IOCTL */
}
#endif /* _USE_IOCTL == 1 */

然后在main.c里根据串口输入命令(16进制单字节)实现如下功能:
0x01. 读取FLASH ID
0x02. 装载FATS文件系统
0x03: 创建/打开文件并从头位置写入数据
0x04: 打开文件并从头位置读入数据
0x05: 创建/打开文件并从特定位置写入数据
0x06: 打开文件并从特定位置读入数据
完整的代码实现如下:

/* USER CODE BEGIN Header */
/********************************************************************************* @file           : main.c* @brief          : Main program body******************************************************************************* @attention** Copyright (c) 2023 STMicroelectronics.* All rights reserved.** This software is licensed under terms that can be found in the LICENSE file* in the root directory of this software component.* If no LICENSE file comes with this software, it is provided AS-IS.********************************************************************************/
//Written by Pegasus Yu in 2023
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "fatfs.h"/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "usart.h"
#include "W25QXX.h"
#include <string.h>
/* USER CODE END Includes *//* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
__IO float usDelayBase;
void PY_usDelayTest(void)
{__IO uint32_t firstms, secondms;__IO uint32_t counter = 0;firstms = HAL_GetTick()+1;secondms = firstms+1;while(uwTick!=firstms) ;while(uwTick!=secondms) counter++;usDelayBase = ((float)counter)/1000;
}void PY_Delay_us_t(uint32_t Delay)
{__IO uint32_t delayReg;__IO uint32_t usNum = (uint32_t)(Delay*usDelayBase);delayReg = 0;while(delayReg!=usNum) delayReg++;
}void PY_usDelayOptimize(void)
{__IO uint32_t firstms, secondms;__IO float coe = 1.0;firstms = HAL_GetTick();PY_Delay_us_t(1000000) ;secondms = HAL_GetTick();coe = ((float)1000)/(secondms-firstms);usDelayBase = coe*usDelayBase;
}void PY_Delay_us(uint32_t Delay)
{__IO uint32_t delayReg;__IO uint32_t msNum = Delay/1000;__IO uint32_t usNum = (uint32_t)((Delay%1000)*usDelayBase);if(msNum>0) HAL_Delay(msNum);delayReg = 0;while(delayReg!=usNum) delayReg++;
}
/* USER CODE END PTD *//* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD *//* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM *//* USER CODE END PM *//* Private variables ---------------------------------------------------------*/SPI_HandleTypeDef hspi2;UART_HandleTypeDef huart1;/* USER CODE BEGIN PV */
uint8_t uart1_rx[16];
uint8_t cmd;uint8_t Flash_mount_status = 0; //FLASH fats mount status indication (0: unmount; 1: mount)
uint8_t FATS_Buff[_MAX_SS]; //Buffer for f_mkfs() operationFRESULT retFLASH;
FIL file;
FATFS *fs;UINT bytesread;
UINT byteswritten;
uint8_t rBuffer[20];      //Buffer for read
uint8_t WBuffer[20] ={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20}; //Buffer for write#define user_sector_byte_size 512
uint8_t flashbuffer[user_sector_byte_size];extern char USERPath[4];
/* USER CODE END PV *//* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
void PeriphCommonClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_USART1_UART_Init(void);
static void MX_SPI2_Init(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 */Flash_mount_status = 0;uint32_t FLASH_Read_Size;extern char USERPath[4];char * dpath = "0:"; //Disk Pathfor(uint8_t i=0; i<4; i++){USERPath[i] = *(dpath+i);}const TCHAR* filepath = "0:test.txt";/* 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();/* Configure the peripherals common clocks */PeriphCommonClock_Config();/* USER CODE BEGIN SysInit *//* USER CODE END SysInit *//* Initialize all configured peripherals */MX_GPIO_Init();MX_USART1_UART_Init();MX_SPI2_Init();MX_FATFS_Init();/* USER CODE BEGIN 2 */PY_usDelayTest();PY_usDelayOptimize();HAL_UART_Receive_IT(&huart1, uart1_rx, 1);W25QXX_Init();/* USER CODE END 2 *//* Infinite loop *//* USER CODE BEGIN WHILE */while (1){if(cmd==1) //Read ID{cmd = 0;printf("FLASH ID=0x%x\r\n\r\n", W25QXX_ReadID());printf("W25Q80_ID: 0XEF13\r\n");printf("W25Q16_ID: 0XEF14\r\n");printf("W25Q32_ID: 0XEF15\r\n");printf("W25Q64_ID: 0XEF16\r\n");printf("W25Q128_ID: 0XEF17\r\n");printf("W25Q256_ID: 0XEF18\r\n");printf("W25Q512_ID: 0XEF18\r\n");printf("W25Q1024_ID: 0XEF20\r\n");}else if(cmd==2) //Flash File System Mount{cmd = 0;retFLASH=f_mount(&USERFatFS, (TCHAR const*)USERPath, 1);if (retFLASH != FR_OK){printf("File system mount failure: %d\r\n", retFLASH);if(retFLASH==FR_NO_FILESYSTEM){printf("No file system. Now to format......\r\n");retFLASH = f_mkfs((TCHAR const*)USERPath, FM_FAT, 1024, FATS_Buff, sizeof(FATS_Buff)); //FLASH formattingif(retFLASH == FR_OK){printf("FLASH formatting success!\r\n");}else{printf("FLASH formatting failure!\r\n");}}}else{Flash_mount_status = 1;printf("File system mount success\r\n");}}else if(cmd==3) //File creation and write{cmd = 0;if(Flash_mount_status==0) printf("\r\nFLASH File system not mounted: %d\r\n",retFLASH);else{retFLASH = f_open( &file, filepath, FA_CREATE_ALWAYS | FA_WRITE );  //Open or create fileif(retFLASH == FR_OK){printf("\r\nFile open or creation successful\r\n");retFLASH = f_write( &file, (const void *)WBuffer, sizeof(WBuffer), &byteswritten); //Write dataif(retFLASH == FR_OK){printf("\r\nFile write successful\r\n");}else{printf("\r\nFile write error: %d\r\n",retFLASH);}f_close(&file);   //Close file}else{printf("\r\nFile open or creation error %d\r\n",retFLASH);}}}else if(cmd==4) //File read{cmd = 0;if(Flash_mount_status==0) printf("\r\nFLASH File system not mounted: %d\r\n",retFLASH);else{retFLASH = f_open( &file, filepath, FA_OPEN_EXISTING | FA_READ); //Open fileif(retFLASH == FR_OK){printf("\r\nFile open successful\r\n");retFLASH = f_read( &file, (void *)rBuffer, sizeof(rBuffer), &bytesread); //Read dataif(retFLASH == FR_OK){printf("\r\nFile read successful\r\n");PY_Delay_us_t(200000);FLASH_Read_Size = sizeof(rBuffer);for(uint16_t i = 0;i < FLASH_Read_Size;i++){printf("%d ", rBuffer[i]);}printf("\r\n");}else{printf("\r\nFile read error: %d\r\n", retFLASH);}f_close(&file); //Close file}else{printf("\r\nFile open error: %d\r\n", retFLASH);}}}else if(cmd==5) //File locating write{cmd = 0;if(Flash_mount_status==0) printf("\r\nFLASH File system not mounted: %d\r\n",retFLASH);else{retFLASH = f_open( &file, filepath, FA_CREATE_ALWAYS | FA_WRITE);  //Open or create fileif(retFLASH == FR_OK){printf("\r\nFile open or creation successful\r\n");retFLASH=f_lseek( &file, f_tell(&file) + sizeof(WBuffer) ); //move file operation pointer, f_tell(&file) gets file head locatingif(retFLASH == FR_OK){retFLASH = f_write( &file, (const void *)WBuffer, sizeof(WBuffer), &byteswritten);if(retFLASH == FR_OK){printf("\r\nFile locating write successful\r\n");}else{printf("\r\nFile locating write error: %d\r\n", retFLASH);}}else{printf("\r\nFile pointer error: %d\r\n",retFLASH);}f_close(&file);   //Close file}else{printf("\r\nFile open or creation error %d\r\n",retFLASH);}}}else if(cmd==6) //File locating read{cmd = 0;if(Flash_mount_status==0) printf("\r\nFLASH File system not mounted: %d\r\n",retFLASH);else{retFLASH = f_open(&file, filepath, FA_OPEN_EXISTING | FA_READ); //Open fileif(retFLASH == FR_OK){printf("\r\nFile open successful\r\n");retFLASH =  f_lseek(&file,f_tell(&file)+ sizeof(WBuffer)/2); //move file operation pointer, f_tell(&file) gets file head locatingif(retFLASH == FR_OK){retFLASH = f_read( &file, (void *)rBuffer, sizeof(rBuffer), &bytesread);if(retFLASH == FR_OK){printf("\r\nFile locating read successful\r\n");PY_Delay_us_t(200000);FLASH_Read_Size = sizeof(rBuffer);for(uint16_t i = 0;i < FLASH_Read_Size;i++){printf("%d ",rBuffer[i]);}printf("\r\n");}else{printf("\r\nFile locating read error: %d\r\n",retFLASH);}}else{printf("\r\nFile pointer error: %d\r\n",retFLASH);}f_close(&file);}else{printf("\r\nFile open error: %d\r\n",retFLASH);}}}/* 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};/** Supply configuration update enable*/HAL_PWREx_ConfigSupply(PWR_LDO_SUPPLY);/** Configure the main internal regulator output voltage*/__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}__HAL_RCC_SYSCFG_CLK_ENABLE();__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE0);while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}/** Initializes the RCC Oscillators according to the specified parameters* in the RCC_OscInitTypeDef structure.*/RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;RCC_OscInitStruct.HSIState = RCC_HSI_DIV1;RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;RCC_OscInitStruct.PLL.PLLM = 4;RCC_OscInitStruct.PLL.PLLN = 60;RCC_OscInitStruct.PLL.PLLP = 2;RCC_OscInitStruct.PLL.PLLQ = 2;RCC_OscInitStruct.PLL.PLLR = 2;RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_3;RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE;RCC_OscInitStruct.PLL.PLLFRACN = 0;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_CLOCKTYPE_D3PCLK1|RCC_CLOCKTYPE_D1PCLK1;RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1;RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV2;RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV2;RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV2;RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV2;RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV2;if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK){Error_Handler();}
}/*** @brief Peripherals Common Clock Configuration* @retval None*/
void PeriphCommonClock_Config(void)
{RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};/** Initializes the peripherals clock*/PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_CKPER;PeriphClkInitStruct.CkperClockSelection = RCC_CLKPSOURCE_HSI;if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK){Error_Handler();}
}/*** @brief SPI2 Initialization Function* @param None* @retval None*/
static void MX_SPI2_Init(void)
{/* USER CODE BEGIN SPI2_Init 0 *//* USER CODE END SPI2_Init 0 *//* USER CODE BEGIN SPI2_Init 1 *//* USER CODE END SPI2_Init 1 *//* SPI2 parameter configuration*/hspi2.Instance = SPI2;hspi2.Init.Mode = SPI_MODE_MASTER;hspi2.Init.Direction = SPI_DIRECTION_2LINES;hspi2.Init.DataSize = SPI_DATASIZE_8BIT;hspi2.Init.CLKPolarity = SPI_POLARITY_LOW;hspi2.Init.CLKPhase = SPI_PHASE_1EDGE;hspi2.Init.NSS = SPI_NSS_SOFT;hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;hspi2.Init.TIMode = SPI_TIMODE_DISABLE;hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;hspi2.Init.CRCPolynomial = 0x0;hspi2.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;hspi2.Init.NSSPolarity = SPI_NSS_POLARITY_LOW;hspi2.Init.FifoThreshold = SPI_FIFO_THRESHOLD_01DATA;hspi2.Init.TxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;hspi2.Init.RxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;hspi2.Init.MasterSSIdleness = SPI_MASTER_SS_IDLENESS_00CYCLE;hspi2.Init.MasterInterDataIdleness = SPI_MASTER_INTERDATA_IDLENESS_00CYCLE;hspi2.Init.MasterReceiverAutoSusp = SPI_MASTER_RX_AUTOSUSP_DISABLE;hspi2.Init.MasterKeepIOState = SPI_MASTER_KEEP_IO_STATE_DISABLE;hspi2.Init.IOSwap = SPI_IO_SWAP_DISABLE;if (HAL_SPI_Init(&hspi2) != HAL_OK){Error_Handler();}/* USER CODE BEGIN SPI2_Init 2 *//* USER CODE END SPI2_Init 2 */}/*** @brief USART1 Initialization Function* @param None* @retval None*/
static void MX_USART1_UART_Init(void)
{/* USER CODE BEGIN USART1_Init 0 *//* USER CODE END USART1_Init 0 *//* USER CODE BEGIN USART1_Init 1 *//* USER CODE END USART1_Init 1 */huart1.Instance = USART1;huart1.Init.BaudRate = 115200;huart1.Init.WordLength = UART_WORDLENGTH_8B;huart1.Init.StopBits = UART_STOPBITS_1;huart1.Init.Parity = UART_PARITY_NONE;huart1.Init.Mode = UART_MODE_TX_RX;huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;huart1.Init.OverSampling = UART_OVERSAMPLING_16;huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;huart1.Init.ClockPrescaler = UART_PRESCALER_DIV1;huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;if (HAL_UART_Init(&huart1) != HAL_OK){Error_Handler();}if (HAL_UARTEx_SetTxFifoThreshold(&huart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK){Error_Handler();}if (HAL_UARTEx_SetRxFifoThreshold(&huart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK){Error_Handler();}if (HAL_UARTEx_DisableFifoMode(&huart1) != HAL_OK){Error_Handler();}/* USER CODE BEGIN USART1_Init 2 *//* USER CODE END USART1_Init 2 */}/*** @brief GPIO Initialization Function* @param None* @retval None*/
static void MX_GPIO_Init(void)
{GPIO_InitTypeDef GPIO_InitStruct = {0};/* GPIO Ports Clock Enable */__HAL_RCC_GPIOB_CLK_ENABLE();__HAL_RCC_GPIOA_CLK_ENABLE();/*Configure GPIO pin Output Level */HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_SET);/*Configure GPIO pin : PB12 */GPIO_InitStruct.Pin = GPIO_PIN_12;GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;GPIO_InitStruct.Pull = GPIO_NOPULL;GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);}/* USER CODE BEGIN 4 */
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{if(huart==&huart1){cmd = uart1_rx[0];HAL_UART_Receive_IT(&huart1, uart1_rx, 1);}}
/* 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 */

STM32例程测试

串口指令0x01测试效果如下:
在这里插入图片描述
串口指令0x02测试效果如下:
在这里插入图片描述
串口指令0x03测试效果如下:
在这里插入图片描述
串口指令0x04测试效果如下:
在这里插入图片描述串口指令0x05测试效果如下:
在这里插入图片描述
串口指令0x06测试效果如下:
在这里插入图片描述

STM32例程下载

STM32H750VBT6 SPI总线FATS文件读写FLASH W25QXX例程下载

–End–

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/198401.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

好莱坞罢工事件!再次警醒人类重视AI监管,人工智能矛盾一触即发!

原创 | 文 BFT机器人 关注国外新闻的应该都知道&#xff0c;最近焦点新闻是好莱坞史上最大规模的一场罢工运动。这场维持118天的罢工运动&#xff0c;终于在11月9号早上12点在好莱坞宣布结束。这场罢工运动虽是演员工会和代表资方的影视制片人联盟的茅盾&#xff0c;但直接引发…

求二叉树的高度(可运行)

输入二叉树为&#xff1a;ABD##E##C##。 运行环境&#xff1a;main.cpp 运行结果&#xff1a;3 #include "bits/stdc.h" using namespace std; typedef struct BiTNode{char data;struct BiTNode *lchild,*rchild;int tag; }BiTNode,*BiTree;void createTree(BiTre…

【数据结构】详解链表结构

目录 引言一、链表的介绍二、链表的几种分类三、不带头单链表的一些常用接口3.1 动态申请一个节点3.2 尾插数据3.3 头插数据3.4 尾删数据3.5 头删数据3.6 查找数据3.7 pos位置后插入数据3.8 删除pos位置数据3.9 释放空间 四、带头双向链表的常见接口4.1创建头节点&#xff08;初…

有趣的按钮分享

前些天发现了一个巨牛的人工智能学习网站&#xff0c;通俗易懂&#xff0c;风趣幽默&#xff0c;忍不住分享一下给大家。点击跳转到网站。 广告打完&#xff0c;我们进入正题&#xff0c;先看效果&#xff1a; 废话不多&#xff0c;上源码&#xff1a; <button class&quo…

【LeetCode刷题日志】232.用栈实现队列

&#x1f388;个人主页&#xff1a;库库的里昂 &#x1f390;C/C领域新星创作者 &#x1f389;欢迎 &#x1f44d;点赞✍评论⭐收藏✨收录专栏&#xff1a;LeetCode 刷题日志&#x1f91d;希望作者的文章能对你有所帮助&#xff0c;有不足的地方请在评论区留言指正&#xff0c;…

竞赛 题目:基于机器视觉opencv的手势检测 手势识别 算法 - 深度学习 卷积神经网络 opencv python

文章目录 1 简介2 传统机器视觉的手势检测2.1 轮廓检测法2.2 算法结果2.3 整体代码实现2.3.1 算法流程 3 深度学习方法做手势识别3.1 经典的卷积神经网络3.2 YOLO系列3.3 SSD3.4 实现步骤3.4.1 数据集3.4.2 图像预处理3.4.3 构建卷积神经网络结构3.4.4 实验训练过程及结果 3.5 …

负载均衡简介

负载均衡 负载均衡&#xff08;Load Balance&#xff0c;简称 LB&#xff09;是高并发、高可用系统必不可少的关键组件&#xff0c;目标是 尽力将网络流量平均分发到多个服务器上&#xff0c;以提高系统整体的响应速度和可用性。 负载均衡的分类和OSI模型息息相关&#xff0c…

【广州华锐互动】VR可视化政务服务为公众提供更直观、形象的政策解读

虚拟现实&#xff08;VR&#xff09;技术正在逐渐应用于政务服务领域&#xff0c;为公众提供更加便捷、高效和个性化的服务体验。通过VR眼镜、手机等设备&#xff0c;公众可以在虚拟环境中参观政务服务中心&#xff0c;并根据自己的需求选择不同的办事窗口或事项进行咨询和办理…

03 前后端数据交互【小白入门SpringBoot + Vue3】

项目笔记&#xff0c;教学视频来源于B站青戈 https://www.bilibili.com/video/BV1H14y1S7YV 前两个笔记。是把前端页面大致做出来&#xff0c;接下来&#xff0c;把后端项目搞一下。 后端项目&#xff0c;使用IDEA软件、jdk1.8、springboot2.x 。基本上用的是稳定版。 还有My…

【Linux】vscode远程连接ubuntu失败

VSCode远程连接ubuntu服务器 这部分网上有很多&#xff0c;都烂大街了&#xff0c;自己搜吧。给个参考连接&#xff1a;VSCode远程连接ubuntu服务器 注意&#xff0c;这里我提前设置了免密登录。至于怎么设置远程免密登录&#xff0c;可以看其它帖子&#xff0c;比如这个。 …

51单片机应用

目录 ​编辑 1. C51的数据类型 1.1 C51中的基本数据类型 1.2 特殊功能寄存器类型 2. C51的变量 2.1 存储种类 1. C51的数据类型 C51是一种基于8051架构的单片机&#xff0c;它支持以下基本数据类型&#xff1a; 位&#xff08;Bit&#xff09;&#xff1a;可以表…

WSL 2 更改默认安装的 Linux 发行版

目录 什么是 WSL 2&#xff1f;更改默认安装的 Linux 发行版更改发行版的 WSL 版本 什么是 WSL 2&#xff1f; WSL 2 是适用于 Linux 的 Windows 子系统体系结构的一个新版本&#xff0c;它支持适用于 Linux 的 Windows 子系统在 Windows 上运行 ELF64 Linux 二进制文件。 它的…

单元测试实战(四)MyBatis-Plus 的测试

为鼓励单元测试&#xff0c;特分门别类示例各种组件的测试代码并进行解说&#xff0c;供开发人员参考。 本文中的测试均基于JUnit5。 单元测试实战&#xff08;一&#xff09;Controller 的测试 单元测试实战&#xff08;二&#xff09;Service 的测试 单元测试实战&am…

Flutter 使用 device_info_plus 遇到的问题

问题&#xff1a;引用device_info_plus 插件出现了异常&#xff0c;不知道为啥打开项目的时候就不能用了。 解决&#xff1a;改了版本解决 Target of URI doesnt exist: package:device_info_plus/device_info_plus.dart. (Documentation) Try creating the file reference…

react antd下拉选择框选项内容换行

下拉框选项字太多&#xff0c;默认样式是超出就省略号&#xff0c;需求要换行全展示&#xff0c;选完在选择框里还是要省略的 .less: .aaaDropdown {:global {.ant-select-dropdown-menu-item {white-space: pre-line !important;word-break: break-all !important;}} } html…

uniapp 手动调用form表单submit事件

背景&#xff1a; UI把提交的按钮弄成了图片&#xff0c;之前的button不能用了。 <button form-type"submit">搜索</button> 实现&#xff1a; html&#xff1a; 通过 this.$refs.fd 获取到form的vue对象。手动调用里面的_onSubmit()方法。 methods:…

STM32CubeMX学习笔记-CAN接口使用

STM32CubeMX学习笔记-CAN接口使用 CAN总线传输协议1.CAN 总线传输特点2.位时序和波特率3.帧的种类4.标准格式数据帧和遥控帧从STM32F407参考手册中可以看出主要特性如下CAN模块基本控制函数CAN模块消息发送CAN模块消息接收标识符筛选发送中断的事件源和回调函数 CubeMX项目设置…

OpenAI 地震!首席执行官被解雇,背后的原因是?

11月17日&#xff0c;ChatGPT的制造商OpenAI表示&#xff0c;经过审查后发现联合创始人兼首席执行官 Sam Altman与董事会“沟通时并不一贯坦诚”&#xff0c;因此公司已经决定解雇他。这家人工智能&#xff08;AI&#xff09;公司在一份声明中表示&#xff1a;“董事会不再相信…

基于深度学习的单帧图像超分辨率重建综述

论文标题&#xff1a;基于深度学习的单帧图像超分辨率重建综述作者&#xff1a; 吴 靖&#xff0c;叶晓晶&#xff0c;黄 峰&#xff0c;陈丽琼&#xff0c;王志锋&#xff0c;刘文犀发表日期&#xff1a;2022 年9 月阅读日期 &#xff1a;2023.11.18研究背景&#xff1a; 图像…

一款实用的.NET Core加密解密工具类库

前言 在我们日常开发工作中&#xff0c;为了数据安全问题对数据加密、解密是必不可少的。加密方式有很多种如常见的AES&#xff0c;RSA&#xff0c;MD5&#xff0c;SAH1&#xff0c;SAH256&#xff0c;DES等&#xff0c;这时候假如我们有一个封装的对应加密解密工具类可以直接…