LED works on stm32f4-discovery

Let’s first get some kudos where they are needed. You can find really great book by Geoffrey Brown.

So the LED works: I have been playing with Tasking’s VX-toolset for some time now.

And I have been posting some findings in the blog. Since I got porting some old code to new 5.1 version covered I thought to play with LEDs on the board now.

But first – let’s create a new environment to work in. The task is rather simple: File | New | Tasking ARM C/C++ Project. Write in the name of the project and you can now select Empty Project under TASKING ARM Application.

Click Next and since you are using stm32f4-discovery board you have to expand STMicroelectronics and select STM32F439 and click on the STM32F439ZI. Click on Finish.

We have to write in the code now so let’s create and empty C source file by: File | New | Source File. Name the file as you like and finish it with .c

To get the LEDs on the board to turn on we need to use RCC (Reset and Clock ) with Tasking Software Platform (right click on the title of the project and select)

By clicking the iconScreen Shot 2014-11-13 at 08.33.51 you can select libraries or code snippets you need to get the code running.

Since we’ll be using RCC and GPIO let’s select them both from the right list (Peripherals) – so STM32F4XX RCC. We also need GPIO access, but since we are accessing only PG13 and PG14 let’s select only GPIOG – by expanding STM32F4XX GPIO and selecting STM32F4XX_GPIOG. Finish with OK and generate the code (check previous post for exact details).

We also need to create a PinMapper map and again use previous post for exact details. Additionally to creating a PinMapper we also need to select proper port under Ports – expand it, and under PG click on the PG13 and select GPIO under Chip input/output.

Repeat the procedure for PG14, too.

And since we are using RCC  we also need to work on that.  Search for RCC under Peripherals and select Crystal/Ceramic Resonator under Low Speed Clock.

Don’t forget to generate the code.

You can then use the following code to light the LEDs on the board:

#include <stdio.h>
#include <stm32f4xx_conf.h>

int main(void)
    // enable clock for the GPIO
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOG, ENABLE);
    // select the ports
	unsigned short int led = GPIO_Pin_13 | GPIO_Pin_14;
    // prepare the data for GPIO port
	GPIO_InitTypeDef GPIO_InitStructure;
    // which PIN
	GPIO_InitStructure.GPIO_Pin = led;
    // output mode
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
	GPIO_Init(GPIOG, &GPIO_InitStructure);
    // set GPIO port to high
	GPIO_WriteBit(GPIOG, led, Bit_SET);

Porting old code to new VX-toolset v5.1r1 (for stm32f4-discovery)

You have been using VX-toolset and now you wan’t to try it, use it … in version v5.1r1 (mind you I have tested the procedure on MAC OS X version, but I guess there should not be a difference).

So let’s try the “porting” procedure on Hello World example that I got in examples folder when visiting the workshop.

1. From menu select File | Import and Existing Projects into Workspace and click Next



2. Click Select archive file and by clicking Browse button find Hello World file

Screen Shot 2014-11-12 at 13.43.54

3. Add the file and click Finish button.

You will get the Hello World entry in the left window. Expand it if needed.

4. Double click Hello World.swpxmi to get TASKING Software Platform and if you see error or warning messages on the right side of the title just hover over them and click the shown link (to re-generate the code). The same goes for the message “Generated code is out-of-date”).

So we are done? Try to compile it and you’ll get error:

amk F128: no rule to make “.\SoftwarePlatform\platform\pal\timing\src\timers.obj

The version 5.1 of VX-toolset has brought some additional tools which need to be added. Thanks to good people from Tasking to bring it to my attention.

You need to right click the Hello World [Active – Debug] title to get the menu, select New, select Pin Mapper Document and by clicking Browse button select Hello World.

Screen Shot 2014-11-12 at 13.59.34

Click Next and select STMicroelectronics

Screen Shot 2014-11-12 at 14.01.34

and click Finish.

Click on the icon (to generate C code) in the upper right corner. It looks like this: Screen Shot 2014-11-13 at 07.47.34


If you pay attention to maps on the left side you’ll notice the map PinMapper is created.

Trying to compile the code still produces the previous error. I was wondering what is going on for long time and then an answer from Tasking gave me a hint – remove the Debug map. Go ahead – right click it and choose Delete.

It’s better now.

The last thing we have to do is include the Hello World header file, so add the line:

#include "Include/Hello World.h"

Try to compile the code now and voila – success.

Let’s take a look at sending the code to the board:


and select Target as on the following image:

Screen Shot 2014-11-13 at 13.30.23

Creating private library for stm32f4-discovery

The procedure is more or less same for any usage of gcc, but we’ll concentrate on stm32f4-discovery board.

The procedure to create functions is similar to any function creation.  I guess there is no need for me to explain that, or is it?

More or less everything is just a – use this Makefile:


LIB_NAME = libname

vpath %.c src src/peripherals

CFLAGS  = -g -O2 -Wall
CFLAGS += -mlittle-endian -mthumb -mcpu=cortex-m4 -mthumb-interwork
CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
CFLAGS += -ffreestanding -nostdlib
CFLAGS += -Ilib/inc -Ilib/inc/core -Ilib/inc/peripherals

SRCS = main.c

OBJS = $(SRCS:.c=.o)


all: $(LIB_NAME).a

%.o : %.c
    $(CC) $(CFLAGS) -c -o $@ $^

libled.a: $(OBJS)
	$(AR) -r $@ $(OBJS)

	rm -f $(OBJS) $(LIB_NAME).a



TASKING VX-toolset for MAC OSX


the good people from Tasking contacted me  since I showed the interest to test their shiny tool for programming all the ARM thingies on MAC OS X (e.g. stm32f-discovery) and it’s a v5.1r1 version. In beta, but I didn’t find any problems … uhm… yet :).

Anyway I will be posting my findings, how to guides and stuff in weeks to come.

The first how to guide (on porting older code to the v5.1r1) is in the making :).


LPCXPRESSO library creation

After some initial tests with LPCXPRESSO I wanted to create a library just so I can use some solutions easily next time.

So how to create one?

1. Create empty library project with selecting: File | New | Project | LPCXPresso C Project. Click Next. Select LPC11U6x under LPC11/LPC12 and click LPCOpen – C Static Library Project. Click Next and type in the library name. Click Next two times. Under LPCOpen Chip Library Project select lpc_chip_11u6x and under LPCOpen Board Library Project select lpc_board_nxp_lpcxpresso_11u68. Click next 3 times and Finish.

2. Expand elements in the created project under Project Explorer.

3. Right click src and select New | File and type in the file name to create an empty source file.

4. Write in the code for the library and save it.

5. Right click inc and select New | File and type in the file name to create an empty header file.

6. Add functions written in the src file.

7. Compile it (e.g. by clicking Build in the Quickstart Panel)

If everything goes well you now have a file with library name ending with .a