STM32 MPU - Sub region configuration

Is it possible to configure Cortex M7 Sub regions? The idea is to disable last few bytes of stack so that the stack overflow is caught before it overflows.

Yes. You main region needs to be at least 256 bytes. Regions smaller than this do not have sub regions. The memory is divided up into 8 equally sized sub regions. So for example a region of 1024 bytes will 8 sub regions of 128 bytes. These are controlled by the SRD field of the MPU Attribute and Size register. See the Cortex-M7 Generic User guide for details (great document).

How to do via Freertos API?

If you want to use the FreeRTOS API you will have to use the MPU port of FreeRTOS - in which case a memory region is placed around the stack by the kernel itself. https://www.freertos.org/FreeRTOS-MPU-memory-protection-unit.html There are examples for an STM32 parts that uses the MPU in the FreeRTOS download - for example https://github.com/FreeRTOS/FreeRTOS/tree/master/FreeRTOS/Demo/CORTEX_MPU_M7_NUCLEO_H743ZI2_GCC_IAR_Keil