3 years, 6 months ago.

NUCLEO F302R8 with HSI

I have a NUCLEO-F302R8 with a cutted off ST-LINK. So the only possible clock souces are HSE_XTAL and HSI. When I compile it with the target settings for NUCLEO-F302R8 the system won't start. A compile with target setting for NUCLEO-F303K8 will start the system without any problems. The difference between the both setting is, that the F302R8 use HSE_EXTC and the F303K8 use HSI. It's not possible to use the F303K8 settings because there are a lot of pins missed.

Then I tried the compile time configuration mit *.json files in the root (described here)

a targets.json in the root will produce a internal error without any futher description

targets.json

{
    "myboard": {
        "inherits": ["FAMILY_STM32"],
        "supported_form_factors": ["ARDUINO", "MORPHO"],
        "core": "Cortex-M4F",
        "extra_labels_add": ["STM32F3", "STM32F302x8", "STM32F302R8"],
        "config": {
            "clock_source": {
                "help": "Mask value : USE_PLL_HSE_EXTC | USE_PLL_HSE_XTAL (need HW patch) | USE_PLL_HSI",
                "value": "USE_PLL_HSI",
                "macro_name": "CLOCK_SOURCE"
            }
        },
        "detect_code": ["0705"],
        "device_has_add": ["ANALOGOUT", "CAN", "LOWPOWERTIMER", "SERIAL_ASYNCH", "SERIAL_FC"],
        "default_lib": "small",
        "release_versions": ["2"],
        "device_name": "STM32F302R8"
    }
}

A mbed_app.json

{
    "myboard": {
        "inherits": ["FAMILY_STM32"],
        "supported_form_factors": ["ARDUINO", "MORPHO"],
        "core": "Cortex-M4F",
        "extra_labels_add": ["STM32F3", "STM32F302x8", "STM32F302R8"],
        "config": {
            "clock_source": {
                "help": "Mask value : USE_PLL_HSE_EXTC | USE_PLL_HSE_XTAL (need HW patch) | USE_PLL_HSI",
                "value": "USE_PLL_HSI",
                "macro_name": "CLOCK_SOURCE"
            }
        },
        "detect_code": ["0705"],
        "device_has_add": ["ANALOGOUT", "CAN", "LOWPOWERTIMER", "SERIAL_ASYNCH", "SERIAL_FC"],
        "default_lib": "small",
        "release_versions": ["2"],
        "device_name": "STM32F302R8"
    }
}

generates: Error: Unknown key(s) 'myboard' in mbed_app.json

A mbed_app.json

{
    "target_overrides": {
        "NUCLEO_F302R8": {
            "config": {
                "clock_source": {
                    "help": "Mask value : USE_PLL_HSE_EXTC | USE_PLL_HSE_XTAL (need HW patch) | USE_PLL_HSI",
                    "value": "USE_PLL_HSI",
                    "macro_name": "CLOCK_SOURCE"
                }
            }
        }
    }
}

generates: Error: Attempt to override undefined parameter 'app.config' in 'application[NUCLEO_F302R8]'

and a mbed_app.json

{
    "target_overrides": {
        "NUCLEO_F302R8": {
            "clock_source": {
                "help": "Mask value : USE_PLL_HSE_EXTC | USE_PLL_HSE_XTAL (need HW patch) | USE_PLL_HSI",
                "value": "USE_PLL_HSI",
                "macro_name": "CLOCK_SOURCE"
            }
        }
    }
}

generates: Warning: Incompatible redefinition of macro "CLOCK_SOURCE" in "build/mbed_config.h" and the system doesn't start.

How could I change the clock source during the start procedure?

targets.json should be the way to go. can you make your board inherit from NUCLEO-F302R8 instead and then only specify clock source config? Many boards do it this way.

For your question related to mbed_app.json I opened a ticket.

posted by Jan Jongboom 05 Oct 2017

I haved tested with custom_targets.json as decribed in https://docs.mbed.com/docs/mbed-os-handbook/en/latest/advanced/mbed_targets/

custom_targets.json

{
    "myboard": {
        "inherits": ["NUCLEO_F302R8"],
        "overrides": {
            "clock_source": "USE_PLL_HSI"
         }
}

Looks like it wasn't used

Maybe it is a further problem. How could I select this custom target "myboard"?

posted by Hermi H 05 Oct 2017

New insights:

In the mbed OS sources there ia a system_clock.c for the clock settings of the STM core. (found in \targets\TARGET_STM\TARGET_STM32F3\TARGET_STM32F302x8\TARGET_NUCLEO_F302R8). Here the CLOCK_SOURCE macro is used the set the RCC_RC register. In the exported library package for the mbed CLI there is only a system_clock.o. So it is precomiled.

Now I could change the CLOCK_SOURCE macro where I want, but nothing changed!!

This works neither in the mbed CLI nor in the online IDE!!

posted by Hermi H 10 Oct 2017

1 Answer

3 years, 6 months ago.

Hi

Update your mbed_app.json :

{
    "target_overrides": {
        "NUCLEO_F302R8": {
            "target.clock_source": "USE_PLL_HSI"
            }
        }
    }

I tried this on a new NUCLEO board.

a printf( "CLOCK_SOURCE = %X\n", CLOCK_SOURCE ); shows me the correct value on every compile target setting (F302R8 and F303K8).

But a readout of the RCC_CR shows me the same difference as before. On a compile with F302R8 the HSE_ON is 1 and on a compile with F302K8 the HSE_ON is 0. Looks like the clock configuration is done before the mbed_app.json is compiled.

It looks like the following compiling sequence:

  • targets.json with all its *.h and *.cpp files
  • all other SDK *.json files
  • mbed_app.json
  • main.cpp
  • ...
posted by Hermi H 05 Oct 2017