Sprintf with "%03X" does not left pad with "0"

I assume you are using Mbed OS6. OS6 uses minimal-printf library which does not support padding. You can switch back to the standard library by overriding the parameter in mbed_app.json.

    "target_overrides": {
        "*": {
            "target.printf_lib": "std"
        }
    }

More info here: