Skip to content

modem_cellular: Add support for the simcom a76xx modem #90081

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 28, 2025

Conversation

olalonde
Copy link
Contributor

@olalonde olalonde commented May 16, 2025

Add support for the simcom a76xx modem which is similar to the simcom 7080 but has a few key differences. Tested with a simcom A7672SA module but as there is a single simcom A76XX AT commands manual, the driver should work with other modems of the series.

Tested with:

CONFIG_MODEM_CMUX_WORK_BUFFER_SIZE=1507

and

/ {
        aliases {
                modem = &modem;
        };
};

/* Tested with Simcom A7672SA module connected via UART
 * TX: P1.2
 * RX: P1.1
 * PWRKEY: P0.02
 */
&uart1 {
        compatible = "nordic,nrf-uarte";
        status = "okay";
        current-speed = <115200>;
        /* The module I tested with doesn't expose RCS/CTS pins
         * hw-flow-control;
         */

        pinctrl-0 = <&uart1_default>;

        modem: modem {
                compatible = "simcom,a76xx";
                status = "okay";
                mdm-power-gpios = <&gpio0 2 (GPIO_ACTIVE_HIGH)>;
        };
};

Copy link

Hello @olalonde, and thank you very much for your first pull request to the Zephyr project!
Our Continuous Integration pipeline will execute a series of checks on your Pull Request commit messages and code, and you are expected to address any failures by updating the PR. Please take a look at our commit message guidelines to find out how to format your commit messages, and at our contribution workflow to understand how to update your Pull Request. If you haven't already, please make sure to review the project's Contributor Expectations and update (by amending and force-pushing the commits) your pull request if necessary.
If you are stuck or need help please join us on Discord and ask your question there. Additionally, you can escalate the review when applicable. 😊

@@ -0,0 +1,27 @@
/ {
Copy link
Member

Choose a reason for hiding this comment

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

This does not look right. Now anyone having this DK will get this simcom modem added automatically even if he/she does not have one.

Copy link
Contributor Author

@olalonde olalonde May 23, 2025

Choose a reason for hiding this comment

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

I used the nrf52840dk board for testing the modem as none of the supported Zephyr boards uses it. There's no reason to run the cellular modem sample with it since it doesn't have a modem, so the chance of confusing someone is low. Is there a better way to do this? Or should i just remove it from the sample? I don't mind either way it was mostly just to facilitate my testing.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The problem is that someone might be using the nRF52840 DK as the host MCU just as you are doing, but with another modem.
Maybe a solution would be to move and rename this overlay so that it's just for this particular modem and you can include it manually in your build.
Don't know what the others think of this.

Copy link
Contributor

Choose a reason for hiding this comment

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

@tomi-font Personally, I feel boards that don't have a modem on them shouldn't be included here at all. Perhaps instead we could include documentation on how to write a DTS for this sample instead.

Comment on lines +8 to +10
config SAMPLE_CELLULAR_MODEM_ENDPOINT_HOSTNAME
string "Endpoint hostname"
default "test-endpoint.com"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice! @bjarki-andreasen something really should be done with regards to test-endpoint.com... cc @kartben

Copy link
Contributor Author

@olalonde olalonde May 23, 2025

Choose a reason for hiding this comment

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

As a side note, in my own project, I recently added this to my CMakeLists.txt to avoid committing secrets to git:

if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/local.conf)
    file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/local.conf 
"# This file is not version controlled, you can use it for local only configuration")
endif()

set(EXTRA_CONF_FILE 
    ${CMAKE_CURRENT_SOURCE_DIR}/local.conf
)

And I also added local.conf to .gitignore.

It would be useful here to allow developers to set a private CONFIG_SAMPLE_CELLULAR_MODEM_ENDPOINT_HOSTNAME without having to edit a version controlled file. And for other configurations (e.g. logging) that are useful for testing but that you don't necessarily want to commit to git.

@@ -0,0 +1,27 @@
/ {
Copy link
Collaborator

Choose a reason for hiding this comment

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

The problem is that someone might be using the nRF52840 DK as the host MCU just as you are doing, but with another modem.
Maybe a solution would be to move and rename this overlay so that it's just for this particular modem and you can include it manually in your build.
Don't know what the others think of this.

@@ -0,0 +1,3 @@
# Otherwise we run into DLCI buffer overruns (maybe due to lack of UART hardware flow control?)
CONFIG_MODEM_CMUX_WORK_BUFFER_SIZE=1507
CONFIG_NET_IPV6=n
Copy link
Collaborator

Choose a reason for hiding this comment

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

Explanation for this? (as a comment)

@@ -1,5 +1,6 @@
# Copyright (c) 2023 Bjarki Arge Andreasen
# SPDX-License-Identifier: Apache-2.0
CONFIG_SAMPLE_CELLULAR_MODEM_ENDPOINT_HOSTNAME=""
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm?

Copy link
Contributor

Choose a reason for hiding this comment

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

@olalonde I guess you include the hostname by passing an environment variable (in CMake or when building with west), but there is no reason not to have a default here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there a default that works? I just thought it would make it more obvious that this option needs to be set.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Then in that case maybe you would change the default of the Kconfig option where it's defined, I think it would make more sense.
But it's true that given test-endpoint.com is no longer functional it might be better to completely remove it.

Comment on lines +2115 to +2176

MODEM_CHAT_SCRIPT_CMDS_DEFINE(simcom_a76xx_shutdown_chat_script_cmds,
MODEM_CHAT_SCRIPT_CMD_RESP("AT+CPOF", ok_match));

MODEM_CHAT_SCRIPT_DEFINE(simcom_a76xx_shutdown_chat_script,
simcom_a76xx_shutdown_chat_script_cmds, abort_matches,
modem_cellular_chat_callback_handler, 15);

Copy link
Collaborator

Choose a reason for hiding this comment

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

Not that important but this commit could be squashed into the first one.

Comment on lines 2079 to 2085
#ifdef CONFIG_MODEM_CELLULAR_POWER_ON_GNSS
/* Power on the GNSS module.
* We need to do this early, otherwise it does not work when
* doing it later (e.g. from a user pipe).
*/
MODEM_CHAT_SCRIPT_CMD_RESP_MULT("AT+CGNSSPWR=1", allow_match),
#endif
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
#ifdef CONFIG_MODEM_CELLULAR_POWER_ON_GNSS
/* Power on the GNSS module.
* We need to do this early, otherwise it does not work when
* doing it later (e.g. from a user pipe).
*/
MODEM_CHAT_SCRIPT_CMD_RESP_MULT("AT+CGNSSPWR=1", allow_match),
#endif
#ifdef CONFIG_MODEM_CELLULAR_POWER_ON_GNSS
/* Power on the GNSS module.
* We need to do this early, otherwise it does not work when
* doing it later (e.g. from a user pipe).
*/
MODEM_CHAT_SCRIPT_CMD_RESP_MULT("AT+CGNSSPWR=1", allow_match),
#endif

Copy link
Collaborator

@bjarki-andreasen bjarki-andreasen left a comment

Choose a reason for hiding this comment

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

The board overlay for the cellular sample must be removed. In zephyr, we have the option of boards and shields for common portable build targets. overlays specific to a local setup is not allowed upstream (outside of common vendor specific fixtures)

Comment on lines 66 to 68
config MODEM_CELLULAR_POWER_ON_GNSS
bool "Power on the modem's GNSS module"
depends on DT_HAS_SIMCOM_A76XX_ENABLED
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please remove this config, the modem_cellular.c driver is an MVP for cellular networking, its not meant for power optimization of GNSS. Just enable it unconditionally. For finer control, introduce a device driver specific driver.

MODEM_CHAT_SCRIPT_CMDS_DEFINE(simcom_a76xx_periodic_chat_script_cmds,
MODEM_CHAT_SCRIPT_CMD_RESP("AT+CREG?", ok_match),
MODEM_CHAT_SCRIPT_CMD_RESP("AT+CEREG?", ok_match),
MODEM_CHAT_SCRIPT_CMD_RESP("AT+CGREG?", ok_match));
Copy link
Contributor

Choose a reason for hiding this comment

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

The AT+CREG? command is used to query circuit-switched network (2G/3G) registration status. The AT+CGREG? command is used to query GPRS (2G) registration status, and the AT+CEREG? is used to query EPS registration status (LTE, essentially). Not all A76XX series modems support all of these technologies, so it is not unexpected to receive a +CGREG: 0,0 or +CREG: 0,0 while you are connected to an LTE network.
The way the current state machine works is it will start some mechanism to recover from a loss of registration. I suspect running these commands in an LTE-only module is going to potentially introduce issues. In general, this area needs to be improved because for multi-RAT modems the logic is finicky at best.

@@ -616,6 +618,8 @@ static int modem_cellular_on_idle_state_enter(struct modem_cellular_data *data)
}

modem_cellular_notify_user_pipes_disconnected(data);
net_if_carrier_off(modem_ppp_get_iface(data->ppp));
net_if_dormant_off(modem_ppp_get_iface(data->ppp));
Copy link
Contributor

Choose a reason for hiding this comment

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

The net_if_dormant_off() should do nothing, because we never call net_if_dormant_on(...). While net_if_carrier_off(...) should be called when leaving CARRIER_ON_STATE in modem_cellular_carrier_on_state_leave(...). Basically, in the same state it was previously turned on.
Could you maybe turn on CONFIG_MODEM_LOG_LEVEL_DBG=y as it will allow us to track these state changes.
Seems that notify_iface_up(...) in net_if.c is never called. Could you please enable CONFIG_NET_IF_LOG_LEVEL_DBG=y so we understand the cause why? Because we should be calling carrier_on.

Copy link
Contributor

Choose a reason for hiding this comment

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

We covered this here #90084

@@ -0,0 +1,27 @@
/ {
Copy link
Contributor

Choose a reason for hiding this comment

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

@tomi-font Personally, I feel boards that don't have a modem on them shouldn't be included here at all. Perhaps instead we could include documentation on how to write a DTS for this sample instead.

@@ -1,5 +1,6 @@
# Copyright (c) 2023 Bjarki Arge Andreasen
# SPDX-License-Identifier: Apache-2.0
CONFIG_SAMPLE_CELLULAR_MODEM_ENDPOINT_HOSTNAME=""
Copy link
Contributor

Choose a reason for hiding this comment

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

@olalonde I guess you include the hostname by passing an environment variable (in CMake or when building with west), but there is no reason not to have a default here.

@olalonde olalonde force-pushed the simcom-a76xx branch 2 times, most recently from 6f7d1e4 to 442d575 Compare May 28, 2025 02:01
@olalonde
Copy link
Contributor Author

@bjarki-andreasen I think I addressed all the issues.

Add support for the simcom a76xx modem which is similar to the simcom 7080
but has a few key differences. Tested with a simcom A7672SA module but as
there is a single simcom A76XX AT commands manual, the driver should work
with other modems of the series.

Signed-off-by: Olivier Lalonde <[email protected]>
Copy link


config SAMPLE_CELLULAR_MODEM_ENDPOINT_HOSTNAME
string "Endpoint hostname"
default "test-endpoint.com"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually I think it makes sense to stop pretending test-endpoint.com should be functional:

Suggested change
default "test-endpoint.com"

Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree, it's really not ideal.
The sample/instructions should be updated to not depend it anymore, or the doc should be updated to indicate how one may host their own server (with the caveat that users might struggle to make their endpoint publicly accessible)

IMO the sample should be a really minimal showcase of printing modem-info, showing that we can ping 8.8.8.8 or whatever, and that's it. Things like testing throughput etc. are really something that's left for a test IMO, and probably don't belong to the sample.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, I agree as well :) With the state of the modem subsystem and drivers, we should be looking to networking samples to test networking, the cellular part really should not make a difference :)

Copy link
Collaborator

@bjarki-andreasen bjarki-andreasen 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!

Copy link
Member

@rerickson1 rerickson1 left a comment

Choose a reason for hiding this comment

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

Looks good. I think it would be better to split this into at least two commits. One for driver changes, and the other for the sample changes.

@kartben kartben merged commit afc481a into zephyrproject-rtos:main May 28, 2025
26 checks passed
Copy link

Hi @olalonde!
Congratulations on getting your very first Zephyr pull request merged 🎉🥳. This is a fantastic achievement, and we're thrilled to have you as part of our community!

To celebrate this milestone and showcase your contribution, we'd love to award you the Zephyr Technical Contributor badge. If you're interested, please claim your badge by filling out this form: Claim Your Zephyr Badge.

Thank you for your valuable input, and we look forward to seeing more of your contributions in the future! 🪁

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

Successfully merging this pull request may close these issues.

8 participants