Hello,
This behavior could be quite a "gotcha", especially since most datasheets make the following recommendation, without any specific mention of the side effect under discussion.
It is a good programming practice to write to the port data register before changing the direction of a port pin to become an output. This ensures that the pin will not be driven momentarily with an old data value that happened to be in the port data register.
What if ISR code writes to any other pin from the same port? It is then possible for an infrequent, and very difficult to track down, bug to occur on occasions when the interrupt routine splits the two instructions. In this case, a solution is to temporarily disable interrupts while the port pin is being set. But this requirement has not normally been associated with simple GPIO manipulations - but I guess it will now come to mind in the future.
The other solution is to write to the output register after setting the direction, but this will potentially cause a short glitch, the very thing we are attempting to avoid in the first instance. For the simulated open drain configuration used in a wire_OR situation, any glitch may potentially cause a conflict at the pin, maybe requiring inclusion of an extra current limiting resistor.
With C programming, where the relationship between the various GPIO pins tends to be "hidden" inside macros, whether there is a need to disable interrupts or not, will never be obvious. With C programming, it may not even be obvious to the programmer that manipulating a GPIO pin is in fact a read-modify-write operation, but may possibly be seen as a write operation.
Maybe it would be a good idea if the potential port corruption mechanism were to get a mention in a revised datasheet and/or be covered by an application note. I wonder how many previous threads on this forum, that reported I/O problems, might be due to this cause.
Regards,
Mac