I've submitted a patch to fix this here: https://review.openocd.org/c/openocd/+/7612 I've also submitted three related patches, one to require enabling OTP writes before OTP protection can be set, one to fix a typo in a message and one to improve the message when trying to undo OTP protection (which is impossible). The second patch is shown as having a merge conflict, but AFAICS that's only because it depends on the first patch and Gerrit does not take that into account. And the third patch shows...
I patched the code to fix this, and further found that: - The code also did not do an unlock sequence and did not set the FLASH_PG bit, so the write would also silently fail. - The code would allow protecting OTP sectors without requiring the otp enable command, as is required before doing regular writes to the main OTP memory. It would probably be better to require this, to minimize the chance of doing any unintentional OTP writes. - The STM32l4x code also supports OTP, but that OTP hardware does...
STM32F2: Protecting OTP fails (code inverts lock value)
Took a while for me to test this, but I just did and it works perfectly. Thanks!
I believe this is fixed in openocd git: https://review.openocd.org/gitweb?p=openocd.git;a=commitdiff;h=cff0e417da58adef1ceef9a63a99412c2cc87ff3 Should this issue be closed?
Draft: Fix incorrect use of `in` operator
Draft: Fix SVG generation for label objects
Draft: Fix mixup of TextAlignment vs Justification for Labels