Using stm32f4 and ecos I wanted to use a newer toolchain than the one provided by ecos. I have used yagarto before together with stm32 and wanted to test this with ecos.

To change compiler you have to change the CYGBLD_GLOBAL_COMMAND_PREFIX option for your build target in ecos. If your’e like me and prefer editing manually in text files this is how I did change this option to “arm-none-eabi” instead of “arm-eabi”:

Go to your ecos installation directory and find your target

cd /opt/ecos/ecos-3.0
find . -name stm32

I manage to find my target under packages/hal/cortexm/stm32/stm32x0g_eval.

cd packages/hal/cortexm/stm32/stm32x0g_eval

Now go to the directory where your targets .cdl file is located

cd current/cdl

Time to edit the file hal_cortexm_stm32_stm32x0g_eval.cdl:

nano -w hal_cortexm_stm32_stm32x0g_eval.cdl

Change the CYGBLD_GLOBAL_COMMAND_PREFIX to “arm-none-eabi”

..
cdl_option CYGBLD_GLOBAL_COMMAND_PREFIX {
display “Global command prefix”
flavor data
no_define
default_value { “arm-none-eabi” }
description ”
This option specifies the command prefix used when
invoking the build tools.”
..

Ok so now I can use “arm-none-eabi” which points to yagarto, but yagarto does not know cygwin paths so I have to use cygpath utility some how.. :(

I started development for the STM3240g_eval board which has a ARM cortex M4 CPU. For evaluation I started checking out eCos RTOS.

RedBoot is a bootloader used together with eCos. To build it for stm3240g_eval board:

- Make sure you have downloaded eCos and have a build environment (arm-eabi). You can find a mercurial repository at hg-pub.ecoscentric.com/ecos/.

- Make sure the ecosconfig script is in your path

Now create a directory where you want to build RedBoot in:

mkdir ecos-redboot-build
cd ecos-redboot-build

Point ecosconfig to your ecos source path (in my case /opt/ecos/ecos-3.0/packages).

ecosconfig –srcdir=/opt/ecos/ecos-3.0/packages new stm3240g_eval

Make sure you build the stm3240g_eval together with the stubs which is the binaries.

ecosconfig new stm3240g_eval stubs

Choose stm3240g_eval target.

ecosconfig target stm3240g_eval

Choose redboot template.

ecosconfig template redboot

Check configuration.

ecosconfig resolve
ecosconfig check

Create build tree

ecosconfig tree

Build

make

The redboot binaries will be found in the folder:
install/bin

, , ,

I wanted to patch the kernel with several patch-files found in a catalog. So I did a search and ended up with doing manually:


patch -p1

To create a script which patches the kernel with a list of patches found under the “patches” catalog:


find patches -name *.* -exec echo patch -p1 {} \; > patch.sh

Then make it runnable


chmod +x patch.sh

Add a line in the beginning:


nano -w patch.sh


#!/bin/sh

And run it! :)


./patch.sh

In cygwin or Linux you can download files over http using wget. This is a useful command if you want to recursively download files and folders from a web page:

wget -r -np http://the.site/I/want/to/download

:)

,

Small script in python for calculating mean and standard deviation:

import math

# Calculate mean of the values
def m(values):
        size = len(values)
        sum = 0.0
        for n in range(0, size):
                sum += values[n]
        return sum / size;

# Calculate standard deviation
def SD(values, mean):
        size = len(values)
        sum = 0.0
        for n in range(0, size):
                sum += math.sqrt((values[n] - mean)**2)
        return math.sqrt((1.0/(size-1))*(sum/size))

To use it:


import myscript
values=[0,2,4,5,6,7,8,1]


m(values)

4.125


SD(values, m(values))

0.5824823725107174
, ,

If you want to merge your branch “MyBranch” with default do the following:

hg update default # just in case you were somewhere else
hg pull -r MyBranch  # that gets MyBranch
hg merge MyBranch  # that merges the changes into default
hg commit # commit the merge
hg update MyBranch # go to the most recent change in MyBranch (note: it is not a 'head')
hg commit --close-branch  # Close the MyBranch

Found this info on stackoverflow.com

To build a cmake project on Windows you can use MinGW.

Open your command prompt “cmd” and go to the cmake project.
1. cd theProject
2. mkdir build
3. cd build
4. cmake -G “MinGW Makefiles” ..
5. mingw32-make

And you have built your project for Windows. :)

, ,

Testing some more functionality of c++11 and gcc 4.6.1 from article softwarequalityconnection. See my earlier post c++11 and gcc – Lambda expressions.

#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <string>

using namespace std;

struct A
{
A()=default; //C++11
~A()=default; //C++11
};

class M //C++11 delegating constructors - Not working with gcc 4.6.1
{
	int x, y;
	char *p;
	static auto const mMAX = 10;
public:
	M(int v) : x(v), y(0),  p(new char [mMAX])  {} //#1 target
//	M(): M(0) {cout<<"delegating ctor"< Not working with gcc 4.6.1
};

class Movable
{
Movable (Movable&&); //move constructor
Movable&& operator=(Movable&&); //move assignment operator
};

class C
{
int a;
int b;
public:
C(int i, int j) : a(i), b(i) {}
};

int main()
{
auto x = 0; // x has type int because 0 is int
auto c = 'a'; // char
auto d = 0.5; // double
auto national_debt = 14400000000000LL;// long long

const vector<int> vi;
typedef decltype (vi.begin()) CIT;
CIT another_const_iterator;

int arr[4]={0,1,2,3};
struct tm today={0};

C c_class {0,0}; //C++11 only. Equivalent to: C c_class(0,0);

int* a = new int[3] { 1, 2, 0 }; //C++11 only
delete [] a;

// C++11 container initializer
vector<string> vs={ "first", "second", "third"};
map<string, string> singers =
{ {"Lady Gaga", "+1 (212) 555-7890"},
{"Beyonce Knowles", "+1 (212) 555-0987"}};

int source[5]={0,12,34,50,80};
int target[5];
//copy 5 elements from source to target
copy_n(source,5,target);

int a2[5]={0};
char c2[3]={0};
iota(a2, a2+5, 10); //changes a2 to {10,11,12,13,14}
iota(c2, c2+3, 'a'); //{'a','b','c'}
}

And it compiles:
make

Scanning dependencies of target more
[100%] Building CXX object src/CMakeFiles/more.dir/more_expr.cpp.o
Linking CXX executable more
[100%] Built target more
, ,

After reading about c++11 at softwarequalityconnection I decided to test some of the examples found in the article.

Unfortunately I have gcc version 4.4 on my Ubuntu so I had to download a later gcc version (4.6-1). More info on what different gcc versions include can be found at gcc.gnu.org.

After downloading it I installed some more libraries needed for the compilation of the compiler.
sudo aptitude install libgmp3-dev libmpfr-dev libmpc-dev

Then I built the compiler:
1. ./configure
2. make
3. Waited for quite some time
4. Create a directory to put the new gcc in: mkdir /home/user/programs/gcc
5. make DESTDIR=/home/user/programs/gcc install

Then it was time to create the CMake build files. I created a new directory for the first example which was lambda expressions:
1. mkdir -p ~/programming/lambda
2. cd ~/programming/lambda
3. mkdir src
4. nano -w CMakeLists.txt

PROJECT(LambdaExpressions)

SET(CMAKE_SYSTEM_NAME Linux)

# set minimum cmake version
cmake_minimum_required(VERSION 2.6)
if(COMMAND cmake_policy)
  cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)

# where is the target environment
SET(CMAKE_FIND_ROOT_PATH  /home/user/programs/gcc/usr/local)
SET(GCC_BIN_DIR  ${CMAKE_FIND_ROOT_PATH}/bin)

SET(CMAKE_C_COMPILER   ${GCC_BIN_DIR}/gcc)
SET(CMAKE_CXX_COMPILER ${GCC_BIN_DIR}/g++)

# search for programs in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# for libraries and headers in the target directories
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

SET(CMAKE_CXX_FLAGS "-std=c++0x") # Add c++11 functionality

#include directories
INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/src )

ADD_SUBDIRECTORY(src)

Then I created the CMake build file for the source code:
1. cd src
2. nano -w CMakeLists.txt

ADD_EXECUTABLE(lambda lambda_expr.cpp)

And the source code:
nano -w lambda_expr.cpp

#include <iostream>
#include <algorithm>

int main()
{
    char s[]="Hello World!";
    int Uppercase = 0; //modified by the lambda
    std::for_each(s, s+sizeof(s), [&Uppercase] (char c) {
        if (std::isupper(c))
            Uppercase++;
    });
    std::cout<< Uppercase<<" uppercase letters in: "<< s << std::endl;
}

Build the application.
1. cd ~/programming/lambda
2. mkdir build
3. cmake ..

Scanning dependencies of target lambda
[100%] Building CXX object src/CMakeFiles/lambda.dir/lambda_expr.cpp.o
Linking CXX executable lambda
[100%] Built target lambda

Test the application:
1. cd ~/programming/lambda/build/src
2. ./lambda

2 uppercase letters in: Hello World!
, , , ,

Are you getting the error message “cannot connect to X server“?

Simple solution:
xhost +LOCAL:

Secure solution:
1. Check xauth for root sudo xauth list

my-desktop/unix:0  MIT-MAGIC-COOKIE-1  12a146abc468f6b9d134f944371ab75d

2. Copy the line (right-click, choose copy)
3. xauth
4. Write add and paste (right-click, choose paste)
5. exit
6. setenv DISPLAY my-desktop/unix:0 (Change the my-desktop/unix:0 part to what was listed for you)

For more info see sun.drydog.com.

, ,