Can someone look at the code below and tell me if there's something wrong? The "if" statement at the bottom is always true - meaning the read-modify-writes to PFCE1 are not working as I expect.
Either I'm hitting a compiler bug or one or more of these registers needs extra care when doing read-modify-write operations.
This is running on a RZ/A1M on a custom board - and if it matters, it sets up P1.0 and P1.10 to be used by timer channel 1 for rotary decoding.
/* P1.0 = TCLKA (3rd alternate input) */
GPIO.PMC1 |= (1 << 0); // PMC = 1 : enable alternative function
GPIO.PFCAE1 &= ~(1 << 0); // PFCAE = 0 : \
GPIO.PFCE1 |= (1 << 0); // PFCE = 1 : 3rd alternative function
GPIO.PFC1 &= ~(1 << 0); // PFC = 0 : /
GPIO.PM1 |= (1 << 0); // PM = 1 : Input
GPIO.PIPC1 |= (1 << 0); // PIPC = 1 : Input
/* P1.10 = TCLKB (4th alternate input) */
GPIO.PMC1 |= (1 << 10); // PMC = 1 : enable alternative function
GPIO.PFCAE1 &= ~(1 << 10); // PFCAE = 0 : \
GPIO.PFCE1 |= (1 << 10); // PFCE = 1 : 4th alternative function
GPIO.PFC1 |= (1 << 10); // PFC = 1 : /
GPIO.PM1 |= (1 << 10); // PM = 1 : Input
GPIO.PIPC1 |= (1 << 10); // PIPC = 1 : Input
if ((GPIO.PFCE1 & 0x0401) != 0x0401) {
printf("!!! PFCE1 not set! (0x%X)\n", GPIO.PFCE1);
GPIO.PFCE1 = 0x0401; // Force it to what it should be
}