Piconomic FW Library  0.4.1
Cross-platform embedded library and documentation for 8/16/32-bit microcontrollers
Piconomic FW Library Documentation

About

piconomic-fwlib is a collection of C firmware and documentation for microcontrollers that proposes a unified approach so that code can be developed that is vendor and architecture independent (or easier to reuse). It is tough to find the best compromise between lean 8-bit targets, middle-of-the-road 16-bit targets, and resource rich 32-bit targets, but this cross-platform library aims to provide a good start before you are forced to add target specific code and getting locked in.

The library (source code and offline documentation) can be downloaded here.

My sincere hope is that seasoned veterans will pitch in and share their years of experience to mentor the future generations and raise the bar in terms of quality and quantity. See Feedback, bug fixes and code and documentation contributions .

Goals

  • Provide a standard framework and drivers for rapid code development.
  • Minimize porting by providing unified peripheral driver APIs (maximize device driver reuse).
  • Publish concise quick start guides and tutorials to reduce the learning curve of new microcontrollers.
  • Share source code, knowledge and expertise with our global community of engineers, scientists and enthusiasts.
  • Recommend good firmware development practices.

Evolution

Great athletes spend years tweaking tiny aspects of their performance to get a competitive edge: bicycle riders adapt their posture in a wind tunnel, golfers analyse their swing,... Like the shark became the apex predator of the sea, we as coders must be inspired to evolve and perfect our art or wither.

Without mentorship, we tend to get stuck with the first coding style and programming patterns that we learned and keep on using it without a second thought, sometimes even justifying and defending it religiously.

After you have written a piece of code, take a break, return and spend 15 minutes to question if the code you have just written is the optimal / best / most readable solution (applying advice from Edward de Bono, the father of lateral thinking). Refactor, rinse, repeat. Next time you will use this improved snippet instead of copying and adapting the same old, inferior code from memory.

Ask yourself: which is better?

// Small fixed delay
for(i=0; i<100; i++)
{
__asm__ __volatile__("nop \n\t"::);
}

Or

// Small fixed delay
for(i=100; i!=0; i--)
{
__asm__ __volatile__("nop \n\t"::);
}

Inspect the assembly generated by the compiler...

Evolve, improve or be left behind!

Editor

As artisans that code for food, we must buy and use the BEST editor, like SlickEdit, not the low budget / free one that we got used to. Think it through! If you use an editor every day to ply your trade and a better editor saves you just 5 - 15 minutes a day, then it will be the best personal tool investment you ever made and it will give you a legal edge over your colleagues and competitors. Don't just gloss over this advice, try the evaluation version for the whole 30 days and then make your decision. I am confident that SlickEdit will make a massive improvement in your productivity!

I have been discovering and using cool SlickEdit features since 1999.

Sections

This documentation is divided into the following sections:

Links

License

A BSD license was modified and applied to promote and maximize adoption of the library and grant freedom to develop open or closed source (commercial) applications. Please familiarize yourself with the conditions of the license: The Piconomic FW Library Open License

A significant amount of time and effort has been invested to create, publish and refine this library. Respect the license conditions!

To comply with clause 3, the following text and URL must be added to all internet publications (including advertisements) of your project or product:

Uses Piconomic FW Library <http://www.piconomic.co.za>

A single developer commercial license or company commercial license can be purchased which will grant you or your company an exemption from clause 2 and 3 of the The Piconomic FW Library Open License. The proceeds will be used for the continuous development and refinement of this library, hosting costs, etc. For more information see The Piconomic FW Library Commercial License.

CLICK HERE TO VISIT THE SHOP

Examples

Here are three select examples to pique your interest:

Atmel AVR GPIO

This example demonstrates how easy it is to define and use a GPIO pin:

#include "gpio.h"
// LED is on PORT B, pin 2, configured as an output, initally off
#define GPIO_LED GPIO(B, 2, GPIO_DIR_OUT, GPIO_INIT_LO)
// Push Button is on PORT B, pin 0, configured as an input, pull-up enabled
#define GPIO_PB GPIO(B, 0, GPIO_DIR_IN, GPIO_INIT_PULLUP)
int main(void)
{
#if 1
// Initialise group of pins
#else
// Initialise pins individually
#endif
for(;;)
{
// Is button being pressed?
{
// Enable LED
}
else
{
// Disable LED
}
}
}

Even though it appears that functions calls are used, the lines reduce to single assembly statements for maximum efficiency and minimum code size:

// Enable LED
8c: 2a 9a sbi 0x05, 2 ; 5

Atmel AVR UART

This example demonstrates how easy it is to set up and use a UART peripheral. After the set up phase (using architecture specific options), the driver is abstracted and the same code can be used on different architectures:

#include "uart.h"
#include "common/compiler.h"
static uart_handle_t uart_handle;
int main(void)
{
u8_t data;
// Initialise modules
// Enable interrupts
interrupts_enable();
// Open UART0 @ 115200 BAUD, 8 data bits, no parity, 1 stop bit
uart_handle = uart_open2(0,
115200,
UART_DATA_BITS_8,
UART_PARITY_NONE,
UART_STOP_BITS_1);
// Select UART0
uart_select(uart_handle);
for(;;)
{
// Wait until a byte is received
if(uart_rd_u8(&data))
{
// Send back received byte (loopback/echo mode)
uart_wr_u8(data);
}
}
}

CLI (Command Line Interpreter)

This example demonstrates a Command Line Interpreter interfacing with a ANSI/VT100 terminal emulator.

tera_term_cli.png
CLI Demo on Tera Term (Terminal Emulator)

Defining commands and using the CLI module is easy (I hope)

Feedback, bug fixes and code and documentation contributions

I strive for coding excellence and appreciate any constructive criticism, bug fixes, spelling or grammar improvements (Afrikaans is my 1st language), new code or better documentation that will improve and expand this library. At the moment it is supported in my free time (after work, family, friends, sport, ...) so please use your discretion when contacting me and be economical. For example:

Here is a bug fix patch generated with TortoiseSVN that fixes the "counter 
roll-over" bug in "counting_sheep.c".

P.S. I love your library, even my wife gives it a thumbs up!

Methods of communication:

Please do not feel offended if I do not respond. It may just be that I finally figured out how to build a time machine and am immersed in that or spending some nice vacation time in 1992...

For consideration, your code or bug fix patch must:

To be clear: when you submit anything, you also give me explicit permission to sell an exemption to clause 2 and 3 of The Piconomic FW Library Open License and use the funds to take over the WORLD! Bwah Ha Ha!! Ahem...

Share and Enjoy!

Author

pieter_conradie.jpg
Pieter Conradie
Kom ons praat weer Afrikaans,
laat ons kinders dans,
loshande hang oor die krans
met onverbeterlike balans.
Kom ons vat die kans.
Kom ons praat weer Afrikaans! 

-- Diana Ferrus --