Skip to content

stm32CubeProg.sh getopt: illegal option -- a on macOS Apple Silicon, Sequoia 15.6, internal BSD getopt #112

Closed

Description

@ndoo

STM32Tools 2.4.0 that shipped with STM32Duino Arduino core 2.12.0.

macOS 15.6 24G84
Using built-in macOS BSD getopt.

Describe the bug
getopt: illegal option -- a when using DFU upload. Board STM32U0 -> Generic U073C8Tx.
Upload method: "STM32CubeProgrammer (DFU)".

To Reproduce
Steps to reproduce the behavior:

  1. Compile (success)
  2. Upload
  3. Fails due to getopt error.

Expected behavior
Successful upload (it was working on STM32Tools@2.3.1 that shipped with STM32Duino Arduino core 2.11.0).

Screenshots
Sorry, unable to provide

Desktop (please complete the following information):

  • OS: macOS 15.6 24G84
  • Arduino IDE version: 2.3.6
  • STM32 core version: 2.12.0
  • Library version: N/A (fails even with empty sketch)
  • Tools menu settings if not the default: Board STM32U0 -> Generic U073C8Tx
  • Upload method: [e.g. SWD]

Hardware (please complete the following information):

  • Board Name: Generic U073C8Tx
  • Hardware Revision: Proprietary
  • Extra hardware used if any: N/A native USB

Additional context

Activity

  1. ndoo commented on Dec 17, 2025

    @ndoo
    Author

    Just to add, the same software environment and build settings, I do not get the getopts error on macOS 26.1 (25B78).

    So I’m not sure what has changed between STM32Tools 2.3.1 to STM32Tools 2.4.0 that would break BSD getopts just for the older macOS version.

  2. fpistm commented on Dec 17, 2025

    @fpistm
    Member

    Hi,
    The getopt usage on macos is a nightmare.
    More info here:
    #100

    I think I forgot to populate some new option when trying to handle getopt on mac like adress option -a but you should have also the issue with 2.3.1. Seems strange.
    Or this is again the management of the getopt version GNU one or not.
    Could you telle me where is your getopt?

  3. ndoo commented on Dec 17, 2025

    @ndoo
    Author

    macOS 15.6 24G84 (not working)

    % which getopt
    /usr/bin/getopt
    

    macOS 26.1 25B78 (working)

    % which getopt
    /usr/bin/getopt
    

    Don't think this helps you much…

  4. ndoo commented on Dec 17, 2025

    @ndoo
    Author

    I intentionally did not use the Homebrew gnu-getopt to get the regression; using GNU getopts does solve it of course.

    By the way, this is unrelated to this specific issue, but brew --prefix should be used instead of hardcoding /opt/homebrew and also /usr/local/opt because I couldn't put it in the 2 locations tested by stm32CubeProg.sh due to lack of admin rights on the older macOS laptop.

    Should I raise an issue for that? I hardcoded the path I am using for my Homebrew prefix in order to test gnu-getopt.

  5. ndoo commented on Dec 17, 2025

    @ndoo
    Author

    I just ran a diff of the manpages of 26.1 and 15.6 built-in getopt and only the macOS version line has changed, the rest of the manpages are identical…

  6. fpistm commented on Dec 17, 2025

    @fpistm
    Member

    right... could you tell me the version of getopt?

  7. ndoo commented on Dec 17, 2025

    @ndoo
    Author

    I have no idea how to identify it, unfortunately…

    % getopt -T; echo $?
     --
    0
    

    On both macOS versions.

  8. fpistm commented on Dec 17, 2025

    @fpistm
    Member

    Well, try to sum up.
    On macOS 15.6 24G84:

    • With 2.4.0 of the Arduino Tools you got the error: getopt: illegal option -- a
    • While with 2.31 you don't.

    There is no change on getopt management between 2.31 and 2.4.0.
    Except those one: #105 and #108
    The first add a -a option but in this case you should have Unknown option error message if not handled.

    So it is the version of getopt which does not support the -a option. In that case it should be the same issue between 2.3.1 and 2.4.0.
    I can't reproduce as I have only one MAC but very old and by default the getopt is the GNU one.

    So I would first understand why you don't have issue with 2.3.1.
    When you do a getopt -a ? what is the result?

    One other point, you talk about brew --prefix , I'm not a MAC expert.
    Is it something common to all MAC? Is it callable in any case (right admin?)...

  9. ndoo commented on Dec 17, 2025

    @ndoo
    Author

    Let me do some further testing tonight, I will nuke away all my Arduino app/user data folders and install cleanly on both environments and report back tomorrow sometime.

    One thing is for sure, using gnu-getopt from Homebrew works fine. I will edit the subject to make it clearer only built-in getopt is affected.

  10. changed the title [-]stm32CubeProg.sh `getopt: illegal option -- a` on macOS Apple Silicon, Sequoia 15.6[/-] [+]stm32CubeProg.sh `getopt: illegal option -- a` on macOS Apple Silicon, Sequoia 15.6, internal BSD getopt[/+] on Dec 17, 2025
  11. fpistm commented on Dec 17, 2025

    @fpistm
    Member

    Thanks for the help. Very appreciated.

  12. ndoo commented on Dec 17, 2025

    @ndoo
    Author

    No worries.

    Here is the state of my mind, before I go offline for the day…

    STM32Tools 2.3.1 STM32Tools 2.4.0
    macOS 15.6 24G84, BSD getopt ✅ ❌ (getopt: illegal option -- a but need to test further)
    macOS 15.6 24G84, GNU getopt ✅ ✅
    macOS 26.1 25B78, BSD getopt ✅ ✅ (but need to test further)
    macOS 26.1 25B78, GNU getopt ✅ ✅
  13. fpistm commented on Dec 17, 2025

    @fpistm
    Member

    Thanks for the status. Anyway, I really don't understand the fact it works with 2.3.1.
    Maybe related to the options added later and not managed properly in case of BSD getopt.
    I will provide a patch for this.

  14. fpistm commented on Dec 17, 2025

    @fpistm
    Member

    Well, I guess the easiest way to handle this and avoid any further regression link to the FreeBSD getopt.
    I think the best way is to test if the getopt is the GNU one, if not then advise user to install it.
    This will be easier to maintain, manage the long option and space in arguments.

  15. ndoo commented on Dec 17, 2025

    @ndoo
    Author
  16. 2 remaining items

  17. fpistm commented on Feb 24, 2026

    @fpistm
    Member

    @nomosno
    Feel free to contribute it is a community project.

  18. ndoo commented on Mar 17, 2026

    @ndoo
    Author

    Hi @fpistm , this fixed the issue for me:

    --- ~/Library/Arduino15/packages/STMicroelectronics/tools/STM32Tools/2.4.0/stm32CubeProg.sh.orig 2026-03-17 10:09:45
    +++ ~/Library/Arduino15/packages/STMicroelectronics/tools/STM32Tools/2.4.0/stm32CubeProg.sh  2026-03-17 10:10:33
    @@ -120,7 +120,7 @@
    # parse command line arguments
    # options may be followed by one colon to indicate they have a required arg
    if [ -n "${GNU_GETOPT}" ]; then
    -  if ! options=$(getopt hi:ef:o:c:r:d:v:p: "$@"); then
    +  if ! options=$(getopt a:hi:m:ef:o:c:r:s:d:v:p: "$@"); then
         echo "Terminating..." >&2
         exit 1
       fi
    

    Should I raise a PR? I feel like this needs more testing but I don't have the various other versions of MacOS around to test for regressions.

  19. fpistm commented on Mar 17, 2026

    @fpistm
    Member

    Don't think it solve the issue. You don't have the error but options are not properly parsed.

  20. ndoo commented on Mar 17, 2026

    @ndoo
    Author

    Don't think it solve the issue. You don't have the error but options are not properly parsed.

    what's the test criteria for this? it does try to flash my board in DFU

  21. fpistm commented on Mar 17, 2026

    @fpistm
    Member

    If you used serial programming it will fail as it uses a long option.

  22. wanthalf commented on Apr 17, 2026

    @wanthalf

    Thanks for solving this issue. Could you add detection of the MacPorts version of gnuopt installed under /opt/local/bin/getopt, please? It works well, too.

  23. fpistm commented on May 29, 2026

    @fpistm
    Member

    I wonder if a solution would be to provide a busybox including the Gnu getopt version and when the GNU one is not installed on the MACOS we fallback on the one provided with the busybox (for arm and x64 if I'm not wrong).

  24. Thorwegian commented on May 29, 2026

    @Thorwegian

    Thanks for getting back to me so quickly. The maintainers are gentlemen.

    I've been asked to submit a pull request. Fair enough. Making a complex architecture like the STM32 simple to use is via the Arduino IDE is... not so simple. 😬

    getopt is a couple of steps down the chain from the ROM offset and I'm not sure how the STM toolchain operates. Based on how slowly this ran on my old ThinkPad, maybe no one is quite sure how it all works and a slapdash approach to things was taken to get it working...

    Image

    Maybe just do the Busybox thing. Life and death does not depend on this feature. It just makes hobby electronics a bit more fun. 🐶

  25. Thorwegian commented on May 29, 2026

    @Thorwegian
    1780006319848.mp4

    So, what I'm actually working on is this comfy ASMR type thing. I've got the 16 GPIO outputs driving 16 LEDs within the electrical specs of the chip, using 16 software PWM channels thru an ISR. Each LED driven individually through a two-stage low-pass filter to produce an organic flame-like effect, like 16 colourful tea candles.

    It took some effort to get it working. The rand() functions to produce that flame effect causes a hang in the firmware, so I had to come up with my own PRNG to produce the necessary Brownian noise.

    I thought maybe these flames need a bit of airflow too, so I moved the project over to my Mac for some creative inspiration, and that's where I ran into the snag.

  26. added
    bug 🐛
    on Jul 21, 2026
  27. added theissue type on Jul 21, 2026
  28. added this to the 2.4.1/2.5.0 milestone on Jul 21, 2026
  29. fpistm commented on Jul 21, 2026

    @fpistm
    Member

    The illegal option -- a is fixed by #118.
    About other issues linked to long options and BSD/GNU getopt, it will be addressed by an other PR.
    So I close this one as the illegal option is fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🐛

    Type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions