Skip to content

uBit.flash

Overview

Provides access to USB flash capabilities on the micro:bit.

API

getConfiguration

MicroBitUSBFlashConfig
getConfiguration
()

Description

Determines the filename, filesize and visibility of the USB file presented on the MICROBIT drive. note: This may query the USB interface chip via I2C, and wait for completion.

Returns

a configuration structure containing the current USB File interface confuguration.


setConfiguration

int
setConfiguration
(
MicroBitUSBFlashConfig
config)

Description

Updates the filename, filesize and visibility of the USB file presented on the MICROBIT drive. note: This will update the USB interface chip via I2C, and wait for completion.

Parameters

MicroBitUSBFlashConfig
config - the new configuration to write

Returns

DEVICE_OK on success, or error code.

int
setConfiguration
(
MicroBitUSBFlashConfig
config,
bool
persist)

Description

Updates the filename, filesize and visibility of the USB file presented on the MICROBIT drive. note: This will update the USB interface chip via I2C, and wait for completion.

Parameters

MicroBitUSBFlashConfig
config - the new configuration to write

bool
persist - true if the configuraiton should be permananet across device reset, false otherwise.

Returns

DEVICE_OK on success, or error code.


getGeometry

MicroBitUSBFlashGeometry
getGeometry
()

Description

Determines the physical blocksize and number of blocks available in the USB file storage. note: This may query the USB interface chip via I2C, and wait for completion.

Returns

a configuration structure containing the geeometry of the USB file storage area.


remount

int
remount
()

Description

Remounts the USB MICROBIT drive, if it is connected.

Returns

DEVICE_OK on success, or error code.


eraseConfig

int
eraseConfig
()

Description

Reset the KL27 Flash Storage configuration to its default settings.

Returns

DEVICE_OK on success, or error code.


read

ManagedBuffer
read
(
uint32_t
address,
uint32_t
length)

Description

Reads data from the specified location in the USB file staorage area.

Parameters

uint32_t
address - the logical address of the memory to read.

uint32_t
length - the number of 32-bit words to read.

Returns

the data read, or a zero length buffer on failure.


write

int
write
(
uint32_t
address,
uint32_t *
data,
uint32_t
length)

Description

Writes data to the specified location in the USB file staorage area.

Parameters

uint32_t
address - the location to write to

uint32_t *
data - a buffer containing the data to write

uint32_t
length - the number of 32-bit words to write

Returns

DEVICE_OK on success, or error code.


erase

int
erase
(
uint32_t
address,
uint32_t
length)

Description

Flash Erase one or more physical blocks in the USB file staorage area. n.b. this method will perform an ERASE operation on all physical memory blocks that are are part of the specified region.

If the specified region is not aligned to physical block boundaries as defined by the disks geometry, areas in an overlapping block outside the given range will be automatically read, erased and rewritten.

Parameters

uint32_t
address - the logical address of the memory to start the erase operation.

uint32_t
length - the number of 32-bit words to erase.

Returns

DEVICE_OK on success, or error code.


getFlashStart

uint32_t
getFlashStart
()

Description

Determines the logical address of the start of non-volatile memory region

Returns

The logical address of the first valid logical address in the region of non-volatile memory


getFlashEnd

uint32_t
getFlashEnd
()

Description

Determines the logical address of the end of the non-volatile memory region

Returns

The logical address of the first invalid logical address beyond the non-volatile memory.


getPageSize

uint32_t
getPageSize
()

Description

Determines the size of a non-volatile memory page. A page is defined as the block of memory the can be efficiently erased without impacted on other regions of memory.

Returns

The size of a single page in bytes.


getFlashSize

uint32_t
getFlashSize
()

Description

Determines the amount of available storage.

Returns

the amount of available storage, in bytes.


getFlashStart

uint32_t
getFlashStart
()

Description

Determines the logical address of the start of non-volatile memory region

Returns

The logical address of the first valid logical address in the region of non-volatile memory


getFlashEnd

uint32_t
getFlashEnd
()

Description

Determines the logical address of the end of the non-volatile memory region

Returns

The logical address of the first invalid logical address beyond the non-volatile memory.


getPageSize

uint32_t
getPageSize
()

Description

Determines the size of a non-volatile memory page. A page is defined as the block of memory the can be efficiently erased without impacted on other regions of memory.

Returns

The size of a single page in bytes.


getFlashSize

uint32_t
getFlashSize
()

Description

Determines the amount of available storage.

Returns

the amount of available storage, in bytes.


read

int
read
(
uint32_t *
dest,
uint32_t
source,
uint32_t
size)

Description

Reads a block of memory from non-volatile memory into RAM

dest

The address in RAM in which to store the result of the read operation

source

The logical address in non-voltile memory to read from

size

The number 32-bit words to read.

Parameters

uint32_t *
dest - The address in RAM in which to store the result of the read operation

uint32_t
source - The logical address in non-voltile memory to read from

uint32_t
size - The number 32-bit words to read.


write

int
write
(
uint32_t
dest,
uint32_t *
source,
uint32_t
size)

Description

Writes a block of memory to non-volatile memory.

dest

The logical address in non-voltile memory to write to

source

The address in RAM of the data to write to non-volatile memory

size

The number 32-bit words to write.

Parameters

uint32_t
dest - The logical address in non-voltile memory to write to

uint32_t *
source - The address in RAM of the data to write to non-volatile memory

uint32_t
size - The number 32-bit words to write.


erase

int
erase
(
uint32_t
page)

Description

Erases a given page in non-volatile memory.

page

The address of the page to erase (logical address of the start of the page).

Parameters

uint32_t
page - The address of the page to erase (logical address of the start of the page).


Component Constructor

Advanced users only

Do not use this unless you really know what you're doing. It's usually best to use uBit.

MicroBitUSBFlashManager(
MicroBitI2C &
i2c,
MicroBitIO &
ioPins,
MicroBitPowerManager &
powerManager)

Description

Constructor. Create a software abstraction of a USB Flash manager.

i2c

the I2C bus to use to communicate with the micro:bit USB interface chip

ioPins

the IO pins in use on this device.

id

the unique EventModel id of this component. Defaults to: MICROBIT_ID_USB_FLASH_MANAGER

Parameters

MicroBitI2C &
i2c - the I2C bus to use to communicate with the micro:bit USB interface chip

MicroBitIO &
ioPins - the IO pins in use on this device.

MicroBitPowerManager &
powerManager

MicroBitUSBFlashManager(
MicroBitI2C &
i2c,
MicroBitIO &
ioPins,
MicroBitPowerManager &
powerManager,
uint16_t
id)

Description

Constructor. Create a software abstraction of a USB Flash manager.

i2c

the I2C bus to use to communicate with the micro:bit USB interface chip

ioPins

the IO pins in use on this device.

id

the unique EventModel id of this component. Defaults to: MICROBIT_ID_USB_FLASH_MANAGER

Parameters

MicroBitI2C &
i2c - the I2C bus to use to communicate with the micro:bit USB interface chip

MicroBitIO &
ioPins - the IO pins in use on this device.

MicroBitPowerManager &
powerManager

uint16_t
id - the unique EventModel id of this component. Defaults to: MICROBIT_ID_USB_FLASH_MANAGER