How to port code to a different MCU of the same family? like from STM32F401RE to STM32F401RC?

Hi,

I am trying to port an app built around STM32F401RE/NUCLEO_F401RE to its sibling STM32F401RC, to save a bit money on each MCU. I thought this is going to be straightforward but so far it doesn’t go well.

On the same board, a blinky built with STM32CubeIDE seems to work just fine.

int main(void)
{
  HAL_Init();
  SystemClock_Config();
  MX_GPIO_Init();
  MX_USART6_UART_Init();
  while (1)
  {
	HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
	HAL_Delay(1000);
  }
}

But blinky built with Mbed somehow doesn’t work.

int main() {
    //Watchdog &watchdog = Watchdog::get_instance();
    //watchdog.start(30000);
    //printf("system started\r\n");

    DigitalOut led(PA_5);

    while (1)
    {
        //printf("System running\r\n");
        led = !led;
        ThisThread::sleep_for(1000);
        //watchdog.kick();
    }
}

Since the only difference between STM32F401RE and F401RC is the size of flash, I assume as long as code can fit into F401RC, it should run fine.

What am I missing here?

Thanks in advance.

The problem is STM32F401RC has only 64KB RAM while F401RE has 96KB. Once this is changed is linker script accordingly, the blinky seems to work just fine.

https://os.mbed.com/docs/mbed-os/v5.15/reference/memory.html

1 Like

Hi @zhiyong ,

I am facing exactly the same issue but cannot make it work.

What is it that you changed?

Did you create a custom target?

Thanks,
Lluis

Top of my head, I think what I did was changing the starting address of RAM in linker file. The project I was working got shelved later on so I don’t have any recent memory about it.

Hello Lluis,

Create a custom target custom_targets.json with the following content:

{
    "STM32F401RC": {
        "inherits": [
            "MCU_STM32F4"
        ],
        "macros_add": [
            "STM32F401xC"
        ],
        "extra_labels_add": [
            "STM32F401xC"
        ],
        "supported_form_factors": [
            "ARDUINO",
            "MORPHO"
        ],
        "detect_code": [
            "0720"
        ],
        "device_name": "STM32F401RC"
    }
}

With this, Mbed will use the startup and linker files for the STM32F401xC models and set the appropriate SRAM size, interrupt vector table, MBED_ROM_START and MBED_ROM_SIZE.

1 Like