Use internal flash as a buffer to download data to MQX with FTP,TFTP ...

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Use internal flash as a buffer to download data to MQX with FTP,TFTP ...

1,903 Views
trailman
Contributor V

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.

 

5 Replies

606 Views
trailman
Contributor V

Here is a new version of the buffer driver supporting S-record format and download through serial line.

 

If the data is in S-record format (.S19) it is automatically on-the-fly converted to binary (smaller) before beeing written to the buffer and its checksum is verified (using S-record internal sums).

 

The data can be loaded in the buffer as follows :
*   - using buffer: as target device; for example with FTP using the following FTP command : get filename buffer:
*   - or though serial line by using the Shell_flash_buffer_tty_load() provided  the buffer driver code

 

See comments in code for more infos on how to use it.

 

This software is provided "as is" without any warranty. Use it at your own risk as you want.

0 Kudos

606 Views
artur73
Contributor I

Hi,

Can you publish the code here?

Thanks.

0 Kudos

606 Views
trailman
Contributor V

Hi,

The attachment has been lost, lease find it again below.

Gilles

0 Kudos

606 Views
trailman
Contributor V

NOTE : should work on any processor on which the flashx driver is supported (flashbuf uses flashx to access internal flash)

0 Kudos

606 Views
trailman
Contributor V

Please also note that this buffer has been designed to download some data, so only open(), write() and seek() have been implemented (the calls used by a software downloading some data such as FTP or TFTP).

Read() is NOT implemented : once downloaded, the data can be directly read from the internal flash at the buffer's base address (FLASH_READ_BASE_ADDRESS + FLASH_BUFFER_OFFSET)

Also to prevent network timing issues when downloading from network or serial line, the buffer must be erased before starting downloading, not while downloading. So to make it simple the buffer is erased at open().

If upload is also required, the read() should be implemented, and the erase should be removed from open() and run separately (to prevent from uploding blank data).

0 Kudos