4 years, 8 months ago.

Ported to STM32F401CCU6 failed, heads up needed.

I uses online compiler to export STM32_USBSerial project with Nucleo-F401RE to Keil uVision5 IDE. Then I switched some configuration like target and flash algorithms in Keil IDE. The code can be built, with some warning, After loading the code, the code is captured in NMI handler or hard fault before running into main(). I guess it is something wrong with mbed platform for STM32F401CCU.

I compare the hardware, Nucleo-F401RE has more GPIO, more ROM, no external crystal. But my STM32F401CC has 25MHz external crystal, less GPIO, less ROM (256KB). Both MCU have same top frequency at 84MHz.

I noticed that there is a 3rd party of STM32F103C8 USB Serial project, which has embedded configureClock() at very beginning. But in my situation, the mbed platform should be initialized before running into main().

Is there any tutorial to switch from F104RE to F401CC?

Question relating to:

Affordable and flexible platform to ease prototyping using a STM32F401RET6 microcontroller.

2 Answers

4 years, 8 months ago.

Did you actually make the project work on a 401RE using the online compiler? The Nucleo-401RE does use an external clock (8 MHz) which comes from the USB micro. If in fact the code has worked on a Nucleo board then porting it should be very straight forward but double-check your pin assignments and clock changes. You can also make the online compiler use the 401CC setup but it's not for the timid.

4 years, 8 months ago.

Hello Kai,

Since your custom board is equipped with a 25 MHz external crystal and you would like to use its USB peripheral I'd suggest to add an mbed_app.json:

mbed_app.json

{
    "target_overrides": {
        "*": {
            "target.clock_source": "USE_PLL_HSE_XTAL",
            "target.clock_source_usb": "1"
        }
    }
}

Also modify the mbed-os\targets\TARGET_STM\TARGET_STM32F4\TARGET_STM32F401xE\TARGET_NUCLEO_F401RE\system_clock.c file as follows:

system_clock.c

// ...

uint8_t SetSysClock_PLL_HSE(uint8_t bypass)
{

// ...

    //RCC_OscInitStruct.PLL.PLLM            = 8;             // VCO input clock = 1 MHz (8 MHz / 8)
    RCC_OscInitStruct.PLL.PLLM            = 25;            // VCO input clock = 1 MHz (25 MHz / 25)

// ...

}

Because the STM32F401CC has 256kB flash and 64kB SRAM, you should modify the STM32F401XE.ld associated with Keil uVision5 IDE. Since I'm not familiar with that here is the modification for GCC-ARM: mbed-os\targets\TARGET_STM\TARGET_STM32F4\TARGET_STM32F401xE\device\TOOLCHAIN_GCC_ARM\STM32F401XE.ld

// ...

MEMORY
{ 
  FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 256K
  RAM (rwx)  : ORIGIN = 0x20000198, LENGTH = 64k - (0x194+0x4)
}

// ...

If you are lucky than that should make it work. Otherwise additional modifications will be needed to:

  • mbed-os\targets\TARGET_STM\TARGET_STM32F4\TARGET_STM32F401xE\stm32f4xx.h
  • mbed-os\targets\TARGET_STM\TARGET_STM32F4\TARGET_STM32F401xE\stm32f401xe.h

To accomplish that, compare the peripherals and interrupts available on STM32F401CC with those available on STM32F401RE.

Edit: When building offline with Mbed classic (aka Mbed OS-2) select the DISCO_F401VC as target rather than the NUCLEO_F401RE. It's a closer match for an STM32F401CC chip. View "Table 2. STM32F401xB/C features and peripheral counts" in the "STM32F401xB STM32F401xC datasheet" for differences.