[Add] First commit

This commit is contained in:
gaoyang3513
2023-05-18 18:53:00 +08:00
commit 179cffc2c1
6607 changed files with 2163514 additions and 0 deletions

63
NSPE/CMakeLists.txt Normal file
View File

@ -0,0 +1,63 @@
cmake_minimum_required(VERSION 3.15)
set(TARGET_EXE nspe)
set(TAGET_PROJECT_DIR ${PROJECT_SOURCE_DIR}/NSPE/Project/WIFI_IOT)
add_executable(${TARGET_EXE})
add_subdirectory(Firmware/GD32W51x_standard_peripheral)
add_subdirectory(Firmware/GD32W51x_wifi_driver)
add_subdirectory(Firmware/CMSIS)
add_subdirectory(WIFI_IOT)
set_target_properties(${TARGET_EXE}
PROPERTIES
SUFFIX ".axf"
ARCHIVE_OUTPUT_DIRECTORY "${TAGET_PROJECT_DIR}/GCC/output/lib"
LIBRARY_OUTPUT_DIRECTORY "${TAGET_PROJECT_DIR}/GCC/output/lib"
RUNTIME_OUTPUT_DIRECTORY "${TAGET_PROJECT_DIR}/GCC/output/bin"
)
target_add_scatter_file(${TARGET_EXE}
${TAGET_PROJECT_DIR}/GCC/nspe_gdm32_ns.ld
)
if (CONFIG_STATIC_LIB_BUILDED)
add_library(gd32w51x_wifi STATIC IMPORTED GLOBAL)
set_target_properties(gd32w51x_wifi
PROPERTIES IMPORTED_LOCATION
${PROJECT_SOURCE_DIR}/NSPE/WIFI_IOT/lib/GCC/libgd32w51x_wifi.a)
endif()
target_link_libraries(${TARGET_EXE}
PRIVATE
gd32w51x_wifi
)
target_link_libraries(${TARGET_EXE}
PRIVATE
app
gd32w51x_peripheral
bsp
common
lwIP
mbedtls_ssl
wifi
os
cmsis
)
target_link_options(${TARGET_EXE}
PUBLIC
-Wl,--just-symbols=${PROJECT_SOURCE_DIR}/ROM-EXPORT/symbol/rom_symbol.gcc
-Wl,-Map=${TAGET_PROJECT_DIR}/GCC/output/bin/${TARGET_EXE}.map
-Wl,--cref
)
add_custom_command(TARGET ${TARGET_EXE} POST_BUILD
COMMAND ${TAGET_PROJECT_DIR}/nspe_afterbuild.bat ${TAGET_PROJECT_DIR}/GCC/output/bin GCC \"\"
COMMENT "Building ${TARGET_EXE}"
)

View File

@ -0,0 +1,160 @@
/*!
\file gd32w51x_it.c
\brief interrupt service routines
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "gd32w51x_it.h"
#include "systick.h"
#include "gd32w515p_eval.h"
extern uint8_t data;
/*!
\brief this function handles NMI exception
\param[in] none
\param[out] none
\retval none
*/
void NMI_Handler(void)
{
}
/*!
\brief this function handles HardFault exception
\param[in] none
\param[out] none
\retval none
*/
void HardFault_Handler(void)
{
/* if Hard Fault exception occurs, go to infinite loop */
while (1){
}
}
/*!
\brief this function handles MemManage exception
\param[in] none
\param[out] none
\retval none
*/
void MemManage_Handler(void)
{
/* if Memory Manage exception occurs, go to infinite loop */
while (1){
}
}
/*!
\brief this function handles BusFault exception
\param[in] none
\param[out] none
\retval none
*/
void BusFault_Handler(void)
{
/* if Bus Fault exception occurs, go to infinite loop */
while (1){
}
}
/*!
\brief this function handles UsageFault exception
\param[in] none
\param[out] none
\retval none
*/
void UsageFault_Handler(void)
{
/* if Usage Fault exception occurs, go to infinite loop */
while (1){
}
}
/*!
\brief this function handles SVC exception
\param[in] none
\param[out] none
\retval none
*/
void SVC_Handler(void)
{
}
/*!
\brief this function handles DebugMon exception
\param[in] none
\param[out] none
\retval none
*/
void DebugMon_Handler(void)
{
}
/*!
\brief this function handles PendSV exception
\param[in] none
\param[out] none
\retval none
*/
void PendSV_Handler(void)
{
}
/*!
\brief this function handles SysTick exception
\param[in] none
\param[out] none
\retval none
*/
void SysTick_Handler(void)
{
delay_decrement();
}
/*!
\brief this function handles ADC exception
\param[in] none
\param[out] none
\retval none
*/
void ADC_IRQHandler(void)
{
if(SET == adc_interrupt_flag_get(ADC_INT_FLAG_WDE)){
/* clear the ADC interrupt or status flag */
adc_interrupt_flag_clear(ADC_INT_FLAG_WDE);
/* turn on LED2 */
gd_eval_led_on(LED2);
data = 1U;
}
}

View File

@ -0,0 +1,62 @@
/*!
\file gd32w51x_it.h
\brief the header file of the ISR
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#ifndef GD32W51X_IT_H
#define GD32W51X_IT_H
#include "gd32w51x.h"
/* function declarations */
/* this function handles NMI exception */
void NMI_Handler(void);
/* this function handles HardFault exception */
void HardFault_Handler(void);
/* this function handles MemManage exception */
void MemManage_Handler(void);
/* this function handles BusFault exception */
void BusFault_Handler(void);
/* this function handles UsageFault exception */
void UsageFault_Handler(void);
/* this function handles SVC exception */
void SVC_Handler(void);
/* this function handles DebugMon exception */
void DebugMon_Handler(void);
/* this function handles PendSV exception */
void PendSV_Handler(void);
/* this function handles SysTick exception */
void SysTick_Handler(void);
/* this function handles ADC exception */
void ADC_IRQHandler(void);
#endif /* GD32W51X_IT_H */

View File

@ -0,0 +1,70 @@
/*!
\file gd32w51x_libopt.h
\brief library optional for gd32w51x
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#ifndef GD32W51X_LIBOPT_H
#define GD32W51X_LIBOPT_H
#include "gd32w51x_adc.h"
#include "gd32w51x_cau.h"
#include "gd32w51x_crc.h"
#include "gd32w51x_dbg.h"
#include "gd32w51x_dci.h"
#include "gd32w51x_dma.h"
#include "gd32w51x_efuse.h"
#include "gd32w51x_exti.h"
#include "gd32w51x_fmc.h"
#include "gd32w51x_fwdgt.h"
#include "gd32w51x_gpio.h"
#include "gd32w51x_hau.h"
#include "gd32w51x_hpdf.h"
#include "gd32w51x_i2c.h"
#include "gd32w51x_icache.h"
#include "gd32w51x_misc.h"
#include "gd32w51x_pkcau.h"
#include "gd32w51x_pmu.h"
#include "gd32w51x_qspi.h"
#include "gd32w51x_rcu.h"
#include "gd32w51x_rtc.h"
#include "gd32w51x_sdio.h"
#include "gd32w51x_spi.h"
#include "gd32w51x_sqpi.h"
#include "gd32w51x_syscfg.h"
#include "gd32w51x_timer.h"
#include "gd32w51x_trng.h"
#include "gd32w51x_tsi.h"
#include "gd32w51x_tzpcu.h"
#include "gd32w51x_usart.h"
#include "gd32w51x_wwdgt.h"
#endif /* GD32W51X_LIBOPT_H */

View File

@ -0,0 +1,178 @@
/*!
\file main.c
\brief ADC analog watchdog demo
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "gd32w51x.h"
#include "systick.h"
#include <stdio.h>
#include "gd32w515p_eval.h"
#define BOARD_ADC_CHANNEL ADC_CHANNEL_0
#define ADC_GPIO_PORT GPIOA
#define ADC_GPIO_PIN GPIO_PIN_0
#define ADC_WATCHDOG_HT 0x0A00U
#define ADC_WATCHDOG_LT 0x0400U
uint8_t data;
uint16_t adc_value;
void rcu_config(void);
void gpio_config(void);
void nvic_config(void);
void adc_config(void);
/*!
\brief main function
\param[in] none
\param[out] none
\retval none
*/
int main(void)
{
/* system clocks configuration */
rcu_config();
/* systick configuration */
systick_config();
/* GPIO configuration */
gpio_config();
/* configure COM port */
gd_eval_com_init(EVAL_COM0);
/* NVIC configuration */
nvic_config();
/* ADC configuration */
adc_config();
while(1){
delay_1ms(1000);
/* ADC software trigger enable */
adc_software_trigger_enable(ADC_REGULAR_CHANNEL);
while(SET != adc_flag_get(ADC_FLAG_EOC)){
}
adc_flag_clear(ADC_FLAG_EOC);
adc_value = adc_regular_data_read();
printf("\r\n //*********************************//");
printf("\r\n ADC watchdog low threshold: 0x%04X", ADC_WATCHDOG_LT);
printf("\r\n ADC watchdog hgih threshold: 0x%04X", ADC_WATCHDOG_HT);
printf("\r\n ADC regular channel data = 0x%04X \r\n", adc_value);
if(1U == data){
/* turn off LED2 */
if((adc_value < ADC_WATCHDOG_HT) && (adc_value > ADC_WATCHDOG_LT)){
data = 0;
gd_eval_led_off(LED2);
}
}
}
}
/*!
\brief configure the different system clocks
\param[in] none
\param[out] none
\retval none
*/
void rcu_config(void)
{
/* enable GPIOC clock */
rcu_periph_clock_enable(RCU_GPIOA);
/* enable ADC clock */
rcu_periph_clock_enable(RCU_ADC);
/* config ADC clock */
adc_clock_config(ADC_ADCCK_HCLK_DIV5);
}
/*!
\brief configure the GPIO peripheral
\param[in] none
\param[out] none
\retval none
*/
void gpio_config(void)
{
/* configure led GPIO */
gd_eval_led_init(LED2);
/* config the GPIO as analog mode */
gpio_mode_set(ADC_GPIO_PORT, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, ADC_GPIO_PIN);
}
/*!
\brief configure interrupt priority
\param[in] none
\param[out] none
\retval none
*/
void nvic_config(void)
{
nvic_priority_group_set(NVIC_PRIGROUP_PRE2_SUB2);
nvic_irq_enable(ADC_IRQn, 0U, 0U);
}
/*!
\brief configure the ADC peripheral
\param[in] none
\param[out] none
\retval none
*/
void adc_config(void)
{
/* ADC data alignment config */
adc_data_alignment_config(ADC_DATAALIGN_RIGHT);
/* ADC channel length config */
adc_channel_length_config(ADC_REGULAR_CHANNEL, 1U);
/* ADC regular channel config */
adc_regular_channel_config(0U, BOARD_ADC_CHANNEL, ADC_SAMPLETIME_55POINT5);
adc_external_trigger_config(ADC_REGULAR_CHANNEL, EXTERNAL_TRIGGER_DISABLE);
/* enable ADC interface */
adc_enable();
delay_1ms(1U);
/* ADC analog watchdog threshold config */
adc_watchdog_threshold_config(ADC_WATCHDOG_LT, ADC_WATCHDOG_HT);
/* ADC analog watchdog single channel config */
adc_watchdog_single_channel_enable(BOARD_ADC_CHANNEL);
/* ADC interrupt config */
adc_interrupt_enable(ADC_INT_WDE);
}
/* retarget the C library printf function to the USART */
int fputc(int ch, FILE *f)
{
usart_data_transmit(EVAL_COM0, (uint8_t)ch);
while(RESET == usart_flag_get(EVAL_COM0, USART_FLAG_TBE));
return ch;
}

View File

@ -0,0 +1,45 @@
/*!
\file readme.txt
\brief description of the ADC analog watchdog demo
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
This demo is based on the GD32W515P-EVAL-V1.0 board, it shows how to use the ADC analog
watchdog to guard continuously an ADC channel. The ADC is configured in continuous mode,
PA0 is chosen as analog input pin.
Change the VR1 on the GD32W515P-EVAL-V1.0 board, when the channel0 converted value is
over the programmed analog watchdog high threshold (value 0x0A00) or below the analog
watchdog low threshold(value 0x0400), an WDE interrupt will occur, and LED2 will turn on.
When the channel0 converted value is in safe range(among 0x0400 and 0x0A00), the LED2
will be off.
The analog input pin should be configured to AIN mode.

View File

@ -0,0 +1,82 @@
/*!
\file systick.c
\brief the systick configuration file
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "gd32w51x.h"
#include "systick.h"
volatile static uint32_t delay;
/*!
\brief configure systick
\param[in] none
\param[out] none
\retval none
*/
void systick_config(void)
{
/* setup systick timer for 1000Hz interrupts */
if(SysTick_Config(SystemCoreClock / 1000U)){
/* capture error */
while(1){
}
}
/* configure the systick handler priority */
NVIC_SetPriority(SysTick_IRQn, 0x00U);
}
/*!
\brief delay a time in milliseconds
\param[in] count: count in milliseconds
\param[out] none
\retval none
*/
void delay_1ms(uint32_t count)
{
delay = count;
while(0U != delay){
}
}
/*!
\brief delay decrement
\param[in] none
\param[out] none
\retval none
*/
void delay_decrement(void)
{
if(0U != delay){
delay--;
}
}

View File

@ -0,0 +1,47 @@
/*!
\file systick.h
\brief the header file of systick
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#ifndef SYSTICK_H
#define SYSTICK_H
#include <stdint.h>
/* configure systick */
void systick_config(void);
/* delay a time in milliseconds */
void delay_1ms(uint32_t count);
/* delay decrement */
void delay_decrement(void);
#endif /* SYSTICK_H */

View File

@ -0,0 +1,159 @@
/*!
\file gd32w51x_it.c
\brief interrupt service routines
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "gd32w51x_it.h"
#include "systick.h"
#include "gd32w515p_eval.h"
extern uint16_t inserted_data[4];
/*!
\brief this function handles NMI exception
\param[in] none
\param[out] none
\retval none
*/
void NMI_Handler(void)
{
}
/*!
\brief this function handles HardFault exception
\param[in] none
\param[out] none
\retval none
*/
void HardFault_Handler(void)
{
/* if Hard Fault exception occurs, go to infinite loop */
while (1){
}
}
/*!
\brief this function handles MemManage exception
\param[in] none
\param[out] none
\retval none
*/
void MemManage_Handler(void)
{
/* if Memory Manage exception occurs, go to infinite loop */
while (1){
}
}
/*!
\brief this function handles BusFault exception
\param[in] none
\param[out] none
\retval none
*/
void BusFault_Handler(void)
{
/* if Bus Fault exception occurs, go to infinite loop */
while (1){
}
}
/*!
\brief this function handles UsageFault exception
\param[in] none
\param[out] none
\retval none
*/
void UsageFault_Handler(void)
{
/* if Usage Fault exception occurs, go to infinite loop */
while (1){
}
}
/*!
\brief this function handles SVC exception
\param[in] none
\param[out] none
\retval none
*/
void SVC_Handler(void)
{
}
/*!
\brief this function handles DebugMon exception
\param[in] none
\param[out] none
\retval none
*/
void DebugMon_Handler(void)
{
}
/*!
\brief this function handles PendSV exception
\param[in] none
\param[out] none
\retval none
*/
void PendSV_Handler(void)
{
}
/*!
\brief this function handles SysTick exception
\param[in] none
\param[out] none
\retval none
*/
void SysTick_Handler(void)
{
delay_decrement();
}
/*!
\brief this function handles ADC interrupt
\param[in] none
\param[out] none
\retval none
*/
void ADC_IRQHandler(void)
{
/* clear the ADC flag */
adc_interrupt_flag_clear(ADC_INT_FLAG_EOIC);
/* read ADC inserted group data register */
inserted_data[0] = adc_inserted_data_read(ADC_INSERTED_CHANNEL_0);
inserted_data[1] = adc_inserted_data_read(ADC_INSERTED_CHANNEL_1);
inserted_data[2] = adc_inserted_data_read(ADC_INSERTED_CHANNEL_2);
inserted_data[3] = adc_inserted_data_read(ADC_INSERTED_CHANNEL_3);
}

View File

@ -0,0 +1,62 @@
/*!
\file gd32w51x_it.h
\brief the header file of the ISR
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#ifndef GD32W51X_IT_H
#define GD32W51X_IT_H
#include "gd32w51x.h"
/* function declarations */
/* this function handles NMI exception */
void NMI_Handler(void);
/* this function handles HardFault exception */
void HardFault_Handler(void);
/* this function handles MemManage exception */
void MemManage_Handler(void);
/* this function handles BusFault exception */
void BusFault_Handler(void);
/* this function handles UsageFault exception */
void UsageFault_Handler(void);
/* this function handles SVC exception */
void SVC_Handler(void);
/* this function handles DebugMon exception */
void DebugMon_Handler(void);
/* this function handles PendSV exception */
void PendSV_Handler(void);
/* this function handles SysTick exception */
void SysTick_Handler(void);
/* this function handles ADC exception */
void ADC_IRQHandler(void);
#endif /* GD32W51X_IT_H */

View File

@ -0,0 +1,70 @@
/*!
\file gd32w51x_libopt.h
\brief library optional for gd32w51x
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#ifndef GD32W51X_LIBOPT_H
#define GD32W51X_LIBOPT_H
#include "gd32w51x_adc.h"
#include "gd32w51x_cau.h"
#include "gd32w51x_crc.h"
#include "gd32w51x_dbg.h"
#include "gd32w51x_dci.h"
#include "gd32w51x_dma.h"
#include "gd32w51x_efuse.h"
#include "gd32w51x_exti.h"
#include "gd32w51x_fmc.h"
#include "gd32w51x_fwdgt.h"
#include "gd32w51x_gpio.h"
#include "gd32w51x_hau.h"
#include "gd32w51x_hpdf.h"
#include "gd32w51x_i2c.h"
#include "gd32w51x_icache.h"
#include "gd32w51x_misc.h"
#include "gd32w51x_pkcau.h"
#include "gd32w51x_pmu.h"
#include "gd32w51x_qspi.h"
#include "gd32w51x_rcu.h"
#include "gd32w51x_rtc.h"
#include "gd32w51x_sdio.h"
#include "gd32w51x_spi.h"
#include "gd32w51x_sqpi.h"
#include "gd32w51x_syscfg.h"
#include "gd32w51x_timer.h"
#include "gd32w51x_trng.h"
#include "gd32w51x_tsi.h"
#include "gd32w51x_tzpcu.h"
#include "gd32w51x_usart.h"
#include "gd32w51x_wwdgt.h"
#endif /* GD32W51X_LIBOPT_H */

View File

@ -0,0 +1,244 @@
/*!
\file main.c
\brief EXTI trigger ADC regular and inserted channel demo
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "gd32w51x.h"
#include "systick.h"
#include <stdio.h>
#include "gd32w515p_eval.h"
uint16_t adc_value[4];
uint16_t inserted_data[4];
void rcu_config(void);
void gpio_config(void);
void nvic_config(void);
void dma_config(void);
void adc_config(void);
void exti_config(void);
/*!
\brief main function
\param[in] none
\param[out] none
\retval none
*/
int main(void)
{
/* system clocks configuration */
rcu_config();
/* GPIO configuration */
gpio_config();
/* configure the EXTI peripheral */
exti_config();
/* systick configuration */
systick_config();
/* NVIC configuration */
nvic_config();
/* configure COM port */
gd_eval_com_init(EVAL_COM0);
/* DMA configuration */
dma_config();
/* ADC configuration */
adc_config();
while(1){
delay_1ms(1000);
printf("\r\n ADC regular channel 0 data = %d \r\n", adc_value[0]);
printf(" ADC regular channel 1 data = %d \r\n", adc_value[1]);
printf(" ADC regular channel 2 data = %d \r\n", adc_value[2]);
printf(" ADC regular channel 3 data = %d \r\n", adc_value[3]);
printf("\r\n ADC inserted channel 0 data = %d \r\n", inserted_data[0]);
printf(" ADC inserted channel 1 data = %d \r\n", inserted_data[1]);
printf(" ADC inserted channel 2 data = %d \r\n", inserted_data[2]);
printf(" ADC inserted channel 3 data = %d \r\n", inserted_data[3]);
printf(" ***********************************\r\n");
}
}
/*!
\brief configure the different system clocks
\param[in] none
\param[out] none
\retval none
*/
void rcu_config(void)
{
/* enable GPIOA clock */
rcu_periph_clock_enable(RCU_GPIOA);
/* enable DMA clock */
rcu_periph_clock_enable(RCU_DMA1);
/* config ADC clock */
rcu_periph_clock_enable(RCU_ADC);
adc_clock_config(ADC_ADCCK_HCLK_DIV6);
}
/*!
\brief configure the GPIO peripheral
\param[in] none
\param[out] none
\retval none
*/
void gpio_config(void)
{
/* config the GPIO as analog mode, for ADC */
gpio_mode_set(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE,GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);
gpio_mode_set(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE,GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7);
/* config the GPIO as floating input mode, for EXTI */
gpio_mode_set(GPIOA, GPIO_MODE_INPUT, GPIO_PUPD_NONE, GPIO_PIN_11|GPIO_PIN_15);
}
/**
\brief configure the nested vectored interrupt controller
\param[in] none
\param[out] none
\retval none
*/
void nvic_config(void)
{
nvic_priority_group_set(NVIC_PRIGROUP_PRE1_SUB3);
nvic_irq_enable(ADC_IRQn, 1, 1);
}
/*!
\brief configure the DMA peripheral
\param[in] none
\param[out] none
\retval none
*/
void dma_config(void)
{
/* ADC_DMA_channel configuration */
dma_single_data_parameter_struct dma_single_data_parameter;
/* ADC DMA_channel configuration */
dma_deinit(DMA1, DMA_CH0);
/* initialize DMA single data mode */
dma_single_data_parameter.periph_addr = (uint32_t)(&ADC_RDATA);
dma_single_data_parameter.periph_inc = DMA_PERIPH_INCREASE_DISABLE;
dma_single_data_parameter.memory0_addr = (uint32_t)(&adc_value);
dma_single_data_parameter.memory_inc = DMA_MEMORY_INCREASE_ENABLE;
dma_single_data_parameter.periph_memory_width = DMA_PERIPH_WIDTH_16BIT;
dma_single_data_parameter.direction = DMA_PERIPH_TO_MEMORY;
dma_single_data_parameter.number = 4;
dma_single_data_parameter.priority = DMA_PRIORITY_HIGH;
dma_single_data_mode_init(DMA1, DMA_CH0, &dma_single_data_parameter);
dma_channel_subperipheral_select(DMA1, DMA_CH0, DMA_SUBPERI0);
/* enable DMA circulation mode */
dma_circulation_enable(DMA1, DMA_CH0);
/* enable DMA channel */
dma_channel_enable(DMA1, DMA_CH0);
}
/*!
\brief configure the ADC peripheral
\param[in] none
\param[out] none
\retval none
*/
void adc_config(void)
{
/* ADC scan function enable */
adc_special_function_config(ADC_SCAN_MODE, ENABLE);
/* ADC data alignment config */
adc_data_alignment_config(ADC_DATAALIGN_RIGHT);
/* ADC inserted channel length config */
adc_channel_length_config(ADC_INSERTED_CHANNEL, 4U);
/* ADC inserted channel config */
adc_inserted_channel_config(0, ADC_CHANNEL_0, ADC_SAMPLETIME_14POINT5);
adc_inserted_channel_config(1, ADC_CHANNEL_1, ADC_SAMPLETIME_14POINT5);
adc_inserted_channel_config(2, ADC_CHANNEL_2, ADC_SAMPLETIME_14POINT5);
adc_inserted_channel_config(3, ADC_CHANNEL_3, ADC_SAMPLETIME_14POINT5);
/* ADC inserted channel trigger config */
adc_external_trigger_source_config(ADC_INSERTED_CHANNEL, ADC_EXTTRIG_INSERTED_EXTI_15);
/* ADC inserted channel external trigger enable */
adc_external_trigger_config(ADC_INSERTED_CHANNEL, EXTERNAL_TRIGGER_RISING);
/* clear the ADC flag */
adc_interrupt_flag_clear(ADC_INT_FLAG_EOC);
adc_interrupt_flag_clear(ADC_INT_FLAG_EOIC);
/* enable ADC interrupt */
adc_interrupt_enable(ADC_INT_EOIC);
/* ADC regular channel length config */
adc_channel_length_config(ADC_REGULAR_CHANNEL, 4U);
/* ADC regular channel config */
adc_regular_channel_config(0, ADC_CHANNEL_4, ADC_SAMPLETIME_14POINT5);
adc_regular_channel_config(1, ADC_CHANNEL_5, ADC_SAMPLETIME_14POINT5);
adc_regular_channel_config(2, ADC_CHANNEL_6, ADC_SAMPLETIME_14POINT5);
adc_regular_channel_config(3, ADC_CHANNEL_7, ADC_SAMPLETIME_14POINT5);
/* ADC regular channel trigger config */
adc_external_trigger_source_config(ADC_REGULAR_CHANNEL, ADC_EXTTRIG_REGULAR_EXTI_11);
adc_external_trigger_config(ADC_REGULAR_CHANNEL, EXTERNAL_TRIGGER_RISING);
/* ADC regular channel discontinuous mode */
adc_discontinuous_mode_config(ADC_REGULAR_CHANNEL, 1);
/* ADC DMA function enable */
adc_dma_request_after_last_enable();
adc_dma_mode_enable();
/* enable ADC interface */
adc_enable();
/* wait for ADC stability */
delay_1ms(1);
}
/*!
\brief configure the EXTI peripheral
\param[in] none
\param[out] none
\retval none
*/
void exti_config(void)
{
/* connect EXTI line to GPIO pin for inserted group */
syscfg_exti_line_config(EXTI_SOURCE_GPIOA, EXTI_SOURCE_PIN15);
/* configure EXTI line for inserted group */
exti_init(EXTI_15, EXTI_EVENT, EXTI_TRIG_RISING);
exti_flag_clear(EXTI_15);
/* connect EXTI line to GPIO pin for inserted group */
syscfg_exti_line_config(EXTI_SOURCE_GPIOA, EXTI_SOURCE_PIN11);
/* configure EXTI line for inserted group */
exti_init(EXTI_11, EXTI_EVENT, EXTI_TRIG_RISING);
exti_flag_clear(EXTI_11);
}
/* retarget the C library printf function to the USART */
int fputc(int ch, FILE *f)
{
usart_data_transmit(EVAL_COM0, (uint8_t)ch);
while(RESET == usart_flag_get(EVAL_COM0, USART_FLAG_TBE));
return ch;
}

View File

@ -0,0 +1,48 @@
/*!
\file readme.txt
\brief description of the EXTI trigger ADC regular and inserted channel demo
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
This demo is based on the GD32W515P-EVAL-V1.0 board, it shows how to convert ADC
regular and inserted group channels using EXTI external triggers.
The inserted group length is 4, the scan mode is set, every rising edge event of
EXTI15 (PA15) will trigger ADC to convert all the channels in the inserted group. When
all inserted group channels are converted, EOIC Interrupt will be generated. The
inserted datas are print by USART.
The regular group is configured in discontinuous mode, group length is 4, conversion
length is 1, Every rising edge event of EXTI11 (PA11) converts 1 channel and DMA can be
used to transfer the converted data.
We can watch array adc_value[]/inserted_data[] in debug mode or by COM0.
Connect PA11/PA15 to key Tamper(PA2).

View File

@ -0,0 +1,82 @@
/*!
\file systick.c
\brief the systick configuration file
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "gd32w51x.h"
#include "systick.h"
volatile static uint32_t delay;
/*!
\brief configure systick
\param[in] none
\param[out] none
\retval none
*/
void systick_config(void)
{
/* setup systick timer for 1000Hz interrupts */
if(SysTick_Config(SystemCoreClock / 1000U)){
/* capture error */
while(1){
}
}
/* configure the systick handler priority */
NVIC_SetPriority(SysTick_IRQn, 0x00U);
}
/*!
\brief delay a time in milliseconds
\param[in] count: count in milliseconds
\param[out] none
\retval none
*/
void delay_1ms(uint32_t count)
{
delay = count;
while(0U != delay){
}
}
/*!
\brief delay decrement
\param[in] none
\param[out] none
\retval none
*/
void delay_decrement(void)
{
if(0U != delay){
delay--;
}
}

View File

@ -0,0 +1,47 @@
/*!
\file systick.h
\brief the header file of systick
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#ifndef SYSTICK_H
#define SYSTICK_H
#include <stdint.h>
/* configure systick */
void systick_config(void);
/* delay a time in milliseconds */
void delay_1ms(uint32_t count);
/* delay decrement */
void delay_decrement(void);
#endif /* SYSTICK_H */

View File

@ -0,0 +1,140 @@
/*!
\file gd32w51x_it.c
\brief interrupt service routines
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "gd32w51x_it.h"
#include "systick.h"
#include "gd32w515p_eval.h"
/*!
\brief this function handles NMI exception
\param[in] none
\param[out] none
\retval none
*/
void NMI_Handler(void)
{
}
/*!
\brief this function handles HardFault exception
\param[in] none
\param[out] none
\retval none
*/
void HardFault_Handler(void)
{
/* if Hard Fault exception occurs, go to infinite loop */
while (1){
}
}
/*!
\brief this function handles MemManage exception
\param[in] none
\param[out] none
\retval none
*/
void MemManage_Handler(void)
{
/* if Memory Manage exception occurs, go to infinite loop */
while (1){
}
}
/*!
\brief this function handles BusFault exception
\param[in] none
\param[out] none
\retval none
*/
void BusFault_Handler(void)
{
/* if Bus Fault exception occurs, go to infinite loop */
while (1){
}
}
/*!
\brief this function handles UsageFault exception
\param[in] none
\param[out] none
\retval none
*/
void UsageFault_Handler(void)
{
/* if Usage Fault exception occurs, go to infinite loop */
while (1){
}
}
/*!
\brief this function handles SVC exception
\param[in] none
\param[out] none
\retval none
*/
void SVC_Handler(void)
{
}
/*!
\brief this function handles DebugMon exception
\param[in] none
\param[out] none
\retval none
*/
void DebugMon_Handler(void)
{
}
/*!
\brief this function handles PendSV exception
\param[in] none
\param[out] none
\retval none
*/
void PendSV_Handler(void)
{
}
/*!
\brief this function handles SysTick exception
\param[in] none
\param[out] none
\retval none
*/
void SysTick_Handler(void)
{
delay_decrement();
}

View File

@ -0,0 +1,60 @@
/*!
\file gd32w51x_it.h
\brief the header file of the ISR
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#ifndef GD32W51X_IT_H
#define GD32W51X_IT_H
#include "gd32w51x.h"
/* function declarations */
/* this function handles NMI exception */
void NMI_Handler(void);
/* this function handles HardFault exception */
void HardFault_Handler(void);
/* this function handles MemManage exception */
void MemManage_Handler(void);
/* this function handles BusFault exception */
void BusFault_Handler(void);
/* this function handles UsageFault exception */
void UsageFault_Handler(void);
/* this function handles SVC exception */
void SVC_Handler(void);
/* this function handles DebugMon exception */
void DebugMon_Handler(void);
/* this function handles PendSV exception */
void PendSV_Handler(void);
/* this function handles SysTick exception */
void SysTick_Handler(void);
#endif /* GD32W51X_IT_H */

View File

@ -0,0 +1,70 @@
/*!
\file gd32w51x_libopt.h
\brief library optional for gd32w51x
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#ifndef GD32W51X_LIBOPT_H
#define GD32W51X_LIBOPT_H
#include "gd32w51x_adc.h"
#include "gd32w51x_cau.h"
#include "gd32w51x_crc.h"
#include "gd32w51x_dbg.h"
#include "gd32w51x_dci.h"
#include "gd32w51x_dma.h"
#include "gd32w51x_efuse.h"
#include "gd32w51x_exti.h"
#include "gd32w51x_fmc.h"
#include "gd32w51x_fwdgt.h"
#include "gd32w51x_gpio.h"
#include "gd32w51x_hau.h"
#include "gd32w51x_hpdf.h"
#include "gd32w51x_i2c.h"
#include "gd32w51x_icache.h"
#include "gd32w51x_misc.h"
#include "gd32w51x_pkcau.h"
#include "gd32w51x_pmu.h"
#include "gd32w51x_qspi.h"
#include "gd32w51x_rcu.h"
#include "gd32w51x_rtc.h"
#include "gd32w51x_sdio.h"
#include "gd32w51x_spi.h"
#include "gd32w51x_sqpi.h"
#include "gd32w51x_syscfg.h"
#include "gd32w51x_timer.h"
#include "gd32w51x_trng.h"
#include "gd32w51x_tsi.h"
#include "gd32w51x_tzpcu.h"
#include "gd32w51x_usart.h"
#include "gd32w51x_wwdgt.h"
#endif /* GD32W51X_LIBOPT_H */

View File

@ -0,0 +1,146 @@
/*!
\file main.c
\brief ADC oversample shift example demo
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "gd32w51x.h"
#include "systick.h"
#include <stdio.h>
#include "gd32w515p_eval.h"
#define BOARD_ADC_CHANNEL ADC_CHANNEL_0
#define ADC_GPIO_PORT GPIOA
#define ADC_GPIO_PIN GPIO_PIN_0
uint16_t adc_value = 0U;
void rcu_config(void);
void gpio_config(void);
void adc_config(void);
/*!
\brief main function
\param[in] none
\param[out] none
\retval none
*/
int main(void)
{
/* system clocks configuration */
rcu_config();
/* systick configuration */
systick_config();
/* GPIO configuration */
gpio_config();
/* ADC configuration */
adc_config();
/* configures COM port */
gd_eval_com_init(EVAL_COM0);
/* enable ADC software trigger for regular channel */
adc_software_trigger_enable(ADC_REGULAR_CHANNEL);
while(1){
adc_flag_clear(ADC_FLAG_EOC);
while(SET != adc_flag_get(ADC_FLAG_EOC)){
}
adc_value = ADC_RDATA;
printf("\r\n*ADC oversample shift example demo*\r\n");
printf("16 times sample, 4 bits shift: 0x%X\r\n", adc_value);
delay_1ms(1000U);
}
}
/*!
\brief configure the different system clocks
\param[in] none
\param[out] none
\retval none
*/
void rcu_config(void)
{
/* enable GPIOC clock */
rcu_periph_clock_enable(RCU_GPIOA);
/* config ADC clock */
rcu_periph_clock_enable(RCU_ADC);
adc_clock_config(ADC_ADCCK_HCLK_DIV6);
}
/*!
\brief configure the GPIO peripheral
\param[in] none
\param[out] none
\retval none
*/
void gpio_config(void)
{
/* config the GPIO as analog mode */
gpio_mode_set(ADC_GPIO_PORT, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, ADC_GPIO_PIN);
}
/*!
\brief configure the ADC peripheral
\param[in] none
\param[out] none
\retval none
*/
void adc_config(void)
{
/* ADC contineous function disable */
adc_special_function_config(ADC_CONTINUOUS_MODE, ENABLE);
/* ADC data alignment config */
adc_data_alignment_config(ADC_DATAALIGN_RIGHT);
/* ADC external trigger enable */
adc_external_trigger_config(ADC_REGULAR_CHANNEL, EXTERNAL_TRIGGER_DISABLE);
/* ADC channel length config */
adc_channel_length_config(ADC_REGULAR_CHANNEL, 1U);
/* ADC inserted channel config */
adc_regular_channel_config(0U, BOARD_ADC_CHANNEL, ADC_SAMPLETIME_55POINT5);
/* 16 times sample, 4 bits shift */
adc_oversample_mode_config(ADC_OVERSAMPLING_ALL_CONVERT, ADC_OVERSAMPLING_SHIFT_4B, ADC_OVERSAMPLING_RATIO_MUL16);
adc_oversample_mode_enable();
/* enable ADC interface */
adc_enable();
/* wait for ADC stability */
delay_1ms(1);
}
/* retarget the C library printf function to the USART */
int fputc(int ch, FILE *f)
{
usart_data_transmit(EVAL_COM0, (uint8_t)ch);
while(RESET == usart_flag_get(EVAL_COM0, USART_FLAG_TBE));
return ch;
}

View File

@ -0,0 +1,40 @@
/*!
\file readme.txt
\brief description of the ADC oversample shift example demo
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
This demo is based on the GD32W515P-EVAL-V1.0 board, it shows how to use the function
of oversample and shift. In this demo, 16 times ratio of oversample and 4 bits shift are
configured. PA0 (channel0) is chosen as analog input pin. The ADC conversion begins by
software, the converted data is printed by USART.
The analog input pin should configured to analog mode.

View File

@ -0,0 +1,82 @@
/*!
\file systick.c
\brief the systick configuration file
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "gd32w51x.h"
#include "systick.h"
volatile static uint32_t delay;
/*!
\brief configure systick
\param[in] none
\param[out] none
\retval none
*/
void systick_config(void)
{
/* setup systick timer for 1000Hz interrupts */
if(SysTick_Config(SystemCoreClock / 1000U)){
/* capture error */
while(1){
}
}
/* configure the systick handler priority */
NVIC_SetPriority(SysTick_IRQn, 0x00U);
}
/*!
\brief delay a time in milliseconds
\param[in] count: count in milliseconds
\param[out] none
\retval none
*/
void delay_1ms(uint32_t count)
{
delay = count;
while(0U != delay){
}
}
/*!
\brief delay decrement
\param[in] none
\param[out] none
\retval none
*/
void delay_decrement(void)
{
if(0U != delay){
delay--;
}
}

View File

@ -0,0 +1,47 @@
/*!
\file systick.h
\brief the header file of systick
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#ifndef SYSTICK_H
#define SYSTICK_H
#include <stdint.h>
/* configure systick */
void systick_config(void);
/* delay a time in milliseconds */
void delay_1ms(uint32_t count);
/* delay decrement */
void delay_decrement(void);
#endif /* SYSTICK_H */

View File

@ -0,0 +1,140 @@
/*!
\file gd32w51x_it.c
\brief interrupt service routines
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "gd32w51x_it.h"
#include "systick.h"
#include "gd32w515p_eval.h"
/*!
\brief this function handles NMI exception
\param[in] none
\param[out] none
\retval none
*/
void NMI_Handler(void)
{
}
/*!
\brief this function handles HardFault exception
\param[in] none
\param[out] none
\retval none
*/
void HardFault_Handler(void)
{
/* if Hard Fault exception occurs, go to infinite loop */
while (1){
}
}
/*!
\brief this function handles MemManage exception
\param[in] none
\param[out] none
\retval none
*/
void MemManage_Handler(void)
{
/* if Memory Manage exception occurs, go to infinite loop */
while (1){
}
}
/*!
\brief this function handles BusFault exception
\param[in] none
\param[out] none
\retval none
*/
void BusFault_Handler(void)
{
/* if Bus Fault exception occurs, go to infinite loop */
while (1){
}
}
/*!
\brief this function handles UsageFault exception
\param[in] none
\param[out] none
\retval none
*/
void UsageFault_Handler(void)
{
/* if Usage Fault exception occurs, go to infinite loop */
while (1){
}
}
/*!
\brief this function handles SVC exception
\param[in] none
\param[out] none
\retval none
*/
void SVC_Handler(void)
{
}
/*!
\brief this function handles DebugMon exception
\param[in] none
\param[out] none
\retval none
*/
void DebugMon_Handler(void)
{
}
/*!
\brief this function handles PendSV exception
\param[in] none
\param[out] none
\retval none
*/
void PendSV_Handler(void)
{
}
/*!
\brief this function handles SysTick exception
\param[in] none
\param[out] none
\retval none
*/
void SysTick_Handler(void)
{
delay_decrement();
}

View File

@ -0,0 +1,60 @@
/*!
\file gd32w51x_it.h
\brief the header file of the ISR
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#ifndef GD32W51X_IT_H
#define GD32W51X_IT_H
#include "gd32w51x.h"
/* function declarations */
/* this function handles NMI exception */
void NMI_Handler(void);
/* this function handles HardFault exception */
void HardFault_Handler(void);
/* this function handles MemManage exception */
void MemManage_Handler(void);
/* this function handles BusFault exception */
void BusFault_Handler(void);
/* this function handles UsageFault exception */
void UsageFault_Handler(void);
/* this function handles SVC exception */
void SVC_Handler(void);
/* this function handles DebugMon exception */
void DebugMon_Handler(void);
/* this function handles PendSV exception */
void PendSV_Handler(void);
/* this function handles SysTick exception */
void SysTick_Handler(void);
#endif /* GD32W51X_IT_H */

View File

@ -0,0 +1,70 @@
/*!
\file gd32w51x_libopt.h
\brief library optional for gd32w51x
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#ifndef GD32W51X_LIBOPT_H
#define GD32W51X_LIBOPT_H
#include "gd32w51x_adc.h"
#include "gd32w51x_cau.h"
#include "gd32w51x_crc.h"
#include "gd32w51x_dbg.h"
#include "gd32w51x_dci.h"
#include "gd32w51x_dma.h"
#include "gd32w51x_efuse.h"
#include "gd32w51x_exti.h"
#include "gd32w51x_fmc.h"
#include "gd32w51x_fwdgt.h"
#include "gd32w51x_gpio.h"
#include "gd32w51x_hau.h"
#include "gd32w51x_hpdf.h"
#include "gd32w51x_i2c.h"
#include "gd32w51x_icache.h"
#include "gd32w51x_misc.h"
#include "gd32w51x_pkcau.h"
#include "gd32w51x_pmu.h"
#include "gd32w51x_qspi.h"
#include "gd32w51x_rcu.h"
#include "gd32w51x_rtc.h"
#include "gd32w51x_sdio.h"
#include "gd32w51x_spi.h"
#include "gd32w51x_sqpi.h"
#include "gd32w51x_syscfg.h"
#include "gd32w51x_timer.h"
#include "gd32w51x_trng.h"
#include "gd32w51x_tsi.h"
#include "gd32w51x_tzpcu.h"
#include "gd32w51x_usart.h"
#include "gd32w51x_wwdgt.h"
#endif /* GD32W51X_LIBOPT_H */

View File

@ -0,0 +1,173 @@
/*!
\file main.c
\brief ADC discontinuous mode for regular channel demo
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "gd32w51x.h"
#include "systick.h"
#include <stdio.h>
#include "gd32w515p_eval.h"
uint16_t adc_value[16];
void rcu_config(void);
void gpio_config(void);
void dma_config(void);
void adc_config(void);
/*!
\brief main function
\param[in] none
\param[out] none
\retval none
*/
int main(void)
{
/* system clocks configuration */
rcu_config();
/* systick configuration */
systick_config();
/* GPIO configuration */
gpio_config();
/* DMA configuration */
dma_config();
/* ADC configuration */
adc_config();
while(1){
/* delay 1s */
delay_1ms(1000U);
/* ADC software trigger enable */
adc_software_trigger_enable(ADC_REGULAR_CHANNEL);
}
}
/*!
\brief configure the different system clocks
\param[in] none
\param[out] none
\retval none
*/
void rcu_config(void)
{
/* enable GPIO clock */
rcu_periph_clock_enable(RCU_GPIOA);
rcu_periph_clock_enable(RCU_GPIOB);
/* enable ADC clock */
rcu_periph_clock_enable(RCU_ADC);
adc_clock_config(ADC_ADCCK_HCLK_DIV6);
/* enable DMA clock */
rcu_periph_clock_enable(RCU_DMA1);
}
/*!
\brief configure the GPIO peripheral
\param[in] none
\param[out] none
\retval none
*/
void gpio_config(void)
{
/* config the GPIO as analog mode */
gpio_mode_set(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
gpio_mode_set(GPIOB, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5);
}
/*!
\brief configure the DMA peripheral
\param[in] none
\param[out] none
\retval none
*/
void dma_config(void)
{
/* ADC_DMA_channel configuration */
dma_single_data_parameter_struct dma_single_data_parameter;
/* ADC DMA_channel configuration */
dma_deinit(DMA1, DMA_CH0);
/* initialize DMA single data mode */
dma_single_data_parameter.periph_addr = (uint32_t)(&ADC_RDATA);
dma_single_data_parameter.periph_inc = DMA_PERIPH_INCREASE_DISABLE;
dma_single_data_parameter.memory0_addr = (uint32_t)(adc_value);
dma_single_data_parameter.memory_inc = DMA_MEMORY_INCREASE_ENABLE;
dma_single_data_parameter.periph_memory_width = DMA_PERIPH_WIDTH_16BIT;
dma_single_data_parameter.direction = DMA_PERIPH_TO_MEMORY;
dma_single_data_parameter.number = 16U;
dma_single_data_parameter.priority = DMA_PRIORITY_HIGH;
dma_single_data_mode_init(DMA1, DMA_CH0, &dma_single_data_parameter);
dma_channel_subperipheral_select(DMA1, DMA_CH0, DMA_SUBPERI0);
/* enable DMA circulation mode */
dma_circulation_enable(DMA1, DMA_CH0);
/* enable DMA channel */
dma_channel_enable(DMA1, DMA_CH0);
}
/*!
\brief configure the ADC peripheral
\param[in] none
\param[out] none
\retval none
*/
void adc_config(void)
{
/* ADC data alignment config */
adc_data_alignment_config(ADC_DATAALIGN_RIGHT);
/* ADC channel length config */
adc_channel_length_config(ADC_REGULAR_CHANNEL, 8U);
/* ADC discontinuous mode */
adc_discontinuous_mode_config(ADC_REGULAR_CHANNEL, 3U);
/* ADC regular channel config */
adc_regular_channel_config(0U, ADC_CHANNEL_0, ADC_SAMPLETIME_55POINT5);
adc_regular_channel_config(1U, ADC_CHANNEL_1, ADC_SAMPLETIME_55POINT5);
adc_regular_channel_config(2U, ADC_CHANNEL_2, ADC_SAMPLETIME_55POINT5);
adc_regular_channel_config(3U, ADC_CHANNEL_3, ADC_SAMPLETIME_55POINT5);
adc_regular_channel_config(4U, ADC_CHANNEL_4, ADC_SAMPLETIME_55POINT5);
adc_regular_channel_config(5U, ADC_CHANNEL_5, ADC_SAMPLETIME_55POINT5);
adc_regular_channel_config(6U, ADC_CHANNEL_6, ADC_SAMPLETIME_55POINT5);
adc_regular_channel_config(7U, ADC_CHANNEL_7, ADC_SAMPLETIME_55POINT5);
/* ADC external trigger config */
adc_external_trigger_config(ADC_REGULAR_CHANNEL, EXTERNAL_TRIGGER_DISABLE);
/* enable ADC interface */
adc_enable();
delay_1ms(1U);
/* ADC DMA function enable */
adc_dma_mode_enable();
}

View File

@ -0,0 +1,39 @@
/*!
\file readme.txt
\brief description of the ADC regular channel discontinuous mode example
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
This demo is based on the GD32W515P-EVAL-V1.0 board, it shows how to use the ADC
discontinuous mode. The ADC is configured in discontinuous mode, group length is 8,
conversion length is 3, using software trigger. Every trigger converts 3 channels.
You can use the watch window to see the conversion result.

View File

@ -0,0 +1,82 @@
/*!
\file systick.c
\brief the systick configuration file
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "gd32w51x.h"
#include "systick.h"
volatile static uint32_t delay;
/*!
\brief configure systick
\param[in] none
\param[out] none
\retval none
*/
void systick_config(void)
{
/* setup systick timer for 1000Hz interrupts */
if(SysTick_Config(SystemCoreClock / 1000U)){
/* capture error */
while(1){
}
}
/* configure the systick handler priority */
NVIC_SetPriority(SysTick_IRQn, 0x00U);
}
/*!
\brief delay a time in milliseconds
\param[in] count: count in milliseconds
\param[out] none
\retval none
*/
void delay_1ms(uint32_t count)
{
delay = count;
while(0U != delay){
}
}
/*!
\brief delay decrement
\param[in] none
\param[out] none
\retval none
*/
void delay_decrement(void)
{
if(0U != delay){
delay--;
}
}

View File

@ -0,0 +1,47 @@
/*!
\file systick.h
\brief the header file of systick
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#ifndef SYSTICK_H
#define SYSTICK_H
#include <stdint.h>
/* configure systick */
void systick_config(void);
/* delay a time in milliseconds */
void delay_1ms(uint32_t count);
/* delay decrement */
void delay_decrement(void);
#endif /* SYSTICK_H */

View File

@ -0,0 +1,139 @@
/*!
\file gd32w51x_it.c
\brief interrupt service routines
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "gd32w51x_it.h"
#include "systick.h"
/*!
\brief this function handles NMI exception
\param[in] none
\param[out] none
\retval none
*/
void NMI_Handler(void)
{
}
/*!
\brief this function handles HardFault exception
\param[in] none
\param[out] none
\retval none
*/
void HardFault_Handler(void)
{
/* if Hard Fault exception occurs, go to infinite loop */
while(1){
}
}
/*!
\brief this function handles MemManage exception
\param[in] none
\param[out] none
\retval none
*/
void MemManage_Handler(void)
{
/* if Memory Manage exception occurs, go to infinite loop */
while(1){
}
}
/*!
\brief this function handles BusFault exception
\param[in] none
\param[out] none
\retval none
*/
void BusFault_Handler(void)
{
/* if Bus Fault exception occurs, go to infinite loop */
while(1){
}
}
/*!
\brief this function handles UsageFault exception
\param[in] none
\param[out] none
\retval none
*/
void UsageFault_Handler(void)
{
/* if Usage Fault exception occurs, go to infinite loop */
while(1){
}
}
/*!
\brief this function handles SVC exception
\param[in] none
\param[out] none
\retval none
*/
void SVC_Handler(void)
{
}
/*!
\brief this function handles DebugMon exception
\param[in] none
\param[out] none
\retval none
*/
void DebugMon_Handler(void)
{
}
/*!
\brief this function handles PendSV exception
\param[in] none
\param[out] none
\retval none
*/
void PendSV_Handler(void)
{
}
/*!
\brief this function handles SysTick exception
\param[in] none
\param[out] none
\retval none
*/
void SysTick_Handler(void)
{
delay_decrement();
}

View File

@ -0,0 +1,60 @@
/*!
\file gd32w51x_it.h
\brief the header file of the ISR
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#ifndef GD32W51X_IT_H
#define GD32W51X_IT_H
#include "gd32w51x.h"
/* function declarations */
/* this function handles NMI exception */
void NMI_Handler(void);
/* this function handles HardFault exception */
void HardFault_Handler(void);
/* this function handles MemManage exception */
void MemManage_Handler(void);
/* this function handles BusFault exception */
void BusFault_Handler(void);
/* this function handles UsageFault exception */
void UsageFault_Handler(void);
/* this function handles SVC exception */
void SVC_Handler(void);
/* this function handles DebugMon exception */
void DebugMon_Handler(void);
/* this function handles PendSV exception */
void PendSV_Handler(void);
/* this function handles SysTick exception */
void SysTick_Handler(void);
#endif /* GD32W51X_IT_H */

View File

@ -0,0 +1,70 @@
/*!
\file gd32w51x_libopt.h
\brief library optional for gd32w51x
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#ifndef GD32W51X_LIBOPT_H
#define GD32W51X_LIBOPT_H
#include "gd32w51x_adc.h"
#include "gd32w51x_cau.h"
#include "gd32w51x_crc.h"
#include "gd32w51x_dbg.h"
#include "gd32w51x_dci.h"
#include "gd32w51x_dma.h"
#include "gd32w51x_efuse.h"
#include "gd32w51x_exti.h"
#include "gd32w51x_fmc.h"
#include "gd32w51x_fwdgt.h"
#include "gd32w51x_gpio.h"
#include "gd32w51x_hau.h"
#include "gd32w51x_hpdf.h"
#include "gd32w51x_i2c.h"
#include "gd32w51x_icache.h"
#include "gd32w51x_misc.h"
#include "gd32w51x_pkcau.h"
#include "gd32w51x_pmu.h"
#include "gd32w51x_qspi.h"
#include "gd32w51x_rcu.h"
#include "gd32w51x_rtc.h"
#include "gd32w51x_sdio.h"
#include "gd32w51x_spi.h"
#include "gd32w51x_sqpi.h"
#include "gd32w51x_syscfg.h"
#include "gd32w51x_timer.h"
#include "gd32w51x_trng.h"
#include "gd32w51x_tsi.h"
#include "gd32w51x_tzpcu.h"
#include "gd32w51x_usart.h"
#include "gd32w51x_wwdgt.h"
#endif /* GD32W51X_LIBOPT_H */

View File

@ -0,0 +1,182 @@
/*!
\file main.c
\brief ADC regular channel with DMA demo
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "gd32w51x.h"
#include "systick.h"
#include <stdio.h>
#include "gd32w515p_eval.h"
uint16_t adc_value[4];
void rcu_config(void);
void gpio_config(void);
void dma_config(void);
void adc_config(void);
/*!
\brief main function
\param[in] none
\param[out] none
\retval none
*/
int main(void)
{
/* system clocks configuration */
rcu_config();
/* systick configuration */
systick_config();
/* GPIO configuration */
gpio_config();
/* configure COM port */
gd_eval_com_init(EVAL_COM0);
/* DMA configuration */
dma_config();
/* ADC configuration */
adc_config();
while(1){
delay_1ms(1000U);
printf("\r\n //*******************************//");
printf("\r\n ADC regular channel data = %04X", adc_value[0]);
printf("\r\n ADC regular channel data = %04X", adc_value[1]);
printf("\r\n ADC regular channel data = %04X", adc_value[2]);
printf("\r\n ADC regular channel data = %04X\r\n", adc_value[3]);
}
}
/*!
\brief configure the different system clocks
\param[in] none
\param[out] none
\retval none
*/
void rcu_config(void)
{
/* enable GPIOC clock */
rcu_periph_clock_enable(RCU_GPIOA);
/* enable DMA clock */
rcu_periph_clock_enable(RCU_DMA1);
/* config ADC clock */
rcu_periph_clock_enable(RCU_ADC);
adc_clock_config(ADC_ADCCK_HCLK_DIV6);
}
/*!
\brief configure the GPIO peripheral
\param[in] none
\param[out] none
\retval none
*/
void gpio_config(void)
{
/* config the GPIO as analog mode */
gpio_mode_set(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO_PIN_0| GPIO_PIN_1| GPIO_PIN_2| GPIO_PIN_3);
}
/*!
\brief configure the DMA peripheral
\param[in] none
\param[out] none
\retval none
*/
void dma_config(void)
{
/* ADC_DMA_channel configuration */
dma_single_data_parameter_struct dma_single_data_parameter;
/* ADC DMA_channel configuration */
dma_deinit(DMA1, DMA_CH0);
/* initialize DMA single data mode */
dma_single_data_parameter.periph_addr = (uint32_t)(&ADC_RDATA);
dma_single_data_parameter.periph_inc = DMA_PERIPH_INCREASE_DISABLE;
dma_single_data_parameter.memory0_addr = (uint32_t)(&adc_value);
dma_single_data_parameter.memory_inc = DMA_MEMORY_INCREASE_ENABLE;
dma_single_data_parameter.periph_memory_width = DMA_PERIPH_WIDTH_16BIT;
dma_single_data_parameter.direction = DMA_PERIPH_TO_MEMORY;
dma_single_data_parameter.number = 4U;
dma_single_data_parameter.priority = DMA_PRIORITY_HIGH;
dma_single_data_mode_init(DMA1, DMA_CH0, &dma_single_data_parameter);
dma_channel_subperipheral_select(DMA1, DMA_CH0, DMA_SUBPERI0);
/* enable DMA circulation mode */
dma_circulation_enable(DMA1, DMA_CH0);
/* enable DMA channel */
dma_channel_enable(DMA1, DMA_CH0);
}
/*!
\brief configure the ADC peripheral
\param[in] none
\param[out] none
\retval none
*/
void adc_config(void)
{
/* ADC contineous function disable */
adc_special_function_config(ADC_CONTINUOUS_MODE, ENABLE);
/* ADC scan mode disable */
adc_special_function_config(ADC_SCAN_MODE, ENABLE);
/* ADC data alignment config */
adc_data_alignment_config(ADC_DATAALIGN_RIGHT);
/* ADC external trigger enable */
adc_external_trigger_config(ADC_REGULAR_CHANNEL, EXTERNAL_TRIGGER_DISABLE);
/* ADC channel length config */
adc_channel_length_config(ADC_REGULAR_CHANNEL, 4U);
/* ADC inserted channel config */
adc_regular_channel_config(0U, ADC_CHANNEL_0, ADC_SAMPLETIME_55POINT5);
adc_regular_channel_config(1U, ADC_CHANNEL_1, ADC_SAMPLETIME_55POINT5);
adc_regular_channel_config(2U, ADC_CHANNEL_2, ADC_SAMPLETIME_55POINT5);
adc_regular_channel_config(3U, ADC_CHANNEL_3, ADC_SAMPLETIME_55POINT5);
/* enable ADC interface */
adc_enable();
/* wait for ADC stability */
delay_1ms(1);
/* ADC DMA function enable */
adc_dma_request_after_last_enable();
adc_dma_mode_enable();
/* enable ADC software trigger */
adc_software_trigger_enable(ADC_REGULAR_CHANNEL);
}
/* retarget the C library printf function to the USART */
int fputc(int ch, FILE *f)
{
usart_data_transmit(EVAL_COM0, (uint8_t)ch);
while(RESET == usart_flag_get(EVAL_COM0, USART_FLAG_TBE));
return ch;
}

View File

@ -0,0 +1,44 @@
/*!
\file readme.txt
\brief description of the ADC regular channel with DMA demo
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
This demo is based on the GD32W515P-EVAL-V1.0 board, it shows how to use the ADC to
convert analog signal to digital data through DMA. The ADC is configured in continuous
mode, PA0~PA3 is chosen as analog input pin.
As the ADC conversion begins by software, the converted data from ADC_RDATA register
to SRAM begins continuously. Users can change the voltage on the pins, and check if the
values matche the converted data through the watch window.
The analog input pin should configured to AIN mode. We can watch array adc_value[] in
debug mode or COM.

View File

@ -0,0 +1,82 @@
/*!
\file systick.c
\brief the systick configuration file
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "gd32w51x.h"
#include "systick.h"
volatile static uint32_t delay;
/*!
\brief configure systick
\param[in] none
\param[out] none
\retval none
*/
void systick_config(void)
{
/* setup systick timer for 1000Hz interrupts */
if(SysTick_Config(SystemCoreClock / 1000U)){
/* capture error */
while(1){
}
}
/* configure the systick handler priority */
NVIC_SetPriority(SysTick_IRQn, 0x00U);
}
/*!
\brief delay a time in milliseconds
\param[in] count: count in milliseconds
\param[out] none
\retval none
*/
void delay_1ms(uint32_t count)
{
delay = count;
while(0U != delay){
}
}
/*!
\brief delay decrement
\param[in] none
\param[out] none
\retval none
*/
void delay_decrement(void)
{
if(0U != delay){
delay--;
}
}

View File

@ -0,0 +1,47 @@
/*!
\file systick.h
\brief the header file of systick
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#ifndef SYSTICK_H
#define SYSTICK_H
#include <stdint.h>
/* configure systick */
void systick_config(void);
/* delay a time in milliseconds */
void delay_1ms(uint32_t count);
/* delay decrement */
void delay_decrement(void);
#endif /* SYSTICK_H */

View File

@ -0,0 +1,152 @@
/*!
\file gd32w51x_it.c
\brief interrupt service routines
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "gd32w51x_it.h"
#include "systick.h"
#include "gd32w515p_eval.h"
/*!
\brief this function handles NMI exception
\param[in] none
\param[out] none
\retval none
*/
void NMI_Handler(void)
{
}
/*!
\brief this function handles HardFault exception
\param[in] none
\param[out] none
\retval none
*/
void HardFault_Handler(void)
{
/* if Hard Fault exception occurs, go to infinite loop */
while (1){
}
}
/*!
\brief this function handles MemManage exception
\param[in] none
\param[out] none
\retval none
*/
void MemManage_Handler(void)
{
/* if Memory Manage exception occurs, go to infinite loop */
while (1){
}
}
/*!
\brief this function handles BusFault exception
\param[in] none
\param[out] none
\retval none
*/
void BusFault_Handler(void)
{
/* if Bus Fault exception occurs, go to infinite loop */
while (1){
}
}
/*!
\brief this function handles UsageFault exception
\param[in] none
\param[out] none
\retval none
*/
void UsageFault_Handler(void)
{
/* if Usage Fault exception occurs, go to infinite loop */
while (1){
}
}
/*!
\brief this function handles SVC exception
\param[in] none
\param[out] none
\retval none
*/
void SVC_Handler(void)
{
}
/*!
\brief this function handles DebugMon exception
\param[in] none
\param[out] none
\retval none
*/
void DebugMon_Handler(void)
{
}
/*!
\brief this function handles PendSV exception
\param[in] none
\param[out] none
\retval none
*/
void PendSV_Handler(void)
{
}
/*!
\brief this function handles SecureFault exception
\param[in] none
\param[out] none
\retval none
*/
void SecureFault_Handler(void)
{
/* if Secure Fault exception occurs, go to infinite loop */
while (1){
}
}
/*!
\brief this function handles SysTick exception
\param[in] none
\param[out] none
\retval none
*/
void SysTick_Handler(void)
{
delay_decrement();
}

View File

@ -0,0 +1,62 @@
/*!
\file gd32w51x_it.h
\brief the header file of the ISR
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#ifndef GD32W51X_IT_H
#define GD32W51X_IT_H
#include "gd32w51x.h"
/* function declarations */
/* this function handles NMI exception */
void NMI_Handler(void);
/* this function handles HardFault exception */
void HardFault_Handler(void);
/* this function handles MemManage exception */
void MemManage_Handler(void);
/* this function handles BusFault exception */
void BusFault_Handler(void);
/* this function handles UsageFault exception */
void UsageFault_Handler(void);
/* this function handles SVC exception */
void SVC_Handler(void);
/* this function handles DebugMon exception */
void DebugMon_Handler(void);
/* this function handles PendSV exception */
void PendSV_Handler(void);
/* this function handles SecureFault exception */
void SecureFault_Handler(void);
/* this function handles SysTick exception */
void SysTick_Handler(void);
#endif /* GD32W51X_IT_H */

View File

@ -0,0 +1,70 @@
/*!
\file gd32w51x_libopt.h
\brief library optional for gd32w51x
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#ifndef GD32W51X_LIBOPT_H
#define GD32W51X_LIBOPT_H
#include "gd32w51x_adc.h"
#include "gd32w51x_cau.h"
#include "gd32w51x_crc.h"
#include "gd32w51x_dbg.h"
#include "gd32w51x_dci.h"
#include "gd32w51x_dma.h"
#include "gd32w51x_efuse.h"
#include "gd32w51x_exti.h"
#include "gd32w51x_fmc.h"
#include "gd32w51x_fwdgt.h"
#include "gd32w51x_gpio.h"
#include "gd32w51x_hau.h"
#include "gd32w51x_hpdf.h"
#include "gd32w51x_i2c.h"
#include "gd32w51x_icache.h"
#include "gd32w51x_misc.h"
#include "gd32w51x_pkcau.h"
#include "gd32w51x_pmu.h"
#include "gd32w51x_qspi.h"
#include "gd32w51x_rcu.h"
#include "gd32w51x_rtc.h"
#include "gd32w51x_sdio.h"
#include "gd32w51x_spi.h"
#include "gd32w51x_sqpi.h"
#include "gd32w51x_syscfg.h"
#include "gd32w51x_timer.h"
#include "gd32w51x_trng.h"
#include "gd32w51x_tsi.h"
#include "gd32w51x_tzpcu.h"
#include "gd32w51x_usart.h"
#include "gd32w51x_wwdgt.h"
#endif /* GD32W51X_LIBOPT_H */

View File

@ -0,0 +1,140 @@
/*!
\file main.c
\brief ADC software trigger regular channel polling
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "gd32w51x.h"
#include "systick.h"
#include <stdio.h>
#include "gd32w515p_eval.h"
__IO uint16_t adc_value[4];
void rcu_config(void);
void gpio_config(void);
void adc_config(void);
uint16_t adc_channel_sample(uint8_t channel);
/*!
\brief main function
\param[in] none
\param[out] none
\retval none
*/
int main(void)
{
/* system clocks configuration */
rcu_config();
/* systick configuration */
systick_config();
/* GPIO configuration */
gpio_config();
/* ADC configuration */
adc_config();
while(1){
adc_value[0] = adc_channel_sample(ADC_CHANNEL_0);
adc_value[1] = adc_channel_sample(ADC_CHANNEL_1);
adc_value[2] = adc_channel_sample(ADC_CHANNEL_2);
adc_value[3] = adc_channel_sample(ADC_CHANNEL_3);
}
}
/*!
\brief configure the different system clocks
\param[in] none
\param[out] none
\retval none
*/
void rcu_config(void)
{
/* enable GPIO clock */
rcu_periph_clock_enable(RCU_GPIOA);
/* enable ADC clock */
rcu_periph_clock_enable(RCU_ADC);
adc_clock_config(ADC_ADCCK_HCLK_DIV6);
}
/*!
\brief configure the GPIO peripheral
\param[in] none
\param[out] none
\retval none
*/
void gpio_config(void)
{
/* config the GPIO as analog mode */
gpio_mode_set(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
}
/*!
\brief configure the ADC peripheral
\param[in] none
\param[out] none
\retval none
*/
void adc_config(void)
{
/* ADC data alignment config */
adc_data_alignment_config(ADC_DATAALIGN_RIGHT);
/* ADC channel length config */
adc_channel_length_config( ADC_REGULAR_CHANNEL, 1U);
/* ADC external trigger config */
adc_external_trigger_config(ADC_REGULAR_CHANNEL, EXTERNAL_TRIGGER_DISABLE);
/* enable ADC interface */
adc_enable();
delay_1ms(1U);
}
/*!
\brief ADC channel sample
\param[in] none
\param[out] none
\retval none
*/
uint16_t adc_channel_sample(uint8_t channel)
{
/* ADC regular channel config */
adc_regular_channel_config(0U, channel, ADC_SAMPLETIME_14POINT5);
/* ADC software trigger enable */
adc_software_trigger_enable(ADC_REGULAR_CHANNEL);
/* wait the end of conversion flag */
while(!adc_flag_get(ADC_FLAG_EOC));
/* clear the end of conversion flag */
adc_flag_clear(ADC_FLAG_EOC);
/* return regular channel sample value */
return (adc_regular_data_read());
}

View File

@ -0,0 +1,43 @@
/*!
\file readme.txt
\brief description of the ADC software trigger regular channel polling
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
This demo is based on the GD32W515P-EVAL-V1.0 board, it shows how to use the ADC to
convert analog signal to digital data, four channel analog signals are collected in a
certain sequence. PA0~PA3 are chosen as analog input pin(AIN mode).
As the ADC conversion begins by software, the conversion data will read with checking
the EOC flag.
Users can change the input signal on the GD32W515P-EVAL-V1.0 board, and check if its
value matches the converted data through the watch window.

View File

@ -0,0 +1,82 @@
/*!
\file systick.c
\brief the systick configuration file
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "gd32w51x.h"
#include "systick.h"
volatile static uint32_t delay;
/*!
\brief configure systick
\param[in] none
\param[out] none
\retval none
*/
void systick_config(void)
{
/* setup systick timer for 1000Hz interrupts */
if(SysTick_Config(SystemCoreClock / 1000U)){
/* capture error */
while(1){
}
}
/* configure the systick handler priority */
NVIC_SetPriority(SysTick_IRQn, 0x00U);
}
/*!
\brief delay a time in milliseconds
\param[in] count: count in milliseconds
\param[out] none
\retval none
*/
void delay_1ms(uint32_t count)
{
delay = count;
while(0U != delay){
}
}
/*!
\brief delay decrement
\param[in] none
\param[out] none
\retval none
*/
void delay_decrement(void)
{
if(0U != delay){
delay--;
}
}

View File

@ -0,0 +1,47 @@
/*!
\file systick.h
\brief the header file of systick
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#ifndef SYSTICK_H
#define SYSTICK_H
#include <stdint.h>
/* configure systick */
void systick_config(void);
/* delay a time in milliseconds */
void delay_1ms(uint32_t count);
/* delay decrement */
void delay_decrement(void);
#endif /* SYSTICK_H */

View File

@ -0,0 +1,171 @@
/*!
\file gd32w51x_it.c
\brief interrupt service routines
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "gd32w51x_it.h"
#include "systick.h"
#include "gd32w515p_eval.h"
extern uint16_t inserted_data[4];
/*!
\brief this function handles NMI exception
\param[in] none
\param[out] none
\retval none
*/
void NMI_Handler(void)
{
}
/*!
\brief this function handles HardFault exception
\param[in] none
\param[out] none
\retval none
*/
void HardFault_Handler(void)
{
/* if Hard Fault exception occurs, go to infinite loop */
while (1){
}
}
/*!
\brief this function handles MemManage exception
\param[in] none
\param[out] none
\retval none
*/
void MemManage_Handler(void)
{
/* if Memory Manage exception occurs, go to infinite loop */
while (1){
}
}
/*!
\brief this function handles BusFault exception
\param[in] none
\param[out] none
\retval none
*/
void BusFault_Handler(void)
{
/* if Bus Fault exception occurs, go to infinite loop */
while (1){
}
}
/*!
\brief this function handles UsageFault exception
\param[in] none
\param[out] none
\retval none
*/
void UsageFault_Handler(void)
{
/* if Usage Fault exception occurs, go to infinite loop */
while (1){
}
}
/*!
\brief this function handles SVC exception
\param[in] none
\param[out] none
\retval none
*/
void SVC_Handler(void)
{
}
/*!
\brief this function handles DebugMon exception
\param[in] none
\param[out] none
\retval none
*/
void DebugMon_Handler(void)
{
}
/*!
\brief this function handles PendSV exception
\param[in] none
\param[out] none
\retval none
*/
void PendSV_Handler(void)
{
}
/*!
\brief this function handles SecureFault exception
\param[in] none
\param[out] none
\retval none
*/
void SecureFault_Handler(void)
{
/* if Secure Fault exception occurs, go to infinite loop */
while (1){
}
}
/*!
\brief this function handles SysTick exception
\param[in] none
\param[out] none
\retval none
*/
void SysTick_Handler(void)
{
delay_decrement();
}
/*!
\brief this function handles ADC interrupt
\param[in] none
\param[out] none
\retval none
*/
void ADC_IRQHandler(void)
{
/* clear the ADC flag */
adc_interrupt_flag_clear(ADC_INT_FLAG_EOIC);
/* read ADC inserted group data register */
inserted_data[0] = adc_inserted_data_read(ADC_INSERTED_CHANNEL_0);
inserted_data[1] = adc_inserted_data_read(ADC_INSERTED_CHANNEL_1);
inserted_data[2] = adc_inserted_data_read(ADC_INSERTED_CHANNEL_2);
inserted_data[3] = adc_inserted_data_read(ADC_INSERTED_CHANNEL_3);
}

View File

@ -0,0 +1,64 @@
/*!
\file gd32w51x_it.h
\brief the header file of the ISR
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#ifndef GD32W51X_IT_H
#define GD32W51X_IT_H
#include "gd32w51x.h"
/* function declarations */
/* this function handles NMI exception */
void NMI_Handler(void);
/* this function handles HardFault exception */
void HardFault_Handler(void);
/* this function handles MemManage exception */
void MemManage_Handler(void);
/* this function handles BusFault exception */
void BusFault_Handler(void);
/* this function handles UsageFault exception */
void UsageFault_Handler(void);
/* this function handles SVC exception */
void SVC_Handler(void);
/* this function handles DebugMon exception */
void DebugMon_Handler(void);
/* this function handles PendSV exception */
void PendSV_Handler(void);
/* this function handles SecureFault exception */
void SecureFault_Handler(void);
/* this function handles SysTick exception */
void SysTick_Handler(void);
/* this function handles ADC interrupt */
void ADC_IRQHandler(void);
#endif /* GD32W51X_IT_H */

View File

@ -0,0 +1,70 @@
/*!
\file gd32w51x_libopt.h
\brief library optional for gd32w51x
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#ifndef GD32W51X_LIBOPT_H
#define GD32W51X_LIBOPT_H
#include "gd32w51x_adc.h"
#include "gd32w51x_cau.h"
#include "gd32w51x_crc.h"
#include "gd32w51x_dbg.h"
#include "gd32w51x_dci.h"
#include "gd32w51x_dma.h"
#include "gd32w51x_efuse.h"
#include "gd32w51x_exti.h"
#include "gd32w51x_fmc.h"
#include "gd32w51x_fwdgt.h"
#include "gd32w51x_gpio.h"
#include "gd32w51x_hau.h"
#include "gd32w51x_hpdf.h"
#include "gd32w51x_i2c.h"
#include "gd32w51x_icache.h"
#include "gd32w51x_misc.h"
#include "gd32w51x_pkcau.h"
#include "gd32w51x_pmu.h"
#include "gd32w51x_qspi.h"
#include "gd32w51x_rcu.h"
#include "gd32w51x_rtc.h"
#include "gd32w51x_sdio.h"
#include "gd32w51x_spi.h"
#include "gd32w51x_sqpi.h"
#include "gd32w51x_syscfg.h"
#include "gd32w51x_timer.h"
#include "gd32w51x_trng.h"
#include "gd32w51x_tsi.h"
#include "gd32w51x_tzpcu.h"
#include "gd32w51x_usart.h"
#include "gd32w51x_wwdgt.h"
#endif /* GD32W51X_LIBOPT_H */

View File

@ -0,0 +1,200 @@
/*!
\file main.c
\brief TIMER trigger injected channel of ADC demo
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "gd32w51x.h"
#include "systick.h"
#include <stdio.h>
#include "gd32w515p_eval.h"
void rcu_config(void);
void nvic_config(void);
void gpio_config(void);
void timer_config(void);
void adc_config(void);
uint16_t inserted_data[4];
/*!
\brief main function
\param[in] none
\param[out] none
\retval none
*/
int main(void)
{
/* system clocks configuration */
rcu_config();
/* systick configuration */
systick_config();
/* GPIO configuration */
gpio_config();
/* NVIC configuration */
nvic_config();
/* configure COM port */
gd_eval_com_init(EVAL_COM0);
/* TIMER configuration */
timer_config();
/* ADC configuration */
adc_config();
/* enable TIMER2 */
timer_enable(TIMER2);
while(1){
delay_1ms(1000);
printf("\r\nADC inserted channel 0 data = %d \r\n", inserted_data[0]);
printf("ADC inserted channel 1 data = %d \r\n", inserted_data[1]);
printf("ADC inserted channel 2 data = %d \r\n", inserted_data[2]);
printf("ADC inserted channel 3 data = %d \r\n", inserted_data[3]);
printf("***********************************\r\n");
}
}
/*!
\brief configure the different system clocks
\param[in] none
\param[out] none
\retval none
*/
void rcu_config(void)
{
/* enable GPIOC clock */
rcu_periph_clock_enable(RCU_GPIOA);
/* enable timer1 clock */
rcu_periph_clock_enable(RCU_TIMER2);
/* config ADC clock */
rcu_periph_clock_enable(RCU_ADC);
adc_clock_config(ADC_ADCCK_HCLK_DIV6);
}
/*!
\brief configure the GPIO peripheral
\param[in] none
\param[out] none
\retval none
*/
void gpio_config(void)
{
/* config the GPIO as analog mode */
gpio_mode_set(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO_PIN_0| GPIO_PIN_1| GPIO_PIN_2| GPIO_PIN_3);
}
/*!
\brief configure the TIMER peripheral
\param[in] none
\param[out] none
\retval none
*/
void timer_config(void)
{
timer_oc_parameter_struct timer_ocintpara;
timer_parameter_struct timer_initpara;
/* TIMER2 configuration */
timer_initpara.prescaler = 1799U;
timer_initpara.alignedmode = TIMER_COUNTER_EDGE;
timer_initpara.counterdirection = TIMER_COUNTER_UP;
timer_initpara.period = 9999U;
timer_initpara.clockdivision = TIMER_CKDIV_DIV1;
timer_initpara.repetitioncounter = 0U;
timer_init(TIMER2, &timer_initpara);
/* CH3 configuration in PWM mode1 */
timer_ocintpara.ocpolarity = TIMER_OC_POLARITY_HIGH;
timer_ocintpara.outputstate = TIMER_CCX_ENABLE;
timer_channel_output_config(TIMER2, TIMER_CH_3, &timer_ocintpara);
timer_channel_output_pulse_value_config(TIMER2, TIMER_CH_3, 3999U);
timer_channel_output_mode_config(TIMER2, TIMER_CH_3, TIMER_OC_MODE_PWM1);
timer_channel_output_shadow_config(TIMER2, TIMER_CH_3, TIMER_OC_SHADOW_DISABLE);
}
/*!
\brief configure the ADC peripheral
\param[in] none
\param[out] none
\retval none
*/
void adc_config(void)
{
/* ADC scan function enable */
adc_special_function_config(ADC_SCAN_MODE, ENABLE);
/* ADC data alignment config */
adc_data_alignment_config(ADC_DATAALIGN_RIGHT);
/* ADC external trigger enable */
adc_external_trigger_config(ADC_INSERTED_CHANNEL, EXTERNAL_TRIGGER_RISING);
/* ADC external trigger source config */
adc_external_trigger_source_config(ADC_INSERTED_CHANNEL, ADC_EXTTRIG_INSERTED_T2_CH3);
/* ADC channel length config */
adc_channel_length_config(ADC_INSERTED_CHANNEL, 4U);
/* ADC inserted channel config */
adc_inserted_channel_config(0U, ADC_CHANNEL_0, ADC_SAMPLETIME_55POINT5);
adc_inserted_channel_config(1U, ADC_CHANNEL_1, ADC_SAMPLETIME_55POINT5);
adc_inserted_channel_config(2U, ADC_CHANNEL_2, ADC_SAMPLETIME_55POINT5);
adc_inserted_channel_config(3U, ADC_CHANNEL_3, ADC_SAMPLETIME_55POINT5);
/* clear the ADC flag */
adc_interrupt_flag_clear(ADC_INT_FLAG_EOC);
adc_interrupt_flag_clear(ADC_INT_FLAG_EOIC);
/* enable ADC interrupt */
adc_interrupt_enable(ADC_INT_EOIC);
/* enable ADC interface */
adc_enable();
/* wait for ADC stability */
delay_1ms(1);
}
/**
\brief configure the nested vectored interrupt controller
\param[in] none
\param[out] none
\retval none
*/
void nvic_config(void)
{
nvic_priority_group_set(NVIC_PRIGROUP_PRE1_SUB3);
nvic_irq_enable(ADC_IRQn, 0, 0);
}
/* retarget the C library printf function to the USART */
int fputc(int ch, FILE *f)
{
usart_data_transmit(EVAL_COM0, (uint8_t)ch);
while(RESET == usart_flag_get(EVAL_COM0, USART_FLAG_TBE));
return ch;
}

View File

@ -0,0 +1,40 @@
/*!
\file readme.txt
\brief description of TIMER trigger inserted channel of ADC demo
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
This demo is based on the GD32W515P-EVAL-V1.0 board, it shows how to convert ADC
inserted group channels continuously using TIMER2_CH3 external trigger. The inserted
group length is 4, the scan mode is set, every compare event will trigger ADC to convert
all the channels in the inserted group.
We can watch inserted_data[] by COM0.

View File

@ -0,0 +1,82 @@
/*!
\file systick.c
\brief the systick configuration file
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "gd32w51x.h"
#include "systick.h"
volatile static uint32_t delay;
/*!
\brief configure systick
\param[in] none
\param[out] none
\retval none
*/
void systick_config(void)
{
/* setup systick timer for 1000Hz interrupts */
if(SysTick_Config(SystemCoreClock / 1000U)){
/* capture error */
while(1){
}
}
/* configure the systick handler priority */
NVIC_SetPriority(SysTick_IRQn, 0x00U);
}
/*!
\brief delay a time in milliseconds
\param[in] count: count in milliseconds
\param[out] none
\retval none
*/
void delay_1ms(uint32_t count)
{
delay = count;
while(0U != delay){
}
}
/*!
\brief delay decrement
\param[in] none
\param[out] none
\retval none
*/
void delay_decrement(void)
{
if(0U != delay){
delay--;
}
}

View File

@ -0,0 +1,47 @@
/*!
\file systick.h
\brief the header file of systick
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#ifndef SYSTICK_H
#define SYSTICK_H
#include <stdint.h>
/* configure systick */
void systick_config(void);
/* delay a time in milliseconds */
void delay_1ms(uint32_t count);
/* delay decrement */
void delay_decrement(void);
#endif /* SYSTICK_H */

View File

@ -0,0 +1,152 @@
/*!
\file gd32w51x_it.c
\brief interrupt service routines
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "gd32w51x_it.h"
#include "systick.h"
#include "gd32w515p_eval.h"
/*!
\brief this function handles NMI exception
\param[in] none
\param[out] none
\retval none
*/
void NMI_Handler(void)
{
}
/*!
\brief this function handles HardFault exception
\param[in] none
\param[out] none
\retval none
*/
void HardFault_Handler(void)
{
/* if Hard Fault exception occurs, go to infinite loop */
while (1){
}
}
/*!
\brief this function handles MemManage exception
\param[in] none
\param[out] none
\retval none
*/
void MemManage_Handler(void)
{
/* if Memory Manage exception occurs, go to infinite loop */
while (1){
}
}
/*!
\brief this function handles BusFault exception
\param[in] none
\param[out] none
\retval none
*/
void BusFault_Handler(void)
{
/* if Bus Fault exception occurs, go to infinite loop */
while (1){
}
}
/*!
\brief this function handles UsageFault exception
\param[in] none
\param[out] none
\retval none
*/
void UsageFault_Handler(void)
{
/* if Usage Fault exception occurs, go to infinite loop */
while (1){
}
}
/*!
\brief this function handles SVC exception
\param[in] none
\param[out] none
\retval none
*/
void SVC_Handler(void)
{
}
/*!
\brief this function handles DebugMon exception
\param[in] none
\param[out] none
\retval none
*/
void DebugMon_Handler(void)
{
}
/*!
\brief this function handles PendSV exception
\param[in] none
\param[out] none
\retval none
*/
void PendSV_Handler(void)
{
}
/*!
\brief this function handles SecureFault exception
\param[in] none
\param[out] none
\retval none
*/
void SecureFault_Handler(void)
{
/* if Secure Fault exception occurs, go to infinite loop */
while (1){
}
}
/*!
\brief this function handles SysTick exception
\param[in] none
\param[out] none
\retval none
*/
void SysTick_Handler(void)
{
delay_decrement();
}

View File

@ -0,0 +1,62 @@
/*!
\file gd32w51x_it.h
\brief the header file of the ISR
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#ifndef GD32W51X_IT_H
#define GD32W51X_IT_H
#include "gd32w51x.h"
/* function declarations */
/* this function handles NMI exception */
void NMI_Handler(void);
/* this function handles HardFault exception */
void HardFault_Handler(void);
/* this function handles MemManage exception */
void MemManage_Handler(void);
/* this function handles BusFault exception */
void BusFault_Handler(void);
/* this function handles UsageFault exception */
void UsageFault_Handler(void);
/* this function handles SVC exception */
void SVC_Handler(void);
/* this function handles DebugMon exception */
void DebugMon_Handler(void);
/* this function handles PendSV exception */
void PendSV_Handler(void);
/* this function handles SecureFault exception */
void SecureFault_Handler(void);
/* this function handles SysTick exception */
void SysTick_Handler(void);
#endif /* GD32W51X_IT_H */

View File

@ -0,0 +1,70 @@
/*!
\file gd32w51x_libopt.h
\brief library optional for gd32w51x
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#ifndef GD32W51X_LIBOPT_H
#define GD32W51X_LIBOPT_H
#include "gd32w51x_adc.h"
#include "gd32w51x_cau.h"
#include "gd32w51x_crc.h"
#include "gd32w51x_dbg.h"
#include "gd32w51x_dci.h"
#include "gd32w51x_dma.h"
#include "gd32w51x_efuse.h"
#include "gd32w51x_exti.h"
#include "gd32w51x_fmc.h"
#include "gd32w51x_fwdgt.h"
#include "gd32w51x_gpio.h"
#include "gd32w51x_hau.h"
#include "gd32w51x_hpdf.h"
#include "gd32w51x_i2c.h"
#include "gd32w51x_icache.h"
#include "gd32w51x_misc.h"
#include "gd32w51x_pkcau.h"
#include "gd32w51x_pmu.h"
#include "gd32w51x_qspi.h"
#include "gd32w51x_rcu.h"
#include "gd32w51x_rtc.h"
#include "gd32w51x_sdio.h"
#include "gd32w51x_spi.h"
#include "gd32w51x_sqpi.h"
#include "gd32w51x_syscfg.h"
#include "gd32w51x_timer.h"
#include "gd32w51x_trng.h"
#include "gd32w51x_tsi.h"
#include "gd32w51x_tzpcu.h"
#include "gd32w51x_usart.h"
#include "gd32w51x_wwdgt.h"
#endif /* GD32W51X_LIBOPT_H */

View File

@ -0,0 +1,145 @@
/*!
\file main.c
\brief ADC channel of temperature, vref and vbat demo
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "gd32w51x.h"
#include "systick.h"
#include <stdio.h>
#include "gd32w515p_eval.h"
float temperature;
float vref_value;
float vbat_value;
void rcu_config(void);
void adc_config(void);
/*!
\brief main function
\param[in] none
\param[out] none
\retval none
*/
int main(void)
{
/* system clocks configuration */
rcu_config();
/* systick configuration */
systick_config();
/* ADC configuration */
adc_config();
/* USART configuration */
gd_eval_com_init(EVAL_COM0);
while(1){
/* delay a time in milliseconds */
delay_1ms(2000U);
/* ADC software trigger enable */
adc_software_trigger_enable(ADC_INSERTED_CHANNEL);
while(SET != adc_flag_get(ADC_FLAG_EOIC)){
}
adc_flag_clear(ADC_FLAG_EOIC);
/* value convert */
temperature = (float)((1.43f - ADC_IDATA0*3.3f/4096) * 1000 / 4.3f + 25);
vref_value = (float)(ADC_IDATA1 * 3.3f / 4096);
vbat_value = (float)((ADC_IDATA2 * 3.3f / 4096) * 4);
printf("\r\n//***********************************//\r\n");
printf(" the temperature data is %2.0f degrees Celsius\r\n", temperature);
printf(" the reference voltage data is %5.3fV \r\n", vref_value);
printf(" the battery voltage is %5.3fV\r\n", vbat_value);
}
}
/*!
\brief configure the different system clocks
\param[in] none
\param[out] none
\retval none
*/
void rcu_config(void)
{
/* enable ADC clock */
rcu_periph_clock_enable(RCU_ADC);
/* config ADC clock */
adc_clock_config(ADC_ADCCK_HCLK_DIV6);
}
/*!
\brief configure the ADC peripheral
\param[in] none
\param[out] none
\retval none
*/
void adc_config(void)
{
/* ADC SCAN function enable */
adc_special_function_config(ADC_SCAN_MODE, ENABLE);
/* ADC data alignment config */
adc_data_alignment_config(ADC_DATAALIGN_RIGHT);
/* ADC external trigger disable */
adc_external_trigger_config(ADC_INSERTED_CHANNEL, EXTERNAL_TRIGGER_DISABLE);
/* ADC channel length config */
adc_channel_length_config(ADC_INSERTED_CHANNEL, 3U);
/* ADC temperature sensor channel config */
adc_inserted_channel_config(0, ADC_CHANNEL_9, ADC_SAMPLETIME_479POINT5);
/* ADC internal reference voltage channel config */
adc_inserted_channel_config(1, ADC_CHANNEL_10, ADC_SAMPLETIME_479POINT5);
/* ADC 1/4 voltate of external battery config */
adc_inserted_channel_config(2, ADC_CHANNEL_11, ADC_SAMPLETIME_479POINT5);
/* ADC vbat channel enable */
adc_channel_9_to_11(ADC_VBAT_CHANNEL_SWITCH, ENABLE);
/* ADC temperature and vref enable */
adc_channel_9_to_11(ADC_TEMP_VREF_CHANNEL_SWITCH, ENABLE);
/* enable ADC interface */
adc_enable();
/* wait for ADC stability */
delay_1ms(1);
/* ADC software trigger enable */
adc_software_trigger_enable(ADC_INSERTED_CHANNEL);
}
/* retarget the C library printf function to the USART */
int fputc(int ch, FILE *f)
{
usart_data_transmit(EVAL_COM0, (uint8_t) ch);
while (RESET == usart_flag_get(EVAL_COM0,USART_FLAG_TBE));
return ch;
}

View File

@ -0,0 +1,43 @@
/*!
\file readme.txt
\brief description of the ADC channel of temperature, vref and vbat
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
This demo is based on the GD32W515P-EVAL-V1.0 board, it shows how to use the ADC to
convert analog signal to digital data.The ADC is configured in dependent mode, inner
channel9 (temperature sensor channel), channel10 (VREF channel) and channel11 (VBAT/4
channel) are chosen as analog input pin.
As the AD convertion begins by software,the converted data in the ADC_IDTRx register,
where the x is 0 to 2.
We can watch temperature, vref_value and vbat_value in debug mode or by COM.

View File

@ -0,0 +1,82 @@
/*!
\file systick.c
\brief the systick configuration file
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "gd32w51x.h"
#include "systick.h"
volatile static uint32_t delay;
/*!
\brief configure systick
\param[in] none
\param[out] none
\retval none
*/
void systick_config(void)
{
/* setup systick timer for 1000Hz interrupts */
if(SysTick_Config(SystemCoreClock / 1000U)){
/* capture error */
while(1){
}
}
/* configure the systick handler priority */
NVIC_SetPriority(SysTick_IRQn, 0x00U);
}
/*!
\brief delay a time in milliseconds
\param[in] count: count in milliseconds
\param[out] none
\retval none
*/
void delay_1ms(uint32_t count)
{
delay = count;
while(0U != delay){
}
}
/*!
\brief delay decrement
\param[in] none
\param[out] none
\retval none
*/
void delay_decrement(void)
{
if(0U != delay){
delay--;
}
}

View File

@ -0,0 +1,47 @@
/*!
\file systick.h
\brief the header file of systick
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#ifndef SYSTICK_H
#define SYSTICK_H
#include <stdint.h>
/* configure systick */
void systick_config(void);
/* delay a time in milliseconds */
void delay_1ms(uint32_t count);
/* delay decrement */
void delay_decrement(void);
#endif /* SYSTICK_H */

View File

@ -0,0 +1,15 @@
plain data :
0x6BC1BEE2 0x2E409F96 0xE93D7E11 0x7393172A [Block 1]
0xAE2D8A57 0x1E03AC9C 0x9EB76FAC 0x45AF8E51 [Block 2]
AES-128 encrypted data:
0x3AD77BB4 0x0D7A3660 0xA89ECAF3 0x2466EF97 [Block 1]
0xF5D3D585 0x03B9699D 0xE785895A 0x96FDBAAF [Block 2]
AES-128 decrypted data:
0x6BC1BEE2 0x2E409F96 0xE93D7E11 0x7393172A [Block 1]
0xAE2D8A57 0x1E03AC9C 0x9EB76FAC 0x45AF8E51 [Block 2]

View File

@ -0,0 +1,70 @@
/*!
\file gd32w51x_libopt.h
\brief library optional for gd32w51x
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#ifndef GD32W51X_LIBOPT_H
#define GD32W51X_LIBOPT_H
#include "gd32w51x_adc.h"
#include "gd32w51x_cau.h"
#include "gd32w51x_crc.h"
#include "gd32w51x_dbg.h"
#include "gd32w51x_dci.h"
#include "gd32w51x_dma.h"
#include "gd32w51x_efuse.h"
#include "gd32w51x_exti.h"
#include "gd32w51x_fmc.h"
#include "gd32w51x_fwdgt.h"
#include "gd32w51x_gpio.h"
#include "gd32w51x_hau.h"
#include "gd32w51x_hpdf.h"
#include "gd32w51x_i2c.h"
#include "gd32w51x_icache.h"
#include "gd32w51x_misc.h"
#include "gd32w51x_pkcau.h"
#include "gd32w51x_pmu.h"
#include "gd32w51x_qspi.h"
#include "gd32w51x_rcu.h"
#include "gd32w51x_rtc.h"
#include "gd32w51x_sdio.h"
#include "gd32w51x_spi.h"
#include "gd32w51x_sqpi.h"
#include "gd32w51x_syscfg.h"
#include "gd32w51x_timer.h"
#include "gd32w51x_trng.h"
#include "gd32w51x_tsi.h"
#include "gd32w51x_tzpcu.h"
#include "gd32w51x_usart.h"
#include "gd32w51x_wwdgt.h"
#endif /* GD32W51X_LIBOPT_H */

View File

@ -0,0 +1,212 @@
/*!
\file main.c
\brief CAU AESECB mode example
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "main.h"
#include "gd32w515p_eval.h"
uint32_t key_128[4]={0x2b7e1516, 0x28aed2a6, 0xabf71588, 0x09cf4f3c};
uint32_t plaintext[DATA_SIZE]={
0x6bc1bee2, 0x2e409f96, 0xe93d7e11, 0x7393172a, /* block 1 */
0xae2d8a57, 0x1e03ac9c, 0x9eb76fac, 0x45af8e51}; /* block 2 */
uint32_t encrypt_result[DATA_SIZE];
uint32_t decrypt_result[DATA_SIZE];
/* encrypt/decrypt data using AES */
static void aes_128_dma(uint32_t mode, uint32_t *source, uint32_t *dest);
/* printf data by a block of 16 bytes */
static void data_display(uint32_t datalength, uint32_t *data);
/*!
\brief main function
\param[in] none
\param[out] none
\retval none
*/
int main(void)
{
gd_eval_com_init(EVAL_COM0);
printf(" plain data :\r\n");
data_display(DATA_SIZE, plaintext);
/* encryption */
aes_128_dma(CAU_ENCRYPT, plaintext, encrypt_result);
printf(" \r\n\r\nAES-128 encrypted data:\r\n\r\n");
data_display(DATA_SIZE, encrypt_result);
/* decryption */
aes_128_dma(CAU_DECRYPT, encrypt_result, decrypt_result);
printf(" \r\n\r\nAES-128 decrypted data:\r\n\r\n");
data_display(DATA_SIZE, decrypt_result);
while(1){
}
}
/*!
\brief encrypt/decrypt data using AES
\param[in] mode: algorithm direction
\arg CAU_ENCRYPT: encrypt
\arg CAU_DECRYPT: decrypt
\param[in] source: pointer to the source address
\param[in] dest: pointer to the dest address
\param[out] none
\retval none
*/
static void aes_128_dma(uint32_t mode, uint32_t *source, uint32_t *dest)
{
cau_key_parameter_struct key_initpara;
dma_single_data_parameter_struct dma_initpara;
/* enable CAU clock */
rcu_periph_clock_enable(RCU_CAU);
/* enable DMA1 clock */
rcu_periph_clock_enable(RCU_DMA1);
/* key structure initialization */
cau_key_struct_para_init(&key_initpara);
cau_aes_keysize_config(CAU_KEYSIZE_128BIT);
key_initpara.key_2_high = key_128[0];
key_initpara.key_2_low = key_128[1];
key_initpara.key_3_high = key_128[2];
key_initpara.key_3_low = key_128[3];
/* key initialization */
cau_key_init(&key_initpara);
/* flush the IN and OUT FIFOs */
cau_fifo_flush();
if(CAU_ENCRYPT == mode){
/* initialize the CAU peripheral */
cau_init(CAU_ENCRYPT, CAU_MODE_AES_ECB, CAU_SWAPPING_32BIT);
cau_enable();
}else{
/* prepare the key */
cau_init(CAU_DECRYPT, CAU_MODE_AES_KEY, CAU_SWAPPING_32BIT);
cau_enable();
/* wait until the busy flag is reset */
while(RESET != cau_flag_get(CAU_FLAG_BUSY)){
}
/* initialize the CAU peripheral */
cau_init(CAU_DECRYPT, CAU_MODE_AES_ECB, CAU_SWAPPING_32BIT);
/* flush the IN and OUT FIFOs */
cau_fifo_flush();
cau_enable();
}
/* enable the CAU DMA interface */
cau_dma_enable(CAU_DMA_INFIFO | CAU_DMA_OUTFIFO);
/* DMA configuration */
dma_deinit(DMA1, DMA_CH5);
dma_deinit(DMA1, DMA_CH6);
dma_single_data_para_struct_init(&dma_initpara);
/* DMA1 channel6 for CAU_IN configuration */
dma_initpara.direction = DMA_MEMORY_TO_PERIPH;
dma_initpara.memory0_addr = (uint32_t)source;
dma_initpara.memory_inc = DMA_MEMORY_INCREASE_ENABLE;
dma_initpara.periph_memory_width = DMA_PERIPH_WIDTH_32BIT;
dma_initpara.circular_mode = DMA_CIRCULAR_MODE_DISABLE;
dma_initpara.number = DATA_SIZE;
dma_initpara.periph_addr = (uint32_t)(&CAU_DI);
dma_initpara.periph_inc = DMA_PERIPH_INCREASE_DISABLE;
dma_initpara.priority = DMA_PRIORITY_HIGH;
dma_single_data_mode_init(DMA1, DMA_CH6, &dma_initpara);
dma_channel_subperipheral_select(DMA1, DMA_CH6, DMA_SUBPERI2);
/* DMA1 channel5 for CAU_OUT configuration */
dma_initpara.direction = DMA_PERIPH_TO_MEMORY;
dma_initpara.memory0_addr = (uint32_t)dest;
dma_initpara.memory_inc = DMA_MEMORY_INCREASE_ENABLE;
dma_initpara.periph_memory_width = DMA_PERIPH_WIDTH_32BIT;
dma_initpara.circular_mode = DMA_CIRCULAR_MODE_DISABLE;
dma_initpara.number = DATA_SIZE;
dma_initpara.periph_addr = (uint32_t)(&CAU_DO);
dma_initpara.periph_inc = DMA_PERIPH_INCREASE_DISABLE;
dma_initpara.priority = DMA_PRIORITY_HIGH;
dma_single_data_mode_init(DMA1, DMA_CH5, &dma_initpara);
dma_channel_subperipheral_select(DMA1, DMA_CH5, DMA_SUBPERI2);
/* enable DMA transfer */
dma_channel_enable(DMA1, DMA_CH5);
dma_channel_enable(DMA1, DMA_CH6);
/* wait until the last transfer from OUT FIFO */
while(!dma_flag_get(DMA1, DMA_CH5, DMA_FLAG_FTF)){
}
dma_flag_clear(DMA1, DMA_CH5, DMA_FLAG_FTF);
dma_flag_clear(DMA1, DMA_CH6, DMA_FLAG_FTF);
cau_disable();
cau_dma_disable(CAU_DMA_INFIFO | CAU_DMA_OUTFIFO);
dma_channel_disable(DMA1, DMA_CH5);
dma_channel_disable(DMA1, DMA_CH6);
}
/*!
\brief printf data by a block of 16 bytes
\param[in] datalength: length of the data to display
\param[in] data: pointer to the data to display
\param[out] none
\retval none
*/
static void data_display(uint32_t datalength, uint32_t *data)
{
uint32_t i =0, count = 0;
for(i = 0; i < datalength; i++){
printf("0x%08X ", data[i]);
count++;
if(4 == count){
count = 0;
printf(" [Block %d] \r\n", (i/4) + 1);
}
}
}
/* retarget the C library printf function to the USART */
int fputc(int ch, FILE *f)
{
usart_data_transmit(EVAL_COM0, (uint8_t)ch);
while(RESET == usart_flag_get(EVAL_COM0, USART_FLAG_TBE));
return ch;
}

View File

@ -0,0 +1,44 @@
/*!
\file main.h
\brief the header file of main
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "gd32w51x.h"
#include "stdio.h"
#ifndef MAIN_H
#define MAIN_H
/* plain text size in words, it must be a multiple of 4(128 bits = 16 bytes = 4 words) for AES algorithm */
#define DATA_SIZE ((uint32_t)8)
#endif /* MAIN_H */

View File

@ -0,0 +1,41 @@
/*!
\file readme.txt
\brief description of CAU_AESECB_mode example
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
This demo is based on the GD32W515P-EVAL-V1.0 board, it shows how to use the CAU
peripheral to encrypt and decrypt data using AES-128 Algorithm.
For this example, DMA is used to transfer data from memory to the CAU processor
IN FIFO and also to transfer data from CAU processor OUT FIFO to memory.
The data to be encrypted is a 256-bit data (8 words), which corresponds to
2x AES-128 Blocks.
The all data can be displayed on a PC HyperTerminal using the USART.

View File

@ -0,0 +1,69 @@
plain text:
0x6B 0xC1 0xBE 0xE2 0x2E 0x40 0x9F 0x96 0xE9 0x3D 0x7E 0x11 0x73 0x93 0x17 0x2A [Block 0]
0xAE 0x2D 0x8A 0x57 0x1E 0x03 0xAC 0x9C 0x9E 0xB7 0x6F 0xAC 0x45 0xAF 0x8E 0x51 [Block 1]
0x30 0xC8 0x1C 0x46 0xA3 0x5C 0xE4 0x11 0xE5 0xFB 0xC1 0x19 0x1A 0x0A 0x52 0xEF [Block 2]
0xF6 0x9F 0x24 0x45 0xDF 0x4F 0x9B 0x17 0xAD 0x2B 0x41 0x7B 0xE6 0x6C 0x37 0x10 [Block 3]
encryption in GCM mode
encrypted data:
0x3B 0x3F 0xD9 0x2E 0xB7 0x2D 0xAD 0x20 0x33 0x34 0x49 0xF8 0xE8 0x3C 0xFB 0x4A [Block 0]
0x01 0x0C 0x04 0x19 0x99 0xE0 0x3F 0x36 0x44 0x86 0x24 0x48 0x3E 0x58 0x2D 0x0E [Block 1]
0xA6 0x22 0x93 0xCF 0xA6 0xDF 0x74 0x53 0x5C 0x35 0x41 0x81 0x16 0x87 0x74 0xDF [Block 2]
0x2D 0x55 0xA5 0x47 0x06 0x27 0x3C 0x50 0xD7 0xB4 0xF8 0xA8 0xCD 0xDC 0x6E 0xD7 [Block 3]
tag:
0x99 0x75 0x01 0xFA 0x29 0xEB 0xE5 0x54 0x49 0x5F 0xBE 0x0B 0xBA 0xF1 0xD8 0x22 [Block 0]
encryption in CCM mode
encrypted data:
0x99 0x41 0x6C 0x21 0x5B 0x8F 0xE6 0xD3 0xC9 0x0E 0x23 0xA8 0x58 0x83 0x60 0x38 [Block 0]
0xCD 0xD2 0xBA 0xCF 0x0A 0xFB 0x2C 0xB0 0xC1 0x0C 0x16 0x29 0xD9 0x3E 0xD7 0x36 [Block 1]
0x70 0xA8 0xF6 0xD5 0x1F 0xCC 0x2F 0x2D 0x77 0xCA 0x86 0xEA 0x3B 0x25 0x91 0x6C [Block 2]
0xEC 0x2C 0xEB 0xDE 0x42 0x55 0x40 0xA9 0xF3 0xB5 0x5F 0xF7 0x90 0x74 0xEE 0x14 [Block 3]
tag:
0xC3 0x2D 0x8D 0x3B 0x84 0x90
encryption in CFB mode
encrypted data:
0x3B 0x3F 0xD9 0x2E 0xB7 0x2D 0xAD 0x20 0x33 0x34 0x49 0xF8 0xE8 0x3C 0xFB 0x4A [Block 0]
0xC8 0xA6 0x45 0x37 0xA0 0xB3 0xA9 0x3F 0xCD 0xE3 0xCD 0xAD 0x9F 0x1C 0xE5 0x8B [Block 1]
0x26 0x75 0x1F 0x67 0xA3 0xCB 0xB1 0x40 0xB1 0x80 0x8C 0xF1 0x87 0xA4 0xF4 0xDF [Block 2]
0xC0 0x4B 0x05 0x35 0x7C 0x5D 0x1C 0x0E 0xEA 0xC4 0xC6 0x6F 0x9F 0xF7 0xF2 0xE6 [Block 3]
encryption in OFB mode
encrypted data:
0x3B 0x3F 0xD9 0x2E 0xB7 0x2D 0xAD 0x20 0x33 0x34 0x49 0xF8 0xE8 0x3C 0xFB 0x4A [Block 0]
0x77 0x89 0x50 0x8D 0x16 0x91 0x8F 0x03 0xF5 0x3C 0x52 0xDA 0xC5 0x4E 0xD8 0x25 [Block 1]
0x97 0x40 0x05 0x1E 0x9C 0x5F 0xEC 0xF6 0x43 0x44 0xF7 0xA8 0x22 0x60 0xED 0xCC [Block 2]
0x30 0x4C 0x65 0x28 0xF6 0x59 0xC7 0x78 0x66 0xA5 0x10 0xD9 0xC1 0xD6 0xAE 0x5E [Block 3]
decryption in GCM mode
decrypted data:
0x6B 0xC1 0xBE 0xE2 0x2E 0x40 0x9F 0x96 0xE9 0x3D 0x7E 0x11 0x73 0x93 0x17 0x2A [Block 0]
0xAE 0x2D 0x8A 0x57 0x1E 0x03 0xAC 0x9C 0x9E 0xB7 0x6F 0xAC 0x45 0xAF 0x8E 0x51 [Block 1]
0x30 0xC8 0x1C 0x46 0xA3 0x5C 0xE4 0x11 0xE5 0xFB 0xC1 0x19 0x1A 0x0A 0x52 0xEF [Block 2]
0xF6 0x9F 0x24 0x45 0xDF 0x4F 0x9B 0x17 0xAD 0x2B 0x41 0x7B 0xE6 0x6C 0x37 0x10 [Block 3]
tag:
0x99 0x75 0x01 0xFA 0x29 0xEB 0xE5 0x54 0x49 0x5F 0xBE 0x0B 0xBA 0xF1 0xD8 0x22 [Block 0]
decryption in CCM mode
decrypted data:
0x6B 0xC1 0xBE 0xE2 0x2E 0x40 0x9F 0x96 0xE9 0x3D 0x7E 0x11 0x73 0x93 0x17 0x2A [Block 0]
0xAE 0x2D 0x8A 0x57 0x1E 0x03 0xAC 0x9C 0x9E 0xB7 0x6F 0xAC 0x45 0xAF 0x8E 0x51 [Block 1]
0x30 0xC8 0x1C 0x46 0xA3 0x5C 0xE4 0x11 0xE5 0xFB 0xC1 0x19 0x1A 0x0A 0x52 0xEF [Block 2]
0xF6 0x9F 0x24 0x45 0xDF 0x4F 0x9B 0x17 0xAD 0x2B 0x41 0x7B 0xE6 0x6C 0x37 0x10 [Block 3]
tag:
0xC3 0x2D 0x8D 0x3B 0x84 0x90
decryption in CFB mode
decrypted data:
0x6B 0xC1 0xBE 0xE2 0x2E 0x40 0x9F 0x96 0xE9 0x3D 0x7E 0x11 0x73 0x93 0x17 0x2A [Block 0]
0xAE 0x2D 0x8A 0x57 0x1E 0x03 0xAC 0x9C 0x9E 0xB7 0x6F 0xAC 0x45 0xAF 0x8E 0x51 [Block 1]
0x30 0xC8 0x1C 0x46 0xA3 0x5C 0xE4 0x11 0xE5 0xFB 0xC1 0x19 0x1A 0x0A 0x52 0xEF [Block 2]
0xF6 0x9F 0x24 0x45 0xDF 0x4F 0x9B 0x17 0xAD 0x2B 0x41 0x7B 0xE6 0x6C 0x37 0x10 [Block 3]
decryption in OFB mode
decrypted data:
0x6B 0xC1 0xBE 0xE2 0x2E 0x40 0x9F 0x96 0xE9 0x3D 0x7E 0x11 0x73 0x93 0x17 0x2A [Block 0]
0xAE 0x2D 0x8A 0x57 0x1E 0x03 0xAC 0x9C 0x9E 0xB7 0x6F 0xAC 0x45 0xAF 0x8E 0x51 [Block 1]
0x30 0xC8 0x1C 0x46 0xA3 0x5C 0xE4 0x11 0xE5 0xFB 0xC1 0x19 0x1A 0x0A 0x52 0xEF [Block 2]
0xF6 0x9F 0x24 0x45 0xDF 0x4F 0x9B 0x17 0xAD 0x2B 0x41 0x7B 0xE6 0x6C 0x37 0x10 [Block 3]

View File

@ -0,0 +1,70 @@
/*!
\file gd32w51x_libopt.h
\brief library optional for gd32w51x
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#ifndef GD32W51X_LIBOPT_H
#define GD32W51X_LIBOPT_H
#include "gd32w51x_adc.h"
#include "gd32w51x_cau.h"
#include "gd32w51x_crc.h"
#include "gd32w51x_dbg.h"
#include "gd32w51x_dci.h"
#include "gd32w51x_dma.h"
#include "gd32w51x_efuse.h"
#include "gd32w51x_exti.h"
#include "gd32w51x_fmc.h"
#include "gd32w51x_fwdgt.h"
#include "gd32w51x_gpio.h"
#include "gd32w51x_hau.h"
#include "gd32w51x_hpdf.h"
#include "gd32w51x_i2c.h"
#include "gd32w51x_icache.h"
#include "gd32w51x_misc.h"
#include "gd32w51x_pkcau.h"
#include "gd32w51x_pmu.h"
#include "gd32w51x_qspi.h"
#include "gd32w51x_rcu.h"
#include "gd32w51x_rtc.h"
#include "gd32w51x_sdio.h"
#include "gd32w51x_spi.h"
#include "gd32w51x_sqpi.h"
#include "gd32w51x_syscfg.h"
#include "gd32w51x_timer.h"
#include "gd32w51x_trng.h"
#include "gd32w51x_tsi.h"
#include "gd32w51x_tzpcu.h"
#include "gd32w51x_usart.h"
#include "gd32w51x_wwdgt.h"
#endif /* GD32W51X_LIBOPT_H */

View File

@ -0,0 +1,300 @@
/*!
\file main.c
\brief CAU gcm, ccm, cfb, ofb example
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "gd32w515p_eval.h"
#include <stdio.h>
#define KEY_SIZE 128
#define AAD_SIZE 16
#define PLAINTEXT_SIZE 64
#define CIPHERTEXT_SIZE 64
#define TEXT_SIZE 64
#define IV_SIZE 16
#define CCM_IV_SIZE 8
#define CCM_TAG_SIZE 6
#define GCM_TAG_SIZE 16
const uint8_t key_128[KEY_SIZE] = {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c};
const uint8_t ccm_key_128[KEY_SIZE] = {0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f};
const uint8_t vectors[IV_SIZE] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f};
const uint8_t ccm_vectors[CCM_IV_SIZE] = {0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17};
const uint8_t aadmessage[AAD_SIZE] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f};
uint8_t plaintext[PLAINTEXT_SIZE] = {0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10};
uint8_t ciphertext_gcm[CIPHERTEXT_SIZE] = {0x3B, 0x3F, 0xD9, 0x2E, 0xB7, 0x2D, 0xAD, 0x20, 0x33, 0x34, 0x49, 0xF8, 0xE8, 0x3C, 0xFB, 0x4A,
0x01, 0x0C, 0x04, 0x19, 0x99, 0xE0, 0x3F, 0x36, 0x44, 0x86, 0x24, 0x48, 0x3E, 0x58, 0x2D, 0x0E,
0xA6, 0x22, 0x93, 0xCF, 0xA6, 0xDF, 0x74, 0x53, 0x5C, 0x35, 0x41, 0x81, 0x16, 0x87, 0x74, 0xDF,
0x2D, 0x55, 0xA5, 0x47, 0x06, 0x27, 0x3C, 0x50, 0xD7, 0xB4, 0xF8, 0xA8, 0xCD, 0xDC, 0x6E, 0xD7};
uint8_t ciphertext_ccm[CIPHERTEXT_SIZE] = {0x99, 0x41, 0x6c, 0x21, 0x5b, 0x8f, 0xe6, 0xd3, 0xc9, 0x0e, 0x23, 0xa8, 0x58, 0x83, 0x60, 0x38,
0xcd, 0xd2, 0xba, 0xcf, 0x0a, 0xfb, 0x2c, 0xb0, 0xc1, 0x0c, 0x16, 0x29, 0xd9, 0x3e, 0xd7, 0x36,
0x70, 0xa8, 0xf6, 0xd5, 0x1f, 0xcc, 0x2f, 0x2d, 0x77, 0xca, 0x86, 0xea, 0x3b, 0x25, 0x91, 0x6c,
0xec, 0x2c, 0xeb, 0xde, 0x42, 0x55, 0x40, 0xa9, 0xf3, 0xb5, 0x5f, 0xf7, 0x90, 0x74, 0xee, 0x14};
uint8_t ciphertext_cfb[CIPHERTEXT_SIZE] = {0x3b, 0x3f, 0xd9, 0x2e, 0xb7, 0x2d, 0xad, 0x20, 0x33, 0x34, 0x49, 0xf8, 0xe8, 0x3c, 0xfb, 0x4a,
0xc8, 0xa6, 0x45, 0x37, 0xa0, 0xb3, 0xa9, 0x3f, 0xcd, 0xe3, 0xcd, 0xad, 0x9f, 0x1c, 0xe5, 0x8b,
0x26, 0x75, 0x1f, 0x67, 0xa3, 0xcb, 0xb1, 0x40, 0xb1, 0x80, 0x8c, 0xf1, 0x87, 0xa4, 0xf4, 0xdf,
0xc0, 0x4b, 0x05, 0x35, 0x7c, 0x5d, 0x1c, 0x0e, 0xea, 0xc4, 0xc6, 0x6f, 0x9f, 0xf7, 0xf2, 0xe6};
uint8_t ciphertext_ofb[CIPHERTEXT_SIZE] = {0x3b, 0x3f, 0xd9, 0x2e, 0xb7, 0x2d, 0xad, 0x20, 0x33, 0x34, 0x49, 0xf8, 0xe8, 0x3c, 0xfb, 0x4a,
0x77, 0x89, 0x50, 0x8d, 0x16, 0x91, 0x8f, 0x03, 0xf5, 0x3c, 0x52, 0xda, 0xc5, 0x4e, 0xd8, 0x25,
0x97, 0x40, 0x05, 0x1e, 0x9c, 0x5f, 0xec, 0xf6, 0x43, 0x44, 0xf7, 0xa8, 0x22, 0x60, 0xed, 0xcc,
0x30, 0x4c, 0x65, 0x28, 0xf6, 0x59, 0xc7, 0x78, 0x66, 0xa5, 0x10, 0xd9, 0xc1, 0xd6, 0xae, 0x5e};
uint8_t encrypt_result[TEXT_SIZE];
uint8_t decrypt_result[TEXT_SIZE];
uint8_t ccm_tag[CCM_TAG_SIZE]; /* used for storing computed MAC (TAG) */
uint8_t gcm_tag[GCM_TAG_SIZE];
uint8_t aad_buf[AAD_SIZE + 21]; /* buffer used to append the aad. aad_buf[] size must be equal to AAD_SIZE + 21 */
void cau_aes_encrypt(void);
void cau_aes_decrypt(void);
void cau_parameter_printf(char* name, uint8_t *data, uint32_t data_size);
/*!
\brief main function
\param[in] none
\param[out] none
\retval none
*/
int main(void)
{
rcu_periph_clock_enable(RCU_CAU);
gd_eval_com_init(EVAL_COM0);
/* print input parameters */
cau_parameter_printf("plain text", (uint8_t *)plaintext, PLAINTEXT_SIZE);
/* encryption in GCM, CCM, CFB, OFB mode */
cau_aes_encrypt();
/* decryption in GCM, CCM, CFB, OFB mode */
cau_aes_decrypt();
while(1){
}
}
/*!
\brief encryption in GCM, CCM, CFB, OFB mode
\param[in] none
\param[out] none
\retval none
*/
void cau_aes_encrypt(void)
{
cau_parameter_struct cau_gcm_parameter;
cau_parameter_struct cau_ccm_parameter;
cau_parameter_struct cau_cfb_parameter;
cau_parameter_struct cau_ofb_parameter;
/* --------- encryption in GCM mode --------- */
cau_gcm_parameter.alg_dir = CAU_ENCRYPT;
cau_gcm_parameter.key = (uint8_t *)key_128;
cau_gcm_parameter.key_size = KEY_SIZE;
cau_gcm_parameter.iv = (uint8_t *)vectors;
cau_gcm_parameter.iv_size = IV_SIZE;
cau_gcm_parameter.input = (uint8_t *)plaintext;
cau_gcm_parameter.in_length = PLAINTEXT_SIZE;
cau_gcm_parameter.aad = (uint8_t *)aadmessage;
cau_gcm_parameter.aad_size = AAD_SIZE;
cau_aes_gcm(&cau_gcm_parameter, encrypt_result, gcm_tag);
printf("\r\nencryption in GCM mode\r\n");
/* print output parameters */
cau_parameter_printf("encrypted data", encrypt_result, PLAINTEXT_SIZE);
cau_parameter_printf("tag", gcm_tag, GCM_TAG_SIZE);
/* --------- encryption in CCM mode --------- */
cau_deinit();
cau_ccm_parameter.alg_dir = CAU_ENCRYPT;
cau_ccm_parameter.key = (uint8_t *)ccm_key_128;
cau_ccm_parameter.key_size = KEY_SIZE;
cau_ccm_parameter.iv = (uint8_t *)ccm_vectors;
cau_ccm_parameter.iv_size = CCM_IV_SIZE;
cau_ccm_parameter.input = (uint8_t *)plaintext;
cau_ccm_parameter.in_length = PLAINTEXT_SIZE;
cau_ccm_parameter.aad = (uint8_t *)aadmessage;
cau_ccm_parameter.aad_size = AAD_SIZE;
cau_aes_ccm(&cau_ccm_parameter, encrypt_result, ccm_tag, CCM_TAG_SIZE, (uint8_t *)aad_buf);
printf("\r\nencryption in CCM mode\r\n");
/* print output parameters */
cau_parameter_printf("encrypted data", encrypt_result, PLAINTEXT_SIZE);
cau_parameter_printf("tag", ccm_tag, CCM_TAG_SIZE);
printf("\r\n");
/* --------- encryption in CFB mode --------- */
cau_deinit();
cau_cfb_parameter.alg_dir = CAU_ENCRYPT;
cau_cfb_parameter.key = (uint8_t *)key_128;
cau_cfb_parameter.key_size = KEY_SIZE;
cau_cfb_parameter.iv = (uint8_t *)vectors;
cau_cfb_parameter.iv_size = IV_SIZE;
cau_cfb_parameter.input = (uint8_t *)plaintext;
cau_cfb_parameter.in_length = PLAINTEXT_SIZE;
cau_aes_cfb(&cau_cfb_parameter, encrypt_result);
printf("\r\nencryption in CFB mode\r\n");
/* print output parameters */
cau_parameter_printf("encrypted data", encrypt_result, PLAINTEXT_SIZE);
/* --------- encryption in OFB mode --------- */
cau_deinit();
cau_ofb_parameter.alg_dir = CAU_ENCRYPT;
cau_ofb_parameter.key = (uint8_t *)key_128;
cau_ofb_parameter.key_size = KEY_SIZE;
cau_ofb_parameter.iv = (uint8_t *)vectors;
cau_ofb_parameter.iv_size = IV_SIZE;
cau_ofb_parameter.input = (uint8_t *)plaintext;
cau_ofb_parameter.in_length = PLAINTEXT_SIZE;
cau_aes_ofb(&cau_ofb_parameter, encrypt_result);
printf("\r\nencryption in OFB mode\r\n" );
/* print output parameters */
cau_parameter_printf("encrypted data", encrypt_result, PLAINTEXT_SIZE);
}
/*!
\brief decryption in GCM, CCM, CFB, OFB mode
\param[in] none
\param[out] none
\retval none
*/
void cau_aes_decrypt(void)
{
cau_parameter_struct cau_gcm_parameter;
cau_parameter_struct cau_ccm_parameter;
cau_parameter_struct cau_cfb_parameter;
cau_parameter_struct cau_ofb_parameter;
/* --------- decryption in GCM mode --------- */
cau_deinit();
cau_gcm_parameter.alg_dir = CAU_DECRYPT;
cau_gcm_parameter.key = (uint8_t *)key_128;
cau_gcm_parameter.key_size = KEY_SIZE;
cau_gcm_parameter.iv = (uint8_t *)vectors;
cau_gcm_parameter.iv_size = IV_SIZE;
cau_gcm_parameter.input = (uint8_t *)ciphertext_gcm;
cau_gcm_parameter.in_length = CIPHERTEXT_SIZE;
cau_gcm_parameter.aad = (uint8_t *)aadmessage;
cau_gcm_parameter.aad_size = AAD_SIZE;
cau_aes_gcm(&cau_gcm_parameter, decrypt_result, gcm_tag);
printf("\r\ndecryption in GCM mode\r\n");
/* print output parameters */
cau_parameter_printf("decrypted data", decrypt_result, CIPHERTEXT_SIZE);
cau_parameter_printf("tag", gcm_tag, GCM_TAG_SIZE);
/* --------- decryption in CCM mode --------- */
cau_deinit();
cau_ccm_parameter.alg_dir = CAU_DECRYPT;
cau_ccm_parameter.key = (uint8_t *)ccm_key_128;
cau_ccm_parameter.key_size = KEY_SIZE;
cau_ccm_parameter.iv = (uint8_t *)ccm_vectors;
cau_ccm_parameter.iv_size = CCM_IV_SIZE;
cau_ccm_parameter.input = (uint8_t *)ciphertext_ccm;
cau_ccm_parameter.in_length = CIPHERTEXT_SIZE;
cau_ccm_parameter.aad = (uint8_t *)aadmessage;
cau_ccm_parameter.aad_size = AAD_SIZE;
cau_aes_ccm(&cau_ccm_parameter, decrypt_result, ccm_tag, CCM_TAG_SIZE, (uint8_t *)aad_buf);
printf("\r\ndecryption in CCM mode\r\n" );
/* print output parameters */
cau_parameter_printf("decrypted data", decrypt_result, CIPHERTEXT_SIZE);
cau_parameter_printf("tag", ccm_tag, CCM_TAG_SIZE);
printf("\r\n");
/* --------- decryption in CFB mode --------- */
cau_deinit();
cau_cfb_parameter.alg_dir = CAU_DECRYPT;
cau_cfb_parameter.key = (uint8_t *)key_128;
cau_cfb_parameter.key_size = KEY_SIZE;
cau_cfb_parameter.iv = (uint8_t *)vectors;
cau_cfb_parameter.iv_size = IV_SIZE;
cau_cfb_parameter.input = (uint8_t *)ciphertext_cfb;
cau_cfb_parameter.in_length = CIPHERTEXT_SIZE;
cau_aes_cfb(&cau_cfb_parameter,decrypt_result);
printf("\r\ndecryption in CFB mode\r\n" );
/* print output parameters */
cau_parameter_printf("decrypted data", decrypt_result, CIPHERTEXT_SIZE);
/* --------- decryption in OFB mode --------- */
cau_deinit();
cau_ofb_parameter.alg_dir = CAU_DECRYPT;
cau_ofb_parameter.key = (uint8_t *)key_128;
cau_ofb_parameter.key_size = KEY_SIZE;
cau_ofb_parameter.iv = (uint8_t *)vectors;
cau_ofb_parameter.iv_size = IV_SIZE;
cau_ofb_parameter.input = (uint8_t *)ciphertext_ofb;
cau_ofb_parameter.in_length = CIPHERTEXT_SIZE;
cau_aes_ofb(&cau_ofb_parameter,decrypt_result);
printf("\r\ndecryption in OFB mode\r\n" );
cau_parameter_printf("decrypted data", decrypt_result, CIPHERTEXT_SIZE);
}
/*!
\brief print cau parameter
\param[in] name: parameter name
\param[in] data: parameter raw data
\param[in] data_size: raw data size
\param[out] none
\retval none
*/
void cau_parameter_printf(char* name, uint8_t *data, uint32_t data_size)
{
uint32_t i =0, count = 0;
printf("%s:\n", name);
for(i = 0; i < data_size; i++){
printf("0x%02X ", data[i]);
count++;
if(16 == count){
count = 0;
printf(" [Block %d] \r\n", i/16);
}
}
}
/* retarget the C library printf function to the USART */
int fputc(int ch, FILE *f)
{
usart_data_transmit(EVAL_COM0, (uint8_t)ch);
while(RESET == usart_flag_get(EVAL_COM0, USART_FLAG_TBE));
return ch;
}

View File

@ -0,0 +1,39 @@
/*!
\file readme.txt
\brief description of cau aes gcm ccm cfb ofb example
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
This example is based on the GD32W515P-EVAL-V1.0 board, it shows how to use the CAU
peripheral to encrypt and decrypt data using AES in chaining modes(GCM, CCM, CFB, OFB)algorithm.
After encryption and decryption are completed, the encryption result and decryption
result are output through the USART.
The all data can be displayed on a PC HyperTerminal using the USART.

View File

@ -0,0 +1,150 @@
plain data :
0x6B 0xC1 0xBE 0xE2 0x2E 0x40 0x9F 0x96 0xE9 0x3D 0x7E 0x11 0x73 0x93 0x17 0x2A [Block 0]
0xAE 0x2D 0x8A 0x57 0x1E 0x03 0xAC 0x9C 0x9E 0xB7 0x6F 0xAC 0x45 0xAF 0x8E 0x51 [Block 1]
0x30 0xC8 0x1C 0x46 0xA3 0x5C 0xE4 0x11 0xE5 0xFB 0xC1 0x19 0x1A 0x0A 0x52 0xEF [Block 2]
0xF6 0x9F 0x24 0x45 0xDF 0x4F 0x9B 0x17 0xAD 0x2B 0x41 0x7B 0xE6 0x6C 0x37 0x10 [Block 3]
Encrypted Data with AES 128 Mode ECB :
0x3A 0xD7 0x7B 0xB4 0x0D 0x7A 0x36 0x60 0xA8 0x9E 0xCA 0xF3 0x24 0x66 0xEF 0x97 [Block 0]
0xF5 0xD3 0xD5 0x85 0x03 0xB9 0x69 0x9D 0xE7 0x85 0x89 0x5A 0x96 0xFD 0xBA 0xAF [Block 1]
0x43 0xB1 0xCD 0x7F 0x59 0x8E 0xCE 0x23 0x88 0x1B 0x00 0xE3 0xED 0x03 0x06 0x88 [Block 2]
0x7B 0x0C 0x78 0x5E 0x27 0xE8 0xAD 0x3F 0x82 0x23 0x20 0x71 0x04 0x72 0x5D 0xD4 [Block 3]
Encrypted Data with AES 192 Mode ECB :
0xBD 0x33 0x4F 0x1D 0x6E 0x45 0xF2 0x5F 0xF7 0x12 0xA2 0x14 0x57 0x1F 0xA5 0xCC [Block 0]
0x97 0x41 0x04 0x84 0x6D 0x0A 0xD3 0xAD 0x77 0x34 0xEC 0xB3 0xEC 0xEE 0x4E 0xEF [Block 1]
0xEF 0x7A 0xFD 0x22 0x70 0xE2 0xE6 0x0A 0xDC 0xE0 0xBA 0x2F 0xAC 0xE6 0x44 0x4E [Block 2]
0x9A 0x4B 0x41 0xBA 0x73 0x8D 0x6C 0x72 0xFB 0x16 0x69 0x16 0x03 0xC1 0x8E 0x0E [Block 3]
Encrypted Data with AES 256 Mode ECB :
0xF3 0xEE 0xD1 0xBD 0xB5 0xD2 0xA0 0x3C 0x06 0x4B 0x5A 0x7E 0x3D 0xB1 0x81 0xF8 [Block 0]
0x59 0x1C 0xCB 0x10 0xD4 0x10 0xED 0x26 0xDC 0x5B 0xA7 0x4A 0x31 0x36 0x28 0x70 [Block 1]
0xB6 0xED 0x21 0xB9 0x9C 0xA6 0xF4 0xF9 0xF1 0x53 0xE7 0xB1 0xBE 0xAF 0xED 0x1D [Block 2]
0x23 0x30 0x4B 0x7A 0x39 0xF9 0xF3 0xFF 0x06 0x7D 0x8D 0x8F 0x9E 0x24 0xEC 0xC7 [Block 3]
Decrypted Data with AES 128 Mode ECB :
0x6B 0xC0 0xBC 0xE1 0x2A 0x45 0x99 0x91 0xE1 0x34 0x74 0x1A 0x7F 0x9E 0x19 0x25 [Block 0]
0xD8 0x64 0x21 0xFB 0x9F 0x1A 0x1E 0xDA 0x50 0x5E 0xE1 0x37 0x57 0x46 0x97 0x2C [Block 1]
0x60 0x4E 0xD7 0xDD 0xF3 0x2E 0xFD 0xFF 0x70 0x20 0xD0 0x23 0x8B 0x7C 0x2A 0x5D [Block 2]
0x85 0x21 0xF2 0xFD 0x3C 0x8E 0xEF 0x2C 0xDC 0x3D 0xA7 0xE5 0xC4 0x4E 0xA2 0x06 [Block 3]
Decrypted Data with AES 192 Mode ECB :
0x4F 0x29 0xDF 0x6B 0x08 0x18 0x89 0xD1 0xD5 0x32 0x39 0x5C 0xF9 0x68 0x6D 0x3C [Block 0]
0xDA 0x32 0x3A 0x59 0x4B 0x66 0x84 0x2B 0x0C 0x2C 0x7D 0x54 0x26 0xBA 0xDB 0x43 [Block 1]
0x63 0xCC 0x39 0x59 0x12 0x82 0xF5 0x61 0xBB 0xC5 0xEC 0x77 0xD8 0x39 0x56 0xAE [Block 2]
0xD5 0x70 0xFD 0x6D 0x5B 0x9E 0x8E 0x40 0xAE 0x2D 0xBB 0xF2 0x14 0xC3 0x80 0x7E [Block 3]
Decrypted Data with AES 256 Mode ECB :
0xBB 0xC4 0x2D 0x8F 0x95 0x09 0xDB 0x39 0x1F 0xD8 0xB6 0x44 0x81 0xE6 0x1E 0xED [Block 0]
0x6D 0x7F 0xD8 0x8D 0x64 0x96 0x07 0x14 0xB8 0x12 0xDD 0xB8 0x16 0x75 0xF2 0x20 [Block 1]
0x6E 0xF9 0xB4 0x81 0x8E 0x70 0x61 0x4D 0x76 0x0C 0x03 0xE6 0xE1 0xB7 0xE1 0xED [Block 2]
0x81 0x4B 0xC2 0x11 0xD7 0x9C 0x47 0xDF 0xE3 0xDC 0x76 0x15 0xBD 0x2D 0xEB 0x86 [Block 3]
Encrypted Data with AES 128 Mode CBC :
0x76 0x49 0xAB 0xAC 0x81 0x19 0xB2 0x46 0xCE 0xE9 0x8E 0x9B 0x12 0xE9 0x19 0x7D [Block 0]
0x50 0x86 0xCB 0x9B 0x50 0x72 0x19 0xEE 0x95 0xDB 0x11 0x3A 0x91 0x76 0x78 0xB2 [Block 1]
0x73 0xBE 0xD6 0xB8 0xE3 0xC1 0x74 0x3B 0x71 0x16 0xE6 0x9E 0x22 0x22 0x95 0x16 [Block 2]
0x3F 0xF1 0xCA 0xA1 0x68 0x1F 0xAC 0x09 0x12 0x0E 0xCA 0x30 0x75 0x86 0xE1 0xA7 [Block 3]
Encrypted Data with AES 192 Mode CBC :
0x4F 0x02 0x1D 0xB2 0x43 0xBC 0x63 0x3D 0x71 0x78 0x18 0x3A 0x9F 0xA0 0x71 0xE8 [Block 0]
0xB4 0xD9 0xAD 0xA9 0xAD 0x7D 0xED 0xF4 0xE5 0xE7 0x38 0x76 0x3F 0x69 0x14 0x5A [Block 1]
0x57 0x1B 0x24 0x20 0x12 0xFB 0x7A 0xE0 0x7F 0xA9 0xBA 0xAC 0x3D 0xF1 0x02 0xE0 [Block 2]
0x08 0xB0 0xE2 0x79 0x88 0x59 0x88 0x81 0xD9 0x20 0xA9 0xE6 0x4F 0x56 0x15 0xCD [Block 3]
Encrypted Data with AES 256 Mode CBC :
0xF5 0x8C 0x4C 0x04 0xD6 0xE5 0xF1 0xBA 0x77 0x9E 0xAB 0xFB 0x5F 0x7B 0xFB 0xD6 [Block 0]
0x9C 0xFC 0x4E 0x96 0x7E 0xDB 0x80 0x8D 0x67 0x9F 0x77 0x7B 0xC6 0x70 0x2C 0x7D [Block 1]
0x39 0xF2 0x33 0x69 0xA9 0xD9 0xBA 0xCF 0xA5 0x30 0xE2 0x63 0x04 0x23 0x14 0x61 [Block 2]
0xB2 0xEB 0x05 0xE2 0xC3 0x9B 0xE9 0xFC 0xDA 0x6C 0x19 0x07 0x8C 0x6A 0x9D 0x1B [Block 3]
Decrypted Data with AES 128 Mode CBC :
0x6B 0xC1 0xBE 0xE2 0x2E 0x40 0x9F 0x96 0xE9 0x3D 0x7E 0x11 0x73 0x93 0x17 0x2A [Block 0]
0xAE 0x2D 0x8A 0x57 0x1E 0x03 0xAC 0x9C 0x9E 0xB7 0x6F 0xAC 0x45 0xAF 0x8E 0x51 [Block 1]
0x30 0xC8 0x1C 0x46 0xA3 0x5C 0xE4 0x11 0xE5 0xFB 0xC1 0x19 0x1A 0x0A 0x52 0xEF [Block 2]
0xF6 0x9F 0x24 0x45 0xDF 0x4F 0x9B 0x17 0xAD 0x2B 0x41 0x7B 0xE6 0x6C 0x37 0x10 [Block 3]
Decrypted Data with AES 192 Mode CBC :
0x4F 0x28 0xDD 0x68 0x0C 0x1D 0x8F 0xD6 0xDD 0x3B 0x33 0x57 0xF5 0x65 0x63 0x33 [Block 0]
0xAC 0x7B 0x91 0xF5 0xCA 0x7F 0x36 0x6D 0xC2 0xC5 0xF3 0xCF 0x34 0x53 0xC2 0x3E [Block 1]
0x33 0x4A 0xF2 0xC2 0x42 0xF0 0xEC 0x8F 0x2E 0x1E 0xFD 0x4D 0x49 0x4F 0x2E 0x1C [Block 2]
0xA6 0xCE 0x2B 0xD5 0xB8 0x5F 0xFA 0x7B 0xDF 0x3B 0x5D 0x6C 0x36 0xE1 0x15 0x68 [Block 3]
Decrypted Data with AES 256 Mode CBC :
0xBB 0xC5 0x2F 0x8C 0x91 0x0C 0xDD 0x3E 0x17 0xD1 0xBC 0x4F 0x8D 0xEB 0x10 0xE2 [Block 0]
0x1B 0x36 0x73 0x21 0xE5 0x8F 0xB5 0x52 0x76 0xFB 0x53 0x23 0x04 0x9C 0xEB 0x5D [Block 1]
0x3E 0x7F 0x7F 0x1A 0xDE 0x02 0x78 0xA3 0xE3 0xD7 0x12 0xDC 0x70 0xC1 0x99 0x5F [Block 2]
0xF2 0xF5 0x14 0xA9 0x34 0x5D 0x33 0xE4 0x92 0xCA 0x90 0x8B 0x9F 0x0F 0x7E 0x90 [Block 3]
Encrypted Data with AES 128 Mode CTR :
0x3B 0x3F 0xD9 0x2E 0xB7 0x2D 0xAD 0x20 0x33 0x34 0x49 0xF8 0xE8 0x3C 0xFB 0x4A [Block 0]
0x01 0x0C 0x04 0x19 0x99 0xE0 0x3F 0x36 0x44 0x86 0x24 0x48 0x3E 0x58 0x2D 0x0E [Block 1]
0xA6 0x22 0x93 0xCF 0xA6 0xDF 0x74 0x53 0x5C 0x35 0x41 0x81 0x16 0x87 0x74 0xDF [Block 2]
0x2D 0x55 0xA5 0x47 0x06 0x27 0x3C 0x50 0xD7 0xB4 0xF8 0xA8 0xCD 0xDC 0x6E 0xD7 [Block 3]
Encrypted Data with AES 192 Mode CTR :
0xCD 0xC8 0x0D 0x6F 0xDD 0xF1 0x8C 0xAB 0x34 0xC2 0x59 0x09 0xC9 0x9A 0x41 0x74 [Block 0]
0x37 0xD8 0xA6 0x39 0x17 0x1F 0xDC 0xCA 0x63 0xEB 0xD1 0x7C 0xE2 0xD7 0x32 0x1A [Block 1]
0x79 0xA0 0xC9 0x6B 0x53 0xC7 0xEE 0xEC 0xD9 0xED 0x71 0x57 0xC4 0x44 0xFC 0x7A [Block 2]
0x84 0x5C 0x37 0xB2 0xF5 0x11 0x69 0x7B 0x0E 0x89 0xD5 0xED 0x60 0xC4 0xD4 0x9E [Block 3]
Encrypted Data with AES 256 Mode CTR :
0xDC 0x7E 0x84 0xBF 0xDA 0x79 0x16 0x4B 0x7E 0xCD 0x84 0x86 0x98 0x5D 0x38 0x60 [Block 0]
0xD5 0x77 0x78 0x8B 0x8D 0x8A 0x85 0x74 0x55 0x13 0xA5 0xD5 0x0F 0x82 0x1F 0x30 [Block 1]
0xFF 0xE9 0x6D 0x5C 0xF5 0x4B 0x23 0x8D 0xCC 0x8D 0x67 0x83 0xA8 0x7F 0x3B 0xEA [Block 2]
0xE9 0xAF 0x54 0x63 0x44 0xCB 0x9C 0xA4 0xD1 0xE5 0x53 0xFF 0xC0 0x6B 0xC7 0x3E [Block 3]
Decrypted Data with AES 128 Mode CTR :
0x26 0xB7 0xCC 0x60 0x18 0x74 0x80 0xF0 0x14 0xE0 0xB9 0x72 0x89 0x46 0xF5 0x1D [Block 0]
0xFF 0xA7 0x45 0xD5 0xD7 0x91 0x8A 0x44 0x4F 0xEA 0x5A 0xDE 0xEA 0x81 0xDB 0xED [Block 1]
0xE5 0x54 0x59 0x31 0xE6 0x42 0xE4 0x79 0xC8 0xD8 0x66 0x06 0x2E 0xAF 0xB3 0x26 [Block 2]
0xE4 0x3B 0x4B 0xA3 0xB1 0x77 0x0B 0x4E 0x68 0x91 0x73 0xE3 0x5E 0x36 0xB8 0x60 [Block 3]
Decrypted Data with AES 192 Mode CTR :
0xD0 0x40 0x18 0x21 0x72 0xA8 0xA1 0x7B 0x13 0x16 0xA9 0x83 0xA8 0xE0 0x4F 0x23 [Block 0]
0xC9 0x73 0xE7 0xF5 0x59 0x6E 0x69 0xB8 0x68 0x87 0xAF 0xEA 0x36 0x0E 0xC4 0xF9 [Block 1]
0x3A 0xD6 0x03 0x95 0x13 0x5A 0x7E 0xC6 0x4D 0x00 0x56 0xD0 0xFC 0x6C 0x3B 0x83 [Block 2]
0x4D 0x32 0xD9 0x56 0x42 0x41 0x5E 0x65 0xB1 0xAC 0x5E 0xA6 0xF3 0x2E 0x02 0x29 [Block 3]
Decrypted Data with AES 256 Mode CTR :
0xC1 0xF6 0x91 0xF1 0x75 0x20 0x3B 0x9B 0x59 0x19 0x74 0x0C 0xF9 0x27 0x36 0x37 [Block 0]
0x2B 0xDC 0x39 0x47 0xC3 0xFB 0x30 0x06 0x5E 0x7F 0xDB 0x43 0xDB 0x5B 0xE9 0xD3 [Block 1]
0xBC 0x9F 0xA7 0xA2 0xB5 0xD6 0xB3 0xA7 0x58 0x60 0x40 0x04 0x90 0x57 0xFC 0x13 [Block 2]
0x20 0xC1 0xBA 0x87 0xF3 0x9B 0xAB 0xBA 0x6E 0xC0 0xD8 0xB4 0x53 0x81 0x11 0x89 [Block 3]

View File

@ -0,0 +1,70 @@
/*!
\file gd32w51x_libopt.h
\brief library optional for gd32w51x
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#ifndef GD32W51X_LIBOPT_H
#define GD32W51X_LIBOPT_H
#include "gd32w51x_adc.h"
#include "gd32w51x_cau.h"
#include "gd32w51x_crc.h"
#include "gd32w51x_dbg.h"
#include "gd32w51x_dci.h"
#include "gd32w51x_dma.h"
#include "gd32w51x_efuse.h"
#include "gd32w51x_exti.h"
#include "gd32w51x_fmc.h"
#include "gd32w51x_fwdgt.h"
#include "gd32w51x_gpio.h"
#include "gd32w51x_hau.h"
#include "gd32w51x_hpdf.h"
#include "gd32w51x_i2c.h"
#include "gd32w51x_icache.h"
#include "gd32w51x_misc.h"
#include "gd32w51x_pkcau.h"
#include "gd32w51x_pmu.h"
#include "gd32w51x_qspi.h"
#include "gd32w51x_rcu.h"
#include "gd32w51x_rtc.h"
#include "gd32w51x_sdio.h"
#include "gd32w51x_spi.h"
#include "gd32w51x_sqpi.h"
#include "gd32w51x_syscfg.h"
#include "gd32w51x_timer.h"
#include "gd32w51x_trng.h"
#include "gd32w51x_tsi.h"
#include "gd32w51x_tzpcu.h"
#include "gd32w51x_usart.h"
#include "gd32w51x_wwdgt.h"
#endif /* GD32W51X_LIBOPT_H */

View File

@ -0,0 +1,243 @@
/*!
\file main.c
\brief CAU AES modes example
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "main.h"
#include "gd32w515p_eval.h"
uint8_t key_128[16] = {0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,
0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c};
uint8_t key_192[24] = {0x8e,0x73,0xb0,0xf7,0xda,0x0e,0x64,0x52,
0xc8,0x10,0xf3,0x2b,0x80,0x90,0x79,0xe5,
0x62,0xf8,0xea,0xd2,0x52,0x2c,0x6b,0x7b};
uint8_t key_256[32] = {0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4};
uint8_t *key_select[3] = {key_128, key_192, key_256};
uint16_t keysize[3] = {128, 192, 256};
uint8_t vectors[16] = {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f};
uint8_t plaintext[TEXT_SIZE] =
{0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10};
uint8_t ciphertext[TEXT_SIZE] =
{0x76,0x49,0xab,0xac,0x81,0x19,0xb2,0x46,
0xce,0xe9,0x8e,0x9b,0x12,0xe9,0x19,0x7d,
0x50,0x86,0xcb,0x9b,0x50,0x72,0x19,0xee,
0x95,0xdb,0x11,0x3a,0x91,0x76,0x78,0xb2,
0x73,0xbe,0xd6,0xb8,0xe3,0xc1,0x74,0x3b,
0x71,0x16,0xe6,0x9e,0x22,0x22,0x95,0x16,
0x3f,0xf1,0xca,0xa1,0x68,0x1f,0xac,0x09,
0x12,0x0e,0xca,0x30,0x75,0x86,0xe1,0xa7};
uint8_t encrypt_result[TEXT_SIZE];
uint8_t decrypt_result[TEXT_SIZE];
uint32_t i = 0;
/* printf data by a block of 16 bytes */
static void data_display(uint32_t datalength, uint8_t *data);
/*!
\brief main function
\param[in] none
\param[out] none
\retval none
*/
int main(void)
{
cau_parameter_struct text;
uint8_t *key_addr;
uint32_t key_size;
gd_eval_com_init(EVAL_COM0);
/* enable CAU clock */
rcu_periph_clock_enable(RCU_CAU);
printf("\r\nplain data :\r\n");
data_display(TEXT_SIZE, plaintext);
cau_struct_para_init(&text);
/* encryption in ECB mode */
/* ECB mode: AES 128 -> AES 192 -> AES 256 */
for(i = 0; i < 3; i++){
key_addr = key_select[i];
key_size = keysize[i];
text.alg_dir = CAU_ENCRYPT;
text.key = key_addr;
text.key_size = key_size;
text.input = plaintext;
text.in_length = TEXT_SIZE;
if(SUCCESS == cau_aes_ecb(&text, encrypt_result)){
printf(" \r\n\r\nEncrypted Data with AES %d Mode ECB :\r\n\r\n", key_size);
data_display(TEXT_SIZE, encrypt_result);
}
}
/* decryption in ECB mode */
/* ECB mode: AES 128 -> AES 192 -> AES 256 */
for(i = 0; i < 3; i++){
key_addr = key_select[i];
key_size = keysize[i];
text.alg_dir = CAU_DECRYPT;
text.key = key_addr;
text.key_size = key_size;
text.input = ciphertext;
text.in_length = TEXT_SIZE;
if(SUCCESS == cau_aes_ecb(&text, decrypt_result)){
printf(" \r\n\r\nDecrypted Data with AES %d Mode ECB :\r\n\r\n", key_size);
data_display(TEXT_SIZE, decrypt_result);
}
}
/* encryption in CBC mode */
/* CBC mode: AES 128 -> AES 192 -> AES 256 */
for(i = 0; i < 3; i++){
key_addr = key_select[i];
key_size = keysize[i];
text.alg_dir = CAU_ENCRYPT;
text.key = key_addr;
text.key_size = key_size;
text.iv = vectors;
text.input = plaintext;
text.in_length = TEXT_SIZE;
if(SUCCESS == cau_aes_cbc(&text, encrypt_result)){
printf(" \r\n\r\nEncrypted Data with AES %d Mode CBC :\r\n\r\n", key_size);
data_display(TEXT_SIZE, encrypt_result);
}
}
/* decryption in CBC mode */
/* CBC mode: AES 128 -> AES 192 -> AES 256 */
for(i = 0; i < 3; i++){
key_addr = key_select[i];
key_size = keysize[i];
text.alg_dir = CAU_DECRYPT;
text.key = key_addr;
text.key_size = key_size;
text.iv = vectors;
text.input = ciphertext;
text.in_length = TEXT_SIZE;
if(SUCCESS == cau_aes_cbc(&text, decrypt_result)){
printf(" \r\n\r\nDecrypted Data with AES %d Mode CBC :\r\n\r\n", key_size);
data_display(TEXT_SIZE, decrypt_result);
}
}
/* encryption in CTR mode */
/* CTR mode: AES 128 -> AES 192 -> AES 256 */
for(i = 0; i < 3; i++){
key_addr = key_select[i];
key_size = keysize[i];
text.alg_dir = CAU_ENCRYPT;
text.key = key_addr;
text.key_size = key_size;
text.iv = vectors;
text.input = plaintext;
text.in_length = TEXT_SIZE;
if(SUCCESS == cau_aes_ctr(&text, encrypt_result)){
printf(" \r\n\r\nEncrypted Data with AES %d Mode CTR :\r\n\r\n", key_size);
data_display(TEXT_SIZE, encrypt_result);
}
}
/* decryption in CTR mode */
/* CTR mode: AES 128 -> AES 192 -> AES 256 */
for(i = 0; i < 3; i++){
key_addr = key_select[i];
key_size = keysize[i];
text.alg_dir = CAU_DECRYPT;
text.key = key_addr;
text.key_size = key_size;
text.iv = vectors;
text.input = ciphertext;
text.in_length = TEXT_SIZE;
if(SUCCESS == cau_aes_ctr(&text, decrypt_result)){
printf(" \r\n\r\nDecrypted Data with AES %d Mode CTR :\r\n\r\n", key_size);
data_display(TEXT_SIZE, decrypt_result);
}
}
while(1){
}
}
/*!
\brief printf data by a block of 16 bytes
\param[in] datalength: length of the data to display
\param[in] data: pointer to the data to display
\param[out] none
\retval none
*/
static void data_display(uint32_t datalength, uint8_t *data)
{
uint32_t i =0, count = 0;
for(i = 0; i < datalength; i++){
printf("0x%02X ", data[i]);
count++;
if(16 == count){
count = 0;
printf(" [Block %d] \r\n", i/16);
}
}
}
/* retarget the C library printf function to the USART */
int fputc(int ch, FILE *f)
{
usart_data_transmit(EVAL_COM0, (uint8_t)ch);
while(RESET == usart_flag_get(EVAL_COM0, USART_FLAG_TBE));
return ch;
}

View File

@ -0,0 +1,44 @@
/*!
\file main.h
\brief the header file of main
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "gd32w51x.h"
#include "stdio.h"
#ifndef MAIN_H
#define MAIN_H
/* plain text size in bytes, it must be a multiple of 16(128 bits = 16 bytes) for AES algorithm */
#define TEXT_SIZE 64
#endif /* MAIN_H */

View File

@ -0,0 +1,38 @@
/*!
\file readme.txt
\brief description of CAU_AES_modes example
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
This demo is based on the GD32W515P-EVAL-V1.0 board, it shows how to use the
CAU peripheral to encrypt and decrypt data using AES in chaining modes
(ECB, CBC, CTR) and all key sizes (128, 192, 256) Algorithm.
The all data can be displayed on a PC HyperTerminal using the USART.

View File

@ -0,0 +1,35 @@
plain data :
0x31 0x32 0x33 0x34 0x35 0x36 0x37 0x38 [Block 0]
encrypted data with DES Mode ECB :
0xAF 0xE6 0x49 0x61 0xCC 0x4F 0x7C 0x13 [Block 0]
decrypted data with DES Mode ECB :
0x31 0x32 0x33 0x34 0x35 0x36 0x37 0x38 [Block 0]
encrypted data with DES Mode CBC :
0xD4 0xE3 0x6B 0x07 0x60 0xBD 0x60 0x15 [Block 0]
decrypted data with DES Mode CBC :
0x31 0x32 0x33 0x34 0x35 0x36 0x37 0x38 [Block 0]
encrypted data with TDES Mode ECB :
0x50 0x08 0x77 0xCB 0x7B 0x95 0xBC 0x0C [Block 0]
decrypted data with TDES Mode ECB :
0x31 0x32 0x33 0x34 0x35 0x36 0x37 0x38 [Block 0]
encrypted data with TDES Mode CBC :
0x06 0x63 0x86 0xC3 0x3E 0xCB 0x14 0xDF [Block 0]
decrypted data with TDES Mode CBC :
0x31 0x32 0x33 0x34 0x35 0x36 0x37 0x38 [Block 0]

View File

@ -0,0 +1,70 @@
/*!
\file gd32w51x_libopt.h
\brief library optional for gd32w51x
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#ifndef GD32W51X_LIBOPT_H
#define GD32W51X_LIBOPT_H
#include "gd32w51x_adc.h"
#include "gd32w51x_cau.h"
#include "gd32w51x_crc.h"
#include "gd32w51x_dbg.h"
#include "gd32w51x_dci.h"
#include "gd32w51x_dma.h"
#include "gd32w51x_efuse.h"
#include "gd32w51x_exti.h"
#include "gd32w51x_fmc.h"
#include "gd32w51x_fwdgt.h"
#include "gd32w51x_gpio.h"
#include "gd32w51x_hau.h"
#include "gd32w51x_hpdf.h"
#include "gd32w51x_i2c.h"
#include "gd32w51x_icache.h"
#include "gd32w51x_misc.h"
#include "gd32w51x_pkcau.h"
#include "gd32w51x_pmu.h"
#include "gd32w51x_qspi.h"
#include "gd32w51x_rcu.h"
#include "gd32w51x_rtc.h"
#include "gd32w51x_sdio.h"
#include "gd32w51x_spi.h"
#include "gd32w51x_sqpi.h"
#include "gd32w51x_syscfg.h"
#include "gd32w51x_timer.h"
#include "gd32w51x_trng.h"
#include "gd32w51x_tsi.h"
#include "gd32w51x_tzpcu.h"
#include "gd32w51x_usart.h"
#include "gd32w51x_wwdgt.h"
#endif /* GD32W51X_LIBOPT_H */

View File

@ -0,0 +1,188 @@
/*!
\file main.c
\brief CAU DES/TDES modes example
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "main.h"
#include "gd32w515p_eval.h"
/* key size 64 bytes */
uint8_t des_key[8] = {0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6};
/* key : 192 bits */
uint8_t tdes_key[24] = {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF,
0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10,
0x89,0xAB,0xCD,0xEF,0x01,0x23,0x45,0x67};
uint8_t plaintext[DATA_SIZE] = {0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38};
/* initialization vector */
uint8_t vectors[8] = {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07};
uint8_t encrypt_result[DATA_SIZE];
uint8_t decrypt_result[DATA_SIZE];
/* printf data by a block of 8 bytes */
static void data_display(uint32_t datalength, uint8_t *data);
/*!
\brief main function
\param[in] none
\param[out] none
\retval none
*/
int main(void)
{
cau_parameter_struct text;
gd_eval_com_init(EVAL_COM0);
/* enable CAU clock */
rcu_periph_clock_enable(RCU_CAU);
printf("\r\nplain data :\r\n");
data_display(DATA_SIZE, plaintext);
cau_struct_para_init(&text);
/* encryption in DES ECB mode */
text.alg_dir = CAU_ENCRYPT;
text.key = des_key;
text.input = plaintext;
text.in_length = DATA_SIZE;
if(SUCCESS == cau_des_ecb(&text, encrypt_result)){
printf(" \r\n encrypted data with DES Mode ECB :\r\n\r\n");
data_display(DATA_SIZE, encrypt_result);
}
/* decryption in DES ECB mode */
text.alg_dir = CAU_DECRYPT;
text.key = des_key;
text.input = encrypt_result;
text.in_length = DATA_SIZE;
if(SUCCESS == cau_des_ecb(&text, decrypt_result)){
printf(" \r\n decrypted data with DES Mode ECB :\r\n\r\n");
data_display(DATA_SIZE, decrypt_result);
}
/* encryption in DES CBC mode */
text.alg_dir = CAU_ENCRYPT;
text.key = des_key;
text.iv = vectors;
text.input = plaintext;
text.in_length = DATA_SIZE;
if(SUCCESS == cau_des_cbc(&text, encrypt_result)){
printf(" \r\n encrypted data with DES Mode CBC :\r\n\r\n");
data_display(DATA_SIZE, encrypt_result);
}
/* decryption in DES CBC mode */
text.alg_dir = CAU_DECRYPT;
text.key = des_key;
text.iv = vectors;
text.input = encrypt_result;
text.in_length = DATA_SIZE;
if(SUCCESS == cau_des_cbc(&text, decrypt_result)){
printf(" \r\n decrypted data with DES Mode CBC :\r\n\r\n");
data_display(DATA_SIZE, decrypt_result);
}
/* encryption in TDES ECB mode */
text.alg_dir = CAU_ENCRYPT;
text.key = tdes_key;
text.input = plaintext;
text.in_length = DATA_SIZE;
if(SUCCESS == cau_tdes_ecb(&text, encrypt_result)){
printf(" \r\n encrypted data with TDES Mode ECB :\r\n\r\n");
data_display(DATA_SIZE, encrypt_result);
}
/* decryption in TDES ECB mode */
text.alg_dir = CAU_DECRYPT;
text.key = tdes_key;
text.input = encrypt_result;
text.in_length = DATA_SIZE;
if(SUCCESS == cau_tdes_ecb(&text, decrypt_result)){
printf(" \r\n decrypted data with TDES Mode ECB :\r\n\r\n");
data_display(DATA_SIZE, decrypt_result);
}
/* encryption in TDES CBC mode */
text.alg_dir = CAU_ENCRYPT;
text.key = tdes_key;
text.iv = vectors;
text.input = plaintext;
text.in_length = DATA_SIZE;
if(SUCCESS == cau_tdes_cbc(&text, encrypt_result)){
printf(" \r\n encrypted data with TDES Mode CBC :\r\n\r\n");
data_display(DATA_SIZE, encrypt_result);
}
/* decryption in TDES CBC mode */
text.alg_dir = CAU_DECRYPT;
text.key = tdes_key;
text.iv = vectors;
text.input = encrypt_result;
text.in_length = DATA_SIZE;
if(SUCCESS == cau_tdes_cbc(&text, decrypt_result)){
printf(" \r\n decrypted data with TDES Mode CBC :\r\n\r\n");
data_display(DATA_SIZE, decrypt_result);
}
while(1){
}
}
/*!
\brief printf data by a block of 8 bytes
\param[in] datalength: length of the data to display
\param[in] data: pointer to the data to display
\param[out] none
\retval none
*/
static void data_display(uint32_t datalength, uint8_t *data)
{
uint32_t i =0, count = 0;
for(i = 0; i < datalength; i++){
printf("0x%02X ", data[i]);
count++;
if(8 == count){
count = 0;
printf(" [Block %d] \r\n", i/8);
}
}
}
/* retarget the C library printf function to the USART */
int fputc(int ch, FILE *f)
{
usart_data_transmit(EVAL_COM0, (uint8_t)ch);
while(RESET == usart_flag_get(EVAL_COM0, USART_FLAG_TBE));
return ch;
}

View File

@ -0,0 +1,43 @@
/*!
\file main.h
\brief the header file of main
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "gd32w51x.h"
#include "stdio.h"
#ifndef MAIN_H
#define MAIN_H
#define DATA_SIZE 8
#endif /* MAIN_H */

View File

@ -0,0 +1,38 @@
/*!
\file readme.txt
\brief description of CAU_DES_TDES_modes example
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
This demo is based on the GD32W515P-EVAL-V1.0 board, it shows how to use the CAU
peripheral to encrypt and decrypt data using DES and TDES in all modes (ECB, CBC)
algorithm.
The all data can be displayed on a PC HyperTerminal using the USART.

View File

@ -0,0 +1,22 @@
plain data :
0x20212223 0x24252627 [Block 0]
0x28292A2B 0x2C2D2E2F [Block 1]
0xFFEEDDCC 0xBBAA9988 [Block 2]
0x77665544 0x33221100 [Block 3]
0x10000000 0x20000000 [Block 4]
TDES encrypted data:
0xC9406174 0xF076C814 [Block 0]
0x81A2BCB1 0x4ED3E70D [Block 1]
0x54351409 0x6C4E674B [Block 2]
0x4FDE2AEC 0xDBE00AC3 [Block 3]
0xEE46220C 0xCAB2CEFB [Block 4]
TDES decrypted data:
0x20212223 0x24252627 [Block 0]
0x28292A2B 0x2C2D2E2F [Block 1]
0xFFEEDDCC 0xBBAA9988 [Block 2]
0x77665544 0x33221100 [Block 3]
0x10000000 0x20000000 [Block 4]

View File

@ -0,0 +1,70 @@
/*!
\file gd32w51x_libopt.h
\brief library optional for gd32w51x
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#ifndef GD32W51X_LIBOPT_H
#define GD32W51X_LIBOPT_H
#include "gd32w51x_adc.h"
#include "gd32w51x_cau.h"
#include "gd32w51x_crc.h"
#include "gd32w51x_dbg.h"
#include "gd32w51x_dci.h"
#include "gd32w51x_dma.h"
#include "gd32w51x_efuse.h"
#include "gd32w51x_exti.h"
#include "gd32w51x_fmc.h"
#include "gd32w51x_fwdgt.h"
#include "gd32w51x_gpio.h"
#include "gd32w51x_hau.h"
#include "gd32w51x_hpdf.h"
#include "gd32w51x_i2c.h"
#include "gd32w51x_icache.h"
#include "gd32w51x_misc.h"
#include "gd32w51x_pkcau.h"
#include "gd32w51x_pmu.h"
#include "gd32w51x_qspi.h"
#include "gd32w51x_rcu.h"
#include "gd32w51x_rtc.h"
#include "gd32w51x_sdio.h"
#include "gd32w51x_spi.h"
#include "gd32w51x_sqpi.h"
#include "gd32w51x_syscfg.h"
#include "gd32w51x_timer.h"
#include "gd32w51x_trng.h"
#include "gd32w51x_tsi.h"
#include "gd32w51x_tzpcu.h"
#include "gd32w51x_usart.h"
#include "gd32w51x_wwdgt.h"
#endif /* GD32W51X_LIBOPT_H */

View File

@ -0,0 +1,205 @@
/*!
\file main.c
\brief CAU TDESECB mode example
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "main.h"
#include "gd32w515p_eval.h"
/* 192 bit key */
uint32_t tdes_key[6]={
0x40414243,0x44454647, /* KEY1 */
0x48494A4B,0x4C4D4E4F, /* KEY2 */
0x50515253,0x54555657}; /* KEY3 */
uint32_t plaintext[DATA_SIZE]={
0x20212223,0x24252627, /* block 0 */
0x28292a2b,0x2c2d2e2f, /* block 1 */
0xFFEEDDCC,0xBBAA9988, /* block 2 */
0x77665544,0x33221100, /* block 3 */
0x10000000,0x20000000 }; /* block 4 */
uint32_t encrypt_result[DATA_SIZE];
uint32_t decrypt_result[DATA_SIZE];
/* encrypt/decrypt data using TDES */
static void tdes_dma(uint32_t mode, uint32_t *source, uint32_t *dest);
/* printf data by a block of 8 bytes */
static void data_display(uint32_t datalength, uint32_t *data);
/*!
\brief main function
\param[in] none
\param[out] none
\retval none
*/
int main(void)
{
gd_eval_com_init(EVAL_COM0);
printf(" plain data :\r\n");
data_display(DATA_SIZE, plaintext);
/* encrypt */
tdes_dma(CAU_ENCRYPT, plaintext, encrypt_result);
printf(" \r\nTDES encrypted data:\r\n\r\n");
data_display(DATA_SIZE, encrypt_result);
/* decrypt */
tdes_dma(CAU_DECRYPT, encrypt_result, decrypt_result);
printf(" \r\nTDES decrypted data:\r\n\r\n");
data_display(DATA_SIZE, decrypt_result);
while(1){
}
}
/*!
\brief encrypt/decrypt data using TDES
\param[in] mode: algorithm direction
\arg CAU_ENCRYPT: encrypt
\arg CAU_DECRYPT: decrypt
\param[in] source: pointer to the source address
\param[in] dest: pointer to the dest address
\param[out] none
\retval none
*/
static void tdes_dma(uint32_t mode, uint32_t *source, uint32_t *dest)
{
cau_key_parameter_struct key_initpara;
dma_single_data_parameter_struct dma_initpara;
/* enable CAU clock */
rcu_periph_clock_enable(RCU_CAU);
/* Enable DMA1 clock */
rcu_periph_clock_enable(RCU_DMA1);
cau_fifo_flush();
/* key structure initialization */
cau_key_struct_para_init(&key_initpara);
key_initpara.key_1_high = tdes_key[0];
key_initpara.key_1_low = tdes_key[1];
key_initpara.key_2_high = tdes_key[2];
key_initpara.key_2_low = tdes_key[3];
key_initpara.key_3_high = tdes_key[4];
key_initpara.key_3_low = tdes_key[5];
/* key initialization */
cau_key_init(&key_initpara);
/* initialize the CAU peripheral */
cau_init(mode, CAU_MODE_TDES_ECB, CAU_SWAPPING_32BIT);
/* flush the IN and OUT FIFOs */
cau_fifo_flush();
cau_enable();
/* enable the CAU DMA interface */
cau_dma_enable(CAU_DMA_INFIFO | CAU_DMA_OUTFIFO);
/* DMA configuration */
dma_deinit(DMA1, DMA_CH5);
dma_deinit(DMA1, DMA_CH6);
dma_single_data_para_struct_init(&dma_initpara);
/* DMA1 channel6 for CAU_IN configuration */
dma_initpara.direction = DMA_MEMORY_TO_PERIPH;
dma_initpara.memory0_addr = (uint32_t)source;
dma_initpara.memory_inc = DMA_MEMORY_INCREASE_ENABLE;
dma_initpara.periph_memory_width = DMA_PERIPH_WIDTH_32BIT;
dma_initpara.circular_mode = DMA_CIRCULAR_MODE_DISABLE;
dma_initpara.number = DATA_SIZE;
dma_initpara.periph_addr = (uint32_t)(&CAU_DI);
dma_initpara.periph_inc = DMA_PERIPH_INCREASE_DISABLE;
dma_initpara.priority = DMA_PRIORITY_HIGH;
dma_single_data_mode_init(DMA1, DMA_CH6, &dma_initpara);
dma_channel_subperipheral_select(DMA1, DMA_CH6, DMA_SUBPERI2);
/* DMA1 channel5 for CAU_OUT configuration */
dma_initpara.direction = DMA_PERIPH_TO_MEMORY;
dma_initpara.memory0_addr = (uint32_t)dest;
dma_initpara.memory_inc = DMA_MEMORY_INCREASE_ENABLE;
dma_initpara.periph_memory_width = DMA_PERIPH_WIDTH_32BIT;
dma_initpara.circular_mode = DMA_CIRCULAR_MODE_DISABLE;
dma_initpara.number = DATA_SIZE;
dma_initpara.periph_addr = (uint32_t)(&CAU_DO);
dma_initpara.periph_inc = DMA_PERIPH_INCREASE_DISABLE;
dma_initpara.priority = DMA_PRIORITY_HIGH;
dma_single_data_mode_init(DMA1, DMA_CH5, &dma_initpara);
dma_channel_subperipheral_select(DMA1, DMA_CH5, DMA_SUBPERI2);
/* enable DMA transfer */
dma_channel_enable(DMA1, DMA_CH5);
dma_channel_enable(DMA1, DMA_CH6);
/* wait until the last transfer from OUT FIFO */
while(!dma_flag_get(DMA1, DMA_CH5, DMA_FLAG_FTF)){
}
dma_flag_clear(DMA1, DMA_CH5, DMA_FLAG_FTF);
dma_flag_clear(DMA1, DMA_CH6, DMA_FLAG_FTF);
cau_disable();
cau_dma_disable(CAU_DMA_INFIFO | CAU_DMA_OUTFIFO);
dma_channel_disable(DMA1, DMA_CH5);
dma_channel_disable(DMA1, DMA_CH6);
}
/*!
\brief printf data by a block of 8 bytes
\param[in] datalength: length of the data to display
\param[in] data: pointer to the data to display
\param[out] none
\retval none
*/
static void data_display(uint32_t datalength, uint32_t *data)
{
uint32_t i =0, count = 0;
for(i = 0; i < datalength; i++){
printf("0x%08X ", data[i]);
count++;
if(2 == count){
count = 0;
printf(" [Block %d] \r\n", (i/2));
}
}
}
/* retarget the C library printf function to the USART */
int fputc(int ch, FILE *f)
{
usart_data_transmit(EVAL_COM0, (uint8_t)ch);
while(RESET == usart_flag_get(EVAL_COM0, USART_FLAG_TBE));
return ch;
}

View File

@ -0,0 +1,44 @@
/*!
\file main.h
\brief the header file of main
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "gd32w51x.h"
#include "stdio.h"
#ifndef MAIN_H
#define MAIN_H
#define BLOCKS_NBR 5
#define DATA_SIZE ((BLOCKS_NBR*64)/32)
#endif /* MAIN_H */

View File

@ -0,0 +1,40 @@
/*!
\file readme.txt
\brief description of CAU_TDESECB_mode example
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
This demo is based on the GD32W515P-EVAL-V1.0 board, it shows how to use the CAU
peripheral to encrypt and decrypt data using TDES algorithm.
For this example, DMA is used to transfer data from memory to the CAU processor
IN FIFO and also to transfer data from CAU processor OUT FIFO to memory.
The data to be encrypted is a 320 bit data, which corresponds to 5 TDES Blocks.
The all data can be displayed on a PC HyperTerminal using the USART.

View File

@ -0,0 +1,70 @@
/*!
\file gd32w51x_libopt.h
\brief library optional for gd32w51x
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#ifndef GD32W51X_LIBOPT_H
#define GD32W51X_LIBOPT_H
#include "gd32w51x_adc.h"
#include "gd32w51x_cau.h"
#include "gd32w51x_crc.h"
#include "gd32w51x_dbg.h"
#include "gd32w51x_dci.h"
#include "gd32w51x_dma.h"
#include "gd32w51x_efuse.h"
#include "gd32w51x_exti.h"
#include "gd32w51x_fmc.h"
#include "gd32w51x_fwdgt.h"
#include "gd32w51x_gpio.h"
#include "gd32w51x_hau.h"
#include "gd32w51x_hpdf.h"
#include "gd32w51x_i2c.h"
#include "gd32w51x_icache.h"
#include "gd32w51x_misc.h"
#include "gd32w51x_pkcau.h"
#include "gd32w51x_pmu.h"
#include "gd32w51x_qspi.h"
#include "gd32w51x_rcu.h"
#include "gd32w51x_rtc.h"
#include "gd32w51x_sdio.h"
#include "gd32w51x_spi.h"
#include "gd32w51x_sqpi.h"
#include "gd32w51x_syscfg.h"
#include "gd32w51x_timer.h"
#include "gd32w51x_trng.h"
#include "gd32w51x_tsi.h"
#include "gd32w51x_tzpcu.h"
#include "gd32w51x_usart.h"
#include "gd32w51x_wwdgt.h"
#endif /* GD32W51X_LIBOPT_H */

View File

@ -0,0 +1,69 @@
/*!
\file main.c
\brief CRC calculate demo
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "gd32w51x.h"
#include "gd32w515p_eval.h"
uint32_t val = 0, valcrc = 0;
/*!
\brief main function
\param[in] none
\param[out] none
\retval none
*/
int main(void)
{
val = (uint32_t)0xabcd1234;
/* initialize the LED1 and LED2, turn off them */
gd_eval_led_init(LED1);
gd_eval_led_init(LED2);
gd_eval_led_off(LED1);
gd_eval_led_off(LED2);
rcu_periph_clock_enable(RCU_CRC);
/* reset the CRC data register and calculate the CRC of the value */
crc_data_register_reset();
valcrc = crc_single_data_calculate(val);
if(0xf7018a40 == valcrc){
gd_eval_led_on(LED1);
gd_eval_led_on(LED2);
}
while(1){
}
}

View File

@ -0,0 +1,37 @@
/*!
\file readme.txt
\brief description of CRC example
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
This example is based on the GD32W515P-EVAL-V1.0 board, it shows how to use CRC to calculate
the CRC value. In this demo, 1 CRC value is calculated for a 32-bit data. If the result is
success, turn on the LED1 and LED2.

View File

@ -0,0 +1,140 @@
/*!
\file gd32w51x_it.c
\brief interrupt service routines
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "gd32w51x_it.h"
#include "main.h"
#include "systick.h"
/*!
\brief this function handles NMI exception
\param[in] none
\param[out] none
\retval none
*/
void NMI_Handler(void)
{
}
/*!
\brief this function handles HardFault exception
\param[in] none
\param[out] none
\retval none
*/
void HardFault_Handler(void)
{
/* if Hard Fault exception occurs, go to infinite loop */
while(1){
}
}
/*!
\brief this function handles MemManage exception
\param[in] none
\param[out] none
\retval none
*/
void MemManage_Handler(void)
{
/* if Memory Manage exception occurs, go to infinite loop */
while(1){
}
}
/*!
\brief this function handles BusFault exception
\param[in] none
\param[out] none
\retval none
*/
void BusFault_Handler(void)
{
/* if Bus Fault exception occurs, go to infinite loop */
while(1){
}
}
/*!
\brief this function handles UsageFault exception
\param[in] none
\param[out] none
\retval none
*/
void UsageFault_Handler(void)
{
/* if Usage Fault exception occurs, go to infinite loop */
while(1){
}
}
/*!
\brief this function handles SVC exception
\param[in] none
\param[out] none
\retval none
*/
void SVC_Handler(void)
{
}
/*!
\brief this function handles DebugMon exception
\param[in] none
\param[out] none
\retval none
*/
void DebugMon_Handler(void)
{
}
/*!
\brief this function handles PendSV exception
\param[in] none
\param[out] none
\retval none
*/
void PendSV_Handler(void)
{
}
/*!
\brief this function handles SysTick exception
\param[in] none
\param[out] none
\retval none
*/
void SysTick_Handler(void)
{
delay_decrement();
}

View File

@ -0,0 +1,60 @@
/*!
\file gd32w51x_it.h
\brief the header file of the ISR
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#ifndef GD32W51X_IT_H
#define GD32W51X_IT_H
#include "gd32w51x.h"
/* function declarations */
/* this function handles NMI exception */
void NMI_Handler(void);
/* this function handles HardFault exception */
void HardFault_Handler(void);
/* this function handles MemManage exception */
void MemManage_Handler(void);
/* this function handles BusFault exception */
void BusFault_Handler(void);
/* this function handles UsageFault exception */
void UsageFault_Handler(void);
/* this function handles SVC exception */
void SVC_Handler(void);
/* this function handles DebugMon exception */
void DebugMon_Handler(void);
/* this function handles PendSV exception */
void PendSV_Handler(void);
/* this function handles SysTick exception */
void SysTick_Handler(void);
#endif /* GD32W51X_IT_H */

View File

@ -0,0 +1,70 @@
/*!
\file gd32w51x_libopt.h
\brief library optional for gd32w51x
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#ifndef GD32W51X_LIBOPT_H
#define GD32W51X_LIBOPT_H
#include "gd32w51x_adc.h"
#include "gd32w51x_cau.h"
#include "gd32w51x_crc.h"
#include "gd32w51x_dbg.h"
#include "gd32w51x_dci.h"
#include "gd32w51x_dma.h"
#include "gd32w51x_efuse.h"
#include "gd32w51x_exti.h"
#include "gd32w51x_fmc.h"
#include "gd32w51x_fwdgt.h"
#include "gd32w51x_gpio.h"
#include "gd32w51x_hau.h"
#include "gd32w51x_hpdf.h"
#include "gd32w51x_i2c.h"
#include "gd32w51x_icache.h"
#include "gd32w51x_misc.h"
#include "gd32w51x_pkcau.h"
#include "gd32w51x_pmu.h"
#include "gd32w51x_qspi.h"
#include "gd32w51x_rcu.h"
#include "gd32w51x_rtc.h"
#include "gd32w51x_sdio.h"
#include "gd32w51x_spi.h"
#include "gd32w51x_sqpi.h"
#include "gd32w51x_syscfg.h"
#include "gd32w51x_timer.h"
#include "gd32w51x_trng.h"
#include "gd32w51x_tsi.h"
#include "gd32w51x_tzpcu.h"
#include "gd32w51x_usart.h"
#include "gd32w51x_wwdgt.h"
#endif /* GD32W51X_LIBOPT_H */

View File

@ -0,0 +1,160 @@
/*!
\file main.c
\brief debug TIMER0 when the MCU is in debug mode
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "gd32w51x.h"
#include "gd32w515p_eval.h"
#include "systick.h"
void gpio_configuration(void);
void timer_configuration(void);
/*!
\brief main function
\param[in] none
\param[out] none
\retval none
*/
int main(void)
{
/* systick configuration */
systick_config();
/* system clocks configuration */
rcu_periph_clock_enable(RCU_GPIOA);
/* gpio configuration */
gpio_configuration();
/* enable the led clock */
rcu_periph_clock_enable(RCU_GPIOA);
/* configure led GPIO port */
gpio_mode_set(GPIOA, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO_PIN_15);
gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_166MHZ, GPIO_PIN_15);
GPIO_BC(GPIOA) = GPIO_PIN_15;
timer_configuration();
/* keep timer0 counter when the MCU is in debug mode */
dbg_periph_enable(DBG_TIMER0_HOLD);
while(1)
{
/* toggle LED1 output status every second */
GPIO_TG(GPIOA) = GPIO_PIN_15;
/* you can set breakpoint here, then look over the register in timer0 */
delay_1ms(1000);
}
}
/*!
\brief configure the GPIO ports
\param[in] none
\param[out] none
\retval none
*/
void gpio_configuration(void)
{
/* Configure PA9 PA10 PA11(TIMER0 CH1 CH2 CH3) as alternate function */
gpio_mode_set(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_9);
gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_166MHZ, GPIO_PIN_9);
gpio_mode_set(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_10);
gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_166MHZ, GPIO_PIN_10);
gpio_mode_set(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_11);
gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_166MHZ, GPIO_PIN_11);
gpio_af_set(GPIOA, GPIO_AF_1, GPIO_PIN_9);
gpio_af_set(GPIOA, GPIO_AF_1, GPIO_PIN_10);
gpio_af_set(GPIOA, GPIO_AF_1, GPIO_PIN_11);
}
/*!
\brief configure the TIMER peripheral
\param[in] none
\param[out] none
\retval none
*/
void timer_configuration(void)
{
/* TIMER0 configuration: generate 3 PWM signals with 3 different duty cycles:
TIMER0CLK = SystemCoreClock / 90 = 2MHz
TIMER0 Channel1 duty cycle = 4000/ 16000 = 25%
TIMER0 Channel2 duty cycle = 8000/ 16000 = 50%
TIMER0 Channel3 duty cycle = 12000/ 16000 = 75% */
timer_parameter_struct timer_initpara;
timer_oc_parameter_struct timer_ocintpara;
rcu_periph_clock_enable(RCU_TIMER0);
/* TIMER0 configuration */
timer_deinit(TIMER0);
/* TIMER0 configuration */
timer_initpara.prescaler = 89;
timer_initpara.alignedmode = TIMER_COUNTER_EDGE;
timer_initpara.counterdirection = TIMER_COUNTER_UP;
timer_initpara.period = 15999;
timer_initpara.clockdivision = TIMER_CKDIV_DIV1;
timer_initpara.repetitioncounter = 0;
timer_init(TIMER0,&timer_initpara);
/* CH1,CH2 and CH3 configuration in PWM mode */
timer_ocintpara.ocpolarity = TIMER_OC_POLARITY_HIGH;
timer_ocintpara.outputstate = TIMER_CCX_ENABLE;
timer_channel_output_config(TIMER0, TIMER_CH_1, &timer_ocintpara);
timer_channel_output_config(TIMER0, TIMER_CH_2, &timer_ocintpara);
timer_channel_output_config(TIMER0, TIMER_CH_3, &timer_ocintpara);
timer_channel_output_pulse_value_config(TIMER0, TIMER_CH_1, 3999);
timer_channel_output_mode_config(TIMER0, TIMER_CH_1, TIMER_OC_MODE_PWM1);
timer_channel_output_shadow_config(TIMER0, TIMER_CH_1, TIMER_OC_SHADOW_DISABLE);
timer_channel_output_pulse_value_config(TIMER0, TIMER_CH_2, 7999);
timer_channel_output_mode_config(TIMER0, TIMER_CH_2, TIMER_OC_MODE_PWM1);
timer_channel_output_shadow_config(TIMER0, TIMER_CH_2, TIMER_OC_SHADOW_DISABLE);
timer_channel_output_pulse_value_config(TIMER0, TIMER_CH_3, 11999);
timer_channel_output_mode_config(TIMER0, TIMER_CH_3, TIMER_OC_MODE_PWM1);
timer_channel_output_shadow_config(TIMER0, TIMER_CH_3, TIMER_OC_SHADOW_DISABLE);
/* TIMER0 primary output function enable */
timer_primary_output_config(TIMER0, ENABLE);
/* auto-reload preload enable */
timer_auto_reload_shadow_enable(TIMER0);
timer_enable(TIMER0);
}

View File

@ -0,0 +1,38 @@
/*!
\file main.h
\brief the header file of main
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#ifndef MAIN_H
#define MAIN_H
#endif /* MAIN_H */

View File

@ -0,0 +1,54 @@
/*!
\file readme.txt
\brief description of the DBG demo
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
This demo is based on the GD32W515P-EVAL-V1.0 board, it shows that, when the
DBG_CTL0_TM1_HOLD bit in DBG control register(DBG_CTL0) is set and the core halted,
the TIMER0 counter stop counting and the PWM outputs of all channels are stopped as
well.It's benefit for debugging.
The TIMER0 counter clock used is 2MHz.
The Three Duty cycles are computed as the following description:
The channel 1 duty cycle is set to 25%
The channel 2 duty cycle is set to 50%
The channel 3 duty cycle is set to 75%
Connect the TIMER0 pins to an oscilloscope and monitor the different waveforms:
- TIMER0_CH1 pin (PA9)
- TIMER0_CH2 pin (PA10)
- TIMER0_CH3 pin (PA11)
For Keil,in debug mode,when the core is stopped,update the register window for TIMER0,
you will see that the count value will not change. And at the same time,the PWM outputs of
all the channels of TIMER0 will be stopped.

View File

@ -0,0 +1,82 @@
/*!
\file systick.c
\brief the systick configuration file
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "gd32w51x.h"
#include "systick.h"
volatile static uint32_t delay;
/*!
\brief configure systick
\param[in] none
\param[out] none
\retval none
*/
void systick_config(void)
{
/* setup systick timer for 1000Hz interrupts */
if(SysTick_Config(SystemCoreClock / 1000U)){
/* capture error */
while(1){
}
}
/* configure the systick handler priority */
NVIC_SetPriority(SysTick_IRQn, 0x00U);
}
/*!
\brief delay a time in milliseconds
\param[in] count: count in milliseconds
\param[out] none
\retval none
*/
void delay_1ms(uint32_t count)
{
delay = count;
while(0U != delay){
}
}
/*!
\brief delay decrement
\param[in] none
\param[out] none
\retval none
*/
void delay_decrement(void)
{
if(0U != delay){
delay--;
}
}

View File

@ -0,0 +1,47 @@
/*!
\file systick.h
\brief the header file of systick
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#ifndef SYSTICK_H
#define SYSTICK_H
#include <stdint.h>
/* configure systick */
void systick_config(void);
/* delay a time in milliseconds */
void delay_1ms(uint32_t count);
/* delay decrement */
void delay_decrement(void);
#endif /* SYSTICK_H */

View File

@ -0,0 +1,220 @@
/*!
\file dci_ov2640.c
\brief DCI config file
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "dci_ov2640.h"
#include "dci_ov2640_init_table.h"
#include "gd32w51x.h"
#include "systick.h"
extern uint8_t capture_image[320*240*2];
/*!
\brief configure the DCI to interface with the camera module
\param[in] none
\param[out] none
\retval none
*/
void dci_config(void)
{
dci_parameter_struct dci_struct;
dma_multi_data_parameter_struct dma_multi_struct;
rcu_periph_clock_enable(RCU_GPIOA);
rcu_periph_clock_enable(RCU_GPIOB);
rcu_periph_clock_enable(RCU_GPIOC);
rcu_periph_clock_enable(RCU_DCI);
/* DCI GPIO AF configuration */
gpio_af_set(GPIOA, GPIO_AF_13, GPIO_PIN_6);
gpio_af_set(GPIOB, GPIO_AF_13, GPIO_PIN_7);
gpio_af_set(GPIOA, GPIO_AF_13, GPIO_PIN_4);
gpio_af_set(GPIOB, GPIO_AF_13, GPIO_PIN_11);
gpio_af_set(GPIOC, GPIO_AF_13, GPIO_PIN_7);
gpio_af_set(GPIOB, GPIO_AF_13, GPIO_PIN_2);
gpio_af_set(GPIOA, GPIO_AF_13, GPIO_PIN_12);
gpio_af_set(GPIOB, GPIO_AF_13, GPIO_PIN_0);
gpio_af_set(GPIOB, GPIO_AF_13, GPIO_PIN_6);
gpio_af_set(GPIOB, GPIO_AF_13, GPIO_PIN_8);
gpio_af_set(GPIOB, GPIO_AF_13, GPIO_PIN_9);
/* configure DCI_PIXCLK(PA6), DCI_VSYNC(PB7), DCI_HSYNC(PA4), DCI_D0(PB11), DCI_D1(PC7)
DCI_D2(PB2), DCI_D3(PA12), DCI_D4(PB0), DCI_D5(PB6), DCI_D6(PB8), DCI_D7(PB9) */
gpio_mode_set(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_4 | GPIO_PIN_6 | GPIO_PIN_12);
gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, GPIO_PIN_4 | GPIO_PIN_6 | GPIO_PIN_12);
gpio_mode_set(GPIOB, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_0 | GPIO_PIN_2 | GPIO_PIN_6 | GPIO_PIN_7 |
GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_11);
gpio_output_options_set(GPIOB, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, GPIO_PIN_0 | GPIO_PIN_2 | GPIO_PIN_6 | GPIO_PIN_7 |
GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_11);
gpio_mode_set(GPIOC, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_7);
gpio_output_options_set(GPIOC, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, GPIO_PIN_7);
/* DCI configuration */
dci_struct.capture_mode = DCI_CAPTURE_MODE_CONTINUOUS;
dci_struct.clock_polarity = DCI_CK_POLARITY_RISING;
dci_struct.hsync_polarity = DCI_HSYNC_POLARITY_LOW;
dci_struct.vsync_polarity = DCI_VSYNC_POLARITY_LOW;
dci_struct.frame_rate = DCI_FRAME_RATE_ALL;
dci_struct.interface_format = DCI_INTERFACE_FORMAT_8BITS;
dci_init(&dci_struct);
/* DCI DMA configuration */
rcu_periph_clock_enable(RCU_DMA1);
dma_deinit(DMA1, DMA_CH7);
dma_multi_struct.periph_addr = (uint32_t)DCI_DATA_ADDRESS;
dma_multi_struct.memory0_addr = (uint32_t)(SRAM_Address);
dma_multi_struct.direction = DMA_PERIPH_TO_MEMORY;
dma_multi_struct.number = 38400;
dma_multi_struct.periph_inc = DMA_PERIPH_INCREASE_DISABLE;
dma_multi_struct.memory_inc = DMA_MEMORY_INCREASE_ENABLE;
dma_multi_struct.periph_width = DMA_PERIPH_WIDTH_32BIT;
dma_multi_struct.memory_width = DMA_MEMORY_WIDTH_32BIT;
dma_multi_struct.circular_mode = DMA_CIRCULAR_MODE_ENABLE;
dma_multi_struct.priority = DMA_PRIORITY_HIGH;
dma_multi_struct.critical_value = DMA_FIFO_4_WORD;
dma_multi_struct.memory_burst_width = DMA_MEMORY_BURST_SINGLE;
dma_multi_struct.periph_burst_width = DMA_PERIPH_BURST_SINGLE;
dma_multi_data_mode_init(DMA1,DMA_CH7, &dma_multi_struct);
dma_channel_subperipheral_select(DMA1, DMA_CH7, DMA_SUBPERI1);
}
/*!
\brief DCI camera outsize set
\param[in] width: outsize width
\param[in] height: outsize height
\param[out] none
\retval 0x00 or 0xFF
*/
uint8_t ov2640_outsize_set(uint16_t width,uint16_t height)
{
uint16_t outh;
uint16_t outw;
uint8_t temp;
if(width%4)return 0xFF;
if(height%4)return 0xFF;
outw=width/4;
outh=height/4;
dci_byte_write(0xFF,0x00);
dci_byte_write(0xE0,0x04);
dci_byte_write(0x5A,outw&0xFF);
dci_byte_write(0x5B,outh&0xFF);
temp=(outw>>8)&0x03;
temp|=(outh>>6)&0x04;
dci_byte_write(0x5C,temp);
dci_byte_write(0xE0,0x00);
return 0;
}
/*!
\brief DCI camera initialization
\param[in] none
\param[out] none
\retval 0x00 or 0xFF
*/
uint8_t dci_ov2640_init(void)
{
uint8_t i;
sccb_config();
dci_config();
ckout0_init();
delay_1ms(10);
/* OV2640 reset */
if(dci_byte_write(0xFF, 0x01)!=0)
return 0xFF;
if(dci_byte_write(0x12, 0x80)!=0)
return 0xFF;
delay_1ms(10);
for(i=0;i<sizeof(ov2640_svga_init_reg_tbl)/2;i++){
if(0 != dci_byte_write(ov2640_svga_init_reg_tbl[i][0],ov2640_svga_init_reg_tbl[i][1])){
return 0xFF;
}
}
delay_1ms(100);
for(i=0;i<(sizeof(ov2640_rgb565_reg_tbl)/2);i++){
if(0 != dci_byte_write(ov2640_rgb565_reg_tbl[i][0],ov2640_rgb565_reg_tbl[i][1])){
return 0xFF;
}
}
delay_1ms(100);
ov2640_outsize_set(320,240);
return 0;
}
/*!
\brief ckout0 initialization
\param[in] none
\param[out] none
\retval none
*/
void ckout0_init(void)
{
rcu_periph_clock_enable(RCU_GPIOA);
gpio_af_set(GPIOA, GPIO_AF_CKOUT, GPIO_PIN_8);
gpio_mode_set(GPIOA, GPIO_MODE_AF, GPIO_PUPD_PULLUP, GPIO_PIN_8);
gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_166MHZ, GPIO_PIN_8);
rcu_ckout0_config(RCU_CKOUT0SRC_IRC16M, RCU_CKOUT0_DIV1);
}
/*!
\brief read the ov2640 manufacturer identifier
\param[in] ov2640id: pointer to the ov2640 manufacturer struct
\param[out] none
\retval 0x00 or 0xFF
*/
uint8_t dci_ov2640_id_read(ov2640_id_struct* ov2640id)
{
uint8_t temp;
dci_byte_write(0xFF, 0x01);
if(dci_byte_read(OV2640_MIDH,&temp)!=0){
return 0xFF;
}
ov2640id->manufacturer_id1 = temp;
if(dci_byte_read(OV2640_MIDL,&temp)!=0){
return 0xFF;
}
ov2640id->manufacturer_id2 = temp;
if(dci_byte_read(OV2640_VER,&temp)!=0){
return 0xFF;
}
ov2640id->version = temp;
if(dci_byte_read(OV2640_PID,&temp)!=0){
return 0xFF;
}
ov2640id->pid = temp;
return 0x00;
}

View File

@ -0,0 +1,65 @@
/*!
\file dci_ov2640.h
\brief definitions for ov2640
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#ifndef DCI_OV2640_H
#define DCI_OV2640_H
#include "sccb.h"
#define SRAM_Address 0x20010000 /* 320*240*2 */
#define DCI_DATA_ADDRESS ((uint32_t)&DCI_DATA) /* 0x4C050028U */
#define DCI_TIMEOUT 20000
#define GPIO_AF_CKOUT GPIO_AF_0
typedef struct
{
uint8_t manufacturer_id1;
uint8_t manufacturer_id2;
uint8_t version;
uint8_t pid;
}ov2640_id_struct;
/* ov2640 registers definition */
#define OV2640_PID 0x0A
#define OV2640_VER 0x0B
#define OV2640_MIDH 0x1C
#define OV2640_MIDL 0x1D
/* function declarations */
void dci_config(void);
void ckout0_init(void);
uint8_t dci_ov2640_init(void);
uint8_t dci_ov2640_id_read(ov2640_id_struct* ov2640id);
uint8_t ov2640_outsize_set(uint16_t width,uint16_t height);
#endif /* DCI_OV2640_H */

View File

@ -0,0 +1,238 @@
/*!
\file dci_ov2640_init_table.h
\brief definitions for ov2640 initialization
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#ifndef DCI_OV2640_INIT_TABLE_H
#define DCI_OV2640_INIT_TABLE_H
const char ov2640_svga_init_reg_tbl[][2]=
{
0xff, 0x00,
0x2c, 0xff,
0x2e, 0xdf,
0xff, 0x01,
0x3c, 0x32,
0x11, 0x01, /* 0x11, 0x00, */
0x09, 0x02,
0x04, 0xD8,
0x13, 0xe5,
0x14, 0x48,
0x2c, 0x0c,
0x33, 0x78,
0x3a, 0x33,
0x3b, 0xfB,
0x3e, 0x00,
0x43, 0x11,
0x16, 0x10,
0x39, 0x92,
0x35, 0xda,
0x22, 0x1a,
0x37, 0xc3,
0x23, 0x00,
0x34, 0xc0,
0x36, 0x1a,
0x06, 0x88,
0x07, 0xc0,
0x0d, 0x87,
0x0e, 0x41,
0x4c, 0x00,
0x48, 0x00,
0x5B, 0x00,
0x42, 0x03,
0x4a, 0x81,
0x21, 0x99,
0x24, 0x40,
0x25, 0x38,
0x26, 0x82,
0x5c, 0x00,
0x63, 0x00,
0x46, 0x22,
0x0c, 0x3c,
0x61, 0x70,
0x62, 0x80,
0x7c, 0x05,
0x20, 0x80,
0x28, 0x30,
0x6c, 0x00,
0x6d, 0x80,
0x6e, 0x00,
0x70, 0x02,
0x71, 0x94,
0x73, 0xc1,
0x3d, 0x34,
0x5a, 0x57,
0x12, 0x40, /* SVGA 800*600 */
0x17, 0x11,
0x18, 0x43,
0x19, 0x00,
0x1a, 0x4b,
0x32, 0x09,
0x37, 0xc0,
0x4f, 0xca,
0x50, 0xa8,
0x5a, 0x23,
0x6d, 0x00,
0x3d, 0x38,
0xff, 0x00,
0xe5, 0x7f,
0xf9, 0xc0,
0x41, 0x24,
0xe0, 0x14,
0x76, 0xff,
0x33, 0xa0,
0x42, 0x20,
0x43, 0x18,
0x4c, 0x00,
0x87, 0xd5,
0x88, 0x3f,
0xd7, 0x03,
0xd9, 0x10,
0xd3, 0x82,
0xc8, 0x08,
0xc9, 0x80,
0x7c, 0x00,
0x7d, 0x00,
0x7c, 0x03,
0x7d, 0x48,
0x7d, 0x48,
0x7c, 0x08,
0x7d, 0x20,
0x7d, 0x10,
0x7d, 0x0e,
0x90, 0x00,
0x91, 0x0e,
0x91, 0x1a,
0x91, 0x31,
0x91, 0x5a,
0x91, 0x69,
0x91, 0x75,
0x91, 0x7e,
0x91, 0x88,
0x91, 0x8f,
0x91, 0x96,
0x91, 0xa3,
0x91, 0xaf,
0x91, 0xc4,
0x91, 0xd7,
0x91, 0xe8,
0x91, 0x20,
0x92, 0x00,
0x93, 0x06,
0x93, 0xe3,
0x93, 0x05,
0x93, 0x05,
0x93, 0x00,
0x93, 0x04,
0x93, 0x00,
0x93, 0x00,
0x93, 0x00,
0x93, 0x00,
0x93, 0x00,
0x93, 0x00,
0x93, 0x00,
0x96, 0x00,
0x97, 0x08,
0x97, 0x19,
0x97, 0x02,
0x97, 0x0c,
0x97, 0x24,
0x97, 0x30,
0x97, 0x28,
0x97, 0x26,
0x97, 0x02,
0x97, 0x98,
0x97, 0x80,
0x97, 0x00,
0x97, 0x00,
0xc3, 0xed,
0xa4, 0x00,
0xa8, 0x00,
0xc5, 0x11,
0xc6, 0x51,
0xbf, 0x80,
0xc7, 0x10,
0xb6, 0x66,
0xb8, 0xA5,
0xb7, 0x64,
0xb9, 0x7C,
0xb3, 0xaf,
0xb4, 0x97,
0xb5, 0xFF,
0xb0, 0xC5,
0xb1, 0x94,
0xb2, 0x0f,
0xc4, 0x5c,
0xc0, 0x64,
0xc1, 0x4B,
0x8c, 0x00,
0x86, 0x3D,
0x50, 0x00,
0x51, 0xC8,
0x52, 0x96,
0x53, 0x00,
0x54, 0x00,
0x55, 0x00,
0x5a, 0xC8,
0x5b, 0x96,
0x5c, 0x00,
0xd3, 0x02,
0xc3, 0xed,
0x7f, 0x00,
0xda, 0x09,
0xe5, 0x1f,
0xe1, 0x67,
0xe0, 0x00,
0xdd, 0x7f,
0x05, 0x00,
};
const char ov2640_rgb565_reg_tbl[][2]=
{
0xFF, 0x00,
0xDA, 0x09,
0xD7, 0x03,
0xDF, 0x02,
0x33, 0xa0,
0x3C, 0x00,
0xe1, 0x67,
0xff, 0x01,
0xe0, 0x00,
0xe1, 0x00,
0xe5, 0x00,
0xd7, 0x00,
0xda, 0x00,
0xe0, 0x00,
};
#endif /* DCI_OV2640_INIT_TABLE_H */

View File

@ -0,0 +1,139 @@
/*!
\file gd32w51x_it.c
\brief interrupt service routines
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "gd32w51x_it.h"
#include "systick.h"
/*!
\brief this function handles NMI exception
\param[in] none
\param[out] none
\retval none
*/
void NMI_Handler(void)
{
}
/*!
\brief this function handles HardFault exception
\param[in] none
\param[out] none
\retval none
*/
void HardFault_Handler(void)
{
/* if Hard Fault exception occurs, go to infinite loop */
while (1){
}
}
/*!
\brief this function handles MemManage exception
\param[in] none
\param[out] none
\retval none
*/
void MemManage_Handler(void)
{
/* if Memory Manage exception occurs, go to infinite loop */
while (1){
}
}
/*!
\brief this function handles BusFault exception
\param[in] none
\param[out] none
\retval none
*/
void BusFault_Handler(void)
{
/* if Bus Fault exception occurs, go to infinite loop */
while (1){
}
}
/*!
\brief this function handles UsageFault exception
\param[in] none
\param[out] none
\retval none
*/
void UsageFault_Handler(void)
{
/* if Usage Fault exception occurs, go to infinite loop */
while (1){
}
}
/*!
\brief this function handles SVC exception
\param[in] none
\param[out] none
\retval none
*/
void SVC_Handler(void)
{
}
/*!
\brief this function handles DebugMon exception
\param[in] none
\param[out] none
\retval none
*/
void DebugMon_Handler(void)
{
}
/*!
\brief this function handles PendSV exception
\param[in] none
\param[out] none
\retval none
*/
void PendSV_Handler(void)
{
}
/*!
\brief this function handles SysTick exception
\param[in] none
\param[out] none
\retval none
*/
void SysTick_Handler(void)
{
delay_decrement();
}

View File

@ -0,0 +1,60 @@
/*!
\file gd32w51x_it.h
\brief the header file of the ISR
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#ifndef GD32W51X_IT_H
#define GD32W51X_IT_H
#include "gd32w51x.h"
/* function declarations */
/* this function handles NMI exception */
void NMI_Handler(void);
/* this function handles HardFault exception */
void HardFault_Handler(void);
/* this function handles MemManage exception */
void MemManage_Handler(void);
/* this function handles BusFault exception */
void BusFault_Handler(void);
/* this function handles UsageFault exception */
void UsageFault_Handler(void);
/* this function handles SVC exception */
void SVC_Handler(void);
/* this function handles DebugMon exception */
void DebugMon_Handler(void);
/* this function handles PendSV exception */
void PendSV_Handler(void);
/* this function handles SysTick exception */
void SysTick_Handler(void);
#endif /* GD32W51X_IT_H */

View File

@ -0,0 +1,70 @@
/*!
\file gd32w51x_libopt.h
\brief library optional for gd32w51x
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#ifndef GD32W51x_LIBOPT_H
#define GD32W51x_LIBOPT_H
#include "gd32w51x_adc.h"
#include "gd32w51x_cau.h"
#include "gd32w51x_crc.h"
#include "gd32w51x_dbg.h"
#include "gd32w51x_dci.h"
#include "gd32w51x_dma.h"
#include "gd32w51x_efuse.h"
#include "gd32w51x_exti.h"
#include "gd32w51x_fmc.h"
#include "gd32w51x_fwdgt.h"
#include "gd32w51x_gpio.h"
#include "gd32w51x_hau.h"
#include "gd32w51x_hpdf.h"
#include "gd32w51x_i2c.h"
#include "gd32w51x_icache.h"
#include "gd32w51x_misc.h"
#include "gd32w51x_pkcau.h"
#include "gd32w51x_pmu.h"
#include "gd32w51x_qspi.h"
#include "gd32w51x_rcu.h"
#include "gd32w51x_rtc.h"
#include "gd32w51x_sdio.h"
#include "gd32w51x_spi.h"
#include "gd32w51x_sqpi.h"
#include "gd32w51x_syscfg.h"
#include "gd32w51x_timer.h"
#include "gd32w51x_trng.h"
#include "gd32w51x_tsi.h"
#include "gd32w51x_tzpcu.h"
#include "gd32w51x_usart.h"
#include "gd32w51x_wwdgt.h"
#endif /* GD32W51x_LIBOPT_H */

View File

@ -0,0 +1,64 @@
/*!
\file main.c
\brief DCI display demo
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#include "gd32w51x.h"
#include "systick.h"
#include <stdio.h>
#include "dci_ov2640.h"
uint8_t capture_image[320*240*2];
/*!
\brief main function
\param[in] none
\param[out] none
\retval none
*/
int main(void)
{
ov2640_id_struct ov2640id;
/* configure Systick */
systick_config();
dci_ov2640_init();
dci_ov2640_id_read(&ov2640id);
delay_1ms(100);
dma_channel_enable(DMA1, DMA_CH7);
dci_enable();
dci_capture_enable();
delay_1ms(100);
while(1){
}
}

View File

@ -0,0 +1,37 @@
/*!
\file readme.txt
\brief description of the DCI_OV2640 example
\version 2021-10-30, V1.0.0, firmware for GD32W51x
*/
/*
Copyright (c) 2021, GigaDevice Semiconductor Inc.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
This demo is based on the GD32W515 board, it shows how to use OV2640 camera to capture
images.
Firstly, download program to the board. Then correctly install the OV2640 camera
to the development board.

Some files were not shown because too many files have changed in this diff Show More