add support for GD32F310G-START
This commit is contained in:
60
board/GD32F310G_START/BSP/Inc/gd32f3x0_it.h
Normal file
60
board/GD32F310G_START/BSP/Inc/gd32f3x0_it.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/*!
|
||||
\file gd32f3x0_it.h
|
||||
\brief the header file of the ISR
|
||||
|
||||
\version 2022-03-06, V1.0.0, demo for GD32F3x0
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright (c) 2022, 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 GD32F3X0_IT_H
|
||||
#define GD32F3X0_IT_H
|
||||
|
||||
#include "gd32f3x0.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 /* GD32F3X0_IT_H */
|
65
board/GD32F310G_START/BSP/Inc/gd32f3x0_libopt.h
Normal file
65
board/GD32F310G_START/BSP/Inc/gd32f3x0_libopt.h
Normal file
@@ -0,0 +1,65 @@
|
||||
/*!
|
||||
\file gd32f3x0_libopt.h
|
||||
\brief library optional for gd32f3x0
|
||||
|
||||
\version 2022-03-06, V1.0.0, demo for GD32F3x0
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright (c) 2022, 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 GD32F3X0_LIBOPT_H
|
||||
#define GD32F3X0_LIBOPT_H
|
||||
|
||||
#include "gd32f3x0_adc.h"
|
||||
#include "gd32f3x0_crc.h"
|
||||
#include "gd32f3x0_ctc.h"
|
||||
#include "gd32f3x0_dbg.h"
|
||||
#include "gd32f3x0_dma.h"
|
||||
#include "gd32f3x0_exti.h"
|
||||
#include "gd32f3x0_fmc.h"
|
||||
#include "gd32f3x0_gpio.h"
|
||||
#include "gd32f3x0_syscfg.h"
|
||||
#include "gd32f3x0_i2c.h"
|
||||
#include "gd32f3x0_fwdgt.h"
|
||||
#include "gd32f3x0_pmu.h"
|
||||
#include "gd32f3x0_rcu.h"
|
||||
#include "gd32f3x0_rtc.h"
|
||||
#include "gd32f3x0_spi.h"
|
||||
#include "gd32f3x0_timer.h"
|
||||
#include "gd32f3x0_usart.h"
|
||||
#include "gd32f3x0_wwdgt.h"
|
||||
#include "gd32f3x0_misc.h"
|
||||
#include "gd32f3x0_tsi.h"
|
||||
|
||||
#ifdef GD32F350
|
||||
#include "gd32f3x0_cec.h"
|
||||
#include "gd32f3x0_cmp.h"
|
||||
#include "gd32f3x0_dac.h"
|
||||
#endif /* GD32F350 */
|
||||
|
||||
#endif /* GD32F3X0_LIBOPT_H */
|
30
board/GD32F310G_START/BSP/Inc/gpio.h
Normal file
30
board/GD32F310G_START/BSP/Inc/gpio.h
Normal file
@@ -0,0 +1,30 @@
|
||||
/******************************************************************************
|
||||
* File: gpio.h
|
||||
*
|
||||
* Author: iysheng@163.com
|
||||
* Created: 04/14/22
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef __GPIO_H__
|
||||
#define __GPIO_H__
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "gd32f3x0_libopt.h"
|
||||
|
||||
#define LED_Pin GPIO_PIN_1
|
||||
#define LED_GPIO_Port GPIOA
|
||||
|
||||
/**
|
||||
* @brief GPIO inint
|
||||
* @param void:
|
||||
* retval N/A.
|
||||
*/
|
||||
void board_gpio_init(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /*__PINOUT_H__ */
|
36
board/GD32F310G_START/BSP/Inc/main.h
Normal file
36
board/GD32F310G_START/BSP/Inc/main.h
Normal file
@@ -0,0 +1,36 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : main.h
|
||||
* @brief : Header for main.c file.
|
||||
* This file contains the common defines of the application.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2019 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under BSD 3-Clause license,
|
||||
* the "License"; You may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at:
|
||||
* opensource.org/licenses/BSD-3-Clause
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __MAIN_H
|
||||
#define __MAIN_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __MAIN_H */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
18
board/GD32F310G_START/BSP/Inc/mcu_init.h
Normal file
18
board/GD32F310G_START/BSP/Inc/mcu_init.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef __MCU_INIT_H
|
||||
#define __MCU_INIT_H
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "main.h"
|
||||
#include "usart.h"
|
||||
#include "gpio.h"
|
||||
#include "tos_k.h"
|
||||
|
||||
void board_init(void);
|
||||
void SystemClock_Config(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /*__ __MCU_INIT_H */
|
11
board/GD32F310G_START/BSP/Inc/tickless/bsp_pm_device.h
Normal file
11
board/GD32F310G_START/BSP/Inc/tickless/bsp_pm_device.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#ifndef _PM_DEVICE_H_
|
||||
#define _PM_DEVICE_H_
|
||||
|
||||
#if TOS_CFG_PWR_MGR_EN > 0u
|
||||
|
||||
extern k_pm_device_t pm_device_uart;
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
17
board/GD32F310G_START/BSP/Inc/tickless/bsp_tickless_alarm.h
Normal file
17
board/GD32F310G_START/BSP/Inc/tickless/bsp_tickless_alarm.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef _TICKLESS_ALARM_H_
|
||||
#define _TICKLESS_ALARM_H_
|
||||
|
||||
#if TOS_CFG_TICKLESS_EN > 0u
|
||||
|
||||
extern k_tickless_wkup_alarm_t tickless_wkup_alarm_systick;
|
||||
|
||||
extern k_tickless_wkup_alarm_t tickless_wkup_alarm_tim;
|
||||
|
||||
extern k_tickless_wkup_alarm_t tickless_wkup_alarm_rtc_wkupirq;
|
||||
|
||||
extern k_tickless_wkup_alarm_t tickless_wkup_alarm_rtc_alarmirq;
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
25
board/GD32F310G_START/BSP/Inc/usart.h
Normal file
25
board/GD32F310G_START/BSP/Inc/usart.h
Normal file
@@ -0,0 +1,25 @@
|
||||
/******************************************************************************
|
||||
* File: usart.h
|
||||
*
|
||||
* Author: iysheng@163.com
|
||||
* Created: 04/14/22
|
||||
* Description:
|
||||
*****************************************************************************/
|
||||
#ifndef __USART_H__
|
||||
#define __USART_H__
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include "gd32f3x0_libopt.h"
|
||||
|
||||
/**
|
||||
* @brief 板级 usart 硬件初始化
|
||||
* @param void:
|
||||
* retval N/A.
|
||||
*/
|
||||
int board_usart_init(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /*__USART_H__ */
|
151
board/GD32F310G_START/BSP/Src/gd32f3x0_it.c
Normal file
151
board/GD32F310G_START/BSP/Src/gd32f3x0_it.c
Normal file
@@ -0,0 +1,151 @@
|
||||
/*!
|
||||
\file gd32f3x0_it.c
|
||||
\brief interrupt service routines
|
||||
|
||||
\version 2022-03-06, V1.0.0, demo for GD32F3x0
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright (c) 2022, 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 "gd32f3x0_it.h"
|
||||
#include "tos_k.h"
|
||||
#include "tos_shell.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 SysTick exception
|
||||
\param[in] none
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
void SysTick_Handler(void)
|
||||
{
|
||||
if (tos_knl_is_running())
|
||||
{
|
||||
tos_knl_irq_enter();
|
||||
tos_tick_handler();
|
||||
tos_knl_irq_leave();
|
||||
}
|
||||
}
|
||||
|
||||
void USART0_IRQHandler(void)
|
||||
{
|
||||
tos_knl_irq_enter();
|
||||
if (SET == usart_interrupt_flag_get(USART0, USART_INT_FLAG_RBNE))
|
||||
{
|
||||
usart_flag_clear(USART0, USART_FLAG_ORERR);
|
||||
tos_shell_input_byte((uint8_t)usart_data_receive(USART0));
|
||||
}
|
||||
if (SET == usart_interrupt_flag_get(USART0, USART_INT_FLAG_RBNE_ORERR))
|
||||
{
|
||||
usart_interrupt_flag_clear(USART0, USART_INT_FLAG_RBNE_ORERR);
|
||||
}
|
||||
tos_knl_irq_leave();
|
||||
}
|
||||
|
29
board/GD32F310G_START/BSP/Src/gpio.c
Normal file
29
board/GD32F310G_START/BSP/Src/gpio.c
Normal file
@@ -0,0 +1,29 @@
|
||||
/******************************************************************************
|
||||
* File: gpio.c
|
||||
*
|
||||
* Author: iysheng@163.com
|
||||
* Created: 04/14/22
|
||||
* gpio hardware init
|
||||
*****************************************************************************/
|
||||
|
||||
#include "gpio.h"
|
||||
|
||||
/**
|
||||
* @brief GPIO inint
|
||||
* @param void:
|
||||
* retval N/A.
|
||||
*/
|
||||
void board_gpio_init(void)
|
||||
{
|
||||
rcu_periph_clock_enable(RCU_GPIOA);
|
||||
rcu_periph_clock_enable(RCU_GPIOA);
|
||||
gpio_mode_set(GPIOA, GPIO_MODE_AF, GPIO_PUPD_PULLUP, GPIO_PIN_9);
|
||||
gpio_mode_set(GPIOA, GPIO_MODE_AF, GPIO_PUPD_PULLUP, GPIO_PIN_10);
|
||||
gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, GPIO_PIN_10);
|
||||
gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, GPIO_PIN_9);
|
||||
gpio_af_set(GPIOA, GPIO_AF_1, GPIO_PIN_9);
|
||||
gpio_af_set(GPIOA, GPIO_AF_1, GPIO_PIN_10);
|
||||
gpio_mode_set(GPIOA, GPIO_MODE_OUTPUT, GPIO_PUPD_PULLUP, GPIO_PIN_1);
|
||||
gpio_bit_set(GPIOA, GPIO_PIN_1);
|
||||
}
|
||||
|
37
board/GD32F310G_START/BSP/Src/main.c
Normal file
37
board/GD32F310G_START/BSP/Src/main.c
Normal file
@@ -0,0 +1,37 @@
|
||||
#include "mcu_init.h"
|
||||
#include "tos_shell.h"
|
||||
|
||||
#define APPLICATION_TASK_STK_SIZE 0x100
|
||||
k_task_t application_task;
|
||||
uint8_t application_task_stk[APPLICATION_TASK_STK_SIZE];
|
||||
static char gs_cmd_buffer[32];
|
||||
|
||||
__attribute__ ((__weak__)) void application_entry(void *arg)
|
||||
{
|
||||
while (1) {
|
||||
gpio_bit_toggle(LED_GPIO_Port, LED_Pin);
|
||||
tos_task_delay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
static void board_shell_output_t(const char ch)
|
||||
{
|
||||
if (ch == '\n')
|
||||
{
|
||||
while(RESET == usart_flag_get(USART0, USART_FLAG_TBE));
|
||||
usart_data_transmit(USART0, '\r');
|
||||
}
|
||||
while(RESET == usart_flag_get(USART0, USART_FLAG_TBE));
|
||||
usart_data_transmit(USART0, ch);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
board_init();
|
||||
printf("Welcome to TencentOS tiny(%s)\r\n", TOS_VERSION);
|
||||
tos_knl_init();
|
||||
tos_task_create(&application_task, "application_task", application_entry, NULL, 4, application_task_stk, APPLICATION_TASK_STK_SIZE, 0);
|
||||
tos_shell_init(gs_cmd_buffer, sizeof(gs_cmd_buffer), board_shell_output_t, NULL);
|
||||
tos_knl_start();
|
||||
}
|
||||
|
36
board/GD32F310G_START/BSP/Src/mcu_init.c
Normal file
36
board/GD32F310G_START/BSP/Src/mcu_init.c
Normal file
@@ -0,0 +1,36 @@
|
||||
#include "mcu_init.h"
|
||||
|
||||
#define USART_CONSOLE (USART0)
|
||||
int fputc(int ch, FILE *f)
|
||||
{
|
||||
if (ch == '\n') {
|
||||
while(RESET == usart_flag_get(USART_CONSOLE, USART_FLAG_TBE));
|
||||
/* Auto complete return char */
|
||||
usart_data_transmit(USART_CONSOLE, '\r');
|
||||
}
|
||||
while(RESET == usart_flag_get(USART_CONSOLE, USART_FLAG_TBE));
|
||||
usart_data_transmit(USART_CONSOLE, ch);
|
||||
return ch;
|
||||
}
|
||||
|
||||
int _write(int fd, char *ptr, int len)
|
||||
{
|
||||
int i = 0;
|
||||
for (; i < len; i++)
|
||||
{
|
||||
if (*(ptr + i) == '\n') {
|
||||
while(RESET == usart_flag_get(USART_CONSOLE, USART_FLAG_TBE));
|
||||
/* Auto complete return char */
|
||||
usart_data_transmit(USART_CONSOLE, '\r');
|
||||
}
|
||||
while(RESET == usart_flag_get(USART_CONSOLE, USART_FLAG_TBE));
|
||||
usart_data_transmit(USART_CONSOLE, *(ptr + i));
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
void board_init(void)
|
||||
{
|
||||
board_gpio_init();
|
||||
board_usart_init();
|
||||
}
|
31
board/GD32F310G_START/BSP/Src/tickless/bsp_pm_device.c
Normal file
31
board/GD32F310G_START/BSP/Src/tickless/bsp_pm_device.c
Normal file
@@ -0,0 +1,31 @@
|
||||
#include "tos_k.h"
|
||||
#include "mcu_init.h"
|
||||
|
||||
#if TOS_CFG_PWR_MGR_EN > 0u
|
||||
|
||||
static int pm_device_uart_init(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int pm_device_uart_suspend(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int pm_device_uart_resume(void)
|
||||
{
|
||||
SystemClock_Config();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
k_pm_device_t pm_device_uart = {
|
||||
.name = "uart",
|
||||
.init = pm_device_uart_init,
|
||||
.suspend = pm_device_uart_suspend,
|
||||
.resume = pm_device_uart_resume,
|
||||
};
|
||||
|
||||
#endif
|
||||
|
26
board/GD32F310G_START/BSP/Src/tickless/bsp_pwr_mgr.c
Normal file
26
board/GD32F310G_START/BSP/Src/tickless/bsp_pwr_mgr.c
Normal file
@@ -0,0 +1,26 @@
|
||||
#include "tos_k.h"
|
||||
#include "tickless/bsp_pm_device.h"
|
||||
#include "tickless/bsp_tickless_alarm.h"
|
||||
|
||||
int tos_bsp_tickless_setup(void)
|
||||
{
|
||||
#if TOS_CFG_TICKLESS_EN > 0u
|
||||
tos_pm_device_register(&pm_device_uart);
|
||||
|
||||
/* we set a default one shot timer here(systick) */
|
||||
// tos_tickless_wkup_alarm_install(TOS_LOW_POWER_MODE_SLEEP, &tickless_wkup_alarm_systick);
|
||||
tos_tickless_wkup_alarm_install(TOS_LOW_POWER_MODE_SLEEP, &tickless_wkup_alarm_tim);
|
||||
tos_tickless_wkup_alarm_init(TOS_LOW_POWER_MODE_SLEEP);
|
||||
|
||||
tos_tickless_wkup_alarm_install(TOS_LOW_POWER_MODE_STOP, &tickless_wkup_alarm_rtc_wkupirq);
|
||||
tos_tickless_wkup_alarm_init(TOS_LOW_POWER_MODE_STOP);
|
||||
|
||||
tos_tickless_wkup_alarm_install(TOS_LOW_POWER_MODE_STANDBY, &tickless_wkup_alarm_rtc_alarmirq);
|
||||
tos_tickless_wkup_alarm_init(TOS_LOW_POWER_MODE_STANDBY);
|
||||
|
||||
tos_pm_cpu_lpwr_mode_set(TOS_LOW_POWER_MODE_SLEEP);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
440
board/GD32F310G_START/BSP/Src/tickless/bsp_tickless_alarm.c
Normal file
440
board/GD32F310G_START/BSP/Src/tickless/bsp_tickless_alarm.c
Normal file
@@ -0,0 +1,440 @@
|
||||
#include "tos_k.h"
|
||||
|
||||
#include "stm32l4xx_hal.h"
|
||||
#include "stm32l4xx_hal_tim.h"
|
||||
#include "stm32l4xx_hal_rtc.h"
|
||||
|
||||
#if TOS_CFG_TICKLESS_EN > 0u
|
||||
|
||||
/*
|
||||
systick<63><6B><EFBFBD><EFBFBD>Ҳ<EFBFBD><D2B2>ʵ<EFBFBD><CAB5>Ϊtickless<73>Ļ<EFBFBD><C4BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD>ʵ<EFBFBD><CAB5>ԭ<EFBFBD><D4AD><EFBFBD>ǣ<EFBFBD><C7A3><EFBFBD>ϵͳҪ<CDB3><D2AA><EFBFBD><EFBFBD>ticklessģʽʱ<CABD><CAB1>
|
||||
<20><>systick<63>Ĵ<EFBFBD><C4B4><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
<20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>6000ms<6D><73>ִ<EFBFBD>У<EFBFBD><D0A3><EFBFBD>ô<EFBFBD><C3B4>6000ms<6D><73>systickû<6B>б<EFBFBD>Ҫһֱ<D2BB><D6B1><EFBFBD><EFBFBD>
|
||||
<20><><EFBFBD><EFBFBD>systick<63><6B><EFBFBD>жϼ<D0B6><CFBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ6000ms<6D><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD>systick<63>ڲ<EFBFBD><DAB2>ļ<EFBFBD>ʱ<EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>ֻ<EFBFBD><D6BB>24λ<34><CEBB>systick
|
||||
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϼ<D0B6><CFBC><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD>Բο<D4B2>tickless_systick_wkup_alarm_max_delayʵ<79>֣<EFBFBD><D6A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȼ<EFBFBD><C8BB><EFBFBD><EFBFBD><EFBFBD>ڽ<EFBFBD><DABD><EFBFBD>idleʱ<65><CAB1><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>cpu<70><75><EFBFBD><EFBFBD>sleepģʽҪ<CABD>ͣ<EFBFBD><CDA3><EFBFBD>Ϊsystick<63><6B><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˣ<EFBFBD>cpu<70><75><EFBFBD><EFBFBD><EFBFBD><EFBFBD>sleep
|
||||
ģʽ<C4A3><CABD>ͣ<EFBFBD><CDA3><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD>
|
||||
|
||||
ʵ<><CAB5><EFBFBD>ϣ<EFBFBD>tickless_systick_wkup_alarm_dismiss<73><73>tickless_wkup_alarm_dismiss<73><73><EFBFBD>ӿ<EFBFBD><D3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȱ<EFBFBD>ݵģ<DDB5>
|
||||
<20><>ΪCPU<50><55>tickless<73><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܲ<EFBFBD><DCB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>ʱ<EFBFBD>䵽<EFBFBD>ˣ<EFBFBD><CBA3>п<EFBFBD><D0BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ⲿ<EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>CPU<50><55><EFBFBD>ѣ<EFBFBD><D1A3><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>
|
||||
Ϊ<>걸<EFBFBD><EAB1B8>ʵ<EFBFBD><CAB5>Ӧ<EFBFBD><D3A6><EFBFBD>ǣ<EFBFBD><C7A3><EFBFBD>tickless_wkup_alarm_dismiss<73>ӿڷ<D3BF><DAB7><EFBFBD>ʵ<EFBFBD><CAB5>˯<EFBFBD>ߵ<EFBFBD>ʱ<EFBFBD>䣨<EFBFBD><E4A3A8><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD>ӵļ<D3B5>ʱ<EFBFBD>Ĵ<EFBFBD>
|
||||
<20><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȱ<EFBFBD>ݺ<EFBFBD><DDBA>ڻ<EFBFBD><DABB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><DEB8><EFBFBD><EFBFBD>ֽζ<D7B6>Ӳ<EFBFBD><D3B2><EFBFBD>в<EFBFBD><D0B2><EFBFBD>Ϥ<EFBFBD><CFA4>
|
||||
|
||||
ע<>⣬systickֻ<6B><D6BB><EFBFBD><EFBFBD>Ϊsleepģʽ<C4A3>µĻ<C2B5><C4BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD>ο<EFBFBD>tos_pm.h<><68>
|
||||
|
||||
Ŀǰ<C4BF><C7B0>һ<EFBFBD><D2BB>ʵ<EFBFBD><CAB5><EFBFBD>в<EFBFBD><D0B2>걸<EFBFBD><EAB1B8><EFBFBD>кܶ<D0BA><DCB6>ⷽ<EFBFBD><E2B7BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѻ<EFBFBD>ӭ<EFBFBD>ͽ<EFBFBD>~
|
||||
*/
|
||||
static void tickless_systick_suspend(void)
|
||||
{
|
||||
cpu_systick_suspend();
|
||||
cpu_systick_pending_reset();
|
||||
}
|
||||
|
||||
static void tickless_systick_resume(void)
|
||||
{
|
||||
cpu_systick_resume();
|
||||
}
|
||||
|
||||
static void tickless_systick_wkup_alarm_expires_set(k_time_t millisecond)
|
||||
{
|
||||
cpu_systick_expires_set(millisecond);
|
||||
}
|
||||
|
||||
static int tickless_systick_wkup_alarm_setup(k_time_t millisecond)
|
||||
{
|
||||
tickless_systick_suspend();
|
||||
tickless_systick_wkup_alarm_expires_set(millisecond);
|
||||
tickless_systick_resume();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tickless_systick_wkup_alarm_dismiss(void)
|
||||
{
|
||||
// TODO:
|
||||
// if not wakeup by systick(that's say another interrupt), need to identify this and fix
|
||||
return 0;
|
||||
}
|
||||
|
||||
static k_time_t tickless_systick_wkup_alarm_max_delay(void)
|
||||
{
|
||||
return cpu_systick_max_delay_millisecond();
|
||||
}
|
||||
|
||||
k_tickless_wkup_alarm_t tickless_wkup_alarm_systick = {
|
||||
.init = K_NULL,
|
||||
.setup = tickless_systick_wkup_alarm_setup,
|
||||
.dismiss = tickless_systick_wkup_alarm_dismiss,
|
||||
.max_delay = tickless_systick_wkup_alarm_max_delay,
|
||||
};
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/*
|
||||
<20><><EFBFBD><EFBFBD>timer6ʵ<36>ֵ<EFBFBD>tickless<73><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD><D3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ΪSLEEPģʽ<C4A3>µĻ<C2B5><C4BB><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><EFBFBD>ο<EFBFBD>tos_pm.h<><68>
|
||||
Ŀǰ<C4BF><C7B0>һ<EFBFBD><D2BB>ʵ<EFBFBD><CAB5><EFBFBD>в<EFBFBD><D0B2>걸<EFBFBD><EAB1B8><EFBFBD>кܶ<D0BA><DCB6>ⷽ<EFBFBD><E2B7BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѻ<EFBFBD>ӭ<EFBFBD>ͽ<EFBFBD>~
|
||||
*/
|
||||
static TIM_HandleTypeDef tim6;
|
||||
|
||||
void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *tim_handler)
|
||||
{
|
||||
if (tim_handler->Instance == TIM6) {
|
||||
__HAL_RCC_TIM6_CLK_ENABLE();
|
||||
|
||||
/* TIM6 interrupt Init */
|
||||
HAL_NVIC_SetPriority(TIM6_DAC_IRQn, 0, 0);
|
||||
HAL_NVIC_EnableIRQ(TIM6_DAC_IRQn);
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef *tim_handler)
|
||||
{
|
||||
if (tim_handler->Instance == TIM6) {
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_TIM6_CLK_DISABLE();
|
||||
|
||||
/* TIM6 interrupt Deinit */
|
||||
HAL_NVIC_DisableIRQ(TIM6_DAC_IRQn);
|
||||
}
|
||||
}
|
||||
|
||||
static int tickless_tim6_wkup_alarm_init(void)
|
||||
{
|
||||
tim6.Instance = TIM6;
|
||||
tim6.Init.Prescaler = 0;
|
||||
tim6.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
tim6.Init.Period = 0;
|
||||
tim6.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||
tim6.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||
HAL_TIM_Base_Init(&tim6);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tickless_tim6_wkup_alarm_setup(k_time_t millisecond)
|
||||
{
|
||||
tim6.Init.Prescaler = 8000 - 1;
|
||||
tim6.Init.Period = (millisecond * 10) - 1;
|
||||
|
||||
HAL_TIM_Base_Stop(&tim6);
|
||||
__HAL_TIM_CLEAR_IT(&tim6, TIM_IT_UPDATE);
|
||||
|
||||
HAL_TIM_Base_Init(&tim6);
|
||||
HAL_TIM_Base_Start_IT(&tim6);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tickless_tim6_wkup_alarm_dismiss(void)
|
||||
{
|
||||
TOS_CPU_CPSR_ALLOC();
|
||||
|
||||
TOS_CPU_INT_DISABLE();
|
||||
|
||||
HAL_TIM_Base_Stop(&tim6);
|
||||
HAL_TIM_Base_Stop_IT(&tim6);
|
||||
|
||||
TOS_CPU_INT_ENABLE();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static k_time_t tickless_tim6_wkup_alarm_max_delay(void)
|
||||
{
|
||||
k_time_t millisecond;
|
||||
uint32_t max_period;
|
||||
|
||||
max_period = ~((uint32_t)0u);
|
||||
millisecond = (max_period - 1) / 10;
|
||||
return millisecond;
|
||||
}
|
||||
|
||||
void TIM6_DAC_IRQHandler(void)
|
||||
{
|
||||
HAL_TIM_IRQHandler(&tim6);
|
||||
}
|
||||
|
||||
k_tickless_wkup_alarm_t tickless_wkup_alarm_tim = {
|
||||
.init = tickless_tim6_wkup_alarm_init,
|
||||
.setup = tickless_tim6_wkup_alarm_setup,
|
||||
.dismiss = tickless_tim6_wkup_alarm_dismiss,
|
||||
.max_delay = tickless_tim6_wkup_alarm_max_delay,
|
||||
};
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/*
|
||||
<20><><EFBFBD><EFBFBD>rtc wakeup<75>ж<EFBFBD>ʵ<EFBFBD>ֵ<EFBFBD>tickless<73><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD><D3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ΪSLEEP<45><50>STOPģʽ<C4A3>µĻ<C2B5><C4BB><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><EFBFBD>ο<EFBFBD>tos_pm.h<><68>
|
||||
Ŀǰ<C4BF><C7B0>һ<EFBFBD><D2BB>ʵ<EFBFBD><CAB5><EFBFBD>в<EFBFBD><D0B2>걸<EFBFBD><EAB1B8><EFBFBD>кܶ<D0BA><DCB6>ⷽ<EFBFBD><E2B7BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѻ<EFBFBD>ӭ<EFBFBD>ͽ<EFBFBD>~
|
||||
*/
|
||||
static RTC_HandleTypeDef rtc_handler;
|
||||
|
||||
static HAL_StatusTypeDef tickless_rtc_time_set(uint8_t hour, uint8_t minu, uint8_t sec, uint8_t format)
|
||||
{
|
||||
RTC_TimeTypeDef rtc_time;
|
||||
|
||||
rtc_time.Hours = hour;
|
||||
rtc_time.Minutes = minu;
|
||||
rtc_time.Seconds = sec;
|
||||
rtc_time.TimeFormat = format;
|
||||
rtc_time.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
|
||||
rtc_time.StoreOperation = RTC_STOREOPERATION_RESET;
|
||||
return HAL_RTC_SetTime(&rtc_handler, &rtc_time, RTC_FORMAT_BIN);
|
||||
}
|
||||
|
||||
static HAL_StatusTypeDef tickless_rtc_date_set(uint8_t year, uint8_t month, uint8_t date, uint8_t week)
|
||||
{
|
||||
RTC_DateTypeDef rtc_date;
|
||||
|
||||
rtc_date.Date = date;
|
||||
rtc_date.Month = month;
|
||||
rtc_date.WeekDay = week;
|
||||
rtc_date.Year = year;
|
||||
return HAL_RTC_SetDate(&rtc_handler, &rtc_date, RTC_FORMAT_BIN);
|
||||
}
|
||||
|
||||
static int tickless_rtc_wkup_alarm_init(void)
|
||||
{
|
||||
rtc_handler.Instance = RTC;
|
||||
rtc_handler.Init.HourFormat = RTC_HOURFORMAT_24;
|
||||
rtc_handler.Init.AsynchPrediv = 0X7F;
|
||||
rtc_handler.Init.SynchPrediv = 0XFF;
|
||||
rtc_handler.Init.OutPut = RTC_OUTPUT_DISABLE;
|
||||
rtc_handler.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
|
||||
rtc_handler.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
|
||||
|
||||
if (HAL_RTC_Init(&rtc_handler) != HAL_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (HAL_RTCEx_BKUPRead(&rtc_handler, RTC_BKP_DR0) != 0X5050) {
|
||||
tickless_rtc_time_set(23, 59, 56, RTC_HOURFORMAT12_PM);
|
||||
tickless_rtc_date_set(15, 12, 27, 7);
|
||||
HAL_RTCEx_BKUPWrite(&rtc_handler, RTC_BKP_DR0,0X5050);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tickless_rtc_wkupirq_wkup_alarm_setup(k_time_t millisecond)
|
||||
{
|
||||
uint32_t wkup_clock = RTC_WAKEUPCLOCK_CK_SPRE_16BITS;
|
||||
if (millisecond < 1000) {
|
||||
millisecond = 1000;
|
||||
}
|
||||
uint32_t wkup_count = (millisecond / 1000) - 1;
|
||||
|
||||
__HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(&rtc_handler, RTC_FLAG_WUTF);
|
||||
|
||||
HAL_RTCEx_SetWakeUpTimer_IT(&rtc_handler, wkup_count, wkup_clock);
|
||||
|
||||
HAL_NVIC_SetPriority(RTC_WKUP_IRQn, 0x02, 0x02);
|
||||
HAL_NVIC_EnableIRQ(RTC_WKUP_IRQn);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tickless_rtc_wkupirq_wkup_alarm_dismiss(void)
|
||||
{
|
||||
#if defined(STM32F4) || defined(STM32L4)
|
||||
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
|
||||
#endif
|
||||
|
||||
__HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(&rtc_handler, RTC_FLAG_WUTF);
|
||||
|
||||
if (HAL_RTCEx_DeactivateWakeUpTimer(&rtc_handler) != HAL_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
HAL_NVIC_DisableIRQ(RTC_WKUP_IRQn);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static k_time_t tickless_rtc_wkupirq_wkup_alarm_max_delay(void)
|
||||
{
|
||||
return 0xFFFF * K_TIME_MILLISEC_PER_SEC;
|
||||
}
|
||||
|
||||
void HAL_RTC_MspInit(RTC_HandleTypeDef *rtc_handler)
|
||||
{
|
||||
RCC_OscInitTypeDef rcc_osc;
|
||||
RCC_PeriphCLKInitTypeDef periph_clock;
|
||||
|
||||
__HAL_RCC_PWR_CLK_ENABLE();
|
||||
HAL_PWR_EnableBkUpAccess();
|
||||
|
||||
rcc_osc.OscillatorType = RCC_OSCILLATORTYPE_LSE;
|
||||
rcc_osc.PLL.PLLState = RCC_PLL_NONE;
|
||||
rcc_osc.LSEState = RCC_LSE_ON;
|
||||
HAL_RCC_OscConfig(&rcc_osc);
|
||||
|
||||
periph_clock.PeriphClockSelection = RCC_PERIPHCLK_RTC;
|
||||
periph_clock.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
|
||||
HAL_RCCEx_PeriphCLKConfig(&periph_clock);
|
||||
|
||||
__HAL_RCC_RTC_ENABLE();
|
||||
}
|
||||
|
||||
void RTC_WKUP_IRQHandler(void)
|
||||
{
|
||||
HAL_RTCEx_WakeUpTimerIRQHandler(&rtc_handler);
|
||||
}
|
||||
|
||||
void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *rtc_handler)
|
||||
{
|
||||
}
|
||||
|
||||
k_tickless_wkup_alarm_t tickless_wkup_alarm_rtc_wkupirq = {
|
||||
.init = tickless_rtc_wkup_alarm_init,
|
||||
.setup = tickless_rtc_wkupirq_wkup_alarm_setup,
|
||||
.dismiss = tickless_rtc_wkupirq_wkup_alarm_dismiss,
|
||||
.max_delay = tickless_rtc_wkupirq_wkup_alarm_max_delay,
|
||||
};
|
||||
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/*
|
||||
<20><><EFBFBD><EFBFBD>rtc alarm<72>ж<EFBFBD>ʵ<EFBFBD>ֵ<EFBFBD>tickless<73><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD><D3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ΪSLEEP<45><50>STOP<4F><50>STANDBYģʽ<C4A3>µĻ<C2B5><C4BB><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><EFBFBD>ο<EFBFBD>tos_pm.h<><68>
|
||||
Ŀǰ<C4BF><C7B0>һ<EFBFBD><D2BB>ʵ<EFBFBD><CAB5><EFBFBD>в<EFBFBD><D0B2>걸<EFBFBD><EAB1B8><EFBFBD>кܶ<D0BA><DCB6>ⷽ<EFBFBD><E2B7BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѻ<EFBFBD>ӭ<EFBFBD>ͽ<EFBFBD>~
|
||||
*/
|
||||
static int tickless_rtc_alarmirq_wkup_alarm_setup(k_time_t millisecond)
|
||||
{
|
||||
uint8_t hour, minute, second, subsecond, date;
|
||||
|
||||
RTC_AlarmTypeDef rtc_alarm;
|
||||
RTC_TimeTypeDef rtc_time;
|
||||
RTC_DateTypeDef rtc_date;
|
||||
|
||||
HAL_RTC_GetTime(&rtc_handler, &rtc_time, RTC_FORMAT_BIN);
|
||||
HAL_RTC_GetDate(&rtc_handler, &rtc_date, RTC_FORMAT_BIN);
|
||||
|
||||
hour = rtc_time.Hours;
|
||||
minute = rtc_time.Minutes;
|
||||
second = rtc_time.Seconds;
|
||||
#if 0
|
||||
date = rtc_date.Date;
|
||||
#else
|
||||
date = rtc_date.WeekDay;
|
||||
#endif
|
||||
|
||||
printf("before >>> %d %d %d %d\n", date, hour, minute, second);
|
||||
|
||||
/* I know it's ugly, I will find a elegant way. Welcome to tell me, 3ks~ */
|
||||
second += millisecond / K_TIME_MILLISEC_PER_SEC;
|
||||
if (second >= 60) {
|
||||
minute += 1;
|
||||
second -= 60;
|
||||
}
|
||||
if (minute >= 60) {
|
||||
hour += 1;
|
||||
minute -= 60;
|
||||
}
|
||||
if (hour >= 24) {
|
||||
date += 1;
|
||||
hour -= 24;
|
||||
}
|
||||
|
||||
printf("after >>> %d %d %d %d\n", date, hour, minute, second);
|
||||
|
||||
rtc_alarm.AlarmTime.Hours = hour;
|
||||
rtc_alarm.AlarmTime.Minutes = minute;
|
||||
rtc_alarm.AlarmTime.Seconds = second;
|
||||
rtc_alarm.AlarmTime.SubSeconds = 0;
|
||||
rtc_alarm.AlarmTime.TimeFormat = RTC_HOURFORMAT12_AM;
|
||||
|
||||
rtc_alarm.AlarmMask = RTC_ALARMMASK_NONE;
|
||||
rtc_alarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_NONE;
|
||||
rtc_alarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_WEEKDAY; // RTC_ALARMDATEWEEKDAYSEL_DATE; // RTC_ALARMDATEWEEKDAYSEL_WEEKDAY;
|
||||
rtc_alarm.AlarmDateWeekDay = date;
|
||||
rtc_alarm.Alarm = RTC_ALARM_A;
|
||||
HAL_RTC_SetAlarm_IT(&rtc_handler, &rtc_alarm, RTC_FORMAT_BIN);
|
||||
|
||||
HAL_NVIC_SetPriority(RTC_Alarm_IRQn, 0x01, 0x02);
|
||||
HAL_NVIC_EnableIRQ(RTC_Alarm_IRQn);
|
||||
|
||||
|
||||
// __HAL_PWR_GET_FLAG(PWR_FLAG_WU)
|
||||
|
||||
|
||||
__HAL_RCC_AHB1_FORCE_RESET(); //<2F><>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>IO<49><4F>
|
||||
__HAL_RCC_PWR_CLK_ENABLE(); //ʹ<><CAB9>PWRʱ<52><CAB1>
|
||||
|
||||
// __HAL_RCC_BACKUPRESET_FORCE(); //<2F><>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
HAL_PWR_EnableBkUpAccess(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>
|
||||
|
||||
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB);
|
||||
__HAL_RTC_WRITEPROTECTION_DISABLE(&rtc_handler);//<2F>ر<EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD>
|
||||
|
||||
//<2F>ر<EFBFBD>RTC<54><43><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
__HAL_RTC_WAKEUPTIMER_DISABLE_IT(&rtc_handler,RTC_IT_WUT);
|
||||
#if 0
|
||||
__HAL_RTC_TIMESTAMP_DISABLE_IT(&rtc_handler,RTC_IT_TS);
|
||||
__HAL_RTC_ALARM_DISABLE_IT(&rtc_handler,RTC_IT_ALRA|RTC_IT_ALRB);
|
||||
#endif
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>RTC<54><43><EFBFBD><EFBFBD><EFBFBD>жϱ<D0B6>־λ
|
||||
__HAL_RTC_ALARM_CLEAR_FLAG(&rtc_handler,RTC_FLAG_ALRAF|RTC_FLAG_ALRBF);
|
||||
__HAL_RTC_TIMESTAMP_CLEAR_FLAG(&rtc_handler,RTC_FLAG_TSF);
|
||||
__HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(&rtc_handler,RTC_FLAG_WUTF);
|
||||
|
||||
// __HAL_RCC_BACKUPRESET_RELEASE(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>
|
||||
__HAL_RTC_WRITEPROTECTION_ENABLE(&rtc_handler); //ʹ<><CAB9>RTCд<43><D0B4><EFBFBD><EFBFBD>
|
||||
|
||||
|
||||
#ifdef STM32F4
|
||||
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU); //<2F><><EFBFBD><EFBFBD>Wake_UP<55><50>־
|
||||
#endif
|
||||
|
||||
#ifdef STM32F7
|
||||
// __HAL_PWR_CLEAR_WAKEUP_FLAG(PWR_WAKEUP_PIN_FLAG1); //<2F><><EFBFBD><EFBFBD>Wake_UP<55><50>־
|
||||
#endif
|
||||
|
||||
// HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1); //<2F><><EFBFBD><EFBFBD>WKUP<55><50><EFBFBD>ڻ<EFBFBD><DABB><EFBFBD>
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tickless_rtc_alarmirq_wkup_alarm_dismiss(void)
|
||||
{
|
||||
#if 1
|
||||
// __HAL_PWR_GET_FLAG(PWR_FLAG_WU);
|
||||
|
||||
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
|
||||
|
||||
// __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(&rtc_handler, RTC_FLAG_ALRAF);
|
||||
|
||||
__HAL_RTC_ALARM_CLEAR_FLAG(&rtc_handler, RTC_FLAG_ALRAF);
|
||||
|
||||
#if 0
|
||||
if (HAL_RTCEx_DeactivateWakeUpTimer(&rtc_handler) != HAL_OK) {
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
HAL_NVIC_DisableIRQ(RTC_Alarm_IRQn);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
static k_time_t tickless_rtc_alarmirq_wkup_alarm_max_delay(void)
|
||||
{
|
||||
return 0xFFFF; // just kidding, I will fix it out. Welcome to tell me, 3ks~ */
|
||||
}
|
||||
|
||||
void RTC_Alarm_IRQHandler(void)
|
||||
{
|
||||
HAL_RTC_AlarmIRQHandler(&rtc_handler);
|
||||
}
|
||||
|
||||
void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *rtc_handler)
|
||||
{
|
||||
}
|
||||
|
||||
k_tickless_wkup_alarm_t tickless_wkup_alarm_rtc_alarmirq = {
|
||||
.init = tickless_rtc_wkup_alarm_init,
|
||||
.setup = tickless_rtc_alarmirq_wkup_alarm_setup,
|
||||
.dismiss = tickless_rtc_alarmirq_wkup_alarm_dismiss,
|
||||
.max_delay = tickless_rtc_alarmirq_wkup_alarm_max_delay,
|
||||
};
|
||||
|
||||
#endif
|
||||
|
43
board/GD32F310G_START/BSP/Src/usart.c
Normal file
43
board/GD32F310G_START/BSP/Src/usart.c
Normal file
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* File Name : USART.c
|
||||
* Description : This file provides code for the configuration
|
||||
* of the USART instances.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2019 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under BSD 3-Clause license,
|
||||
* the "License"; You may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at:
|
||||
* opensource.org/licenses/BSD-3-Clause
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usart.h"
|
||||
|
||||
/**
|
||||
* @brief 板级 usart 硬件初始化
|
||||
* @param void:
|
||||
* retval N/A.
|
||||
*/
|
||||
int board_usart_init(void)
|
||||
{
|
||||
rcu_periph_clock_enable(RCU_USART0);
|
||||
usart_deinit(RCU_USART0);
|
||||
usart_baudrate_set(USART0, 115200);
|
||||
usart_stop_bit_set(USART0, USART_STB_1BIT);
|
||||
usart_word_length_set(USART0, USART_WL_8BIT);
|
||||
usart_parity_config(USART0, USART_PM_NONE);
|
||||
usart_transmit_config(USART0, USART_TRANSMIT_ENABLE);
|
||||
usart_receive_config(USART0, USART_RECEIVE_ENABLE);
|
||||
usart_interrupt_enable(USART0, USART_INT_RBNE);
|
||||
usart_enable(USART0);
|
||||
nvic_irq_enable(USART0_IRQn, 0, 0);
|
||||
|
||||
return 0;
|
||||
}
|
226
board/GD32F310G_START/GCC/hello_world/Makefile
Normal file
226
board/GD32F310G_START/GCC/hello_world/Makefile
Normal file
@@ -0,0 +1,226 @@
|
||||
##########################################################################################################################
|
||||
# File automatically-generated by tool: [projectgenerator] version: [3.3.0] date: [Mon Aug 05 10:29:11 CST 2019]
|
||||
##########################################################################################################################
|
||||
|
||||
# ------------------------------------------------
|
||||
# Generic Makefile (based on gcc)
|
||||
#
|
||||
# ChangeLog :
|
||||
# 2022-04-13 - Port to GD32F310-START
|
||||
# 2017-02-10 - Several enhancements + project update mode
|
||||
# 2015-07-22 - first version
|
||||
# ------------------------------------------------
|
||||
|
||||
######################################
|
||||
# target
|
||||
######################################
|
||||
TARGET = TencentOS_tiny
|
||||
|
||||
|
||||
######################################
|
||||
# building variables
|
||||
######################################
|
||||
# debug build?
|
||||
DEBUG = 1
|
||||
# optimization
|
||||
OPT = -O2
|
||||
|
||||
TOP_DIR = ../../../..
|
||||
#######################################
|
||||
# paths
|
||||
#######################################
|
||||
# Build path
|
||||
BUILD_DIR = build
|
||||
|
||||
######################################
|
||||
# source
|
||||
######################################
|
||||
# C sources
|
||||
KERNEL_SRC = \
|
||||
${wildcard $(TOP_DIR)/kernel/core/*.c}
|
||||
C_SOURCES += $(KERNEL_SRC)
|
||||
|
||||
ARCH_SRC = \
|
||||
${wildcard $(TOP_DIR)/arch/arm/arm-v7m/cortex-m4/gcc/*.c} \
|
||||
${wildcard $(TOP_DIR)/arch/arm/arm-v7m/common/*.c}
|
||||
C_SOURCES += $(ARCH_SRC)
|
||||
|
||||
HAL_DRIVER_SRC = \
|
||||
$(TOP_DIR)/board/GD32F310G_START/BSP/Src/main.c \
|
||||
$(TOP_DIR)/board/GD32F310G_START/BSP/Src/mcu_init.c \
|
||||
$(TOP_DIR)/board/GD32F310G_START/BSP/Src/gd32f3x0_it.c \
|
||||
$(TOP_DIR)/board/GD32F310G_START/BSP/Src/gpio.c \
|
||||
$(TOP_DIR)/board/GD32F310G_START/BSP/Src/usart.c \
|
||||
$(TOP_DIR)/platform/vendor_bsp/gd/GD32F3x0_Firmware_Library/CMSIS/GD/GD32F3x0/Source/system_gd32f3x0.c \
|
||||
$(TOP_DIR)/platform/vendor_bsp/gd/GD32F3x0_Firmware_Library/GD32F3x0_standard_peripheral/Source/gd32f3x0_dbg.c \
|
||||
$(TOP_DIR)/platform/vendor_bsp/gd/GD32F3x0_Firmware_Library/GD32F3x0_standard_peripheral/Source/gd32f3x0_dma.c \
|
||||
$(TOP_DIR)/platform/vendor_bsp/gd/GD32F3x0_Firmware_Library/GD32F3x0_standard_peripheral/Source/gd32f3x0_exti.c \
|
||||
$(TOP_DIR)/platform/vendor_bsp/gd/GD32F3x0_Firmware_Library/GD32F3x0_standard_peripheral/Source/gd32f3x0_fmc.c \
|
||||
$(TOP_DIR)/platform/vendor_bsp/gd/GD32F3x0_Firmware_Library/GD32F3x0_standard_peripheral/Source/gd32f3x0_gpio.c \
|
||||
$(TOP_DIR)/platform/vendor_bsp/gd/GD32F3x0_Firmware_Library/GD32F3x0_standard_peripheral/Source/gd32f3x0_misc.c \
|
||||
$(TOP_DIR)/platform/vendor_bsp/gd/GD32F3x0_Firmware_Library/GD32F3x0_standard_peripheral/Source/gd32f3x0_pmu.c \
|
||||
$(TOP_DIR)/platform/vendor_bsp/gd/GD32F3x0_Firmware_Library/GD32F3x0_standard_peripheral/Source/gd32f3x0_rcu.c \
|
||||
$(TOP_DIR)/platform/vendor_bsp/gd/GD32F3x0_Firmware_Library/GD32F3x0_standard_peripheral/Source/gd32f3x0_syscfg.c \
|
||||
$(TOP_DIR)/platform/vendor_bsp/gd/GD32F3x0_Firmware_Library/GD32F3x0_standard_peripheral/Source/gd32f3x0_timer.c \
|
||||
$(TOP_DIR)/platform/vendor_bsp/gd/GD32F3x0_Firmware_Library/GD32F3x0_standard_peripheral/Source/gd32f3x0_usart.c
|
||||
C_SOURCES += $(HAL_DRIVER_SRC)
|
||||
|
||||
# ASM sources
|
||||
ASM_SOURCES = \
|
||||
$(TOP_DIR)/platform/vendor_bsp/gd/GD32F3x0_Firmware_Library/CMSIS/GD/GD32F3x0/Source/GCC/startup_gd32f3x0.s
|
||||
|
||||
ASM_SOURCES_S = \
|
||||
$(TOP_DIR)/arch/arm/arm-v7m/cortex-m4/gcc/port_s.S
|
||||
|
||||
COMPONENTS_SRC = \
|
||||
$(TOP_DIR)/components/shell/tos_shell.c \
|
||||
$(TOP_DIR)/components/shell/tos_shell_commands.c
|
||||
C_SOURCES += $(COMPONENTS_SRC)
|
||||
|
||||
#######################################
|
||||
# binaries
|
||||
#######################################
|
||||
PREFIX = arm-none-eabi-
|
||||
# The gcc compiler bin path can be either defined in make command via GCC_PATH variable (> make GCC_PATH=xxx)
|
||||
# either it can be added to the PATH environment variable.
|
||||
ifdef GCC_PATH
|
||||
CC = $(GCC_PATH)/$(PREFIX)gcc
|
||||
AS = $(GCC_PATH)/$(PREFIX)gcc -x assembler-with-cpp
|
||||
CP = $(GCC_PATH)/$(PREFIX)objcopy
|
||||
SZ = $(GCC_PATH)/$(PREFIX)size
|
||||
else
|
||||
CC = $(PREFIX)gcc
|
||||
AS = $(PREFIX)gcc -x assembler-with-cpp
|
||||
CP = $(PREFIX)objcopy
|
||||
SZ = $(PREFIX)size
|
||||
endif
|
||||
HEX = $(CP) -O ihex
|
||||
BIN = $(CP) -O binary -S
|
||||
|
||||
#######################################
|
||||
# CFLAGS
|
||||
#######################################
|
||||
# cpu
|
||||
CPU = -mcpu=cortex-m4
|
||||
|
||||
# fpu
|
||||
FPU = -mfpu=fpv4-sp-d16
|
||||
|
||||
# float-abi
|
||||
FLOAT-ABI = -mfloat-abi=hard
|
||||
|
||||
# mcu
|
||||
MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI)
|
||||
|
||||
# macros for gcc
|
||||
# AS defines
|
||||
AS_DEFS =
|
||||
|
||||
# C defines
|
||||
C_DEFS = \
|
||||
-DGD32F310
|
||||
|
||||
# AS includes
|
||||
AS_INCLUDES =
|
||||
|
||||
# C includes
|
||||
KERNEL_INC = \
|
||||
-I $(TOP_DIR)/kernel/core/include \
|
||||
-I $(TOP_DIR)/kernel/pm/include \
|
||||
-I $(TOP_DIR)/kernel/hal/include \
|
||||
-I $(TOP_DIR)/arch/arm/arm-v7m/common/include \
|
||||
-I $(TOP_DIR)/arch/arm/arm-v7m/cortex-m4/gcc \
|
||||
-I $(TOP_DIR)/board/GD32F310G_START/TOS-CONFIG
|
||||
C_INCLUDES += $(KERNEL_INC)
|
||||
|
||||
CMSIS_INC = \
|
||||
-I $(TOP_DIR)/osal/cmsis_os \
|
||||
-I $(TOP_DIR)/platform/vendor_bsp/gd/GD32F3x0_Firmware_Library/CMSIS
|
||||
C_INCLUDES += $(CMSIS_INC)
|
||||
|
||||
HAL_DRIVER_INC = \
|
||||
-I $(TOP_DIR)/board/GD32F310G_START/BSP/Inc \
|
||||
-I $(TOP_DIR)/platform/vendor_bsp/gd/GD32F3x0_Firmware_Library/CMSIS/GD/GD32F3x0/Include \
|
||||
-I $(TOP_DIR)/platform/vendor_bsp/gd/GD32F3x0_Firmware_Library/GD32F3x0_standard_peripheral/Include
|
||||
C_INCLUDES += $(HAL_DRIVER_INC)
|
||||
|
||||
COMPONENTS_INC = \
|
||||
-I $(TOP_DIR)/components/shell/include
|
||||
C_INCLUDES += $(COMPONENTS_INC)
|
||||
|
||||
# compile gcc flags
|
||||
ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
|
||||
|
||||
CFLAGS = $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
|
||||
|
||||
ifeq ($(DEBUG), 1)
|
||||
CFLAGS += -g -gdwarf-2
|
||||
endif
|
||||
|
||||
|
||||
# Generate dependency information
|
||||
CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)"
|
||||
|
||||
|
||||
#######################################
|
||||
# LDFLAGS
|
||||
#######################################
|
||||
# link script
|
||||
LDSCRIPT = gd32f310_flash.ld
|
||||
|
||||
# libraries
|
||||
LIBS = -lc -lm -lnosys
|
||||
LIBDIR =
|
||||
LDFLAGS = $(MCU) -specs=nano.specs -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections
|
||||
|
||||
# default action: build all
|
||||
all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin
|
||||
|
||||
|
||||
#######################################
|
||||
# build the application
|
||||
#######################################
|
||||
# list of objects
|
||||
OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o)))
|
||||
vpath %.c $(sort $(dir $(C_SOURCES)))
|
||||
# list of ASM program objects
|
||||
OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_SOURCES:.s=.o)))
|
||||
vpath %.s $(sort $(dir $(ASM_SOURCES)))
|
||||
OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_SOURCES_S:.S=.o)))
|
||||
vpath %.S $(sort $(dir $(ASM_SOURCES_S)))
|
||||
|
||||
$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR)
|
||||
$(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@
|
||||
|
||||
$(BUILD_DIR)/%.o: %.s Makefile | $(BUILD_DIR)
|
||||
$(AS) -c $(CFLAGS) $< -o $@
|
||||
|
||||
$(BUILD_DIR)/%.o: %.S Makefile | $(BUILD_DIR)
|
||||
$(AS) -c $(CFLAGS) $< -o $@
|
||||
|
||||
$(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile
|
||||
$(CC) $(OBJECTS) $(LDFLAGS) -o $@
|
||||
$(SZ) $@
|
||||
|
||||
$(BUILD_DIR)/%.hex: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
|
||||
$(HEX) $< $@
|
||||
|
||||
$(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
|
||||
$(BIN) $< $@
|
||||
@cp $@ ./$(notdir $@)
|
||||
|
||||
$(BUILD_DIR):
|
||||
mkdir $@
|
||||
|
||||
#######################################
|
||||
# clean up
|
||||
#######################################
|
||||
clean:
|
||||
-rm -fR $(BUILD_DIR)
|
||||
|
||||
#######################################
|
||||
# dependencies
|
||||
#######################################
|
||||
-include $(wildcard $(BUILD_DIR)/*.d)
|
||||
|
||||
# *** EOF ***
|
156
board/GD32F310G_START/GCC/hello_world/gd32f310_flash.ld
Normal file
156
board/GD32F310G_START/GCC/hello_world/gd32f310_flash.ld
Normal file
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
* linker script for GD32F3x0 with GNU ld
|
||||
* bernard.xiong 2009-10-14
|
||||
* iysheng 2022-04-14
|
||||
*/
|
||||
|
||||
/* Program Entry, set to mark it as "used" and avoid gc */
|
||||
ENTRY(Reset_Handler)
|
||||
FLASH_SIZE = 0x10000;
|
||||
SRAM_SIZE = 0x2000;
|
||||
HEAP_SIZE = 0x800;
|
||||
STACK_SIZE = 0x200;
|
||||
|
||||
MEMORY
|
||||
{
|
||||
CODE (rx) : ORIGIN = 0x08000000, LENGTH = FLASH_SIZE
|
||||
DATA (rw) : ORIGIN = 0x20000000, LENGTH = SRAM_SIZE
|
||||
HEAP (rw) : ORIGIN = 0x20000000 + SRAM_SIZE - HEAP_SIZE, LENGTH = HEAP_SIZE
|
||||
}
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
.text :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
_stext = .;
|
||||
KEEP(*(.isr_vector)) /* Startup code */
|
||||
. = ALIGN(4);
|
||||
*(.text) /* remaining code */
|
||||
*(.text.*) /* remaining code */
|
||||
*(.rodata) /* read-only data (constants) */
|
||||
*(.rodata*)
|
||||
*(.glue_7)
|
||||
*(.glue_7t)
|
||||
*(.gnu.linkonce.t*)
|
||||
|
||||
/* section information for finsh shell */
|
||||
. = ALIGN(4);
|
||||
__fsymtab_start = .;
|
||||
KEEP(*(FSymTab))
|
||||
__fsymtab_end = .;
|
||||
. = ALIGN(4);
|
||||
__vsymtab_start = .;
|
||||
KEEP(*(VSymTab))
|
||||
__vsymtab_end = .;
|
||||
. = ALIGN(4);
|
||||
|
||||
/* section information for initial. */
|
||||
. = ALIGN(4);
|
||||
__rt_init_start = .;
|
||||
KEEP(*(SORT(.rti_fn*)))
|
||||
__rt_init_end = .;
|
||||
. = ALIGN(4);
|
||||
|
||||
. = ALIGN(4);
|
||||
_etext = .;
|
||||
} > CODE = 0
|
||||
|
||||
/* .ARM.exidx is sorted, so has to go in its own output section. */
|
||||
__exidx_start = .;
|
||||
.ARM.exidx :
|
||||
{
|
||||
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
|
||||
|
||||
/* This is used by the startup in order to initialize the .data secion */
|
||||
_sidata = .;
|
||||
} > CODE
|
||||
__exidx_end = .;
|
||||
|
||||
/* .data section which is used for initialized data */
|
||||
|
||||
.data : AT (_sidata)
|
||||
{
|
||||
. = ALIGN(4);
|
||||
/* This is used by the startup in order to initialize the .data secion */
|
||||
_sdata = . ;
|
||||
|
||||
*(.data)
|
||||
*(.data.*)
|
||||
*(.gnu.linkonce.d*)
|
||||
|
||||
. = ALIGN(4);
|
||||
/* This is used by the startup in order to initialize the .data secion */
|
||||
_edata = . ;
|
||||
} >DATA
|
||||
|
||||
.stack :
|
||||
{
|
||||
. = . + STACK_SIZE;
|
||||
. = ALIGN(4);
|
||||
_estack = .;
|
||||
} >DATA
|
||||
|
||||
__bss_start = .;
|
||||
.bss :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
/* This is used by the startup in order to initialize the .bss secion */
|
||||
_sbss = .;
|
||||
|
||||
*(.bss)
|
||||
*(.bss.*)
|
||||
*(COMMON)
|
||||
|
||||
. = ALIGN(4);
|
||||
/* This is used by the startup in order to initialize the .bss secion */
|
||||
_ebss = . ;
|
||||
*(.bss.init)
|
||||
} > DATA
|
||||
__bss_end = .;
|
||||
|
||||
.heap : {
|
||||
__heap_start__ = .;
|
||||
end = __heap_start__;
|
||||
_end = end;
|
||||
__end = end;
|
||||
. = . + HEAP_SIZE;
|
||||
/* . = . + Min_Heap_Size; */
|
||||
__heap_end__ = .;
|
||||
__HeapLimit = __heap_end__;
|
||||
} > HEAP
|
||||
|
||||
/* Stabs debugging sections. */
|
||||
.stab 0 : { *(.stab) }
|
||||
.stabstr 0 : { *(.stabstr) }
|
||||
.stab.excl 0 : { *(.stab.excl) }
|
||||
.stab.exclstr 0 : { *(.stab.exclstr) }
|
||||
.stab.index 0 : { *(.stab.index) }
|
||||
.stab.indexstr 0 : { *(.stab.indexstr) }
|
||||
.comment 0 : { *(.comment) }
|
||||
/* DWARF debug sections.
|
||||
* Symbols in the DWARF debugging sections are relative to the beginning
|
||||
* of the section so we begin them at 0. */
|
||||
/* DWARF 1 */
|
||||
.debug 0 : { *(.debug) }
|
||||
.line 0 : { *(.line) }
|
||||
/* GNU DWARF 1 extensions */
|
||||
.debug_srcinfo 0 : { *(.debug_srcinfo) }
|
||||
.debug_sfnames 0 : { *(.debug_sfnames) }
|
||||
/* DWARF 1.1 and DWARF 2 */
|
||||
.debug_aranges 0 : { *(.debug_aranges) }
|
||||
.debug_pubnames 0 : { *(.debug_pubnames) }
|
||||
/* DWARF 2 */
|
||||
.debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
|
||||
.debug_abbrev 0 : { *(.debug_abbrev) }
|
||||
.debug_line 0 : { *(.debug_line) }
|
||||
.debug_frame 0 : { *(.debug_frame) }
|
||||
.debug_str 0 : { *(.debug_str) }
|
||||
.debug_loc 0 : { *(.debug_loc) }
|
||||
.debug_macinfo 0 : { *(.debug_macinfo) }
|
||||
/* SGI/MIPS DWARF 2 extensions */
|
||||
.debug_weaknames 0 : { *(.debug_weaknames) }
|
||||
.debug_funcnames 0 : { *(.debug_funcnames) }
|
||||
.debug_typenames 0 : { *(.debug_typenames) }
|
||||
.debug_varnames 0 : { *(.debug_varnames) }
|
||||
}
|
41
board/GD32F310G_START/TOS-CONFIG/tickless/tos_config.h
Normal file
41
board/GD32F310G_START/TOS-CONFIG/tickless/tos_config.h
Normal file
@@ -0,0 +1,41 @@
|
||||
#ifndef _TOS_CONFIG_H_
|
||||
#define _TOS_CONFIG_H_
|
||||
|
||||
#include "stm32l4xx.h"
|
||||
|
||||
#define TOS_CFG_TASK_PRIO_MAX 10u
|
||||
|
||||
#define TOS_CFG_ROUND_ROBIN_EN 1u
|
||||
|
||||
#define TOS_CFG_OBJECT_VERIFY_EN 1u
|
||||
|
||||
#define TOS_CFG_TASK_DYNAMIC_CREATE_EN 0u
|
||||
|
||||
#define TOS_CFG_EVENT_EN 1u
|
||||
|
||||
#define TOS_CFG_MMBLK_EN 1u
|
||||
|
||||
#define TOS_CFG_MMHEAP_EN 1u
|
||||
|
||||
#define TOS_CFG_MMHEAP_DEFAULT_POOL_SIZE 0x6000
|
||||
|
||||
#define TOS_CFG_MUTEX_EN 1u
|
||||
|
||||
#define TOS_CFG_TIMER_EN 1u
|
||||
|
||||
#define TOS_CFG_PWR_MGR_EN 1u
|
||||
|
||||
#define TOS_CFG_TICKLESS_EN 1u
|
||||
|
||||
#define TOS_CFG_SEM_EN 1u
|
||||
|
||||
#define TOS_CFG_IDLE_TASK_STK_SIZE 512u
|
||||
|
||||
#define TOS_CFG_CPU_TICK_PER_SECOND 1000u
|
||||
|
||||
#define TOS_CFG_CPU_CLOCK (SystemCoreClock)
|
||||
|
||||
#define TOS_CFG_TIMER_AS_PROC 1u
|
||||
|
||||
#endif
|
||||
|
47
board/GD32F310G_START/TOS-CONFIG/tos_config.h
Normal file
47
board/GD32F310G_START/TOS-CONFIG/tos_config.h
Normal file
@@ -0,0 +1,47 @@
|
||||
#ifndef _TOS_CONFIG_H_
|
||||
#define _TOS_CONFIG_H_
|
||||
|
||||
#include "gd32f3x0.h"
|
||||
|
||||
#define TOS_CFG_TASK_PRIO_MAX 10u
|
||||
|
||||
#define TOS_CFG_ROUND_ROBIN_EN 1u
|
||||
|
||||
#define TOS_CFG_OBJECT_VERIFY_EN 1u
|
||||
|
||||
#define TOS_CFG_TASK_DYNAMIC_CREATE_EN 0u
|
||||
|
||||
#define TOS_CFG_EVENT_EN 1u
|
||||
|
||||
#define TOS_CFG_MMBLK_EN 1u
|
||||
|
||||
#define TOS_CFG_MMHEAP_EN 0u
|
||||
|
||||
#define TOS_CFG_MMHEAP_DEFAULT_POOL_SIZE 0x400
|
||||
|
||||
#define TOS_CFG_MUTEX_EN 1u
|
||||
|
||||
#define TOS_CFG_TIMER_EN 1u
|
||||
|
||||
#define TOS_CFG_PWR_MGR_EN 0u
|
||||
|
||||
#define TOS_CFG_TICKLESS_EN 0u
|
||||
|
||||
#define TOS_CFG_SEM_EN 1u
|
||||
|
||||
#define TOS_CFG_TASK_STACK_DRAUGHT_DEPTH_DETACT_EN 1u
|
||||
|
||||
#define TOS_CFG_FAULT_BACKTRACE_EN 0u
|
||||
|
||||
#define TOS_CFG_IDLE_TASK_STK_SIZE 128u
|
||||
|
||||
#define TOS_CFG_CPU_TICK_PER_SECOND 1000u
|
||||
|
||||
#define TOS_CFG_CPU_CLOCK (SystemCoreClock)
|
||||
|
||||
#define TOS_CFG_TIMER_AS_PROC 1u
|
||||
|
||||
#define TOS_CFG_MAIL_QUEUE_EN 1u
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user