Connect with us

very basic (general) microcontroller programming question

Discussion in 'Microcontrollers, Programming and IoT' started by c3po, Jan 13, 2017.

  1. c3po

    c3po

    6
    3
    Jan 13, 2017
    I'm just getting started in microcontroller programming. I'm using a Texas Instruments Tiva (ARM) micro controller board. I'm trying to learn direct register programming instead of using the API provided by TI. I assumed this would make my programs at least somewhat portable (able to run on other manufacturers ARM micro controllers). But I recently looked at the datasheet for an ARM micro controller made by ST. To my horror, it looks the register names are completely different. Is micro controller programming so specific that the programmer has to start basically from scratch to learn each individual manufacturer's chip?
     
  2. Arouse1973

    Arouse1973 Adam

    5,164
    1,078
    Dec 18, 2013
    That's why we write in C, because it's reasonably portable.
    Thanks
    Adam
     
  3. c3po

    c3po

    6
    3
    Jan 13, 2017
    Writing code in C doesn't help portability much if the register names and mnemonics for Texas Instruments ARM micro's aren't the same a ST's. The C code will be completely different. There's no chance a program written for TI will come close to running on an ST micro. I assumed register names were established by Acorn, the company that owns the ARM design. No?
     
  4. Austin Clark

    Austin Clark

    16
    8
    Aug 29, 2016
    You ask an obviously misguided question, get a decent (though short) answer, then respond back with non-sense as though you know better than the person trying to help you? Sheesh.

    For starters, by "direct register programming" you really mean "assembly programming", which is going to be mostly ISA (instruction set architecture) dependent (ARM VS x86, etc) but in general is the LEAST portable of any code (ignoring straight-up machine language programming, because that's kinda dumb). You're going backwards if you want portability.

    Programs written in C are more portable because C code can be re-compiled and re-targeted for different hardware. You basically design your software at a higher level of abstraction (most of the time) plug in some configuration info (like clock speed for timing), and allow compilers to create the actual lower-level assembly/machine program for you.

    Different manufacturers will use different mnemonics because they're arbitrary. The same goes for byte endianness, etc; Though that's probably not the main technical reason for their incompatibility. Others here would know more about that than I.

    I'd be interested in knowing about how peripherals are accessed differently between platforms and such myself.
     
  5. Arouse1973

    Arouse1973 Adam

    5,164
    1,078
    Dec 18, 2013
    Well if you want a language that is fit for all then I think you are out of luck. To say C isn't portable is nonsense. Unfortunately you will have to change a few things.... it's a bummer I know, that's life.

    Advantages of C Language
    1. C language is a building block for many other currently known languages. C language has variety of data types and powerful operators. Due to this, programs written in C language are efficient, fast and easy to understand.

    2. C is highly portable language. This means that C programs written for one computer can easily run on another computer without any change or by doing a little change.

    3. There are only 32 keywords in ANSI C and its strength lies in its built-in functions. Several standard functions are available which can be used for developing programs.

    4. Another important advantage of C is its ability to extend itself. A C program is basically a collection of functions that are supported by the C library this makes us easier to add our own functions to C library. Due to the availability of large number of functions, the programming task becomes simple.

    5. C language is a structured programming language. This makes user to think of a problem in terms of function modules or blocks. Collection of these modules makes a complete program. This modular structure makes program debugging, testing and maintenance easier.
     
  6. Arouse1973

    Arouse1973 Adam

    5,164
    1,078
    Dec 18, 2013
    Thank you for your comments Austin. I purposely give short answers where relevant, it should encourage the OP to do some research for themselves. The OP obviously couldn't be bothered so in my last but one reply I have.
    Cheers
    Adam
     
  7. hevans1944

    hevans1944 Hop - AC8NS

    4,226
    1,995
    Jun 21, 2012
    Yes, if you want to program at the register level. No, if you want to program in a higher-level language such as C or even BASIC.

    As for portability... that depends on how wedded your peripheral circuits are to a particular microprocessor's internal hardware capabilities. But that's why drivers are written, so you can exercise peripherals from a higher level language call. Obviously each driver is specific to a particular set of hardware.

    Please tell us what you are trying to DO with your newly acquired microprocessor programming ability? Why is portability an issue or even a requirement?
     
  8. c3po

    c3po

    6
    3
    Jan 13, 2017
    My question was not about the portability of the C language. I've been programming in C since 1990 and in Fortran since 1975. I know something about it. The question is specifically about using C to program ARM micro controllers. But so far nobody has demonstrated any knowledge of micro controller programming. Someone even suggested that my question is about assembly language programming. Good grief! I created an account on this site just to ask this one question but I'm outa here. Bye!
     
  9. Arouse1973

    Arouse1973 Adam

    5,164
    1,078
    Dec 18, 2013
    Why did you say you are just getting started? The answers you get will depend on what level we think you are at.
    Thanks
    Adam
     
  10. c3po

    c3po

    6
    3
    Jan 13, 2017
    Araouse, My very first sentence was, "I'm just getting started in MICRO CONTROLLER PROGRAMMING." I've been programming for years. The question is about ARM micro controllers, not C programming.
     
  11. OBW0549

    OBW0549

    158
    118
    Jul 5, 2016
    Alas, this aspect of microcontroller programming is largely unavoidable; different chips can be quite different inside, with different suites of on-chip peripherals and their associated registers, and programming them necessarily entails close familiarity with each particular chip. This is true whether one works in C or assembly language or any other language.

    On the other hand, once having programmed several different microcontrollers it becomes steadily more easy to pick up new ones, to the point where learning a new device and beginning to use it effectively becomes the work of a few hours, rather than days or weeks.
     
  12. c3po

    c3po

    6
    3
    Jan 13, 2017
    Thanks OBW. This is what I was hoping to find, someone who has experience programming micro controllers. I do appreciate other folks trying to help however.

    I "assumed" that all ARM chips have the same basic set of registers since they are all based on the same cpu design. But that's the problem with assumptions, I guess. Maybe I better drop back to AVR chips to learn how micro controllers work. AVR's seem to be much simpler than ARM's and have far more documentation, consistency between manufacturers, and more example programs and tutorials.

    thanks!
     
    OBW0549 likes this.
  13. hevans1944

    hevans1944 Hop - AC8NS

    4,226
    1,995
    Jun 21, 2012
    Sorry for the confusion. Perhaps you could explain what the following statement means.

    Many of us here have been programming microprocessors for many years with various languages and application development interfaces. I learned the rudiments of programming in the 1960s and jumped on the microprocessor bandwagon in the 1970s. The real programmers, sitting behind air-conditioned glass walls (mainframes ate up a lot of power and needed lots of air conditioning), laughed at me and made snide remarks, but I mastered it and then waited for the programming tools to catch up. Even bought a Microsoft FORTRAN 77 compiler to accommodate a "professional" programmer who insisted on writing code on a VAX-11/750 for downloading to an IBM PC-XT. He tried his "best" to break the Microsoft compiler, hoping to thereby demonstrate my stupidity in choosing a PC instead of DEC PDP-11 for an embedded application. It was a DEC shop, and I was a new hire. Sorry, Charlie. The PC and its custom hardware interface that I designed worked just fine. And the programmer eventually settled down and wrote some decent code. Never did convince him that the DEC business model was doomed, but Digital Equipment Corporation made "pretty good" computers while they lasted...

    Why should be "demonstrate" any knowledge of micro controller programming? We don't know you. We don't know what you are trying to do. We don't know whether you have even selected an appropriate microprocessor for whatever task(s) you have in mind. But welcome to Electronics Point. I hope you weren't unduly inconvenienced by the registration requirements before posting here.

    See the comment by @OBW0549 in post #11.
     
    OBW0549 likes this.
  14. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,191
    2,693
    Jan 21, 2010
    I haven't weighed in on this thread until now, but perhaps I have something to add.

    If you're using a language with "ifdef" style compiler directives and access to defined constants which specify the target environment then you can write code which is "portable". You're really limited by your knowledge of how to get X done on hardware Y.

    It makes life easier if register names and meanings are consistent, but doesn't change the general approach.

    Both C and assembler natively support the things you need, but any language ported for use with a microcontroller will almost certainly have this functionality bolted on.

    The decision whether to use the high or low level language can be based on all sorts of factors, but one important one is that the C language may be more portable than assembler.

    Offsetting this is that a microcontroller with a different set of instructions may not share the same approach to peripherals.

    My gut feeling is that you might choose a different language depending on the level of your code. You might implement an interface to functionality for a class of microcontrollers in ASM and implement higher level abstractions on to of this interface in a higher level language.

    However, whilst that is becoming more viable, it is still a "big computer" way of doing things.

    Having said that, I do everything in C++, but I don't work across different manufacturers products and I don't use ARM processors. Your question is possibly a little specific to ARM since the architecture is licenced to various manufacturers who can add their own wrinkles.
     
    OBW0549 and hevans1944 like this.
  15. OBW0549

    OBW0549

    158
    118
    Jul 5, 2016
    I think everyone else who responded has had plenty of experience with microcontrollers, too; the reason for the confusion was there was some difficulty in ascertaining just what you were asking, especially your remark about wanting to learn "direct register programming instead of using the API provided by TI"; I, too, initially thought you were referring to assembly language programming.

    You might also give a look at some of the higher-end PIC processors such as the 16-bit PIC24 series and the dsPIC parts, which have the same PIC24 core but with the addition of a DSP engine.
     
  16. c3po

    c3po

    6
    3
    Jan 13, 2017
    I found the following answer elsewhere. Someone else asked the same question I did. I'm entering the answer below for those who might be wondering the same thing.

    For those unfamiliar with ARM here is a brief intro (my interpretation). ARM is a cpu design created by a British company (Acorn?) that doesn't even make cpu's or microcontrollers. The design is apparently so good that major microcontroller manufacturers decided not to design their own cpu's but license the design from ARM instead. Consequently the cpu in microcontrollers from various vendors is the same design but the peripherals, which are on the same chip as the cpu, are designed by each vendor. This means that programs written for one manufacturer's ARM microcontroller typically won't work on others. There have been attempts to create higher level API's to abstract away the differences and make programs portable.

    === third party answer starts here ===
    The GPIO hardware in your chip is designed by TI instead of ARM and thus its headers have a slightly different coding style.

    When using Cortex-M (ARM) microcontrollers, it's helpful to keep track of which part of the hardware were designed by ARM and which were designed by the silicon vendor that licensed the processor from ARM (TI in this case). ARM designed the CPU and the debug and tracing related hardware blocks (that you could even use to do some I/O, e.g. SWD) but everything else, GPIO, Timers, PWM, ADC, UART, SPI, I2S are all done by silicon vendor. Thus, even a simple low-level blink example would not port from TI to ST, NXP or Atmel chips even if they're all Cortex-M microcontrollers.

    ARM had a CMSIS-Driver initiative that was aimed at creating a unified API for the common peripherals, but it's essentially dead. For portable high-level APIs, look to the mBed or Arduino projects.
     
    OBW0549 and hevans1944 like this.
  17. Hellmut1956

    Hellmut1956

    53
    3
    Aug 11, 2014
    What I have been missing in the replies of this thread is related to the fact that the originator is looking for ARM Cortex m controller. The great think about ARM Cortex M controllers is the requirement that ARM puts on its licensees to make available for their products based on ARM Cortex licenses the CMSIS library. That is one key advantage in using controllers based on an ARM Cortex M license. ARM has defined an API that is shared by the CMSIS libraries of any supplier. So if a software accesses hardware using the CMSIC calls it can be easily ported to the controller of any other supplier, as long as it offers the same set of peripherals as the originally chosen controller. Here a link to get information about what CMSIS is. So far i have seen and used CMSIS libraries for NXP LPC and NXP (Freescale).
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-