SD card logging on Teensy 4.0 in Simulink Arduino support package (It shares an SPI bus with a sensor)?

I am using the Simulink Arduino support package with a Teensy 4.0 to build custom flight controller firmware. So far, I have been able to communicate successfully with my sensors over SPI:
  1. ICM20948
  2. BMP388
and I2C:
  1. TF-Luna Lidar Range Finder
and I can also receive iBUS data from my transmitter. However, I am having trouble finding a clean way to do SD card logging directly through Simulink on the Teensy 4.0. As many may know, the Teensy 4.0 does not have an inbuilt SD card, so it is sharing the bus with the ICM20948. This is a custom PCB design, and all components have been validated with an arduino based flight controller.
My main questions are:
  1. Is SD card logging natively supported for the Teensy 4.0 through the Simulink Arduino support package?
  2. If so, how do I configure the chip select pin for the SD card?
  3. Does the support package properly handle a shared SPI bus, where the SD card and other SPI peripherals are on the same bus but use different chip select lines?
This shared bus point is important for my setup, since I already have SPI sensors connected and working. I am unsure whether the support package supports this kind of multi-device SPI configuration correctly, or whether it assumes a simpler one-device-per-bus usage.
At the moment, most of the possible workarounds seem to involve wrapping custom C/C++ code, but I would prefer to stay inside the Simulink workflow if possible. I am looking for either:
  • a native Simulink block-based way to log data to SD on Teensy 4.0
  • guidance on shared SPI bus support in this setup
  • or confirmation that custom code wrapping is currently required
If anyone has gotten SD logging working on a Teensy 4.0 in Simulink, especially with other SPI devices active on the same bus, I would appreciate details on the block setup, hardware configuration, and any required custom code.

 Réponse acceptée

Hello,
No, there is no native SDcard logging block for Teensy 4.0 in the official Simulink Arduino Support Package.
The support package lists Teensy 4.0 as supported hardware, but it does not include SDcard peripheral blocks.
There is no SD logging block, Simulink does not provide a CSpin configuration option for SD on Teensy 4.0. To use SD you must write custom C/C++ (via SFunction or custom driver blocks), or use the Teensy ERT custom target, which includes filewrite blocks.
Simulink’s Arduino/Teensy support package handles generic SPI blocks, but not multidevice SPI arbitration (no SPI transaction API, no bus sharing logic).
SPI devices can share MOSI/MISO/SCK if each has its own CS pin (standard SPI practice). SPI Arduino Library, connecting SPI devices to Teensy
But some SD modules fail when sharing SPI due to busholding issues on MISO. (Documented in community tests.) Sharing SPI bus - Projects / General Guidance - Arduino Forum
So although hardware supports shared SPI, Simulink does not manage it for you.
Hope this helps.

Plus de réponses (0)

Produits

Version

R2025b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by