当前位置: 首页 > news >正文

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])

相关文章:

  • 探索设计模式——单例模式详解
  • matplotlib 创建多个子图
  • TWM论文阅读笔记
  • ChatTTS 推荐及使用说明
  • Spring框架的最新进展:2023年Spring Boot和Spring Cloud功能更新
  • 数据分析的Excel基础操作
  • 节能减排如何替电子行业巨头降低成本
  • [程序员] 表达的能力
  • 在公司的一些笔记
  • 【ARM 安全系列介绍 3.7 -- SM4 对称加密算】
  • Java中的图形用户界面开发
  • 【MySQL进阶之路 | 高级篇】SQL执行过程
  • 用Vite基于Vue3+ts+DataV+ECharts开发数据可视化大屏,即能快速开发又能保证屏幕适配
  • PCB行业迈入数字化新时代,智能工厂引领未来制造
  • 供应链投毒预警 | utilitytool系列Py包开展XenoRAT远控木马投毒
  • 2017届校招提前批面试回顾
  • 2017年终总结、随想
  • nginx 负载服务器优化
  • React组件设计模式(一)
  • TCP拥塞控制
  • 第2章 网络文档
  • 短视频宝贝=慢?阿里巴巴工程师这样秒开短视频
  • 多线程事务回滚
  • 简单易用的leetcode开发测试工具(npm)
  • 力扣(LeetCode)21
  • 网页视频流m3u8/ts视频下载
  • 微信如何实现自动跳转到用其他浏览器打开指定页面下载APP
  • 在Docker Swarm上部署Apache Storm:第1部分
  • 《TCP IP 详解卷1:协议》阅读笔记 - 第六章
  • # dbt source dbt source freshness命令详解
  • # Redis 入门到精通(七)-- redis 删除策略
  • #{}和${}的区别是什么 -- java面试
  • #QT(一种朴素的计算器实现方法)
  • #数据结构 笔记三
  • #我与Java虚拟机的故事#连载03:面试过的百度,滴滴,快手都问了这些问题
  • (1)Android开发优化---------UI优化
  • (10)STL算法之搜索(二) 二分查找
  • (11)MSP430F5529 定时器B
  • (2)(2.10) LTM telemetry
  • (2)从源码角度聊聊Jetpack Navigator的工作流程
  • (附源码)springboot 个人网页的网站 毕业设计031623
  • (附源码)计算机毕业设计SSM智慧停车系统
  • (贪心) LeetCode 45. 跳跃游戏 II
  • (转)C#调用WebService 基础
  • (转载)CentOS查看系统信息|CentOS查看命令
  • (轉貼) VS2005 快捷键 (初級) (.NET) (Visual Studio)
  • .dat文件写入byte类型数组_用Python从Abaqus导出txt、dat数据
  • .net core MVC 通过 Filters 过滤器拦截请求及响应内容
  • .net core 的缓存方案
  • .Net Core 中间件与过滤器
  • .NET Core跨平台微服务学习资源
  • .Net Core中Quartz的使用方法
  • .NET Framework与.NET Framework SDK有什么不同?
  • .Net IOC框架入门之一 Unity
  • .NET/C# 使用 ConditionalWeakTable 附加字段(CLR 版本的附加属性,也可用用来当作弱引用字典 WeakDictionary)