SPI_FLASH_SECTOR_ERASE

时间: 2025-04-07 10:19:59 浏览: 41
<think>好的,我现在需要回答用户关于SPI Flash扇区擦除操作及实现细节的问题。首先,我得回顾一下用户提供的引用内容,里面提到AT26DF Flash芯片的驱动模块,以及SPI操作的基本时序:拉低CS引脚,发送8位操作码和相关信息,再拉高CS引脚。用户的问题集中在扇区擦除的具体步骤和实现细节上。 首先,我需要明确SPI Flash的基本操作流程。扇区擦除通常是擦除某个特定扇区的数据,为写入新数据做准备。擦除操作需要特定的命令,用户可能想知道具体的操作码、地址发送方式以及时序要求。 根据常见的SPI Flash操作,扇区擦除一般使用Sector Erase命令,比如0x20或0xD8,但不同厂商可能有不同的操作码。例如,AT25系列可能用0x20,而Winbond的芯片可能用0x20或0xD8,具体要看数据手册。需要确认AT26DF的具体命令,可能需要查阅其数据手册,但用户提供的引用没有详细说明,这里可能需要假设或给出通用流程。 接下来,地址的发送方式。SPI Flash通常使用24位地址,即3个字节,高位先发。例如,要擦除扇区地址为0x123456,那么发送的三个字节是0x12、0x34、0x56。但有些芯片可能支持32位地址,这取决于容量。AT26DF属于哪个类型?假设是24位地址,因为早期的Flash通常如此。 然后是时序问题。在发送命令和地址之前,需要确保设备未被写保护,即检查状态寄存器的WEL位是否置1。因此,在发送擦除命令前,可能需要先发送写使能命令(0x06)。此外,擦除操作可能需要一定的时间,期间状态寄存器中的BUSY位会被置1,主机需要轮询或等待完成。 实现细节方面,代码示例可能会有帮助。比如,在嵌入式系统中,如何通过SPI发送命令、地址,以及处理状态寄存器。可能需要拉低CS,发送操作码,发送地址,拉高CS,然后等待擦除完成。 还要考虑扇区的大小。不同的Flash芯片扇区大小不同,常见的有4KB、32KB、64KB等。用户需要知道擦除的扇区大小,以确保正确操作。例如,AT26DF可能每个扇区是4KB,所以擦除地址应对齐到4KB边界。 另外,安全措施也很重要,比如在擦除前检查地址是否有效,避免误擦除。同时,电源稳定性在擦除过程中很关键,突然断电可能导致数据损坏或设备故障。 现在需要组织这些信息,按照用户的要求,结构清晰,分步骤说明,并生成相关问题。同时,引用用户提供的参考信息,特别是关于SPI时序的部分,即拉低CS,发送操作码和信息,再拉高CS的部分。需要确保LaTeX格式正确,行内公式用$...$,独立公式用$$...$$,并且用中文回答。 可能需要检查是否有遗漏的步骤,比如是否需要先发送写使能命令,擦除命令的具体操作码,地址发送顺序,以及状态寄存器的轮询方法。此外,是否需要考虑SPI的模式(如模式0或3),但用户的问题可能不需要涉及那么底层,除非用户特别指出。 最后,生成相关的问题,例如不同擦除命令的区别、擦除时间的影响因素、如何确保擦除完成等。</think>### SPI Flash扇区擦除操作详解 #### 1. 基本操作时序 SPI Flash扇区擦除遵循标准SPI指令时序[^1]: 1. 拉低CS引脚启动通信 2. 发送8位擦除操作码 3. 发送24位地址(3字节) 4. 拉高CS引脚完成指令传输 典型擦除命令格式: $$ \text{操作码}(1B) + \text{地址}(3B) $$ #### 2. 关键参数说明 | 参数 | 典型值 | 说明 | |---------------|-------------|-------------------------| | 操作码 | 0x20/0xD8 | 常见擦除指令(具体需查数据手册)| | 地址格式 | 24位大端模式 | 如地址0x123456对应[0x12,0x34,0x56]| | 扇区大小 | 4KB/32KB/64KB | 需对齐地址边界 | | 擦除时间 | 100ms-3s | 与芯片工艺和容量相关 | #### 3. 实现步骤 1. **写使能**:先发送WREN(0x06)指令 ```c // 示例代码片段 spi_write(0x06); // 发送写使能命令 ``` 2. **发送擦除命令**: ```c uint8_t cmd[4] = {0x20, 0x00, 0x30, 0x00}; // 示例擦除0x003000扇区 spi_write(cmd, 4); ``` 3. **等待擦除完成**: ```c do { spi_write(0x05); // 读状态寄存器 status = spi_read(); } while(status & 0x01); // 检查BUSY位 ``` #### 4. 重要注意事项 - 地址必须对齐扇区边界(如4KB对齐地址末12位需为0) - 擦除前需确保WP#引脚为高电平解除写保护 - 操作期间供电需稳定(波动可能导致数据损坏) - 擦除后所有位变为1(即存储值为0xFF)
阅读全文

相关推荐

void shangdian(void) { // 1. 从Flash读取当前ID spi_flash_buffer_read((uint8_t*)&sys_config.log_file_id, 0x7E000, sizeof(sys_config.log_file_id)); // 2. 处理首次使用情况(全FF表示未初始化) if(sys_config.log_file_id == 0xFFFFFFFF) { sys_config.log_file_id = 0; } // 3. ID递增 sys_config.log_file_id++; // 4. 擦除扇区并写入新ID spi_flash_sector_erase(0x7E000); delay_ms(10); // 等待擦除完成 spi_flash_buffer_write((uint8_t*)&sys_config.log_file_id, 0x7E000, sizeof(sys_config.log_file_id)); delay_ms(10); // 等待写入完成 // 5. 打印新ID printf("New Log File ID: %lu\n", sys_config.log_file_id); } // 全局变量 uint32_t sample_cycle = CYCLE_5S; // 当前采样周期,单位秒 uint8_t hide_mode = 0; // 隐藏模式标志 /************************ 函数定义 ************************/ ErrStatus memory_compare(uint8_t* src,uint8_t* dst,uint16_t length); void nvic_config(void); void write_file(void); void create_required_folders(void); // 创建文件夹 void store_log_entry(const char *action); /************************ 存储日志文件 ************************/ void store_log_entry(const char *action) { static uint8_t log_initialized = 0; char filename[50]; // 当前文件名缓存 /* 上电时创建新日志文件 */ if (!log_initialized) { sprintf(filename, "log/log%lu.txt", sys_config.log_file_id); f_mkdir("log"); if (f_open(&log_file, filename, FA_CREATE_ALWAYS | FA_WRITE) == FR_OK) { log_file_open = 1; log_initialized = 1; } /* 写入初始信息 */ if (log_file_open) { rtc_time_t current_time; rtc_current_time_get(&rtc_initpara); char header[128]; sprintf(header, "System started at 20%02d-%02d-%02d %02d:%02d:%02d\r\n", current_time.year, current_time.month, current_time.day, current_time.hour, current_time.minute, current_time.second); UINT bw; f_write(&log_file, header, strlen(header), &bw); f_sync(&log_file); } } /* 写入日志条目 */ if (log_file_open) { rtc_time_t current_time; rtc_current_time_get(&rtc_initpara); char log_entry[128]; sprintf(log_entry, "[20%02d-%02d-%02d %02d:%02d:%02d] %s\r\n", current_time.year, current_time.month, current_time.day, current_time.hour, current_time.minute, current_time.second, action); UINT bw; f_write(&log_file, log_entry, strlen(log_entry), &bw); f_sync(&log_file); } } /************************ 保存config文件到flash************************/ void save_config_to_flash(void){ uint32_t sector_addr = target_addr & ~(SECTOR_SIZE - 1); uint16_t size = sizeof(sys_config); // 擦除目标扇区 spi_flash_write_enable(); // 使能写操作 spi_flash_sector_erase(sector_addr); spi_flash_wait_for_write_end(); // 等待擦除完成 // 写入数据 spi_flash_write_enable(); // 再次使能写操作 spi_flash_buffer_write((uint8_t*)&sys_config, target_addr, size); spi_flash_wait_for_write_end(); // 等待写入完成 } /************************************************************ * Function : System_Init * Comment : 用于初始化MCU * Parameter: null * Return : null * Author : Lingyu Meng * Date : 2025-02-30 V0.1 original ************************************************************/ void System_Init(void) { systick_config(); // 时钟配置 nvic_config(); // 配置中断控制器 KEY_Init(); // KEY初始化 LED_Init(); USART0_Config(); // 串口初始化 nvic_irq_enable(USART0_IRQn, 0, 0); // 使能USART0中断 usart_interrupt_enable(USART0, USART_INT_RBNE); // 接收中断打开 ADC_port_init(); // ADC初始化 OLED_Init(); TF_Init(); spi_flash_init(); // 初始化SPI Flash RTC_Init(); /* 初始化日志 */ shangdian(); // 每次上电递增 save_config_to_flash(); // 保存新的文件ID store_log_entry("System started"); // 从Flash读取保存的采样周期 uint32_t saved_cycle; spi_flash_buffer_read((uint8_t*)&saved_cycle, SAMPLE_CYCLE_ADDR, sizeof(uint32_t)); // 验证读取的值是否有效 if (saved_cycle == CYCLE_5S || saved_cycle == CYCLE_10S || saved_cycle == CYCLE_15S) { sample_cycle = saved_cycle; // printf("Loaded saved sample cycle: %d s\r\n", sample_cycle); } else { // 无效值,使用默认5秒 sample_cycle = CYCLE_5S; // printf("Using default sample cycle: %d s\r\n", sample_cycle); // 保存默认值到Flash spi_flash_sector_erase(SAMPLE_CYCLE_ADDR); spi_flash_buffer_write((uint8_t*)&sample_cycle, SAMPLE_CYCLE_ADDR, sizeof(uint32_t)); } // 读取队伍编号 Team_num(); delay_1ms(10); }上电sys_config.log_file_id自增现在有问题,检测ft卡中log文件夹无文件时sys_config.log_file_id=0,然后上电自增

SPI_InitTypeDef SPI_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; /* 使能SPI时钟 */ FLASH_SPI_APBxClock_FUN ( FLASH_SPI_CLK, ENABLE ); /* 使能SPI引脚相关的时钟 */ FLASH_SPI_CS_APBxClock_FUN ( FLASH_SPI_CS_CLK|FLASH_SPI_SCK_CLK| FLASH_SPI_MISO_PIN|FLASH_SPI_MOSI_PIN, ENABLE ); /* 配置SPI的 CS引脚,普通IO即可 */ GPIO_InitStructure.GPIO_Pin = FLASH_SPI_CS_PIN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(FLASH_SPI_CS_PORT, &GPIO_InitStructure); /* 配置SPI的 SCK引脚*/ GPIO_InitStructure.GPIO_Pin = FLASH_SPI_SCK_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(FLASH_SPI_SCK_PORT, &GPIO_InitStructure); /* 配置SPI的 MISO引脚*/ GPIO_InitStructure.GPIO_Pin = FLASH_SPI_MISO_PIN; GPIO_Init(FLASH_SPI_MISO_PORT, &GPIO_InitStructure); /* 配置SPI的 MOSI引脚*/ GPIO_InitStructure.GPIO_Pin = FLASH_SPI_MOSI_PIN; GPIO_Init(FLASH_SPI_MOSI_PORT, &GPIO_InitStructure); /* 停止信号 FLASH: CS引脚高电平*/ SPI_FLASH_CS_HIGH(); /* SPI 模式配置 */ // FLASH芯片 支持SPI模式0及模式3,据此设置CPOL CPHA SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; SPI_InitStructure.SPI_Mode = SPI_Mode_Master; //主机的宏 SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; SPI_InitStructure.SPI_CPOL = SPI_CPOL_High; SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4; SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; SPI_InitStructure.SPI_CRCPolynomial = 7; SPI_Init(FLASH_SPIx , &SPI_InitStructure); /* 使能 SPI */ SPI_Cmd(FLASH_SPIx , ENABLE);

/************************************************************ °æÈ¨£º2025CIMC Copyright¡£ Îļþ£ºFunction.c ×÷Õß: Lingyu Meng ƽ̨: 2025CIMC IHD-V04 °æ±¾: Lingyu Meng 2025/2/16 V0.01 original ************************************************************/ /************************* Í·Îļþ *************************/ #include “Function.h” #include “LED.h” #include “RTC.h” #include “USART0.h” #include “SPI_FLASH.h” #include “ff.h” #include “diskio.h” #include “sdcard.h” #include “sys_check.h” #include “oled.h” #include “conf_read.h” #include “ratio_set.h” #include “limit_set.h” #include “key.h” #include “adc.h” #include “RTC.h” /************************* ºê¶¨Òå *************************/ #define BUFFER_SIZE 256 #define TX_BUFFER_SIZE BUFFER_SIZE #define RX_BUFFER_SIZE BUFFER_SIZE #define FLASH_WRITE_ADDRESS 0x000000 #define FLASH_READ_ADDRESS FLASH_WRITE_ADDRESS // ²ÉÑùÖÜÆÚ³£Á¿¶¨Òå #define CYCLE_5S 1 #define CYCLE_10S 10 #define CYCLE_15S 15 // Flash´æ´¢µØÖ·¶¨Òå #define SAMPLE_CYCLE_ADDR 0x000100 /************************ ±äÁ¿¶¨Òå ************************/ uint8_t tx_buffer[TX_BUFFER_SIZE]; uint8_t rx_buffer[TX_BUFFER_SIZE]; uint16_t i = 0, count, result = 0; uint8_t is_successful = 0; //FIL fdst; UINT br, bw; BYTE buffer[128]; BYTE filebuffer[128]; typedef struct { int count; // µ±Ç°ÎļþÊý¾Ý¼ÆÊý // unsigned long datetime; // µ±Ç°ÎļþµÄʱ¼ä´Á FIL file; // µ±Ç°Îļþ¶ÔÏó } DataFileInfo; static DataFileInfo data_file_info = {0, {0}}; // È«¾Ö±äÁ¿ uint32_t sample_cycle = CYCLE_5S; // µ±Ç°²ÉÑùÖÜÆÚ£¬µ¥Î»Ãë /************************ º¯Êý¶¨Òå **********************/ ErrStatus memory_compare(uint8_t src,uint8_t dst,uint16_t length); void nvic_config(void); void write_file(void); /************************************************************ Function : System_Init Comment : ÓÃÓÚ³õʼ»¯MCU Parameter: null Return : null Author : Lingyu Meng Date : 2025-02-30 V0.1 original ************************************************************/ void System_Init(void) { systick_config(); // ʱÖÓÅäÖà nvic_config(); // ÅäÖÃÖжϿØÖÆÆ÷ KEY_Init(); // KEY³õʼ»¯ LED_Init(); USART0_Config(); // ´®¿Ú³õʼ»¯ nvic_irq_enable(USART0_IRQn, 0, 0); // ʹÄÜUSART0ÖÐ¶Ï usart_interrupt_enable(USART0, USART_INT_RBNE); // ½ÓÊÕÖжϴò¿ª ADC_port_init(); // ADC³õʼ»¯ OLED_Init(); TF_Init(); spi_flash_init(); // ³õʼ»¯SPI Flash RTC_Init(); // ´ÓFlash¶ÁÈ¡±£´æµÄ²ÉÑùÖÜÆÚ uint32_t saved_cycle; spi_flash_buffer_read((uint8_t*)&saved_cycle, SAMPLE_CYCLE_ADDR, sizeof(uint32_t)); // ÑéÖ¤¶ÁÈ¡µÄÖµÊÇ·ñÓÐЧ if (saved_cycle == CYCLE_5S || saved_cycle == CYCLE_10S || saved_cycle == CYCLE_15S) { sample_cycle = saved_cycle; printf("Loaded saved sample cycle: %d s\r\n", sample_cycle); } else { // ÎÞЧֵ£¬Ê¹ÓÃĬÈÏ5Ãë sample_cycle = CYCLE_5S; printf("Using default sample cycle: %d s\r\n", sample_cycle); // ±£´æÄ¬ÈÏÖµµ½Flash spi_flash_sector_erase(SAMPLE_CYCLE_ADDR); spi_flash_buffer_write((uint8_t*)&sample_cycle, SAMPLE_CYCLE_ADDR, sizeof(uint32_t)); } // ¶ÁÈ¡¶ÓÎé±àºÅ Team_num(); delay_1ms(10); } /************************************************************ Function : UsrFunction Comment : Óû§³ÌÐò¹¦ÄÜ Parameter: null Return : null Author : Liu Tao @ GigaDevice Date : 2025-05-10 V0.1 original ************************************************************/ void UsrFunction(void) { uint8_t sampling_enabled = 0; // ²ÉÑùʹÄܱêÖ¾ uint32_t last_sample_time = 0; // ÉϴβÉÑùʱ¼ä uint32_t last_led_toggle_time = 0; // LEDÇл»Ê±¼ä uint8_t led_state = 0; // LEDµ±Ç°×´Ì¬ // ¾²Ì¬±äÁ¿¼Ç¼°´¼üÉÏ´Î״̬£¨ÓÃÓÚ±ßÔµ¼ì²â£© static uint8_t last_key2 = 1, last_key3 = 1, last_key4 = 1; printf("====system init====\r\n"); Read_Team_num(); // ¶ÁÈ¡¶ÓÎé±àºÅ printf("\n\r====system ready====\r\n"); OLED_ShowString(0, 0, "system idle", 16); OLED_Refresh(); while (1) { uint32_t current_tick = systick_get_tick(); // ================ °´¼ü´¦Àí ================ // ¼ì²âKEY1°´ÏÂʼþ if (KEY_Stat(KEY_PORT, KEY1_PIN)) { // °´¼ü״̬·­×ª sampling_enabled = !sampling_enabled; if (sampling_enabled) { // Æô¶¯²ÉÑù printf("Output==> Periodic Sampling (Key Start)\r\n"); printf("Output==> sample cycle: %ds\r\n", sample_cycle); last_sample_time = current_tick; last_led_toggle_time = current_tick; led_state = 0; OLED_Clear(); OLED_ShowString(0, 0, "Sampling...", 16); OLED_Refresh(); } else { // Í£Ö¹²ÉÑù printf("Output==> Periodic Sampling STOP (Key Stop)\r\n"); gpio_bit_reset(GPIOA, GPIO_PIN_5); // ¹Ø±ÕLED1 OLED_Clear(); OLED_ShowString(0, 0, "system idle", 16); OLED_Refresh(); } // Ìí¼ÓÈ¥¶¶ÑÓʱ delay_1ms(50); } // ¼ì²âKEY2°´ÏÂʼþ£¨ÖÜÆÚÉèΪ5s£© uint8_t current_key2 = KEY_Stat(KEY_PORT, KEY2_PIN); if (current_key2 && !last_key2) { sample_cycle = CYCLE_5S; printf("Output==> sample cycle adjust: %ds\r\n", sample_cycle); // ±£´æµ½Flash spi_flash_sector_erase(SAMPLE_CYCLE_ADDR); spi_flash_buffer_write((uint8_t*)&sample_cycle, SAMPLE_CYCLE_ADDR, sizeof(uint32_t)); // Èç¹ûÕýÔÚ²ÉÑù£¬¸üвÉÑùʱ¼ä if (sampling_enabled) { last_sample_time = current_tick; } } last_key2 = current_key2; // ¼ì²âKEY3°´ÏÂʼþ£¨ÖÜÆÚÉèΪ10s£© uint8_t current_key3 = KEY_Stat(KEY_PORT, KEY3_PIN); if (current_key3 && !last_key3) { sample_cycle = CYCLE_10S; printf("Output==> sample cycle adjust: %ds\r\n", sample_cycle); // ±£´æµ½Flash spi_flash_sector_erase(SAMPLE_CYCLE_ADDR); spi_flash_buffer_write((uint8_t*)&sample_cycle, SAMPLE_CYCLE_ADDR, sizeof(uint32_t)); // Èç¹ûÕýÔÚ²ÉÑù£¬¸üвÉÑùʱ¼ä if (sampling_enabled) { last_sample_time = current_tick; } } last_key3 = current_key3; // ¼ì²âKEY4°´ÏÂʼþ£¨ÖÜÆÚÉèΪ15s£© uint8_t current_key4 = KEY_Stat(KEY_PORT, KEY4_PIN); if (current_key4 && !last_key4) { sample_cycle = CYCLE_15S; printf("Output==> sample cycle adjust: %ds\r\n", sample_cycle); // ±£´æµ½Flash spi_flash_sector_erase(SAMPLE_CYCLE_ADDR); spi_flash_buffer_write((uint8_t*)&sample_cycle, SAMPLE_CYCLE_ADDR, sizeof(uint32_t)); // Èç¹ûÕýÔÚ²ÉÑù£¬¸üвÉÑùʱ¼ä if (sampling_enabled) { last_sample_time = current_tick; } } last_key4 = current_key4; // ================ ´®¿ÚÃüÁî´¦Àí ================ if (cmd_ready) { cmd_ready = 0; int len = cmd_index; // ÇåÀíÃüÁîĩβµÄ¿Õ°××Ö·û while (len > 0 && (cmd_buffer[len - 1] == '\r' || cmd_buffer[len - 1] == '\n' || cmd_buffer[len - 1] == ' ')) { cmd_buffer[len - 1] = '\0'; len--; } // ²âÊÔÃüÁî if (strcmp((const char*)cmd_buffer, "test") == 0) { sys_check(); // ϵͳ×Ô¼ì } // RTCÅäÖÃÃüÁî else if (strcmp((const char*)cmd_buffer, "RTC Config") == 0) { printf("\r\nInput Datetime\r\n"); while (cmd_ready == 0) delay_1ms(10); char datetime_str[64]; strcpy(datetime_str, (const char*)cmd_buffer); cmd_ready = 0; rtc_settime(datetime_str); } // ÏÔʾµ±Ç°Ê±¼ä else if (strcmp((const char*)cmd_buffer, "RTC now") == 0) { rtc_show_time(); } // conf¼ì²â else if (strcmp((const char*)cmd_buffer, "conf") == 0) { conf(); } // ratio¼ì²â else if (strcmp((const char*)cmd_buffer, "ratio") == 0) { ratio_set(); } // limit¼ì²â else if (strcmp((const char*)cmd_buffer, "limit") == 0) { limit_set(); } // conf_read¼ì²â else if (strcmp((const char*)cmd_buffer, "conf_read") == 0) { printf("\r\nread parameters from flash\r\n"); conf_read(); } // conf_save¼ì²â else if (strcmp((const char*)cmd_buffer, "conf_save") == 0) { conf_save(); } // Æô¶¯²ÉÑùÃüÁî else if (strcmp((const char*)cmd_buffer, "start") == 0) { sampling_enabled = 1; printf("Output==> Periodic Sampling\r\n"); printf("Output==> sample cycle: %ds\r\n", sample_cycle); last_sample_time = current_tick; last_led_toggle_time = current_tick; led_state = 0; OLED_Clear(); OLED_ShowString(0, 0, "Sampling...", 16); OLED_Refresh(); } // Í£Ö¹²ÉÑùÃüÁî else if (strcmp((const char*)cmd_buffer, "stop") == 0) { if (sampling_enabled) { sampling_enabled = 0; printf("Output==> Periodic Sampling STOP\r\n"); gpio_bit_reset(GPIOA, GPIO_PIN_5); // ¹Ø±ÕLED1 OLED_Clear(); OLED_ShowString(0, 0, "system idle", 16); OLED_Refresh(); } } } // ================ ²ÉÑùÈÎÎñ ) ================ if (sampling_enabled) { // LEDÉÁ˸¿ØÖÆ£¨·Ç×èÈû·½Ê½£© if (current_tick - last_led_toggle_time >= 500) { last_led_toggle_time = current_tick; led_state = !led_state; if (led_state) { gpio_bit_set(GPIOA, GPIO_PIN_5); // LEDÁÁ } else { gpio_bit_reset(GPIOA, GPIO_PIN_5); // LEDÃð } } // ²ÉÑù¶¨Ê±£¨Ê¹Óõ±Ç°ÖÜÆÚ£© if (current_tick - last_sample_time >= sample_cycle * 1000) { // ¶ÁÈ¡RTCʱ¼ä // ¶ÁÈ¡ADCÖµ adc_flag_clear(ADC0, ADC_FLAG_EOC); while (SET != adc_flag_get(ADC0, ADC_FLAG_EOC)) {} // µÈ´ýת»»Íê³É uint16_t adc_value = ADC_RDATA(ADC0); float vol_value = adc_value * 3.3f / 4095.0f; rtc_current_time_get(&rtc_initpara); // ת»»Îª10½øÖÆ uint8_t hour = bcd_to_dec(rtc_initpara.hour); uint8_t minute = bcd_to_dec(rtc_initpara.minute); uint8_t second = bcd_to_dec(rtc_initpara.second); uint8_t year = bcd_to_dec(rtc_initpara.year); uint8_t month = bcd_to_dec(rtc_initpara.month); uint8_t day = bcd_to_dec(rtc_initpara.date); /**************** OLED?? ****************/ char time_str[16]; char volt_str[16]; sprintf(time_str, "%02u:%02u:%02u", hour, minute, second); sprintf(volt_str, "%.2f V", vol_value); OLED_Clear(); OLED_ShowString(0, 0, time_str, 16); OLED_ShowString(0, 16, volt_str, 16); OLED_Refresh(); /***************´®¿ÚÊä³ö****************/ printf("20%02u-%02u-%02u %02u:%02u:%02u %.2fV\r\n", year, month, day, hour, minute, second, vol_value); /*************** ´æ´¢Êý¾Ý *************** int count; // µ±Ç°ÎļþÊý¾Ý¼ÆÊý unsigned long datetime; // µ±Ç°ÎļþµÄʱ¼ä´Á FIL file; // µ±Ç°Îļþ¶ÔÏóDataFileInfo data_file_info = {0, 0, {0}};*/ FRESULT res; FATFS fs; char dir_path[] = "0:/sample"; // Ä¿±êĿ¼ char filename[64]; if (data_file_info.count == 0) { //³õʼ»¯´æ´¢É豸 DSTATUS status = disk_initialize(0); if (status != 0) { printf("Disk initialize failed. Status: 0x%02X\n", status); return; } //¹ÒÔØÎļþϵͳ res = f_mount(0, &fs); if (res != FR_OK) { printf("Mount failed=%d\n", res); return; } // ¹Ø±Õ֮ǰ´ò¿ªµÄÎļþ if (data_file_info.file.fs) { f_close(&data_file_info.file); } //È·±£Ä¿±êĿ¼´æÔÚ FILINFO fno; res = f_stat(dir_path, &fno); if (res == FR_NO_FILE) { // Ŀ¼²»´æÔÚ res = f_mkdir(dir_path); // ´´½¨Ä¿Â¼ if (res != FR_OK) { printf("Ŀ¼´´½¨Ê§°Ü %s: %d\n", dir_path, res); return; } } else if (res != FR_OK) { printf("Ŀ¼·ÃÎÊ´íÎó: %d\n", res); return; } // Éú³É´øÂ·¾¶µÄÎļþÃû snprintf(filename, sizeof(filename), "%s/sampleDeta20%02d%02d%02d%02d%02d%02d.txt", dir_path, year, month, day, hour, minute, second); // ´´½¨ÐÂÎļþ res = f_open(&data_file_info.file, filename, FA_CREATE_ALWAYS | FA_WRITE); if (res != FR_OK) { printf("Îļþ´´½¨Ê§°Ü %s: %d\n", filename, res); // return; }else{ printf(“Îļþ´´½¨³É¹¦”); f_open(&data_file_info.file, filename, FA_CREATE_ALWAYS | FA_WRITE); } } // дÈëÊý¾Ý char data_line[50]; snprintf(data_line, sizeof(data_line), "20%02d-%02d-%02d %02d:%02d:%02d %.2f V\r\n", year, month, day, hour, minute, second, vol_value); UINT bw; // f_open(&data_file_info.file, filename, FA_CREATE_ALWAYS | FA_WRITE); res = f_write(&data_file_info.file, data_line, strlen(data_line), &bw); // f_close(&data_file_info.file); // f_mount(0, NULL);//Ð¶ÔØÎļþϵͳ if (res != FR_OK || bw != strlen(data_line)) { printf(“Êý¾ÝдÈëʧ°Ü: %d\n”, res); } else { f_sync(&data_file_info.file); data_file_info.count++; // ´ïµ½10ÌõÊý¾ÝºóÖØÖà if (data_file_info.count >= 10) { data_file_info.count = 0; f_mount(0, NULL);//Ð¶ÔØÎļþϵͳ } } last_sample_time = current_tick; } } else { // ¿ÕÏÐ״̬ÏÂÌí¼ÓСÑÓʱ delay_1ms(10); } } } void nvic_config(void) { nvic_priority_group_set(NVIC_PRIGROUP_PRE1_SUB3); // ÉèÖÃÖжÏÓÅÏȼ¶·Ö×é nvic_irq_enable(SDIO_IRQn, 0, 0); // ʹÄÜSDIOÖжϣ¬ÓÅÏȼ¶Îª0 } /* ͨ¹ý´®¿ÚÊäÈëдÈëÎļþ */ void write_file(void) { printf(“Input data (press Enter to save):\r\n”); uint16_t index = 0; while(1){ if(usart_flag_get(USART0, USART_FLAG_RBNE) != RESET){ char ch = usart_data_receive(USART0); // Èç¹û½ÓÊÕ»º³åÇø·Ç¿Õ£¬´ÓUSART0½ÓÊÕÒ»¸ö×Ö·û if(ch == '\r'){ // ¼ì²é½ÓÊÕµ½µÄ×Ö·ûÊÇ·ñΪ»Ø³µ¼ü£¨'\r'£© filebuffer[index] = '\0'; // Èç¹ûÊǻسµ¼ü£¬ÔÚµ±Ç°Î»ÖÃÌí¼Ó×Ö·û´®½áÊø·û '\0' break; // Ìø³öÑ­»·£¬½áÊøÊý¾Ý½ÓÊÕ } filebuffer[index++] = ch; // ´æ´¢½ÓÊÕµ½µÄ×Ö·û if(index >= sizeof(filebuffer)-1) break; // Èç¹û»º³åÇøÂúÔò½áÊø½ÓÊÕ } } } /! \brief memory compare function \param[in] src: source data pointer \param[in] dst: destination data pointer \param[in] length: the compare data length \param[out] none \retval ErrStatus: ERROR or SUCCESS / ErrStatus memory_compare(uint8_t src, uint8_t dst, uint16_t length) { while(length --){ if(*src++ != *dst++) return ERROR; } return SUCCESS; } 把 int count; // µ±Ç°ÎļþÊý¾Ý¼ÆÊý unsigned long datetime; // µ±Ç°ÎļþµÄʱ¼ä´Á FIL file; // µ±Ç°Îļþ¶ÔÏóDataFileInfo data_file_info = {0, 0, {0}};*/ FRESULT res; FATFS fs; char dir_path[] = "0:/sample"; // Ä¿±êĿ¼ char filename[64]; if (data_file_info.count == 0) { //³õʼ»¯´æ´¢É豸 DSTATUS status = disk_initialize(0); if (status != 0) { printf("Disk initialize failed. Status: 0x%02X\n", status); return; } //¹ÒÔØÎļþϵͳ res = f_mount(0, &fs); if (res != FR_OK) { printf("Mount failed=%d\n", res); return; } // ¹Ø±Õ֮ǰ´ò¿ªµÄÎļþ if (data_file_info.file.fs) { f_close(&data_file_info.file); } //È·±£Ä¿±êĿ¼´æÔÚ FILINFO fno; res = f_stat(dir_path, &fno); if (res == FR_NO_FILE) { // Ŀ¼²»´æÔÚ res = f_mkdir(dir_path); // ´´½¨Ä¿Â¼ if (res != FR_OK) { printf("Ŀ¼´´½¨Ê§°Ü %s: %d\n", dir_path, res); return; } } else if (res != FR_OK) { printf("Ŀ¼·ÃÎÊ´íÎó: %d\n", res); return; } // Éú³É´øÂ·¾¶µÄÎļþÃû snprintf(filename, sizeof(filename), "%s/sampleDeta20%02d%02d%02d%02d%02d%02d.txt", dir_path, year, month, day, hour, minute, second); // ´´½¨ÐÂÎļþ res = f_open(&data_file_info.file, filename, FA_CREATE_ALWAYS | FA_WRITE); if (res != FR_OK) { printf("Îļþ´´½¨Ê§°Ü %s: %d\n", filename, res); // return; }else{ printf(“Îļþ´´½¨³É¹¦”); f_open(&data_file_info.file, filename, FA_CREATE_ALWAYS | FA_WRITE); } } // дÈëÊý¾Ý char data_line[50]; snprintf(data_line, sizeof(data_line), "20%02d-%02d-%02d %02d:%02d:%02d %.2f V\r\n", year, month, day, hour, minute, second, vol_value); UINT bw; // f_open(&data_file_info.file, filename, FA_CREATE_ALWAYS | FA_WRITE); res = f_write(&data_file_info.file, data_line, strlen(data_line), &bw); // f_close(&data_file_info.file); // f_mount(0, NULL);//Ð¶ÔØÎļþϵͳ if (res != FR_OK || bw != strlen(data_line)) { printf(“Êý¾ÝдÈëʧ°Ü: %d\n”, res); } else { f_sync(&data_file_info.file); data_file_info.count++; // ´ïµ½10ÌõÊý¾ÝºóÖØÖà if (data_file_info.count >= 10) { data_file_info.count = 0; f_mount(0, NULL);//Ð¶ÔØÎļþϵͳ } }封装起来,void write_data_to_file(const char* dir_path, int year, int month, int day, int hour, int minute, int second, float vol_value),只需要封装起来,不要改这里面的程序,一点也不要改,因为测试他没有错

/******************************************************************************** * * $Workfile: TCC_M25P80.c $ * * Copyright (C) 2012-2013 All Rights Reserved. * * Function: SPI initialize. * * Language: C * * $Revision: A1 $ * * $Author: Gongming Song $ * * $Log: $ * *******************************************************************************/ #include "TCC_M25P80.h" extern u32 currentAddress; #define ADDRESS_STORAGE_LOCATION 0x0000 u8 addressBuffer[4]; #define M25P80_CS0() GPIO_ResetBits(GPIOA,GPIO_Pin_7) #define M25P80_CS1() GPIO_SetBits(GPIOA,GPIO_Pin_7) void MP25P80_GPIO_Config() { GPIO_InitTypeDef GPIO_InitStructure; // ??GPIOB?GPIOA?? RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOA, ENABLE); // ??PB13?PB14?PB15?SPI2???? GPIO_PinAFConfig(GPIOB, GPIO_PinSource13, GPIO_AF_SPI2); // SCK GPIO_PinAFConfig(GPIOB, GPIO_PinSource14, GPIO_AF_SPI2); // MISO GPIO_PinAFConfig(GPIOB, GPIO_PinSource15, GPIO_AF_SPI2); // MOSI // ??SPI?? GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOB, &GPIO_InitStructure); // ??PA7?CS?? GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_SetBits(GPIOA, GPIO_Pin_7); // ??????? } void SPI_Configuration() { SPI_InitTypeDef SPI_InitStructure; // ??SPI2?? RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE); // ??SPI2?? SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; SPI_InitStructure.SPI_Mode = SPI_Mode_Master; SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; SPI_InitStructure.SPI_CPOL = SPI_CPOL_High; // ??????? SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; // ???????????? SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; // ????CS SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_16; SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; SPI_InitStructure.SPI_CRCPolynomial = 7; SPI_Init(SPI2, &SPI_InitStructure); SPI_Cmd(SPI2, ENABLE); // ??SPI2 } void M25P80_INIT(void) { // u8 addressBuffer[4]; MP25P80_GPIO_Config(); SPI_Configuration(); M25P80_Read_Bytes(ADDRESS_STORAGE_LOCATION, addressBuffer, 4); // currentAddress = (addressBuffer[0] << 24) | (addressBuffer[1] << 16) | (addressBuffer[2] << 8) | addressBuffer[3]; if (currentAddress == 0) { currentAddress = 0x0010; } // SPI_InitTypeDef SPI_InitStructure; // GPIO_InitTypeDef GPIO_InitStructure; // /* ??GPIO?SPI?? */ // FLASH_SPI_APBxClock_FUN ( FLASH_SPI_CLK, ENABLE ); // FLASH_SPI_SCK_APBxClock_FUN ( FLASH_SPI_SCK_CLK, ENABLE ); // FLASH_SPI_MISO_APBxClock_FUN ( FLASH_SPI_MISO_CLK, ENABLE ); // FLASH_SPI_MOSI_APBxClock_FUN ( FLASH_SPI_MOSI_CLK, ENABLE ); // FLASH_SPI_CS_APBxClock_FUN ( FLASH_SPI_CS_CLK, ENABLE ); // /* ??SPI????:SCK ???? */ // GPIO_InitStructure.GPIO_Pin = FLASH_SPI_SCK_PIN; // GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; // GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; // GPIO_Init(FLASH_SPI_SCK_PORT, &GPIO_InitStructure); // /* ??SPI????:MISO ?????????? */ // GPIO_InitStructure.GPIO_Pin = FLASH_SPI_MISO_PIN; // GPIO_Init(FLASH_SPI_MISO_PORT, &GPIO_InitStructure); // /* ??SPI????:MISO ?????????? */ // GPIO_InitStructure.GPIO_Pin = FLASH_SPI_MOSI_PIN; // GPIO_Init(FLASH_SPI_MOSI_PORT, &GPIO_InitStructure); // /* ??SPI????:CS ??Flash???? */ // GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; // GPIO_InitStructure.GPIO_Pin = FLASH_SPI_CS_PIN; // GPIO_Init(FLASH_SPI_CS_PORT, &GPIO_InitStructure); // /* ??????Flash,???????Flash?????? */ // FLASH_SPI_CS_DISABLE(); // SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; // SPI_InitStructure.SPI_Mode = SPI_Mode_Master; // SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; // SPI_InitStructure.SPI_CPOL = SPI_CPOL_High; // SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; // SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; // SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4; // SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; // SPI_InitStructure.SPI_CRCPolynomial = 7; // SPI_Init(SPI1 , &SPI_InitStructure); // /* ??SPI?? */ // SPI_Cmd(SPI1 , ENABLE); // u8 addressBuffer[4]; // M25P80_Read_Bytes(ADDRESS_STORAGE_LOCATION, addressBuffer, 4); // currentAddress = (addressBuffer[0] << 24) | (addressBuffer[1] << 16) | (addressBuffer[2] << 8) | addressBuffer[3]; // if (currentAddress == 0) { // currentAddress = 0x0000; // } } /******************************************************************************* * Function Name : SPI_FLASH_SendByte * Description : Sends a byte through the SPI interface and return the byte * received from the SPI bus. * Input : byte : byte to send. * Output : None * Return : The value of the received byte. * 8Mbit = 1,048,576 bytes = 16 sectors (512 Kbits, 65536 bytes each) = * 4096 pages (256 bytes each) * 1sector = 256 page * address range 00000 ~ fffffh *******************************************************************************/ u16 SPI_FLASH_SendByte(u8 byte) { /* Loop while DR register in not emplty */ while(SPI_I2S_GetFlagStatus(TCC_SPI, SPI_I2S_FLAG_TXE) == RESET); /* Send byte through the SPI1 peripheral */ SPI_I2S_SendData(TCC_SPI, (uint16_t)byte); /* Wait to receive a byte */ while(SPI_I2S_GetFlagStatus(TCC_SPI, SPI_I2S_FLAG_RXNE) == RESET); /* Return the byte read from the SPI bus */ return SPI_I2S_ReceiveData(TCC_SPI); } /******************************************************************************* * Function Name : void M25P80_CMD1B(u8 cmd) * Description : 发送一个字节指令 * This function must be used only if the Start_Read_Sequence * function has been previously called. * Input : None * Output : None * Return : Byte Read from the SPI Flash. *******************************************************************************/ void M25P80_CMD1B(u8 cmd) { M25P80_CS0(); // GPIO_ResetBits(GPIOA,GPIO_Pin_7); //FLASH_CS=0; SPI_FLASH_SendByte(cmd); M25P80_CS1(); //GPIO_SetBits(GPIOA,GPIO_Pin_7); //FLASH_CS=1; } /******************************************************************************* * Function Name : u8 M25P80_CMD1B_READ1B(u8 cmd) * Description : 发送一个字节指令并接受返回值 * This function must be used only if the Start_Read_Sequence * function has been previously called. * Input : None * Output : None * Return : Byte Read from the SPI Flash. *******************************************************************************/ u16 M25P80_CMD1B_READ1B(u16 cmd) { u16 data; M25P80_CS0(); //GPIO_ResetBits(GPIOA,GPIO_Pin_7); //FLASH_CS=0; SPI_FLASH_SendByte(cmd); data = SPI_FLASH_SendByte(0xFF); M25P80_CS1(); //GPIO_SetBits(GPIOA,GPIO_Pin_7); //FLASH_CS=1; return data; } /******************************************************************************* * Function Name : void M25P80_CMD1B_S1B(u16 cmd , u16 data) * Description : 写一指令与一数据 * Input : None * Output : None * Return : Byte Read from the SPI Flash. *******************************************************************************/ void M25P80_CMD1B_S1B(u16 cmd , u16 data) { M25P80_CS0(); //GPIO_ResetBits(GPIOA,GPIO_Pin_7); //FLASH_CS=0; SPI_FLASH_SendByte(cmd); SPI_FLASH_SendByte(data); M25P80_CS1(); //GPIO_SetBits(GPIOA,GPIO_Pin_7); //FLASH_CS=1; } /******************************************************************************* * Function Name : void M25P80_WP_En(void) * Description : 写使能 * 使能寄存器中的WEL位 * Input : None * Output : None * Return : None *******************************************************************************/ void M25P80_Write_En(void) { u16 sta; //清除 Block Protect位:PB0,PB1,PB2,即取消所有区域保护 sta = M25P80_CMD1B_READ1B(RDSR) & (~0x1C); M25P80_CMD1B_S1B(WRSR, sta); // Protected Area Upper sixteenth (Sector 15)以及WEL位 M25P80_CMD1B(WREN); while(!(M25P80_CMD1B_READ1B(RDSR) & 0x02)); sta = M25P80_CMD1B_READ1B(RDSR); } /******************************************************************************* * Function Name : void M25P80_WP_En(void) * Description : 写失能 * 使能寄存器中的WEL位 * Input : None * Output : None * Return : None *******************************************************************************/ void M25P80_WP_En(void) { u16 sta; //添加PB0,PB1,PB2的保护位 sta = M25P80_CMD1B_READ1B(RDSR) | 0x1c; M25P80_CMD1B_S1B(WRSR, sta); M25P80_CMD1B(WRDI); } /******************************************************************************* * Function Name : u8 M25P80_Busy(void) * Description : 状态检测 * 最低位WIP为1则正在工作 * Input : None * Output : None * Return : return (sta & 0x01); *******************************************************************************/ u8 M25P80_Busy(void) { u8 sta; sta = M25P80_CMD1B_READ1B(RDSR); return (sta & 0x01); } /******************************************************************************* * Function Name : void M25P80_Section_Erase(u32 addr) * Description : 位擦除 * 擦除FLASH固定地址的数据 * Input : None * Output : None * Return : None *******************************************************************************/ void M25P80_Section_Erase(u32 addr) { u8 ad[3] ; // ad[0] = (addr & 0x00ff0000) ; // ad[1] = (addr & 0x0000ff00) >> 8; // ad[2] = (addr & 0x000000ff) >> 16; ad[0] = (addr >> 16) & 0xFF; // ?8? ad[1] = (addr >> 8) & 0xFF; // ?8? ad[2] = addr & 0xFF; // ?8? M25P80_Write_En(); M25P80_CS0(); //GPIO_ResetBits(GPIOA,GPIO_Pin_7); //FLASH_CS=0; SPI_FLASH_SendByte(SECTOR_ERASER); SPI_FLASH_SendByte(ad[0]); SPI_FLASH_SendByte(ad[1]); SPI_FLASH_SendByte(ad[2]); M25P80_CS1(); //GPIO_SetBits(GPIOA,GPIO_Pin_7); //FLASH_CS=1; while(M25P80_Busy()); while(M25P80_Busy()); while(M25P80_Busy()); M25P80_CMD1B(WRDI); //M25P80_WP_En(); while(M25P80_Busy()); // ?????? while(M25P80_Busy()); } /******************************************************************************* * Function Name : void M25P80_Bulk_Erase(void) * Description : 全扇区擦除 * 格式化8MFLASH * Input : None * Output : None * Return : None *******************************************************************************/ void M25P80_Bulk_Erase(void) { M25P80_Write_En(); M25P80_CMD1B(BULK_ERASER); while(M25P80_Busy()); M25P80_CMD1B(WRDI); //M25P80_WP_En(); while(M25P80_Busy()); // ?????? while(M25P80_Busy()); } /******************************************************************************* * Function Name : void M25P80_Write_1Byte(u32 addr , u8 data) * Description : 写数据 * 写固定地址的一位数据 * Input : None * Output : None * Return : None *******************************************************************************/ void M25P80_Write_1Byte(u32 addr , u8 data) { u8 ad[3] ; // ad[0] = (addr & 0x00ff0000); // ad[1] = (addr & 0x0000ff00) >> 8; // ad[2] = (addr & 0x000000ff) >> 16; ad[0] = (addr >> 16) & 0xFF; // ?8? ad[1] = (addr >> 8) & 0xFF; // ?8? ad[2] = addr & 0xFF; // ?8? M25P80_Write_En(); M25P80_CS0(); //GPIO_ResetBits(GPIOA,GPIO_Pin_7); //FLASH_CS=0; SPI_FLASH_SendByte(PAGE_PROG); SPI_FLASH_SendByte(ad[0]); SPI_FLASH_SendByte(ad[1]); SPI_FLASH_SendByte(ad[2]); SPI_FLASH_SendByte(data); M25P80_CS1(); //GPIO_SetBits(GPIOA,GPIO_Pin_7); //FLASH_CS=1; while(M25P80_Busy()); M25P80_CMD1B(WRDI); //M25P80_WP_En(); } /******************************************************************************* * Function Name : void M25p80_Write_Bytes(u32 addr , u8* wr_buf_p , u16 no) * Description : 写数据 * 多字节写入数据 * Input : u32 addr启示地址 , u8* wr_buf_p写入数据初始位指针 , * u16 no写入字节个数 * Output : None * Return : None *******************************************************************************/ void M25P80_Write_Bytes(u32 addr , u8* wr_buf_p , u16 no) { u8 ad[3] ; // ad[0] = (addr & 0x00ff0000) ; // ad[1] = (addr & 0x0000ff00) >> 8; // ad[2] = (addr & 0x000000ff) >> 16; // ad[0] = (addr >> 16) & 0xFF; // ?8? ad[1] = (addr >> 8) & 0xFF; // ?8? ad[2] = addr & 0xFF; // ?8? M25P80_Write_En(); M25P80_CS0(); //GPIO_ResetBits(GPIOA,GPIO_Pin_7); //FLASH_CS=0; SPI_FLASH_SendByte(PAGE_PROG); SPI_FLASH_SendByte(ad[0]); SPI_FLASH_SendByte(ad[1]); SPI_FLASH_SendByte(ad[2]); for(; no > 0; no--) { SPI_FLASH_SendByte(*wr_buf_p); wr_buf_p++; } M25P80_CS1(); //GPIO_SetBits(GPIOA,GPIO_Pin_7); //FLASH_CS=1; while(M25P80_Busy()); M25P80_CMD1B(WRDI); //M25P80_WP_En(); } /******************************************************************************* * Function Name : u8 M25P80_Read_1Byte(u32 addr ) * Description : 读数据 * 读固定地址的一位数据 * Input : None * Output : None * Return : return data; *******************************************************************************/ u8 M25P80_Read_1Byte(u32 addr ) { u8 ad[3] , data; // ad[0] = (addr & 0x00ff0000) ; // ad[1] = (addr & 0x0000ff00) >> 8; // ad[2] = (addr & 0x000000ff) >> 16; ad[0] = (addr >> 16) & 0xFF; // ?8? ad[1] = (addr >> 8) & 0xFF; // ?8? ad[2] = addr & 0xFF; // ?8? //M25P80_CMD1B(WRDI); M25P80_CS0(); //GPIO_ResetBits(GPIOA,GPIO_Pin_7); //FLASH_CS=0; SPI_FLASH_SendByte(READ); SPI_FLASH_SendByte(ad[0]); SPI_FLASH_SendByte(ad[1]); SPI_FLASH_SendByte(ad[2]); data = SPI_FLASH_SendByte(0xff); M25P80_CS1(); //GPIO_SetBits(GPIOA,GPIO_Pin_7); //FLASH_CS=1; return data; } /******************************************************************************* * Function Name : void M25P80_Read_Bytes(u32 addr , u8* re_buf_p , u16 no) * Description : 读数据 * 读固定地址的N位数据 * Input : u32 addr地址 , u8* re_buf_p存放数据缓冲指针 * , u16 no读取数据个数N * Output : None * Return : return data; *******************************************************************************/ void M25P80_Read_Bytes(u32 addr , u8* re_buf_p , u16 no) { u8 ad[3] ; // ad[0] = (addr & 0x00ff0000) ; // ad[1] = (addr & 0x0000ff00) >> 8; // ad[2] = (addr & 0x000000ff) >> 16; ad[0] = (addr >> 16) & 0xFF; // ?8? ad[1] = (addr >> 8) & 0xFF; // ?8? ad[2] = addr & 0xFF; // ?8? //M25P80_CMD1B(WRDI); //M25P80_Write_En(); M25P80_CMD1B(WREN); M25P80_CS0(); //GPIO_ResetBits(GPIOA,GPIO_Pin_7); //FLASH_CS=0; SPI_FLASH_SendByte(READ); SPI_FLASH_SendByte(ad[0]); SPI_FLASH_SendByte(ad[1]); SPI_FLASH_SendByte(ad[2]); for(; no > 0; no--) *re_buf_p++ = SPI_FLASH_SendByte(0xff); M25P80_CS1(); //GPIO_SetBits(GPIOA,GPIO_Pin_7); //FLASH_CS=1; } /******************************************************************************* * Function Name :WriteDataToM25P80(u8* data, u16 length) * Description : * Input : * * Output : None * Return : return data; *******************************************************************************/ u32 WriteDataToM25P80(u8* data, u16 length) { // PAGE ALINE u32 startAddress = currentAddress; u32 page_size = 256; u32 page_offset = currentAddress % page_size; u16 remainingData; // u8 addressBuffer[4]; // if (page_offset != 0) { remainingData = page_size - page_offset; if (remainingData > length) { remainingData = length; } M25P80_Write_Bytes(currentAddress, data, remainingData); currentAddress += remainingData; length -= remainingData; data += remainingData; } // while (length >= page_size) { M25P80_Write_Bytes(currentAddress, data, page_size); currentAddress += page_size; length -= page_size; data += page_size; } // if (length > 0) { M25P80_Write_Bytes(currentAddress, data, length); currentAddress += length; } // ???????M25P80????? // u8 addressBuffer[4]; addressBuffer[0] = (currentAddress >> 24) & 0xFF; addressBuffer[1] = (currentAddress >> 16) & 0xFF; addressBuffer[2] = (currentAddress >> 8) & 0xFF; addressBuffer[3] = currentAddress & 0xFF; M25P80_Write_Bytes(ADDRESS_STORAGE_LOCATION, addressBuffer, 4); // M25P80_Write_Bytes(currentAddress, addressBuffer, 4); return startAddress; } /******************************************************************************* * Function Name :ReadAllDataFromM25P80 * Description : read all data in the chip * Input : * Output : None * Return : return data; *******************************************************************************/ //#define M25P80_SIZE 0x800000 // 8MB size of M25P80 void ReadAllDataFromM25P80(u8* buffer) { u32 addr; for (addr = 0; addr < M25P80_SIZE; addr += 256) { M25P80_Read_Bytes(addr, &buffer[addr], 256); } } u8 M25P80_ReadID(void) { u8 id; M25P80_CS0(); SPI_FLASH_SendByte(0x9F); // ?ID?? id = SPI_FLASH_SendByte(0xFF); M25P80_CS1(); return id; } 在这个m25p80的驱动程序中,这个WriteDataToM25P80函数是否能够正常使用

/********************************************************************************************************* * * File : W25Qx.h * Hardware Environment: * Build Environment : RealView MDK-ARM Version: 5.15 * Version : V1.0 * By : * * (c) Copyright 2005-2015, WaveShare * http://www.waveshare.net * All Rights Reserved * *********************************************************************************************************/ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __W25QXX_H #define __W25QXX_H #ifdef __cplusplus extern "C" { #endif /* Includes ------------------------------------------------------------------*/ #include "stm32f1xx.h" #include "spi.h" /** @addtogroup BSP * @{ */ /** @addtogroup Components * @{ */ /** @addtogroup W25Q128FV * @{ */ /** @defgroup W25Q128FV_Exported_Types * @{ */ /** * @} */ /** @defgroup W25Q128FV_Exported_Constants * @{ */ /** * @brief W25Q128FV Configuration */ #define W25Q128FV_FLASH_SIZE 0x1000000 /* 128 MBits => 16MBytes */ #define W25Q128FV_SECTOR_SIZE 0x10000 /* 256 sectors of 64KBytes */ #define W25Q128FV_SUBSECTOR_SIZE 0x1000 /* 4096 subsectors of 4kBytes */ #define W25Q128FV_PAGE_SIZE 0x100 /* 65536 pages of 256 bytes */ #define W25Q128FV_DUMMY_CYCLES_READ 4 #define W25Q128FV_DUMMY_CYCLES_READ_QUAD 10 #define W25Q128FV_BULK_ERASE_MAX_TIME 250000 #define W25Q128FV_SECTOR_ERASE_MAX_TIME 3000 #define W25Q128FV_SUBSECTOR_ERASE_MAX_TIME 800 #define W25Qx_TIMEOUT_VALUE 1000 /** * @brief W25Q128FV Commands */ /* Reset Operations */ #define RESET_ENABLE_CMD 0x66 #define RESET_MEMORY_CMD 0x99 #define ENTER_QPI_MODE_CMD 0x38 #define EXIT_QPI_MODE_CMD 0xFF /* Identification Operations */ #define READ_ID_CMD 0x90 #define DUAL_READ_ID_CMD 0x92 #define QUAD_READ_ID_CMD 0x94 #define READ_JEDEC_ID_CMD 0x9F /* Read Operations */ #define READ_CMD 0x03 #define FAST_READ_CMD 0x0B #define DUAL_OUT_FAST_READ_CMD 0x3B #define DUAL_INOUT_FAST_READ_CMD 0xBB #define QUAD_OUT_FAST_READ_CMD 0x6B #define QUAD_INOUT_FAST_READ_CMD 0xEB /* Write Operations */ #define WRITE_ENABLE_CMD 0x06 #define WRITE_DISABLE_CMD 0x04 /* Register Operations */ #define READ_STATUS_REG1_CMD 0x05 #define READ_STATUS_REG2_CMD 0x35 #define READ_STATUS_REG3_CMD 0x15 #define WRITE_STATUS_REG1_CMD 0x01 #define WRITE_STATUS_REG2_CMD 0x31 #define WRITE_STATUS_REG3_CMD 0x11 /* Program Operations */ #define PAGE_PROG_CMD 0x02 #define QUAD_INPUT_PAGE_PROG_CMD 0x32 /* Erase Operations */ #define SECTOR_ERASE_CMD 0x20 #define CHIP_ERASE_CMD 0xC7 #define PROG_ERASE_RESUME_CMD 0x7A #define PROG_ERASE_SUSPEND_CMD 0x75 /* Flag Status Register */ #define W25Q128FV_FSR_BUSY ((uint8_t)0x01) /*!< busy */ #define W25Q128FV_FSR_WREN ((uint8_t)0x02) /*!< write enable */ #define W25Q128FV_FSR_QE ((uint8_t)0x02) /*!< quad enable */ #define W25Qx_Enable() HAL_GPIO_WritePin(SPI1_CS_GPIO_Port, SPI1_CS_Pin, GPIO_PIN_RESET) #define W25Qx_Disable() HAL_GPIO_WritePin(SPI1_CS_GPIO_Port, SPI1_CS_Pin, GPIO_PIN_SET) #define W25Qx_OK ((uint8_t)0x00) #define W25Qx_ERROR ((uint8_t)0x01) #define W25Qx_BUSY ((uint8_t)0x02) #define W25Qx_TIMEOUT ((uint8_t)0x03) uint8_t BSP_W25Qx_Init(void); static void BSP_W25Qx_Reset(void); static uint8_t BSP_W25Qx_GetStatus(void); uint8_t BSP_W25Qx_WriteEnable(void); void BSP_W25Qx_Read_ID(uint8_t *ID); uint8_t BSP_W25Qx_Read(uint8_t* pData, uint32_t ReadAddr, uint32_t Size); uint8_t BSP_W25Qx_Write(uint8_t* pData, uint32_t WriteAddr, uint32_t Size); uint8_t BSP_W25Qx_Erase_Block(uint32_t Address); uint8_t BSP_W25Qx_Erase_Chip(void); /** * @} */ /** @defgroup W25Q128FV_Exported_Functions * @{ */ /** * @} */ /** * @} */ /** * @} */ /** * @} */ #ifdef __cplusplus } #endif #endif /* __W25Qx_H */ /********************************************************************************************************* * * File : ws_W25Qx.c * Hardware Environment: * Build Environment : RealView MDK-ARM Version: 4.20 * Version : V1.0 * By : * * (c) Copyright 2005-2011, WaveShare * http://www.waveshare.net * All Rights Reserved * *********************************************************************************************************/ #include "W25QXX.h" /** * @brief Initializes the W25Q128FV interface. * @retval None */ uint8_t BSP_W25Qx_Init(void) { /* Reset W25Qxxx */ BSP_W25Qx_Reset(); return BSP_W25Qx_GetStatus(); } /** * @brief This function reset the W25Qx. * @retval None */ static void BSP_W25Qx_Reset(void) { uint8_t cmd[2] = {RESET_ENABLE_CMD,RESET_MEMORY_CMD}; W25Qx_Enable(); /* Send the reset command */ HAL_SPI_Transmit(&hspi1, cmd, 2, W25Qx_TIMEOUT_VALUE); W25Qx_Disable(); } /** * @brief Reads current status of the W25Q128FV. * @retval W25Q128FV memory status */ static uint8_t BSP_W25Qx_GetStatus(void) { uint8_t cmd[] = {READ_STATUS_REG1_CMD}; uint8_t status; W25Qx_Enable(); /* Send the read status command */ HAL_SPI_Transmit(&hspi1, cmd, 1, W25Qx_TIMEOUT_VALUE); /* Reception of the data */ HAL_SPI_Receive(&hspi1,&status, 1, W25Qx_TIMEOUT_VALUE); W25Qx_Disable(); /* Check the value of the register */ if((status & W25Q128FV_FSR_BUSY) != 0) { return W25Qx_BUSY; } else { return W25Qx_OK; } } /** * @brief This function send a Write Enable and wait it is effective. * @retval None */ uint8_t BSP_W25Qx_WriteEnable(void) { uint8_t cmd[] = {WRITE_ENABLE_CMD}; uint32_t tickstart = HAL_GetTick(); /*Select the FLASH: Chip Select low */ W25Qx_Enable(); /* Send the read ID command */ HAL_SPI_Transmit(&hspi1, cmd, 1, W25Qx_TIMEOUT_VALUE); /*Deselect the FLASH: Chip Select high */ W25Qx_Disable(); /* Wait the end of Flash writing */ while(BSP_W25Qx_GetStatus() == W25Qx_BUSY); { /* Check for the Timeout */ if((HAL_GetTick() - tickstart) > W25Qx_TIMEOUT_VALUE) { return W25Qx_TIMEOUT; } } return W25Qx_OK; } /** * @brief Read Manufacture/Device ID. * @param return value address * @retval None */ void BSP_W25Qx_Read_ID(uint8_t *ID) { uint8_t cmd[4] = {READ_ID_CMD,0x00,0x00,0x00}; W25Qx_Enable(); /* Send the read ID command */ HAL_SPI_Transmit(&hspi1, cmd, 4, W25Qx_TIMEOUT_VALUE); /* Reception of the data */ HAL_SPI_Receive(&hspi1,ID, 2, W25Qx_TIMEOUT_VALUE); W25Qx_Disable(); } /** * @brief Reads an amount of data from the QSPI memory. * @param pData: Pointer to data to be read * @param ReadAddr: Read start address * @param Size: Size of data to read * @retval QSPI memory status */ uint8_t BSP_W25Qx_Read(uint8_t* pData, uint32_t ReadAddr, uint32_t Size) { uint8_t cmd[4]; /* Configure the command */ cmd[0] = READ_CMD; cmd[1] = (uint8_t)(ReadAddr >> 16); cmd[2] = (uint8_t)(ReadAddr >> 8); cmd[3] = (uint8_t)(ReadAddr); W25Qx_Enable(); /* Send the read ID command */ HAL_SPI_Transmit(&hspi1, cmd, 4, W25Qx_TIMEOUT_VALUE); /* Reception of the data */ if (HAL_SPI_Receive(&hspi1, pData,Size,W25Qx_TIMEOUT_VALUE) != HAL_OK) { return W25Qx_ERROR; } W25Qx_Disable(); return W25Qx_OK; } /** * @brief Writes an amount of data to the QSPI memory. * @param pData: Pointer to data to be written * @param WriteAddr: Write start address * @param Size: Size of data to write,No more than 256byte. * @retval QSPI memory status */ uint8_t BSP_W25Qx_Write(uint8_t* pData, uint32_t WriteAddr, uint32_t Size) { uint8_t cmd[4]; uint32_t end_addr, current_size, current_addr; uint32_t tickstart = HAL_GetTick(); /* Calculation of the size between the write address and the end of the page */ current_addr = 0; while (current_addr <= WriteAddr) { current_addr += W25Q128FV_PAGE_SIZE; } current_size = current_addr - WriteAddr; /* Check if the size of the data is less than the remaining place in the page */ if (current_size > Size) { current_size = Size; } /* Initialize the adress variables */ current_addr = WriteAddr; end_addr = WriteAddr + Size; /* Perform the write page by page */ do { /* Configure the command */ cmd[0] = PAGE_PROG_CMD; cmd[1] = (uint8_t)(current_addr >> 16); cmd[2] = (uint8_t)(current_addr >> 8); cmd[3] = (uint8_t)(current_addr); /* Enable write operations */ BSP_W25Qx_WriteEnable(); W25Qx_Enable(); /* Send the command */ if (HAL_SPI_Transmit(&hspi1,cmd, 4, W25Qx_TIMEOUT_VALUE) != HAL_OK) { return W25Qx_ERROR; } /* Transmission of the data */ if (HAL_SPI_Transmit(&hspi1, pData,current_size, W25Qx_TIMEOUT_VALUE) != HAL_OK) { return W25Qx_ERROR; } W25Qx_Disable(); /* Wait the end of Flash writing */ while(BSP_W25Qx_GetStatus() == W25Qx_BUSY); { /* Check for the Timeout */ if((HAL_GetTick() - tickstart) > W25Qx_TIMEOUT_VALUE) { return W25Qx_TIMEOUT; } } /* Update the address and size variables for next page programming */ current_addr += current_size; pData += current_size; current_size = ((current_addr + W25Q128FV_PAGE_SIZE) > end_addr) ? (end_addr - current_addr) : W25Q128FV_PAGE_SIZE; } while (current_addr < end_addr); return W25Qx_OK; } /** * @brief Erases the specified block of the QSPI memory. * @param BlockAddress: Block address to erase * @retval QSPI memory status */ uint8_t BSP_W25Qx_Erase_Block(uint32_t Address) { uint8_t cmd[4]; uint32_t tickstart = HAL_GetTick(); cmd[0] = SECTOR_ERASE_CMD; cmd[1] = (uint8_t)(Address >> 16); cmd[2] = (uint8_t)(Address >> 8); cmd[3] = (uint8_t)(Address); /* Enable write operations */ BSP_W25Qx_WriteEnable(); /*Select the FLASH: Chip Select low */ W25Qx_Enable(); /* Send the read ID command */ HAL_SPI_Transmit(&hspi1, cmd, 4, W25Qx_TIMEOUT_VALUE); /*Deselect the FLASH: Chip Select high */ W25Qx_Disable(); /* Wait the end of Flash writing */ while(BSP_W25Qx_GetStatus() == W25Qx_BUSY); { /* Check for the Timeout */ if((HAL_GetTick() - tickstart) > W25Q128FV_SECTOR_ERASE_MAX_TIME) { return W25Qx_TIMEOUT; } } return W25Qx_OK; } /** * @brief Erases the entire QSPI memory.This function will take a very long time. * @retval QSPI memory status */ uint8_t BSP_W25Qx_Erase_Chip(void) { uint8_t cmd[4]; uint32_t tickstart = HAL_GetTick(); cmd[0] = SECTOR_ERASE_CMD; /* Enable write operations */ BSP_W25Qx_WriteEnable(); /*Select the FLASH: Chip Select low */ W25Qx_Enable(); /* Send the read ID command */ HAL_SPI_Transmit(&hspi1, cmd, 1, W25Qx_TIMEOUT_VALUE); /*Deselect the FLASH: Chip Select high */ W25Qx_Disable(); /* Wait the end of Flash writing */ while(BSP_W25Qx_GetStatus() != W25Qx_BUSY); { /* Check for the Timeout */ if((HAL_GetTick() - tickstart) > W25Q128FV_BULK_ERASE_MAX_TIME) { return W25Qx_TIMEOUT; } } return W25Qx_OK; } /* USER CODE BEGIN Header */ /** ****************************************************************************** * @file : main.c * @brief : Main program body ****************************************************************************** * @attention * * Copyright (c) 2025 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 */ /* Includes ------------------------------------------------------------------*/ #include "main.h" #include "spi.h" #include "usart.h" #include "gpio.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ #include "stm32f1xx_hal.h" #include <stdio.h> #include <string.h> #include "W25QXX.h" uint8_t wData[0x100]; uint8_t rData[0x100]; uint32_t i; uint8_t ID[2]; extern UART_HandleTypeDef huart1; //声明串口 /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ /* USER CODE BEGIN PTD */ /* USER CODE END PTD */ /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN PD */ /** * 函数功能: 重定向c库函数printf到DEBUG_USARTx * 输入参数: 无 * 返 回 值: 无 * 说 明:无 */ int fputc(int ch, FILE *f) { HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xffff); return ch; } /** * 函数功能: 重定向c库函数getchar,scanf到DEBUG_USARTx * 输入参数: 无 * 返 回 值: 无 * 说 明:无 */ int fgetc(FILE *f) { uint8_t ch = 0; HAL_UART_Receive(&huart1, &ch, 1, 0xffff); return ch; } /* USER CODE END PD */ /* Private macro -------------------------------------------------------------*/ /* USER CODE BEGIN PM */ /* 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_USART1_UART_Init(); MX_SPI1_Init(); /* USER CODE BEGIN 2 */ printf("\r\n SPI-W25Qxxx Example \r\n\r\n"); /*##-1- Read the device ID ########################*/ BSP_W25Qx_Init(); BSP_W25Qx_Read_ID(ID); printf(" W25Qxxx ID is : 0x%02X 0x%02X \r\n\r\n",ID[0],ID[1]); /*##-2- Erase Block ##################################*/ if(BSP_W25Qx_Erase_Block(0) == W25Qx_OK) printf(" SPI Erase Block ok\r\n"); else Error_Handler(); /*##-3- Written to the flash ########################*/ /* fill buffer */ for(i =0;i<0x100;i ++) { wData[i] = i; rData[i] = 0; } if(BSP_W25Qx_Write(wData,0x00,0x100)== W25Qx_OK) printf(" SPI Write ok\r\n"); else Error_Handler(); /*##-4- Read the flash ########################*/ if(BSP_W25Qx_Read(rData,0x00,0x100)== W25Qx_OK) printf(" SPI Read ok\r\n\r\n"); else Error_Handler(); printf("SPI Read Data : \r\n"); for(i =0;i<0x100;i++) printf("0x%02X ",rData[i]); printf("\r\n\r\n"); /*##-5- check date ########################*/ if(memcmp(wData,rData,0x100) == 0 ) printf(" W25Q128FV SPI Test OK\r\n"); else printf(" W25Q128FV SPI Test False\r\n"); /* 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 */ /* USER CODE BEGIN Header */ /** ****************************************************************************** * @file gpio.c * @brief This file provides code for the configuration * of all used GPIO pins. ****************************************************************************** * @attention * * Copyright (c) 2025 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 */ /* Includes ------------------------------------------------------------------*/ #include "gpio.h" /* USER CODE BEGIN 0 */ /* USER CODE END 0 */ /*----------------------------------------------------------------------------*/ /* Configure GPIO */ /*----------------------------------------------------------------------------*/ /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /** Configure pins as * Analog * Input * Output * EVENT_OUT * EXTI */ void MX_GPIO_Init(void) { GPIO_InitTypeDef GPIO_InitStruct = {0}; /* GPIO Ports Clock Enable */ __HAL_RCC_GPIOD_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE(); /*Configure GPIO pin Output Level */ HAL_GPIO_WritePin(SPI1_CS_GPIO_Port, SPI1_CS_Pin, GPIO_PIN_RESET); /*Configure GPIO pin : PtPin */ GPIO_InitStruct.Pin = SPI1_CS_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(SPI1_CS_GPIO_Port, &GPIO_InitStruct); } /* USER CODE BEGIN 2 */ /* USER CODE END 2 */ /* USER CODE BEGIN Header */ /** ****************************************************************************** * @file spi.c * @brief This file provides code for the configuration * of the SPI instances. ****************************************************************************** * @attention * * Copyright (c) 2025 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 */ /* Includes ------------------------------------------------------------------*/ #include "spi.h" /* USER CODE BEGIN 0 */ /* USER CODE END 0 */ SPI_HandleTypeDef hspi1; /* SPI1 init function */ void MX_SPI1_Init(void) { /* USER CODE BEGIN SPI1_Init 0 */ /* USER CODE END SPI1_Init 0 */ /* USER CODE BEGIN SPI1_Init 1 */ /* USER CODE END SPI1_Init 1 */ hspi1.Instance = SPI1; hspi1.Init.Mode = SPI_MODE_MASTER; hspi1.Init.Direction = SPI_DIRECTION_2LINES; hspi1.Init.DataSize = SPI_DATASIZE_8BIT; hspi1.Init.CLKPolarity = SPI_POLARITY_LOW; hspi1.Init.CLKPhase = SPI_PHASE_1EDGE; hspi1.Init.NSS = SPI_NSS_SOFT; hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64; hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB; hspi1.Init.TIMode = SPI_TIMODE_DISABLE; hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; hspi1.Init.CRCPolynomial = 10; if (HAL_SPI_Init(&hspi1) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN SPI1_Init 2 */ /* USER CODE END SPI1_Init 2 */ } void HAL_SPI_MspInit(SPI_HandleTypeDef* spiHandle) { GPIO_InitTypeDef GPIO_InitStruct = {0}; if(spiHandle->Instance==SPI1) { /* USER CODE BEGIN SPI1_MspInit 0 */ /* USER CODE END SPI1_MspInit 0 */ /* SPI1 clock enable */ __HAL_RCC_SPI1_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE(); /**SPI1 GPIO Configuration PA5 ------> SPI1_SCK PA6 ------> SPI1_MISO PA7 ------> SPI1_MOSI */ GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_7; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); GPIO_InitStruct.Pin = GPIO_PIN_6; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); /* USER CODE BEGIN SPI1_MspInit 1 */ /* USER CODE END SPI1_MspInit 1 */ } } void HAL_SPI_MspDeInit(SPI_HandleTypeDef* spiHandle) { if(spiHandle->Instance==SPI1) { /* USER CODE BEGIN SPI1_MspDeInit 0 */ /* USER CODE END SPI1_MspDeInit 0 */ /* Peripheral clock disable */ __HAL_RCC_SPI1_CLK_DISABLE(); /**SPI1 GPIO Configuration PA5 ------> SPI1_SCK PA6 ------> SPI1_MISO PA7 ------> SPI1_MOSI */ HAL_GPIO_DeInit(GPIOA, GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7); /* USER CODE BEGIN SPI1_MspDeInit 1 */ /* USER CODE END SPI1_MspDeInit 1 */ } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* USER CODE BEGIN Header */ /** ****************************************************************************** * @file usart.c * @brief This file provides code for the configuration * of the USART instances. ****************************************************************************** * @attention * * Copyright (c) 2025 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 */ /* Includes ------------------------------------------------------------------*/ #include "usart.h" /* USER CODE BEGIN 0 */ /* USER CODE END 0 */ UART_HandleTypeDef huart1; /* USART1 init function */ 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; if (HAL_UART_Init(&huart1) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN USART1_Init 2 */ /* USER CODE END USART1_Init 2 */ } void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) { GPIO_InitTypeDef GPIO_InitStruct = {0}; if(uartHandle->Instance==USART1) { /* USER CODE BEGIN USART1_MspInit 0 */ /* USER CODE END USART1_MspInit 0 */ /* USART1 clock enable */ __HAL_RCC_USART1_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE(); /**USART1 GPIO Configuration PA9 ------> USART1_TX PA10 ------> USART1_RX */ GPIO_InitStruct.Pin = GPIO_PIN_9; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); GPIO_InitStruct.Pin = GPIO_PIN_10; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); /* USER CODE BEGIN USART1_MspInit 1 */ /* USER CODE END USART1_MspInit 1 */ } } void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle) { if(uartHandle->Instance==USART1) { /* USER CODE BEGIN USART1_MspDeInit 0 */ /* USER CODE END USART1_MspDeInit 0 */ /* Peripheral clock disable */ __HAL_RCC_USART1_CLK_DISABLE(); /**USART1 GPIO Configuration PA9 ------> USART1_TX PA10 ------> USART1_RX */ HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_10); /* USER CODE BEGIN USART1_MspDeInit 1 */ /* USER CODE END USART1_MspDeInit 1 */ } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* USER CODE BEGIN Header */ /** ****************************************************************************** * @file stm32f1xx_it.c * @brief Interrupt Service Routines. ****************************************************************************** * @attention * * Copyright (c) 2025 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 */ /* Includes ------------------------------------------------------------------*/ #include "main.h" #include "stm32f1xx_it.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ /* USER CODE BEGIN TD */ /* USER CODE END TD */ /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN PD */ /* USER CODE END PD */ /* Private macro -------------------------------------------------------------*/ /* USER CODE BEGIN PM */ /* USER CODE END PM */ /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN PV */ /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ /* USER CODE BEGIN PFP */ /* USER CODE END PFP */ /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ /* USER CODE END 0 */ /* External variables --------------------------------------------------------*/ /* USER CODE BEGIN EV */ /* USER CODE END EV */ /******************************************************************************/ /* Cortex-M3 Processor Interruption and Exception Handlers */ /******************************************************************************/ /** * @brief This function handles Non maskable interrupt. */ void NMI_Handler(void) { /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ /* USER CODE END NonMaskableInt_IRQn 0 */ /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ while (1) { } /* USER CODE END NonMaskableInt_IRQn 1 */ } /** * @brief This function handles Hard fault interrupt. */ void HardFault_Handler(void) { /* USER CODE BEGIN HardFault_IRQn 0 */ /* USER CODE END HardFault_IRQn 0 */ while (1) { /* USER CODE BEGIN W1_HardFault_IRQn 0 */ /* USER CODE END W1_HardFault_IRQn 0 */ } } /** * @brief This function handles Memory management fault. */ void MemManage_Handler(void) { /* USER CODE BEGIN MemoryManagement_IRQn 0 */ /* USER CODE END MemoryManagement_IRQn 0 */ while (1) { /* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */ /* USER CODE END W1_MemoryManagement_IRQn 0 */ } } /** * @brief This function handles Prefetch fault, memory access fault. */ void BusFault_Handler(void) { /* USER CODE BEGIN BusFault_IRQn 0 */ /* USER CODE END BusFault_IRQn 0 */ while (1) { /* USER CODE BEGIN W1_BusFault_IRQn 0 */ /* USER CODE END W1_BusFault_IRQn 0 */ } } /** * @brief This function handles Undefined instruction or illegal state. */ void UsageFault_Handler(void) { /* USER CODE BEGIN UsageFault_IRQn 0 */ /* USER CODE END UsageFault_IRQn 0 */ while (1) { /* USER CODE BEGIN W1_UsageFault_IRQn 0 */ /* USER CODE END W1_UsageFault_IRQn 0 */ } } /** * @brief This function handles System service call via SWI instruction. */ void SVC_Handler(void) { /* USER CODE BEGIN SVCall_IRQn 0 */ /* USER CODE END SVCall_IRQn 0 */ /* USER CODE BEGIN SVCall_IRQn 1 */ /* USER CODE END SVCall_IRQn 1 */ } /** * @brief This function handles Debug monitor. */ void DebugMon_Handler(void) { /* USER CODE BEGIN DebugMonitor_IRQn 0 */ /* USER CODE END DebugMonitor_IRQn 0 */ /* USER CODE BEGIN DebugMonitor_IRQn 1 */ /* USER CODE END DebugMonitor_IRQn 1 */ } /** * @brief This function handles Pendable request for system service. */ void PendSV_Handler(void) { /* USER CODE BEGIN PendSV_IRQn 0 */ /* USER CODE END PendSV_IRQn 0 */ /* USER CODE BEGIN PendSV_IRQn 1 */ /* USER CODE END PendSV_IRQn 1 */ } /** * @brief This function handles System tick timer. */ void SysTick_Handler(void) { /* USER CODE BEGIN SysTick_IRQn 0 */ /* USER CODE END SysTick_IRQn 0 */ HAL_IncTick(); /* USER CODE BEGIN SysTick_IRQn 1 */ /* USER CODE END SysTick_IRQn 1 */ } /******************************************************************************/ /* STM32F1xx Peripheral Interrupt Handlers */ /* Add here the Interrupt Handlers for the used peripherals. */ /* For the available peripheral interrupt handler names, */ /* please refer to the startup file (startup_stm32f1xx.s). */ /******************************************************************************/ /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* USER CODE BEGIN Header */ /** ****************************************************************************** * @file stm32f1xx_hal_msp.c * @brief This file provides code for the MSP Initialization * and de-Initialization codes. ****************************************************************************** * @attention * * Copyright (c) 2025 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 */ /* Includes ------------------------------------------------------------------*/ #include "main.h" /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ /* USER CODE BEGIN TD */ /* USER CODE END TD */ /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN Define */ /* USER CODE END Define */ /* Private macro -------------------------------------------------------------*/ /* USER CODE BEGIN Macro */ /* USER CODE END Macro */ /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN PV */ /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ /* USER CODE BEGIN PFP */ /* USER CODE END PFP */ /* External functions --------------------------------------------------------*/ /* USER CODE BEGIN ExternalFunctions */ /* USER CODE END ExternalFunctions */ /* USER CODE BEGIN 0 */ /* USER CODE END 0 */ /** * Initializes the Global MSP. */ void HAL_MspInit(void) { /* USER CODE BEGIN MspInit 0 */ /* USER CODE END MspInit 0 */ __HAL_RCC_AFIO_CLK_ENABLE(); __HAL_RCC_PWR_CLK_ENABLE(); /* System interrupt init*/ /** NOJTAG: JTAG-DP Disabled and SW-DP Enabled */ __HAL_AFIO_REMAP_SWJ_NOJTAG(); /* USER CODE BEGIN MspInit 1 */ /* USER CODE END MspInit 1 */ } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ 这段代码串口打印出来的都是0x00,是什么原因,要怎么改,使用的芯片为stm32f103rct6,cpol设置为low cpha设置为1Edge,SPI1_sck、SPI1_miso、SPI1_mosi分别对应的引脚为PA5、PA6、PA7

/********************************************************************************************************* * * File : ws_W25Qx.c * Hardware Environment: * Build Environment : RealView MDK-ARM Version: 4.20 * Version : V1.0 * By : * * (c) Copyright 2005-2011, WaveShare * http://www.waveshare.net * All Rights Reserved * *********************************************************************************************************/ #include "W25QXX.h" /** * @brief Initializes the W25Q128FV interface. * @retval None */ uint8_t BSP_W25Qx_Init(void) { /* Reset W25Qxxx */ BSP_W25Qx_Reset(); return BSP_W25Qx_GetStatus(); } /** * @brief This function reset the W25Qx. * @retval None */ static void BSP_W25Qx_Reset(void) { uint8_t cmd[2] = {RESET_ENABLE_CMD,RESET_MEMORY_CMD}; W25Qx_Enable(); /* Send the reset command */ HAL_SPI_Transmit(&hspi2, cmd, 2, W25Qx_TIMEOUT_VALUE); W25Qx_Disable(); } /** * @brief Reads current status of the W25Q128FV. * @retval W25Q128FV memory status */ static uint8_t BSP_W25Qx_GetStatus(void) { uint8_t cmd[] = {READ_STATUS_REG1_CMD}; uint8_t status; W25Qx_Enable(); /* Send the read status command */ HAL_SPI_Transmit(&hspi2, cmd, 1, W25Qx_TIMEOUT_VALUE); /* Reception of the data */ HAL_SPI_Receive(&hspi2,&status, 1, W25Qx_TIMEOUT_VALUE); W25Qx_Disable(); /* Check the value of the register */ if((status & W25Q128FV_FSR_BUSY) != 0) { return W25Qx_BUSY; } else { return W25Qx_OK; } } /** * @brief This function send a Write Enable and wait it is effective. * @retval None */ uint8_t BSP_W25Qx_WriteEnable(void) { uint8_t cmd[] = {WRITE_ENABLE_CMD}; uint32_t tickstart = HAL_GetTick(); /*Select the FLASH: Chip Select low */ W25Qx_Enable(); /* Send the read ID command */ HAL_SPI_Transmit(&hspi2, cmd, 1, W25Qx_TIMEOUT_VALUE); /*Deselect the FLASH: Chip Select high */ W25Qx_Disable(); /* Wait the end of Flash writing */ while(BSP_W25Qx_GetStatus() == W25Qx_BUSY); { /* Check for the Timeout */ if((HAL_GetTick() - tickstart) > W25Qx_TIMEOUT_VALUE) { return W25Qx_TIMEOUT; } } return W25Qx_OK; } /** * @brief Read Manufacture/Device ID. * @param return value address * @retval None */ void BSP_W25Qx_Read_ID(uint8_t *ID) { uint8_t cmd[4] = {READ_ID_CMD,0x00,0x00,0x00}; W25Qx_Enable(); /* Send the read ID command */ HAL_SPI_Transmit(&hspi2, cmd, 4, W25Qx_TIMEOUT_VALUE); /* Reception of the data */ HAL_SPI_Receive(&hspi2,ID, 2, W25Qx_TIMEOUT_VALUE); W25Qx_Disable(); } /** * @brief Reads an amount of data from the QSPI memory. * @param pData: Pointer to data to be read * @param ReadAddr: Read start address * @param Size: Size of data to read * @retval QSPI memory status */ uint8_t BSP_W25Qx_Read(uint8_t* pData, uint32_t ReadAddr, uint32_t Size) { uint8_t cmd[4]; /* Configure the command */ cmd[0] = READ_CMD; cmd[1] = (uint8_t)(ReadAddr >> 16); cmd[2] = (uint8_t)(ReadAddr >> 8); cmd[3] = (uint8_t)(ReadAddr); W25Qx_Enable(); /* Send the read ID command */ HAL_SPI_Transmit(&hspi2, cmd, 4, W25Qx_TIMEOUT_VALUE); /* Reception of the data */ if (HAL_SPI_Receive(&hspi2, pData,Size,W25Qx_TIMEOUT_VALUE) != HAL_OK) { return W25Qx_ERROR; } W25Qx_Disable(); return W25Qx_OK; } /** * @brief Writes an amount of data to the QSPI memory. * @param pData: Pointer to data to be written * @param WriteAddr: Write start address * @param Size: Size of data to write,No more than 256byte. * @retval QSPI memory status */ uint8_t BSP_W25Qx_Write(uint8_t* pData, uint32_t WriteAddr, uint32_t Size) { uint8_t cmd[4]; uint32_t end_addr, current_size, current_addr; uint32_t tickstart = HAL_GetTick(); /* Calculation of the size between the write address and the end of the page */ current_addr = 0; while (current_addr <= WriteAddr) { current_addr += W25Q128FV_PAGE_SIZE; } current_size = current_addr - WriteAddr; /* Check if the size of the data is less than the remaining place in the page */ if (current_size > Size) { current_size = Size; } /* Initialize the adress variables */ current_addr = WriteAddr; end_addr = WriteAddr + Size; /* Perform the write page by page */ do { /* Configure the command */ cmd[0] = PAGE_PROG_CMD; cmd[1] = (uint8_t)(current_addr >> 16); cmd[2] = (uint8_t)(current_addr >> 8); cmd[3] = (uint8_t)(current_addr); /* Enable write operations */ BSP_W25Qx_WriteEnable(); W25Qx_Enable(); /* Send the command */ if (HAL_SPI_Transmit(&hspi2,cmd, 4, W25Qx_TIMEOUT_VALUE) != HAL_OK) { return W25Qx_ERROR; } /* Transmission of the data */ if (HAL_SPI_Transmit(&hspi2, pData,current_size, W25Qx_TIMEOUT_VALUE) != HAL_OK) { return W25Qx_ERROR; } W25Qx_Disable(); /* Wait the end of Flash writing */ while(BSP_W25Qx_GetStatus() == W25Qx_BUSY); { /* Check for the Timeout */ if((HAL_GetTick() - tickstart) > W25Qx_TIMEOUT_VALUE) { return W25Qx_TIMEOUT; } } /* Update the address and size variables for next page programming */ current_addr += current_size; pData += current_size; current_size = ((current_addr + W25Q128FV_PAGE_SIZE) > end_addr) ? (end_addr - current_addr) : W25Q128FV_PAGE_SIZE; } while (current_addr < end_addr); return W25Qx_OK; } /** * @brief Erases the specified block of the QSPI memory. * @param BlockAddress: Block address to erase * @retval QSPI memory status */ uint8_t BSP_W25Qx_Erase_Block(uint32_t Address) { uint8_t cmd[4]; uint32_t tickstart = HAL_GetTick(); cmd[0] = SECTOR_ERASE_CMD; cmd[1] = (uint8_t)(Address >> 16); cmd[2] = (uint8_t)(Address >> 8); cmd[3] = (uint8_t)(Address); /* Enable write operations */ BSP_W25Qx_WriteEnable(); /*Select the FLASH: Chip Select low */ W25Qx_Enable(); /* Send the read ID command */ HAL_SPI_Transmit(&hspi2, cmd, 4, W25Qx_TIMEOUT_VALUE); /*Deselect the FLASH: Chip Select high */ W25Qx_Disable(); /* Wait the end of Flash writing */ while(BSP_W25Qx_GetStatus() == W25Qx_BUSY); { /* Check for the Timeout */ if((HAL_GetTick() - tickstart) > W25Q128FV_SECTOR_ERASE_MAX_TIME) { return W25Qx_TIMEOUT; } } return W25Qx_OK; } /** * @brief Erases the entire QSPI memory.This function will take a very long time. * @retval QSPI memory status */ uint8_t BSP_W25Qx_Erase_Chip(void) { uint8_t cmd[4]; uint32_t tickstart = HAL_GetTick(); cmd[0] = SECTOR_ERASE_CMD; /* Enable write operations */ BSP_W25Qx_WriteEnable(); /*Select the FLASH: Chip Select low */ W25Qx_Enable(); /* Send the read ID command */ HAL_SPI_Transmit(&hspi2, cmd, 1, W25Qx_TIMEOUT_VALUE); /*Deselect the FLASH: Chip Select high */ W25Qx_Disable(); /* Wait the end of Flash writing */ while(BSP_W25Qx_GetStatus() != W25Qx_BUSY); { /* Check for the Timeout */ if((HAL_GetTick() - tickstart) > W25Q128FV_BULK_ERASE_MAX_TIME) { return W25Qx_TIMEOUT; } } return W25Qx_OK; } /********************************************************************************************************* * * File : W25Qx.h * Hardware Environment: * Build Environment : RealView MDK-ARM Version: 5.15 * Version : V1.0 * By : * * (c) Copyright 2005-2015, WaveShare * http://www.waveshare.net * All Rights Reserved * *********************************************************************************************************/ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __W25QXX_H #define __W25QXX_H #ifdef __cplusplus extern "C" { #endif /* Includes ------------------------------------------------------------------*/ #include "stm32f1xx.h" #include "spi.h" /** @addtogroup BSP * @{ */ /** @addtogroup Components * @{ */ /** @addtogroup W25Q128FV * @{ */ /** @defgroup W25Q128FV_Exported_Types * @{ */ /** * @} */ /** @defgroup W25Q128FV_Exported_Constants * @{ */ /** * @brief W25Q128FV Configuration */ #define W25Q128FV_FLASH_SIZE 0x1000000 /* 128 MBits => 16MBytes */ #define W25Q128FV_SECTOR_SIZE 0x10000 /* 256 sectors of 64KBytes */ #define W25Q128FV_SUBSECTOR_SIZE 0x1000 /* 4096 subsectors of 4kBytes */ #define W25Q128FV_PAGE_SIZE 0x100 /* 65536 pages of 256 bytes */ #define W25Q128FV_DUMMY_CYCLES_READ 4 #define W25Q128FV_DUMMY_CYCLES_READ_QUAD 10 #define W25Q128FV_BULK_ERASE_MAX_TIME 250000 #define W25Q128FV_SECTOR_ERASE_MAX_TIME 3000 #define W25Q128FV_SUBSECTOR_ERASE_MAX_TIME 800 #define W25Qx_TIMEOUT_VALUE 1000 /** * @brief W25Q128FV Commands */ /* Reset Operations */ #define RESET_ENABLE_CMD 0x66 #define RESET_MEMORY_CMD 0x99 #define ENTER_QPI_MODE_CMD 0x38 #define EXIT_QPI_MODE_CMD 0xFF /* Identification Operations */ #define READ_ID_CMD 0x90 #define DUAL_READ_ID_CMD 0x92 #define QUAD_READ_ID_CMD 0x94 #define READ_JEDEC_ID_CMD 0x9F /* Read Operations */ #define READ_CMD 0x03 #define FAST_READ_CMD 0x0B #define DUAL_OUT_FAST_READ_CMD 0x3B #define DUAL_INOUT_FAST_READ_CMD 0xBB #define QUAD_OUT_FAST_READ_CMD 0x6B #define QUAD_INOUT_FAST_READ_CMD 0xEB /* Write Operations */ #define WRITE_ENABLE_CMD 0x06 #define WRITE_DISABLE_CMD 0x04 /* Register Operations */ #define READ_STATUS_REG1_CMD 0x05 #define READ_STATUS_REG2_CMD 0x35 #define READ_STATUS_REG3_CMD 0x15 #define WRITE_STATUS_REG1_CMD 0x01 #define WRITE_STATUS_REG2_CMD 0x31 #define WRITE_STATUS_REG3_CMD 0x11 /* Program Operations */ #define PAGE_PROG_CMD 0x02 #define QUAD_INPUT_PAGE_PROG_CMD 0x32 /* Erase Operations */ #define SECTOR_ERASE_CMD 0x20 #define CHIP_ERASE_CMD 0xC7 #define PROG_ERASE_RESUME_CMD 0x7A #define PROG_ERASE_SUSPEND_CMD 0x75 /* Flag Status Register */ #define W25Q128FV_FSR_BUSY ((uint8_t)0x01) /*!< busy */ #define W25Q128FV_FSR_WREN ((uint8_t)0x02) /*!< write enable */ #define W25Q128FV_FSR_QE ((uint8_t)0x02) /*!< quad enable */ #define W25Qx_Enable() HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_RESET) #define W25Qx_Disable() HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_SET) #define W25Qx_OK ((uint8_t)0x00) #define W25Qx_ERROR ((uint8_t)0x01) #define W25Qx_BUSY ((uint8_t)0x02) #define W25Qx_TIMEOUT ((uint8_t)0x03) uint8_t BSP_W25Qx_Init(void); static void BSP_W25Qx_Reset(void); static uint8_t BSP_W25Qx_GetStatus(void); uint8_t BSP_W25Qx_WriteEnable(void); void BSP_W25Qx_Read_ID(uint8_t *ID); uint8_t BSP_W25Qx_Read(uint8_t* pData, uint32_t ReadAddr, uint32_t Size); uint8_t BSP_W25Qx_Write(uint8_t* pData, uint32_t WriteAddr, uint32_t Size); uint8_t BSP_W25Qx_Erase_Block(uint32_t Address); uint8_t BSP_W25Qx_Erase_Chip(void); /** * @} */ /** @defgroup W25Q128FV_Exported_Functions * @{ */ /** * @} */ /** * @} */ /** * @} */ /** * @} */ #ifdef __cplusplus } #endif #endif /* __W25Qx_H */ /* USER CODE BEGIN Header */ /** ****************************************************************************** * @file : main.c * @brief : Main program body ****************************************************************************** * @attention * * Copyright (c) 2025 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 */ /* Includes ------------------------------------------------------------------*/ #include "main.h" #include "spi.h" #include "usart.h" #include "gpio.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ #include "stm32f1xx_hal.h" #include <stdio.h> #include <string.h> #include "W25QXX.h" uint8_t wData[0x100]; uint8_t rData[0x100]; uint32_t i; uint8_t ID[2]; extern UART_HandleTypeDef huart1; //声明串口 /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ /* USER CODE BEGIN PTD */ /* USER CODE END PTD */ /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN PD */ /** * 函数功能: 重定向c库函数printf到DEBUG_USARTx * 输入参数: 无 * 返 回 值: 无 * 说 明:无 */ int fputc(int ch, FILE *f) { HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xffff); return ch; } /** * 函数功能: 重定向c库函数getchar,scanf到DEBUG_USARTx * 输入参数: 无 * 返 回 值: 无 * 说 明:无 */ int fgetc(FILE *f) { uint8_t ch = 0; HAL_UART_Receive(&huart1, &ch, 1, 0xffff); return ch; } /* USER CODE END PD */ /* Private macro -------------------------------------------------------------*/ /* USER CODE BEGIN PM */ /* 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_SPI2_Init(); MX_USART1_UART_Init(); /* USER CODE BEGIN 2 */ printf("\r\n SPI-W25Qxxx Example \r\n\r\n"); /*##-1- Read the device ID ########################*/ BSP_W25Qx_Init(); BSP_W25Qx_Read_ID(ID); printf(" W25Qxxx ID is : 0x%02X 0x%02X \r\n\r\n",ID[0],ID[1]); /*##-2- Erase Block ##################################*/ if(BSP_W25Qx_Erase_Block(0) == W25Qx_OK) printf(" SPI Erase Block ok\r\n"); else Error_Handler(); /*##-3- Written to the flash ########################*/ /* fill buffer */ for(i =0;i<0x100;i ++) { wData[i] = i; rData[i] = 0; } if(BSP_W25Qx_Write(wData,0x00,0x100)== W25Qx_OK) printf(" SPI Write ok\r\n"); else Error_Handler(); /*##-4- Read the flash ########################*/ if(BSP_W25Qx_Read(rData,0x00,0x100)== W25Qx_OK) printf(" SPI Read ok\r\n\r\n"); else Error_Handler(); printf("SPI Read Data : \r\n"); for(i =0;i<0x100;i++) printf("0x%02X ",rData[i]); printf("\r\n\r\n"); /*##-5- check date ########################*/ if(memcmp(wData,rData,0x100) == 0 ) printf(" W25Q128FV SPI Test OK\r\n"); else printf(" W25Q128FV SPI Test False\r\n"); /* 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 */ /* USER CODE BEGIN Header */ /** ****************************************************************************** * @file gpio.c * @brief This file provides code for the configuration * of all used GPIO pins. ****************************************************************************** * @attention * * Copyright (c) 2025 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 */ /* Includes ------------------------------------------------------------------*/ #include "gpio.h" /* USER CODE BEGIN 0 */ /* USER CODE END 0 */ /*----------------------------------------------------------------------------*/ /* Configure GPIO */ /*----------------------------------------------------------------------------*/ /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /** Configure pins as * Analog * Input * Output * EVENT_OUT * EXTI */ void MX_GPIO_Init(void) { GPIO_InitTypeDef GPIO_InitStruct = {0}; /* GPIO Ports Clock Enable */ __HAL_RCC_GPIOD_CLK_ENABLE(); __HAL_RCC_GPIOB_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE(); /*Configure GPIO pin Output Level */ HAL_GPIO_WritePin(SPI2_CS_GPIO_Port, SPI2_CS_Pin, GPIO_PIN_RESET); /*Configure GPIO pin : PtPin */ GPIO_InitStruct.Pin = SPI2_CS_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(SPI2_CS_GPIO_Port, &GPIO_InitStruct); } /* USER CODE BEGIN 2 */ /* USER CODE END 2 */ /* USER CODE BEGIN Header */ /** ****************************************************************************** * @file spi.c * @brief This file provides code for the configuration * of the SPI instances. ****************************************************************************** * @attention * * Copyright (c) 2025 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 */ /* Includes ------------------------------------------------------------------*/ #include "spi.h" /* USER CODE BEGIN 0 */ /* USER CODE END 0 */ SPI_HandleTypeDef hspi2; /* SPI2 init function */ 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 */ 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_64; hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB; hspi2.Init.TIMode = SPI_TIMODE_DISABLE; hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; hspi2.Init.CRCPolynomial = 10; if (HAL_SPI_Init(&hspi2) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN SPI2_Init 2 */ /* USER CODE END SPI2_Init 2 */ } void HAL_SPI_MspInit(SPI_HandleTypeDef* spiHandle) { GPIO_InitTypeDef GPIO_InitStruct = {0}; if(spiHandle->Instance==SPI2) { /* USER CODE BEGIN SPI2_MspInit 0 */ /* USER CODE END SPI2_MspInit 0 */ /* SPI2 clock enable */ __HAL_RCC_SPI2_CLK_ENABLE(); __HAL_RCC_GPIOB_CLK_ENABLE(); /**SPI2 GPIO Configuration PB13 ------> SPI2_SCK PB14 ------> SPI2_MISO PB15 ------> SPI2_MOSI */ GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_15; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); GPIO_InitStruct.Pin = GPIO_PIN_14; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); /* USER CODE BEGIN SPI2_MspInit 1 */ /* USER CODE END SPI2_MspInit 1 */ } } void HAL_SPI_MspDeInit(SPI_HandleTypeDef* spiHandle) { if(spiHandle->Instance==SPI2) { /* USER CODE BEGIN SPI2_MspDeInit 0 */ /* USER CODE END SPI2_MspDeInit 0 */ /* Peripheral clock disable */ __HAL_RCC_SPI2_CLK_DISABLE(); /**SPI2 GPIO Configuration PB13 ------> SPI2_SCK PB14 ------> SPI2_MISO PB15 ------> SPI2_MOSI */ HAL_GPIO_DeInit(GPIOB, GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15); /* USER CODE BEGIN SPI2_MspDeInit 1 */ /* USER CODE END SPI2_MspDeInit 1 */ } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 *//* USER CODE BEGIN Header */ /** ****************************************************************************** * @file usart.c * @brief This file provides code for the configuration * of the USART instances. ****************************************************************************** * @attention * * Copyright (c) 2025 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 */ /* Includes ------------------------------------------------------------------*/ #include "usart.h" /* USER CODE BEGIN 0 */ /* USER CODE END 0 */ UART_HandleTypeDef huart1; /* USART1 init function */ 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; if (HAL_UART_Init(&huart1) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN USART1_Init 2 */ /* USER CODE END USART1_Init 2 */ } void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) { GPIO_InitTypeDef GPIO_InitStruct = {0}; if(uartHandle->Instance==USART1) { /* USER CODE BEGIN USART1_MspInit 0 */ /* USER CODE END USART1_MspInit 0 */ /* USART1 clock enable */ __HAL_RCC_USART1_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE(); /**USART1 GPIO Configuration PA9 ------> USART1_TX PA10 ------> USART1_RX */ GPIO_InitStruct.Pin = GPIO_PIN_9; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); GPIO_InitStruct.Pin = GPIO_PIN_10; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); /* USER CODE BEGIN USART1_MspInit 1 */ /* USER CODE END USART1_MspInit 1 */ } } void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle) { if(uartHandle->Instance==USART1) { /* USER CODE BEGIN USART1_MspDeInit 0 */ /* USER CODE END USART1_MspDeInit 0 */ /* Peripheral clock disable */ __HAL_RCC_USART1_CLK_DISABLE(); /**USART1 GPIO Configuration PA9 ------> USART1_TX PA10 ------> USART1_RX */ HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_10); /* USER CODE BEGIN USART1_MspDeInit 1 */ /* USER CODE END USART1_MspDeInit 1 */ } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* USER CODE BEGIN Header */ /** ****************************************************************************** * @file usart.c * @brief This file provides code for the configuration * of the USART instances. ****************************************************************************** * @attention * * Copyright (c) 2025 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 */ /* Includes ------------------------------------------------------------------*/ #include "usart.h" /* USER CODE BEGIN 0 */ /* USER CODE END 0 */ UART_HandleTypeDef huart1; /* USART1 init function */ 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; if (HAL_UART_Init(&huart1) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN USART1_Init 2 */ /* USER CODE END USART1_Init 2 */ } void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) { GPIO_InitTypeDef GPIO_InitStruct = {0}; if(uartHandle->Instance==USART1) { /* USER CODE BEGIN USART1_MspInit 0 */ /* USER CODE END USART1_MspInit 0 */ /* USART1 clock enable */ __HAL_RCC_USART1_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE(); /**USART1 GPIO Configuration PA9 ------> USART1_TX PA10 ------> USART1_RX */ GPIO_InitStruct.Pin = GPIO_PIN_9; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); GPIO_InitStruct.Pin = GPIO_PIN_10; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); /* USER CODE BEGIN USART1_MspInit 1 */ /* USER CODE END USART1_MspInit 1 */ } } void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle) { if(uartHandle->Instance==USART1) { /* USER CODE BEGIN USART1_MspDeInit 0 */ /* USER CODE END USART1_MspDeInit 0 */ /* Peripheral clock disable */ __HAL_RCC_USART1_CLK_DISABLE(); /**USART1 GPIO Configuration PA9 ------> USART1_TX PA10 ------> USART1_RX */ HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_10); /* USER CODE BEGIN USART1_MspDeInit 1 */ /* USER CODE END USART1_MspDeInit 1 */ } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* USER CODE BEGIN Header */ /** ****************************************************************************** * @file usart.c * @brief This file provides code for the configuration * of the USART instances. ****************************************************************************** * @attention * * Copyright (c) 2025 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 */ /* Includes ------------------------------------------------------------------*/ #include "usart.h" /* USER CODE BEGIN 0 */ /* USER CODE END 0 */ UART_HandleTypeDef huart1; /* USART1 init function */ 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; if (HAL_UART_Init(&huart1) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN USART1_Init 2 */ /* USER CODE END USART1_Init 2 */ } void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) { GPIO_InitTypeDef GPIO_InitStruct = {0}; if(uartHandle->Instance==USART1) { /* USER CODE BEGIN USART1_MspInit 0 */ /* USER CODE END USART1_MspInit 0 */ /* USART1 clock enable */ __HAL_RCC_USART1_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE(); /**USART1 GPIO Configuration PA9 ------> USART1_TX PA10 ------> USART1_RX */ GPIO_InitStruct.Pin = GPIO_PIN_9; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); GPIO_InitStruct.Pin = GPIO_PIN_10; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); /* USER CODE BEGIN USART1_MspInit 1 */ /* USER CODE END USART1_MspInit 1 */ } } void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle) { if(uartHandle->Instance==USART1) { /* USER CODE BEGIN USART1_MspDeInit 0 */ /* USER CODE END USART1_MspDeInit 0 */ /* Peripheral clock disable */ __HAL_RCC_USART1_CLK_DISABLE(); /**USART1 GPIO Configuration PA9 ------> USART1_TX PA10 ------> USART1_RX */ HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_10); /* USER CODE BEGIN USART1_MspDeInit 1 */ /* USER CODE END USART1_MspDeInit 1 */ } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* USER CODE BEGIN Header */ /** ****************************************************************************** * @file stm32f1xx_it.c * @brief Interrupt Service Routines. ****************************************************************************** * @attention * * Copyright (c) 2025 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 */ /* Includes ------------------------------------------------------------------*/ #include "main.h" #include "stm32f1xx_it.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ /* USER CODE BEGIN TD */ /* USER CODE END TD */ /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN PD */ /* USER CODE END PD */ /* Private macro -------------------------------------------------------------*/ /* USER CODE BEGIN PM */ /* USER CODE END PM */ /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN PV */ /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ /* USER CODE BEGIN PFP */ /* USER CODE END PFP */ /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ /* USER CODE END 0 */ /* External variables --------------------------------------------------------*/ /* USER CODE BEGIN EV */ /* USER CODE END EV */ /******************************************************************************/ /* Cortex-M3 Processor Interruption and Exception Handlers */ /******************************************************************************/ /** * @brief This function handles Non maskable interrupt. */ void NMI_Handler(void) { /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ /* USER CODE END NonMaskableInt_IRQn 0 */ /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ while (1) { } /* USER CODE END NonMaskableInt_IRQn 1 */ } /** * @brief This function handles Hard fault interrupt. */ void HardFault_Handler(void) { /* USER CODE BEGIN HardFault_IRQn 0 */ /* USER CODE END HardFault_IRQn 0 */ while (1) { /* USER CODE BEGIN W1_HardFault_IRQn 0 */ /* USER CODE END W1_HardFault_IRQn 0 */ } } /** * @brief This function handles Memory management fault. */ void MemManage_Handler(void) { /* USER CODE BEGIN MemoryManagement_IRQn 0 */ /* USER CODE END MemoryManagement_IRQn 0 */ while (1) { /* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */ /* USER CODE END W1_MemoryManagement_IRQn 0 */ } } /** * @brief This function handles Prefetch fault, memory access fault. */ void BusFault_Handler(void) { /* USER CODE BEGIN BusFault_IRQn 0 */ /* USER CODE END BusFault_IRQn 0 */ while (1) { /* USER CODE BEGIN W1_BusFault_IRQn 0 */ /* USER CODE END W1_BusFault_IRQn 0 */ } } /** * @brief This function handles Undefined instruction or illegal state. */ void UsageFault_Handler(void) { /* USER CODE BEGIN UsageFault_IRQn 0 */ /* USER CODE END UsageFault_IRQn 0 */ while (1) { /* USER CODE BEGIN W1_UsageFault_IRQn 0 */ /* USER CODE END W1_UsageFault_IRQn 0 */ } } /** * @brief This function handles System service call via SWI instruction. */ void SVC_Handler(void) { /* USER CODE BEGIN SVCall_IRQn 0 */ /* USER CODE END SVCall_IRQn 0 */ /* USER CODE BEGIN SVCall_IRQn 1 */ /* USER CODE END SVCall_IRQn 1 */ } /** * @brief This function handles Debug monitor. */ void DebugMon_Handler(void) { /* USER CODE BEGIN DebugMonitor_IRQn 0 */ /* USER CODE END DebugMonitor_IRQn 0 */ /* USER CODE BEGIN DebugMonitor_IRQn 1 */ /* USER CODE END DebugMonitor_IRQn 1 */ } /** * @brief This function handles Pendable request for system service. */ void PendSV_Handler(void) { /* USER CODE BEGIN PendSV_IRQn 0 */ /* USER CODE END PendSV_IRQn 0 */ /* USER CODE BEGIN PendSV_IRQn 1 */ /* USER CODE END PendSV_IRQn 1 */ } /** * @brief This function handles System tick timer. */ void SysTick_Handler(void) { /* USER CODE BEGIN SysTick_IRQn 0 */ /* USER CODE END SysTick_IRQn 0 */ HAL_IncTick(); /* USER CODE BEGIN SysTick_IRQn 1 */ /* USER CODE END SysTick_IRQn 1 */ } /******************************************************************************/ /* STM32F1xx Peripheral Interrupt Handlers */ /* Add here the Interrupt Handlers for the used peripherals. */ /* For the available peripheral interrupt handler names, */ /* please refer to the startup file (startup_stm32f1xx.s). */ /******************************************************************************/ /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* USER CODE BEGIN Header */ /** ****************************************************************************** * @file stm32f1xx_hal_msp.c * @brief This file provides code for the MSP Initialization * and de-Initialization codes. ****************************************************************************** * @attention * * Copyright (c) 2025 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 */ /* Includes ------------------------------------------------------------------*/ #include "main.h" /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ /* USER CODE BEGIN TD */ /* USER CODE END TD */ /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN Define */ /* USER CODE END Define */ /* Private macro -------------------------------------------------------------*/ /* USER CODE BEGIN Macro */ /* USER CODE END Macro */ /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN PV */ /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ /* USER CODE BEGIN PFP */ /* USER CODE END PFP */ /* External functions --------------------------------------------------------*/ /* USER CODE BEGIN ExternalFunctions */ /* USER CODE END ExternalFunctions */ /* USER CODE BEGIN 0 */ /* USER CODE END 0 */ /** * Initializes the Global MSP. */ void HAL_MspInit(void) { /* USER CODE BEGIN MspInit 0 */ /* USER CODE END MspInit 0 */ __HAL_RCC_AFIO_CLK_ENABLE(); __HAL_RCC_PWR_CLK_ENABLE(); /* System interrupt init*/ /** NOJTAG: JTAG-DP Disabled and SW-DP Enabled */ __HAL_AFIO_REMAP_SWJ_NOJTAG(); /* USER CODE BEGIN MspInit 1 */ /* USER CODE END MspInit 1 */ } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */

大家在看

recommend-type

TXT文件合并器一款合并文本文件的工具

TXT文件合并器,一款合并文本文件的工具,可以的。
recommend-type

Scratch语言教程&案例&相关项目资源

这篇文章为想要学习和探索Scratch编程的青少年和初学者们提供了宝贵的教程、案例以及相关项目资源,旨在帮助他们轻松入门Scratch编程,并在实践中不断提升编程能力。 文章首先聚焦于Scratch教程的介绍,强调了教程在Scratch编程学习中的重要性。通过精心挑选的一系列优质教程资源,文章引导读者逐步了解Scratch的基本界面、积木块功能以及编程逻辑等核心概念。这些教程采用图文结合的方式,使得复杂的编程概念变得简单易懂,帮助初学者快速掌握Scratch编程的基础知识。 除了基础教程,文章还深入探讨了Scratch案例学习的价值。通过展示一系列真实而有趣的Scratch案例,文章让读者了解到Scratch在动画设计、游戏制作等领域的广泛应用。这些案例不仅具有创意和趣味性,而且能够帮助读者将所学知识应用到实际项目中,提升解决实际问题的能力。 此外,文章还梳理了与Scratch相关的项目资源,为学习者提供了实践Scratch编程的机会。这些项目资源包括Scratch社区分享的项目、学校或教育机构的实践项目等,为学习者提供了丰富的实战演练场景。通过参与这些项目,学习者不仅可以锻炼编
recommend-type

Xilinx 7系列FPGA手册[打包下载]

Xilinx 7系列FPGA手册打包下载,包括以下手册: 1)ug470_7Series_Config.pdf 2)ug471_7Series_SelectIO.pdf 3)ug472_7Series_Clocking.pdf 4)ug473_7Series_Memory_Resources.pdf 5)ug474_7Series_CLB.pdf 6)ug479_7Series_DSP48E1.pdf 7)ug480_7Series_XADC.pdf 8)ug482_7Series_GTP_Transceivers.pdf
recommend-type

filter LTC1068 模块AD设计 Altium设计 硬件原理图+PCB文件.rar

filter LTC1068 模块AD设计 Altium设计 硬件原理图+PCB文件,2层板设计,Altium Designer 设计的工程文件,包括完整的原理图及PCB文件,可以用Altium(AD)软件打开或修改,可作为你产品设计的参考。
recommend-type

谐响应分析步骤-ANSYS谐响应分析

谐响应分析 第三节:步骤 四个主要步骤: 建模 选择分析类型和选项 施加谐波载荷并求解 观看结果

最新推荐

recommend-type

2022年互联网金融行业分析报告.pptx

2022年互联网金融行业分析报告.pptx
recommend-type

全面解析SOAP库包功能与应用

从给定的文件信息中,我们可以提取到的核心知识点主要集中在“SOAP”这一项技术上,由于提供的信息量有限,这里将尽可能详细地解释SOAP相关的知识。 首先,SOAP代表简单对象访问协议(Simple Object Access Protocol),是一种基于XML的消息传递协议。它主要用于在网络上不同应用程序之间的通信。SOAP定义了如何通过HTTP和XML格式来构造消息,并规定了消息的格式应遵循XML模式。这种消息格式使得两个不同平台或不同编程语言的应用程序之间能够进行松耦合的服务交互。 在分布式计算环境中,SOAP作为一种中间件技术,可以被看作是应用程序之间的一种远程过程调用(RPC)机制。它通常与Web服务结合使用,Web服务是使用特定标准实现的软件系统,它公开了可以通过网络(通常是互联网)访问的API。当客户端与服务端通过SOAP进行通信时,客户端可以调用服务端上特定的方法,而不需要关心该服务是如何实现的,或者是运行在什么类型的服务器上。 SOAP协议的特点主要包括: 1. **平台无关性**:SOAP基于XML,XML是一种跨平台的标准化数据格式,因此SOAP能够跨越不同的操作系统和编程语言平台进行通信。 2. **HTTP协议绑定**:虽然SOAP协议本身独立于传输协议,但是它通常与HTTP协议绑定,这使得SOAP能够利用HTTP的普及性和无需额外配置的优势。 3. **消息模型**:SOAP消息是交换信息的载体,遵循严格的结构,包含三个主要部分:信封(Envelope)、标题(Header)和正文(Body)。信封是消息的外壳,定义了消息的开始和结束;标题可以包含各种可选属性,如安全性信息;正文则是实际的消息内容。 4. **错误处理**:SOAP提供了详细的错误处理机制,可以通过错误码和错误信息来描述消息处理过程中的错误情况。 5. **安全性和事务支持**:SOAP协议可以集成各种安全性标准,如WS-Security,以确保消息传输过程中的安全性和完整性。同时,SOAP消息可以包含事务信息,以便于服务端处理事务性的业务逻辑。 在描述中提到的“所有库包”,这可能意味着包含了SOAP协议的实现、相关工具集或库等。由于信息不足,这里的“库包”具体指的是什么并不清楚,但可以理解为与SOAP相关的软件开发工具包(SDK)或框架,它们使得开发者可以更加方便地创建SOAP消息,处理SOAP请求和响应,以及实现Web服务。 至于“压缩包子文件的文件名称列表”中只有一个单词“soap”,这可能表明实际文件内容仅有一个与SOAP相关的文件,或者是一个压缩包文件的名称为“soap”。由于缺乏更详尽的文件列表,无法进一步分析其可能的内容。 综上所述,SOAP作为一种实现Web服务的技术标准,通过HTTP和XML实现系统间的通信。它支持跨平台、跨语言的服务调用,并具备强大的安全性和错误处理机制。在具体应用中,开发者可能需要用到与之相关的库包或工具集来开发和部署Web服务。
recommend-type

编程语言选择指南:为不同项目量身定制的编程语言策略

# 摘要 选择合适的编程语言对于软件项目的成功至关重要。本文首先探讨了编程语言选择的重要性,并对不同分类和特点的编程语言进行了详尽分析,重点介绍了静态与动态类型、解释型与编译型、面向对象与函数式编程语言的区别和应用场景。接着,文章根据项目需求详细讨论了如何选择适合的编程语言,包括功能需求、性能考量、开发效率和团队技能等关键因素。通过实践案例分析,本文进一步探讨了不同
recommend-type

手写vue2的插件vue-router

<think>我们正在手写一个简化版的vue-router插件,用于Vue2。主要步骤:1.定义一个类VueRouter,包含路由映射、当前路由状态等。2.实现install方法,用于Vue.use()安装插件,在install方法中:-混入beforeCreate生命周期钩子,在组件创建时初始化router。-全局注册router-view和router-link组件。3.实现路由映射:将路由配置转换为路径与组件的映射表。4.监听hashchange事件(或者使用history模式,这里以hash模式为例)来响应路由变化。5.实现router-view组件,根据当前路由渲染对应组件。6.实现
recommend-type

《软件工程:实践者的方法》第6版课件解析

根据提供的文件信息,我们可以推断出以下知识点: 1. 课程名称:“SOFTWARE ENGINEERING A practitioner's approach 6e”,表明这是关于软件工程的课程教材,第6版,针对实践者的教学方法。 2. 版本信息:由于标题中明确指出是第6版(6e),我们知道这是一系列教科书或课件的最新版本,这意味着内容已经根据最新的软件工程理论和实践进行了更新和改进。 3. 课程类型:课程是针对“practitioner”,即实践者的,这表明教材旨在教授学生如何将理论知识应用于实际工作中,注重解决实际问题和案例学习,可能包含大量的项目管理、需求分析、系统设计和测试等方面的内容。 4. 适用范围:文件描述中提到了“仅供校园内使用”,说明这个教材是专为教育机构内部学习而设计的,可能含有某些版权保护的内容,不允许未经授权的外部使用。 5. 标签:“SOFTWARE ENGINEERING A practitioner's approach 6e 软件工程”提供了关于这门课程的直接标签信息。标签不仅重复了课程名称,还强化了这是关于软件工程的知识。软件工程作为一门学科,涉及软件开发的整个生命周期,从需求收集、设计、编码、测试到维护和退役,因此课程内容可能涵盖了这些方面。 6. 文件命名:压缩包文件名“SftEng”是“SOFTWARE ENGINEERING”的缩写,表明该压缩包包含的是软件工程相关的教材或资料。 7. 关键知识点:根据标题和描述,我们可以推测课件中可能包含的知识点有: - 软件工程基础理论:包括软件工程的定义、目标、原则和软件开发生命周期的模型。 - 需求分析:学习如何获取、分析、记录和管理软件需求。 - 系统设计:涉及软件架构设计、数据库设计、界面设计等,以及如何将需求转化为设计文档。 - 实现与编码:包括编程语言的选择、代码编写规范、版本控制等。 - 测试:软件测试的原则、方法和测试用例的设计。 - 项目管理:时间管理、团队协作、风险管理、成本估算等与软件项目成功相关的管理活动。 - 质量保证:软件质量模型、质量度量和质量控制措施。 - 维护和演化:软件部署后如何进行持续维护、升级和系统退役。 - 软件工程的新兴领域:包括敏捷开发方法、DevOps、用户体验设计等现代软件开发趋势。 8. 版权和使用限制:由于是专供校园内使用的教材,课件可能包含版权声明和使用限制,要求用户在没有授权的情况下不得对外传播和用于商业用途。 综上所述,这门课程的课件是为校园内的学生和教职员工设计的,关于软件工程的全面教育材料,覆盖了理论知识和实践技巧,并且在版权方面有所限制。由于是最新版的教材,它很可能包含了最新的软件工程技术和方法论。
recommend-type

QUARTUS II 13.0全攻略:新手到专家的10个必备技能

# 摘要 本文旨在详细介绍QUARTUS II 13.0软件的使用,包括其安装、FPGA基础、项目设置、设计流程、高级功能应用
recommend-type

IllegalArgumentException.class

<think>首先,用户的问题是:“我想查找与Java中IllegalArgumentException类相关的信息请问Java IllegalArgumentExceptionclass usageand examples”。这翻译成英文是:“Iwant tofind informationrelated tothe IllegalArgumentExceptionclass inJava.Please provideusage andexamples ofJavaIllegalArgumentException class.” 根据系统级指令:-所有行内数学表达式必须使用$...$格式,
recommend-type

高效进程监控工具的探索与应用

根据提供的文件信息,我们可以推断出一系列与“监控进程东东”相关的知识点。这些信息暗示了该工具可能是一个用来监控操作系统中运行的进程的应用程序。以下是对这些知识点的详细说明: ### 标题知识点: 1. **监控进程的意义**:在IT行业中,监控进程是指持续跟踪系统中运行的进程状态和行为。进程监控对于系统管理员和开发人员来说至关重要,它可以帮助他们理解系统在特定时刻的行为,以及在出现问题时快速定位问题所在。 2. **“超级好用”的含义**:这通常意味着该监控工具具有用户友好的界面、高效的性能、详细的进程信息展示以及可能具备自动化问题检测与报告的功能。超级好用还可能意味着它易于安装、配置和使用,即使是对于非技术用户。 ### 描述知识点: 1. **重复强调“超级好用”**:这种表述强调该工具的易用性和高效性,暗示它可能采用了直观的用户界面设计,以及优化过的性能,能够减少系统负载,同时提供快速且精准的进程信息。 2. **监控进程工具的常见功能**:通常包括实时进程列表显示、进程资源使用情况监控(CPU、内存、磁盘I/O、网络活动等)、进程启动和结束的跟踪、进程关联性分析(例如父子关系)、以及可能的进程安全监控。 ### 标签知识点: 1. **“监控”标签**:这个标签明确指出了工具的主要用途,即监控。在IT领域,监控是指使用特定的软件或硬件工具来持续检测和记录系统、网络或应用的性能和可用性。 ### 压缩包子文件的文件名称列表知识点: 1. **procexp.chm**:这很可能是一个帮助文件(CHM是Microsoft Compiled HTML Help文件的扩展名),提供了监控进程工具的详细用户指南、使用说明、常见问题解答和功能介绍。CHM文件是将HTML页面、索引和其他资源编译成单一文件的格式,方便用户查阅。 2. **procexp.exe**:这指的是实际的监控进程应用程序的可执行文件。EXE文件是Windows操作系统下的可执行程序文件,用户通过双击它可以启动应用程序。该程序可能包含了用于监控进程的核心功能,比如列出所有运行中的进程,显示它们的详细信息,进行性能分析等。 3. **Eula.txt**:这是一个文本文件,通常包含了最终用户许可协议(End-User License Agreement,EULA)。EULA是供应商和用户之间的法律协议,规定了软件的合法使用条件,包括用户能做什么和不能做什么,以及版权和担保声明。 ### 综合知识点: - **监控进程工具选择标准**:一个优质的监控进程工具应当包括实时更新、多层次的系统信息(如进程树、模块、句柄等)、过滤和搜索功能、安全性高以及对用户行为影响小等特点。 - **监控进程工具在不同场景下的应用**:例如,在开发过程中,开发者可以使用进程监控工具来分析应用程序运行状况,进行性能调优;在安全领域,安全专家可以利用这些工具来发现可疑进程,防止恶意软件的运行。 - **监控进程工具的未来发展**:随着技术的不断进步,监控进程工具也在不断演化,可能会集成更多的智能分析技术,如机器学习算法来预测系统问题,或者提供云平台支持,使得跨区域的进程监控成为可能。 总体来说,上述文件信息所暗示的“超级好用的监控进程东东”可能是一个集多种功能于一身的进程监控工具,它能够帮助用户有效地管理和维护计算机系统,保障其稳定性和安全性。通过提供的文件列表,我们可以得知该工具附带详细的帮助文档,以及用户可能需要的许可协议,这体现了其对用户友好性和专业性的重视。
recommend-type

【Catalyst 9800无线控制器实战手册】:从故障排查到网络优化的必备技能

# 1. Catalyst 9800无线控制器概述 Catalyst 9800无线控制器是思科公司推出的针对企业级无线网络的管理设备,它负责管理和优化无线网络环境。作为一款无线局域网控制器,9800系列在设计上集成了先进的网络功
recommend-type

qcustemplot

<think>我们正在处理关于Qt QCustomPlot的使用问题。根据引用内容,QCustomPlot是一个用于Qt的图表库,支持多种图表类型和交互功能。用户询问的是使用问题,可能涉及安装、集成或基本用法。根据引用[1]和[2],安装QCustomPlot通常需要将头文件和源文件(qcustomplot.h和qcustomplot.cpp)复制到项目目录中,并在项目中包含它们。引用[4]提到,如果是代码方式添加,可以直接声明QCustomPlot对象,并且需要添加printsupport模块(因为QCustomPlot依赖于Qt的打印支持模块)。根据引用[3],用户可以通过在QtDesig