Author Topic: SDCC-Anyone using it for PIC micro's?  (Read 3740 times)

0 Members and 1 Guest are viewing this topic.

Offline djsbTopic starter

  • Frequent Contributor
  • **
  • Posts: 893
  • Country: gb
SDCC-Anyone using it for PIC micro's?
« on: August 29, 2021, 04:33:49 pm »
I've just been playing around with version 4.1.0 of SDCC and I've managed to get a couple of simple MPLABX projects completed (just a simple LED flash and LED flash activated with a button on a 16f877A).
My aim is to make a set of simple examples for use by the students where I work. I've also been working with XC8 as well and that's coming along nicely.
Has anyone got any experience with using SDCC to exercise the timers, the USART, I2C,PWM and other peripherals on the 877A (or any more recent PIC). I'd be grateful for any TIMER0 examples to help me make some more progress.
The impetus behind all this work is the need to reduce costs for students (we've been using CCS for several years). I also like to promote open source projects, and I'd love SDCC to get wider exposure. Can anyone help? Thanks.
David
Hertfordshire,UK
University Electronics Technician, London PIC,CCS C,Arduino,Kicad, Altium Designer,LPKF S103,S62 Operator, Electronics instructor. Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime. Credited Kicad French to English translator.
 

Offline HwAoRrDk

  • Super Contributor
  • ***
  • Posts: 1478
  • Country: gb
Re: SDCC-Anyone using it for PIC micro's?
« Reply #1 on: August 29, 2021, 06:55:38 pm »
Be warned that PIC support in SDCC is unmaintained and may be discontinued in future releases.
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14481
  • Country: fr
Re: SDCC-Anyone using it for PIC micro's?
« Reply #2 on: August 29, 2021, 07:06:37 pm »
Be warned that PIC support in SDCC is unmaintained and may be discontinued in future releases.

Indeed. That's clearly stated: http://sdcc.sourceforge.net/

If you want to use open source tools with microcontrollers for teaching, I would recommend using some other microcontrollers these days. The PIC16 and 18 were nice, but they are kind of dated, have an odd architecture and are limited.

Switching to ARM Cortex MCUs for your courses would allow you to expose the students to a widely-used architecture and use 100% open source tools. Just my 2 cents.
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9890
  • Country: us
Re: SDCC-Anyone using it for PIC micro's?
« Reply #3 on: August 29, 2021, 08:29:06 pm »
If I were involved with teaching, I would be all over Arduino.  The Arduino Nano is $10 at Amazon and the very popular Arduino Uno is $35.  There are Starter Kits (of parts) all over Amazon and some come with really good documentation and tutorials.  VERY good tutorials!  Plus, there are projects all over the Internet and hundreds of videos.

https://www.amazon.com/ELEGOO-Project-Tutorial-Controller-Projects/dp/B01D8KOZF4  - $35 WITH Arduino Compatible Uno

I doubt that a PIC 16F877A prototype board is much cheaper than the Nano.

https://www.amazon.com/Microchip-PIC16F877A-Microcontroller-Development-Interface/dp/B07WTB68FK -- $20

The thing about the PIC board is that you may still need a PIC Kit 2 or later programmer (for some boards).

I used the 16F series way back when but I haven't used them in the last several years.  There are too many less expensive and more capable chips.

For a C compiler, the 16F series is a really ugly architecture to target.  Look at the emitted code, count the number of page and bank swaps compared to actual usable code.
« Last Edit: August 29, 2021, 08:31:22 pm by rstofer »
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5912
  • Country: es
Re: SDCC-Anyone using it for PIC micro's?
« Reply #4 on: August 29, 2021, 09:31:04 pm »
Why stick to an uncomplete, obsolete and abandoned compiler? Microchip lets you use XC8 with O2 optimization for free:
Quote
Our free MPLAB XC C Compiler comes with the majority of the optimizations you need to reduce your code by up to 70% and increase efficiency. Specifically, the free compiler contains these optimizations:

O0 - Ensures that your code is in its pristine state
O1 - Invokes all optimizations that won't affect debugging
O2 - Invokes a balanced set of speed and size optimizations

When you purchase one of our PRO licenses, you also get the following optimizations:

Os - Gives maximum code size reductions
O3 - Gives the best speed optimizations
mpa (Procedural Abstraction) - Reduces code size even further
« Last Edit: August 29, 2021, 09:34:32 pm by DavidAlfa »
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline djsbTopic starter

  • Frequent Contributor
  • **
  • Posts: 893
  • Country: gb
Re: SDCC-Anyone using it for PIC micro's?
« Reply #5 on: August 29, 2021, 09:43:14 pm »
Yes, I'm mainly concentrating on using XC8. I'm just curious about SDCC so thought I'd try a few examples just for the fun of it. We mainly use 16f819, 16f1827 and 16f1847. Just had a few 16f877a lying around.
David
Hertfordshire,UK
University Electronics Technician, London PIC,CCS C,Arduino,Kicad, Altium Designer,LPKF S103,S62 Operator, Electronics instructor. Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime. Credited Kicad French to English translator.
 

Offline ebclr

  • Super Contributor
  • ***
  • Posts: 2328
  • Country: 00
Re: SDCC-Anyone using it for PIC micro's?
« Reply #6 on: August 30, 2021, 03:24:06 am »
Just for information , have another kid on the block for a while and is a nice and strong kid

http://www.ccsinfo.com/content.php?page=compilers
 

Offline djsbTopic starter

  • Frequent Contributor
  • **
  • Posts: 893
  • Country: gb
Re: SDCC-Anyone using it for PIC micro's?
« Reply #7 on: August 30, 2021, 04:47:29 am »
Yes, we have been using the CCS PCM compiler exclusively for over 10 years and I like it. It's nice to have alternatives, though.
David
Hertfordshire,UK
University Electronics Technician, London PIC,CCS C,Arduino,Kicad, Altium Designer,LPKF S103,S62 Operator, Electronics instructor. Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime. Credited Kicad French to English translator.
 

Offline retiredfeline

  • Frequent Contributor
  • **
  • Posts: 539
  • Country: au
Re: SDCC-Anyone using it for PIC micro's?
« Reply #8 on: August 30, 2021, 06:10:51 am »
I briefly played with SDCC for PIC after using XC8. A couple of things: you have to install the device specific headers package, it's not installed by default with SDCC, maybe due to incompatibility with GPL. The other thing is that it uses different downstream utilities from the usual adapted asxxxx assemblers and linker; it uses gputils assembler and linker. I think that is historical. That's probably why the PIC target is unmaintained.
 

Online Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 3361
  • Country: nl
Re: SDCC-Anyone using it for PIC micro's?
« Reply #9 on: September 02, 2021, 01:55:55 am »
I simply do not use PIC's because they're not friendly with open source tools. Apparently some of their micro's run GCC but they try to hide that stuff.

I do use some of the older AVR's such as the m328 and even the ATMEGA8. "avr-gcc --version" gives 5.4.0 from 2015 on my system so apparently they don't bother to make linux packages for it. I'm fine with a compiler from 2015 though.

"arm-none-eabi-gcc --version" gives (15:9-2019-q4-0ubuntu1) 9.2.1 20191025 (release) [ARM/arm-9-branch revision 277599] so almost two years out, and I'm fine with that too.

If you're just interested in SDCC, then I recommend to get a few micro's that are properly supported by it. The Cypress CY7C68013A may be a good choice. It's the chip in the cheap Logic Analyzers supported by Sigrok/Pulseview. It also has a nifty USB device (which is why it's used as a LA).
It is a bit of a weird chip though. It does not have FLASH. It does have a bootloader that can read an USB id from an EEPROM, and then waits for software via DFU. Good thing is that you can't brick it, and the Flash can't wear out. I think it can also load a program from the I2C eeprom, but I'm not sure. I never looked at the details of that chip. It is an 8051 core, but that does not matter much if you program it in C.

The STM8 series may also be interesting if you want to experiment SDCC. The're just regular off-the-mill micro's, but that is also the target for SDCC.
https://en.wikipedia.org/wiki/STM8

https://en.wikipedia.org/wiki/Small_Device_C_Compiler


 

Offline brucehoult

  • Super Contributor
  • ***
  • Posts: 4039
  • Country: nz
Re: SDCC-Anyone using it for PIC micro's?
« Reply #10 on: September 02, 2021, 03:55:46 am »
If I were involved with teaching, I would be all over Arduino.  The Arduino Nano is $10 at Amazon and the very popular Arduino Uno is $35.  There are Starter Kits (of parts) all over Amazon and some come with really good documentation and tutorials.  VERY good tutorials!  Plus, there are projects all over the Internet and hundreds of videos.

Agreed. I really can't see any point to use PIC at this point, unless you're someone who's been using it for decades.

The ELEGOO Uno clone is $14 by itself. I don't notice any quality difference between them and official Unos. I think it's only $1 more for their Mega2560!

ELEGOO also have a pack of three Arduino Nano clones for $16, including headers you can solder on if you want.

Arduino Nano of course has the usual ATMega328 with 2 KB RAM and 32 KB flash, same as the Uno.

For projects that don't need many pins (5 IOs if you don't want to risk easy reprogramming by repurposing the RESET pin), it's also fun to use bare DIP8 ATtiny85 chips, which don't require any external components at all, cost about $1, and can be easily programmed using an Uno.

For code that uses mostly 8 bit variables with a few 16 bit thrown in, the AVR instruction set is just about as friendly to both the compiler and the assembly language programmer as ARM, especially the cut-down ISA in the Cortex M0(+).

AVRs are a *lot* easier to program bare metal without using library code to initialise the hardware.

The $4 Raspberry Pi Pico is also a great new choice, with 133 MHz, 264 KB RAM, 2 MB flash, dual Cortex M0+ cores, and very comprehensive and understandable documentation.

The $5 Sipeed Longan Nano is a dark horse contender. You get 108 MHz RISC-V CPU, 32 KB RAM, 128 KB Flash. As a bonus, the $5 price includes a 160x80 RGB LCD display. The documentation isn't as good as Arduino and Pi Pico, but it's not bad. You could certainly build courses around them. They're supported by the nice PlatformIO IDE.


It's really quite amazing that you've got good AVR, ARM, and RISC-V options for around $5 a board, all with easy power and programming via a USB connector.

At those prices, you don't care if students break a few of them.

These $5 boards look not quite as convenient as an Uno to get started with, but add the header pins and plug them into a cheap breadboard (which you quickly need with the Uno anyway) and it's basically the same.
« Last Edit: September 02, 2021, 07:38:44 am by brucehoult »
 

Offline JOEBOBSICLE

  • Regular Contributor
  • *
  • Posts: 63
  • Country: gb
Re: SDCC-Anyone using it for PIC micro's?
« Reply #11 on: September 02, 2021, 06:49:06 am »
I quite like up5k, you can fit a Pico rv32 core on it and then treat it like a micro
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5912
  • Country: es
Re: SDCC-Anyone using it for PIC micro's?
« Reply #12 on: September 02, 2021, 10:04:16 am »
ARM for starters! And cyanide for dessert? Probably they have never touched registers, bits, addresses, flags... they're about to learn these things.
Exposing them to a such complex architecture is like learning bike riding in a 45ยบ downhill. There's just too much of everything.

AVR/PIC are the perfect choice the wake their curiosity, they'll eventually go for better options by themselves.
Set up some config bits, TRISA registers and you're ready to blink some leds, no more than 20 asm instructions. Try that with an arm!  :-DD

The only thing I'd really take care of is having debugging support. Some pic10/12/16 can't be debugged without a a specific (and expensive) header.
You'll definitely want to make them see how their code works in real time!


Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Online Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 3361
  • Country: nl
Re: SDCC-Anyone using it for PIC micro's?
« Reply #13 on: September 02, 2021, 11:47:16 am »
OP never said anything about the educational market.
[ Edit ] Oops, I think I goofed up a bit here...

I'm not sure if his main thing is doing something with PIC's, or curiosity for SDCC.

I think it's clear that those two do not mix together well and it seems we need more feedback from him before something conductive can be said (written).
« Last Edit: September 02, 2021, 04:46:01 pm by Doctorandus_P »
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5912
  • Country: es
Re: SDCC-Anyone using it for PIC micro's?
« Reply #14 on: September 02, 2021, 12:01:53 pm »
OP never said anything about the educational market.


My aim is to make a set of simple examples for use by the students where I work.
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline voltsandjolts

  • Supporter
  • ****
  • Posts: 2300
  • Country: gb
Re: SDCC-Anyone using it for PIC micro's?
« Reply #15 on: September 02, 2021, 12:14:55 pm »
I agree with DavidAlfa comments in reply #12.

When introducing students to microcontrollers I think AVR (8bit) would be great choice.
Nice memory space arrangement, nice instruction set for asm, great FOSS compiler gccavr, option to use Arduino stuff, datasheets much smaller than 32bit ARM devices.

Starting with ARM is dropping them in at the deep end, although that could work, with prepared environment and very focused examples for them to modify.
I think the risk of losing the less electronic-experienced students is much greater.
 

Offline brucehoult

  • Super Contributor
  • ***
  • Posts: 4039
  • Country: nz
Re: SDCC-Anyone using it for PIC micro's?
« Reply #16 on: September 02, 2021, 12:50:09 pm »
Starting with ARM is dropping them in at the deep end, although that could work, with prepared environment and very focused examples for them to modify.
I think the risk of losing the less electronic-experienced students is much greater.

The ARM instruction set itself is fine, certainly the Cortex M0 instruction set is not complex.

The RP2040 datasheet is about twice the length of the ATMega328P datasheet, but I think it 1) does have a bit more functionality available, and 2) explains each thing a bit more simply.

The RP2040 has an on-chip ROM which initializes hardware and also contains a number of useful library functions including popcount, reverse, clz, ctz, memset, memcpy, functions to read and program flash, an almost IEEE single and double precision soft floating point library (denorms are set to zero, NaNs are treated as infinity, basic functions are correctly rounded, scientific functions are accurate to 1 ULP). After initialization of hardware, the ROM calls a replaceable bootloader in flash which is somewhat like the Arduino bootloader in providing easy downloading of new applications via USB or running an already installed one.

It's probably not as easy to get started with as an AVR, but it looks close.
 

Offline JPortici

  • Super Contributor
  • ***
  • Posts: 3461
  • Country: it
Re: SDCC-Anyone using it for PIC micro's?
« Reply #17 on: September 02, 2021, 01:27:21 pm »
I remember when i took an embedded course when i attended uni (note i had previous experience with PICs in high school, both asm and C)
in this course were going to use the STM32 with the STM32F103DISCOVERY.

The thing was great because for ten euros we had this little self contained board, programming was a bit difficult at first because of the hal with almost zero information that you could gather from the datasheet (because it used different naming) or that pile of uselesness that is doxygen documentation. If you are used to microchip's or TIs datasheet you will understand the pain.

The thing was less than great because the tutors insisted in using linux, gcc and eclipse with everything set up manually by following their point to point list, because reasons.
I hated that. I still hate that. I hate eclipse, using eclipse, having to set up a lot of things manually over and over and over and if something doesn't work because something in the installation or because today's moon is unfavourable you are on your own, in the tutor's pc is working. In that guy's blog is working.
And even though today things have become simpler (eclipse installation manager actually works!) it's still a lot of effort for somebody used to commercial just-works tools or someone with zero knowledge, the point of the course should be learning about programming, not debugging the IDE and compiler installation.

The beauty of MPLAB(X) which has/had the assembler built in (had because starting from 5.40 the assembler is the one in XC8 as mpasm got deprecated), or the compiler that just work (tm): create a new project, select the part, start programming. Done. Can't beat the simplicity. Maybe platformIO is even simpler to use (but i dislike those tools for other reasons)
 

Offline HB9EVI

  • Frequent Contributor
  • **
  • Posts: 722
  • Country: ch
Re: SDCC-Anyone using it for PIC micro's?
« Reply #18 on: September 02, 2021, 02:21:03 pm »
I worked a while on SDCC for PICs, but since nobody wants to maintain the code and it heavily depends on proprietary files from Microchip, I gave up on it and the whole PIC uC.
it didn't come out of the blue sky, that AVR uCs became the choice for the Arduino platform, though I consider it a very nasty platform, but that's another story
imho Microchip came too late with their newer PIC16F series, but since they bought ATMEL, it doesn't really matter no more.
the learning curve for ATmega/ATtiny is rather flat, there's a well developed compiler so no real need for a PIC environment.
I wouldn't bother too much with SDCC and either go down the AVR or directly the ARM route
 

Offline spth

  • Regular Contributor
  • *
  • Posts: 163
  • Country: de
Re: SDCC-Anyone using it for PIC micro's?
« Reply #19 on: December 01, 2021, 03:16:47 pm »
The STM8 series may also be interesting if you want to experiment SDCC. The're just regular off-the-mill micro's, but that is also the target for SDCC.
https://en.wikipedia.org/wiki/STM8

https://en.wikipedia.org/wiki/Small_Device_C_Compiler

The STM8 is a great choice for SDCC. At the moment, the stm8 port in SDCC is IMO the most advanced, and really shows what SDCC can do.

In 2020, I compared of four compilers for STM8:

http://www.colecovision.eu/stm8/compilers.shtml

AFAIK, all compilers have seen improvements since then. For SDCC I know that they have been substantial, am I'm looking forward to redoing that comparison after SDCC 4.2.0 gets released (probably early next year).
« Last Edit: December 01, 2021, 04:22:07 pm by spth »
 
The following users thanked this post: djsb, voltsandjolts


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf