You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
stm32CubeProg.sh getopt: illegal option -- a on macOS Apple Silicon, Sequoia 15.6, internal BSD getopt #112
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?
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.
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…
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?)...
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.
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
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.
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.
Another project that is incompatible with BSD getopt is OpenWrt build
system, so there is some precedence.
Though, it must be documented somewhere if installing gnu-getopt is a
breaking change, if that’s how it will be going forward.
In any case let me continue deep diving this tomorrow. If it is a
straightforward fix hopefully things can remain simple for macOS users who
don’t have Homebrew.
--- ~/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.
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.
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).
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...
Maybe just do the Busybox thing. Life and death does not depend on this feature. It just makes hobby electronics a bit more fun. 🐶
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.
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.
Activity
ndoo commentedon Dec 17, 2025
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.
fpistm commentedon Dec 17, 2025
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?
ndoo commentedon Dec 17, 2025
macOS 15.6 24G84 (not working)
macOS 26.1 25B78 (working)
Don't think this helps you much…
ndoo commentedon Dec 17, 2025
I intentionally did not use the Homebrew
gnu-getoptto get the regression; using GNU getopts does solve it of course.By the way, this is unrelated to this specific issue, but
brew --prefixshould be used instead of hardcoding/opt/homebrewand also/usr/local/optbecause I couldn't put it in the 2 locations tested bystm32CubeProg.shdue 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.
ndoo commentedon Dec 17, 2025
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…
fpistm commentedon Dec 17, 2025
right... could you tell me the version of getopt?
ndoo commentedon Dec 17, 2025
I have no idea how to identify it, unfortunately…
On both macOS versions.
fpistm commentedon Dec 17, 2025
Well, try to sum up.
On macOS 15.6 24G84:
getopt: illegal option -- aThere 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?)...
ndoo commentedon Dec 17, 2025
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.
[-]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[/+]fpistm commentedon Dec 17, 2025
Thanks for the help. Very appreciated.
ndoo commentedon Dec 17, 2025
No worries.
Here is the state of my mind, before I go offline for the day…
getopt: illegal option -- abut need to test further)fpistm commentedon Dec 17, 2025
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.
fpistm commentedon Dec 17, 2025
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.
ndoo commentedon Dec 17, 2025
2 remaining items
fpistm commentedon Feb 24, 2026
@nomosno
Feel free to contribute it is a community project.
ndoo commentedon Mar 17, 2026
Hi @fpistm , this fixed the issue for me:
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.
fpistm commentedon Mar 17, 2026
Don't think it solve the issue. You don't have the error but options are not properly parsed.
ndoo commentedon Mar 17, 2026
what's the test criteria for this? it does try to flash my board in DFU
fpistm commentedon Mar 17, 2026
If you used serial programming it will fail as it uses a long option.
wanthalf commentedon Apr 17, 2026
Thanks for solving this issue. Could you add detection of the MacPorts version of
gnuoptinstalled under/opt/local/bin/getopt, please? It works well, too.fpistm commentedon May 29, 2026
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).
Thorwegian commentedon May 29, 2026
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...
Maybe just do the Busybox thing. Life and death does not depend on this feature. It just makes hobby electronics a bit more fun. 🐶
Thorwegian commentedon May 29, 2026
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.
fpistm commentedon Jul 21, 2026
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.