Startup Code

12 Aug 2011

My code generates a waveform using timer 0 and timer 1 interrupts. This works fine as long as I toggle the output pin using the DigitalOut in the mbed library. If I switch to using GPIO directly this results in:

  • my code not using the mbed library at all
  • the bin size drops from around 10k to 2k
  • the waveform generation fails dismally (part of it is generated then it stops)

If my project does not use any of the mbed library is the same startup code still used, or is it left out because the library is not being used?

Andy

13 Aug 2011

The startup code should be the same no matter if you use the mbed library or not.

Is is possible that you introduced a bug into your code when you switched from using the library to using GPIO directly? If you share out the code which demonstrates the problem then maybe someone on the forum can help spot the potential cause of your problem.

13 Aug 2011

I recompiled my code without changes using Keil Realview (with the standard CM3 startup code and CMSIS). It works perfectly. This is without the mbed library of course. So I don't think it is my GPIO code...

Andy

13 Aug 2011

There could be differences between the startup code that you get with Keil RealView and the cloud compiler. This difference may then be taken care of by the DigitalOut class in the mbed library.

This GPIO based LED blinker code which doesn't use the mbed library works with the mbed compiler for me:

#include "LPC17xx.h"

volatile int g_LoopDummy;

int main() 
{
	LPC_GPIO1->FIODIR |= 1 << 18; // P1.18 connected to LED1
	while(1)
	{
		LPC_GPIO1->FIOPIN ^= 1 << 18; // Toggle P1.18
		for (int i = 0 ; i < 5000000 && !g_LoopDummy ; i++)
		{
		}
	}
	return 0;
}

The binary which results from this code is 1460 bytes in length.

14 Aug 2011

I think the GPIO works fine. What stops working when the mbed library is no longer included are my timer 0 and timer 1 interrupts.

Andy

14 Aug 2011

Hi Andy,

Make sure your interrupt handlers are defined:

extern "C" handlername() {}

Without extern C, you don't actually overwrite the default handlers (C++ name mangling means the names wouldn't match); behaviour would likely appear a hang after one interrupt, as default handler is effectively while(1).

Hope that helps,

Simon

14 Aug 2011

Thanks, yes, that is how they are defined. This code generates a repeating waveform - timer 1 triggers a new waveform generation every 18ms and timer 0 toggles the pin according to a look-up table for 10ms in each 18ms period. This works fine as long as I use DigitalOut for the pin. It doesn't work if the only change I make is to switch to GPIO and the mbed library is no longer used. I've confirmed the GPIO and interrupts work using the Keil startup code.

Andy