ChipKIT/MCB32 toolchain FAQ

The MCB32 toolchain is a c-compiler and assembler for the Uno32 boards, which are used in the course for labs and the student project.

If you have a question regarding the installation or usage of the MCB32 toolchain, please first search this FAQ. If your question is not in the FAQ, post the question here on KTH Social and it will get included in the FAQ.

 

MCB32 toolchain FAQ

  • Make install fails with message "can't open device" on Windows or Mac
    Find the serial port used by the Uno32 board by looking at /dev/ with and without the board connected. On Windows the serial port will have a name such as /dev/ttyS1 or any other number. On mac, look for /dev/cu.usbserial-* or /dev/tty.usbserial-* where the asterisk can be a random string of letters and digits (e.g., ttyS0...ttyS5). Note also that on the Mac you cannot use the MCB32 shell to find the USB device ID. Use another standard terminal on your Mac to find the USB device ID and then copy the string to the MCB32 terminal window. When you have found the serial port, use "make install TTYDEV=/dev/path-to-serial-port" without the quotes.
    If you get a "Resource busy" error alongside the "can't open device" error, then try to reboot your machine.

  • Make install fails with message "permission denied" on Linux
    Depending on you distribution, you need to add your user to a group that has access to the serial ports such as the USB serial port connected to the Uno32. In Ubuntu and debian-based systems, this groups is dialout. In arch it is uucp. You can determine which group owns the character device of Uno32 by typing the following (while Uno32 is connected to your computer and the respective character device is /dev/ttyUSB0):
    $ ls -l /dev/ttyUSB0
    crw-rw---- 1 root dialout 4, 64 jan 15 08:17 /dev/ttyUSB0
    You can add the user to the appropriate group either by using the graphical user and group manager control panel of your distribution or by running the following command from the shell:
    $ sudo usermod -a -G dialout $USER

    This will take action after you re-login to your system. You might reboot, login or switch user (su $USER) in a terminal.

  • Make install fails with message "permission denied" on Windows
    When executing ""make install" in WSL, one may, from time to time, you may get this error:

    ser_open(): can't open device "/dev/ttyUSB0": Permission denied
    When this happens, the problem is related to the fact that your user does not have permissions to access the serial-port file. You can fix permissions with either of these two commands:
    $ sudo chown USERNAME:USERNAME /dev/ttyUSB0
    or
    $ sudo chmod a+rw /dev/<NAME OF USB SERIAL PORT>

    This will take action after you re-login and/or reboot to your system.

  • Make install fails with message "libftdi1.so.1 not found" on Linux
    Install libftdi1 by running the following command from the shell:
    $ sudo apt-get install libftdi1

    This will take action immediately. No reboot or re-login is necessary.

    Note from a previous student (unverified): If you are running Fedora, you might still get an error (also, the package might not be named libftdi1). A possible solution is to create a symbolic link "/lib64/libftdi" that links to "/lib64/libftdi1". Some students had to create the following link "/lib64/libftdi.so.1: symbolic link to /lib64/libftdi1.so.2" so it may depend a bit. 

  • Make install fails with error code 127/126 on Windows
    This is possibly caused by inconsistency between msys2 and the mcb32tools suite. Check that your installation is consistent following the steps here Links to an external site. (Windows section). You better uninstall all previous installations and remove all previous downloads of the mcb32tools and msys.

  • Make install fails with "can't open device "/dev/ttyUSB0": on Windows
    Window is lacking the driver for the FT232R. The following procedure (thanks to Viktor Fornstad) should solve the problem:
    1) Download the correct VCP driver here: https://www.ftdichip.com/old2020/Drivers/VCP.htm Links to an external site. 
    2) Unpack the zip-file to your C-drive, to any directory.
    3) Connect the ChipKit to the PC. Go to "Device Manager" in Windows (Enhetshanteraren in Swedish) and right hand click the FT232R icon under other devices. Select update driver. Select update from your hard-drive and choose the folder which the unpacked zip-file is located.
    4) Now Windows will detect the physical board, but not the USB-port. Look under other devices for an USB device. Select update driver and point to the same folder again. Now you should have a serial port under ports (COM & LPT).
  • I get verification errors when I run "make install"
    This is likely due to a previously failed programming attempt where the USB cable was disconnected during the flashing process. To fix this, a new boot loader needs to be flashed to the board using special hardware, please come to a lunch office hour or contact a course assistant.

  • Compilation fails when i try to use standard functions in stdio.h/string.h/stdlib.h/...

    Software for the Uno32 board is compiled as freestanding, which means that there is no standard library available. This is because many of the standard library functions require an underlying operating system. Since there is no operatating system on the Uno32 boards there is no standard library.

    For the functions you might need (string compare, string length, etc) there are two options. The first option is to implement these simple functions yourselves.

    The second option is to use the latest version (2.1) of mcb32 which contains a rudimentary C standard library that you can manually link with your software. This library contains only the most basic functions such as strlen, memcpy, rand, etc that do not require an operating system. To enable the standard library you will need to edit the Makefile. Add -lc at the end of the LDFLAGS-line.

    Please do not use malloc on the Uno32 board. The malloc function in the mcb32 standard library does not behave as the regular malloc and has not been tested at all. Instead define all the arrays and variables at compile time as global or local variables.

    The following standard headers are availble even if you compile without a standard library: float.h, iso646.h, limits.h, stdalign.h, stdarg.h, stdbool.h, stddef.h, stdint.h, and stdnoreturn.h.

  • I get undefined references to stdin, stdout or stderr when using the C standard library
    Define these variables as void pointers in any C file that does not include stdio.h to work around the problem:
    void *stdin, *stdout, *stderr;
  • Can I use an IDE like Code::Blocks or Eclipse together with mcb32?
    Using an IDE is not supported because mcb32 has to run from its own environment. Use a text editor such as Notpad++ to edit your code and use mcb32 from the msys2 command line to compile.

  • My default shell is not bash, how do I use the toolchain?
    Currently, only bash is supported. Sourcing the environment file with another shell may or may not work. If you experience problems, please use bash to source the toolchain environment file.

  • Compilation fails when using the temperature sensor or other I²C module
    Please update your version of mcb32. Definitions for the I²C registers are currently missing from the pic32mx.h file. Download the following C header file, put it in your project folder and include it with
    #include "i2c-defs.h": Definitions for I²C in Mcb32 Links to an external site.
  • Mac OS: När man ska skriva filerna till minidatorn med "make install TTYDEV=........" får man timeout() och minidatorn visas inte när man kör "ls -l /dev/tty.* " i en terminal (tack Lucas Fredman). 
    Ladda ner "VCP Drivers" från https://ftdichip.com/drivers/vcp-drivers/ 
    Välj rätt version för ditt OS. I mitt fall var det listat nästan längst ner "Mac OS X 10.9 and above".
    Öppna .dmg filen och följ installationsanvisningarna.
    Reboot. Efter omstart bör det man se " /dev/tty.usbserial....." när man kör kommandot "ls -l /dev/tty.* "

  • Cannot flash the chipkit using Windows (tack Chaitanya Katpatal), even though the device COM port is visible in Device Manager. The problem may arise when using WSL version 2. It seems WSL2 does not support USB devices out of the box (https://github.com/microsoft/WSL/issues/4322). It requires you to install usbipd (https://learn.microsoft.com/en-us/windows/wsl/connect-usb), check mcb32tools on Windows Subsystem for Linux (WSL) if you want to do this. An alternative is rolling back to WSL1, which to be the easiest alternative to fix this.

  • When I clone the github project "hello-leds" I get an "Operation timed out" error". What should I do?
    This is a new error and it seems to be related to the command "git clone git://github.com/is1200-example-projects/hello-leds.git". You can run this alternative command "git clone https://github.com/is1200-example-projects/hello-leds.git". Links to an external site.

  • How to run MCB32 on M1, M2, M3 processors? There is no arm64 installer.
    Apple provides a so-called Rosetta emulation layer, which can take an x86 executable and run it on an arm64 processor. If you have Rosetta installed, you should download the x86 executable for Mac, and launch it normally.

Uno32 devboard FAQ

  • Can I use the uC32 board instead of the Uno32 board?
    Yes! However, to be able to run the lab code on your board a few steps should be taken:

    • The Uno32 bootloader must be flashed to your uC32 board using special hardware, please contact a teacher or course assistant. (All uC32 boards should already have the bootloader pre-flashed)
    • The jumper JP4 on the uC32 board should be set to the rightmost (DIGITAL) position.  (All uC32 boards should already have the jumper in the correct position)
    • To use the extra memory availble in the microcontroller, the Makefile of your project needs a slight modification to use the correct device number. This is not strictly nessecary, but recommended.
      Change the line
             DEVICE = 32MX320F128H
      to
             DEVICE = 32MX340F512H
  • How can I connect my own sensor/module to the Uno32 devboard
    Identify the interface used by the sensor by studying its datasheet. The Uno32 supports the following interfaces:
    • GPIO (General Purpose Input/Output)
    • SPI (Serial Peripheral Interface)
    • I²C (Inter-Integrated Circuit)
    • UART (Universal Asynchronous Receiver/Transmitter)
    • ADC (Analog to Digital Converter)

    For information on a particular interface, see Wikipedia, the datasheet of your sensor and the reference manual for the PIC32MX320F128H microcontroller Links to an external site. that is used on the Uno32 board.

  • Which arduino GPIO pin number on the Uno32 board correspond to which PORTs in my source code?

    Look at the table "3.7.1 Pinout Table by Logical Pin Number" in the Uno32 Reference Manual Links to an external site.. For example, consider the pin #41 in the bottom left corner of the digital header. The Chipkit pin numbers are marked in white text on the Uno32 board. In the "Pic32 signal" column of the table in the manual we can see the following for pin 41: "PGC1/AN1/VREF-/CVREF-/CN3/RB1". The last value here is the important one: RB1. This means bit 1 of register PORTB.


    (If you prefer looking at the schematic Links to an external site. the same information can be found on page 4. For example, pin 41 is mapped to RB1 in the schematic which means bit 1 of PORTB in the source code.)
  • I need a source of random numbers in my project
    If you link your software with the standard library (add -lc to LDFLAGS) you have access to the functions rand and srand. You will need to seed the algorithm with a different value every time you power on your circuit. Since there is no real time clock on the board you will need to find something else that will be different every time you start your program. Be creative! You can try reading from the analog to digital converter with nothing connected to the analog input pin or you can try reading from uninitialized memory. Use a couple of different sources and ADD or XOR the values together to get a good, final seed. Another good way is to use a timer and rely on user input. Measure the time from startup until the first button press and use this value as a seed.

  • My project hangs when talking to the temperature sensor or another I²C device
    Make sure the jumpers on the Uno32 and the Basic IO Shield are set up correctly.
  • How can I save some data that will be kept when the board loses power? (highscores, etc)
    There is an EEPROM-chip on the basic io shield connected to the I²C-bus. See the example code for the temperature sensor for how to use I²C. The name of the EEPROM-chip can be found in the Basic IO Shield datasheet.

  • The ChipKIT does not show up in /dev when connecting it to a Windows computer
    Note from a previous student (unverified): There are drivers available for manual installation at https://www.ftdichip.com/ Links to an external site.

 

  • Where can I buy my own ChipKit and Shield?
    The ChipKits can be found Here Links to an external site. and the I/O shield can be found Here Links to an external site.. The following has not been thoroughly tested but It appears that some newly bought uC32 boards can be used directly with the mcb32 toolchain. Set the jumpers of your board according to the following picture Jumper settings. You can then test your chipkit by running one of the example projects in https://github.com/is1200-example-projects Links to an external site. or run your own code from lab 1 on the chipkit. If a flashing of the bootloader is indeed necessary you need to ask one of the TAs to help you Flash the kit with relevant bootloaders as it requires special hardware.