Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


Unable to run pure C program on STM32F030

Posted by jbeik on November 13, 2014


I'm trying to run a test program on a Cortex M0. Without any real success.

I can flash internal memory but my program does not run as expected. In a first time, I only try to switch on and of PB12 line (GPIO).

My configuration: - FreeRTOSV8.1.2 - gcc 4.9.1 (bare metal) - STM32F030

I have written a pure C test program. Thus I have used the following ldscript:

~~~~~~~~~~~~~~~~~~ OUTPUTFORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm") OUTPUTARCH(arm) ENTRY(ResetHandler) SEARCHDIR(".");

MEMORY { FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 64K RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 8K }

SECTIONS { .text : { . = ALIGN(4); KEEP((.isr_vector)) *(.text) *(.text) (.rodata) *(.rodata) . = ALIGN(4); } > FLASH

_data_flash = .;

.data : AT ( _data_flash )
    . = ALIGN(4);
    _data_begin = .;
    . = ALIGN(4);
    _data_end = .;
} > RAM

.bss :
    . = ALIGN(4);
    _bss_begin = .;
    __bss_start__ = _bss_begin;
    . = ALIGN(4);
    _bss_end = .;
    __bss_end__ = _bss_end;
} > RAM

_stack_size = 1024;
_stack_end = ORIGIN(RAM)+LENGTH(RAM);
_stack_begin = _stack_end - _stack_size;
. = _stack_begin;
._stack :
    . = . + _stack_size;
} > RAM

} ~~~~~~~~~~~~~~~~~~

Loader is:

~~~~~~~~~~~~~~~~~~ extern unsigned long dataflash; extern unsigned long databegin; extern unsigned long dataend; extern unsigned long bssbegin; extern unsigned long bssend; extern unsigned long stackend;

extern void startup(void);

void Reset_Handler(void) { unsigned long *source; unsigned long *destination;

// Copying data from Flash to RAM
source = &_data_flash;
for(destination = &_data_begin; destination < &_data_end;)
    *(destination++) = *(source++);

// default zero to undefined variables
for(destination = &_bss_begin; destination < &_bss_end;)
    *(destination++) = 0;

// starting main program


void Default_Handler(void) { for(;;); }

attribute ((section(".isrvector"))) void (* const tableinterruptvector[])(void) = { (void *) &stackend, // 0 - initial stack pointer ResetHandler, // 1 - initial PC DefaultHandler, // 2 - NMI DefaultHandler, // 3 - hard fault ... DefaultHandler, // 45 - Irq 29 DefaultHandler, // 46 - Irq 30 Default_Handler, // 47 - Irq 31 }; ~~~~~~~~~~~~~~~~~~

My test program is only :


include "FreeRTOS.h"
include "task.h"
include "stm32f0xx_conf.h"

void startup(void) { GPIOInitTypeDef gpioinit;



while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET);


gpio_init.GPIO_Pin = GPIO_Pin_12;
gpio_init.GPIO_Mode  = GPIO_Mode_OUT;
gpio_init.GPIO_Speed = GPIO_Speed_Level_1;
gpio_init.GPIO_OType = GPIO_OType_PP;
gpio_init.GPIO_PuPd = GPIO_PuPd_NOPULL;

GPIO_Init(GPIOB, &gpio_init);

    GPIO_SetBits(GPIOB, GPIO_Pin_12);
    GPIO_ResetBits(GPIOB, GPIO_Pin_12);

} ~~~~~~~~~~~~~~~~~~~

I can build this test program without any trouble. I have checked with objdump that assembly output is correct:

~~~~~~~~~~~~~~~~~~~~~ image.elf: file format elf32-littlearm

Disassembly of section .text:

08000000 : ...

080000c0 : 80000c0: b580 push {r7, lr} 80000c2: b082 sub sp, #8 80000c4: af00 add r7, sp, #0 80000c6: f240 0300 movw r3, #0 80000ca: f2c0 0300 movt r3, #0 80000ce: 607b str r3, [r7, #4] 80000d0: f240 0300 movw r3, #0 80000d4: f2c0 0300 movt r3, #0 80000d8: 603b str r3, [r7, #0] 80000da: e007 b.n 80000ec ... ~~~~~~~~~~~~~~~~~~~~

I suppose I have done a mistake. But where ? Any ideas ?

Thanks a lot in advance,


Unable to run pure C program on STM32F030

Posted by rtel on November 13, 2014

It is always recommended to create a new project by editing the official demo for the port you are using - that way everything is pre-configured for you and in a known working state. If there is not an exact match for your port then chose the closest match. You should not need to create the low level stuff yourself unless you are the device manufacturer doing the first board bring up.

http://www.freertos.org/FreeRTOS-quick-start-guide.html http://www.freertos.org/Creating-a-new-FreeRTOS-project.html http://www.freertos.org/porting-a-freertos-demo-to-different-hardware.html

In this case it looks simply like you are trying to use FreeRTOS API functions that will place the calling task in the Blocked state without first creating a task or starting the scheduler. There are literally hundreds of demos you can use as a template for how to create tasks and start the scheduler, so your vTaskDelay() calls are called from within a task. This is perhaps a good generic start:


There is also lots of information on the FreeRTOS website showing how to do this, the tutorial books, etc.


[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]

Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.


"OTA Update Security and Reliability" webinar presented by TI and AWS. Register here.


FreeRTOS and other embedded software careers at AWS.

Latest News

FreeRTOS kernel V10.0.1 is available for immediate download. Now MIT licensed.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner