Git Product home page Git Product logo

mbed-os-example-fat-filesystem's Introduction

Obsolete

The following application has superseded this repository:

Getting started with the FAT file system on Mbed OS

This guide reviews the steps to get the FAT file system working on an Mbed OS platform.

Please install Mbed CLI.

Hardware requirements

This example uses a RAM-backed FAT file system. The FAT file system requires at least 128 512-byte blocks for a total of 64KB of space. The HeapBlockDevice, which uses a target's heap for storage, backs this space. Therefore, to support this example, a target must have at least 64KB of space usable by as heap. Because there is more than just the heap in a device's RAM, this translates to the requirement that a target's RAM must be at least 96KB large.

Import the example application

From the command-line, import the example:

mbed import mbed-os-example-fat-filesystem
cd mbed-os-example-fat-filesystem

Now compile

Invoke mbed compile, and specify the name of your platform and your favorite toolchain (GCC_ARM, ARM, IAR). For example, for the ARM Compiler 5:

mbed compile -m K64F -t ARM

Your PC may take a few minutes to compile your code. At the end, you see the following result:

[snip]
+--------------------------+-------+-------+-------+
| Module                   | .text | .data |  .bss |
+--------------------------+-------+-------+-------+
| Fill                     |   164 |     0 |  2136 |
| Misc                     | 54505 |  2556 |   754 |
| drivers                  |   640 |     0 |    32 |
| features/filesystem      | 15793 |     0 |   550 |
| features/storage         |    42 |     0 |   184 |
| hal                      |   418 |     0 |     8 |
| platform                 |  2355 |    20 |   582 |
| rtos                     |   135 |     4 |     4 |
| rtos/rtx                 |  5861 |    20 |  6870 |
| targets/TARGET_Freescale |  8382 |    12 |   384 |
| Subtotals                | 88295 |  2612 | 11504 |
+--------------------------+-------+-------+-------+
Allocated Heap: 24576 bytes
Allocated Stack: unknown
Total Static RAM memory (data + bss): 14116 bytes
Total RAM memory (data + bss + heap + stack): 38692 bytes
Total Flash memory (text + data + misc): 91947 bytes

Image: ./BUILD/K64F/gcc_arm/mbed-os-example-fat-filesystem.bin

Program your board

  1. Connect your Mbed device to the computer over USB.
  2. Copy the binary file to the Mbed device.
  3. Press the reset button to start the program.
  4. Open the UART of the board in your favorite UART viewing program. For example, screen /dev/ttyACM0.

Note: The default serial port baud rate is 9600 bit/s.

You see the following output:

Welcome to the filesystem example.
Formatting a FAT, RAM-backed filesystem. done.
Mounting the filesystem on "/fs". done.
Opening a new file, numbers.txt. done.
Writing decimal numbers to a file (20/20) done.
Closing file. done.
Re-opening file read-only. done.
Dumping file to screen.
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
EOF.
Closing file. done.
Opening root directory. done.
Printing all filenames:
  numbers.txt
Closeing root directory. done.
Filesystem Demo complete.

Switch from RAM backed block device to an SD card

From the command-line, run the following command:

mbed add sd-driver

Then change the code on line 3 of main.cpp to import the SD card header:

#include "SDBlockDevice.h"

Change the block device declaration on line 7 of main.cpp to use the SD card by replacing the PinNames with the pins connected to the SD card:

SDBlockDevice bd(PinName mosi, PinName miso, PinName sclk, PinName cs);

Troubleshooting

If you have problems, you can review the documentation for suggestions on what could be wrong and how to fix it.

mbed-os-example-fat-filesystem's People

Contributors

0xc0170 avatar adbridge avatar bogdanm avatar iriark01 avatar jaustin avatar kegilbert avatar marcelosalazar avatar mlnx avatar sg- avatar theotherjimmy avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

mbed-os-example-fat-filesystem's Issues

File write and read back errors

Using this example project with small modifications, file writes fail after several kilobytes.

Please checkout my branch which demonstrates the error:
https://github.com/bmcdonnell-ionx/mbed-os-example-fat-filesystem/tree/demo-error

(You'll have to direct your serial output, or grab my demo-err-usbserial branch if you're also using the EA LPC4088-QSB.)

Details are in the code comments, also quoted below. I don't know if there's any relation to the micro I'm using, but it's noted here in case there is.

// Failures using NXP LPC4088 micro, on Embedded Artists' LPC4088 QuickStart Board:
//
// - With mbed online compiler, 2017-12-08 (armcc):
//   - error writing at line 5974 (~35 KiB)
//   - file readback ends early after line 5888 (~512 bytes fewer)
//
// - With NXP MCUXpresso IDE v10.1.0 [Build 589] [2017-11-14]
//   (gcc-arm-none-eabi):
//   - error writing at line 4779 (~28 KiB)
//   - file readback ends early after line 4608 (~1 KiB fewer)

// 6 characters per line (4 digits + "\r\n")
// * 10000 lines = 60 KB, should fit on 128 * 512 = 64 KiB block device
#define NUM_INTS         (10000)
#define FIELD_WIDTH_STR  "4"

HeapBlockDevice bd(128 * 512, 512);

Format returns -9 error code

Description

  • Type: Bug
  • Priority: Critical

Bug

Target
K64F

Toolchain:
GCC_ARM, ARM

Toolchain version:

mbed-cli version:
1.1.1

mbed-os sha:
f4274b4 (HEAD, tag: mbed-os-5.7.0-rc3) Updating mbed-os to mbed-os-5.7.0-rc3

DAPLink version:

Expected behavior
Formatting and mounting works without errors.
Also printing should work.
Actual behavior
Formatting returns error code -9.
Printing does not work.
Steps to reproduce
run example

[oob-5.4-rc1] Build failed by online compiler

How to reproduce

  1. Open online IDE
  2. Press [Import] button
  3. URL import
  4. Source URL: https://github.com/ARMmbed/mbed-os-example-fat-filesystem
  5. Change mbed-os version to #3a27568 (origin/mbed-os-5.4)
  6. Set any target
  7. Build the project
Error: Cannot open source input file "FATFileSystem.h": No such file or directory in "main.cpp", Line: 2, Col: 28

[oob 5.4] Executing IAR compiled binary on max32620 fills up dynamic memory

ERROR:

Welcome to the filesystem example.
Formatting a FAT, RAM-backed filesystem. Failure. -5
Mounting the filesystem on "/fs". done.
Operator new out of memory
Opening a new file, numbers.txt.mbed assertation failed: obj->name != (PinName)NC, file: C:\Repos\mbed-os-example-fat-filesystem\mbed-os\targets\TARGET_Maxim\TARGET_MAX32620\gpio_object.h, line 1852402720

Not getting full log output K66F

I've tried this a few times on a K66F and had mixed results. I often just get:

Welcome to the fWelcome to the filesystem example.
Formatting a FAT, RAM-backedly. done.
Dumping file to screen.
0
1
2
3

..and then I need to reflash the board and reopen the terminal to get any output again. This is usually the same, but I did once get up to 'EOF'. Other mbed boards I've used have printed to terminal correctly, so I doubt it's an issue with serial. I'm compiling on Win10, and used both arm and gcc_arm compilers. Tried both tera term and putty for terminal.

Errors from "make" (after make_iar export)

After running this command: mbed export -i make_iar -m K66F I receive no errors. However, when I run make (on Windows using GnuWin32 make) I receive the following errors:

$ make
C:/Repos/mbed-os-example-fat-filesystem/makefile:569: warning: overriding commands for target `.s.o'
C:/Repos/mbed-os-example-fat-filesystem/makefile:564: warning: ignoring old commands for target `.s.o'
"link: mbed-os-example-fat-filesystem.elf"

   IAR ELF Linker V7.80.1.11864/W32 for ARM
   Copyright 2007-2016 IAR Systems AB.
Error[Li005]: no definition for "_printf_percent" [referenced from
          C:\Repos\mbed-os-example-fat-filesystem\BUILD\main.o]
Error[Li005]: no definition for "_printf_d" [referenced from
          C:\Repos\mbed-os-example-fat-filesystem\BUILD\main.o]
Error[Li005]: no definition for "_printf_int_dec" [referenced from
          C:\Repos\mbed-os-example-fat-filesystem\BUILD\main.o]
Error[Li005]: no definition for "_printf_s" [referenced from
          C:\Repos\mbed-os-example-fat-filesystem\BUILD\main.o]
Error[Li005]: no definition for "_printf_str" [referenced from
          C:\Repos\mbed-os-example-fat-filesystem\BUILD\main.o]
Error[Li005]: no definition for "__2printf" [referenced from
          C:\Repos\mbed-os-example-fat-filesystem\BUILD\main.o]
Error[Li005]: no definition for "__2fprintf" [referenced from
          C:\Repos\mbed-os-example-fat-filesystem\BUILD\main.o]
Error[Li005]: no definition for "__stdout" [referenced from
          C:\Repos\mbed-os-example-fat-filesystem\BUILD\main.o]

   59 940 bytes of readonly  code memory
    6 814 bytes of readonly  data memory
  109 056 bytes of readwrite data memory

Errors: 8
Warnings: none

Link time:   0.48 (CPU)   0.53 (elapsed)
make[1]: *** [mbed-os-example-fat-filesystem.elf] Error 2
make: *** [all] Error 2

[OoB_5.5.0-RC2]: NUCLEO_F746ZG, make_armc5: Build failure.

Steps:

  1. Update to RC2 branch.
  2. mbed export -i make_armc5 -m NUCLEO_F746ZG
  3. make clean
  4. make

Expected: Successful build.
Actual: Build failure with following error:

"Compile: mbed_boot.c"
"Compile: rtos_idle.c"
"Compile: cmsis_os1.c"
"Compile: RTX_Config.c"
"Assemble: irq_cm4f.s"
"../mbed-os/rtos/rtx5/TARGET_CORTEX_M/TARGET_RTOS_M4_M7/TOOLCHAIN_ARM/irq_cm4f.s", line 69 (column 8): Error: A1163E: Unknown opcode __FPU_PRESENT , expecting opcode or Macro
   69 00000030 #ifdef __FPU_PRESENT
                      ^
"../mbed-os/rtos/rtx5/TARGET_CORTEX_M/TARGET_RTOS_M4_M7/TOOLCHAIN_ARM/irq_cm4f.s", line 75: Error: A1167E: Invalid line start
   75 0000003c #endif
"../mbed-os/rtos/rtx5/TARGET_CORTEX_M/TARGET_RTOS_M4_M7/TOOLCHAIN_ARM/irq_cm4f.s", line 79 (column 8): Error: A1163E: Unknown opcode __FPU_PRESENT , expecting opcode or Macro
   79 00000040 #ifdef __FPU_PRESENT
                      ^
"../mbed-os/rtos/rtx5/TARGET_CORTEX_M/TARGET_RTOS_M4_M7/TOOLCHAIN_ARM/irq_cm4f.s", line 82: Error: A1167E: Invalid line start
   82 0000004a #endif
"../mbed-os/rtos/rtx5/TARGET_CORTEX_M/TARGET_RTOS_M4_M7/TOOLCHAIN_ARM/irq_cm4f.s", line 95 (column 8): Error: A1163E: Unknown opcode __FPU_PRESENT , expecting opcode or Macro
   95 0000005e #ifdef __FPU_PRESENT
                      ^
"../mbed-os/rtos/rtx5/TARGET_CORTEX_M/TARGET_RTOS_M4_M7/TOOLCHAIN_ARM/irq_cm4f.s", line 98: Error: A1167E: Invalid line start
   98 00000068 #endif
6 Errors, 0 Warnings
make[1]: *** [mbed-os/rtos/rtx5/TARGET_CORTEX_M/TARGET_RTOS_M4_M7/TOOLCHAIN_ARM/irq_cm4f.o] Error 1
make: *** [all] Error 2

C:\Ashok\mbed_CLI\OoB_5_5\Filesystem\mbed-os-example-fat-filesystem>

SHA's:
mbed-os-example-fat-filesystem (2e5f21f)
`- mbed-os (162f80099d94)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.