Technology
Is There Anything as Embedded C?
Is There Anything as Embedded C?
Yes, absolutely. C compilers are available for most embedded processors nowadays. I personally have been using C for embedded processor applications for the past 20 years, witnessing a significant evolution in the technology.
My First Embedded Project
My first embedded project was in assembly language on a HC05 processor with 4k of ROM and about 100 bytes of RAM. This choice was not ideal for using C. Writing code for such a limited environment required a different approach, with only a few bytes and kilobytes available for storing and executing the program. This would have been a poor choice for tackling C due to the limitations of the limited memory and resources.
Advancements in Modern Microcontrollers
Nowadays, 32-bit microcontrollers are available that run over 100 MHz, feature rich instruction sets, and have upwards of a megabyte of flash and half a megabyte of RAM. These advancements have greatly expanded the possibilities for using C in modern embedded systems, providing not only more power but also the space to handle more complex and resource-intensive tasks.
Challenges in Using C
Despite the advancements, there are still some challenges to using C in embedded systems. The only thing you would NOT want to do is use the heap too much. While it is acceptable to create objects on the heap, repeatedly creating and destroying them can lead to heap fragmentation, making it difficult to allocate memory.
This restriction implies that you can't use a large portion of the Standard Template Library (STL). However, this does not mean that you cannot do anything useful. Despite these limitations, there is still a lot of functionality that you can leverage. For example, organizing your code into classes can be a significant improvement over the traditional C techniques I used on the HC05 processor. Even on the smallest Atmel processors, I found that using classes provided a more modular and maintainable way of structuring code.
The transition from C to modern C and the use of classes has significantly improved the reliability and maintainability of my code. The rich libraries and frameworks available in C have also made it easier to write efficient, performant, and scalable code.
Conclusion
While there are still some limitations and challenges in using C for embedded systems, the benefits far outweigh the drawbacks. The availability of advanced microcontrollers, the expansion of available memory and processing power, and the advantages of modern programming techniques like class organization make C a valuable tool for developing efficient and robust embedded applications.