Firmware

Firmware

Communication Interface

The interface is configured during power up with the following pins.

  • PA7 - SPI MOSI (internal pulldown)
  • PA15 - SPI CS (internal pulldown)
  • PB3 - SPI SCK (internal pullup)

Bootloader (UART)

When the FATSC controller is started in bootloader mode then it automatically searches all available devices for a FIRMWARE.IMG file in the root directory. If a newer firmware version is found within 5s then an update will be done and the new firmware will be started (with interface selected by pin states). Always ensure that there is no power outage during the update process. The update can take up to 15s.

UART settings: 115200 baud (8N1)

Pin states to select the interface:

  • PA7 MOSI = high
  • PA15 CS = low

UART

Settings: 115200 baud (8N1)

Pin states to select the interface:

  • PA7 MOSI = low
  • PA15 CS = low
  • PB3 SCK = high: 115200 baud, low: 9600 baud

I2C

planned feature

Pin states to select the interface:

  • PA7 MOSI = low
  • PA15 CS = high

SPI

planned feature

Pin states to select the interface:

  • PA7 MOSI = high
  • PA15 CS = high

Commands

Commands end with <LF> and numbers are written as strings of hexadecimal digits (ASCII), e.g. 16 would be 12 (bytes 0x31 and 0x32).

Carriage return <CR> is interpreted as line feed <LF> on commands.

Hexadecimal digits A to F must be upper case.

<LF> = 0x0A (line feed)
<CR> = 0x0D (carriage return)
<SP> = 0x20 (space)
{RR} = Result code (hex value)

I - Initialize device

Mount the respective device.

Command

I<SP>{D}<LF>
  • {D} drive name:
    • M: Memory card
    • U0: USB drive 0
    • U1: USB drive 1

Response

!{RR}<LF>

O - Open file

Open the respective file.

Command

O<SP>{H}{M}>{F}<LF>
  • {H} handle: 0...F
  • {M} mode: R=read, W=write, A=append
  • {F} file name, e.g. “U0:/path/filename.txt”

Response

!{RR}<LF>

C - Close file

Close the respective file.

Command

C<SP>{H}<LF>
  • {H} handle: 0...F

Response

!{RR}<LF>

R - Read file

Read data from file.

Command

R<SP>{H}{F}>{S}<LF>
  • {H} handle: 0...F
  • {F} filler byte
  • {S} bytes to read (hex value)

Response

!{RR}<LF>
Data-Bytes
${XXXXXXXX}<LF>
!{RR}<LF>
  • {XXXXXXXX} valid bytes without filler (hex value)

W - Write file

Write data to file.

Command

W<SP>{H}>{S}<LF>
  • {H} handle: 0...F
  • {S} bytes to write (hex value)

Response

!{RR}<LF>
Data-Bytes (from host)
${XXXXXXXX}<LF>
!{RR}<LF>
  • {XXXXXXXX} bytes written (hex value)

F - Flush file

This command flushes the cached information of a writing file. The close command will also flush the data before closing the file.

Command

F<SP>{H}<LF>
  • {H} handle: 0...F

Response

!{RR}<LF>

J - Get status

Read respective status register.

Command

J<SP>{N}<LF>
  • {N} register:
    • 0 device status
    • 1 file status
    • 2 auxiliary status

Response

!{RR}<LF>
${S}<LF>
!{RR}<LF>
  • {S} status (hex value)
    • 0 device status (8 bit)
      • bit 7: 0 reserved
      • bit 6: 1=U1 attached
      • bit 5: 1=U0 attached
      • bit 4: 1=M mounted
      • bit 3: 1=U1 mounted
      • bit 2: 1=U0 mounted
      • bit 1: 1=M readonly (WP=high)
      • bit 0: 1=M attached (CD=low)
    • 1 file status (16 bit)
      • bit 0: 1=handle 0 used … bit 15: 1=handle F used
    • 2 auxiliary status (16 bit)
      • bit 15-8: 0 reserved
      • bit 7: 1=auto mount on
      • bit 6: 1=LSE okay (32768 Hz crystal)
      • bit 5: 1=HSE okay (high-speed external crystal)
      • bit 4-0: 0 reserved

Z - System control

Set system mode or registers.

Command

Z<SP>{N}{>{V}}<LF>
  • {N} register:
    • 0 start standby mode (without parameter)
    • 1 start stop mode (without parameter)
    • 2 Wakeup pin: 0=wakeup, 1=emergency flush and close
    • 3 0=auto mount off, 1=auto mount on
  • {V} parameter value, e.g. Z<SP>3>1<LF> to activate auto mounting

Response

!{RR}<LF>

G - Get time

Get the time and date.

Command

G<SP>{N}<LF>
  • {N} date or time:
    • D date
    • T time
    • G date and time

Response

{MM-DD-YYYY}<LF>
{HH:MM:SS}<LF>
{MM-DD-YYYY HH:MM:SS}<LF>
!{RR}<LF>
  • {MM-DD-YYYY} date D response
  • {HH:MM:SS} time T response
  • {MM-DD-YYYY HH:MM:SS} date and time G response

S - Set time

Set the time and date.

Command

S<SP>{DDDDTTTT}<LF>
  • {DDDDTTTT} date and time as 32 bit hex value or MM-DD-YYYY HH:MM:SS string
    • bit 31-25: years since 1980
    • bit 24-21: month (1-12)
    • bit 20-16: day (1-31)
    • bit 15-11: hour (0-23)
    • bit 10-5: minute (0-59)
    • bit 4-0: seconds divided by 2 (0-30)

Response

!{RR}<LF>

T - Check RTC

The clock source of the RTC is automatically selected and this command checks the current RTC clock source.

Command

T<SP>{M}<LF>
  • {M} RTC mode:
    • S shared mode
    • B backup mode with crystal (LSE) and battery

Response

!{RR}<LF>
  • returns 00 if the RTC mode is the requested one

B - Set baudrate

Set the UART baud rate.

Command

B<SP>{N}<LF>
  • {N} baudrate as 32 bit hex value

Response

!{RR}<LF>
!{RR}<LF>
  • first result code with current baudrate and second code with new baudrate (after 10ms), if there are no errors

V - Get version

Get the firmware version.

Command

V<LF>

Response

v{X.X.X}<LF>
!{RR}<LF>
  • v{X.X.X} version, eg. v3.0.0

U - Update

Update the firmware with a subsequent restart. Always ensure that there is no power outage during the update process. Please wait for a response code or after the reboot for the startup message. The interface is selected by pin states after the restart and the update can take up to 15s.

Command

U<SP>{F}<LF>
  • {F} file name, e.g. U0:/firmware.img

Response

!{RR}<LF>

<LF> - NOP

No operation (NOP).

Command

<LF>

Response

!{00}<LF>

Result Codes

CodeDescription
00OK, command successful
01Unknown command
02Incorrect parameters
03Operation failed, also returned on a write to write-protected card
04Reached end of the file/folder list - this is not an error
11Initialize media/drive failed
20File/folder does not exist
21Failed to open the file
26File/folder name already exists
30Invalid file handle
37File handle already in use