encryptionstm32

Using a HEX code as a part (e.g function or subrutine or library) of another Code on STM32


I have a STM32F103CBT HEX code which is used to unlock hardware. For example, it sends 0xAE12D3B1 to my MCU and after encryption it returns 0x1E47C0A3. If this Data transfer is correct then I have the access to use hardware, else it tries once more until correct answer comes to it. After that I have a STM32F407VGT which handle a lot of tasks like commination with USART, I2C, multiple ADC Channels, PWM, CAN, etc.

How can I use my STM32F103 HEX code as a function or library in my STM32F407 MCU? For example, I should have a multi section code. First it boots HEX and then boots my own code?


Solution

  • It is not clear what you mean by "HEX code". If you mean an Intel Hex format object file, that is just a representation of the binary object code output by your linker.

    Both processors are largely binary compatible and code compiled for one will run on the other. The Cortex M4 has additional DSP and floating point instructions, so the code needs to be built for the lowest common denominator.

    However the hex file output from your linker is normally fully linked executable and not simply the unlock function in question. It will contain start-up and library code that is not relevant or already exists in the target processor application, and likely very target specific.

    To use common code across applications you should either:

    A hex file is normally a complete fully linked application and not easy to load as an extension to another application or to be extended itself. Runtime loading of object modules is a subject that has come up recently on SO. That is not straightforward either.

    For example, I should have a multi section code. First it boots HEX and then boots my own code?

    That does not sound like the same question. That sounds like a bootloader. It may make sense to build your access authorisation into a bootloader (or boot without implementing the "loader" functionality) and jump to a separately linked application image if authorisation passes. Either way switching from one application image to another at a separate load address is the function of a bootloader, so even if you are not actually building a bootloader the technique is the same. There are questions on SO specifically about Cortex-M bootloader that may help.