EEVblog® Electronics Community Forum

Electronics => Microcontrollers => Topic started by: Andreilie on March 02, 2019, 02:42:41 pm

Title: WIll te same code work
Post by: Andreilie on March 02, 2019, 02:42:41 pm
Hello,

I have a silly question I think.
Iwant to use for a project an existing code written for stm32f405 microcontroller, which has an ARM Cortex-M4F core.
Can I use the code for a STMF7 CHIP ?

Thanks.
Title: Re: WIll te same code work
Post by: ogden on March 02, 2019, 03:43:11 pm
Your question is answered in AN4660.
Title: Re: WIll te same code work
Post by: Fred27 on March 02, 2019, 06:31:04 pm
I find that code ports easily, but peripheral setup takes some tweaking. It should be reasonably simple if you're sticking with STM32s, but will still take some time and effort.
Title: Re: WIll te same code work
Post by: TomS_ on March 04, 2019, 01:57:42 pm
I find that code ports easily, but peripheral setup takes some tweaking. It should be reasonably simple if you're sticking with STM32s, but will still take some time and effort.

This would match my experience too.

The main logic of your application should be portable enough between platforms and families - but the bits that interface with peripherals (configuring timers/responding to their interrupts, talking to UARTs etc) will need to be adapted on a per device/family basis.

If your code is well written, the peripheral interfaces should be abstracted away from your application logic code so that they can be replaced easily. If not, this would be a good exercise to do just that. The build environment should ideally make some variables available to the compiler so that you can use ifdefs etc to include or exclude different pieces of code depending on the type of device the code is being compiled for.