IAR的link配置

不像STVD有翔实的UI界面来配置详细的link参数,IAR无法无法细致的展现这些参数,那么如何配置这些参数呢,比如section,内存起始等。

在我们创建IAR的工程时,会生成EWSTM8目录,在目录下面的icf文件,就是默认iar工程加载的配置文件。没有的话,也可以自己修改或者从其他工程拿模板来修改。

ST的写保护

有时候拿到的开发板或者其他ST的产品在IAR中烧录时会提示写保护。
解决的办法:
用STVP进行一次写入(默认会擦除flash,所以标识也被擦除了)Program the current tab

STM8 bootloader纪要

STM8 bootloader-UM0506

mcu:STM8L051F3P6,属于 STM8L Series low density

bootloder 支持

已经内置bootloader的mcu
bootloader group

没有内置bootloader的mcu

bootloder 执行流程图

bootloader执行流程图:

bootloder 传输设置

ota 同步消息SYNCHR=0x7F

支持传输的外设

从图上看,051F支持UART或者SPI
UART设置:1 start bit, 8 data bit, 1 bit 奇校验 ,1 stop bit
波特率:通过0x7F的传输,自动适配波特率,最大115200,最小4800.

传输回复
串口:1 start bit, 8 data bit, no parity bit, 1 stop bit,波特率自适应

SPI设置
• 8 data bit, MSB first
• Bit rate: Set by the host which acts as a master
• Peripheral set in slave mode with software management of NSS
• Data polarity: CPOL = 0 (SCK to 0 when idle), CPHA = 0 (the first clock transition is the
first data capture edge).

收到命令后,bl回复ACK 0x79

bootloder 外设选择

从资源的角度,我们倾向于使用spi做外设,因为uart可以预留来做用户调试用,但是目前官方提供了uart的串口下载PC客户端,方便测试。所以目前看使用uart作为bl外设可能更方便。这里也就要求选用单片机时,最好是多串口的设备。

bootloder 跳转地址表

关键点检测后,要跳转的地址表:

目前我们可以先考虑实现串口的版本,但是最后还是SPI的更实用。

完整文档:UM0506

Apollo mcu的flash写入函数am_hal_flash_program_info异常

参考系统给的样例,封装了写入函数:

int usr_write_config_to_flash() {
  int ret;
  U32 offset = 0;
  // do {
  // 写入前要先擦除块
  info_block_erase();

  // 写入配置数据
  memset(flash_write_buf, 0, sizeof(flash_write_buf));
  memcpy(flash_write_buf, &sys_config, sizeof(sys_config));
  offset = 0;

  ret = am_hal_flash_program_info(AM_HAL_FLASH_PROGRAM_KEY,
                                  0, // we are only supporting INFO on instance 0.
                                  flash_write_buf,
                                  offset / 4,                    // offset
                                  (sizeof(sys_config) + 3) / 4); // num words
  //} while (ret);

  if (ret) {
    log(ERR, "am_hal_flash_program_info at offset 0x%08x i32ReturnCode = 0x%x.\n", offset, ret);
    return ERROR;
  }
  log(RUN, "flash write success\r\n");
  return SUCCESS;
}

系统的样例是正常的,因为没有别的业务逻辑,我的代码在开机执行也是正常的,但是在业务中调用 am_hal_flash_program_info 函数时就会随机失败,开始一直怀疑是地址区段的问题,各种尝试都不行,后来看函数的原型,发现下面的文字说明,才恍然一惊:

 

看到蓝色标识的部分,才想到是不是被系统的定时器中断影响了,因为系统起来后开启了很多定时器中断,于是在擦除和写入的逻辑区间关闭了中断,于是就没有再发现失败了。

浪费了半天时间,惭愧,特此随记,以示教训:在没有相关文档的情况下,要仔细看函数原型的任何一行说明文字

STM8 IWDG看门狗的使用说明

好久不搞stm8了,但朋友请教,还是帮忙确认下。主要是确认STM8的看门狗用法和喂狗时间问题,网上大把的代码样例,但是还是要刨根问底弄清楚细节,才可以用,否则就是埋雷。

大概的调用样例代码:

#define SYS_IWDG_OPEN        IWDG_KR=0xCC;
#define SYS_IWDG_FEED        IWDG_KR=0xAA;

void SystemIWDG_Config(void)   
{
    CLK_ICKCR|=S3;
    while((CLK_ICKCR&S4)==0);
    //STM8单片机需先执行0xCC指令,即先打开IWDG模块,否则IWDG工作不正常
    IWDG_KR=0xCC;                //启动看门狗
    IWDG_KR=0x55;                //使能模块访问
    IWDG_RLR=0xFF;               //溢出时间
    IWDG_PR=0x06;                //256分频 38000/256=148HZ T=6.7ms    
    IWDG_KR=0xAA;                //装载IWDG->RLR
}

代码的解释请参见以下的网络内容:

STM8独立看门狗介绍

独立看门狗模块可以用于解决处理器因为硬件或软件的故障所发生的错误。它由一个内部的128kHz的LSI阻容振荡器作为时钟源驱动,因此即使是主时钟失效时它仍然照常工作。

  • 独立看门狗功能说明
    图24是STM8独立看门狗模块的功能框图。
    当在键寄存器(IWDG_KR)中写入数值0xCC后,独立看门狗就被启动了,计数器开始从它的复位值0xFF开始递减计数,当计数减到0x00时就会产生一个复位信号(WDG RESET)。
    使用IWDG_PR和IWDG_RLR寄存器配置独立看门狗。IWDG_PR寄存器是用于选择驱动计数器时钟的预分频系数。每当KEY_REFRESH的数值(0xAA)写入到IWDG_KR寄存器时,独立看门狗将用IWDG_RLR的数值刷新计数器的内容,从而避免了产生看门狗的复位。
    IWDG_PR和IWDG_RLR寄存器具有写保护功能,要修改它们前,需首先在IWDG_KR寄存器写入KEY_ACCESS代码(0x55);在IWDG_KR写入0xAA将恢复写保护状态。

STM8_蜂鸣器功能图
(图24:STM8独立看门狗框图)

  • 硬件看门狗功能
    如果在IWDG_HW选择字节中使能了硬件看门狗的功能,在芯片上电时看门狗的功能被自动开启,如果软件不能及时操作键寄存器,则在计数器达到0x00时产生复位。关于选择字节的内容请参考数据手册中的说明。
  • 超时周期
    超时周期由计数器数值和时钟预分频器决定,下表列出了它们的数值。


(表26:STM8看门狗超时周期(假定计数器时钟为64kHz) )

键寄存器(IWDG_KR)

地址偏移值:0x00
复位值:未定义

STM8_键寄存器(IWDG_KR)

位7:0 KEY[7:0]:键值
软件必须在规定的时间内写入KEY_REFRESH数值,否则当计数器数值达到0时,看门狗会产生一个复位。
KEY_ENABLE数值=0xCC
写入KEY_ENABLE数值将启动IWDG。
KEY_REFRESH数值=0xAA
写入KEY_REFRESH数值将刷新IDDG。
KEY_ACCESS数值=0x55
写入KEY_ACCESS数值将允许对受保护的IWDG_PR和IWDG_RLR寄存器的操作

预分频寄存器(IWDG_PR)

地址偏移值:0x01
复位值:0x00

STM8_预分频寄存器(IWDG_PR)

位7:3 保留,必须保持为0。
位2:0 PR[2:0]:预分频系数
这些位是写保护的。它们用于指定对计数器时钟分频的分频系数。
000:分频系数=4
001:分频系数=8
010:分频系数=16
011:分频系数=32
100:分频系数=64
101:分频系数=128
110:分频系数=256
111:保留

重装载寄存器(IWDG_RLR)

地址偏移值:0x02
复位值:0xFF

STM8_重装载寄存器(IWDG_RLR)

位7:0 RL[7:0]:看门狗计数器重装载数值
这些位是写保护的(见14.2)。每次在IWDG_KR寄存器中写入0x
被传送到看门狗的计数器中,看门狗的计数器将重新从这个值开和时钟的预分频系数决定,见表26。

IWDG寄存器映像和复位数值


(表27:STM8 IWDG寄存器映像 )

 

官方手册原始内容,124页:

http://www.st.com/content/ccc/resource/technical/document/reference_manual/9a/1b/85/07/ca/eb/4f/dd/CD00190271.pdf/files/CD00190271.pdf/jcr:content/translations/en.CD00190271.pdf

本地下载备份:en.CD00190271

根据芯片手册中时钟的配置:

文章开头样例代码的看门狗最大喂狗时间大约1.725秒(38K时钟)

openwrt中添加mt7628an对sim7600ce的支持

按照模块的使用手册,我们知道设备的usb会虚拟出5个串口设备。
在openwrt中默认是支持usb转uart的驱动的,默认是可以支持此设备的,我们只要在menuconfig中选择相应的开关就可以完成支持

Kernel Modules → USB Support
<*> kmod-usb2
<*> kmod-usb-ohci
<*> kmod-usb-serial
                <*> kmod-usb-serial-option
                -*- kmod-usb-serial-wwan
<*> kmod-usb-core

LoRa技术介绍

目前看,LoRa是一个在IOT方案领域替换GSM的初步可行方案,主要从距离和功耗两个考虑方面。

介绍如下:
http://www.lora-alliance.org/What-Is-LoRa/Technology
http://www.rfwireless-world.com/Terminology/LoRa-technology-basics.html
http://www.rfwireless-world.com/Terminology/IoT-wireless-technologies.html

芯片厂商目前也已经有了量产的芯片可供评估,成本在1-2个美金。
http://www.microchip.com/design-centers/wireless-connectivity/embedded-wireless/lora-technology
http://www.semtech.com/wireless-rf/lora.html

hugo-md文档书写时的格式说明

前言

在决定使用github-hugo自动化流程后,第一个面临的问题就是,这个文档头的格式到底是什么样的,因为现在你要手写,就需要彻底搞清楚, 以便达到正确和高效。

阅读查找了gohugo.io的所有相关页面,找到以下两个相关的内容基本上说的很清楚了:
https://gohugo.io/content/front-matter/
https://gohugo.io/content/archetypes/

头格式

md只是文档的类型,但是里面的内容遵循怎样的格式呢? hugo目前支持3中toml,yaml,json,三种格式的文件头。识别符号分别如下

  • toml: +++
  • yaml: —
  • json: {}

toml示例:

+++
title = "spf13-vim 3.0 release and new website"
description = "spf13-vim is a cross platform distribution of vim plugins and resources for Vim."
tags = [ ".vimrc", "plugins", "spf13-vim", "vim" ]
date = "2012-04-06"
categories = [
  "Development",
  "VIM"
]
slug = "spf13-vim-3-0-release-and-new-website"
+++

Content of the file goes Here

yaml示例:

---
title: "spf13-vim 3.0 release and new website"
description: "spf13-vim is a cross platform distribution of vim plugins and resources for Vim."
tags: [ ".vimrc", "plugins", "spf13-vim", "vim" ]
date: "2012-04-06"
categories:
  - "Development"
  - "VIM"
slug: "spf13-vim-3-0-release-and-new-website"
---

Content of the file goes Here

json示例:

{
    "title": "spf13-vim 3.0 release and new website",
    "description": "spf13-vim is a cross platform distribution of vim plugins and resources for Vim.",
    "tags": [ ".vimrc", "plugins", "spf13-vim", "vim" ],
    "date": "2012-04-06",
    "categories": [
        "Development",
        "VIM"
    ],
    "slug": "spf13-vim-3-0-release-and-new-website",
}

Content of the file goes Here

字段变量

文档可以包含很多变量。

必要字段

  • tile: 内容的标题
  • description: 内容的描述
  • date:日期
  • taxonomies:分类字段,包括tag和categories

可选字段

  • aliases: 别名
  • draft: 是否是草稿
  • publishdate: 定时未来发布的时间
  • type: 内容的格式,可以从内容自动识别
  • isCJKLanguage:是否时CJK
  • weight: 排序的权重
  • markup: 时markdown格式还是reStructuredText
  • slug: url尾部的token
  • url: 完整的url

hugo markdown引擎的配置

finish!

ublox agps proxy

perl版本的proxy实现,目前比较粗糙是无差别流量代理。

  1. 修复了一个bug:每当有请求时,都会产生一个子进程,响应后子进程不退出,导致内存泄漏
  2. 遗留的bug:按照原来的设计,socket建链后,只有client 发送 身份请求,验证成功后,才响应,目前是在 accept 建链时,就主动回应数据

代码地址:
ublox agps proxy

Hanging Sockets and Power Consumption – Basics, Part 3

很好的文章,就mobile 空socket 的耗电状态做了深入的分析.

更完整的内容参见:trepn-whitepaper-apps-power

from:https://developer.qualcomm.com/blog/hanging-sockets-and-power-consumption-basics-part-3

Continuing our series on mobile apps and their effect on battery drain, I’ll pick up where the three guidelines in Wayne Lee’s last post left off, especially #3: “Know what your app is doing with the hardware and when it’s doing it.”

One common way that mobile apps use too much power is through hanging sockets –network connections that the app is no longer using, but which the server thinks are still alive because the app has not closed them. The subsequent query from the server results in needless battery drain.

Here’s more background on the problem and how you can deal with it.

“Wake up. It’s time to go to sleep.”

Applications often “forget” to close their socket after they are done with it. Then, after some amount of time without data activity, the server times the socket out and closes it.

Socket termination in TCP requires a four-way handshake, so the server has to send a FIN packet to the device, which usually takes the device from the low-power dormant state to the higher-power active state. The device goes idle for a bit, then back to dormant. It’s like waking somebody up to tell them that it’s time to go to sleep.

Look at the example in the diagram. The red (1) shows the device jumping from dormant to active mode to send and receive data normally for a few seconds. Once finished, the cellular radio drops to a power-saving idle mode (2) in case that it’s needed again. After about 15 seconds of inactivity, the radio goes dormant (3).

    The diagram shows inefficiencies in Socket Termination activity on a device, the multiple steps it goes through to send/receive data and why it’s important to close sockets.

But the app has left the socket open (hanging). The server doesn’t like loose ends, so it sends its FIN packet to the device. This rouses the radio from dormant to active again (4), the same as if it were sending/receiving data for the app. Worse yet, the radio follows the normal curve back down to idle for another 15 seconds, wasting more power (5).

Begin to get the idea?

The phone has to bring up the radio for a simple, easily avoidable handshake because the server has asked the device for something that the app should have provided in the first place. If no other traffic moves between the device and the network, the connection is a complete waste of several hundred milliamperes.

Assuming that the app uses the network four times in an hour, the simple fix of having the app close the socket when finished can reduce network power consumption by about 20 percent, which would be the difference between eight and ten hours of standby power.

The lesson is: Program your app to close sockets when it has finished with them. Otherwise, the phone consumes power to bring up the radio for a needless handshake with the server.

Next Steps

So, to paraphrase Wayne, you need to know what your app is doing with the cellular radio, when it’s doing it and how to turn it off when the app no longer needs it.

Questions? Visit the Trepn Profiler Support Forum or let me know in the comments below.

cosmic 编译器未调用函数优化

Q. Can the compiler automatically remove unused functions from my application?

A. Yes, the default behavior includes all code linked however, you can add the +split compiler command line option to split the object into multiple sections. i.e. One section per function such that individual functions may be removed by the linker if they are not called. You then mark one or more segments in the link command file with the -k (keep) option to specifiy which segments need to be kept. Typically, you just need to add the -k segment option to the segment containing the vecotr table. This usually coversl all of the applications call trees.

stvd-cosmic

GPS Tracker系列漫谈(一)

序:

鉴于最近朋友的提议,打算将有关GPS Tracker 的相关知识做一个不断更新的漫谈系列,方便相关的朋友了解和讨论。同时也将对一些网络上以售卖为目的错误宣传予以指正。话题没有提纲,本人将根据随机想到的话题随意展开,如果希望了解相关话题对相关细节感兴趣的朋友,也可以留言,我会在后面的章节展开。

切入正文:

什么是GPS Tracker?

首先顺带说一下GPS,gps是一套通过卫星完成定位的系统,细节可在维基上搜索“GPS”。GPS目前已经不仅专指美制GPS导航系统,已经成为一个定位系统的泛称,所以你经常会听到北斗gps导航系统这样的叫法。

什么是GPS Tracker,参见其英文本意,就明白是GPS定位器。其主要功能为获取当前设备的gps坐标位置,结合地图或者专业GIS,人们就可以知道目标当前的实际空间位置。为什么说是空间位置,因为除了人们用的比较多的平面坐标,gps还能获取3维的海拔高度参数。

根据使用范围,GPS Tracker 也可分为很多类型,海事,军事,车载,个人,宠物等,不同的产品和方案都会有很大的参数差别和要求,可能使用不同的卫星,采用不同的物理信道,使用不同的定位系统等。后面的文章我们主要介绍民用的车载和个人GPS Tracker。对特殊行业GPS 感兴趣的朋友可以留言,以便进一步补充。

 

手机多基站定位中RXLEV跟接收信号强度(dbm)的对应关系

在开发手机多基站定位的过程中,会获取手机当前基站周边的其他基站的接收侧信号等级rxlev,当我们要做多基站定位时,要转化成基站侧的信号强度。 RXLEV跟接收信号强度的对应关系如下表:(信号依次增强)

RXLEV = 0                             RX < -110 dBm

RXLEV = 1        -110 dBm =< RX < -109 dBm

RXLEV = 2        -109 dBm =< RX < -108 dBm

RXLEV = 3        -108 dBm =< RX < -107 dBm

RXLEV = 61       -50  dBm =< RX <  -49 dBm

RXLEV = 62       -49  dBm =< RX <= -48 dBm

RXLEV = 63                           RX >  -48 dBm