1

Sorry for my bad English. I have an Ubuntu on my PC, which I use to program my STM32L-DISCOVERY. Well, program successfully compiles, but I have an error while link the application. I am newbie in development for such devices. So, I use Eclipse as IDE, and Code Sourcery instruments. I compile program using command arm-none-linux-gnueabi-gcc to compile with that flags:

-DSTM32L1XX_MD -DUSE_STDPERIPH_DRIVER -I/usr/CodeSourcery/Libraries/CMSIS/Include -I/usr
/CodeSourcery/Libraries/STMTouch_Driver/inc -I/usr/CodeSourcery/Libraries
/STMTouch_Driver/src -I/usr/CodeSourcery/Libraries/CMSIS/Device/ST/STM32L1xx/Include
-I/usr/CodeSourcery/Libraries/STM32L1xx_StdPeriph_Driver/inc -I/usr/CodeSourcery /Libraries
/STM32L1xx_StdPeriph_Driver/src -O2 -ffunction-sections -fdata-sections -Wall
-Wa,-adhlns="$@.lst" -c -fmessage-length=0 -march=armv7-m -mcpu=cortex-m3 -mthumb -g3
-gdwarf-2

and I am using the same command to link with that flags:

-T"/home/luka/workspace/stm32ld_template/stm32l152rb.ld" -nostartfiles -Xlinker
--gc-sections -Wl,-Map,stm32ld_template.map -march=armv7-m -mcpu=cortex-m3 
-mthumb -g3 -gdwarf-2

Well, after execution with the last command it gives me such errors:

error: /usr/CodeSourcery/Sourcery_CodeBench_Lite_for_ARM_GNU_Linux/bin/../arm-none-linux-gnueabi/libc/thumb2/lib/ld-linux.so.3: Conflicting architecture profiles A/M stm32ld_template C/C++ Problem error: /usr/CodeSourcery/Sourcery_CodeBench_Lite_for_ARM_GNU_Linux/bin/../arm-none-linux-gnueabi/libc/thumb2/lib/libc.so.6: Conflicting architecture profiles A/M stm32ld_template C/C++ Problem error: /usr/CodeSourcery/Sourcery_CodeBench_Lite_for_ARM_GNU_Linux/bin/../arm-none-linux-gnueabi/libc/thumb2/lib/libgcc_s.so.1: Conflicting architecture profiles A/M stm32ld_template C/C++ Problem

When I remove the flag -mthumb in link command, there are no errors. But, when i try to debug the program it terminates with Function main not defined. I also use st-util for debugging, and when I try to debug,it shows me this:

recv: qSupported:multiprocess+;qRelocInsn+
query: Supported;multiprocess+;qRelocInsn+
send: PacketSize=3fff;qXfer:memory-map:read+
recv: !
send: OK
recv: Hg0
send: 
recv: ?
send: S05
recv: Hc-1
send: 
recv: qC
send: 
recv: qAttached
query: Attached;
send: 
recv: g
send: 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002c6c6962ffffffff2e6c642d
recv: qXfer:memory-map:read::0,fff
query: Xfer;memory-map:read::0,fff
Xfer: type:memory-map;op:read;annex:;addr:0;length:4095
send: m<?xml version="1.0"?><!DOCTYPE memory-map PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"     "http://sourceware.org/gdb/gdb-memory-map.dtd"><memory-map>  <memory type="rom" start="0x00000000" length="0x10000"/>  <memory type="ram" start="0x20000000" length="0x4000"/>  <memory type="flash" start="0x08000000" length="0x10000">    <property name="blocksize">0x100</property>  </memory>  <memory type="ram" start="0x40000000" length="0x1fffffff"/>  <memory type="ram" start="0xe0000000" length="0x1fffffff"/>  <memory type="rom" start="0x1ff00000" length="0x1000"/>  <memory type="rom" start="0x1ffff800" length="0x8"/></memory-map>
recv: qXfer:memory-map:read::27c,d83
query: Xfer;memory-map:read::27c,d83
Xfer: type:memory-map;op:read;annex:;addr:636;length:3459
send: l
recv: qTStatus
query: TStatus;
send: 
recv: X20000000,0:
send: 
recv: M20000000,70:0100000001000000010000000f0000000400000030000008050000001400000806000000140000080a000000190000000b000000100000001500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
send: OK
recv: M20000070,c:000000200000000000000000
send: OK
recv: vFlashErase:08000000,00000100
FlashErase: addr:08000000,len:0100
send: OK
recv: vFlashWrite:8000000:/lib/ld-linux.so.3
binary packet 19 -> 20
send: OK
recv: vFlashWrite:8000014:
binary packet 25 -> 26
send: OK
recv: vFlashWrite:8000030:
binary packet 12 -> 12
send: OK
recv: vFlashDone
flash_do: block 08000000 -> 0100
flash_do: page 08000000
2013-09-27T18:23:14 INFO src/stlink-common.c: Attempting to write 256 (0x100) bytes to stm32 address: 134217728 (0x8000000)
Flash page at addr: 0x08000000 erased
2013-09-27T18:23:14 INFO src/stlink-common.c: Finished erasing 1 pages of 256 (0x100) bytes
2013-09-27T18:23:14 INFO src/stlink-common.c: Starting Half page flash write for STM32L core id
2013-09-27T18:23:14 INFO src/stlink-common.c: Successfully loaded flash loader in sram

2013-09-27T18:23:14 INFO src/stlink-common.c: Starting verification of write complete
2013-09-27T18:23:14 INFO src/stlink-common.c: Flash written and verified! jolly good!
send: OK
recv: Pf=00000008
send: OK
recv: p19
send: 00000001
recv: qTStatus
query: TStatus;
send: 
recv: qTStatus
query: TStatus;
send: 
recv: qTStatus
query: TStatus;
send: 
recv: qTStatus
query: TStatus;
send: 
recv: qfThreadInfo
query: fThreadInfo;
send: 
recv: qL1200000000000000000
send: 
recv: qTStatus
query: TStatus;
send: 
recv: qTStatus
query: TStatus;
send: 
recv: qTStatus
query: TStatus;
send: 
recv: qTStatus
query: TStatus;
send: 
recv: qSymbol::
query: Symbol;:
send: 
recv: g
send: 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002c6c6962ffffffff00000008
recv: qL1200000000000000000
send: 
recv: m8000000,4
send: 2f6c6962
recv: m8000000,4
send: 2f6c6962
recv: m8000000,4
send: 2f6c6962
recv: m8000000,4
send: 2f6c6962
recv: m8000000,4
send: 2f6c6962
recv: m8000000,4
send: 2f6c6962
recv: m8000000,4
send: 2f6c6962
recv: p19
send: 00000001
recv: qTStatus
query: TStatus;
send: 
recv: qTStatus
query: TStatus;
send: 
recv: vKill;a410
send: OK
recv: ?
send: OK
recv: vRun;
send: 
recv: R0
KARL - should read back as 0x03, not 60 02 00 00
init watchpoints
send: OK
cannot recv: -2
closing connection
KARL - should read back as 0x03, not 60 02 00 00
init watchpoints
Listening at *:4242...
GDB connected.
recv: qSupported:multiprocess+;qRelocInsn+
query: Supported;multiprocess+;qRelocInsn+
send: PacketSize=3fff;qXfer:memory-map:read+
recv: !
send: OK
recv: Hg0
send: 
recv: ?
send: S05
recv: Hc-1
send: 
recv: qC
send: 
recv: qAttached
query: Attached;
send: 
recv: g
send: 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002c6c6962ffffffff2e6c642d
recv: qXfer:memory-map:read::0,fff
query: Xfer;memory-map:read::0,fff
Xfer: type:memory-map;op:read;annex:;addr:0;length:4095
send: m<?xml version="1.0"?><!DOCTYPE memory-map PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"     "http://sourceware.org/gdb/gdb-memory-map.dtd"><memory-map>  <memory type="rom" start="0x00000000" length="0x10000"/>  <memory type="ram" start="0x20000000" length="0x4000"/>  <memory type="flash" start="0x08000000" length="0x10000">    <property name="blocksize">0x100</property>  </memory>  <memory type="ram" start="0x40000000" length="0x1fffffff"/>  <memory type="ram" start="0xe0000000" length="0x1fffffff"/>  <memory type="rom" start="0x1ff00000" length="0x1000"/>  <memory type="rom" start="0x1ffff800" length="0x8"/></memory-map>
recv: qXfer:memory-map:read::27c,d83
query: Xfer;memory-map:read::27c,d83
Xfer: type:memory-map;op:read;annex:;addr:636;length:3459
send: l
recv: qTStatus
query: TStatus;
send: 
recv: X20000000,0:
send: 
recv: M20000000,70:0100000001000000010000000f0000000400000030000008050000001400000806000000140000080a000000190000000b000000100000001500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
send: OK
recv: M20000070,c:000000200000000000000000
send: OK
recv: vFlashErase:08000000,00000100
FlashErase: addr:08000000,len:0100
send: OK
recv: vFlashWrite:8000000:/lib/ld-linux.so.3
binary packet 19 -> 20
send: OK
recv: vFlashWrite:8000014:
binary packet 25 -> 26
send: OK
recv: vFlashWrite:8000030:
binary packet 12 -> 12
send: OK
recv: vFlashDone
flash_do: block 08000000 -> 0100
flash_do: page 08000000
2013-09-27T18:23:59 INFO src/stlink-common.c: Attempting to write 256 (0x100) bytes to stm32 address: 134217728 (0x8000000)
Flash page at addr: 0x08000000 erased
2013-09-27T18:23:59 INFO src/stlink-common.c: Finished erasing 1 pages of 256 (0x100) bytes
2013-09-27T18:23:59 INFO src/stlink-common.c: Starting Half page flash write for STM32L core id
2013-09-27T18:23:59 INFO src/stlink-common.c: Successfully loaded flash loader in sram

2013-09-27T18:23:59 INFO src/stlink-common.c: Starting verification of write complete
2013-09-27T18:23:59 INFO src/stlink-common.c: Flash written and verified! jolly good!
send: OK
recv: Pf=00000008
send: OK
recv: p19
send: 00000001
recv: qTStatus
query: TStatus;
send: 
recv: qTStatus
query: TStatus;
send: 
recv: qTStatus
query: TStatus;
send: 
recv: qTStatus
query: TStatus;
send: 
recv: qfThreadInfo
query: fThreadInfo;
send: 
recv: qL1200000000000000000
send: 
recv: qTStatus
query: TStatus;
send: 
recv: qTStatus
query: TStatus;
send: 
recv: qTStatus
query: TStatus;
send: 
recv: qTStatus
query: TStatus;
send: 
recv: qSymbol::
query: Symbol;:
send: 
recv: g
send: 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002c6c6962ffffffff00000008
recv: qL1200000000000000000
send: 
recv: m8000000,4
send: 2f6c6962
recv: m8000000,4
send: 2f6c6962
recv: m8000000,4
send: 2f6c6962
recv: m8000000,4
send: 2f6c6962
recv: m8000000,4
send: 2f6c6962
recv: m8000000,4
send: 2f6c6962
recv: m8000000,4
send: 2f6c6962
recv: p19
send: 00000001
recv: qTStatus
query: TStatus;
send: 
recv: qTStatus
query: TStatus;
send: 
recv: vKill;a410
send: OK
recv: ?
send: OK
recv: vRun;
send: 
recv: R0
KARL - should read back as 0x03, not 60 02 00 00
init watchpoints
send: OK
cannot recv: -2
closing connection
KARL - should read back as 0x03, not 60 02 00 00
init watchpoints
Listening at *:4242...

And my main.c:

#include <stm32l1xx.h>

#include <stm32l1xx_rcc.h>
#include <stm32l1xx_gpio.h>

int main()
{

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM9, ENABLE);


  GPIO_InitTypeDef gpio;
  gpio.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9;
  gpio.GPIO_Speed = GPIO_Speed_2MHz;


  GPIO_Init(GPIOC, &gpio);

  GPIO_SetBits(GPIOC, GPIO_Pin_8 | GPIO_Pin_9);

  do __NOP(); while (1);
}

What I am doing wrong? I thank anybody, who helps me.

EDIT1:

I've added -nodefaultlibs to the link command, so it links well now. But debug still not working.

ams
  • 24,923
  • 4
  • 54
  • 75
user2574232
  • 21
  • 1
  • 6
  • 1
    you have to use the -mthumb, the cortex-m is thumb only. Your problem looks to be with the libraries you are linking in. you arent running linux so why is ld-linux.so even mentioned by the compiler? likewise libc.so? you cant link runtime libraries they have to be static if anything, and you have to be very careful with libc since you dont have an operating system. – old_timer Sep 27 '13 at 18:19
  • Really, I don't know why it want it. I just want to work with it. So, what can I do to "unlink" libraries? – user2574232 Sep 27 '13 at 18:49
  • github.com/dwelch67 has some bare metal examples using gnu tools (code sourcery, etc) – old_timer Sep 27 '13 at 19:26
  • I add -nodefaultlibs for the linker, now it links well. But still can't debug the application. – user2574232 Sep 27 '13 at 19:28
  • I cant help you with that I dont use gdb or anything like that. – old_timer Sep 27 '13 at 19:33

1 Answers1

0

I think you have the wrong toolchain.

You're using the ARM Linux toolchain, but I think you might want the "ARM EABI" toolchain. That will do the right thing with -mcpu=cortex-m3 -mthumb.

ams
  • 24,923
  • 4
  • 54
  • 75