1# Copyright (c) 2021 ATL-Electronics 2# SPDX-License-Identifier: Apache-2.0 3 4if(CONFIG_HAS_GD32_HAL) 5 6string(TOUPPER ${CONFIG_SOC} gd32_soc_uc) 7 8set(gd32_soc_dir ${ZEPHYR_HAL_GIGADEVICE_MODULE_DIR}/${CONFIG_SOC_SERIES}) 9if(CONFIG_SOC_FAMILY_GD32_ARM) 10 set(gd32_soc_sys_dir ${gd32_soc_dir}/cmsis/gd/${CONFIG_SOC_SERIES}) 11elseif(CONFIG_SOC_SERIES_GD32VF103) 12 set(gd32_soc_sys_dir ${gd32_soc_dir}/riscv) 13 zephyr_include_directories(${gd32_soc_dir}/riscv/drivers) 14endif() 15 16set(gd32_std_dir ${gd32_soc_dir}/standard_peripheral) 17set(gd32_std_src_dir ${gd32_std_dir}/source) 18 19zephyr_library_named(hal_gigadevice) 20 21zephyr_compile_definitions(${gd32_soc_uc}) 22 23# The header files of GigaDevice firmware are reference HXTAL_VALUE. 24# The HXTAL_VALUE has the possibility of being referenced from any files 25# via that header files. 26# Therefore, we need to define HXTAL_VALUE for all compilations. 27if(${CONFIG_GD32_HXTAL_8MHZ}) 28 zephyr_compile_definitions(HXTAL_VALUE=8000000 HXTAL_VALUE_25M=8000000) 29elseif(${CONFIG_GD32_HXTAL_25MHZ}) 30 zephyr_compile_definitions(HXTAL_VALUE=25000000 HXTAL_VALUE_8M=25000000) 31endif() 32 33if(CONFIG_GD32_HAS_IRC_32K) 34 zephyr_compile_definitions(IRC32K_VALUE=${CONFIG_GD32_LOW_SPEED_IRC_FREQUENCY}) 35endif() 36 37if(CONFIG_GD32_HAS_IRC_40K) 38 zephyr_compile_definitions(IRC40K_VALUE=${CONFIG_GD32_LOW_SPEED_IRC_FREQUENCY}) 39endif() 40 41# GD32E50X series HAL public headers require extra definitions 42if(${CONFIG_SOC_SERIES_GD32E50X}) 43 zephyr_compile_definitions(GD32E50X) 44 if (${CONFIG_SOC_GD32E507}) 45 zephyr_compile_definitions(GD32E50X_CL) 46 endif() 47endif() 48 49# GD32A50X series HAL public headers require extra definitions 50if(${CONFIG_SOC_SERIES_GD32A50X}) 51 zephyr_compile_definitions(GD32A50X) 52endif() 53 54# Global includes to be used outside hal_gigadevice 55zephyr_include_directories(${gd32_soc_sys_dir}/include) 56zephyr_include_directories(${gd32_std_dir}/include) 57zephyr_include_directories(${ZEPHYR_HAL_GIGADEVICE_MODULE_DIR}/include) 58zephyr_include_directories(${ZEPHYR_HAL_GIGADEVICE_MODULE_DIR}/common_include) 59 60zephyr_library_sources(${gd32_soc_sys_dir}/source/system_${CONFIG_SOC_SERIES}.c) 61 62zephyr_library_sources_ifdef(CONFIG_USE_GD32_ADC ${gd32_std_src_dir}/${CONFIG_SOC_SERIES}_adc.c) 63zephyr_library_sources_ifdef(CONFIG_USE_GD32_BKP ${gd32_std_src_dir}/${CONFIG_SOC_SERIES}_bkp.c) 64zephyr_library_sources_ifdef(CONFIG_USE_GD32_CAN ${gd32_std_src_dir}/${CONFIG_SOC_SERIES}_can.c) 65zephyr_library_sources_ifdef(CONFIG_USE_GD32_CMP ${gd32_std_src_dir}/${CONFIG_SOC_SERIES}_cmp.c) 66zephyr_library_sources_ifdef(CONFIG_USE_GD32_CEC ${gd32_std_src_dir}/${CONFIG_SOC_SERIES}_cec.c) 67zephyr_library_sources_ifdef(CONFIG_USE_GD32_CRC ${gd32_std_src_dir}/${CONFIG_SOC_SERIES}_crc.c) 68zephyr_library_sources_ifdef(CONFIG_USE_GD32_CTC ${gd32_std_src_dir}/${CONFIG_SOC_SERIES}_ctc.c) 69zephyr_library_sources_ifdef(CONFIG_USE_GD32_DAC ${gd32_std_src_dir}/${CONFIG_SOC_SERIES}_dac.c) 70zephyr_library_sources_ifdef(CONFIG_USE_GD32_DBG ${gd32_std_src_dir}/${CONFIG_SOC_SERIES}_dbg.c) 71zephyr_library_sources_ifdef(CONFIG_USE_GD32_DCI ${gd32_std_src_dir}/${CONFIG_SOC_SERIES}_dci.c) 72zephyr_library_sources_ifdef(CONFIG_USE_GD32_DMA ${gd32_std_src_dir}/${CONFIG_SOC_SERIES}_dma.c) 73zephyr_library_sources_ifdef(CONFIG_USE_GD32_ENET ${gd32_std_src_dir}/${CONFIG_SOC_SERIES}_enet.c) 74zephyr_library_sources_ifdef(CONFIG_USE_GD32_EXMC ${gd32_std_src_dir}/${CONFIG_SOC_SERIES}_exmc.c) 75zephyr_library_sources_ifdef(CONFIG_USE_GD32_EXTI ${gd32_std_src_dir}/${CONFIG_SOC_SERIES}_exti.c) 76zephyr_library_sources_ifdef(CONFIG_USE_GD32_FMC ${gd32_std_src_dir}/${CONFIG_SOC_SERIES}_fmc.c) 77zephyr_library_sources_ifdef(CONFIG_USE_GD32_FWDGT ${gd32_std_src_dir}/${CONFIG_SOC_SERIES}_fwdgt.c) 78zephyr_library_sources_ifdef(CONFIG_USE_GD32_GPIO ${gd32_std_src_dir}/${CONFIG_SOC_SERIES}_gpio.c) 79zephyr_library_sources_ifdef(CONFIG_USE_GD32_I2C ${gd32_std_src_dir}/${CONFIG_SOC_SERIES}_i2c.c) 80zephyr_library_sources_ifdef(CONFIG_USE_GD32_IPA ${gd32_std_src_dir}/${CONFIG_SOC_SERIES}_ipa.c) 81zephyr_library_sources_ifdef(CONFIG_USE_GD32_IREF ${gd32_std_src_dir}/${CONFIG_SOC_SERIES}_iref.c) 82zephyr_library_sources_ifdef(CONFIG_USE_GD32_MISC ${gd32_std_src_dir}/${CONFIG_SOC_SERIES}_misc.c) 83zephyr_library_sources_ifdef(CONFIG_USE_GD32_PMU ${gd32_std_src_dir}/${CONFIG_SOC_SERIES}_pmu.c) 84zephyr_library_sources_ifdef(CONFIG_USE_GD32_RCU ${gd32_std_src_dir}/${CONFIG_SOC_SERIES}_rcu.c) 85zephyr_library_sources_ifdef(CONFIG_USE_GD32_RTC ${gd32_std_src_dir}/${CONFIG_SOC_SERIES}_rtc.c) 86zephyr_library_sources_ifdef(CONFIG_USE_GD32_SDIO ${gd32_std_src_dir}/${CONFIG_SOC_SERIES}_sdio.c) 87zephyr_library_sources_ifdef(CONFIG_USE_GD32_SHRTIMER ${gd32_std_src_dir}/${CONFIG_SOC_SERIES}_shrtimer.c) 88zephyr_library_sources_ifdef(CONFIG_USE_GD32_SPI ${gd32_std_src_dir}/${CONFIG_SOC_SERIES}_spi.c) 89zephyr_library_sources_ifdef(CONFIG_USE_GD32_SYSCFG ${gd32_std_src_dir}/${CONFIG_SOC_SERIES}_syscfg.c) 90zephyr_library_sources_ifdef(CONFIG_USE_GD32_TIMER ${gd32_std_src_dir}/${CONFIG_SOC_SERIES}_timer.c) 91zephyr_library_sources_ifdef(CONFIG_USE_GD32_TLI ${gd32_std_src_dir}/${CONFIG_SOC_SERIES}_tli.c) 92zephyr_library_sources_ifdef(CONFIG_USE_GD32_TMU ${gd32_std_src_dir}/${CONFIG_SOC_SERIES}_tmu.c) 93zephyr_library_sources_ifdef(CONFIG_USE_GD32_TRNG ${gd32_std_src_dir}/${CONFIG_SOC_SERIES}_trng.c) 94zephyr_library_sources_ifdef(CONFIG_USE_GD32_TSI ${gd32_std_src_dir}/${CONFIG_SOC_SERIES}_tsi.c) 95zephyr_library_sources_ifdef(CONFIG_USE_GD32_USART ${gd32_std_src_dir}/${CONFIG_SOC_SERIES}_usart.c) 96zephyr_library_sources_ifdef(CONFIG_USE_GD32_WWDGT ${gd32_std_src_dir}/${CONFIG_SOC_SERIES}_wwdgt.c) 97 98endif() 99