microsoft / microsoft/pxt-microbit

Setting constants in `pxt.json` with `yotta.config.codal` does not work

Open
#5,352 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

cli
Dominant language
TypeScript
Stars
804
Forks
721
Avg merge
2d 9h
Merged PRs (30d)
2

Description

Describe the bug
From the documentation in https://github.com/microsoft/pxt/blob/d6fa4dffb4bf95eb7c5ab8f93323d64f240bc157/docs/extensions/pxt-json.md#setting-c-constants-for-dal-config---yotta this should work, but when tested it does not set up the macro in the CODAL builds:

    "yotta": {
        "config": {
            "codal": {
                "CODAL_RANDOM_MACRO_NAME": 1
            }
        }
    }

Adding the macros to yotta.config instead does work, but that adds them to both V1 and V2 builds.

    "yotta": {
        "config": {
            "CODAL_AND_DAL_RANDOM_MACRO_NAME": 1
        }
    }

To Reproduce

To test this I've created this MakeCode programme with a C++ file that prints macro values, based on this @martinwork's extension for the same purpose: https://github.com/martinwork/pxt-cpp/blob/master/ext.cpp

The project example can be imported from: https://github.com/microbit-carlos/makecode-macrotest

  1. Go to https://makecode.microbit.org/beta
  2. Click on the "Import" button, and "import from URL"
  3. Enter the https://github.com/microbit-carlos/makecode-macrotest URL
  4. Inspect the macros defined in pxt.json
  5. Compile the programme and flash the micro:bit
  6. Inspect the output printed to serial
    "yotta": {
        "config": {
            "codal": {
                "MICROBIT_BLE_UTILITY_SERVICE": 1,
                "MICROBIT_BLE_UTILITY_SERVICE_PAIRING": 1,
                "RANDOM_MACRO_IN_YOTTA_CONFIG_CODAL": 1
            },
            "microbit-dal": {
                "RANDOM_MACRO_IN_YOTTA_CONFIG_MICROBITDAL": 1
            },
            "RANDOM_MACRO_IN_YOTTA_CONFIG": 1
        }
    }
uBit.serial.send("MICROBIT_BLE_UTILITY_SERVICE_PAIRING     = " MACROTOSTRING(MICROBIT_BLE_UTILITY_SERVICE_PAIRING) "\n");
uBit.serial.send("MICROBIT_BLE_UTILITY_SERVICE             = " MACROTOSTRING(MICROBIT_BLE_UTILITY_SERVICE) "\n");
uBit.serial.send("RANDOM_MACRO_IN_YOTTA_CONFIG_CODAL       = " MACROTOSTRING(RANDOM_MACRO_IN_YOTTA_CONFIG_CODAL) "\n");
uBit.serial.send("RANDOM_MACRO_IN_YOTTA_CONFIG_MICROBITDAL = " MACROTOSTRING(RANDOM_MACRO_IN_YOTTA_CONFIG_MICROBITDAL) "\n");
uBit.serial.send("RANDOM_MACRO_IN_YOTTA_CONFIG             = " MACROTOSTRING(RANDOM_MACRO_IN_YOTTA_CONFIG) "\n");

Output:

MICROBIT_BLE_UTILITY_SERVICE_PAIRING     = 0
MICROBIT_BLE_UTILITY_SERVICE             = 0
RANDOM_MACRO_IN_YOTTA_CONFIG_CODAL       = RANDOM_MACRO_IN_YOTTA_CONFIG_CODAL
RANDOM_MACRO_IN_YOTTA_CONFIG_MICROBITDAL = RANDOM_MACRO_IN_YOTTA_CONFIG_MICROBITDAL
RANDOM_MACRO_IN_YOTTA_CONFIG             = 1

As show, RANDOM_MACRO_IN_YOTTA_CONFIG_CODAL should be equal to 1, but as an undefined macro it prints its name.
RANDOM_MACRO_IN_YOTTA_CONFIG_MICROBITDAL is correctly undefined, as that's a macro for V1 DAL only.

Expected behavior

The expected output on a micro:bit V2 would have been:

MICROBIT_BLE_UTILITY_SERVICE_PAIRING     = 1
MICROBIT_BLE_UTILITY_SERVICE             = 1
RANDOM_MACRO_IN_YOTTA_CONFIG_CODAL       = 1
RANDOM_MACRO_IN_YOTTA_CONFIG_MICROBITDAL = RANDOM_MACRO_IN_YOTTA_CONFIG_MICROBITDAL
RANDOM_MACRO_IN_YOTTA_CONFIG             = 1

Screenshots
N/A

micro:bit version (please complete the following information):

V2.xx

Desktop (please complete the following information):
N/A

Additional context

makecode.microbit.org version: 6.1.5
Microsoft MakeCode version: 9.1.11
microbit runtime version: v2.2.0-rc6
codal-microbit-v2 runtime version: v0.2.57

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the pxt.json configuration documented in docs/extensions/pxt-json.md and reproduce the issue using the linked makecode-macrotest project and its C++ macro output. Trace how the codal and microbit-dal sections are passed into the V2 build, then verify completion by compiling the example and confirming the CODAL macros expand to 1 while the DAL-only macro remains undefined.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, typescript
Domain
build-system, embedded-iot
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.