2023-05-30 07:53 AM
Hi,
i'm currently trying to find a suitable way to programm options bytes in production.
The boards are flashed using a J-Link and we would not like to switch to ST-Link.
Is it possible to simply add the option bytes to our binary?
I guess at least some script would be necessary for unlocking the the write access for the option bytes.
Any help is appreciated!
BR
2023-05-31 12:08 AM
Hi @EStei.3,
You can program your option bytes within the code that you flash on your boards.
In order to do that, you have to create first the programming option structure :
FLASH_OBProgramInitTypeDef OBInitStruct;
You are right about the need to unlock the write access for the option bytes.
You need to unlock the flash, and then the option bytes using :
HAL_FLASH_Unlock();
HAL_FLASH_OB_Unlock();
Then you can fill your OBInitStruct with the options you need (you can find the detail of the possible options and the values you can attribute in the stm32XXxx_hal_flash.h or stm32XXxx_hal_flash_ex.h file, depending on what product you are using.
You can now program the selected option bytes using :
HAL_FLASHEx_OBProgram(&OBInitStruct);
Then you lock what you unlocked earlier using HAL_FLASH_OB_Lock() and HAL_FLASH_Lock().
Finally, you start the option bytes load operation using :
HAL_FLASH_OB_Launch();
This should help you program your option bytes directly into your code.
Best regards,
Florian LR
2023-05-31 12:35 AM
Ask on the Segger J-Flash forum, perhaps they have some utility for STM32 option bytes.
2023-05-31 02:20 AM
Thanks for the response!
Unfortunately our board won't boot on power up unless the option bytes are set correctly because there is a pull up on the boot pin.
I could probably add the code as you described and somehow start the firmware using the debugger but I was looking for a way to directly set the option bytes using the debugger.
Are there any suggestions on how to set the option bytes with any generic debugger?
2023-05-31 02:43 AM
The STM32 model isn't mentioned
If you have serial port connectivity, perhaps use the system loader, see AN2606 for pins, AN3155 for protocol
2023-05-31 02:53 AM
Thanks for the response!
I didn't mention the STM32 model on purpose because the problem is generic and independent to the exact controller.
Unfortunately there is no serial port connectivity on the board.
2023-05-31 02:59 AM
In future designs perhaps consider getting some connectivity per AN2606 so you can establish test station connectivity with a low cost, low complexity interface. Pins for a UART, NRST, BOOT0 can be facilitated by Test Points, Edge Castellations, or break-off sections of board when separated from panel.