Thursday, February 20, 2014

eBible on Cortex M0 with mbed

The eBible code has been ported from to use a Cortex M0 device and external flash chip.  The original chip used an M3 with lots of flash and SRAM, but this M0 part (NXP LPC1114FN28) has only 32Kbytes flash and 4Kbytes SRAM.

The challenge was to reduce and rewrite the functionality using less resources.  The M3 solution had used an SD card with FAT filesystem and had access to 512Kbytes flash and 64Kbytes SRAM.  All that was originally required was the bible.txt file on the SD, and the firmware would index all the books, chapters, and verses for navigation into multiple files on the SD card the first time it ran.  The M3 had no problem loading large sections of the text into memory to parse it into verses.  The M0 with its limited resources has less capability.

The M0 version does not use a file system, so the Bible text and index data are stored sequentially in flash storage (Spansion S25FL164K).  The index data structure is a sequence of structures for books, then intermixed with structures for chapters and verses.  The structures include text offsets, counts, and variable sized arrays pointing to other structures.  A fixed offset to the index structure, and bookmark structure is included in the code.  A separate firmware program for the M3 was written to convert the SD text and indexes and store them in flash.  This program was run once on the M3 to populate the flash chip, then the flash chip was moved to the M0 circuit.

Two different SPI circuits are present with one for the display and one for the flash.  The M0 chip used only has one SPI peripheral, so software SPI (bit banged) was implemented (ported from my C# implementation) to simulate another SPI peripheral.

A Text LCD wrapper library targeting Nokia 5110 was written to reduce the number of changes to the eBible source in porting from a text only lcd to the graphical Nokia 5110 lcd.

The remaining portions of the circuit to mention are the 3.3V voltage regulator (Microchip MCP1702), Nokia 5110 LCD display (purchased on eBay from a seller in Shenzhen, China), two switches, three blue LEDs, three AAA batteries, a battery holder, and some sockets.  A surface mount prototyping adapter board (SO8-50-EB) was used to attach the flash memory.  Two screws secure the battery holder to the circuit board.  The outside LEDs mirror the button presses, and the center LED flashes when bookmarks are changed when holding down both buttons.  Pressing the left button goes back one screen of text, and the right button advances to the next screen of text or next verse whichever comes first.  Holding down the buttons for a time navigates back or forward by multiple verses, chapters, or books depending on how long they are held down.  While navigating large sections of text, the book name, chapter number, and verse number are displayed, then switch back to the text after the buttons are released.

The parts chosen were primarily with consideration of cost.  The memory, display, and microcontroller are mbed online compiler and mbed library.  For debugging, the code was simply exported from the online compiler to Keil uVision 4 using a SeeedStudio Arch to act as the CMSIS-DAP debugger and programmer.  Being able to use a full-featured IDE including debugger for an mbed target is greatly appreciated.  Most of the work was done with the components in a breadboard, then transferred to a solder prototyping breadboard.  The result is a handheld electronic Bible that is smaller and more cost efficient that the originally developed version.
Schematic

1 comment:

  1. I would need to learn a bit about the IC you used, and we'll be good to go.and David! your http://www.intimeessay.com/ is really demonstrative and easy to understand. Keep it up!

    ReplyDelete