Skip to content
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

return const struct device * for device_get_binding(const char *name) #43573

Closed
zzzh opened this issue Mar 9, 2022 · 2 comments
Closed

return const struct device * for device_get_binding(const char *name) #43573

zzzh opened this issue Mar 9, 2022 · 2 comments
Labels
bug The issue is a bug, or the PR is fixing a bug

Comments

@zzzh
Copy link

zzzh commented Mar 9, 2022

Describe the bug
the definition is now "__syscall const struct device *device_get_binding(const char *name);",
which bring many compile warnings as below, and at last, program can't link

warning: initialization discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
37 | struct device *i2c_dev = device_get_binding(DT_LABEL(I2C2_NODE));

it used to be "__syscall struct device *device_get_binding(const char *name);" and work well in zephyr-2.3

Please also mention any information which could help others to understand
the problem you're facing:

  • What target platform are you using? STM32F030
  • What have you tried to diagnose or workaround this issue? compare with before building
  • ...

To Reproduce
Steps to reproduce the behavior:
west build

Expected behavior
A clear and concise description of what you expected to happen.
pass the building

Impact
What impact does this issue have on your progress (e.g., annoyance, showstopper)
Can't continue

Logs and console output
If applicable, add console logs or other types of debug information
e.g Wireshark capture or Logic analyzer capture (upload in zip archive).
copy-and-paste text and put a code fence (```) before and after, to help
explain the issue. (if unable to obtain text log, add a screenshot)

warning: initialization discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
37 | struct device *i2c_dev = device_get_binding(DT_LABEL(I2C2_NODE));

Environment (please complete the following information):

  • OS: (e.g. Linux, MacOS, Windows) Linux
  • Toolchain (e.g Zephyr SDK, ...) Zephyr SDK
  • Commit SHA or Version used zephyr-3.99

Additional context
Add any other context that could be relevant to your issue, such as pin setting,
target configuration, ...

@zzzh zzzh added the bug The issue is a bug, or the PR is fixing a bug label Mar 9, 2022
@gmarull
Copy link
Member

gmarull commented Mar 9, 2022

This is not a bug, you need to use const struct device *dev = device_get_binding(...); now (devices were constified a few releases ago). You can also make use of i2c_dt_spec facilities for I2C devices in particular, as well as take a look at DEVICE_DT_GET(). You'll find many in-tree examples.

@gmarull gmarull closed this as completed Mar 9, 2022
@zzzh
Copy link
Author

zzzh commented Mar 10, 2022

I see, Thanks for the help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The issue is a bug, or the PR is fixing a bug
Projects
None yet
Development

No branches or pull requests

2 participants