7
Bubbles
3y

Does anyone here have any good resources for introduction to embedded, low level development, or anything on advanced C concepts? I've been having trouble trying to step into more complicated topics like bit manipulation and stuff I can do with memory management. Also any advice is also appreciated.

Comments
  • 3
    You'd need to learn about actual data organisation in memory on byte level and alignment of data types, because while the compiler will do that for you, there are still some potential gotchas like padding behind the scenes.

    Another topic is integer types. In C, an integer is at least 16 bits wide, a long int at least 32 bit - but they can (and often do) have more. Use the plain types if the minimum range is OK, otherwise check out the portable data types like uint32_t, uint_ptr, size_t.

    Bit manipulation is easy: just check out the truth table of &, |, ^ for one bit and then have several bits in parallel in a multi-bit variable such as an integer.

    Undefined behaviour in C is also important, unfortunately, because code may compile, but not do what you intended. Always fix all compiler warnings, though that's still not bullet-proof.

    IMO, you'll need a solid grasp on C before you go embedded unless all you want is clicking some ready-made Arduino sketches together.
  • 3
    @Fast-Nop so how would I go about learning these things?

    Are there projects that will force me to experience undefined behavior and need to watch what data types I use?

    I have a little experience picking the right data type for the job but undefined behavior I do not.

    I don't mind waiting a bit to do embedded work if it means a better grasp on C, I'm just struggling with how I can go about doing that.
  • 2
  • 3
    @Bubbles I had a superficial C book for learning and then piled on over the decades, which is probably not the best way to do it. Then again, we didn't even have the portable C99 data types back then.

    I'd recommend googling for stuff like alignment and padding, and probably also an IDE that has a graphic debugger with memory display so that you can examine how e.g. strings, arrays, and structs actually look in memory. Also, how the struct layout changes if you change the declaration order of struct members like one, two, and four byte types.

    As for undefined behaviour, you could start out with https://blog.regehr.org/archives/... and http://blog.llvm.org/2011/05/... plus their follow-up articles.
  • 2
    If you have no µC programming experience, ask around "makers" what µControllers have the biggest community and get a dev board for one of them. Start tinkering around with it in assembly or C and search the web for the information you need. The community of choice will also know what projects are best for starting on the chosen µC.
  • 0
    @Oktokolo I want to mess with ASM but I'm not sure what to do or where to start with it
  • 1
    @Bubbles I learned ASM back then on a C64. You might want to go for a more modern plattform though... 😀

    Do you already know a nice embedded plattform, you are interested in?
  • 2
    "more complicated topics like bit manipulation"

    Bit manipulation are not complicated, in fact they are probably the easiest thing you can do in programming.

    Microcontroller are a lot easier to understand than applications running on a OS (no file systems, library management, no syscalls, not different processes, no IPC, ....). I suggest you buy a board with a Microcontroller (µC) to program (if you can buy one, µCs are constantly sold out), and start programming, start with something very simple such as toggle a pin in a loop.
  • 2
    @Fast-Nop I think the opposite is true: Embedded is the easiest to start with. I learned to program C on a 8051-compatible µC. It is a lot easier than Programming on a Computer* and it is easier to understand every single bit of it.

    *With that i mean, it is easier to write some functional code that is useful for that platform. Of course if you try to do exactly the same as on a PC, it is often harder or impossible. Software on a PC can much more and is more flexible.
  • 0
    @Oktokolo I tried looking at the AMD 64bit assembly instructions
  • 1
    @happygimp0 Then again, a PC hides the actual HW stuff behind convenient I/O libraries for you. With a µC, you also have to go through the datasheet and understand how the HW works. While that is indeed valuable, in particular for low-level devs, it's not where I'd start out.

    Especially not with a pretty sick architecture like the 8051 with its rather confusing RAM layout. Then again, Cortex-M doesn't have that problem, but it's pretty difficult to get going because it's rather complex.
  • 1
    Do you have an oscilloscope or/and a logic analyzer? They can be very handy for debugging and understanding what is going on.If not, do you have a Multimeter?

    Do you have a preference which architecture you want to use, or which manufacturer in case of ARM (There are a lot of ARM manufacturers that all have different ways of accessing peripherals and different programmers)?

    Do you have some experience with electronics, for example do you know how you can connect a LED to your controller?
  • 0
    @Fast-Nop The IO-Libraries are complex and very hard to understand. You have to understand how libraries work, syscalls, and the OS, on top of how the hardware works. Yes you can use it without understanding it, but as a professional you better understand what is going on.

    But then again, you may have permission errors, other processes that uses something you want to use, ... things which you don't have to deal with on a µC's. I needed a lot less time to learn the UART on a new controller than i needed to learn the serial API on Linux.

    In the beginning, i only used the 128 Bytes of RAM that where directly accessible, you can learn a lot without needing more RAM.
  • 1
    @happygimp0 As beginner, you don't have to understand how the libraries work. You take I/O for given and first concentrate on the language.

    I prefer a top-down learning strategy where I first get the bigger picture and then drill into the details. The advantage is that I know where which detail belongs.
  • 0
    @happygimp0 I have an oscilloscope and a multimeter, I've wanted to mess with the STM32 and Raspberry Pi pico cause I've heard a lot of good things about both.

    I've also been told to look into FPGA but I feel like that's something I shouldn't mess with until I have micro controllers down.
  • 0
    Just to add I've started learning electronics too but I'm still not great at it yet, that's why I have an oscilloscope and multimeter
  • 1
    Many hacking /modding efforts for hackable devices can get you into it. As does a simple arduino, but it might be too easy and not motivate you or require to dig deep.

    With arduino, you could start with Arduino IDE and later recode a project with only Atmel Libs (e.g. with Atmel Studio or plain makefiles). Maybe even progress to writing parts in assembly.

    Also C on your pc can also expose you to many low level memory management things.

    Or follow tutorials for sw/games for emulators like "Writing a game for a N64" or similar.
  • 0
    @LinusCDE what about writing a game for an NES in 6502 ASM?

    Also I thought about playing with the raspberry pi pico and stm32 but not using the Arduino ide just following the docs of either one and compiling it directly for the board. I'm trying to avoid Arduinos and it's software as much as I can.
  • 1
    @Bubbles Having an Oscilloscope makes it a lot easier. Do you know how to use it?

    On the positive side, you find a lot of examples for Raspberry Pico and it is ARM for which many compilers exist. But it does not have LEDs you can control, you can't probe every pin and many examples are in some kind of Python (which means the code is far away from the generated assembler) and the controller is complex.

    For me, the hardest part was always and still is the toolchain: Having the correct compiler/linker with the correct settings, correct file format, programmer (hardware), including driver, programmer (software), debugger (software) and so on. This includes a way to control if the code is really running on the controller, like a GPIO that toggles, so you have to learn that too at the start. Once i know how i can compile, program, debug and run the correct code, things become a lot easier.
  • 3
    Also, keep in mind that some development boards like the Raspberry Pico, don't need a extra Programmer/Debugger Hardware, the Pico is special in this regard since you can use it as a mass storage and drop the complete ELF. This is not how you program Controllers used for productive systems. Instead they have a programmer with USB (or RS232, Parallel) on the PC side and a programming interface, such as JTAG, something based on SPI or I2C on the other side, that has 3-6 wires to connect the controller to. They are also systems with bootloaders, which you shouldn't worry about now.

    I personally think something like an 8 bit AVR or PIC is easier to understand than a 32 bit ARM. Because ARMs often have more clock systems (which you may need to enable to use GPIOs), more functions, more registers, bigger buffers and are faster (GPIOs are often slower than the core and you need to add a pause before toggle a PIN). Not saying you shouldn't start with ARM that is just my subjective opinion.
  • 0
    @happygimp0 I'm still learning how to use the oscilloscope.

    Do you think using a 6502 as a microcontroller would be a good idea?
  • 0
    @happygimp0 I appreciate your reasoning for not using the pico, I will probably take the advice. Ive just always thought it's a pretty cool little micro controller.

    Every time I've brought up using a microcontroller some people have kinda put it down cause "micro controllers are the easy way to do things" so I appreciate the enthusiasm a lot
  • 1
    @Bubbles I didn't say the Pico is a bad choice, because it is used a lot you are probably more likely to find help online. AFAIK the 6502 does not have real GPIOs, and needs external memory. If you are own your own, use a controller that has some RAM and Flash inside so you don't need external memory. Between the 6502 and Pico, the Pico is the better choice.

    I said, i would use a AVR or PIC*, but i am not you. And the problem is that i can't really help you when it does not work. It would help when you know someone in real life that can help you when there is a problem. Many problems can't be solved online. I hope you don't make a bad decision based on my (bad) input.
  • 0
    @happygimp0 I don't really know what AVR and PIC's are. I appreciate all the input, I just don't really talk to too many embedded devs so I have no clue what to think about any of it. It's nice to talk about it
  • 1
    @Bubbles Microcontrollers. Use a search engineering or Wikipedia. They have a Core (Most of them are 8 bit cores), RAM (often 1-8 KiB), Flash (often 1-128 KiB), GPIOs, Timers, UARTs/USARTs (Serial interface), I2C hardware and so on.

    They often don't need external devices, except bypass capacitors and sometimes a crystal (If you need a somewhat accurate clock, you need a crystal anyway) and power. On the other hand the 6502 you mentioned before is a microprocessor, it only has the core. The RAM and EEPROM must be external connected, the 6502 does not even have GPIOs. To program the 6502 you have to program the external EEPROM.

    You find microcontroller development boards in most electronic shops (Digikey, mouser, Farnell ...) or you can get them from producers like Olimex or MikroElektronika or from Microchip directly (Producer of PIC controllers and they bought Atmel, who made AVR).
  • 0
    @happygimp0 I know I'd need to buy registers and ram if I used a 6502 I just thought it would be a nice way to learn assembly
  • 1
    @Bubbles It would be great to learn how a CPU works, with RAM, EEPROM, IOs. If your goal is to learn that. Because everything has its own IC and you can physically see it.
  • 0
    @happygimp0 I've been down those rabbit holes and I'm still exploring them, Ben eaters helps a lot
  • 0
    Also for now I'm just trying to focus on understanding C more I just don't know what to look at or what projects to make. I thought about an interpreter or compiler of some kind but I don't know what I should try to do but I'd want it to be challenging.
  • 1
    @Bubbles If your goal is just the programming side, you should buy a complete microcontroller not a microprocessor that needs a lot of additional components in order to work.

    If your goal is just C and not embedded C, you could also start your own kernel which you can test in qemu (Also great when you want to learn concepts in modern CPUs, like MMU, privilege levels, CPU extensions like AVX which all don't exist in small microcontrollers) or make your own 3D engine.
Add Comment