ARM compatibility between vendors, with and without RTOS (FreeRTOS)
FreeRTOS uses the RTOS CMSIS API by ARM to implement basic functions for thread, timer and queue management. If you do not use port specific FreeRTOS functions you will be able to run it on a different Cortex-M MCU since the required hardware is common to all Cortex-M cores.

Peripherals are mostly different between vendors and you will have to adapt the software in most cases, but you can make your live easy by using a separate abstraction layer by defining your own functions that you use and providing a mapping between your functions and the vendors HAL.
However if you use for example the Cube HAL you will be able to port your software from a ST Cortex-M0 to a ST Cortex-M3. Other vendors have their own solutions.