GPIO mix-up in Flowcode v4 for ARM?

Moderator: Benj

Post Reply
User avatar
PPerreijn
Flowcode V4 User
Posts: 7
Joined: Tue Mar 30, 2010 3:15 pm
Location: Heerlen, The Netherlands
Contact:

GPIO mix-up in Flowcode v4 for ARM?

Post by PPerreijn »

Hi everybody,

Recently I built a custom device with an AT91SAM7S64-microcontroller from Atmel. The schematic is based on an evaluation-kit from Olimex, this one, to be precise: http://www.olimex.com/dev/pdf/ARM/ATMEL ... -REV-E.pdf.
Alas, the AT91SAM7S64 is insanely difficult to get; it's more or less sold out everywhere, even at big distributors like Farnell, RS and Mouser. Luckily the AT91SAM7S321 is pin- and function-compatible (less memory, but that's ok) and in stock. So I used that MCU instead.
Tried to program it with a simple blink-a-led for a led on pin 9 (PA17, D0 in Flowcode), with my new copy of Flowcode 4. This didn't work, checked my soldering and replaced the MCU. Again, nothing, not even on the second PCB I built. :evil:
So, that's when I decided to check all the pins with a scope and lots of wires. Here's what I found out:
  • Toggle pin C1 and you'll actually toggle pin D0
  • Toggle pin C2 and you'll actually toggle pin D1
  • Toggle pin C3 and you'll actually toggle pin D2
  • Toggle pin C4 and you'll actually toggle pin D3
  • Toggle pin C5 and you'll actually toggle pin C7
  • Toggle pin D1 and you'll actually toggle pin C4
  • Toggle pin D2 and you'll actually toggle pin C1
  • Toggle pin D3 and you'll actually toggle pin D2
Because of the layout of my PCB, I couldn't test C0 and D4, but I suspect them to be mixed up as well.
I've tried different settings in Flowcode, even changed my project setting to AT91SAM7S64 to see if it had anything to do with the defines for the AT91SAM7S321... no effect.
There must be something wrong with the GPIO settings. Can somebody please look at this, since it's kind of frustrating to change all my pin settings. Thanks in advance for your help.

Regards,

Paul

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: GPIO mix-up in Flowcode v4 for ARM?

Post by Benj »

Hello Paul,

The pins are defined in the Board_Generic.h file that resides in the "Flowcode ARM V4/Tools/Global" directory.

You can edit this file to remap the I/O pins any way you like them.

Code: Select all

#define PORTA0 			( 1<<0 )
#define PORTA1			( 1<<1 )
#define PORTA2			( 1<<2 )
#define PORTA3			( 1<<3 )
#define PORTA4			( 1<<4 )
#define PORTA5			( 1<<5 )
#define PORTA6			( 1<<6 )
#define PORTA7			( 1<<7 )
Eg change the number after the (1<< to specify the RP pin number.

User avatar
PPerreijn
Flowcode V4 User
Posts: 7
Joined: Tue Mar 30, 2010 3:15 pm
Location: Heerlen, The Netherlands
Contact:

Re: GPIO mix-up in Flowcode v4 for ARM?

Post by PPerreijn »

Hello Ben,

Thanks for the reply. I've read the file you mentioned and now I know why everything was mixed up: the pin mapping was indeed all wrong.
I've corrected the errors and now it works as expected (but this should be fixed in the next release to avoid confusion for others).
As a note to others: if you want to make sure the pins shown in the little chip diagram in Flowcode correspond to the correct hardware pins, adjust the "ports definition" section in Board_Generic.h as follows:

Code: Select all

/*-----------------*/
/* Ports definition*/
/*-----------------*/

/* Based on Matrix */
/* ARM E-Block     */

#define PORTA0 			( 1<<0 )
#define PORTA1			( 1<<1 )
#define PORTA2			( 1<<2 )
#define PORTA3			( 1<<3 )
#define PORTA4			( 1<<4 )
#define PORTA5			( 1<<5 )
#define PORTA6			( 1<<6 )
#define PORTA7			( 1<<7 )

#define PORTA (PORTA0|PORTA1|PORTA2|PORTA3|PORTA4|PORTA5|PORTA6|PORTA7)

#define PORTB0			( 1<<8 )
#define PORTB1			( 1<<9 )
#define PORTB2			( 1<<10 )
#define PORTB3			( 1<<11 )
#define PORTB4			( 1<<12 )
#define PORTB5			( 1<<13 )
#define PORTB6			( 1<<14 )
#define PORTB7			( 1<<15 )

#define PORTB (PORTB0|PORTB1|PORTB2|PORTB3|PORTB4|PORTB5|PORTB6|PORTB7)

#define PORTC0			( 1<<24 )
#define PORTC1			( 1<<26 )
#define PORTC2			( 1<<27 )
#define PORTC3			( 1<<28 )
#define PORTC4			( 1<<25 )
#define PORTC5			( 1<<23 )
#define PORTC6			( 1<<22 )
#define PORTC7			( 1<<21 )

#define PORTC (PORTC0|PORTC1|PORTC2|PORTC3|PORTC4|PORTC5|PORTC6|PORTC7)

#define PORTD0			( 1<<17 )
#define PORTD1			( 1<<18 )
#define PORTD2			( 1<<19 )
#define PORTD3			( 1<<20 )
#define PORTD4			( 1<<16 )
#define PORTD5			( 1<<29 )
#define PORTD6			( 1<<30 )
#define PORTD7			( 1<<31 )

#define PORTD (PORTD0|PORTD1|PORTD2|PORTD3|PORTD4|PORTD5|PORTD6|PORTD7)
This should work for the models AT91SAM7S161, AT91SAM7S321, AT91SAM7S64, AT91SAM7S128, AT91SAM7S256 and AT91SAM7S512
It might not work for the AT91SAM7S16 and AT91SAM7S32 because of the different package. Check the data sheet.

Paul

Post Reply