From 145454356b2b14cb1a86ce1df9abcf4477fd974e Mon Sep 17 00:00:00 2001 From: songruojing Date: Fri, 1 Jul 2022 15:43:04 +0800 Subject: [PATCH] gpio: Fix ESP32S3 GPIO48 does not support hold function bug GPIO_HOLD_MASK array was missing the last item Add __Static_assert to check array sizes for all gpio_periph.c files to prevent same mistake in the future. --- components/soc/esp32/gpio_periph.c | 26 +++++++++++--------------- components/soc/esp32c2/gpio_periph.c | 8 ++++++-- components/soc/esp32c3/gpio_periph.c | 26 +++++++++++--------------- components/soc/esp32h2/gpio_periph.c | 8 ++++++-- components/soc/esp32s2/gpio_periph.c | 8 ++++++-- components/soc/esp32s3/gpio_periph.c | 27 ++++++++++++--------------- tools/ci/check_copyright_ignore.txt | 3 --- 7 files changed, 52 insertions(+), 54 deletions(-) diff --git a/components/soc/esp32/gpio_periph.c b/components/soc/esp32/gpio_periph.c index d993cb42ac..97b1cefad4 100644 --- a/components/soc/esp32/gpio_periph.c +++ b/components/soc/esp32/gpio_periph.c @@ -1,20 +1,12 @@ -// Copyright 2018 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2018-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #include "soc/gpio_periph.h" -const uint32_t GPIO_PIN_MUX_REG[SOC_GPIO_PIN_COUNT] = { +const uint32_t GPIO_PIN_MUX_REG[] = { IO_MUX_GPIO0_REG, IO_MUX_GPIO1_REG, IO_MUX_GPIO2_REG, @@ -57,7 +49,9 @@ const uint32_t GPIO_PIN_MUX_REG[SOC_GPIO_PIN_COUNT] = { IO_MUX_GPIO39_REG, }; -const uint32_t GPIO_HOLD_MASK[SOC_GPIO_PIN_COUNT] = { +_Static_assert(sizeof(GPIO_PIN_MUX_REG) == SOC_GPIO_PIN_COUNT * sizeof(uint32_t), "Invalid size of GPIO_PIN_MUX_REG"); + +const uint32_t GPIO_HOLD_MASK[] = { 0, BIT(1), 0, @@ -99,3 +93,5 @@ const uint32_t GPIO_HOLD_MASK[SOC_GPIO_PIN_COUNT] = { 0, 0, }; + +_Static_assert(sizeof(GPIO_HOLD_MASK) == SOC_GPIO_PIN_COUNT * sizeof(uint32_t), "Invalid size of GPIO_HOLD_MASK"); diff --git a/components/soc/esp32c2/gpio_periph.c b/components/soc/esp32c2/gpio_periph.c index 3bb5104fa6..00e258d087 100644 --- a/components/soc/esp32c2/gpio_periph.c +++ b/components/soc/esp32c2/gpio_periph.c @@ -6,7 +6,7 @@ #include "soc/gpio_periph.h" -const uint32_t GPIO_PIN_MUX_REG[SOC_GPIO_PIN_COUNT] = { +const uint32_t GPIO_PIN_MUX_REG[] = { IO_MUX_GPIO0_REG, IO_MUX_GPIO1_REG, IO_MUX_GPIO2_REG, @@ -30,7 +30,9 @@ const uint32_t GPIO_PIN_MUX_REG[SOC_GPIO_PIN_COUNT] = { IO_MUX_GPIO20_REG, }; -const uint32_t GPIO_HOLD_MASK[SOC_GPIO_PIN_COUNT] = { +_Static_assert(sizeof(GPIO_PIN_MUX_REG) == SOC_GPIO_PIN_COUNT * sizeof(uint32_t), "Invalid size of GPIO_PIN_MUX_REG"); + +const uint32_t GPIO_HOLD_MASK[] = { BIT(0), //GPIO0 BIT(1), //GPIO1 BIT(2), //GPIO2 @@ -53,3 +55,5 @@ const uint32_t GPIO_HOLD_MASK[SOC_GPIO_PIN_COUNT] = { BIT(19), //GPIO19 BIT(20), //GPIO20 }; + +_Static_assert(sizeof(GPIO_HOLD_MASK) == SOC_GPIO_PIN_COUNT * sizeof(uint32_t), "Invalid size of GPIO_HOLD_MASK"); diff --git a/components/soc/esp32c3/gpio_periph.c b/components/soc/esp32c3/gpio_periph.c index 1bdf359819..29ae01e229 100644 --- a/components/soc/esp32c3/gpio_periph.c +++ b/components/soc/esp32c3/gpio_periph.c @@ -1,20 +1,12 @@ -// Copyright 2020 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #include "soc/gpio_periph.h" -const uint32_t GPIO_PIN_MUX_REG[SOC_GPIO_PIN_COUNT] = { +const uint32_t GPIO_PIN_MUX_REG[] = { IO_MUX_GPIO0_REG, IO_MUX_GPIO1_REG, IO_MUX_GPIO2_REG, @@ -39,7 +31,9 @@ const uint32_t GPIO_PIN_MUX_REG[SOC_GPIO_PIN_COUNT] = { IO_MUX_GPIO21_REG, }; -const uint32_t GPIO_HOLD_MASK[SOC_GPIO_PIN_COUNT] = { +_Static_assert(sizeof(GPIO_PIN_MUX_REG) == SOC_GPIO_PIN_COUNT * sizeof(uint32_t), "Invalid size of GPIO_PIN_MUX_REG"); + +const uint32_t GPIO_HOLD_MASK[] = { BIT(0), //GPIO0 BIT(1), //GPIO1 BIT(2), //GPIO2 @@ -63,3 +57,5 @@ const uint32_t GPIO_HOLD_MASK[SOC_GPIO_PIN_COUNT] = { BIT(20), //GPIO20 BIT(21), //GPIO21 }; + +_Static_assert(sizeof(GPIO_HOLD_MASK) == SOC_GPIO_PIN_COUNT * sizeof(uint32_t), "Invalid size of GPIO_HOLD_MASK"); diff --git a/components/soc/esp32h2/gpio_periph.c b/components/soc/esp32h2/gpio_periph.c index 02df23128c..f1807dd6e7 100644 --- a/components/soc/esp32h2/gpio_periph.c +++ b/components/soc/esp32h2/gpio_periph.c @@ -6,7 +6,7 @@ #include "soc/gpio_periph.h" -const uint32_t GPIO_PIN_MUX_REG[SOC_GPIO_PIN_COUNT] = { +const uint32_t GPIO_PIN_MUX_REG[] = { IO_MUX_GPIO0_REG, IO_MUX_GPIO1_REG, IO_MUX_GPIO2_REG, @@ -52,7 +52,9 @@ const uint32_t GPIO_PIN_MUX_REG[SOC_GPIO_PIN_COUNT] = { #endif }; -const uint32_t GPIO_HOLD_MASK[SOC_GPIO_PIN_COUNT] = { +_Static_assert(sizeof(GPIO_PIN_MUX_REG) == SOC_GPIO_PIN_COUNT * sizeof(uint32_t), "Invalid size of GPIO_PIN_MUX_REG"); + +const uint32_t GPIO_HOLD_MASK[] = { #if CONFIG_IDF_TARGET_ESP32H2_BETA_VERSION_1 BIT(0), //GPIO0 BIT(1), //GPIO1 @@ -124,3 +126,5 @@ const uint32_t GPIO_HOLD_MASK[SOC_GPIO_PIN_COUNT] = { BIT(25), //GPIO25 #endif }; + +_Static_assert(sizeof(GPIO_HOLD_MASK) == SOC_GPIO_PIN_COUNT * sizeof(uint32_t), "Invalid size of GPIO_HOLD_MASK"); diff --git a/components/soc/esp32s2/gpio_periph.c b/components/soc/esp32s2/gpio_periph.c index 08e9e58258..25a453915a 100644 --- a/components/soc/esp32s2/gpio_periph.c +++ b/components/soc/esp32s2/gpio_periph.c @@ -6,7 +6,7 @@ #include "soc/gpio_periph.h" -const uint32_t GPIO_PIN_MUX_REG[SOC_GPIO_PIN_COUNT] = { +const uint32_t GPIO_PIN_MUX_REG[] = { IO_MUX_GPIO0_REG, IO_MUX_GPIO1_REG, IO_MUX_GPIO2_REG, @@ -56,7 +56,9 @@ const uint32_t GPIO_PIN_MUX_REG[SOC_GPIO_PIN_COUNT] = { IO_MUX_GPIO46_REG, }; -const uint32_t GPIO_HOLD_MASK[SOC_GPIO_PIN_COUNT] = { +_Static_assert(sizeof(GPIO_PIN_MUX_REG) == SOC_GPIO_PIN_COUNT * sizeof(uint32_t), "Invalid size of GPIO_PIN_MUX_REG"); + +const uint32_t GPIO_HOLD_MASK[] = { 0, 0, 0, @@ -105,3 +107,5 @@ const uint32_t GPIO_HOLD_MASK[SOC_GPIO_PIN_COUNT] = { BIT(24), BIT(25), }; + +_Static_assert(sizeof(GPIO_HOLD_MASK) == SOC_GPIO_PIN_COUNT * sizeof(uint32_t), "Invalid size of GPIO_HOLD_MASK"); diff --git a/components/soc/esp32s3/gpio_periph.c b/components/soc/esp32s3/gpio_periph.c index 143f02f1fb..770e50cea8 100644 --- a/components/soc/esp32s3/gpio_periph.c +++ b/components/soc/esp32s3/gpio_periph.c @@ -1,20 +1,12 @@ -// Copyright 2018 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2018-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #include "soc/gpio_periph.h" -const uint32_t GPIO_PIN_MUX_REG[SOC_GPIO_PIN_COUNT] = { +const uint32_t GPIO_PIN_MUX_REG[] = { IO_MUX_GPIO0_REG, IO_MUX_GPIO1_REG, IO_MUX_GPIO2_REG, @@ -66,7 +58,9 @@ const uint32_t GPIO_PIN_MUX_REG[SOC_GPIO_PIN_COUNT] = { IO_MUX_GPIO48_REG, }; -const uint32_t GPIO_HOLD_MASK[SOC_GPIO_PIN_COUNT] = { +_Static_assert(sizeof(GPIO_PIN_MUX_REG) == SOC_GPIO_PIN_COUNT * sizeof(uint32_t), "Invalid size of GPIO_PIN_MUX_REG"); + +const uint32_t GPIO_HOLD_MASK[] = { 0, 0, 0, @@ -115,4 +109,7 @@ const uint32_t GPIO_HOLD_MASK[SOC_GPIO_PIN_COUNT] = { BIT(24), BIT(25), BIT(26), + BIT(27), }; + +_Static_assert(sizeof(GPIO_HOLD_MASK) == SOC_GPIO_PIN_COUNT * sizeof(uint32_t), "Invalid size of GPIO_HOLD_MASK"); diff --git a/tools/ci/check_copyright_ignore.txt b/tools/ci/check_copyright_ignore.txt index 9146cf7efb..3205187f9e 100644 --- a/tools/ci/check_copyright_ignore.txt +++ b/tools/ci/check_copyright_ignore.txt @@ -1006,7 +1006,6 @@ components/sdmmc/sdmmc_mmc.c components/sdmmc/sdmmc_sd.c components/soc/esp32/adc_periph.c components/soc/esp32/dac_periph.c -components/soc/esp32/gpio_periph.c components/soc/esp32/i2c_periph.c components/soc/esp32/include/soc/apb_ctrl_reg.h components/soc/esp32/include/soc/apb_ctrl_struct.h @@ -1075,7 +1074,6 @@ components/soc/esp32/sigmadelta_periph.c components/soc/esp32/spi_periph.c components/soc/esp32/touch_sensor_periph.c components/soc/esp32/uart_periph.c -components/soc/esp32c3/gpio_periph.c components/soc/esp32c3/i2c_bbpll.h components/soc/esp32c3/i2c_periph.c components/soc/esp32c3/include/soc/apb_ctrl_reg.h @@ -1251,7 +1249,6 @@ components/soc/esp32s2/touch_sensor_periph.c components/soc/esp32s2/uart_periph.c components/soc/esp32s2/usb_periph.c components/soc/esp32s3/dedic_gpio_periph.c -components/soc/esp32s3/gpio_periph.c components/soc/esp32s3/i2c_periph.c components/soc/esp32s3/include/soc/apb_ctrl_reg.h components/soc/esp32s3/include/soc/apb_ctrl_struct.h