Help with setting a bit-band-aliased bit on Teensy 3.5

Status
Not open for further replies.

shawn

Well-known member
I'm trying to enable FEIE on UART0 on a Teensy 3.5, but the board seems to lock up when I set the bit via the bit-band alias region, and I'm having some difficulty figuring out why. Here is a vastly simplified example:

This works fine:
Code:
void setup() {
  Serial.begin(115200);
  while (!Serial && millis() < 4000) {
  }

  Serial1.begin(250000, SERIAL_8N2);
  UART0_C3 |= UART_C3_FEIE;
  Serial.println("Here!");
}

The board becomes unresponsive with this:
Code:
void setup() {
  Serial.begin(115200);
  while (!Serial && millis() < 4000) {
  }

  Serial1.begin(250000, SERIAL_8N2);
  *reinterpret_cast<uint32_t *>(0x42d400c4U) = 1;
  Serial.println("Here!");
}

For the bit-band alias address: The address for UART0_C3 is 0x4006a006. Subtracting 0x40000000, multiplying by 32, adding 4 (because bit number of FEIE is 1), and then adding 0x42000000 gives 0x42d400c4.
 
You need to cast to uint8_t, because the underlying UART0 registers are 8 bits.

This is a not-so-well documented feature of the bitband, where the size of your access controls the size of the atomic read-modify-write the bitband will perform for you.
 
Awesome, that worked. Thanks for that.

For posterity and for anyone that finds this thread needing the same information, here's the working version of the code. Note the change to the `reinterpret_cast` type.
Code:
void setup() {
  Serial.begin(115200);
  while (!Serial && millis() < 4000) {
  }

  Serial1.begin(250000, SERIAL_8N2);
  *reinterpret_cast<uint8_t *>(0x42d400c4U) = 1;
  Serial.println("Here!");
}

Also for posterity, I'll spell out my specific confusion: the chip docs (all of K20, K64, and K66) explicitly mention 32-bit reads and writes for the bit-band alias region but don't mention 8-bit access (Section "Aliased bit-band regions").
 
The bitband is part of the ARM processor which NXP/Freescale licenses from ARM, Ltd. There's only very limited docs about it on NXP's site.

The detailed info for that part are on ARM's website, but they're quite difficult to read. The best info about the ARM part is in Joseph Yiu's book.
 
Status
Not open for further replies.
Back
Top