Loading...
Searching...
No Matches
periph_cpu.h File Reference

CPU specific definitions for internal peripheral handling. More...

Detailed Description

CPU specific definitions for internal peripheral handling.

Author
Koen Zandberg koen@.nosp@m.berg.nosp@m.zand..nosp@m.net
Gunar Schorcht gunar.nosp@m.@sch.nosp@m.orcht.nosp@m..net

Definition in file periph_cpu.h.

#include <inttypes.h>
#include "cpu.h"
#include "clic.h"
#include "kernel_defines.h"
#include "macros/units.h"
+ Include dependency graph for periph_cpu.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

union  gpio_conf_gd32v
 GPIO pin configuration for GD32V MCUs. More...
 
struct  adc_conf_t
 ADC device configuration. More...
 
struct  dac_conf_t
 DAC line configuration data. More...
 
struct  timer_conf_t
 Timer device configuration. More...
 
struct  uart_conf_t
 UART device configuration. More...
 
struct  spi_conf_t
 SPI device configuration. More...
 
struct  i2c_conf_t
 I2C configuration structure. More...
 
struct  pwm_chan_t
 PWM channel. More...
 
struct  pwm_conf_t
 PWM device configuration. More...
 

Macros

#define ADC_DEVS   (2U)
 Available number of ADC devices.
 
#define DAC_CHANNEL_NUMOF   (2)
 GD32V DAC has 2 channels.
 
#define TIMER_CHANNEL_NUMOF   (4U)
 GD32V timers have 4 capture-compare channels.
 
#define TIMER_CHANNEL(tim, chan)   *(&dev(tim)->CH0CV + (chan * 2))
 Macro for accessing the capture/compare register of a timer channel.
 
#define UART_ISR_PRIO   (2)
 UART interrupt priority.
 
#define SPI_HWCS_MASK   (0xffffff00)
 Define a magic number that tells us to use hardware chip select.
 
#define SPI_HWCS(x)   (SPI_HWCS_MASK | x)
 Override the default SPI hardware chip select access macro.
 
#define SPI_CS_UNDEF   (GPIO_UNDEF)
 Define value for unused CS line.
 
#define WDT_INTR_PRIORITY   (PLIC_NUM_PRIORITIES)
 WDT interrupt priority: use highest priority.
 
#define WDT_HAS_STOP   (0)
 No brakes on the WDT train.
 

Enumerations

enum  bus_t { AHB , APB1 , APB2 }
 On-Chip buses. More...
 
enum  
 Available GPIO ports. More...
 
enum  gpio_af_t { GPIO_AF_OUT_PP = 0xb , GPIO_AF_OUT_OD = 0xf }
 Override alternative GPIO mode options. More...
 

Functions

void gpio_init_af (gpio_t pin, gpio_af_t af)
 Configure the alternate function for the given pin.
 
void gpio_init_analog (gpio_t pin)
 Configure the given pin to be used as ADC input.
 
void periph_clk_en (bus_t bus, uint32_t mask)
 Enable the given peripheral clock.
 
void periph_clk_dis (bus_t bus, uint32_t mask)
 Disable the given peripheral clock.
 
uint32_t periph_apb_clk (bus_t bus)
 Get the actual bus clock frequency for the APB buses.
 
void gd32vf103_clock_init (void)
 
void gd32v_enable_irc8 (void)
 
void gd32v_disable_irc8 (void)
 

Power management configuration

#define PM_NUM_MODES   (3U)
 Number of usable low power modes.
 
#define CONFIG_PM_EWUP_USED   (0U)
 Wake-up pin used.
 
enum  { GD32V_PM_STANDBY = 0 , GD32V_PM_DEEPSLEEP = 1 , GD32V_PM_IDLE = 2 }
 Power modes. More...
 
#define PERIPH_SPI_NEEDS_TRANSFER_BYTE
 Use the shared SPI functions.
 
#define PERIPH_SPI_NEEDS_TRANSFER_REG
 Use transfer reg function from periph common.
 
#define PERIPH_SPI_NEEDS_TRANSFER_REGS
 Use transfer regs function from periph common.
 
#define HAVE_SPI_CLK_T
 Override SPI clock speed values.
 
enum  {
  SPI_CLK_100KHZ = KHZ(100) , SPI_CLK_400KHZ = KHZ(400) , SPI_CLK_1MHZ = MHZ(1) , SPI_CLK_5MHZ = MHZ(5) ,
  SPI_CLK_10MHZ = MHZ(10)
}
 
typedef uint32_t spi_clk_t
 SPI clock type.
 

Use the shared I2C functions

#define PERIPH_I2C_NEED_READ_REG
 Use read reg function from periph common.
 
#define PERIPH_I2C_NEED_WRITE_REG
 Use write reg function from periph common.
 
#define PERIPH_I2C_NEED_READ_REGS
 Use read regs function from periph common.
 
#define PERIPH_I2C_NEED_WRITE_REGS
 Use write regs function from periph common.
 

WDT upper and lower bound times in ms

#define NWDT_TIME_LOWER_LIMIT   (1)
 
#define NWDT_TIME_UPPER_LIMIT   ((UINT32_MAX >> 15) * MS_PER_SEC + 1)
 

RTT/RTC configuration

#define RTT_DEV   RTC
 RTC is used as RTT device.
 
#define RTT_IRQ   RTC_ALARM_IRQn
 RTC_ALARM_IRQn is used as IRQ number.
 
#define RTT_IRQ_PRIORITY   (2)
 RTT interrupt priority.
 
#define RTT_MAX_VALUE   (0xffffffff)
 maximum RTT value
 
#define RTT_MIN_FREQUENCY   (1U)
 minimum RTT frequency in Hz
 

USB device definitions

#define USBDEV_SET_ADDR_AFTER_STATUS   0
 Set device address after SETUP stage.
 
#define USBDEV_NUM_ENDPOINTS   4
 Number of USB OTG FS endpoints including EP0.
 

Macro Definition Documentation

◆ ADC_DEVS

#define ADC_DEVS   (2U)

Available number of ADC devices.

Definition at line 282 of file periph_cpu.h.

◆ CONFIG_PM_EWUP_USED

#define CONFIG_PM_EWUP_USED   (0U)

Wake-up pin used.

Definition at line 70 of file periph_cpu.h.

◆ DAC_CHANNEL_NUMOF

#define DAC_CHANNEL_NUMOF   (2)

GD32V DAC has 2 channels.

Definition at line 296 of file periph_cpu.h.

◆ HAVE_SPI_CLK_T

#define HAVE_SPI_CLK_T

Override SPI clock speed values.

Definition at line 391 of file periph_cpu.h.

◆ NWDT_TIME_LOWER_LIMIT

#define NWDT_TIME_LOWER_LIMIT   (1)

Definition at line 493 of file periph_cpu.h.

◆ NWDT_TIME_UPPER_LIMIT

#define NWDT_TIME_UPPER_LIMIT   ((UINT32_MAX >> 15) * MS_PER_SEC + 1)

Definition at line 498 of file periph_cpu.h.

◆ PERIPH_I2C_NEED_READ_REG

#define PERIPH_I2C_NEED_READ_REG

Use read reg function from periph common.

Definition at line 430 of file periph_cpu.h.

◆ PERIPH_I2C_NEED_READ_REGS

#define PERIPH_I2C_NEED_READ_REGS

Use read regs function from periph common.

Definition at line 434 of file periph_cpu.h.

◆ PERIPH_I2C_NEED_WRITE_REG

#define PERIPH_I2C_NEED_WRITE_REG

Use write reg function from periph common.

Definition at line 432 of file periph_cpu.h.

◆ PERIPH_I2C_NEED_WRITE_REGS

#define PERIPH_I2C_NEED_WRITE_REGS

Use write regs function from periph common.

Definition at line 436 of file periph_cpu.h.

◆ PERIPH_SPI_NEEDS_TRANSFER_BYTE

#define PERIPH_SPI_NEEDS_TRANSFER_BYTE

Use the shared SPI functions.

Use transfer byte function from periph common

Definition at line 380 of file periph_cpu.h.

◆ PERIPH_SPI_NEEDS_TRANSFER_REG

#define PERIPH_SPI_NEEDS_TRANSFER_REG

Use transfer reg function from periph common.

Definition at line 382 of file periph_cpu.h.

◆ PERIPH_SPI_NEEDS_TRANSFER_REGS

#define PERIPH_SPI_NEEDS_TRANSFER_REGS

Use transfer regs function from periph common.

Definition at line 384 of file periph_cpu.h.

◆ PM_NUM_MODES

#define PM_NUM_MODES   (3U)

Number of usable low power modes.

Number of usable low power modes

Definition at line 42 of file periph_cpu.h.

◆ RTT_DEV

#define RTT_DEV   RTC

RTC is used as RTT device.

Definition at line 515 of file periph_cpu.h.

◆ RTT_IRQ

#define RTT_IRQ   RTC_ALARM_IRQn

RTC_ALARM_IRQn is used as IRQ number.

Definition at line 517 of file periph_cpu.h.

◆ RTT_IRQ_PRIORITY

#define RTT_IRQ_PRIORITY   (2)

RTT interrupt priority.

Definition at line 518 of file periph_cpu.h.

◆ RTT_MAX_VALUE

#define RTT_MAX_VALUE   (0xffffffff)

maximum RTT value

Definition at line 519 of file periph_cpu.h.

◆ RTT_MIN_FREQUENCY

#define RTT_MIN_FREQUENCY   (1U)

minimum RTT frequency in Hz

Definition at line 521 of file periph_cpu.h.

◆ SPI_CS_UNDEF

#define SPI_CS_UNDEF   (GPIO_UNDEF)

Define value for unused CS line.

Definition at line 363 of file periph_cpu.h.

◆ SPI_HWCS

#define SPI_HWCS (   x)    (SPI_HWCS_MASK | x)

Override the default SPI hardware chip select access macro.

Since the CPU does only support one single hardware chip select line, we can detect the usage of non-valid lines by comparing to SPI_HWCS_VALID.

Definition at line 358 of file periph_cpu.h.

◆ SPI_HWCS_MASK

#define SPI_HWCS_MASK   (0xffffff00)

Define a magic number that tells us to use hardware chip select.

We use a random value here, that does clearly differentiate from any possible GPIO_PIN(x) value.

Definition at line 350 of file periph_cpu.h.

◆ TIMER_CHANNEL

#define TIMER_CHANNEL (   tim,
  chan 
)    *(&dev(tim)->CH0CV + (chan * 2))

Macro for accessing the capture/compare register of a timer channel.

Definition at line 314 of file periph_cpu.h.

◆ TIMER_CHANNEL_NUMOF

#define TIMER_CHANNEL_NUMOF   (4U)

GD32V timers have 4 capture-compare channels.

Definition at line 309 of file periph_cpu.h.

◆ UART_ISR_PRIO

#define UART_ISR_PRIO   (2)

UART interrupt priority.

Definition at line 342 of file periph_cpu.h.

◆ USBDEV_NUM_ENDPOINTS

#define USBDEV_NUM_ENDPOINTS   4

Number of USB OTG FS endpoints including EP0.

Definition at line 529 of file periph_cpu.h.

◆ USBDEV_SET_ADDR_AFTER_STATUS

#define USBDEV_SET_ADDR_AFTER_STATUS   0

Set device address after SETUP stage.

Definition at line 528 of file periph_cpu.h.

◆ WDT_HAS_STOP

#define WDT_HAS_STOP   (0)

No brakes on the WDT train.

Definition at line 509 of file periph_cpu.h.

◆ WDT_INTR_PRIORITY

#define WDT_INTR_PRIORITY   (PLIC_NUM_PRIORITIES)

WDT interrupt priority: use highest priority.

Definition at line 504 of file periph_cpu.h.

Typedef Documentation

◆ spi_clk_t

typedef uint32_t spi_clk_t

SPI clock type.

Definition at line 403 of file periph_cpu.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Power modes.

The GD32V has three power modes (terminology as defined by GigaDevice).

  • Sleep: Only the clock of the RISC-V core is switched off.
  • Deep sleep: The RISC-V core including all AHB and APB peripheralsa and all high speed clocks are off. The LDO is in operation and the SRAM is retained. The MCU can be woken up by external interrupts or events without restart.
  • Standby: The RISC-V core including all AHB and APB peripherals, all high-speed clocks, and the LDO are off. The SRAM is not retained. The MCU can be woken up by WKUP or the NRST pin, watchdog reset and RTC alarms with restart.
Enumerator
GD32V_PM_STANDBY 

STANDBY mode,

GD32V_PM_DEEPSLEEP 

DEEPSLEEP mode, corresponds to STOP mode of STM32.

GD32V_PM_IDLE 

IDLE mode.

Definition at line 60 of file periph_cpu.h.

◆ anonymous enum

anonymous enum

Available GPIO ports.

Definition at line 86 of file periph_cpu.h.

◆ anonymous enum

anonymous enum
Enumerator
SPI_CLK_100KHZ 

drive the SPI bus with 100KHz

SPI_CLK_400KHZ 

drive the SPI bus with 400KHz

SPI_CLK_1MHZ 

drive the SPI bus with 1MHz

SPI_CLK_5MHZ 

drive the SPI bus with 5MHz

SPI_CLK_10MHZ 

drive the SPI bus with 10MHz

Definition at line 392 of file periph_cpu.h.

◆ bus_t

enum bus_t

On-Chip buses.

Enumerator
AHB 

Advanced High-performance Bus.

APB1 

Advanced Peripheral Bus 1

APB2 

Advanced Peripheral Bus 2

Definition at line 77 of file periph_cpu.h.

◆ gpio_af_t

enum gpio_af_t

Override alternative GPIO mode options.

Enumerator
GPIO_AF_OUT_PP 

alternate function output - push-pull

GPIO_AF_OUT_OD 

alternate function output - open-drain

Definition at line 166 of file periph_cpu.h.

Function Documentation

◆ gpio_init_af()

void gpio_init_af ( gpio_t  pin,
gpio_af_t  af 
)

Configure the alternate function for the given pin.

Parameters
[in]pinpin to configure
[in]afalternate function to use

◆ gpio_init_analog()

void gpio_init_analog ( gpio_t  pin)

Configure the given pin to be used as ADC input.

Parameters
[in]pinpin to configure

◆ periph_apb_clk()

uint32_t periph_apb_clk ( bus_t  bus)

Get the actual bus clock frequency for the APB buses.

Parameters
[in]bustarget APBx bus
Returns
bus clock frequency in Hz

◆ periph_clk_dis()

void periph_clk_dis ( bus_t  bus,
uint32_t  mask 
)

Disable the given peripheral clock.

Parameters
[in]busbus the peripheral is connected to
[in]maskbit in the RCU enable register

◆ periph_clk_en()

void periph_clk_en ( bus_t  bus,
uint32_t  mask 
)

Enable the given peripheral clock.

Parameters
[in]busbus the peripheral is connected to
[in]maskbit in the RCU enable register