STM32F4 - Grouping pins to form a bus - Page 1
Forum section: electronics / general

author: spudboy488
author_rank: Regular Contributor
timestamp: September 27, 2016, 04:21:09 pm
content: I'm new to the STM32F series (and ARM in general) and have a question. Various board schematics show groups of port/pin combinations that are somehow used as a bus. I can't seem to find an example on how to write the software to do it.Lets say I want to create an 8 bit address bus using the following port/pins.PD14 - A0PD15 - A1PD0 - A2PD1 - A3PE7 - A4PE8 - A5PE9 - A6PE10 - A7I know how to configure the individual pins as output, etc. but I don't know how, or if it's possible, to group them and use them in software as an 8 bit port. I want to be able to set all 8 pins with a single command. Is something like this possible? What info am I missing to help answer the question?

author: jnz
author_rank: Frequent Contributor
timestamp: September 27, 2016, 04:25:03 pm
content: Did you look up bitbanding?

author: spudboy488
author_rank: Regular Contributor
timestamp: September 27, 2016, 04:33:11 pm
content: As mentioned, I'm new to the ARM series and am not familiar with the term bit-banding. I'll start there. Thanks.

author: dannyf
author_rank: Super Contributor
timestamp: September 27, 2016, 04:33:45 pm
content: "use them in software as an 8 bit port. I want to be able to set all 8 pins with a single command.."Depending on what you meant by "use" and "command".There are countless ways to output a vakye on individual pins across multiple ports.There is no way to make the value atomic, not matter how fancy a term one may wish to use.

author: spudboy488
author_rank: Regular Contributor
timestamp: September 27, 2016, 05:29:42 pm
content: To clarify "use" and "command", from my example of making an 8-bit address bus, I would like to set the address on the bus to 0x55, for example. How can I have the 8 lines set to 01010101 without clearing/setting each pin individually?

author: JPortici
author_rank: Super Contributor
timestamp: September 27, 2016, 05:55:14 pm
content: one way is to make a big ass function that checks every bit of the "command" and set the corresponding pin.. for exampleif (command & 1)pin_0_output = 1;elsepin_0_output = 0;if (command & 2)[...]where pin_x_output could be the hal gpio set pin function if you have time to lose or maybe something a little more optimized, like accessing directly the output driver register, likeGPIOD->ODR |= GPIO_Pin_14 to set the pin andGPIOD->ODR &= ~GPIO_Pin_14 to clear the pin(GPIO_Pin_14 is actually (1 << 14)to give more flexibility you could use a label for GPIOD and GPIO_Pin_14, for example BUS_PortPin0 and BUS_Pin0 and#define BUS_PortPin0 GPIOD#define BUS_Pin0 GPIO_Pin_14in another file so you can reuse your function... but i'm sure there can be better (faster) ways but i don't know STM arm that goodaltough you could just try and route the bus into, you know... a bus. so maybe you can use the FSMC or DMA to GPIO and offload some work

author: Rolo
author_rank: Regular Contributor
timestamp: September 28, 2016, 10:33:40 am
content: They do it in MBED, it's called BusOut and BusIn. Don't know the details but you can take a look under the hood how they do it.

author: amyk
author_rank: Super Contributor
timestamp: September 28, 2016, 10:58:18 am
content: Quote from: spudboy488 on September 27, 2016, 05:29:42 pmBy writing 0x55 to the port register? I don't use STM32, but I'd be very surprised if you had to change each pin individually.

author: Boscoe
author_rank: Frequent Contributor
timestamp: September 28, 2016, 02:39:09 pm
content: I don't think you can pick any old set of pins. This will tell you more:http://www.st.com/content/ccc/resource/technical/document/application_note/7a/88/df/e3/d3/36/40/29/DM00169730.pdf/files/DM00169730.pdf/jcr:content/translations/en.DM00169730.pdf