bloggerads

2021年7月24日 星期六

Scatter File Note

用來描述source code裡面, 變數, 程式要放到memory的哪一段位址.
然後一些defin, source code 和 scatter file會互相參考

常見的簡單 scatter file內容:

1.

https://developer.arm.com/documentation/dui0493/i/Chdbjdii


execution region的起始位置設為load region的起始位置

 2.

LOAD ADDR SIZE ;ADDR: 起始位址, SIZE: 長度
{
    RO +0
    {
        * (+RO)
    }

    RW +0 ;跟在前一個區域後面接著放
    {
        * (+RW)
    }

    ZI +0
    {
        * (+ZI)
    }
}

2021年7月19日 星期一

Windows平台用cygwin安裝build code工具make

1. Download cygwin
https://www.cygwin.com/
2. Execute the exe:
When you get to the "Select Packages" screen, expand the "Devel" section, find the "make" package, and select the version you want
3. Add make path to the environment. (typically under cygwin64/bin)
4. Done.

2021年7月14日 星期三

2021年7月6日 星期二

ARM 打包 library的command

打包成.a的形式:   armar   -r  mylib.a   obj1   obj2   obj3

打包成.lib的形式: armar   --create   mylib.lib   obj1   obj2 

.a或.lib可以直接和其他.o檔一起link, 產生出最後的binary

Visual Studio Hotkey/Operation (Continue Update..)

Duplicate this line: Alt + Shift + ↓

Comment/Uncomment line(s): Ctrl + /

Search Function: Ctrl + t

Bookmark: Ctrl + Alt + k

Jump to Bookmark: Ctrl + Alt + j

Trim trailing space automatically:

Transform TAB to Space

Show the function list in a file



2021年6月29日 星期二

Add a Git Submodule

Use Git Turtoise:

TortoiseGit -> Submodule Add...

Use Git Command:

git submodule add -b <branch> --name <submodule name> <repository> <folder path>

----------------------------------------------------------------------------------------------

After setting the previous step, you will find the new file ".gitmodules" is created (or updated)
Check the contents if it is as expect:

[submodule "name"]

path <folder path>

url =  <repository>

branch <branch>  -->  One of branch in the Submodule repository (Can ignore this one)

----------------------------------------------------------------------------------------------

Following Issue happened in build code after I add the submodule in my one of project:

cp: cannot overwrite directory 'xxxxxxxx.git' with non-directory

This means the build procedure is trying to copy xxxxxxxx.git to somewhere the xxxxxxxx.git has already existed.

I did the following steps to overcome this problem. (or you can simply delete it, and it will be automatically generated during submodule init)

1. git commit/check-in the code 
2. delete the xxxxxxxx.git in the submodule 
3. git submodule init/update



2021年6月26日 星期六

Arm Memory Structure Note

Observe the .lst file (generated by ARM compiler) to get the following conclustion.
ARM memory map is consists of:
  1. .Code
  2. .RO
  3. .RW
  4. .ZI
.Code = Code + inline Data
.RO = Constant Data
.RW = Local Variable
.ZI = Global Variable (Include Static Variable)

Add any code that may possibly increase RAM or ROM size.

ROM size = .Code + .RO + .RW 
RAM size = .RW + .ZI

The actual ARM outputted binary size is ROM size

<NOTE>
What makes .RW so special is because .RW data stays in the ROM but during initializing, it will be copied to RAM

C/C++ in Arm Cross Compiler

in Arm, C++ compiler recognizes keyword: extern "C", and the Macro __cplusplus

In C header files, add __cplusplus to make sure the header files can be recognized by C++, as following

#ifdef  __cplusplus // This statement is true in C++ but false in C
extern "C"
{
#endif

//Original Header File Contents

#ifdef __cplusplus
}
#endif

In C++, 

If you'd like to include a C header file without changing the C header, you can do like:

extern "C"{
     #include "CHeader.h"
}

If you'd like to export a function to C, you can do like:

extern "C" int OutputApi(int);



<NOTE>
A header file can only be compiled one time.
So it is needed to add a pure C type header file additionally to designate what C++ exported functions.
This C type header file is actually included in other C source files. (not in C++)
Following are the workable method to achieve the C/C++ cross compiler in ARM.

a.cpp
void aa(void){}

a.h
#ifdef  __cplusplus
#define EXTERN_C extern "C"
#else
#define EXTERN_C
#endif
EXTERN_C  void aa(void);

intermediate.h
include <a.h>

b.c
include <intermediate.h>
void call_c()
{
    aa();
}

2021年2月24日 星期三

Plant UML Example


PlantText UML Editor: https://www.planttext.com/

Flow Chart
@startuml
(*) --> "A example of a step"
    if "Is This is a good example?" then
        --> [Yes] "Copy it"
        -->(*)
    else
        --> [No] "Drop it!"
        -->(*)
    endif
@enduml


@startuml
participant User
 
User -> A1
activate A

-> B2
activate B

-> C3
activate C

C --> B: end3
destroy C

B --> A: end2
deactivate B

-> User: end1
deactivate A
 
@enduml



@startuml
A : A's property
B : B's property
C : C's property
[*] --> A : start to A
[*] --> B : start to B
A --> B : A to B
B --> C : B to C
C --> B : C to B
C --> C : C to C
@enduml

2024/05/21
Set arrow color & set contents color
skinparam arrowColor #blue
AAA-->BBB:  <color:blue> Description
AAA-[#red]->BBB:  Description

2017年10月3日 星期二

Python : struct

這篇說明 Python 要如何像C/C++一樣,將struct資料以binary的形式寫入檔案。
參考以下範例:

#! python2
""" Author: Martin Lee """
import struct
with open('out.bin','wb') as f:
    f.write(struct.pack('B8sHHL', 22, 'Hi World', 1, 2, 0x3322))

fin = open("out.bin", "rb")
i = struct.unpack('B8sHHL', fin.read())
fin.close()

2017年9月17日 星期日

Python : 使用 py2exe 打包 py檔成執行檔

Windows下將py檔打包成執行檔, 以python 2.7為範例

基本上是參考 http://www.py2exe.org/index.cgi/Tutorial

試過import 第三方模組、內建的GUI 模組(Tkinter)、自定義的模組, py2exe 都能打包。以下是流程:

1.安裝 py2exe

2.在要打包的py檔目錄下,新增一個'setup.py'檔,其內容為
  • from distutils.core import setup
  • import py2exe
  • setup(console=['要打包的檔名.py'])
3.python setup.py py2exe

4.會在同目錄下產生兩個資料夾,其一個新增的資料夾'dist'內會產生一個同檔名的exe檔

Linux下將py檔打包成執行檔, 以python 2.7為範例

1. 安裝 pyinstaller (pip install pyinstaller)
2. pyinstaller --onefile filename.py
3. 在同目錄下的dist資料夾內產生可執行檔 filename

2017年9月14日 星期四

Python : JSON

鑒於JSON愈來愈普及, 很多數據都要求使用JSON的格式,因此特別在這篇做個紀錄, 了解JSON以及如何用Python處理JSON。  

了解 JSON 的 format可以從這個
網站開始: http://jsoneditoronline.org/



#  JSON的規則:

1.  key:value
2.  value 型態可以是 數字, 字串, 布林, 陣列[], 物件{}, NULL, 但key一定是要字串
3.  同一個物件內的key不可重複, 如以下的 Age 就重複了
{
    "Martin": {
        "Age":33,
        "Age":5,
     }
}

2017年9月10日 星期日

Python : regular expression

re module的一些紀錄, 持續update

### Common use of the regular expression

\w   [a-zA-Z0-9_]
\d    [0-9]
\s    space
\\     '\'
.       ''
+     1 or more than 1
.\     everything

### Code

>>> import re
>>> string = 'Age=20'
>>> re.search('\d+', string).group()
20

>>> import re
>>> string = 'Beautiful, is; better*than\nugly'
>>> # 分隔符號:,  ;  *  \n
>>> list= re.split(',|; |\*|\n', string)
>>> list
['Beautiful', 'is', 'better', 'than', 'ugly']

2017年9月5日 星期二

Python : Combobox 範例

距離上次Python文,不知不覺又過了兩三個星期了。 時間過得真快,這段時間除了工作外,還去了花蓮玩兩天! 雖然工作上每天都在改code, 但使用到Python的機會很少,本著學海無涯,惟勤是岸的精神,隔一段時間就來po 一下,以免生疏了。今天介紹Combobox,搭配Button作範例,話不多說,馬上端上code:

#! python2
# coding: utf-8

import Tkinter as tk
import ttk   

def clickOkButton():
    print 'Select ' + str(numberChosen.current()) # 丟出選到的index number

win = tk.Tk()
win.title("Python Combobox example") 

2017年8月14日 星期一

Python : 透過字串與數字轉換來做"進制轉換"

所有的非10進制數字都要以字串的型式表達而數字一律是10進制表示

因此進制轉換就只是字串轉數字或數字轉字串的差別。以下就針對這兩種狀況來說明。

● 字串轉數字

>>> int ('0x10', 16)  #必須告訴直譯器字串是哪種進制
16

2017年8月13日 星期日

Python : Tkinter (Button, Label, Entry, Listbox)

Tkinter 並不是一個很強大的GUI library, 但優點是, 他是Python官方支援的module, 且大部分的OS都有預先安裝它<Note 1>。 之後陸續出現的第三方GUI library相信都是由他啟發的。因此如果不是開發太複雜的GUI tool, 又想了解這個歷史悠久的library, 那就值得來了解他。

話不多說,直接上code:

step 1. 先來創一個空的視窗

from Tkinter import *
    
win = Tk()
win.title("Tk Gui")
win.resizable(width=False, height=False)
win.geometry("500x250")

win.mainloop()


Python : 調用模組的語法比較

以調用random模組中randint函數,印出隨機數字0~10來作範例

1. 函數呼叫透過: 模組.函數() 
    import random
    print random.randint(0,10)

2. 直接呼叫函數(), 但必須告訴直譯器調用模組中的哪個函數
    from random import randint
    print randint(0,10)  

3. 直接呼叫函數(), 直接告訴直譯器要引用模組中所有的函數。 會有函數名稱衝突的風險!
    from random import *
    print randint(0,10)

4. 在script中定義模組的新名稱, 呼叫方式: 模組新名稱.函數()
    import random as newname
    print newname.randint(0, 10)

2017年8月11日 星期五

Python : tuple, list, set, dict 整理與比較


python常用的四種container types: tuple, list, set dictionary

tuple: ()
    - save in order
    - read only
list: []
    - save in order
set: {}

dictionary: {key:value}

NOTE:
t = tuple([1,2,3])
>>>t[0]
1



Python : Use dictionary to simulate multi-dimension array

Since there is no array in Python. Use dictionary instead.

Follows are the example to initialize a 2x2 array

>>>a={}
>>>for i in range(4):
. . .      a[i/2, i%2] = i
>>> a
{ (0,1):1, (1,0):2, (0,0):0, (1,1):3 }
>>>a[0,1]
1

2017年8月9日 星期三

Python : string related

### Demonstrate join

>>> list = ['Nice', 'to', 'meet', 'you']
>>> ''.join(list)
Nicetomeetyou

>>> ' '.join(list)
Nice to meet you

>>>'_'.join(list)
Nice_to_meet_you