GithubHelp home page GithubHelp logo

Comments (3)

akospasztor avatar akospasztor commented on July 19, 2024

Hi pycan,

While the ARM Cortex architecture theoretically supports both little- and big-endianness, (see https://en.wikipedia.org/wiki/Endianness), almost all of the Cortex M MCUs are little-endian. Therefore, the HAL_FLASH_Program should do exactly the described behavior :) So it must write the LSB byte first, then the MSB byte at last.

Btw, why would you like to have the "Big Endian" writing method? (MSB byte comes first)

Best,
Akos

from stm32-bootloader.

pycan avatar pycan commented on July 19, 2024

Hi Akos,

Thanks for your reply.
I checked the hex file that is generated by the project and the data is indeed LSB. However, when it is written by the flash driver it will be LSB of LSB. Therefore, each DWORD has to be MSB and then pass it to HAL_FLASH_Program so that it ends up LittleEndianess in the Flash.

How did you handle this issue in your project?

from stm32-bootloader.

akospasztor avatar akospasztor commented on July 19, 2024

Hi pycan,

First of all: are you talking about a hex file (https://en.wikipedia.org/wiki/Intel_HEX) or a binary file? Because those two are entirely different. Secondly, please excuse me, but your question does not make any sense to me.

Let's imagine we have 52651 (decimal) pieces of apples in a (really big) bucket. It's entirely up to you how you represent this number in your head or on paper, or in the microcontroller flash. The most important thing is that we have this amount of apples, and no matter which representation we use, we are always talking about the same number of apples.

Now, if we are talking about the human form, we can write the number "43981" on a piece of paper. Actually we, humans, learned to represent and imagine numbers in "big-endian" format (which is not exactly correct, since there are no "bits" in decimal representation). Anyways, that's why we write "43981" on the paper. If we want to represent the same number in a "little-endian" decimal format, then we would write "18934". It does not matter, as long as we both know which representation are we talking about. The numbers are just symbols. This goes the same for hexadecimal representation. If I decide to write this number in the big-endian format, it would be 0xABCD. If I decide to write it in little-endian format, it will be 0xCDAB.

Sorry for the long text, let's get practical. You write a small application, and you compile it into a binary file. The very first 32bit data of an application code is the initialization value of the stack pointer. This value has to be within the RAM range of the MCU, meaning it should be between 0x20000000 and 0x20050000 (this is written in the human-form, meaning big-endian), considering an STM32L496xx MCU. Let's say you have a stack pointer value of 0x20012345. When you compile your program and flash it to a little-endian MCU, the very first byte of the flash will be 0x45, then the second 0x23, and so on.

When you build an application and generate a binary output, it will be little-endian (in your case). When you want to use the bootloader to copy this application binary to the microcontroller flash, you don't have to do anything but copy the bytes one-to-one to the MCU flash. Take the first DWORD (8 bytes), pass it to the HAL_FLASH_Program without changing the byte order, and that's it.

from stm32-bootloader.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.