]> granicus.if.org Git - esp-idf/commitdiff
gpio: Bitmask overflow fix in gpio_reset_pin
authorTaavi Hein <taavi.hein@hedgehog.ee>
Wed, 8 Aug 2018 12:31:17 +0000 (15:31 +0300)
committerIvan Grokhotkov <ivan@espressif.com>
Tue, 14 Aug 2018 01:23:56 +0000 (04:23 +0300)
For pins 32 and up the BIT(nr) macro used here overflowed,
causing undetermined GPIO pins to be reset.
Example: freeing SPI device/bus where CS is on pin 33
caused debug UART to cease communication, TXD0 was
disabled.

Fixed as BIT64(nr) macro, to be used elsewhere as needed.
For example in definitions like GPIO_SEL_32..GPIO_SEL_39.

components/driver/gpio.c
components/soc/esp32/include/soc/soc.h

index 07bf6988539d76c07f85d8ba087ef96e2a7faa08..d81d2c25c316e0c8933c40ed67d707b112e500ae 100644 (file)
@@ -316,7 +316,7 @@ esp_err_t gpio_reset_pin(gpio_num_t gpio_num)
 {
     assert(gpio_num >= 0 && GPIO_IS_VALID_GPIO(gpio_num));
     gpio_config_t cfg = {
-        .pin_bit_mask = BIT(gpio_num),
+        .pin_bit_mask = BIT64(gpio_num),
         .mode = GPIO_MODE_DISABLE,
         //for powersave reasons, the GPIO should not be floating, select pullup
         .pull_up_en = true,
index 660abbdb3fc6c1191b01039b0b094c9111f46c28..bc822e236421e54d46ed792acea0a3492e6740a0 100644 (file)
 
 #ifndef __ASSEMBLER__
 #define BIT(nr)                 (1UL << (nr))
+#define BIT64(nr)               (1ULL << (nr))
 #else
 #define BIT(nr)                 (1 << (nr))
 #endif