STM32L0读出保护示例代码?

STM32L0 Read out protection example code?

我想防止我的代码被读出,我在网上看到STM32有一个功能可以做到这一点。但是我没有找到一些示例代码,而且我也不明白如何使用它?

一个示例代码对我来说真的很有帮助。

谢谢。

STM32闪存由2个内存区域组成:第一个写读保护,第二个读保护。参见 this for reference. All you need is to write proper linker script that loads your code into proper memory region and sets proper option bytes. How to do this look here. And how to include linker file to eclipse see here

EDT:Here is example of how to set option bytes directly from your code with functions mentioned in your post (see clive1 post) those functions seem to be part of mbed library (see this for reference). This code needs to be executed form your main function. Here 是一些关于来自控制器代码的选项字节编程的有用信息。

您不需要将其添加到代码中,因为代码可能会更改,或者您可能会错误计算扇区以使其不可读。刷入代码后,您可以使用 ST Link utility 到 select 闪存的特定部分,并在代码上设置读出保护。

您可以通过代码启用和禁用读出保护。 但我建议使用软件 "stm32 Flash loader" 或 "ST Link utility" 来代替。 请参阅教程 here。 要禁用读出保护,只需批量擦除闪存。