Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 4 of 4

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

  1. #1
    Member
    Join Date
    Mar 2017
    Location
    Oakland, CA, USA
    Posts
    90

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

    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.

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,585
    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.

  3. #3
    Member
    Join Date
    Mar 2017
    Location
    Oakland, CA, USA
    Posts
    90
    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").

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,585
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •