Porting of code designed for one microcontroller to another microcontroller.

Thread Starter

lord_K

Joined Apr 24, 2019
16
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.
 

danadak

Joined Mar 10, 2018
3,793
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:

Papabravo

Joined Feb 24, 2006
12,770
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.
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.
 

BobaMosfet

Joined Jul 1, 2009
941
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.
 

Papabravo

Joined Feb 24, 2006
12,770
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.
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.
 

Thread Starter

lord_K

Joined Apr 24, 2019
16
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.
Thank you Sir,
Will give it a try Right away.
 

Thread Starter

lord_K

Joined Apr 24, 2019
16
That is why you need to start over. Trust me on this it will take less time if you do that.
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.
 

Papabravo

Joined Feb 24, 2006
12,770
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.
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?
 

djsfantasi

Joined Apr 11, 2010
5,958
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.
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.
 

Papabravo

Joined Feb 24, 2006
12,770
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

Joined Jul 5, 2008
1,990
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.
 

djsfantasi

Joined Apr 11, 2010
5,958
Hah! What kind of Arduino platform supports USB and Ethernet smart guy?
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.
 

djsfantasi

Joined Apr 11, 2010
5,958
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.
 

Papabravo

Joined Feb 24, 2006
12,770
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.
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.
 
Top