Enable single PAL pads?

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
Florian
Posts: 18
Joined: Fri Sep 09, 2011 3:19 pm

Enable single PAL pads?

Post 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
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Enable single PAL pads?

Post 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
Florian
Posts: 18
Joined: Fri Sep 09, 2011 3:19 pm

Re: Enable single PAL pads?

Post 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
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Enable single PAL pads?

Post 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
Florian
Posts: 18
Joined: Fri Sep 09, 2011 3:19 pm

Re: Enable single PAL pads?

Post by Florian »

Ok i will add those changes and post the modified file here in this thread.
Florian
Posts: 18
Joined: Fri Sep 09, 2011 3:19 pm

Re: Enable single PAL pads?

Post 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
Attachments
pal_lld.zip
(1.75 KiB) Downloaded 515 times
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Enable single PAL pads?

Post by Giovanni »

Hi,

Thanks, I will merge everything in the weekend.

Giovanni
Post Reply