Page 1 of 1

Group/Bus Port mode/read/write, help!

Posted: Wed Oct 08, 2014 9:16 am
by Rick Burnett
I must be missing something fundamental here, I've looked at all the documentation and tried to find examples to help me figure this out, nothing seems to be working.

PROBLEM 1:

If I change a port mode like this, it works as expected and I am able to verify with a scope that the port is pulled up:

Code: Select all

palSetPadMode(GPIOF,5,PAL_MODE_INPUT_PULLUP);


If I then try to do this in a for loop, the pad does not change to pullup:

Code: Select all

int32_t i=0;
for( i=0; i<16;i++);
{  palSetPadMode(GPIOF,i,PAL_MODE_INPUT_PULLUP);
}


If I try to use the bus method, again, I cannot get the port to pullup:

Code: Select all

palSetBusMode(GPIOF,PAL_MODE_INPUT_PULLUP);


PROBLEM 2:

I attempted to use palReadBus(GPIOF) but it halts operation of my code. I also notice the docs that this returns a uint8_t typedef. The port I am reading is 16-bit. Can I read this in on read? If not, how do I read both halves of this bus? Really surprised it is halting the code.

I switched to using palReadGroup, but again, given the 8-bit vs 16-bit, it's just not making sense how I use it. I basically want to read all 16 bits into a 16-bit uint16_t.

Thanks!

Re: Group/Bus Port mode/read/write, help!

Posted: Wed Oct 08, 2014 9:23 am
by Rick Burnett
Should I be using something like this:

Code: Select all

IOBus busF = {GPIOF,0xFFFF, 0};


And then using this with the bus functions? Still not sure on the 16-bit data though.

Re: Group/Bus Port mode/read/write, help!

Posted: Wed Oct 08, 2014 9:34 am
by Rick Burnett
That was it! Going to leave this here for others that might be confused as to what to use with the Bus options.

Re: Group/Bus Port mode/read/write, help!

Posted: Wed Oct 08, 2014 11:07 am
by Giovanni
A bus is a set of contiguous lines on a port that can be handled as a whole (atomically if the HW allows it).

A bus of 16 bits is equivalent to a port.

Giovanni

Re: Group/Bus Port mode/read/write, help!

Posted: Wed Oct 08, 2014 4:12 pm
by Rick Burnett
So is the documentation just limited to showing one implementation? The return type for portReadBus() shows it returned a uint8_t, but in the case of the STM32F4, the implementation appears to be returning 16 bits.

Re: Group/Bus Port mode/read/write, help!

Posted: Wed Oct 08, 2014 4:23 pm
by Giovanni
The documentation returns a stub implementation that is what you see under /os/hal/templates.

Low level details must always be studied on the MCU Reference Manual and looking at examples.

Giovanni

Re: Group/Bus Port mode/read/write, help!

Posted: Wed Oct 08, 2014 8:15 pm
by Rick Burnett
Ahhh, okay. That makes sense.

I will say, the examples for bus and group reading seem to be pretty sparse. I did a grep on the entire release and didn't find any examples showing how to use these. I extracted the usage from studying the FSMC example here:

http://www.chibios.org/dokuwiki/doku.ph ... ternal_ram


But even that does not do read/write bus or group showing how the PAL functions should work. Is there somewhere I should have seen these more in use?

Re: Group/Bus Port mode/read/write, help!

Posted: Wed Oct 08, 2014 8:28 pm
by Giovanni
Yes, it is true that it is not the most commonly used feature, I think because most have not yet understood what is it for.

It is for I/O abstraction, imagine you want to write a 44780 LCD driver and wanting to make it portable. This would not normally be possible because the display could be attached to different lines on different boards/MCUs.

If the driver is written to use a generic 4 bits bus for data, a 1 bit bus for RW and another 1 bit bus for the E signals then the driver would be portable because the bus definitions would be out of the driver code (in the board code for example).

Giovanni

Re: Group/Bus Port mode/read/write, help!

Posted: Wed Oct 08, 2014 9:08 pm
by Rick Burnett
What have people been doing? Writing to the port directly?

Personally I really like what you've done, now that I understand it. :)

Re: Group/Bus Port mode/read/write, help!

Posted: Wed Oct 08, 2014 9:12 pm
by Giovanni
I must admit that it is not an idea of mine :)

It is a feature of the AUTOSAR DIO driver that I included in PAL.

Giovanni