Difference between revisions of "PIC"

From the Linux and Unix Users Group at Virginia Teck Wiki
Jump to: navigation, search
imported>Cov
(Compiling Code)
imported>Mjh
(Categorization)
Line 23: Line 23:
 
RM = rm
 
RM = rm
  
Proj1.cof : main.o messages.o interrupts.o user_interrupts.o my_uart.o uart_thread.o timer1_thread.o timer0_thread.o my_i2c.o
+
Proj1.cof : main.o messages.o interSecure Shellrupts.o user_interrupts.o my_uart.o uart_thread.o timer1_thread.o timer0_thread.o my_i2c.o
 
$(LD) /p18F2680 /l"C:\MCC18\lib" "main.o" "messages.o" "interrupts.o" "user_interrupts.o" "my_uart.o" "uart_thread.o" "timer1_thread.o" "timer0_thread.o" "my_i2c.o" /u_CRUNTIME /u_EXTENDEDMODE /z__MPLAB_BUILD=1 /m"Proj1.map" /w /o"Proj1.cof"
 
$(LD) /p18F2680 /l"C:\MCC18\lib" "main.o" "messages.o" "interrupts.o" "user_interrupts.o" "my_uart.o" "uart_thread.o" "timer1_thread.o" "timer0_thread.o" "my_i2c.o" /u_CRUNTIME /u_EXTENDEDMODE /z__MPLAB_BUILD=1 /m"Proj1.map" /w /o"Proj1.cof"
  
Line 68: Line 68:
 
==External Links==
 
==External Links==
 
* [http://hackaday.com/2010/11/03/how-to-program-pics-using-linux/ How-to Program PICs using Linux - Hackaday] (see article and comments)
 
* [http://hackaday.com/2010/11/03/how-to-program-pics-using-linux/ How-to Program PICs using Linux - Hackaday] (see article and comments)
 +
 +
[[Category:Hardware hacking]]
 +
[[Category:Classwork]]

Revision as of 06:50, 3 February 2013

PIC microcontrollers are a RISC line from Microchip. They are used in ECE 2504 Introduction to Computer Engineering and ECE 4534 Embedded System Design.

Compiling Code

MPLAB is the IDE recommended by the ECE department. It can be run inside a Virtual Machine, programming using USB passthrough. It can also be installed under wine and the compiler used from the commandline. sdcc is a GPL C compiler with some support for PIC devices. Some GNU utilities (namely the assembler and linker, but not compiler) have been modified to support Microchip's microprocessors as part of the gputils project. Piklab is an IDE with support for both open source toolchains.

Using Wine to Run the Toolchain

The MCC18 toolchain can be run using wine. This page should be updated to give more detailed instructions.

Makefile Using Wine

The file below is a work in progress.

# Hacked up makefile for Linux

export WINEPREFIX = /home/user/class/embedded/pic/toolchain
MCCPATH = $(WINEPREFIX)/drive_c/MCC18/bin
CC = wine $(MCCPATH)/mcc18.exe
CFLAGS =  --extended -Opa-
# -D__DEBUG -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa-
LD = wine $(MCCPATH)/mplink.exe
AR = wine $(MCCPATH)/mplib.exe
PK2PATH = /home/user/class/embedded/pic/pk2cmd/pk2cmdv1.20LinuxMacSource
PK2CMD = $(PK2PATH)/pk2cmd
RM = rm

Proj1.cof : main.o messages.o interSecure Shellrupts.o user_interrupts.o my_uart.o uart_thread.o timer1_thread.o timer0_thread.o my_i2c.o
	$(LD) /p18F2680 /l"C:\MCC18\lib" "main.o" "messages.o" "interrupts.o" "user_interrupts.o" "my_uart.o" "uart_thread.o" "timer1_thread.o" "timer0_thread.o" "my_i2c.o" /u_CRUNTIME /u_EXTENDEDMODE /z__MPLAB_BUILD=1 /m"Proj1.map" /w /o"Proj1.cof"

main.o : main.c ../toolchain/drive_c/MCC18/h/stdio.h ../toolchain/drive_c/MCC18/h/usart.h ../toolchain/drive_c/MCC18/h/i2c.h ../toolchain/drive_c/MCC18/h/timers.h messages.h my_uart.h my_i2c.h uart_thread.h timer1_thread.h timer0_thread.h main.c maindefs.h ../toolchain/drive_c/MCC18/h/p18f2680.h ../toolchain/drive_c/MCC18/h/stdarg.h ../toolchain/drive_c/MCC18/h/stddef.h ../toolchain/drive_c/MCC18/h/pconfig.h interrupts.h
	$(CC) -p=18F2680 "main.c" -fo="main.o" $(CFLAGS)

messages.o : messages.c messages.h messages.c maindefs.h ../toolchain/drive_c/MCC18/h/p18f2680.h interrupts.h
	$(CC) -p=18F2680 "messages.c" -fo="messages.o" $(CFLAGS)

interrupts.o : interrupts.c messages.h my_uart.h interrupts.c maindefs.h ../toolchain/drive_c/MCC18/h/p18f2680.h interrupts.h user_interrupts.h
	$(CC) -p=18F2680 "interrupts.c" -fo="interrupts.o" $(CFLAGS)

user_interrupts.o : user_interrupts.c ../toolchain/drive_c/MCC18/h/timers.h messages.h my_uart.h user_interrupts.c maindefs.h ../toolchain/drive_c/MCC18/h/p18f2680.h ../toolchain/drive_c/MCC18/h/pconfig.h user_interrupts.h
	$(CC) -p=18F2680 "user_interrupts.c" -fo="user_interrupts.o" $(CFLAGS)

my_uart.o : my_uart.c ../toolchain/drive_c/MCC18/h/usart.h messages.h my_uart.h my_uart.c maindefs.h ../toolchain/drive_c/MCC18/h/p18f2680.h ../toolchain/drive_c/MCC18/h/pconfig.h
	$(CC) -p=18F2680 "my_uart.c" -fo="my_uart.o" $(CFLAGS)

uart_thread.o : uart_thread.c ../toolchain/drive_c/MCC18/h/stdio.h uart_thread.h uart_thread.c maindefs.h ../toolchain/drive_c/MCC18/h/p18f2680.h ../toolchain/drive_c/MCC18/h/stdarg.h ../toolchain/drive_c/MCC18/h/stddef.h
	$(CC) -p=18F2680 "uart_thread.c" -fo="uart_thread.o" $(CFLAGS)

timer1_thread.o : timer1_thread.c ../toolchain/drive_c/MCC18/h/stdio.h messages.h timer1_thread.h timer1_thread.c maindefs.h ../toolchain/drive_c/MCC18/h/p18f2680.h ../toolchain/drive_c/MCC18/h/stdarg.h ../toolchain/drive_c/MCC18/h/stddef.h
	$(CC) -p=18F2680 "timer1_thread.c" -fo="timer1_thread.o" $(CFLAGS)

timer0_thread.o : timer0_thread.c ../toolchain/drive_c/MCC18/h/stdio.h timer0_thread.h timer0_thread.c maindefs.h ../toolchain/drive_c/MCC18/h/p18f2680.h ../toolchain/drive_c/MCC18/h/stdarg.h ../toolchain/drive_c/MCC18/h/stddef.h
	$(CC) -p=18F2680 "timer0_thread.c" -fo="timer0_thread.o" $(CFLAGS)

my_i2c.o : my_i2c.c ../toolchain/drive_c/MCC18/h/i2c.h messages.h my_i2c.h my_i2c.c maindefs.h ../toolchain/drive_c/MCC18/h/p18f2680.h ../toolchain/drive_c/MCC18/h/pconfig.h
	$(CC) -p=18F2680 "my_i2c.c" -fo="my_i2c.o" $(CFLAGS)

clean : 
	$(RM) "main.o" "messages.o" "interrupts.o" "user_interrupts.o" "my_uart.o" "uart_thread.o" "timer1_thread.o" "timer0_thread.o" "my_i2c.o" "Proj1.cof" "Proj1.hex" "Proj1.map"

prog : Proj1.hex
	$(PK2CMD) -A3.3 -B$(PK2PATH) -P -M -FProj1.hex -Y -T

Programming

See the PICKit 2 article for programming your hex file natively using pk2cmd.

Debugging

Reading printf-style debugging messages over UART with the PICKit 2 is possible from a Windows virtual machine with USB passthrough.

External Links