Page 1 of 1

Enable single PAL pads?

Posted: Wed Sep 21, 2011 5:41 pm
by Florian
Hi,

I have a question about the PAL driver. For me it seems impossible to enable or disable the PAL functionality for single pads? So, if I enable the PAL module by setting HAL_USE_PAL to TRUE, it automatically enables the GPIO functionality on all pads/pins in the _pal_lld_init.

We are working on the AT91SAM7. The corresponding PAL_LLD driver automatically writes 0xFFFFFFFF to the PIO Enable Registers, so all 64 pins are switched to I/O mode, although we just need 4 of them.

Is there a way to avoid this? I think it would be nice to have an additional field in the config structure (where the pullup settings, etc. are defined) that indicates for each pad if it is used for PAL or if it is not.
Besides, it would be great if the setup for a pin could be changed during runtime, e.g. by additional macros in the PAL module. Otherwise I had to change the definition of the pal_default_config in hal_lld.c.

Thanks!
Regards,
Florian

Re: Enable single PAL pads?

Posted: Wed Sep 21, 2011 5:57 pm
by Giovanni
In the SAM7 HAL the various device drivers switch the pins in the mode they need. The PAL driver already offers macros/functions to change a pin mode at runtime: palSetPadMode(), palSetGroupMode() and palSetBusMode(). Are you thinking to something different?

Giovanni

Re: Enable single PAL pads?

Posted: Thu Sep 22, 2011 9:51 am
by Florian
On the SAM7, a pin can be set either to GPIO usage or Peripheral A or Peripheral B. The peripherals could be things like UART, SPI, etc.

The choice, if a pin is used by the PIO controller (for GPIO) or for a peripheral is done in the PIO Enable Register within the PIO controller. Within the _pal_lld_setgroupmode function, just the Output Enable Register (determines the data direction), the Pullup Enable register and a few other PIO-internal registers are set, but the PIO_PER is never affected.
As I wrote, the _pal_lld_init sets PIO_PER to 0xFFFFFFFF, as it enables PIO on all pins.

Of course, if a line is used by SPI for instance, the SPI driver again disables PIO on those pins by writing into the PIO_PDR (PIO disable register). But in my opinion this is not a nice (and safe) solution.

An alternative to my idea above was, to simply integrate the PIO_PER in _pal_lld_setgroupmode (as you assumed) and write 0xFFFFFFFF to PIO_PDR (disable all pins) in the initialization function. Would you prefer that solution?

Regards,
Florian

Re: Enable single PAL pads?

Posted: Thu Sep 22, 2011 9:56 am
by Giovanni
Alternate functions should be handled through the PAL driver, the STM32 implementation does that and I wrongly assumed the SAM7 implementation did that as well.

It should be handled in _pal_lld_setgroupmode() as you mentioned.

Giovanni

Re: Enable single PAL pads?

Posted: Thu Sep 22, 2011 2:20 pm
by Florian
Ok i will add those changes and post the modified file here in this thread.

Re: Enable single PAL pads?

Posted: Thu Oct 13, 2011 3:18 pm
by Florian
Hi,
sorry for answering so late.
Here is the modified file. As discussed, I removed the activation of all PIO channels in the init function (writing 0xFFFFFFFF to PIO_PER) and added it to the setgroupmode function.
Everything else should be unchanged but you better try a diff before committing.

Regards,
Florian

Re: Enable single PAL pads?

Posted: Thu Oct 13, 2011 7:20 pm
by Giovanni
Hi,

Thanks, I will merge everything in the weekend.

Giovanni