Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ryanparanich

macrumors newbie
Original poster
Jul 21, 2010
7
0
Can't say
I'm an electronics engineering student. One of our courses is basic C programming for microcontrollers.

For the quick and important chunk, check out the bottom, the middle here is going to be all descriptive content, in case there is something there that can help you help me.


I'm currently running a iMac, 27", i7, 8GB RAM, 2TB HD, etc etc. Probably doesn't help...

Our board is the MSP430FG4618, made by Texas Instruments. (if that helps) See some info here.

I'm programming in ANSI C, and currently (at school on the PC) using a 9 pin serial connection to run output back to the computer. It has I/O through USB connection, I don't know why we don't use output through the USB, but that's just the way it is...

We're using hyper terminal to display text and instructions, and get input. Our instructor created his own stdio library variation. Honestly, if you have suggestions on how I can just make it simpler, I'm all ears. we use xprintf() instead of printf(), I don't care which way I type things in, so long as it's ansi c and it runs.


Basically, I need to program in ANSI C, compile and run it, and I need some kind of terminal window where I can see the text that the program outputs, and enter input that the program will then accept and process. Simple right?

Your help is truly appreciated. It may make the difference between me passing or failing... So I really really appreciate it.
 
Last edited:
The Terminal app is in your Mac's /Applications/Utilities folder. Install the free optional Developer Tools or Xcode download from developer.apple.com, and you will have an ANSI C compiler that you can run from the Terminal command-line.
 
I might suggest wrapping his non-ANSI (somewhat ironic) calls around the standard one for testing and fallback.

Code:
if (xprintf != NULL) {
     xprintf("something");
} else {
     printf("something");
}
 
I don't understand, is this C code supposed to run on the microcontroller board? If so, you can't use the C compiler that comes with the Developer Tools. You'll have to install an MSP430 toolchain, like MSPGCC. (http://mspgcc.sourceforge.net/)

jared_kipe, your code will fail to link if xprintf() is not defined. You'd have to use preprocessor macros.
 
jared_kipe, your code will fail to link if xprintf() is not defined. You'd have to use preprocessor macros.

You would need to declare the function as extern, possibly in a header you only include through preprocessor macros, the compiler will fill unlinked addresses with NULL.

This is straight from apple's developer page. I suppose maybe apple provides some magic to make it work, but since it is for C functions it can't be that impressive on the back end.

To determine if a weakly linked C function is available, use the fact that the linker sets the address of unavailable functions to NULL. Check a function’s address—and hence, its availability—by comparing the address to NULL or nil. For example, before using the CGColorCreateGenericCMYK function in a project whose deployment target is earlier than Mac OS X v10.5, use code like the following:

Listing 3-2 Checking the availability of a C function
if (CGColorCreateGenericCMYK != NULL) {
CGColorCreateGenericCMYK (0.1,0.5.0.0,1.0,0.1);
} else {
// Function is not available.
// Alternate code to create a color object with earlier technology
}
Note: To check the availability of a function, explicitly compare its address to NULL or nil. You cannot use the negation operator ( ! ) to negate the address of a function to check its availability. Also, note that the name of a C function is synonymous with its address. That is, &myFunction is equivalent to myFunction.
 
Install MacPorts and install minicom from there. That will act as a terminal program. With it, you can interact with a serial port like you can in Hyperterminal.
 
To determine if a weakly linked C function is available, use the fact that the linker sets the address of unavailable functions to NULL.

Interesting. I vaguely remember hearing that, the linker on OS X does lots of magic and I'm not sure how much of it is cross-platform. Usually, instead of checking for the availability of individual functions, you check for a platform-specific define (__GNUC__, __APPLE__, etc.), but I'm not sure this suffices for all cases.

You might not need to install minicom: Mac OS X comes with screen, which can be used to connect to a serial device like this:
Code:
screen /dev/cu.usbserial 38400
where /dev/cu.usbserial is your serial port device and 38400 is the baud rate. To exit, press Control-a followed by Control-\. As far as I can tell it doesn't allow your to set any of the other serial parameters (parity, stop bits, etc.), though.
 
I'm from Edmonton, cool.

I have a 24" iMac and develop for the Freescale HCS12.
Maybe not what you want to hear, but I run Parallels with windows XP.
I use Hyper Terminal too.
There's not a lot of support for embedded development on the Mac.

If you do this, I recommend 8 G of memory.
 
I'm from Edmonton, cool.

I have a 24" iMac and develop for the Freescale HCS12.
Maybe not what you want to hear, but I run Parallels with windows XP.
I use Hyper Terminal too.
There's not a lot of support for embedded development on the Mac.

If you do this, I recommend 8 G of memory.

+1 to this except replace Parallels with VirtualBox. I've honestly found it to be superior to Parallels in many ways and it's free!
 
The USB line is probably just used to flash the microcontroller, whereas the 9-pin serial connection is allowing you to interact directly with the MSP430's UART. Something like minicom would help, but you still need to find a way to convert the serial data to USB. An FTDI serial to USB module might help.

In terms of compiling, you can't just use gcc from Xcode to compile executables for the MSP430, as it is only configured to generate binary code for the Intel x86 architecture. You will need something like MSPGCC, which may or may not run on OS X (I haven't tried it before), and it may not support the exact variant of MSP430 you have.

Honestly it would be easier to use something like VirtualBox and use the TI software, as others have suggested. Even then you may need to use the FTDI module to send and receive to the MSP430 UART. TI's Mac support is severely lacking, despite customers complaining to them about it for years.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.