> 3.2.3 | Download Protocol for USB

> The firmware download via USB can take place when the module is connected via the USB interface to the USB host. There is no need for a firmware inside a module because the Siemens bootloader includes a fully functional USB stack with a CDC (Communication Device Class) ACM (Abstract Control Model) device implementation.
> The module simulates a modem connected via a standard serial COM port. Through this virtual COM port the module can be forced to enter the firmware download mode.
> At first the module must be started by an appropriate mechanism, such as asserting the IGT (Ignition) signal or plugging in the USB cable.
> Code fragments shown below are in pseudo C code based on the operating system with enabled USB functionality and should be easily adaptable to other operating systems.
> What is the major difference between a generic update through ASC0/ASC1 and a generic update through USB?

> • | The USB scenario requires that the virtual COM port be closed immediately after the AT^SFDL command was sent and OK received. Then, after 2 seconds the COM port shall be opened again.

> • | The length byte and the data bytes of each record must be transferred in one USB transaction, i.e. by calling the API only once per record.

> Figure 8: Download protocol for USB

> 3.2.3.1 | Example of Firmware Download Program for USB

> void DoUpdate (void) { BYTE bAnswer ; BYTE bRecord[MAX_RECORD_SIZE] ; Int iTry ; /* Number of tries of open virtual COM port*/ /* Send AT command */ WriteToModule ((BYTE *) "AT^SFDL\r", 8) ; /* Wait for answer */ if (!ReadResultLineFromModule ()) /* Error */ return ; /* Close port because the virtual COM port of the module shall be disabled for a short time */ CloseComPort() ; /* Allow USB host to disable the virtual COM port. */ Wait (2 SECONDS) ; /* Try to reopen the virtual COM port again */ iTry = 0 ; do { if (OpenComPort ()) /* Virtual COM port is opened again */ iTry = -1 ; else { /* Virtual COM port is not opened, wait 100 ms */ Wait (100 MILLISECONDS) ; iTry++ ; } } while (0 <= iTry && 80 > iTry) ; if (-1 != iTry) /* Error, virtual COM port is not opened again */ return ; /* Wait for start pattern */ do { ReadFromModule (&bAnswer, 1) ; } while (ANSWER_OK != bAnswer) ; do { /* Read record from file */ bRecord[0] = MAX_RECORD_SIZE ; FileReadRecord (bRecord, bRecord + 1) ; do { /* Send length and data of record */ WriteToModule (bRecord, bRecord[0] + 1) ; do { /* Wait for answer */ ReadFromModule (&bAnswer, 1) ; } while (ANSWER_BUSY == bAnswer) ; } while (ANSWER_RETRY == bAnswer) ; } while (!FileEnd () && ANSWER_OK == bAnswer) ; }