Porting of code designed for one microcontroller to another microcontroller.

Discussion in 'Embedded Systems and Microcontrollers' started by lord_K, Jul 7, 2019.

  1. lord_K

    Thread Starter New Member

    Apr 24, 2019
    11
    0
    I have a code that is designed for atmel atmega 2560 MCU. Now, there is a need to interface a USB and ethernet port into the system which is currently working on an atmega2560 MCU. ATmega 2560 does not support either of USB or ethernet so the MCU has to be changed. I donot want to rewrite the complete code again so, is there any way that the same code can be implemented on another 32 bit MCU with minimal changes. i have all the required program and code data. I just don't know where to start from and what to do.The basic function of the system is to take data from memory card and transfer is via RS-422 protocol. The code is significantly big for redesigning again. Any help would be highly appreciated.
     
  2. danadak

    Distinguished Member

    Mar 10, 2018
    3,047
    676
    If code in C should not be too difficult, in fact most of the
    effort will occur handling USB and Ethernet, although
    with most MCUs today their libraries and example projects
    make this part of development fairly straightforward.

    I have done similar work between significantly different
    architectures, and the vendor supplied C libraries for their
    hardware features made this not that difficult, vs doing it
    in assembly which I also had to do 40+ years ago. That
    was ugly.

    A fast approach might be consider handling the Ethernet and
    USB protocol in a separate chip and writing a simple interface
    to main application.


    Regards, Dana.
     
    Last edited: Jul 8, 2019 at 6:26 AM
    DNA Robotics likes this.
  3. Papabravo

    Expert

    Feb 24, 2006
    12,151
    2,663
    Not to put too fine a point on the problem; the ATMega2560 is an 8-bit MCU. Going to a 32 bit part is going to involve numerous challenges. I'm not sanguine about the prospects of a simple and straightforward port of your existing code. It may actually take less time to redesign the whole system than to port what you have into a patchwork quilt.
     
  4. BobaMosfet

    AAC Fanatic!

    Jul 1, 2009
    621
    142
    The correct way to do this in C is to understand the proper way to use #define, and variable structures, along with native word sizing constructs, and endianism so that you only need to change a single define and your program will compile correctly for the platform you're compiling on. Same code can be compiled on completely different architectures this way.

    I've done a lot of this over the years.
     
  5. Papabravo

    Expert

    Feb 24, 2006
    12,151
    2,663
    If he has not done this already, that would be equivalent to a redesign of what he has. Considering the addition of USB and Ethernet he might as well get started now.
     
  6. be80be

    AAC Fanatic!

    Jul 5, 2008
    1,780
    348
  7. lord_K

    Thread Starter New Member

    Apr 24, 2019
    11
    0
  8. lord_K

    Thread Starter New Member

    Apr 24, 2019
    11
    0
    Thank you Sir,
    Will give it a try Right away.
     
  9. Papabravo

    Expert

    Feb 24, 2006
    12,151
    2,663
    That is why you need to start over. Trust me on this it will take less time if you do that.
     
    hexreader and lord_K like this.
  10. lord_K

    Thread Starter New Member

    Apr 24, 2019
    11
    0
    Sir,
    There is a small problem here. The MCU is interacting with another system and IS providing meaningful data to that system. Now understanding that whole procedure and rewriting the protocols for transfer and processing is not my concern. I just have to implement a communication protocol or let's say adding a communication protocol. The rest of the stuff is supposed to remain same. Not a bit change is acceptable.
     
  11. Papabravo

    Expert

    Feb 24, 2006
    12,151
    2,663
    A patchwork quilt will still end up looking like a patchwork quilt. You have no freaking idea what trouble you are buying for yourself if you try to switch processors, peripherals, and protocols to a new platform. Failure of the entire project is a distinct possibility. Are you prepared to bet your career on the outcome?
     
    hexreader likes this.
  12. DickCappels

    Moderator

    Aug 21, 2008
    5,526
    1,726
    Or....you can add a processor with ethernet and USB as a co-processor and have it talk to your AVR via the serial port.
     
  13. djsfantasi

    AAC Fanatic!

    Apr 11, 2010
    5,014
    1,905
    Then you have been given an impossible task and you are set up for failure. Is your CV up-to-date?

    It is entirely unrealistic to expect a port to a different platform can be done without any “bit” changes.

    When porting you can expect...
    • Different memory models
    • Different methods available for peripheral communications
    • Different libraries
    • Different programming processes
    • Different compilers
    • Different everything except for the underlying algorithms.
     
    hexreader likes this.
  14. Papabravo

    Expert

    Feb 24, 2006
    12,151
    2,663
    Every legacy system on the planet has a load of "cruft" ( a highly technical term ) which can only be eliminated by the opportunity for a complete redesign from the ground up. You can spend time arguing about the alternatives or you can get on the stick. The sooner you do that, the sooner the new system will be up and running. If you choose to ignore hundreds of years of combined experience of developers who have gone through it one or more times; by all means vaya con Dios.

    https://en.wikipedia.org/wiki/Cruft
     
    be80be, hexreader and djsfantasi like this.
  15. be80be

    AAC Fanatic!

    Jul 5, 2008
    1,780
    348
    Let see you switch to a blue pill and ditch the uno if it's arduino code where someone else did the hard part
    of porting it maybe ez done.
     
  16. Papabravo

    Expert

    Feb 24, 2006
    12,151
    2,663
    Hah! What kind of Arduino platform supports USB and Ethernet smart guy?
     
  17. djsfantasi

    AAC Fanatic!

    Apr 11, 2010
    5,014
    1,905
    All of them! What do you mean?

    Well, maybe not ALL, but MOST.

    Most have onboard USB support, with the appropriate libraries. And while unlike other platforms with onboard Ethernet support, Ethernet shields for Arduinos are fairly common. I’ve used the one from Adafruit.
     
  18. djsfantasi

    AAC Fanatic!

    Apr 11, 2010
    5,014
    1,905
    Addendum: I’ve built a system where the Arduino is a host, connected to the Internet and thusly was controlled by a Telnet session over TCP/IP sockets.
     
  19. Papabravo

    Expert

    Feb 24, 2006
    12,151
    2,663
    The TS sounds like he wants to migrate from his AVR platform to something that can support higher data thruput. I took the to mean some platform that can move a larger volume of data over multiple interfaces. I'm not sure that piecing things together was what he had in mind. In fairness the TS has been less than straightforward in defining his requirements.
     
  20. be80be

    AAC Fanatic!

    Jul 5, 2008
    1,780
    348
    Here one and you can get them with ARM cores on them
    [​IMG]
     
Loading...