Protect Code inside Microcontroller
Flash &amp; lock the microcontroller with a bootloader which loads encrypted code from external flash into RAM. Then the external flash can be rewritten at will. For bonus points use a microcontroller with some high-security flash for storing the encryption key.

There are also microcontrollers with multiple flash regions- you can put the bootloader on one and lock it and have the encrypted code on the others (perhaps multiple, for safe updates).

If there are vulnerabilities in your code then it can be hijacked and read out from RAM.