Writing to STM32767ZI OTP Flash

Anyone have success or any information for writing data to the chips OTP flash? I have tried a few things and have not been able to change the values from 0xff (trying to write a MAC address to OTP since I do not have any other NVRam and we erase/rewrite flash sectors using FlashIAP and we do not want to lose the MAC we assign (OTP should be permanently permanent…).

Thanks

Forgot to mention about wanting to do this inside a program , not using dfu-util (which works great - by the way) so we can use a manufacturing jig and application to write the MAC…

OK, I git it working… For anyone else who tries this,

First comment out in HAL_FLASH_Program:
/* Process Locked */
//__HAL_LOCK(&pFlash);

AND:
/* Process Unlocked */
//__HAL_UNLOCK(&pFlash);

Or it will lock up/Segfault…

And then realize that “FLASH_Program_DoubleWord” in the HAL library DOES NOT WORK. I ended up writing two 32 bit values, and that worked. The 64 bit version does two 32 bit writes but it sets the FLASH_PSIZE_DOUBLE_WORD in the FLASH->CR, and that is what apparently fails. So I changed it to FLASH_PSIZE_WORD and the code worked great.