PIC30 toolchain on OSX

I found a good build script to create Mac OS X toolchain with C30 binutils and GCC compiler at Bas van Klinkenberg’s site, but i’ve got same problem like other people in comments:

Process: as
Path: .../bin/as
Identifier: as
Version: ??? (???)
Code Type: X86 (Native)
Parent Process: sh

OS Version: Mac OS X 10.5.6 (9G55)
Report Version: 1

Exception Codes: KERN_PROTECTION_FAILURE at 0×0000000000084318
Crashed Thread: 0

Thread 0 Crashed:
0 libSystem.B.dylib 0×9471a7c4 strcpy + 52
1 as 0×0006c95b process_resource_file + 59
2 as 0×0006d012 pic30_update_resource + 258
3 as 0×0003c30d bfd_init + 29
4 as 0×00004ae7 main + 183
5 as 0×00001dd6 start + 54

After launching pic30-elf-as in gdb, backtrace could help to find the reason of bus error/segmentation fault message.

Here is the problematic code segment in file c30_resource/src/generato/resource.c, function read_rib():

  if (stat(name,&fileinfo) == -1) {
    /* name cannot be statted */
    /* this could be because of the reoganization of the install directory 
     * some of the binaries are in the same directory as the resource file,
     * some are one directory below it... try moving one up and looking again
    char *c;
    char *ultimate = (char *)name,
         *penultimate = (char *)name;
    char *temp;

    for (c = (char *)name; *c; c++) {
      if ((*c == '/') || (*c == '\\')) {
        penultimate = ultimate;
        ultimate = c;
        while (c[1] == *c) c++;  /* ignore duplicate slashes */
    temp = (char *)xcalloc(strlen(ultimate)+1,1);
    strcpy(temp, ultimate);

If the path name of current working (install) directory is longer than predefined resource filename (pic30_resource_file) at argument of read_rib() funtion, a bus error occurs here:


Static string definition at acme/bfd/cpu-pic30.c:

static char *pic30_resource_file = "/usr/local/share/pic30-support/c30_device.info"; 

Possible solutions:
– copy install directory contents into /usr/local
– copy install directory to a higher level in directory tree
– create a symlink of ${TOOLCHAINDIR}/share/pic30-support to /usr/local/share/pic30-support
Microchip Technology Inc. fix this terrible bug in binutils package

Eclipse integration with PIC C Builder

PIC30 Eclipse: test build

The PicCBuilder is an Eclipse plugin for allowing the use of Eclipse CDT as the editor and builder of projects for Microchip PIC microcontrollers. It creates makefiles that involke the C30 toolchain to generate the binary files.

Additional properties to set – following HOWTO – in Eclipse (my toolchain in /opt/pic30-toolchain folder):

Peter-Jan Randewijk: Microchip MPLAB C30 v3.00
Pilot’s logbook: MPLAB C30 rev 3.02
dsPIC30F Language Tools Quick Reference Guide
MPLAB C30 User Guide

Leave a Reply

Your email address will not be published. Required fields are marked *