Teensy 4.1: ~30 mA extra sleep current once the SD card has been initialized (SdFat SDIO) in hibernate

JayB333

New member
Hi all,

I'm building a battery-powered ultrasonic audio recorder (bats / cetaceans) on a Teensy 4.1 and I'm trying to get hibernate current under 10 mA between recordings. A bare Teensy hibernates at about 5 mA. I've run into the following with a microSD card in the built-in socket, and I'd appreciate any ideas.

Setup: Teensy 4.1, Arduino IDE with Teensyduino 1.60+ (core 1.62), SdFat 2.1.2 (the version bundled with Teensyduino), sd.begin(SdioConfig(FIFO_SDIO)), Paul's fork of Snooze (Snooze.hibernate(), timer wake). Current measured on the 5 V supply with a meter while the board is hibernating.

Measurements (same board, same sketch, only one change each time):
- No card in the socket: 5.5 mA
- Card inserted but sd.begin() never called: 5.7 mA
- Card inserted and sd.begin() succeeded, then hibernate: 34.7 mA (Samsung 256 GB). A SanDisk card was worse (about 40 mA).

Things I tried before hibernating, none of which changed the 35 mA:
- Sending the card CMD0 (go idle) directly through the USDHC1 registers, using the same register sequence as SdFat's cardCommand().
- Switching the six SDIO pads (GPIO_SD_B0_00..05) back to plain GPIO inputs with pull-ups off.
- Both together.

So it is not the SD controller or the pad configuration on the Teensy side (no card plus controller initialized is 5.5 mA). It looks like the card is left in an active state once it has been initialized, and the SDIO bus is then left floating while the chip is powered down. I understand the socket 3.3 V rail is not switchable on the Teensy 4.1, so I can't cut power to the card.

Questions:
1. Has anyone gotten the Teensy 4.1 built-in SD socket down to a few mA in hibernate after the card was initialized? If so, what did you do (a particular card, a specific shutdown sequence, something in SdFat)?
2. SdioCard::end() in SdFat is empty. Is there a recommended way to put the card into its lowest-power state before power-off?
3. Is there a known card brand or model that sleeps properly after SDIO init?

For now I'm planning to try different cards, and for a future board revision an external SD socket with a switched supply. Thanks for any pointers!

Side note, unrelated to the SD card: in my sketch, Snooze.hibernate() woke after about 1 s instead of the 60 s I asked for once Wire.begin() had run earlier in the same boot, and Wire.end() did not undo it. Restarting the chip first and hibernating in the fresh boot (before any Wire use) works around it. I haven't yet found the cause.
 
In SD native bus mode (including 4-bit mode), SD memory cards support CMD7. The host can deselect the currently selected card by issuing CMD7 with an RCA argument of 0x0000. The card then returns from Transfer State to Stand-by State.

The API only needs a method such as deselectCard() to perform this operation

edit:
I would ask Bill to consider implementing something like:

bool deselectCard();
bool selectCard();

and then hope that it eventually makes its way into Teensyduino. The upstream library is several versions ahead.

Edit: this is not "Sleep Mode", but at least "Stand-by State". How much power that saves would have to be tested, I suppose.
 
Last edited:
There is also a Power Down mode (CMD48/CMD49 to read the register). Support for these commands is optional, but the card's support for them can be queried. I suspect this could provid greater power savings - IF the Card supports it.
 
Last edited:
1793802692970.png
Code:
Card in Transfer State
                  |
                  v
          Check SCR[34]
                  |
                  v
       Read General Information
                  |
                  v
      Determine Power Management Base
                  |
                  v
           CMD48: Read Status
                  |
                  v
              PDMS == 1?
             /        \
           No          Yes
            |           |
          End           v
                 CMD49: Set PDMN = 1
                        |
                        v
                   Wait for Busy
                        |
                        v
                  CMD48: Read Status
                        |
                        v
                   PDMR == 1?
                   /       \
                 No         Yes
                  |           |
                  +-----------+
                              |
                              v
                       Stop SD Clock
 
Last edited:
Title: Followup: I found a solution for Teensy 4.1 hibernate with an RTC alarm via SNVS that drops power consumption to 0.75 mA, works with the SD card and Wire already active.

A followup to my earlier question about high sleep current with an initialized SD card. I found a way around it and want to share it in case it helps others.

What I saw with Snooze.hibernate() on a Teensy 4.1 (Teensyduino core 1.62, SdFat 2.1.2, SDIO):
- Hibernate after sd.begin() succeeded: about 35 mA (Samsung 256 GB; a SanDisk card was about 40 mA). No card, or a card inserted but never initialized: about 5.5 mA.
- Separately, once Wire.begin() had run earlier in the same boot, a 60 s hibernate woke after about 1 s. Wire.end() did not undo it. Restarting the chip and calling hibernate in the fresh boot, before any Wire use, worked around that.
- Sending the card CMD0 or putting the SDIO pads back to plain inputs before sleeping made no difference to the 35 mA.

What fixed it: not using Snooze for the sleep. The recorder code I'm building on, microPAM by Walter Zimmer, sets the SNVS RTC alarm itself and then sets the "turn off power" bit (SNVS_LPCR bit 6). His hibernate function, doHibernate(), is in Teensy.cxx here:


I took the same approach in my own test sketch (set the SNVS alarm to now plus the wait time, then set the power-off bit). With it, the same board, with the SD card initialized, Wire.begin() already run, a 60 MHz CPU clock and the ADC pins driven low, slept the full 60 s (timed with a stopwatch) at 0.75 mA, repeatedly. The chip powers down and the RTC alarm brings it back up, so it boots from setup() like a cold start.

Notes and caveats:
- The wake is a full restart, so everything in RAM is lost. I keep a small marker file on the SD card (time, wait length, file number) to tell a wake from a cold start.
- I only tested with a coin cell on VBAT and the board powered from the 5 V pin. I haven't tested it without a coin cell, so I don't know whether the alarm wake behaves the same there.
- I measured current with a meter on the 5 V supply, so 0.75 mA includes everything on that supply, with the ADC module powered down and its enable pins driven low.
- I don't know where the technique originally comes from, and I'd welcome a pointer to the reference manual section or an earlier thread that covers it.

Questions for the forum: is there an official or recommended way to do this on the Teensy 4.1? And does anyone know why Snooze's hibernate seems to be disturbed by earlier Wire use, or why an initialized SD card keeps drawing current through it, while the direct SNVS method does not?

Thanks to everyone who replied to my first post.
 
Some of the SD card libraries use the multi-sector write command and leave it hanging for single sector writes. If the next write is sequential, this is a lot faster. But it leaves the card active and waiting for more data.

Looking at the SD specification, it appears that a CMD0 will not terminate that operation. A stop command is the way to go. (CMD12) No need to send a CMD0.
 
Back
Top