File tree Expand file tree Collapse file tree 1 file changed +7
-5
lines changed
ports/nrf/common-hal/analogio Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change @@ -76,7 +76,13 @@ uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) {
76
76
// Something else might have used the ADC in a different way,
77
77
// so we completely re-initialize it.
78
78
79
- nrf_saadc_value_t value = -1 ;
79
+ // Adding the "asm volatile" memory fence here or many places after this declaration
80
+ // fixes an issue with gcc13 which causes `value` to always be zero.
81
+ // Compiling with gcc10 or gcc12 is fine.
82
+ // It can also be fixed by declaring `value` to be static.
83
+ // I think I'd like to declare this as volatile, but that causes type errors.
84
+ nrf_saadc_value_t value = 0 ;
85
+ asm volatile ("" : : : "memory" );
80
86
81
87
const nrf_saadc_channel_config_t config = {
82
88
.resistor_p = NRF_SAADC_RESISTOR_DISABLED ,
@@ -120,10 +126,6 @@ uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) {
120
126
121
127
nrf_saadc_disable (NRF_SAADC );
122
128
123
- if (value < 0 ) {
124
- value = 0 ;
125
- }
126
-
127
129
// Stretch 14-bit ADC reading to 16-bit range
128
130
return (value << 2 ) | (value >> 12 );
129
131
}
You can’t perform that action at this time.
0 commit comments