adc: adc_read() not check for error (#1575) v2 #1599
No reviewers
Labels
No labels
bazel
bluetooth
board settings
boot_stage2
bug
build
c++
can't reproduce
clang
clib-interface
cmsis
code cleanliness
code size
compiler version issues
cyw43_driver
debug
discussion
documentation
duplicate
dynamic_clock
elf2uf2
enhancement
errata
filesystem
flash layout
floating point
FreeRTOS
hardware_adc
hardware_claim
hardware_clocks
hardware_dma
hardware_exception
hardware_flash
hardware_gpio
hardware_i2c
hardware_irq
hardware_pio
hardware_pwm
hardware_rcp
hardware_rtc
hardware_spi
hardware_sync
hardware_uart
hardware_vreg
hardware_watchdog
hardware_xosc
help wanted
host
IAR
installation
invalid
linker scripts
lto
lwip
mbedtls
missing API
needs reporter detail
networking
newlib
newlib-multicore
non-c
non-cmake
non-gcc
openocd
orphan PR
OS integration
pico_async_context
pico_base
pico_binary_info
pico_flash
picolibc
pico_lwip
pico_malloc
pico_multicore
pico_printf
pico_runtime
pico_stdio
pico_stdio_usb
pico_sync
pico_time
pico_util
pioasm
port
question
review
review2
rtos interop
runtime init
static library
svd
test
tinyusb
vscode
wifi integration
wontfix
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-raspberrypi/pico-sdk!1599
Loading…
Reference in a new issue
No description provided.
Delete branch "ruehlchris/develop"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Implementation of adc_read() not check for errors in the ADC_CS register.
v2:
@ -140,0 +144,4 @@return -ADC_CS_ERR_BITS;}/* clear sticky bit */hw_set_bits(&adc_hw->cs, ADC_CS_ERR_STICKY_BITS);Might be better to use ADC_RESULT_BITS
@ -140,2 +147,4 @@hw_set_bits(&adc_hw->cs, ADC_CS_ERR_STICKY_BITS);return -ADC_CS_ERR_STICKY_BITS;}It's a bit random to return -ADC_CS_ERR_BITS. It would be better to return a "standard" error code? Maybe PICO_ERROR_GENERIC or PICO_ERROR_NO_DATA?
same comment as above
@ -140,0 +144,4 @@return -ADC_CS_ERR_BITS;}/* clear sticky bit */hw_set_bits(&adc_hw->cs, ADC_CS_ERR_STICKY_BITS);I will have a look if that will have benefit. The original code check for the ADC_CS_READY_BITS.
@ -140,2 +147,4 @@hw_set_bits(&adc_hw->cs, ADC_CS_ERR_STICKY_BITS);return -ADC_CS_ERR_STICKY_BITS;}I see your point, but if we doing this we can't distinguished what caused the error.
Use
PICO_ERROR_NO_DATA
and additional, define a new code:
PICO_ERROR_ADC_STICKY_BIT
@ -140,0 +144,4 @@return -ADC_CS_ERR_BITS;}/* clear sticky bit */hw_set_bits(&adc_hw->cs, ADC_CS_ERR_STICKY_BITS);I believe Peter meant use
ADC_RESULT_BITSinstead of0xfff- see https://github.com/raspberrypi/pico-sdk/blob/master/src/rp2040/hardware_regs/include/hardware/regs/adc.h#L111@ -140,0 +144,4 @@return -ADC_CS_ERR_BITS;}/* clear sticky bit */hw_set_bits(&adc_hw->cs, ADC_CS_ERR_STICKY_BITS);Oh, :)
Thanks for the eye opener.
Looks good but see previous comments concerning minor changes
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.