cancel
Showing results for 
Search instead for 
Did you mean: 

Getting Started, MCU plays dead ?

Posted on March 05, 2012 at 03:33

Hello, I am trying to get started with STM32 microcontrollers. I have a STM32F103RBT6 on a development board and I am using the gcc toolchain (target arm-elf, flags -s -Os -mthumb -mcpu=cortex-m3).

The sample code I am using toggles 2 IO pins as fast as possible, it compiles fine. However when compiled (and optimized for size) the output is quite large (about 50k), after the elf is converted to binary its still around 50k in size and is mostly empty space (zeros). When I flash the MCU with the program it does not seem to execute it (IO pins are still in the same states). I have the IO port thats being toggled enabled in code. I'm not sure what I am doing wrong (program, compiler, etc), any help would be appreciated.

My code can be found

https://docs.google.com/open?id=0BwP0qhqyaTIIcktzWVcxS0JRNEM0Z1BhS0tlT0pyZw

(in google docs)
6 REPLIES 6
Posted on March 05, 2012 at 04:08

The ELF file is an object file, what you need is a binary or hex file.

You could use objcopy to achieve that, and perhaps reflect on your linker script.

https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/DispForm.aspx?ID=12211

https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32VLDiscovery/Flat.aspx?RootFolder=https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32VLDiscovery/Exporting flash files from atollic&FolderCTID=0x01200200770978C69A1141439FE559EB459D758000491D59B8574F8049B5DFA3E8B21CBA51&currentviews=965

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on March 05, 2012 at 12:40

I am already doing that, any other suggestions ?

Just on a sidenote, I don't have any extra scripts for linking set up. Should I have one ?

Posted on March 05, 2012 at 13:55

I am already doing that, any other suggestions ? Just on a sidenote, I don't have any extra scripts for linking set up. Should I have one ?

You'll need some scripting for the linker so that it places the vectors, code and stack at the correct addresses.

The code should be placed at 0x08000000, and should be relatively small, certainly smaller than you are talking about.

You could use objdump to disassemble the code, or use a JTAG debugger, to understand if the generated code is viable.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on March 24, 2012 at 16:59


/*STM32F103 Program Linker Script*/

MEMORY

{

ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K

rom (rx) : ORIGIN = 0x00000000, LENGTH = 128K

}

SECTIONS

{

. = 0x0; 
/* From 0x00000000 */

.text : {

*(vectors) 
/* Vector table */

} >rom


. = 0x08000000;

.text : {

*(.text) 
/* Program code */

*(.rodata) 
/* Read only data */

} >rom


. = 0x20000000; 
/* From 0x20000000 */

.data : {

*(.data) 
/* Data memory */

} >ram AT > rom 


.bss : {

*(.bss) 
/* Zero-filled run time allocate data memory */

} >ram AT > rom 

} 

/*========== end of file ==========*/

my linker script is above, is it correct ? the output (50kb) is stripped down to a binary program using objcopy. I then program my MCU through the serial bootloader, the program (now 2kb) gets copied to 0x8000000 . What else needs to happen to make it work ?
thebooney
Associate II
Posted on April 03, 2012 at 22:16

Why are you putting your vector table at 0x00000000 but then putting everything else starting at 0x08000000. The vector table should be at 0x08000000

Posted on April 04, 2012 at 01:02

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6ao&d=%2Fa%2F0X0000000brK%2FCwW3XZPcTCZzN_gpDrjwaze2pKTY8LXyCCKe2XOmhq8&asPdf=false
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..