cancel
Showing results for 
Search instead for 
Did you mean: 

The simplest things...

peterharrison9
Associate II
Posted on May 09, 2009 at 11:19

The simplest things...

5 REPLIES 5
peterharrison9
Associate II
Posted on May 17, 2011 at 13:11

Glutton for punishment that I am, I have been trying to build CodeSourcery tools on my iMac. The tools built OK in the end so I tried to put the simplest of programs into my STM32-SK board from IAR. It has a STM32F103RBT6 processor.

I used a simple bit of blinky code from fosstronics.com thus:

[code]

#define GPIOB_CRH (*((volatile unsigned long*)(0x40010c00 + 0x4)))

#define GPIOB_BSRR (*((volatile unsigned long*)(0x40010c00 + 0x10)))

#define RCC_APB2ENR (*((volatile unsigned long*)(0x40021000 + 0x018)))

__asm__(''.word 0x20001000'');

__asm__(''.word main'');

main()

{

unsigned int c = 0;

RCC_APB2ENR = (1 << 3);

GPIOB_CRH = 0x44444114;

while(1) {

GPIOB_BSRR = (1 << 10); // ON

for(c = 0; c < 100000; c++);

GPIOB_BSRR = (1 << 26); // OFF

for(c = 0; c < 100000; c++);

}

}

[/code]

it compiles just fine. I link it with this very simple linker script:

[code]

SECTIONS {

. = 0x0;

.text : {

*(.text)

}

}

[/code]

(sorry - lookslike BBcode is not allowed for some reason)

According to objdump, everything goes where it should. That is, the first couple of bytes contain the address of the stack in RAM and the next couple are the address of main().

I download the binary to the processor with a bootloader. I am happy that is putting stuff where it should and the code reads back from the chip just fine.

But - when I put he chip back into run mode, nothing happens after a reset or a power cycle. no light blink, nothing.

I had previously been playing with a crossconnect from Rowley. That no longer seems to work and cant talk to the board. Not sure if it is the crossconnect or the processor. The processor, presumably, works OK or the bootloader would fail.

I also have an Olimex STM32-P103 board that behave exactly the same way.

After a couple of hours trying variations of the same thing, I have had enough. I must be doing something wrong.

Is it possible to have put the processor into some state where it cannot run? Or have I just overlooked something obvious?

Does anyone have any other suggestions?

miles
Associate II
Posted on May 17, 2011 at 13:11

Tried this?

http://ccgi.rowley.co.uk/support/faq.php?do=article&articleid=52

[ This message was edited by: miles.gazic on 04-05-2009 22:02 ]

peterharrison9
Associate II
Posted on May 17, 2011 at 13:11

Sadly, yes 🙂

Not my favourite discovery in Crossworks.

In this case, there is no startup code. The labels at the start of the program should place the appropriate values directly into the binary image. As far as I can see from the disassembled image, they do.

Thanks anyway.

Pete

andreas2
Associate II
Posted on May 17, 2011 at 13:11

Which bootloader are you using? The built in? How are you putting it into ''run mode''? ''Go'' from the bootloader or system reset with boot pins reconfigured to run from flash?

Can you share the objdump -S of your image? Verify that the second word in flash (address to main()) has LSB set. If not, make sure you compile with -mthumb -mcpu=cortex-m3.

Flash starts at 0x08000000 so you should link it there instead of 0x0 (but it's aliased at 0x0 if the boot pins are set correctly so it shouldn't matter in your case).

peterharrison9
Associate II
Posted on May 17, 2011 at 13:11

I have just worked out what was wrong and I am not proud!

Turns out I was giving the bootloader the name of a hex file rather than the binary image. I had persuaded myself it could read hex files but it cant. Consequently, I was writing ASCII text into the processor. Clearly, that was not going to work. With a binary file, all is fine.

The bootloader is a python script. I wrote up a little bit about it here:

http://www.micromouseonline.com/blog/2009/05/07/stm32-arm-cortex-bootloader/

Thanks

Pete