-
Notifications
You must be signed in to change notification settings - Fork 1.4k
boards/arm/rp2040: Fix code style and error checking #16869
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
base: master
Are you sure you want to change the base?
Conversation
This patch tries to follow the coding style of NuttX and avoids nesting functions, handling the error return. Signed-off-by: Alan C. Assis <[email protected]>
|
@nmaggioni please test if you temperature sensor still working. I just tested compiling it! |
cederom
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @acassis :-)
- I had to switch
pico-sdkfrom2.2.0to2.1.0as the latest one seems to have changed headers and does not build :D - No build errors, but I have no sensor to test on real hardware sorry.
% uname -a
FreeBSD hexagon 14.2-RELEASE-p1 FreeBSD 14.2-RELEASE-p1 GENERIC amd64
% pwd
/XXX/embedded/rpi/pico-sdk.git
% git branch
* (HEAD detached at 2.1.0)
% ./tools/configure.sh -B raspberrypi-pico:tmp112
(..)
% /usr/bin/time -h gmake -j24
Create version.h
LN: platform/board to /XXX/nuttx-apps.git/platform/dummy
Register: dd
Register: nsh
Register: sh
Register: hello
Register: getprime
Register: ostest
/usr/local/gcc-arm-embedded-14.2.rel1/bin/../lib/gcc/arm-none-eabi/14.2.1/../../../../arm-none-eabi/bin/ld: warning: rp2040_boot_stage2.elf has a LOAD segment with RWX permissions
CPP: /XXX/nuttx.git/boards/arm/rp2040/raspberrypi-pico/scripts/raspberrypi-pico-flash.ld-> /XXXLD: nuttx
Memory region Used Size Region Size %age Used
flash: 160 KB 2 MB 7.81%
sram: 8884 B 264 KB 3.29%
Generating: nuttx.uf2
Done.
6,81s real 30,48s user 14,54s sys
% picotool load nuttx.uf2
Loading into Flash: [==============================] 100%
% picotool reboot
The device was rebooted into application mode.
% cu -l /dev/cuaU0 -s 115200
Connected
NuttShell (NSH) NuttX-10.4.0
nsh>
nsh> uname -a
NuttX 10.4.0 2e07dc5956 Aug 20 2025 01:50:52 arm raspberrypi-pico
nsh> ls /dev
/dev:
console
null
temp0
ttyACM0
zero
|
CI build error :-( |
| else | ||
| { | ||
| syslog(LOG_ERR, "Failed to register MCP3008 device driver: %d\n", ret); | ||
| struct adc_dev_s *mcp3008 = mcp3008_initialize(spi); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd honestly fully remove the MCP3008 stuff
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this actually may be a good idea to remove external ic specific code from common rp2040 initialization code.. users may want to add it to their application :-)
|
There are errors in job Linux (arm-06) https://github.com/apache/nuttx/actions/runs/17084057983/job/48447096636#logs` |
|
Im on it, thanks! :-) Looking at https://github.com/raspberrypi/pico-sdk/releases/tag/2.2.0 there is only one mention of breaking change for |
In their defense, I suppose not using the SDK in its entirety is outside their scope - even if they should care about that IMO. Anyway, my bad for having trusted their changelog and not having retested everything on a clean slate :) |
|
|
||
| ret = mcp9600_register(rp2040_i2cbus_initialize(0), 0x60, 1, 2, 3); | ||
| if (ret < 0) | ||
| i2c = rp2040_i2cbus_initialize(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if CONFIG_SENSORS_SHT4X and i2c is already initialized?
| ret = ms56xx_register(rp2040_i2cbus_initialize(0), 0, MS56XX_ADDR0, | ||
| MS56XX_MODEL_MS5611); | ||
| if (ret < 0) | ||
| i2c = rp2040_i2cbus_initialize(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto, what happens if CONFIG_SENSORS_SHT4X and/or CONFIG_SENSORS_MCP9600 and i2c is already initialized?
| ret = board_tmp112_initialize(rp2040_i2cbus_initialize(0), 0, | ||
| TMP112_ADDR_1); | ||
| if (ret < 0) | ||
| i2c = rp2040_i2cbus_initialize(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto, CONFIG_SENSORS_SHT4X and/or CONFIG_SENSORS_MCP9600 and/or CONFIG_SENSORS_MS56XX already initialized i2c?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For all of these, it doesn't matter. The rp2040_i2cbus_initialize() function (and all xxxx_i2cbus_initialize() functions first check if the bus has already been initialized. If it has, it just returns the initialized i2cdev struct without re-performing the init.
|
As #16876 is merged lets see how this CI builds now :-) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend a different git log message. (The current one makes it seem like the change is nxstyle fixes, but the actual change is error handling in board bringup.)
Something like:
boards/arm/rp2040: Improve error handling in board bringup
rp2040_common_bringup: In case of failure to initialize SPI and/or I2C
buses, do not try to initialize devices that depend on these buses:
MCP3008 (SPI), RP2040, SHT4X, MCP9600, MS56XX (I2C).
(Edit: Wrap the proposed log message at 72 columns.)
|
please fix the conflict @acassis |
|
@acassis any updates on this PR? It can get merged once the conflict is fixed and I think it would be good. |
Hi, Please see my comment above regarding the commit log. I think a better log message is (copying from my earlier comment): Thanks! |
Summary
This patch tries to follow the coding style of NuttX and avoids nesting functions, handling the error return.
Impact
Improvement
Testing
build only