SAME70 - Confused about ports and GPIO

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

Hello!

 

I'm inexperienced with Atmel and embedded design in general.

 

I'm trying to write to a ILI9341 TFT screen using an 8-bit parallel interface. I'm using the pins on the J507 extension. I chose that because it seemed to have a lot of pins on a single port (A).

 

Can I use any pin as GPIO? Do I need to configure anything specific?

 

It seems like the screen wants to work. It responds to DISPLAY OFF and DISPLAY ON commands so I know the bus is mostly working. But it won't draw any actual color data to screen despite using the same code to draw as another microcontroller that I managed to get working with the display (but was too slow.)

 

I'm driving the gpio mostly with ioport ASF commands. Also using gpio commands to flip a single pin. I've tested all the signals with an external LED and they seem to work.

 

I have no idea what the issue is.

 

Here is the relevant drawing code.

 

        SetWriteFrame(0, 0, 320, 240); //Set the write frame to the entire screen.
	output_command(0x2C, 1); //Write memory.
	
	uint8_t c = 0; //8 bit color. Written twice to make a 16bit color.

	while (true) {
	
	uint32_t color = portmap[c]; //Set the IO lines because they aren't continuous
	ioport_set_port_level(0, color, IOPORT_PIN_LEVEL_HIGH);	
	
	for(int i = 0; i < 76800; i++) //320x240. Two toggles per pixel because 16bit color and only 8 bit bus
	{
		gpio_set_pin_high(PIN_WR);
		gpio_set_pin_low(PIN_WR);		
	        gpio_set_pin_high(PIN_WR);
		gpio_set_pin_low(PIN_WR);
	}	
	
	delay_ms(1);
	ioport_set_port_level(0, portmap[0xFF], IOPORT_PIN_LEVEL_LOW); //Clear 8 bit bus
	c++;
	}

 

Things I don't like:

 

No groups of pins logically laid out in order. It makes debugging a parallel bus a nightmare.

Pins and ports all over the place. Seemingly random.

 

^- Those could be just from my lack of experience. Maybe there is a good reason for that?

 

I'm not sure if the pins I'm using (port A) are used exclusively for something else, but it doesn't seem like it?

 

Here are my pin #defines - anything stick out?

 

#define PIN_D0		PIO_PA18_IDX
#define PIN_D1		PIO_PA30_IDX
#define PIN_D2		PIO_PA28_IDX
#define PIN_D3		PIO_PA21_IDX
#define PIN_D4		PIO_PA25_IDX
#define PIN_D5		PIO_PA24_IDX
#define PIN_D6		PIO_PA23_IDX
#define PIN_D7		PIO_PA31_IDX

#define PIN_CS		PIO_PA5_IDX
#define PIN_CD		PIO_PA29_IDX
#define PIN_WR		PIO_PA1_IDX
#define PIN_RD		PIO_PA26_IDX
#define PIN_RESET	PIO_PA12_IDX

#define PIN_CD_MASK		1 << 29
#define PIN_WR_MASK		1 << 1
#define PIN_RD_MASK		1 << 26
#define PIN_CS_MASK		1 << 5
#define PIN_RESET_MASK	1 << 12

 

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

Wallaby3 wrote:

I'm inexperienced with Atmel and embedded design in general.

 

Welcome! You are in the right place.  Hopefully you have a strong background in C programming, or at least C++.  The embedded world is quite different than higher level GUI type programming.  Generally expect things to go wrong and handle all error conditions - things like "sending byte A to the slave but it received a different value".  It happens all the time.  So build your programs expecting errors and recover from them.

 

Wallaby3 wrote:

I'm trying to write to a ILI9341 TFT screen using an 8-bit parallel interface. I'm using the pins on the J507 extension. I chose that because it seemed to have a lot of pins on a single port (A).

 

What specific variant of the SAM E70 are you using?  Vendors build different flavors of the same processor packaging, pin outs, peripherals, size of memory, etc.  I'm guessing you have a SAME70 Xplained evaluation board from Atmel/Microchip.  If so, pull down the documents including schematic and datasheet.

 

Wallaby3 wrote:

Can I use any pin as GPIO? Do I need to configure anything specific?

...

 

I'm not sure if the pins I'm using (port A) are used exclusively for something else, but it doesn't seem like it?

 

Here's where the datasheet is needed.  Every embedded processor manufacturer supplies a datasheet with details on the pins, pin numbering, peripherals, etc.  The SAM E70 datasheet lists all the details on the GPIO pins.  Keep in mind that many times pins can be used for different peripherals but only one at a time.  On power up the firmware will program the peripherals to use a pin certain way, be it GPIO output, GPIO input, TWIHS, UART, etc.  Again, see the datasheet.

 

So, start with the datasheet, read the first few overview chapters, skip the peripherals you are not interested in, and read the GPIO section in detail.  I garauntee most of your first questions will be answered.  But a whole new batch of questions will arise.  Be sure to post back once you get through the datasheet.

 

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

Thank you for the in depth reply!

 

I think this is an instance where reading the manual has just created more questions than answers. It is a SAM E70 Xplained Pro by Atmel. ATSAME7DQ21.

 

So this system has multiplexed peripherals that you can you select - ABCDE. However, if you configure your pin for GPIO, it cannot also be used multiplexed as a peripheral. I think that means that you have a total of 32 pins (if my understanding is correct: PA12 means Port A, Pin 12. PB12 means Port B, Pin 12 -- are these the same pin if I set them GPIO?) Some of those pins are used for SDRAM and other things I think are probably important - so clearing peripheral support on all the pins is probably not something you actually want to do if they are the same pins.

 

But I'm not clear on that. If I set PA12 to GPIO and not multiplexed, does that affect PB12? Or is PB12 separate?

 

If PA12 is separate from PB12 and PC12, etc, then I can probably find a way to work it out. It would also explain why PD, PA, PB seem to be spread around everywhere. If they can be used together in the same write then that's fine. If you have to switch ports to use them (which I think I found to be true in testing) it just makes them really inconvenient and annoying.

 

As for programming - no problem there! Many years of software and game programming: Servers, graphics, logic. I only ever have to get low level with network packets and now embedded programming it seems.

 

Thanks again!

 

 

 

 

 

 

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

Well I figured this out with some digging. So for anyone in the future who has a similar question, here is the down-low as I understand it.

 

All pins are configured as GPIO at start up. If there is a #define in the conf_board.h enabling a peripheral that uses pins, those will then be re-configured as PIO for those peripherals.

 

Nearly every pin on the board has multiple functions so you'll generally sacrifice something or another to use them as general purpose.

 

Using PIOA12 doesn't affect PIOB12 like I wondered above. If you need a parallel 16-bit GPIO you'll struggle to find them on a single port without disabling a lot of built-in peripherals. This board has an external SDRAM which uses a lot of IO, but you can still manage pretty well even that considered. I have a parallel 8-bit TFT working now and while it's fast, I feel like I'd need 16-bit parallel to drive a higher resolution. SPI doesn't have the bandwidth for me personally.

 

ASF is slow but it's a good interface for learning the registers. Once I had I looked at how ASF set various registers, I bypassed it and accessed them directly giving a very noticeable speed boost.

 

Still learning...

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

Wallaby3 wrote:
Nearly every pin on the board (sic?) has multiple functions

Did you mean every pin on the chip ?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...