Need help in Flash sector erase functionality in Arducopter Firmware

Hi friends I need help regarding Ardupilot firmware(copter 3.6 FMUv5) flash to erase. I am working on a custom firmware for Ardupilot. where I added the MBEDTLS library and implemented a secure Key store in Ardupilot firmware. I have reserve flash sector 23 for storing rsa2048 keys in the linker script. At some point, I need to erase that sector. I have used the stm32 hal library to achieve direct flash read-write operation. READ and WRITE(only 1 time write as flash can be erased in sector and mass erase only) is working. but sector erase is not working. So my question is. Is there any reference in code that provides the functionality to erase flash sector or similar.