Getting started with ColdFire's C language

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Getting started with ColdFire's C language

3,058 Views
E_Dattilo
Contributor I
Hi all,
i'm a new ColdFire user. I've already use other microprocessors and i know C and asm languages. I use M52235EVB, the PCF52235's evaluation board and CodeWarrior IDE.
What i'm looking for is documentation about the specific C functions/macros/defines for this processor. I've seen that some examples code use:
MCF_UART1_UIMR, MCF_GPIO_DDRGP, ...
I'd like to know all this constant and how to use them. For example, if i want to use Uart and Capture modules, or Interrupt, where can i find documentation that explain me how to do that?

Thank you for you time,
Erik Dattilo
Labels (1)
0 Kudos
7 Replies

634 Views
SimonMarsden_de
Contributor II
Hi Erik

The CodeWarrior macros are at a very low level. They're mainly just definitions of the bits in the MCF52235's peripheral registers.

What you need to look at is the MCF52235 Reference Manual, which is a PDF file available for download from Freescale's web site (on the MCF52235 page).

In it, you will find a complete description of the programming model for the processor, including sections on the GPIO, UARTs, etc. You should then be able to compare the register descriptions to CodeWarrior's macros.

You might also find it useful to look at a free tool called CFInit from MicroAPL. It's a graphical tool which helps you to write initialisation code for ColdFire processors. It won't give you everything you need because it's only intended for initialisation code (So, for example, it will show you how to set up a UART at 9600 baud and 1 stop bit, but not how to send and receive data). Hopefully you can relate the CodeWarrior C code which it produces to the Reference Manual and figure out the rest.

The URL is:

http://www.microapl.co.uk/CFInit/cfinit_main.html
0 Kudos

634 Views
E_Dattilo
Contributor I
Hi Simon,
Thank you very much for you explanations. I started to do in the way you said and i was able to make something work.
Now, my problem is: how can i use interrupt in codewarrior?
I'm able to set them via registers settings, but i don't know how to declare (and use) and interrupt routine. I've seen there is something in some .s assembler files (for example ".extern _timer_handler" in mcf52235_vectors.s) and i tried to use it:
__interrupt__ void timer_handler() {
...
}
but it still seems to me it doesn't work
0 Kudos

634 Views
SimonMarsden_de
Contributor II
Hi Erik

Briefly, you need to carry out a number of steps:

(1) Enable the interrupt in the individual module (e.g. for the PIT you need to set the PCSRn[PIE] bit)

(2) Configure the corresponding ICRn register in the Interrupt Controller to assign the interrupt a level, and to enable it. (Each source of interrupt like a PIT, UART, etc, is mapped to a unique ICRn).

(3) Make sure the interrupt is unmasked by clearing the appropriate bit in the Interrupt Controller's IMRH/IMRL global mask.

(4) Make sure that the appropriate entry in the exception vector table points to your interrupt handler code. In CodeWarrior this is usually done in an assembler file called 'vectors.s' or similar. You also need to make sure that the Vector Base Register (VBR) points to the table, but the CodeWarrior stationery should have done this for you.

(5) Declare the interrupt handler in a C file:

__interrupt__ void my_handler(void)
{
...code here
}


Hope this helps. If you look at a sample CodeWarrior project you'll find some useful guidance.


Cheers


Simon
0 Kudos

634 Views
SimonMarsden_de
Contributor II
Sorry, one other thing you need to do...

(6) Set the interrupt fence in the processor's Status Register (SR) so that it doesn't mask out interrupts of the level which you programmed into the ICR in step (2)


Simon
0 Kudos

634 Views
josh_outerspace
Contributor I
I am trying to do this interrupt and followed all steps, but when I compile I get

"unknown identifier" error from vectors.s

I named my interrupt function with the same identifier that I put in vectors.s
0 Kudos

634 Views
E_Dattilo
Contributor I
Maybe you have forgot to declare the function as "extern"?
In the vectors.s file you need to place a string like:
.extern MyFunction
where MyFunction is the name of your function.
If you look at some sample vector.s file you can see that a function is "recalled" in more place: we say that your function is timer_handler(), in vector.s you'll have:

#define _timer_handler timer_handler
.extern _timer_handler
vector77: .long _timer_handler

And in your .c file (int_handlers.c for example):
__interrupt__ void timer_handler (void) {
MCF_PIT0_PMR |= MCF_PIT_PCSR_PIF;
}

Hope this is helpfull,
Erik Dattilo
0 Kudos

634 Views
E_Dattilo
Contributor I
I'm still thank you to you Simon,
now it works
0 Kudos