Skip to content

Arduino Opta support#531

Open
putertubby wants to merge 4 commits into
mbed-ce:mainfrom
putertubby:arduino-opta-target
Open

Arduino Opta support#531
putertubby wants to merge 4 commits into
mbed-ce:mainfrom
putertubby:arduino-opta-target

Conversation

@putertubby
Copy link
Copy Markdown

@putertubby putertubby commented Dec 29, 2025

Summary of changes

This pull request implements support for the Arduino Opta microPLC by the addition of two public build targets; ARDUINO_OPTA_M7 and ARDUINO_OPTA_M4.

Documentation

None. The new targets follow the established pattern.


Pull request type

[x] Patch update (Bug fix / Target update / Docs update / Test update / Refactor)
[] Feature update (New feature / Functionality change / New API)
[] Major update (Breaking change E.g. Return code change / API behaviour change)

Test results

[] No Tests required for this change (E.g docs only update)
[] Covered by existing mbed-os tests (Greentea or Unittest)
[x] Tests / results supplied as part of this PR

Tested on an Arduino Opta WIFI M7, nothing running on the M4 yet.

  • All the basic functionality is working, however the Opta RTC does not keep time correctly. (Off by about 1ms/hour)
  • I/O pins are operational
  • External flash (QSPI) is working fine
  • RS485 (Modbus RTU) interface is working fine
  • Ethernet seems to be working fine when running unencrypted, however - I'm having issues getting TLS to work properly.

Connection to the server often fails just to succeed in later reconnect attempts. Previous software, using a custom target and based on this version of mbed does not exhibit this behaviour. The only known difference is that I set "lwip.tcp-mss": 1460 in mbed_app.json5 in the old software but trying that in this branch fails sanity checks in lwip_init.c so I had to remove the setting. Maybe I'm dropping a lot of packets?

#if !MEMP_MEM_MALLOC && PBUF_POOL_SIZE && (TCP_WND > (PBUF_POOL_SIZE * (PBUF_POOL_BUFSIZE - (PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN + PBUF_IP_HLEN + PBUF_TRANSPORT_HLEN))))
#error "lwip_sanity_check: WARNING: TCP_WND is larger than space provided by PBUF_POOL_SIZE * (PBUF_POOL_BUFSIZE - protocol headers). If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error."
#endif

Copy link
Copy Markdown
Collaborator

@multiplemonomials multiplemonomials left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work on this! Just a few small comments and things to fix.

btw, did you get a chance to test the ethernet? Is it working with this branch?

Comment thread targets/targets.json5 Outdated
Comment thread targets/targets.json5 Outdated
Comment thread targets/upload_method_cfg/ARDUINO_OPTA_M7.cmake
/* Set pinstrap for 100mbit */
// TODO

/* Reset ETH Phy */
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I missed this earlier, oops, but this entire block can be removed. We reset the ethernet phy during its initialization, so as long as you implement EthGetPhyResetPin(), you don't need to touch PJ15 at all!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried removing the reset code but that caused crashes at initialization. Which part did you want removed?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh that's really weird, what was the crash? You should be able to safely remove the following lines:

    __HAL_RCC_GPIOJ_CLK_ENABLE();
    GPIO_InitTypeDef  gpio_eth_rst_init_structure;
    gpio_eth_rst_init_structure.Pin = GPIO_PIN_15;
    gpio_eth_rst_init_structure.Mode = GPIO_MODE_OUTPUT_PP;
    gpio_eth_rst_init_structure.Pull = GPIO_NOPULL;
    gpio_eth_rst_init_structure.Speed = GPIO_SPEED_FREQ_LOW;
    HAL_GPIO_Init(GPIOJ, &gpio_eth_rst_init_structure);

and then

    HAL_Delay(25);
    HAL_GPIO_WritePin(GPIOJ, GPIO_PIN_15, 0);
    HAL_Delay(100);
    HAL_GPIO_WritePin(GPIOJ, GPIO_PIN_15, 1);

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still get an Mbed OS crash (4 long/4 short red LED pattern) when I remove the code above. Can't say for sure what's going on as I only have one Opta device and can't really open it up to attach a debugger.

What's even curiouser is that I found a call to SCB_DisableDCache() in the Arduino mbed-os ethernet init code. When I added that call back in I got TLS to work reliably again (see the top comment on test results). I have no idea what's going on but it doesn't seem right to disable data cache in the ethernet initialization function?

Copy link
Copy Markdown
Collaborator

@multiplemonomials multiplemonomials Jan 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm what if you keep the GPIOJ clock enable but remove everything else? Or if you just remove the second group of lines?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@putertubby Any updates on this? If you can check this out, I'm good to merge the PR!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't had the time to dig further yet. I'll try to look into it. 🤞

@putertubby putertubby marked this pull request as ready for review January 9, 2026 12:22

#if !(defined(DUAL_CORE) && defined(CORE_CM4))
/* Disable DCache for STM32H7 family */
SCB_DisableDCache();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait why are we disabling the data cache? This slows the CPU down immensely and shouldn't be needed with the new Mbed CE ethernet drivers

Copy link
Copy Markdown
Collaborator

@multiplemonomials multiplemonomials Jan 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I saw your other comment. Damn that's annoying that it actually seems to be making a difference with TLS, I thought I fixed this. What code are you running that shows issues with TLS? I think the best path here may be for me to run that code on another STM32H7 board and see if I can reproduce the issues.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try to create a minimal example. It is quite possible that I made an error in my application code and that issues were masked by the disabled data cache. We'll find out.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants