14 votes

RISC-V implemented in a night

4 comments

  1. [4]
    Gyrfalcon
    Link
    As someone with an interest in embedded systems what's the best way to get into something like this?

    As someone with an interest in embedded systems what's the best way to get into something like this?

    3 votes
    1. [3]
      s4b3r6
      Link Parent
      Depends on what you mean by 'embedded'. a) Programmable Hardware, like this FPGA, which is outside my wheelhouse. I know it's usually in Verilog, like this project, and usually uses very...

      Depends on what you mean by 'embedded'.

      a) Programmable Hardware, like this FPGA, which is outside my wheelhouse. I know it's usually in Verilog, like this project, and usually uses very proprietary toolchains and very expensive chips. But that's about all.

      b) Microcontrollers. I'm fairly familiar with AVR chips, which have begun to fall out of favour due to higher power consumption, and rather small memory footprints. Don't optimise, get a ARM M0. C is king here. Or rather, C-style C++, as most toolchains will use a C++ compiler, though most of the C++ library will either be unavailable, or impact performance too much to be justified.

      c) Small-scale Linux devices. They still get called embedded, but are far beefier with a much bigger set of concerns, such as security, update routines, and the like.


      I fall into microcontroller territory, which is thankfully not so hard to learn.

      You can start out small, and learn what you need along the way.

      As much as they are ripped on by the community, you can start out with an Arduino - just try not to start out with the Arduino IDE. The not-quite-C++ language they use abstract over most of the things you actually need to know. (A cheap Chinese-clone Arduino can be as little as $2).

      The toolchain choice is simple enough, if we're not touching the Arduino IDE:

      a) Atmel Studio

      b) Any text editor, avr-gcc, avrdude.

      A pure-C equivalent to the Arduino 'blink' example, would probably be:

      #include <avr/io.h>
      #include <util/delay.h>
      
      int main(void) {
        /* Set the register to output */
        DDRB |= _BV(PORTB5);
      
        while(1) {
          /* Bitshift the register to on */
          PORTB |= _BV(PORTB5);
      
          _delay_ms(1000);
      
          /* Bitshift back the other way. */
          PORTB &= ~_BV(PORTB5);
      
          _delay_ms(1000);
        }
      
        return 0;
      }
      

      Understanding the bitshifts needs two parts:

      • Understanding how C works
      • Knowing what addresses are defined in the AVR header files

      But basically DDRx sets the direction of the pin, input or output.

      And PORTx is the group of pins being accessed.

      To dive in more, there are a few books like this one that can help, and more to find online too. But, a good grasp of C is where it starts.

      2 votes
      1. [2]
        Gyrfalcon
        Link Parent
        Thank you so much for pointing me in the right direction! I have a Raspberry Pi that seems to fall more in the third category you mentioned. I've done some C and C++ programming, including using...

        Thank you so much for pointing me in the right direction! I have a Raspberry Pi that seems to fall more in the third category you mentioned. I've done some C and C++ programming, including using the Pi to do some control in Kerbal Space Program. The book you mentioned is available at my school's library. I did download this book as well as this book from my library, though I'm not sure if they are much good.

        There's also this tutorial I found which seems to be using C for GPIO, so I will have to check that out. I think for me right now reading the books and applying that to my Kerbal adventures should be good, although I did learn that there are FPGA boards that you can plug onto the Pi GPIO and program that way, so I could look into that more. Thanks again!

        1. s4b3r6
          Link Parent
          It's a bit of both. You can run 'baremetal' code on the Pi, using it as a microcontroller, basically. First one is for a PIC, which if you can get your hands on one, will teach you just as well as...

          I have a Raspberry Pi that seems to fall more in the third category you mentioned

          It's a bit of both. You can run 'baremetal' code on the Pi, using it as a microcontroller, basically.

          I did download this book as well as this book from my library, though I'm not sure if they are much good.

          First one is for a PIC, which if you can get your hands on one, will teach you just as well as an Arduino - though they aren't nearly as much used as they once. The PIC16C84 was probably the most popular hobbyist microcontroller at one time.

          1 vote