periph_cpu.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2025 Tom Hert <git@annsann.eu>
3  * SPDX-FileCopyrightText: 2025 HAW Hamburg
4  * SPDX-License-Identifier: LGPL-2.1-only
5  */
6 
7 #pragma once
8 
19 #include <inttypes.h>
20 
22 #define HAVE_GPIO_T
23 typedef uint32_t gpio_t;
24 
30 #define GPIO_PIN(port, pin) (((port) & 0) | (pin))
31 
33 #define _u(x) ((uint32_t)(x))
34 
35 #ifdef RP2350_USE_RISCV
36 # include "periph_cpu_common.h"
37 # include "xh3irq.h"
38 #endif
39 #include "cpu.h"
40 #include "core_cm33.h" /* Trick RP2350 into believing the file exists on RISCV */
41 #include "RP2350.h"
42 #include "helpers.h"
43 #include "gpio_conf.h"
44 #include "clock_conf.h"
45 #include "uart_conf.h"
46 
47 #if !(defined(RP2350_USE_ARM) || defined(RP2350_USE_RISCV))
48 # error "Either RP2350_USE_ARM or RP2350_USE_RISCV must be defined"
49 #endif
50 
51 #if (defined(RP2350_USE_ARM) && defined(RP2350_USE_RISCV))
52 # error "Only one of RP2350_USE_ARM or RP2350_USE_RISCV can be defined"
53 #endif
54 
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58 
60 #define OSC_DEBUG_PIN_ID 15u
61 
63 #define RESET_PLL_SYS (1u << 14u)
64 
66 #define RESET_PADS_BANK0 (1u << 9u)
67 
69 #define RESET_UART0 (1u << 26u)
70 
72 #define RESET_UART1 (1u << 27u)
73 
75 #define RESET_IO_BANK0 (1u << 6u)
76 
78 #define PADS_BANK0_GPIO0_IE_BITS (1u << 6u)
79 
81 #define PADS_BANK0_ISO_BITS (1u << 8u)
82 
87 void rp2350_init(void);
88 
94 static inline uint32_t* calculate_gpio_pad_register_addr(gpio_t pin)
95 {
96  /* Each pin has a 4 byte register, so we can calculate the address
97  * by adding 4 bytes for each pin, starting at the base address of PADS_BANK0
98  * and adding 4 bytes to skip VOLTAGE_SELECT */
99  return (uint32_t*) (PADS_BANK0_BASE + (4 * (pin + 1)));
100 }
101 
107 static uint32_t calculate_gpio_io_status_register_addr(gpio_t pin) {
108  /* Each status register is followed by a ctrl register */
109  return IO_BANK0_BASE + (8 * pin);
110 }
111 
118 static inline uint32_t* calculate_gpio_io_ctrl_register_addr(gpio_t pin) {
119  /* Each pin has a 8 byte register (4 Bytes of Status, 4 Bytes of CTRL),
120  * so we can calculate the address by adding 8 bytes for each pin,
121  * starting at the base address of IO_BANK0 */
122  return (uint32_t*) (calculate_gpio_io_status_register_addr(pin) + 4);
123 }
124 
125 #ifdef __cplusplus
126 }
127 #endif
128 
Clock configuration for the RP2350.
GPIO configuration for the RP2350.
unsigned int gpio_t
GPIO type identifier.
Definition: gpio.h:91
Helper functions for atomic register operations.
Adds include for missing inttype definitions.
void rp2350_init(void)
Initialize RP2350 specific CPU peripherals that are not architecture specific.
static uint32_t calculate_gpio_io_status_register_addr(gpio_t pin)
Calculate the address of the GPIO IO status register for a given pin.
Definition: periph_cpu.h:107
static uint32_t * calculate_gpio_pad_register_addr(gpio_t pin)
Calculate the address of the GPIO pad register for a given pin.
Definition: periph_cpu.h:94
static uint32_t * calculate_gpio_io_ctrl_register_addr(gpio_t pin)
Calculate the address of the GPIO IO control register for a given pin.
Definition: periph_cpu.h:118
UART configuration for the RP2350.
xh3irq.h interrupt controller support