2018年12月18日 星期二

Keil C: Warning: #1296-D: extended constant initialiser used"?


The root cause is miss use a pointer to a static variable like:

int x = 1;
int y = (int) &x;

Modify version

int x = 1;
int *y = &x;

printf("%p\n", &x);  // memory address of x
printf("%p\n", &y);   // memory address of y

printf("%p\n", y);     // y = memory address of x
printf("%d\n", *y);   // *y = memory content of x  = 1


Addresses are not arithmetic types in ANSI C spec, so if need to get the address of a static variable, use a pointer point to the variable's address.







Ref :
 1. http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.faqs/ka15182.html
 2.https://openhome.cc/Gossip/CGossip/Pointer.html

2018年8月1日 星期三

CC2640: Bus fault exception error on AuxAdiDdiSafeWrite function

Temporary solution : Disable the Power Saving feature on your project and rebuild both stack and app project.

My BLE stack version is 2_02_01_18, TI RTOS CC26xx version is 2_20_01_18,  XDC tool version is 3_32_00_06

I guess the reason of this error is cause by the power constrain setting and peripheral issue, because the power initial code in [9],  but I am not very sure since I didn't go deep in this problem now.








 Some related source:
    1.CC26XX Driver lib document:AuxAdiDdiSafeWrite 
    2.CC2640: Bus fault after random number of packets received to cc2640
    3.CC2650调试问题
    4.CC2640 - Sensor Controller power consumption
    5.hard fault in CC3200 I2C
    6.I2C Peripheral Setup Causes a processor Force Hardware Fault
    7.RTOS/CC2640: Hard Fault: FORCED: BUSFAULT: PRECISERR.Data Access Error.
    8.Hard Fault: FORCED: BUSFAULT: PRECISERR.Data Access Error
    9.CC2650 as I2C Slave

Reason?


  1. CC2640如何在打开PowerSaving模式下唤醒并操作uart?
  2. RTOS/CC2640: Unresponsive in power saving mode
  3. CC2640 UART With Power Saving
  4. Power Managementfor CC26xx SimpleLink Wireless MCUsUser’s Guide
  5. Where and why the SMPH0 reset error (keep 0) did not release


2018年7月30日 星期一

Unsigned and signed shift:logical shift and arithmetic shift

In C, we usually use left shift and right shift operation << and >> to operate multiple / divide to variable with power of 2,ex: 4<<2  = 16

But when we use the signed variable and the shift operation we must consider the singed bit.See the below example code.

int 8_t b = -10; // b = 0xf6 for 2's complement
b = b << 1; // b=0xec
b = b >> 1; // Now b = 0x76 and for demical b = 118 unexpect ouput
// The correct way to do that operation
b = b&0x80 | b>>1;// b = 0xf6 for demical b = 10
view raw gistfile1.txt hosted with ❤ by GitHub
Since the C language support the arithmetic left shift and logic right shift,  we must consider the signed bit to  avoid some bug in code.



Ref:
     1.Logical Vs. Arithmetic Shift
     2.C语言中的逻辑右移和算术左移

2018年5月28日 星期一

CC2640: Merge app and stack hex file

1. Install Python2.7
2. Open cmd.exe type > pip install intelhex
 






3. Use below instruction to merge your hex file
python C:\Python27\Scripts\hexmerge.py -o .\SOMETHING_MERGED.hex -r 0000:1FFFF .\SOMETHING_APP.hex:0000:1FFFF .\SOMETHING_STACK.hex --overlap=error
view raw gistfile1.txt hosted with ❤ by GitHub

2018年5月13日 星期日

GO: Development a simple windows GUI use lxn-walk package(2) -- Combobox and Button

1.Create the project folder and win_gui_v1.go in your go work space
   > cd ..\src\
   > mkdir win_gui_v1
2.Copy the .manifest file and modify to your_execution.exe.manifest
 












3.Code
// Copyright 2017 The Walk Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"fmt"
"log"
"os"
"github.com/lxn/walk"
. "github.com/lxn/walk/declarative"
)
func main() {
var connPB, exitPB *walk.PushButton
var comCB *walk.ComboBox
data := make([]string, 3)
data = []string{"123", "456", "789"}
if _, err := (MainWindow{
Title: "ComboBox Button",
Layout: VBox{},
Children: []Widget{
HSplitter{
Children: []Widget{
Label{
Text: "ComboBox:",
},
ComboBox{
AssignTo: &comCB,
Editable: false,
Model: data,
},
PushButton{
AssignTo: &connPB,
Text: "Show",
OnClicked: func() {
fmt.Println("Show " + data[comCB.CurrentIndex()])
},
},
},
},
PushButton{
AssignTo: &exitPB,
Text: "Exit",
OnClicked: func() {
fmt.Println("Exit")
os.Exit(0)
},
},
},
}).Run(); err != nil {
log.Fatal(err)
}
}
view raw gistfile1.txt hosted with ❤ by GitHub
3.Result
 











Ref:
      1. Go实战--使用golang开发Windows Gui桌面程序(lxn/walk)
      2. ComboBox 類別
      3. lxn/walk/examples

2018年5月6日 星期日

GO: Development a simple windows GUI use lxn-walk package(1) -- Getting start


"Walk is a "Windows Application Library Kit" for the Go Programming Language.
Its primarily useful for Desktop GUI development".  In this series I try to build a simple terminal program to commnunicate via COM port.

1. Getting start
    >   go get github.com/lxn/walk

2. Build the example
     >   cd ..\src\github.com\lxn\walk\examples\imageviewer
     >   go build

3. run the imageviewer.exe

  
    






Ref:
    1.  l/walk

GO : List all the serial port in windows use golang-sys package

We can easily get all the serial port in windows using regedit.exe











In our application we read the windows register key `HARDWARE\\DEVICEMAP\\SERIALCOMM` through windows API and list all the sub key and value.


Github project: win_serial_console

2018年4月2日 星期一

CC2640:Change RF front end mode and bias

1. In ../main.c define your own BLE configuration template.
#ifndef USE_DEFAULT_USER_CFG
#include "ble_user_config.h"
// BLE user defined configuration
//bleUserCfg_t user0Cfg = BLE_USER_CFG;
#define MY_RF_FE_MODE_AND_BIAS ( RF_FE_DIFFERENTIAL | RF_FE_INT_BIAS)
#define MY_BLE_USER_CFG { MAX_NUM_BLE_CONNS, \
MAX_NUM_PDU, \
MAX_PDU_SIZE, \
MY_RF_FE_MODE_AND_BIAS, \
rfRegTbl, \
&txPwrTbl, \
rfDriverTable, \
eccDriverTable, \
CRYPTO_DRV_TABLE, \
trngDriverTable, \
ASSERT_CBACK, \
L2CAP_NUM_PSM, \
L2CAP_NUM_CO_CHANNELS,\
&pfnBMAlloc, \
&pfnBMFree, \
PM_STARTUP_MARGIN }
bleUserCfg_t user0Cfg = MY_BLE_USER_CFG;
#endif // USE_DEFAULT_USER_CFG
view raw gistfile1.txt hosted with ❤ by GitHub
2.The option and default configuration is define in ../ble_user_config.h
// RF Front End Settings
// Note: The use of these values completely depends on how the PCB is laid out.
// Please see Device Package and Evaluation Module (EM) Board below.
#define RF_FE_DIFFERENTIAL 0
#define RF_FE_SINGLE_ENDED_RFP 1
#define RF_FE_SINGLE_ENDED_RFN 2
#define RF_FE_ANT_DIVERSITY_RFP_FIRST 3
#define RF_FE_ANT_DIVERSITY_RFN_FIRST 4
#define RF_FE_SINGLE_ENDED_RFP_EXT_PINS 5
#define RF_FE_SINGLE_ENDED_RFN_EXT_PINS 6
//
#define RF_FE_INT_BIAS (0<<3)
#define RF_FE_EXT_BIAS (1<<3)
...
...
...
#define BLE_USER_CFG { MAX_NUM_BLE_CONNS, \
MAX_NUM_PDU, \
MAX_PDU_SIZE, \
RF_FE_MODE_AND_BIAS, \
rfRegTbl, \
&txPwrTbl, \
rfDriverTable, \
eccDriverTable, \
CRYPTO_DRV_TABLE, \
trngDriverTable, \
ASSERT_CBACK, \
L2CAP_NUM_PSM, \
L2CAP_NUM_CO_CHANNELS,\
&pfnBMAlloc, \
&pfnBMFree, \
PM_STARTUP_MARGIN }
view raw gistfile1.txt hosted with ❤ by GitHub
 

The internal bias and external bias is determine by the RX_TX pin, which didn't implement in 7x7 package.In our application we use the CC2592 as PA and use 5x5 package for smaller footprint, and the configuration is differential mode internal bias.


Ref:
      1.CC26xx HW Training : RF Front End options and Antennas
      2.CC2640 在 Beacon 应用中的实现方法
      3.CC26x0 SimpleLink™Bluetooth®low energy Software Stack 2.2.xDeveloper's Guide

2018年1月17日 星期三

CC2640:Use System_printf in project.

1.I use IAR as IDE to develop CC2640 BLE project and XDS100V3 as debugger.First make sure           enable the Semihosted and Via semihosting in General Options.
 
2.Add below code in app_ble.cfg file.
utils.importFile("../../../../../src/common/cc26xx/kernel/cc2640/config/cc2640.cfg");
/*
* Extend the cc2640 configuration
*/
var SysStd = xdc.useModule("xdc.runtime.SysStd");
var System = xdc.useModule("xdc.runtime.System");
System.SupportProxy = SysStd;
System.extendedFormats = '%$L%$S%$F%f';
view raw gistfile1.txt hosted with ❤ by GitHub
 

3.Add include header file and test.
#include <xdc/runtime/System.h>
..
..
..
System_printf("Hello World!");
view raw gistfile1.txt hosted with ❤ by GitHub



4.In debug mode enable View->Terminal I/O and we can see the Hello World! in terminal.




















Ref:
     1.System_printf and printf() on CC2650 sensorTag
     2.System_printf supported format specifications

Linux driver: How to enable dynamic debug at booting time for built-in driver.

 Dynamic debug is useful for debug driver, and can be enable by: 1. Mount debug fs #>mount -t debugfs none /sys/kernel/debug 2. Enable dy...