periph_cpu.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2021 Otto-von-Guericke-Universität Magdeburg
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
9 #pragma once
10 
22 #include "cpu.h"
23 #include "vendor/RP2040.h"
24 #include "io_reg.h"
25 #include "macros/units.h"
26 #include "periph/pio.h" /* pio_t */
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 #if !defined(PLL_SYS_REF_DIV) || defined(DOXYGEN)
38 #define PLL_SYS_REF_DIV 1
39 #endif
40 
41 #if !defined(PLL_USB_REF_DIV) || defined(DOXYGEN)
45 #define PLL_USB_REF_DIV 1
46 #endif
47 
48 #if !defined(PLL_SYS_VCO_FEEDBACK_SCALE) || defined(DOXYGEN)
55 #define PLL_SYS_VCO_FEEDBACK_SCALE 125
56 #endif
57 
58 #if !defined(PLL_SYS_POSTDIV1) || defined(DOXYGEN)
64 #define PLL_SYS_POSTDIV1 6
65 #endif
66 
67 #if !defined(PLL_SYS_POSTDIV2) || defined(DOXYGEN)
73 #define PLL_SYS_POSTDIV2 2
74 #endif
75 
76 #if !defined(PLL_USB_VCO_FEEDBACK_SCALE) || defined(DOXYGEN)
83 #define PLL_USB_VCO_FEEDBACK_SCALE 40
84 #endif
85 
86 #if !defined(PLL_USB_POSTDIV1) || defined(DOXYGEN)
92 #define PLL_USB_POSTDIV1 5
93 #endif
94 
95 #if !defined(PLL_USB_POSTDIV2) || defined(DOXYGEN)
101 #define PLL_USB_POSTDIV2 2
102 #endif
103 
104 #if !defined(CLOCK_XOSC) || defined(DOXYGEN)
109 #define CLOCK_XOSC MHZ(12)
110 #endif
111 
115 #define PLL_CLOCK(vco_feedback, postdiv1, postdiv2) \
116  (CLOCK_XOSC * (vco_feedback) / (postdiv1) / (postdiv2))
117 
121 #define CLOCK_CORECLOCK \
122  PLL_CLOCK(PLL_SYS_VCO_FEEDBACK_SCALE, PLL_SYS_POSTDIV1, PLL_SYS_POSTDIV2)
123 
127 #define CLOCK_USB \
128  PLL_CLOCK(PLL_USB_VCO_FEEDBACK_SCALE, PLL_USB_POSTDIV1, PLL_USB_POSTDIV2)
129 
134 #define CLOCK_XOSC_MAX MHZ(15)
135 #define CLOCK_XOSC_MIN MHZ(5)
136 #define PLL_POSTDIV_MIN (1U)
137 #define PLL_POSTDIV_MAX (7U)
138 #define PLL_VCO_FEEDBACK_SCALE_MIN (16U)
139 #define PLL_VCO_FEEDBACK_SCALE_MAX (320U)
140 #define PLL_REF_DIV_MIN (1U)
142 #define PLL_REF_DIV_MAX (1U)
146 #if CLOCK_USB != MHZ(48)
147 #error "USB clock != 48 MHz, check PLL_USB_VCO_FEEDBACK_SCALE, PLL_USB_POSTDIV1, PLL_SYS_POSTDIV2"
148 #endif
149 
150 #if (CLOCK_XOSC > CLOCK_XOSC_MAX) || (CLOCK_XOSC < CLOCK_XOSC_MIN)
151 #error "Value for CLOCK_XOSC out of range, check config"
152 #endif
153 
154 #if (PLL_SYS_REF_DIV < PLL_REF_DIV_MIN) || (PLL_SYS_REF_DIV > PLL_REF_DIV_MAX)
155 #error "Value for PLL_SYS_REF_DIV out of range, check config"
156 #endif
157 
158 #if (PLL_USB_REF_DIV < PLL_REF_DIV_MIN) || (PLL_USB_REF_DIV > PLL_REF_DIV_MAX)
159 #error "Value for PLL_USB_REF_DIV out of range, check config"
160 #endif
161 
162 #if (PLL_SYS_VCO_FEEDBACK_SCALE < PLL_VCO_FEEDBACK_SCALE_MIN) \
163  || (PLL_SYS_VCO_FEEDBACK_SCALE > PLL_VCO_FEEDBACK_SCALE_MAX)
164 #error "Value for PLL_SYS_VCO_FEEDBACK_SCALE out of range, check config"
165 #endif
166 
167 #if (PLL_USB_VCO_FEEDBACK_SCALE < PLL_VCO_FEEDBACK_SCALE_MIN) \
168  || (PLL_USB_VCO_FEEDBACK_SCALE > PLL_VCO_FEEDBACK_SCALE_MAX)
169 #error "Value for PLL_USB_VCO_FEEDBACK_SCALE out of range, check config"
170 #endif
171 
172 #if (PLL_SYS_POSTDIV1 < PLL_POSTDIV_MIN) || (PLL_SYS_POSTDIV1 > PLL_POSTDIV_MAX)
173 #error "Value for PLL_SYS_POSTDIV1 out of range, check config"
174 #endif
175 
176 #if (PLL_SYS_POSTDIV2 < PLL_POSTDIV_MIN) || (PLL_SYS_POSTDIV2 > PLL_POSTDIV_MAX)
177 #error "Value for PLL_SYS_POSTDIV2 out of range, check config"
178 #endif
179 
180 #if (PLL_USB_POSTDIV1 < PLL_POSTDIV_MIN) || (PLL_USB_POSTDIV1 > PLL_POSTDIV_MAX)
181 #error "Value for PLL_USB_POSTDIV1 out of range, check config"
182 #endif
183 
184 #if (PLL_USB_POSTDIV2 < PLL_POSTDIV_MIN) || (PLL_USB_POSTDIV2 > PLL_POSTDIV_MAX)
185 #error "Value for PLL_USB_POSTDIV2 out of range, check config"
186 #endif
187 
188 #if !defined(CLOCK_PERIPH_SOURCE) || defined(DOXYGEN)
192 #define CLOCK_PERIPH_SOURCE CLOCKS_CLK_PERI_CTRL_AUXSRC_clk_sys
193 #endif
194 
195 #if !defined(CLOCK_PERIPH) || defined(DOXYGEN)
199 #define CLOCK_PERIPH CLOCK_CORECLOCK
200 #endif
201 
205 #define RESETS_RESET_MASK \
206  (RESETS_RESET_usbctrl_Msk | \
207  RESETS_RESET_uart1_Msk | \
208  RESETS_RESET_uart0_Msk | \
209  RESETS_RESET_timer_Msk | \
210  RESETS_RESET_tbman_Msk | \
211  RESETS_RESET_sysinfo_Msk | \
212  RESETS_RESET_syscfg_Msk | \
213  RESETS_RESET_spi1_Msk | \
214  RESETS_RESET_spi0_Msk | \
215  RESETS_RESET_rtc_Msk | \
216  RESETS_RESET_pwm_Msk | \
217  RESETS_RESET_pll_usb_Msk | \
218  RESETS_RESET_pll_sys_Msk | \
219  RESETS_RESET_pio1_Msk | \
220  RESETS_RESET_pio0_Msk | \
221  RESETS_RESET_pads_qspi_Msk | \
222  RESETS_RESET_pads_bank0_Msk | \
223  RESETS_RESET_jtag_Msk | \
224  RESETS_RESET_io_qspi_Msk | \
225  RESETS_RESET_io_bank0_Msk | \
226  RESETS_RESET_i2c1_Msk | \
227  RESETS_RESET_i2c0_Msk | \
228  RESETS_RESET_dma_Msk | \
229  RESETS_RESET_busctrl_Msk | \
230  RESETS_RESET_adc_Msk)
231 
238 #define GPIO_PIN(port, pin) ((((port) & 0)) | (pin))
239 
244 #define HAVE_GPIO_T
245 typedef uint32_t gpio_t;
251 #define GPIO_UNDEF UINT32_MAX
252 
257 #define HAVE_GPIO_FLANK_T
258 typedef enum {
261  GPIO_FALLING = 0x4,
262  GPIO_RISING = 0x8,
263  GPIO_BOTH = 0xc
274 #define GPIO_PAD_REGISTER_RESET_VALUE (0x00000056)
278 enum {
284 };
285 
289 typedef struct {
290  uint32_t slew_rate_fast : 1;
291  uint32_t schmitt_trig_enable : 1;
292  uint32_t pull_down_enable : 1;
293  uint32_t pull_up_enable : 1;
294  uint32_t drive_strength : 2;
295  uint32_t input_enable : 1;
296  uint32_t output_disable : 1;
298  uint32_t : 24;
309 #define GPIO_IO_REGISTER_RESET_VALUE (0x0000001f)
313 typedef enum {
314  FUNCTION_SELECT_SPI = 1,
318  FUNCTION_SELECT_I2C = 3,
320  FUNCTION_SELECT_PWM = 4,
327  FUNCTION_SELECT_USB = 9,
331 
335 enum {
341 };
342 
346 enum {
352 };
353 
357 enum {
363 };
364 
368 enum {
374 };
375 
379 typedef struct {
380  uint32_t function_select : 5;
381  uint32_t : 3;
382  uint32_t output_override : 2;
383  uint32_t : 2;
384  uint32_t output_enable_override : 2;
385  uint32_t : 2;
386  uint32_t input_override : 2;
387  uint32_t : 10;
388  uint32_t irq_override : 2;
389  uint32_t : 2;
396 typedef struct {
397  gpio_t pin;
398  uint8_t chan;
399 } adc_conf_t;
400 
404 #define PWM_SLICE_NUMOF (8)
405 
409 #define PWM_CHANNEL_NUMOF (2)
410 
414 typedef struct {
415  gpio_t pin;
416  uint8_t cc_chan;
417 } pwm_chan_t;
418 
422 typedef struct {
423  uint8_t pwm_slice;
427 } pwm_conf_t;
428 
432 typedef struct {
433  UART0_Type *dev;
434  gpio_t rx_pin;
435  gpio_t tx_pin;
436  IRQn_Type irqn;
437 } uart_conf_t;
438 
442 #define PERIPH_TIMER_PROVIDES_SET
443 
447 typedef struct {
450 
456 typedef struct {
457  TIMER_Type *dev;
459  uint8_t ch_numof;
460 } timer_conf_t;
461 
465 typedef struct {
466  PIO0_Type *dev;
469 } pio_conf_t;
470 
474 typedef struct {
476  gpio_t sda;
477  gpio_t scl;
478  unsigned irq;
480 
486 static inline volatile uint32_t * gpio_pad_register(uint8_t pin)
487 {
488  return (uint32_t *)(PADS_BANK0_BASE + 4 + (pin << 2));
489 }
490 
495 static inline void gpio_set_pad_config(uint8_t pin, gpio_pad_ctrl_t config)
496 {
497  uint32_t *c = (uint32_t *)&config;
498  *gpio_pad_register(pin) = *c;
499 }
500 
504 static inline volatile uint32_t * gpio_io_register(uint8_t pin)
505 {
506  return (uint32_t *)(IO_BANK0_BASE + 4 + (pin << 3));
507 }
508 
513 static inline void gpio_set_io_config(uint8_t pin, gpio_io_ctrl_t config)
514 {
515  uint32_t *c = (uint32_t *)&config;
516  *gpio_io_register(pin) = *c;
517 }
518 
522 static inline void gpio_set_function_select(uint8_t pin, gpio_function_select_t funcsel)
523 {
524  io_reg_write_dont_corrupt(gpio_io_register(pin), funcsel << IO_BANK0_GPIO0_CTRL_FUNCSEL_Pos,
525  IO_BANK0_GPIO0_CTRL_FUNCSEL_Msk);
526 }
527 
531 static inline void gpio_reset_all_config(uint8_t pin)
532 {
535 }
536 
543 static inline void periph_reset(uint32_t components)
544 {
545  io_reg_atomic_set(&RESETS->RESET, components);
546 }
547 
554 static inline void periph_reset_done(uint32_t components)
555 {
556  io_reg_atomic_clear(&RESETS->RESET, components);
557  while ((~RESETS->RESET_DONE) & components) { }
558 }
559 
573 void clock_sys_configure_source(uint32_t f_in, uint32_t f_out,
574  CLOCKS_CLK_SYS_CTRL_SRC_Enum source);
575 
586 void clock_sys_configure_aux_source(uint32_t f_in, uint32_t f_out,
587  CLOCKS_CLK_SYS_CTRL_AUXSRC_Enum aux);
588 
599 void clock_ref_configure_source(uint32_t f_in, uint32_t f_out,
600  CLOCKS_CLK_REF_CTRL_SRC_Enum source);
601 
612 void clock_ref_configure_aux_source(uint32_t f_in, uint32_t f_out,
613  CLOCKS_CLK_REF_CTRL_AUXSRC_Enum aux);
614 
621 void clock_periph_configure(CLOCKS_CLK_PERI_CTRL_AUXSRC_Enum aux);
622 
633 void clock_gpout0_configure(uint32_t f_in, uint32_t f_out, CLOCKS_CLK_GPOUT0_CTRL_AUXSRC_Enum aux);
634 
645 void clock_gpout1_configure(uint32_t f_in, uint32_t f_out, CLOCKS_CLK_GPOUT1_CTRL_AUXSRC_Enum aux);
646 
657 void clock_gpout2_configure(uint32_t f_in, uint32_t f_out, CLOCKS_CLK_GPOUT2_CTRL_AUXSRC_Enum aux);
658 
669 void clock_gpout3_configure(uint32_t f_in, uint32_t f_out, CLOCKS_CLK_GPOUT3_CTRL_AUXSRC_Enum aux);
670 
677 void clock_adc_configure(CLOCKS_CLK_ADC_CTRL_AUXSRC_Enum aux);
696 void pll_start_sys(uint8_t ref_div,
697  uint16_t vco_feedback_scale,
698  uint8_t post_div_1, uint8_t post_div_2);
699 
711 void pll_start_usb(uint8_t ref_div,
712  uint16_t vco_feedback_scale,
713  uint8_t post_div_1, uint8_t post_div_2);
714 
718 void pll_stop_sys(void);
719 
723 void pll_stop_usb(void);
724 
728 void pll_reset_sys(void);
729 
733 void pll_reset_usb(void);
734 
750 void xosc_start(uint32_t f_ref);
751 
755 void xosc_stop(void);
756 
770 void rosc_start(void);
771 
777 void rosc_stop(void);
778 
785 #define HAVE_SPI_CLK_T
786 enum {
792 };
793 
797 typedef uint32_t spi_clk_t;
803 typedef struct {
804  SPI0_Type *dev;
805  gpio_t miso_pin;
806  gpio_t mosi_pin;
807  gpio_t clk_pin;
808 } spi_conf_t;
809 
810 #define PERIPH_SPI_NEEDS_TRANSFER_REG
811 #define PERIPH_SPI_NEEDS_TRANSFER_REGS
812 #define PERIPH_SPI_NEEDS_TRANSFER_BYTE
813 
814 #ifdef __cplusplus
815 }
816 #endif
817 
gpio_flank_t
Definition: periph_cpu.h:179
spi_clk_t
Definition: periph_cpu.h:351
gpio_t adc_conf_t
ADC configuration wrapper.
Definition: periph_cpu.h:336
High-level PIO peripheral driver interface.
enum IRQn IRQn_Type
Interrupt Number Definition.
unsigned int gpio_t
GPIO type identifier.
Definition: gpio.h:91
@ GPIO_LEVEL_LOW
emit interrupt level-triggered on low input
Definition: periph_cpu.h:259
@ GPIO_FALLING
emit interrupt on falling flank
Definition: periph_cpu.h:109
@ GPIO_LEVEL_HIGH
emit interrupt level-triggered on low input
Definition: periph_cpu.h:260
@ GPIO_RISING
emit interrupt on rising flank
Definition: periph_cpu.h:110
@ GPIO_BOTH
emit interrupt on both flanks
Definition: periph_cpu.h:111
unsigned pio_t
PIO index type.
Definition: pio.h:70
@ SPI_CLK_10MHZ
drive the SPI bus with 10MHz
Definition: periph_cpu.h:356
@ SPI_CLK_5MHZ
drive the SPI bus with 5MHz
Definition: periph_cpu.h:355
@ SPI_CLK_400KHZ
drive the SPI bus with 400KHz
Definition: periph_cpu.h:353
@ SPI_CLK_1MHZ
drive the SPI bus with 1MHz
Definition: periph_cpu.h:354
@ SPI_CLK_100KHZ
drive the SPI bus with 100KHz
Definition: periph_cpu.h:352
RP2040 atomic register access macros.
static void io_reg_atomic_clear(volatile uint32_t *reg, uint32_t mask)
Clear the bits in the register at address reg as given by the set bits in operand op.
Definition: io_reg.h:99
static void io_reg_write_dont_corrupt(volatile uint32_t *reg, uint32_t value, uint32_t mask)
Updates part of an I/O register without corrupting its contents.
Definition: io_reg.h:127
static void io_reg_atomic_set(volatile uint32_t *reg, uint32_t mask)
Set the bits in the register at address reg as given by the set bits in operand op.
Definition: io_reg.h:87
void rosc_start(void)
Start the ring oscillator in default mode.
void clock_gpout2_configure(uint32_t f_in, uint32_t f_out, CLOCKS_CLK_GPOUT2_CTRL_AUXSRC_Enum aux)
Configure gpio24 as clock output pin.
static volatile uint32_t * gpio_io_register(uint8_t pin)
Get the IO control register for the given GPIO pin as word.
Definition: periph_cpu.h:504
void clock_gpout3_configure(uint32_t f_in, uint32_t f_out, CLOCKS_CLK_GPOUT3_CTRL_AUXSRC_Enum aux)
Configure gpio25 as clock output pin.
static void gpio_set_pad_config(uint8_t pin, gpio_pad_ctrl_t config)
Convenience function to set the pad configuration of the given pin using the bit-field convenience ty...
Definition: periph_cpu.h:495
gpio_function_select_t
Possible function values for gpio_io_ctrl_t::function_select.
Definition: periph_cpu.h:313
@ FUNCTION_SELECT_PIO0
connect pin to the first PIO peripheral
Definition: periph_cpu.h:323
@ FUNCTION_SELECT_CLOCK
connect pin to the timer (depending on pin: external clock, clock output, or not supported)
Definition: periph_cpu.h:325
@ FUNCTION_SELECT_PIO1
connect pin to the second PIO peripheral
Definition: periph_cpu.h:324
@ FUNCTION_SELECT_I2C
connect pin to the I2C peripheral (SCL/SDA depends on pin)
Definition: periph_cpu.h:318
@ FUNCTION_SELECT_PWM
connect pin to the timer for PWM (channel depends on pin)
Definition: periph_cpu.h:320
@ FUNCTION_SELECT_UART
connect pin to the UART peripheral (TXD/RXD depends on pin)
Definition: periph_cpu.h:316
@ FUNCTION_SELECT_USB
connect pin to the USB peripheral (function depends on pin)
Definition: periph_cpu.h:327
@ FUNCTION_SELECT_SIO
use pin as vanilla GPIO
Definition: periph_cpu.h:322
@ FUNCTION_SELECT_SPI
connect pin to the SPI peripheral (MISO/MOSI/SCK depends on pin)
Definition: periph_cpu.h:314
@ FUNCTION_SELECT_NONE
Reset value, pin unconnected.
Definition: periph_cpu.h:329
@ INPUT_OVERRIDE_LOW
signal low to connected peripheral
Definition: periph_cpu.h:360
@ INPUT_OVERRIDE_INVERT
invert signal to connected peripheral
Definition: periph_cpu.h:359
@ INPUT_OVERRIDE_NUMOF
number of possible input override settings
Definition: periph_cpu.h:362
@ INPUT_OVERRIDE_NOMARL
don't mess with peripheral input signal
Definition: periph_cpu.h:358
@ INPUT_OVERRIDE_HIGH
signal high to connected peripheral
Definition: periph_cpu.h:361
@ OUTPUT_OVERRIDE_HIGH
drive pin high, overriding peripheral signal
Definition: periph_cpu.h:339
@ OUTPUT_OVERRIDE_NORMAL
drive pin from connected peripheral
Definition: periph_cpu.h:336
@ OUTPUT_OVERRIDE_LOW
drive pin low, overriding peripheral signal
Definition: periph_cpu.h:338
@ OUTPUT_OVERRIDE_NUMOF
number of possible output override settings
Definition: periph_cpu.h:340
@ OUTPUT_OVERRIDE_INVERT
drive pin from connected peripheral, but invert output
Definition: periph_cpu.h:337
void xosc_start(uint32_t f_ref)
Configures the Crystal to run.
static void gpio_reset_all_config(uint8_t pin)
Restore the default I/O and PAD configuration of the given GPIO pin.
Definition: periph_cpu.h:531
void pll_start_usb(uint8_t ref_div, uint16_t vco_feedback_scale, uint8_t post_div_1, uint8_t post_div_2)
Start the PLL for the USB clock output[MHz] = f_ref / ref_div * vco_feedback_scale / post_div_1 / pos...
void pll_stop_sys(void)
Stop the PLL of the system clock.
void clock_adc_configure(CLOCKS_CLK_ADC_CTRL_AUXSRC_Enum aux)
Configure the ADC clock to run from a dedicated auxiliary clock source.
static volatile uint32_t * gpio_pad_register(uint8_t pin)
Get the PAD control register for the given GPIO pin as word.
Definition: periph_cpu.h:486
static void gpio_set_function_select(uint8_t pin, gpio_function_select_t funcsel)
Set the function select subregister for the given pin to the given value.
Definition: periph_cpu.h:522
void xosc_stop(void)
Stop the crystal.
#define GPIO_PAD_REGISTER_RESET_VALUE
Reset value of the GPIO pad configuration register.
Definition: periph_cpu.h:274
void clock_ref_configure_aux_source(uint32_t f_in, uint32_t f_out, CLOCKS_CLK_REF_CTRL_AUXSRC_Enum aux)
Configure the reference clock to run from an auxiliary clock source, like PLL.
#define PWM_CHANNEL_NUMOF
Number of channels available per slice.
Definition: periph_cpu.h:409
static void gpio_set_io_config(uint8_t pin, gpio_io_ctrl_t config)
Convenience function to set the I/O configuration of the given pin using the bit-field convenience ty...
Definition: periph_cpu.h:513
@ OUTPUT_ENABLE_OVERRIDE_NUMOF
number of possible output enable override settings
Definition: periph_cpu.h:351
@ OUTPUT_ENABLE_OVERRIDE_DISABLE
disable output, overriding peripheral signal
Definition: periph_cpu.h:349
@ OUTPUT_ENABLE_OVERRIDE_NOMARL
enable output as specified by connected peripheral
Definition: periph_cpu.h:347
@ OUTPUT_ENABLE_OVERRIDE_ENABLE
enable output, overriding peripheral signal
Definition: periph_cpu.h:350
@ OUTPUT_ENABLE_OVERRIDE_INVERT
invert output enable setting of peripheral
Definition: periph_cpu.h:348
void clock_ref_configure_source(uint32_t f_in, uint32_t f_out, CLOCKS_CLK_REF_CTRL_SRC_Enum source)
Configure the reference clock to run from a clock source, which is either the ROSC or the XOSC.
void pll_stop_usb(void)
Stop the PLL of the USB clock.
@ DRIVE_STRENGTH_NUMOF
number of different drive strength options
Definition: periph_cpu.h:283
@ DRIVE_STRENGTH_4MA
set driver strength to 4 mA
Definition: periph_cpu.h:280
@ DRIVE_STRENGTH_8MA
set driver strength to 8 mA
Definition: periph_cpu.h:281
@ DRIVE_STRENGTH_12MA
set driver strength to 12 mA
Definition: periph_cpu.h:282
@ DRIVE_STRENGTH_2MA
set driver strength to 2 mA
Definition: periph_cpu.h:279
@ IRQ_OVERRIDE_INVERT
invert IRQ signal
Definition: periph_cpu.h:370
@ IRQ_OVERRIDE_LOW
set IRQ signal to low
Definition: periph_cpu.h:371
@ IRQ_OVERRIDE_NORMAL
don't mess with IRQ signal
Definition: periph_cpu.h:369
@ IRQ_OVERRIDE_HIGH
set IRQ signal to high
Definition: periph_cpu.h:372
@ IRQ_OVERRIDE_NUMOF
number of possible IRQ override settings
Definition: periph_cpu.h:373
void clock_sys_configure_aux_source(uint32_t f_in, uint32_t f_out, CLOCKS_CLK_SYS_CTRL_AUXSRC_Enum aux)
Configure the system clock to run from an auxiliary clock source, like PLL.
void pll_reset_sys(void)
Reset the PLL of the system clock.
void pll_reset_usb(void)
Reset the PLL of the USB clock.
void clock_sys_configure_source(uint32_t f_in, uint32_t f_out, CLOCKS_CLK_SYS_CTRL_SRC_Enum source)
Configure the system clock to run from the reference clock, which is the default on boot.
void clock_gpout1_configure(uint32_t f_in, uint32_t f_out, CLOCKS_CLK_GPOUT1_CTRL_AUXSRC_Enum aux)
Configure gpio23 as clock output pin.
void clock_gpout0_configure(uint32_t f_in, uint32_t f_out, CLOCKS_CLK_GPOUT0_CTRL_AUXSRC_Enum aux)
Configure gpio21 as clock output pin.
void pll_start_sys(uint8_t ref_div, uint16_t vco_feedback_scale, uint8_t post_div_1, uint8_t post_div_2)
Start the PLL for the system clock output[MHz] = f_ref / ref_div * vco_feedback_scale / post_div_1 / ...
static void periph_reset_done(uint32_t components)
Waits until hardware components have been reset.
Definition: periph_cpu.h:554
void clock_periph_configure(CLOCKS_CLK_PERI_CTRL_AUXSRC_Enum aux)
Configure the peripheral clock to run from a dedicated auxiliary clock source.
#define GPIO_IO_REGISTER_RESET_VALUE
Reset value of the GPIO I/O configuration register.
Definition: periph_cpu.h:309
void rosc_stop(void)
Turn off the ROSC to save power.
static void periph_reset(uint32_t components)
Reset hardware components.
Definition: periph_cpu.h:543
Memory layout of GPIO control register in IO bank 0.
Definition: periph_cpu.h:379
uint32_t output_enable_override
output enable override
Definition: periph_cpu.h:384
uint32_t input_override
input value override
Definition: periph_cpu.h:386
uint32_t irq_override
interrupt inversion override
Definition: periph_cpu.h:388
uint32_t output_override
output value override
Definition: periph_cpu.h:382
uint32_t function_select
select GPIO function
Definition: periph_cpu.h:380
Memory layout of GPIO control register in pads bank 0.
Definition: periph_cpu.h:289
uint32_t pull_up_enable
enable pull up resistor
Definition: periph_cpu.h:293
uint32_t schmitt_trig_enable
enable Schmitt trigger
Definition: periph_cpu.h:291
uint32_t input_enable
enable as input
Definition: periph_cpu.h:295
uint32_t slew_rate_fast
set slew rate control to fast
Definition: periph_cpu.h:290
uint32_t output_disable
disable output, overwrite output enable from peripherals
Definition: periph_cpu.h:296
uint32_t drive_strength
GPIO driver strength.
Definition: periph_cpu.h:294
uint32_t pull_down_enable
enable pull down resistor
Definition: periph_cpu.h:292
PIO configuration type.
Definition: periph_cpu.h:465
IRQn_Type irqn0
PIO IRQ0 interrupt number.
Definition: periph_cpu.h:467
IRQn_Type irqn1
PIO IRQ1 interrupt number.
Definition: periph_cpu.h:468
PIO0_Type * dev
PIO device.
Definition: periph_cpu.h:466
PIO I2C configuration type.
Definition: periph_cpu.h:474
gpio_t sda
Pin to use as SDA pin.
Definition: periph_cpu.h:476
pio_t pio
PIO number of the PIO to run this configuration.
Definition: periph_cpu.h:475
unsigned irq
PIO IRQ line to use.
Definition: periph_cpu.h:478
gpio_t scl
Pin to use as SCL pin.
Definition: periph_cpu.h:477
PWM channel.
Definition: periph_cpu.h:468
PWM device configuration.
uint8_t pwm_slice
PWM slice instance, must be < to PWM_SLICE_NUMOF.
Definition: periph_cpu.h:423
SPI device configuration.
Definition: periph_cpu.h:336
SPI0_Type * dev
Base address of the I/O registers of the device.
Definition: periph_cpu.h:804
gpio_t clk_pin
GPIO pin to use for CLK.
Definition: periph_cpu.h:807
Configuration type of a timer channel.
Definition: periph_cpu.h:447
IRQn_Type irqn
timer channel interrupt number
Definition: periph_cpu.h:448
Timer device configuration.
Definition: periph_cpu.h:263
const timer_channel_conf_t * ch
pointer to timer channel configuration
Definition: periph_cpu.h:458
uint8_t ch_numof
number of timer channels
Definition: periph_cpu.h:459
UART device configuration.
Definition: periph_cpu.h:217
UART0_Type * dev
Base address of the I/O registers of the device.
Definition: periph_cpu.h:433
Unit helper macros.
#define MHZ(x)
A macro to return the Hz in x MHz.
Definition: units.h:48
#define KHZ(x)
A macro to return the Hz in x kHz.
Definition: units.h:43