You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mynewt.apache.org by Fabio Utzig <ut...@utzig.org> on 2017/01/19 12:17:16 UTC

Adding support for an external SPI flash (AT45DB)

Hi,

Just opened a new PR
(https://github.com/apache/incubator-mynewt-core/pull/162) that adds
support for the AT45DB321 SPI flash. AFAIK this AT45DB series consists
of chips supporting 16, 32 and 64Mb (321 is 32Mb!). The size is still
hardcoded so only DB321 for now. Also got NFFS working on this flash
with some minor tweaks!

One important change not directly related to this flash model itself, is
that the hal_flash calls now receive a pointer to their own hal_flash
struct as the first parameter. This was not required before because only
the internal flash of the MCUs was being used and it didn't need any
"configuration", state, etc, because there was always only a single
instance with fixed parameters. To use external memories, extra
information is required when wanting to support more than one chip, to
know what bus it is connected to, what is the bus configuration, its own
configuration, etc. Since I'm using STM32F4-Discovery for the tests I
only updated that MCU and still need to update the other BSP/MCUs.

NFFS still lacks support for more than one device at any time and
doesn't seem to be a "piece of cake" to fix, due to the amount of
internal global state. To get NFFS working on the AT45DB I changed the
FLASH_AREA_NFFS device to 1 in pkg.yml, initialized a pointer to the
hal_flash struct as NULL to not start automatically on hal_flash_init,
updated hal_bsp_flash_dev to return this pointer and initialized it
manually later at the end of hal_bsp_init. This is required mostly due
to requiring manual SPI configuration, etc.

Also I'm using hw/drivers/flash as root of the "flash" drivers. The name
is maybe no appropriate because many chips are not proper "flash" but
eeprom, nvram, etc. Usually the name MTD is used for that (Memory
Technology Devices).

Also I chose to create the device specific structure as a "superset" of
struct hal_flash which means that the first field of the more
specialized struct (at45db_dev) has a hal_flash struct as its own first
field. I'm considering changing it so that hal_flash as an extra pointer
field, something like "device_priv" or similar that points to whatever
extra data the needs...

Anyway, still needs some polish but a good start I think!

Cheers,
Fabio Utzig