Rewriting Code in Internal Flash in STM32F439
Assuming the goal is protect company intellectual property, STM32F7 and STM32F401re  family of product offer distinct level of protection that might work.
Readout Protection (RDP)

Level 0: No readout protection
Level 1: memory readout protection
Level 2: chip read out protection

Proprietary code Read out Protection (PcROP)

PcROP is capable of preventing the CPU of executing malicious code

Write Protection (WRP)

Protecting the flash sector Read/Write/Erase Access

The attached reference documents have in-depth details of the features. The following slide from the attached document might be of interest.

Readout Protection Configuration are done through options bytes. Review the content around option bytes.

The FLASH_OPTCR register is used to modify the option bytes.
In the respective microcontroller datasheet look for information similar to the below. This should help zero in the content that is of interest.

The system memory (ROM) stores the native bootloader (STM32F401re) and is read only.
References:

STM32 System Memory Protection
RM0090 Reference manual STM32F429/439 advanced Arm®-based 32-bit MCUs