Author Topic: Is there a simple to use toolchain in Linux for PIC MCUs?  (Read 1818 times)

0 Members and 1 Guest are viewing this topic.

Offline Red SquirrelTopic starter

  • Super Contributor
  • ***
  • Posts: 2757
  • Country: ca
Is there a simple to use toolchain in Linux for PIC MCUs?
« on: January 09, 2025, 04:17:58 am »
Looking at getting into PIC, particularly want to do ethernet based projects with the PIC18F97J60.

I downloaded the MPlab X IDE but it looks way more complicated than I want or need. I just want to write code and push it to the chip.

Does a simpler toolchain exist that would work in Linux, as well as code examples available somewhere?  I did not buy a programmer yet, i don't mind paying for the official Pickit one but open to other suggestions too.
 

Online wilfred

  • Super Contributor
  • ***
  • Posts: 1409
  • Country: au
Re: Is there a simple to use toolchain in Linux for PIC MCUs?
« Reply #1 on: January 09, 2025, 07:09:14 am »
I briefly looked into Great Cow Basic for programming PICs. Haven't done enough with it to recommend it from experience but it does tick your boxes.
In any case Evan Venn has a channel on YT that might clear thing up on what it does.

I've not noticed much on PICs lately but he does still post new content.
 

Offline JPortici

  • Super Contributor
  • ***
  • Posts: 3577
  • Country: it
Re: Is there a simple to use toolchain in Linux for PIC MCUs?
« Reply #2 on: January 09, 2025, 08:43:15 am »
Nope, official tools are still the better supported ones. And probably the easiest to use, really.
- Install MPLABX
- Install XC8
Should just work. At least it does on my debian 12 desktop, i don't think i did anything strange other than making the installer executable from non root

- Open MPLABX
- Create New Project
- Select the device
- Select the folder
- Untick MCC
Great! You have created an empty project

On the project view, right click on source files, add new, C source file
Code: [Select]
// --- insert configuration bits here, in a source file, before any include.
//Code generator for configuration bits at Window -> Target Memory Views -> Configuration bits

#define _XTAL_FREQ 4000000 //Whatever frequency your Oscillator is At - Required for software delays - See XC8 Compiler guide

#include <xc.h>  //Do NOT include the device include file. Always include xc.h and only xc.h for device related stuff

void main(void) {
  TRISAbits.TRISA = 0;
  while(1) {
    LATAbits.LATA = 1;
    __delay_ms(100);
    LATAbits.LATA = 0;
    __delay_ms(100);
  }
}

Hit debug for debug, hit make and program to release
Couldn't be simpler IMHO.

However, the newest XC8 released just before the holidays can be integrated with VSCode via the MPLAB Extensions... But it's still pretty much in alpha stage*, i don't have direct experience other than verifying code completition works. I have a couple of boards coming next week that i intend to make the firmware in it, to see when it's going to be a good time to abandon MPLABX

*currently no disassembly, i don't know if it's actually possible to compile in release mode, don't know if it's possible to change compiler parameters, don't know how to manage multiple configurations/pre-post build scripts, don't know if/how to combine projects for single build/combine of bootloader and application
« Last Edit: January 09, 2025, 10:12:14 am by JPortici »
 

Offline sharow

  • Contributor
  • Posts: 18
  • Country: 00
Re: Is there a simple to use toolchain in Linux for PIC MCUs?
« Reply #3 on: January 09, 2025, 09:33:46 am »
sdcc and gputils seem to support 18F97J60.

Code: [Select]
$ pacman -Ql sdcc | grep -i 18f97j60
sdcc /usr/share/sdcc/lib/pic16/libio18f97j60.lib
sdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-adcbusy.Po
sdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-adcclose.Po
sdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-adcconv.Po
sdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-adcopen.Po
sdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-adcread.Po
sdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-adcsetch.Po
sdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-dummy.Po
sdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-i2cack.Po
sdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-i2cclose.Po
sdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-i2cdrdy.Po
sdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-i2cidle.Po
sdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-i2cnack.Po
sdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-i2copen.Po
sdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-i2creadc.Po
sdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-i2creads.Po
sdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-i2crestart.Po
sdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-i2cstart.Po
sdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-i2cstop.Po
sdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-i2cwritec.Po
sdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-i2cwrites.Po
sdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-ubaud.Po
sdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-ubusy.Po
sdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-uclose.Po
sdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-udrdy.Po
sdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-ugetc.Po
sdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-ugets.Po
sdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-uopen.Po
sdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-uputc.Po
sdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-uputs.Po
sdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-usartd.Po
sdcc /usr/share/sdcc/lib/src/pic16/libio/libio18f97j60.a
sdcc /usr/share/sdcc/non-free/include/pic16/pic18f97j60.h
sdcc /usr/share/sdcc/non-free/lib/pic16/libdev18f97j60.lib
sdcc /usr/share/sdcc/non-free/lib/src/pic16/libdev/.deps/libdev18f97j60_a-pic18f97j60.Po
sdcc /usr/share/sdcc/non-free/lib/src/pic16/libdev/libdev18f97j60.a
sdcc /usr/share/sdcc/non-free/lib/src/pic16/libdev/pic18f97j60.c
$ pacman -Ql gputils | grep -i 18f97j60
gputils /usr/share/doc/gputils-1.5.2/html/PIC18F97J60-conf.html
gputils /usr/share/doc/gputils-1.5.2/html/PIC18F97J60-feat.html
gputils /usr/share/doc/gputils-1.5.2/html/PIC18F97J60-ram.html
gputils /usr/share/doc/gputils-1.5.2/html/PIC18F97J60-sfr.html
gputils /usr/share/gputils/header/p18f97j60.inc
gputils /usr/share/gputils/lkr/18f97j60_g.lkr


Writer/Programmer/Debugger is another kettle of fish for linux tho.


--
related topic:
PIC programming - how should I start (on Linux)?
https://www.eevblog.com/forum/microcontrollers/pic-programming-how-should-i-start/
 

Offline JPortici

  • Super Contributor
  • ***
  • Posts: 3577
  • Country: it
Re: Is there a simple to use toolchain in Linux for PIC MCUs?
« Reply #4 on: January 09, 2025, 10:11:23 am »
related topic:
PIC programming - how should I start (on Linux)?
https://www.eevblog.com/forum/microcontrollers/pic-programming-how-should-i-start/

Yeah.. thread from 10 years ago. Things are much better now re linux support, and even then I would have avoided sdcc wherever possible.
XC8 came out in 2012, i don't remember when exactly i started using it though, it think it was v1.21 (2013) or 1.35 (2015), because at the time i was still using mikroe compilers under windows
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4361
  • Country: us
Re: Is there a simple to use toolchain in Linux for PIC MCUs?
« Reply #5 on: January 09, 2025, 10:30:07 am »
Theoretically you should be able to download xc8 and the device “packs”, and use them from the cli in manually created make files and similar.  But figuring out enough of mplabx to get by is probably easier - you don’t have to use all the bells and whistles like “harmony.”  (Like, I think the pic assembler is part of mplabx, and not xc8?). (If you already installed mplabx, all the tools that can run from the cli are probably already there.  Somewhere.)

 

Offline woofy

  • Frequent Contributor
  • **
  • Posts: 377
  • Country: gb
    • Woofys Place
Re: Is there a simple to use toolchain in Linux for PIC MCUs?
« Reply #6 on: January 09, 2025, 10:36:59 am »
I think you will need MPLABX and MCC for the stack.

But really, unless you have some PIC18F97J60's laying around, WHY?
This chip is nearly 20 years old (2006 vintage) with very limited memory resources. It also does not play well with modern switches. I once used a member of this family in a product and not working in an industrial environment was the primary reason for dropping it.
So unless you have a solid reason to use it, I would definitely avoid it.

Offline JoeyG

  • Regular Contributor
  • *
  • Posts: 137
  • Country: au
Re: Is there a simple to use toolchain in Linux for PIC MCUs?
« Reply #7 on: January 09, 2025, 11:57:22 am »
Use a newer part

WHY
===
OK you want to do Ethernet based project.  This mean you will need a ethernet drivers and TCP/IP stack.
A good TCP/IP stack with all the features is probably 50k~100K  flash memory size. Then add your only program on top.

Also you will need to process 10MB/100MB  Ethernet TCP/IP packets the mcu need to be fast.
=============

If it were me I'd used existing Ethernet  software projects on  existing hardware.

Example
The the Microchip ATSAME54  mcu
Here's the  MPLAB X projects  https://github.com/Microchip-MPLAB-Harmony/net_apps_sam_e5x

https://github.com/Microchip-MPLAB-Harmony/net_apps_sam_e5x/blob/master/release_notes.md

MPLAB X learning https://mu.microchip.com/intro-to-the-mplab-x-ide

Using this development hardware platform
https://www.microchip.com/en-us/development-tool/ATSAME54-XPRO

https://mu.microchip.com/getting-started-with-writing-code-for-the-microchip-arm-cortex-microcontrollers
https://mu.microchip.com/ethernet-fundamentals

https://mu.microchip.com/mplab-harmony-v3-fundamentals


 
 
The following users thanked this post: Dazed_N_Confused

Offline JPortici

  • Super Contributor
  • ***
  • Posts: 3577
  • Country: it
Re: Is there a simple to use toolchain in Linux for PIC MCUs?
« Reply #8 on: January 09, 2025, 12:00:27 pm »
MCC for the stack.

bleh :P
one can also download the good old MLA (https://www.microchip.com/en-us/tools-resources/develop/libraries/microchip-libraries-for-applications) without using that bloated monstruosity
Pretty sure there are third party ethernet stacks as well

though i second going for another chip if possible
 
The following users thanked this post: Dazed_N_Confused

Offline Red SquirrelTopic starter

  • Super Contributor
  • ***
  • Posts: 2757
  • Country: ca
Re: Is there a simple to use toolchain in Linux for PIC MCUs?
« Reply #9 on: January 09, 2025, 09:20:22 pm »
Nope, official tools are still the better supported ones. And probably the easiest to use, really.
- Install MPLABX
- Install XC8
Should just work. At least it does on my debian 12 desktop, i don't think i did anything strange other than making the installer executable from non root

- Open MPLABX
- Create New Project
- Select the device
- Select the folder
- Untick MCC
Great! You have created an empty project

On the project view, right click on source files, add new, C source file
Code: [Select]
// --- insert configuration bits here, in a source file, before any include.
//Code generator for configuration bits at Window -> Target Memory Views -> Configuration bits

#define _XTAL_FREQ 4000000 //Whatever frequency your Oscillator is At - Required for software delays - See XC8 Compiler guide

#include <xc.h>  //Do NOT include the device include file. Always include xc.h and only xc.h for device related stuff

void main(void) {
  TRISAbits.TRISA = 0;
  while(1) {
    LATAbits.LATA = 1;
    __delay_ms(100);
    LATAbits.LATA = 0;
    __delay_ms(100);
  }
}

Hit debug for debug, hit make and program to release
Couldn't be simpler IMHO.

However, the newest XC8 released just before the holidays can be integrated with VSCode via the MPLAB Extensions... But it's still pretty much in alpha stage*, i don't have direct experience other than verifying code completition works. I have a couple of boards coming next week that i intend to make the firmware in it, to see when it's going to be a good time to abandon MPLABX

*currently no disassembly, i don't know if it's actually possible to compile in release mode, don't know if it's possible to change compiler parameters, don't know how to manage multiple configurations/pre-post build scripts, don't know if/how to combine projects for single build/combine of bootloader and application

Looks like I was on the right track more or less then, for some reason though I couldn't figure out how to make it DO anything, like I purposely made an error in the code that shouldn't compile, hit build, and nothing happens, no error or anything. Also having a hard time finding any sort of code samples, like how do you set a pin high or low, or how to interface with the ethernet phy etc. 

Also opened to other part suggestions, my goal is to create sensors/controls that will be ethernet based and have a cheap enough BOM so that is one chip I found while searching.
 

Online oPossum

  • Super Contributor
  • ***
  • Posts: 1475
  • Country: us
  • Very dangerous - may attack at any time
Re: Is there a simple to use toolchain in Linux for PIC MCUs?
« Reply #10 on: January 09, 2025, 10:42:32 pm »
https://www.wch-ic.com/products/CH32V307.html

10M (internal PHY) / 1G (external PHY) ethernet
USB
RISC-V
 

Offline Red SquirrelTopic starter

  • Super Contributor
  • ***
  • Posts: 2757
  • Country: ca
Re: Is there a simple to use toolchain in Linux for PIC MCUs?
« Reply #11 on: January 10, 2025, 02:58:56 am »
Can't find where to buy that, doesn't show up in Digikey, never even heard of that company, are they reputable?

I figured out what I was doing wrong in Mplab, I guess the main file has to be called newmain.c and not main.cpp.  I didn't think the name mattered.  I can get a blank project to compile now.

Although finding sample code seems to be hard, really not finding much when I google. Is there some sort of documentation somewhere, like a list of functions, classes, variable names and such?  The datasheet doesn't really touch much on actual code. I keep reading "use the microchip tcp/ip stack" in my search, but where is this?  I just find 404 pages and expired SSL certs when I search for it.
« Last Edit: January 10, 2025, 03:07:41 am by Red Squirrel »
 

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 2791
  • Country: us
Re: Is there a simple to use toolchain in Linux for PIC MCUs?
« Reply #12 on: January 10, 2025, 03:21:25 am »

I figured out what I was doing wrong in Mplab, I guess the main file has to be called newmain.c and not main.cpp.  I didn't think the name mattered.  I can get a blank project to compile now.


No. 
The file containing the main() function can be called anything.
However, it can NOT have the extension of .cpp.  You are writing simple C code.  Not C++ code.

I have developed the habit of naming the main file and its header by the MCU.
In your case, I would have named them pic18f97j60.h and pic18f97j60.c
That's just my preference.  You call them anything you want.

 

Offline Red SquirrelTopic starter

  • Super Contributor
  • ***
  • Posts: 2757
  • Country: ca
Re: Is there a simple to use toolchain in Linux for PIC MCUs?
« Reply #13 on: January 10, 2025, 04:20:02 am »
Oh ok maybe using .cpp was my issue.

But I missed the part about this chip being 20 years old while rereading replies so maybe this is not the best chip to use.  Is there a newer version or something similar from a reputable brand that I can get from Digikey? That's just what comes up when I google for "microcontroller with ethernet" and similar keywords.  It always brings me back to this chip.

My goal is to create sensor/devices that use ethernet on a rather small footprint with reasonable BOM cost (like say $25CAD max) and speak a basic TCP language, the central server software would handle all the heavy lifting.
 

Offline JPortici

  • Super Contributor
  • ***
  • Posts: 3577
  • Country: it
Re: Is there a simple to use toolchain in Linux for PIC MCUs?
« Reply #14 on: January 10, 2025, 07:30:08 am »
Also having a hard time finding any sort of code samples, like how do you set a pin high or low, or how to interface with the ethernet phy etc. 

XC8 compiler manual for embedded engineers, or something like that. located in the XC8 installation folder (with references to it on the XC8 compiler manual!)

Can't find where to buy that, doesn't show up in Digikey, never even heard of that company, are they reputable?

I figured out what I was doing wrong in Mplab, I guess the main file has to be called newmain.c and not main.cpp.  I didn't think the name mattered.  I can get a blank project to compile now.

Although finding sample code seems to be hard, really not finding much when I google. Is there some sort of documentation somewhere, like a list of functions, classes, variable names and such?  The datasheet doesn't really touch much on actual code. I keep reading "use the microchip tcp/ip stack" in my search, but where is this?  I just find 404 pages and expired SSL certs when I search for it.

WHC is a pretty good company, but you will have to buy parts from china, or other distributors (maybe TME carries them? though TME is european.)

re: main.cpp
yup.
cpp extension invokes the C++ compiler, which XC8 isn't. so no surprise it's not doing anything. Surprising that it doesn't tell you anything. I shall check that later.
main file can be called asjhdlaksjdlkajstastajlk.c for that matter, compiler doesn't care. compiler cares that there is a main function (Why the compiler would be picky about the name of the file?)
« Last Edit: January 10, 2025, 07:33:24 am by JPortici »
 

Online oPossum

  • Super Contributor
  • ***
  • Posts: 1475
  • Country: us
  • Very dangerous - may attack at any time
Re: Is there a simple to use toolchain in Linux for PIC MCUs?
« Reply #15 on: January 10, 2025, 08:51:59 am »
Can't find where to buy that, doesn't show up in Digikey, never even heard of that company, are they reputable?

Yes, they are great. You probably have things with their CH340 series chip inside.

Available from LCSC

https://www.lcsc.com/search?q=CH32V307&s_z=h_CH32V307


If you really want something from Digikey there is the TI Tiva TM4C129. Has a 10/100 ethenet with PHY.

https://www.ti.com/product/TM4C129ENCPDT


There are many more MCU to choose from if you are willing to use an external PHY.
There are also the Wiznet chips that are a ethernet controller, PHY and TCP/IP stack with a SPI interface so they can be used with any MCU.
« Last Edit: January 10, 2025, 08:53:44 am by oPossum »
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4361
  • Country: us
Re: Is there a simple to use toolchain in Linux for PIC MCUs?
« Reply #16 on: January 10, 2025, 09:11:01 am »
Quote
Is there a newer version or something similar from a reputable brand that I can get from Digikey?
Unfortunately, microcontrollers with a built-in Ethernet Phy are relatively rare.  Apparently the analog electronics needed to implement a Phy are not particularly compatible with the processes used for modern microcontrollers :-(

If you're willing to use a separate Phy chip, the number of microprocessors with the digital part of Ethernet (the "MAC") are much more common.  The interconnect is typically MII or RMII, which take a significant number of pins (18 or 9) and some careful layout, but they're capable of 100Mbps as well as 10Mbps ethernet.
 

Offline Dazed_N_Confused

  • Newbie
  • Posts: 9
  • Country: us
Re: Is there a simple to use toolchain in Linux for PIC MCUs?
« Reply #17 on: January 10, 2025, 10:08:40 am »

Although finding sample code seems to be hard, really not finding much when I google. Is there some sort of documentation somewhere, like a list of functions, classes, variable names and such?  The datasheet doesn't really touch much on actual code. I keep reading "use the microchip tcp/ip stack" in my search, but where is this?  I just find 404 pages and expired SSL certs when I search for it.

 Microchip has a github page with all sorts of code
https://github.com/microchip-pic-avr-solutions
https://github.com/microchip-pic-avr-solutions/pic-tcpip-lite-enc28j60-solution
« Last Edit: January 10, 2025, 10:16:15 am by Dazed_N_Confused »
Windows: Tailor-Made Technology for the Soccer Mom!
Linux: Unleashing the Alpha Male in the Digital Domain!
"Premature optimization is the root of all evil" ~ Donald Knuth
 
The following users thanked this post: Red Squirrel

Offline fchk

  • Frequent Contributor
  • **
  • Posts: 284
  • Country: de
Re: Is there a simple to use toolchain in Linux for PIC MCUs?
« Reply #18 on: January 10, 2025, 11:15:36 am »
But I missed the part about this chip being 20 years old while rereading replies so maybe this is not the best chip to use.  Is there a newer version or something similar from a reputable brand that I can get from Digikey? That's just what comes up when I google for "microcontroller with ethernet" and similar keywords.  It always brings me back to this chip.

My goal is to create sensor/devices that use ethernet on a rather small footprint with reasonable BOM cost (like say $25CAD max) and speak a basic TCP language, the central server software would handle all the heavy lifting.

I used this chip for projects 20 years ago. Some of these system still run file after all these years in 24x7 without any crash.

Back then a PIC18F67J60 cost about 3€. Nowadays it's more like 6.50€.

The other single-chip alternative is TI TIVA TM4C1294. 16€ in single quantities. This is Cortex M4F, so recent technology. I've used it also for some projects - no problem.

Besides this you will only find controllers with external PHYs or MAC/PHYs. If you want reputable sorces you probably will end up with STM or Microchip PIC32M (MIPS) or PIC32C (ARM, former ATSAM) or some NXP/Freescale stuff.
 

Offline Red SquirrelTopic starter

  • Super Contributor
  • ***
  • Posts: 2757
  • Country: ca
Re: Is there a simple to use toolchain in Linux for PIC MCUs?
« Reply #19 on: January 10, 2025, 08:51:02 pm »
Quote
Is there a newer version or something similar from a reputable brand that I can get from Digikey?
Unfortunately, microcontrollers with a built-in Ethernet Phy are relatively rare.  Apparently the analog electronics needed to implement a Phy are not particularly compatible with the processes used for modern microcontrollers :-(

If you're willing to use a separate Phy chip, the number of microprocessors with the digital part of Ethernet (the "MAC") are much more common.  The interconnect is typically MII or RMII, which take a significant number of pins (18 or 9) and some careful layout, but they're capable of 100Mbps as well as 10Mbps ethernet.

I guess that makes sense, probably tricky to have a process to mix digital and analog on the same die.  I was looking into that possibility of using an external phy originally until I found that chip that has it built in.  Was looking at the ENC28J60 and it looks fairly easy to use.  There's also the Wiznet W5500 which also has TCP/IP built right in so that might be a better route, I see you can buy the chip standalone. Not TOO expensive, about $8 at Digikey. Open to other suggestions too.   I would probably end up interfacing with an Atmega MCU as I'm already familiar with those and have a programmer already too.  The toolchain looks simpler too. I have not played with it outside of Arduino though but it looks like it would be fairly easy to script.
 

Online voltsandjolts

  • Supporter
  • ****
  • Posts: 2589
  • Country: gb
Re: Is there a simple to use toolchain in Linux for PIC MCUs?
« Reply #20 on: January 10, 2025, 10:31:40 pm »
There's also the Wiznet W5500 which also has TCP/IP built right in so that might be a better route

Yup.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf