Is there a simple to use toolchain in Linux for PIC MCUs? - Page 1
Forum section: electronics / general

author: Red Squirrel
author_rank: Super Contributor
timestamp: January 09, 2025, 04:17:58 am
content: 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.

author: wilfred
author_rank: Super Contributor
timestamp: January 09, 2025, 07:09:14 am
content: 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.

author: JPortici
author_rank: Super Contributor
timestamp: January 09, 2025, 08:43:15 am
content: Nope, official tools are still the better supported ones. And probably the easiest to use, really.- Install MPLABX- Install XC8Should 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 MCCGreat! You have created an empty projectOn the project view, right click on source files, add new, C source fileCode:// --- 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 stuffvoid 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 releaseCouldn'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

author: sharow
author_rank: Contributor
timestamp: January 09, 2025, 09:33:46 am
content: sdcc and gputils seem to support 18F97J60.Code:$ pacman -Ql sdcc | grep -i 18f97j60sdcc /usr/share/sdcc/lib/pic16/libio18f97j60.libsdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-adcbusy.Posdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-adcclose.Posdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-adcconv.Posdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-adcopen.Posdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-adcread.Posdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-adcsetch.Posdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-dummy.Posdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-i2cack.Posdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-i2cclose.Posdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-i2cdrdy.Posdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-i2cidle.Posdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-i2cnack.Posdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-i2copen.Posdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-i2creadc.Posdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-i2creads.Posdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-i2crestart.Posdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-i2cstart.Posdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-i2cstop.Posdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-i2cwritec.Posdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-i2cwrites.Posdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-ubaud.Posdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-ubusy.Posdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-uclose.Posdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-udrdy.Posdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-ugetc.Posdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-ugets.Posdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-uopen.Posdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-uputc.Posdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-uputs.Posdcc /usr/share/sdcc/lib/src/pic16/libio/.deps/libio18f97j60_a-usartd.Posdcc /usr/share/sdcc/lib/src/pic16/libio/libio18f97j60.asdcc /usr/share/sdcc/non-free/include/pic16/pic18f97j60.hsdcc /usr/share/sdcc/non-free/lib/pic16/libdev18f97j60.libsdcc /usr/share/sdcc/non-free/lib/src/pic16/libdev/.deps/libdev18f97j60_a-pic18f97j60.Posdcc /usr/share/sdcc/non-free/lib/src/pic16/libdev/libdev18f97j60.asdcc /usr/share/sdcc/non-free/lib/src/pic16/libdev/pic18f97j60.c$ pacman -Ql gputils | grep -i 18f97j60gputils /usr/share/doc/gputils-1.5.2/html/PIC18F97J60-conf.htmlgputils /usr/share/doc/gputils-1.5.2/html/PIC18F97J60-feat.htmlgputils /usr/share/doc/gputils-1.5.2/html/PIC18F97J60-ram.htmlgputils /usr/share/doc/gputils-1.5.2/html/PIC18F97J60-sfr.htmlgputils /usr/share/gputils/header/p18f97j60.incgputils /usr/share/gputils/lkr/18f97j60_g.lkrWriter/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/

author: JPortici
author_rank: Super Contributor
timestamp: January 09, 2025, 10:11:23 am
content: Quote from: sharow on January 09, 2025, 09:33:46 amYeah.. 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

author: westfw
author_rank: Super Contributor
timestamp: January 09, 2025, 10:30:07 am
content: 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.)

author: woofy
author_rank: Frequent Contributor
timestamp: January 09, 2025, 10:36:59 am
content: 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.

author: JoeyG
author_rank: Regular Contributor
timestamp: January 09, 2025, 11:57:22 am
content: Use a newer partWHY===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.ExampleThe the Microchip ATSAME54 mcuHere's the MPLAB X projectshttps://github.com/Microchip-MPLAB-Harmony/net_apps_sam_e5xhttps://github.com/Microchip-MPLAB-Harmony/net_apps_sam_e5x/blob/master/release_notes.mdMPLAB X learninghttps://mu.microchip.com/intro-to-the-mplab-x-ideUsing this development hardware platformhttps://www.microchip.com/en-us/development-tool/ATSAME54-XPROhttps://mu.microchip.com/getting-started-with-writing-code-for-the-microchip-arm-cortex-microcontrollershttps://mu.microchip.com/ethernet-fundamentalshttps://mu.microchip.com/mplab-harmony-v3-fundamentals

author: JPortici
author_rank: Super Contributor
timestamp: January 09, 2025, 12:00:27 pm
content: Quote from: woofy on January 09, 2025, 10:36:59 amblehone 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 monstruosityPretty sure there are third party ethernet stacks as wellthough i second going for another chip if possible

author: Red Squirrel
author_rank: Super Contributor
timestamp: January 09, 2025, 09:20:22 pm
content: Quote from: JPortici on January 09, 2025, 08:43:15 amLooks 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.

author: oPossum
author_rank: Super Contributor
timestamp: January 09, 2025, 10:42:32 pm
content: https://www.wch-ic.com/products/CH32V307.html10M (internal PHY) / 1G (external PHY) ethernetUSBRISC-V

author: Red Squirrel
author_rank: Super Contributor
timestamp: January 10, 2025, 02:58:56 am
content: 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.

author: MarkF
author_rank: Super Contributor
timestamp: January 10, 2025, 03:21:25 am
content: Quote from: Red Squirrel on January 10, 2025, 02:58:56 amNo.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.cThat's just my preference. You call them anything you want.

author: Red Squirrel
author_rank: Super Contributor
timestamp: January 10, 2025, 04:20:02 am
content: 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.

author: JPortici
author_rank: Super Contributor
timestamp: January 10, 2025, 07:30:08 am
content: Quote from: Red Squirrel on January 09, 2025, 09:20:22 pmXC8 compiler manual for embedded engineers, or something like that. located in the XC8 installation folder (with references to it on the XC8 compiler manual!)Quote from: Red Squirrel on January 10, 2025, 02:58:56 amWHC 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.cppyup.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?)

author: oPossum
author_rank: Super Contributor
timestamp: January 10, 2025, 08:51:59 am
content: Quote from: Red Squirrel on January 10, 2025, 02:58:56 amYes, they are great. You probably have things with their CH340 series chip inside.Available from LCSChttps://www.lcsc.com/search?q=CH32V307&s_z=h_CH32V307If you really want something from Digikey there is the TI Tiva TM4C129. Has a 10/100 ethenet with PHY.https://www.ti.com/product/TM4C129ENCPDTThere 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.

author: westfw
author_rank: Super Contributor
timestamp: January 10, 2025, 09:11:01 am
content: QuoteUnfortunately, 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.

author: Dazed_N_Confused
author_rank: Contributor
timestamp: January 10, 2025, 10:08:40 am
content: Quote from: Red Squirrel on January 10, 2025, 02:58:56 amMicrochip has a github page with all sorts of codehttps://github.com/microchip-pic-avr-solutionshttps://github.com/microchip-pic-avr-solutions/pic-tcpip-lite-enc28j60-solution

author: fchk
author_rank: Frequent Contributor
timestamp: January 10, 2025, 11:15:36 am
content: Quote from: Red Squirrel on January 10, 2025, 04:20:02 amI 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.

author: Red Squirrel
author_rank: Super Contributor
timestamp: January 10, 2025, 08:51:02 pm
content: Quote from: westfw on January 10, 2025, 09:11:01 amI 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.

author: voltsandjolts
author_rank: Unknown
timestamp: January 10, 2025, 10:31:40 pm
content: Quote from: Red Squirrel on January 10, 2025, 08:51:02 pmYup.