platformio烧写STC8H1K08单片机程序失败:Serial port error: read timeout

问题

在使用platformio进行STC8H1K08单片机开发,在烧录编译好的程序时失败了,烧录过程日志如下:

 *  正在执行任务: C:\Users\23043036\.platformio\penv\Scripts\platformio.exe run --target upload Processing STC8H1K08 (platform: intel_mcs51; board: STC8H1K08)
----------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/intel_mcs51/STC8H1K08.html
PLATFORM: Intel MCS-51 (8051) (2.2.0) > Generic STC8H1K08
HARDWARE: STC8H1K08 11MHz, 1.25KB RAM, 8KB Flash
PACKAGES:- tool-stcgal @ 1.110.0 (1.10)- tool-vnproch55x @ 1.0.220407- toolchain-sdcc @ 1.40400.0 (4.4.0)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 0 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Checking size .pio\build\STC8H1K08\firmware.hex
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
Flash: [========  ]  76.3% (used 6251 bytes from 8192 bytes)
Configuring upload protocol...
AVAILABLE: stcgal
CURRENT: upload_protocol = stcgal
Looking for upload port...
Auto-detected: COM3
Uploading .pio\build\STC8H1K08\firmware.hex
Cycling power: done
Waiting for MCU: done
Target model:Name: STC8H1K08Magic: F734Code flash: 8.0 KBEEPROM flash: 4.0 KB
Target frequency: 11.058 MHz
Target BSL version: 7.3.12U
Target wakeup frequency: 35.825 KHz
Target ref. voltage: 1190 mV
Target mfg. date: 2021-03-18
Target options:reset_pin_enabled=Falseclock_gain=highwatchdog_por_enabled=Falsewatchdog_stop_idle=Truewatchdog_prescale=256low_voltage_reset=Truelow_voltage_threshold=0eeprom_erase_enabled=Truebsl_pindetect_enabled=Falsepor_reset_delay=longrstout_por_state=highuart1_remap=Falseuart2_passthrough=Trueuart2_pin_mode=push-pullepwm_open_drain=Trueprogram_eeprom_split=8192
Loading flash: 6251 bytes (Intel HEX)
Trimming frequency: 11.062 MHz
Switching to 19200 baud: done
Serial port error: read timeout
*** [upload] Error 1
====================================== [FAILED] Took 24.20 seconds ======================================

解决过程

使用串口进行程序烧写,platformio使用的是stcgal工具,日志显示的就是stcgal和单片机的串口交互过程,为了查看更详细的过程日志,我们将Debug模式打开(在C:\Users\23043036\.platformio\platforms\intel_mcs51\builder\main.py中的UPLOADERFLAGS下添加"-D"参数),然后查看烧录过程日志:

 *  正在执行任务: C:\Users\23043036\.platformio\penv\Scripts\platformio.exe run --target upload Processing STC8H1K08 (platform: intel_mcs51; board: STC8H1K08)
----------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/intel_mcs51/STC8H1K08.html
PLATFORM: Intel MCS-51 (8051) (2.2.0) > Generic STC8H1K08
HARDWARE: STC8H1K08 11MHz, 1.25KB RAM, 8KB Flash
PACKAGES:- tool-stcgal @ 1.110.0 (1.10)- tool-vnproch55x @ 1.0.220407- toolchain-sdcc @ 1.40400.0 (4.4.0)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 0 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Checking size .pio\build\STC8H1K08\firmware.hex
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
Flash: [========  ]  77.3% (used 6330 bytes from 8192 bytes)
Configuring upload protocol...
AVAILABLE: stcgal
CURRENT: upload_protocol = stcgal
Looking for upload port...
Auto-detected: COM3
Uploading .pio\build\STC8H1K08\firmware.hex
Cycling power: done
<- Packet data: 46 B9 68 00 38 50 00 A8 F3 90 B4 00 02 FF FF BF BF FF 26 9C F7 20 73 55 00 F7 34 0C 8B F1 AF DC 0F 1F 20 FF 00 30 00 20 04 A6 21 03 18 32 FF 7B 2E 5A 8B A6 C4 F4 FF 17 CA 16
Waiting for MCU: done
Target model:Name: STC8H1K08Magic: F734Code flash: 8.0 KBEEPROM flash: 4.0 KB
-> Packet data: 46 B9 6A 00 20 00 0C 00 00 17 00 2E 00 45 00 5C 00 73 00 8A 00 A1 00 B8 00 CF 00 E6 00 FF 00 06 86 16
Target frequency: 11.072 MHz
Target BSL version: 7.3.12U
Target wakeup frequency: 35.825 KHz
Target ref. voltage: 1190 mV
Target mfg. date: 2021-03-18
Target options:reset_pin_enabled=Falseclock_gain=highwatchdog_por_enabled=Falsewatchdog_stop_idle=Truewatchdog_prescale=256low_voltage_reset=Truelow_voltage_threshold=0eeprom_erase_enabled=Truebsl_pindetect_enabled=Falsepor_reset_delay=longrstout_por_state=highuart1_remap=Falseuart2_passthrough=Trueuart2_pin_mode=push-pullepwm_open_drain=Trueprogram_eeprom_split=8192
Loading flash: 6330 bytes (Intel HEX)
<- Packet data: 46 B9 68 00 20 00 0C 17 72 19 31 1A CC 1C 64 1E 08 1F A9 21 08 22 A9 24 44 25 B2 27 4A 28 F7 07 7E 16
-> Packet data: 46 B9 6A 00 20 00 0C B3 00 B4 00 B5 00 B3 01 B4 01 B5 01 B3 02 B4 02 B5 02 B3 03 B4 03 B5 03 09 18 16
<- Packet data: 46 B9 68 00 20 00 0C 23 F0 24 08 24 17 23 F0 24 0E 24 1D 23 F3 24 0B 24 20 23 F9 24 0E 24 23 06 B2 16
Trimming frequency: 11.051 MHz
-> Packet data: 46 B9 6A 00 0E 01 00 00 FF CC 03 B3 80 03 7A 16
<- Packet data: 46 B9 68 00 07 01 00 70 16
-> Packet data: 46 B9 6A 00 0B 05 00 00 5A A5 01 79 16
Switching to 115200 baud: done
<- Packet data: 46 B9 68 00 07 05 00 74 16
-> Packet data: 46 B9 6A 00 0B 03 00 00 5A A5 01 77 16
Serial port error: read timeout
*** [upload] Error 1
====================================== [FAILED] Took 24.72 seconds ======================================*  终端进程“C:\Users\23043036\.platformio\penv\Scripts\platformio.exe 'run', '--target', 'upload'”已终止,退出代码: 1。 *  终端将被任务重用,按任意键关闭。

可以看到在stcgal与单片机交互过程中,发送了报文后单片机没有响应,最终超时了,通过阅读stcgal的代码以及添加打印,可以知道是在擦除芯片时交互失败的,通过报文分析,发现stcgal发送的报文是没有问题的,那为什么单片机没有响应呢?????
在stcgal的github上,issues中有类似的打印,但是没有具体的解决办法,网上相关的资料也很少,查找了好久,最终是在platformio的github上找到了解决办法。

解决办法

对于stc8,烧录时需要将stcgal_protocol改为auto,其他系列怎么样不知道,但是STC8如此修改后确实是可以的。
修改C:\Users\23043036\.platformio\platforms\intel_mcs51\builder\main.py文件,添加了一下内容:

if stcgal_protocol == 'stc8':stcgal_protocol = 'auto'

详细内容为:

# Copyright 2014-present PlatformIO <contact@platformio.org>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.import sys
from os.path import joinfrom SCons.Script import ARGUMENTS, AlwaysBuild, Default, DefaultEnvironmentdef __getSize(size_type, env):# FIXME: i don't really know how to do this right. see:#        https://community.platformio.org/t/missing-integers-in-board-extra-flags-in-board-json/821return str(env.BoardConfig().get("build",{# defaults"size_heap": 1024,"size_iram": 256,"size_xram": 65536,"size_code": 65536,},)[size_type])def _parseSdccFlags(flags):assert flagsif isinstance(flags, list):flags = " ".join(flags)flags = str(flags)parsed_flags = []unparsed_flags = []prev_token = ""for token in flags.split(" "):if prev_token.startswith("--") and not token.startswith("-"):parsed_flags.extend([prev_token, token])prev_token = ""continueif prev_token:unparsed_flags.append(prev_token)prev_token = tokenunparsed_flags.append(prev_token)return (parsed_flags, unparsed_flags)env = DefaultEnvironment()
platform = env.PioPlatform()
board_config = env.BoardConfig()env.Replace(AR="sdar",AS="sdas8051",CC="sdcc",LD="sdld",RANLIB="sdranlib",OBJCOPY="sdobjcopy",OBJSUFFIX=".rel",LIBSUFFIX=".lib",SIZETOOL=join(platform.get_dir(), "builder", "size.py"),SIZECHECKCMD="$PYTHONEXE $SIZETOOL $SOURCES",SIZEPRINTCMD='"$PYTHONEXE" $SIZETOOL $SOURCES',SIZEPROGREGEXP=r"^ROM/EPROM/FLASH\s+[a-fx\d]+\s+[a-fx\d]+\s+(\d+).*",PROGNAME="firmware",PROGSUFFIX=".hex",
)env.Append(ASFLAGS=["-l", "-s"],CFLAGS=["--std-sdcc11"],CCFLAGS=["--opt-code-size",  # optimize for size"--peep-return",  # peephole optimization for return instructions"-m%s" % board_config.get("build.cpu"),],CPPDEFINES=["F_CPU=$BOARD_F_CPU", "HEAP_SIZE=" + __getSize("size_heap", env)],LINKFLAGS=["-m%s" % board_config.get("build.cpu"),"--iram-size",__getSize("size_iram", env),"--xram-size",__getSize("size_xram", env),"--code-size",__getSize("size_code", env),"--out-fmt-ihx",],
)if int(ARGUMENTS.get("PIOVERBOSE", 0)):env.Prepend(UPLOADERFLAGS=["-v"])# parse manually SDCC flags
if env.get("BUILD_FLAGS"):_parsed, _unparsed = _parseSdccFlags(env.get("BUILD_FLAGS"))env.Append(CCFLAGS=_parsed)env["BUILD_FLAGS"] = _unparsedproject_sdcc_flags = None
if env.get("SRC_BUILD_FLAGS"):project_sdcc_flags, _unparsed = _parseSdccFlags(env.get("SRC_BUILD_FLAGS"))env["SRC_BUILD_FLAGS"] = _unparsed#
# Target: Build executable and linkable firmware
#target_firm = env.BuildProgram()if project_sdcc_flags:env.Import("projenv")projenv.Append(CCFLAGS=project_sdcc_flags)AlwaysBuild(env.Alias("nobuild", target_firm))
target_buildprog = env.Alias("buildprog", target_firm, target_firm)#
# Target: Print binary size
#target_size = env.Alias("size", target_firm, env.VerboseAction("$SIZEPRINTCMD", "Calculating size $SOURCE")
)
AlwaysBuild(target_size)#
# Target: Upload firmware
#upload_protocol = env.subst("$UPLOAD_PROTOCOL")
upload_actions = []if upload_protocol == "stcgal":f_cpu_khz = int(board_config.get("build.f_cpu").strip("L")) / 1000stcgal_protocol = board_config.get("upload.stcgal_protocol")if stcgal_protocol == 'stc8':stcgal_protocol = 'auto'env.Replace(UPLOADER=join(platform.get_package_dir("tool-stcgal") or "", "stcgal.py"),UPLOADERFLAGS=["-P",stcgal_protocol,"-p","$UPLOAD_PORT","-t",int(f_cpu_khz),"-a","-D"],UPLOADCMD='"$PYTHONEXE" "$UPLOADER" $UPLOADERFLAGS $SOURCE',)upload_actions = [env.VerboseAction(env.AutodetectUploadPort, "Looking for upload port..."),env.VerboseAction("$UPLOADCMD", "Uploading $SOURCE"),]# CH55x upload tool
elif upload_protocol == "ch55x":env.Replace(UPLOADER="vnproch55x",UPLOADERFLAGS=["-f"],UPLOADCMD="$UPLOADER $UPLOADERFLAGS $BUILD_DIR/${PROGNAME}.bin",)upload_actions = [env.VerboseAction(" ".join(["$OBJCOPY","-I","ihex","-O","binary","$SOURCE","$BUILD_DIR/${PROGNAME}.bin",]),"Creating binary",),env.VerboseAction("$UPLOADCMD", "Uploading ${PROGNAME}.bin"),]# custom upload tool
elif upload_protocol == "custom":upload_actions = [env.VerboseAction("$UPLOADCMD", "Uploading $SOURCE")]else:sys.stderr.write("Warning! Unknown upload protocol %s\n" % upload_protocol)AlwaysBuild(env.Alias("upload", target_firm, upload_actions))#
# Setup default targets
#Default([target_buildprog, target_size])

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

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

相关文章

ionic7 从安装 到 项目启动最后打包成 apk

报错处理 在打包的时候遇到过几个问题&#xff0c;这里记录下来两个 Visual Studio Code运行ionic build出错显示ionic : 无法加载文件 ionic 项目通过 android studio 打开报错 capacitor.settings.gradle 文件不存在 说明 由于之前使用的是 ionic 3&#xff0c;当时打包的…

驾考小技巧:老北京布鞋!距离高考出分还剩3天,我却看到有些孩子已经拿了“满分”——早读(逆天打工人爬取热门微信文章解读)

我20年驾校4000多块钱&#xff0c;你呢&#xff1f; 引言Python 代码第一篇 洞见 距离高考出分还剩3天&#xff0c;我却看到有些孩子已经拿了“满分”第二篇 视频新闻结尾 引言 昨天的文章顺利发出 看来“梅西” 这两个字在我们这边 不是敏感词 只是很多个罗粉搞得有点过头了 …

Android设置页面Activity全屏(隐藏导航栏、状态栏)

3、代码中设置&#xff1a;在setContentView 之前调用 requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 注意&#xff1a; 当有全面屏手机可以显示虚拟…

2769. 找出最大的可达成数字

2769. 找出最大的可达成数字 题目链接&#xff1a;2769. 找出最大的可达成数字 代码如下&#xff1a; class Solution { public:int theMaximumAchievableX(int num, int t) {return num2*t; } };

公司名称含有关商标名称可能涉及侵权!

有个朋友找到普推商标知产老杨&#xff0c;说有个人给他打电话&#xff0c;说他的公司名称侵权另一家的商标名称&#xff0c;让他要改下公司名称&#xff0c;不改就要告侵权&#xff0c;此前看到过许多&#xff0c;在一些省市注册公司时&#xff0c;如果公司名称与已注册商标相…

聚类算法(1)---最大最小距离、C-均值算法

本篇文章是博主在人工智能等领域学习时&#xff0c;用于个人学习、研究或者欣赏使用&#xff0c;并基于博主对人工智能等领域的一些理解而记录的学习摘录和笔记&#xff0c;若有不当和侵权之处&#xff0c;指出后将会立即改正&#xff0c;还望谅解。文章分类在AI学习笔记&#…

区块链2024

项目名称&#xff1a;基于区块链的物资管理系统 技术栈:SpringBoot SpringSecurity MyBatis-Plus MySQL Redis CouchDB Hyperledger Fabric RabbitMQ Docker 项目描述&#xff1a;在自然灾害期间&#xff0c;物资管理常面临信息孤立和不透明等问题。为此&#xff0c;我…

象战----第十二届中山市邀请赛正赛

本次的题解一定让大家享受脑细胞碰撞与再生死亡的感受&#xff01;定然酣畅淋漓&#xff01;请耐心的读完 简称&#xff1a;让脑袋死机。。。 象战 老规矩先分析在打码&#xff1a; 注意到题目告诉我们&#xff1a;四个角落是不能放的 那么 我们设象在(i,j).(注意&#xff1a…

uniapp实现幻灯功能方法及代码

在 UniApp 中实现幻灯功能&#xff0c;通常可以使用 swiper 组件&#xff0c;该组件用于滑动视图容器&#xff0c;常用于制作轮播图效果。以下是一个简单的幻灯功能实现方法及代码示例&#xff1a; 步骤 1&#xff1a;在页面的模板部分添加 swiper 和 swiper-item 组件 <t…

解决双击bootstrap.bat没有生成b2.exe文件

双击bootstrap.bat但是并没有没有生成b2.exe文件&#xff0c;会报如下错误&#xff1a; "cl" 不是内部或外部命令&#xff0c;也不是可运行的程序 或批处理文件。D:\cppsoft\boost_1_85_0\tools\build\src\engine>dir *.exe 驱动器 D 中的卷是 Data 卷的序列号是…

eNSP学习——配置基于全局地址池的DHCP

目录 主要命令 原理概述 实验目的 实验场景 实验拓扑 实验编址 实验步骤 1、基本配置 2、配置基于全局地址池的 DHCP Server 3、配置DHCP Client 主要命令 [R1]dhcp enable //开启 DHCP功能//创建一个全局地址池&#xff0c;地址池名称为huawei1 [R1]ip pool h…

Linux系统开机自启动脚本(案例:Raspberry Pi 4B脚本)

前言&#xff1a;本篇博客为手把手教学的 Linux 系统开机自启动脚本教程&#xff0c;且额外包含有 Raspberry Pi 4B 的开机自启动案例。日常工程项目中往往需要 Linux 系统能够自启动一些代码程序&#xff0c;本篇博客利用虚拟机下的 Ubuntu 自启动脚本来进行教学&#xff0c;且…

力扣240.搜索二维矩阵II

力扣240.搜索二维矩阵II 因为原数组是从上到下从左到右增加的 在左下(和右上角)时有特性&#xff1a;i减小则a[i]减小&#xff0c;j增大则a[j]增大因此从左下角开始遍历 找到结果return即可 class Solution {public:bool searchMatrix(vector<vector<int>>&…

vue canvas学习

说明 在vue里试用一下canvas&#xff0c;记录一下 代码 <template><div><canvas ref"canvas1" height"500" width"500"></canvas><button click"draw">画图</button></div> </templa…

深入解析Transformer:大模型核心技术揭秘

在大模型发展历程中&#xff0c;有两个比较重要点&#xff1a;第一&#xff0c;Transformer 架构。它是模型的底座&#xff0c;但 Transformer 不等于大模型&#xff0c;但大模型的架构可以基于 Transformer&#xff1b;第二&#xff0c;GPT。严格意义上讲&#xff0c;GPT 可能…

【网络安全的神秘世界】docker启动失败?看我如何成功启动

&#x1f31d;博客主页&#xff1a;泥菩萨 &#x1f496;专栏&#xff1a;Linux探索之旅 | 网络安全的神秘世界 | 专接本 | 每天学会一个渗透测试工具 &#x1f64b;‍♂️问题描述 关闭docker后再启动就发现启动失败了 错误信息&#xff1a;Job for docker.service failed b…

2020C++等级考试二级真题题解

202012数组指定部分逆序重放c #include <iostream> using namespace std; int main() {int a[110];int n, k;cin >> n >> k;for (int i 0; i < n; i) {cin >> a[i];}for (int i 0; i < k / 2; i) {swap(a[i], a[k - 1 - i]);}for (int i 0…

Unity定时(延迟)管理器实现

前言 Unity中实现定时功能的方法有很多&#xff0c;比如协程、Update、Invoke、Async等&#xff0c;可以说是五花八门&#xff0c;对于这类实现方法多、需求频繁的功能还是需要一个管理器来统一处理。 功能 下面列出了该管理器支持的功能&#xff0c;可以根据根据所列功能判…

tron-passwd写入提权

troneasy敏感信息收集、Brainfuck解密、替换密码、ssh利用、passwd提权机发现 **后续需要虚拟机的私信我&#xff0c;我会打包进行文章发布链接&#xff0c;请持续关注&#xff01;&#xff01;&#xff01;** 主机发现 netdiscover -i eth0 -r 192.168.44.0/24端口服务 nm…

注解详解系列 - @Profile:基于环境的配置切换

注解简介 在今天的注解详解系列中&#xff0c;我们将探讨Profile注解。Profile是Spring框架中的一个重要注解&#xff0c;用于根据不同的环境配置有选择性地启用或禁用特定的bean。通过Profile注解&#xff0c;可以方便地在开发、测试、生产等不同环境中切换配置。 注解定义 …