Bit-banding in the XMC4500

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Not applicable
ARM's Cortex-M4 Devices Generic User Guide (sec 2.2.5) specifies an optional bit-banding feature.

It is not mentioned in the Infineon XMC4500 reference manual. Does the XMC4500 support bit banding?
0 Likes
4 Replies
AndreasG
Employee
Employee
10 replies posted 5 replies posted Welcome!
The XMC4000 family does not support bit-banding.

Most peripherals in the devices provide different means of direct bit manipulation, e.g. *SET and *CLR registers, allowing to modify individual or groups of bits and bit fields.
Another example is the Output Modification Register (OMR) of the Ports, which allows to set, clear or toggle single or multiple GPIO pins of the respective Port with a single access.
0 Likes
Not applicable
Andreas, Thanks for your reply.

Yes, I see that writing to a pin using DAVE app IO004 eventually results to a write to the port's OMR register.

However this is so slow and inefficient! To improve speed, the DAVE app could be rewritten to use #defines for bit positions rather than shifts for every call. Of course this would take more code space.

My XMC4500 running at 120MHz takes
621ns to set a pin high using IO004_SetOutputValue
530ns to set a pin low using IO004_SetOutputValue

Yes the OMR allows you to change port pins atomically which is great, but you still have to spend time assembling a 32bit image of the bits you want to affect, before writing the result to the OMR. It's cumbersome.

So I wanted to see just how fast I could toggle a pin. The advantage of the toggle feature of the OMR allowed me to get 33MHz by writing two instructions in assembly: transferring a register to the OMR and branch back.
However, toggling using the DAVE app is... slowww. Bit-banding would have helped a lot.

I would have loved to have both your present implementation -and- bit-banding both on your silicon.

Also I think bit-banding would have also improved the efficiency of C bit field constructs. Oh well.
0 Likes
AndreasG
Employee
Employee
10 replies posted 5 replies posted Welcome!
You are welcome, Murray.
I am not really an expert on bit-banding, but I try to comment anyway...

I am sure bit-banding has its merrits, but also some limitations and drawbacks.
Bit-banding accesses are executed as read-modify-write operations, meaning that the CPU reads the full (e.g.32bit) register, manipulates the addressed bit and writes the full register back. So if you just want to set or clear a single bit, you still have two bus accesses.
Also, assembling a write mask for multiple bits that shall be updated in the same register may still be more efficient in system performance than a bunch of bit-banding accesses.
The read-modify-write operation may also have a drawback regarding registers with mixed content regarding status and control bits. If you have a status flag that may be set by hardware and cleared by software in the same register, a read-modify-write operation to a different bit in the same register may result in missing/losing information. Similar for bits that are cleared when read.

I also don't think that bit-banding really supports bit fields, but is limited to accesses to individual bits. Taking the OMR example, if you want to toggle two pins as a differential pair, bit-banding would always have some delay between the switching of the two pins, while that's easily possible without delay with a single write operation to the OMR register.
Similarly, bit-banding will not help in accessing "true" bit fields, like the IOCRx.PCy bit field (to stick with the Port example)...
0 Likes
User11773
Level 4
Level 4
First like received First solution authored
Not to revive a stale thread, but this still shows up in searches.

I use something like :
#define DO_TP200(A) (PORT3->OMR = ((A)==1) ? PORT3_OMR_PS8_Msk : PORT3_OMR_PR8_Msk)

This is very fast. I think I can get about 13MHz+ toggle speed on a 144 MHz XMC4700
I wish DAVE would do something like this. I use the same name for DAVE Digi IO App "DO_TP200".
0 Likes