Jump to content
Sign in to follow this  
smiffy

msp430-gcc: delay loops optimised out

Recommended Posts

Is there a preferred method of preventing delay loops from being optimised out? (I'm not using timers as I am trying to do some very basic testing without involving peripherals.)

 

A loop like this seems to have no effect at all, so I am assuming it is getting culled in the optimisation process:

/* This is ignored. */
unsigned int i=0;

for (i=0; i<65535; i++)
{
 ;
}

 

At the moment, I'm actually getting it to read the value of a port to keep the loop in there:

/* This works. */
unsigned int i=0;
unsigned char c=0;

for (i=0; i<65535; i++)
{
  c=P1IN;
}

 

Whilst this works, is there a preferred/best practice way of stopping a particular piece of code from being optimised?

Share this post


Link to post
Share on other sites

*slaps forehead* Thank you. It hadn't occurred to me to make the loop variable volatile! Now I feel stoopid. Especially since the variable c to which I was assigning the input value WAS declared as volatile in my test code.

 

I'll probably employ the __delay_cycles() when I've finished this stage of testing - I'll also have a look through the libc docs for any other goodies, although trying to avoid using too much non-standard stuff.

 

I'm actually trying to put together a little library of portable code so I can test on a couple of other families, hence why I'm sticking to simple loops. Which will now have i and j always declared as volatile. (This project started out on AVR, but has been switched to MSP430 since I didn't really want to have to build a power station to run the thing :-P

Share this post


Link to post
Share on other sites

Houston, we have a problem...

 

I just substituted __delay_cycles() in my code, to see if it would work. (I'm running a 1.8432MHz crystal, wanted to see if __delay_cyles(1843200) would give me a true 1s on/1s off on the test LED.)

 

However, I was told:

main.c:3:19: error: inmsp.h: No such file or directory

 

I'm using the msp4gcc referred to in http://hackaday.com/2010/08/11/how-to-launchpad-programming-with-linux/..

 

Is this known to have a broken libc? Sufficient to say, I have added:

#include 

...to my code, per the documentation for __delay_cycles() at http://www.rowley.co.uk/documentation/html/msp430_libc_delay_cycles.htm

Share this post


Link to post
Share on other sites

Assuming you are using Uniarch (you are, right? :)), you only need to include msp430.h. That, in turn, will include everything needed from the compiler side (so this does not apply to libc stuff, obviously).

 

__delay_cycles() in Uniarch needs no extra headers anyway, it's hardwired into the compiler itself.

 

The header with the intrinsic definitions is in430.h, but again, you don't reference it directly (don't let it stop you from peeking in it, though).

Share this post


Link to post
Share on other sites

I'm not using Uniarch; in fact, I hadn't heard of it until you mentioned it as I've just been working from information gleaned from the Hackaday article.

 

However, as I was groaning earlier at the prospect of having to build mspgcc myself to get over the shortcomings of what I have (like not supporting my target device, the MSP430AFE253), I will be getting my hands on that before I go any further.

 

Thanks for setting me on the True Path :-)

 

Er, any pointers on where to get it? The only sense I'm getting out of Google is http://sourceforge.net/projects/mspgcc/ - is that what I should be looking for? (Doesn't mention the term 'Uniarch' except as 'Group: uniarch mspgcc.')

Share this post


Link to post
Share on other sites

Quickstart: viewtopic.php?f=5&t=1402#p9193. I am standing by my earlier opinion that if your OS has Uniarch packages, use those, if it doesn't, poke the vendor to have them. In the meantime, you can use the script attached there (check for patches that might have appeared since), or a number of other Uniarch build scripts/instructions floating around even in this forum.

 

There's a SF wiki page too for a bit of a background information and whatnot.

Share this post


Link to post
Share on other sites

Thanks, Gordon. Unfortunately, I don't have a separate dev machine for this and therefore have to use the (stable) distro that is running on all my/my clients servers - Debian Lenny. Other than the LAMP stack, packages are mostly OLD, if they are there at all.

 

Don't fancy hand-crafting gcc - I've had my days of doing that stuff and stopped when I ditched Gentoo because I actually wanted to get work done rather than just sitting here maintaining my OS - but build scripts sound like the optimal solution for me.

 

So, yeah, sounds like a good compromise. I really was dreading having to do it all from scratch, but I used to use build scripts a lot in my DIY days, so am more than happy to pursue that route. (I really don't want to put too much effort into getting tools working, as I'm trying to do parallel evaluation on AVR [where low power no issue,] HCS08 as well as MSP430. My ultimate aim is to standardise on 2 platforms - but MSP430 is here to stay as a) it's the only 16-bit one I'm looking at and B) I just plain like TI's attitude, especially when it comes to putting out stuff like LaunchPad, Chronos, etc.)

 

Your input is much appreciated, Gordon, I'd vote you a very large beer, only PHPBB won't let me ;)

Share this post


Link to post
Share on other sites

AFAICT Lenny is only short with MPC, but while there you could as well build a newer GMP and MPFR too (needed for building GCC). These aren't supposed to be much trouble to install from sources (or maybe even backports exist, I don't know).

 

Otherwise, Lenny should be quite OK.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...