initial commit

This commit is contained in:
bmy
2024-04-25 22:31:01 +08:00
commit 200b5703f9
119 changed files with 52620 additions and 0 deletions

150
project/inc/at32f413_conf.h Normal file
View File

@@ -0,0 +1,150 @@
/**
**************************************************************************
* @file at32f413_conf.h
* @brief at32f413 config header file
**************************************************************************
* Copyright notice & Disclaimer
*
* The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the
* software is governed by this copyright notice and the following disclaimer.
*
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
* GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
* TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
* STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
*
**************************************************************************
*/
/* define to prevent recursive inclusion -------------------------------------*/
#ifndef __AT32F413_CONF_H
#define __AT32F413_CONF_H
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief in the following line adjust the value of high speed exernal crystal (hext)
* used in your application
*
* tip: to avoid modifying this file each time you need to use different hext, you
* can define the hext value in your toolchain compiler preprocessor.
*
*/
#if !defined HEXT_VALUE
#define HEXT_VALUE ((uint32_t)8000000) /*!< value of the high speed exernal crystal in hz */
#endif
/**
* @brief in the following line adjust the high speed exernal crystal (hext) startup
* timeout value
*/
#define HEXT_STARTUP_TIMEOUT ((uint16_t)0x3000) /*!< time out for hext start up */
#define HICK_VALUE ((uint32_t)8000000) /*!< value of the high speed internal clock in hz */
#define LEXT_VALUE ((uint32_t)32768) /*!< value of the low speed exernal clock in hz */
/* module define -------------------------------------------------------------*/
/*#define ACC_MODULE_ENABLED----------------------*/
/*#define ADC_MODULE_ENABLED----------------------*/
/*#define BPR_MODULE_ENABLED----------------------*/
#define CAN_MODULE_ENABLED
/*#define CRC_MODULE_ENABLED----------------------*/
#define CRM_MODULE_ENABLED
#define DEBUG_MODULE_ENABLED
/*#define DMA_MODULE_ENABLED----------------------*/
#define EXINT_MODULE_ENABLED
#define FLASH_MODULE_ENABLED
#define GPIO_MODULE_ENABLED
/*#define I2C_MODULE_ENABLED----------------------*/
#define MISC_MODULE_ENABLED
#define PWC_MODULE_ENABLED
/*#define RTC_MODULE_ENABLED----------------------*/
/*#define SDIO_MODULE_ENABLED---------------------*/
/*#define SPI_MODULE_ENABLED----------------------*/
#define TMR_MODULE_ENABLED
#define USART_MODULE_ENABLED
/*#define USB_MODULE_ENABLED----------------------*/
/*#define WDT_MODULE_ENABLED----------------------*/
/*#define WWDT_MODULE_ENABLED---------------------*/
/* includes ------------------------------------------------------------------*/
#ifdef ACC_MODULE_ENABLED
#include "at32f413_acc.h"
#endif
#ifdef ADC_MODULE_ENABLED
#include "at32f413_adc.h"
#endif
#ifdef BPR_MODULE_ENABLED
#include "at32f413_bpr.h"
#endif
#ifdef CAN_MODULE_ENABLED
#include "at32f413_can.h"
#endif
#ifdef CRC_MODULE_ENABLED
#include "at32f413_crc.h"
#endif
#ifdef CRM_MODULE_ENABLED
#include "at32f413_crm.h"
#endif
#ifdef DEBUG_MODULE_ENABLED
#include "at32f413_debug.h"
#endif
#ifdef DMA_MODULE_ENABLED
#include "at32f413_dma.h"
#endif
#ifdef EXINT_MODULE_ENABLED
#include "at32f413_exint.h"
#endif
#ifdef FLASH_MODULE_ENABLED
#include "at32f413_flash.h"
#endif
#ifdef GPIO_MODULE_ENABLED
#include "at32f413_gpio.h"
#endif
#ifdef I2C_MODULE_ENABLED
#include "at32f413_i2c.h"
#endif
#ifdef MISC_MODULE_ENABLED
#include "at32f413_misc.h"
#endif
#ifdef PWC_MODULE_ENABLED
#include "at32f413_pwc.h"
#endif
#ifdef RTC_MODULE_ENABLED
#include "at32f413_rtc.h"
#include "rtc.h"
#endif
#ifdef SDIO_MODULE_ENABLED
#include "at32f413_sdio.h"
#endif
#ifdef SPI_MODULE_ENABLED
#include "at32f413_spi.h"
#endif
#ifdef TMR_MODULE_ENABLED
#include "at32f413_tmr.h"
#endif
#ifdef USART_MODULE_ENABLED
#include "at32f413_usart.h"
#endif
#ifdef USB_MODULE_ENABLED
#include "at32f413_usb.h"
#endif
#ifdef WDT_MODULE_ENABLED
#include "at32f413_wdt.h"
#endif
#ifdef WWDT_MODULE_ENABLED
#include "at32f413_wwdt.h"
#endif
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,76 @@
/* add user code begin Header */
/**
**************************************************************************
* @file at32f413_int.h
* @brief header file of main interrupt service routines.
**************************************************************************
* Copyright notice & Disclaimer
*
* The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the
* software is governed by this copyright notice and the following disclaimer.
*
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
* GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
* TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
* STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
*
**************************************************************************
*/
/* add user code end Header */
/* define to prevent recursive inclusion -------------------------------------*/
#ifndef __AT32F413_INT_H
#define __AT32F413_INT_H
#ifdef __cplusplus
extern "C" {
#endif
/* includes ------------------------------------------------------------------*/
#include "at32f413.h"
/* private includes ----------------------------------------------------------*/
/* add user code begin private includes */
/* add user code end private includes */
/* exported types ------------------------------------------------------------*/
/* add user code begin exported types */
/* add user code end exported types */
/* exported constants --------------------------------------------------------*/
/* add user code begin exported constants */
/* add user code end exported constants */
/* exported macro ------------------------------------------------------------*/
/* add user code begin exported macro */
/* add user code end exported macro */
/* exported functions ------------------------------------------------------- */
void NMI_Handler(void);
void HardFault_Handler(void);
void MemManage_Handler(void);
void BusFault_Handler(void);
void UsageFault_Handler(void);
void SVC_Handler(void);
void DebugMon_Handler(void);
void PendSV_Handler(void);
/* add user code begin exported functions */
/* add user code end exported functions */
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,121 @@
/* add user code begin Header */
/**
**************************************************************************
* @file at32f413_wk_config.h
* @brief header file of work bench config
**************************************************************************
* Copyright notice & Disclaimer
*
* The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the
* software is governed by this copyright notice and the following disclaimer.
*
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
* GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
* TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
* STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
*
**************************************************************************
*/
/* add user code end Header */
/* define to prevent recursive inclusion -----------------------------------*/
#ifndef __AT32F413_WK_CONFIG_H
#define __AT32F413_WK_CONFIG_H
#ifdef __cplusplus
extern "C" {
#endif
/* includes -----------------------------------------------------------------------*/
#include "at32f413.h"
/* private includes -------------------------------------------------------------*/
/* add user code begin private includes */
/* add user code end private includes */
/* exported types -------------------------------------------------------------*/
/* add user code begin exported types */
/* add user code end exported types */
/* exported constants --------------------------------------------------------*/
/* add user code begin exported constants */
/* add user code end exported constants */
/* exported macro ------------------------------------------------------------*/
/* add user code begin exported macro */
/* add user code end exported macro */
/* Private defines -------------------------------------------------------------*/
#define SW_IN2_PIN GPIO_PINS_10
#define SW_IN2_GPIO_PORT GPIOB
#define SW_IN1_PIN GPIO_PINS_11
#define SW_IN1_GPIO_PORT GPIOB
#define MODE2_PIN GPIO_PINS_12
#define MODE2_GPIO_PORT GPIOB
#define MODE1_PIN GPIO_PINS_13
#define MODE1_GPIO_PORT GPIOB
#define MODE0_PIN GPIO_PINS_14
#define MODE0_GPIO_PORT GPIOB
#define STEP_PIN GPIO_PINS_15
#define STEP_GPIO_PORT GPIOB
#define DIR_PIN GPIO_PINS_8
#define DIR_GPIO_PORT GPIOA
#define EN_PIN GPIO_PINS_9
#define EN_GPIO_PORT GPIOA
/* exported functions ------------------------------------------------------- */
/* system clock config. */
void wk_system_clock_config(void);
/* config periph clock. */
void wk_periph_clock_config(void);
/* init debug function. */
void wk_debug_config(void);
/* nvic config. */
void wk_nvic_config(void);
/* init gpio function. */
void wk_gpio_config(void);
/* init exint function. */
void wk_exint_config(void);
/* init can1 function. */
void wk_can1_init(void);
/* init usart2 function. */
void wk_usart2_init(void);
/* init tmr1 function. */
void wk_tmr1_init(void);
/* init tmr3 function. */
void wk_tmr3_init(void);
/* init tmr9 function. */
void wk_tmr9_init(void);
/* init tmr10 function. */
void wk_tmr10_init(void);
/* add user code begin exported functions */
/* add user code end exported functions */
#ifdef __cplusplus
}
#endif
#endif

31
project/inc/by_debug.h Normal file
View File

@@ -0,0 +1,31 @@
#ifndef _BY_DEBUG_H__
#define _BY_DEBUG_H__
#include <stdio.h>
#include "at32f413.h"
#include "lwprintf.h"
#define BY_DEBUG_USART_INDEX (USART2)
#define BY_DEBUG_LOG_MODE (2) // 0-not log, 1-no debug log, 2-all
#if (BY_DEBUG_LOG_MODE == 2)
#define LOGI(format, ...) lwprintf("[INFO] " format "\r\n", ##__VA_ARGS__)
#define LOGW(format, ...) lwprintf("[WARN] " format "\r\n", ##__VA_ARGS__)
#define LOGE(format, ...) lwprintf("[ERR] " format "\r\n", ##__VA_ARGS__)
#define LOGD(format, ...) lwprintf("[DEBUG] " format "\r\n", ##__VA_ARGS__)
#elif (BY_DEBUG_LOG_MODE == 1)
#define LOGI(format, ...) lwprintf("[INFO] " format "\r\n", ##__VA_ARGS__)
#define LOGW(format, ...) lwprintf("[WARN] " format "\r\n", ##__VA_ARGS__)
#define LOGE(format, ...) lwprintf("[ERR] " format "\r\n", ##__VA_ARGS__)
#define LOGD(format, ...)
#elif (BY_DEBUG_LOG_MODE == 0)
#define LOGI(format, ...)
#define LOGW(format, ...)
#define LOGE(format, ...)
#define LOGD(format, ...)
#endif
extern void by_debug_init(void);
#endif

80
project/inc/eeprom.h Normal file
View File

@@ -0,0 +1,80 @@
/**
**************************************************************************
* @file eeprom.h
* @version v2.0.0
* @date 2020-11-02
* @brief flash eeprom libray header file
**************************************************************************
* Copyright notice & Disclaimer
*
* The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the
* software is governed by this copyright notice and the following disclaimer.
*
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
* GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
* TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
* STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
*
**************************************************************************
*/
/*!< define to prevent recursive inclusion -------------------------------------*/
#ifndef __EEPROM_H
#define __EEPROM_H
#ifdef __cplusplus
extern "C" {
#endif
/* includes ------------------------------------------------------------------*/
#include "at32f413.h"
/*
+-----------------------------------------------------+
| EEPROM |
+--------------------------+--------------------------+
| PAGE 0 | PAGE 1 |
+--------+--------+--------+--------+--------+--------+
| | | | | | |
| sector | sector | sector | sector | sector | sector |
| 0 | ... | N | N + 1 | ... | N + N |
| | | | | | |
+--------+--------+--------+--------+--------+--------+
*/
/*!< user defined */
#define EE_SECTOR_NUM ((uint32_t)1) /*!< sector number, support multiple sectors to from 1 page */
#define EE_SECTOR_SIZE ((uint32_t)(1024 * 2)) /*!< sector size */
/*!< user do not need to care */
#define EE_FLASH_SIZE (*(uint16_t *)0x1FFFF7E0) /*!< at32 flash size information */
#define EE_PAGE_SIZE ((uint32_t)(EE_SECTOR_NUM * EE_SECTOR_SIZE)) /*!< page size */
#define EE_BASE_ADDRESS ((uint32_t)(0x08000000 + 1024 * EE_FLASH_SIZE - EE_PAGE_SIZE * 2)) /*!< eeprom base address */
#define EE_PAGE0_ADDRESS ((uint32_t)(EE_BASE_ADDRESS)) /*!< eeprom page 0 base address */
#define EE_PAGE1_ADDRESS ((uint32_t)(EE_PAGE0_ADDRESS + EE_PAGE_SIZE)) /*!< eeprom page 1 base address */
#define EE_PARA_MAX_NUMBER ((uint16_t)(EE_PAGE_SIZE / 4 - 1)) /*!< maximum number of variables that can be stored */
flash_status_type flash_ee_init (void);
uint16_t flash_ee_data_read (uint16_t address, uint16_t* pdata);
flash_status_type flash_ee_data_write (uint16_t address, uint16_t data);
#ifdef __cplusplus
}
#endif
#endif