mcu-an-300247-e-v10-16fx usb bootloader · (Flash Loader) Internal FLASH USB Host Interface USB...

21
Fujitsu Microelectronics Europe Application Note MCU-AN-300247-E-V10 F²MC-16FX FAMILY 16-BIT MICROCONTROLLER USB SERIES USB / SD CARD BOOTLOADER APPLICATION NOTE

Transcript of mcu-an-300247-e-v10-16fx usb bootloader · (Flash Loader) Internal FLASH USB Host Interface USB...

Page 1: mcu-an-300247-e-v10-16fx usb bootloader · (Flash Loader) Internal FLASH USB Host Interface USB Mass Storage MMC/SD Card Support Status Information ... a driver for data input and

Fujitsu Microelectronics Europe Application Note

MCU-AN-300247-E-V10

F²MC-16FX FAMILY 16-BIT MICROCONTROLLER

USB SERIES

USB / SD CARD BOOTLOADER

APPLICATION NOTE

Page 2: mcu-an-300247-e-v10-16fx usb bootloader · (Flash Loader) Internal FLASH USB Host Interface USB Mass Storage MMC/SD Card Support Status Information ... a driver for data input and

USB / SD CARD BOOTLOADER Revision History

MCU-AN-300247-E-V10 - 2 - © Fujitsu Microelectronics Europe GmbH

Revision History

Date Issue 2008-12-19 V1.0, MSc, First version

This document contains 21 pages.

Page 3: mcu-an-300247-e-v10-16fx usb bootloader · (Flash Loader) Internal FLASH USB Host Interface USB Mass Storage MMC/SD Card Support Status Information ... a driver for data input and

USB / SD CARD BOOTLOADER Warranty and Disclaimer

© Fujitsu Microelectronics Europe GmbH - 3 - MCU-AN-300247-E-V10

Warranty and Disclaimer To the maximum extent permitted by applicable law, Fujitsu Microelectronics Europe GmbH restricts its warranties and its liability for all products delivered free of charge (eg. software include or header files, application examples, target boards, evaluation boards, engineering samples of IC’s etc.), its performance and any consequential damages, on the use of the Product in accordance with (i) the terms of the License Agreement and the Sale and Purchase Agreement under which agreements the Product has been delivered, (ii) the technical descriptions and (iii) all accompanying written materials. In addition, to the maximum extent permitted by applicable law, Fujitsu Microelectronics Europe GmbH disclaims all warranties and liabilities for the performance of the Product and any consequential damages in cases of unauthorised decompiling and/or reverse engineering and/or disassembling. Note, all these products are intended and must only be used in an evaluation laboratory environment.

1. Fujitsu Microelectronics Europe GmbH warrants that the Product will perform substantially in accordance with the accompanying written materials for a period of 90 days form the date of receipt by the customer. Concerning the hardware components of the Product, Fujitsu Microelectronics Europe GmbH warrants that the Product will be free from defects in material and workmanship under use and service as specified in the accompanying written materials for a duration of 1 year from the date of receipt by the customer.

2. Should a Product turn out to be defect, Fujitsu Microelectronics Europe GmbH´s entire liability and the customer´s exclusive remedy shall be, at Fujitsu Microelectronics Europe GmbH´s sole discretion, either return of the purchase price and the license fee, or replacement of the Product or parts thereof, if the Product is returned to Fujitsu Microelectronics Europe GmbH in original packing and without further defects resulting from the customer´s use or the transport. However, this warranty is excluded if the defect has resulted from an accident not attributable to Fujitsu Microelectronics Europe GmbH, or abuse or misapplication attributable to the customer or any other third party not relating to Fujitsu Microelectronics Europe GmbH.

3. To the maximum extent permitted by applicable law Fujitsu Microelectronics Europe GmbH disclaims all other warranties, whether expressed or implied, in particular, but not limited to, warranties of merchantability and fitness for a particular purpose for which the Product is not designated.

4. To the maximum extent permitted by applicable law, Fujitsu Microelectronics Europe GmbH´s and its suppliers´ liability is restricted to intention and gross negligence.

NO LIABILITY FOR CONSEQUENTIAL DAMAGES

To the maximum extent permitted by applicable law, in no event shall Fujitsu Microelectronics Europe GmbH and its suppliers be liable for any damages whatsoever (including but without limitation, consequential and/or indirect damages for personal injury, assets of substantial value, loss of profits, interruption of business operation, loss of information, or any other monetary or pecuniary loss) arising from the use of the Product.

Should one of the above stipulations be or become invalid and/or unenforceable, the remaining stipulations shall stay in full effect

Page 4: mcu-an-300247-e-v10-16fx usb bootloader · (Flash Loader) Internal FLASH USB Host Interface USB Mass Storage MMC/SD Card Support Status Information ... a driver for data input and

USB / SD CARD BOOTLOADER Contents

MCU-AN-300247-E-V10 - 4 - © Fujitsu Microelectronics Europe GmbH

Contents

REVISION HISTORY.............................................................................................................. 2

WARRANTY AND DISCLAIMER........................................................................................... 3

CONTENTS ............................................................................................................................ 4

1 INTRODUCTION................................................................................................................ 6 1.1 Overview ................................................................................................................... 6 1.2 Features.................................................................................................................... 6

2 OVERVIEW........................................................................................................................ 7 2.1 Project Parts ............................................................................................................. 7

2.1.1 Project Block Diagram................................................................................. 7

3 QUICK START................................................................................................................... 8 3.1.1 Error codes:................................................................................................. 9

4 MEMORY SECTIONS...................................................................................................... 10 4.1 Introduction ............................................................................................................. 10 4.2 Memory Map for MB96F338US .............................................................................. 11 4.3 Address Sections .................................................................................................... 12

4.3.1 Memory Sections ...................................................................................... 12 4.3.2 ROM Configuration Block.......................................................................... 12 4.3.3 Bootloader Code Section .......................................................................... 12

4.3.3.1 Fixed Boot Vector ..................................................................... 12 4.3.3.2 Alternative Interrupt Vector Table ............................................. 12 4.3.3.3 RAMCODE Section................................................................... 12

4.3.4 User Code Section .................................................................................... 12

5 BOOTLOADER PROCESS ............................................................................................. 13 5.1 Boot Loader Process Order .................................................................................... 13 5.2 Flash Process ......................................................................................................... 15 5.3 MHX Format Conversion......................................................................................... 16

5.3.1 S-Record Structure ................................................................................... 16 5.3.1.1 Example: MHX Record ............................................................. 16

5.3.2 Even/Odd Data Lengths and Addresses................................................... 16 5.3.2.1 Example Odd Data Record: ...................................................... 16 5.3.2.2 Example: Odd Address Record ................................................ 17 5.3.2.3 Example: Even Data and Even Address................................... 17

6 PROJECT OPTIONS FOR BOOTLOADER .................................................................... 18

Page 5: mcu-an-300247-e-v10-16fx usb bootloader · (Flash Loader) Internal FLASH USB Host Interface USB Mass Storage MMC/SD Card Support Status Information ... a driver for data input and

USB / SD CARD BOOTLOADER Contents

© Fujitsu Microelectronics Europe GmbH - 5 - MCU-AN-300247-E-V10

6.1 Compiler Options .................................................................................................... 18 6.2 Linker Options......................................................................................................... 18

7 TIMING............................................................................................................................. 20

8 APPENDIX....................................................................................................................... 21 8.1 Bootloader Download.............................................................................................. 21 8.2 USB Mass Storage Drivers ..................................................................................... 21 8.3 MMC/SD Card Drivers ............................................................................................ 21 8.4 FatFs Module (FAT, FAT16, FAT32 driver) ............................................................ 21

Page 6: mcu-an-300247-e-v10-16fx usb bootloader · (Flash Loader) Internal FLASH USB Host Interface USB Mass Storage MMC/SD Card Support Status Information ... a driver for data input and

USB / SD CARD BOOTLOADER Chapter 1 Introduction

MCU-AN-300247-E-V10 - 6 - © Fujitsu Microelectronics Europe GmbH

1 Introduction

1.1 Overview This user guide describes the implementation of a bootloader which uses USB mass storage support or an optional SD/MMC card interface driver to read a Softune Workbench generated file named app.mhx in root directory of the storage device and flash it as main application. Supported file systems are FAT, FAT16 and FAT32. A optional debug information is displayed via UART 0 (115200,N,1).

The software is developed for the Fujitsu MB96F300 series USB microcontroller. This example is designed primarily for Fujitsu MB96F338U microcontroller (SK-16FX-144PMC –USB Starterkit).

Also in this application note a FAT file system is used which can be downloaded from the developer’s website: http://elm-chan.org/fsw/ff/00index_e.html

1.2 Features - Supports USB stick / USB card reader (tested with max. 320GB USB hard drive)

- Supports MMC/SD cards (disabled by default) (non USB)

- Supports FAT, FAT16 and FAT32

- Supports reset vector check (If not valid, load bootloader)

- Starts bootloader only at power on (except no valid Reset Vector)

- Can be located in lower flash 8KByte sections

- Needs max. 24KByte Flash (max. 32KByte with MMC/SDC support)

- Debug Information via UART 0 (can be disabled)

Page 7: mcu-an-300247-e-v10-16fx usb bootloader · (Flash Loader) Internal FLASH USB Host Interface USB Mass Storage MMC/SD Card Support Status Information ... a driver for data input and

USB / SD CARD BOOTLOADER Chapter 2 Overview

© Fujitsu Microelectronics Europe GmbH - 7 - MCU-AN-300247-E-V10

2 Overview

OVERVIEW OF THE USB/SD CARD BOOTLOADER

2.1 Project Parts - USB Host & USB Mass Storage – Disk I/O Driver

- [ MMC/SD card – Disk I/O Driver (Optional) ]

- FatFs Module (FAT, FAT16, FAT32 driver) from Elm-Chan

- Internal Flash Routines

- Main Application (Bootloader) and MHX/S-Record File Converter

- UART for Debug Information and Hardware Specific Support

2.1.1 Project Block Diagram

Main Application

FAT Filesystem

Disk I/O

SD/MM

UART

Elm-Chan’s FatFs

MHX to FLASH

(Flash Loader)

Internal FLASH

USB Host Interface

USB Mass Storage

MMC/SD Card Support

Status Information over UART 0 while flashing device

UART 0, RS232 UART 3, SPI USB Host

Optional SD Card Support

Page 8: mcu-an-300247-e-v10-16fx usb bootloader · (Flash Loader) Internal FLASH USB Host Interface USB Mass Storage MMC/SD Card Support Status Information ... a driver for data input and

USB / SD CARD BOOTLOADER Chapter 3 Quick Start

MCU-AN-300247-E-V10 - 8 - © Fujitsu Microelectronics Europe GmbH

3 Quick Start First the bootloader needs to be flashed into the target microcontroller. Flash the file usb-bootloader.mhx with the Fujitsu Flash Programmer FX for example into the MCU.

Connect a serial cable to UART 0 and open the Starterkit Wizard. Use a connection speed of 115200 Baud. After switching in running mode and pressing the reset button, the bootloader should start. The next screen should be displayed:

It shows that the bootloader is running and no USB-Stick or MMC/SD Card was found and that no app.mhx file is available for flashing. It also detects, that no valid Reset Vector exists and halts the boot process.

Page 9: mcu-an-300247-e-v10-16fx usb bootloader · (Flash Loader) Internal FLASH USB Host Interface USB Mass Storage MMC/SD Card Support Status Information ... a driver for data input and

USB / SD CARD BOOTLOADER Chapter 3 Quick Start

© Fujitsu Microelectronics Europe GmbH - 9 - MCU-AN-300247-E-V10

The next step is flashing the main application. The main application can only be flashed if no valid boot vector exists – this should be the cause after the bootloader was flashed – or at power on. Load the main application to a USB-Stick and rename the *.mhx file to app.mhx.

Plug the USB stick to your hardware application and turn power off and on. The bootloader should now find the app.mhx file and starts to erase the flash sections except the bootloader sections. After erasing, the bootloader flashes the main application and restarts in it.

3.1.1 Error codes: If no UART is available, activity and error codes are in default configuration provided over PDR09_P7. Following Errors can be seen in Morse Code:

Device Empty: ·/--/·--·/-/-·— (EMPTY) CRC-Error: -·-·/·-·/-·-· (CRC) Note: Port can be changed or disabled in bootloader.h

Page 10: mcu-an-300247-e-v10-16fx usb bootloader · (Flash Loader) Internal FLASH USB Host Interface USB Mass Storage MMC/SD Card Support Status Information ... a driver for data input and

USB / SD CARD BOOTLOADER Chapter 4 Memory Sections

MCU-AN-300247-E-V10 - 10 - © Fujitsu Microelectronics Europe GmbH

4 Memory Sections

FLASH SECTIONS

4.1 Introduction Before a bootloader is implemented in a microcontroller structure, a concept of the memory allocation, type of memory and firmware input is useful. The allocation of used memory from the bootloader should be as small as possible to have enough free space for the main application. The bootloader contains only a boot manager, a driver for data input and a driver for data output for writing the main application.

The target memory is a Flash type which can be read, erased and rewritten, but it always has to be erased before it can be written. To make it more flexible, the Flash memory is divided into different sectors. The MB96F338U microcontroller has some 8KBytes sectors at the lower Flash sections (4*8KBytes = 32KBytes) and 64KBytes sectors at the higher addressed sections (8*64KBytes=512KBytes). Each sector can be erased autonomous without touching the other sectors. The bootloader is located in the smaller sectors, because it only takes 24KBytes of the Flash memory and if a 64KBytes sector were chosen, 40KBytes would be unused. This configuration let the user one 8KBytes sector for special constants for example or other configuration data and gives also the freedom to use the whole upper 512KBytes Flash memory.

The boot manager section decides which address should be started at the beginning. For the MB96300 series it is possible to use an alternative boot address called fix boot vector. Normally the microcontroller starts the program from the reset vector in which the address of the main application is written. The boot manager is programmed at the enabled fix boot vector and is called at each reset instead of the reset vector. After the boot decision, the boot manager continues to load the bootloader or starts the main application. In this project the boot management is part of the bootloader. The main application start address is stored like in every other application at the reset vector address and is called from the bootloader.

In this project the input drivers are front ended by a FAT filesystem which uses disk-io, USB host and USB mass storage class drivers to connect to different storage types. The main flash process is running in RAM and disables interrupts while writing or erasing.

Page 11: mcu-an-300247-e-v10-16fx usb bootloader · (Flash Loader) Internal FLASH USB Host Interface USB Mass Storage MMC/SD Card Support Status Information ... a driver for data input and

USB / SD CARD BOOTLOADER Chapter 4 Memory Sections

© Fujitsu Microelectronics Europe GmbH - 11 - MCU-AN-300247-E-V10

4.2 Memory Map for MB96F338US The Bootloader is located in flash DF0000 – DF5FFF. Free User Code Area is available in the upper flash section (F80000 – FFFFFF). All User Code which contains data in sections below F80000 will be ignored and not flashed by the bootloader.

CPU address Sector name and flash size

in byte

FF:FFFF FF:0000 S39 – 64K

FE:FFFF FE:0000 S38 – 64K

FD:FFFF FD:0000 S37 – 64K

FC:FFFF FC:0000 S36 – 64K

FB:FFFF FB:0000 S35 – 64K

FA:FFFF FA:0000 S34 – 64K

F9:FFFF F9:0000 S33 – 64K

F8:FFFF F8:0000 S32 – 64K

External Bus

Reserved

DF:7FFF DF:6000 SA3 – 8K

DF:5FFF DF:4000 SA2 – 8K

DF:3FFF DF:2000 SA1 – 8K

DF:1FFF DF:0000 SA0 – 8K

Reserved

Boot Loader

Only used, if MMC/SDC support is enabled

User Code

Page 12: mcu-an-300247-e-v10-16fx usb bootloader · (Flash Loader) Internal FLASH USB Host Interface USB Mass Storage MMC/SD Card Support Status Information ... a driver for data input and

USB / SD CARD BOOTLOADER Chapter 4 Memory Sections

MCU-AN-300247-E-V10 - 12 - © Fujitsu Microelectronics Europe GmbH

4.3 Address Sections

4.3.1 Memory Sections

DF0000 – DF007F : Reserved for ROM Configuration Block DF0080 – DF5FFF : Bootloader Code Section DF0080 - DF0083 : Fixed Boot Vector DF0214 - DF03D3 : Alternative Interrupt Vector Table DF5C00 – DF5EB5 : RAMCODE Section – Code which is copied in RAM DF6000 – DF7FFF : free, except MMC/SDC support is enabled F80000 – FFFFFF : User Code Section

4.3.2 ROM Configuration Block This Block is defined in start.asm and will be automatically generated. This section only contains data from the bootloader application. The main application has no access here. All data in the app.mhx which is linked to this section will be ignored by the flashing Process.

4.3.3 Bootloader Code Section The Flash which will be used for the bootloader is located at DF0080 – DF5FFF. If MMC/SDC support is enabled, DF6000 – DF7FFF is also used for the bootloader code. The bootloader code section contains all USB host, mass storage and filesystem functions.

4.3.3.1 Fixed Boot Vector

The Bootloader Code starts at the Fixed Boot Vector DF0080. If the Bootloader Code Section does not start at Fixed Boot Vector, section “6.17 Jump to Bootloader” in start.asm has to be uncommented. In the headerfile bootloader.h the new startaddress has to be defined as BOOTLOADER_START.

4.3.3.2 Alternative Interrupt Vector Table

Some space is needed in the bootloader section for the alternative interrupt vector table which is located from DF0214 - DF03D3 and is initialized in vectors.c. Normally the interrupt vector table is located at a fixed address, which will be erased and flashed with the main application and can’t be used here as boot loader interrupt vector table. In bootloader.h, VECTTABLE defines the alternative vector address, which can only be chosen by sector start address. If VECTTABLE is changed, this address must be manually changed also in vectors.c: #pragma section INTVECT=INTVECT_RELOCATED, locate=0xDF0000

4.3.3.3 RAMCODE Section

This section is needed for the flashing Process. To erase or write the Flash sections, during these processes code can only be executed in RAM. At bootloader start the RAMCODE is copied from Flash to RAM. (See linker settings chapter 6)

4.3.4 User Code Section In this section user code, data, etc. can be located. All data in the app.mhx which is linked to addresses lower than F80000 will be ignored by the flashing Process.

Page 13: mcu-an-300247-e-v10-16fx usb bootloader · (Flash Loader) Internal FLASH USB Host Interface USB Mass Storage MMC/SD Card Support Status Information ... a driver for data input and

USB / SD CARD BOOTLOADER Chapter 5 Bootloader Process

© Fujitsu Microelectronics Europe GmbH - 13 - MCU-AN-300247-E-V10

5 Bootloader Process

Bootloader Process

5.1 Boot Loader Process Order The bootloader starts with some initialisations: Before it handles its own start code, it checks for a valid reset vector and checks the power on state. If no valid boot vector exists, the microcontroller would execute not wanted undefined code. So if it does not exist, the bootloader will be started instead of the main application. If the “Power On” state was a reset, the main application will be started instead no valid boot vector exists. If the “Power On” state was power on, the bootloader starts don’t caring about the boot vector of the app.

After USB-initialisation the bootloader resets all USB functions and enumerates again a USB stick - if it is available - and tries to mount it. After a timeout of about 500ms the function gives up to find a valid USB mass storage and tries to find a valid MMC/SD card device. If neither USB stick nor MMC/SD card were found, the bootloader restarts in main application. If a USB stick or MMC/SD card was found, it will be checked whether a file app.mhx exists in root directory. If the file was found, the bootloader begins to erase all Flash sections except the bootloader Flash sections and flashes the main application from app.mhx.

Note: The Power-On Flag is reset by reading it by the bootloader. It is not available for the main application anymore.

(Power Cause: Power On) || (No Valid Reset Vector)

(Pow

erC

ause

:Res

et)&

&(V

alid

Res

etV

ecto

r)

Check forUSB-Stick

Start

Check forMHX File

found

Check forMMC/SDC

not found

Check forMHX File

not found

found

found

Nothing done

not found Erase Flash

found

Read File

and Flash it

not found

Check for Reset Vector

Reboot in

main app

System Halt

Display Error

found

not found

MMC/SDC Support

by default disabled

Page 14: mcu-an-300247-e-v10-16fx usb bootloader · (Flash Loader) Internal FLASH USB Host Interface USB Mass Storage MMC/SD Card Support Status Information ... a driver for data input and

USB / SD CARD BOOTLOADER Chapter 5 Bootloader Process

MCU-AN-300247-E-V10 - 14 - © Fujitsu Microelectronics Europe GmbH

The next code located in start.asm explains how the boot management is working. In section 6.3.1 the bootloader checks the cause of reset. If bit 0 of the RCCSRC register is set, the reset is a “Power On”. This is the condition to continue the bootloader at start2.

Section 6.3.2 is a post check before the main application starts. A valid reset vector is required to boot the main application. This condition is reached weather the boot vector is not 0xFFFFFFFF or 0x00000000. After passed test the main application will start. At start_mainapp the microcontroller will jump to the application reset vector 0xFFFFDC where the main application start address is defined.

;==================================================================== ; 6.3.1 BOOTLOADER: POWER ON CHECK, if restarted, goto main app ;====================================================================

MOV A,0x40B ; RCCSRC (Reset Cause Reg) AND A,#0x01 ; bit 0 Power Reset BNE start2 ; start bootloader

;==================================================================== ; 6.3.2 BOOTLOADER: Reset Vector OK?, goto main app ;====================================================================

MOVW A,0xFFFFDC ; read Resetvector CMPW A,#0x0000 ; compare empty BNE checkFF ; if not empty, start main-app MOVW A,0xFFFFDE ; read Resetvector CMPW A,#0x0000 ; compare empty BEQ start2 ; if empty, start bootloader

checkFF: MOVW A,0xFFFFDC ; read Resetvector CMPW A,#0xFFFF ; compare empty BNE start_mainapp ; if not empty, start main-app MOVW A,0xFFFFDE ; read Resetvector CMPW A,#0xFFFF ; compare empty BEQ start2 ; if empty, start bootloader

start_mainapp: JMPP @0xFFFFDC ; Resetvector

;==================================================================== ; 6.4 Initialisation of processor status ;==================================================================== start2:

;boot loader continues

Page 15: mcu-an-300247-e-v10-16fx usb bootloader · (Flash Loader) Internal FLASH USB Host Interface USB Mass Storage MMC/SD Card Support Status Information ... a driver for data input and

USB / SD CARD BOOTLOADER Chapter 5 Bootloader Process

© Fujitsu Microelectronics Europe GmbH - 15 - MCU-AN-300247-E-V10

5.2 Flash Process Before Flash can be written, it has to be erased. During the erase and write Process, the program part which handles the Flash routines has to be executed in RAM and all interrupts need to be disabled. But USB functions having the need of interrupts, so if there is the need to disable interrupts, it has to be synchronous to the USB functions interrupts. Unfortunately this is not really USB conform. USB conform would be to enumerate the USB stick again after turn on the interrupts, if necessary. To save time, data of the app.mhx file is read in 512 Byte blocks. Before a 512 Byte block is read, the interrupts will be enabled and the first USB interrupt is awaited. After read, one USB interrupt is awaited before interrupts will be disabled again.

Timing diagram:

USB IRQs

FLASH

IDLE/WAIT

DATA READ SYNC* FLASH DATA SYNC* DATA READ

Erase Init (Disable IRQs)

Read File: 512 bytes

Convert DATA

Enable Interrupts

Disable Interrupts

Convert DATA

Flash DATA

Flash DATA

Buffer empty

Read File: 512 bytes

Enable Interrupts

Disable Interrupts

Convert DATA

Convert DATA

Flash DATA

Main Flash File Read with Interrupts Flash Routines

Process from file app.mhx in RAM

Erase Flash

Buffer empty

*SYNC means synchronous disable/enable interrupts

Page 16: mcu-an-300247-e-v10-16fx usb bootloader · (Flash Loader) Internal FLASH USB Host Interface USB Mass Storage MMC/SD Card Support Status Information ... a driver for data input and

USB / SD CARD BOOTLOADER Chapter 5 Bootloader Process

MCU-AN-300247-E-V10 - 16 - © Fujitsu Microelectronics Europe GmbH

5.3 MHX Format Conversion

5.3.1 S-Record Structure The MHX Format is a Motorola-S-Record file, which has the ability to flash only used sections and leave sections, which are not used untouched. Each line represents a record. There are 10 different types of records (S0 – S9); however the mhx converter in the bootloader handles only the S2 type. The line is structured as followed:

5.3.1.1 Example: MHX Record

Data in S-Record: S209F8B0788C7625096640 Data in Flash after conversion: 0xF8B078: 76 8C 09 25 xx 66 xx = Data not changed

Start Code

Record Type

Byte Count

Address (3 Byte)

Data CRC

S 2 09 F8B078 8C76250966 40

Start-Code: Is every record line the first character and contains every time an “S”

Record-Type: Record Type (0-9), only 2 is supported

Byte-Count: Number of Bytes of record (Address + Data + CRC)

Address: Flash-Address (3 Bytes)

Data: Data to write at the specified address

CRC: Checksum

5.3.2 Even/Odd Data Lengths and Addresses Flashing is only available in words with even addresses, but the S-Record file also contains records with odd data-lengths and -addresses. Even data-lengths and even addresses can be handled by word access, odd data-lengths and odd addresses can only be handled in byte mode. To handle these problems, for odd data lengths and addresses 2 words has to be read: the data of the current even address and the next even address. The result is combined with logical AND and shift operations to realize half word write operations, which needs at the end 2 word read and 2 word write cycles, to write one word. After all, data from the mhx file also have to be byte swapped before it can be written into the internal Flash.

5.3.2.1 Example Odd Data Record:

Data in S-Record: S209F8B0788C7625096640

Data in Flash before conversion: 0xF8B078: FF FF FF FF AF FF Data in Flash after conversion: 0xF8B078: 76 8C 09 25 AF 66

Page 17: mcu-an-300247-e-v10-16fx usb bootloader · (Flash Loader) Internal FLASH USB Host Interface USB Mass Storage MMC/SD Card Support Status Information ... a driver for data input and

USB / SD CARD BOOTLOADER Chapter 5 Bootloader Process

© Fujitsu Microelectronics Europe GmbH - 17 - MCU-AN-300247-E-V10

5.3.2.2 Example: Odd Address Record

Data in S-Record: S207F8AF9B8C1E66A6

Data in Flash before conversion: 0xF8AF9A: AF FF FF FF

Data in Flash after conversion: 0xF8AF9A: AF 8C 66 1E

5.3.2.3 Example: Even Data and Even Address

Data in S-Record: S20CFFC35C453A205459504500F4

Data in Flash before conversion: 0xFFC35C: FF FF FF FF FF FF FF FF

Data in Flash after conversion: 0xFFC35C: 3A 45 54 20 50 59 00 45

Page 18: mcu-an-300247-e-v10-16fx usb bootloader · (Flash Loader) Internal FLASH USB Host Interface USB Mass Storage MMC/SD Card Support Status Information ... a driver for data input and

USB / SD CARD BOOTLOADER Chapter 6 Project Options for Bootloader

MCU-AN-300247-E-V10 - 18 - © Fujitsu Microelectronics Europe GmbH

6 Project Options for Bootloader

Project Options & Settings in Softune Workbench

6.1 Compiler Options To locate constants in the same Flash sectors the bootloader is located, the memory model has set to “large”. This can be done in Softune Workbench, menu “Project > Setup Project…”.

Select the tab “C Compiler” and choose in the category chooser “Target Depend”. Now there is the possibility to change the Memory Model to “large”.

6.2 Linker Options Linker Options can be done in “Project > Setup Project…”. Choose category “Disposition/Connection”:

Here _INROM01 and _INROM2 has to be swapped. This can be done by deleting both sections and setting them new by pressing the “Set…” button.

Page 19: mcu-an-300247-e-v10-16fx usb bootloader · (Flash Loader) Internal FLASH USB Host Interface USB Mass Storage MMC/SD Card Support Status Information ... a driver for data input and

USB / SD CARD BOOTLOADER Chapter 6 Project Options for Bootloader

© Fujitsu Microelectronics Europe GmbH - 19 - MCU-AN-300247-E-V10

At Last the RAMCODE and @RAMCODE Sections has to be added by pressing the “Set Section…” button. RAMCODE has to be added in _INRAM01 section, @RAMCODE has to be specified in „Specify in Address“. To locate the RAMCODE at flash 0xDF5C00 add the fields like it is shown. To add these entries press “Set”.

Page 20: mcu-an-300247-e-v10-16fx usb bootloader · (Flash Loader) Internal FLASH USB Host Interface USB Mass Storage MMC/SD Card Support Status Information ... a driver for data input and

USB / SD CARD BOOTLOADER Chapter 7 Timing

MCU-AN-300247-E-V10 - 20 - © Fujitsu Microelectronics Europe GmbH

7 Timing

Timing

For flashing 512KByte the bootloader takes about 9 seconds for erasing the sections and about 80 seconds for writing 512KByte of random data from a USB mass storage device (about 100 seconds with MMC/SDC). The initialisations taking about 1 seconds.

Programming random 512KB data via USB stick:

Complete bootloading process for writing 512KB random data (output via UART): ####################################### FUJITSU Microelectronics USB Bootloader #######################################

(!) unlocking FLASH (!) waiting for USB Device... USB-Stick found: app.mhx found. saving FIXBOOT-Vector if needed... erasing Flash... leaving sector: 0xDF0000 - BOOT-LOADER leaving sector: 0xDF2000 - BOOT-LOADER leaving sector: 0xDF4000 - BOOT-LOADER leaving sector: 0xDF6000 - BOOT-LOADER erasing sector: 0xF80000 erasing sector: 0xF90000 erasing sector: 0xFA0000 erasing sector: 0xFB0000 erasing sector: 0xFC0000 erasing sector: 0xFD0000 erasing sector: 0xFE0000 erasing sector: 0xFF0000 Flashing Program... ......................................................................................................................................................................................................................................................................FLASHED FINISHED, restarting now in main application... 3 2 1

Power On

Init Erase Flash (from USB)

End of Programming

Flash (from MMC/SD)

0s 1s 10s 90s 110s

Takes about 1 second

Takes about 9 seconds

Takes about 80 seconds (USB) Takes about 100 seconds (MMC/SD)

Page 21: mcu-an-300247-e-v10-16fx usb bootloader · (Flash Loader) Internal FLASH USB Host Interface USB Mass Storage MMC/SD Card Support Status Information ... a driver for data input and

USB / SD CARD BOOTLOADER Chapter 8 Appendix

© Fujitsu Microelectronics Europe GmbH - 21 - MCU-AN-300247-E-V10

8 Appendix

8.1 Bootloader Download Please download the newest version from http://mcu.emea.fujitsu.com/mcu_product/mcu_all_software.htm -> mb96330-usb_bootloader

8.2 USB Mass Storage Drivers For more information refer to appnote sk16fx144pmc_usb_host.

8.3 MMC/SD Card Drivers For more information refer to appnote 16fx_sd_card_interface.

8.4 FatFs Module (FAT, FAT16, FAT32 driver) For more information refer appnote sk16fx144pmc_usb_host and 16fx_sd_card_interface or visit the developer’s website: http://elm-chan.org/fsw/ff/00index_e.html