![]() |
Program option bytes on STM32G4xx - Printable Version +- EmBitz (https://www.embitz.org/forum) +-- Forum: EBlink (https://www.embitz.org/forum/forum-3.html) +--- Forum: Using EBlink (https://www.embitz.org/forum/forum-6.html) +--- Thread: Program option bytes on STM32G4xx (/thread-145.html) Pages:
1
2
|
Program option bytes on STM32G4xx - matsb - 22-11-2022 I've previously been working with STM32F411 but recently switched to STM32G473, so I need to learn new things. STM32G473 have dual-bank FLASH, configurable via the option bytes as single- or dual-bank. Factory default is dual-bank. I will use singe-bank mode and therefore need to somehow program the option bytes. My first attempt was to embed the option bytes via the source code into the .hex file, to be flashed when writing/updating the firmware on the CPU. I was able to do this with the help of the linker script. STM32CubeProgrammer will take the generated .hex file and write the option bytes along with the rest of the firmware. This works. I copy/paste the code here in case someone else have use for it: In the source code: Code: #include <stdint.h> In the linker script: Code: MEMORY BUT, unfortunately this does not work with EBlink 4.7 in EmBitz 2.50: Quote:EBlink version 4.7-[13] by Gerard Zagema And I guess the reason is in EBlink/scripts/stmicro/stm32gx.script Quote:///////////////////////////////////////////////////// I've looked briefly at the script code and I would not know where to start, if I try to implement this myself. Are there any plans of implementing this anytime soon? What are my alternatives? Suggestions are appreciated as this is a new CPU for me and I'm learning. At the moment I'm in development, and can set the options with STM32CubeProgrammer, but eventually I will be getting factory empty CPU's and by then I need to get them flashed as conveniently as possible, that was why I initially tried to embed the option bytes directly in the .hex file. RE: Program option bytes on STM32G4xx - embitz - 23-11-2022 What you have to do: - Add at the end of the EBlink XML memory map the sector with the option base address and right length - Give that sector a fake number e.g. 999 (something which is out of range of normal flash) - Give that sector a virtual attribute to exclude it from the EBlink caching algorithm (property sectype = virtual) - In the EBlink erase function filter on sector number 999 to skip normal flash erase function - In the EBlink flash write function filter on sector number 999 and jump to a new to create function e.g. "option_write" - Create new "option_write" function with the right algorithm to program option bytes Check the script code for the stm32h7 which supports option programming. e.g. Memory map H7: Code: const mem_template_H7 = @@" H7 erase function: Code: function flash_erase(sector, address) H7 write function: Code: function flash_write(sector, address, buffer) H7 option_write: Code: function option_write(buffer) Last but not least, if everything works: share it. P.s. It's not much work but currently I'm a bit busy. RE: Program option bytes on STM32G4xx - matsb - 24-11-2022 Thank you very much! I will have a go at this. RE: Program option bytes on STM32G4xx - embitz - 24-11-2022 Remember: The algorithm to program option bytes is for STmicro totally different than programming code flash. Other keys to use etc etc Check MCU reference manual for the right Algorithm. Tip: To test your scripts you can just use printf statements to give debug feedback. RE: Program option bytes on STM32G4xx - matsb - 25-11-2022 I think I'm pretty close, I'm at the final step and need help with reconnecting to the target. From the reference manual: Quote:Option byte loading So the CPU does a reset to take the new options into use when setting OBL_LAUNCH bit. I can see this as EBlink seems to loose connection with the target. How do I tell EBlink to reconnect so the script can continue? Attached is what I have so far. RE: Program option bytes on STM32G4xx - embitz - 25-11-2022 Great! I will see if I can find a disco board to test it. What do you mean with "EB is losing connection "? Are you using EB as file flash tool or as GDB server? RE: Program option bytes on STM32G4xx - mri - 25-11-2022 (I seem to have a different account at home) "What do you mean with "EB is losing connection "?" After setting the OBL_LAUNCH bit, I was relocking the option bytes, but EBlink then gave an error message and my guess was the relocking read-and-write failed because the CPU was reset. There is a comment in the code about this. "Are you using EB as file flash tool or as GDB server?" I'm so far using Flash menu to write the compiled .hex file to the traget. BTW, as soon as I added those virtual sectors to the memory map, Flash verification started complaining about verification failing. Is there some script code needed to properly support verification? RE: Program option bytes on STM32G4xx - embitz - 25-11-2022 That's, most likely, because we can't just easily read options back. I can solve this by introducing special read callbacks for virtual sectors. I will put it on my list for next EBlink version. Thanks. RE: Program option bytes on STM32G4xx - embitz - 25-11-2022 Perhaps it is easier to introduce two additional optional properties for xml sectors. One for defining sector script write function and one for sector script read function. All that filtering of fake sector numbers is not needed anymore when using function assignments to virtual scripts. RE: Program option bytes on STM32G4xx - mri - 25-11-2022 That sounds like a good design! |