If you MQX application requires to download some data through network (via FTP, TFTP) or from serial line, the standard way is to use MFS on top of a device where the data will be stored.
However, in most situations, a real filesystem support with paths + filenames is not required.
If you just need a place where to store the data downloaded with standard MQX shell commands, a simple buffer driver will have a smaller footprint than MFS.
And if you have a microcontroller without external memory devices, you would probably be interested in using a part of your internal flash for the buffer (the free part not used by your application code). The raw downloaded data can later be read easily from flash at buffer base address.
Here is sample code to implement such a buffer in internal flash. It has been used with MQX3.4 on MCF52259, but should be OK on other chips supported by the flashx driver.
To use it :
- place this code in your application source tree (or in the BSP but it's not mandatory)
- make sure to enable the flashx driver in the BSP as the buffer driver use it (to further reduce memory footprint, some simple CPU specifc erase and write functions can be written instead of using flashx)
- modify your BSP intflash.lcf linker file to define the area of flash manageable by flashx. To define all flash :
___FLASHX_START_ADDR = ___INTERNAL_FLASH_BASE;
___FLASHX_END_ADDR = ___INTERNAL_FLASH_BASE + ___INTERNAL_FLASH_SIZE - 1;
- change FLASH_BUFFER_OFFSET, FLASH_BUFFER_SIZE and FLASH_SECTOR_SIZE in the source to your needs. Make sure not to overwrite your application code (buffer offset is the onerelated to the area managed by flashx).
- install the flash buffer driver by calling io_flashbuf_install(). This creates a "buffer:" device
- to use it; for examle in FTP client : get remotefilename buffer:
The buffer is entirely erased when "buffer:" is open, then filled with write to the device, seek is also support.ed.
The flashx driver is open when "buffer:" is open. This is not very clean (better to open flashx then to pass the FILE_PTR to __io_flashbuf_install()), but this has the advantage to keep flashx unused until buffer is open by a shell command.
However no problem should occur as only one open of buffer: is allowed at a given time.