flash和ram问题 ============== 常见问题 -------- 1、Cat.1模块的flash和ram有多大?Luat二次开发给用户使用的空间有多大? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Flash总空间:64Mb SPI Nor Flash ram总空间:128Mb PSRAM :: Luat二次开发使用的Flash空间有两部分:脚本区和文件系统区 脚本区: 通过Luatools烧写的所有文件,都存放在此区域 非TTS版本为720KB,TTS版本为426KB;如果烧录时,超过此限制,Luatools会报错 不同版本的core可能会有差异,以版本每次的更新记录为准 文件系统区: 程序运行过程中实时创建的文件都会存放在此区域 下载的差分升级包存放在文件系统区 总空间为1.2MB 不同版本的core可能会有差异,可通过rtos.get_fs_free_size()查询剩余的文件系统可用空间 :: Luat二次开发可用的ram空间有1.36MB 可通过collectgarbage("count")查询已经使用的内存空间(返回值单位为KB),总的1.36MB减去使用的内存,就是当前剩余的Lua运行可用内存 +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ | | L | 字 | 图 | 扫 | 二 | 摄 | T | W | 蓝 | S | l | V | 脚 | 文 | R | | | C | 库 | 片 | 码 | 维 | 像 | T | I | 牙 | D | i | O | 本 | 件 | A | | | D | | | | 码 | 头 | S | F | | 卡 | t | L | 文 | 系 | M | | | | | | | 生 | | | I | | | t | T | 件 | 统 | 空 | | | | | | | 成 | | | S | | | l | E | | 空 | 间 | | | | | | | | | | c | | | e | | | 间 | | | | | | | | | | | a | | | V | | | | | | | | | | | | | | n | | | G | | | | | | | | | | | | | | | | | L | | | | | +===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+ | L | 支 | 支 | 支 | 支 | 支 | 支 | 不 | 支 | 不 | 支 | 支 | 支 | 7 | 1 | 1 | | u | 持 | 持 | 持 | 持 | 持 | 持 | 支 | 持 | 支 | 持 | 持 | 持 | 2 | . | . | | a | | | | | | | 持 | | 持 | | | | 0 | 3 | 3 | | t | | | | | | | | | | | | | K | M | 6 | | _ | | | | | | | | | | | | | B | B | M | | R | | | | | | | | | | | | | | | B | | D | | | | | | | | | | | | | | | | | A | | | | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | | | | 9 | | | | | | | | | | | | | | | | | 1 | | | | | | | | | | | | | | | | | 0 | | | | | | | | | | | | | | | | +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ | L | 支 | 支 | 支 | 支 | 支 | 支 | 不 | 支 | 不 | 支 | 支 | 支 | 7 | 1 | 1 | | u | 持 | 持 | 持 | 持 | 持 | 持 | 支 | 持 | 支 | 持 | 持 | 持 | 2 | . | . | | a | | | | | | | 持 | | 持 | | | | 0 | 3 | 3 | | t | | | | | | | | | | | | | K | M | 6 | | _ | | | | | | | | | | | | | B | B | M | | R | | | | | | | | | | | | | | | B | | D | | | | | | | | | | | | | | | | | A | | | | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | | | | 9 | | | | | | | | | | | | | | | | | 1 | | | | | | | | | | | | | | | | | 0 | | | | | | | | | | | | | | | | | _ | | | | | | | | | | | | | | | | | F | | | | | | | | | | | | | | | | | L | | | | | | | | | | | | | | | | | O | | | | | | | | | | | | | | | | | A | | | | | | | | | | | | | | | | | T | | | | | | | | | | | | | | | | +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ | L | 支 | 支 | 支 | 不 | 不 | 不 | 支 | 支 | 不 | 不 | 支 | 支 | 4 | 1 | 1 | | u | 持 | 持 | 持 | 支 | 支 | 支 | 持 | 持 | 支 | 支 | 持 | 持 | 2 | . | . | | a | | | | 持 | 持 | 持 | | | 持 | 持 | | | 6 | 3 | 3 | | t | | | | | | | | | | | | | K | M | 6 | | _ | | | | | | | | | | | | | B | B | M | | R | | | | | | | | | | | | | | | B | | D | | | | | | | | | | | | | | | | | A | | | | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | | | | 9 | | | | | | | | | | | | | | | | | 1 | | | | | | | | | | | | | | | | | 0 | | | | | | | | | | | | | | | | | _ | | | | | | | | | | | | | | | | | T | | | | | | | | | | | | | | | | | T | | | | | | | | | | | | | | | | | S | | | | | | | | | | | | | | | | +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ | L | 支 | 支 | 支 | 不 | 不 | 不 | 支 | 支 | 不 | 不 | 支 | 支 | 4 | 1 | 1 | | u | 持 | 持 | 持 | 支 | 支 | 支 | 持 | 持 | 支 | 支 | 持 | 持 | 2 | . | . | | a | | | | 持 | 持 | 持 | | | 持 | 持 | | | 6 | 3 | 3 | | t | | | | | | | | | | | | | K | M | 6 | | _ | | | | | | | | | | | | | B | B | M | | R | | | | | | | | | | | | | | | B | | D | | | | | | | | | | | | | | | | | A | | | | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | | | | 9 | | | | | | | | | | | | | | | | | 1 | | | | | | | | | | | | | | | | | 0 | | | | | | | | | | | | | | | | | _ | | | | | | | | | | | | | | | | | T | | | | | | | | | | | | | | | | | T | | | | | | | | | | | | | | | | | S | | | | | | | | | | | | | | | | | _ | | | | | | | | | | | | | | | | | F | | | | | | | | | | | | | | | | | L | | | | | | | | | | | | | | | | | O | | | | | | | | | | | | | | | | | A | | | | | | | | | | | | | | | | | T | | | | | | | | | | | | | | | | +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ | L | 支 | 支 | 支 | 不 | 不 | 不 | 支 | 支 | 不 | 不 | 不 | 支 | 4 | 1 | 1 | | u | 持 | 持 | 持 | 支 | 支 | 支 | 持 | 持 | 支 | 支 | 支 | 持 | 2 | . | . | | a | | | | 持 | 持 | 持 | | | 持 | 持 | 持 | | 6 | 3 | 3 | | t | | | | | | | | | | | | | K | M | 6 | | _ | | | | | | | | | | | | | B | B | M | | R | | | | | | | | | | | | | | | B | | D | | | | | | | | | | | | | | | | | A | | | | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | | | | 9 | | | | | | | | | | | | | | | | | 1 | | | | | | | | | | | | | | | | | 0 | | | | | | | | | | | | | | | | | _ | | | | | | | | | | | | | | | | | T | | | | | | | | | | | | | | | | | T | | | | | | | | | | | | | | | | | S | | | | | | | | | | | | | | | | | _ | | | | | | | | | | | | | | | | | N | | | | | | | | | | | | | | | | | O | | | | | | | | | | | | | | | | | L | | | | | | | | | | | | | | | | | V | | | | | | | | | | | | | | | | | G | | | | | | | | | | | | | | | | | L | | | | | | | | | | | | | | | | +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ | L | 支 | 支 | 支 | 不 | 不 | 不 | 支 | 支 | 不 | 不 | 支 | 不 | 4 | 1 | 1 | | u | 持 | 持 | 持 | 支 | 支 | 支 | 持 | 持 | 支 | 支 | 持 | 支 | 2 | . | . | | a | | | | 持 | 持 | 持 | | | 持 | 持 | | 持 | 6 | 3 | 3 | | t | | | | | | | | | | | | | K | M | 6 | | _ | | | | | | | | | | | | | B | B | M | | R | | | | | | | | | | | | | | | B | | D | | | | | | | | | | | | | | | | | A | | | | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | | | | 9 | | | | | | | | | | | | | | | | | 1 | | | | | | | | | | | | | | | | | 0 | | | | | | | | | | | | | | | | | _ | | | | | | | | | | | | | | | | | T | | | | | | | | | | | | | | | | | T | | | | | | | | | | | | | | | | | S | | | | | | | | | | | | | | | | | _ | | | | | | | | | | | | | | | | | N | | | | | | | | | | | | | | | | | O | | | | | | | | | | | | | | | | | V | | | | | | | | | | | | | | | | | O | | | | | | | | | | | | | | | | | L | | | | | | | | | | | | | | | | | T | | | | | | | | | | | | | | | | | E | | | | | | | | | | | | | | | | | _ | | | | | | | | | | | | | | | | | F | | | | | | | | | | | | | | | | | L | | | | | | | | | | | | | | | | | O | | | | | | | | | | | | | | | | | A | | | | | | | | | | | | | | | | | T | | | | | | | | | | | | | | | | +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ | L | 支 | 支 | 支 | 不 | 不 | 不 | 支 | 支 | 不 | 不 | 不 | 支 | 4 | 1 | 1 | | u | 持 | 持 | 持 | 支 | 支 | 支 | 持 | 持 | 支 | 支 | 支 | 持 | 2 | . | . | | a | | | | 持 | 持 | 持 | | | 持 | 持 | 持 | | 6 | 3 | 3 | | t | | | | | | | | | | | | | K | M | 6 | | _ | | | | | | | | | | | | | B | B | M | | R | | | | | | | | | | | | | | | B | | D | | | | | | | | | | | | | | | | | A | | | | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | | | | 9 | | | | | | | | | | | | | | | | | 1 | | | | | | | | | | | | | | | | | 0 | | | | | | | | | | | | | | | | | _ | | | | | | | | | | | | | | | | | T | | | | | | | | | | | | | | | | | T | | | | | | | | | | | | | | | | | S | | | | | | | | | | | | | | | | | _ | | | | | | | | | | | | | | | | | N | | | | | | | | | | | | | | | | | O | | | | | | | | | | | | | | | | | L | | | | | | | | | | | | | | | | | V | | | | | | | | | | | | | | | | | G | | | | | | | | | | | | | | | | | L | | | | | | | | | | | | | | | | | _ | | | | | | | | | | | | | | | | | F | | | | | | | | | | | | | | | | | L | | | | | | | | | | | | | | | | | O | | | | | | | | | | | | | | | | | A | | | | | | | | | | | | | | | | | T | | | | | | | | | | | | | | | | +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ | L | 支 | 支 | 支 | 支 | 支 | 支 | 不 | 支 | 支 | 支 | 支 | 不 | 7 | 1 | 1 | | u | 持 | 持 | 持 | 持 | 持 | 持 | 支 | 持 | 持 | 持 | 持 | 支 | 2 | . | . | | a | | | | | | | 持 | | | | | 持 | 0 | 3 | 3 | | t | | | | | | | | | | | | | K | M | 6 | | _ | | | | | | | | | | | | | B | B | M | | R | | | | | | | | | | | | | | | B | | D | | | | | | | | | | | | | | | | | A | | | | | | | | | | | | | | | | | 8 | | | | | | | | | | | | | | | | | 9 | | | | | | | | | | | | | | | | | 1 | | | | | | | | | | | | | | | | | 0 | | | | | | | | | | | | | | | | | _ | | | | | | | | | | | | | | | | | B | | | | | | | | | | | | | | | | | T | | | | | | | | | | | | | | | | | _ | | | | | | | | | | | | | | | | | F | | | | | | | | | | | | | | | | | L | | | | | | | | | | | | | | | | | O | | | | | | | | | | | | | | | | | A | | | | | | | | | | | | | | | | | T | | | | | | | | | | | | | | | | +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ 2、如何分析not enough memory问题? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 在代码中增加 :: sys.timerLoopStart(function() log.info("Mem Free Size KB:", 1433- collectgarbage("count")) end, 2000) 每隔2秒钟打印一次剩余内存,如果剩余小于等于200KB,则表示剩余可用内存很少,考虑到内存碎片的影响,此时的剩余可用内存几乎为0,不足以维持程序正常运行 如果是开机后剩余可用内存就这么少,基本可以判断是脚本程序本身占用内存较多引起的,只能精简优化脚本代码,别无他法 如果开机后剩余内存很多,随着时间的推移,可用内存越来越少,可能是脚本程序中有内存泄漏,可以通过日志推断内存泄漏的代码或者通过关闭代码来分析