From 3e4972261615610b0dfa355a0ac80adea7eeb778 Mon Sep 17 00:00:00 2001 From: Robofish <1683502971@qq.com> Date: Wed, 6 Aug 2025 05:11:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbsp=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/code_generate_interface.py | 43 +++++++++++++++++++++++++++++++++- app/main_window.py | 6 ++--- assets/User_code/bsp/spi.c | 12 +++++----- assets/User_code/bsp/spi.h | 1 + assets/User_code/bsp/time.c | 2 +- assets/User_code/bsp/uart.h | 3 ++- assets/User_code/config.csv | 2 +- 7 files changed, 56 insertions(+), 13 deletions(-) diff --git a/app/code_generate_interface.py b/app/code_generate_interface.py index 293e275..489861f 100644 --- a/app/code_generate_interface.py +++ b/app/code_generate_interface.py @@ -64,7 +64,13 @@ class CodeGenerateInterface(QWidget): freertos_label.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred) top_layout.addWidget(freertos_label) - # 配置并生成FreeRTOS任务按钮,直接调用已有方法 + # 自动生成FreeRTOS任务按钮 + auto_task_btn = PushButton(FluentIcon.SEND, "自动生成FreeRTOS任务") + auto_task_btn.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) + auto_task_btn.clicked.connect(self.on_freertos_task_btn_clicked) + top_layout.addWidget(auto_task_btn, alignment=Qt.AlignRight) + + # 配置并生成FreeRTOS任务按钮 freertos_task_btn = PushButton(FluentIcon.SETTING, "配置并生成FreeRTOS任务") freertos_task_btn.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) freertos_task_btn.clicked.connect(self.on_task_code_btn_clicked) @@ -113,6 +119,41 @@ class CodeGenerateInterface(QWidget): duration=2000 ) + def on_freertos_task_btn_clicked(self): + # 检查是否开启 FreeRTOS + ioc_files = [f for f in os.listdir(self.project_path) if f.endswith('.ioc')] + if ioc_files: + ioc_path = os.path.join(self.project_path, ioc_files[0]) + if not analyzing_ioc.is_freertos_enabled_from_ioc(ioc_path): + InfoBar.error( + title="错误", + content="请先在 .ioc 文件中开启 FreeRTOS,再自动生成任务!", + parent=self, + duration=3000 + ) + return + else: + InfoBar.error( + title="错误", + content="未找到 .ioc 文件,无法检测 FreeRTOS 状态!", + parent=self, + duration=3000 + ) + return + + # 自动生成FreeRTOS任务代码 + from app.data_interface import DataInterface + di = DataInterface() + di.project_path = self.project_path + di.generate_freertos_task() + InfoBar.success( + title="自动生成成功", + content="FreeRTOS任务代码已自动生成!", + parent=self, + duration=2000 + ) + + def generate_code(self): """生成代码逻辑""" # 收集所有已加载的页面对象 diff --git a/app/main_window.py b/app/main_window.py index eac4ffc..89057c0 100644 --- a/app/main_window.py +++ b/app/main_window.py @@ -50,15 +50,15 @@ class MainWindow(FluentWindow): self.homeInterface = HomeInterface(self) self.serialTerminalInterface = SerialTerminalInterface(self) self.partLibraryInterface = PartLibraryInterface(self) - self.dataInterface = DataInterface(self) + # self.dataInterface = DataInterface(self) self.miniToolInterface = MiniToolInterface(self) self.codeConfigurationInterface = CodeConfigurationInterface(self) def initNavigation(self): self.addSubInterface(self.homeInterface, FIF.HOME, self.tr('主页')) - self.addSubInterface(self.dataInterface, FIF.CODE, self.tr('代码生成')) - self.addSubInterface(self.codeConfigurationInterface, FIF.SETTING, self.tr('代码配置')) + # self.addSubInterface(self.dataInterface, FIF.CODE, self.tr('代码生成')) + self.addSubInterface(self.codeConfigurationInterface, FIF.CODE, self.tr('代码生成')) self.addSubInterface(self.serialTerminalInterface, FIF.COMMAND_PROMPT,self.tr('串口助手')) self.addSubInterface(self.partLibraryInterface, FIF.DOWNLOAD, self.tr('零件库')) self.addSubInterface(self.miniToolInterface, FIF.LIBRARY, self.tr('迷你工具箱')) diff --git a/assets/User_code/bsp/spi.c b/assets/User_code/bsp/spi.c index 5226feb..e545e80 100644 --- a/assets/User_code/bsp/spi.c +++ b/assets/User_code/bsp/spi.c @@ -101,9 +101,9 @@ int8_t BSP_SPI_Transmit(BSP_SPI_t spi, uint8_t *data, uint16_t size, bool dma) { if (hspi == NULL) return BSP_ERR; if (dma) { - return HAL_SPI_Transmit_DMA(hspi, data, size); + return HAL_SPI_Transmit_DMA(hspi, data, size)!= HAL_OK;; } else { - return HAL_SPI_Transmit_IT(hspi, data, size); + return HAL_SPI_Transmit_IT(hspi, data, size)!= HAL_OK;; } } @@ -113,9 +113,9 @@ int8_t BSP_SPI_Receive(BSP_SPI_t spi, uint8_t *data, uint16_t size, bool dma) { if (hspi == NULL) return BSP_ERR; if (dma) { - return HAL_SPI_Receive_DMA(hspi, data, size); + return HAL_SPI_Receive_DMA(hspi, data, size)!= HAL_OK;; } else { - return HAL_SPI_Receive_IT(hspi, data, size); + return HAL_SPI_Receive_IT(hspi, data, size)!= HAL_OK;; } } @@ -126,9 +126,9 @@ int8_t BSP_SPI_TransmitReceive(BSP_SPI_t spi, uint8_t *txData, uint8_t *rxData, if (hspi == NULL) return BSP_ERR; if (dma) { - return HAL_SPI_TransmitReceive_DMA(hspi, txData, rxData, size); + return HAL_SPI_TransmitReceive_DMA(hspi, txData, rxData, size)!= HAL_OK;; } else { - return HAL_SPI_TransmitReceive_IT(hspi, txData, rxData, size); + return HAL_SPI_TransmitReceive_IT(hspi, txData, rxData, size)!= HAL_OK;; } } diff --git a/assets/User_code/bsp/spi.h b/assets/User_code/bsp/spi.h index a4d0ea7..374b34a 100644 --- a/assets/User_code/bsp/spi.h +++ b/assets/User_code/bsp/spi.h @@ -7,6 +7,7 @@ extern "C" { /* Includes ----------------------------------------------------------------- */ #include #include +#include #include "bsp/bsp.h" diff --git a/assets/User_code/bsp/time.c b/assets/User_code/bsp/time.c index 0ea6087..3476482 100644 --- a/assets/User_code/bsp/time.c +++ b/assets/User_code/bsp/time.c @@ -1,5 +1,5 @@ /* Includes ----------------------------------------------------------------- */ -#include "bsp/delay.h" +#include "bsp/time.h" #include "bsp.h" #include diff --git a/assets/User_code/bsp/uart.h b/assets/User_code/bsp/uart.h index bbb6126..324b1df 100644 --- a/assets/User_code/bsp/uart.h +++ b/assets/User_code/bsp/uart.h @@ -7,6 +7,7 @@ extern "C" { /* Includes ----------------------------------------------------------------- */ #include #include +#include #include "bsp/bsp.h" @@ -43,7 +44,7 @@ typedef enum { UART_HandleTypeDef *BSP_UART_GetHandle(BSP_UART_t uart); int8_t BSP_UART_RegisterCallback(BSP_UART_t uart, BSP_UART_Callback_t type, void (*callback)(void)); - + int8_t BSP_UART_Transmit(BSP_UART_t uart, uint8_t *data, uint16_t size, bool dma); int8_t BSP_UART_Receive(BSP_UART_t uart, uint8_t *data, uint16_t size, bool dma); diff --git a/assets/User_code/config.csv b/assets/User_code/config.csv index bd8d5ac..66f08b4 100644 --- a/assets/User_code/config.csv +++ b/assets/User_code/config.csv @@ -1,4 +1,4 @@ -bsp,can,delay,dwt,,gpio,i2c,mm,spi,uart,pwm,time +bsp,can,dwt,gpio,i2c,mm,spi,uart,pwm,time component,pid,filter,ahrs device,dr16,ai,nuc module,chassis,gimbal,arm,shoot \ No newline at end of file