Where is my RAM?

I know there are gobbles of RAM in a PIC32 (more than the entire FLASH bank in most other PIC16/18… ) but RAM is one of those things in life you can never have enough of!

Plus, I am an 8-bitter by education, as I have already acknowledged before, and having spent most of my professional life working on microcontrollers with very limited resources, I am very sensitive to waste and waste of RAM in particular.

If you check the memory gauges in MPLAB, even an empty PIC32 program with no function calls and practically no code at all in the main(), will give you a minimum memory usage of 1.5K bytes of RAM. To me that’s huge! I need to know where all this RAM is going and how I can control it should I need it all!

The mystery is easily solved, if you look at the .map file, it shows that 1k byte of that RAM is just the default amount “reserved” for the stack.  As we have seen before (the stack so misunderstood…) the way MPLAB manages the stack memory allocation is a bit tricky. By the way, that memory is not literally allocated, nor the SP register is affected directly, but this number is used at compile time, only once, to check if , after allocating all the global variables and the heap (if there is one), there is still room for the requested amount of stack. So it shows in the memory gauges, but it is not representing by any means the “real” amount of RAM that will be used by your application stack, nor the maximum amount available. In fact the stack will take all the memory left and some… if it needs to.

But where is the other 1/2k byte of RAM gone?

Continue reading

Posted in PIC32, Tips and Tricks | 1 Comment

Olimex PIC-P32MX board

And the PIC32 demo boards saga cannot be complete until we mention the Olimex PIC-P32MX

Olimex PIC32MX

This board is interesting and unique for a couple of good reasons:

  • It offers a traditional serial port instead of the USB interface
  • It ‘s the most convenient for a quick wire wrap job
  • Offers both ICD and JTAG connectors
  • It’s most probably the cheapest of them all at Euro 19.95!
Posted in PIC32, Tools | 1 Comment

A Great New Board from mikroElektronika

The guys at mikroElektronika are very well known in the embedded and educational world for their large but inexpensive and well laid out boards for all PIC products. So I had been waiting quite anxiously for their first PIC32 specific board, and here it is!

The LV32MX Development Board

LV32MX

Continue reading

Posted in PIC32, Tools | Comments Off on A Great New Board from mikroElektronika

A new PIC32 Stick

PIC32 Stick

There is a new third party tool available for the PIC32 … it’s a stick!

I love sticks because they are easy to handle, expand, connect. They fit on good old breadboards and wire wrap (perforated) boards.

The guys at eFlightWorks have done a good job of fitting a PIC32MX440F256 in a 56 pin DIL package, exposing the USB port and providing all the basic necessities.

The promise is to port a simple BASIC interpreter and OS (known as StickOS) to the PIC32 so that code development, programming and debugging will be possible without need to use any external (in circuit) debugger/programmer …

I am waiting anxiously for the first release to give it a try…  I will let you know…

Posted in PIC32, Tools | Comments Off on A new PIC32 Stick

June Bug(s)

June Bug

I am always grateful to readers that report to me typos and/or issues found with the books listings and the CDROM code, but today I want to thank particularly Laurent Debrauwer not only for pointing out an issue with the SD card fileio.c module (as posted on Chapter 15 of the “Exploring the PIC32” book) but also for isolating the “bug”.  Continue reading

Posted in AV16/32, PIC32 | Tagged , | Comments Off on June Bug(s)

Loosing your Head(er)

Contrary to what most MPLAB users believe, the “Headers” folder in MPLAB  Project window is not affecting the compiler selection and access to .h files. It is there merely to let you access them quickly and open them in the editor window.
If you want to make sure that the compiler finds the .h files you are using you have to make sure to do one of two things:
A) Put the .h files (or copies) in the main project directory and use:
#include “xxx.h” (note the use of quotes).
or
B) Make sure to add the directory(-ies) where the .h files are to the “include search path” list in the Build Options for Project Dialog Box. Now you can use #include <xx.h> (note the angled brackets used as quotes)

Method A) is used for simplicity in the first half of the book.

Method B) is used in the second half of the book as we start building more advanced modules/libraries. The steps to add the include directory path to the Build Options for Project Dialog box are described in Chapter 10 (Day 10) page 238 and following…

Don’t loose your head(er)…

Posted in PIC32 | Comments Off on Loosing your Head(er)

MicroC/OS II

I finally got my hands around “the book” on Real Time Operating Systems.

uC/OS ii

Read it all in a couple of days… I loved the clarity and completeness.

Highly, highly recommended! Definitely added to my “favorites” bookshelf !

Posted in PIC32 | Tagged , | Comments Off on MicroC/OS II

Searching for a Pin in a Haystack

There is one problem I have with the current style used in the PIC24 and PIC32 datasheets, it has to do with the way the pin out of the device is presented. Since so many functions are multiplexed on each pin, I find myself constantly checking for potential conflicts when choosing carefully my GP I/Os. The pin-out table is designed to list alphabetically all the individual options and determine the pin number, but then how do you cross check for other functions with the same number?

As I did before for the PIC24, I have created a convenient Excel spreadsheet and filled it with the PIC32MX3xx pinout table info: PIC32MX3xx pinout

Now you can sort the pins by name, by pin number (in different packages) or by group/peripheral.

As an added bonus it was easy to include the information about the pin usage by the Explore16 board and the various PICTail boards available (including the AV16/32 of course).

I hope you’ll find it useful…

P.S. Should you find any error or omission, please make sure to report it to me…

Posted in AV16/32, PIC24, PIC32 | 1 Comment

Reporting Memory Usage

I think I can say we all love the little Memory Usage gauges introduced in MPLAB a couple of years ago.. or was it more?

Memory Usage Gauges

When working in assembly with an 8-bit microcontroller and a couple of Kbytes of FLASH memory they definitely do their job, but when using the PIC24 or PIC32 type of devices, the memory space grows into the hundreds of Kbytes and things get … well, more complicated!

You start including a stack here (USB?) and a library there (Advanced Graphics), the compiler throws in a couple library modules of its own (math libs, stdio…) and both FLASH and RAM spaces become a little more crowded. It does not take long before we start wondering who is using up more memory, and why… the little memory gauges just don’t cut it anymore.

The experts will tell you right away that the sensible thing to do is to turn on the “map” option of the linker, (Project Build Options, Linker Tab, Select Diagnostics pane, then Check Create Map file) and inspect the resulting .map file in the editor window.  But the text file generated is a pretty complex (and long) document and browsing through it in search of clues about what happened to our program and data memory can be quite hard work.

Fortunately with the latest version 1.05 of MPLAB C32 compiler there is a new  option for the linker to produce a detailed summary of your project memory usage: –report-mem. Continue reading

Posted in PIC32, Tips and Tricks | Comments Off on Reporting Memory Usage

Good Old printf()

Good old printf() is probably the oldest debugging tool ever used, I mean beside a light bulb (nowadays replaced by an LED) … yet it represents a pretty sophisticated one when working in a deeply embedded control project. If you take the standard definition of the printf() function (as in the ANSI C standard) it assumes that you will be able to convert and print integers and floating point numbers of any size, and use a myriad of formatting options.

Assuming you have a serial port (UART) to spare for the interface with a terminal (Hyper- if you use a PC) it is the code space requirements (even excluding the floating point support) for a full implementation that makes it a difficult choice. It could be pretty large (several K of code), comparable if not more than the entire program memory available on some 8-bit microcontrollers.

So in the past I have used a bit of everything to avoid relying on printf() for my debugging/diagnostic output.  Mostly macros including itoa() followed by puts() and a mix of other hand made optimizations for simple hex output.

In the 16-bit and 32-bit world, there is a little bit more room to breathe, and  with a smart compiler’s help, things get manageable. Continue reading

Posted in PIC32, Tips and Tricks | Tagged | Comments Off on Good Old printf()