Hackaday Badge Data Storage
The PIC32 chip at the heart of Hackaday Belgrade 2018 badge has a fixed program memory for storing machine code. There's also a pool of random access memory for program data during execution. But what happens to user data? It wouldn't belong in fixed code memory, and if it is kept in RAM it would be lost when the battery is removed.
The answer is a small block of nonvolatile memory that the user can read and write but would also maintain their data when the chip is shutdown or reset. It is a little chip with eight legs that sit to the right of the main PIC32 processor who has many more than eight legs.
A comment block in badge_settings.h outlines how this flash memory storage is allocated by the default badge firmware:
/*
* FLASH organization is as follows
* 0x000000-0x003FFF - first slot
* 0x004000-0x007FFF - second slot
* ...etc
* 0x03C000-0x03FFFF - 16-th slot
* 0x040000-0x07FFFF - empty space
* 0x080000-0x0FFFFF - D disk of CP/M machine
*/
The slots refer to BASIC program storage, where users can load from and save to up to sixteen BASIC programs, up to 16 kilobytes each. (BPROG_LEN
) These 16 slots * 16 kilobytes takes up the first 256 kilobytes of flash memory. (0x00000-0x3FFFF
) The second 256 kilobytes (0x040000-0x07FFFF
) are unclaimed and available for custom user programs to use. The 512 kilobytes that follow (0x080000-0xFFFFF
) is exposed as drive D: of the Z80 emulator running CP/M.
Custom user programs that wish to access that 256 kilobytes of unclaimed flash memory can access that space by referencing the code used to load and save BASIC programs. Flash memory can be read from, written to, and erased using the fl_*
series of functions in hwz.c. See basic_save_program
and basic_load_program
in badge.c.
If a custom user program needs more than the available 256 kilobytes of flash memory, it'd have to take away from some one else... or does it? There's one piece of mystery at hand. The memory allocation described above (256 kilobytes for BASIC, 256 kilobytes unclaimed, 512 kilobytes for CP/M drive D) add up to 1 megabyte. Is that all of flash storage?
Yes. No. Maybe.
The schematic and silkscreen on the Belgrade badge both name the flash chip as MX25V1635F. The datasheet for this chip indicates it has 2 megabyte capacity. However, the number actually printed on the chip is AT25DF081A, which is a 1 megabyte chip. The chip identity was confirmed by the badge Bill of Materials on Findchips.
But for the Hackaday Superconference badge, the flash chip is quoted to be a Microchip SST26VF016BT, which is a 2 megabyte chip. Maybe we'll have a second megabyte of flash to play with at Supercon!