網(wǎng)站建設(shè)好的圖片seo優(yōu)化專員工作內(nèi)容
????????以前經(jīng)常使用 KEIL 寫 STM32 的代碼,自從使用 VScode 寫 ESP32 后感覺 KEIL 的開發(fā)環(huán)境不美觀不智能了,后面學(xué)習(xí)了 VScode 開發(fā) STM32 。
? ? ? ? 使用過程中發(fā)現(xiàn) 串口重定向在 KEIL 中可以用,搬到 VScode 后不能用,不用勾選 Use Micro LIB 選型的重定向方法也不能用,不知道為什么了,所以改了文中這種配置,程序在 Keil 和VScode 中都能編譯下載,唯一區(qū)別 VScode 中燒錄不能串口重定向,不過問題不大,也可以使用 hal 庫(kù)的串口發(fā)送接收函數(shù),同樣可以實(shí)現(xiàn)。
? ? ? ? 使用軟件:VScode + STM32CubeMX + KEIL,可以在 VScode 中調(diào)整代碼格式,在 keil 中下載調(diào)試。
先前條件
????????VScode 下載插件?PlatformIO 開發(fā)環(huán)境
????????修改 VScode 默認(rèn)編碼格式(防止代碼在 keil 中中文亂碼)
? ? ? ? 設(shè)置搜索 encod 編碼改成 gb2312
? ? ? ? VScode 設(shè)置 ctrl + s 格式化代碼 (format on save)
????????VScode 設(shè)置 json 文件
{"cmake.configureOnOpen": true,"cmake.showOptionsMovedNotification": false,"arduino.useArduinoCli": true,"editor.detectIndentation": false, /* 啟用時(shí)根據(jù)文件內(nèi)容進(jìn)行重寫*/"explorer.confirmDelete": false,"security.workspace.trust.untrustedFiles": "open","C_Cpp.errorSquiggles": "enabled","editor.formatOnSave": true,"terminal.integrated.autoReplies": {},"explorer.confirmDragAndDrop": false,"editor.insertSpaces": false, /* 自動(dòng)插入空格禁用*/"editor.renderControlCharacters": true, /* 是否顯示控制字符:啟用*/// "editor.renderWhitespace": "all", /* 顯示 4 個(gè)空格是.... */"editor.tabSize": 4, /* tab 設(shè)置為 4 個(gè)空格*/"editor.fontSize": 18, /* 代碼字體大小*/"editor.fontFamily": "Monaco, 'Courier New', monospace", /* 代碼字體*/"update.mode": "manual","cmake.pinnedCommands": ["workbench.action.tasks.configureTaskRunner","workbench.action.tasks.runTask"],"explorer.confirmPasteNative": false,"files.autoGuessEncoding": true,"debug.console.fontSize": 18,"scm.inputFontSize": 16,"chat.editor.fontSize": 18,"terminal.integrated.fontSize": 16,"files.encoding": "gb2312" /* 設(shè)置不自動(dòng)更新*/
}
?PlatformIO 生成項(xiàng)目工程
? ? ? ? 注意自選項(xiàng)目生成位置?,后面還會(huì)在這個(gè)位置生成工程
????????修改配置文件,刪除框選文件夾
[platformio]
include_dir = Inc
src_dir = Src[env:genericSTM32F103C8]
platform = ststm32
board = genericSTM32F103C8
framework = stm32cubeupload_protocol = jlink
upload_speed = 921600debug_tool = jlinkbuild_flags = -Wl,-u,_printf_float ;支持輸出小數(shù)-Wl,-Map,output.map ;輸出map-O0 ;編譯優(yōu)先級(jí)(0,1,2,3)
STM32cubeMX 生成項(xiàng)目工程
? ? ? ? 這里使用 STM32F103C8T6 芯片類型,簡(jiǎn)單基礎(chǔ)配置一下
????????調(diào)試接口
? ? ? ? 選擇外部時(shí)鐘
? ? ? ? 串口異步通信
? ? ? ? 配置中斷
? ? ? ? 時(shí)鐘配置,外部晶振 8M,103的時(shí)鐘 72M
? ? ? ? ?生成工程
? ? ? ? 點(diǎn)擊 “GENERATE CODE” 生成代碼
? ? ? ? 串口重映射
/* USER CODE BEGIN 1 */#include "stdio.h"#if 1struct __FILE
{int handle;
};
FILE __stdout;void _sys_exit(int x)
{x = x;
}int fputc(int ch, FILE *f)
{HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0x0001);return ch;
}#endif/* USER CODE END 1 */
????????這樣工程就可以在兩個(gè)環(huán)境中編譯使用