Nano Matter on Apple Silicon machine without Rosetta

Continuing the discussion from How to avoid installing Rosetta on an Apple Silicon Mac:

I have followed the above instructions but it still does not work for me.
Environment: IDE 2.3.7 , Apple Silicon M4
The sketch compiles (verify) w/o errors but fails to upload into Arduino NanoMatter . I still have the ' bad CPU type' message. I run the avrdude -v command and it looks like .... System wide configuration file is /opt/homebrew/etc/avrdude.conf
User configuration file /Users/myself/.avrduderc does not exist....

Any idea?

Hi @new4fun. The instructions shared by @jpurnell are intended for expert users who, for whatever reason, don't want to use the tool binaries that are built for the x86 (AKA "Intel") host architecture.

For we mere mortals who just want to get the system working with the least effort and maintenance burden, the best approach is to simply install Apple's Rosetta 2 binary translator. This will allow your Mac to run the x86 tool binary builds that are distributed by Arduino/Silicon Labs.

You can do that by following the instructions here:

https://support.arduino.cc/hc/en-us/articles/7765785712156-Error-bad-CPU-type-in-executable-on-macOS#if-your-mac-computer-has-an-apple-silicon-processor

Many thanks for your prompt reply. I just wanted to avoid installing Rosetta on my iMac following the given instructions step by step: maybe there is some more environment set-up that I missed !. Thank you again for your help.

The problem is that @jpurnell instructions are for installing and configuring Arduino IDE to use the native Apple Silicon builds of the tool dependencies of the "Arduino AVR Boards" platform. Other than Ctags, the "Silicon Labs" boards platform has completely different tool dependencies, so installing those tools that are specific to microcontrollers of the AVR architecture won't accomplish anything for the Nano Matter board, which uses a microcontroller (MGM240SD22VNA) of a completely different architecture, and thus has different tool dependencies.

So binaries that are built for x86 host architecture are still being used when compiling or uploading for the Nano Matter board, and this is why you are still encountering that "bad CPU type" error. The only way to use the Nano Matter board without installing Rosetta would be to install native Apple Silicon builds of the tool dependencies of that board, and make the adjustments to that platform that are necessary to cause it to use the tools you installed instead of the once that were installed by the Arduino IDE Boards Manager.

The tool dependencies of the Nano Matter board are listed here:

Your detailed answer confirms my initial suspect on the tools dependencies for the nanomatter chip architecture. I believe that the only ( frustrating! ) solution to keep on working on Siliconlabs chip aside of M4 Apple Silicon will be to install Rosetta :unamused_face: ( or to switch to a different board / chip) . Thanks.

It is definitely possible to set up your system to use native Apple Silicon builds of these tools. The ARM GNU Toolchain (AKA "gcc-arm-none-eabi") and OpenOCD are very widely used outside the Arduino community, so it should be relatively easy to procure native Apple Silicon builds of the tools to install.

The adjustment of the platform configuration to use those installations instead of the installations made by Boards Manager is more obscure, but that is something the forum helpers are better equipped to assist with.

From a quick glance at the subject, it seems that the Ctags tool was the most tricky part (since Arduino created their own obscure variant of the tool and so the only way to obtain an Apple Silicon build is to build it yourself from source), but thankfully @jpurnell managed to figure that out and was kind enough to share their findings.

But as I said before, this is an advanced endeavor that really isn't necessary to undertake. Many thousands of Arduino community members (including myself) are happily using the x86 builds of these tools (these tools are also dependencies of many other popular boards) on their Apple Silicon machines.

Some update on this matter.. with some good news and some bad news!

I have changed board to Arduino ESP 32 (instead of NanoMatter) and I did the following:

  1. Updated board ESP32….
    arduino-esp32/README.md at master · espressif/arduino-esp32 · GitHub

  2. Downloaded DFU-UTIL (for the…bad CPU type….error)
    dfuutil-darwin-arm64.zip
    3 . Made necessary corrections…
    Reddit - The heart of the internet

  3. Upload gives error…

    dfu-util: invalid option -- Q
    
  4. I found that the option --Q is actually NOT a valid option!!

  5. Opened a terminal window and gave the command WITHOUT the --Q option

  6. And..VOILA'...The code was successfully loaded into Arduino ESP32 board.

The bad news is that if I try now with Arduino nanomatter board it fails again to compile !

Yeah, this is something the Arduino developers added to the variant of dfu-util that Arduino distributes.

So it would be necessary to build Arduino's variant of dfu-util from the source code in order to have a native Apple Silicon of that tool with the -Q flag support. Unfortunately I am having trouble tracking down that source code right now. I have asked the developers about it. I'll make an update here if I am able to find it.

If you provide the full text of the error you are experiencing we might be able to help you with that.

I tracked it down. The source code for Arduino's variant of dfu-util is here:

So if you build it from source on an Apple Silicon machine the generated binary can be used as a replacement for the tool installed by Arduino Boards Manager without requiring Rosetta 2.

Thank you so much for your help. I will try to compile dfu util by myself meantime Arduino team will release a new IDE that includes the right utils.
As far as the nanomatter compile is concerned... I removed the esp32 boards, cleaned some cache and reinstalled. Now (at least for the two ESP32 boards) compile works fine. The upload is of course done via command line without the --Q option.

You are welcome. I'm glad if I was able to be of some small assistance.

Let us know how it goes. I'm sure others who have the same goal would be grateful for any information you can share.

To be clear, there is no need for any changes in the Arduino IDE application. We already produce native Apple Silicon builds of the application.

The deficiency is in the build systems of the separate helper tools used by Arduino IDE. Arduino IDE downloads those tools from the Internet on demand. Arduino IDE has an algorithm for determining which tool build to download for the host system in use. On an Apple Silicon host, Arduino IDE will always download the native Apple Silicon build of the tool if it is available. It only falls back on downloading the x86 build of the tool if an Apple Silicon build is not available. So as soon as native Apple Silicon builds of a helper tool become available, even the current version of Arduino IDE will chose that build of the tool.

The 'opened' executable file originally installed with ESP32 Espressif board gives the "Bad CPU Type" error. " while trying to upload to nanomatter board.
Checked for version and this is:

file openocd
openocd: Mach-O 64-bit executable x86_64

I have replaced it with an arm64 executable but now this is the error for the NANOMATTER BOARD:

Open On-Chip Debugger 0.12.0
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
debug_level: 2

Info : auto-selecting first available session transport "swd". To override use 'transport select <transport>'.
Error: flash driver 'efm32s2' not found

Failed uploading: uploading error: exit status 1

The compile (verify) works fine.

I see. It looks like the arduino:openocd@0.12.0-arduino1-static variant of OpenOCD that is used by the "Silicon Labs" Arduino boards platform has been modified to include this driver:

That "efm32s2 driver" is used by the command defined in the "Silicon Labs" platform for uploading to the Nano Matter board, but the "driver" is not present in the official OpenOCD build, so that is why you get this error when you try to use the official OpenOCD binary in place of the one from arduino:openocd@0.12.0-arduino1-static.

It looks like the developer of the efm32s2 driver was kind enough to provide high quality instructions for building OpenOCD from source with that driver, so I think it should be possible for you to create a native Apple Silicon build of OpenOCD with that driver.

Thank you so much ptillish. I will be very grateful if I could have more detailed instructions on how to rebuild on my Mac M4 the efm32s2 driver.
To be honest I landed to same link a few days ago and gave some try to rebuild openOCD driver but so far I have not been successful :pensive_face:
So any help is appreciated!

Unfortunately I am not knowledgeable in this subject matter. I only know what I read in the documentation of that GitHub repository I linked.

Hopefully one of the other forum helpers will be able to provide assistance.

I think it will be productive for you to provide a detailed description of exactly what you did and exactly what happened that did not match your expectations. Make sure to provide the full and exact text of any relevant warnings or error messages you encountered.

New update (no success so far!)
Installed prereqs:

  • brew install autoconf
  • brew install libtool
  • brew install automake
  • brew install pkg-config
  1. mkdir openOCD_ARM64 (name of my choice)
  2. gh repo clone knieriem/openocd-efm32-series2
  3. cd openocd-efm32-series2
  4. ./setup-openocd-src.sh

Setup complains that libjaylink-0.2 is required

checking for libgpiod... no
checking for libjaylink >= 0.2... no
configure: error: libjaylink-0.2 is required for the SEGGER J-Link Programmer

So….

4B.

gh repo clone https://github.com/syntacore/libjaylink.git`
cd libjaylink
$ ./autogen.sh
$ ./configure
$ make
$ make install

4C. Run again ./setup-openocd-src.sh
5. ./build.sh

It seems that everything is OK BUT cannot flash the board !

** Programming Started **
Info : detected part: MG24B210, rev 18
Info : flash size = 1536 KiB
Info : flash page size = 8192 B
Warn : Don't know EFR/EFM Gx family number, can't set MSC register. Defaulting to EF{M,R}xG22 values..
Info : detected part: MG24B210, rev 18
Info : flash size = 1536 KiB
Info : flash page size = 8192 B
Warn : Don't know EFR/EFM Gx family number, can't set MSC register. Defaulting to EF{M,R}xG22 values..
Warn : no flash bank found for address 0x08006000
** Programming Finished **

Are you sure of that? The output you shared appears to be of a successful upload. There are some warnings, but no errors.

At the end of an upload operation, a notification appears at the bottom right corner of the Arduino IDE window. If the upload failed, you will The message might be "Upload error: ...:

But if you instead see the message "Done uploading." in that notification, it means the upload was successful:

Note that this notification is hidden after a few seconds, so you might miss it if you aren't watching. If you miss it, you can click the :bell: icon at the right side of the status bar to show the hidden notifications again.

Unfortunately everything looks ok BUT the board keeps in its memory the old sketch that never get replaced. I have created an empty sketch, that is:

void setup() {
Serial.begin(115200);
}

void loop() {
Serial.println("Hello !");
delay(5000);
}

But this sketch never gets uploaded into the board that in fact acts with the previous loaded sketch (a simple press button that flash the builtin led).

void setup() {
 Serial.begin(115200);
  pinMode(BTN_BUILTIN, INPUT_PULLUP);
  pinMode(LED_BUILTIN, OUTPUT);

  }
void loop() {

digitalWrite(LED_BUILTIN,digitalRead(BTN_BUILTIN));
  if (digitalRead(BTN_BUILTIN) == 0) {
  Serial.println("Pulsante premuto...");
  Serial.println();
  }
}