Adding support for 1Bitsy

Hi there.

I’ve started working on adding support for 1Bitsy which is based on an STM32F415RGT6.

I’m stuck literally at the first step, I’ve created a custom_targets.json file which contains the following, which I figured was the minimum possible starting point:

{
  "1BITSY": {
    "inherits": ["MCU_STM32F4"],
    "device_name": "STM32F415RG"
  }
}

When I run mbed compile -m 1BITSY -t GCC_ARM both on my Mac and inside a mbedos/mbed-os-env docker container I get the following error:

[mbed] Working path "/Users/jimsy/Dev/gitlab.com/jimsy/mbed-os-1bitsy" (program)
Traceback (most recent call last):
  File "/Users/jimsy/Dev/gitlab.com/jimsy/mbed-os-1bitsy/mbed-os/tools/targets/__init__.py", line 157, in target
    resolution_order = get_resolution_order(json_data, name, [])
  File "/Users/jimsy/Dev/gitlab.com/jimsy/mbed-os-1bitsy/mbed-os/tools/targets/__init__.py", line 145, in get_resolution_order
    order = get_resolution_order(json_data, par, order, level + 1)
  File "/Users/jimsy/Dev/gitlab.com/jimsy/mbed-os-1bitsy/mbed-os/tools/targets/__init__.py", line 143, in get_resolution_order
    parents = json_data[target_name].get("inherits", [])
KeyError: 'MCU_STM32F4'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/jimsy/Dev/gitlab.com/jimsy/mbed-os-1bitsy/mbed-os/tools/make.py", line 412, in <module>
    main()
  File "/Users/jimsy/Dev/gitlab.com/jimsy/mbed-os-1bitsy/mbed-os/tools/make.py", line 309, in main
    mcu = extract_mcus(parser, options)[0]
  File "/Users/jimsy/Dev/gitlab.com/jimsy/mbed-os-1bitsy/mbed-os/tools/options.py", line 146, in extract_mcus
    update_target_data()
  File "/Users/jimsy/Dev/gitlab.com/jimsy/mbed-os-1bitsy/mbed-os/tools/targets/__init__.py", line 800, in update_target_data
    TARGETS[:] = [Target.get_target(tgt) for tgt, obj
  File "/Users/jimsy/Dev/gitlab.com/jimsy/mbed-os-1bitsy/mbed-os/tools/targets/__init__.py", line 800, in <listcomp>
    TARGETS[:] = [Target.get_target(tgt) for tgt, obj
  File "/Users/jimsy/Dev/gitlab.com/jimsy/mbed-os-1bitsy/mbed-os/tools/targets/__init__.py", line 113, in wrapper
    CACHES[(func.__name__, args)] = func(*args, **kwargs)
  File "/Users/jimsy/Dev/gitlab.com/jimsy/mbed-os-1bitsy/mbed-os/tools/targets/__init__.py", line 368, in get_target
    return target(target_name, Target.get_json_target_data())
  File "/Users/jimsy/Dev/gitlab.com/jimsy/mbed-os-1bitsy/mbed-os/tools/targets/__init__.py", line 159, in target
    raise_from(NotSupportedException(
  File "/usr/local/lib/python3.8/site-packages/future/utils/__init__.py", line 398, in raise_from
    exec(execstr, myglobals, mylocals)
  File "<string>", line 1, in <module>
tools.utils.NotSupportedException: target 1BITSY has an incomplete target definition
[mbed] ERROR: "/usr/local/opt/python@3.8/bin/python3.8" returned error.
       Code: 1
       Path: "/Users/jimsy/Dev/gitlab.com/jimsy/mbed-os-1bitsy"
       Command: "/usr/local/opt/python@3.8/bin/python3.8 -u /Users/jimsy/Dev/gitlab.com/jimsy/mbed-os-1bitsy/mbed-os/tools/make.py -t GCC_ARM -m 1BITSY --source . --build ./BUILD/1BITSY/GCC_ARM"
       Tip: You could retry the last command with "-v" flag for verbose output
---

I have made a TARGET_1BITSY directory and copied PeripheralPins.c and PinNames.h from a similar board.

Obviously I’ve done something particularly dumb. Can anyone point out my mistake?

Thanks!

Hi

KeyError: ‘MCU_STM32F4’

Note that this is available with STM32 custom target: create MCU_STM32xx for each family by jeromecoutant · Pull Request #13229 · ARMmbed/mbed-os · GitHub
which is currently only available on mbed-os master branch

I have made a TARGET_1BITSY directory and copied PeripheralPins.c and PinNames.h from a similar board.

This is good but not sufficient :frowning:
My recommendation would be to create a full TARGET_STM32F415xG (copy from targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F413xH for ex)
Then check/update the linker script and cmsis_nvic.h

Here is how custom_targets.json could be:

"1BITSY": {
    "inherits": ["MCU_STM32F4"],
    "extra_labels_add": [
        "STM32F415xG"
    ],
    "macros_add": [
        "STM32F415xx"
    ],
    "device_name": "STM32F415RGTx"
},

Thanks for the reply @jeromecoutant. Are you saying I need to send a PR to mbed-os with the new target?

It depends if you want to make your project public.

One alternative is to create only the “intermediate” step:
“MCU_STM32F415xG” in targets.json like for ex in

Regards,

Thanks for adding support for the 1Bitsy, this seems like a great board that could help many developers!

We don’t think is appropriate to add support for it in Mbed OS as that’s for officially supported boards, but instead you can add support as custom board as you started already.

You seem to be close to get it working. Do you mind creating a GitHub repo and add the corresponding files as suggested by @jeromecoutant and explained in the blog? Thanks!

I forked mbed-os and managed to compile code for this target, so I’m feeling pretty good. I’ll go back to making it work as a custom target however. Would you accept a PR that just includes the MCU_STM32F415xG target @MarceloSalazar?

Yes, an MCU entry is ok as already defined in other cases.
Please set “public”: false , so this isn’t confused with a board.

Thanks @MarceloSalazar - I have opened a PR with MCU support: Add STM32F415xG target support. by jimsynz · Pull Request #13417 · ARMmbed/mbed-os · GitHub

So I have a PR open against mbed which enables the MCU_STM32F415xG target. In the mean time I’ve been working off that branch on the 1bitsy support. Code is here: James Harton / mbed-os-1bitsy · GitLab

The current status is that the code compiles and runs, but ThisThread::sleep_for never returns. When I inspect it with the debugger I can step through it fine, however. My assumption is that I haven’t set up the system clock source or a timer correctly (I’m basically just working straight from the MCU_STM32F415xG target with very little added code for now). Any pointers would be appreciated.

Debug output is here: `ThisThread::sleep_for` not returning. ($2005007) · Snippets · James Harton / mbed-os-1bitsy · GitLab