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

本文主要是介绍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])

这篇关于platformio烧写STC8H1K08单片机程序失败:Serial port error: read timeout的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1083322

相关文章

Xshell远程连接失败以及解决方案

《Xshell远程连接失败以及解决方案》本文介绍了在Windows11家庭版和CentOS系统中解决Xshell无法连接远程服务器问题的步骤,在Windows11家庭版中,需要通过设置添加SSH功能并... 目录一.问题描述二.原因分析及解决办法2.1添加ssh功能2.2 在Windows中开启ssh服务2

Redis连接失败:客户端IP不在白名单中的问题分析与解决方案

《Redis连接失败:客户端IP不在白名单中的问题分析与解决方案》在现代分布式系统中,Redis作为一种高性能的内存数据库,被广泛应用于缓存、消息队列、会话存储等场景,然而,在实际使用过程中,我们可能... 目录一、问题背景二、错误分析1. 错误信息解读2. 根本原因三、解决方案1. 将客户端IP添加到Re

JAVA智听未来一站式有声阅读平台听书系统小程序源码

智听未来,一站式有声阅读平台听书系统 🌟&nbsp;开篇:遇见未来,从“智听”开始 在这个快节奏的时代,你是否渴望在忙碌的间隙,找到一片属于自己的宁静角落?是否梦想着能随时随地,沉浸在知识的海洋,或是故事的奇幻世界里?今天,就让我带你一起探索“智听未来”——这一站式有声阅读平台听书系统,它正悄悄改变着我们的阅读方式,让未来触手可及! 📚&nbsp;第一站:海量资源,应有尽有 走进“智听

EMLOG程序单页友链和标签增加美化

单页友联效果图: 标签页面效果图: 源码介绍 EMLOG单页友情链接和TAG标签,友链单页文件代码main{width: 58%;是设置宽度 自己把设置成与您的网站宽度一样,如果自适应就填写100%,TAG文件不用修改 安装方法:把Links.php和tag.php上传到网站根目录即可,访问 域名/Links.php、域名/tag.php 所有模板适用,代码就不粘贴出来,已经打

基于51单片机的自动转向修复系统的设计与实现

文章目录 前言资料获取设计介绍功能介绍设计清单具体实现截图参考文献设计获取 前言 💗博主介绍:✌全网粉丝10W+,CSDN特邀作者、博客专家、CSDN新星计划导师,一名热衷于单片机技术探索与分享的博主、专注于 精通51/STM32/MSP430/AVR等单片机设计 主要对象是咱们电子相关专业的大学生,希望您们都共创辉煌!✌💗 👇🏻 精彩专栏 推荐订阅👇🏻 单片机

跨系统环境下LabVIEW程序稳定运行

在LabVIEW开发中,不同电脑的配置和操作系统(如Win11与Win7)可能对程序的稳定运行产生影响。为了确保程序在不同平台上都能正常且稳定运行,需要从兼容性、驱动、以及性能优化等多个方面入手。本文将详细介绍如何在不同系统环境下,使LabVIEW开发的程序保持稳定运行的有效策略。 LabVIEW版本兼容性 LabVIEW各版本对不同操作系统的支持存在差异。因此,在开发程序时,尽量使用

CSP 2023 提高级第一轮 CSP-S 2023初试题 完善程序第二题解析 未完

一、题目阅读 (最大值之和)给定整数序列 a0,⋯,an−1,求该序列所有非空连续子序列的最大值之和。上述参数满足 1≤n≤105 和 1≤ai≤108。 一个序列的非空连续子序列可以用两个下标 ll 和 rr(其中0≤l≤r<n0≤l≤r<n)表示,对应的序列为 al,al+1,⋯,ar​。两个非空连续子序列不同,当且仅当下标不同。 例如,当原序列为 [1,2,1,2] 时,要计算子序列 [

这些心智程序你安装了吗?

原文题目:《为什么聪明人也会做蠢事(四)》 心智程序 大脑有两个特征导致人类不够理性,一个是处理信息方面的缺陷,一个是心智程序出了问题。前者可以称为“认知吝啬鬼”,前几篇文章已经讨论了。本期主要讲心智程序这个方面。 心智程序这一概念由哈佛大学认知科学家大卫•帕金斯提出,指个体可以从记忆中提取出的规则、知识、程序和策略,以辅助我们决策判断和解决问题。如果把人脑比喻成计算机,那心智程序就是人脑的

ORACLE 11g 创建数据库时 Enterprise Manager配置失败的解决办法 无法打开OEM的解决办法

在win7 64位系统下安装oracle11g,在使用Database configuration Assistant创建数据库时,在创建到85%的时候报错,错误如下: 解决办法: 在listener.ora中增加对BlueAeri-PC或ip地址的侦听,具体步骤如下: 1.启动Net Manager,在“监听程序”--Listener下添加一个地址,主机名写计

uniapp设置微信小程序的交互反馈

链接:uni.showToast(OBJECT) | uni-app官网 (dcloud.net.cn) 设置操作成功的弹窗: title是我们弹窗提示的文字 showToast是我们在加载的时候进入就会弹出的提示。 2.设置失败的提示窗口和标签 icon:'error'是设置我们失败的logo 设置的文字上限是7个文字,如果需要设置的提示文字过长就需要设置icon并给