I have a full time job as a firmware engineer. I've recently been given a task to review GPIO configurations and change the settings as needed. I found a few pins that were incorrectly configured so naturally I reconfigured them, however I was told I did it in the wrong order. Here is what I'm talking about:
Before:
GPIO1.direction = INPUT;After:
GPIO1.direction = OUTPUT;
GPIO1.value = 0;
However during the code review I've been told that I need to change the order of initialization to the following:
GPIO1.value = 0;
GPIO1.direction = OUTPUT;
In other words set the value first and then set direction of the pin. I've also been told that this is how it needs to be on the modern processors because they use two registers, one for input and one for output, however old processors use only one register, so the order of operations wouldn't matter.
(Note: Modern = ARM Cortex M3 and above, Old = Intel 8051)
I asked for a better explanation at work, but I couldn't get a good answer. That's why I decided to ask here.
So here are my questions:
- Why does the order of initialization matter on the new processors?
- Why does the order of initialization not matter on the old processors?
- What two registers are they talking about in the modern processors?
- What single register are they talking about on the old processors?
If someone could provide some sort of a diagram, that would be even better.