mirror of
https://github.com/WeActStudio/WeActStudio.EpaperModule.git
synced 2026-08-16 13:13:45 +02:00
first commit
This commit is contained in:
@@ -0,0 +1,143 @@
|
||||
/*!
|
||||
\file gd32f30x_it.c
|
||||
\brief interrupt service routines
|
||||
|
||||
\version 2017-02-10, V1.0.0, firmware for GD32F30x
|
||||
\version 2018-10-10, V1.1.0, firmware for GD32F30x
|
||||
\version 2018-12-25, V2.0.0, firmware for GD32F30x
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright (c) 2018, GigaDevice Semiconductor Inc.
|
||||
|
||||
All rights reserved.
|
||||
|
||||
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 "gd32f30x_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();
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#include "gpio.h"
|
||||
|
||||
void gpio_config(void)
|
||||
{
|
||||
/* enable clock */
|
||||
rcu_periph_clock_enable(RCU_AF);
|
||||
|
||||
rcu_periph_clock_enable(KEY_RCU);
|
||||
rcu_periph_clock_enable(LED_PB2_RCU);
|
||||
|
||||
/* JTAG-DP disabled and SW-DP enabled */
|
||||
gpio_pin_remap_config(GPIO_SWJ_SWDPENABLE_REMAP,ENABLE);
|
||||
|
||||
/* configure button pin as input */
|
||||
gpio_init(KEY_PORT, GPIO_MODE_IPD, GPIO_OSPEED_50MHZ, KEY_PIN);
|
||||
/* configure led pin as output */
|
||||
gpio_init(LED_PB2_PORT, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, LED_PB2_PIN);
|
||||
gpio_bit_reset(LED_PB2_PORT,LED_PB2_PIN);
|
||||
}
|
||||
@@ -0,0 +1,301 @@
|
||||
/*---------------------------------------
|
||||
- WeAct Studio Official Link
|
||||
- taobao: weactstudio.taobao.com
|
||||
- aliexpress: weactstudio.aliexpress.com
|
||||
- github: github.com/WeActTC
|
||||
- gitee: gitee.com/WeAct-TC
|
||||
- blog: www.weact-tc.cn
|
||||
---------------------------------------*/
|
||||
|
||||
#include "gd32f30x.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#include "systick.h"
|
||||
#include "usart.h"
|
||||
#include "gpio.h"
|
||||
|
||||
float temperature;
|
||||
float vref_value;
|
||||
|
||||
void adc_config(void);
|
||||
void jump_to_app(uint32_t addr);
|
||||
|
||||
#include "epaper.h"
|
||||
#include "bmp.h"
|
||||
|
||||
// define for White Black Red Epaper Module
|
||||
#define EPD_BWR
|
||||
|
||||
uint8_t image_bw[4000];
|
||||
#ifdef EPD_BWR
|
||||
uint8_t image_red[4000];
|
||||
#endif
|
||||
|
||||
/*!
|
||||
\brief main function
|
||||
\param[in] none
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
uint8_t text[20];
|
||||
|
||||
#ifdef HID_IAP
|
||||
/* Soft :GD32 MCU HID IAP Programmer, Bootloader Size :8KB */
|
||||
/* if use HID bootloader ,set ROM start addr 0x8002000 && set vector */
|
||||
/* if not use HID bootloader ,set ROM start addr 0x8000000 && Comment out the following code */
|
||||
// nvic_vector_table_set(NVIC_VECTTAB_FLASH,0x2000);
|
||||
nvic_vector_table_set(NVIC_VECTTAB_FLASH, 0x2000);
|
||||
#endif
|
||||
|
||||
rcu_all_reset_flag_clear();
|
||||
|
||||
dbg_low_power_enable(DBG_LOW_POWER_SLEEP | DBG_LOW_POWER_DEEPSLEEP | DBG_LOW_POWER_STANDBY);
|
||||
|
||||
systick_config();
|
||||
|
||||
gpio_config();
|
||||
|
||||
adc_config();
|
||||
|
||||
usart0_config();
|
||||
|
||||
FlagStatus sw_led = SET;
|
||||
|
||||
uint32_t tick1, tick2;
|
||||
tick1 = tick2 = get_tick();
|
||||
|
||||
printf("\r\nWeAct Studio Core Board\r\n");
|
||||
printf("weactstudio.taobao.com\r\n");
|
||||
printf("weactstudio.aliexpress.com\r\n");
|
||||
printf("wwww.weact-tc.cn\r\n\r\n");
|
||||
printf("SystemClk:%d\r\n", SystemCoreClock);
|
||||
printf("CK_AHB is %d\r\n", rcu_clock_freq_get(CK_AHB));
|
||||
printf("CK_APB1 is %d\r\n", rcu_clock_freq_get(CK_APB1));
|
||||
printf("CK_APB2 is %d\r\n", rcu_clock_freq_get(CK_APB2));
|
||||
|
||||
printf("Epaper Module Test\r\n");
|
||||
|
||||
epd_io_init();
|
||||
|
||||
epd_init();
|
||||
|
||||
#ifdef EPD_BWR
|
||||
epd_paint_newimage(image_bw, EPD_W, EPD_H, EPD_ROTATE_180, EPD_COLOR_WHITE);
|
||||
|
||||
epd_paint_newimage(image_red, EPD_W, EPD_H, EPD_ROTATE_180, EPD_COLOR_WHITE);
|
||||
|
||||
epd_paint_selectimage(image_bw);
|
||||
epd_paint_clear(EPD_COLOR_WHITE);
|
||||
epd_paint_showPicture(0, 0, 250, 122, gImage_2, EPD_COLOR_BLACK);
|
||||
|
||||
epd_paint_selectimage(image_red);
|
||||
epd_paint_clear(EPD_COLOR_WHITE);
|
||||
epd_paint_showPicture(0, 0, 250, 122, gImage_3, EPD_COLOR_WHITE);
|
||||
|
||||
epd_display(image_bw, image_red);
|
||||
|
||||
delay(8000);
|
||||
|
||||
epd_paint_selectimage(image_bw);
|
||||
epd_paint_clear(EPD_COLOR_WHITE);
|
||||
epd_paint_showString(10, 0, (uint8_t *)&"2.13 Epaper Module", EPD_FONT_SIZE24x12, EPD_COLOR_BLACK);
|
||||
epd_paint_showString(10, 29, (uint8_t *)&"Designed By WeAct Studio", EPD_FONT_SIZE16x8, EPD_COLOR_BLACK);
|
||||
epd_paint_showString(10, 50, (uint8_t *)&"with 250 x 122 resolution", EPD_FONT_SIZE16x8, EPD_COLOR_BLACK);
|
||||
|
||||
epd_paint_selectimage(image_red);
|
||||
epd_paint_clear(EPD_COLOR_WHITE);
|
||||
|
||||
sprintf((char *)&text, ">> Hello World.");
|
||||
epd_paint_showString(10, 71, text, EPD_FONT_SIZE24x12, EPD_COLOR_RED);
|
||||
|
||||
#if 0
|
||||
epd_paint_showString(10,100,(uint8_t *)&"GD32F303CCT6 Example",EPD_FONT_SIZE16x8,EPD_COLOR_RED);
|
||||
#else
|
||||
epd_paint_drawRectangle(10, 103, 240, 116, EPD_COLOR_RED, 1);
|
||||
#endif
|
||||
|
||||
epd_display(image_bw, image_red);
|
||||
#else
|
||||
epd_paint_newimage(image_bw, EPD_W, EPD_H, EPD_ROTATE_180, EPD_COLOR_WHITE);
|
||||
|
||||
epd_paint_selectimage(image_bw);
|
||||
epd_paint_clear(EPD_COLOR_WHITE);
|
||||
epd_paint_showPicture(0, 0, 250, 122, gImage_1, EPD_COLOR_WHITE);
|
||||
|
||||
epd_displayBW(image_bw);
|
||||
|
||||
delay(5000);
|
||||
|
||||
epd_paint_selectimage(image_bw);
|
||||
epd_paint_clear(EPD_COLOR_WHITE);
|
||||
epd_paint_showString(10, 0, (uint8_t *)&"2.13 Epaper Module", EPD_FONT_SIZE24x12, EPD_COLOR_BLACK);
|
||||
epd_paint_showString(10, 29, (uint8_t *)&"Designed By WeAct Studio", EPD_FONT_SIZE16x8, EPD_COLOR_BLACK);
|
||||
epd_paint_showString(10, 50, (uint8_t *)&"with 250 x 122 resolution", EPD_FONT_SIZE16x8, EPD_COLOR_BLACK);
|
||||
|
||||
sprintf((char *)&text, ">> Hello World.");
|
||||
epd_paint_showString(10, 71, text, EPD_FONT_SIZE24x12, EPD_COLOR_BLACK);
|
||||
|
||||
#if 0
|
||||
epd_paint_showString(10,100,(uint8_t *)&"GD32F303CCT6 Example",EPD_FONT_SIZE16x8,EPD_COLOR_BLACK);
|
||||
#else
|
||||
epd_paint_drawRectangle(10, 103, 240, 116, EPD_COLOR_BLACK, 1);
|
||||
#endif
|
||||
epd_displayBW(image_bw);
|
||||
#endif
|
||||
|
||||
epd_enter_deepsleepmode(EPD_DEEPSLEEP_MODE1);
|
||||
|
||||
while (1)
|
||||
{
|
||||
|
||||
if (get_tick() > tick1)
|
||||
{
|
||||
tick1 = get_tick() + 500 / SysTick_Tick;
|
||||
|
||||
if (sw_led == SET)
|
||||
{
|
||||
/* toggle LED */
|
||||
gpio_bit_write(LED_PB2_PORT, LED_PB2_PIN, (gpio_output_bit_get(LED_PB2_PORT, LED_PB2_PIN)) == SET ? RESET : SET);
|
||||
}
|
||||
else
|
||||
{
|
||||
gpio_bit_reset(LED_PB2_PORT, LED_PB2_PIN);
|
||||
}
|
||||
}
|
||||
|
||||
if (get_tick() > tick2)
|
||||
{
|
||||
tick2 = get_tick() + 10 / SysTick_Tick;
|
||||
|
||||
static uint32_t PressTimeCount = 0;
|
||||
|
||||
static FlagStatus IsPress = RESET;
|
||||
if (gpio_input_bit_get(KEY_PORT, KEY_PIN) != SET)
|
||||
{
|
||||
if (IsPress == SET)
|
||||
{
|
||||
IsPress = RESET;
|
||||
|
||||
/* KEY click */
|
||||
sw_led = sw_led == SET ? RESET : SET;
|
||||
printf("Hello,WeAct Studio\r\n");
|
||||
|
||||
/* ADC software trigger enable */
|
||||
adc_software_trigger_enable(ADC0, ADC_INSERTED_CHANNEL);
|
||||
/* delay a time in milliseconds */
|
||||
|
||||
while (adc_flag_get(ADC0, ADC_FLAG_EOC) == RESET)
|
||||
{
|
||||
delay_lp(1);
|
||||
}
|
||||
adc_flag_clear(ADC0, ADC_FLAG_EOC);
|
||||
|
||||
/* value convert */
|
||||
temperature = (1430.f - ADC_IDATA0(ADC0) * 3300 / 4096) / 4.3f + 25;
|
||||
vref_value = (ADC_IDATA1(ADC0) * 3300 / 4096.f);
|
||||
|
||||
/* value print */
|
||||
printf("The temperature data is %2.1f degrees Celsius\r\n", temperature);
|
||||
printf("The reference voltage data is %5.3fmV \r\n", vref_value);
|
||||
printf("\r\n");
|
||||
|
||||
PressTimeCount = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (IsPress == RESET)
|
||||
{
|
||||
IsPress = SET;
|
||||
}
|
||||
PressTimeCount++;
|
||||
|
||||
/*0.5s KEY long press */
|
||||
if (PressTimeCount >= 50)
|
||||
{
|
||||
/* long press , system reset and enter the IAP bootloader */
|
||||
if (SCB->VTOR != 0)
|
||||
{
|
||||
printf("Enter IAP Bootloader ...\r\n");
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Enter system ISP Bootloader ...\r\n");
|
||||
|
||||
#define ISP_ADDR ((uint32_t)0x1FFFF000)
|
||||
|
||||
systick_deinit();
|
||||
gpio_deinit(LED_PB2_PORT);
|
||||
gpio_deinit(KEY_PORT);
|
||||
jump_to_app(ISP_ADDR);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
pmu_to_sleepmode(WFI_CMD);
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief configure the ADC peripheral
|
||||
\param[in] none
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
void adc_config(void)
|
||||
{
|
||||
/* enable ADC clock */
|
||||
rcu_periph_clock_enable(RCU_ADC0);
|
||||
/* config ADC clock */
|
||||
rcu_adc_clock_config(RCU_CKADC_CKAPB2_DIV4);
|
||||
|
||||
/* ADC SCAN function enable */
|
||||
adc_special_function_config(ADC0, ADC_SCAN_MODE, ENABLE);
|
||||
adc_special_function_config(ADC0, ADC_CONTINUOUS_MODE, DISABLE);
|
||||
/* ADC trigger config */
|
||||
adc_external_trigger_source_config(ADC0, ADC_INSERTED_CHANNEL, ADC0_1_2_EXTTRIG_INSERTED_NONE);
|
||||
/* ADC mode config */
|
||||
adc_mode_config(ADC_MODE_FREE);
|
||||
/* ADC data alignment config */
|
||||
adc_data_alignment_config(ADC0, ADC_DATAALIGN_RIGHT);
|
||||
/* ADC channel length config */
|
||||
adc_channel_length_config(ADC0, ADC_INSERTED_CHANNEL, 2);
|
||||
|
||||
/* ADC temperature sensor channel config */
|
||||
adc_inserted_channel_config(ADC0, 0, ADC_CHANNEL_16, ADC_SAMPLETIME_239POINT5);
|
||||
/* ADC internal reference voltage channel config */
|
||||
adc_inserted_channel_config(ADC0, 1, ADC_CHANNEL_17, ADC_SAMPLETIME_239POINT5);
|
||||
|
||||
adc_external_trigger_config(ADC0, ADC_INSERTED_CHANNEL, ENABLE);
|
||||
|
||||
/* ADC temperature and Vrefint enable */
|
||||
adc_tempsensor_vrefint_enable();
|
||||
|
||||
/* enable ADC interface */
|
||||
adc_enable(ADC0);
|
||||
delay(1);
|
||||
/* ADC calibration and reset calibration */
|
||||
adc_calibration_enable(ADC0);
|
||||
}
|
||||
|
||||
void jump_to_app(uint32_t addr)
|
||||
{
|
||||
uint32_t app_address;
|
||||
void *(*application)(void);
|
||||
|
||||
/* test if user code is programmed starting from address */
|
||||
if (((*(__IO uint32_t *)addr) & 0x2FFE0000) == 0x20000000)
|
||||
{
|
||||
app_address = *(__IO uint32_t *)(addr + 4);
|
||||
application = (void *(*)(void))app_address;
|
||||
|
||||
/* initialize user application's stack pointer */
|
||||
__set_MSP(*(__IO uint32_t *)addr);
|
||||
|
||||
/* jump to application */
|
||||
application();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
/*!
|
||||
\file systick.c
|
||||
\brief the systick configuration file
|
||||
|
||||
\version 2017-02-10, V1.0.0, firmware for GD32F30x
|
||||
\version 2018-10-10, V1.1.0, firmware for GD32F30x
|
||||
\version 2018-12-25, V2.0.0, firmware for GD32F30x
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright (c) 2018, GigaDevice Semiconductor Inc.
|
||||
|
||||
All rights reserved.
|
||||
|
||||
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 "gd32f30x.h"
|
||||
#include "systick.h"
|
||||
|
||||
volatile static uint32_t tick = 0;
|
||||
|
||||
/*!
|
||||
\brief configure systick
|
||||
\param[in] none
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
void systick_config(void)
|
||||
{
|
||||
/* setup systick timer for (SysTick_Freq) Hz interrupts */
|
||||
if (SysTick_Config(SystemCoreClock / SysTick_Freq)){
|
||||
/* capture error */
|
||||
while (1){
|
||||
}
|
||||
}
|
||||
/* configure the systick handler priority */
|
||||
NVIC_SetPriority(SysTick_IRQn, 0x05U);
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief delay a time in milliseconds
|
||||
\param[in] count: count in milliseconds
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
void delay(uint32_t count)
|
||||
{
|
||||
uint32_t utick;
|
||||
utick = count + get_tick();
|
||||
|
||||
while(get_tick() < utick){
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief delay a time in milliseconds with low power
|
||||
\param[in] count: count in milliseconds
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
void delay_lp(uint32_t count)
|
||||
{
|
||||
uint32_t utick;
|
||||
utick = count + get_tick();
|
||||
|
||||
while(get_tick() < utick){
|
||||
pmu_to_sleepmode(WFI_CMD);
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief delay decrement
|
||||
\param[in] none
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
void delay_decrement(void)
|
||||
{
|
||||
tick++;
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief get systick tick
|
||||
\param[in] none
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
|
||||
uint32_t get_tick(void)
|
||||
{
|
||||
return tick;
|
||||
}
|
||||
|
||||
void systick_DisableIRQ(void)
|
||||
{
|
||||
/* Disable SysTick Interrupt */
|
||||
SysTick->CTRL &= ~SysTick_CTRL_TICKINT_Msk;
|
||||
}
|
||||
|
||||
void systick_EnableIRQ(void)
|
||||
{
|
||||
/* Enable SysTick Interrupt */
|
||||
SysTick->CTRL |= SysTick_CTRL_TICKINT_Msk;
|
||||
}
|
||||
|
||||
void systick_Disable(void)
|
||||
{
|
||||
/* Disable SysTick */
|
||||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
|
||||
}
|
||||
|
||||
void systick_Enable(void)
|
||||
{
|
||||
/* Enable SysTick */
|
||||
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
|
||||
}
|
||||
|
||||
void systick_deinit(void)
|
||||
{
|
||||
SysTick->CTRL = 0;
|
||||
SysTick->LOAD = 0;
|
||||
SysTick->VAL = 0;
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
#include "usart.h"
|
||||
|
||||
/* for MicroLIB */
|
||||
int fputc(int ch, FILE *f)
|
||||
{
|
||||
/* Place your implementation of fputc here */
|
||||
/* e.g. write a character to the USART3 and Loop until the end of transmission */
|
||||
usart_data_transmit(USART0, (uint8_t)ch);
|
||||
while(RESET == usart_flag_get(USART0, USART_FLAG_TBE));
|
||||
return ch;
|
||||
}
|
||||
|
||||
/* for GNU */
|
||||
int _write (int fd, char *pBuffer, int size)
|
||||
{
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
usart_data_transmit(USART0, (uint8_t)pBuffer[i]);
|
||||
while(RESET == usart_flag_get(USART0, USART_FLAG_TBE));
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
void usart0_config(void)
|
||||
{
|
||||
/* enable GPIO clock */
|
||||
rcu_periph_clock_enable(RCU_GPIOA);
|
||||
|
||||
/* enable USART clock */
|
||||
rcu_periph_clock_enable(RCU_USART0);
|
||||
|
||||
/* connect port to USARTx_Tx */
|
||||
gpio_init(GPIOA, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_9);
|
||||
|
||||
/* connect port to USARTx_Rx */
|
||||
gpio_init(GPIOA, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_10);
|
||||
|
||||
/* USART configure */
|
||||
usart_deinit(USART0);
|
||||
usart_baudrate_set(USART0, 115200U);
|
||||
usart_receive_config(USART0, USART_RECEIVE_ENABLE);
|
||||
usart_transmit_config(USART0, USART_TRANSMIT_ENABLE);
|
||||
usart_enable(USART0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user