1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
Commit Graph

188 Commits

Author SHA1 Message Date
Marian Buschsieweke
36e8526046
drivers/periph_gpio_ll: change API to access GPIO ports
The API was based on the assumption that GPIO ports are mapped in memory
sanely, so that a `GPIO_PORT(num)` macro would work allow for constant
folding when `num` is known and still be efficient when it is not.

Some MCUs, however, will need a look up tables to efficiently translate
GPIO port numbers to the port's base address. This will prevent the use
of such a `GPIO_PORT(num)` macro in constant initializers.

As a result, we rather provide `GPIO_PORT_0`, `GPIO_PORT_1`, etc. macros
for each GPIO port present (regardless of MCU naming scheme), as well as
`GPIO_PORT_A`, `GPIO_PORT_B`, etc. macros if (and only if) the MCU port
naming scheme uses letters rather than numbers.

These can be defined as macros to the peripheral base address even when
those are randomly mapped into the address space. In addition, a C
function `gpio_port()` replaces the role of the `GPIO_PORT()` and
`gpio_port_num()` the `GPIO_PORT_NUM()` macro. Those functions will
still be implemented as efficient as possible and will allow constant
folding where it was formerly possible. Hence, there is no downside for
MCUs with sane peripheral memory mapping, but it is highly beneficial
for the crazy ones.

There are also two benefits for the non-crazy MCUs:
1. We can now test for valid port numbers with `#ifdef GPIO_PORT_<NUM>`
    - This directly benefits the test in `tests/periph/gpio_ll`, which
      can now provide a valid GPIO port for each and every board
    - Writing to invalid memory mapped I/O addresses was treated as
      triggering undefined behavior by the compiler and used as a
      optimization opportunity
2. We can now detect at compile time if the naming scheme of the MCU
   uses letters or numbers, and produce more user friendly output.
    - This is directly applied in the test app
2024-08-02 09:55:24 +02:00
Marian Buschsieweke
dd585f9e9d
cpu/esp32/gpio_ll: fix & cleanup
- `gpio_ll_toggle()` now is race-free
- avoid using a look up table but branch to the two different registers
  in the `gpio_ll*()` functions
    - in most cases the GPIO port is a compile time constant and the
      dead branch is eliminated by the optimizer, making this vastly
      more efficient
    - some MCUs do only have a single port, in which case
      `GPIO_PORT_NUM(port)` is known to return `0` even if `port` is
      not known, resulting in one of the branch being eliminated as
      dead branch no matter what
    - in case it really is unknown at compile time which port to work
      on, the branch can still be implemented efficiently by the
      compiler e.g. using a conditional move; likely more efficient
      than fetching a value from the look up table.
2024-04-30 14:16:28 +02:00
Marian Buschsieweke
2a00ec13e5
drivers/periph/gpio_ll: shrink gpio_conf_t
This commit optimizes the `gpio_conf_t` type in the following
regards:

- The "base" `gpio_conf_t` is stripped from members that only some
  platforms support, e.g. drive strength, slew rate, and disabling of
  the Schmitt Trigger are no longer universally available but
  platform-specific extensions
- The `gpio_conf_t` is now crammed into a bit-field that is 8 bit or
  16 bit wide. This allows for storing lots of them e.g. in
  `driver_foo_params_t` or `uart_conf_t` etc.
- A `union` of the `struct` with bit-field members and a `bits` is used
  to allow accessing all bits in a simple C statement and to ensure
  alignment for efficient handling of the type

Co-authored-by: Gunar Schorcht <gunar@schorcht.net>
2024-01-21 08:38:40 +01:00
benpicco
714958ad3c
Merge pull request #20241 from benpicco/busy_wait
sys/busy_wait: add busy wait helper
2024-01-11 12:19:31 +00:00
Benjamin Valentin
fff9ff14da cpu/esp32: add busy loop cycles for all sub-arches 2024-01-10 22:43:31 +01:00
Gunar Schorcht
92657f5fd2 cpu/esp32: add SDMMC support 2024-01-05 07:22:27 +01:00
Gunar Schorcht
70053c5284 cpu/esp32: add LCD low-level parallel interface suppport 2023-11-13 13:01:57 +01:00
Gunar Schorcht
b707235592 cpu/esp32: define RAM_START_ADDR and RAM_LEN 2023-06-25 17:33:06 +02:00
bors[bot]
812c216f0c
Merge #19450 #19476
19450: cpu/esp32: fix compilation issues with GCC 12.2 r=benpicco a=gschorcht

### Contribution description

This PR provides the changes in `cpu/esp32` and `cpu/esp_common` to fix the compilation issues with GCC v12.2.  It is required as the first step in the preparation of the upgrade to ESP-IDF version 5.1.

**Please note**: Insead of fixing the ESP-IDF 4.4 code itself by a big bunch of patches to fix the compilation problems with GCC v12.2, it temporarily disables some warnings. The reason is that the ESP-IDF 5.1 requires GCC v12.2 and should be fixed for this compiler version by the vendor.

### Testing procedure

Green CI

The change were already tested with all ESP-specific modules like `esp_now`, `esp_wifi`, `esp_spi`  and `esp_ble` for all supported ESP platforms.

### Issues/PRs references

Prerequisite for https://github.com/RIOT-OS/riotdocker/pull/227
Fixes issue #19421

19476: native/syscalls: rename real_clock_gettime to clock_gettime r=benpicco a=Teufelchen1

### Contribution description

When compiling RIOT for native using a recent LLVM and enabling ASAN, one might encounter "Duplicated symbol".

This is due to a name clash with `real_clock_gettime()` in compiler-rt from [LLVM](f50246da65), I renamed RIOTs `real_clock_gettime` and just default to the posix function `clock_gettime`. The wrapper existed, most likely, for consistency only.

(The best solution would probably to convince the LLVM folks to declare their symbol as `static` and refactor a bit)

### Testing procedure

Passing CI should be enough.


Co-authored-by: Gunar Schorcht <gunar@schorcht.net>
Co-authored-by: Teufelchen1 <bennet.blischke@haw-hamburg.de>
2023-04-17 20:18:02 +00:00
Gunar Schorcht
0de2570802 cpu/esp32: fix compilation with gcc 12.2 2023-04-17 07:32:48 +02:00
Gunar Schorcht
0c9eb535eb cpu/esp32: clarify units in USB FIFO size definitions
Since the USB OTG FIFO sizes are partly defined in 32-bit words and partly in bytes, the documentation of the of the USB OTG FIFO size definitions is extended by the respective unit.
2023-04-16 22:59:11 +02:00
Gunar Schorcht
457c0cffc3 cpu/esp32: remove USB OTG HS definitions in vendor definitions
ESP32 MCUs do not support USB OTG HS mode. The according definitions are therefore removed from vendor definitions.
2023-04-16 22:59:11 +02:00
Gunar Schorcht
d4d4bc4df1 cpu/esp32: add RMT configuration type 2023-03-29 00:47:35 +02:00
Gunar Schorcht
6cb4a66ff6 cpu/esp32: add interrupt for RMT 2023-03-28 18:50:48 +02:00
Gunar Schorcht
343369476b cpu/esp32: remove ESP-IDF periph_ctrl interface API 2023-03-27 03:10:56 +02:00
Gunar Schorcht
c2f3102a4d cpu/esp32: remove ESP-IDF ledc interface API 2023-03-27 03:10:56 +02:00
Gunar Schorcht
5fac30bc9a cpu/esp32: remove ESP-IDF dac interface API 2023-03-27 03:10:56 +02:00
Gunar Schorcht
d93972c369 cpu/esp32: remove ESP-IDF adc interface API 2023-03-27 03:10:56 +02:00
Gunar Schorcht
dc9b3094dc cpu/esp32: add number of EPs provided by USB OTG peripheral 2023-03-12 13:15:44 +01:00
Benjamin Valentin
ed5bfb7392 cpu/esp32: drop CONFIG_ESP_PHY_ENABLE_USB for ESP32S2 2023-02-02 10:56:40 +01:00
bors[bot]
7855aad7e4
Merge #19079
19079: cpu/esp32: add periph_flashpage support r=kaspar030 a=gschorcht

### Contribution description

This PR provides the `periph_flashpage` support for ESP32x SoCs.

For byte-aligned read access to constant data in the flash, the MMU of all ESP32x SoCs allows to map a certain number of 64 kByte pages of the flash into the data address space of the CPU. This address space is called DROM. Normally the whole DROM address space is assigned to the section `.rodata`. The default flash layout used by all ESP32x SoCs is:
| Address in Flash | Content |
|:-----------------------|:-----------|
| `0x0000` or `0x1000` | bootloader |
| `0x8000` | parition table |
| `0x9000` | `nvs` parition with WiFi data |
| `0xf000`  | `phy_init` partition with RF data |
| `0x10000` | `factory` partition with the app image |

The factory partition consists of a number of 64 kByte pages for the sections `.text`, `.rodata`, `.bss` and others. The `.text` and `rodata` sections are page-aligned and are simply mapped into the instruction address space (IROM) and the data address space (DROM), respectively. All other sections are loaded into RAM.

If the `periph_flashpage` module is used, the `periph_flashpage` driver
- decreases the size of the `.rodata` section in DROM address space by `CONFIG_ESP_FLASHPAGE_CAPACITY`,
- adds a section `.flashpage.writable` of size `CONFIG_ESP_FLASHPAGE_CAPACITY` at the end of DROM address space that is mapped into data address space of the CPU,
- reserves a region of size `CONFIG_ESP_FLASHPAGE_CAPACITY` starting from `0x10000` in front of the image partition `factory` and
- moves the image partition `factory` by  `CONFIG_ESP_FLASHPAGE_CAPACITY` to address `0x10000 + CONFIG_ESP_FLASHPAGE_CAPACITY`. 

The new flash layout is then:
| Address in Flash | Content |
|:-----------------------|:-----------|
| `0x0000` or `0x1000` | bootloader |
| `0x8000` | parition table |
| `0x9000` | `nvs` parition with WiFi data |
| `0xf000`  | `phy_init` partition with RF data |
| `0x10000` | flashpage region |
| `0x10000 + CONFIG_ESP_FLASHPAGE_CAPACITY` | `factory` partition with the app image |

This guarantees that the flash pages are not overwritten if a new app image with changed size is flashed. `CONFIG_ESP_FLASHPAGE_CAPACITY` has to be a multiple of 64 kBytes.

~The PR includes PR #19077 and PR #19078 for the moment to be compilable.~

### Testing procedure

The following tests should pass.
```
USEMODULE='esp_log_startup ps shell_cmds_default' BOARD=esp32-wroom-32 make -j8 -C tests/periph_flashpage flash term
```
```
USEMODULE='esp_log_startup ps shell_cmds_default' BOARD=esp32-wroom-32 make -j8 -C tests/mtd_flashpage flash term
```

### Issues/PRs references

Depends on PR #19077
Depends on PR #19078 


Co-authored-by: Gunar Schorcht <gunar@schorcht.net>
2023-01-18 17:48:29 +00:00
Benjamin Valentin
55b5c47bc8 cpu/esp32: add stdio_usb_serial_jtag 2023-01-09 00:51:27 +01:00
Gunar Schorcht
6f9c64c6cb cpu/esp32: add flashpage support to Kconfig 2023-01-07 10:38:52 +01:00
Gunar Schorcht
f4c0d7da71 cpu/esp32: add flashpage definitions in CPU config 2023-01-07 10:38:52 +01:00
bors[bot]
4f1bb12720
Merge #18752 #19100 #19104
18752: nanocoap_sock: deprecate nanocoap_get() r=benpicco a=benpicco





19100: cpu/esp_common: allow configuration of UART0 r=benpicco a=gschorcht

### Contribution description

This PR
- fixes the issue for ESP32 SoCs that UART0 signals can't be routed to arbitrary GPIOs and
- allows the configuration of the UART device used by the bootloader.

The UART interface and its configuration used by the STDIO are defined in RIOT using the define `STDIO_UART_DEV` and the configuration of the corresponding UART device in `periph_conf.h`. 

However, the bootloader compiled directly in ESP-IDF uses its own definitions `CONFIG_ESP_CONSOLE_UART_*` for the UART configuration. To be able to use a consistent UART configuration in RIOT and the bootloader, e.g. to see the output of the 2nd stage bootloader, these `CONFIG_ESP_CONSOLE_UART_*` can be defined via a set of KConfig variables in RIOT (not yet implemented in Kconfig):
- `CONSOLE_CONFIG_UART_NUM` defines the UART device to be used by the bootloader and by `STDIO_UART_DEV`
- `CONSOLE_CONFIG_UART_RX` and `CONSOLE_CONFIG_UART_TX` define the GPIOs to be used by the bootloader and should be the GPIOs as defined in `periph_conf.h` for the corresponding UART device.

### Testing procedure

Any ESP32 node should still work with `stdio_uart` and the default configuration. To test an alternative configuration, use
```
CFLAGS='-DUART1_TXD=5 -DUART1_RXD=4 -DCONFIG_CONSOLE_UART_NUM=1 -DCONFIG_CONSOLE_UART_TX=5 -DCONFIG_CONSOLE_UART_RX=4' USEMODULE=esp_log_startup BOARD=esp32-wroom-32 make -C tests/shell flash
```
The bootloader output and the STDIO should be routed to UART1 at GPIO4 and GPIO5.

### Issues/PRs references

Prerequisite for PR ##18863

19104: tests/periph_uart: only exclude STDIO_UART_DEV if stdio_uart is used r=benpicco a=benpicco



Co-authored-by: Benjamin Valentin <benjamin.valentin@ml-pa.com>
Co-authored-by: Gunar Schorcht <gunar@schorcht.net>
Co-authored-by: Benjamin Valentin <benjamin.valentin@bht-berlin.de>
2023-01-06 21:15:36 +00:00
Gunar Schorcht
7230299575 cpu/esp32: use same UART device in stdio_uart and bootloader 2023-01-06 16:43:51 +01:00
Gunar Schorcht
8b34d547ac cpu/esp32: fix SDK configuration for USB PHY
When using USB Serial/JTAG/OTG/CDC, USB should be enabled in `phy_init`, otherwise USB interface is not working properly.
2023-01-06 12:30:11 +01:00
Gunar Schorcht
dc2dc801cc cpu/esp32x: generate memory.ld from vendor memory.ld.in
Using the vendor `memory.ld.in` instead of a static `memory.ld`, from which the actual used `memory.ld` is generated with the C preprocessor, allows to use the configuration in `sdkconfig.h` as well as Kconfig to use a custom memory layout. For example, it is no longer necessary to maintain different `memory.ld` files for the ESP32 BLE module, since the memory layout is now defined from the values of the configuration.
2022-12-31 15:30:34 +01:00
Gunar Schorcht
d9dbaa3c2c cpu/esp32s{2,3}: DWC2_USB_OTG_FS_TOTAL_FIFO_SIZE must not overridable
Since the total USB OTG FIFO size is a hardware propertie, it must not be overridable.
2022-10-17 20:03:51 +02:00
Benjamin Valentin
2b2298b796 cpu/esp32: implement periph_spi_reconfigure 2022-10-08 22:02:49 +02:00
Gunar Schorcht
8696783853 cpu/esp32: enable tinyUSB package for ESP32-S2 and ESP32-S3 2022-09-30 19:05:51 +02:00
Gunar Schorcht
9d5a7ac083 cpu/esp32: use usbdev_synopsys_dwc2 driver as periph_usbdev 2022-09-27 01:00:57 +02:00
Gunar Schorcht
ac075ee320 cpu/esp32: add USB interrupt for periph_usbdev 2022-09-27 01:00:57 +02:00
Gunar Schorcht
da2f024f8b cpu/esp32: remove include of esp_can.h
Since `esp_can.h` is included by main `cpu/esp32/include/periph_cpu.h` after the include of the specific `periph_cpu_$(CPU_FAM)`, it is not necessary to include `esp_can.h` in each specific `periph_cpu_$(CPU_FAM)`.
2022-09-27 00:57:42 +02:00
Gunar Schorcht
b37338ba0b cpu/esp32: changes for periph/gpio_ll in ESP-IDF interface API 2022-09-02 15:03:45 +02:00
Gunar Schorcht
94b4f03b47 cpu/esp32: implement periph/gpio_ll_irq 2022-09-02 15:03:45 +02:00
Gunar Schorcht
581c2dd9be cpu/esp32: implement periph/gpio_ll 2022-09-02 15:03:45 +02:00
Gunar Schorcht
af719f9c3b cpu/esp32: fix doc for gpio_flank_t 2022-08-31 12:21:46 +02:00
benpicco
2917c0f51e
Merge pull request #18506 from gschorcht/cpu/esp32/add_esp32s2_cpu_support
cpu/esp32: add support for ESP32-S2
2022-08-30 21:24:36 +02:00
Gunar Schorcht
dac197031e cpu/esp32: add ESP32-S2 specific configuration header files 2022-08-29 17:19:39 +02:00
Gunar Schorcht
60c681a2c3 cpu/esp32/esp-ble-nimble: fix too many empty lines in syscfg.h 2022-08-27 17:27:23 +02:00
Gunar Schorcht
5e0b1d665b cpu/esp32: add BLE support for ESP32-S3 2022-08-26 21:16:09 +02:00
Gunar Schorcht
aba5e35ac4 cpu/esp32: add BLE support for ESP32-C3 2022-08-26 17:10:42 +02:00
Gunar Schorcht
56e59eb036 cpu/esp32: add NimBLE support for ESP32 2022-08-24 09:05:25 +02:00
Gunar Schorcht
abccc41db7 cpu/esp32: add BLE support for ESP32 2022-08-24 09:05:25 +02:00
Gunar Schorcht
b74bf015ef cpu/esp32: change the UART interrupt number
When using Bluetooth LE, the former UART interrupt number 5 is occupied by the ESP32 Bluetooth Controller. Therefore, another interrupt number has to be used for UART.
2022-08-24 09:03:38 +02:00
Gunar Schorcht
e7bf789dd4 cpu/esp32: move CLOCK_CORECLOCK to periph_cpu_*.h
This define does not belong to the defines in `sdkconfig_*.h` that are used for the ESP-IDF SDK. It is therefore moved to the corresponding `periph_cpu_*.h` file.
2022-08-17 15:58:40 +02:00
Gunar Schorcht
55e1f88a60 cpu/esp32: add ESP32-S3 specific configuration header files 2022-08-17 02:04:07 +02:00
Gunar Schorcht
70d427da0b cpu/esp32: move common ESP-IDF configurations to common file 2022-08-07 12:04:22 +02:00
Gunar Schorcht
d0b3c20d88 cpu/esp32: add ESP32-C3 specific configuration header files 2022-08-05 22:26:22 +02:00