Simulating Circuits and Programming Micro-controllers over Linux - c

I'm about to go through a Micro-Controller project which controls a robotic arm. My problem is that # MS Windows there are MikroElectronica (IDE: MicroC) compile .c to Hex put the hex in Proteus and simulate. Then using a special (PCB) Kit with CD (carries windows software) I would put the microchip and install the hex file or what ever.
First all the respect to Ms but I just hate it! I adore Ubuntu/linux and open-source I need from the experts to tell me in "Steps" how to do the previously mentioned in linux with minimal complications.
The Electrical and Mechanical Engineers along with me always brag about Ms is easy. I want to show them how Computer Science guy uses open-source technology and how strong and reliable it is.
Please help !

You wish to demonstrate the power of Linux by trying to run products designed for another operating system on it? Chances are those tools may work in Wine.
Or maybe you can use Hi-Tech C as a compiler and try gEDA for simulation. It is also possible to compile Microchip C30 on Linux if you are working on 16-bit PIC:s. In any case, this may not be as easy as using the out-of the-box Windows tools. It will be more educational, nevertheless.

If you can be flexible and opt for AVR then you will have free GCC compiler and programming tools. All open source and Linux/Mac friendly. More info at www.avrfreaks.com.

Here is a compiler, linker and simulator tutorial for PIC on linux. Here is one that uses SDCC c compiler. Google throws out lots of websites when you search for linux pic.

From my side, I cross-compile and program Microchip dsPIC from Linux but it is not really straightforward. Here are the big steps
First I built the C30 toolchain from Microchip sources (you need to apply a few patches on the given sources for it to compile).
Once you have the toolchain binaries, you will need to have the specific Microchip MCU resources. Those are coming with the C30 installation on a win32. I copied those files from the Windows installation folder onto my linux filesystem.
Here you should be able to compile and link some C & ASM code to a hex file through command line.
Second step, I wanted to build my projects within the Eclipse IDE. To do that we "just" had to write a couple makefiles to call our new C30 toolchain.
Third step, program the .hex onto your microchip MCU. Two ways to do it. If you have a Pickit2, Microchip provides a command line tool to play with it. I personally have an ICD2 programmer. I use the command line tool provided in the Piklab project.
Now I don't have any facility to debug with my ICD2 under Linux.
Now Microchip provides an alternative IDE with "Mplab X" which is based on Netbeans (sick) and should work under Linux and MacOS. But this project seemed to be yet under development, I don't know if it is really usable.

Related

Can you open and edit .c files in the Arduino IDE? And subsequently load them to an Arduino board

I have been trying to open c files in the Arduino IDE (which some people claim is possible).
I have not been able to do so.
How can I program the Arduino in c given that I have a project/files in another IDE? (for example, MPLABX)
I am not sure what you are trying to archive. Is it that you want to open it via the Arduino IDE or also compile the source code?
I am not aware of programming in bare c in the Arduino IDE. But if you're looking into using real c code, it might be a good time start either compiling and uploading via terminal yourself, or use an IDE which is suited for development with micro controllers.
I think you can tell the Arduino IDE to more elaborately log outputs. This would tell you exactly the commands the IDE is using (uses avrdude). Then you can use an IDE/Editor of your choice for coding.
Otherwise, have a look at eg. Atmel Studio. They also support Arduino.
There are two answers in one:
If you really want to use the ArduinoIDE you have to have a basic *.ino file having at least the defines and includes which are in the project file and the reqiured setup() loop() usually whats in main in c goes to loop() in ArduinoIDE. Thats the stoney path because there are some specific issues coming from the philosophy behind ArduinoIDE (help makers with little (no?) programming skills to get started quickly).
If you just need the Arduino tool-chain and want to work more comfortable you have two other options:
EclipseIDE with the Sloeber add-on. Download the Sloeber-AllInOne-Package for an easy start and THEN add the other modules you need (like for web development or similar)
PlatformIO an IDE for micro controller development - there is also a cloud based version for testing around.
All mentioned tools are real open source and available cross PC platform and not a gift from a company like MS for probably later lockin of devs

How to start ARM programming in linux?

I was using PIC micro controller for my projects. Now I would like to move to ARM based Controllers. I would like to start ARM using Linux (using C). But I have no idea how to start using Linux. Which compiler is best, what all things I need to study like a lot of confusions. Can you guys help me on that? My projects usually includes UART, IIC, LCD and such things. I am not using any RTOS. Can you guys help me?
Sorry for my bad English
Once you put a heavyweight OS like Linux on a device, the level of abstraction from the hardware it provides makes it largely irrelevant what the chip is. If you want to learn something about ARM specifically, using Linux is a way of avoiding exactly that!
Morover the jump from PIC to ARM + Linux is huge. Linux does not get out of bed for less that 4Mb or RAM and considerably more non-volatile storage - and that is a bare minimum. ARM chips cover a broad spectrum, with low-end parts not even capable of supporting Linux. To make Linux worthwhile you need an ARM part with MMU support, which excludes a large range of ARM7 and Cortex-M parts.
There are plenty of smaller operating systems for ARM that will allow you to perform efficient (and hard real-time) scheduling and IPC with a very small footprint. They range form simple scheduling kernels such as FreeRTOS to more complete operating systems with standard device support and networking such as eCOS. Even if you use a simple scheduler, there are plenty of libraries available to support networking, filesystems, USB etc.
The answer to your question about compiler is almost certainly GCC - thet is the compiler Linux is built with. You will need a cross-compiler to build the kernel itself, but if you do have an ARM platform with sufficient resource, once you have Linux running on it, your target can host a compiler natively.
If you truly want to use Linux on ARM against all my advice, then the lowest cost, least effort approach to doing so is perhaps to use a Raspberry Pi. It is an ARM11 based board that runs Linux out of the box, is increasingly widely supported, and can be overclocked to 900MHz
You can also try using the Beagle Bone development board. To start with it has few features like UART I2C and others also u can give a try developing the device driver modules for the hardware.
ARM Linux compilers and build toolchains are provided by many vendors. Below are your options which I know of:
1.ARM themselves in form of their product DS-5 ;
2.Codesourcery now acquired by Mentor graphics. See some instructions to obtain & install, codesourcery toolchain for ARM linux here
3.To first start programming using ARM (C , assembly ) I find this Windows-Cygwin version of ARM linux tool chain very helpfull. Here. These are prebuilt executables which work under Cygwin(A Posix shell layer) on Windows.
4.Another option would be to cross compile gcc/g++ toolchain on Linux for ARM target of your choice. Search and web will have information about how it is done. But this could be a slightly mroe involved and long-winding process.
enjoy ARM'ing.
First, you should question yourself if you really need to program assembly language, most modern compilers are hard to beat when it comes to generating optimized code.
Then if you decide you really need it, you can make life easier for your self by using inline assembler, and let the compiler write the glue code for you, as shown in this wikipedia article.
Then the compiler to use: For free compilers there are practically only two choices: either gcc or clang.
There is also a non free toolchain from arm which when i last tried, 5 years ago, produced about 30% faster code than gcc at the time. I have not used it since.
The latest version of this compiler can be found here
You can also write standalone assembler code in .s files, both gcc and clang can compile .s into .o in the same way you would compile a .c or .cpp file.
Compile
If you are using a STM32 based microcontroller you need to get CMSIS and GNU arm-non-eabi-gcc package installed. Then you need to write your own makefile to pass your c codes into arm gcc compiler.
Programming
For the programming step you need to install openocd and configure that for your specific programmer. You can find a full description on how to do that on my blog
http://bijan.binaee.com/index.php/2016/04/14/how-to-program-cortex-m-under-gnulinux-arch/ and in my GitHub repository.
IDE
I'm using vim with CTags but you can use gEdit with the Shortcut plugin if you need a simpler text editor.

How do I setup a C environment on Windows (and maybe Linux compatible, too)

Short version of question: How do I get started with C programming? Note that I am not asking for a tutorial on learning C language (I can learn that easy enough). I need to setup the environment (I hope I'm asking this question clearly). Here's what I mean:
For my math thesis, I need to write a program in C on Gentoo Linux, using a library called CVODE/SUNDIALS. There is nobody (it seems) in my department who can help me set this up - my professor has left the computer work 100% to me because I have some programming background and he's a math geek. But my experience is with scripting languages (think VBA) and not full, powerful programming languages where you have to link the compiler and libraries, etc. like C.
There is no development environment on the Linux cluster - or at least not that's friendly, and has a debugger - that I've found. So, what I need to figure out how to setup a C programming environment with CVODE library on my PC (Win 7 x64, at little to no cost.
I have found plenty of tutorials on programming in C. I looked up Eclipse, which I have a little bit of experience with, as a development environment, but it's instructions say you need to install a compiler, too.
What I would like is someone to tell me, in simple language that I can understand (which might be the most difficult part of this question) the big picture of what I need and what to do (and maybe even links to where I can find what I need) to set up a C environment with CVODE. If the information is Windows/Gentoo Linux cross platform, even better.
Thank you.
P.S. I did search the site and saw lots of "How do I setup" quesitons, but no C one. Because I know someone will yell at me for that. Also, I don't want to have a convo about whether to use C#, C++, Java, etc. That just complicates the issue - and I need to get this done.
Edit: I have learned a little more since this question and now realize that I left out a key part of the question. The CVODE library and Linux cluster at school use MPI - parallel programming - which is not available on your average, run-of-the-mill PC. So all development must be done directly on the cluster.
Linux: Simple way is to install gcc or g++.
You can write your code in your plain text editor (nano, vim, gedit, kwrite, etc)
Save your file in .c or .cpp extention and type in terminal
gcc filename.c
or
g++ filename.cpp
You said that you want to write c code on Gentoo Linux, as i understand you're not familiar with Linux? The best choice in this case is to:
Install virtualbox in your windows machine (https://www.virtualbox.org/), it's a free software that let you emulate in your desktop another systems like Linux...
Install Gentoo linux on virtualbox, there are a lot of tutorials on the net, for example this video: http://www.youtube.com/watch?v=DUf_1wAPeyA
When you install Gentoo Linux on virtualbox you have all you need to develop C (gcc compiler, gdb debugger...)
Now you can download your library, and decompress it
In general all (Good) Linux libraries come with a 'README' file that contain all instructions for installing the library.
I think you need to do this:
./configure --prefix=/DIRECTORY_YOU_WANT_TO_INSTALL_THE_LIBRARY
make
make install
You can now play with C and you new library, like this:
suppose you create a new file test_lib_ CVODE.c you can compile it like this:
gcc -Wall test_lib_ CVODE.c -o test_lib_ CVODE -lcvode
I assume that the installed library is named libcvode.so
If you have any questions, you can always get help here.
Regards.
I think you should use Code::Block in Linux, it is very similar to Window's Code::Block and it is very easy to debug and other things.
These were all useful answers. I tried pursuing each of them at least a little bit. However, the only reasonable solution seems to be to use emacs on a terminal window. This is because I'm using MPI - yes, I know I didn't mention that in the OP - which can only be done on a cluster.
I am new to this environment and was not aware of the MPI or the affect it would have on my attempt to develop.
I believe I can do better than this if I can figure out X/Windows using Cygwin. But I am a long way from that.
Thanks all for your effort and sorry I can't really award a best answer (I guess).

what software should i use when i want to study c

i want to write code use notepad and compile the c code use cmd on windows (like java),
what software should i use ,
gcc for windows
cygwin
Turbo C
gvim
thanks
An excellent option for Windows is the Visual C++ Express Edition (which is free). This is a full IDE, compiler, and debugger and is a great way to get started.
GCC is also a good option if for some reason you wish to avoid an IDE. I wouldn't recommend this for a beginner, though.
Please don't use Turbo C, it's very old and you will have problems with it.
Cygwin is a popular linux environment for Windows.
Gvim is an editor and (in my opinion) has a very high learning curve. You could use Notepad++ or Code::Blocks to develop your code in.
mingw is also a good option to start with.
IMO you should avoid IDEs: a beginner needs to actually see and feel the whole process of compiling by invoking the compiler from a terminal, not by simply pressing some keys and bang! Also most of the IDEs have code completion facilities which is not good for beginners (especially for C). So I would go with vim (or gvim) and cygwin.
PS: Give Linux a try, you might actually like it; then vim and gcc.
Use cygwin. It's just about the only way to get a C environment on Windows that's both modern (i.e. not 16-bit, DOS-based) and conformant to the standards, and with it you get a fairly-complete POSIX environment, which allows you to actually do interesting things with C.
The classics would be Cygwin and MSYS/MinGW.
Cygwin provides a Linux API compatibility layer and includes a package manager which provides access to many well-known Linux applications (ie batteries included).
MSYS/MinGW only provides a minimal userland to get the GNU build system working.
Both come with their own shell environment, but can be used from Windows' command line as well.
Binaries created with Cygwin-gcc won't work without cygwin1.dll, but you get all the benefits of a mostly-POSIX environment. You can also use Cygwin's MinGW package for cross-compilation and thus create stand-alone binaries.
Other solutions are possible: Currently, I'm using the MinGW compiler together with the Cygwin userland from the Windows command line...
I think cygwin itself named as gcc for windows.
also gvim is not a compiler , It is a very nice and powerful tool for code editing.Also you can try emacs and kwrite
Some suggestions from my side:
In windows, you need to install a third party software to try all programming stuffs(c,c++ etc) ,Most of the times it is having GUI implementations and you didn't get any exact idea behind the code execution flow.also the command prompt of windows not at all efficient as linux shell.
But if you install a good linux distro (ubuntu/fedora/cent os/debian/pardus/suse/arch linux),all default compilers,debuggers and editors are installed within the OS and you can try the basic and all advanced programs by just opening the terminal(shell).Also the shell is a more powerful tool and you can enjoy all kind of automation comamnds(I mean scripting).
Also: for your added information, most of the embedded programmers in the industry prefer command line execution unlike GUI implementation because it is too fast than GUI.

C compiler from where?

I want to learn C language (is this something good ?) and i didn't know from where i can download the language to my PC ?
and are this FREE or must pay for ?
Is C a good language? Definitely. Is it the best first language? Depends.
If you are using Windows, you can download Visual C++ 2008 Express Edition SP1 from Microsoft for free.
On Ubuntu, just run
sudo apt-get install build-essential
On Mac OS X, install Xcode from Snow Leopard/Leopard DVD (or download the latest version from Apple developer Web site)
There are quite a few free C compilers for the PC.
As seen above, MS Visual Studio comes in a free version.
However, most introductory C programming materials will work best in a unix-like environment. Two options for such an environment are:
Cygwin, which provides a unix-like environment that can be installed over a windows system.
MinGW32/MSYS, which natively ports GCC and some unix-like development tooling onto Windows, allowing you to use GCC to build native Win32 apps.
For learning you might be better off running a native unix/linux environment. If you already have Windows and don't want to uninstall or dual-boot you can run this under a VM. Several free hypervisors are available that will let you do this.
If you want to use a different development environment you could try Eclipse.
Just go to this link and look for Eclipse IDE for C/C++ Developers (79 MB).
http://www.eclipse.org/downloads/
There is a free compiler called gcc that will compile C code. On Mac OS X and Linux you probably already have it, try typing gcc at a command prompt.
On Windows, you can still use gcc, but you need to use either Cygwin or Mingw.
Or if you want to use an IDE and Microsoft's C compiler you can get a free version of Visual Studio here.
You can use Dev C++ . Very decent tool for beginners and intermediates.
OK (all free):
For Windows
- there is Visual C++ Express
- MinGW (and is command-line based)
You will need the MS Platform SDK as well.
Linux/Sun
- GCC (there are a number of ways to get this distro depending)
OS X
- Apple's Developer Tools (Xcode and others)
It is definitely free to learn and program C, but the answer to your first question "is this something good ?" depends on what your goals are. C is a very good language for some things, but not everything.
System programming is almost always done in C, along with network programs and some applications. C is also the basis for most modern programming languages you will work with, so learning the C syntax can be applied as you go about learning other things. However, if you are looking to make a interactive webpage, you might want to learn PHP. If you are looking to make a desktop application with a GUI, you might want to learn Java.
If you want to just get a start learning about programming, C can help you with that. If that's what you want to do, and dont care much about application right now, I suggest you go to the bookstore and just find a book on learning C for beginners. It should have a CD in the back with a compiler (probably visual studio), and should get you on your way.
This is a an excellent reference of free compilers for many systems.
http://www.thefreecountry.com/compilers/cpp.shtml
Intel provides free non-commercial compilers for Linux. The download includes the excellent Intel debugger & profiler. The free license can be summed up in two points:
My use of software products is for personal non-commercial purposes.
I understand that technical support will be provided by community self-help and user forums (via the Software Support link above), but cannot get committed support with a non-commercial license.
For the projects I work on, I personally prefer Intel Compilers over GNU... Intel seems to do a better job of optimization.
On Windows, I'll suggest Dev CPP. This is free an a very good product. It is also easier for the newbies to learn. I used it a lot. You can download the latest from
http://www.bloodshed.net/devcpp.html
If in Linux, there should be gcc. Use any editor of your choice( In my case vim). Just type vim filename.c in the terminal. This should bring the editor. press 'i' and write in the code. then press 'Esc' followed by ':' and x (This will save the file and exit the editor.
Now type gcc filename.c at the terminal. this should compile it. Now enter ./a.out to execute it.
If you wanted a "portable" compiler, Tiny C Compiler is a decent compiler that you can take with you on a USB stick - it's only a single .exe file or a single folder IIRC. It is cross platform as well, but the biggest downsides are that the warnings are lacking and that it's optimization isn't as good as the bigger compilers out there.
Nonetheless, it's a decent compiler to "play around with" if you don't want to install Visual Studio or Cygwin on Windows.
I think you need to be clear about the distinction between C and C++ before you decide what to do.
On Windows, try either Digital Mars C and C++ compilers or Open Watcom C and C++ products
About.com maintains a large list of c compilers for windows at http://cplus.about.com/od/glossary/a/compilers.htm

Resources