Megasquirt 3 - SD card datalogging

Home

Intro - Supported cards - Settings - Button/light - Log extraction - Utilities - Error codes -

Introduction

Megasquirt-3 has a built-in SD card slot which allows fast datalogging to a supported SD card without the need for a laptop. The operation can be continual or button controlled. Once logging is complete, TunerStudio is used to convert the compact SD log data files into regular datalogs that can be viewed in logging software as normal.

Supported cards

Most SD cards and SDHC cards ought to work.
The firmware supports cards formatted with FAT16 or FAT32 format and with or without a partition table.
MMC cards are not supported due to their slimmer size.
Various SD cards have been tested and there is a wide range of speeds observed. MS3 communicates with the card using the "SPI" serial protocol which is more suited to an engine controller, but cannot match the datarates used within video cameras or PCs.

Here are some example cards tested by the firmware developers.
SD cards

Settings
The configuration for the SD card is on the Datalogging menu in TunerStudio.

SD card dialogue

SD card logging
- Disabled - turns off the SD logging feature
- Insertion - basically it means always log. It is best not to insert the SD card while the MS3 is powered on and most certainly do not unplug the card while the power is on. Card damage can result.
- Button - logging is controlled by a push button
- Button+WTF - not yet supported
Datalog button - selects the input pin used for the button if used.
LED indicator - selects the output used for the optional LED indicator
Log data block size
- 64 byte is the most common setting
- 64 byte + stream allows the simultaneous recording of data and a 8kHz mono sound input. This could be used as a commentary during a datalog such as position on a racetrack or notable incidents in the log. Presently the tuning software does not support extracting this audio data.
Sampling
- Timed - a data sample is taken at predefined time interval - this is the most common option
- every tooth, every cycle - for special logging and at low engine speeds these options take a data sample at these events
Sample interval - how often to take a data sample.
3ms is the fastest supported, but many cards will only sustain 5ms before you start getting small gaps in the logs. See the utilities section for speed testing.
Log file max duration - how long each datalog should be.
The files are always created full size and fill up the allocated space during logging. If the log file is filled, a new file is started. If you turn off the power to the Megasquirt (which is safe to do during a log) the log will be there and will show full size. When the log file is extracted, the unused part of the allocated file will be ignored. (Note, it is impossible for the MS3 to set the file length or otherwise "clean up" the log file in this case because there is no power and the processor is off !) A result of this is that all log files on the SD card will appear the same size.
Stream input - where the 0-5V audio input is connected
Log field selection
The field selector allows you to choose which data fields you want to log. Because of the compact datalog format, only 64 bytes are available total, so you need to pick the data that you find most critical.
To add a field, highlight it on the left and then click on > to move it to the right.
To remove a field, highlight it on the right and then click on < to move it to the left.

An optional extra that can be very useful with the SD logging feature is a realtime clock. Without the realtime clock, the MS3 has no idea what time or date it is and all log files on the card are stored with a bogus timestamp.
There are presently two supported clock options.
a. On the MS3X card there is space to install a clock module (coming soon)
b. The JBperf IO-Extender has a realtime clock which is used via CAN.
Configuration for both of these options is on the "CAN, VSS, gear, RTC" dialogue

Button / light Wiring and usage

Within "insertion" mode you do not need the button. It is required for "button" mode to start and stop datalogs.
The LED/light output is optional in either mode but can be helpful to more quickly diagnose any error conditions and confirm that logging is happening. It is recommended when using button mode. When using the MS3X spark outputs, it is likely convenient to set the "middle LED" as the LED output as zero wiring is required.
SD logging wiring

Button usage
When Megasquirt-3 powers up it will create an empty datalog file ready for logging.
Press and hold the button for over half a second to start a log.
A quick press of the button will end the log.
When extracting the log files you will likely find a blank logfile on the card after your real logs, this is normal.

LED flash codes
Off - SD logging not active
On (solid) - Ready but not logging
Fast flashing - Initialising card
Slow flashing - Logging
Pause, sequence of flashes - error code (See Error codes section)

Log file extraction

The log files on the card use a compact binary format. Before you can view these files it is necessary to convert them to the conventional log format using TunerStudio.
The firmware supports fetching the log files directly over the serial connection. Presently TunerStudio does not support this and a standalone utility sd_sync2 is used. This could be useful at the track, but for large or multiple log files it is often fastest to pop the card out of the MS3 and plug it into your computer or card reader. When inserting the card into a Windows computer, cancel all dialogues and attempts to handle camera files etc.

Open TunerStudio and ensure your current Project and tune file are open.
Go to DataLogging > Import/Conversion > Convert Binary Log
Browse to find the file you want to import from the SD card, select it and then click ok.
A progress window should pop up as the log file is converted.
Repeat for all files needed.
Processed datalogs are stored along with regular datalogs in the Datalogs directory under your project.
View the logs in MegaLogViewer.

Software utilities

Presently there are a few utilities for the SD card system, these are somewhat rudimentary and are all commandline tools. If you are not familiar with using commandline utilities you might want to skip this section.
Windows
sd_speed - this performs a speed test on the SD card
NOTE! this utility WILL erase data on the card. Ensure there is nothing of value on the card first.
This utility is not presently available for Windows
Exit TunerStudio and ensure your Megasquirt is powered up and the serial/USB connection is available.
Then open a command prompt and...
cd c:\efi\ms3
sd_speed com1:
The utility will then make a test on the card and report on the fastest log rate you can use. e.g.

Card status = 0x6f
Stopping log and resetting
Card status = 0x21
Card busy - sleeping
Card status = 0x21
Card busy - sleeping
Card status = 0x67
Fetch full status
Test start sector = 0x100000 - caution writing blindly to card
Waiting.4%.6%.10%.16%.23%.31%.41%.52%.65%.78%.94%.100%

Summary Min = 13 ms, max = 61 ms, average = 14 ms
Shortest write interval 2 ms, gapless write interval 5 ms


sd_sync2 - this will download all logs from your SD card to your computer over the serial link
To use this utility you need to download one file: sd_sync2_win32.exe Save these files to a directory such as C:\efi\ms3
Exit TunerStudio and ensure your Megasquirt is powered up and the serial/USB connection is available.
Then open a command prompt and...
cd c:\efi\ms3
sd_sync2_win32 com1:

The files are downloaded from the card and stored to the local disk with the date/time of downloading. After each file is downloaded, it is erased from the SD card.

Linux
The operation is much the same as Windows, but your serial port is more likely named /dev/ttyUSB0 or /dev/ttyS0
The executable files can be downloaded from http://www.msextra.com/doc/ms3/files/sdcard/linux/

Error codes

If the card fails to initialise or has another problem you will usually get an error code. This is visible through the "SD error" gauge in TunerStudio or through the LED flash sequences.
Error no.NameMeaning / remedy
0no errorOK
1sending clocksCard fault?
2idleCard fault?
3initCard fault?
4set blocksizeCard fault?
5request CSDUnsupported card?
6reading MBRRemove files and reformat card
7MBR end marker not foundRemove files and reformat card
8no partition 1 definedRemove files and reformat card
9reading partition boot sectorCard fault?
10reading directoryCard fault?
11(not used)
12reading FATCard fault?
13reading FAT continuation sectorCard fault?
14writing FATCard fault?
15reading directoryCard fault?
16writing directoryCard fault?
17writing log sectorCard fault?
18unsupported non-FAT16Remove files and reformat card
19-
20SDHC detection
21VCA check pattern failed
22VCA voltage rejected
23OCR1
24OCR2
25OCR3
26OCR4
28processing CSDTry a lower SPI speed
29write failed
30directory fullRoot directory is full, delete some files
31can't find space in FATCard is full, delete some files
32looks like VBR but not validRemove files and reformat card

If you have a question, comment, or suggestion for this FAQ please post it on the forum.

No part of this manual may be reproduced or changed without written permission from James Murray and Ken Culver.