Initial commit

This commit is contained in:
EmanuelFeru
2020-02-07 14:57:44 +01:00
commit 836e321549
551 changed files with 113644 additions and 0 deletions

View File

@@ -0,0 +1,140 @@
/*!
\file gd32f1x0_it.c
\brief interrupt service routines
*/
/*
Copyright (C) 2017 GigaDevice
2014-12-26, V1.0.0, platform GD32F1x0(x=3,5)
2016-01-15, V2.0.0, platform GD32F1x0(x=3,5,7,9)
2016-04-30, V3.0.0, firmware update for GD32F1x0(x=3,5,7,9)
2017-06-19, V3.1.0, firmware update for GD32F1x0(x=3,5,7,9)
*/
#include "gd32f1x0_it.h"
#include "gd32f1x0_eval.h"
__IO uint8_t counter0 = 0x00;
__IO uint8_t counter1 = 0;
extern void LED_Spark(void);
/*!
\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)
{
if (counter1 == 20){
LED_Spark();
/* Reset Counter */
counter1 = 0;
}else{
/* increment Counter */
counter1++;
}
}
/*!
\brief this function handles USART wakeup from deepsleep interrupt request
\param[in] none
\param[out] none
\retval none
*/
void USART0_IRQHandler(void)
{
if (SET == usart_interrupt_flag_get(EVAL_COM1, USART_INT_FLAG_WU)){
usart_flag_clear(EVAL_COM1, USART_FLAG_WU);
counter0 = 0x01;
}
}

View File

@@ -0,0 +1,42 @@
/*!
\file gd32f1x0_it.h
\brief the header file of the ISR
*/
/*
Copyright (C) 2017 GigaDevice
2014-12-26, V1.0.0, platform GD32F1x0(x=3,5)
2016-01-15, V2.0.0, platform GD32F1x0(x=3,5,7,9)
2016-04-30, V3.0.0, firmware update for GD32F1x0(x=3,5,7,9)
2017-06-19, V3.1.0, firmware update for GD32F1x0(x=3,5,7,9)
*/
#ifndef GD32F1X0_IT_H
#define GD32F1X0_IT_H
#include "gd32f1x0.h"
/* function declarations */
/* NMI handle function */
void NMI_Handler(void);
/* HardFault handle function */
void HardFault_Handler(void);
/* MemManage handle function */
void MemManage_Handler(void);
/* BusFault handle function */
void BusFault_Handler(void);
/* UsageFault handle function */
void UsageFault_Handler(void);
/* SVC handle function */
void SVC_Handler(void);
/* DebugMon handle function */
void DebugMon_Handler(void);
/* PendSV handle function */
void PendSV_Handler(void);
/* SysTick handle function */
void SysTick_Handler(void);
/* USART0 handle function */
void USART0_IRQHandler(void);
#endif /* GD32F1X0_IT_H */

View File

@@ -0,0 +1,47 @@
/*!
\file gd32f1x0_libopt.h
\brief library optional for gd32f1x0
*/
/*
Copyright (C) 2017 GigaDevice
2014-12-26, V1.0.0, platform GD32F1x0(x=3,5)
2016-01-15, V2.0.0, platform GD32F1x0(x=3,5,7,9)
2016-04-30, V3.0.0, firmware update for GD32F1x0(x=3,5,7,9)
2017-06-19, V3.1.0, firmware update for GD32F1x0(x=3,5,7,9)
*/
#ifndef GD32F1X0_LIBOPT_H
#define GD32F1X0_LIBOPT_H
#include "gd32f1x0_adc.h"
#include "gd32f1x0_cec.h"
#include "gd32f1x0_crc.h"
#include "gd32f1x0_cmp.h"
#include "gd32f1x0_dac.h"
#include "gd32f1x0_dbg.h"
#include "gd32f1x0_dma.h"
#include "gd32f1x0_exti.h"
#include "gd32f1x0_fmc.h"
#include "gd32f1x0_gpio.h"
#include "gd32f1x0_syscfg.h"
#include "gd32f1x0_i2c.h"
#include "gd32f1x0_fwdgt.h"
#include "gd32f1x0_pmu.h"
#include "gd32f1x0_rcu.h"
#include "gd32f1x0_rtc.h"
#include "gd32f1x0_spi.h"
#include "gd32f1x0_timer.h"
#include "gd32f1x0_usart.h"
#include "gd32f1x0_wwdgt.h"
#include "gd32f1x0_misc.h"
#include "gd32f1x0_tsi.h"
#ifdef GD32F170_190
#include "gd32f1x0_slcd.h"
#include "gd32f1x0_opa.h"
#include "gd32f1x0_ivref.h"
#include "gd32f1x0_can.h"
#endif /* GD32F170_190 */
#endif /* GD32F1X0_LIBOPT_H */

View File

@@ -0,0 +1,160 @@
/*!
\file main.c
\brief Deepsleep wakeup
*/
/*
Copyright (C) 2017 GigaDevice
2014-12-26, V1.0.0, platform GD32F1x0(x=3,5)
2016-01-15, V2.0.0, platform GD32F1x0(x=3,5,7,9)
2016-04-30, V3.0.0, firmware update for GD32F1x0(x=3,5,7,9)
2017-06-19, V3.1.0, firmware update for GD32F1x0(x=3,5,7,9)
*/
#include "gd32f1x0.h"
#include "gd32f1x0_it.h"
#include "gd32f1x0_eval.h"
extern __IO uint8_t counter0;
static void system_clock_reconfig(void);
void delay_s(uint32_t nTime);
/*!
\brief main function
\param[in] none
\param[out] none
\retval none
*/
int main(void)
{
SysTick_Config((SystemCoreClock / 1000));
gd_eval_led_init(LED2);
/* USART configuration the CK_IRC8M as USART clock */
rcu_usart_clock_config(RCU_USART0SRC_IRC8M);
gd_eval_com_init(EVAL_COM1);
nvic_irq_enable(USART0_IRQn, 0, 0);
delay_s(20);
{
/* use start bit wakeup mcu */
usart_wakeup_mode_config(EVAL_COM1, USART_WUM_STARTB);
/* enable USART */
usart_enable(EVAL_COM1);
while(RESET == usart_flag_get(EVAL_COM1, USART_FLAG_REA));
usart_wakeup_enable(EVAL_COM1);
/* enable the WUIE interrupt */
usart_interrupt_enable(EVAL_COM1, USART_INT_WU);
/* enable PWU APB clock */
rcu_periph_clock_enable(RCU_PMU);
/* enter deep-sleep mode */
pmu_to_deepsleepmode(PMU_LDO_LOWPOWER, WFI_CMD);
/* wait a WUIE interrup event */
while(0x00 == counter0);
/* disable USART peripheral in deepsleep mode */
usart_wakeup_disable(EVAL_COM1);
while(RESET == usart_flag_get(EVAL_COM1, USART_FLAG_RBNE));
usart_data_receive(EVAL_COM1);
usart_receive_config(EVAL_COM1, USART_RECEIVE_ENABLE);
while (RESET == usart_flag_get(EVAL_COM1, USART_FLAG_TC));
/* disable the USART */
usart_disable(EVAL_COM1);
}
/* reconfigure systemclock */
system_clock_reconfig();
/* configure and enable the systick timer to generate an interrupt each 1 ms */
SysTick_Config((SystemCoreClock / 1000));
while (1);
}
/*!
\brief delay function
\param[in] nTime
\param[out] none
\retval none
*/
void delay_s(uint32_t nTime)
{
uint32_t TimingDelay = 7200000*nTime;
while(TimingDelay != 0)
TimingDelay--;
}
/*!
\brief restore peripheral config before entering deepsleep mode
\param[in] none
\param[out] none
\retval none
*/
static void system_clock_reconfig(void)
{
__IO uint32_t StartUpCounter = 0, HXTALStatus = 0;
/* enable HXTAL */
RCU_CTL0 |= RCU_CTL0_HXTALEN;
HXTALStatus = rcu_osci_stab_wait(RCU_HXTAL);
if (SUCCESS == HXTALStatus){
/* configure AHB */
rcu_ahb_clock_config(RCU_AHB_CKSYS_DIV1);
/* configure APB1, APB2 */
rcu_apb1_clock_config(RCU_APB1_CKAHB_DIV1);
rcu_apb2_clock_config(RCU_APB2_CKAHB_DIV1);
/* PLL configuration: = HXTAL * 9 = 72 MHz */
rcu_hxtal_prediv_config(RCU_PLL_HXTAL_DIV1);
rcu_pll_config(RCU_PLLSRC_HXTAL, RCU_PLL_MUL9);
/* enable PLL */
RCU_CTL0 |= RCU_CTL0_PLLEN;
/* select PLL as system clock */
RCU_CFG0 &= ~RCU_CFG0_SCS;
RCU_CFG0 |= RCU_CKSYSSRC_PLL;
}
}
/*!
\brief LED spark
\param[in] none
\param[out] none
\retval none
*/
void LED_Spark(void)
{
static __IO uint32_t TimingDelayLocal = 0;
if (0x00 != TimingDelayLocal){
if(TimingDelayLocal < 50){
/* light on */
gd_eval_led_on(LED2);
}else{
/* light off */
gd_eval_led_off(LED2);
}
TimingDelayLocal--;
}else{
TimingDelayLocal = 100;
}
}

View File

@@ -0,0 +1,21 @@
/*!
\file readme.txt
\brief description of the USART wakeup from deepsleep
*/
/*
Copyright (C) 2017 GigaDevice
2014-12-26, V1.0.0, platform GD32F1x0(x=3,5)
2016-01-15, V2.0.0, platform GD32F1x0(x=3,5,7,9)
2016-04-30, V3.0.0, firmware update for GD32F1x0(x=3,5,7,9)
2017-06-19, V3.1.0, firmware update for GD32F1x0(x=3,5,7,9)
*/
This demo is based on the GD32150R-EVAL/GD32190R-EVAL board, it shows how to use
USART to wake up the MCU from deepsleep mode.
In this demo, the wake up method is configured as start bit detection. When the MCU
enters into deepsleep mode, LED2 stops in a certain status(on or off). In this
case, you can send some characters to wake up USART and LED2 goes on blink.