bloggerads

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();
}