提交 563d11f8 编写于 作者: Z ze9hyr

警告消除及代码格式化

修改文件头信息

修改ACM32F030 BSP的文件格式

新增BSP驱动中的lib文件

IAR和GCC支持备份

1. 修复不能包含HAL_EFLASH.h问题, 2. 消除GCC编译的几个警告

1. gcc启动文件重命名;2. 文件头信息修改; 3. 硬件timer支持修改

移动 .ignore_format.yml到bsp的目录下

修改目录成相对目录
上级 f0ab92a8
......@@ -29,6 +29,7 @@ jobs:
fail-fast: false
matrix:
legs:
- {RTT_BSP: "acm32f0x0-nucleo", RTT_TOOL_CHAIN: "sourcery-arm"}
- {RTT_BSP: "CME_M7", RTT_TOOL_CHAIN: "sourcery-arm"}
- {RTT_BSP: "apollo2", RTT_TOOL_CHAIN: "sourcery-arm"}
- {RTT_BSP: "asm9260t", RTT_TOOL_CHAIN: "sourcery-arm"}
......
......@@ -12,3 +12,14 @@ dir_path:
- components/net/lwip-2.0.3
- components/net/lwip-2.1.2
- bsp/mm32f327x/Libraries
- bsp/fm33lc026/libraries
- bsp/stm32/libraries/STM32F0xx_HAL
- bsp/stm32/libraries/STM32F2xx_HAL
- bsp/stm32/libraries/STM32F4xx_HAL
- bsp/stm32/libraries/STM32F7xx_HAL
- bsp/stm32/libraries/STM32G0xx_HAL
- bsp/stm32/libraries/STM32G4xx_HAL
- bsp/stm32/libraries/STM32L4xx_HAL
- bsp/stm32/libraries/STM32MPxx_HAL
- bsp/stm32/libraries/STM32WBxx_HAL
- bsp/stm32/libraries/STM32H7xx_HAL
......@@ -10,6 +10,16 @@ The peripheral library or firmware library of the chip manufacturer is authorize
## BSP's License and Coyright:
### acm32f0x0-nucleo
License: bsd-new
Copyright: Copyright (c) 2021, AisinoChip
Path:
- bsp/acm32f0x0-nucleo/libraries
### apollo2
License: bsd-new
......
# files format check exclude path, please follow the instructions below to modify;
# If you need to exclude an entire folder, add the folder path in dir_path;
# If you need to exclude a file, add the path to the file in file_path.
dir_path:
- libraries
mainmenu "RT-Thread Project Configuration"
config BSP_DIR
string
option env="BSP_ROOT"
default "."
config RTT_DIR
string
option env="RTT_ROOT"
default "../.."
config PKGS_DIR
string
option env="PKGS_ROOT"
default "packages"
source "$RTT_DIR/Kconfig"
source "$PKGS_DIR/Kconfig"
config SOC_SERIES_ACM32F0
bool
select ARCH_ARM_CORTEX_M0
default y
source "$BSP_DIR/drivers/Kconfig"
# acm32f0x0板级支持包
## 1. 简介
ACM32F0x0芯片是上海爱信诺航芯电子科技有限公司(后续简称上海航芯)一系列支持多种低功耗模式的通用MCU。包括如下硬件特性:
|--------------------------|--------------------|
| 硬件 | 描述 |
| -------------------------|--------------------|
|芯片型号 | ACM32F0X0系列 |
|CPU | ARM Cortex-M0 |
|主频 | 64MHz |
|片内SRAM | 32K |
|片内Flash | 128K |
|--------------------------|--------------------|
具体型号及资源请参考上海航芯官方网站[ACM32F0](www.aisinochip.com/index.php/product/child1/id/217.html)
## 2. 编译说明
推荐使用[env工具][1],可以在console下进入到`bsp/acm32f0x0-nucleo`目录中,运行以下命令:
`scons`
来编译这个板级支持包。如果编译正确无误,会产生rtthread.elf、rtthread.bin文件。其中rtthread.bin需要烧写到设备中进行运行。
也可以通过`scons --target=iar``scons --target=mdk5`生成IAR或是keil工程,再使用相应的工具进行编译。
## 3. 烧写及执行
开发板的使用请参考上海航芯官方网站相应型号的[开发工具](www.aisinochip.com/index.php/product/detail/id/25.html)
### 3.1 运行结果
如果编译 & 烧写无误,当复位设备后,会在串口上看到RT-Thread的启动logo信息:
## 4. 驱动支持情况及计划
| **片上外设** | **支持情况** | **备注** |
| ------------- | ------------ | ------------------------------------- |
| GPIO | 支持 | PA0, PA1... PD15 ---> PIN: 0, 1...63 |
| UART | 支持 | UART1/UART2 |
| LED | 支持 | LED1 |
| WDT | 支持 | WDT/IWDT |
| ADC | 支持 | |
## 5. 联系人信息
维护人:AisinoChip < xiangfeng.liu@aisinochip.com >
## 6. 参考
* 板子[数据手册][2]
* 芯片[数据手册][3]
[1]: https://www.rt-thread.org/page/download.html
[2]: www.aisinochip.com/index.php/product/detail/id/32.html
[3]: www.aisinochip.com/index.php/product/detail/id/32.html
# for module compiling
import os
from building import *
cwd = GetCurrentDir()
objs = []
list = os.listdir(cwd)
for d in list:
path = os.path.join(cwd, d)
if os.path.isfile(os.path.join(path, 'SConscript')):
objs = objs + SConscript(os.path.join(d, 'SConscript'))
Return('objs')
import os
import sys
import rtconfig
if os.getenv('RTT_ROOT'):
RTT_ROOT = os.getenv('RTT_ROOT')
else:
RTT_ROOT = os.path.normpath(os.getcwd() + '/../..')
sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
try:
from building import *
except:
print('Cannot found RT-Thread root directory, please check RTT_ROOT')
print(RTT_ROOT)
exit(-1)
TARGET = 'rtthread.' + rtconfig.TARGET_EXT
DefaultEnvironment(tools=[])
env = Environment(tools = ['mingw'],
AS = rtconfig.AS, ASFLAGS = rtconfig.AFLAGS,
CC = rtconfig.CC, CCFLAGS = rtconfig.CFLAGS,
AR = rtconfig.AR, ARFLAGS = '-rc',
CXX = rtconfig.CXX, CXXFLAGS = rtconfig.CXXFLAGS,
LINK = rtconfig.LINK, LINKFLAGS = rtconfig.LFLAGS)
env.PrependENVPath('PATH', rtconfig.EXEC_PATH)
if rtconfig.PLATFORM == 'iar':
env.Replace(CCCOM = ['$CC $CCFLAGS $CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS -o $TARGET $SOURCES'])
env.Replace(ARFLAGS = [''])
env.Replace(LINKCOM = env["LINKCOM"] + ' --map rt-thread.map')
Export('RTT_ROOT')
Export('rtconfig')
SDK_ROOT = os.path.abspath('./')
if os.path.exists(SDK_ROOT + '/libraries'):
libraries_path_prefix = SDK_ROOT + '/libraries'
else:
libraries_path_prefix = os.path.dirname(SDK_ROOT) + '/libraries'
SDK_LIB = libraries_path_prefix
Export('SDK_LIB')
# prepare building environment
objs = PrepareBuilding(env, RTT_ROOT, has_libcpu=False)
# make a building
DoBuilding(TARGET, objs)
Import('RTT_ROOT')
Import('rtconfig')
from building import *
cwd = os.path.join(str(Dir('#')), 'applications')
src = Glob('*.c')
CPPPATH = [cwd, str(Dir('#'))]
group = DefineGroup('Applications', src, depend = [''], CPPPATH = CPPPATH)
Return('group')
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2021-08-23 AisinoChip the first version
*/
#include <rthw.h>
#include <rtthread.h>
#include "board.h"
/*******************************************************************************
* Function Name : assert_failed
* Description : Reports the name of the source file and the source line number
* where the assert error has occurred.
* Input : - file: pointer to the source file name
* - line: assert error line source number
* Output : None
* Return : None
*******************************************************************************/
void assert_failed(uint8_t *file, uint32_t line)
{
rt_kprintf("\n\r Wrong parameter value detected on\r\n");
rt_kprintf(" file %s\r\n", file);
rt_kprintf(" line %d\r\n", line);
while (1) ;
}
int main(void)
{
rt_hw_led_init();
while(1)
{
rt_hw_led_on(0);
rt_thread_delay(RT_TICK_PER_SECOND/2);
rt_hw_led_off(0);
rt_thread_delay(RT_TICK_PER_SECOND/2);
}
}
menu "Hardware Drivers Config"
config SOC_ACM32F070RBT7
bool
select SOC_SERIES_ACM32F0
select RT_USING_COMPONENTS_INIT
default y
config SOC_SRAM_START_ADDR
hex
default 0x20000000
config SOC_SRAM_SIZE
hex
default 0x20
config SOC_FLASH_START_ADDR
hex
default 0x00000000
config SOC_FLASH_SIZE
hex
default 0x80
menu "Onboard Peripheral Drivers"
endmenu
menu "On-chip Peripheral Drivers"
menu "Hardware GPIO"
config BSP_USING_GPIO1
bool "Enable GPIOAB"
default y
select RT_USING_PIN
config BSP_USING_GPIO2
bool "Enable GPIOCD"
default y
select RT_USING_PIN
endmenu
config BSP_USING_ADC
bool "Enable ADC"
select RT_USING_ADC
default n
menu "Hardware UART"
config BSP_USING_UART1
bool "Enable UART1 (PA9/PA10)"
default y
select RT_USING_SERIAL
config BSP_USING_UART2
bool "Enable UART2 (PA2/PA3)"
default y
select RT_USING_SERIAL
if BSP_USING_UART2
config BSP_UART2_RX_USING_DMA
bool "Enable UART2 RX DMA"
depends on BSP_USING_UART2
select RT_SERIAL_USING_DMA
default n
config BSP_UART2_TX_USING_DMA
bool "Enable UART2 TX DMA"
depends on BSP_USING_UART2
select RT_SERIAL_USING_DMA
default n
endif
config BSP_USING_UART3
bool "Enable UART3 (PC4/PC5)"
default n
select RT_USING_SERIAL
if BSP_USING_UART3
config BSP_UART3_RX_USING_DMA
bool "Enable UART3 RX DMA"
depends on BSP_USING_UART3
select RT_SERIAL_USING_DMA
default n
config BSP_UART3_TX_USING_DMA
bool "Enable UART3 TX DMA"
depends on BSP_USING_UART3
select RT_SERIAL_USING_DMA
default n
endif
endmenu
config BSP_USING_RTC
bool "Enable RTC"
select RT_USING_RTC
default n
menu "Hardware I2C"
config BSP_USING_I2C1
bool "Enable I2C1"
default n
select RT_USING_I2C
config BSP_USING_I2C2
bool "Enable I2C2"
default n
select RT_USING_I2C
endmenu
menu "Hardware CAN"
config BSP_USING_CAN1
bool "Enable CAN1"
default n
select RT_USING_CAN
endmenu
menu "Hardware TIMER"
config BSP_USING_TIM1
bool "Enable Timer1"
default n
select RT_USING_HWTIMER
config BSP_USING_TIM3
bool "Enable Timer3"
default n
select RT_USING_HWTIMER
config BSP_USING_TIM6
bool "Enable Timer6"
default n
select RT_USING_HWTIMER
config BSP_USING_TIM14
bool "Enable Timer14"
default n
select RT_USING_HWTIMER
config BSP_USING_TIM15
bool "Enable Timer15"
default n
select RT_USING_HWTIMER
config BSP_USING_TIM16
bool "Enable Timer16"
default n
select RT_USING_HWTIMER
config BSP_USING_TIM17
bool "Enable Timer17"
default n
select RT_USING_HWTIMER
endmenu
menu "Hardware WDT"
config BSP_USING_WDT
bool "Enable Watch Dog Timer"
default n
select RT_USING_WDT
config BSP_USING_IWDT
bool "Enable Independent Watch Dog Timer"
default n
select RT_USING_WDT
endmenu
config BSP_USING_LCD
bool "Enable LCD"
default n
menu "Hardware SPI"
config BSP_USING_SPI1
bool "Enable SPI1"
select RT_USING_SPI
default n
if BSP_USING_SPI1
config BSP_SPI1_RX_USING_DMA
bool "Enable SPI1 RX DMA"
default n
config BSP_SPI1_TX_USING_DMA
bool "Enable SPI1 TX DMA"
default n
endif
config BSP_USING_SPI2
bool "Enable SPI2"
select RT_USING_SPI
default n
if BSP_USING_SPI2
config BSP_SPI2_RX_USING_DMA
bool "Enable SPI2 RX DMA"
default n
config BSP_SPI2_TX_USING_DMA
bool "Enable SPI2 TX DMA"
default n
endif
endmenu
menu "Hardware CRYPTO"
config BSP_USING_CRC
select RT_HWCRYPTO_USING_CRC
bool "Enable CRC"
default n
select RT_USING_HWCRYPTO
config BSP_USING_AES
select RT_HWCRYPTO_USING_AES
bool "Enable AES"
default n
select RT_USING_HWCRYPTO
config BSP_USING_HRNG
select RT_HWCRYPTO_USING_RNG
bool "Enable HRNG"
default n
select RT_USING_HWCRYPTO
endmenu
config BSP_USING_CMP
bool "Enable Analog Voltage Comparer"
default n
config BSP_USING_OPA
bool "Enable Operational Amplifier"
default n
config BSP_USING_TKEY
bool "Enable Touch Key"
select RT_USING_TOUCH
default n
config BSP_USING_RPMU
bool "Enable RTC PMU"
select RT_USING_PM
default n
endmenu
menu "Board extended module Drivers"
endmenu
endmenu
Import('RTT_ROOT')
Import('rtconfig')
from building import *
cwd = GetCurrentDir()
src = Glob('*.c')
CPPPATH = [cwd]
#remove other no use files
#SrcRemove(src, '*.c')
group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH)
Return('group')
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2021-08-25 AisinoChip first implementation
*/
#include <rthw.h>
#include <rtthread.h>
#include "rtconfig.h"
#include "board.h"
#include <rtdevice.h>
#define SOC_SRAM_END_ADDR (SOC_SRAM_START_ADDR+SOC_SRAM_SIZE*1024)
extern int rt_application_init(void);
#if defined(__CC_ARM) || defined(__CLANG_ARM)
extern int Image$$RW_IRAM1$$ZI$$Limit;
#elif __ICCARM__
#pragma section="HEAP"
#else
extern int __bss_end;
#endif
extern void rt_hw_uart_init(void);
/**
* This is the timer interrupt service routine.
*
*/
void SysTick_Handler(void)
{
/* enter interrupt */
rt_interrupt_enter();
rt_tick_increase();
/* leave interrupt */
rt_interrupt_leave();
}
/**
* This function will initial EVB board.
*/
void rt_hw_board_init(void)
{
/* system init, clock, NVIC */
System_Init();
/* Configure the SysTick */
SysTick_Config(System_Get_SystemClock() / RT_TICK_PER_SECOND);
rt_hw_uart_init();
rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
#ifdef RT_USING_HEAP
#if defined(__CC_ARM) || defined(__CLANG_ARM)
rt_system_heap_init((void *)&Image$$RW_IRAM1$$ZI$$Limit, (void *)SOC_SRAM_END_ADDR);
#elif __ICCARM__
rt_system_heap_init(__segment_end("HEAP"), (void *)SOC_SRAM_END_ADDR);
#else
/* init memory system */
rt_system_heap_init((void *)&__bss_end, (void *)SOC_SRAM_END_ADDR);
#endif
#endif /* RT_USING_HEAP */
#ifdef RT_USING_COMPONENTS_INIT
rt_components_board_init();
#endif
}
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2021-08-27 AisinoCip add board.h to this bsp
*/
#ifndef __BOARD_H__
#define __BOARD_H__
#include <rtconfig.h>
#include "ACM32Fxx_HAL.h"
#include "led.h"
/*-------------------------- UART CONFIG BEGIN --------------------------*/
/** After configuring corresponding UART or UART DMA, you can use it.
*
* STEP 1, define macro define related to the serial port opening based on the serial port number
* such as #define BSP_USING_UATR1
*
* STEP 2, according to the corresponding pin of serial port, modify the related serial port information
* such as #define UART1_TX_PORT GPIOX -> GPIOA
* #define UART1_RX_PORT GPIOX -> GPIOA
* #define UART1_TX_PIN GPIO_PIN_X -> GPIO_PIN_9
* #define UART1_RX_PIN GPIO_PIN_X -> GPIO_PIN_10
*
* STEP 3, if you want using SERIAL DMA, you must open it in the RT-Thread Settings.
* RT-Thread Setting -> Components -> Device Drivers -> Serial Device Drivers -> Enable Serial DMA Mode
*
* STEP 4, according to serial port number to define serial port tx/rx DMA function in the board.h file
* such as #define BSP_UART1_RX_USING_DMA
*
*/
#if defined(BSP_USING_UART1)
#define UART1_TX_PORT GPIOA
#define UART1_RX_PORT GPIOA
#define UART1_TX_PIN GPIO_PIN_9
#define UART1_RX_PIN GPIO_PIN_10
#if defined(BSP_UART1_RX_USING_DMA)
#define UART1_RX_DMA_INSTANCE DMA_Channel0
#define UART1_RX_DMA_RCC BIT12
#define UART1_RX_DMA_IRQ DMA_IRQn
#define UART1_RX_DMA_CHANNEL 0
#define UART1_RX_DMA_REQUEST REQ6_UART1_RECV
#endif /* BSP_UART1_RX_USING_DMA */
#if defined(BSP_UART1_TX_USING_DMA)
#define UART1_TX_DMA_INSTANCE DMA_Channel1
#define UART1_TX_DMA_RCC BIT12
#define UART1_TX_DMA_IRQ DMA_IRQn
#define UART1_TX_DMA_CHANNEL 1
#define UART1_TX_DMA_REQUEST REQ5_UART1_SEND
#endif /* BSP_UART1_TX_USING_DMA */
#endif /* BSP_USING_UART1 */
#if defined(BSP_USING_UART2)
#define UART2_TX_PORT GPIOA
#define UART2_RX_PORT GPIOA
#define UART2_TX_PIN GPIO_PIN_2
#define UART2_RX_PIN GPIO_PIN_3
#if defined(BSP_UART2_RX_USING_DMA)
#define UART2_RX_DMA_INSTANCE DMA_Channel0
#define UART2_RX_DMA_RCC BIT12
#define UART2_RX_DMA_IRQ DMA_IRQn
#define UART2_RX_DMA_CHANNEL 0
#define UART2_RX_DMA_REQUEST REQ8_UART2_RECV
#endif /* BSP_UART2_RX_USING_DMA */
#if defined(BSP_UART2_TX_USING_DMA)
#define UART2_TX_DMA_INSTANCE DMA_Channel1
#define UART2_TX_DMA_RCC BIT12
#define UART2_TX_DMA_IRQ DMA_IRQn
#define UART2_TX_DMA_CHANNEL 1
#define UART2_TX_DMA_REQUEST REQ7_UART2_SEND
#endif /* BSP_UART2_TX_USING_DMA */
#endif /* BSP_USING_UART2 */
#if defined(BSP_USING_UART3)
#define UART3_TX_PORT GPIOB
#define UART3_RX_PORT GPIOB
#define UART3_TX_PIN GPIO_PIN_10
#define UART3_RX_PIN GPIO_PIN_11
#if defined(BSP_UART3_RX_USING_DMA)
#define UART3_RX_DMA_INSTANCE DMA_Channel0
#define UART3_RX_DMA_RCC BIT12
#define UART3_RX_DMA_IRQ DMA_IRQn
#define UART3_RX_DMA_CHANNEL 2
#define UART3_RX_DMA_REQUEST REQ29_UART3_RECV
#endif /* BSP_UART3_RX_USING_DMA */
#if defined(BSP_UART3_TX_USING_DMA)
#define UART3_TX_DMA_INSTANCE DMA_Channel1
#define UART3_TX_DMA_RCC BIT12
#define UART3_TX_DMA_IRQ DMA_IRQn
#define UART3_TX_DMA_CHANNEL 3
#define UART3_TX_DMA_REQUEST REQ27_UART3_SEND
#endif /* BSP_UART3_TX_USING_DMA */
#endif /* BSP_USING_UART3 */
/*-------------------------- UART CONFIG END --------------------------*/
/* board configuration */
void rt_hw_board_init(void);
#endif /* __BOARD_H__ */
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2021-08-23 AisinoChip first implementation
*/
#include <board.h>
#include <rtthread.h>
#include <rtdevice.h>
#define ADC_NAME "adc"
#if defined(BSP_USING_ADC)
struct acm32_adc
{
ADC_HandleTypeDef handle;
struct rt_adc_device acm32_adc_device;
};
static struct acm32_adc acm32_adc_obj = {0};
static rt_err_t acm32_adc_enabled(struct rt_adc_device *device, rt_uint32_t channel, rt_bool_t enabled)
{
struct acm32_adc *adcObj = RT_NULL;
RT_ASSERT(device != RT_NULL);
adcObj = rt_container_of(device, struct acm32_adc, acm32_adc_device);
if (enabled)
{
/* channel enabled */
if (0 != (adcObj->handle.Init.ChannelEn & (1 << channel)))
{
return RT_EOK;
}
adcObj->handle.Instance = ADC;
adcObj->handle.Init.ClockDiv = ADC_CLOCK_DIV8;
adcObj->handle.Init.ConConvMode = ADC_CONCONVMODE_DISABLE;
adcObj->handle.Init.JChannelMode = ADC_JCHANNELMODE_DISABLE;
adcObj->handle.Init.DiffMode = ADC_DIFFMODE_DISABLE;
adcObj->handle.Init.DMAMode = ADC_DMAMODE_DISABLE;
adcObj->handle.Init.OverMode = ADC_OVERMODE_DISABLE;
adcObj->handle.Init.OverSampMode = ADC_OVERSAMPMODE_DISABLE;
adcObj->handle.Init.AnalogWDGEn = ADC_ANALOGWDGEN_DISABLE;
adcObj->handle.Init.ExTrigMode.ExTrigSel = ADC_SOFTWARE_START;
adcObj->handle.Init.ChannelEn |= 1 << channel;
HAL_ADC_Init(&adcObj->handle);
adcObj->handle.ChannelNum ++;
}
else
{
/* channel disabled */
if (0 == (adcObj->handle.Init.ChannelEn & (1 << channel)))
{
return RT_EOK;
}
adcObj->handle.Init.ChannelEn &= ~(1 << channel);
adcObj->handle.ChannelNum --;
}
return RT_EOK;
}
static rt_err_t acm32_get_adc_value(struct rt_adc_device *device, rt_uint32_t channel, rt_uint32_t *value)
{
struct acm32_adc *adcObj = RT_NULL;
ADC_ChannelConfTypeDef channelConf = {0};
RT_ASSERT(device != RT_NULL);
RT_ASSERT(value != RT_NULL);
if (channel > ADC_CHANNEL_15)
{
return -RT_ERROR;
}
*value = RT_UINT32_MAX;
adcObj = rt_container_of(device, struct acm32_adc, acm32_adc_device);
/* channel disabled */
if (0 == (adcObj->handle.Init.ChannelEn & (1 << channel)))
{
return -RT_ERROR;
}
channelConf.Channel = channel;
channelConf.RjMode = 0;
channelConf.Sq = ADC_SEQUENCE_SQ1;
channelConf.Smp = ADC_SMP_CLOCK_320;
HAL_ADC_ConfigChannel(&adcObj->handle, &channelConf);
if (HAL_OK != HAL_ADC_Polling(&adcObj->handle, (uint32_t *)value, 1, 100))
{
return -RT_ERROR;
}
*value &= ~(HAL_ADC_EOC_FLAG);
return RT_EOK;
}
static const struct rt_adc_ops acm_adc_ops =
{
.enabled = acm32_adc_enabled,
.convert = acm32_get_adc_value,
};
static int acm32_adc_init(void)
{
return rt_hw_adc_register(&acm32_adc_obj.acm32_adc_device,
ADC_NAME,
&acm_adc_ops,
RT_NULL);
}
INIT_BOARD_EXPORT(acm32_adc_init);
#endif /* BSP_USING_ADC */
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2021-08-26 AisinoChip first version
*/
#include <rthw.h>
#include <rtthread.h>
#include <rtdevice.h>
#include <rtconfig.h>
#include "board.h"
#ifdef RT_USING_PIN
#include <rtdevice.h>
#define __ACM32_PIN(index, gpio, gpio_index) \
{ \
index, GPIO##gpio, GPIO_PIN_##gpio_index \
}
#define __ACM32_PIN_RESERVE \
{ \
-1, 0, 0 \
}
/* ACM32 GPIO driver */
struct pin_index
{
int index;
enum_GPIOx_t gpio;
uint32_t pin;
};
struct pin_irq_map
{
rt_uint16_t line;
EXTI_HandleTypeDef handle;
};
static const struct pin_index pins[] =
{
#if defined(BSP_USING_GPIO1)
__ACM32_PIN(0, A, 0),
__ACM32_PIN(1, A, 1),
__ACM32_PIN(2, A, 2),
__ACM32_PIN(3, A, 3),
__ACM32_PIN(4, A, 4),
__ACM32_PIN(5, A, 5),
__ACM32_PIN(6, A, 6),
__ACM32_PIN(7, A, 7),
__ACM32_PIN(8, A, 8),
__ACM32_PIN(9, A, 9),
__ACM32_PIN(10, A, 10),
__ACM32_PIN(11, A, 11),
__ACM32_PIN(12, A, 12),
__ACM32_PIN(13, A, 13),
__ACM32_PIN(14, A, 14),
__ACM32_PIN(15, A, 15),
__ACM32_PIN(16, B, 0),
__ACM32_PIN(17, B, 1),
__ACM32_PIN(18, B, 2),
__ACM32_PIN(19, B, 3),
__ACM32_PIN(20, B, 4),
__ACM32_PIN(21, B, 5),
__ACM32_PIN(22, B, 6),
__ACM32_PIN(23, B, 7),
__ACM32_PIN(24, B, 8),
__ACM32_PIN(25, B, 9),
__ACM32_PIN(26, B, 10),
__ACM32_PIN(27, B, 11),
__ACM32_PIN(28, B, 12),
__ACM32_PIN(29, B, 13),
__ACM32_PIN(30, B, 14),
__ACM32_PIN(31, B, 15),
#if defined(BSP_USING_GPIO2)
__ACM32_PIN(32, C, 0),
__ACM32_PIN(33, C, 1),
__ACM32_PIN(34, C, 2),
__ACM32_PIN(35, C, 3),
__ACM32_PIN(36, C, 4),
__ACM32_PIN(37, C, 5),
__ACM32_PIN(38, C, 6),
__ACM32_PIN(39, C, 7),
__ACM32_PIN(40, C, 8),
__ACM32_PIN(41, C, 9),
__ACM32_PIN(42, C, 10),
__ACM32_PIN(43, C, 11),
__ACM32_PIN(44, C, 12),
__ACM32_PIN(45, C, 13),
__ACM32_PIN(46, C, 14),
__ACM32_PIN(47, C, 15),
__ACM32_PIN(48, D, 0),
__ACM32_PIN(49, D, 1),
__ACM32_PIN(50, D, 2),
__ACM32_PIN(51, D, 3),
__ACM32_PIN(52, D, 4),
__ACM32_PIN(53, D, 5),
__ACM32_PIN(54, D, 6),
__ACM32_PIN(55, D, 7),
__ACM32_PIN(56, D, 8),
__ACM32_PIN(57, D, 9),
__ACM32_PIN(58, D, 10),
__ACM32_PIN(59, D, 11),
__ACM32_PIN(60, D, 12),
__ACM32_PIN(61, D, 13),
__ACM32_PIN(62, D, 14),
__ACM32_PIN(63, D, 15),
#endif /* defined(BSP_USING_GPIO2) */
#endif /* defined(BSP_USING_GPIO1) */
};
static struct pin_irq_map pin_irq_map[] =
{
{EXTI_LINE_0, {0}},
{EXTI_LINE_1, {0}},
{EXTI_LINE_2, {0}},
{EXTI_LINE_3, {0}},
{EXTI_LINE_4, {0}},
{EXTI_LINE_5, {0}},
{EXTI_LINE_6, {0}},
{EXTI_LINE_7, {0}},
{EXTI_LINE_8, {0}},
{EXTI_LINE_9, {0}},
{EXTI_LINE_10, {0}},
{EXTI_LINE_11, {0}},
{EXTI_LINE_12, {0}},
{EXTI_LINE_13, {0}},
{EXTI_LINE_14, {0}},
{EXTI_LINE_15, {0}},
};
static struct rt_pin_irq_hdr pin_irq_hdr_tab[] =
{
{-1, 0, RT_NULL, RT_NULL},
{-1, 0, RT_NULL, RT_NULL},
{-1, 0, RT_NULL, RT_NULL},
{-1, 0, RT_NULL, RT_NULL},
{-1, 0, RT_NULL, RT_NULL},
{-1, 0, RT_NULL, RT_NULL},
{-1, 0, RT_NULL, RT_NULL},
{-1, 0, RT_NULL, RT_NULL},
{-1, 0, RT_NULL, RT_NULL},
{-1, 0, RT_NULL, RT_NULL},
{-1, 0, RT_NULL, RT_NULL},
{-1, 0, RT_NULL, RT_NULL},
{-1, 0, RT_NULL, RT_NULL},
{-1, 0, RT_NULL, RT_NULL},
{-1, 0, RT_NULL, RT_NULL},
{-1, 0, RT_NULL, RT_NULL},
};
static uint32_t pin_irq_enable_mask = 0;
#define ITEM_NUM(items) sizeof(items) / sizeof(items[0])
static const struct pin_index *get_pin(uint8_t pin)
{
const struct pin_index *index;
if (pin < ITEM_NUM(pins))
{
index = &pins[pin];
if (index->index == -1)
index = RT_NULL;
}
else
{
index = RT_NULL;
}
return index;
};
static void acm32_pin_write(rt_device_t dev, rt_base_t pin, rt_base_t value)
{
const struct pin_index *index;
index = get_pin(pin);
if (index == RT_NULL)
{
return;
}
HAL_GPIO_WritePin(index->gpio, index->pin, (enum_PinState_t)value);
}
static int acm32_pin_read(rt_device_t dev, rt_base_t pin)
{
int value;
const struct pin_index *index;
value = PIN_LOW;
index = get_pin(pin);
if (index == RT_NULL)
{
return value;
}
value = HAL_GPIO_ReadPin(index->gpio, index->pin);
return value;
}
static void acm32_pin_mode(rt_device_t dev, rt_base_t pin, rt_base_t mode)
{
const struct pin_index *index;
GPIO_InitTypeDef GPIO_InitStruct;
index = get_pin(pin);
if (index == RT_NULL)
{
return;
}
/* Configure GPIO_InitStructure */
GPIO_InitStruct.Pin = index->pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Alternate = GPIO_FUNCTION_0;
if (mode == PIN_MODE_OUTPUT)
{
/* output setting */
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
}
else if (mode == PIN_MODE_INPUT)
{
/* input setting: not pull. */
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
}
else if (mode == PIN_MODE_INPUT_PULLUP)
{
/* input setting: pull up. */
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_PULLUP;
}
else if (mode == PIN_MODE_INPUT_PULLDOWN)
{
/* input setting: pull down. */
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
}
else if (mode == PIN_MODE_OUTPUT_OD)
{
/* output setting: od. */
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
GPIO_InitStruct.Pull = GPIO_NOPULL;
}
/* special PIN process */
__HAL_RTC_PC13_DIGIT();
HAL_GPIO_Init(index->gpio, &GPIO_InitStruct);
}
#define PIN2INDEX(pin) ((pin) % 16)
static rt_err_t acm32_pin_attach_irq(struct rt_device *device, rt_int32_t pin,
rt_uint32_t mode, void (*hdr)(void *args), void *args)
{
const struct pin_index *index;
rt_base_t level;
rt_int32_t irqindex = -1;
index = get_pin(pin);
if (index == RT_NULL)
{
return RT_ENOSYS;
}
irqindex = PIN2INDEX(pin);
level = rt_hw_interrupt_disable();
if (pin_irq_hdr_tab[irqindex].pin == pin &&
pin_irq_hdr_tab[irqindex].hdr == hdr &&
pin_irq_hdr_tab[irqindex].mode == mode &&
pin_irq_hdr_tab[irqindex].args == args)
{
rt_hw_interrupt_enable(level);
return RT_EOK;
}
if (pin_irq_hdr_tab[irqindex].pin != -1)
{
rt_hw_interrupt_enable(level);
return RT_EBUSY;
}
pin_irq_hdr_tab[irqindex].pin = pin;
pin_irq_hdr_tab[irqindex].hdr = hdr;
pin_irq_hdr_tab[irqindex].mode = mode;
pin_irq_hdr_tab[irqindex].args = args;
rt_hw_interrupt_enable(level);
return RT_EOK;
}
static rt_err_t acm32_pin_dettach_irq(struct rt_device *device, rt_int32_t pin)
{
const struct pin_index *index;
rt_base_t level;
rt_int32_t irqindex = -1;
index = get_pin(pin);
if (index == RT_NULL)
{
return RT_ENOSYS;
}
irqindex = PIN2INDEX(pin);
level = rt_hw_interrupt_disable();
if (pin_irq_hdr_tab[irqindex].pin == -1)
{
rt_hw_interrupt_enable(level);
return RT_EOK;
}
pin_irq_hdr_tab[irqindex].pin = -1;
pin_irq_hdr_tab[irqindex].hdr = RT_NULL;
pin_irq_hdr_tab[irqindex].mode = 0;
pin_irq_hdr_tab[irqindex].args = RT_NULL;
rt_hw_interrupt_enable(level);
return RT_EOK;
}
static rt_err_t acm32_pin_irq_enable(struct rt_device *device, rt_base_t pin,
rt_uint32_t enabled)
{
const struct pin_index *index;
struct pin_irq_map *irqmap;
rt_base_t level;
rt_int32_t irqindex = -1;
GPIO_InitTypeDef GPIO_InitStruct;
index = get_pin(pin);
if (index == RT_NULL)
{
return RT_ENOSYS;
}
irqindex = PIN2INDEX(pin);
irqmap = &pin_irq_map[irqindex];
if (enabled == PIN_IRQ_ENABLE)
{
level = rt_hw_interrupt_disable();
if (pin_irq_hdr_tab[irqindex].pin == -1)
{
rt_hw_interrupt_enable(level);
return RT_ENOSYS;
}
/* Configure GPIO_InitStructure */
GPIO_InitStruct.Pin = index->pin;
GPIO_InitStruct.Alternate = GPIO_FUNCTION_0;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
irqmap->handle.u32_Line = irqmap->line;
irqmap->handle.u32_Mode = EXTI_MODE_INTERRUPT;
switch (pin_irq_hdr_tab[irqindex].mode)
{
case PIN_IRQ_MODE_RISING:
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
irqmap->handle.u32_Trigger = EXTI_TRIGGER_RISING;
break;
case PIN_IRQ_MODE_FALLING:
GPIO_InitStruct.Pull = GPIO_PULLUP;
irqmap->handle.u32_Trigger = EXTI_TRIGGER_FALLING;
break;
case PIN_IRQ_MODE_RISING_FALLING:
GPIO_InitStruct.Pull = GPIO_NOPULL;
irqmap->handle.u32_Trigger = EXTI_TRIGGER_RISING_FALLING;
break;
}
HAL_GPIO_Init(index->gpio, &GPIO_InitStruct);
irqmap->handle.u32_GPIOSel = pin / 16;
HAL_EXTI_SetConfigLine(&irqmap->handle);
pin_irq_enable_mask |= 1 << irqindex;
rt_hw_interrupt_enable(level);
}
else if (enabled == PIN_IRQ_DISABLE)
{
if ((pin_irq_enable_mask & (1 << irqindex)) == 0)
{
return RT_ENOSYS;
}
level = rt_hw_interrupt_disable();
EXTI->IENR &= ~irqmap->line;
EXTI->EENR &= ~irqmap->line;
rt_hw_interrupt_enable(level);
}
else
{
return -RT_ENOSYS;
}
return RT_EOK;
}
const static struct rt_pin_ops _acm32_pin_ops =
{
acm32_pin_mode,
acm32_pin_write,
acm32_pin_read,
acm32_pin_attach_irq,
acm32_pin_dettach_irq,
acm32_pin_irq_enable,
};
rt_inline void pin_irq_hdr(int irqno)
{
if (pin_irq_hdr_tab[irqno].hdr)
{
pin_irq_hdr_tab[irqno].hdr(pin_irq_hdr_tab[irqno].args);
}
}
int rt_hw_pin_init(void)
{
return rt_device_pin_register("pin", &_acm32_pin_ops, RT_NULL);
}
INIT_BOARD_EXPORT(rt_hw_pin_init);
void EXTI_IRQHandler(void)
{
/* enter interrupt */
rt_interrupt_enter();
for (int i = 0; i < 16; i++)
{
if (EXTI->PDR & pin_irq_map[i].line)
{
EXTI->PDR = pin_irq_map[i].line;
pin_irq_hdr(i);
break;
}
}
/* leave interrupt */
rt_interrupt_leave();
}
#endif /* RT_USING_PIN */
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2021-08-26 AisinoChip first version
*/
#include <board.h>
#include <rtthread.h>
#include <rtdevice.h>
#ifdef BSP_USING_TIM
#include "tim_config.h"
#ifdef RT_USING_HWTIMER
enum
{
#ifdef BSP_USING_TIM1
TIM1_INDEX,
#endif
#ifdef BSP_USING_TIM3
TIM3_INDEX,
#endif
#ifdef BSP_USING_TIM6
TIM6_INDEX,
#endif
#ifdef BSP_USING_TIM14
TIM14_INDEX,
#endif
#ifdef BSP_USING_TIM15
TIM15_INDEX,
#endif
#ifdef BSP_USING_TIM16
TIM16_INDEX,
#endif
#ifdef BSP_USING_TIM17
TIM17_INDEX,
#endif
};
struct acm32_hwtimer
{
rt_hwtimer_t time_device;
TIM_HandleTypeDef tim_handle;
IRQn_Type tim_irqn;
char *name;
};
static struct acm32_hwtimer acm32_hwtimer_obj[] =
{
#ifdef BSP_USING_TIM1
TIM1_CONFIG,
#endif
#ifdef BSP_USING_TIM3
TIM3_CONFIG,
#endif
#ifdef BSP_USING_TIM6
TIM6_CONFIG,
#endif
#ifdef BSP_USING_TIM14
TIM14_CONFIG,
#endif
#ifdef BSP_USING_TIM15
TIM15_CONFIG,
#endif
#ifdef BSP_USING_TIM16
TIM16_CONFIG,
#endif
#ifdef BSP_USING_TIM17
TIM17_CONFIG,
#endif
};
static void timer_init(struct rt_hwtimer_device *timer, rt_uint32_t state)
{
rt_uint32_t timer_clock = 0;
TIM_HandleTypeDef *tim = RT_NULL;
RT_ASSERT(timer != RT_NULL);
if (state)
{
tim = (TIM_HandleTypeDef *)timer->parent.user_data;
/* time init */
timer_clock = System_Get_APBClock();
if (System_Get_SystemClock() != System_Get_APBClock()) /* if hclk/pclk != 1, then timer clk = pclk * 2 */
{
timer_clock = System_Get_APBClock() << 1;
}
tim->Init.Period = (timer->freq) - 1;
tim->Init.Prescaler = (timer_clock / timer->freq) - 1 ;
tim->Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
if (timer->info->cntmode == HWTIMER_CNTMODE_UP)
{
tim->Init.CounterMode = TIM_COUNTERMODE_UP;
}
else
{
tim->Init.CounterMode = TIM_COUNTERMODE_DOWN;
}
tim->Init.RepetitionCounter = 0;
tim->Init.ARRPreLoadEn = TIM_ARR_PRELOAD_ENABLE;
HAL_TIMER_MSP_Init(tim);
HAL_TIMER_Base_Init(tim);
}
}
static rt_err_t timer_start(rt_hwtimer_t *timer, rt_uint32_t t, rt_hwtimer_mode_t opmode)
{
TIM_HandleTypeDef *tim = RT_NULL;
RT_ASSERT(timer != RT_NULL);
tim = (TIM_HandleTypeDef *)timer->parent.user_data;
/* set tim cnt */
tim->Instance->CNT = 0;
/* set tim arr */
tim->Instance->ARR = t - 1;
if (opmode == HWTIMER_MODE_ONESHOT)
{
/* set timer to single mode */
SET_BIT(tim->Instance->CR1, BIT3);
}
else
{
/* set timer to period mode */
CLEAR_BIT(tim->Instance->CR1, BIT3);
}
/* enable IRQ */
HAL_TIM_ENABLE_IT(tim, TIMER_INT_EN_UPD);
/* start timer */
HAL_TIMER_Base_Start(tim->Instance);
return RT_EOK;
}
static void timer_stop(rt_hwtimer_t *timer)
{
TIM_HandleTypeDef *tim = RT_NULL;
RT_ASSERT(timer != RT_NULL);
tim = (TIM_HandleTypeDef *)timer->parent.user_data;
/* stop timer */
HAL_TIMER_Base_Stop(tim->Instance);
}
static rt_err_t timer_ctrl(rt_hwtimer_t *timer, rt_uint32_t cmd, void *arg)
{
TIM_HandleTypeDef *tim = RT_NULL;
rt_err_t result = RT_EOK;
RT_ASSERT(timer != RT_NULL);
RT_ASSERT(arg != RT_NULL);
tim = (TIM_HandleTypeDef *)timer->parent.user_data;
switch (cmd)
{
case HWTIMER_CTRL_FREQ_SET:
{
rt_uint32_t freq;
rt_uint32_t timer_clock;
rt_uint16_t val;
/* set timer frequence */
freq = *((rt_uint32_t *)arg);
timer_clock = System_Get_APBClock();
if (System_Get_SystemClock() != System_Get_APBClock()) /* if hclk/pclk != 1, then timer clk = pclk * 2 */
{
timer_clock = System_Get_APBClock() << 1;
}
val = timer_clock / freq;
tim->Instance->PSC = val - 1;
/* Update frequency value */
tim->Instance->CR1 = BIT2; /* CEN=0, URS=1, OPM = 0 */
tim->Instance->EGR |= TIM_EVENTSOURCE_UPDATE;
}
break;
default:
{
result = -RT_ENOSYS;
}
break;
}
return result;
}
static rt_uint32_t timer_counter_get(rt_hwtimer_t *timer)
{
RT_ASSERT(timer != RT_NULL);
return ((TIM_HandleTypeDef *)timer->parent.user_data)->Instance->CNT;
}
static const struct rt_hwtimer_info _info = TIM_DEV_INFO_CONFIG;
static const struct rt_hwtimer_ops _ops =
{
.init = timer_init,
.start = timer_start,
.stop = timer_stop,
.count_get = timer_counter_get,
.control = timer_ctrl,
};
#ifdef BSP_USING_TIM1
void TIM1_BRK_UP_TRG_COM_IRQHandler(void)
{
/* enter interrupt */
rt_interrupt_enter();
/* interrupt service routine */
if (TIM1->SR & TIMER_SR_UIF)
{
rt_device_hwtimer_isr(&acm32_hwtimer_obj[TIM1_INDEX].time_device);
}
TIM1->SR = 0; /* write 0 to clear hardware flag */
/* leave interrupt */
rt_interrupt_leave();
}
#endif
#ifdef BSP_USING_TIM3
void TIM3_IRQHandler(void)
{
/* enter interrupt */
rt_interrupt_enter();
if (TIM3->SR & TIMER_SR_UIF)
{
rt_device_hwtimer_isr(&acm32_hwtimer_obj[TIM3_INDEX].time_device);
}
TIM3->SR = 0; /* write 0 to clear hardware flag */
/* leave interrupt */
rt_interrupt_leave();
}
#endif
#ifdef BSP_USING_TIM6
void TIM6_IRQHandler(void)
{
/* enter interrupt */
rt_interrupt_enter();
/* interrupt service routine */
if (TIM6->SR & TIMER_SR_UIF)
{
rt_device_hwtimer_isr(&acm32_hwtimer_obj[TIM6_INDEX].time_device);
}
TIM6->SR = 0; /* write 0 to clear hardware flag */
/* leave interrupt */
rt_interrupt_leave();
}
#endif
#ifdef BSP_USING_TIM14
void TIM14_IRQHandler(void)
{
/* enter interrupt */
rt_interrupt_enter();
/* interrupt service routine */
if (TIM14->SR & TIMER_SR_UIF)
{
rt_device_hwtimer_isr(&acm32_hwtimer_obj[TIM14_INDEX].time_device);
}
TIM14->SR = 0; /* write 0 to clear hardware flag */
/* leave interrupt */
rt_interrupt_leave();
}
#endif
#ifdef BSP_USING_TIM15
void TIM15_IRQHandler(void)
{
/* enter interrupt */
rt_interrupt_enter();
/* interrupt service routine */
if (TIM15->SR & TIMER_SR_UIF)
{
rt_device_hwtimer_isr(&acm32_hwtimer_obj[TIM15_INDEX].time_device);
}
TIM15->SR = 0; /* write 0 to clear hardware flag */
/* leave interrupt */
rt_interrupt_leave();
}
#endif
#ifdef BSP_USING_TIM16
void TIM16_IRQHandler(void)
{
/* enter interrupt */
rt_interrupt_enter();
if (TIM16->SR & TIMER_SR_UIF)
{
rt_device_hwtimer_isr(&acm32_hwtimer_obj[TIM16_INDEX].time_device);
}
TIM16->SR = 0; /* write 0 to clear hardware flag */
/* leave interrupt */
rt_interrupt_leave();
}
#endif
#ifdef BSP_USING_TIM17
void TIM17_IRQHandler(void)
{
/* enter interrupt */
rt_interrupt_enter();
if (TIM17->SR & TIMER_SR_UIF)
{
rt_device_hwtimer_isr(&acm32_hwtimer_obj[TIM17_INDEX].time_device);
}
TIM17->SR = 0; /* write 0 to clear hardware flag */
/* leave interrupt */
rt_interrupt_leave();
}
#endif
static int acm32_hwtimer_init(void)
{
int i = 0;
int result = RT_EOK;
for (i = 0; i < sizeof(acm32_hwtimer_obj) / sizeof(acm32_hwtimer_obj[0]); i++)
{
acm32_hwtimer_obj[i].time_device.info = &_info;
acm32_hwtimer_obj[i].time_device.ops = &_ops;
result = rt_device_hwtimer_register(&acm32_hwtimer_obj[i].time_device,
acm32_hwtimer_obj[i].name,
&acm32_hwtimer_obj[i].tim_handle);
if (result != RT_EOK)
{
result = -RT_ERROR;
break;
}
}
return result;
}
INIT_BOARD_EXPORT(acm32_hwtimer_init);
#endif /* RT_USING_HWTIMER */
#endif /* BSP_USING_TIM */
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2021-08-23 AisinoChip the first version
*/
#include <rthw.h>
#include <rtthread.h>
#include <rtdevice.h>
#include "rtconfig.h"
#include "board.h"
#include "uart_config.h"
#ifdef RT_USING_SERIAL
#ifdef RT_SERIAL_USING_DMA
struct dma_config
{
DMA_Channel_TypeDef *Instance;
rt_uint32_t dma_rcc;
IRQn_Type dma_irq;
rt_uint32_t channel;
rt_uint32_t request;
};
#endif
#ifdef RT_SERIAL_USING_DMA
static void DMA_Configuration(struct rt_serial_device *serial, rt_uint32_t flag);
#endif /* RT_SERIAL_USING_DMA */
struct acm32_uart_config
{
const char *name;
UART_TypeDef *Instance;
IRQn_Type irq_type;
enum_Enable_ID_t enable_id;
#ifdef RT_SERIAL_USING_DMA
struct dma_config *dma_rx;
struct dma_config *dma_tx;
#endif
enum_GPIOx_t tx_port;
enum_GPIOx_t rx_port;
rt_uint32_t tx_pin;
rt_uint32_t rx_pin;
};
struct acm32_uart
{
UART_HandleTypeDef handle;
struct acm32_uart_config *config;
#ifdef RT_SERIAL_USING_DMA
struct
{
DMA_HandleTypeDef handle;
rt_size_t last_index;
} dma_rx;
struct
{
DMA_HandleTypeDef handle;
} dma_tx;
#endif
rt_uint16_t uart_dma_flag;
struct rt_serial_device serial;
};
static rt_err_t uart_rx_indicate_cb(rt_device_t dev, rt_size_t size)
{
return RT_EOK;
}
static rt_err_t _uart_configure(struct rt_serial_device *serial, struct serial_configure *cfg)
{
struct acm32_uart *uart;
RT_ASSERT(serial != RT_NULL);
RT_ASSERT(cfg != RT_NULL);
uart = rt_container_of(serial, struct acm32_uart, serial);
uart->handle.Instance = uart->config->Instance;
uart->handle.Init.BaudRate = cfg->baud_rate;
if (cfg->data_bits == DATA_BITS_8)
{
uart->handle.Init.WordLength = UART_WORDLENGTH_8B;
}
else /* not support */
{
return -RT_EINVAL;
}
if (cfg->stop_bits == STOP_BITS_1)
{
uart->handle.Init.StopBits = UART_STOPBITS_1;
}
else if (cfg->stop_bits == STOP_BITS_2)
{
uart->handle.Init.StopBits = UART_STOPBITS_2;
}
else /* not support */
{
return -RT_EINVAL;
}
if (cfg->parity == PARITY_NONE)
{
uart->handle.Init.Parity = UART_PARITY_NONE;
}
else if (cfg->parity == PARITY_ODD)
{
uart->handle.Init.Parity = UART_PARITY_ODD;
}
else if (cfg->parity == PARITY_EVEN)
{
uart->handle.Init.Parity = UART_PARITY_EVEN;
}
else /* not support */
{
return -RT_EINVAL;
}
uart->handle.Init.Mode = UART_MODE_TX_RX;
uart->handle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
HAL_UART_Init(&uart->handle);
uart->handle.Instance->LCRH &= ~UART_LCRH_FEN;
return RT_EOK;
}
static rt_err_t _uart_control(struct rt_serial_device *serial, int cmd, void *arg)
{
struct acm32_uart *uart;
#ifdef RT_SERIAL_USING_DMA
rt_ubase_t ctrl_arg = (rt_ubase_t)arg;
#endif
RT_ASSERT(serial != RT_NULL);
uart = rt_container_of(serial, struct acm32_uart, serial);
switch (cmd)
{
/* disable interrupt */
case RT_DEVICE_CTRL_CLR_INT:
NVIC_DisableIRQ(uart->config->irq_type);
/* Disable RX interrupt */
uart->handle.Instance->IE &= ~UART_IE_RXI;
break;
/* enable interrupt */
case RT_DEVICE_CTRL_SET_INT:
NVIC_EnableIRQ(uart->config->irq_type);
/* Enable RX interrupt */
uart->handle.Instance->IE |= UART_IE_RXI;
break;
#ifdef RT_SERIAL_USING_DMA
/* UART config */
case RT_DEVICE_CTRL_CONFIG :
DMA_Configuration(serial, (rt_uint32_t)ctrl_arg);
rt_device_set_rx_indicate((rt_device_t)serial, uart_rx_indicate_cb);
break;
#endif /* RT_SERIAL_USING_DMA */
}
return RT_EOK;
}
static int _uart_putc(struct rt_serial_device *serial, char c)
{
struct acm32_uart *uart;
RT_ASSERT(serial != RT_NULL);
uart = rt_container_of(serial, struct acm32_uart, serial);
while (uart->handle.Instance->FR & UART_FR_TXFF); /* wait Tx FIFO not full */
uart->handle.Instance->DR = c;
while ((uart->handle.Instance->FR & UART_FR_BUSY)); /* wait TX Complete */
return 1;
}
static int _uart_getc(struct rt_serial_device *serial)
{
struct acm32_uart *uart;
int ch;
RT_ASSERT(serial != RT_NULL);
uart = rt_container_of(serial, struct acm32_uart, serial);
ch = -1;
if (!(uart->handle.Instance->FR & UART_FR_RXFE)) /* Rx FIFO not empty */
{
ch = uart->handle.Instance->DR & 0xff;
}
return ch;
}
#ifdef RT_SERIAL_USING_DMA
/**
* Serial port receive idle process. This need add to uart idle ISR.
*
* @param serial serial device
*/
static void dma_uart_rx_idle_isr(struct rt_serial_device *serial)
{
struct acm32_uart *uart;
RT_ASSERT(serial != RT_NULL);
uart = rt_container_of(serial, struct acm32_uart, serial);
rt_size_t recv_total_index, recv_len;
rt_base_t level;
/* disable interrupt */
level = rt_hw_interrupt_disable();
recv_total_index = uart->handle.lu32_RxSize - (uart->handle.HDMA_Rx->Instance->CTRL & 0xFFF);
recv_len = recv_total_index - uart->handle.lu32_RxCount;
uart->handle.lu32_RxCount = recv_total_index;
/* enable interrupt */
rt_hw_interrupt_enable(level);
if (recv_len)
{
rt_hw_serial_isr(serial, RT_SERIAL_EVENT_RX_DMADONE | (recv_len << 8));
}
}
/*
DMA receive done process. This need add to DMA receive done ISR.
@param serial serial device
*/
static void dma_rx_done_isr(struct rt_serial_device *serial)
{
struct acm32_uart *uart;
struct rt_serial_rx_fifo *rx_fifo = (struct rt_serial_rx_fifo *)serial->serial_rx;
RT_ASSERT(serial != RT_NULL);
uart = rt_container_of(serial, struct acm32_uart, serial);
rt_size_t recv_len;
rt_base_t level;
/* disable interrupt */
level = rt_hw_interrupt_disable();
recv_len = serial->config.bufsz - (uart->handle.HDMA_Rx->Instance->CTRL & 0xFFF);
uart->dma_rx.last_index = 0;
DMA->INT_TC_CLR |= 1 << (uart->config->dma_rx->channel); /* clear channel0 TC flag */
/* enable interrupt */
rt_hw_interrupt_enable(level);
if (recv_len)
{
rt_hw_serial_isr(serial, RT_SERIAL_EVENT_RX_DMADONE | (recv_len << 8));
}
HAL_UART_Receive_DMA(&(uart->handle), &rx_fifo->buffer[rx_fifo->put_index], serial->config.bufsz);
}
static rt_size_t _uart_dma_transmit(struct rt_serial_device *serial, rt_uint8_t *buf, rt_size_t size, int direction)
{
struct acm32_uart *uart;
RT_ASSERT(serial != RT_NULL);
uart = rt_container_of(serial, struct acm32_uart, serial);
if (size == 0)
{
return 0;
}
if (RT_SERIAL_DMA_TX == direction)
{
if (HAL_UART_Transmit_DMA(&uart->handle, buf, size) == HAL_OK)
{
rt_hw_serial_isr(serial, RT_SERIAL_EVENT_TX_DMADONE);
return size;
}
else
{
return 0;
}
}
return 0;
}
#endif /* RT_SERIAL_USING_DMA */
static const struct rt_uart_ops acm32_uart_ops =
{
_uart_configure,
_uart_control,
_uart_putc,
_uart_getc,
#ifdef RT_SERIAL_USING_DMA
_uart_dma_transmit,
#endif
};
#ifdef RT_SERIAL_USING_DMA
static void DMA_Configuration(struct rt_serial_device *serial, rt_uint32_t flag)
{
struct rt_serial_rx_fifo *rx_fifo;
DMA_HandleTypeDef *DMA_Handle;
struct dma_config *dma_config;
struct acm32_uart *uart;
RT_ASSERT(serial != RT_NULL);
uart = rt_container_of(serial, struct acm32_uart, serial);
if (RT_DEVICE_FLAG_DMA_RX == flag)
{
DMA_Handle = &uart->dma_rx.handle;
dma_config = uart->config->dma_rx;
}
else if (RT_DEVICE_FLAG_DMA_TX == flag)
{
DMA_Handle = &uart->dma_tx.handle;
dma_config = uart->config->dma_tx;
}
else
{
return;
}
DMA_Handle->Instance = dma_config->Instance;
if (RT_DEVICE_FLAG_DMA_RX == flag)
{
DMA_Handle->Init.Data_Flow = DMA_DATA_FLOW_P2M;
DMA_Handle->Init.Mode = DMA_NORMAL;
DMA_Handle->Init.Source_Inc = DMA_SOURCE_ADDR_INCREASE_DISABLE;
DMA_Handle->Init.Desination_Inc = DMA_DST_ADDR_INCREASE_ENABLE;
}
else if (RT_DEVICE_FLAG_DMA_TX == flag)
{
DMA_Handle->Init.Data_Flow = DMA_DATA_FLOW_M2P;
DMA_Handle->Init.Mode = DMA_NORMAL;
DMA_Handle->Init.Source_Inc = DMA_SOURCE_ADDR_INCREASE_ENABLE;
DMA_Handle->Init.Desination_Inc = DMA_DST_ADDR_INCREASE_DISABLE;
}
DMA_Handle->Init.Request_ID = dma_config->request;
DMA_Handle->Init.Source_Width = DMA_SRC_WIDTH_BYTE;
DMA_Handle->Init.Desination_Width = DMA_DST_WIDTH_BYTE;
if (HAL_DMA_Init(DMA_Handle) != HAL_OK)
{
RT_ASSERT(0);
}
if (RT_DEVICE_FLAG_DMA_RX == flag)
{
__HAL_LINK_DMA(uart->handle, HDMA_Rx, uart->dma_rx.handle);
}
else if (RT_DEVICE_FLAG_DMA_TX == flag)
{
__HAL_LINK_DMA(uart->handle, HDMA_Tx, uart->dma_tx.handle);
}
/* enable interrupt */
if (flag == RT_DEVICE_FLAG_DMA_RX)
{
rx_fifo = (struct rt_serial_rx_fifo *)serial->serial_rx;
/* Start DMA transfer */
if (HAL_UART_Receive_DMA(&(uart->handle), rx_fifo->buffer, serial->config.bufsz) != HAL_OK)
{
/* Transfer error in reception process */
RT_ASSERT(0);
}
}
}
#endif /* RT_SERIAL_USING_DMA */
enum
{
#ifdef BSP_USING_UART1
UART1_INDEX,
#endif
#ifdef BSP_USING_UART2
UART2_INDEX,
#endif
#ifdef BSP_USING_UART3
UART3_INDEX,
#endif
UART_MAX_INDEX,
};
static struct acm32_uart_config uart_config[] =
{
#ifdef BSP_USING_UART1
UART1_CONFIG,
#endif
#ifdef BSP_USING_UART2
UART2_CONFIG,
#endif
#ifdef BSP_USING_UART3
UART3_CONFIG,
#endif
};
static struct acm32_uart uart_obj[sizeof(uart_config) / sizeof(uart_config[0])] = {0};
#ifdef RT_SERIAL_USING_DMA
static void uart_get_dma_config(void)
{
#if defined(BSP_USING_UART1)
#if defined(BSP_UART1_RX_USING_DMA)
static struct dma_config uart1_rx_dma_conf = UART1_DMA_RX_CONFIG;
uart_obj[UART1_INDEX].uart_dma_flag |= RT_DEVICE_FLAG_DMA_RX;
uart_config[UART1_INDEX].dma_rx = &uart1_rx_dma_conf;
#endif /* BSP_UART1_RX_USING_DMA */
#if defined(BSP_UART1_TX_USING_DMA)
static struct dma_config uart1_tx_dma_conf = UART1_DMA_TX_CONFIG;
uart_obj[UART1_INDEX].uart_dma_flag |= RT_DEVICE_FLAG_DMA_TX;
uart_config[UART1_INDEX].dma_tx = &uart1_tx_dma_conf;
#endif /* BSP_UART1_TX_USING_DMA */
#endif /* BSP_USING_UART1 */
#if defined(BSP_USING_UART2)
#if defined(BSP_UART2_RX_USING_DMA)
static struct dma_config uart2_rx_dma_conf = UART2_DMA_RX_CONFIG;
uart_obj[UART2_INDEX].uart_dma_flag |= RT_DEVICE_FLAG_DMA_RX;
uart_config[UART2_INDEX].dma_rx = &uart2_rx_dma_conf;
#endif /* BSP_UART2_RX_USING_DMA */
#if defined(BSP_UART2_TX_USING_DMA)
static struct dma_config uart2_tx_dma_conf = UART2_DMA_TX_CONFIG;
uart_obj[UART2_INDEX].uart_dma_flag |= RT_DEVICE_FLAG_DMA_TX;
uart_config[UART2_INDEX].dma_tx = &uart2_tx_dma_conf;
#endif /* BSP_UART2_TX_USING_DMA */
#endif /* BSP_USING_UART2 */
#if defined(BSP_USING_UART3)
#if defined(BSP_UART3_RX_USING_DMA)
static struct dma_config uart3_rx_dma_conf = UART3_DMA_RX_CONFIG;
uart_obj[UART3_INDEX].uart_dma_flag |= RT_DEVICE_FLAG_DMA_RX;
uart_config[UART3_INDEX].dma_rx = &uart3_rx_dma_conf;
#endif /* BSP_UART3_RX_USING_DMA */
#if defined(BSP_UART3_TX_USING_DMA)
static struct dma_config uart3_tx_dma_conf = UART3_DMA_TX_CONFIG;
uart_obj[UART3_INDEX].uart_dma_flag |= RT_DEVICE_FLAG_DMA_TX;
uart_config[UART3_INDEX].dma_tx = &uart3_tx_dma_conf;
#endif /* BSP_UART3_TX_USING_DMA */
#endif /* BSP_USING_UART3 */
}
#endif
rt_err_t rt_hw_uart_init(void)
{
rt_size_t obj_num = sizeof(uart_obj) / sizeof(struct acm32_uart);
struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT;
rt_err_t rc = RT_EOK;
#ifdef RT_SERIAL_USING_DMA
uart_get_dma_config();
#endif
for (int i = 0; i < obj_num; i++)
{
uart_obj[i].config = &uart_config[i];
uart_obj[i].serial.ops = &acm32_uart_ops;
uart_obj[i].serial.config = config;
/* register UART device */
rc = rt_hw_serial_register(&uart_obj[i].serial, uart_obj[i].config->name,
RT_DEVICE_FLAG_RDWR
| RT_DEVICE_FLAG_INT_RX
| RT_DEVICE_FLAG_INT_TX
| uart_obj[i].uart_dma_flag
, NULL);
RT_ASSERT(rc == RT_EOK);
}
return rc;
}
static void uart_isr(struct rt_serial_device *serial)
{
struct acm32_uart *uart = rt_container_of(serial, struct acm32_uart, serial);
RT_ASSERT(serial != RT_NULL);
/* receive interrupt enabled */
if (uart->handle.Instance->IE & UART_IE_RXI)
{
if (uart->handle.Instance->RIS & UART_RIS_RXI)
{
rt_hw_serial_isr(serial, RT_SERIAL_EVENT_RX_IND);
}
}
#ifdef RT_SERIAL_USING_DMA
if (uart->handle.Instance->IE & UART_IE_RTI) /* Receive TimeOut Interrupt */
{
dma_uart_rx_idle_isr(serial);
/* Clear RTI Status */
uart->handle.Instance->ICR = UART_ICR_RTI;
}
#endif /* RT_SERIAL_USING_DMA */
if (uart->handle.Instance->IE & UART_IE_TXI && \
uart->handle.Instance->RIS & UART_RIS_TXI)
{
/* Clear TXI Status */
uart->handle.Instance->ICR = UART_ICR_TXI;
if (serial->parent.open_flag & RT_DEVICE_FLAG_INT_TX)
{
rt_hw_serial_isr(serial, RT_SERIAL_EVENT_TX_DONE);
}
/* Disable TX interrupt */
uart->handle.Instance->IE &= ~UART_IE_TXI;
}
}
#if defined(BSP_USING_UART1)
void UART1_IRQHandler(void)
{
/* enter interrupt */
rt_interrupt_enter();
uart_isr(&uart_obj[UART1_INDEX].serial);
/* leave interrupt */
rt_interrupt_leave();
}
#endif /* BSP_USING_UART1 */
#if defined(BSP_USING_UART2)
void UART2_IRQHandler(void)
{
/* enter interrupt */
rt_interrupt_enter();
uart_isr(&uart_obj[UART2_INDEX].serial);
/* leave interrupt */
rt_interrupt_leave();
}
#endif /* BSP_USING_UART1 */
#if defined(BSP_USING_UART3)
void UART3_IRQHandler(void)
{
/* enter interrupt */
rt_interrupt_enter();
uart_isr(&uart_obj[UART3_INDEX].serial);
/* leave interrupt */
rt_interrupt_leave();
}
#endif /* BSP_USING_UART1 */
#ifdef RT_SERIAL_USING_DMA
void DMA_IRQHandler(void)
{
/* enter interrupt */
rt_interrupt_enter();
for (int i = 0; i < UART_MAX_INDEX; i++)
{
if (DMA->RAW_INT_TC_STATUS & (1 << uart_obj[i].config->dma_rx->channel))
{
dma_rx_done_isr(&uart_obj[i].serial);
break;
}
if (DMA->RAW_INT_TC_STATUS & (1 << uart_obj[i].config->dma_tx->channel))
{
DMA->INT_TC_CLR |= 1 << (uart_obj[i].config->dma_tx->channel); /* clear channel0 TC flag */
break;
}
}
/* leave interrupt */
rt_interrupt_leave();
}
#endif /* RT_SERIAL_USING_DMA */
void HAL_UART_MspInit(UART_HandleTypeDef *huart)
{
struct acm32_uart *uart;
GPIO_InitTypeDef GPIO_Uart;
RT_ASSERT(huart != RT_NULL);
/* get uart object */
uart = rt_container_of(huart, struct acm32_uart, handle);
/* Enable Clock */
System_Module_Enable(uart->config->enable_id);
/* Initialization GPIO */
GPIO_Uart.Pin = uart->config->tx_pin;
GPIO_Uart.Mode = GPIO_MODE_AF_PP;
GPIO_Uart.Pull = GPIO_PULLUP;
GPIO_Uart.Alternate = GPIO_FUNCTION_2;
HAL_GPIO_Init(uart->config->tx_port, &GPIO_Uart);
GPIO_Uart.Pin = uart->config->rx_pin;
GPIO_Uart.Mode = GPIO_MODE_AF_PP;
GPIO_Uart.Pull = GPIO_PULLUP;
GPIO_Uart.Alternate = GPIO_FUNCTION_2;
HAL_GPIO_Init(uart->config->rx_port, &GPIO_Uart);
/* NVIC Config */
NVIC_ClearPendingIRQ(uart->config->irq_type);
NVIC_SetPriority(uart->config->irq_type, 5);
NVIC_EnableIRQ(uart->config->irq_type);
}
#endif /* RT_USING_SEARIAL */
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2021-08-25 AisinoChip First Version
*/
#include <board.h>
#include <rtthread.h>
#include <rtdevice.h>
#ifdef RT_USING_WDT
#include "board.h"
struct acm32_wdt_obj
{
union
{
WDT_HandleTypeDef wdt;
IWDT_HandleTypeDef iwdt;
} handle;
rt_uint16_t is_start;
rt_uint16_t type;
rt_watchdog_t watchdog;
};
#define TYPE_WDT 0
#define TYPE_IWDT 1
#define IWDT_FREQ (32000)
#ifdef BSP_USING_WDT
#define WDT_NAME "wdt"
static struct acm32_wdt_obj acm32_wdt;
#endif
#ifdef BSP_USING_IWDT
#define IWDT_NAME "iwdt"
static struct acm32_wdt_obj acm32_iwdt;
#endif
static struct rt_watchdog_ops ops;
rt_inline rt_base_t calc_wdt_divisor_load(rt_uint32_t freq, rt_uint32_t sec, rt_uint32_t *divisor, rt_uint32_t *load)
{
rt_uint32_t freqMaxSec = 0;
rt_uint32_t minFreqDiv = WDT_DIVISOR_NONE;
freqMaxSec = RT_UINT32_MAX / freq;
while (minFreqDiv <= WDT_DIVISOR_128)
{
if (sec < freqMaxSec)
{
break;
}
minFreqDiv ++;
freqMaxSec = RT_UINT32_MAX / freq * (1 << minFreqDiv);
}
if (minFreqDiv > WDT_DIVISOR_128)
{
return -1;
}
*divisor = minFreqDiv;
*load = sec * (freq >> minFreqDiv);
return 0;
}
rt_inline rt_base_t calc_iwdt_divisor_load(rt_uint32_t freq, rt_uint32_t sec, rt_uint32_t *divisor, rt_uint32_t *load)
{
rt_uint32_t minFreqDiv = IWDT_CLOCK_PRESCALER_4;
rt_uint32_t freqMaxMs = 0;
freqMaxMs = IWDT_RELOAD_MAX_VALUE * 1000 / (freq >> (2 + minFreqDiv));
while (minFreqDiv <= IWDT_CLOCK_PRESCALER_256)
{
if (sec * 1000 < freqMaxMs)
{
break;
}
minFreqDiv ++;
freqMaxMs = IWDT_RELOAD_MAX_VALUE * 1000 / (freq >> (2 + minFreqDiv));
}
if (minFreqDiv > IWDT_CLOCK_PRESCALER_256)
{
return -1;
}
*divisor = minFreqDiv;
if (sec < 1000)
{
*load = (sec * 1000) * IWDT_RELOAD_MAX_VALUE / freqMaxMs;
}
else
{
*load = (sec) * IWDT_RELOAD_MAX_VALUE / freqMaxMs / 1000;
}
return 0;
}
rt_inline rt_uint32_t calc_wdt_timeout(rt_uint32_t freq, rt_uint32_t divisor, rt_uint32_t count)
{
/* 1 / ( freq / (1<<divisor) ) * (count) */
return (rt_uint32_t)(((rt_uint64_t)count) * (1 << divisor) / (freq));
}
rt_inline rt_uint32_t calc_iwdt_timeout(rt_uint32_t freq, rt_uint32_t divisor, rt_uint32_t count)
{
/* (freq >> (2+divisor)) / IWDT_RELOAD_MAX_VALUE * count */
return count / (freq >> (2 + divisor));
}
static rt_err_t wdt_init(rt_watchdog_t *wdt)
{
return RT_EOK;
}
static rt_err_t wdt_control(rt_watchdog_t *wdt, int cmd, void *arg)
{
struct acm32_wdt_obj *wdtObj = NULL;
rt_uint32_t timer_clk_hz;
rt_uint32_t divisor, load;
RT_ASSERT(wdt != RT_NULL);
wdtObj = rt_container_of(wdt, struct acm32_wdt_obj, watchdog);
timer_clk_hz = System_Get_APBClock();
switch (cmd)
{
/* feed the watchdog */
case RT_DEVICE_CTRL_WDT_KEEPALIVE:
if (TYPE_WDT == wdtObj->type)
{
HAL_WDT_Feed(&wdtObj->handle.wdt);
}
else
{
HAL_IWDT_Kick_Watchdog_Wait_For_Done(&wdtObj->handle.iwdt);
}
break;
/* set watchdog timeout, seconds */
case RT_DEVICE_CTRL_WDT_SET_TIMEOUT:
if (TYPE_WDT == wdtObj->type)
{
if (calc_wdt_divisor_load(timer_clk_hz, (*((rt_uint32_t *)arg)), &divisor, &load))
{
return -RT_ERROR;
}
wdtObj->handle.wdt.Init.WDTDivisor = (WDT_DIVISOR)divisor;
wdtObj->handle.wdt.Init.WDTLoad = load;
HAL_WDT_Init(&wdtObj->handle.wdt);
}
else
{
if (calc_iwdt_divisor_load(IWDT_FREQ, (*((rt_uint32_t *)arg)), &divisor, &load))
{
return -RT_ERROR;
}
wdtObj->handle.iwdt.Instance = IWDT;
wdtObj->handle.iwdt.Init.Prescaler = divisor;
wdtObj->handle.iwdt.Init.Reload = load;
}
if (wdtObj->is_start)
{
if (TYPE_WDT == wdtObj->type)
{
HAL_WDT_Init(&wdtObj->handle.wdt);
}
else
{
HAL_IWDT_Init(&wdtObj->handle.iwdt);
}
}
break;
case RT_DEVICE_CTRL_WDT_GET_TIMELEFT:
if (TYPE_WDT == wdtObj->type)
{
(*((rt_uint32_t *)arg)) = calc_wdt_timeout(timer_clk_hz,
wdtObj->handle.wdt.Init.WDTDivisor,
wdtObj->handle.wdt.Instance->COUNT);
}
else
{
return -RT_EINVAL;
}
break;
case RT_DEVICE_CTRL_WDT_GET_TIMEOUT:
if (TYPE_WDT == wdtObj->type)
{
(*((rt_uint32_t *)arg)) = calc_wdt_timeout(timer_clk_hz,
wdtObj->handle.wdt.Init.WDTDivisor,
wdtObj->handle.wdt.Init.WDTLoad);
}
else
{
(*((rt_uint32_t *)arg)) = calc_iwdt_timeout(IWDT_FREQ,
wdtObj->handle.iwdt.Init.Prescaler,
wdtObj->handle.iwdt.Init.Reload);
}
break;
case RT_DEVICE_CTRL_WDT_START:
if (TYPE_WDT == wdtObj->type)
{
wdtObj->handle.wdt.Instance = WDT;
wdtObj->handle.wdt.Init.WDTMode = WDT_MODE_RST;
wdtObj->handle.wdt.Init.WDTINTCLRTIME = 0xffff;
HAL_WDT_Init(&wdtObj->handle.wdt);
HAL_WDT_Start(&wdtObj->handle.wdt);
}
else
{
wdtObj->handle.iwdt.Instance->CMDR = IWDT_ENABLE_COMMAND;
wdtObj->handle.iwdt.Init.Window = IWDT_RELOAD_MAX_VALUE; /* window function disabled when window >= reload */
wdtObj->handle.iwdt.Init.Wakeup = IWDT_RELOAD_MAX_VALUE; /* wakeup function disabled when wakeup >= reload */
HAL_IWDT_Init(&wdtObj->handle.iwdt);
}
wdtObj->is_start = 1;
break;
case RT_DEVICE_CTRL_WDT_STOP:
if (TYPE_WDT == wdtObj->type)
{
HAL_WDT_Stop(&wdtObj->handle.wdt);
}
else
{
wdtObj->handle.iwdt.Instance->CMDR = IWDT_DISABLE_COMMAND;
}
wdtObj->is_start = 0;
break;
default:
return -RT_ERROR;
}
return RT_EOK;
}
int rt_wdt_init(void)
{
ops.init = &wdt_init;
ops.control = &wdt_control;
#ifdef BSP_USING_WDT
acm32_wdt.type = TYPE_WDT;
acm32_wdt.is_start = 0;
acm32_wdt.watchdog.ops = &ops;
if (rt_hw_watchdog_register(&acm32_wdt.watchdog, WDT_NAME, RT_DEVICE_FLAG_DEACTIVATE, RT_NULL) != RT_EOK)
{
return -RT_ERROR;
}
#endif
#ifdef BSP_USING_IWDT
acm32_iwdt.type = TYPE_IWDT;
acm32_iwdt.is_start = 0;
acm32_iwdt.watchdog.ops = &ops;
if (rt_hw_watchdog_register(&acm32_iwdt.watchdog, IWDT_NAME, RT_DEVICE_FLAG_DEACTIVATE, RT_NULL) != RT_EOK)
{
return -RT_ERROR;
}
#endif
return RT_EOK;
}
INIT_BOARD_EXPORT(rt_wdt_init);
#endif /* RT_USING_WDT */
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2021-08-23 AisinoChip first implementation
*/
#include <rtthread.h>
#include "board.h"
#define led1_gpio GPIOA
#define led1_pin (GPIO_PIN_1)
void rt_hw_led_init(void)
{
GPIO_InitTypeDef GPIO_Handle;
GPIO_Handle.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_Handle.Pull = GPIO_PULLUP;
GPIO_Handle.Alternate = GPIO_FUNCTION_0;
GPIO_Handle.Pin = led1_pin;
HAL_GPIO_Init(led1_gpio, &GPIO_Handle);
}
void rt_hw_led_on(rt_uint32_t n)
{
switch (n)
{
case 0:
HAL_GPIO_WritePin(led1_gpio, led1_pin, GPIO_PIN_SET);
break;
default:
break;
}
}
void rt_hw_led_off(rt_uint32_t n)
{
switch (n)
{
case 0:
HAL_GPIO_WritePin(led1_gpio, led1_pin, GPIO_PIN_CLEAR);
break;
default:
break;
}
}
void rt_hw_led_toggle(rt_uint32_t n)
{
static rt_bool_t stat = RT_TRUE;
if (stat == RT_TRUE)
{
rt_hw_led_on(n);
stat = RT_FALSE;
}
else
{
rt_hw_led_off(n);
stat = RT_TRUE;
}
}
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2021-08-25 AisinoChip the first version
*/
#ifndef __LED_H__
#define __LED_H__
#include <rtthread.h>
void rt_hw_led_init(void);
void rt_hw_led_on(rt_uint32_t led);
void rt_hw_led_off(rt_uint32_t led);
void rt_hw_led_toggle(rt_uint32_t led);
#endif
/*###ICF### Section handled by ICF editor, don't touch! ****/
/*-Editor annotation file-*/
/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */
/*-Specials-*/
define symbol __ICFEDIT_intvec_start__ = 0x00000000;
/*-Memory Regions-*/
define symbol __ICFEDIT_region_ROM_start__ = 0x00000000;
define symbol __ICFEDIT_region_ROM_end__ = 0x0001FFFF;
define symbol __ICFEDIT_region_RAM_start__ = 0x20000000;
define symbol __ICFEDIT_region_RAM_end__ = 0x20007FFF;
/*-Sizes-*/
define symbol __ICFEDIT_size_cstack__ = 0x0800;
define symbol __ICFEDIT_size_heap__ = 0x0000;
/**** End of ICF editor section. ###ICF###*/
define memory mem with size = 4G;
define region ROM_region = mem:[from __ICFEDIT_region_ROM_start__ to __ICFEDIT_region_ROM_end__];
define region RAM_region = mem:[from __ICFEDIT_region_RAM_start__ to __ICFEDIT_region_RAM_end__];
define block CSTACK with alignment = 8, size = __ICFEDIT_size_cstack__ { };
define block HEAP with alignment = 8, size = __ICFEDIT_size_heap__ { };
initialize by copy { readwrite };
do not initialize { section .noinit };
place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec };
place in ROM_region { readonly };
place in RAM_region { readwrite,
block CSTACK, block HEAP };
export symbol __ICFEDIT_region_RAM_start__;
export symbol __ICFEDIT_region_RAM_end__;
/*
* linker script for ACM32F030 with GNU ld
*/
/* describes the location and size of blocks of memory in the target. */
MEMORY
{
ROM (rx) : ORIGIN = 0x00000000, LENGTH = 128k /* 128KB flash */
RAM (rw) : ORIGIN = 0x20000000, LENGTH = 32k /* 32KB sram */
}
/* Program Entry, set to mark it as "used" and avoid gc */
ENTRY(Reset_Handler)
_system_stack_size = 0x800;
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 = .;
/* section information for initial. */
. = ALIGN(4);
__rt_init_start = .;
KEEP(*(SORT(.rti_fn*)))
__rt_init_end = .;
. = ALIGN(4);
PROVIDE(__ctors_start__ = .);
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array))
PROVIDE(__ctors_end__ = .);
. = ALIGN(4);
_etext = .;
} > ROM = 8
/* .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 = .;
} > ROM
__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*)
PROVIDE(__dtors_start__ = .);
KEEP(*(SORT(.dtors.*)))
KEEP(*(.dtors))
PROVIDE(__dtors_end__ = .);
. = ALIGN(4);
/* This is used by the startup in order to initialize the .data secion */
_edata = . ;
} > RAM
.stack :
{
. = ALIGN(8);
_sstack = .;
. = . + _system_stack_size;
. = ALIGN(8);
_estack = .;
} > RAM
__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)
} > RAM
__bss_end = .;
_end = .;
/* 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) }
}
; *************************************************************
; *** Scatter-Loading Description File generated by uVision ***
; *************************************************************
LR_IROM1 0x00000000 0x00020000 { ; load region size_region
ER_IROM1 0x00000000 0x00020000 { ; load address = execution address
*.o (RESET, +First)
*(InRoot$$Sections)
.ANY (+RO)
.ANY (+XO)
}
RW_IRAM1 0x20000000 0x00008000 { ; RW data
.ANY (+RW +ZI)
}
}
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2021-08-26 AisinoChip first version
*/
#ifndef __TIM_CONFIG_H__
#define __TIM_CONFIG_H__
#include <rtthread.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef TIM_DEV_INFO_CONFIG
#define TIM_DEV_INFO_CONFIG \
{ \
.maxfreq = 1000000, \
.minfreq = 2000, \
.maxcnt = 0xFFFF, \
.cntmode = HWTIMER_CNTMODE_UP, \
}
#endif /* TIM_DEV_INFO_CONFIG */
#ifdef BSP_USING_TIM1
#ifndef TIM1_CONFIG
#define TIM1_CONFIG \
{ \
.tim_handle.Instance = TIM1, \
.tim_irqn = TIM1_BRK_UP_TRG_COM_IRQn, \
.name = "timer1", \
}
#endif /* TIM1_CONFIG */
#endif /* BSP_USING_TIM1 */
#ifdef BSP_USING_TIM3
#ifndef TIM3_CONFIG
#define TIM3_CONFIG \
{ \
.tim_handle.Instance = TIM3, \
.tim_irqn = TIM3_IRQn, \
.name = "timer3", \
}
#endif /* TIM3_CONFIG */
#endif /* BSP_USING_TIM3 */
#ifdef BSP_USING_TIM6
#ifndef TIM6_CONFIG
#define TIM6_CONFIG \
{ \
.tim_handle.Instance = TIM6, \
.tim_irqn = TIM6_IRQn, \
.name = "timer6", \
}
#endif /* TIM6_CONFIG */
#endif /* BSP_USING_TIM6 */
#ifdef BSP_USING_TIM14
#ifndef TIM14_CONFIG
#define TIM14_CONFIG \
{ \
.tim_handle.Instance = TIM14, \
.tim_irqn = TIM14_IRQn, \
.name = "timer14", \
}
#endif /* TIM14_CONFIG */
#endif /* BSP_USING_TIM14 */
#ifdef BSP_USING_TIM15
#ifndef TIM15_CONFIG
#define TIM15_CONFIG \
{ \
.tim_handle.Instance = TIM15, \
.tim_irqn = TIM15_IRQn, \
.name = "timer15", \
}
#endif /* TIM15_CONFIG */
#endif /* BSP_USING_TIM15 */
#ifdef BSP_USING_TIM16
#ifndef TIM16_CONFIG
#define TIM16_CONFIG \
{ \
.tim_handle.Instance = TIM16, \
.tim_irqn = TIM16_IRQn, \
.name = "timer16", \
}
#endif /* TIM16_CONFIG */
#endif /* BSP_USING_TIM16 */
#ifdef BSP_USING_TIM17
#ifndef TIM17_CONFIG
#define TIM17_CONFIG \
{ \
.tim_handle.Instance = TIM17, \
.tim_irqn = TIM17_IRQn, \
.name = "timer17", \
}
#endif /* TIM17_CONFIG */
#endif /* BSP_USING_TIM17 */
#ifdef __cplusplus
}
#endif
#endif /* __TIM_CONFIG_H__ */
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2021-08-23 AisinoChip the first version
*/
#ifndef __UART_CONFIG_H__
#define __UART_CONFIG_H__
#include <rtthread.h>
#include "board.h"
#ifdef __cplusplus
extern "C" {
#endif
#if defined(RT_USING_SERIAL)
#if defined(BSP_USING_UART1)
#if defined(RT_SERIAL_USING_DMA)
#if defined(BSP_UART1_RX_USING_DMA)
#ifndef UART1_DMA_RX_CONFIG
#define UART1_DMA_RX_CONFIG \
{ \
.Instance = UART1_RX_DMA_INSTANCE, \
.dma_rcc = UART1_RX_DMA_RCC, \
.dma_irq = UART1_RX_DMA_IRQ, \
.channel = UART1_RX_DMA_CHANNEL, \
.request = UART1_RX_DMA_REQUEST, \
}
#endif /* UART1_DMA_RX_CONFIG */
#endif /* BSP_UART1_RX_USING_DMA */
#if defined(BSP_UART1_TX_USING_DMA)
#ifndef UART1_DMA_TX_CONFIG
#define UART1_DMA_TX_CONFIG \
{ \
.Instance = UART1_TX_DMA_INSTANCE, \
.dma_rcc = UART1_TX_DMA_RCC, \
.dma_irq = UART1_TX_DMA_IRQ, \
.channel = UART1_RX_DMA_CHANNEL, \
.request = UART1_RX_DMA_REQUEST, \
}
#endif /* UART1_DMA_TX_CONFIG */
#endif /* BSP_UART1_TX_USING_DMA */
#endif /* RT_SERIAL_USING_DMA */
#ifndef UART1_CONFIG
#define UART1_CONFIG \
{ \
.name = "uart1", \
.Instance = UART1, \
.irq_type = UART1_IRQn, \
.enable_id = EN_UART1, \
.tx_port = UART1_TX_PORT, \
.rx_port = UART1_RX_PORT, \
.tx_pin = UART1_TX_PIN, \
.rx_pin = UART1_RX_PIN, \
}
#endif /* UART1_CONFIG */
#endif /* BSP_USING_UART1 */
#if defined(BSP_USING_UART2)
#if defined(RT_SERIAL_USING_DMA)
#if defined(BSP_UART2_RX_USING_DMA)
#ifndef UART2_DMA_RX_CONFIG
#define UART2_DMA_RX_CONFIG \
{ \
.Instance = UART2_RX_DMA_INSTANCE, \
.dma_rcc = UART2_RX_DMA_RCC, \
.dma_irq = UART2_RX_DMA_IRQ, \
.channel = UART2_RX_DMA_CHANNEL, \
.request = UART2_RX_DMA_REQUEST, \
}
#endif /* UART2_DMA_RX_CONFIG */
#endif /* BSP_UART2_RX_USING_DMA */
#if defined(BSP_UART2_TX_USING_DMA)
#ifndef UART2_DMA_TX_CONFIG
#define UART2_DMA_TX_CONFIG \
{ \
.Instance = UART2_TX_DMA_INSTANCE, \
.dma_rcc = UART2_TX_DMA_RCC, \
.dma_irq = UART2_TX_DMA_IRQ, \
.channel = UART2_TX_DMA_CHANNEL, \
.request = UART2_TX_DMA_REQUEST, \
}
#endif /* UART2_DMA_TX_CONFIG */
#endif /* BSP_UART2_TX_USING_DMA */
#endif /* RT_SERIAL_USING_DMA */
#ifndef UART2_CONFIG
#define UART2_CONFIG \
{ \
.name = "uart2", \
.Instance = UART2, \
.irq_type = UART2_IRQn, \
.enable_id = EN_UART2, \
.tx_port = UART2_TX_PORT, \
.rx_port = UART2_RX_PORT, \
.tx_pin = UART2_TX_PIN, \
.rx_pin = UART2_RX_PIN, \
}
#endif /* UART2_CONFIG */
#endif /* BSP_USING_UART2 */
#if defined(BSP_USING_UART3)
#if defined(RT_SERIAL_USING_DMA)
#if defined(BSP_UART3_RX_USING_DMA)
#ifndef UART3_DMA_RX_CONFIG
#define UART3_DMA_RX_CONFIG \
{ \
.Instance = UART3_RX_DMA_INSTANCE, \
.dma_rcc = UART3_RX_DMA_RCC, \
.dma_irq = UART3_RX_DMA_IRQ, \
.channel = UART3_RX_DMA_CHANNEL, \
.request = UART3_RX_DMA_REQUEST, \
}
#endif /* UART3_DMA_RX_CONFIG */
#endif /* BSP_UART3_RX_USING_DMA */
#if defined(BSP_UART3_TX_USING_DMA)
#ifndef UART3_DMA_TX_CONFIG
#define UART3_DMA_TX_CONFIG \
{ \
.Instance = UART3_TX_DMA_INSTANCE, \
.dma_rcc = UART3_TX_DMA_RCC, \
.dma_irq = UART3_TX_DMA_IRQ, \
.channel = UART3_TX_DMA_CHANNEL, \
.request = UART3_TX_DMA_REQUEST, \
}
#endif /* UART3_DMA_TX_CONFIG */
#endif /* BSP_UART3_TX_USING_DMA */
#endif /* RT_SERIAL_USING_DMA */
#ifndef UART3_CONFIG
#define UART3_CONFIG \
{ \
.name = "uart3", \
.Instance = UART3, \
.irq_type = UART3_IRQn, \
.enable_id = EN_UART3, \
.tx_port = UART3_TX_PORT, \
.rx_port = UART3_RX_PORT, \
.tx_pin = UART3_TX_PIN, \
.rx_pin = UART3_RX_PIN, \
}
#endif /* UART3_CONFIG */
#endif /* BSP_USING_UART3 */
#ifdef __cplusplus
}
#endif
#endif /* RT_USING_SERIAL */
#endif /* __UART_CONFIG_H__ */
此差异已折叠。
此差异已折叠。
此差异已折叠。
/**************************************************************************//**
* @file core_cmFunc.h
* @brief CMSIS Cortex-M Core Function Access Header File
* @version V4.30
* @date 20. October 2015
******************************************************************************/
/* Copyright (c) 2009 - 2015 ARM LIMITED
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- 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.
- Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
---------------------------------------------------------------------------*/
#if defined ( __ICCARM__ )
#pragma system_include /* treat file as system include file for MISRA check */
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
#pragma clang system_header /* treat file as system include file */
#endif
#ifndef __CORE_CMFUNC_H
#define __CORE_CMFUNC_H
/* ########################### Core Function Access ########################### */
/** \ingroup CMSIS_Core_FunctionInterface
\defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions
@{
*/
/*------------------ RealView Compiler -----------------*/
#if defined ( __CC_ARM )
#include "cmsis_armcc.h"
/*------------------ ARM Compiler V6 -------------------*/
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
#include "cmsis_armcc_V6.h"
/*------------------ GNU Compiler ----------------------*/
#elif defined ( __GNUC__ )
#include "cmsis_gcc.h"
/*------------------ ICC Compiler ----------------------*/
#elif defined ( __ICCARM__ )
#include <cmsis_iar.h>
/*------------------ TI CCS Compiler -------------------*/
#elif defined ( __TMS470__ )
#include <cmsis_ccs.h>
/*------------------ TASKING Compiler ------------------*/
#elif defined ( __TASKING__ )
/*
* The CMSIS functions have been implemented as intrinsics in the compiler.
* Please use "carm -?i" to get an up to date list of all intrinsics,
* Including the CMSIS ones.
*/
/*------------------ COSMIC Compiler -------------------*/
#elif defined ( __CSMC__ )
#include <cmsis_csm.h>
#endif
/*@} end of CMSIS_Core_RegAccFunctions */
#endif /* __CORE_CMFUNC_H */
/**************************************************************************//**
* @file core_cmInstr.h
* @brief CMSIS Cortex-M Core Instruction Access Header File
* @version V4.30
* @date 20. October 2015
******************************************************************************/
/* Copyright (c) 2009 - 2015 ARM LIMITED
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- 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.
- Neither the name of ARM 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 COPYRIGHT HOLDERS AND 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.
---------------------------------------------------------------------------*/
#if defined ( __ICCARM__ )
#pragma system_include /* treat file as system include file for MISRA check */
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
#pragma clang system_header /* treat file as system include file */
#endif
#ifndef __CORE_CMINSTR_H
#define __CORE_CMINSTR_H
/* ########################## Core Instruction Access ######################### */
/** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface
Access to dedicated instructions
@{
*/
/*------------------ RealView Compiler -----------------*/
#if defined ( __CC_ARM )
#include "cmsis_armcc.h"
/*------------------ ARM Compiler V6 -------------------*/
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
#include "cmsis_armcc_V6.h"
/*------------------ GNU Compiler ----------------------*/
#elif defined ( __GNUC__ )
#include "cmsis_gcc.h"
/*------------------ ICC Compiler ----------------------*/
#elif defined ( __ICCARM__ )
#include <cmsis_iar.h>
/*------------------ TI CCS Compiler -------------------*/
#elif defined ( __TMS470__ )
#include <cmsis_ccs.h>
/*------------------ TASKING Compiler ------------------*/
#elif defined ( __TASKING__ )
/*
* The CMSIS functions have been implemented as intrinsics in the compiler.
* Please use "carm -?i" to get an up to date list of all intrinsics,
* Including the CMSIS ones.
*/
/*------------------ COSMIC Compiler -------------------*/
#elif defined ( __CSMC__ )
#include <cmsis_csm.h>
#endif
/*@}*/ /* end of group CMSIS_Core_InstructionInterface */
#endif /* __CORE_CMINSTR_H */
此差异已折叠。
/*
******************************************************************************
* @file ACM32Fxx_HAL.h
* @version V1.0.0
* @date 2020
* @brief HAL Config header file.
******************************************************************************
*/
#ifndef __ACM32FXX_HAL_H__
#define __ACM32FXX_HAL_H__
#ifdef __GNUC__
#define __weak __attribute__((weak))
#endif
/*
Uncomment the line below according to the target device used in your application
*/
#define ACM32F0X0 /*!< ACM32F0x0xx */
/* #define ACM32FP0X */ /*!< ACM32FP0xxx */
/** @addtogroup Device_Included
* @{
*/
#if defined(ACM32F0X0)
#include "ACM32F0x0.h"
#elif defined(ACM32FP0X)
#include "ACM32FP0X.h"
#else
#error "Please select first the target device used in your application (in ACM32Fxx_HAL.h file)"
#endif
/**
* @}
*/
/*
* @brief HAL Status structures definition
*/
typedef enum
{
HAL_OK = 0x00U,
HAL_ERROR = 0x01U,
HAL_BUSY = 0x02U,
HAL_TIMEOUT = 0x03U
}HAL_StatusTypeDef;
/* USE FULL ASSERT */
#define USE_FULL_ASSERT (1)
#define HAL_DMA_MODULE_ENABLED
#define HAL_GPIO_MODULE_ENABLED
#define HAL_UART_MODULE_ENABLED
#define HAL_ADC_MODULE_ENABLED
#define HAL_DAC_MODULE_ENABLED
#define HAL_EXTI_MODULE_ENABLED
#define HAL_I2C_MODULE_ENABLED
#define HAL_I2S_MODULE_ENABLED
#define HAL_IWDT_MODULE_ENABLED
#define HAL_RTC_MODULE_ENABLED
#define HAL_SPI_MODULE_ENABLED
#define HAL_TIMER_MODULE_ENABLED
#define HAL_EFLASH_MODULE_ENABLED
#define HAL_OPA_MODULE_ENABLED
#define HAL_COMP_MODULE_ENABLED
#define HAL_CAN_MODULE_ENABLED
#define HAL_LPUART_MODULE_ENABLED
#define HAL_WDT_MODULE_ENABLED
#define HAL_FSUSB_MODULE_ENABLED
#define HAL_LCD_MODULE_ENABLED
//#define HAL_SYSTICK_ENABLED
#define HAL_CRC_ENABLED
#define HAL_TKEY_MODULE_ENABLED
#define HAL_AES_ENABLED
#define HAL_HRNG_ENABLED
#define HAL_DIV_ENABLED
#include "System_ACM32F0x0.h"
#ifdef HAL_DMA_MODULE_ENABLED
#include "HAL_DMA.h"
#endif
#ifdef HAL_GPIO_MODULE_ENABLED
#include "HAL_GPIO.h"
#endif
#ifdef HAL_UART_MODULE_ENABLED
#include "HAL_UART.h"
#include "HAL_UART_EX.h"
#endif
#ifdef HAL_ADC_MODULE_ENABLED
#include "HAL_ADC.h"
#endif
#ifdef HAL_EXTI_MODULE_ENABLED
#include "HAL_EXTI.h"
#endif
#ifdef HAL_I2C_MODULE_ENABLED
#include "HAL_I2C.h"
#endif
#ifdef HAL_RTC_MODULE_ENABLED
#include "HAL_RTC.h"
#endif
#ifdef HAL_SPI_MODULE_ENABLED
#include "HAL_SPI.h"
#endif
#ifdef HAL_IWDT_MODULE_ENABLED
#include "HAL_IWDT.h"
#endif
#ifdef HAL_EFLASH_MODULE_ENABLED
#include "HAL_EFLASH.h"
#include "HAL_EFlash_EX.h"
#endif
#ifdef HAL_OPA_MODULE_ENABLED
#include "HAL_OPA.h"
#endif
#ifdef HAL_COMP_MODULE_ENABLED
#include "HAL_COMP.h"
#endif
#ifdef HAL_CAN_MODULE_ENABLED
#include "HAL_CAN.h"
#endif
#ifdef HAL_LPUART_MODULE_ENABLED
#include "HAL_LPUART.h"
#endif
#ifdef HAL_WDT_MODULE_ENABLED
#include "HAL_WDT.h"
#endif
#ifdef HAL_TIMER_MODULE_ENABLED
#include "HAL_TIMER.h"
#include "HAL_TIMER_EX.h"
#endif
#ifdef HAL_LCD_MODULE_ENABLED
#include "HAL_LCD.h"
#endif
#ifdef HAL_TKEY_MODULE_ENABLED
#include "HAL_TKEY.h"
#endif
#ifdef HAL_CRC_ENABLED
#include "HAL_CRC.h"
#endif
#ifdef HAL_AES_ENABLED
#include "HAL_AES.h"
#endif
#ifdef HAL_HRNG_ENABLED
#include "HAL_HRNG.h"
#endif
#ifdef HAL_DIV_ENABLED
#include "HAL_DIV.h"
#endif
#endif
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
......@@ -25,4 +25,4 @@ do not initialize { section .noinit };
place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec };
place in ROM_region { readonly };
place in RAM_region { readwrite, last block CSTACK};
place in RAM_region { readwrite, last block CSTACK};
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册