ATSAM4LC2CA port definition

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

I am using the Atmel Studio to program an ATSAM4LC2CA controller and needs to read/write an entire port.

I have tried to use GPIOA, PORTA, IOPORT_PORTA and a lot of other names that are used in the documentation.

No matter what I do I get 'IOPORT_PORTA' undeclared (first use in this function).

 

How do I access a Port in Atmel studio and were should the port be defined?

 

Regards,

Morten

 

This topic has a solution.
Last Edited: Thu. Mar 24, 2022 - 07:35 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

(oops.  Edited post follows)

Last Edited: Thu. Mar 24, 2022 - 12:16 AM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Would you believe "GPIO[0].GPIO_PORT->..."

 

Eg, to set bit 10 of Port "A":

 

GPIO[0].GPIO_PORT->GPIO_OVRS = 1<<10;

Or it might be:

	GPIO->reg.GPIO_PORT[0].reg.GPIO_OVRS = 1<<10;

depending on Pack version.  Or something.

(The first one compiled when added to a SAM4L example program.  The second version compiled when put in a "new" SAM4L Studio7 project using (presumably) the latest packs.  (I didn't actually check for the correctness of either version.)
I believe it'll be yet different if you use MPLABX  (Hmm.  maybe not;  I don't see SAM4L support for MPLABX...))

 

You want to start looking in C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\SAM4L_DFP\1.1.61\sam4l4\include\sam4lc2c.h , where there is:

#define GPIO              ((Gpio     *)0x400E1000UL) /**< \brief (GPIO) APB Base Address */

and then successive "goto implementation" will take you to

C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\SAM4L_DFP\1.1.61\sam4l4\include\component\gpio.h

 

and then just experiment till it compiles :-(

 

There is also ...\instance\gpio.h, which has defines for individual registers, like:

#define REG_GPIO_OVRS0             (*(WoReg  *)0x400E1054UL) /**< \brief (GPIO) Output Value Register - Set 0 */

May be easier to understand, but less efficient and less compatible with "modern thinking."

 

(no, I don't understand why the datasheet still talks about PORTA/B/C but they're nowhere defined in the .h files.  And I surely don't understand why they seem to have a compulsion to keep changing things.  At a guess, Atmel got overly trusting in their XML->.h file converter, and never checked very carefully for consistency.  Sigh.  Don't you know you're just supposed to use ASF?  (Grr))

 

BTW, something like "GPIO->reg.GPIO_PORT[0].reg.GPIO_OVRS" all evaluates at compile time, so it's not as bad as it looks.

	GPIO->reg.GPIO_PORT[0].reg.GPIO_OVRS = 1<<10;
 262:	4b02      	ldr	r3, [pc, #8]	; (26c <main+0x10>)
 264:	f44f 6280 	mov.w	r2, #1024	; 0x400
 268:	655a      	str	r2, [r3, #84]	; 0x54
 26a:	e7fe      	b.n	26a <main+0xe>  ; infinite loop when main() returns
 26c:	400e1000 	.word	0x400e1000

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you very much westfw.

 

I finally found

#define IOPORT_GPIOC     2

in the ioport_gpio.h file

 

Good to hear that I am not the only one not able to find PORTA/B/C definitions :-)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I finally found

#define IOPORT_GPIOC     2

Probably for use like:

GPIO->reg.GPIO_PORT[IOPORT_GPIOC].reg.GPIO_OVRS ...