AnsweredAssumed Answered

STM32W and SimpleMAC Library

Question asked by martin.sergio on Mar 19, 2013
Latest reply on Nov 4, 2013 by meister.david

I'm trying to compile and test the examples provided by STthe basics included inSTM32W108xx_StdPeriph_Lib_V1.0.1 and examples using the LibrarySimpleMAC included in STM32W108xx_SimpleMAC_V2.0.1.

When I do it with IAR environments as I have no problembut I'm trying to use free software to create the environment.

I have previously worked with F103 and F107 microprocessors and have had no problem compiling the examples using CodeSourceryor to connect to the board using OpenOCD to load the binary into flash and open a port for GDBor for debugging the examples that come with STM32F10x_StdPeriph_Lib_V3.5.0.

By the time I managed to compile the basic examples like i did with the F103 and F107microprocessors and I loaded and debugged in MB851 RevD evaluation board

For that I have compiled:
Example Files:

STM32W108xx_StdPeriph_Driver Files:
Common files of evaluation boards:
Files MB851 RevD:

A startup.c file: (Can you tell me if there is something wrong?)

#include <stdint.h>
#include "stm32w108xx_it.h"

/* System handlers */
void ResetISR(void) __attribute__ ((interrupt));
extern void NMI_Handler(void) __attribute__ ((interrupt)) __attribute__ ((weak));
extern void HardFault_Handler(void) __attribute__ ((interrupt)) __attribute__ ((weak));
extern void MemManage_Handler(void) __attribute__ ((interrupt)) __attribute__ ((weak));
extern void BusFault_Handler(void) __attribute__ ((interrupt)) __attribute__ ((weak));
extern void UsageFault_Handler(void) __attribute__ ((interrupt)) __attribute__ ((weak));
extern void SVC_Handler(void) __attribute__ ((interrupt)) __attribute__ ((weak));
extern void DebugMon_Handler(void) __attribute__ ((interrupt)) __attribute__ ((weak));
extern void PendSV_Handler(void) __attribute__ ((interrupt)) __attribute__ ((weak));
extern void SysTick_Handler(void) __attribute__ ((interrupt)) __attribute__ ((weak));
extern void TIM1_IRQHandler(void) __attribute__ ((interrupt)) __attribute__ ((weak));
extern void TIM2_IRQHandler(void) __attribute__ ((interrupt)) __attribute__ ((weak));
extern void MNG_IRQHandler(void) __attribute__ ((interrupt)) __attribute__ ((weak));
extern void BASEBAND_IRQHandler(void) __attribute__ ((interrupt)) __attribute__ ((weak));
extern void SLPTIM_IRQHandler(void) __attribute__ ((interrupt)) __attribute__ ((weak));
extern void SC1_IRQHandler(void) __attribute__ ((interrupt)) __attribute__ ((weak));
extern void SC2_IRQHandler(void) __attribute__ ((interrupt)) __attribute__ ((weak));
extern void SECURITY_IRQHandler(void) __attribute__ ((interrupt)) __attribute__ ((weak));
extern void MAC_TIM_IRQHandler(void) __attribute__ ((interrupt)) __attribute__ ((weak));
extern void MAC_TR_IRQHandler(void) __attribute__ ((interrupt)) __attribute__ ((weak));
extern void MAC_RE_IRQHandler(void) __attribute__ ((interrupt)) __attribute__ ((weak));
extern void ADC_IRQHandler(void) __attribute__ ((interrupt)) __attribute__ ((weak));
extern void EXTIA_IRQHandler(void) __attribute__ ((interrupt)) __attribute__ ((weak));
extern void EXTIB_IRQHandler(void) __attribute__ ((interrupt)) __attribute__ ((weak));
extern void EXTIC_IRQHandler(void) __attribute__ ((interrupt)) __attribute__ ((weak));
extern void EXTID_IRQHandler(void) __attribute__ ((interrupt)) __attribute__ ((weak));
extern void DEBUG_IRQHandler(void) __attribute__ ((interrupt)) __attribute__ ((weak));

/* Main entry point */
extern void main(void);

#define STACK_SIZE               1024
static unsigned long mainStack[STACK_SIZE];

void (* const g_pfnVectors[])(void) __attribute__((section(".isr_vector"))) = {</span></div>
    (void (*)(void))((unsigned long)mainStack+sizeof(mainStack)),</span></div>
    ResetISR,               // ; Reset Handler
    NMI_Handler,          // ; NMI Handler
    HardFault_Handler,          // ; Hard Fault Handler
    MemManage_Handler,          // ; MPU Fault Handler
    BusFault_Handler,          // ; Bus Fault Handler
    UsageFault_Handler,          // ; Usage Fault Handler
    0,                    // ; Reserved
    0,                    // ; Reserved
    0,                    // ; Reserved
    0,                    // ; Reserved
    SVC_Handler,          // ; SVCall Handler
    DebugMon_Handler,          // ; Debug Monitor Handler
    0,                    // ; Reserved
    PendSV_Handler,          // ; PendSV Handler
    SysTick_Handler,          // ; SysTick Handler
    TIM1_IRQHandler,            // ; 16+ 0   Timer 1 Interrupt
    TIM2_IRQHandler,            // ; 16+ 1   Timer 2 Interrupt
    MNG_IRQHandler,             // ; 16+ 2   Management Peripheral Interrupt
    BASEBAND_IRQHandler,        // ; 16+ 3   Base Band Interrupt
    SLPTIM_IRQHandler,          // ; 16+ 4   Sleep Timer Interrupt
    SC1_IRQHandler,             // ; 16+ 5   Serial Controller 1 Interrupt
    SC2_IRQHandler,             // ; 16+ 6   Serial Controller 2 Interrupt
    SECURITY_IRQHandler,        // ; 16+ 7   Security Interrupt
    MAC_TIM_IRQHandler,         // ; 16+ 8   MAC Timer Interrupt
    MAC_TR_IRQHandler,          // ; 16+ 9   MAC Transmit Interrupt
    MAC_RE_IRQHandler,          // ; 16+10   MAC Receive Interrupt
    ADC_IRQHandler,             // ; 16+11   ADC Interrupt
    EXTIA_IRQHandler,           // ; 16+12   EXTIA Interrupt
    EXTIB_IRQHandler,           // ; 16+13   EXTIB Interrupt
    EXTIC_IRQHandler,           // ; 16+14   EXTIC Interrupt
    EXTID_IRQHandler,           // ; 16+15   EXTID Interrupt
    DEBUG_IRQHandler,           // ; 16+16   Debug Interrupt

extern unsigned long _etext;
extern unsigned long _data;
extern unsigned long _edata;
extern unsigned long _bss;
extern unsigned long _ebss;

void ResetISR(void) {
     unsigned long *pulSrc, *pulDest;

     /* Copy the .data section from flash to SRAM. */
     pulSrc = &_etext;
     for (pulDest = &_data; pulDest < &_edata;) {
          *pulDest++ = *pulSrc++;

     /* Zero fill the .bss sction.  This is done with inline assembly since this
      * will clear the value of pulDest if it is not kept in a register. */
     __asm("    ldr     r0, =_bss\n"
            "    ldr     r1, =_ebss\n"
            "    mov     r2, #0\n"
            "    .thumb_func\n"
            "    cmp     r0, r1\n"
            "    it      lt\n"
            "    strlt   r2, [r0], #4\n"
            "    blt     zero_loop");

     /* Call entry point: */
     /* Loop forever (If we get here there was an error in main) */

So I have no problem to compile the examples that comes in STM32W108xx_StdPeriph_Examples (except ADC_TSensorGPTimer_InfraRed,I2C_MEMS and Uart_Printfcan upload it to the board and debug it without problems.

In order to compile and debug the programs ADC_TSensorGPTimer_InfraRedI2C_MEMSand Uart_Printf, since use printf through the UART I had to add a syscalls.c file: (Can you tell me if there is something wrong?)

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>

typedef char * caddr_t;

caddr_t _sbrk(int incr) {
     extern char end asm("end");
     return (caddr_t)  &end;

int _write(int file, char *ptr, int len) {
     int DataIdx;

     for (DataIdx = 0; DataIdx < len; DataIdx++)
        __io_putchar( *ptr++ );
     return len;

int _close(int file) {
     return -1;

int _fstat(int file, struct stat *st) {
     return 0;

int _isatty(int file) {
     return 1;

int _lseek(int file, int ptr, int dir) {
     return 0;

int _read(int file, char *ptr, int len) {
     return 0;

The Link File link.ld: (Can you tell me if there is something wrong?)

/* Entry Point */

/* Specify the memory areas */
  FLASH (rx)      : ORIGIN = 0x08000000, LENGTH = 256K
  SRAM (xrw)      : ORIGIN = 0x20000000, LENGTH = 16K

/* Define output sections */
     /* . = 0x08001000; */
     . = 0x08000000;
    .text . :
          . = ALIGN(4);
        . = ALIGN(4);
        . = ALIGN(4);
    } > FLASH
     .ARM.extab :
          *(.ARM.extab* .gnu.linkonce.armextab.*)
     } > FLASH
     .ARM.exidx :
          __exidx_start = .;
          *(.ARM.exidx* .gnu.linkonce.armexidx.*)
          __exidx_end = .;
     } > FLASH

     _etext = .;

    .data : AT (ADDR(.text) + SIZEOF(.text) + SIZEOF(.ARM.extab) + SIZEOF(.ARM.exidx))
        _data = .;
        _edata = .;
    } > SRAM

    .bss : AT (ADDR(.text) + SIZEOF(.text) + SIZEOF(.ARM.extab) + SIZEOF(.ARM.exidx) + SIZEOF(.data))
        _bss = .;
        _ebss = .;
    } > SRAM

At this point I managed to load and debug all examples using:
a) Segger J-Link with the program to load binary stm32w_flasherGDB Server to open the communications port and GDB to debug
bSTLink V2 with STM32 ST-LINK Utility to load the binaryOpenOCD to open the communications port and GDB to debug

When I try to do the same with the examples that come to SimpleMACmore specifically withthe TALK

I have to be included as before:

INC_DIR = -I STM32W108xx_StdPeriph_Driver/inc \</span></div>
          -I CMSIS/Device/ST/STM32W108xx/Include \</span></div>
          -I CMSIS/Include \
          -I Utilities/STM32_EVAL/Common \
          -I Utilities/STM32_EVAL/MB851

and also: (HAL)

INC_DIR +=-I Utilities/STM32W108xx_HAL_Driver \</div>
          -I Utilities/STM32W108xx_HAL_Driver/micro \</div>
          -I Utilities/STM32W108xx_HAL_Driver/micro/cortexm3 \</div>
          -I Utilities/STM32W108xx_HAL_Driver/micro/cortexm3/bootloader \</div>
          -I Utilities/STM32W108xx_HAL_Driver/micro/cortexm3/compiler \</div>
          -I Utilities/STM32W108xx_HAL_Driver/micro/cortexm3/stm32w108 \</div>
          -I Utilities/STM32W108xx_HAL_Driver/micro/generic/compiler</div>
and: (SimpleMAC)

INC_DIR +=-I SimpleMAC/Include

The Flags i use are:
C_FLAGS += -g -c -D USE_STDPERIPH_DRIVER -D USE_MB851_REVD -D STM32W108CC -D PLATFORM_HEADER=\"$(STM32W_DIR)/Utilities/STM32W108xx_HAL_Driver/micro/cortexm3/compiler/gnu.h\" -D CORTEXM3 -D CORTEXM3_STM32W108 -D CORTEXM3_STM32W108CC -D DISABLE_WATCHDOG -mcpu=cortex-m3 -mthumb -fdata-sections -ffunction-sections

LD_FLAGS = -nostartfiles -static -T link.ld -M --gc-sections

LD_DIR += -L SimpleMAC/Binary

LIB = -lc -lgcc -simplemac-library

I compile:
Application files:
Files STM32W108xx_StdPeriph_Driver
Common files of evaluation boards
Files MB851 RevD
I also compile HAL files:

When I compile i don´t have errors but when linked this error appears:

   arm-none-eabi-ld: bad -rpath option
   make: *** [talk.axf] Error 1

What am I doing wrong in the examples that use the library SimpleMAC comparing with basicexamples?

Best Regards,


PD: Sorry my English is very bad, I use google translate