Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

embedded c++ Q

  • 04-11-2008 9:28pm
    #1
    Closed Accounts Posts: 7,134 ✭✭✭


    Hi guys

    I have a degree in microelectronics and as im outta work im thinking of learning some embedded c, for microcontrollers etc.

    Im a n0b with programming, but have done some embedded c at uni.

    Is there any good books to get me off the ground and is it very hard to master.?

    cheers.


Comments

  • Registered Users, Registered Users 2 Posts: 5,401 ✭✭✭DublinDilbert


    Hi guys

    I have a degree in microelectronics and as im outta work im thinking of learning some embedded c, for microcontrollers etc.

    Im a n0b with programming, but have done some embedded c at uni.

    Is there any good books to get me off the ground and is it very hard to master.?

    cheers.

    I've never found embedded books to be very good.... i normally just get a demo kit and start writing some code...

    There's lots of really cheap demo kits out there that come with code which you could modify etc...

    Microchip PIC's or AVR's would be good to learn on. Demo kits are really cheap... and the C compilers are free...

    What sort of embedded projects would you like to work on?

    What sort of communications would you like to have on board?

    I notice your title says C++, most smaller embedded systems just use straight C.


  • Closed Accounts Posts: 7,134 ✭✭✭x in the city


    I see, well I notice in alot of jobs, embedded c++ is mentioned,. I would like to be a bit more prolific on it.

    I did atmel avr stuff for my uni project. I guess that embedded c is used now for all sort of home entertainment, personal devices, consumer gadgets etc so thats the area I would be interested in. (ie: zigbee/nordic rf transceivers, low power consumer embedded processors blah blah..)

    I would just like to get more useful with programming, it would help alot I think for jobs.

    cheers.!


  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    Bare in mind that a lot of these gadgets are moving to Linux (For Cost/Productivity/Device Support Reasons) or have their own little OS. I am currently working on an embedded device for my final year project - A Car Monitor that provides statistics etc in a ARM embedded unit.
    I will be running linux along with C++/QT for the GUI/Application side.

    I don't think true embedded only C is used much on larger devices. It would be more on real time devices that require deterministic response times but then there is RealTime Linux for this. RTLinux.
    I am excited getting into the embedded arena also so thought Embedded Linux was the way to go and along with C++/QT. Course you are looking at controlling microcontrollers directly with C which is a different ball game (Something I'd love to go into as well, but that more electronic engineering side).


  • Registered Users, Registered Users 2 Posts: 5,401 ✭✭✭DublinDilbert


    Webmonkey wrote: »

    I don't think true embedded only C is used much on larger devices.

    Well actually for core Automotive applications C is recommended, as per the MISRA guide-lines. The MISRA guide-lines do not allow dynamic creation of objects etc....

    I'm not saying C++ is not used in embedded applications it is, in particular for user interfaces etc...

    But if you going to work in embedded applications you should know C and know how to write your own co-operative operating systems...

    Its great if you have the luxury of a linux busy-box type OS, but you won't always have the resources to run that. For example you can design embedded Ethernet devices without running linux...


  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    Oh yeah I know that. I'm just doing a OBDII reader device that displays the speed you driving at, rpm etc. Nothing major. Obviously for deterministic systems, the ECU would be better coded at low level C.

    I'm talking about gadget embedded systems such as Phones, PDAs etc. Just telling the OP there might be another path he like to try


  • Advertisement
  • Closed Accounts Posts: 5,361 ✭✭✭Boskowski


    There is absolutely no requirement not to use C++ in embedded programming. Not even in realtime stuff. Makes for much better code.

    What's the difference anyway? As it happens some of the C++ compilers create C code during the preprocessor phase and compile that into object code.
    IMHO if you're accessing devices/hardware do your device drivers in assembler/C and then get into C++ as quickly as possible. The overhead is insignificant with the CPU power you get these days for no money at all even for very small devices/CPUs/environments. Ok some of the real fancy C++ stuff like templates could be tricky and may need avoiding but other than that...

    You need to be disciplined with your memory management but of course you need to be disciplined with that anyway.

    For almost all platforms you get decent C++ compilers now. Theres also a lot of ports of the GNU compiler too.


  • Closed Accounts Posts: 7,134 ✭✭✭x in the city


    Right lads,

    thats all well and good, but im a n0b when it come to either c or c++...

    whats the difference between these?!

    Is there any books I can use to get me up and running than dont have 1200 pages and need a phd in neuro science to understand?


  • Registered Users, Registered Users 2 Posts: 5,401 ✭✭✭DublinDilbert


    realcam wrote: »
    There is absolutely no requirement not to use C++ in embedded programming.

    I never said C++ shouldn't be used in embedded systems. Its important to know C and C++, which you use will be dependant on the system. In some applications like automotive ECU's they recommend just using C.
    thats all well and good, but im a n0b when it come to either c or c++...
    whats the difference between these?!
    C++ is object oriented.
    Webmonkey wrote: »
    Oh yeah I know that. I'm just doing a OBDII reader device that displays the speed you driving at, rpm etc. Nothing major. Obviously for deterministic systems, the ECU would be better coded at low level C

    Sounds like a cool project. Are you communicating via the K-L lines or the CAN Bus?

    It might be worth getting your hands on some ECU's and wiring them up on your bench for testing....


  • Registered Users, Registered Users 2 Posts: 188 ✭✭stylers


    stick to C first, I would think C++ is not necessary where you are just using a micro for simple programming tasks dealing with I/O and simple decision processing/calculations. Big scale embedded (think mobile phones and gadgets and the like) does use C++, but that is on a whole different level involving operating systems etc.
    I'm not sure if there is a whole lot of material dealing with embedded C++ out there either.
    If you are a total newbie to C, it will help enormously to get a simple C compiler/IDE like DevC++ (or GCC/gedit etc. on linux) up and running and do some programming on the PC first, doing simple stuff like "Hello world", and simple programming constructs, variables, pointers etc.

    For books on C, the one that is recommended most for C newbies / converts to C is the original Kernighan and Ritchie C "bible". But most embedded books have a primer on C to start off with anyway.

    Then you could do a bit on the processor of choice.

    There is lots of material out there, but some books on embedded C tend to use a particular development board or processor, and the examples and programs given are thus hard to do unless you have the same environment.

    At this stage it may be worth choosing a target processor. the easiest ones to program are probably the microchip PIC18 series and atmel AVR, which have very mature tools and compilers available, and lots of dev boards available. for example, look up "Sure Electronics" on Ebay, where you can get PIC and AVR development boards and programmers (PICkit 2 for the PIC) complete with LCD display etc. for very few beans,
    proprietary embedded compilers are expensive, but GCC for the AVR is totally free, and microchip have the student version of their C18 compiler which is free, and not too badly crippled. I have been using an open-source compiler called SDCC (small device C compiler) which can target many different processors. One caveat of proprietary compilers is that they may use special "extensions" which are not part of ANSI C, in order to do things which are peculiar to the embedded environment..

    If you do decide to get an embedded C book, try and make sure it uses the compiler of interest to you, as it will be a lot more useful in the long run.


  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    Sounds like a cool project. Are you communicating via the K-L lines or the CAN Bus?

    It might be worth getting your hands on some ECU's and wiring them up on your bench for testing....

    I'll be using the regular 5 OBDII protocols, CAN/KWP2000/Jxxx etc. Won't deal with proprietary stuff.
    I am going to use the ELM327 chip that interprets all and provides a RS232 interface to it.
    It's quite a cool chip. For testing though, it would be good idea to wire up stuff alright but I wouldn't have expertise on this.
    Would it be simple? I was working with a guy that worked years in Car Diagnostics and said it be simple out.
    The GUI side will involve using QT's kit and write directly to frame buffer but I can simply create the application first on a Win/Linux x86 environment and then cross compile.
    Fun times ahead :)

    I've a discussion on the unix side here:
    http://www.boards.ie/vbulletin/showthread.php?t=2055400078

    (Sorry OP for going slightly off topic)


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 188 ✭✭stylers


    For Webmonkey,

    you could power up an ECU on the bench for initial communications/testing. All you'll need is a 12V supply and maybe an LED for a MIL light so you know its alive. something out of a 01 - 04 european car would probably be better so you know it supports OBD2. maybe see if you can pilfer an ECU somewhere (even one thats tossed due to being faulty some way, but not dead) or out of a scrappy (don't pay too much for it though). If you need pinouts just give us a shout..


  • Registered Users, Registered Users 2 Posts: 5,401 ✭✭✭DublinDilbert


    This might be of interest, its an ECU emulator:-
    http://www.geocities.com/darkyp/eng/ecuemulator.html


  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    Thanks guys. Once again OP sorry for hijacking the thread!


  • Registered Users, Registered Users 2 Posts: 413 ✭✭ianhobo


    Hi guys

    I have a degree in microelectronics and as im outta work im thinking of learning some embedded c, for microcontrollers etc.

    Im a n0b with programming, but have done some embedded c at uni.

    Is there any good books to get me off the ground and is it very hard to master.?

    cheers.

    Well, as my browser crashed and lost the previous 30mins I'd already spent replying, this may not be as concise!

    As you said you were new (or at least that its been a while) to c/c++ programming, you don't exactly need to be too concerned with embedded C as such. Embedded C is 90% the same as normal C, so with that in mind, there is no problem starting with a desktop C IDE and learning about data types, functions, parameter passing, linked lists, queues, buffers, pointers, function pointers etc
    If you can understand all of those concepts, applying them in an embedded environment will be no problem at all

    As for a book, I would personally recommend the "Sams teach yourself" books. I found them to very well organised with some great examples. Some people recommend the Kernighan & Ritchie C book, given that they wrote the language, however the ANSI C standard has undergone two whole revisions since they started in the 70's. Pure Kernighan & Ritchie C in NOT guaranteed to be ANSI compliant C. I find some of their techniques too "funky", and not exactly straight forward. However thats just my opinion, the book may perfectly suit others

    Two great websites are cprogramming.com and cplusplus.com! I'm on them every day

    As for C vs C++, google will be more thorough:
    C is a procedural language with basic well defined data types. C++ on the other hand is a super set of C. This means that c++ fully supports c an addition to its own elements. These elements include object orientated programming through the use of classes. c++ boasts a larger standard lilbrary, and a thing called the STL ( another library of pre written templates)

    As for whether to use C or C++ in embedded programming, it depends on your device being programmed, among other things. C++ programs tend to produce larger (in terms of bytes) programs than C. This is because the standard libraries which c++ use are larger than the C libraries. While this isn't an issues in a desktop enviroment, if your embedded device only has a few kilobytes to store program code, it can quickly become an issue.

    Larger embedded devices can still use C over C++, there is no prerequisite. Both languages will produce efficient code if well written. It is often more for design reasons why one is chosen over the other.

    When you ready, often the easiest way to begin programming embedded devices at home is to buy a development board either from a shop (maplin,petes) or from a web site.

    As for what to choose, that will start a whole debate in itself! I would recommend getting something that is cheap, and easily available because you WILL damage the micoprocessor very easily! So you need to be able to quickly and easily replace the parts. The development boards the kits come with loose their usefulness very quickly, they often only have a few LED's that you can control, so bear that in mind when making your purchase, later on you will want to be building your own circuits around the processor ( I imagine) and expanding on the kits/circuits. For that reason, I would recommend one the Velleman PIC kits from maplin or petes. They come with a programming and simple development board, an 8-bit micro processor, and the tools you need. You will often need a specific compiler for the type of microprocessor you choose, all c programs have to be compiled for a specific processor. These are enough to get going, later on, you can put to processor into your bread board and circuit, and use the programmer from the kit to flash the chip.

    Other popular chips and kits include the Atmel Range, 8051 (LOTS of stuff available on the net), the PIC range, the texas MSP 8-bit processor range

    An important note :) Most of the development boards needs a real serial port in order to program the chips! A simulated one like the USB to serial devices will not work!

    ok, thats probably loads of useless info!
    Feel free to ask anymore questions, theres lots more I can waffle on it

    Ian


Advertisement