[HN Gopher] Programming PIC32 Microcontroller with Rust
       ___________________________________________________________________
        
       Programming PIC32 Microcontroller with Rust
        
       Author : pjmlp
       Score  : 89 points
       Date   : 2021-10-10 14:49 UTC (8 hours ago)
        
 (HTM) web link (gill.net.in)
 (TXT) w3m dump (gill.net.in)
        
       | brandmeyer wrote:
       | One detail of note: PIC32 is a modern microcontroller built up
       | around a MIPS core instead of one of the older (oddball) 8- or
       | 16-bit PIC cores. MIPS is much easier to support in a compiler
       | than the legacy PIC instruction set.
       | 
       | It is certainly possible to make an 8-bit core based on RISC
       | principles (ex: AVR), but the PIC wasn't. Classic PIC has a hard-
       | earned reputation for awful compiler support.
        
         | phkahler wrote:
         | The Hi-Tec (sp?) Compiler was excellent on those parts.
         | Microchip even recommended it over their own.
         | 
         | Those parts didnt support stack variables, so that compiler
         | would analyze the call tree and essentially use global (fixed
         | address) variables for locals, but it could reuse them in
         | different functions.
         | 
         | Yes a pain for the compiler, but at least one did it really
         | well.
        
           | mrpippy wrote:
           | Microchip bought HI-TECH a few years ago and rebranded the
           | 8-bit PIC compiler as XC8 (and discontinued their own
           | compiler).
           | 
           | It's the only one of Microchip's compilers that's not GCC-
           | based, which can be a pain. Also I remember at -O0, the
           | generated code is just huge and inefficient.
        
         | ansible wrote:
         | > _Classic PIC has a hard-earned reputation for awful compiler
         | support._
         | 
         | Did it? I didn't realize.
         | 
         | Though I did find at least one bug in the code generation for
         | the compiler we were using ~15 years ago... Something funny was
         | happening with the generation of an if statement, don't
         | remember the rest of the details.
        
           | ManDeJan wrote:
           | May I ask, what language you were using back then?
        
             | eggy wrote:
             | No OP, but I used C and asm. Hi-Tech c compiler. I had no
             | issues with it. Very simple and straightforward to code the
             | PIC chips. I forget how much I paid for it.
        
             | ansible wrote:
             | Good old C. I am moderately sure it was the MPLAB software,
             | I remember we had several of their ICD JTAG units (the
             | round ones). But it might have been Hitech.
        
       | axegon_ wrote:
       | A few personal takes on the microcontroller/embedded rust side:
       | I've been fiddling a lot with the stm32 and rust over the past
       | several months. The fact of the matter is that having rust at
       | your disposal feels like you are given a set of high quality
       | scalpels compared to the otherwise good old C. I mean having a
       | package manager and easy access to third party libraries is an
       | absolute heaven and it's a very enjoyable experience. BUT... It
       | is enjoyable once you have everything up and running of course,
       | which on the other hand is a huge pain in the ass. I feel like
       | there is a gap to be filled between plugging in an embedded board
       | and running a simple "blink the led" program. Unlike say an
       | arduino(or even a raspberry pi pico which I genuinely dislike
       | after fiddling with it as well), where you simply plug it in,
       | open the arduino IDE and click "Upload". If someone dumbs the
       | process down to something like that for Rust, I feel like it
       | would completely take over this niche.
        
         | drran wrote:
         | My attempts on this:
         | 
         | https://github.com/vlisivka/rust-arduino-blink - just minimal
         | blink
         | 
         | https://github.com/vlisivka/rust-arduino-hello-world - just
         | print "Hello, world" to serial port.
         | 
         | https://github.com/vlisivka/rapt - little shell for pin testing
         | (turning them on/off via serial port).
        
         | SAI_Peregrinus wrote:
         | Have you tried Ferrous Systems' probe-run? It's basically that.
        
       | eggy wrote:
       | Nice article. I used to program 8-bit micros, BASIC Stamps, etc.
       | back in the day (early 90s)for animatronic effects for store
       | windows and malls. Mainly electric, pneumatic systems. I even
       | used a capacitive touch sensor through the window of Saks Fifth
       | Ave. to allow children to touch the glass in front of a
       | Nutcracker and have it raise and sound a bell. They loved it!
       | Early touchscreen tech! (I had an NCR 3125 with PenOS and a
       | touchscreen at the same time, so not exactly revolutionary). Most
       | of the logic was pretty simple, so C or asm or even BASIC were
       | fine, and easy enough to step through in my head. At that level,
       | I did not really have very intricate logic or lengthy programs. I
       | picked up the book, "Building High Integrity Applications with
       | SPARK", and read a few articles on how to rewrite portions of C
       | code with SPARK and I am sold on using it for larger embedded
       | projects[1]. I am sure Rust can do the same albeit not with the
       | same ecosystem that you can use with SPARK to the same level -
       | yet. I am happy to see them start to cross pollinate each other
       | with the best ideas from both. I am biased to SPARK, since it was
       | easier for me to understand the syntax, and the concepts as
       | opposed to my efforts with Rust. But this is my preference. I
       | prefer programming in J/APL, so take this with this with a grain
       | of sal(J or APL embedded programming, hell yeah!). It can only
       | get better for both Rust and SPARK from here on in.
       | 
       | [1] https://blog.adacore.com/how-to-prevent-drone-crashes-
       | using-...
        
       | sharmin123 wrote:
       | The Best And Easiest Ways To Protect Yourself From Hackers:
       | https://www.hackerslist.co/the-best-and-easiest-ways-to-prot...
        
       | petrohi wrote:
       | Very glad to see Rust on PIC32! This microcontroller is one of
       | the very few that is still made in DIP package making it ideal
       | for breadboardind and easy through-hole soldering, and by far
       | most powerful, making it ideal choice for interesting projects.
        
         | analog31 wrote:
         | I spent many years with PIC chips, starting with PIC16C84 and a
         | homemade EEPROM programmer on my DOS machine. One thing I like
         | to this day is that the PIC chips were extremely well
         | documented, and the documentation style was consistent across
         | their product line. This in turn made bare-iron programming
         | relatively easy.
        
           | eggy wrote:
           | I still have my UV EPROM eraser from those days. My friend
           | used an old chip of mine with the brass frame around the
           | quartz window as a base for jewelry design. They do look cool
           | on their own!
        
       ___________________________________________________________________
       (page generated 2021-10-10 23:00 UTC)