聊城那里做网站,帝国音乐网站怎么做数据表,杭州网站建设服务,推广公司品牌以前经常使用 KEIL 写 STM32 的代码#xff0c;自从使用 VScode 写 ESP32 后感觉 KEIL 的开发环境不美观不智能了#xff0c;后面学习了 VScode 开发 STM32 。 使用过程中发现 串口重定向在 KEIL 中可以用#xff0c;搬到 VScode 后不能用#xff0c;不用勾选 Use Micro LI… 以前经常使用 KEIL 写 STM32 的代码自从使用 VScode 写 ESP32 后感觉 KEIL 的开发环境不美观不智能了后面学习了 VScode 开发 STM32 。 使用过程中发现 串口重定向在 KEIL 中可以用搬到 VScode 后不能用不用勾选 Use Micro LIB 选型的重定向方法也不能用不知道为什么了所以改了文中这种配置程序在 Keil 和VScode 中都能编译下载唯一区别 VScode 中烧录不能串口重定向不过问题不大也可以使用 hal 库的串口发送接收函数同样可以实现。 使用软件VScode STM32CubeMX KEIL可以在 VScode 中调整代码格式在 keil 中下载调试。 先前条件 VScode 下载插件 PlatformIO 开发环境 修改 VScode 默认编码格式防止代码在 keil 中中文乱码 设置搜索 encod 编码改成 gb2312 VScode 设置 ctrl s 格式化代码 format on save VScode 设置 json 文件 {cmake.configureOnOpen: true,cmake.showOptionsMovedNotification: false,arduino.useArduinoCli: true,editor.detectIndentation: false, /* 启用时根据文件内容进行重写*/explorer.confirmDelete: false,security.workspace.trust.untrustedFiles: open,C_Cpp.errorSquiggles: enabled,editor.formatOnSave: true,terminal.integrated.autoReplies: {},explorer.confirmDragAndDrop: false,editor.insertSpaces: false, /* 自动插入空格禁用*/editor.renderControlCharacters: true, /* 是否显示控制字符启用*/// editor.renderWhitespace: all, /* 显示 4 个空格是.... */editor.tabSize: 4, /* tab 设置为 4 个空格*/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 /* 设置不自动更新*/
} PlatformIO 生成项目工程 注意自选项目生成位置 后面还会在这个位置生成工程 修改配置文件删除框选文件夹 [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 ;支持输出小数-Wl,-Map,output.map ;输出map-O0 ;编译优先级0,1,2,3STM32cubeMX 生成项目工程 这里使用 STM32F103C8T6 芯片类型简单基础配置一下 调试接口 选择外部时钟 串口异步通信 配置中断 时钟配置外部晶振 8M103的时钟 72M 生成工程 点击 “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 */这样工程就可以在两个环境中编译使用