Difference between revisions of "TARGET Embedded Mipsel"

From Free Pascal wiki
Jump to navigationJump to search
m
Line 103: Line 103:
 
and connect to it with gdb:
 
and connect to it with gdb:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
pic32mx-gdb hello.elf --tui --eval-command="target extended :2331" --eval-command="monitor reset halt" --eval-command="set mem inaccessible-by-default off" --eval-command="load" --eval-command="layout asm" --eval-command="layout regs"  --eval-command="set remotetimeout 3000"
+
pic-gdb hello.elf --tui --eval-command="target extended :2331" --eval-command="monitor reset halt" --eval-command="set mem inaccessible-by-default off" --eval-command="load" --eval-command="layout asm" --eval-command="layout regs"  --eval-command="set remotetimeout 3000"
 
</syntaxhighlight>
 
</syntaxhighlight>

Revision as of 14:23, 21 April 2014

The mipsel-embedded target was created to target the pic32mx microcontroller chips produced by Microchip.

There exist several lines of chips:

PIC32MX1/2:
Those are the most maker-friendly chips in the lineup, they come in the form of DIL-28 and SOIC-28, even the TQFP-44 packages are relatively easy to solder. Max. CPU speed is 50MHz
PIC32MX3/4/5/6/7xx:
High Pin Count devices starting with TQFP-48 packages and max. CPU speed of 80-100MHz

Status

  • support is only available in svn trunk version
  • the complete lineup of existing controllers is supported, testing is done with pic32mx150, pic32mx460 and pic32mx795 chips on a MacOSX-Host

Build

Get latest FPC from svn:

svn co http://svn.freepascal.org/svn/fpc/trunk fpc

Get pic32-embedded tools from this page:

http://chipkit.s3.amazonaws.com/index.html

you will find precompiled binaries for macosx, linux and windows in the directory 'compiler'.

You only need the binaries of pic32-ar(.exe), pic32-as(.exe), pic32-ld(.exe), pic32-strip(.exe), pic32-objdump(.exe) and pic32-objcopy(.exe). Put these utils in a directory included in your path.

To build binutils from sources check out https://github.com/chipKIT32/chipKIT-cxx.git

./configure --target=pic32-elf32 --prefix=/opt/embarm/ --program-prefix=pic32- --disable-werror

Build FPC for mipsel-embedded (OABI):

make clean buildbase installbase CROSSINSTALL=1 OS_TARGET=embedded CPU_TARGET=mipsel SUBARCH=pic32mx BINUTILSPREFIX=pic32-

cd fpc
make clean buildbase installbase CROSSINSTALL=1 OS_TARGET=embedded CPU_TARGET=mipsel SUBARCH=pic32mx BINUTILSPREFIX=pic32-

This builds only the compiler and the RTL instead of the whole FPC. Because of the limited capabilities of the embedded systems supposed to be used, building all packages is not useful. However, one must be careful to avoid overwriting an existing arm compiler on the system. If this is the case, INSTALL_PREFIX should be used to install into a different directory and switch between those.

SUBARCH is required and should match your binutils, currently there are three different versions of binutils:
pic32mx: chipkit port with some pic32 specific patches
mips32r2: plain vanilla binutils
xc32: Microchips official version of binutils, does not work correctly atm.

all testing was done with the chipkit version because precompiled binaries are available for all major platforms.

For Debugging you will also need to build pic32-gdb from sources.


Compiling a simple example

program hello;
var
  i : integer;
begin
  GPIOB.setConfig([RB0,RB1,RB2,RB3,RB4,RB5,RB6,RB7],GPIO_Output_Push_Pull);

while true do
begin
  GPIOB.clearBit([RB0,RB1,RB2,RB3,RB4,RB5,RB6,RB7]);
  for i := 0 to 40000 do
    ;
  GPIOB.setBit([RB0,RB1,RB2,RB3,RB4,RB5,RB6,RB7]);
  for i := 0 to 40000 do
    ;
end;
end.

to build the program use the following commands (on Linux & MacOSX)

DEBUG="-gw2 -godwarfsets -godwarfmethodclassprefix"
BINUTILS=pic32-; SUBARCH=pic32mx
CPU=pic32mx795f512h
/usr/local/lib/fpc/2.7.1/ppcrossmipsel -Cp$SUBARCH -Wp$CPU -XP$BINUTILS -MObjFPC -d$CPU -Tembedded -Pmipsel -O2 -Scghi -Ch1024 -Cs1024 $DEBUG -vewnhix -l -FD/usr/local/bin -a hello.pas

Flashing and Debugging

Some history: The pic32 target has been in development for nearly a year now, the main reason for this long development was that there was simply no easy way to reliably flash the chip. But this has changed now, a very simple solution is now available from www.segger.com, their Version 9.0 of the J-Link hardware now supports flashing and debugging of all pic32mx chips.

the openocd project also has support for flashing pic32mx chips but I had mixed results with flashing; debugging on the other side works just fine.

So my recommendation here is that you invest €50 and buy a J-Link Edu debug probe. It also works great for ARM based controllers so you only need one tool for debugging both platforms. You must make sure that the Hardware is at least V9, older versions of the hardware do not support pic32mx.

The only thing you need now is an adapter to connect the J-Link to the pic32, a schematic can be found on the segger homepage: https://www.segger.com/jlink-adapters.html#MicrochipAdapter

Debugging is now straightforward:


Start the gdb-server:

JLinkGDBServer -device PIC32MX795F512H -if 2-wire-JTAG-PIC32 -speed auto

and connect to it with gdb:

pic-gdb hello.elf --tui --eval-command="target extended :2331" --eval-command="monitor reset halt" --eval-command="set mem inaccessible-by-default off" --eval-command="load" --eval-command="layout asm" --eval-command="layout regs"  --eval-command="set remotetimeout 3000"