diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/README.md b/Ubiquitous/XiUOS/board/cortex-m4-emulator/README.md
index 67a84ead2..66842efb5 100644
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/README.md
+++ b/Ubiquitous/XiUOS/board/cortex-m4-emulator/README.md
@@ -1,10 +1,24 @@
-# 从零开始构建矽璓工业物联操作系统:使用ARM架构的STM32F407-discovery开发板
+# 从零开始构建矽璓工业物联操作系统:使用ARM架构的cortex-m4 emulator
-[XiUOS](http://xuos.io/) (X Industrial Ubiquitous Operating System) 矽璓工业物联操作系统是一款面向工业物联场景的泛在操作系统,来自泛在操作系统研究计划。所谓泛在操作系统(UOS: Ubiquitous Operating Systems),是支持互联网时代人机物融合泛在计算应用模式的新型操作系统,是传统操作系统概念的泛化与延伸。在泛在操作系统技术体系中,不同的泛在计算设备和泛在应用场景需要符合各自特性的不同UOS,XiUOS即是面向工业物联场景的一种UOS,主要由一个极简的微型实时操作系统(RTOS)内核和其上的智能工业物联框架构成,支持工业物联网(IIoT: Industrial Internet of Things)应用。
+[XiUOS](http://xuos.io/) (X Industrial Ubiquitous Operating System) 矽璓XiUOS是一款面向智慧车间的工业物联网操作系统,主要由一个极简的微型实时操作系统内核和其上的工业物联框架构成,通过高效管理工业物联网设备、支撑工业物联应用,在生产车间内实现智能化的“感知环境、联网传输、知悉识别、控制调整”,促进以工业设备和工业控制系统为核心的人、机、物深度互联,帮助提升生产线的数字化和智能化水平。
->注:最新版README请访问[从零开始构建矽璓工业物联操作系统:使用ARM架构的STM32F407-discovery开发板](https://blog.csdn.net/AIIT_Ubiquitous/article/details/116209686),如博客内容与本地文档有差异,以网站内容为准。
-## 开发环境搭建
+
+## 1. 简介
+
+QEMU 是一个通用的开源模拟器和虚拟化工具。目前QEMU已经可以较完整的支持ARM cortex-m4架构。XiUOS同样支持运行在QEMU上
+
+| 硬件 | 描述 |
+| -------- | ------------- |
+| 芯片型号 | netduinoplus2 |
+| 架构 | cortex-m4 |
+| 主频 | 168MHz |
+| 片内SRAM | 100+KB |
+| 外设支持 | UART、GPIO |
+
+
+
+## 2. 开发环境搭建
### 推荐使用:
@@ -59,15 +73,16 @@ git clone https://git.trustie.net/xuos/xiuos.git
```
打开源码文件包可以看到以下目录:
-| 名称 | 说明 |
-| -- | -- |
-| application | 应用代码 |
-| board | 板级支持包 |
-| framework | 应用框架 |
-| fs | 文件系统 |
-| kernel | 内核源码 |
-| resources | 驱动文件 |
-| tool | 系统工具 |
+
+| 名称 | 说明 |
+| ----------- | ---------- |
+| application | 应用代码 |
+| board | 板级支持包 |
+| framework | 应用框架 |
+| fs | 文件系统 |
+| kernel | 内核源码 |
+| resources | 驱动文件 |
+| tool | 系统工具 |
使用VScode打开代码,具体操作步骤为:在源码文件夹下打开系统终端,输入`code .`即可打开VScode开发环境,如下图所示:
@@ -75,6 +90,7 @@ git clone https://git.trustie.net/xuos/xiuos.git
+
### 裁减配置工具的下载
裁减配置工具:
@@ -101,113 +117,85 @@ ARM: arm-none-eabi(`gcc version 6.3.1`),默认安装到Ubuntu的/usr/bin/arm
$ sudo apt install gcc-arm-none-eabi
```
-# 在STM32F407-DISCOVERY上创建第一个应用 --helloworld
-## 1. 简介
-| 硬件 | 描述 |
-| -- | -- |
-|芯片型号| Stm32F407VGT6|
-|CPU|arm cortex-m|
-|主频| 168MHz |
-|片内SRAM| 192KB |
-|片上FLASH| 1MB |
-| 外设 | -- |
-| | ADC、DAC、USB、GPIO、UART、SPI、SDIO、RTC、CAN、DMA、MAC、I²C、WDT、Timer等 |
-
-XiUOS板级驱动当前支持使用GPIO、I2C、LCD、USB、RTC、SPI、Timer、UART和WDT等。
-
-## 2. 编译说明
+## 3. 编译说明
### 编辑环境:`Ubuntu18.04`
### 编译工具链:`arm-none-eabi-gcc`
+
使用`VScode`打开工程的方法有多种,本文介绍一种快捷键,在项目目录下将`code .`输入linux系统命令终端即可打开目标项目
-修改`applications`文件夹下`main.c`
-在输出函数中写入 `Hello, world!!! \n Running on stm32f407-st-discovery`完成代码编辑。
-
-
编译步骤:
1.在VScode命令终端中执行以下命令,生成配置文件
```c
- make BOARD=stm32f407-st-discovery menuconfig
+ make BOARD=cortex-m4-emulator menuconfig
```
2.在menuconfig界面配置需要关闭和开启的功能,按回车键进入下级菜单,按Y键选中需要开启的功能,按N键选中需要关闭的功能,配置结束后保存并退出(本例旨在演示简单的输出例程,所以没有需要配置的选项,双击快捷键ESC退出配置)
-
+
+
+
退出时选择`yes`保存上面所配置的内容,如下图所示:
-
+
+
+
3.继续执行以下命令,进行编译
-```c
-make BOARD=stm32f407-st-discovery
+```
+make BOARD=cortex-m4-emulator
```
-4.如果编译正确无误,会产生XiUOS_stm32f407-st-discovery.elf、XiUOS_stm32f407-st-discovery.bin文件。其中XiUOS_stm32f407-st-discovery.bin需要烧写到设备中进行运行。
+4.如果编译正确无误,会产生XiUOS_cortex-m4-emulator.elf、XiUOS_cortex-m4-emulator.bin文件。
-## 3. 烧写及执行
-将 BOARD=stm32f407-st-discovery开发板SWD经 st-link 转接到USB接口,然后使用st-flash工具进行烧写bin文件。
-
+## 4. 运行
-### 烧写工具
-
-ARM:ST-LINK(ST-LINK V2实物如图,可在购物网站搜索关键字购买)
-
-
-
-下载并以下执行命令以下命令安装st-link工具(本文使用v1.5.1版本),下载地址为:[http://101.36.126.201:8011/stlink.zip](http://101.36.126.201:8011/stlink.zip)
+### 4.1 安装QEMU
```
-sudo apt install libusb-dev
-sudo apt install libusb-1.0-0-dev
-sudo apt install cmake
-cd stlink
-make
-cd build/Release && make install DESTDIR=_install
+sudo apt install qemu-system-arm
```
-将生成的st-flash(在stlink/build/Release/bin文件夹下)复制到/usr/bin下就可使用了
+### 4.2 运行结果
-代码根目录下执行st-flash工具烧录
+通过以下命令启动QEMU并加载XiUOS ELF文件
```
-sudo st-flash write build/XiUOS_stm32f407-st-discovery.bin 0x8000000
+qemu-system-arm -machine netduinoplus2 -nographic -kernel build/XiUOS_cortex-m4-emulator.elf
```
-此外,推荐用户使用putty作为终端工具,安装命令如下:
+QEMU运行起来后将会在终端上看到信息打印输出
-```c
-sudo apt install putty
+
+
+
+
+### 4.3 调试
+
+通过QEMU可以方便的对XiUOS进行调试,首先安装gdb调试工具
+
+```
+sudo apt install gdb-multiarch
```
-打开putty配置串口信息
+并通过以下命令启动QEMU
-```c
-sudo puty
+```
+qemu-system-arm -machine netduinoplus2 -nographic -kernel build/XiUOS_cortex-m4-emulator.elf -s -S
```
-选择ttyUSB0(这个端口号根据具体情况而定),配置波特率为115200。
+然后要重新开启另一个linux系统终端一个终端,执行`riscv-none-embed-gdb`命令
-
-
-注意:选择正确的终端端口号,最后可以执行以下命令,清除配置文件和编译生成的文件
-
-```c
-make BOARD=stm32f407-st-discovery distclean
```
-
-### 3.1 运行结果
-
-如果编译 & 烧写无误,将会在串口终端上看到信息打印输出,(终端串口引脚为PB6、PB7)。
-
-
+gdb-multiarch build/XiUOS_cortex-m4-emulator.elf -ex "target remote localhost:1234"
+```
\ No newline at end of file
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/img/main.png b/Ubiquitous/XiUOS/board/cortex-m4-emulator/img/main.png
index d19d92c16..9c1102b06 100644
Binary files a/Ubiquitous/XiUOS/board/cortex-m4-emulator/img/main.png and b/Ubiquitous/XiUOS/board/cortex-m4-emulator/img/main.png differ
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/img/menuconfig.png b/Ubiquitous/XiUOS/board/cortex-m4-emulator/img/menuconfig.png
new file mode 100644
index 000000000..b48b7ded8
Binary files /dev/null and b/Ubiquitous/XiUOS/board/cortex-m4-emulator/img/menuconfig.png differ
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/img/menuconfig1.png b/Ubiquitous/XiUOS/board/cortex-m4-emulator/img/menuconfig1.png
index d150ebc96..449200f64 100644
Binary files a/Ubiquitous/XiUOS/board/cortex-m4-emulator/img/menuconfig1.png and b/Ubiquitous/XiUOS/board/cortex-m4-emulator/img/menuconfig1.png differ
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/img/menuconfig2.jpg b/Ubiquitous/XiUOS/board/cortex-m4-emulator/img/menuconfig2.jpg
deleted file mode 100644
index e5529e40b..000000000
Binary files a/Ubiquitous/XiUOS/board/cortex-m4-emulator/img/menuconfig2.jpg and /dev/null differ
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/img/putty.png b/Ubiquitous/XiUOS/board/cortex-m4-emulator/img/putty.png
deleted file mode 100644
index 3acd6c861..000000000
Binary files a/Ubiquitous/XiUOS/board/cortex-m4-emulator/img/putty.png and /dev/null differ
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/img/st-link.png b/Ubiquitous/XiUOS/board/cortex-m4-emulator/img/st-link.png
deleted file mode 100644
index 4284399d1..000000000
Binary files a/Ubiquitous/XiUOS/board/cortex-m4-emulator/img/st-link.png and /dev/null differ
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/img/stm32f407-st-discovery.png b/Ubiquitous/XiUOS/board/cortex-m4-emulator/img/stm32f407-st-discovery.png
deleted file mode 100644
index 473bf779b..000000000
Binary files a/Ubiquitous/XiUOS/board/cortex-m4-emulator/img/stm32f407-st-discovery.png and /dev/null differ
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/img/terminal.png b/Ubiquitous/XiUOS/board/cortex-m4-emulator/img/terminal.png
index a1bd89aa3..db05b9149 100644
Binary files a/Ubiquitous/XiUOS/board/cortex-m4-emulator/img/terminal.png and b/Ubiquitous/XiUOS/board/cortex-m4-emulator/img/terminal.png differ
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/Kconfig b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/Kconfig
index cfea7e201..6bfb3a99d 100644
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/Kconfig
+++ b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/Kconfig
@@ -1,11 +1,3 @@
-menuconfig BSP_USING_CAN
-bool "Using CAN device"
-default n
-select RESOURCES_CAN
-if BSP_USING_CAN
-source "$BSP_DIR/third_party_driver/can/Kconfig"
-endif
-
menuconfig BSP_USING_DMA
bool "Using DMA device"
default y
@@ -21,56 +13,6 @@ if BSP_USING_GPIO
source "$BSP_DIR/third_party_driver/gpio/Kconfig"
endif
-menuconfig BSP_USING_I2C
-bool "Using I2C device"
-default n
-select RESOURCES_I2C
-if BSP_USING_I2C
-source "$BSP_DIR/third_party_driver/i2c/Kconfig"
-endif
-
-menuconfig BSP_USING_LCD
-bool "Using LCD device"
-default n
-select BSP_USING_SPI1
-select RESOURCES_LCD
-if BSP_USING_LCD
-source "$BSP_DIR/third_party_driver/lcd/Kconfig"
-endif
-
-menuconfig BSP_USING_RTC
-bool "Using RTC device"
-default n
-select RESOURCES_RTC
-if BSP_USING_RTC
-source "$BSP_DIR/third_party_driver/rtc/Kconfig"
-endif
-
-menuconfig BSP_USING_SDIO
-bool "Using SDIO device"
-default n
-select RESOURCES_SDIO
-if BSP_USING_SDIO
-source "$BSP_DIR/third_party_driver/sdio/Kconfig"
-endif
-
-menuconfig BSP_USING_SPI
-bool "Using SPI device"
-default n
-select RESOURCES_SPI
-select BSP_USING_DMA
-if BSP_USING_SPI
-source "$BSP_DIR/third_party_driver/spi/Kconfig"
-endif
-
-menuconfig BSP_USING_HWTIMER
-bool "Using HWTIMER device"
-default n
-select RESOURCES_HWTIMER
-if BSP_USING_HWTIMER
-source "$BSP_DIR/third_party_driver/timer/Kconfig"
-endif
-
menuconfig BSP_USING_UART
bool "Using UART device"
default y
@@ -78,28 +20,3 @@ select RESOURCES_SERIAL
if BSP_USING_UART
source "$BSP_DIR/third_party_driver/uart/Kconfig"
endif
-
-menuconfig BSP_USING_USB
-bool "Using USB device"
-default n
-select BSP_USING_USBH
-select RESOURCES_USB
-select RESOURCES_USB_HOST
-select USBH_MSTORAGE
-select RESOURCES_USB_DEVICE
-if BSP_USING_USB
-source "$BSP_DIR/third_party_driver/usb/Kconfig"
-endif
-
-menuconfig BSP_USING_LWIP
-bool "Using LwIP device"
-default n
-select RESOURCES_LWIP
-
-menuconfig BSP_USING_WDT
-bool "Using WATCHDOG device"
-default y
-select RESOURCES_WDT
-if BSP_USING_WDT
-source "$BSP_DIR/third_party_driver/watchdog/Kconfig"
-endif
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/can/Kconfig b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/can/Kconfig
deleted file mode 100644
index a6889b417..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/can/Kconfig
+++ /dev/null
@@ -1,12 +0,0 @@
-
-config CAN_BUS_NAME_1
- string "can bus name"
- default "can1"
-
-config CAN_DRIVER_NAME
- string "can driver name"
- default "can1_drv"
-
-config CAN_1_DEVICE_NAME_1
- string "can bus 1 device 1 name"
- default "can1_dev1"
\ No newline at end of file
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/can/Makefile b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/can/Makefile
deleted file mode 100644
index b7b250381..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/can/Makefile
+++ /dev/null
@@ -1,4 +0,0 @@
-SRC_FILES := hardware_can.c connect_can.c
-
-
-include $(KERNEL_ROOT)/compiler.mk
\ No newline at end of file
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/can/connect_can.c b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/can/connect_can.c
deleted file mode 100644
index 6b4b6959c..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/can/connect_can.c
+++ /dev/null
@@ -1,275 +0,0 @@
-/*
- * Copyright (c) Guangzhou Xingyi Electronic Technology Co., Ltd
- *
- * Change Logs:
- * Date Author Notes
- * 2014-7-4 alientek first version
- */
-
-/**
-* @file connect_can.c
-* @brief support stm32f407-discovery-board can function and register to bus framework
-* @version 1.0
-* @author AIIT XUOS Lab
-* @date 2021-04-22
-*/
-
-/*************************************************
-File name: can.c
-Description: support can configure and spi bus register function
-Others: hardware/can/can.c for references
-History:
-1. Date: 2021-04-22
-Author: AIIT XUOS Lab
-Modification:
-1. support stm32f407-discovery-board spi configure, write and read
-2. support stm32f407-discovery-board spi bus device and driver register
-*************************************************/
-
-#include "connect_can.h"
-#include "misc.h"
-#include "hardware_rcc.h"
-#include "hardware_gpio.h"
-
-static struct CanSendConfigure can_send_deconfig =
-{
- .stdid = 0x55,
- .exdid = 0x00,
- .ide = 0 ,
- .rtr = 0,
- .data_lenth = 8
-};
-
-static void CanGPIOInit(void)
-{
- CAN_FilterInitTypeDef can1_filter;
- GPIO_InitTypeDef gpio_initstructure;
- CAN_InitTypeDef can_initstruction;
-
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);
-
- gpio_initstructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_8;
- gpio_initstructure.GPIO_Mode = GPIO_Mode_AF;
- gpio_initstructure.GPIO_OType = GPIO_OType_PP;
- gpio_initstructure.GPIO_Speed = GPIO_Speed_100MHz;
- gpio_initstructure.GPIO_PuPd = GPIO_PuPd_UP;
- GPIO_Init(GPIOB, &gpio_initstructure);
-
- GPIO_PinAFConfig(GPIOB, GPIO_PinSource9, GPIO_AF_CAN1);
- GPIO_PinAFConfig(GPIOB, GPIO_PinSource8, GPIO_AF_CAN1);
-}
-
-static void Can1NvicConfig(void)
-{
- NVIC_InitTypeDef can_nvic_config;
-
- can_nvic_config.NVIC_IRQChannel = CAN1_RX0_IRQn;
- can_nvic_config.NVIC_IRQChannelPreemptionPriority = 2;
- can_nvic_config.NVIC_IRQChannelSubPriority = 2;
- can_nvic_config.NVIC_IRQChannelCmd = ENABLE;
- CAN_ITConfig(CAN1, CAN_IT_FMP0, ENABLE);
- NVIC_Init(&can_nvic_config);
-}
-
-static uint32 CanModeInit(void *drv, struct BusConfigureInfo *configure_info)
-{
- NULL_PARAM_CHECK(drv);
- NULL_PARAM_CHECK(configure_info);
- CAN_FilterInitTypeDef can1_filter;
- CAN_InitTypeDef can_initstruction;
-
- struct CanDriverConfigure * config = ( struct CanDriverConfigure *)configure_info->private_data;
-
- can_initstruction.CAN_TTCM = DISABLE;
- can_initstruction.CAN_ABOM = ENABLE;
- can_initstruction.CAN_AWUM = DISABLE;
- can_initstruction.CAN_NART = ENABLE;
- can_initstruction.CAN_TXFP = DISABLE;
- can_initstruction.CAN_Mode = config->mode;
- can_initstruction.CAN_RFLM = DISABLE;
- can_initstruction.CAN_SJW = config->tsjw;
- can_initstruction.CAN_BS1 = config->tbs1;
- can_initstruction.CAN_BS2 = config->tbs2;
- can_initstruction.CAN_Prescaler = config->brp;
-
- CAN_Init(CAN1, &can_initstruction);
-
- can1_filter.CAN_FilterNumber=0;
- can1_filter.CAN_FilterMode=CAN_FilterMode_IdMask;
- can1_filter.CAN_FilterScale=CAN_FilterScale_32bit;
- can1_filter.CAN_FilterIdHigh=0x0000;
- can1_filter.CAN_FilterIdLow=0x0000;
- can1_filter.CAN_FilterMaskIdHigh=0x0000;
- can1_filter.CAN_FilterMaskIdLow=0x0000;
- can1_filter.CAN_FilterFIFOAssignment=CAN_Filter_FIFO0;
- can1_filter.CAN_FilterActivation=ENABLE;
- CAN_FilterInit(&can1_filter);
-
- #ifdef CAN_USING_INTERRUPT
- Can1NvicConfig();
- #endif
-
- return 0;
-}
-
-static uint32 CanSendMsg(void * dev , struct BusBlockWriteParam *write_param )
-{
- NULL_PARAM_CHECK(write_param);
-
- uint8 *data = (uint8 * ) write_param->buffer;
- u8 mbox;
- u16 i = 0;
- u16 timer_count = 1000;
- CanTxMsg tx_data;
- tx_data.StdId = 0x55;
- tx_data.ExtId = 0x00;
- tx_data.IDE = 0;
- tx_data.RTR = 0;
- tx_data.DLC = write_param->size;
-
- for(i = 0;ibuffer;
- CanRxMsg msg;
- if(CAN_MessagePending(CAN1, CAN_FIFO0) == 0)
- return 0;
- CAN_Receive(CAN1, CAN_FIFO0, &msg);
- for(i = 0 ;isize = msg.DLC ;
-
- return msg.DLC;
-}
-
-static struct CanDevDone dev_done =
-{
- .open = NONE,
- .close = NONE,
- .write = CanSendMsg,
- .read = CanRecvMsg
-};
-
-static struct CanHardwareDevice dev;
-
- #ifdef CAN_USING_INTERRUPT
-void CAN1_RX0_IRQHandler(void)
-{
- CanRxMsg rxmsg;
- int i = 0;
- CAN_Receive(CAN1, 0, &rxmsg);
- for(i = 0;i<8;i++)
- KPrintf("rxbuf [%d] = :%d",i,rxmsg.Data[i]);
-}
-DECLARE_HW_IRQ(CAN1_RX0_IRQn, CAN1_RX0_IRQHandler, NONE);
-#endif
-
-static int BoardCanBusInit(struct Stm32Can *stm32can_bus, struct CanDriver *can_driver)
-{
- x_err_t ret = EOK;
-
- /*Init the can bus */
- ret = CanBusInit(&stm32can_bus->can_bus, stm32can_bus->bus_name);
- if (EOK != ret) {
- KPrintf("Board_can_init canBusInit error %d\n", ret);
- return ERROR;
- }
-
- /*Init the can driver*/
- ret = CanDriverInit(can_driver, CAN_DRIVER_NAME);
- if (EOK != ret) {
- KPrintf("Board_can_init canDriverInit error %d\n", ret);
- return ERROR;
- }
- /*Attach the can driver to the can bus*/
- ret = CanDriverAttachToBus(CAN_DRIVER_NAME, stm32can_bus->bus_name);
- if (EOK != ret) {
- KPrintf("Board_can_init CanDriverAttachToBus error %d\n", ret);
- return ERROR;
- }
-
- return ret;
-}
-
-static x_err_t HwCanDeviceAttach(const char *bus_name, const char *device_name)
-{
- NULL_PARAM_CHECK(bus_name);
- NULL_PARAM_CHECK(device_name);
-
- x_err_t result;
- struct CanHardwareDevice *can_device;
-
- /* attach the device to can bus*/
- can_device = (struct CanHardwareDevice *)x_malloc(sizeof(struct CanHardwareDevice));
- CHECK(can_device);
- memset(can_device, 0, sizeof(struct CanHardwareDevice));
- can_device->dev_done = &dev_done;
-
- result = CanDeviceRegister(can_device, NONE, device_name);
- if (EOK != result) {
- KPrintf("board_can_init canDeviceInit device %s error %d\n", "can1", result);
- return ERROR;
- }
-
- result = CanDeviceAttachToBus(device_name, bus_name);
- if (result != EOK) {
- SYS_ERR("%s attach to %s faild, %d\n", device_name, bus_name, result);
- }
-
- CHECK(result == EOK);
-
- KPrintf("%s attach to %s done\n", device_name, bus_name);
-
- return result;
-}
-
-struct Stm32Can can1;
-
- int Stm32HwCanBusInit(void)
-{
- x_err_t ret = EOK;
- struct Stm32Can *stm32_can_bus;
-
- static struct CanDriver can_driver;
- memset(&can_driver, 0, sizeof(struct CanDriver));
-
- can_driver.configure = CanModeInit;
-
- CanGPIOInit();
- stm32_can_bus = &can1;
- stm32_can_bus->instance = CAN1;
- stm32_can_bus->bus_name = CAN_BUS_NAME_1;
- stm32_can_bus->can_bus.private_data = &can1;
-
- ret = BoardCanBusInit(stm32_can_bus, &can_driver);
-
- if (EOK != ret) {
- KPrintf(" can_bus_init %s error ret %u\n", stm32_can_bus->bus_name, ret);
- return ERROR;
- }
-
- ret = HwCanDeviceAttach(CAN_BUS_NAME_1,CAN_1_DEVICE_NAME_1);
- if (EOK != ret) {
- KPrintf(" HwCanDeviceAttach %s error ret %u\n", stm32_can_bus->bus_name, ret);
- return ERROR;
- }
- return EOK;
-}
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/can/hardware_can.c b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/can/hardware_can.c
deleted file mode 100644
index 8dfd96d57..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/can/hardware_can.c
+++ /dev/null
@@ -1,1719 +0,0 @@
-/**
- ******************************************************************************
- * @file stm32f4xx_can.c
- * @author MCD Application Team
- * @version V1.0.0
- * @date 30-September-2011
- * @brief This file is based on stm32f4xx_can.c
- * This file provides firmware functions to manage the following
- * functionalities of the Controller area network (CAN) peripheral:
- * - Initialization and Configuration
- * - CAN Frames Transmission
- * - CAN Frames Reception
- * - Operation modes switch
- * - Error management
- * - Interrupts and flags
- *
- * @verbatim
- *
- * ===================================================================
- * How to use this driver
- * ===================================================================
-
- * 1. Enable the CAN controller interface clock using
- * RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE); for CAN1
- * and RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN2, ENABLE); for CAN2
- * @note In case you are using CAN2 only, you have to enable the CAN1 clock.
- *
- * 2. CAN pins configuration
- * - Enable the clock for the CAN GPIOs using the following function:
- * RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOx, ENABLE);
- * - Connect the involved CAN pins to AF9 using the following function
- * GPIO_PinAFConfig(GPIOx, GPIO_PinSourcex, GPIO_AF_CANx);
- * - Configure these CAN pins in alternate function mode by calling
- * the function GPIO_Init();
- *
- * 3. Initialise and configure the CAN using CAN_Init() and
- * CAN_FilterInit() functions.
- *
- * 4. Transmit the desired CAN frame using CAN_Transmit() function.
- *
- * 5. Check the transmission of a CAN frame using CAN_TransmitStatus()
- * function.
- *
- * 6. Cancel the transmission of a CAN frame using CAN_CancelTransmit()
- * function.
- *
- * 7. Receive a CAN frame using CAN_Recieve() function.
- *
- * 8. Release the receive FIFOs using CAN_FIFORelease() function.
- *
- * 9. Return the number of pending received frames using
- * CAN_MessagePending() function.
- *
- * 10. To control CAN events you can use one of the following two methods:
- * - Check on CAN flags using the CAN_GetFlagStatus() function.
- * - Use CAN interrupts through the function CAN_ITConfig() at
- * initialization phase and CAN_GetITStatus() function into
- * interrupt routines to check if the event has occurred or not.
- * After checking on a flag you should clear it using CAN_ClearFlag()
- * function. And after checking on an interrupt event you should
- * clear it using CAN_ClearITPendingBit() function.
- *
- *
- * @endverbatim
- *
- ******************************************************************************
- * @attention
- *
- * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
- * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
- * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
- * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
- * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
- * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
- *
- * © COPYRIGHT 2011 STMicroelectronics
- ******************************************************************************
- */
-
-/**
-* @file: hardware_can.c
-* @brief: support hardware can function
-* @version: 1.0
-* @author: AIIT XUOS Lab
-* @date: 2021/4/25
-*/
-
-/*************************************************
-File name: hardware_can.c
-Description: support hardware can function
-Others:
-History:
-1. Date: 2021-04-25
-Author: AIIT XUOS Lab
-Modification:
-1. rename stm32f4xx_can.c for XiUOS
-*************************************************/
-
-/* Includes ------------------------------------------------------------------*/
-#include
-#include
-#include
-
-/** @addtogroup STM32F4xx_StdPeriph_Driver
- * @{
- */
-
-/** @defgroup CAN
- * @brief CAN driver modules
- * @{
- */
-/* Private typedef -----------------------------------------------------------*/
-/* Private define ------------------------------------------------------------*/
-
-/* CAN Master Control Register bits */
-#define MCR_DBF ((uint32_t)0x00010000) /* software master reset */
-
-/* CAN Mailbox Transmit Request */
-#define TMIDxR_TXRQ ((uint32_t)0x00000001) /* Transmit mailbox request */
-
-/* CAN Filter Master Register bits */
-#define FMR_FINIT ((uint32_t)0x00000001) /* Filter init mode */
-
-/* Time out for INAK bit */
-#define INAK_TIMEOUT ((uint32_t)0x0000FFFF)
-/* Time out for SLAK bit */
-#define SLAK_TIMEOUT ((uint32_t)0x0000FFFF)
-
-/* Flags in TSR register */
-#define CAN_FLAGS_TSR ((uint32_t)0x08000000)
-/* Flags in RF1R register */
-#define CAN_FLAGS_RF1R ((uint32_t)0x04000000)
-/* Flags in RF0R register */
-#define CAN_FLAGS_RF0R ((uint32_t)0x02000000)
-/* Flags in MSR register */
-#define CAN_FLAGS_MSR ((uint32_t)0x01000000)
-/* Flags in ESR register */
-#define CAN_FLAGS_ESR ((uint32_t)0x00F00000)
-
-/* Mailboxes definition */
-#define CAN_TXMAILBOX_0 ((uint8_t)0x00)
-#define CAN_TXMAILBOX_1 ((uint8_t)0x01)
-#define CAN_TXMAILBOX_2 ((uint8_t)0x02)
-
-#define CAN_MODE_MASK ((uint32_t) 0x00000003)
-
-/* Private macro -------------------------------------------------------------*/
-/* Private variables ---------------------------------------------------------*/
-/* Private function prototypes -----------------------------------------------*/
-/* Private functions ---------------------------------------------------------*/
-static ITStatus CheckITStatus(uint32_t CAN_Reg, uint32_t It_Bit);
-
-/** @defgroup CAN_Private_Functions
- * @{
- */
-
-/** @defgroup CAN_Group1 Initialization and Configuration functions
- * @brief Initialization and Configuration functions
- *
-@verbatim
- ===============================================================================
- Initialization and Configuration functions
- ===============================================================================
- This section provides functions allowing to
- - Initialize the CAN peripherals : Prescaler, operating mode, the maximum number
- of time quanta to perform resynchronization, the number of time quanta in
- Bit Segment 1 and 2 and many other modes.
- Refer to @ref CAN_InitTypeDef for more details.
- - Configures the CAN reception filter.
- - Select the start bank filter for slave CAN.
- - Enables or disables the Debug Freeze mode for CAN
- - Enables or disables the CAN Time Trigger Operation communication mode
-
-@endverbatim
- * @{
- */
-
-/**
- * @brief Deinitializes the CAN peripheral registers to their default reset values.
- * @param CANx: where x can be 1 or 2 to select the CAN peripheral.
- * @retval None.
- */
-void CAN_DeInit(CAN_TypeDef* CANx)
-{
- /* Check the parameters */
- assert_param(IS_CAN_ALL_PERIPH(CANx));
-
- if (CANx == CAN1)
- {
- /* Enable CAN1 reset state */
- RCC_APB1PeriphResetCmd(RCC_APB1Periph_CAN1, ENABLE);
- /* Release CAN1 from reset state */
- RCC_APB1PeriphResetCmd(RCC_APB1Periph_CAN1, DISABLE);
- }
- else
- {
- /* Enable CAN2 reset state */
- RCC_APB1PeriphResetCmd(RCC_APB1Periph_CAN2, ENABLE);
- /* Release CAN2 from reset state */
- RCC_APB1PeriphResetCmd(RCC_APB1Periph_CAN2, DISABLE);
- }
-}
-
-/**
- * @brief Initializes the CAN peripheral according to the specified
- * parameters in the CAN_InitStruct.
- * @param CANx: where x can be 1 or 2 to select the CAN peripheral.
- * @param CAN_InitStruct: pointer to a CAN_InitTypeDef structure that contains
- * the configuration information for the CAN peripheral.
- * @retval Constant indicates initialization succeed which will be
- * CAN_InitStatus_Failed or CAN_InitStatus_Success.
- */
-uint8_t CAN_Init(CAN_TypeDef* CANx, CAN_InitTypeDef* CAN_InitStruct)
-{
- uint8_t InitStatus = CAN_InitStatus_Failed;
- uint32_t wait_ack = 0x00000000;
- /* Check the parameters */
- assert_param(IS_CAN_ALL_PERIPH(CANx));
- assert_param(IS_FUNCTIONAL_STATE(CAN_InitStruct->CAN_TTCM));
- assert_param(IS_FUNCTIONAL_STATE(CAN_InitStruct->CAN_ABOM));
- assert_param(IS_FUNCTIONAL_STATE(CAN_InitStruct->CAN_AWUM));
- assert_param(IS_FUNCTIONAL_STATE(CAN_InitStruct->CAN_NART));
- assert_param(IS_FUNCTIONAL_STATE(CAN_InitStruct->CAN_RFLM));
- assert_param(IS_FUNCTIONAL_STATE(CAN_InitStruct->CAN_TXFP));
- assert_param(IS_CAN_MODE(CAN_InitStruct->CAN_Mode));
- assert_param(IS_CAN_SJW(CAN_InitStruct->CAN_SJW));
- assert_param(IS_CAN_BS1(CAN_InitStruct->CAN_BS1));
- assert_param(IS_CAN_BS2(CAN_InitStruct->CAN_BS2));
- assert_param(IS_CAN_PRESCALER(CAN_InitStruct->CAN_Prescaler));
-
- /* Exit from sleep mode */
- CANx->MCR &= (~(uint32_t)CAN_MCR_SLEEP);
-
- /* Request initialisation */
- CANx->MCR |= CAN_MCR_INRQ ;
-
- /* Wait the acknowledge */
- while (((CANx->MSR & CAN_MSR_INAK) != CAN_MSR_INAK) && (wait_ack != INAK_TIMEOUT))
- {
- wait_ack++;
- }
-
- /* Check acknowledge */
- if ((CANx->MSR & CAN_MSR_INAK) != CAN_MSR_INAK)
- {
- InitStatus = CAN_InitStatus_Failed;
- }
- else
- {
- /* Set the time triggered communication mode */
- if (CAN_InitStruct->CAN_TTCM == ENABLE)
- {
- CANx->MCR |= CAN_MCR_TTCM;
- }
- else
- {
- CANx->MCR &= ~(uint32_t)CAN_MCR_TTCM;
- }
-
- /* Set the automatic bus-off management */
- if (CAN_InitStruct->CAN_ABOM == ENABLE)
- {
- CANx->MCR |= CAN_MCR_ABOM;
- }
- else
- {
- CANx->MCR &= ~(uint32_t)CAN_MCR_ABOM;
- }
-
- /* Set the automatic wake-up mode */
- if (CAN_InitStruct->CAN_AWUM == ENABLE)
- {
- CANx->MCR |= CAN_MCR_AWUM;
- }
- else
- {
- CANx->MCR &= ~(uint32_t)CAN_MCR_AWUM;
- }
-
- /* Set the no automatic retransmission */
- if (CAN_InitStruct->CAN_NART == ENABLE)
- {
- CANx->MCR |= CAN_MCR_NART;
- }
- else
- {
- CANx->MCR &= ~(uint32_t)CAN_MCR_NART;
- }
-
- /* Set the receive FIFO locked mode */
- if (CAN_InitStruct->CAN_RFLM == ENABLE)
- {
- CANx->MCR |= CAN_MCR_RFLM;
- }
- else
- {
- CANx->MCR &= ~(uint32_t)CAN_MCR_RFLM;
- }
-
- /* Set the transmit FIFO priority */
- if (CAN_InitStruct->CAN_TXFP == ENABLE)
- {
- CANx->MCR |= CAN_MCR_TXFP;
- }
- else
- {
- CANx->MCR &= ~(uint32_t)CAN_MCR_TXFP;
- }
-
- /* Set the bit timing register */
- CANx->BTR = (uint32_t)((uint32_t)CAN_InitStruct->CAN_Mode << 30) | \
- ((uint32_t)CAN_InitStruct->CAN_SJW << 24) | \
- ((uint32_t)CAN_InitStruct->CAN_BS1 << 16) | \
- ((uint32_t)CAN_InitStruct->CAN_BS2 << 20) | \
- ((uint32_t)CAN_InitStruct->CAN_Prescaler - 1);
-
- /* Request leave initialisation */
- CANx->MCR &= ~(uint32_t)CAN_MCR_INRQ;
-
- /* Wait the acknowledge */
- wait_ack = 0;
-
- while (((CANx->MSR & CAN_MSR_INAK) == CAN_MSR_INAK) && (wait_ack != INAK_TIMEOUT))
- {
- wait_ack++;
- }
-
- /* ...and check acknowledged */
- if ((CANx->MSR & CAN_MSR_INAK) == CAN_MSR_INAK)
- {
- InitStatus = CAN_InitStatus_Failed;
- }
- else
- {
- InitStatus = CAN_InitStatus_Success ;
- }
- }
-
- /* At this step, return the status of initialization */
- return InitStatus;
-}
-
-/**
- * @brief Configures the CAN reception filter according to the specified
- * parameters in the CAN_FilterInitStruct.
- * @param CAN_FilterInitStruct: pointer to a CAN_FilterInitTypeDef structure that
- * contains the configuration information.
- * @retval None
- */
-void CAN_FilterInit(CAN_FilterInitTypeDef* CAN_FilterInitStruct)
-{
- uint32_t filter_number_bit_pos = 0;
- /* Check the parameters */
- assert_param(IS_CAN_FILTER_NUMBER(CAN_FilterInitStruct->CAN_FilterNumber));
- assert_param(IS_CAN_FILTER_MODE(CAN_FilterInitStruct->CAN_FilterMode));
- assert_param(IS_CAN_FILTER_SCALE(CAN_FilterInitStruct->CAN_FilterScale));
- assert_param(IS_CAN_FILTER_FIFO(CAN_FilterInitStruct->CAN_FilterFIFOAssignment));
- assert_param(IS_FUNCTIONAL_STATE(CAN_FilterInitStruct->CAN_FilterActivation));
-
- filter_number_bit_pos = ((uint32_t)1) << CAN_FilterInitStruct->CAN_FilterNumber;
-
- /* Initialisation mode for the filter */
- CAN1->FMR |= FMR_FINIT;
-
- /* Filter Deactivation */
- CAN1->FA1R &= ~(uint32_t)filter_number_bit_pos;
-
- /* Filter Scale */
- if (CAN_FilterInitStruct->CAN_FilterScale == CAN_FilterScale_16bit)
- {
- /* 16-bit scale for the filter */
- CAN1->FS1R &= ~(uint32_t)filter_number_bit_pos;
-
- /* First 16-bit identifier and First 16-bit mask */
- /* Or First 16-bit identifier and Second 16-bit identifier */
- CAN1->sFilterRegister[CAN_FilterInitStruct->CAN_FilterNumber].FR1 =
- ((0x0000FFFF & (uint32_t)CAN_FilterInitStruct->CAN_FilterMaskIdLow) << 16) |
- (0x0000FFFF & (uint32_t)CAN_FilterInitStruct->CAN_FilterIdLow);
-
- /* Second 16-bit identifier and Second 16-bit mask */
- /* Or Third 16-bit identifier and Fourth 16-bit identifier */
- CAN1->sFilterRegister[CAN_FilterInitStruct->CAN_FilterNumber].FR2 =
- ((0x0000FFFF & (uint32_t)CAN_FilterInitStruct->CAN_FilterMaskIdHigh) << 16) |
- (0x0000FFFF & (uint32_t)CAN_FilterInitStruct->CAN_FilterIdHigh);
- }
-
- if (CAN_FilterInitStruct->CAN_FilterScale == CAN_FilterScale_32bit)
- {
- /* 32-bit scale for the filter */
- CAN1->FS1R |= filter_number_bit_pos;
- /* 32-bit identifier or First 32-bit identifier */
- CAN1->sFilterRegister[CAN_FilterInitStruct->CAN_FilterNumber].FR1 =
- ((0x0000FFFF & (uint32_t)CAN_FilterInitStruct->CAN_FilterIdHigh) << 16) |
- (0x0000FFFF & (uint32_t)CAN_FilterInitStruct->CAN_FilterIdLow);
- /* 32-bit mask or Second 32-bit identifier */
- CAN1->sFilterRegister[CAN_FilterInitStruct->CAN_FilterNumber].FR2 =
- ((0x0000FFFF & (uint32_t)CAN_FilterInitStruct->CAN_FilterMaskIdHigh) << 16) |
- (0x0000FFFF & (uint32_t)CAN_FilterInitStruct->CAN_FilterMaskIdLow);
- }
-
- /* Filter Mode */
- if (CAN_FilterInitStruct->CAN_FilterMode == CAN_FilterMode_IdMask)
- {
- /*Id/Mask mode for the filter*/
- CAN1->FM1R &= ~(uint32_t)filter_number_bit_pos;
- }
- else /* CAN_FilterInitStruct->CAN_FilterMode == CAN_FilterMode_IdList */
- {
- /*Identifier list mode for the filter*/
- CAN1->FM1R |= (uint32_t)filter_number_bit_pos;
- }
-
- /* Filter FIFO assignment */
- if (CAN_FilterInitStruct->CAN_FilterFIFOAssignment == CAN_Filter_FIFO0)
- {
- /* FIFO 0 assignation for the filter */
- CAN1->FFA1R &= ~(uint32_t)filter_number_bit_pos;
- }
-
- if (CAN_FilterInitStruct->CAN_FilterFIFOAssignment == CAN_Filter_FIFO1)
- {
- /* FIFO 1 assignation for the filter */
- CAN1->FFA1R |= (uint32_t)filter_number_bit_pos;
- }
-
- /* Filter activation */
- if (CAN_FilterInitStruct->CAN_FilterActivation == ENABLE)
- {
- CAN1->FA1R |= filter_number_bit_pos;
- }
-
- /* Leave the initialisation mode for the filter */
- CAN1->FMR &= ~FMR_FINIT;
-}
-
-/**
- * @brief Fills each CAN_InitStruct member with its default value.
- * @param CAN_InitStruct: pointer to a CAN_InitTypeDef structure which ill be initialized.
- * @retval None
- */
-void CAN_StructInit(CAN_InitTypeDef* CAN_InitStruct)
-{
- /* Reset CAN init structure parameters values */
-
- /* Initialize the time triggered communication mode */
- CAN_InitStruct->CAN_TTCM = DISABLE;
-
- /* Initialize the automatic bus-off management */
- CAN_InitStruct->CAN_ABOM = DISABLE;
-
- /* Initialize the automatic wake-up mode */
- CAN_InitStruct->CAN_AWUM = DISABLE;
-
- /* Initialize the no automatic retransmission */
- CAN_InitStruct->CAN_NART = DISABLE;
-
- /* Initialize the receive FIFO locked mode */
- CAN_InitStruct->CAN_RFLM = DISABLE;
-
- /* Initialize the transmit FIFO priority */
- CAN_InitStruct->CAN_TXFP = DISABLE;
-
- /* Initialize the CAN_Mode member */
- CAN_InitStruct->CAN_Mode = CAN_Mode_Normal;
-
- /* Initialize the CAN_SJW member */
- CAN_InitStruct->CAN_SJW = CAN_SJW_1tq;
-
- /* Initialize the CAN_BS1 member */
- CAN_InitStruct->CAN_BS1 = CAN_BS1_4tq;
-
- /* Initialize the CAN_BS2 member */
- CAN_InitStruct->CAN_BS2 = CAN_BS2_3tq;
-
- /* Initialize the CAN_Prescaler member */
- CAN_InitStruct->CAN_Prescaler = 1;
-}
-
-/**
- * @brief Select the start bank filter for slave CAN.
- * @param CAN_BankNumber: Select the start slave bank filter from 1..27.
- * @retval None
- */
-void CAN_SlaveStartBank(uint8_t CAN_BankNumber)
-{
- /* Check the parameters */
- assert_param(IS_CAN_BANKNUMBER(CAN_BankNumber));
-
- /* Enter Initialisation mode for the filter */
- CAN1->FMR |= FMR_FINIT;
-
- /* Select the start slave bank */
- CAN1->FMR &= (uint32_t)0xFFFFC0F1 ;
- CAN1->FMR |= (uint32_t)(CAN_BankNumber)<<8;
-
- /* Leave Initialisation mode for the filter */
- CAN1->FMR &= ~FMR_FINIT;
-}
-
-/**
- * @brief Enables or disables the DBG Freeze for CAN.
- * @param CANx: where x can be 1 or 2 to to select the CAN peripheral.
- * @param NewState: new state of the CAN peripheral.
- * This parameter can be: ENABLE (CAN reception/transmission is frozen
- * during debug. Reception FIFOs can still be accessed/controlled normally)
- * or DISABLE (CAN is working during debug).
- * @retval None
- */
-void CAN_DBGFreeze(CAN_TypeDef* CANx, FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_CAN_ALL_PERIPH(CANx));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- if (NewState != DISABLE)
- {
- /* Enable Debug Freeze */
- CANx->MCR |= MCR_DBF;
- }
- else
- {
- /* Disable Debug Freeze */
- CANx->MCR &= ~MCR_DBF;
- }
-}
-
-
-/**
- * @brief Enables or disables the CAN Time TriggerOperation communication mode.
- * @note DLC must be programmed as 8 in order Time Stamp (2 bytes) to be
- * sent over the CAN bus.
- * @param CANx: where x can be 1 or 2 to to select the CAN peripheral.
- * @param NewState: Mode new state. This parameter can be: ENABLE or DISABLE.
- * When enabled, Time stamp (TIME[15:0]) value is sent in the last two
- * data bytes of the 8-byte message: TIME[7:0] in data byte 6 and TIME[15:8]
- * in data byte 7.
- * @retval None
- */
-void CAN_TTComModeCmd(CAN_TypeDef* CANx, FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_CAN_ALL_PERIPH(CANx));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
- if (NewState != DISABLE)
- {
- /* Enable the TTCM mode */
- CANx->MCR |= CAN_MCR_TTCM;
-
- /* Set TGT bits */
- CANx->sTxMailBox[0].TDTR |= ((uint32_t)CAN_TDT0R_TGT);
- CANx->sTxMailBox[1].TDTR |= ((uint32_t)CAN_TDT1R_TGT);
- CANx->sTxMailBox[2].TDTR |= ((uint32_t)CAN_TDT2R_TGT);
- }
- else
- {
- /* Disable the TTCM mode */
- CANx->MCR &= (uint32_t)(~(uint32_t)CAN_MCR_TTCM);
-
- /* Reset TGT bits */
- CANx->sTxMailBox[0].TDTR &= ((uint32_t)~CAN_TDT0R_TGT);
- CANx->sTxMailBox[1].TDTR &= ((uint32_t)~CAN_TDT1R_TGT);
- CANx->sTxMailBox[2].TDTR &= ((uint32_t)~CAN_TDT2R_TGT);
- }
-}
-/**
- * @}
- */
-
-
-/** @defgroup CAN_Group2 CAN Frames Transmission functions
- * @brief CAN Frames Transmission functions
- *
-@verbatim
- ===============================================================================
- CAN Frames Transmission functions
- ===============================================================================
- This section provides functions allowing to
- - Initiate and transmit a CAN frame message (if there is an empty mailbox).
- - Check the transmission status of a CAN Frame
- - Cancel a transmit request
-
-@endverbatim
- * @{
- */
-
-/**
- * @brief Initiates and transmits a CAN frame message.
- * @param CANx: where x can be 1 or 2 to to select the CAN peripheral.
- * @param TxMessage: pointer to a structure which contains CAN Id, CAN DLC and CAN data.
- * @retval The number of the mailbox that is used for transmission or
- * CAN_TxStatus_NoMailBox if there is no empty mailbox.
- */
-uint8_t CAN_Transmit(CAN_TypeDef* CANx, CanTxMsg* TxMessage)
-{
- uint8_t transmit_mailbox = 0;
- /* Check the parameters */
- assert_param(IS_CAN_ALL_PERIPH(CANx));
- assert_param(IS_CAN_IDTYPE(TxMessage->IDE));
- assert_param(IS_CAN_RTR(TxMessage->RTR));
- assert_param(IS_CAN_DLC(TxMessage->DLC));
-
- /* Select one empty transmit mailbox */
- if ((CANx->TSR&CAN_TSR_TME0) == CAN_TSR_TME0)
- {
- transmit_mailbox = 0;
- }
- else if ((CANx->TSR&CAN_TSR_TME1) == CAN_TSR_TME1)
- {
- transmit_mailbox = 1;
- }
- else if ((CANx->TSR&CAN_TSR_TME2) == CAN_TSR_TME2)
- {
- transmit_mailbox = 2;
- }
- else
- {
- transmit_mailbox = CAN_TxStatus_NoMailBox;
- }
-
- if (transmit_mailbox != CAN_TxStatus_NoMailBox)
- {
- /* Set up the Id */
- CANx->sTxMailBox[transmit_mailbox].TIR &= TMIDxR_TXRQ;
- if (TxMessage->IDE == CAN_Id_Standard)
- {
- assert_param(IS_CAN_STDID(TxMessage->StdId));
- CANx->sTxMailBox[transmit_mailbox].TIR |= ((TxMessage->StdId << 21) | \
- TxMessage->RTR);
- }
- else
- {
- assert_param(IS_CAN_EXTID(TxMessage->ExtId));
- CANx->sTxMailBox[transmit_mailbox].TIR |= ((TxMessage->ExtId << 3) | \
- TxMessage->IDE | \
- TxMessage->RTR);
- }
-
- /* Set up the DLC */
- TxMessage->DLC &= (uint8_t)0x0000000F;
- CANx->sTxMailBox[transmit_mailbox].TDTR &= (uint32_t)0xFFFFFFF0;
- CANx->sTxMailBox[transmit_mailbox].TDTR |= TxMessage->DLC;
-
- /* Set up the data field */
- CANx->sTxMailBox[transmit_mailbox].TDLR = (((uint32_t)TxMessage->Data[3] << 24) |
- ((uint32_t)TxMessage->Data[2] << 16) |
- ((uint32_t)TxMessage->Data[1] << 8) |
- ((uint32_t)TxMessage->Data[0]));
- CANx->sTxMailBox[transmit_mailbox].TDHR = (((uint32_t)TxMessage->Data[7] << 24) |
- ((uint32_t)TxMessage->Data[6] << 16) |
- ((uint32_t)TxMessage->Data[5] << 8) |
- ((uint32_t)TxMessage->Data[4]));
- /* Request transmission */
- CANx->sTxMailBox[transmit_mailbox].TIR |= TMIDxR_TXRQ;
- }
- return transmit_mailbox;
-}
-
-/**
- * @brief Checks the transmission status of a CAN Frame.
- * @param CANx: where x can be 1 or 2 to select the CAN peripheral.
- * @param TransmitMailbox: the number of the mailbox that is used for transmission.
- * @retval CAN_TxStatus_Ok if the CAN driver transmits the message,
- * CAN_TxStatus_Failed in an other case.
- */
-uint8_t CAN_TransmitStatus(CAN_TypeDef* CANx, uint8_t TransmitMailbox)
-{
- uint32_t state = 0;
-
- /* Check the parameters */
- assert_param(IS_CAN_ALL_PERIPH(CANx));
- assert_param(IS_CAN_TRANSMITMAILBOX(TransmitMailbox));
-
- switch (TransmitMailbox)
- {
- case (CAN_TXMAILBOX_0):
- state = CANx->TSR & (CAN_TSR_RQCP0 | CAN_TSR_TXOK0 | CAN_TSR_TME0);
- break;
- case (CAN_TXMAILBOX_1):
- state = CANx->TSR & (CAN_TSR_RQCP1 | CAN_TSR_TXOK1 | CAN_TSR_TME1);
- break;
- case (CAN_TXMAILBOX_2):
- state = CANx->TSR & (CAN_TSR_RQCP2 | CAN_TSR_TXOK2 | CAN_TSR_TME2);
- break;
- default:
- state = CAN_TxStatus_Failed;
- break;
- }
- switch (state)
- {
- /* transmit pending */
- case (0x0): state = CAN_TxStatus_Pending;
- break;
- /* transmit failed */
- case (CAN_TSR_RQCP0 | CAN_TSR_TME0): state = CAN_TxStatus_Failed;
- break;
- case (CAN_TSR_RQCP1 | CAN_TSR_TME1): state = CAN_TxStatus_Failed;
- break;
- case (CAN_TSR_RQCP2 | CAN_TSR_TME2): state = CAN_TxStatus_Failed;
- break;
- /* transmit succeeded */
- case (CAN_TSR_RQCP0 | CAN_TSR_TXOK0 | CAN_TSR_TME0):state = CAN_TxStatus_Ok;
- break;
- case (CAN_TSR_RQCP1 | CAN_TSR_TXOK1 | CAN_TSR_TME1):state = CAN_TxStatus_Ok;
- break;
- case (CAN_TSR_RQCP2 | CAN_TSR_TXOK2 | CAN_TSR_TME2):state = CAN_TxStatus_Ok;
- break;
- default: state = CAN_TxStatus_Failed;
- break;
- }
- return (uint8_t) state;
-}
-
-/**
- * @brief Cancels a transmit request.
- * @param CANx: where x can be 1 or 2 to select the CAN peripheral.
- * @param Mailbox: Mailbox number.
- * @retval None
- */
-void CAN_CancelTransmit(CAN_TypeDef* CANx, uint8_t Mailbox)
-{
- /* Check the parameters */
- assert_param(IS_CAN_ALL_PERIPH(CANx));
- assert_param(IS_CAN_TRANSMITMAILBOX(Mailbox));
- /* abort transmission */
- switch (Mailbox)
- {
- case (CAN_TXMAILBOX_0): CANx->TSR |= CAN_TSR_ABRQ0;
- break;
- case (CAN_TXMAILBOX_1): CANx->TSR |= CAN_TSR_ABRQ1;
- break;
- case (CAN_TXMAILBOX_2): CANx->TSR |= CAN_TSR_ABRQ2;
- break;
- default:
- break;
- }
-}
-/**
- * @}
- */
-
-
-/** @defgroup CAN_Group3 CAN Frames Reception functions
- * @brief CAN Frames Reception functions
- *
-@verbatim
- ===============================================================================
- CAN Frames Reception functions
- ===============================================================================
- This section provides functions allowing to
- - Receive a correct CAN frame
- - Release a specified receive FIFO (2 FIFOs are available)
- - Return the number of the pending received CAN frames
-
-@endverbatim
- * @{
- */
-
-/**
- * @brief Receives a correct CAN frame.
- * @param CANx: where x can be 1 or 2 to select the CAN peripheral.
- * @param FIFONumber: Receive FIFO number, CAN_FIFO0 or CAN_FIFO1.
- * @param RxMessage: pointer to a structure receive frame which contains CAN Id,
- * CAN DLC, CAN data and FMI number.
- * @retval None
- */
-void CAN_Receive(CAN_TypeDef* CANx, uint8_t FIFONumber, CanRxMsg* RxMessage)
-{
- /* Check the parameters */
- assert_param(IS_CAN_ALL_PERIPH(CANx));
- assert_param(IS_CAN_FIFO(FIFONumber));
- /* Get the Id */
- RxMessage->IDE = (uint8_t)0x04 & CANx->sFIFOMailBox[FIFONumber].RIR;
- if (RxMessage->IDE == CAN_Id_Standard)
- {
- RxMessage->StdId = (uint32_t)0x000007FF & (CANx->sFIFOMailBox[FIFONumber].RIR >> 21);
- }
- else
- {
- RxMessage->ExtId = (uint32_t)0x1FFFFFFF & (CANx->sFIFOMailBox[FIFONumber].RIR >> 3);
- }
-
- RxMessage->RTR = (uint8_t)0x02 & CANx->sFIFOMailBox[FIFONumber].RIR;
- /* Get the DLC */
- RxMessage->DLC = (uint8_t)0x0F & CANx->sFIFOMailBox[FIFONumber].RDTR;
- /* Get the FMI */
- RxMessage->FMI = (uint8_t)0xFF & (CANx->sFIFOMailBox[FIFONumber].RDTR >> 8);
- /* Get the data field */
- RxMessage->Data[0] = (uint8_t)0xFF & CANx->sFIFOMailBox[FIFONumber].RDLR;
- RxMessage->Data[1] = (uint8_t)0xFF & (CANx->sFIFOMailBox[FIFONumber].RDLR >> 8);
- RxMessage->Data[2] = (uint8_t)0xFF & (CANx->sFIFOMailBox[FIFONumber].RDLR >> 16);
- RxMessage->Data[3] = (uint8_t)0xFF & (CANx->sFIFOMailBox[FIFONumber].RDLR >> 24);
- RxMessage->Data[4] = (uint8_t)0xFF & CANx->sFIFOMailBox[FIFONumber].RDHR;
- RxMessage->Data[5] = (uint8_t)0xFF & (CANx->sFIFOMailBox[FIFONumber].RDHR >> 8);
- RxMessage->Data[6] = (uint8_t)0xFF & (CANx->sFIFOMailBox[FIFONumber].RDHR >> 16);
- RxMessage->Data[7] = (uint8_t)0xFF & (CANx->sFIFOMailBox[FIFONumber].RDHR >> 24);
- /* Release the FIFO */
- /* Release FIFO0 */
- if (FIFONumber == CAN_FIFO0)
- {
- CANx->RF0R |= CAN_RF0R_RFOM0;
- }
- /* Release FIFO1 */
- else /* FIFONumber == CAN_FIFO1 */
- {
- CANx->RF1R |= CAN_RF1R_RFOM1;
- }
-}
-
-/**
- * @brief Releases the specified receive FIFO.
- * @param CANx: where x can be 1 or 2 to select the CAN peripheral.
- * @param FIFONumber: FIFO to release, CAN_FIFO0 or CAN_FIFO1.
- * @retval None
- */
-void CAN_FIFORelease(CAN_TypeDef* CANx, uint8_t FIFONumber)
-{
- /* Check the parameters */
- assert_param(IS_CAN_ALL_PERIPH(CANx));
- assert_param(IS_CAN_FIFO(FIFONumber));
- /* Release FIFO0 */
- if (FIFONumber == CAN_FIFO0)
- {
- CANx->RF0R |= CAN_RF0R_RFOM0;
- }
- /* Release FIFO1 */
- else /* FIFONumber == CAN_FIFO1 */
- {
- CANx->RF1R |= CAN_RF1R_RFOM1;
- }
-}
-
-/**
- * @brief Returns the number of pending received messages.
- * @param CANx: where x can be 1 or 2 to select the CAN peripheral.
- * @param FIFONumber: Receive FIFO number, CAN_FIFO0 or CAN_FIFO1.
- * @retval NbMessage : which is the number of pending message.
- */
-uint8_t CAN_MessagePending(CAN_TypeDef* CANx, uint8_t FIFONumber)
-{
- uint8_t message_pending=0;
- /* Check the parameters */
- assert_param(IS_CAN_ALL_PERIPH(CANx));
- assert_param(IS_CAN_FIFO(FIFONumber));
- if (FIFONumber == CAN_FIFO0)
- {
- message_pending = (uint8_t)(CANx->RF0R&(uint32_t)0x03);
- }
- else if (FIFONumber == CAN_FIFO1)
- {
- message_pending = (uint8_t)(CANx->RF1R&(uint32_t)0x03);
- }
- else
- {
- message_pending = 0;
- }
- return message_pending;
-}
-/**
- * @}
- */
-
-
-/** @defgroup CAN_Group4 CAN Operation modes functions
- * @brief CAN Operation modes functions
- *
-@verbatim
- ===============================================================================
- CAN Operation modes functions
- ===============================================================================
- This section provides functions allowing to select the CAN Operation modes
- - sleep mode
- - normal mode
- - initialization mode
-
-@endverbatim
- * @{
- */
-
-
-/**
- * @brief Selects the CAN Operation mode.
- * @param CAN_OperatingMode: CAN Operating Mode.
- * This parameter can be one of @ref CAN_OperatingMode_TypeDef enumeration.
- * @retval status of the requested mode which can be
- * - CAN_ModeStatus_Failed: CAN failed entering the specific mode
- * - CAN_ModeStatus_Success: CAN Succeed entering the specific mode
- */
-uint8_t CAN_OperatingModeRequest(CAN_TypeDef* CANx, uint8_t CAN_OperatingMode)
-{
- uint8_t status = CAN_ModeStatus_Failed;
-
- /* Timeout for INAK or also for SLAK bits*/
- uint32_t timeout = INAK_TIMEOUT;
-
- /* Check the parameters */
- assert_param(IS_CAN_ALL_PERIPH(CANx));
- assert_param(IS_CAN_OPERATING_MODE(CAN_OperatingMode));
-
- if (CAN_OperatingMode == CAN_OperatingMode_Initialization)
- {
- /* Request initialisation */
- CANx->MCR = (uint32_t)((CANx->MCR & (uint32_t)(~(uint32_t)CAN_MCR_SLEEP)) | CAN_MCR_INRQ);
-
- /* Wait the acknowledge */
- while (((CANx->MSR & CAN_MODE_MASK) != CAN_MSR_INAK) && (timeout != 0))
- {
- timeout--;
- }
- if ((CANx->MSR & CAN_MODE_MASK) != CAN_MSR_INAK)
- {
- status = CAN_ModeStatus_Failed;
- }
- else
- {
- status = CAN_ModeStatus_Success;
- }
- }
- else if (CAN_OperatingMode == CAN_OperatingMode_Normal)
- {
- /* Request leave initialisation and sleep mode and enter Normal mode */
- CANx->MCR &= (uint32_t)(~(CAN_MCR_SLEEP|CAN_MCR_INRQ));
-
- /* Wait the acknowledge */
- while (((CANx->MSR & CAN_MODE_MASK) != 0) && (timeout!=0))
- {
- timeout--;
- }
- if ((CANx->MSR & CAN_MODE_MASK) != 0)
- {
- status = CAN_ModeStatus_Failed;
- }
- else
- {
- status = CAN_ModeStatus_Success;
- }
- }
- else if (CAN_OperatingMode == CAN_OperatingMode_Sleep)
- {
- /* Request Sleep mode */
- CANx->MCR = (uint32_t)((CANx->MCR & (uint32_t)(~(uint32_t)CAN_MCR_INRQ)) | CAN_MCR_SLEEP);
-
- /* Wait the acknowledge */
- while (((CANx->MSR & CAN_MODE_MASK) != CAN_MSR_SLAK) && (timeout!=0))
- {
- timeout--;
- }
- if ((CANx->MSR & CAN_MODE_MASK) != CAN_MSR_SLAK)
- {
- status = CAN_ModeStatus_Failed;
- }
- else
- {
- status = CAN_ModeStatus_Success;
- }
- }
- else
- {
- status = CAN_ModeStatus_Failed;
- }
-
- return (uint8_t) status;
-}
-
-/**
- * @brief Enters the Sleep (low power) mode.
- * @param CANx: where x can be 1 or 2 to select the CAN peripheral.
- * @retval CAN_Sleep_Ok if sleep entered, CAN_Sleep_Failed otherwise.
- */
-uint8_t CAN_Sleep(CAN_TypeDef* CANx)
-{
- uint8_t sleepstatus = CAN_Sleep_Failed;
-
- /* Check the parameters */
- assert_param(IS_CAN_ALL_PERIPH(CANx));
-
- /* Request Sleep mode */
- CANx->MCR = (((CANx->MCR) & (uint32_t)(~(uint32_t)CAN_MCR_INRQ)) | CAN_MCR_SLEEP);
-
- /* Sleep mode status */
- if ((CANx->MSR & (CAN_MSR_SLAK|CAN_MSR_INAK)) == CAN_MSR_SLAK)
- {
- /* Sleep mode not entered */
- sleepstatus = CAN_Sleep_Ok;
- }
- /* return sleep mode status */
- return (uint8_t)sleepstatus;
-}
-
-/**
- * @brief Wakes up the CAN peripheral from sleep mode .
- * @param CANx: where x can be 1 or 2 to select the CAN peripheral.
- * @retval CAN_WakeUp_Ok if sleep mode left, CAN_WakeUp_Failed otherwise.
- */
-uint8_t CAN_WakeUp(CAN_TypeDef* CANx)
-{
- uint32_t wait_slak = SLAK_TIMEOUT;
- uint8_t wakeupstatus = CAN_WakeUp_Failed;
-
- /* Check the parameters */
- assert_param(IS_CAN_ALL_PERIPH(CANx));
-
- /* Wake up request */
- CANx->MCR &= ~(uint32_t)CAN_MCR_SLEEP;
-
- /* Sleep mode status */
- while(((CANx->MSR & CAN_MSR_SLAK) == CAN_MSR_SLAK)&&(wait_slak!=0x00))
- {
- wait_slak--;
- }
- if((CANx->MSR & CAN_MSR_SLAK) != CAN_MSR_SLAK)
- {
- /* wake up done : Sleep mode exited */
- wakeupstatus = CAN_WakeUp_Ok;
- }
- /* return wakeup status */
- return (uint8_t)wakeupstatus;
-}
-/**
- * @}
- */
-
-
-/** @defgroup CAN_Group5 CAN Bus Error management functions
- * @brief CAN Bus Error management functions
- *
-@verbatim
- ===============================================================================
- CAN Bus Error management functions
- ===============================================================================
- This section provides functions allowing to
- - Return the CANx's last error code (LEC)
- - Return the CANx Receive Error Counter (REC)
- - Return the LSB of the 9-bit CANx Transmit Error Counter(TEC).
-
- @note If TEC is greater than 255, The CAN is in bus-off state.
- @note if REC or TEC are greater than 96, an Error warning flag occurs.
- @note if REC or TEC are greater than 127, an Error Passive Flag occurs.
-
-@endverbatim
- * @{
- */
-
-/**
- * @brief Returns the CANx's last error code (LEC).
- * @param CANx: where x can be 1 or 2 to select the CAN peripheral.
- * @retval Error code:
- * - CAN_ERRORCODE_NoErr: No Error
- * - CAN_ERRORCODE_StuffErr: Stuff Error
- * - CAN_ERRORCODE_FormErr: Form Error
- * - CAN_ERRORCODE_ACKErr : Acknowledgment Error
- * - CAN_ERRORCODE_BitRecessiveErr: Bit Recessive Error
- * - CAN_ERRORCODE_BitDominantErr: Bit Dominant Error
- * - CAN_ERRORCODE_CRCErr: CRC Error
- * - CAN_ERRORCODE_SoftwareSetErr: Software Set Error
- */
-uint8_t CAN_GetLastErrorCode(CAN_TypeDef* CANx)
-{
- uint8_t errorcode=0;
-
- /* Check the parameters */
- assert_param(IS_CAN_ALL_PERIPH(CANx));
-
- /* Get the error code*/
- errorcode = (((uint8_t)CANx->ESR) & (uint8_t)CAN_ESR_LEC);
-
- /* Return the error code*/
- return errorcode;
-}
-
-/**
- * @brief Returns the CANx Receive Error Counter (REC).
- * @note In case of an error during reception, this counter is incremented
- * by 1 or by 8 depending on the error condition as defined by the CAN
- * standard. After every successful reception, the counter is
- * decremented by 1 or reset to 120 if its value was higher than 128.
- * When the counter value exceeds 127, the CAN controller enters the
- * error passive state.
- * @param CANx: where x can be 1 or 2 to to select the CAN peripheral.
- * @retval CAN Receive Error Counter.
- */
-uint8_t CAN_GetReceiveErrorCounter(CAN_TypeDef* CANx)
-{
- uint8_t counter=0;
-
- /* Check the parameters */
- assert_param(IS_CAN_ALL_PERIPH(CANx));
-
- /* Get the Receive Error Counter*/
- counter = (uint8_t)((CANx->ESR & CAN_ESR_REC)>> 24);
-
- /* Return the Receive Error Counter*/
- return counter;
-}
-
-
-/**
- * @brief Returns the LSB of the 9-bit CANx Transmit Error Counter(TEC).
- * @param CANx: where x can be 1 or 2 to to select the CAN peripheral.
- * @retval LSB of the 9-bit CAN Transmit Error Counter.
- */
-uint8_t CAN_GetLSBTransmitErrorCounter(CAN_TypeDef* CANx)
-{
- uint8_t counter=0;
-
- /* Check the parameters */
- assert_param(IS_CAN_ALL_PERIPH(CANx));
-
- /* Get the LSB of the 9-bit CANx Transmit Error Counter(TEC) */
- counter = (uint8_t)((CANx->ESR & CAN_ESR_TEC)>> 16);
-
- /* Return the LSB of the 9-bit CANx Transmit Error Counter(TEC) */
- return counter;
-}
-/**
- * @}
- */
-
-/** @defgroup CAN_Group6 Interrupts and flags management functions
- * @brief Interrupts and flags management functions
- *
-@verbatim
- ===============================================================================
- Interrupts and flags management functions
- ===============================================================================
-
- This section provides functions allowing to configure the CAN Interrupts and
- to get the status and clear flags and Interrupts pending bits.
-
- The CAN provides 14 Interrupts sources and 15 Flags:
-
- ===============
- Flags :
- ===============
- The 15 flags can be divided on 4 groups:
-
- A. Transmit Flags
- -----------------------
- CAN_FLAG_RQCP0,
- CAN_FLAG_RQCP1,
- CAN_FLAG_RQCP2 : Request completed MailBoxes 0, 1 and 2 Flags
- Set when when the last request (transmit or abort) has
- been performed.
-
- B. Receive Flags
- -----------------------
-
- CAN_FLAG_FMP0,
- CAN_FLAG_FMP1 : FIFO 0 and 1 Message Pending Flags
- set to signal that messages are pending in the receive
- FIFO.
- These Flags are cleared only by hardware.
-
- CAN_FLAG_FF0,
- CAN_FLAG_FF1 : FIFO 0 and 1 Full Flags
- set when three messages are stored in the selected
- FIFO.
-
- CAN_FLAG_FOV0
- CAN_FLAG_FOV1 : FIFO 0 and 1 Overrun Flags
- set when a new message has been received and passed
- the filter while the FIFO was full.
-
- C. Operating Mode Flags
- -----------------------
- CAN_FLAG_WKU : Wake up Flag
- set to signal that a SOF bit has been detected while
- the CAN hardware was in Sleep mode.
-
- CAN_FLAG_SLAK : Sleep acknowledge Flag
- Set to signal that the CAN has entered Sleep Mode.
-
- D. Error Flags
- -----------------------
- CAN_FLAG_EWG : Error Warning Flag
- Set when the warning limit has been reached (Receive
- Error Counter or Transmit Error Counter greater than 96).
- This Flag is cleared only by hardware.
-
- CAN_FLAG_EPV : Error Passive Flag
- Set when the Error Passive limit has been reached
- (Receive Error Counter or Transmit Error Counter
- greater than 127).
- This Flag is cleared only by hardware.
-
- CAN_FLAG_BOF : Bus-Off Flag
- set when CAN enters the bus-off state. The bus-off
- state is entered on TEC overflow, greater than 255.
- This Flag is cleared only by hardware.
-
- CAN_FLAG_LEC : Last error code Flag
- set If a message has been transferred (reception or
- transmission) with error, and the error code is hold.
-
- ===============
- Interrupts :
- ===============
- The 14 interrupts can be divided on 4 groups:
-
- A. Transmit interrupt
- -----------------------
- CAN_IT_TME : Transmit mailbox empty Interrupt
- if enabled, this interrupt source is pending when
- no transmit request are pending for Tx mailboxes.
-
- B. Receive Interrupts
- -----------------------
- CAN_IT_FMP0,
- CAN_IT_FMP1 : FIFO 0 and FIFO1 message pending Interrupts
- if enabled, these interrupt sources are pending when
- messages are pending in the receive FIFO.
- The corresponding interrupt pending bits are cleared
- only by hardware.
-
- CAN_IT_FF0,
- CAN_IT_FF1 : FIFO 0 and FIFO1 full Interrupts
- if enabled, these interrupt sources are pending when
- three messages are stored in the selected FIFO.
-
- CAN_IT_FOV0,
- CAN_IT_FOV1 : FIFO 0 and FIFO1 overrun Interrupts
- if enabled, these interrupt sources are pending when
- a new message has been received and passed the filter
- while the FIFO was full.
-
- C. Operating Mode Interrupts
- -------------------------------
- CAN_IT_WKU : Wake-up Interrupt
- if enabled, this interrupt source is pending when
- a SOF bit has been detected while the CAN hardware was
- in Sleep mode.
-
- CAN_IT_SLK : Sleep acknowledge Interrupt
- if enabled, this interrupt source is pending when
- the CAN has entered Sleep Mode.
-
- D. Error Interrupts
- -----------------------
- CAN_IT_EWG : Error warning Interrupt
- if enabled, this interrupt source is pending when
- the warning limit has been reached (Receive Error
- Counter or Transmit Error Counter=96).
-
- CAN_IT_EPV : Error passive Interrupt
- if enabled, this interrupt source is pending when
- the Error Passive limit has been reached (Receive
- Error Counter or Transmit Error Counter>127).
-
- CAN_IT_BOF : Bus-off Interrupt
- if enabled, this interrupt source is pending when
- CAN enters the bus-off state. The bus-off state is
- entered on TEC overflow, greater than 255.
- This Flag is cleared only by hardware.
-
- CAN_IT_LEC : Last error code Interrupt
- if enabled, this interrupt source is pending when
- a message has been transferred (reception or
- transmission) with error, and the error code is hold.
-
- CAN_IT_ERR : Error Interrupt
- if enabled, this interrupt source is pending when
- an error condition is pending.
-
-
- Managing the CAN controller events :
- ------------------------------------
- The user should identify which mode will be used in his application to manage
- the CAN controller events: Polling mode or Interrupt mode.
-
- 1. In the Polling Mode it is advised to use the following functions:
- - CAN_GetFlagStatus() : to check if flags events occur.
- - CAN_ClearFlag() : to clear the flags events.
-
-
-
- 2. In the Interrupt Mode it is advised to use the following functions:
- - CAN_ITConfig() : to enable or disable the interrupt source.
- - CAN_GetITStatus() : to check if Interrupt occurs.
- - CAN_ClearITPendingBit() : to clear the Interrupt pending Bit (corresponding Flag).
- @note This function has no impact on CAN_IT_FMP0 and CAN_IT_FMP1 Interrupts
- pending bits since there are cleared only by hardware.
-
-@endverbatim
- * @{
- */
-/**
- * @brief Enables or disables the specified CANx interrupts.
- * @param CANx: where x can be 1 or 2 to to select the CAN peripheral.
- * @param CAN_IT: specifies the CAN interrupt sources to be enabled or disabled.
- * This parameter can be:
- * @arg CAN_IT_TME: Transmit mailbox empty Interrupt
- * @arg CAN_IT_FMP0: FIFO 0 message pending Interrupt
- * @arg CAN_IT_FF0: FIFO 0 full Interrupt
- * @arg CAN_IT_FOV0: FIFO 0 overrun Interrupt
- * @arg CAN_IT_FMP1: FIFO 1 message pending Interrupt
- * @arg CAN_IT_FF1: FIFO 1 full Interrupt
- * @arg CAN_IT_FOV1: FIFO 1 overrun Interrupt
- * @arg CAN_IT_WKU: Wake-up Interrupt
- * @arg CAN_IT_SLK: Sleep acknowledge Interrupt
- * @arg CAN_IT_EWG: Error warning Interrupt
- * @arg CAN_IT_EPV: Error passive Interrupt
- * @arg CAN_IT_BOF: Bus-off Interrupt
- * @arg CAN_IT_LEC: Last error code Interrupt
- * @arg CAN_IT_ERR: Error Interrupt
- * @param NewState: new state of the CAN interrupts.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void CAN_ITConfig(CAN_TypeDef* CANx, uint32_t CAN_IT, FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_CAN_ALL_PERIPH(CANx));
- assert_param(IS_CAN_IT(CAN_IT));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- if (NewState != DISABLE)
- {
- /* Enable the selected CANx interrupt */
- CANx->IER |= CAN_IT;
- }
- else
- {
- /* Disable the selected CANx interrupt */
- CANx->IER &= ~CAN_IT;
- }
-}
-/**
- * @brief Checks whether the specified CAN flag is set or not.
- * @param CANx: where x can be 1 or 2 to to select the CAN peripheral.
- * @param CAN_FLAG: specifies the flag to check.
- * This parameter can be one of the following values:
- * @arg CAN_FLAG_RQCP0: Request MailBox0 Flag
- * @arg CAN_FLAG_RQCP1: Request MailBox1 Flag
- * @arg CAN_FLAG_RQCP2: Request MailBox2 Flag
- * @arg CAN_FLAG_FMP0: FIFO 0 Message Pending Flag
- * @arg CAN_FLAG_FF0: FIFO 0 Full Flag
- * @arg CAN_FLAG_FOV0: FIFO 0 Overrun Flag
- * @arg CAN_FLAG_FMP1: FIFO 1 Message Pending Flag
- * @arg CAN_FLAG_FF1: FIFO 1 Full Flag
- * @arg CAN_FLAG_FOV1: FIFO 1 Overrun Flag
- * @arg CAN_FLAG_WKU: Wake up Flag
- * @arg CAN_FLAG_SLAK: Sleep acknowledge Flag
- * @arg CAN_FLAG_EWG: Error Warning Flag
- * @arg CAN_FLAG_EPV: Error Passive Flag
- * @arg CAN_FLAG_BOF: Bus-Off Flag
- * @arg CAN_FLAG_LEC: Last error code Flag
- * @retval The new state of CAN_FLAG (SET or RESET).
- */
-FlagStatus CAN_GetFlagStatus(CAN_TypeDef* CANx, uint32_t CAN_FLAG)
-{
- FlagStatus bitstatus = RESET;
-
- /* Check the parameters */
- assert_param(IS_CAN_ALL_PERIPH(CANx));
- assert_param(IS_CAN_GET_FLAG(CAN_FLAG));
-
-
- if((CAN_FLAG & CAN_FLAGS_ESR) != (uint32_t)RESET)
- {
- /* Check the status of the specified CAN flag */
- if ((CANx->ESR & (CAN_FLAG & 0x000FFFFF)) != (uint32_t)RESET)
- {
- /* CAN_FLAG is set */
- bitstatus = SET;
- }
- else
- {
- /* CAN_FLAG is reset */
- bitstatus = RESET;
- }
- }
- else if((CAN_FLAG & CAN_FLAGS_MSR) != (uint32_t)RESET)
- {
- /* Check the status of the specified CAN flag */
- if ((CANx->MSR & (CAN_FLAG & 0x000FFFFF)) != (uint32_t)RESET)
- {
- /* CAN_FLAG is set */
- bitstatus = SET;
- }
- else
- {
- /* CAN_FLAG is reset */
- bitstatus = RESET;
- }
- }
- else if((CAN_FLAG & CAN_FLAGS_TSR) != (uint32_t)RESET)
- {
- /* Check the status of the specified CAN flag */
- if ((CANx->TSR & (CAN_FLAG & 0x000FFFFF)) != (uint32_t)RESET)
- {
- /* CAN_FLAG is set */
- bitstatus = SET;
- }
- else
- {
- /* CAN_FLAG is reset */
- bitstatus = RESET;
- }
- }
- else if((CAN_FLAG & CAN_FLAGS_RF0R) != (uint32_t)RESET)
- {
- /* Check the status of the specified CAN flag */
- if ((CANx->RF0R & (CAN_FLAG & 0x000FFFFF)) != (uint32_t)RESET)
- {
- /* CAN_FLAG is set */
- bitstatus = SET;
- }
- else
- {
- /* CAN_FLAG is reset */
- bitstatus = RESET;
- }
- }
- else /* If(CAN_FLAG & CAN_FLAGS_RF1R != (uint32_t)RESET) */
- {
- /* Check the status of the specified CAN flag */
- if ((uint32_t)(CANx->RF1R & (CAN_FLAG & 0x000FFFFF)) != (uint32_t)RESET)
- {
- /* CAN_FLAG is set */
- bitstatus = SET;
- }
- else
- {
- /* CAN_FLAG is reset */
- bitstatus = RESET;
- }
- }
- /* Return the CAN_FLAG status */
- return bitstatus;
-}
-
-/**
- * @brief Clears the CAN's pending flags.
- * @param CANx: where x can be 1 or 2 to to select the CAN peripheral.
- * @param CAN_FLAG: specifies the flag to clear.
- * This parameter can be one of the following values:
- * @arg CAN_FLAG_RQCP0: Request MailBox0 Flag
- * @arg CAN_FLAG_RQCP1: Request MailBox1 Flag
- * @arg CAN_FLAG_RQCP2: Request MailBox2 Flag
- * @arg CAN_FLAG_FF0: FIFO 0 Full Flag
- * @arg CAN_FLAG_FOV0: FIFO 0 Overrun Flag
- * @arg CAN_FLAG_FF1: FIFO 1 Full Flag
- * @arg CAN_FLAG_FOV1: FIFO 1 Overrun Flag
- * @arg CAN_FLAG_WKU: Wake up Flag
- * @arg CAN_FLAG_SLAK: Sleep acknowledge Flag
- * @arg CAN_FLAG_LEC: Last error code Flag
- * @retval None
- */
-void CAN_ClearFlag(CAN_TypeDef* CANx, uint32_t CAN_FLAG)
-{
- uint32_t flagtmp=0;
- /* Check the parameters */
- assert_param(IS_CAN_ALL_PERIPH(CANx));
- assert_param(IS_CAN_CLEAR_FLAG(CAN_FLAG));
-
- if (CAN_FLAG == CAN_FLAG_LEC) /* ESR register */
- {
- /* Clear the selected CAN flags */
- CANx->ESR = (uint32_t)RESET;
- }
- else /* MSR or TSR or RF0R or RF1R */
- {
- flagtmp = CAN_FLAG & 0x000FFFFF;
-
- if ((CAN_FLAG & CAN_FLAGS_RF0R)!=(uint32_t)RESET)
- {
- /* Receive Flags */
- CANx->RF0R = (uint32_t)(flagtmp);
- }
- else if ((CAN_FLAG & CAN_FLAGS_RF1R)!=(uint32_t)RESET)
- {
- /* Receive Flags */
- CANx->RF1R = (uint32_t)(flagtmp);
- }
- else if ((CAN_FLAG & CAN_FLAGS_TSR)!=(uint32_t)RESET)
- {
- /* Transmit Flags */
- CANx->TSR = (uint32_t)(flagtmp);
- }
- else /* If((CAN_FLAG & CAN_FLAGS_MSR)!=(uint32_t)RESET) */
- {
- /* Operating mode Flags */
- CANx->MSR = (uint32_t)(flagtmp);
- }
- }
-}
-
-/**
- * @brief Checks whether the specified CANx interrupt has occurred or not.
- * @param CANx: where x can be 1 or 2 to to select the CAN peripheral.
- * @param CAN_IT: specifies the CAN interrupt source to check.
- * This parameter can be one of the following values:
- * @arg CAN_IT_TME: Transmit mailbox empty Interrupt
- * @arg CAN_IT_FMP0: FIFO 0 message pending Interrupt
- * @arg CAN_IT_FF0: FIFO 0 full Interrupt
- * @arg CAN_IT_FOV0: FIFO 0 overrun Interrupt
- * @arg CAN_IT_FMP1: FIFO 1 message pending Interrupt
- * @arg CAN_IT_FF1: FIFO 1 full Interrupt
- * @arg CAN_IT_FOV1: FIFO 1 overrun Interrupt
- * @arg CAN_IT_WKU: Wake-up Interrupt
- * @arg CAN_IT_SLK: Sleep acknowledge Interrupt
- * @arg CAN_IT_EWG: Error warning Interrupt
- * @arg CAN_IT_EPV: Error passive Interrupt
- * @arg CAN_IT_BOF: Bus-off Interrupt
- * @arg CAN_IT_LEC: Last error code Interrupt
- * @arg CAN_IT_ERR: Error Interrupt
- * @retval The current state of CAN_IT (SET or RESET).
- */
-ITStatus CAN_GetITStatus(CAN_TypeDef* CANx, uint32_t CAN_IT)
-{
- ITStatus itstatus = RESET;
- /* Check the parameters */
- assert_param(IS_CAN_ALL_PERIPH(CANx));
- assert_param(IS_CAN_IT(CAN_IT));
-
- /* check the interrupt enable bit */
- if((CANx->IER & CAN_IT) != RESET)
- {
- /* in case the Interrupt is enabled, .... */
- switch (CAN_IT)
- {
- case CAN_IT_TME:
- /* Check CAN_TSR_RQCPx bits */
- itstatus = CheckITStatus(CANx->TSR, CAN_TSR_RQCP0|CAN_TSR_RQCP1|CAN_TSR_RQCP2);
- break;
- case CAN_IT_FMP0:
- /* Check CAN_RF0R_FMP0 bit */
- itstatus = CheckITStatus(CANx->RF0R, CAN_RF0R_FMP0);
- break;
- case CAN_IT_FF0:
- /* Check CAN_RF0R_FULL0 bit */
- itstatus = CheckITStatus(CANx->RF0R, CAN_RF0R_FULL0);
- break;
- case CAN_IT_FOV0:
- /* Check CAN_RF0R_FOVR0 bit */
- itstatus = CheckITStatus(CANx->RF0R, CAN_RF0R_FOVR0);
- break;
- case CAN_IT_FMP1:
- /* Check CAN_RF1R_FMP1 bit */
- itstatus = CheckITStatus(CANx->RF1R, CAN_RF1R_FMP1);
- break;
- case CAN_IT_FF1:
- /* Check CAN_RF1R_FULL1 bit */
- itstatus = CheckITStatus(CANx->RF1R, CAN_RF1R_FULL1);
- break;
- case CAN_IT_FOV1:
- /* Check CAN_RF1R_FOVR1 bit */
- itstatus = CheckITStatus(CANx->RF1R, CAN_RF1R_FOVR1);
- break;
- case CAN_IT_WKU:
- /* Check CAN_MSR_WKUI bit */
- itstatus = CheckITStatus(CANx->MSR, CAN_MSR_WKUI);
- break;
- case CAN_IT_SLK:
- /* Check CAN_MSR_SLAKI bit */
- itstatus = CheckITStatus(CANx->MSR, CAN_MSR_SLAKI);
- break;
- case CAN_IT_EWG:
- /* Check CAN_ESR_EWGF bit */
- itstatus = CheckITStatus(CANx->ESR, CAN_ESR_EWGF);
- break;
- case CAN_IT_EPV:
- /* Check CAN_ESR_EPVF bit */
- itstatus = CheckITStatus(CANx->ESR, CAN_ESR_EPVF);
- break;
- case CAN_IT_BOF:
- /* Check CAN_ESR_BOFF bit */
- itstatus = CheckITStatus(CANx->ESR, CAN_ESR_BOFF);
- break;
- case CAN_IT_LEC:
- /* Check CAN_ESR_LEC bit */
- itstatus = CheckITStatus(CANx->ESR, CAN_ESR_LEC);
- break;
- case CAN_IT_ERR:
- /* Check CAN_MSR_ERRI bit */
- itstatus = CheckITStatus(CANx->MSR, CAN_MSR_ERRI);
- break;
- default:
- /* in case of error, return RESET */
- itstatus = RESET;
- break;
- }
- }
- else
- {
- /* in case the Interrupt is not enabled, return RESET */
- itstatus = RESET;
- }
-
- /* Return the CAN_IT status */
- return itstatus;
-}
-
-/**
- * @brief Clears the CANx's interrupt pending bits.
- * @param CANx: where x can be 1 or 2 to to select the CAN peripheral.
- * @param CAN_IT: specifies the interrupt pending bit to clear.
- * This parameter can be one of the following values:
- * @arg CAN_IT_TME: Transmit mailbox empty Interrupt
- * @arg CAN_IT_FF0: FIFO 0 full Interrupt
- * @arg CAN_IT_FOV0: FIFO 0 overrun Interrupt
- * @arg CAN_IT_FF1: FIFO 1 full Interrupt
- * @arg CAN_IT_FOV1: FIFO 1 overrun Interrupt
- * @arg CAN_IT_WKU: Wake-up Interrupt
- * @arg CAN_IT_SLK: Sleep acknowledge Interrupt
- * @arg CAN_IT_EWG: Error warning Interrupt
- * @arg CAN_IT_EPV: Error passive Interrupt
- * @arg CAN_IT_BOF: Bus-off Interrupt
- * @arg CAN_IT_LEC: Last error code Interrupt
- * @arg CAN_IT_ERR: Error Interrupt
- * @retval None
- */
-void CAN_ClearITPendingBit(CAN_TypeDef* CANx, uint32_t CAN_IT)
-{
- /* Check the parameters */
- assert_param(IS_CAN_ALL_PERIPH(CANx));
- assert_param(IS_CAN_CLEAR_IT(CAN_IT));
-
- switch (CAN_IT)
- {
- case CAN_IT_TME:
- /* Clear CAN_TSR_RQCPx (rc_w1)*/
- CANx->TSR = CAN_TSR_RQCP0|CAN_TSR_RQCP1|CAN_TSR_RQCP2;
- break;
- case CAN_IT_FF0:
- /* Clear CAN_RF0R_FULL0 (rc_w1)*/
- CANx->RF0R = CAN_RF0R_FULL0;
- break;
- case CAN_IT_FOV0:
- /* Clear CAN_RF0R_FOVR0 (rc_w1)*/
- CANx->RF0R = CAN_RF0R_FOVR0;
- break;
- case CAN_IT_FF1:
- /* Clear CAN_RF1R_FULL1 (rc_w1)*/
- CANx->RF1R = CAN_RF1R_FULL1;
- break;
- case CAN_IT_FOV1:
- /* Clear CAN_RF1R_FOVR1 (rc_w1)*/
- CANx->RF1R = CAN_RF1R_FOVR1;
- break;
- case CAN_IT_WKU:
- /* Clear CAN_MSR_WKUI (rc_w1)*/
- CANx->MSR = CAN_MSR_WKUI;
- break;
- case CAN_IT_SLK:
- /* Clear CAN_MSR_SLAKI (rc_w1)*/
- CANx->MSR = CAN_MSR_SLAKI;
- break;
- case CAN_IT_EWG:
- /* Clear CAN_MSR_ERRI (rc_w1) */
- CANx->MSR = CAN_MSR_ERRI;
- /* @note the corresponding Flag is cleared by hardware depending on the CAN Bus status*/
- break;
- case CAN_IT_EPV:
- /* Clear CAN_MSR_ERRI (rc_w1) */
- CANx->MSR = CAN_MSR_ERRI;
- /* @note the corresponding Flag is cleared by hardware depending on the CAN Bus status*/
- break;
- case CAN_IT_BOF:
- /* Clear CAN_MSR_ERRI (rc_w1) */
- CANx->MSR = CAN_MSR_ERRI;
- /* @note the corresponding Flag is cleared by hardware depending on the CAN Bus status*/
- break;
- case CAN_IT_LEC:
- /* Clear LEC bits */
- CANx->ESR = RESET;
- /* Clear CAN_MSR_ERRI (rc_w1) */
- CANx->MSR = CAN_MSR_ERRI;
- break;
- case CAN_IT_ERR:
- /*Clear LEC bits */
- CANx->ESR = RESET;
- /* Clear CAN_MSR_ERRI (rc_w1) */
- CANx->MSR = CAN_MSR_ERRI;
- /* @note BOFF, EPVF and EWGF Flags are cleared by hardware depending on the CAN Bus status*/
- break;
- default:
- break;
- }
-}
- /**
- * @}
- */
-
-/**
- * @brief Checks whether the CAN interrupt has occurred or not.
- * @param CAN_Reg: specifies the CAN interrupt register to check.
- * @param It_Bit: specifies the interrupt source bit to check.
- * @retval The new state of the CAN Interrupt (SET or RESET).
- */
-static ITStatus CheckITStatus(uint32_t CAN_Reg, uint32_t It_Bit)
-{
- ITStatus pendingbitstatus = RESET;
-
- if ((CAN_Reg & It_Bit) != (uint32_t)RESET)
- {
- /* CAN_IT is set */
- pendingbitstatus = SET;
- }
- else
- {
- /* CAN_IT is reset */
- pendingbitstatus = RESET;
- }
- return pendingbitstatus;
-}
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-
-/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/ethernet/Kconfig b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/ethernet/Kconfig
deleted file mode 100644
index a6889b417..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/ethernet/Kconfig
+++ /dev/null
@@ -1,12 +0,0 @@
-
-config CAN_BUS_NAME_1
- string "can bus name"
- default "can1"
-
-config CAN_DRIVER_NAME
- string "can driver name"
- default "can1_drv"
-
-config CAN_1_DEVICE_NAME_1
- string "can bus 1 device 1 name"
- default "can1_dev1"
\ No newline at end of file
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/ethernet/Makefile b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/ethernet/Makefile
deleted file mode 100644
index cf27edf9c..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/ethernet/Makefile
+++ /dev/null
@@ -1,4 +0,0 @@
-SRC_FILES := hardware_ethernet.c connect_ethernet.c ethernetif.c
-
-
-include $(KERNEL_ROOT)/compiler.mk
\ No newline at end of file
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/ethernet/connect_ethernet.c b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/ethernet/connect_ethernet.c
deleted file mode 100644
index eb7a62661..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/ethernet/connect_ethernet.c
+++ /dev/null
@@ -1,363 +0,0 @@
-/**
- ******************************************************************************
- * @file stm32f4x7_eth_bsp.c
- * @author MCD Application Team
- * @version V1.0.0
- * @date 31-October-2011
- * @brief STM32F4x7 Ethernet hardware configuration.
- ******************************************************************************
- * @attention
- *
- * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
- * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
- * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
- * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
- * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
- * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
- *
- * © COPYRIGHT 2011 STMicroelectronics
- ******************************************************************************
- */
-
- /*
-* Copyright (c) 2020 AIIT XUOS Lab
-* XiUOS is licensed under Mulan PSL v2.
-* You can use this software according to the terms and conditions of the Mulan PSL v2.
-* You may obtain a copy of Mulan PSL v2 at:
-* http://license.coscl.org.cn/MulanPSL2
-* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
-* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
-* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
-* See the Mulan PSL v2 for more details.
-*/
-
-/**
-* @file connect_ethernet.c
-* @brief Adapted network software protocol stack and hardware operation functions
-* @version 1.0
-* @author AIIT XUOS Lab
-* @date 2021-05-29
-*/
-
-/* Includes ------------------------------------------------------------------*/
-#include "hardware_syscfg.h"
-#include "hardware_gpio.h"
-#include "hardware_rcc.h"
-#include "misc.h"
-#include "hardware_exti.h"
-#include "hardware_eth.h"
-#include "connect_ethernet.h"
-#include
-#include
-#include
-
-__IO uint32_t EthInitStatus = 0;
-__IO uint8_t EthLinkStatus = 0;
-
-/* Private function prototypes -----------------------------------------------*/
-static void ETH_GPIO_Config(void);
-static void ETH_MACDMA_Config(void);
-
-extern int32 s_xSemaphore;
-
-
-/* Private functions ---------------------------------------------------------*/
-
-/**
- * @brief ETH_BSP_Config
- * @param None
- * @retval None
- */
-void ETH_BSP_Config(void)
-{
- RCC_ClocksTypeDef RCC_Clocks;
-
- /* Configure the GPIO ports for ethernet pins */
- ETH_GPIO_Config();
-
- /* Configure the Ethernet MAC/DMA */
- ETH_MACDMA_Config();
-
- if (EthInitStatus == 0)
- {
- while(1);
- }
-
- /* Configure Systick clock source as HCLK */
- SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);
-
- /* SystTick configuration: an interrupt every 10ms */
- RCC_GetClocksFreq(&RCC_Clocks);
-
- SysTick_Config(RCC_Clocks.HCLK_Frequency / 100);
-}
-
-/**
- * @brief Configures the Ethernet Interface
- * @param None
- * @retval None
- */
-static void ETH_MACDMA_Config(void)
-{
- ETH_InitTypeDef ETH_InitStructure;
-
- /* Enable ETHERNET clock */
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_ETH_MAC | RCC_AHB1Periph_ETH_MAC_Tx |
- RCC_AHB1Periph_ETH_MAC_Rx, ENABLE);
-
- /* Reset ETHERNET on AHB Bus */
- ETH_DeInit();
-
- /* Software reset */
- ETH_SoftwareReset();
-
- /* Wait for software reset */
- while (ETH_GetSoftwareResetStatus() == SET);
-
- /* ETHERNET Configuration --------------------------------------------------*/
- /* Call ETH_StructInit if you don't like to configure all ETH_InitStructure parameter */
- ETH_StructInit(Ð_InitStructure);
-
- /* Fill ETH_InitStructure parametrs */
- /*------------------------ MAC -----------------------------------*/
- ETH_InitStructure.ETH_AutoNegotiation = ETH_AutoNegotiation_Enable;
-
-
- ETH_InitStructure.ETH_LoopbackMode = ETH_LoopbackMode_Disable;
- ETH_InitStructure.ETH_RetryTransmission = ETH_RetryTransmission_Disable;
- ETH_InitStructure.ETH_AutomaticPadCRCStrip = ETH_AutomaticPadCRCStrip_Disable;
- ETH_InitStructure.ETH_ReceiveAll = ETH_ReceiveAll_Disable;
- ETH_InitStructure.ETH_BroadcastFramesReception = ETH_BroadcastFramesReception_Enable;
- ETH_InitStructure.ETH_PromiscuousMode = ETH_PromiscuousMode_Disable;
- ETH_InitStructure.ETH_MulticastFramesFilter = ETH_MulticastFramesFilter_Perfect;
- ETH_InitStructure.ETH_UnicastFramesFilter = ETH_UnicastFramesFilter_Perfect;
-#ifdef CHECKSUM_BY_HARDWARE
- ETH_InitStructure.ETH_ChecksumOffload = ETH_ChecksumOffload_Enable;
-#endif
-
- /*------------------------ DMA -----------------------------------*/
-
- /* When we use the Checksum offload feature, we need to enable the Store and Forward mode:
- the store and forward guarantee that a whole frame is stored in the FIFO, so the MAC can insert/verify the checksum,
- if the checksum is OK the DMA can handle the frame otherwise the frame is dropped */
- ETH_InitStructure.ETH_DropTCPIPChecksumErrorFrame = ETH_DropTCPIPChecksumErrorFrame_Enable;
- ETH_InitStructure.ETH_ReceiveStoreForward = ETH_ReceiveStoreForward_Enable;
- ETH_InitStructure.ETH_TransmitStoreForward = ETH_TransmitStoreForward_Enable;
-
- ETH_InitStructure.ETH_ForwardErrorFrames = ETH_ForwardErrorFrames_Disable;
- ETH_InitStructure.ETH_ForwardUndersizedGoodFrames = ETH_ForwardUndersizedGoodFrames_Disable;
- ETH_InitStructure.ETH_SecondFrameOperate = ETH_SecondFrameOperate_Enable;
- ETH_InitStructure.ETH_AddressAlignedBeats = ETH_AddressAlignedBeats_Enable;
- ETH_InitStructure.ETH_FixedBurst = ETH_FixedBurst_Enable;
- ETH_InitStructure.ETH_RxDMABurstLength = ETH_RxDMABurstLength_32Beat;
- ETH_InitStructure.ETH_TxDMABurstLength = ETH_TxDMABurstLength_32Beat;
- ETH_InitStructure.ETH_DMAArbitration = ETH_DMAArbitration_RoundRobin_RxTx_2_1;
-
- /* Configure Ethernet */
- EthInitStatus = ETH_Init(Ð_InitStructure, DP83848_PHY_ADDRESS);
-}
-
-/**
- * @brief Configures the different GPIO ports.
- * @param None
- * @retval None
- */
-void ETH_GPIO_Config(void)
-{
- GPIO_InitTypeDef GPIO_InitStructure;
-
- /* Enable GPIOs clocks */
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA |
- RCC_AHB1Periph_GPIOB |
- RCC_AHB1Periph_GPIOC |
- RCC_AHB1Periph_GPIOI |
- RCC_AHB1Periph_GPIOG |
- RCC_AHB1Periph_GPIOH |
- RCC_AHB1Periph_GPIOF, ENABLE);
-
- /* Enable SYSCFG clock */
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
-
- /* Configure MCO (PA8) */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
- GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
- GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
-
- /* MII/RMII Media interface selection --------------------------------------*/
-#ifdef MII_MODE /* Mode MII with STM324xG-EVAL */
- #ifdef PHY_CLOCK_MCO
-
-
- /* Output HSE clock (25MHz) on MCO pin (PA8) to clock the PHY */
- RCC_MCO1Config(RCC_MCO1Source_HSE, RCC_MCO1Div_1);
- #endif /* PHY_CLOCK_MCO */
-
- SYSCFG_ETH_MediaInterfaceConfig(SYSCFG_ETH_MediaInterface_MII);
-#elif defined RMII_MODE /* Mode RMII with STM324xG-EVAL */
-
- SYSCFG_ETH_MediaInterfaceConfig(SYSCFG_ETH_MediaInterface_RMII);
-#endif
-
-/* Ethernet pins configuration ************************************************/
- /*
- ETH_MDIO -------------------------> PA2
- ETH_MDC --------------------------> PC1
- ETH_PPS_OUT ----------------------> PB5
- ETH_MII_CRS ----------------------> PH2
- ETH_MII_COL ----------------------> PH3
- ETH_MII_RX_ER --------------------> PI10
- ETH_MII_RXD2 ---------------------> PH6
- ETH_MII_RXD3 ---------------------> PH7
- ETH_MII_TX_CLK -------------------> PC3
- ETH_MII_TXD2 ---------------------> PC2
- ETH_MII_TXD3 ---------------------> PB8
- ETH_MII_RX_CLK/ETH_RMII_REF_CLK---> PA1
- ETH_MII_RX_DV/ETH_RMII_CRS_DV ----> PA7
- ETH_MII_RXD0/ETH_RMII_RXD0 -------> PC4
- ETH_MII_RXD1/ETH_RMII_RXD1 -------> PC5
- ETH_MII_TX_EN/ETH_RMII_TX_EN -----> PG11
- ETH_MII_TXD0/ETH_RMII_TXD0 -------> PG13
- ETH_MII_TXD1/ETH_RMII_TXD1 -------> PG14
- */
-
- /* Configure PA1, PA2 and PA7 */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_7;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- GPIO_PinAFConfig(GPIOA, GPIO_PinSource1, GPIO_AF_ETH);
- GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_ETH);
- GPIO_PinAFConfig(GPIOA, GPIO_PinSource7, GPIO_AF_ETH);
-
- /* Configure PB11 and PB12 */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
- GPIO_PinAFConfig(GPIOB, GPIO_PinSource11, GPIO_AF_ETH);
- GPIO_PinAFConfig(GPIOB, GPIO_PinSource12, GPIO_AF_ETH);
- GPIO_PinAFConfig(GPIOB, GPIO_PinSource13, GPIO_AF_ETH);
-
- /* Configure PC1, PC2, PC3, PC4 and PC5 */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_4 | GPIO_Pin_5;
- GPIO_Init(GPIOC, &GPIO_InitStructure);
- GPIO_PinAFConfig(GPIOC, GPIO_PinSource1, GPIO_AF_ETH);
- GPIO_PinAFConfig(GPIOC, GPIO_PinSource4, GPIO_AF_ETH);
- GPIO_PinAFConfig(GPIOC, GPIO_PinSource5, GPIO_AF_ETH);
-
-}
-
-/**
- * @brief Configure the PHY to generate an interrupt on change of link status.
- * @param PHYAddress: external PHY address
- * @retval None
- */
-uint32_t Eth_Link_PHYITConfig(uint16_t PHYAddress)
-{
- uint32_t tmpreg = 0;
-
- /* Read MICR register */
- tmpreg = ETH_ReadPHYRegister(PHYAddress, PHY_MICR);
-
- /* Enable output interrupt events to signal via the INT pin */
- tmpreg |= (uint32_t)PHY_MICR_INT_EN | PHY_MICR_INT_OE;
-
- if(!(ETH_WritePHYRegister(PHYAddress, PHY_MICR, tmpreg)))
- {
- /* Return ERROR in case of write timeout */
- return ETH_ERROR;
- }
- /* Read MISR register */
- tmpreg = ETH_ReadPHYRegister(PHYAddress, PHY_MISR);
-
- /* Enable Interrupt on change of link status */
- tmpreg |= (uint32_t)PHY_MISR_LINK_INT_EN;
-
- if(!(ETH_WritePHYRegister(PHYAddress, PHY_MISR, tmpreg)))
- {
-
- /* Return ERROR in case of write timeout */
- return ETH_ERROR;
- }
-
- /* Return SUCCESS */
- return ETH_SUCCESS;
-}
-
-/**
- * @brief EXTI configuration for Ethernet link status.
- * @param PHYAddress: external PHY address
- * @retval None
- */
-void Eth_Link_EXTIConfig(void)
-{
- GPIO_InitTypeDef GPIO_InitStructure;
- EXTI_InitTypeDef EXTI_InitStructure;
- NVIC_InitTypeDef NVIC_InitStructure;
-
- /* Enable the INT (PB14) Clock */
- RCC_AHB1PeriphClockCmd(ETH_LINK_GPIO_CLK, ENABLE);
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
-
- /* Configure INT pin as input */
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
- GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
- GPIO_InitStructure.GPIO_Pin = ETH_LINK_PIN;
- GPIO_Init(ETH_LINK_GPIO_PORT, &GPIO_InitStructure);
-
- /* Connect EXTI Line to INT Pin */
- SYSCFG_EXTILineConfig(ETH_LINK_EXTI_PORT_SOURCE, ETH_LINK_EXTI_PIN_SOURCE);
-
- /* Configure EXTI line */
- EXTI_InitStructure.EXTI_Line = ETH_LINK_EXTI_LINE;
- EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
- EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
- EXTI_InitStructure.EXTI_LineCmd = ENABLE;
- EXTI_Init(&EXTI_InitStructure);
-
- /* Enable and set the EXTI interrupt to the highest priority */
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
- NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
-}
-
-/**
- * @brief This function handles Ethernet link status.
- * @param None
- * @retval None
- */
-void Eth_Link_ITHandler(uint16_t PHYAddress)
-{
- /* Check whether the link interrupt has occurred or not */
- if(((ETH_ReadPHYRegister(PHYAddress, PHY_MISR)) & PHY_LINK_STATUS) != 0)
- {
- EthLinkStatus = ~EthLinkStatus;
-
- }
-}
-
-void assert_failed(uint8_t* file, uint32_t line)
-{
- /* User can add his own implementation to report the file name and line number,
- ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
-
- /* Infinite loop */
- while (1)
- {}
-}
-
-#ifdef BSP_USING_LWIP
-void ETHERNET_IRQHandler(int irq_num, void *arg)
-{
- KPrintf("ethernet irq comes one ...\n");
- ETH_DMAClearITPendingBit(ETH_DMA_IT_R);
- ETH_DMAClearITPendingBit(ETH_DMA_IT_NIS);
- KSemaphoreAbandon(s_xSemaphore);
-}
-DECLARE_HW_IRQ(ETH_IRQn, ETHERNET_IRQHandler, NONE);
-#endif
-
-
-
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/ethernet/ethernetif.c b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/ethernet/ethernetif.c
deleted file mode 100644
index 616cc983d..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/ethernet/ethernetif.c
+++ /dev/null
@@ -1,445 +0,0 @@
-/**
- * @file
- * Ethernet Interface Skeleton
- *
- */
-
-/*
- * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
- *
- * This file is part of the lwIP TCP/IP stack.
- *
- * Author: Adam Dunkels
- *
- */
-
-/*
- * This file is a skeleton for developing Ethernet network interface
- * drivers for lwIP. Add code to the low_level functions and do a
- * search-and-replace for the word "ethernetif" to replace it with
- * something that better describes your network interface.
- */
-
-#include "lwip/opt.h"
-#include "lwip/def.h"
-#include "lwip/mem.h"
-#include "lwip/pbuf.h"
-#include "lwip/sys.h"
-#include "netif/etharp.h"
-#include "err.h"
-#include "ethernetif.h"
-
-#include "main.h"
-#include
-#include
-#include
-#include
-#include
-
-#define netifMTU (1500)
-#define netifINTERFACE_TASK_STACK_SIZE ( 2048 )
-#define netifINTERFACE_TASK_PRIORITY ( configMAX_PRIORITIES - 1 )
-#define netifGUARD_BLOCK_TIME ( 250 )
-/* The time to block waiting for input. */
-#define emacBLOCK_TIME_WAITING_FOR_INPUT ( ( portTickType ) 100 )
-
-/* Define those to better describe your network interface. */
-#define IFNAME0 's'
-#define IFNAME1 't'
-
-/* MAC ADDRESS: MAC_ADDR0:MAC_ADDR1:MAC_ADDR2:MAC_ADDR3:MAC_ADDR4:MAC_ADDR5 */
-#define MAC_ADDR0 2
-#define MAC_ADDR1 0
-#define MAC_ADDR2 0
-#define MAC_ADDR3 0
-#define MAC_ADDR4 0
-#define MAC_ADDR5 0
-
-static struct netif *s_pxNetIf = NULL;
-int32 s_xSemaphore = -1;
-
-
-/* Ethernet Rx & Tx DMA Descriptors */
-extern ETH_DMADESCTypeDef DMARxDscrTab[ETH_RXBUFNB], DMATxDscrTab[ETH_TXBUFNB];
-
-/* Ethernet Receive buffers */
-extern uint8_t Rx_Buff[ETH_RXBUFNB][ETH_RX_BUF_SIZE];
-
-/* Ethernet Transmit buffers */
-extern uint8_t Tx_Buff[ETH_TXBUFNB][ETH_TX_BUF_SIZE];
-
-/* Global pointers to track current transmit and receive descriptors */
-extern ETH_DMADESCTypeDef *DMATxDescToSet;
-extern ETH_DMADESCTypeDef *DMARxDescToGet;
-
-/* Global pointer for last received frame infos */
-extern ETH_DMA_Rx_Frame_infos *DMA_RX_FRAME_infos;
-
-
-
-
-void ethernetif_input( void * pvParameters );
-void LoopGetMacPkg(void * pvParameters);
-
-static void arp_timer(void *arg);
-
-
-
-uint32_t TCPTimer = 0;
-uint32_t ARPTimer = 0;
-__IO uint32_t LocalTime = 0; /* this variable is used to create a time reference incremented by 10ms */
-
-void LwIP_Periodic_Handle(__IO uint32_t localtime)
-{
-#if LWIP_TCP
- /* TCP periodic process every 250 ms */
- if (localtime - TCPTimer >= TCP_TMR_INTERVAL)
- {
- TCPTimer = localtime;
- tcp_tmr();
- }
-#endif
-
- /* ARP periodic process every 5s */
- if ((localtime - ARPTimer) >= ARP_TMR_INTERVAL)
- {
- ARPTimer = localtime;
- etharp_tmr();
- }
-
-}
-
-void LwIP_Pkt_Handle(struct netif *netif)
-{
- /* Read a received packet from the Ethernet buffers and send it to the lwIP for handling */
- ethernetif_input(netif);
-}
-
-void Time_Update_LwIP(void)
-{
- LocalTime += MS_PER_SYSTICK_F407;
-}
-
-
-
-/**
- * In this function, the hardware should be initialized.
- * Called from ethernetif_init().
- *
- * @param netif the already initialized lwip network interface structure
- * for this ethernetif
- */
-static void low_level_init(struct netif *netif)
-{
- uint32_t i;
-
- /* set netif MAC hardware address length */
- netif->hwaddr_len = ETHARP_HWADDR_LEN;
-
- /* set netif MAC hardware address */
- netif->hwaddr[0] = MAC_ADDR0;
- netif->hwaddr[1] = MAC_ADDR1;
- netif->hwaddr[2] = MAC_ADDR2;
- netif->hwaddr[3] = MAC_ADDR3;
- netif->hwaddr[4] = MAC_ADDR4;
- netif->hwaddr[5] = MAC_ADDR5;
-
- /* set netif maximum transfer unit */
- netif->mtu = 1500;
-
- /* Accept broadcast address and ARP traffic */
- netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP;
-
- s_pxNetIf =netif;
-
- /* create binary semaphore used for informing ethernetif of frame reception */
- if (s_xSemaphore < 0)
- {
- s_xSemaphore = KSemaphoreCreate(0);
- }
-
- /* initialize MAC address in ethernet MAC */
- ETH_MACAddressConfig(ETH_MAC_Address0, netif->hwaddr);
-
- /* Initialize Tx Descriptors list: Chain Mode */
- ETH_DMATxDescChainInit(DMATxDscrTab, &Tx_Buff[0][0], ETH_TXBUFNB);
- /* Initialize Rx Descriptors list: Chain Mode */
- ETH_DMARxDescChainInit(DMARxDscrTab, &Rx_Buff[0][0], ETH_RXBUFNB);
-
- /* Enable MAC and DMA transmission and reception */
- ETH_Start();
-
- /* Enable Ethernet Rx interrrupt */
- {
- for(i=0; i= 0)
- {
- StartupKTask(thr_id);
- }
- else
- {
- KPrintf("Eth create failed !");
- }
-}
-
-
-/**
- * This function should do the actual transmission of the packet. The packet is
- * contained in the pbuf that is passed to the function. This pbuf
- * might be chained.
- *
- * @param netif the lwip network interface structure for this ethernetif
- * @param p the MAC packet to send (e.g. IP packet including MAC addresses and type)
- * @return ERR_OK if the packet could be sent
- * an err_t value if the packet couldn't be sent
- *
- * @note Returning ERR_MEM here if a DMA queue of your MAC is full can lead to
- * strange results. You might consider waiting for space in the DMA queue
- * to become availale since the stack doesn't retry to send a packet
- * dropped because of memory failure (except for the TCP timers).
- */
-
-static err_t low_level_output(struct netif *netif, struct pbuf *p)
-{
- static int32 sem = -1;
- struct pbuf *q;
- uint32_t l = 0;
- u8 *buffer ;
-
- if(sem < 0)
- {
- sem = KSemaphoreCreate(1);
- }
-
- KSemaphoreObtain(sem, WAITING_FOREVER);
-
-
- buffer = (u8 *)(DMATxDescToSet->Buffer1Addr);
- for(q = p; q != NULL; q = q->next)
- {
- memcpy((u8_t*)&buffer[l], q->payload, q->len);
- l = l + q->len;
- }
- ETH_Prepare_Transmit_Descriptors(l);
-
- KSemaphoreAbandon(sem);
-
- return ERR_OK;
-}
-
-
-
-
-
-/**
- * Should allocate a pbuf and transfer the bytes of the incoming
- * packet from the interface into the pbuf.
- *
- * @param netif the lwip network interface structure for this ethernetif
- * @return a pbuf filled with the received packet (including MAC header)
- * NULL on memory error
- */
-static struct pbuf * low_level_input(struct netif *netif)
-{
- struct pbuf *p, *q;
- u16_t len;
- uint32_t l=0,i =0;
- FrameTypeDef frame;
- u8 *buffer;
- __IO ETH_DMADESCTypeDef *DMARxNextDesc;
-
- p = NULL;
-
- /* Get received frame */
- frame = ETH_Get_Received_Frame_interrupt();
-
- /* check that frame has no error */
- if ((frame.descriptor->Status & ETH_DMARxDesc_ES) == (uint32_t)RESET)
- {
-
- /* Obtain the size of the packet and put it into the "len" variable. */
- len = frame.length;
- buffer = (u8 *)frame.buffer;
-
- /* We allocate a pbuf chain of pbufs from the pool. */
- p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL);
-
- /* Copy received frame from ethernet driver buffer to stack buffer */
- if (p != NULL)
- {
- for (q = p; q != NULL; q = q->next)
- {
- memcpy((u8_t*)q->payload, (u8_t*)&buffer[l], q->len);
- l = l + q->len;
- }
- }
- }
-
- /* Release descriptors to DMA */
- /* Check if received frame with multiple DMA buffer segments */
- if (DMA_RX_FRAME_infos->Seg_Count > 1)
- {
- DMARxNextDesc = DMA_RX_FRAME_infos->FS_Rx_Desc;
- }
- else
- {
- DMARxNextDesc = frame.descriptor;
- }
-
- /* Set Own bit in Rx descriptors: gives the buffers back to DMA */
- for (i=0; iSeg_Count; i++)
- {
- DMARxNextDesc->Status = ETH_DMARxDesc_OWN;
- DMARxNextDesc = (ETH_DMADESCTypeDef *)(DMARxNextDesc->Buffer2NextDescAddr);
- }
-
- /* Clear Segment_Count */
- DMA_RX_FRAME_infos->Seg_Count =0;
-
-
- /* When Rx Buffer unavailable flag is set: clear it and resume reception */
- if ((ETH->DMASR & ETH_DMASR_RBUS) != (u32)RESET)
- {
- /* Clear RBUS ETHERNET DMA flag */
- ETH->DMASR = ETH_DMASR_RBUS;
-
- /* Resume DMA reception */
- ETH->DMARPDR = 0;
- }
- return p;
-}
-
-
-/**
- * This function is the ethernetif_input task, it is processed when a packet
- * is ready to be read from the interface. It uses the function low_level_input()
- * that should handle the actual reception of bytes from the network
- * interface. Then the type of the received packet is determined and
- * the appropriate input function is called.
- *
- * @param netif the lwip network interface structure for this ethernetif
- */
-void ethernetif_input( void * pvParameters )
-{
- struct pbuf *p;
-
- for( ;; )
- {
- if (KSemaphoreObtain( s_xSemaphore, WAITING_FOREVER)==EOK)
- {
- p = low_level_input( s_pxNetIf );
-
- if (ERR_OK != s_pxNetIf->input( p, s_pxNetIf))
- {
- KPrintf("netif input return not OK ! \n");
- pbuf_free(p);
- p=NULL;
- }
- }
- }
-}
-
-void LoopGetMacPkg(void * pvParameters)
-{
- // Loop Get MAX Pkg
- struct netif *netif = (struct netif *)pvParameters;
- while (1)
- {
- /* check if any packet received */
- if (ETH_CheckFrameReceived())
- {
- KPrintf("ETH_CheckFrameReceived invoke !\n");
- /* process received ethernet packet */
- LwIP_Pkt_Handle(netif);
- }
- /* handle periodic timers for LwIP */
- LwIP_Periodic_Handle(LocalTime);
- }
-}
-
-/**
- * Should be called at the beginning of the program to set up the
- * network interface. It calls the function low_level_init() to do the
- * actual setup of the hardware.
- *
- * This function should be passed as a parameter to netif_add().
- *
- * @param netif the lwip network interface structure for this ethernetif
- * @return ERR_OK if the loopif is initialized
- * ERR_MEM if private data couldn't be allocated
- * any other err_t on error
- */
-err_t ethernetif_init(struct netif *netif)
-{
- LWIP_ASSERT("netif != NULL", (netif != NULL));
-
-#if LWIP_NETIF_HOSTNAME
- /* Initialize interface hostname */
- netif->hostname = "lwip";
-#endif /* LWIP_NETIF_HOSTNAME */
-
- netif->name[0] = IFNAME0;
- netif->name[1] = IFNAME1;
-
- netif->output = etharp_output;
- netif->linkoutput = low_level_output;
-
- /* initialize the hardware */
- low_level_init(netif);
-
- etharp_init();
- sys_timeout(ARP_TMR_INTERVAL, arp_timer, NULL);
-
- return ERR_OK;
-}
-
-
-static void arp_timer(void *arg)
-{
- etharp_tmr();
- sys_timeout(ARP_TMR_INTERVAL, arp_timer, NULL);
-}
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/ethernet/hardware_ethernet.c b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/ethernet/hardware_ethernet.c
deleted file mode 100644
index 20146a1b2..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/ethernet/hardware_ethernet.c
+++ /dev/null
@@ -1,2718 +0,0 @@
-/******************************************************************************
-/**
- * @file hardware_ethernet.c
- * @author MCD Application Team
- * @version V1.0.0
- * @date 14-October-2011
- * @brief This file is the low level driver for STM32F407xx/417xx Ethernet Controller.
- * This driver does not include low level functions for PTP time-stamp.
- ******************************************************************************
- * @attention
- *
- * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
- * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
- * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
- * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
- * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
- * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
- *
- * © COPYRIGHT 2011 STMicroelectronics
- ******************************************************************************
- */
-
-/* Includes ------------------------------------------------------------------*/
-#include "hardware_eth.h"
-#include "hardware_rcc.h"
-#include "hardware_conf.h"
-#include
-#include
-
-/** @addtogroup STM32F4x7_ETH_Driver
- * @brief ETH driver modules
- * @{
- */
-
-/** @defgroup ETH_Private_TypesDefinitions
- * @{
- */
-/**
- * @}
- */
-
-
-/** @defgroup ETH_Private_Defines
- * @{
- */
-
-/**
- * @}
- */
-
-/** @defgroup ETH_Private_Macros
- * @{
- */
-/**
- * @}
- */
-
-/** @defgroup ETH_Private_Variables
- * @{
- */
-
-#if defined (__CC_ARM) /*!< ARM Compiler */
- __align(4)
- ETH_DMADESCTypeDef DMARxDscrTab[ETH_RXBUFNB];/* Ethernet Rx MA Descriptor */
- __align(4)
- ETH_DMADESCTypeDef DMATxDscrTab[ETH_TXBUFNB];/* Ethernet Tx DMA Descriptor */
- __align(4)
- uint8_t Rx_Buff[ETH_RXBUFNB][ETH_RX_BUF_SIZE]; /* Ethernet Receive Buffer */
- __align(4)
- uint8_t Tx_Buff[ETH_TXBUFNB][ETH_TX_BUF_SIZE]; /* Ethernet Transmit Buffer */
-
-#elif defined ( __ICCARM__ ) /*!< IAR Compiler */
- #pragma data_alignment=4
- ETH_DMADESCTypeDef DMARxDscrTab[ETH_RXBUFNB];/* Ethernet Rx MA Descriptor */
- #pragma data_alignment=4
- ETH_DMADESCTypeDef DMATxDscrTab[ETH_TXBUFNB];/* Ethernet Tx DMA Descriptor */
- #pragma data_alignment=4
- uint8_t Rx_Buff[ETH_RXBUFNB][ETH_RX_BUF_SIZE]; /* Ethernet Receive Buffer */
- #pragma data_alignment=4
- uint8_t Tx_Buff[ETH_TXBUFNB][ETH_TX_BUF_SIZE]; /* Ethernet Transmit Buffer */
-
-#elif defined (__GNUC__) /*!< GNU Compiler */
- ETH_DMADESCTypeDef DMARxDscrTab[ETH_RXBUFNB] __attribute__ ((aligned (4))); /* Ethernet Rx DMA Descriptor */
- ETH_DMADESCTypeDef DMATxDscrTab[ETH_TXBUFNB] __attribute__ ((aligned (4))); /* Ethernet Tx DMA Descriptor */
- uint8_t Rx_Buff[ETH_RXBUFNB][ETH_RX_BUF_SIZE] __attribute__ ((aligned (4))); /* Ethernet Receive Buffer */
- uint8_t Tx_Buff[ETH_TXBUFNB][ETH_TX_BUF_SIZE] __attribute__ ((aligned (4))); /* Ethernet Transmit Buffer */
-
-#elif defined (__TASKING__) /*!< TASKING Compiler */
- __align(4)
- ETH_DMADESCTypeDef DMARxDscrTab[ETH_RXBUFNB];/* Ethernet Rx MA Descriptor */
- __align(4)
- ETH_DMADESCTypeDef DMATxDscrTab[ETH_TXBUFNB];/* Ethernet Tx DMA Descriptor */
- __align(4)
- uint8_t Rx_Buff[ETH_RXBUFNB][ETH_RX_BUF_SIZE]; /* Ethernet Receive Buffer */
- __align(4)
- uint8_t Tx_Buff[ETH_TXBUFNB][ETH_TX_BUF_SIZE]; /* Ethernet Transmit Buffer */
-
-#endif /* __CC_ARM */
-
-
-/* Global pointers on Tx and Rx descriptor used to track transmit and receive descriptors */
-__IO ETH_DMADESCTypeDef *DMATxDescToSet;
-__IO ETH_DMADESCTypeDef *DMARxDescToGet;
-
-
-/* Structure used to hold the last received packet descriptors info */
-
-ETH_DMA_Rx_Frame_infos RX_Frame_Descriptor;
-__IO ETH_DMA_Rx_Frame_infos *DMA_RX_FRAME_infos;
-__IO uint32_t Frame_Rx_index;
-
-
-/**
- * @}
- */
-
-/** @defgroup ETH_Private_FunctionPrototypes
- * @{
- */
-/**
- * @}
- */
-
-/** @defgroup ETH_Private_Functions
- * @{
- */
-
-#ifndef USE_Delay
-/**
- * @brief Inserts a delay time.
- * @param nCount: specifies the delay time length.
- * @retval None
- */
-static void ETH_Delay(__IO uint32_t nCount)
-{
- __IO uint32_t index = 0;
- for(index = nCount; index != 0; index--)
- {
- }
-}
-#endif /* USE_Delay*/
-
-
-
-/******************************************************************************/
-/* Global ETH MAC/DMA functions */
-/******************************************************************************/
-
-/**
- * @brief Deinitializes the ETHERNET peripheral registers to their default reset values.
- * @param None
- * @retval None
- */
-void ETH_DeInit(void)
-{
- RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_ETH_MAC, ENABLE);
- RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_ETH_MAC, DISABLE);
-}
-
-
-/**
- * @brief Fills each ETH_InitStruct member with its default value.
- * @param ETH_InitStruct: pointer to a ETH_InitTypeDef structure which will be initialized.
- * @retval None
- */
-void ETH_StructInit(ETH_InitTypeDef* ETH_InitStruct)
-{
- /* ETH_InitStruct members default value */
- /*------------------------ MAC Configuration ---------------------------*/
-
- /* PHY Auto-negotiation enabled */
- ETH_InitStruct->ETH_AutoNegotiation = ETH_AutoNegotiation_Enable;
- /* MAC watchdog enabled: cuts-off long frame */
- ETH_InitStruct->ETH_Watchdog = ETH_Watchdog_Enable;
- /* MAC Jabber enabled in Half-duplex mode */
- ETH_InitStruct->ETH_Jabber = ETH_Jabber_Enable;
- /* Ethernet interframe gap set to 96 bits */
- ETH_InitStruct->ETH_InterFrameGap = ETH_InterFrameGap_96Bit;
- /* Carrier Sense Enabled in Half-Duplex mode */
- ETH_InitStruct->ETH_CarrierSense = ETH_CarrierSense_Enable;
- /* PHY speed configured to 100Mbit/s */
- ETH_InitStruct->ETH_Speed = ETH_Speed_100M;
- /* Receive own Frames in Half-Duplex mode enabled */
- ETH_InitStruct->ETH_ReceiveOwn = ETH_ReceiveOwn_Enable;
- /* MAC MII loopback disabled */
- ETH_InitStruct->ETH_LoopbackMode = ETH_LoopbackMode_Disable;
- /* Full-Duplex mode selected */
- ETH_InitStruct->ETH_Mode = ETH_Mode_FullDuplex;
- /* IPv4 and TCP/UDP/ICMP frame Checksum Offload disabled */
- ETH_InitStruct->ETH_ChecksumOffload = ETH_ChecksumOffload_Disable;
- /* Retry Transmission enabled for half-duplex mode */
- ETH_InitStruct->ETH_RetryTransmission = ETH_RetryTransmission_Enable;
- /* Automatic PAD/CRC strip disabled*/
- ETH_InitStruct->ETH_AutomaticPadCRCStrip = ETH_AutomaticPadCRCStrip_Disable;
- /* half-duplex mode retransmission Backoff time_limit = 10 slot times*/
- ETH_InitStruct->ETH_BackOffLimit = ETH_BackOffLimit_10;
- /* half-duplex mode Deferral check disabled */
- ETH_InitStruct->ETH_DeferralCheck = ETH_DeferralCheck_Disable;
- /* Receive all frames disabled */
- ETH_InitStruct->ETH_ReceiveAll = ETH_ReceiveAll_Disable;
- /* Source address filtering (on the optional MAC addresses) disabled */
- ETH_InitStruct->ETH_SourceAddrFilter = ETH_SourceAddrFilter_Disable;
- /* Do not forward control frames that do not pass the address filtering */
- ETH_InitStruct->ETH_PassControlFrames = ETH_PassControlFrames_BlockAll;
- /* Disable reception of Broadcast frames */
- ETH_InitStruct->ETH_BroadcastFramesReception = ETH_BroadcastFramesReception_Disable;
- /* Normal Destination address filtering (not reverse addressing) */
- ETH_InitStruct->ETH_DestinationAddrFilter = ETH_DestinationAddrFilter_Normal;
- /* Promiscuous address filtering mode disabled */
- ETH_InitStruct->ETH_PromiscuousMode = ETH_PromiscuousMode_Disable;
- /* Perfect address filtering for multicast addresses */
- ETH_InitStruct->ETH_MulticastFramesFilter = ETH_MulticastFramesFilter_Perfect;
- /* Perfect address filtering for unicast addresses */
- ETH_InitStruct->ETH_UnicastFramesFilter = ETH_UnicastFramesFilter_Perfect;
- /* Initialize hash table high and low regs */
- ETH_InitStruct->ETH_HashTableHigh = 0x0;
- ETH_InitStruct->ETH_HashTableLow = 0x0;
- /* Flow control config (flow control disabled)*/
- ETH_InitStruct->ETH_PauseTime = 0x0;
- ETH_InitStruct->ETH_ZeroQuantaPause = ETH_ZeroQuantaPause_Disable;
- ETH_InitStruct->ETH_PauseLowThreshold = ETH_PauseLowThreshold_Minus4;
- ETH_InitStruct->ETH_UnicastPauseFrameDetect = ETH_UnicastPauseFrameDetect_Disable;
- ETH_InitStruct->ETH_ReceiveFlowControl = ETH_ReceiveFlowControl_Disable;
- ETH_InitStruct->ETH_TransmitFlowControl = ETH_TransmitFlowControl_Disable;
- /* VLANtag config (VLAN field not checked) */
- ETH_InitStruct->ETH_VLANTagComparison = ETH_VLANTagComparison_16Bit;
- ETH_InitStruct->ETH_VLANTagIdentifier = 0x0;
-
- /*---------------------- DMA Configuration -------------------------------*/
-
- /* Drops frames with with TCP/IP checksum errors */
- ETH_InitStruct->ETH_DropTCPIPChecksumErrorFrame = ETH_DropTCPIPChecksumErrorFrame_Disable;
- /* Store and forward mode enabled for receive */
- ETH_InitStruct->ETH_ReceiveStoreForward = ETH_ReceiveStoreForward_Enable;
- /* Flush received frame that created FIFO overflow */
- ETH_InitStruct->ETH_FlushReceivedFrame = ETH_FlushReceivedFrame_Enable;
- /* Store and forward mode enabled for transmit */
- ETH_InitStruct->ETH_TransmitStoreForward = ETH_TransmitStoreForward_Enable;
- /* Threshold TXFIFO level set to 64 bytes (used when threshold mode is enabled) */
- ETH_InitStruct->ETH_TransmitThresholdControl = ETH_TransmitThresholdControl_64Bytes;
- /* Disable forwarding frames with errors (short frames, CRC,...)*/
- ETH_InitStruct->ETH_ForwardErrorFrames = ETH_ForwardErrorFrames_Disable;
- /* Disable undersized good frames */
- ETH_InitStruct->ETH_ForwardUndersizedGoodFrames = ETH_ForwardUndersizedGoodFrames_Disable;
- /* Threshold RXFIFO level set to 64 bytes (used when Cut-through mode is enabled) */
- ETH_InitStruct->ETH_ReceiveThresholdControl = ETH_ReceiveThresholdControl_64Bytes;
- /* Disable Operate on second frame (transmit a second frame to FIFO without
- waiting status of previous frame*/
- ETH_InitStruct->ETH_SecondFrameOperate = ETH_SecondFrameOperate_Disable;
- /* DMA works on 32-bit aligned start source and destinations addresses */
- ETH_InitStruct->ETH_AddressAlignedBeats = ETH_AddressAlignedBeats_Enable;
- /* Enabled Fixed Burst Mode (mix of INC4, INC8, INC16 and SINGLE DMA transactions */
- ETH_InitStruct->ETH_FixedBurst = ETH_FixedBurst_Enable;
- /* DMA transfer max burst length = 32 beats = 32 x 32bits */
- ETH_InitStruct->ETH_RxDMABurstLength = ETH_RxDMABurstLength_32Beat;
- ETH_InitStruct->ETH_TxDMABurstLength = ETH_TxDMABurstLength_32Beat;
- /* DMA Ring mode skip length = 0 */
- ETH_InitStruct->ETH_DescriptorSkipLength = 0x0;
- /* Equal priority (round-robin) between transmit and receive DMA engines */
- ETH_InitStruct->ETH_DMAArbitration = ETH_DMAArbitration_RoundRobin_RxTx_1_1;
-}
-
-
-/**
- * @brief Initializes the ETHERNET peripheral according to the specified
- * parameters in the ETH_InitStruct .
- * @param ETH_InitStruct: pointer to a ETH_InitTypeDef structure that contains
- * the configuration information for the specified ETHERNET peripheral.
- * @param PHYAddress: external PHY address
- * @retval ETH_ERROR: Ethernet initialization failed
- * ETH_SUCCESS: Ethernet successfully initialized
- */
-uint32_t ETH_Init(ETH_InitTypeDef* ETH_InitStruct, uint16_t PHYAddress)
-{
- uint32_t RegValue = 0, tmpreg = 0;
- __IO uint32_t i = 0;
- RCC_ClocksTypeDef rcc_clocks;
- uint32_t hclk = 60000000;
- __IO uint32_t timeout = 0;
- /* Check the parameters */
- /* MAC --------------------------*/
- assert_param(IS_ETH_AUTONEGOTIATION(ETH_InitStruct->ETH_AutoNegotiation));
- assert_param(IS_ETH_WATCHDOG(ETH_InitStruct->ETH_Watchdog));
- assert_param(IS_ETH_JABBER(ETH_InitStruct->ETH_Jabber));
- assert_param(IS_ETH_INTER_FRAME_GAP(ETH_InitStruct->ETH_InterFrameGap));
- assert_param(IS_ETH_CARRIER_SENSE(ETH_InitStruct->ETH_CarrierSense));
- assert_param(IS_ETH_SPEED(ETH_InitStruct->ETH_Speed));
- assert_param(IS_ETH_RECEIVE_OWN(ETH_InitStruct->ETH_ReceiveOwn));
- assert_param(IS_ETH_LOOPBACK_MODE(ETH_InitStruct->ETH_LoopbackMode));
- assert_param(IS_ETH_DUPLEX_MODE(ETH_InitStruct->ETH_Mode));
- assert_param(IS_ETH_CHECKSUM_OFFLOAD(ETH_InitStruct->ETH_ChecksumOffload));
- assert_param(IS_ETH_RETRY_TRANSMISSION(ETH_InitStruct->ETH_RetryTransmission));
- assert_param(IS_ETH_AUTOMATIC_PADCRC_STRIP(ETH_InitStruct->ETH_AutomaticPadCRCStrip));
- assert_param(IS_ETH_BACKOFF_LIMIT(ETH_InitStruct->ETH_BackOffLimit));
- assert_param(IS_ETH_DEFERRAL_CHECK(ETH_InitStruct->ETH_DeferralCheck));
- assert_param(IS_ETH_RECEIVE_ALL(ETH_InitStruct->ETH_ReceiveAll));
- assert_param(IS_ETH_SOURCE_ADDR_FILTER(ETH_InitStruct->ETH_SourceAddrFilter));
- assert_param(IS_ETH_CONTROL_FRAMES(ETH_InitStruct->ETH_PassControlFrames));
- assert_param(IS_ETH_BROADCAST_FRAMES_RECEPTION(ETH_InitStruct->ETH_BroadcastFramesReception));
- assert_param(IS_ETH_DESTINATION_ADDR_FILTER(ETH_InitStruct->ETH_DestinationAddrFilter));
- // assert_param(IS_ETH_PROMISCIOUS_MODE(ETH_InitStruct->ETH_PromiscuousMode));
- assert_param(IS_ETH_MULTICAST_FRAMES_FILTER(ETH_InitStruct->ETH_MulticastFramesFilter));
- assert_param(IS_ETH_UNICAST_FRAMES_FILTER(ETH_InitStruct->ETH_UnicastFramesFilter));
- assert_param(IS_ETH_PAUSE_TIME(ETH_InitStruct->ETH_PauseTime));
- assert_param(IS_ETH_ZEROQUANTA_PAUSE(ETH_InitStruct->ETH_ZeroQuantaPause));
- assert_param(IS_ETH_PAUSE_LOW_THRESHOLD(ETH_InitStruct->ETH_PauseLowThreshold));
- assert_param(IS_ETH_UNICAST_PAUSE_FRAME_DETECT(ETH_InitStruct->ETH_UnicastPauseFrameDetect));
- assert_param(IS_ETH_RECEIVE_FLOWCONTROL(ETH_InitStruct->ETH_ReceiveFlowControl));
- assert_param(IS_ETH_TRANSMIT_FLOWCONTROL(ETH_InitStruct->ETH_TransmitFlowControl));
- assert_param(IS_ETH_VLAN_TAG_COMPARISON(ETH_InitStruct->ETH_VLANTagComparison));
- assert_param(IS_ETH_VLAN_TAG_IDENTIFIER(ETH_InitStruct->ETH_VLANTagIdentifier));
- /* DMA --------------------------*/
- assert_param(IS_ETH_DROP_TCPIP_CHECKSUM_FRAME(ETH_InitStruct->ETH_DropTCPIPChecksumErrorFrame));
- assert_param(IS_ETH_RECEIVE_STORE_FORWARD(ETH_InitStruct->ETH_ReceiveStoreForward));
- assert_param(IS_ETH_FLUSH_RECEIVE_FRAME(ETH_InitStruct->ETH_FlushReceivedFrame));
- assert_param(IS_ETH_TRANSMIT_STORE_FORWARD(ETH_InitStruct->ETH_TransmitStoreForward));
- assert_param(IS_ETH_TRANSMIT_THRESHOLD_CONTROL(ETH_InitStruct->ETH_TransmitThresholdControl));
- assert_param(IS_ETH_FORWARD_ERROR_FRAMES(ETH_InitStruct->ETH_ForwardErrorFrames));
- assert_param(IS_ETH_FORWARD_UNDERSIZED_GOOD_FRAMES(ETH_InitStruct->ETH_ForwardUndersizedGoodFrames));
- assert_param(IS_ETH_RECEIVE_THRESHOLD_CONTROL(ETH_InitStruct->ETH_ReceiveThresholdControl));
- assert_param(IS_ETH_SECOND_FRAME_OPERATE(ETH_InitStruct->ETH_SecondFrameOperate));
- assert_param(IS_ETH_ADDRESS_ALIGNED_BEATS(ETH_InitStruct->ETH_AddressAlignedBeats));
- assert_param(IS_ETH_FIXED_BURST(ETH_InitStruct->ETH_FixedBurst));
- assert_param(IS_ETH_RXDMA_BURST_LENGTH(ETH_InitStruct->ETH_RxDMABurstLength));
- assert_param(IS_ETH_TXDMA_BURST_LENGTH(ETH_InitStruct->ETH_TxDMABurstLength));
- assert_param(IS_ETH_DMA_DESC_SKIP_LENGTH(ETH_InitStruct->ETH_DescriptorSkipLength));
- assert_param(IS_ETH_DMA_ARBITRATION_ROUNDROBIN_RXTX(ETH_InitStruct->ETH_DMAArbitration));
- /*-------------------------------- MAC Config ------------------------------*/
- /*---------------------- ETHERNET MACMIIAR Configuration -------------------*/
- /* Get the ETHERNET MACMIIAR value */
- tmpreg = ETH->MACMIIAR;
- /* Clear CSR Clock Range CR[2:0] bits */
- tmpreg &= MACMIIAR_CR_MASK;
- /* Get hclk frequency value */
- RCC_GetClocksFreq(&rcc_clocks);
- hclk = rcc_clocks.HCLK_Frequency;
-
- /* Set CR bits depending on hclk value */
- if((hclk >= 20000000)&&(hclk < 35000000))
- {
- /* CSR Clock Range between 20-35 MHz */
- tmpreg |= (uint32_t)ETH_MACMIIAR_CR_Div16;
- }
- else if((hclk >= 35000000)&&(hclk < 60000000))
- {
- /* CSR Clock Range between 35-60 MHz */
- tmpreg |= (uint32_t)ETH_MACMIIAR_CR_Div26;
- }
- else if((hclk >= 60000000)&&(hclk < 100000000))
- {
- /* CSR Clock Range between 60-100 MHz */
- tmpreg |= (uint32_t)ETH_MACMIIAR_CR_Div42;
- }
- else if((hclk >= 100000000)&&(hclk < 150000000))
- {
- /* CSR Clock Range between 100-150 MHz */
- tmpreg |= (uint32_t)ETH_MACMIIAR_CR_Div62;
- }
- else /* ((hclk >= 150000000)&&(hclk <= 168000000)) */
- {
- /* CSR Clock Range between 150-168 MHz */
- tmpreg |= (uint32_t)ETH_MACMIIAR_CR_Div102;
- }
-
- /* Write to ETHERNET MAC MIIAR: Configure the ETHERNET CSR Clock Range */
- ETH->MACMIIAR = (uint32_t)tmpreg;
- /*-------------------- PHY initialization and configuration ----------------*/
- /* Put the PHY in reset mode */
- if(!(ETH_WritePHYRegister(PHYAddress, PHY_BCR, PHY_Reset)))
- {
- /* Return ERROR in case of write timeout */
- return ETH_ERROR;
- }
-
- /* Delay to assure PHY reset */
- _eth_delay_(PHY_RESET_DELAY);
-
- if(ETH_InitStruct->ETH_AutoNegotiation != ETH_AutoNegotiation_Disable)
- {
- /* We wait for linked status... */
- do
- {
- timeout++;
- } while (!(ETH_ReadPHYRegister(PHYAddress, PHY_BSR) & PHY_Linked_Status) && (timeout < PHY_READ_TO));
-
- /* Return ERROR in case of timeout */
- if(timeout == PHY_READ_TO)
- {
- return ETH_ERROR;
- }
-
- /* Reset Timeout counter */
- timeout = 0;
- /* Enable Auto-Negotiation */
- if(!(ETH_WritePHYRegister(PHYAddress, PHY_BCR, PHY_AutoNegotiation)))
- {
- /* Return ERROR in case of write timeout */
- return ETH_ERROR;
- }
-
- /* Wait until the auto-negotiation will be completed */
- do
- {
- timeout++;
- } while (!(ETH_ReadPHYRegister(PHYAddress, PHY_BSR) & PHY_AutoNego_Complete) && (timeout < (uint32_t)PHY_READ_TO));
-
- /* Return ERROR in case of timeout */
- if(timeout == PHY_READ_TO)
- {
- return ETH_ERROR;
- }
-
- /* Reset Timeout counter */
- timeout = 0;
-
- /* Read the result of the auto-negotiation */
- RegValue = ETH_ReadPHYRegister(PHYAddress, PHY_SR);
-
- /* Configure the MAC with the Duplex Mode fixed by the auto-negotiation process */
- if((RegValue & PHY_DUPLEX_STATUS) != (uint32_t)RESET)
- {
- /* Set Ethernet duplex mode to Full-duplex following the auto-negotiation */
- ETH_InitStruct->ETH_Mode = ETH_Mode_FullDuplex;
- }
- else
- {
- /* Set Ethernet duplex mode to Half-duplex following the auto-negotiation */
- ETH_InitStruct->ETH_Mode = ETH_Mode_HalfDuplex;
- }
-
- /* Configure the MAC with the speed fixed by the auto-negotiation process */
- if(RegValue & PHY_SPEED_STATUS)
- {
- /* Set Ethernet speed to 10M following the auto-negotiation */
- ETH_InitStruct->ETH_Speed = ETH_Speed_10M;
- }
- else
- {
- /* Set Ethernet speed to 100M following the auto-negotiation */
- ETH_InitStruct->ETH_Speed = ETH_Speed_100M;
- }
- }
- else
- {
- if(!ETH_WritePHYRegister(PHYAddress, PHY_BCR, ((uint16_t)(ETH_InitStruct->ETH_Mode >> 3) |
- (uint16_t)(ETH_InitStruct->ETH_Speed >> 1))))
- {
- /* Return ERROR in case of write timeout */
- return ETH_ERROR;
- }
- /* Delay to assure PHY configuration */
- _eth_delay_(PHY_CONFIG_DELAY);
-
- }
- /*------------------------ ETHERNET MACCR Configuration --------------------*/
- /* Get the ETHERNET MACCR value */
- tmpreg = ETH->MACCR;
- /* Clear WD, PCE, PS, TE and RE bits */
- tmpreg &= MACCR_CLEAR_MASK;
- /* Set the WD bit according to ETH_Watchdog value */
- /* Set the JD: bit according to ETH_Jabber value */
- /* Set the IFG bit according to ETH_InterFrameGap value */
- /* Set the DCRS bit according to ETH_CarrierSense value */
- /* Set the FES bit according to ETH_Speed value */
- /* Set the DO bit according to ETH_ReceiveOwn value */
- /* Set the LM bit according to ETH_LoopbackMode value */
- /* Set the DM bit according to ETH_Mode value */
- /* Set the IPCO bit according to ETH_ChecksumOffload value */
- /* Set the DR bit according to ETH_RetryTransmission value */
- /* Set the ACS bit according to ETH_AutomaticPadCRCStrip value */
- /* Set the BL bit according to ETH_BackOffLimit value */
- /* Set the DC bit according to ETH_DeferralCheck value */
- tmpreg |= (uint32_t)(ETH_InitStruct->ETH_Watchdog |
- ETH_InitStruct->ETH_Jabber |
- ETH_InitStruct->ETH_InterFrameGap |
- ETH_InitStruct->ETH_CarrierSense |
- ETH_InitStruct->ETH_Speed |
- ETH_InitStruct->ETH_ReceiveOwn |
- ETH_InitStruct->ETH_LoopbackMode |
- ETH_InitStruct->ETH_Mode |
- ETH_InitStruct->ETH_ChecksumOffload |
- ETH_InitStruct->ETH_RetryTransmission |
- ETH_InitStruct->ETH_AutomaticPadCRCStrip |
- ETH_InitStruct->ETH_BackOffLimit |
- ETH_InitStruct->ETH_DeferralCheck);
- /* Write to ETHERNET MACCR */
- ETH->MACCR = (uint32_t)tmpreg;
-
- /*----------------------- ETHERNET MACFFR Configuration --------------------*/
- /* Set the RA bit according to ETH_ReceiveAll value */
- /* Set the SAF and SAIF bits according to ETH_SourceAddrFilter value */
- /* Set the PCF bit according to ETH_PassControlFrames value */
- /* Set the DBF bit according to ETH_BroadcastFramesReception value */
- /* Set the DAIF bit according to ETH_DestinationAddrFilter value */
- /* Set the PR bit according to ETH_PromiscuousMode value */
- /* Set the PM, HMC and HPF bits according to ETH_MulticastFramesFilter value */
- /* Set the HUC and HPF bits according to ETH_UnicastFramesFilter value */
- /* Write to ETHERNET MACFFR */
- ETH->MACFFR = (uint32_t)(ETH_InitStruct->ETH_ReceiveAll |
- ETH_InitStruct->ETH_SourceAddrFilter |
- ETH_InitStruct->ETH_PassControlFrames |
- ETH_InitStruct->ETH_BroadcastFramesReception |
- ETH_InitStruct->ETH_DestinationAddrFilter |
- ETH_InitStruct->ETH_PromiscuousMode |
- ETH_InitStruct->ETH_MulticastFramesFilter |
- ETH_InitStruct->ETH_UnicastFramesFilter);
- /*--------------- ETHERNET MACHTHR and MACHTLR Configuration ---------------*/
- /* Write to ETHERNET MACHTHR */
- ETH->MACHTHR = (uint32_t)ETH_InitStruct->ETH_HashTableHigh;
- /* Write to ETHERNET MACHTLR */
- ETH->MACHTLR = (uint32_t)ETH_InitStruct->ETH_HashTableLow;
- /*----------------------- ETHERNET MACFCR Configuration --------------------*/
- /* Get the ETHERNET MACFCR value */
- tmpreg = ETH->MACFCR;
- /* Clear xx bits */
- tmpreg &= MACFCR_CLEAR_MASK;
-
- /* Set the PT bit according to ETH_PauseTime value */
- /* Set the DZPQ bit according to ETH_ZeroQuantaPause value */
- /* Set the PLT bit according to ETH_PauseLowThreshold value */
- /* Set the UP bit according to ETH_UnicastPauseFrameDetect value */
- /* Set the RFE bit according to ETH_ReceiveFlowControl value */
- /* Set the TFE bit according to ETH_TransmitFlowControl value */
- tmpreg |= (uint32_t)((ETH_InitStruct->ETH_PauseTime << 16) |
- ETH_InitStruct->ETH_ZeroQuantaPause |
- ETH_InitStruct->ETH_PauseLowThreshold |
- ETH_InitStruct->ETH_UnicastPauseFrameDetect |
- ETH_InitStruct->ETH_ReceiveFlowControl |
- ETH_InitStruct->ETH_TransmitFlowControl);
- /* Write to ETHERNET MACFCR */
- ETH->MACFCR = (uint32_t)tmpreg;
- /*----------------------- ETHERNET MACVLANTR Configuration -----------------*/
- /* Set the ETV bit according to ETH_VLANTagComparison value */
- /* Set the VL bit according to ETH_VLANTagIdentifier value */
- ETH->MACVLANTR = (uint32_t)(ETH_InitStruct->ETH_VLANTagComparison |
- ETH_InitStruct->ETH_VLANTagIdentifier);
-
- /*-------------------------------- DMA Config ------------------------------*/
- /*----------------------- ETHERNET DMAOMR Configuration --------------------*/
- /* Get the ETHERNET DMAOMR value */
- tmpreg = ETH->DMAOMR;
- /* Clear xx bits */
- tmpreg &= DMAOMR_CLEAR_MASK;
-
- /* Set the DT bit according to ETH_DropTCPIPChecksumErrorFrame value */
- /* Set the RSF bit according to ETH_ReceiveStoreForward value */
- /* Set the DFF bit according to ETH_FlushReceivedFrame value */
- /* Set the TSF bit according to ETH_TransmitStoreForward value */
- /* Set the TTC bit according to ETH_TransmitThresholdControl value */
- /* Set the FEF bit according to ETH_ForwardErrorFrames value */
- /* Set the FUF bit according to ETH_ForwardUndersizedGoodFrames value */
- /* Set the RTC bit according to ETH_ReceiveThresholdControl value */
- /* Set the OSF bit according to ETH_SecondFrameOperate value */
- tmpreg |= (uint32_t)(ETH_InitStruct->ETH_DropTCPIPChecksumErrorFrame |
- ETH_InitStruct->ETH_ReceiveStoreForward |
- ETH_InitStruct->ETH_FlushReceivedFrame |
- ETH_InitStruct->ETH_TransmitStoreForward |
- ETH_InitStruct->ETH_TransmitThresholdControl |
- ETH_InitStruct->ETH_ForwardErrorFrames |
- ETH_InitStruct->ETH_ForwardUndersizedGoodFrames |
- ETH_InitStruct->ETH_ReceiveThresholdControl |
- ETH_InitStruct->ETH_SecondFrameOperate);
- /* Write to ETHERNET DMAOMR */
- ETH->DMAOMR = (uint32_t)tmpreg;
-
- /*----------------------- ETHERNET DMABMR Configuration --------------------*/
- /* Set the AAL bit according to ETH_AddressAlignedBeats value */
- /* Set the FB bit according to ETH_FixedBurst value */
- /* Set the RPBL and 4*PBL bits according to ETH_RxDMABurstLength value */
- /* Set the PBL and 4*PBL bits according to ETH_TxDMABurstLength value */
- /* Set the DSL bit according to ETH_DesciptorSkipLength value */
- /* Set the PR and DA bits according to ETH_DMAArbitration value */
- ETH->DMABMR = (uint32_t)(ETH_InitStruct->ETH_AddressAlignedBeats |
- ETH_InitStruct->ETH_FixedBurst |
- ETH_InitStruct->ETH_RxDMABurstLength | /* !! if 4xPBL is selected for Tx or Rx it is applied for the other */
- ETH_InitStruct->ETH_TxDMABurstLength |
- (ETH_InitStruct->ETH_DescriptorSkipLength << 2) |
- ETH_InitStruct->ETH_DMAArbitration |
- ETH_DMABMR_USP); /* Enable use of separate PBL for Rx and Tx */
-
- #ifdef USE_ENHANCED_DMA_DESCRIPTORS
- /* Enable the Enhanced DMA descriptors */
- ETH->DMABMR |= ETH_DMABMR_EDE;
- #endif /* USE_ENHANCED_DMA_DESCRIPTORS */
-
- /* Return Ethernet configuration success */
- return ETH_SUCCESS;
-}
-
-/**
- * @brief Enables ENET MAC and DMA reception/transmission
- * @param None
- * @retval None
- */
-void ETH_Start(void)
-{
- /*tang****************************************/
-
- NVIC_InitTypeDef NVIC_initstruct;
- /*tang****************************************/
- /* Enable transmit state machine of the MAC for transmission on the MII */
- ETH_MACTransmissionCmd(ENABLE);
- /* Flush Transmit FIFO */
- ETH_FlushTransmitFIFO();
- /* Enable receive state machine of the MAC for reception from the MII */
- ETH_MACReceptionCmd(ENABLE);
-
-
-
-
- /*tang****************************************/
- ETH_DMAITConfig(ETH_DMA_IT_NIS | ETH_DMA_IT_R,ENABLE);
- NVIC_initstruct.NVIC_IRQChannel = ETH_IRQn;
- NVIC_initstruct.NVIC_IRQChannelPreemptionPriority =0;
- NVIC_initstruct.NVIC_IRQChannelSubPriority = 0;
- NVIC_initstruct.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_initstruct);
-
- /*tang****************************************/
-
- /* Start DMA transmission */
- ETH_DMATransmissionCmd(ENABLE);
- /* Start DMA reception */
- ETH_DMAReceptionCmd(ENABLE);
-}
-
-
-/**
- * @brief Enables or disables the MAC transmission.
- * @param NewState: new state of the MAC transmission.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void ETH_MACTransmissionCmd(FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- if (NewState != DISABLE)
- {
- /* Enable the MAC transmission */
- ETH->MACCR |= ETH_MACCR_TE;
- }
- else
- {
- /* Disable the MAC transmission */
- ETH->MACCR &= ~ETH_MACCR_TE;
- }
-}
-
-
-/**
- * @brief Enables or disables the MAC reception.
- * @param NewState: new state of the MAC reception.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void ETH_MACReceptionCmd(FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- if (NewState != DISABLE)
- {
- /* Enable the MAC reception */
- ETH->MACCR |= ETH_MACCR_RE;
- }
- else
- {
- /* Disable the MAC reception */
- ETH->MACCR &= ~ETH_MACCR_RE;
- }
-}
-
-
-/**
- * @brief Checks whether the ETHERNET flow control busy bit is set or not.
- * @param None
- * @retval The new state of flow control busy status bit (SET or RESET).
- */
-FlagStatus ETH_GetFlowControlBusyStatus(void)
-{
- FlagStatus bitstatus = RESET;
- /* The Flow Control register should not be written to until this bit is cleared */
- if ((ETH->MACFCR & ETH_MACFCR_FCBBPA) != (uint32_t)RESET)
- {
- bitstatus = SET;
- }
- else
- {
- bitstatus = RESET;
- }
- return bitstatus;
-}
-
-
-/**
- * @brief Initiate a Pause Control Frame (Full-duplex only).
- * @param None
- * @retval None
- */
-void ETH_InitiatePauseControlFrame(void)
-{
- /* When Set In full duplex MAC initiates pause control frame */
- ETH->MACFCR |= ETH_MACFCR_FCBBPA;
-}
-
-
-/**
- * @brief Enables or disables the MAC BackPressure operation activation (Half-duplex only).
- * @param NewState: new state of the MAC BackPressure operation activation.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void ETH_BackPressureActivationCmd(FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- if (NewState != DISABLE)
- {
- /* Activate the MAC BackPressure operation */
- /* In Half duplex: during backpressure, when the MAC receives a new frame,
- the transmitter starts sending a JAM pattern resulting in a collision */
- ETH->MACFCR |= ETH_MACFCR_FCBBPA;
- }
- else
- {
- /* Desactivate the MAC BackPressure operation */
- ETH->MACFCR &= ~ETH_MACFCR_FCBBPA;
- }
-}
-
-
-/**
- * @brief Checks whether the specified ETHERNET MAC flag is set or not.
- * @param ETH_MAC_FLAG: specifies the flag to check.
- * This parameter can be one of the following values:
- * @arg ETH_MAC_FLAG_TST : Time stamp trigger flag
- * @arg ETH_MAC_FLAG_MMCT : MMC transmit flag
- * @arg ETH_MAC_FLAG_MMCR : MMC receive flag
- * @arg ETH_MAC_FLAG_MMC : MMC flag
- * @arg ETH_MAC_FLAG_PMT : PMT flag
- * @retval The new state of ETHERNET MAC flag (SET or RESET).
- */
-FlagStatus ETH_GetMACFlagStatus(uint32_t ETH_MAC_FLAG)
-{
- FlagStatus bitstatus = RESET;
- /* Check the parameters */
- assert_param(IS_ETH_MAC_GET_FLAG(ETH_MAC_FLAG));
- if ((ETH->MACSR & ETH_MAC_FLAG) != (uint32_t)RESET)
- {
- bitstatus = SET;
- }
- else
- {
- bitstatus = RESET;
- }
- return bitstatus;
-}
-
-
-/**
- * @brief Checks whether the specified ETHERNET MAC interrupt has occurred or not.
- * @param ETH_MAC_IT: specifies the interrupt source to check.
- * This parameter can be one of the following values:
- * @arg ETH_MAC_IT_TST : Time stamp trigger interrupt
- * @arg ETH_MAC_IT_MMCT : MMC transmit interrupt
- * @arg ETH_MAC_IT_MMCR : MMC receive interrupt
- * @arg ETH_MAC_IT_MMC : MMC interrupt
- * @arg ETH_MAC_IT_PMT : PMT interrupt
- * @retval The new state of ETHERNET MAC interrupt (SET or RESET).
- */
-ITStatus ETH_GetMACITStatus(uint32_t ETH_MAC_IT)
-{
- ITStatus bitstatus = RESET;
- /* Check the parameters */
- assert_param(IS_ETH_MAC_GET_IT(ETH_MAC_IT));
- if ((ETH->MACSR & ETH_MAC_IT) != (uint32_t)RESET)
- {
- bitstatus = SET;
- }
- else
- {
- bitstatus = RESET;
- }
- return bitstatus;
-}
-
-
-/**
- * @brief Enables or disables the specified ETHERNET MAC interrupts.
- * @param ETH_MAC_IT: specifies the ETHERNET MAC interrupt sources to be
- * enabled or disabled.
- * This parameter can be any combination of the following values:
- * @arg ETH_MAC_IT_TST : Time stamp trigger interrupt
- * @arg ETH_MAC_IT_PMT : PMT interrupt
- * @param NewState: new state of the specified ETHERNET MAC interrupts.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void ETH_MACITConfig(uint32_t ETH_MAC_IT, FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_ETH_MAC_IT(ETH_MAC_IT));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- if (NewState != DISABLE)
- {
- /* Enable the selected ETHERNET MAC interrupts */
- ETH->MACIMR &= (~(uint32_t)ETH_MAC_IT);
- }
- else
- {
- /* Disable the selected ETHERNET MAC interrupts */
- ETH->MACIMR |= ETH_MAC_IT;
- }
-}
-
-
-/**
- * @brief Configures the selected MAC address.
- * @param MacAddr: The MAC address to configure.
- * This parameter can be one of the following values:
- * @arg ETH_MAC_Address0 : MAC Address0
- * @arg ETH_MAC_Address1 : MAC Address1
- * @arg ETH_MAC_Address2 : MAC Address2
- * @arg ETH_MAC_Address3 : MAC Address3
- * @param Addr: Pointer on MAC address buffer data (6 bytes).
- * @retval None
- */
-void ETH_MACAddressConfig(uint32_t MacAddr, uint8_t *Addr)
-{
- uint32_t tmpreg;
- /* Check the parameters */
- assert_param(IS_ETH_MAC_ADDRESS0123(MacAddr));
-
- /* Calculate the selected MAC address high register */
- tmpreg = ((uint32_t)Addr[5] << 8) | (uint32_t)Addr[4];
- /* Load the selected MAC address high register */
- (*(__IO uint32_t *) (ETH_MAC_ADDR_HBASE + MacAddr)) = tmpreg;
- /* Calculate the selected MAC address low register */
- tmpreg = ((uint32_t)Addr[3] << 24) | ((uint32_t)Addr[2] << 16) | ((uint32_t)Addr[1] << 8) | Addr[0];
-
- /* Load the selected MAC address low register */
- (*(__IO uint32_t *) (ETH_MAC_ADDR_LBASE + MacAddr)) = tmpreg;
-}
-
-
-/**
- * @brief Get the selected MAC address.
- * @param MacAddr: The MAC address to return.
- * This parameter can be one of the following values:
- * @arg ETH_MAC_Address0 : MAC Address0
- * @arg ETH_MAC_Address1 : MAC Address1
- * @arg ETH_MAC_Address2 : MAC Address2
- * @arg ETH_MAC_Address3 : MAC Address3
- * @param Addr: Pointer on MAC address buffer data (6 bytes).
- * @retval None
- */
-void ETH_GetMACAddress(uint32_t MacAddr, uint8_t *Addr)
-{
- uint32_t tmpreg;
- /* Check the parameters */
- assert_param(IS_ETH_MAC_ADDRESS0123(MacAddr));
-
- /* Get the selected MAC address high register */
- tmpreg =(*(__IO uint32_t *) (ETH_MAC_ADDR_HBASE + MacAddr));
-
- /* Calculate the selected MAC address buffer */
- Addr[5] = ((tmpreg >> 8) & (uint8_t)0xFF);
- Addr[4] = (tmpreg & (uint8_t)0xFF);
- /* Load the selected MAC address low register */
- tmpreg =(*(__IO uint32_t *) (ETH_MAC_ADDR_LBASE + MacAddr));
- /* Calculate the selected MAC address buffer */
- Addr[3] = ((tmpreg >> 24) & (uint8_t)0xFF);
- Addr[2] = ((tmpreg >> 16) & (uint8_t)0xFF);
- Addr[1] = ((tmpreg >> 8 ) & (uint8_t)0xFF);
- Addr[0] = (tmpreg & (uint8_t)0xFF);
-}
-
-
-/**
- * @brief Enables or disables the Address filter module uses the specified
- * ETHERNET MAC address for perfect filtering
- * @param MacAddr: specifies the ETHERNET MAC address to be used for perfect filtering.
- * This parameter can be one of the following values:
- * @arg ETH_MAC_Address1 : MAC Address1
- * @arg ETH_MAC_Address2 : MAC Address2
- * @arg ETH_MAC_Address3 : MAC Address3
- * @param NewState: new state of the specified ETHERNET MAC address use.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void ETH_MACAddressPerfectFilterCmd(uint32_t MacAddr, FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_ETH_MAC_ADDRESS123(MacAddr));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- if (NewState != DISABLE)
- {
- /* Enable the selected ETHERNET MAC address for perfect filtering */
- (*(__IO uint32_t *) (ETH_MAC_ADDR_HBASE + MacAddr)) |= ETH_MACA1HR_AE;
- }
- else
- {
- /* Disable the selected ETHERNET MAC address for perfect filtering */
- (*(__IO uint32_t *) (ETH_MAC_ADDR_HBASE + MacAddr)) &=(~(uint32_t)ETH_MACA1HR_AE);
- }
-}
-
-
-/**
- * @brief Set the filter type for the specified ETHERNET MAC address
- * @param MacAddr: specifies the ETHERNET MAC address
- * This parameter can be one of the following values:
- * @arg ETH_MAC_Address1 : MAC Address1
- * @arg ETH_MAC_Address2 : MAC Address2
- * @arg ETH_MAC_Address3 : MAC Address3
- * @param Filter: specifies the used frame received field for comparison
- * This parameter can be one of the following values:
- * @arg ETH_MAC_AddressFilter_SA : MAC Address is used to compare with the
- * SA fields of the received frame.
- * @arg ETH_MAC_AddressFilter_DA : MAC Address is used to compare with the
- * DA fields of the received frame.
- * @retval None
- */
-void ETH_MACAddressFilterConfig(uint32_t MacAddr, uint32_t Filter)
-{
- /* Check the parameters */
- assert_param(IS_ETH_MAC_ADDRESS123(MacAddr));
- assert_param(IS_ETH_MAC_ADDRESS_FILTER(Filter));
-
- if (Filter != ETH_MAC_AddressFilter_DA)
- {
- /* The selected ETHERNET MAC address is used to compare with the SA fields of the
- received frame. */
- (*(__IO uint32_t *) (ETH_MAC_ADDR_HBASE + MacAddr)) |= ETH_MACA1HR_SA;
- }
- else
- {
- /* The selected ETHERNET MAC address is used to compare with the DA fields of the
- received frame. */
- (*(__IO uint32_t *) (ETH_MAC_ADDR_HBASE + MacAddr)) &=(~(uint32_t)ETH_MACA1HR_SA);
- }
-}
-
-
-/**
- * @brief Set the filter type for the specified ETHERNET MAC address
- * @param MacAddr: specifies the ETHERNET MAC address
- * This parameter can be one of the following values:
- * @arg ETH_MAC_Address1 : MAC Address1
- * @arg ETH_MAC_Address2 : MAC Address2
- * @arg ETH_MAC_Address3 : MAC Address3
- * @param MaskByte: specifies the used address bytes for comparison
- * This parameter can be any combination of the following values:
- * @arg ETH_MAC_AddressMask_Byte6 : Mask MAC Address high reg bits [15:8].
- * @arg ETH_MAC_AddressMask_Byte5 : Mask MAC Address high reg bits [7:0].
- * @arg ETH_MAC_AddressMask_Byte4 : Mask MAC Address low reg bits [31:24].
- * @arg ETH_MAC_AddressMask_Byte3 : Mask MAC Address low reg bits [23:16].
- * @arg ETH_MAC_AddressMask_Byte2 : Mask MAC Address low reg bits [15:8].
- * @arg ETH_MAC_AddressMask_Byte1 : Mask MAC Address low reg bits [7:0].
- * @retval None
- */
-void ETH_MACAddressMaskBytesFilterConfig(uint32_t MacAddr, uint32_t MaskByte)
-{
- /* Check the parameters */
- assert_param(IS_ETH_MAC_ADDRESS123(MacAddr));
- assert_param(IS_ETH_MAC_ADDRESS_MASK(MaskByte));
-
- /* Clear MBC bits in the selected MAC address high register */
- (*(__IO uint32_t *) (ETH_MAC_ADDR_HBASE + MacAddr)) &=(~(uint32_t)ETH_MACA1HR_MBC);
- /* Set the selected Filter mask bytes */
- (*(__IO uint32_t *) (ETH_MAC_ADDR_HBASE + MacAddr)) |= MaskByte;
-}
-
-
-/******************************************************************************/
-/* DMA Descriptors functions */
-/******************************************************************************/
-
-/**
- * @brief This function should be called to get the received frame (to be used
- * with polling method only).
- * @param none
- * @retval Structure of type FrameTypeDef
- */
-FrameTypeDef ETH_Get_Received_Frame(void)
-{
- uint32_t framelength = 0;
- FrameTypeDef frame = {0,0,0};
-
- /* Get the Frame Length of the received packet: substruct 4 bytes of the CRC */
- framelength = ((DMARxDescToGet->Status & ETH_DMARxDesc_FL) >> ETH_DMARxDesc_FrameLengthShift) - 4;
- frame.length = framelength;
-
- /* Get the address of the buffer start address */
- /* Check if more than one segment in the frame */
- if (DMA_RX_FRAME_infos->Seg_Count >1)
- {
- frame.buffer =(DMA_RX_FRAME_infos->FS_Rx_Desc)->Buffer1Addr;
- }
- else
- {
- frame.buffer = DMARxDescToGet->Buffer1Addr;
- }
-
- frame.descriptor = DMARxDescToGet;
-
- /* Update the ETHERNET DMA global Rx descriptor with next Rx descriptor */
- /* Chained Mode */
- /* Selects the next DMA Rx descriptor list for next buffer to read */
- DMARxDescToGet = (ETH_DMADESCTypeDef*) (DMARxDescToGet->Buffer2NextDescAddr);
-
- /* Return Frame */
- return (frame);
-}
-
-
-/**
- * @brief This function should be called when a frame is received using DMA
- * Receive interrupt, it allows scanning of Rx descriptors to get the
- * the receive frame (should be used with interrupt mode only)
- * @param None
- * @retval Structure of type FrameTypeDef
- */
-FrameTypeDef ETH_Get_Received_Frame_interrupt(void)
-{
- FrameTypeDef frame={0,0,0};
- __IO uint32_t descriptor_scan_counter = 0;
-
- /* scan descriptors owned by CPU */
- while (((DMARxDescToGet->Status & ETH_DMARxDesc_OWN) == (uint32_t)RESET)&&
- (descriptor_scan_counterStatus & ETH_DMARxDesc_FS) != (uint32_t)RESET)&&
- ((DMARxDescToGet->Status & ETH_DMARxDesc_LS) == (uint32_t)RESET))
- {
- DMA_RX_FRAME_infos->FS_Rx_Desc = DMARxDescToGet;
- DMA_RX_FRAME_infos->Seg_Count = 1;
- DMARxDescToGet = (ETH_DMADESCTypeDef*) (DMARxDescToGet->Buffer2NextDescAddr);
- }
-
- /* check if intermediate segment */
- else if (((DMARxDescToGet->Status & ETH_DMARxDesc_LS) == (uint32_t)RESET)&&
- ((DMARxDescToGet->Status & ETH_DMARxDesc_FS) == (uint32_t)RESET))
- {
- (DMA_RX_FRAME_infos->Seg_Count) ++;
- DMARxDescToGet = (ETH_DMADESCTypeDef*) (DMARxDescToGet->Buffer2NextDescAddr);
- }
-
- /* should be last segment */
- else
- {
- /* last segment */
- DMA_RX_FRAME_infos->LS_Rx_Desc = DMARxDescToGet;
-
- (DMA_RX_FRAME_infos->Seg_Count)++;
-
- /* first segment is last segment */
- if ((DMA_RX_FRAME_infos->Seg_Count)==1)
- DMA_RX_FRAME_infos->FS_Rx_Desc = DMARxDescToGet;
-
- /* Get the Frame Length of the received packet: substruct 4 bytes of the CRC */
- frame.length = ((DMARxDescToGet->Status & ETH_DMARxDesc_FL) >> ETH_DMARxDesc_FrameLengthShift) - 4;
-
-
- /* Get the address of the buffer start address */
- /* Check if more than one segment in the frame */
- if (DMA_RX_FRAME_infos->Seg_Count >1)
- {
- frame.buffer =(DMA_RX_FRAME_infos->FS_Rx_Desc)->Buffer1Addr;
- }
- else
- {
- frame.buffer = DMARxDescToGet->Buffer1Addr;
- }
-
- frame.descriptor = DMARxDescToGet;
-
- /* Update the ETHERNET DMA global Rx descriptor with next Rx descriptor */
- DMARxDescToGet = (ETH_DMADESCTypeDef*) (DMARxDescToGet->Buffer2NextDescAddr);
-
- /* Return Frame */
- return (frame);
- }
- }
- return (frame);
-}
-
-
-/**
- * @brief Prepares DMA Tx descriptors to transmit an ethernet frame
- * @param FrameLength : length of the frame to send
- * @retval error status
- */
-uint32_t ETH_Prepare_Transmit_Descriptors(u16 FrameLength)
-{
- uint32_t buf_count =0, size=0,i=0;
- __IO ETH_DMADESCTypeDef *DMATxNextDesc;
-
- /* Check if the descriptor is owned by the ETHERNET DMA (when set) or CPU (when reset) */
- if((DMATxDescToSet->Status & ETH_DMATxDesc_OWN) != (u32)RESET)
- {
- /* Return ERROR: OWN bit set */
- return ETH_ERROR;
- }
-
- DMATxNextDesc = DMATxDescToSet;
-
- if (FrameLength > ETH_TX_BUF_SIZE)
- {
- buf_count = FrameLength/ETH_TX_BUF_SIZE;
- if (FrameLength%ETH_TX_BUF_SIZE) buf_count++;
- }
- else buf_count =1;
-
- if (buf_count ==1)
- {
- /*set LAST and FIRST segment */
- DMATxDescToSet->Status |=ETH_DMATxDesc_FS|ETH_DMATxDesc_LS;
- /* Set frame size */
- DMATxDescToSet->ControlBufferSize = (FrameLength& ETH_DMATxDesc_TBS1);
- /* Set Own bit of the Tx descriptor Status: gives the buffer back to ETHERNET DMA */
- DMATxDescToSet->Status |= ETH_DMATxDesc_OWN;
- DMATxDescToSet= (ETH_DMADESCTypeDef *)(DMATxDescToSet->Buffer2NextDescAddr);
- }
- else
- {
- for (i=0; i< buf_count; i++)
- {
- if (i==0)
- {
- /* Setting the first segment bit */
- DMATxDescToSet->Status |= ETH_DMATxDesc_FS;
- }
-
- /* Program size */
- DMATxNextDesc->ControlBufferSize = (ETH_TX_BUF_SIZE & ETH_DMATxDesc_TBS1);
-
- if (i== (buf_count-1))
- {
- /* Setting the last segment bit */
- DMATxNextDesc->Status |= ETH_DMATxDesc_LS;
- size = FrameLength - (buf_count-1)*ETH_TX_BUF_SIZE;
- DMATxNextDesc->ControlBufferSize = (size & ETH_DMATxDesc_TBS1);
- }
-
- /*give back descriptor to DMA */
- DMATxNextDesc->Status |= ETH_DMATxDesc_OWN;
-
- DMATxNextDesc = (ETH_DMADESCTypeDef *)(DMATxNextDesc->Buffer2NextDescAddr);
- /* Set Own bit of the Tx descriptor Status: gives the buffer back to ETHERNET DMA */
- }
- DMATxDescToSet = DMATxNextDesc ;
- }
-
- /* When Tx Buffer unavailable flag is set: clear it and resume transmission */
- if ((ETH->DMASR & ETH_DMASR_TBUS) != (u32)RESET)
- {
- /* Clear TBUS ETHERNET DMA flag */
- ETH->DMASR = ETH_DMASR_TBUS;
- /* Resume DMA transmission*/
- ETH->DMATPDR = 0;
- }
-
- /* Return SUCCESS */
- return ETH_SUCCESS;
-}
-
-
-/**
- * @brief Initializes the DMA Rx descriptors in chain mode.
- * @param DMARxDescTab: Pointer on the first Rx desc list
- * @param RxBuff: Pointer on the first RxBuffer list
- * @param RxBuffCount: Number of the used Rx desc in the list
- * @retval None
- */
-void ETH_DMARxDescChainInit(ETH_DMADESCTypeDef *DMARxDescTab, uint8_t *RxBuff, uint32_t RxBuffCount)
-{
- uint32_t i = 0;
- ETH_DMADESCTypeDef *DMARxDesc;
-
- /* Set the DMARxDescToGet pointer with the first one of the DMARxDescTab list */
- DMARxDescToGet = DMARxDescTab;
- /* Fill each DMARxDesc descriptor with the right values */
- for(i=0; i < RxBuffCount; i++)
- {
- /* Get the pointer on the ith member of the Rx Desc list */
- DMARxDesc = DMARxDescTab+i;
- /* Set Own bit of the Rx descriptor Status */
- DMARxDesc->Status = ETH_DMARxDesc_OWN;
-
- /* Set Buffer1 size and Second Address Chained bit */
- DMARxDesc->ControlBufferSize = ETH_DMARxDesc_RCH | (uint32_t)ETH_RX_BUF_SIZE;
- /* Set Buffer1 address pointer */
- DMARxDesc->Buffer1Addr = (uint32_t)(&RxBuff[i*ETH_RX_BUF_SIZE]);
-
- /* Initialize the next descriptor with the Next Descriptor Polling Enable */
- if(i < (RxBuffCount-1))
- {
- /* Set next descriptor address register with next descriptor base address */
- DMARxDesc->Buffer2NextDescAddr = (uint32_t)(DMARxDescTab+i+1);
- }
- else
- {
- /* For last descriptor, set next descriptor address register equal to the first descriptor base address */
- DMARxDesc->Buffer2NextDescAddr = (uint32_t)(DMARxDescTab);
- }
- }
-
- /* Set Receive Descriptor List Address Register */
- ETH->DMARDLAR = (uint32_t) DMARxDescTab;
-
-
- DMA_RX_FRAME_infos = &RX_Frame_Descriptor;
-
-}
-
-/**
- * @brief This function polls for a frame reception
- * @param None
- * @retval Returns 1 when a frame is received, 0 if none.
- */
-uint32_t ETH_CheckFrameReceived(void)
-{
- /* check if last segment */
- if(((DMARxDescToGet->Status & ETH_DMARxDesc_OWN) == (uint32_t)RESET) &&
- ((DMARxDescToGet->Status & ETH_DMARxDesc_LS) != (uint32_t)RESET))
- {
- DMA_RX_FRAME_infos->LS_Rx_Desc = DMARxDescToGet;
- DMA_RX_FRAME_infos->Seg_Count++;
- return 1;
- }
-
- /* check if first segment */
- else if(((DMARxDescToGet->Status & ETH_DMARxDesc_OWN) == (uint32_t)RESET) &&
- ((DMARxDescToGet->Status & ETH_DMARxDesc_FS) != (uint32_t)RESET)&&
- ((DMARxDescToGet->Status & ETH_DMARxDesc_LS) == (uint32_t)RESET))
- {
- DMA_RX_FRAME_infos->FS_Rx_Desc = DMARxDescToGet;
- DMA_RX_FRAME_infos->LS_Rx_Desc = NULL;
- DMA_RX_FRAME_infos->Seg_Count = 1;
- DMARxDescToGet = (ETH_DMADESCTypeDef*) (DMARxDescToGet->Buffer2NextDescAddr);
- }
-
- /* check if intermediate segment */
- else if(((DMARxDescToGet->Status & ETH_DMARxDesc_OWN) == (uint32_t)RESET) &&
- ((DMARxDescToGet->Status & ETH_DMARxDesc_FS) == (uint32_t)RESET)&&
- ((DMARxDescToGet->Status & ETH_DMARxDesc_LS) == (uint32_t)RESET))
- {
- (DMA_RX_FRAME_infos->Seg_Count) ++;
- DMARxDescToGet = (ETH_DMADESCTypeDef*) (DMARxDescToGet->Buffer2NextDescAddr);
- }
- return 0;
-}
-
-
-
-/**
- * @brief Initializes the DMA Tx descriptors in chain mode.
- * @param DMATxDescTab: Pointer on the first Tx desc list
- * @param TxBuff: Pointer on the first TxBuffer list
- * @param TxBuffCount: Number of the used Tx desc in the list
- * @retval None
- */
-void ETH_DMATxDescChainInit(ETH_DMADESCTypeDef *DMATxDescTab, uint8_t* TxBuff, uint32_t TxBuffCount)
-{
- uint32_t i = 0;
- ETH_DMADESCTypeDef *DMATxDesc;
-
- /* Set the DMATxDescToSet pointer with the first one of the DMATxDescTab list */
- DMATxDescToSet = DMATxDescTab;
- /* Fill each DMATxDesc descriptor with the right values */
- for(i=0; i < TxBuffCount; i++)
- {
- /* Get the pointer on the ith member of the Tx Desc list */
- DMATxDesc = DMATxDescTab + i;
- /* Set Second Address Chained bit */
- DMATxDesc->Status = ETH_DMATxDesc_TCH;
-
- /* Set Buffer1 address pointer */
- DMATxDesc->Buffer1Addr = (uint32_t)(&TxBuff[i*ETH_TX_BUF_SIZE]);
-
- /* Initialize the next descriptor with the Next Descriptor Polling Enable */
- if(i < (TxBuffCount-1))
- {
- /* Set next descriptor address register with next descriptor base address */
- DMATxDesc->Buffer2NextDescAddr = (uint32_t)(DMATxDescTab+i+1);
- }
- else
- {
- /* For last descriptor, set next descriptor address register equal to the first descriptor base address */
- DMATxDesc->Buffer2NextDescAddr = (uint32_t) DMATxDescTab;
- }
- }
-
- /* Set Transmit Desciptor List Address Register */
- ETH->DMATDLAR = (uint32_t) DMATxDescTab;
-}
-
-
-
-
-/**
- * @brief Checks whether the specified ETHERNET DMA Tx Desc flag is set or not.
- * @param DMATxDesc: pointer on a DMA Tx descriptor
- * @param ETH_DMATxDescFlag: specifies the flag to check.
- * This parameter can be one of the following values:
- * @arg ETH_DMATxDesc_OWN : OWN bit: descriptor is owned by DMA engine
- * @arg ETH_DMATxDesc_IC : Interrupt on completion
- * @arg ETH_DMATxDesc_LS : Last Segment
- * @arg ETH_DMATxDesc_FS : First Segment
- * @arg ETH_DMATxDesc_DC : Disable CRC
- * @arg ETH_DMATxDesc_DP : Disable Pad
- * @arg ETH_DMATxDesc_TTSE: Transmit Time Stamp Enable
- * @arg ETH_DMATxDesc_CIC : Checksum insertion control
- * @arg ETH_DMATxDesc_TER : Transmit End of Ring
- * @arg ETH_DMATxDesc_TCH : Second Address Chained
- * @arg ETH_DMATxDesc_TTSS: Tx Time Stamp Status
- * @arg ETH_DMATxDesc_IHE : IP Header Error
- * @arg ETH_DMATxDesc_ES : Error summary
- * @arg ETH_DMATxDesc_JT : Jabber Timeout
- * @arg ETH_DMATxDesc_FF : Frame Flushed: DMA/MTL flushed the frame due to SW flush
- * @arg ETH_DMATxDesc_PCE : Payload Checksum Error
- * @arg ETH_DMATxDesc_LCA : Loss of Carrier: carrier lost during transmission
- * @arg ETH_DMATxDesc_NC : No Carrier: no carrier signal from the transceiver
- * @arg ETH_DMATxDesc_LCO : Late Collision: transmission aborted due to collision
- * @arg ETH_DMATxDesc_EC : Excessive Collision: transmission aborted after 16 collisions
- * @arg ETH_DMATxDesc_VF : VLAN Frame
- * @arg ETH_DMATxDesc_CC : Collision Count
- * @arg ETH_DMATxDesc_ED : Excessive Deferral
- * @arg ETH_DMATxDesc_UF : Underflow Error: late data arrival from the memory
- * @arg ETH_DMATxDesc_DB : Deferred Bit
- * @retval The new state of ETH_DMATxDescFlag (SET or RESET).
- */
-FlagStatus ETH_GetDMATxDescFlagStatus(ETH_DMADESCTypeDef *DMATxDesc, uint32_t ETH_DMATxDescFlag)
-{
- FlagStatus bitstatus = RESET;
- /* Check the parameters */
- assert_param(IS_ETH_DMATxDESC_GET_FLAG(ETH_DMATxDescFlag));
-
- if ((DMATxDesc->Status & ETH_DMATxDescFlag) != (uint32_t)RESET)
- {
- bitstatus = SET;
- }
- else
- {
- bitstatus = RESET;
- }
- return bitstatus;
-}
-
-/**
- * @brief Returns the specified ETHERNET DMA Tx Desc collision count.
- * @param DMATxDesc: pointer on a DMA Tx descriptor
- * @retval The Transmit descriptor collision counter value.
- */
-uint32_t ETH_GetDMATxDescCollisionCount(ETH_DMADESCTypeDef *DMATxDesc)
-{
- /* Return the Receive descriptor frame length */
- return ((DMATxDesc->Status & ETH_DMATxDesc_CC) >> ETH_DMATXDESC_COLLISION_COUNTSHIFT);
-}
-
-/**
- * @brief Set the specified DMA Tx Desc Own bit.
- * @param DMATxDesc: Pointer on a Tx desc
- * @retval None
- */
-void ETH_SetDMATxDescOwnBit(ETH_DMADESCTypeDef *DMATxDesc)
-{
- /* Set the DMA Tx Desc Own bit */
- DMATxDesc->Status |= ETH_DMATxDesc_OWN;
-}
-
-/**
- * @brief Enables or disables the specified DMA Tx Desc Transmit interrupt.
- * @param DMATxDesc: Pointer on a Tx desc
- * @param NewState: new state of the DMA Tx Desc transmit interrupt.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void ETH_DMATxDescTransmitITConfig(ETH_DMADESCTypeDef *DMATxDesc, FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- if (NewState != DISABLE)
- {
- /* Enable the DMA Tx Desc Transmit interrupt */
- DMATxDesc->Status |= ETH_DMATxDesc_IC;
- }
- else
- {
- /* Disable the DMA Tx Desc Transmit interrupt */
- DMATxDesc->Status &=(~(uint32_t)ETH_DMATxDesc_IC);
- }
-}
-
-/**
- * @brief configure Tx descriptor as last or first segment
- * @param DMATxDesc: Pointer on a Tx desc
- * @param DMATxDesc_FrameSegment: specifies is the actual Tx desc contain last or first segment.
- * This parameter can be one of the following values:
- * @arg ETH_DMATxDesc_LastSegment : actual Tx desc contain last segment
- * @arg ETH_DMATxDesc_FirstSegment : actual Tx desc contain first segment
- * @retval None
- */
-void ETH_DMATxDescFrameSegmentConfig(ETH_DMADESCTypeDef *DMATxDesc, uint32_t DMATxDesc_FrameSegment)
-{
- /* Check the parameters */
- assert_param(IS_ETH_DMA_TXDESC_SEGMENT(DMATxDesc_FrameSegment));
-
- /* Selects the DMA Tx Desc Frame segment */
- DMATxDesc->Status |= DMATxDesc_FrameSegment;
-}
-
-/**
- * @brief Selects the specified ETHERNET DMA Tx Desc Checksum Insertion.
- * @param DMATxDesc: pointer on a DMA Tx descriptor
- * @param DMATxDesc_Checksum: specifies is the DMA Tx desc checksum insertion.
- * This parameter can be one of the following values:
- * @arg ETH_DMATxDesc_ChecksumByPass : Checksum bypass
- * @arg ETH_DMATxDesc_ChecksumIPV4Header : IPv4 header checksum
- * @arg ETH_DMATxDesc_ChecksumTCPUDPICMPSegment : TCP/UDP/ICMP checksum. Pseudo header checksum is assumed to be present
- * @arg ETH_DMATxDesc_ChecksumTCPUDPICMPFull : TCP/UDP/ICMP checksum fully in hardware including pseudo header
- * @retval None
- */
-void ETH_DMATxDescChecksumInsertionConfig(ETH_DMADESCTypeDef *DMATxDesc, uint32_t DMATxDesc_Checksum)
-{
- /* Check the parameters */
- assert_param(IS_ETH_DMA_TXDESC_CHECKSUM(DMATxDesc_Checksum));
-
- /* Set the selected DMA Tx desc checksum insertion control */
- DMATxDesc->Status |= DMATxDesc_Checksum;
-}
-
-/**
- * @brief Enables or disables the DMA Tx Desc CRC.
- * @param DMATxDesc: pointer on a DMA Tx descriptor
- * @param NewState: new state of the specified DMA Tx Desc CRC.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void ETH_DMATxDescCRCCmd(ETH_DMADESCTypeDef *DMATxDesc, FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- if (NewState != DISABLE)
- {
- /* Enable the selected DMA Tx Desc CRC */
- DMATxDesc->Status &= (~(uint32_t)ETH_DMATxDesc_DC);
- }
- else
- {
- /* Disable the selected DMA Tx Desc CRC */
- DMATxDesc->Status |= ETH_DMATxDesc_DC;
- }
-}
-
-
-/**
- * @brief Enables or disables the DMA Tx Desc second address chained.
- * @param DMATxDesc: pointer on a DMA Tx descriptor
- * @param NewState: new state of the specified DMA Tx Desc second address chained.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void ETH_DMATxDescSecondAddressChainedCmd(ETH_DMADESCTypeDef *DMATxDesc, FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- if (NewState != DISABLE)
- {
- /* Enable the selected DMA Tx Desc second address chained */
- DMATxDesc->Status |= ETH_DMATxDesc_TCH;
- }
- else
- {
- /* Disable the selected DMA Tx Desc second address chained */
- DMATxDesc->Status &=(~(uint32_t)ETH_DMATxDesc_TCH);
- }
-}
-
-/**
- * @brief Enables or disables the DMA Tx Desc padding for frame shorter than 64 bytes.
- * @param DMATxDesc: pointer on a DMA Tx descriptor
- * @param NewState: new state of the specified DMA Tx Desc padding for frame shorter than 64 bytes.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void ETH_DMATxDescShortFramePaddingCmd(ETH_DMADESCTypeDef *DMATxDesc, FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- if (NewState != DISABLE)
- {
- /* Enable the selected DMA Tx Desc padding for frame shorter than 64 bytes */
- DMATxDesc->Status &= (~(uint32_t)ETH_DMATxDesc_DP);
- }
- else
- {
- /* Disable the selected DMA Tx Desc padding for frame shorter than 64 bytes*/
- DMATxDesc->Status |= ETH_DMATxDesc_DP;
- }
-}
-
-
-/**
- * @brief Configures the specified DMA Tx Desc buffer1 and buffer2 sizes.
- * @param DMATxDesc: Pointer on a Tx desc
- * @param BufferSize1: specifies the Tx desc buffer1 size.
- * @param BufferSize2: specifies the Tx desc buffer2 size (put "0" if not used).
- * @retval None
- */
-void ETH_DMATxDescBufferSizeConfig(ETH_DMADESCTypeDef *DMATxDesc, uint32_t BufferSize1, uint32_t BufferSize2)
-{
- /* Check the parameters */
- assert_param(IS_ETH_DMATxDESC_BUFFER_SIZE(BufferSize1));
- assert_param(IS_ETH_DMATxDESC_BUFFER_SIZE(BufferSize2));
-
- /* Set the DMA Tx Desc buffer1 and buffer2 sizes values */
- DMATxDesc->ControlBufferSize |= (BufferSize1 | (BufferSize2 << ETH_DMATXDESC_BUFFER2_SIZESHIFT));
-}
-
-
-/**
- * @brief Checks whether the specified ETHERNET Rx Desc flag is set or not.
- * @param DMARxDesc: pointer on a DMA Rx descriptor
- * @param ETH_DMARxDescFlag: specifies the flag to check.
- * This parameter can be one of the following values:
- * @arg ETH_DMARxDesc_OWN: OWN bit: descriptor is owned by DMA engine
- * @arg ETH_DMARxDesc_AFM: DA Filter Fail for the rx frame
- * @arg ETH_DMARxDesc_ES: Error summary
- * @arg ETH_DMARxDesc_DE: Descriptor error: no more descriptors for receive frame
- * @arg ETH_DMARxDesc_SAF: SA Filter Fail for the received frame
- * @arg ETH_DMARxDesc_LE: Frame size not matching with length field
- * @arg ETH_DMARxDesc_OE: Overflow Error: Frame was damaged due to buffer overflow
- * @arg ETH_DMARxDesc_VLAN: VLAN Tag: received frame is a VLAN frame
- * @arg ETH_DMARxDesc_FS: First descriptor of the frame
- * @arg ETH_DMARxDesc_LS: Last descriptor of the frame
- * @arg ETH_DMARxDesc_IPV4HCE: IPC Checksum Error/Giant Frame: Rx Ipv4 header checksum error
- * @arg ETH_DMARxDesc_LC: Late collision occurred during reception
- * @arg ETH_DMARxDesc_FT: Frame type - Ethernet, otherwise 802.3
- * @arg ETH_DMARxDesc_RWT: Receive Watchdog Timeout: watchdog timer expired during reception
- * @arg ETH_DMARxDesc_RE: Receive error: error reported by MII interface
- * @arg ETH_DMARxDesc_DE: Dribble bit error: frame contains non int multiple of 8 bits
- * @arg ETH_DMARxDesc_CE: CRC error
- * @arg ETH_DMARxDesc_MAMPCE: Rx MAC Address/Payload Checksum Error: Rx MAC address matched/ Rx Payload Checksum Error
- * @retval The new state of ETH_DMARxDescFlag (SET or RESET).
- */
-FlagStatus ETH_GetDMARxDescFlagStatus(ETH_DMADESCTypeDef *DMARxDesc, uint32_t ETH_DMARxDescFlag)
-{
- FlagStatus bitstatus = RESET;
- /* Check the parameters */
- assert_param(IS_ETH_DMARxDESC_GET_FLAG(ETH_DMARxDescFlag));
- if ((DMARxDesc->Status & ETH_DMARxDescFlag) != (uint32_t)RESET)
- {
- bitstatus = SET;
- }
- else
- {
- bitstatus = RESET;
- }
- return bitstatus;
-}
-
-#ifdef USE_ENHANCED_DMA_DESCRIPTORS
-/**
- * @brief Checks whether the specified ETHERNET PTP Rx Desc extended flag is set or not.
- * @param DMAPTPRxDesc: pointer on a DMA PTP Rx descriptor
- * @param ETH_DMAPTPRxDescFlag: specifies the extended flag to check.
- * This parameter can be one of the following values:
- * @arg ETH_DMAPTPRxDesc_PTPV: PTP version
- * @arg ETH_DMAPTPRxDesc_PTPFT: PTP frame type
- * @arg ETH_DMAPTPRxDesc_PTPMT: PTP message type
- * @arg ETH_DMAPTPRxDesc_IPV6PR: IPv6 packet received
- * @arg ETH_DMAPTPRxDesc_IPV4PR: IPv4 packet received
- * @arg ETH_DMAPTPRxDesc_IPCB: IP checksum bypassed
- * @arg ETH_DMAPTPRxDesc_IPPE: IP payload error
- * @arg ETH_DMAPTPRxDesc_IPHE: IP header error
- * @arg ETH_DMAPTPRxDesc_IPPT: IP payload type
- * @retval The new state of ETH_DMAPTPRxDescExtendedFlag (SET or RESET).
- */
-FlagStatus ETH_GetDMAPTPRxDescExtendedFlagStatus(ETH_DMADESCTypeDef *DMAPTPRxDesc, uint32_t ETH_DMAPTPRxDescExtendedFlag)
-{
- FlagStatus bitstatus = RESET;
-
- /* Check the parameters */
- assert_param(IS_ETH_DMAPTPRxDESC_GET_EXTENDED_FLAG(ETH_DMAPTPRxDescExtendedFlag));
-
- if ((DMAPTPRxDesc->ExtendedStatus & ETH_DMAPTPRxDescExtendedFlag) != (uint32_t)RESET)
- {
- bitstatus = SET;
- }
- else
- {
- bitstatus = RESET;
- }
- return bitstatus;
-}
-#endif /* USE_ENHANCED_DMA_DESCRIPTORS */
-
-/**
- * @brief Set the specified DMA Rx Desc Own bit.
- * @param DMARxDesc: Pointer on a Rx desc
- * @retval None
- */
-void ETH_SetDMARxDescOwnBit(ETH_DMADESCTypeDef *DMARxDesc)
-{
- /* Set the DMA Rx Desc Own bit */
- DMARxDesc->Status |= ETH_DMARxDesc_OWN;
-}
-
-/**
- * @brief Returns the specified DMA Rx Desc frame length.
- * @param DMARxDesc: pointer on a DMA Rx descriptor
- * @retval The Rx descriptor received frame length.
- */
-uint32_t ETH_GetDMARxDescFrameLength(ETH_DMADESCTypeDef *DMARxDesc)
-{
- /* Return the Receive descriptor frame length */
- return ((DMARxDesc->Status & ETH_DMARxDesc_FL) >> ETH_DMARXDESC_FRAME_LENGTHSHIFT);
-}
-
-/**
- * @brief Enables or disables the specified DMA Rx Desc receive interrupt.
- * @param DMARxDesc: Pointer on a Rx desc
- * @param NewState: new state of the specified DMA Rx Desc interrupt.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void ETH_DMARxDescReceiveITConfig(ETH_DMADESCTypeDef *DMARxDesc, FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- if (NewState != DISABLE)
- {
- /* Enable the DMA Rx Desc receive interrupt */
- DMARxDesc->ControlBufferSize &=(~(uint32_t)ETH_DMARxDesc_DIC);
- }
- else
- {
- /* Disable the DMA Rx Desc receive interrupt */
- DMARxDesc->ControlBufferSize |= ETH_DMARxDesc_DIC;
- }
-}
-
-
-/**
- * @brief Returns the specified ETHERNET DMA Rx Desc buffer size.
- * @param DMARxDesc: pointer on a DMA Rx descriptor
- * @param DMARxDesc_Buffer: specifies the DMA Rx Desc buffer.
- * This parameter can be any one of the following values:
- * @arg ETH_DMARxDesc_Buffer1 : DMA Rx Desc Buffer1
- * @arg ETH_DMARxDesc_Buffer2 : DMA Rx Desc Buffer2
- * @retval The Receive descriptor frame length.
- */
-uint32_t ETH_GetDMARxDescBufferSize(ETH_DMADESCTypeDef *DMARxDesc, uint32_t DMARxDesc_Buffer)
-{
- /* Check the parameters */
- assert_param(IS_ETH_DMA_RXDESC_BUFFER(DMARxDesc_Buffer));
-
- if(DMARxDesc_Buffer != ETH_DMARxDesc_Buffer1)
- {
- /* Return the DMA Rx Desc buffer2 size */
- return ((DMARxDesc->ControlBufferSize & ETH_DMARxDesc_RBS2) >> ETH_DMARXDESC_BUFFER2_SIZESHIFT);
- }
- else
- {
- /* Return the DMA Rx Desc buffer1 size */
- return (DMARxDesc->ControlBufferSize & ETH_DMARxDesc_RBS1);
- }
-}
-
-
-/**
- * @brief Get the size of the received packet.
- * @param None
- * @retval framelength: received packet size
- */
-uint32_t ETH_GetRxPktSize(ETH_DMADESCTypeDef *DMARxDesc)
-{
- uint32_t frameLength = 0;
- if(((DMARxDesc->Status & ETH_DMARxDesc_OWN) == (uint32_t)RESET) &&
- ((DMARxDesc->Status & ETH_DMARxDesc_ES) == (uint32_t)RESET) &&
- ((DMARxDesc->Status & ETH_DMARxDesc_LS) != (uint32_t)RESET))
- {
- /* Get the size of the packet: including 4 bytes of the CRC */
- frameLength = ETH_GetDMARxDescFrameLength(DMARxDesc);
- }
-
- /* Return Frame Length */
- return frameLength;
-}
-
-#ifdef USE_ENHANCED_DMA_DESCRIPTORS
-/**
- * @brief Enables or disables the Enhanced descriptor structure.
- * @param NewState: new state of the Enhanced descriptor structure.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void ETH_EnhancedDescriptorCmd(FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- if (NewState != DISABLE)
- {
- /* Enable enhanced descriptor structure */
- ETH->DMABMR |= ETH_DMABMR_EDE;
- }
- else
- {
- /* Disable enhanced descriptor structure */
- ETH->DMABMR &= ~ETH_DMABMR_EDE;
- }
-}
-#endif /* USE_ENHANCED_DMA_DESCRIPTORS */
-
-/******************************************************************************/
-/* DMA functions */
-/******************************************************************************/
-/**
- * @brief Resets all MAC subsystem internal registers and logic.
- * @param None
- * @retval None
- */
-void ETH_SoftwareReset(void)
-{
- /* Set the SWR bit: resets all MAC subsystem internal registers and logic */
- /* After reset all the registers holds their respective reset values */
- ETH->DMABMR |= ETH_DMABMR_SR;
-}
-
-/**
- * @brief Checks whether the ETHERNET software reset bit is set or not.
- * @param None
- * @retval The new state of DMA Bus Mode register SR bit (SET or RESET).
- */
-FlagStatus ETH_GetSoftwareResetStatus(void)
-{
- FlagStatus bitstatus = RESET;
- if((ETH->DMABMR & ETH_DMABMR_SR) != (uint32_t)RESET)
- {
- bitstatus = SET;
- }
- else
- {
- bitstatus = RESET;
- }
- return bitstatus;
-}
-
-/**
- * @brief Checks whether the specified ETHERNET DMA flag is set or not.
- * @param ETH_DMA_FLAG: specifies the flag to check.
- * This parameter can be one of the following values:
- * @arg ETH_DMA_FLAG_TST : Time-stamp trigger flag
- * @arg ETH_DMA_FLAG_PMT : PMT flag
- * @arg ETH_DMA_FLAG_MMC : MMC flag
- * @arg ETH_DMA_FLAG_DataTransferError : Error bits 0-data buffer, 1-desc. access
- * @arg ETH_DMA_FLAG_ReadWriteError : Error bits 0-write trnsf, 1-read transfr
- * @arg ETH_DMA_FLAG_AccessError : Error bits 0-Rx DMA, 1-Tx DMA
- * @arg ETH_DMA_FLAG_NIS : Normal interrupt summary flag
- * @arg ETH_DMA_FLAG_AIS : Abnormal interrupt summary flag
- * @arg ETH_DMA_FLAG_ER : Early receive flag
- * @arg ETH_DMA_FLAG_FBE : Fatal bus error flag
- * @arg ETH_DMA_FLAG_ET : Early transmit flag
- * @arg ETH_DMA_FLAG_RWT : Receive watchdog timeout flag
- * @arg ETH_DMA_FLAG_RPS : Receive process stopped flag
- * @arg ETH_DMA_FLAG_RBU : Receive buffer unavailable flag
- * @arg ETH_DMA_FLAG_R : Receive flag
- * @arg ETH_DMA_FLAG_TU : Underflow flag
- * @arg ETH_DMA_FLAG_RO : Overflow flag
- * @arg ETH_DMA_FLAG_TJT : Transmit jabber timeout flag
- * @arg ETH_DMA_FLAG_TBU : Transmit buffer unavailable flag
- * @arg ETH_DMA_FLAG_TPS : Transmit process stopped flag
- * @arg ETH_DMA_FLAG_T : Transmit flag
- * @retval The new state of ETH_DMA_FLAG (SET or RESET).
- */
-FlagStatus ETH_GetDMAFlagStatus(uint32_t ETH_DMA_FLAG)
-{
- FlagStatus bitstatus = RESET;
- /* Check the parameters */
- assert_param(IS_ETH_DMA_GET_IT(ETH_DMA_FLAG));
- if ((ETH->DMASR & ETH_DMA_FLAG) != (uint32_t)RESET)
- {
- bitstatus = SET;
- }
- else
- {
- bitstatus = RESET;
- }
- return bitstatus;
-}
-
-/**
- * @brief Clears the ETHERNET�s DMA pending flag.
- * @param ETH_DMA_FLAG: specifies the flag to clear.
- * This parameter can be any combination of the following values:
- * @arg ETH_DMA_FLAG_NIS : Normal interrupt summary flag
- * @arg ETH_DMA_FLAG_AIS : Abnormal interrupt summary flag
- * @arg ETH_DMA_FLAG_ER : Early receive flag
- * @arg ETH_DMA_FLAG_FBE : Fatal bus error flag
- * @arg ETH_DMA_FLAG_ETI : Early transmit flag
- * @arg ETH_DMA_FLAG_RWT : Receive watchdog timeout flag
- * @arg ETH_DMA_FLAG_RPS : Receive process stopped flag
- * @arg ETH_DMA_FLAG_RBU : Receive buffer unavailable flag
- * @arg ETH_DMA_FLAG_R : Receive flag
- * @arg ETH_DMA_FLAG_TU : Transmit Underflow flag
- * @arg ETH_DMA_FLAG_RO : Receive Overflow flag
- * @arg ETH_DMA_FLAG_TJT : Transmit jabber timeout flag
- * @arg ETH_DMA_FLAG_TBU : Transmit buffer unavailable flag
- * @arg ETH_DMA_FLAG_TPS : Transmit process stopped flag
- * @arg ETH_DMA_FLAG_T : Transmit flag
- * @retval None
- */
-void ETH_DMAClearFlag(uint32_t ETH_DMA_FLAG)
-{
- /* Check the parameters */
- assert_param(IS_ETH_DMA_FLAG(ETH_DMA_FLAG));
-
- /* Clear the selected ETHERNET DMA FLAG */
- ETH->DMASR = (uint32_t) ETH_DMA_FLAG;
-}
-
-/**
- * @brief Enables or disables the specified ETHERNET DMA interrupts.
- * @param ETH_DMA_IT: specifies the ETHERNET DMA interrupt sources to be
- * enabled or disabled.
- * This parameter can be any combination of the following values:
- * @arg ETH_DMA_IT_NIS : Normal interrupt summary
- * @arg ETH_DMA_IT_AIS : Abnormal interrupt summary
- * @arg ETH_DMA_IT_ER : Early receive interrupt
- * @arg ETH_DMA_IT_FBE : Fatal bus error interrupt
- * @arg ETH_DMA_IT_ET : Early transmit interrupt
- * @arg ETH_DMA_IT_RWT : Receive watchdog timeout interrupt
- * @arg ETH_DMA_IT_RPS : Receive process stopped interrupt
- * @arg ETH_DMA_IT_RBU : Receive buffer unavailable interrupt
- * @arg ETH_DMA_IT_R : Receive interrupt
- * @arg ETH_DMA_IT_TU : Underflow interrupt
- * @arg ETH_DMA_IT_RO : Overflow interrupt
- * @arg ETH_DMA_IT_TJT : Transmit jabber timeout interrupt
- * @arg ETH_DMA_IT_TBU : Transmit buffer unavailable interrupt
- * @arg ETH_DMA_IT_TPS : Transmit process stopped interrupt
- * @arg ETH_DMA_IT_T : Transmit interrupt
- * @param NewState: new state of the specified ETHERNET DMA interrupts.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void ETH_DMAITConfig(uint32_t ETH_DMA_IT, FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_ETH_DMA_IT(ETH_DMA_IT));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- if (NewState != DISABLE)
- {
- /* Enable the selected ETHERNET DMA interrupts */
- ETH->DMAIER |= ETH_DMA_IT;
- }
- else
- {
- /* Disable the selected ETHERNET DMA interrupts */
- ETH->DMAIER &=(~(uint32_t)ETH_DMA_IT);
- }
-}
-
-/**
- * @brief Checks whether the specified ETHERNET DMA interrupt has occurred or not.
- * @param ETH_DMA_IT: specifies the interrupt source to check.
- * This parameter can be one of the following values:
- * @arg ETH_DMA_IT_TST : Time-stamp trigger interrupt
- * @arg ETH_DMA_IT_PMT : PMT interrupt
- * @arg ETH_DMA_IT_MMC : MMC interrupt
- * @arg ETH_DMA_IT_NIS : Normal interrupt summary
- * @arg ETH_DMA_IT_AIS : Abnormal interrupt summary
- * @arg ETH_DMA_IT_ER : Early receive interrupt
- * @arg ETH_DMA_IT_FBE : Fatal bus error interrupt
- * @arg ETH_DMA_IT_ET : Early transmit interrupt
- * @arg ETH_DMA_IT_RWT : Receive watchdog timeout interrupt
- * @arg ETH_DMA_IT_RPS : Receive process stopped interrupt
- * @arg ETH_DMA_IT_RBU : Receive buffer unavailable interrupt
- * @arg ETH_DMA_IT_R : Receive interrupt
- * @arg ETH_DMA_IT_TU : Underflow interrupt
- * @arg ETH_DMA_IT_RO : Overflow interrupt
- * @arg ETH_DMA_IT_TJT : Transmit jabber timeout interrupt
- * @arg ETH_DMA_IT_TBU : Transmit buffer unavailable interrupt
- * @arg ETH_DMA_IT_TPS : Transmit process stopped interrupt
- * @arg ETH_DMA_IT_T : Transmit interrupt
- * @retval The new state of ETH_DMA_IT (SET or RESET).
- */
-ITStatus ETH_GetDMAITStatus(uint32_t ETH_DMA_IT)
-{
- ITStatus bitstatus = RESET;
- /* Check the parameters */
- assert_param(IS_ETH_DMA_GET_IT(ETH_DMA_IT));
- if ((ETH->DMASR & ETH_DMA_IT) != (uint32_t)RESET)
- {
- bitstatus = SET;
- }
- else
- {
- bitstatus = RESET;
- }
- return bitstatus;
-}
-
-/**
- * @brief Clears the ETHERNET�s DMA IT pending bit.
- * @param ETH_DMA_IT: specifies the interrupt pending bit to clear.
- * This parameter can be any combination of the following values:
- * @arg ETH_DMA_IT_NIS : Normal interrupt summary
- * @arg ETH_DMA_IT_AIS : Abnormal interrupt summary
- * @arg ETH_DMA_IT_ER : Early receive interrupt
- * @arg ETH_DMA_IT_FBE : Fatal bus error interrupt
- * @arg ETH_DMA_IT_ETI : Early transmit interrupt
- * @arg ETH_DMA_IT_RWT : Receive watchdog timeout interrupt
- * @arg ETH_DMA_IT_RPS : Receive process stopped interrupt
- * @arg ETH_DMA_IT_RBU : Receive buffer unavailable interrupt
- * @arg ETH_DMA_IT_R : Receive interrupt
- * @arg ETH_DMA_IT_TU : Transmit Underflow interrupt
- * @arg ETH_DMA_IT_RO : Receive Overflow interrupt
- * @arg ETH_DMA_IT_TJT : Transmit jabber timeout interrupt
- * @arg ETH_DMA_IT_TBU : Transmit buffer unavailable interrupt
- * @arg ETH_DMA_IT_TPS : Transmit process stopped interrupt
- * @arg ETH_DMA_IT_T : Transmit interrupt
- * @retval None
- */
-void ETH_DMAClearITPendingBit(uint32_t ETH_DMA_IT)
-{
- /* Check the parameters */
- assert_param(IS_ETH_DMA_IT(ETH_DMA_IT));
-
- /* Clear the selected ETHERNET DMA IT */
- ETH->DMASR = (uint32_t) ETH_DMA_IT;
-}
-
-/**
- * @brief Returns the ETHERNET DMA Transmit Process State.
- * @param None
- * @retval The new ETHERNET DMA Transmit Process State:
- * This can be one of the following values:
- * - ETH_DMA_TransmitProcess_Stopped : Stopped - Reset or Stop Tx Command issued
- * - ETH_DMA_TransmitProcess_Fetching : Running - fetching the Tx descriptor
- * - ETH_DMA_TransmitProcess_Waiting : Running - waiting for status
- * - ETH_DMA_TransmitProcess_Reading : Running - reading the data from host memory
- * - ETH_DMA_TransmitProcess_Suspended : Suspended - Tx Descriptor unavailable
- * - ETH_DMA_TransmitProcess_Closing : Running - closing Rx descriptor
- */
-uint32_t ETH_GetTransmitProcessState(void)
-{
- return ((uint32_t)(ETH->DMASR & ETH_DMASR_TS));
-}
-
-/**
- * @brief Returns the ETHERNET DMA Receive Process State.
- * @param None
- * @retval The new ETHERNET DMA Receive Process State:
- * This can be one of the following values:
- * - ETH_DMA_ReceiveProcess_Stopped : Stopped - Reset or Stop Rx Command issued
- * - ETH_DMA_ReceiveProcess_Fetching : Running - fetching the Rx descriptor
- * - ETH_DMA_ReceiveProcess_Waiting : Running - waiting for packet
- * - ETH_DMA_ReceiveProcess_Suspended : Suspended - Rx Descriptor unavailable
- * - ETH_DMA_ReceiveProcess_Closing : Running - closing descriptor
- * - ETH_DMA_ReceiveProcess_Queuing : Running - queuing the receive frame into host memory
- */
-uint32_t ETH_GetReceiveProcessState(void)
-{
- return ((uint32_t)(ETH->DMASR & ETH_DMASR_RS));
-}
-
-/**
- * @brief Clears the ETHERNET transmit FIFO.
- * @param None
- * @retval None
- */
-void ETH_FlushTransmitFIFO(void)
-{
- /* Set the Flush Transmit FIFO bit */
- ETH->DMAOMR |= ETH_DMAOMR_FTF;
-}
-
-/**
- * @brief Checks whether the ETHERNET flush transmit FIFO bit is cleared or not.
- * @param None
- * @retval The new state of ETHERNET flush transmit FIFO bit (SET or RESET).
- */
-FlagStatus ETH_GetFlushTransmitFIFOStatus(void)
-{
- FlagStatus bitstatus = RESET;
- if ((ETH->DMAOMR & ETH_DMAOMR_FTF) != (uint32_t)RESET)
- {
- bitstatus = SET;
- }
- else
- {
- bitstatus = RESET;
- }
- return bitstatus;
-}
-
-/**
- * @brief Enables or disables the DMA transmission.
- * @param NewState: new state of the DMA transmission.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void ETH_DMATransmissionCmd(FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- if (NewState != DISABLE)
- {
- /* Enable the DMA transmission */
- ETH->DMAOMR |= ETH_DMAOMR_ST;
- }
- else
- {
- /* Disable the DMA transmission */
- ETH->DMAOMR &= ~ETH_DMAOMR_ST;
- }
-}
-
-/**
- * @brief Enables or disables the DMA reception.
- * @param NewState: new state of the DMA reception.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void ETH_DMAReceptionCmd(FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- if (NewState != DISABLE)
- {
- /* Enable the DMA reception */
- ETH->DMAOMR |= ETH_DMAOMR_SR;
- }
- else
- {
- /* Disable the DMA reception */
- ETH->DMAOMR &= ~ETH_DMAOMR_SR;
- }
-}
-
-/**
- * @brief Checks whether the specified ETHERNET DMA overflow flag is set or not.
- * @param ETH_DMA_Overflow: specifies the DMA overflow flag to check.
- * This parameter can be one of the following values:
- * @arg ETH_DMA_Overflow_RxFIFOCounter : Overflow for FIFO Overflows Counter
- * @arg ETH_DMA_Overflow_MissedFrameCounter : Overflow for Buffer Unavailable Missed Frame Counter
- * @retval The new state of ETHERNET DMA overflow Flag (SET or RESET).
- */
-FlagStatus ETH_GetDMAOverflowStatus(uint32_t ETH_DMA_Overflow)
-{
- FlagStatus bitstatus = RESET;
- /* Check the parameters */
- assert_param(IS_ETH_DMA_GET_OVERFLOW(ETH_DMA_Overflow));
-
- if ((ETH->DMAMFBOCR & ETH_DMA_Overflow) != (uint32_t)RESET)
- {
- bitstatus = SET;
- }
- else
- {
- bitstatus = RESET;
- }
- return bitstatus;
-}
-
-/**
- * @brief Get the ETHERNET DMA Rx Overflow Missed Frame Counter value.
- * @param None
- * @retval The value of Rx overflow Missed Frame Counter.
- */
-uint32_t ETH_GetRxOverflowMissedFrameCounter(void)
-{
- return ((uint32_t)((ETH->DMAMFBOCR & ETH_DMAMFBOCR_MFA)>>ETH_DMA_RX_OVERFLOW_MISSEDFRAMES_COUNTERSHIFT));
-}
-
-/**
- * @brief Get the ETHERNET DMA Buffer Unavailable Missed Frame Counter value.
- * @param None
- * @retval The value of Buffer unavailable Missed Frame Counter.
- */
-uint32_t ETH_GetBufferUnavailableMissedFrameCounter(void)
-{
- return ((uint32_t)(ETH->DMAMFBOCR) & ETH_DMAMFBOCR_MFC);
-}
-
-/**
- * @brief Get the ETHERNET DMA DMACHTDR register value.
- * @param None
- * @retval The value of the current Tx desc start address.
- */
-uint32_t ETH_GetCurrentTxDescStartAddress(void)
-{
- return ((uint32_t)(ETH->DMACHTDR));
-}
-
-/**
- * @brief Get the ETHERNET DMA DMACHRDR register value.
- * @param None
- * @retval The value of the current Rx desc start address.
- */
-uint32_t ETH_GetCurrentRxDescStartAddress(void)
-{
- return ((uint32_t)(ETH->DMACHRDR));
-}
-
-/**
- * @brief Get the ETHERNET DMA DMACHTBAR register value.
- * @param None
- * @retval The value of the current transmit descriptor data buffer address.
- */
-uint32_t ETH_GetCurrentTxBufferAddress(void)
-{
- return ((uint32_t)(ETH->DMACHTBAR));
-}
-
-/**
- * @brief Get the ETHERNET DMA DMACHRBAR register value.
- * @param None
- * @retval The value of the current receive descriptor data buffer address.
- */
-uint32_t ETH_GetCurrentRxBufferAddress(void)
-{
- return ((uint32_t)(ETH->DMACHRBAR));
-}
-
-/**
- * @brief Resumes the DMA Transmission by writing to the DmaTxPollDemand register
- * (the data written could be anything). This forces the DMA to resume transmission.
- * @param None
- * @retval None.
- */
-void ETH_ResumeDMATransmission(void)
-{
- ETH->DMATPDR = 0;
-}
-
-/**
- * @brief Resumes the DMA Transmission by writing to the DmaRxPollDemand register
- * (the data written could be anything). This forces the DMA to resume reception.
- * @param None
- * @retval None.
- */
-void ETH_ResumeDMAReception(void)
-{
- ETH->DMARPDR = 0;
-}
-
-/**
- * @brief Set the DMA Receive status watchdog timer register value
- * @param Value: DMA Receive status watchdog timer register value
- * @retval None
- */
-void ETH_SetReceiveWatchdogTimer(uint8_t Value)
-{
- /* Set the DMA Receive status watchdog timer register */
- ETH->DMARSWTR = Value;
-}
-
-/******************************************************************************/
-/* PHY functions */
-/******************************************************************************/
-
-/**
- * @brief Read a PHY register
- * @param PHYAddress: PHY device address, is the index of one of supported 32 PHY devices.
- * This parameter can be one of the following values: 0,..,31
- * @param PHYReg: PHY register address, is the index of one of the 32 PHY register.
- * This parameter can be one of the following values:
- * @arg PHY_BCR: Transceiver Basic Control Register
- * @arg PHY_BSR: Transceiver Basic Status Register
- * @arg PHY_SR : Transceiver Status Register
- * @arg More PHY register could be read depending on the used PHY
- * @retval ETH_ERROR: in case of timeout
- * MAC MIIDR register value: Data read from the selected PHY register (correct read )
- */
-uint16_t ETH_ReadPHYRegister(uint16_t PHYAddress, uint16_t PHYReg)
-{
- uint32_t tmpreg = 0;
-__IO uint32_t timeout = 0;
- /* Check the parameters */
- assert_param(IS_ETH_PHY_ADDRESS(PHYAddress));
- // assert_param(IS_ETH_PHY_REG(PHYReg));
- /* Get the ETHERNET MACMIIAR value */
- tmpreg = ETH->MACMIIAR;
- /* Keep only the CSR Clock Range CR[2:0] bits value */
- tmpreg &= ~MACMIIAR_CR_MASK;
- /* Prepare the MII address register value */
- tmpreg |=(((uint32_t)PHYAddress<<11) & ETH_MACMIIAR_PA); /* Set the PHY device address */
- tmpreg |=(((uint32_t)PHYReg<<6) & ETH_MACMIIAR_MR); /* Set the PHY register address */
- tmpreg &= ~ETH_MACMIIAR_MW; /* Set the read mode */
- tmpreg |= ETH_MACMIIAR_MB; /* Set the MII Busy bit */
- /* Write the result value into the MII Address register */
-
- ETH->MACMIIAR = tmpreg;
- /* Check for the Busy flag */
- do
- {
- timeout++;
- tmpreg = ETH->MACMIIAR;
-
- } while ((tmpreg & ETH_MACMIIAR_MB) && (timeout < (uint32_t)PHY_READ_TO));
- /* Return ERROR in case of timeout */
- if(timeout == PHY_READ_TO)
- {
- return (uint16_t)ETH_ERROR;
- }
-
- /* Return data register value */
- return (uint16_t)(ETH->MACMIIDR);
-}
-
-/**
- * @brief Write to a PHY register
- * @param PHYAddress: PHY device address, is the index of one of supported 32 PHY devices.
- * This parameter can be one of the following values: 0,..,31
- * @param PHYReg: PHY register address, is the index of one of the 32 PHY register.
- * This parameter can be one of the following values:
- * @arg PHY_BCR : Transceiver Control Register
- * @arg More PHY register could be written depending on the used PHY
- * @param PHYValue: the value to write
- * @retval ETH_ERROR: in case of timeout
- * ETH_SUCCESS: for correct write
- */
-uint32_t ETH_WritePHYRegister(uint16_t PHYAddress, uint16_t PHYReg, uint16_t PHYValue)
-{
- uint32_t tmpreg = 0;
- __IO uint32_t timeout = 0;
- /* Check the parameters */
- assert_param(IS_ETH_PHY_ADDRESS(PHYAddress));
- // assert_param(IS_ETH_PHY_REG(PHYReg));
-
- /* Get the ETHERNET MACMIIAR value */
- tmpreg = ETH->MACMIIAR;
- /* Keep only the CSR Clock Range CR[2:0] bits value */
- tmpreg &= ~MACMIIAR_CR_MASK;
- /* Prepare the MII register address value */
- tmpreg |=(((uint32_t)PHYAddress<<11) & ETH_MACMIIAR_PA); /* Set the PHY device address */
- tmpreg |=(((uint32_t)PHYReg<<6) & ETH_MACMIIAR_MR); /* Set the PHY register address */
- tmpreg |= ETH_MACMIIAR_MW; /* Set the write mode */
- tmpreg |= ETH_MACMIIAR_MB; /* Set the MII Busy bit */
- /* Give the value to the MII data register */
- ETH->MACMIIDR = PHYValue;
- /* Write the result value into the MII Address register */
- ETH->MACMIIAR = tmpreg;
- /* Check for the Busy flag */
- do
- {
- timeout++;
- tmpreg = ETH->MACMIIAR;
- } while ((tmpreg & ETH_MACMIIAR_MB) && (timeout < (uint32_t)PHY_WRITE_TO));
- /* Return ERROR in case of timeout */
- if(timeout == PHY_WRITE_TO)
- {
- return ETH_ERROR;
- }
-
- /* Return SUCCESS */
- return ETH_SUCCESS;
-}
-
-/**
- * @brief Enables or disables the PHY loopBack mode.
- * @Note: Don't be confused with ETH_MACLoopBackCmd function which enables internal
- * loopback at MII level
- * @param PHYAddress: PHY device address, is the index of one of supported 32 PHY devices.
- * @param NewState: new state of the PHY loopBack mode.
- * This parameter can be: ENABLE or DISABLE.
- * @retval ETH_ERROR: in case of bad PHY configuration
- * ETH_SUCCESS: for correct PHY configuration
- */
-uint32_t ETH_PHYLoopBackCmd(uint16_t PHYAddress, FunctionalState NewState)
-{
- uint16_t tmpreg = 0;
- /* Check the parameters */
- assert_param(IS_ETH_PHY_ADDRESS(PHYAddress));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- /* Get the PHY configuration to update it */
- tmpreg = ETH_ReadPHYRegister(PHYAddress, PHY_BCR);
-
- if (NewState != DISABLE)
- {
- /* Enable the PHY loopback mode */
- tmpreg |= PHY_Loopback;
- }
- else
- {
- /* Disable the PHY loopback mode: normal mode */
- tmpreg &= (uint16_t)(~(uint16_t)PHY_Loopback);
- }
- /* Update the PHY control register with the new configuration */
- if(ETH_WritePHYRegister(PHYAddress, PHY_BCR, tmpreg) != (uint32_t)RESET)
- {
- return ETH_SUCCESS;
- }
- else
- {
- /* Return SUCCESS */
- return ETH_ERROR;
- }
-}
-
-/******************************************************************************/
-/* Power Management(PMT) functions */
-/******************************************************************************/
-/**
- * @brief Reset Wakeup frame filter register pointer.
- * @param None
- * @retval None
- */
-void ETH_ResetWakeUpFrameFilterRegisterPointer(void)
-{
- /* Resets the Remote Wake-up Frame Filter register pointer to 0x0000 */
- ETH->MACPMTCSR |= ETH_MACPMTCSR_WFFRPR;
-}
-
-/**
- * @brief Populates the remote wakeup frame registers.
- * @param Buffer: Pointer on remote WakeUp Frame Filter Register buffer data (8 words).
- * @retval None
- */
-void ETH_SetWakeUpFrameFilterRegister(uint32_t *Buffer)
-{
- uint32_t i = 0;
-
- /* Fill Remote Wake-up Frame Filter register with Buffer data */
- for(i =0; iMACRWUFFR = Buffer[i];
- }
-}
-
-/**
- * @brief Enables or disables any unicast packet filtered by the MAC address
- * recognition to be a wake-up frame.
- * @param NewState: new state of the MAC Global Unicast Wake-Up.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void ETH_GlobalUnicastWakeUpCmd(FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- if (NewState != DISABLE)
- {
- /* Enable the MAC Global Unicast Wake-Up */
- ETH->MACPMTCSR |= ETH_MACPMTCSR_GU;
- }
- else
- {
- /* Disable the MAC Global Unicast Wake-Up */
- ETH->MACPMTCSR &= ~ETH_MACPMTCSR_GU;
- }
-}
-
-/**
- * @brief Checks whether the specified ETHERNET PMT flag is set or not.
- * @param ETH_PMT_FLAG: specifies the flag to check.
- * This parameter can be one of the following values:
- * @arg ETH_PMT_FLAG_WUFFRPR : Wake-Up Frame Filter Register Pointer Reset
- * @arg ETH_PMT_FLAG_WUFR : Wake-Up Frame Received
- * @arg ETH_PMT_FLAG_MPR : Magic Packet Received
- * @retval The new state of ETHERNET PMT Flag (SET or RESET).
- */
-FlagStatus ETH_GetPMTFlagStatus(uint32_t ETH_PMT_FLAG)
-{
- FlagStatus bitstatus = RESET;
- /* Check the parameters */
- assert_param(IS_ETH_PMT_GET_FLAG(ETH_PMT_FLAG));
-
- if ((ETH->MACPMTCSR & ETH_PMT_FLAG) != (uint32_t)RESET)
- {
- bitstatus = SET;
- }
- else
- {
- bitstatus = RESET;
- }
- return bitstatus;
-}
-
-/**
- * @brief Enables or disables the MAC Wake-Up Frame Detection.
- * @param NewState: new state of the MAC Wake-Up Frame Detection.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void ETH_WakeUpFrameDetectionCmd(FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- if (NewState != DISABLE)
- {
- /* Enable the MAC Wake-Up Frame Detection */
- ETH->MACPMTCSR |= ETH_MACPMTCSR_WFE;
- }
- else
- {
- /* Disable the MAC Wake-Up Frame Detection */
- ETH->MACPMTCSR &= ~ETH_MACPMTCSR_WFE;
- }
-}
-
-/**
- * @brief Enables or disables the MAC Magic Packet Detection.
- * @param NewState: new state of the MAC Magic Packet Detection.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void ETH_MagicPacketDetectionCmd(FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- if (NewState != DISABLE)
- {
- /* Enable the MAC Magic Packet Detection */
- ETH->MACPMTCSR |= ETH_MACPMTCSR_MPE;
- }
- else
- {
- /* Disable the MAC Magic Packet Detection */
- ETH->MACPMTCSR &= ~ETH_MACPMTCSR_MPE;
- }
-}
-
-/**
- * @brief Enables or disables the MAC Power Down.
- * @param NewState: new state of the MAC Power Down.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void ETH_PowerDownCmd(FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- if (NewState != DISABLE)
- {
- /* Enable the MAC Power Down */
- /* This puts the MAC in power down mode */
- ETH->MACPMTCSR |= ETH_MACPMTCSR_PD;
- }
- else
- {
- /* Disable the MAC Power Down */
- ETH->MACPMTCSR &= ~ETH_MACPMTCSR_PD;
- }
-}
-
-/******************************************************************************/
-/* MMC functions */
-/******************************************************************************/
-/**
- * @brief Preset and Initialize the MMC counters to almost-full value: 0xFFFF_FFF0 (full - 16)
- * @param None
- * @retval None
- */
-void ETH_MMCCounterFullPreset(void)
-{
- /* Preset and Initialize the MMC counters to almost-full value */
- ETH->MMCCR |= ETH_MMCCR_MCFHP | ETH_MMCCR_MCP;
-}
-
-/**
- * @brief Preset and Initialize the MMC counters to almost-hal value: 0x7FFF_FFF0 (half - 16).
- * @param None
- * @retval None
- */
-void ETH_MMCCounterHalfPreset(void)
-{
- /* Preset the MMC counters to almost-full value */
- ETH->MMCCR &= ~ETH_MMCCR_MCFHP;
- /* Initialize the MMC counters to almost-half value */
- ETH->MMCCR |= ETH_MMCCR_MCP;
-}
-
- /**
- * @brief Enables or disables the MMC Counter Freeze.
- * @param NewState: new state of the MMC Counter Freeze.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void ETH_MMCCounterFreezeCmd(FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- if (NewState != DISABLE)
- {
- /* Enable the MMC Counter Freeze */
- ETH->MMCCR |= ETH_MMCCR_MCF;
- }
- else
- {
- /* Disable the MMC Counter Freeze */
- ETH->MMCCR &= ~ETH_MMCCR_MCF;
- }
-}
-
-/**
- * @brief Enables or disables the MMC Reset On Read.
- * @param NewState: new state of the MMC Reset On Read.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void ETH_MMCResetOnReadCmd(FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- if (NewState != DISABLE)
- {
- /* Enable the MMC Counter reset on read */
- ETH->MMCCR |= ETH_MMCCR_ROR;
- }
- else
- {
- /* Disable the MMC Counter reset on read */
- ETH->MMCCR &= ~ETH_MMCCR_ROR;
- }
-}
-
-/**
- * @brief Enables or disables the MMC Counter Stop Rollover.
- * @param NewState: new state of the MMC Counter Stop Rollover.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void ETH_MMCCounterRolloverCmd(FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- if (NewState != DISABLE)
- {
- /* Disable the MMC Counter Stop Rollover */
- ETH->MMCCR &= ~ETH_MMCCR_CSR;
- }
- else
- {
- /* Enable the MMC Counter Stop Rollover */
- ETH->MMCCR |= ETH_MMCCR_CSR;
- }
-}
-
-/**
- * @brief Resets the MMC Counters.
- * @param None
- * @retval None
- */
-void ETH_MMCCountersReset(void)
-{
- /* Resets the MMC Counters */
- ETH->MMCCR |= ETH_MMCCR_CR;
-}
-
-/**
- * @brief Enables or disables the specified ETHERNET MMC interrupts.
- * @param ETH_MMC_IT: specifies the ETHERNET MMC interrupt sources to be enabled or disabled.
- * This parameter can be any combination of Tx interrupt or
- * any combination of Rx interrupt (but not both)of the following values:
- * @arg ETH_MMC_IT_TGF : When Tx good frame counter reaches half the maximum value
- * @arg ETH_MMC_IT_TGFMSC: When Tx good multi col counter reaches half the maximum value
- * @arg ETH_MMC_IT_TGFSC : When Tx good single col counter reaches half the maximum value
- * @arg ETH_MMC_IT_RGUF : When Rx good unicast frames counter reaches half the maximum value
- * @arg ETH_MMC_IT_RFAE : When Rx alignment error counter reaches half the maximum value
- * @arg ETH_MMC_IT_RFCE : When Rx crc error counter reaches half the maximum value
- * @param NewState: new state of the specified ETHERNET MMC interrupts.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void ETH_MMCITConfig(uint32_t ETH_MMC_IT, FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_ETH_MMC_IT(ETH_MMC_IT));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- if ((ETH_MMC_IT & (uint32_t)0x10000000) != (uint32_t)RESET)
- {
- /* Remove Register mak from IT */
- ETH_MMC_IT &= 0xEFFFFFFF;
-
- /* ETHERNET MMC Rx interrupts selected */
- if (NewState != DISABLE)
- {
- /* Enable the selected ETHERNET MMC interrupts */
- ETH->MMCRIMR &=(~(uint32_t)ETH_MMC_IT);
- }
- else
- {
- /* Disable the selected ETHERNET MMC interrupts */
- ETH->MMCRIMR |= ETH_MMC_IT;
- }
- }
- else
- {
- /* ETHERNET MMC Tx interrupts selected */
- if (NewState != DISABLE)
- {
- /* Enable the selected ETHERNET MMC interrupts */
- ETH->MMCTIMR &=(~(uint32_t)ETH_MMC_IT);
- }
- else
- {
- /* Disable the selected ETHERNET MMC interrupts */
- ETH->MMCTIMR |= ETH_MMC_IT;
- }
- }
-}
-
-/**
- * @brief Checks whether the specified ETHERNET MMC IT is set or not.
- * @param ETH_MMC_IT: specifies the ETHERNET MMC interrupt.
- * This parameter can be one of the following values:
- * @arg ETH_MMC_IT_TxFCGC: When Tx good frame counter reaches half the maximum value
- * @arg ETH_MMC_IT_TxMCGC: When Tx good multi col counter reaches half the maximum value
- * @arg ETH_MMC_IT_TxSCGC: When Tx good single col counter reaches half the maximum value
- * @arg ETH_MMC_IT_RxUGFC: When Rx good unicast frames counter reaches half the maximum value
- * @arg ETH_MMC_IT_RxAEC : When Rx alignment error counter reaches half the maximum value
- * @arg ETH_MMC_IT_RxCEC : When Rx crc error counter reaches half the maximum value
- * @retval The value of ETHERNET MMC IT (SET or RESET).
- */
-ITStatus ETH_GetMMCITStatus(uint32_t ETH_MMC_IT)
-{
- ITStatus bitstatus = RESET;
- /* Check the parameters */
- assert_param(IS_ETH_MMC_GET_IT(ETH_MMC_IT));
-
- if ((ETH_MMC_IT & (uint32_t)0x10000000) != (uint32_t)RESET)
- {
- /* ETHERNET MMC Rx interrupts selected */
- /* Check if the ETHERNET MMC Rx selected interrupt is enabled and occurred */
- if ((((ETH->MMCRIR & ETH_MMC_IT) != (uint32_t)RESET)) && ((ETH->MMCRIMR & ETH_MMC_IT) == (uint32_t)RESET))
- {
- bitstatus = SET;
- }
- else
- {
- bitstatus = RESET;
- }
- }
- else
- {
- /* ETHERNET MMC Tx interrupts selected */
- /* Check if the ETHERNET MMC Tx selected interrupt is enabled and occurred */
- if ((((ETH->MMCTIR & ETH_MMC_IT) != (uint32_t)RESET)) && ((ETH->MMCRIMR & ETH_MMC_IT) == (uint32_t)RESET))
- {
- bitstatus = SET;
- }
- else
- {
- bitstatus = RESET;
- }
- }
-
- return bitstatus;
-}
-
-/**
- * @brief Get the specified ETHERNET MMC register value.
- * @param ETH_MMCReg: specifies the ETHERNET MMC register.
- * This parameter can be one of the following values:
- * @arg ETH_MMCCR : MMC CR register
- * @arg ETH_MMCRIR : MMC RIR register
- * @arg ETH_MMCTIR : MMC TIR register
- * @arg ETH_MMCRIMR : MMC RIMR register
- * @arg ETH_MMCTIMR : MMC TIMR register
- * @arg ETH_MMCTGFSCCR : MMC TGFSCCR register
- * @arg ETH_MMCTGFMSCCR: MMC TGFMSCCR register
- * @arg ETH_MMCTGFCR : MMC TGFCR register
- * @arg ETH_MMCRFCECR : MMC RFCECR register
- * @arg ETH_MMCRFAECR : MMC RFAECR register
- * @arg ETH_MMCRGUFCR : MMC RGUFCRregister
- * @retval The value of ETHERNET MMC Register value.
- */
-uint32_t ETH_GetMMCRegister(uint32_t ETH_MMCReg)
-{
- /* Check the parameters */
- assert_param(IS_ETH_MMC_REGISTER(ETH_MMCReg));
-
- /* Return the selected register value */
- return (*(__IO uint32_t *)(ETH_MAC_BASE + ETH_MMCReg));
-}
-
-
-
-/**
- * @}
- */
-
-/**
- * @}
- */
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/i2c/Kconfig b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/i2c/Kconfig
deleted file mode 100644
index e9e435d9e..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/i2c/Kconfig
+++ /dev/null
@@ -1,11 +0,0 @@
-if BSP_USING_I2C
- config I2C_BUS_NAME_1
- string "i2c bus 1 name"
- default "i2c1"
- config I2C_DRV_NAME_1
- string "i2c bus 1 driver name"
- default "i2c1_drv"
- config I2C_1_DEVICE_NAME_0
- string "i2c bus 1 device 0 name"
- default "i2c1_dev0"
-endif
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/i2c/Makefile b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/i2c/Makefile
deleted file mode 100644
index 5f0faa560..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/i2c/Makefile
+++ /dev/null
@@ -1,3 +0,0 @@
-SRC_FILES := hardware_i2c.c connect_i2c.c
-
-include $(KERNEL_ROOT)/compiler.mk
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/i2c/connect_i2c.c b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/i2c/connect_i2c.c
deleted file mode 100644
index 1bb39194f..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/i2c/connect_i2c.c
+++ /dev/null
@@ -1,696 +0,0 @@
-/*
- * Copyright (c) 2020 RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2012-04-25 weety first version
- */
-
-/**
-* @file connect_i2c.c
-* @brief support stm32f407-st-discovery-board i2c function and register to bus framework
-* @version 1.0
-* @author AIIT XUOS Lab
-* @date 2021-04-25
-*/
-
-/*************************************************
-File name: connect_i2c.c
-Description: support stm32f407-st-discovery-board i2c configure and i2c bus register function
-Others: take RT-Thread v4.0.2/components/drivers/i2c/i2c-bit-ops.c for references
- https://github.com/RT-Thread/rt-thread/tree/v4.0.2
-History:
-1. Date: 2021-04-25
-Author: AIIT XUOS Lab
-Modification:
-1. support stm32f407-st-discovery-board i2c bit configure, write and read
-2. support stm32f407-st-discovery-board i2c bus device and driver register
-*************************************************/
-
-#include
-#include "core_cm4.h"
-#include "connect_i2c.h"
-
-#ifndef BSP_USING_I2C1
-#define BSP_USING_I2C1
-#endif
-
-#define I2C_SDA_FUNC_GPIO 25
-#define I2C_SCL_FUNC_GPIO 24
-
-static I2cBusParam i2c_bus_param =
-{
- I2C_SDA_FUNC_GPIO,
- I2C_SCL_FUNC_GPIO,
-};
-static BusType pin;
-
-#define SET_SDA(done, val) done->SetSdaState(done->data, val)
-#define SET_SCL(done, val) done->SetSclState(done->data, val)
-#define GET_SDA(done) done->GetSdaState(done->data)
-#define GET_SCL(done) done->GetSclState(done->data)
-#define SdaLow(done) SET_SDA(done, 0)
-#define SdaHigh(done) SET_SDA(done, 1)
-#define SclLow(done) SET_SCL(done, 0)
-
-static void I2cGpioInit(const I2cBusParam *bus_param)
-{
- struct PinParam i2c_scl;
- struct PinStat i2c_scl_stat;
- struct PinParam i2c_sda;
- struct PinStat i2c_sda_stat;
-
- struct BusConfigureInfo configure_info;
- struct BusBlockWriteParam write_param;
-
- int ret = 0;
-
- pin = BusFind(PIN_BUS_NAME);
- if (!pin) {
- KPrintf("find %s failed!\n", PIN_BUS_NAME);
- return ;
- }
- pin->owner_driver = BusFindDriver(pin, PIN_DRIVER_NAME);
- pin->owner_haldev = BusFindDevice(pin, PIN_DEVICE_NAME);
-
- configure_info.configure_cmd = OPE_INT;
- ret = BusDrvConfigure(pin->owner_driver, &configure_info);
- if (ret != EOK) {
- KPrintf("initialize %s failed!\n", PIN_BUS_NAME);
- return ;
- }
-
- /* config scl pin as output*/
- i2c_scl.cmd = GPIO_CONFIG_MODE;
- i2c_scl.pin = bus_param->i2c_scl_pin;
- i2c_scl.mode = GPIO_CFG_OUTPUT_OD;
-
- configure_info.configure_cmd = OPE_CFG;
- configure_info.private_data = (void *)&i2c_scl;
- ret = BusDrvConfigure(pin->owner_driver, &configure_info);
- if (ret != EOK) {
- KPrintf("config i2c scl pin %d failed!\n", bus_param->i2c_scl_pin);
- return ;
- }
- /* set scl pin as high*/
- i2c_scl_stat.pin = bus_param->i2c_scl_pin;
- i2c_scl_stat.val = GPIO_HIGH;
- write_param.buffer = (void *)&i2c_sda_stat;
- BusDevWriteData(pin->owner_haldev, &write_param);
-
- /* config sda pin as output*/
- i2c_sda.cmd = GPIO_CONFIG_MODE;
- i2c_sda.pin = bus_param->i2c_sda_pin;
- i2c_sda.mode = GPIO_CFG_OUTPUT_OD;
-
- configure_info.configure_cmd = OPE_CFG;
- configure_info.private_data = (void *)&i2c_sda;
- ret = BusDrvConfigure(pin->owner_driver, &configure_info);
- if (ret != EOK) {
- KPrintf("config i2c sda pin %d failed!\n", bus_param->i2c_sda_pin);
- return ;
- }
- /* set sda pin as high*/
- i2c_sda_stat.pin = bus_param->i2c_sda_pin;
- i2c_sda_stat.val = GPIO_HIGH;
- write_param.buffer = (void *)&i2c_sda_stat;
- BusDevWriteData(pin->owner_haldev, &write_param);
-
-}
-
-static void SetSdaState(void *data, uint8 sda_state)
-{
- struct PinStat i2c_sda_stat;
- struct BusBlockWriteParam write_param;
- I2cBusParam *bus_param = (I2cBusParam *)data;
- if (sda_state) {
- i2c_sda_stat.pin = bus_param->i2c_sda_pin;
- i2c_sda_stat.val = GPIO_HIGH;
-
- write_param.buffer = (void *)&i2c_sda_stat;
- BusDevWriteData(pin->owner_haldev, &write_param);
- } else {
- i2c_sda_stat.pin = bus_param->i2c_sda_pin;
- i2c_sda_stat.val = GPIO_LOW;
-
- write_param.buffer = (void *)&i2c_sda_stat;
- BusDevWriteData(pin->owner_haldev, &write_param);
- }
-}
-
-static void SetSclState(void *data, uint8 scl_state)
-{
- struct PinStat i2c_scl_stat;
- struct BusBlockWriteParam write_param;
- I2cBusParam *bus_param = (I2cBusParam *)data;
-
- if (scl_state) {
- i2c_scl_stat.pin = bus_param->i2c_scl_pin;
- i2c_scl_stat.val = GPIO_HIGH;
-
- write_param.buffer = (void *)&i2c_scl_stat;
- BusDevWriteData(pin->owner_haldev, &write_param);
- } else {
- i2c_scl_stat.pin = bus_param->i2c_scl_pin;
- i2c_scl_stat.val = GPIO_LOW;
-
- write_param.buffer = (void *)&i2c_scl_stat;
- BusDevWriteData(pin->owner_haldev, &write_param);
- }
-}
-
-static uint8 GetSdaState(void *data)
-{
- struct PinStat i2c_sda_stat;
- struct BusBlockReadParam read_param;
- I2cBusParam *bus_param = (I2cBusParam *)data;
-
- i2c_sda_stat.pin = bus_param->i2c_sda_pin;
-
- read_param.buffer = (void *)&i2c_sda_stat;
- return BusDevReadData(pin->owner_haldev, &read_param);
-}
-
-static uint8 GetSclState(void *data)
-{
- struct PinStat i2c_scl_stat;
- struct BusBlockReadParam read_param;
- I2cBusParam *bus_param = (I2cBusParam *)data;
- i2c_scl_stat.pin = bus_param->i2c_scl_pin;
-
- read_param.buffer = (void *)&i2c_scl_stat;
- return BusDevReadData(pin->owner_haldev, &read_param);
-}
-
- static int Stm32Udelay(uint32 us)
-{
- uint32 ticks;
- uint32 told, tnow, tcnt = 0;
- uint32 reload = SysTick->LOAD;
-
- ticks = us * reload / (1000000 / TICK_PER_SECOND);
- told = SysTick->VAL;
- while (1) {
- tnow = SysTick->VAL;
- if (tnow != told) {
- if (tnow < told) {
- tcnt += told - tnow;
- } else {
- tcnt += reload - tnow + told;
- }
- told = tnow;
- if (tcnt >= ticks) {
- return 0;
- break;
- }
- }
- }
-}
-
-static const struct I2cHalDrvDone i2c_hal_drv_done =
-{
- .data = (&i2c_bus_param),
- .SetSdaState = SetSdaState,
- .SetSclState = SetSclState,
- .GetSdaState = GetSdaState,
- .GetSclState = GetSclState,
- .udelay = Stm32Udelay,
- .delay_us = 1,
- .timeout = 100
-};
-
-static x_err_t I2cBusReset(const I2cBusParam *bus_param)
-{
- int32 i = 0;
-
- if (GPIO_LOW == GetSdaState((void *)bus_param)) {
- while (i++ < 9) {
- SetSclState((void *)bus_param,GPIO_HIGH);
- Stm32Udelay(100);
- SetSclState((void *)bus_param,GPIO_LOW);
- Stm32Udelay(100);
- }
- }
-
- if (GPIO_LOW == GetSdaState((void *)bus_param)) {
- return -ERROR;
- }
- return EOK;
-}
-
-static __inline void I2cDelay(struct I2cHalDrvDone *done)
-{
- done->udelay((done->delay_us + 1) >> 1);
-}
-
-static __inline void I2cDelay2(struct I2cHalDrvDone *done)
-{
- done->udelay(done->delay_us);
-}
-
-static x_err_t SclHigh(struct I2cHalDrvDone *done)
-{
- x_ticks_t start;
-
- SET_SCL(done, 1);
-
- if (!done->GetSclState)
- goto done;
-
- start = CurrentTicksGain();
- while (!GET_SCL(done))
- {
- if ((CurrentTicksGain() - start) > done->timeout)
- return -ETIMEOUT;
- DelayKTask((done->timeout + 1) >> 1);
- }
-
-done:
- I2cDelay(done);
-
- return EOK;
-}
-
-static void I2cStart(struct I2cHalDrvDone *done)
-{
- SdaLow(done);
- I2cDelay(done);
- SclLow(done);
-}
-
-static void I2cRestart(struct I2cHalDrvDone *done)
-{
- SdaHigh(done);
- SclHigh(done);
- I2cDelay(done);
- SdaLow(done);
- I2cDelay(done);
- SclLow(done);
-}
-
-static void I2cStop(struct I2cHalDrvDone *done)
-{
- SdaLow(done);
- I2cDelay(done);
- SclHigh(done);
- I2cDelay(done);
- SdaHigh(done);
- I2cDelay2(done);
-}
-
-static __inline x_bool I2cWaitack(struct I2cHalDrvDone *done)
-{
- x_bool ack;
-
- SdaHigh(done);
- GET_SDA(done);
- I2cDelay(done);
-
- if (SclHigh(done) < 0) {
- KPrintf("wait ack timeout");
- return -ETIMEOUT;
- }
-
- ack = !GET_SDA(done);
-
- SclLow(done);
-
- return ack;
-}
-
-static int32 I2cWriteb(struct I2cBus *bus, uint8 data)
-{
- int32 i;
- uint8 bit;
-
- struct I2cHalDrvDone *done = (struct I2cHalDrvDone *)bus->private_data;
-
- for (i = 7; i >= 0; i--) {
- SclLow(done);
- bit = (data >> i) & 1;
- SET_SDA(done, bit);
- I2cDelay(done);
- if (SclHigh(done) < 0) {
- KPrintf("I2cWriteb: 0x%02x, "
- "wait scl pin high timeout at bit %d",
- data, i);
-
- return -ETIMEOUT;
- }
- }
- SclLow(done);
- I2cDelay(done);
-
- return I2cWaitack(done);
-}
-
-static int32 I2cReadb(struct I2cBus *bus)
-{
- uint8 i;
- uint8 data = 0;
- struct I2cHalDrvDone *done = (struct I2cHalDrvDone *)bus->private_data;
-
- SdaHigh(done);
- GET_SDA(done);
- I2cDelay(done);
- for (i = 0; i < 8; i++) {
- data <<= 1;
-
- if (SclHigh(done) < 0) {
- KPrintf("I2cReadb: wait scl pin high "
- "timeout at bit %d", 7 - i);
-
- return -ETIMEOUT;
- }
-
- if (GET_SDA(done))
- data |= 1;
- SclLow(done);
- I2cDelay2(done);
- }
-
- return data;
-}
-
-static x_size_t I2cSendBytes(struct I2cBus *bus, struct I2cDataStandard *msg)
-{
- int32 ret;
- x_size_t bytes = 0;
- const uint8 *ptr = msg->buf;
- int32 count = msg->len;
- uint16 ignore_nack = msg->flags & I2C_IGNORE_NACK;
-
- while (count > 0) {
- ret = I2cWriteb(bus, *ptr);
-
- if ((ret > 0) || (ignore_nack && (ret == 0))) {
- count --;
- ptr ++;
- bytes ++;
- } else if (ret == 0) {
-
- return 0;
- } else {
- KPrintf("send bytes: error %d", ret);
-
- return ret;
- }
- }
-
- return bytes;
-}
-
-static x_err_t I2cSendAckOrNack(struct I2cBus *bus, int ack)
-{
- struct I2cHalDrvDone *done = (struct I2cHalDrvDone *)bus->private_data;
-
- if (ack)
- SET_SDA(done, 0);
- I2cDelay(done);
- if (SclHigh(done) < 0) {
- KPrintf("ACK or NACK timeout.");
-
- return -ETIMEOUT;
- }
- SclLow(done);
-
- return EOK;
-}
-
-static x_size_t I2cRecvBytes(struct I2cBus *bus, struct I2cDataStandard *msg)
-{
- int32 val;
- int32 bytes = 0;
- uint8 *ptr = msg->buf;
- int32 count = msg->len;
- const uint32 flags = msg->flags;
-
- while (count > 0) {
- val = I2cReadb(bus);
- if (val >= 0) {
- *ptr = val;
- bytes ++;
- } else {
- break;
- }
-
- ptr ++;
- count --;
-
- if (!(flags & I2C_NO_READ_ACK)){
- val = I2cSendAckOrNack(bus, count);
- if (val < 0)
- return val;
- }
- }
-
- return bytes;
-}
-
-static int32 I2cSendAddress(struct I2cBus *bus, uint8 addr, int32 retries)
-{
- struct I2cHalDrvDone *done = (struct I2cHalDrvDone *)bus->private_data;
- int32 i;
- x_err_t ret = 0;
-
- for (i = 0; i <= retries; i++) {
- ret = I2cWriteb(bus, addr);
- if (ret == 1 || i == retries)
- break;
- I2cStop(done);
- I2cDelay2(done);
- I2cStart(done);
- }
-
- return ret;
-}
-
-static x_err_t I2cBitSendAddress(struct I2cBus *bus, struct I2cDataStandard *msg)
-{
- uint16 flags = msg->flags;
- uint16 ignore_nack = msg->flags & I2C_IGNORE_NACK;
- struct I2cHalDrvDone *done = (struct I2cHalDrvDone *)bus->private_data;
-
- uint8 addr1, addr2;
- int32 retries;
- x_err_t ret;
-
- retries = ignore_nack ? 0 : msg->retries;
-
- if (flags & I2C_ADDR_10BIT) {
- addr1 = 0xf0 | ((msg->addr >> 7) & 0x06);
- addr2 = msg->addr & 0xff;
-
- ret = I2cSendAddress(bus, addr1, retries);
- if ((ret != 1) && !ignore_nack){
-
- return -EPIO;
- }
-
- ret = I2cWriteb(bus, addr2);
- if ((ret != 1) && !ignore_nack){
-
- return -EPIO;
- }
- if (flags & I2C_RD) {
- I2cRestart(done);
- addr1 |= 0x01;
- ret = I2cSendAddress(bus, addr1, retries);
- if ((ret != 1) && !ignore_nack) {
-
- return -EPIO;
- }
- }
- } else {
- addr1 = msg->addr << 1;
- if (flags & I2C_RD)
- addr1 |= 1;
- ret = I2cSendAddress(bus, addr1, retries);
- if ((ret != 1) && !ignore_nack)
- return -EPIO;
- }
-
- return EOK;
-}
-
-static uint32 I2cWriteData(struct I2cHardwareDevice *i2c_dev, struct I2cDataStandard *msg)
-{
- struct I2cBus *bus = (struct I2cBus *)i2c_dev->haldev.owner_bus;
- bus->private_data = i2c_dev->haldev.owner_bus->private_data;
- struct I2cHalDrvDone *done = (struct I2cHalDrvDone *)bus->private_data;
- int32 ret;
- int32 i = 0;
- uint16 ignore_nack;
-
- I2cStart(done);
- while (NONE != msg) {
- ignore_nack = msg->flags & I2C_IGNORE_NACK;
- if (!(msg->flags & I2C_NO_START)) {
- if (i) {
- I2cRestart(done);
- }
- ret = I2cBitSendAddress(bus, msg);
- if ((ret != EOK) && !ignore_nack) {
- goto out;
- }
- }
-
- if (msg->flags & I2C_WR) {
- ret = I2cSendBytes(bus, msg);
- if (ret >= 1)
- //KPrintf("write %d byte%s", ret, ret == 1 ? "" : "s");
- if (ret < msg->len){
- if (ret >= 0)
- ret = -ERROR;
- goto out;
- }
- }
- msg = msg->next;
- i++;
- }
- ret = i;
-
-out:
- I2cStop(done);
-
- return ret;
-}
-
-static uint32 I2cReadData(struct I2cHardwareDevice *i2c_dev, struct I2cDataStandard *msg)
-{
- struct I2cBus *bus = (struct I2cBus *)i2c_dev->haldev.owner_bus;
- bus->private_data = i2c_dev->haldev.owner_bus->private_data;
- struct I2cHalDrvDone *done = (struct I2cHalDrvDone *)bus->private_data;
- int32 ret;
- int32 i = 0;
- uint16 ignore_nack;
-
- I2cStart(done);
- while (NONE != msg) {
- ignore_nack = msg->flags & I2C_IGNORE_NACK;
- if (!(msg->flags & I2C_NO_START)) {
- if (i) {
- I2cRestart(done);
- }
- ret = I2cBitSendAddress(bus, msg);
- if ((ret != EOK) && !ignore_nack) {
- goto out;
- }
- }
- if (msg->flags & I2C_RD) {
- ret = I2cRecvBytes(bus, msg);
- if (ret >= 1)
- //KPrintf("read %d byte%s", ret, ret == 1 ? "" : "s");
- if (ret < msg->len){
- if (ret >= 0)
- ret = -EPIO;
- goto out;
- }
- }
- msg = msg->next;
- i++;
- }
- ret = i;
-
-out:
- I2cStop(done);
-
- return ret;
-}
-
-/*manage the i2c device operations*/
-static const struct I2cDevDone i2c_dev_done =
-{
- .dev_open = NONE,
- .dev_close = NONE,
- .dev_write = I2cWriteData,
- .dev_read = I2cReadData,
-};
-
-/*Init i2c bus*/
-static int BoardI2cBusInit(struct I2cBus *i2c_bus, struct I2cDriver *i2c_driver)
-{
- x_err_t ret = EOK;
-
- /*Init the i2c bus */
- i2c_bus->private_data = (void *)&i2c_hal_drv_done;
- ret = I2cBusInit(i2c_bus, I2C_BUS_NAME_1);
- if (EOK != ret) {
- KPrintf("board_i2c_init I2cBusInit error %d\n", ret);
- return ERROR;
- }
-
- /*Init the i2c driver*/
- i2c_driver->private_data = (void *)&i2c_hal_drv_done;
- ret = I2cDriverInit(i2c_driver, I2C_DRV_NAME_1);
- if (EOK != ret) {
- KPrintf("board_i2c_init I2cDriverInit error %d\n", ret);
- return ERROR;
- }
-
- /*Attach the i2c driver to the i2c bus*/
- ret = I2cDriverAttachToBus(I2C_DRV_NAME_1, I2C_BUS_NAME_1);
- if (EOK != ret) {
- KPrintf("board_i2c_init I2cDriverAttachToBus error %d\n", ret);
- return ERROR;
- }
-
- return ret;
-}
-
-/*Attach the i2c device to the i2c bus*/
-static int BoardI2cDevBend(void)
-{
- x_err_t ret = EOK;
- static struct I2cHardwareDevice i2c_device0;
- memset(&i2c_device0, 0, sizeof(struct I2cHardwareDevice));
-
- i2c_device0.i2c_dev_done = &i2c_dev_done;
-
- ret = I2cDeviceRegister(&i2c_device0, NONE, I2C_1_DEVICE_NAME_0);
- if (EOK != ret) {
- KPrintf("board_i2c_init I2cDeviceInit device %s error %d\n", I2C_1_DEVICE_NAME_0, ret);
- return ERROR;
- }
-
- ret = I2cDeviceAttachToBus(I2C_1_DEVICE_NAME_0, I2C_BUS_NAME_1);
- if (EOK != ret) {
- KPrintf("board_i2c_init I2cDeviceAttachToBus device %s error %d\n", I2C_1_DEVICE_NAME_0, ret);
- return ERROR;
- }
-
- return ret;
-}
-
-/*STM32F407 BOARD I2C INIT*/
-int Stm32HwI2cInit(void)
-{
- x_err_t ret = EOK;
- static struct I2cBus i2c_bus;
- memset(&i2c_bus, 0, sizeof(struct I2cBus));
-
- static struct I2cDriver i2c_driver;
- memset(&i2c_driver, 0, sizeof(struct I2cDriver));
-
-#ifdef BSP_USING_I2C1
- I2cGpioInit(&i2c_bus_param);
-
- ret = BoardI2cBusInit(&i2c_bus, &i2c_driver);
- if (EOK != ret) {
- KPrintf("board_i2c_Init error ret %u\n", ret);
- return ERROR;
- }
-
- ret = BoardI2cDevBend();
- if (EOK != ret) {
- KPrintf("board_i2c_Init error ret %u\n", ret);
- return ERROR;
- }
-
- I2cBusReset(&i2c_bus_param);
-#endif
-
- return ret;
-}
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/i2c/hardware_i2c.c b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/i2c/hardware_i2c.c
deleted file mode 100644
index e9625da3d..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/i2c/hardware_i2c.c
+++ /dev/null
@@ -1,1415 +0,0 @@
-/**
- ******************************************************************************
- * @file stm32f4xx_i2c.c
- * @author MCD Application Team
- * @version V1.0.0
- * @date 30-September-2011
- * @brief This file provides firmware functions to manage the following
- * functionalities of the Inter-integrated circuit (I2C)
- * - Initialization and Configuration
- * - Data transfers
- * - PEC management
- * - DMA transfers management
- * - Interrupts, events and flags management
- *
- * @verbatim
- *
- * ===================================================================
- * How to use this driver
- * ===================================================================
- * 1. Enable peripheral clock using RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2Cx, ENABLE)
- * function for I2C1, I2C2 or I2C3.
- *
- * 2. Enable SDA, SCL and SMBA (when used) GPIO clocks using
- * RCC_AHBPeriphClockCmd() function.
- *
- * 3. Peripherals alternate function:
- * - Connect the pin to the desired peripherals' Alternate
- * Function (AF) using GPIO_PinAFConfig() function
- * - Configure the desired pin in alternate function by:
- * GPIO_InitStruct->GPIO_Mode = GPIO_Mode_AF
- * - Select the type, pull-up/pull-down and output speed via
- * GPIO_PuPd, GPIO_OType and GPIO_Speed members
- * - Call GPIO_Init() function
- * Recommended configuration is Push-Pull, Pull-up, Open-Drain.
- * Add an external pull up if necessary (typically 4.7 KOhm).
- *
- * 4. Program the Mode, duty cycle , Own address, Ack, Speed and Acknowledged
- * Address using the I2C_Init() function.
- *
- * 5. Optionally you can enable/configure the following parameters without
- * re-initialization (i.e there is no need to call again I2C_Init() function):
- * - Enable the acknowledge feature using I2C_AcknowledgeConfig() function
- * - Enable the dual addressing mode using I2C_DualAddressCmd() function
- * - Enable the general call using the I2C_GeneralCallCmd() function
- * - Enable the clock stretching using I2C_StretchClockCmd() function
- * - Enable the fast mode duty cycle using the I2C_FastModeDutyCycleConfig()
- * function.
- * - Configure the NACK position for Master Receiver mode in case of
- * 2 bytes reception using the function I2C_NACKPositionConfig().
- * - Enable the PEC Calculation using I2C_CalculatePEC() function
- * - For SMBus Mode:
- * - Enable the Address Resolution Protocol (ARP) using I2C_ARPCmd() function
- * - Configure the SMBusAlert pin using I2C_SMBusAlertConfig() function
- *
- * 6. Enable the NVIC and the corresponding interrupt using the function
- * I2C_ITConfig() if you need to use interrupt mode.
- *
- * 7. When using the DMA mode
- * - Configure the DMA using DMA_Init() function
- * - Active the needed channel Request using I2C_DMACmd() or
- * I2C_DMALastTransferCmd() function.
- * @note When using DMA mode, I2C interrupts may be used at the same time to
- * control the communication flow (Start/Stop/Ack... events and errors).
- *
- * 8. Enable the I2C using the I2C_Cmd() function.
- *
- * 9. Enable the DMA using the DMA_Cmd() function when using DMA mode in the
- * transfers.
- *
- * @endverbatim
- *
- ******************************************************************************
- * @attention
- *
- * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
- * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
- * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
- * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
- * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
- * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
- *
- * © COPYRIGHT 2011 STMicroelectronics
- ******************************************************************************
- */
-
-/**
-* @file: hardware_i2c.c
-* @brief: support hardware i2c function
-* @version: 1.0
-* @author: AIIT XUOS Lab
-* @date: 2021/4/25
-*/
-
-/*************************************************
-File name: hardware_i2c.c
-Description: support hardware i2c function
-Others:
-History:
-1. Date: 2021-04-25
-Author: AIIT XUOS Lab
-Modification:
-1. rename stm32f4xx_i2c.c for XiUOS
-*************************************************/
-
-/* Includes ------------------------------------------------------------------*/
-#include
-#include
-#include
-
-/** @addtogroup STM32F4xx_StdPeriph_Driver
- * @{
- */
-
-/** @defgroup I2C
- * @brief I2C driver modules
- * @{
- */
-
-/* Private typedef -----------------------------------------------------------*/
-/* Private define ------------------------------------------------------------*/
-
-#define CR1_CLEAR_MASK ((uint16_t)0xFBF5) /*I2C_ClockSpeed));
- assert_param(IS_I2C_MODE(I2C_InitStruct->I2C_Mode));
- assert_param(IS_I2C_DUTY_CYCLE(I2C_InitStruct->I2C_DutyCycle));
- assert_param(IS_I2C_OWN_ADDRESS1(I2C_InitStruct->I2C_OwnAddress1));
- assert_param(IS_I2C_ACK_STATE(I2C_InitStruct->I2C_Ack));
- assert_param(IS_I2C_ACKNOWLEDGE_ADDRESS(I2C_InitStruct->I2C_AcknowledgedAddress));
-
-/*---------------------------- I2Cx CR2 Configuration ------------------------*/
- /* Get the I2Cx CR2 value */
- tmpreg = I2Cx->CR2;
- /* Clear frequency FREQ[5:0] bits */
- tmpreg &= (uint16_t)~((uint16_t)I2C_CR2_FREQ);
- /* Get pclk1 frequency value */
- RCC_GetClocksFreq(&rcc_clocks);
- pclk1 = rcc_clocks.PCLK1_Frequency;
- /* Set frequency bits depending on pclk1 value */
- freqrange = (uint16_t)(pclk1 / 1000000);
- tmpreg |= freqrange;
- /* Write to I2Cx CR2 */
- I2Cx->CR2 = tmpreg;
-
-/*---------------------------- I2Cx CCR Configuration ------------------------*/
- /* Disable the selected I2C peripheral to configure TRISE */
- I2Cx->CR1 &= (uint16_t)~((uint16_t)I2C_CR1_PE);
- /* Reset tmpreg value */
- /* Clear F/S, DUTY and CCR[11:0] bits */
- tmpreg = 0;
-
- /* Configure speed in standard mode */
- if (I2C_InitStruct->I2C_ClockSpeed <= 100000)
- {
- /* Standard mode speed calculate */
- result = (uint16_t)(pclk1 / (I2C_InitStruct->I2C_ClockSpeed << 1));
- /* Test if CCR value is under 0x4*/
- if (result < 0x04)
- {
- /* Set minimum allowed value */
- result = 0x04;
- }
- /* Set speed value for standard mode */
- tmpreg |= result;
- /* Set Maximum Rise Time for standard mode */
- I2Cx->TRISE = freqrange + 1;
- }
- /* Configure speed in fast mode */
- /* To use the I2C at 400 KHz (in fast mode), the PCLK1 frequency (I2C peripheral
- input clock) must be a multiple of 10 MHz */
- else /*(I2C_InitStruct->I2C_ClockSpeed <= 400000)*/
- {
- if (I2C_InitStruct->I2C_DutyCycle == I2C_DutyCycle_2)
- {
- /* Fast mode speed calculate: Tlow/Thigh = 2 */
- result = (uint16_t)(pclk1 / (I2C_InitStruct->I2C_ClockSpeed * 3));
- }
- else /*I2C_InitStruct->I2C_DutyCycle == I2C_DutyCycle_16_9*/
- {
- /* Fast mode speed calculate: Tlow/Thigh = 16/9 */
- result = (uint16_t)(pclk1 / (I2C_InitStruct->I2C_ClockSpeed * 25));
- /* Set DUTY bit */
- result |= I2C_DutyCycle_16_9;
- }
-
- /* Test if CCR value is under 0x1*/
- if ((result & I2C_CCR_CCR) == 0)
- {
- /* Set minimum allowed value */
- result |= (uint16_t)0x0001;
- }
- /* Set speed value and set F/S bit for fast mode */
- tmpreg |= (uint16_t)(result | I2C_CCR_FS);
- /* Set Maximum Rise Time for fast mode */
- I2Cx->TRISE = (uint16_t)(((freqrange * (uint16_t)300) / (uint16_t)1000) + (uint16_t)1);
- }
-
- /* Write to I2Cx CCR */
- I2Cx->CCR = tmpreg;
- /* Enable the selected I2C peripheral */
- I2Cx->CR1 |= I2C_CR1_PE;
-
-/*---------------------------- I2Cx CR1 Configuration ------------------------*/
- /* Get the I2Cx CR1 value */
- tmpreg = I2Cx->CR1;
- /* Clear ACK, SMBTYPE and SMBUS bits */
- tmpreg &= CR1_CLEAR_MASK;
- /* Configure I2Cx: mode and acknowledgement */
- /* Set SMBTYPE and SMBUS bits according to I2C_Mode value */
- /* Set ACK bit according to I2C_Ack value */
- tmpreg |= (uint16_t)((uint32_t)I2C_InitStruct->I2C_Mode | I2C_InitStruct->I2C_Ack);
- /* Write to I2Cx CR1 */
- I2Cx->CR1 = tmpreg;
-
-/*---------------------------- I2Cx OAR1 Configuration -----------------------*/
- /* Set I2Cx Own Address1 and acknowledged address */
- I2Cx->OAR1 = (I2C_InitStruct->I2C_AcknowledgedAddress | I2C_InitStruct->I2C_OwnAddress1);
-}
-
-/**
- * @brief Fills each I2C_InitStruct member with its default value.
- * @param I2C_InitStruct: pointer to an I2C_InitTypeDef structure which will be initialized.
- * @retval None
- */
-void I2C_StructInit(I2C_InitTypeDef* I2C_InitStruct)
-{
-/*---------------- Reset I2C init structure parameters values ----------------*/
- /* initialize the I2C_ClockSpeed member */
- I2C_InitStruct->I2C_ClockSpeed = 5000;
- /* Initialize the I2C_Mode member */
- I2C_InitStruct->I2C_Mode = I2C_Mode_I2C;
- /* Initialize the I2C_DutyCycle member */
- I2C_InitStruct->I2C_DutyCycle = I2C_DutyCycle_2;
- /* Initialize the I2C_OwnAddress1 member */
- I2C_InitStruct->I2C_OwnAddress1 = 0;
- /* Initialize the I2C_Ack member */
- I2C_InitStruct->I2C_Ack = I2C_Ack_Disable;
- /* Initialize the I2C_AcknowledgedAddress member */
- I2C_InitStruct->I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
-}
-
-/**
- * @brief Enables or disables the specified I2C peripheral.
- * @param I2Cx: where x can be 1, 2 or 3 to select the I2C peripheral.
- * @param NewState: new state of the I2Cx peripheral.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void I2C_Cmd(I2C_TypeDef* I2Cx, FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_I2C_ALL_PERIPH(I2Cx));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
- if (NewState != DISABLE)
- {
- /* Enable the selected I2C peripheral */
- I2Cx->CR1 |= I2C_CR1_PE;
- }
- else
- {
- /* Disable the selected I2C peripheral */
- I2Cx->CR1 &= (uint16_t)~((uint16_t)I2C_CR1_PE);
- }
-}
-
-/**
- * @brief Generates I2Cx communication START condition.
- * @param I2Cx: where x can be 1, 2 or 3 to select the I2C peripheral.
- * @param NewState: new state of the I2C START condition generation.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None.
- */
-void I2C_GenerateSTART(I2C_TypeDef* I2Cx, FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_I2C_ALL_PERIPH(I2Cx));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
- if (NewState != DISABLE)
- {
- /* Generate a START condition */
- I2Cx->CR1 |= I2C_CR1_START;
- }
- else
- {
- /* Disable the START condition generation */
- I2Cx->CR1 &= (uint16_t)~((uint16_t)I2C_CR1_START);
- }
-}
-
-/**
- * @brief Generates I2Cx communication STOP condition.
- * @param I2Cx: where x can be 1, 2 or 3 to select the I2C peripheral.
- * @param NewState: new state of the I2C STOP condition generation.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None.
- */
-void I2C_GenerateSTOP(I2C_TypeDef* I2Cx, FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_I2C_ALL_PERIPH(I2Cx));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
- if (NewState != DISABLE)
- {
- /* Generate a STOP condition */
- I2Cx->CR1 |= I2C_CR1_STOP;
- }
- else
- {
- /* Disable the STOP condition generation */
- I2Cx->CR1 &= (uint16_t)~((uint16_t)I2C_CR1_STOP);
- }
-}
-
-/**
- * @brief Transmits the address byte to select the slave device.
- * @param I2Cx: where x can be 1, 2 or 3 to select the I2C peripheral.
- * @param Address: specifies the slave address which will be transmitted
- * @param I2C_Direction: specifies whether the I2C device will be a Transmitter
- * or a Receiver.
- * This parameter can be one of the following values
- * @arg I2C_Direction_Transmitter: Transmitter mode
- * @arg I2C_Direction_Receiver: Receiver mode
- * @retval None.
- */
-void I2C_Send7bitAddress(I2C_TypeDef* I2Cx, uint8_t Address, uint8_t I2C_Direction)
-{
- /* Check the parameters */
- assert_param(IS_I2C_ALL_PERIPH(I2Cx));
- assert_param(IS_I2C_DIRECTION(I2C_Direction));
- /* Test on the direction to set/reset the read/write bit */
- if (I2C_Direction != I2C_Direction_Transmitter)
- {
- /* Set the address bit0 for read */
- Address |= I2C_OAR1_ADD0;
- }
- else
- {
- /* Reset the address bit0 for write */
- Address &= (uint8_t)~((uint8_t)I2C_OAR1_ADD0);
- }
- /* Send the address */
- I2Cx->DR = Address;
-}
-
-/**
- * @brief Enables or disables the specified I2C acknowledge feature.
- * @param I2Cx: where x can be 1, 2 or 3 to select the I2C peripheral.
- * @param NewState: new state of the I2C Acknowledgement.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None.
- */
-void I2C_AcknowledgeConfig(I2C_TypeDef* I2Cx, FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_I2C_ALL_PERIPH(I2Cx));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
- if (NewState != DISABLE)
- {
- /* Enable the acknowledgement */
- I2Cx->CR1 |= I2C_CR1_ACK;
- }
- else
- {
- /* Disable the acknowledgement */
- I2Cx->CR1 &= (uint16_t)~((uint16_t)I2C_CR1_ACK);
- }
-}
-
-/**
- * @brief Configures the specified I2C own address2.
- * @param I2Cx: where x can be 1, 2 or 3 to select the I2C peripheral.
- * @param Address: specifies the 7bit I2C own address2.
- * @retval None.
- */
-void I2C_OwnAddress2Config(I2C_TypeDef* I2Cx, uint8_t Address)
-{
- uint16_t tmpreg = 0;
-
- /* Check the parameters */
- assert_param(IS_I2C_ALL_PERIPH(I2Cx));
-
- /* Get the old register value */
- tmpreg = I2Cx->OAR2;
-
- /* Reset I2Cx Own address2 bit [7:1] */
- tmpreg &= (uint16_t)~((uint16_t)I2C_OAR2_ADD2);
-
- /* Set I2Cx Own address2 */
- tmpreg |= (uint16_t)((uint16_t)Address & (uint16_t)0x00FE);
-
- /* Store the new register value */
- I2Cx->OAR2 = tmpreg;
-}
-
-/**
- * @brief Enables or disables the specified I2C dual addressing mode.
- * @param I2Cx: where x can be 1, 2 or 3 to select the I2C peripheral.
- * @param NewState: new state of the I2C dual addressing mode.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void I2C_DualAddressCmd(I2C_TypeDef* I2Cx, FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_I2C_ALL_PERIPH(I2Cx));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
- if (NewState != DISABLE)
- {
- /* Enable dual addressing mode */
- I2Cx->OAR2 |= I2C_OAR2_ENDUAL;
- }
- else
- {
- /* Disable dual addressing mode */
- I2Cx->OAR2 &= (uint16_t)~((uint16_t)I2C_OAR2_ENDUAL);
- }
-}
-
-/**
- * @brief Enables or disables the specified I2C general call feature.
- * @param I2Cx: where x can be 1, 2 or 3 to select the I2C peripheral.
- * @param NewState: new state of the I2C General call.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void I2C_GeneralCallCmd(I2C_TypeDef* I2Cx, FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_I2C_ALL_PERIPH(I2Cx));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
- if (NewState != DISABLE)
- {
- /* Enable generall call */
- I2Cx->CR1 |= I2C_CR1_ENGC;
- }
- else
- {
- /* Disable generall call */
- I2Cx->CR1 &= (uint16_t)~((uint16_t)I2C_CR1_ENGC);
- }
-}
-
-/**
- * @brief Enables or disables the specified I2C software reset.
- * @note When software reset is enabled, the I2C IOs are released (this can
- * be useful to recover from bus errors).
- * @param I2Cx: where x can be 1, 2 or 3 to select the I2C peripheral.
- * @param NewState: new state of the I2C software reset.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void I2C_SoftwareResetCmd(I2C_TypeDef* I2Cx, FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_I2C_ALL_PERIPH(I2Cx));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
- if (NewState != DISABLE)
- {
- /* Peripheral under reset */
- I2Cx->CR1 |= I2C_CR1_SWRST;
- }
- else
- {
- /* Peripheral not under reset */
- I2Cx->CR1 &= (uint16_t)~((uint16_t)I2C_CR1_SWRST);
- }
-}
-
-/**
- * @brief Enables or disables the specified I2C Clock stretching.
- * @param I2Cx: where x can be 1, 2 or 3 to select the I2C peripheral.
- * @param NewState: new state of the I2Cx Clock stretching.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void I2C_StretchClockCmd(I2C_TypeDef* I2Cx, FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_I2C_ALL_PERIPH(I2Cx));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
- if (NewState == DISABLE)
- {
- /* Enable the selected I2C Clock stretching */
- I2Cx->CR1 |= I2C_CR1_NOSTRETCH;
- }
- else
- {
- /* Disable the selected I2C Clock stretching */
- I2Cx->CR1 &= (uint16_t)~((uint16_t)I2C_CR1_NOSTRETCH);
- }
-}
-
-/**
- * @brief Selects the specified I2C fast mode duty cycle.
- * @param I2Cx: where x can be 1, 2 or 3 to select the I2C peripheral.
- * @param I2C_DutyCycle: specifies the fast mode duty cycle.
- * This parameter can be one of the following values:
- * @arg I2C_DutyCycle_2: I2C fast mode Tlow/Thigh = 2
- * @arg I2C_DutyCycle_16_9: I2C fast mode Tlow/Thigh = 16/9
- * @retval None
- */
-void I2C_FastModeDutyCycleConfig(I2C_TypeDef* I2Cx, uint16_t I2C_DutyCycle)
-{
- /* Check the parameters */
- assert_param(IS_I2C_ALL_PERIPH(I2Cx));
- assert_param(IS_I2C_DUTY_CYCLE(I2C_DutyCycle));
- if (I2C_DutyCycle != I2C_DutyCycle_16_9)
- {
- /* I2C fast mode Tlow/Thigh=2 */
- I2Cx->CCR &= I2C_DutyCycle_2;
- }
- else
- {
- /* I2C fast mode Tlow/Thigh=16/9 */
- I2Cx->CCR |= I2C_DutyCycle_16_9;
- }
-}
-
-/**
- * @brief Selects the specified I2C NACK position in master receiver mode.
- * @note This function is useful in I2C Master Receiver mode when the number
- * of data to be received is equal to 2. In this case, this function
- * should be called (with parameter I2C_NACKPosition_Next) before data
- * reception starts,as described in the 2-byte reception procedure
- * recommended in Reference Manual in Section: Master receiver.
- * @param I2Cx: where x can be 1, 2 or 3 to select the I2C peripheral.
- * @param I2C_NACKPosition: specifies the NACK position.
- * This parameter can be one of the following values:
- * @arg I2C_NACKPosition_Next: indicates that the next byte will be the last
- * received byte.
- * @arg I2C_NACKPosition_Current: indicates that current byte is the last
- * received byte.
- *
- * @note This function configures the same bit (POS) as I2C_PECPositionConfig()
- * but is intended to be used in I2C mode while I2C_PECPositionConfig()
- * is intended to used in SMBUS mode.
- *
- * @retval None
- */
-void I2C_NACKPositionConfig(I2C_TypeDef* I2Cx, uint16_t I2C_NACKPosition)
-{
- /* Check the parameters */
- assert_param(IS_I2C_ALL_PERIPH(I2Cx));
- assert_param(IS_I2C_NACK_POSITION(I2C_NACKPosition));
-
- /* Check the input parameter */
- if (I2C_NACKPosition == I2C_NACKPosition_Next)
- {
- /* Next byte in shift register is the last received byte */
- I2Cx->CR1 |= I2C_NACKPosition_Next;
- }
- else
- {
- /* Current byte in shift register is the last received byte */
- I2Cx->CR1 &= I2C_NACKPosition_Current;
- }
-}
-
-/**
- * @brief Drives the SMBusAlert pin high or low for the specified I2C.
- * @param I2Cx: where x can be 1, 2 or 3 to select the I2C peripheral.
- * @param I2C_SMBusAlert: specifies SMBAlert pin level.
- * This parameter can be one of the following values:
- * @arg I2C_SMBusAlert_Low: SMBAlert pin driven low
- * @arg I2C_SMBusAlert_High: SMBAlert pin driven high
- * @retval None
- */
-void I2C_SMBusAlertConfig(I2C_TypeDef* I2Cx, uint16_t I2C_SMBusAlert)
-{
- /* Check the parameters */
- assert_param(IS_I2C_ALL_PERIPH(I2Cx));
- assert_param(IS_I2C_SMBUS_ALERT(I2C_SMBusAlert));
- if (I2C_SMBusAlert == I2C_SMBusAlert_Low)
- {
- /* Drive the SMBusAlert pin Low */
- I2Cx->CR1 |= I2C_SMBusAlert_Low;
- }
- else
- {
- /* Drive the SMBusAlert pin High */
- I2Cx->CR1 &= I2C_SMBusAlert_High;
- }
-}
-
-/**
- * @brief Enables or disables the specified I2C ARP.
- * @param I2Cx: where x can be 1, 2 or 3 to select the I2C peripheral.
- * @param NewState: new state of the I2Cx ARP.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void I2C_ARPCmd(I2C_TypeDef* I2Cx, FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_I2C_ALL_PERIPH(I2Cx));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
- if (NewState != DISABLE)
- {
- /* Enable the selected I2C ARP */
- I2Cx->CR1 |= I2C_CR1_ENARP;
- }
- else
- {
- /* Disable the selected I2C ARP */
- I2Cx->CR1 &= (uint16_t)~((uint16_t)I2C_CR1_ENARP);
- }
-}
-/**
- * @}
- */
-
-/** @defgroup I2C_Group2 Data transfers functions
- * @brief Data transfers functions
- *
-@verbatim
- ===============================================================================
- Data transfers functions
- ===============================================================================
-
-@endverbatim
- * @{
- */
-
-/**
- * @brief Sends a data byte through the I2Cx peripheral.
- * @param I2Cx: where x can be 1, 2 or 3 to select the I2C peripheral.
- * @param Data: Byte to be transmitted..
- * @retval None
- */
-void I2C_SendData(I2C_TypeDef* I2Cx, uint8_t Data)
-{
- /* Check the parameters */
- assert_param(IS_I2C_ALL_PERIPH(I2Cx));
- /* Write in the DR register the data to be sent */
- I2Cx->DR = Data;
-}
-
-/**
- * @brief Returns the most recent received data by the I2Cx peripheral.
- * @param I2Cx: where x can be 1, 2 or 3 to select the I2C peripheral.
- * @retval The value of the received data.
- */
-uint8_t I2C_ReceiveData(I2C_TypeDef* I2Cx)
-{
- /* Check the parameters */
- assert_param(IS_I2C_ALL_PERIPH(I2Cx));
- /* Return the data in the DR register */
- return (uint8_t)I2Cx->DR;
-}
-
-/**
- * @}
- */
-
-/** @defgroup I2C_Group3 PEC management functions
- * @brief PEC management functions
- *
-@verbatim
- ===============================================================================
- PEC management functions
- ===============================================================================
-
-@endverbatim
- * @{
- */
-
-/**
- * @brief Enables or disables the specified I2C PEC transfer.
- * @param I2Cx: where x can be 1, 2 or 3 to select the I2C peripheral.
- * @param NewState: new state of the I2C PEC transmission.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void I2C_TransmitPEC(I2C_TypeDef* I2Cx, FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_I2C_ALL_PERIPH(I2Cx));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
- if (NewState != DISABLE)
- {
- /* Enable the selected I2C PEC transmission */
- I2Cx->CR1 |= I2C_CR1_PEC;
- }
- else
- {
- /* Disable the selected I2C PEC transmission */
- I2Cx->CR1 &= (uint16_t)~((uint16_t)I2C_CR1_PEC);
- }
-}
-
-/**
- * @brief Selects the specified I2C PEC position.
- * @param I2Cx: where x can be 1, 2 or 3 to select the I2C peripheral.
- * @param I2C_PECPosition: specifies the PEC position.
- * This parameter can be one of the following values:
- * @arg I2C_PECPosition_Next: indicates that the next byte is PEC
- * @arg I2C_PECPosition_Current: indicates that current byte is PEC
- *
- * @note This function configures the same bit (POS) as I2C_NACKPositionConfig()
- * but is intended to be used in SMBUS mode while I2C_NACKPositionConfig()
- * is intended to used in I2C mode.
- *
- * @retval None
- */
-void I2C_PECPositionConfig(I2C_TypeDef* I2Cx, uint16_t I2C_PECPosition)
-{
- /* Check the parameters */
- assert_param(IS_I2C_ALL_PERIPH(I2Cx));
- assert_param(IS_I2C_PEC_POSITION(I2C_PECPosition));
- if (I2C_PECPosition == I2C_PECPosition_Next)
- {
- /* Next byte in shift register is PEC */
- I2Cx->CR1 |= I2C_PECPosition_Next;
- }
- else
- {
- /* Current byte in shift register is PEC */
- I2Cx->CR1 &= I2C_PECPosition_Current;
- }
-}
-
-/**
- * @brief Enables or disables the PEC value calculation of the transferred bytes.
- * @param I2Cx: where x can be 1, 2 or 3 to select the I2C peripheral.
- * @param NewState: new state of the I2Cx PEC value calculation.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void I2C_CalculatePEC(I2C_TypeDef* I2Cx, FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_I2C_ALL_PERIPH(I2Cx));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
- if (NewState != DISABLE)
- {
- /* Enable the selected I2C PEC calculation */
- I2Cx->CR1 |= I2C_CR1_ENPEC;
- }
- else
- {
- /* Disable the selected I2C PEC calculation */
- I2Cx->CR1 &= (uint16_t)~((uint16_t)I2C_CR1_ENPEC);
- }
-}
-
-/**
- * @brief Returns the PEC value for the specified I2C.
- * @param I2Cx: where x can be 1, 2 or 3 to select the I2C peripheral.
- * @retval The PEC value.
- */
-uint8_t I2C_GetPEC(I2C_TypeDef* I2Cx)
-{
- /* Check the parameters */
- assert_param(IS_I2C_ALL_PERIPH(I2Cx));
- /* Return the selected I2C PEC value */
- return ((I2Cx->SR2) >> 8);
-}
-
-/**
- * @}
- */
-
-/** @defgroup I2C_Group4 DMA transfers management functions
- * @brief DMA transfers management functions
- *
-@verbatim
- ===============================================================================
- DMA transfers management functions
- ===============================================================================
- This section provides functions allowing to configure the I2C DMA channels
- requests.
-
-@endverbatim
- * @{
- */
-
-/**
- * @brief Enables or disables the specified I2C DMA requests.
- * @param I2Cx: where x can be 1, 2 or 3 to select the I2C peripheral.
- * @param NewState: new state of the I2C DMA transfer.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void I2C_DMACmd(I2C_TypeDef* I2Cx, FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_I2C_ALL_PERIPH(I2Cx));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
- if (NewState != DISABLE)
- {
- /* Enable the selected I2C DMA requests */
- I2Cx->CR2 |= I2C_CR2_DMAEN;
- }
- else
- {
- /* Disable the selected I2C DMA requests */
- I2Cx->CR2 &= (uint16_t)~((uint16_t)I2C_CR2_DMAEN);
- }
-}
-
-/**
- * @brief Specifies that the next DMA transfer is the last one.
- * @param I2Cx: where x can be 1, 2 or 3 to select the I2C peripheral.
- * @param NewState: new state of the I2C DMA last transfer.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void I2C_DMALastTransferCmd(I2C_TypeDef* I2Cx, FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_I2C_ALL_PERIPH(I2Cx));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
- if (NewState != DISABLE)
- {
- /* Next DMA transfer is the last transfer */
- I2Cx->CR2 |= I2C_CR2_LAST;
- }
- else
- {
- /* Next DMA transfer is not the last transfer */
- I2Cx->CR2 &= (uint16_t)~((uint16_t)I2C_CR2_LAST);
- }
-}
-
-/**
- * @}
- */
-
-/** @defgroup I2C_Group5 Interrupts events and flags management functions
- * @brief Interrupts, events and flags management functions
- *
-@verbatim
- ===============================================================================
- Interrupts, events and flags management functions
- ===============================================================================
- This section provides functions allowing to configure the I2C Interrupts
- sources and check or clear the flags or pending bits status.
- The user should identify which mode will be used in his application to manage
- the communication: Polling mode, Interrupt mode or DMA mode.
-
- ===============================================================================
- I2C State Monitoring Functions
- ===============================================================================
- This I2C driver provides three different ways for I2C state monitoring
- depending on the application requirements and constraints:
-
-
- 1. Basic state monitoring (Using I2C_CheckEvent() function)
- -----------------------------------------------------------
- It compares the status registers (SR1 and SR2) content to a given event
- (can be the combination of one or more flags).
- It returns SUCCESS if the current status includes the given flags
- and returns ST_ERROR if one or more flags are missing in the current status.
-
- - When to use
- - This function is suitable for most applications as well as for startup
- activity since the events are fully described in the product reference
- manual (RM0090).
- - It is also suitable for users who need to define their own events.
-
- - Limitations
- - If an error occurs (ie. error flags are set besides to the monitored
- flags), the I2C_CheckEvent() function may return SUCCESS despite
- the communication hold or corrupted real state.
- In this case, it is advised to use error interrupts to monitor
- the error events and handle them in the interrupt IRQ handler.
-
- @note
- For error management, it is advised to use the following functions:
- - I2C_ITConfig() to configure and enable the error interrupts (I2C_IT_ERR).
- - I2Cx_ER_IRQHandler() which is called when the error interrupt occurs.
- Where x is the peripheral instance (I2C1, I2C2 ...)
- - I2C_GetFlagStatus() or I2C_GetITStatus() to be called into the
- I2Cx_ER_IRQHandler() function in order to determine which error occurred.
- - I2C_ClearFlag() or I2C_ClearITPendingBit() and/or I2C_SoftwareResetCmd()
- and/or I2C_GenerateStop() in order to clear the error flag and source
- and return to correct communication status.
-
-
- 2. Advanced state monitoring (Using the function I2C_GetLastEvent())
- --------------------------------------------------------------------
- Using the function I2C_GetLastEvent() which returns the image of both status
- registers in a single word (uint32_t) (Status Register 2 value is shifted left
- by 16 bits and concatenated to Status Register 1).
-
- - When to use
- - This function is suitable for the same applications above but it
- allows to overcome the mentioned limitation of I2C_GetFlagStatus()
- function.
- - The returned value could be compared to events already defined in
- the library (stm32f4xx_i2c.h) or to custom values defined by user.
- This function is suitable when multiple flags are monitored at the
- same time.
- - At the opposite of I2C_CheckEvent() function, this function allows
- user to choose when an event is accepted (when all events flags are
- set and no other flags are set or just when the needed flags are set
- like I2C_CheckEvent() function.
-
- - Limitations
- - User may need to define his own events.
- - Same remark concerning the error management is applicable for this
- function if user decides to check only regular communication flags
- (and ignores error flags).
-
-
- 3. Flag-based state monitoring (Using the function I2C_GetFlagStatus())
- -----------------------------------------------------------------------
-
- Using the function I2C_GetFlagStatus() which simply returns the status of
- one single flag (ie. I2C_FLAG_RXNE ...).
-
- - When to use
- - This function could be used for specific applications or in debug
- phase.
- - It is suitable when only one flag checking is needed (most I2C
- events are monitored through multiple flags).
- - Limitations:
- - When calling this function, the Status register is accessed.
- Some flags are cleared when the status register is accessed.
- So checking the status of one Flag, may clear other ones.
- - Function may need to be called twice or more in order to monitor
- one single event.
-
- For detailed description of Events, please refer to section I2C_Events in
- stm32f4xx_i2c.h file.
-
-@endverbatim
- * @{
- */
-
-/**
- * @brief Reads the specified I2C register and returns its value.
- * @param I2C_Register: specifies the register to read.
- * This parameter can be one of the following values:
- * @arg I2C_Register_CR1: CR1 register.
- * @arg I2C_Register_CR2: CR2 register.
- * @arg I2C_Register_OAR1: OAR1 register.
- * @arg I2C_Register_OAR2: OAR2 register.
- * @arg I2C_Register_DR: DR register.
- * @arg I2C_Register_SR1: SR1 register.
- * @arg I2C_Register_SR2: SR2 register.
- * @arg I2C_Register_CCR: CCR register.
- * @arg I2C_Register_TRISE: TRISE register.
- * @retval The value of the read register.
- */
-uint16_t I2C_ReadRegister(I2C_TypeDef* I2Cx, uint8_t I2C_Register)
-{
- __IO uint32_t tmp = 0;
-
- /* Check the parameters */
- assert_param(IS_I2C_ALL_PERIPH(I2Cx));
- assert_param(IS_I2C_REGISTER(I2C_Register));
-
- tmp = (uint32_t) I2Cx;
- tmp += I2C_Register;
-
- /* Return the selected register value */
- return (*(__IO uint16_t *) tmp);
-}
-
-/**
- * @brief Enables or disables the specified I2C interrupts.
- * @param I2Cx: where x can be 1, 2 or 3 to select the I2C peripheral.
- * @param I2C_IT: specifies the I2C interrupts sources to be enabled or disabled.
- * This parameter can be any combination of the following values:
- * @arg I2C_IT_BUF: Buffer interrupt mask
- * @arg I2C_IT_EVT: Event interrupt mask
- * @arg I2C_IT_ERR: Error interrupt mask
- * @param NewState: new state of the specified I2C interrupts.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void I2C_ITConfig(I2C_TypeDef* I2Cx, uint16_t I2C_IT, FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_I2C_ALL_PERIPH(I2Cx));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
- assert_param(IS_I2C_CONFIG_IT(I2C_IT));
-
- if (NewState != DISABLE)
- {
- /* Enable the selected I2C interrupts */
- I2Cx->CR2 |= I2C_IT;
- }
- else
- {
- /* Disable the selected I2C interrupts */
- I2Cx->CR2 &= (uint16_t)~I2C_IT;
- }
-}
-
-/*
- ===============================================================================
- 1. Basic state monitoring
- ===============================================================================
- */
-
-/**
- * @brief Checks whether the last I2Cx Event is equal to the one passed
- * as parameter.
- * @param I2Cx: where x can be 1, 2 or 3 to select the I2C peripheral.
- * @param I2C_EVENT: specifies the event to be checked.
- * This parameter can be one of the following values:
- * @arg I2C_EVENT_SLAVE_TRANSMITTER_ADDRESS_MATCHED: EV1
- * @arg I2C_EVENT_SLAVE_RECEIVER_ADDRESS_MATCHED: EV1
- * @arg I2C_EVENT_SLAVE_TRANSMITTER_SECONDADDRESS_MATCHED: EV1
- * @arg I2C_EVENT_SLAVE_RECEIVER_SECONDADDRESS_MATCHED: EV1
- * @arg I2C_EVENT_SLAVE_GENERALCALLADDRESS_MATCHED: EV1
- * @arg I2C_EVENT_SLAVE_BYTE_RECEIVED: EV2
- * @arg (I2C_EVENT_SLAVE_BYTE_RECEIVED | I2C_FLAG_DUALF): EV2
- * @arg (I2C_EVENT_SLAVE_BYTE_RECEIVED | I2C_FLAG_GENCALL): EV2
- * @arg I2C_EVENT_SLAVE_BYTE_TRANSMITTED: EV3
- * @arg (I2C_EVENT_SLAVE_BYTE_TRANSMITTED | I2C_FLAG_DUALF): EV3
- * @arg (I2C_EVENT_SLAVE_BYTE_TRANSMITTED | I2C_FLAG_GENCALL): EV3
- * @arg I2C_EVENT_SLAVE_ACK_FAILURE: EV3_2
- * @arg I2C_EVENT_SLAVE_STOP_DETECTED: EV4
- * @arg I2C_EVENT_MASTER_MODE_SELECT: EV5
- * @arg I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED: EV6
- * @arg I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED: EV6
- * @arg I2C_EVENT_MASTER_BYTE_RECEIVED: EV7
- * @arg I2C_EVENT_MASTER_BYTE_TRANSMITTING: EV8
- * @arg I2C_EVENT_MASTER_BYTE_TRANSMITTED: EV8_2
- * @arg I2C_EVENT_MASTER_MODE_ADDRESS10: EV9
- *
- * @note For detailed description of Events, please refer to section I2C_Events
- * in stm32f4xx_i2c.h file.
- *
- * @retval An ErrorStatus enumeration value:
- * - SUCCESS: Last event is equal to the I2C_EVENT
- * - ST_ERROR: Last event is different from the I2C_EVENT
- */
-ErrorStatus I2C_CheckEvent(I2C_TypeDef* I2Cx, uint32_t I2C_EVENT)
-{
- uint32_t lastevent = 0;
- uint32_t flag1 = 0, flag2 = 0;
- ErrorStatus status = ST_ERROR;
-
- /* Check the parameters */
- assert_param(IS_I2C_ALL_PERIPH(I2Cx));
- assert_param(IS_I2C_EVENT(I2C_EVENT));
-
- /* Read the I2Cx status register */
- flag1 = I2Cx->SR1;
- flag2 = I2Cx->SR2;
- flag2 = flag2 << 16;
-
- /* Get the last event value from I2C status register */
- lastevent = (flag1 | flag2) & FLAG_MASK;
-
- /* Check whether the last event contains the I2C_EVENT */
- if ((lastevent & I2C_EVENT) == I2C_EVENT)
- {
- /* SUCCESS: last event is equal to I2C_EVENT */
- status = SUCCESS;
- }
- else
- {
- /* ST_ERROR: last event is different from I2C_EVENT */
- status = ST_ERROR;
- }
- /* Return status */
- return status;
-}
-
-/*
- ===============================================================================
- 2. Advanced state monitoring
- ===============================================================================
- */
-
-/**
- * @brief Returns the last I2Cx Event.
- * @param I2Cx: where x can be 1, 2 or 3 to select the I2C peripheral.
- *
- * @note For detailed description of Events, please refer to section I2C_Events
- * in stm32f4xx_i2c.h file.
- *
- * @retval The last event
- */
-uint32_t I2C_GetLastEvent(I2C_TypeDef* I2Cx)
-{
- uint32_t lastevent = 0;
- uint32_t flag1 = 0, flag2 = 0;
-
- /* Check the parameters */
- assert_param(IS_I2C_ALL_PERIPH(I2Cx));
-
- /* Read the I2Cx status register */
- flag1 = I2Cx->SR1;
- flag2 = I2Cx->SR2;
- flag2 = flag2 << 16;
-
- /* Get the last event value from I2C status register */
- lastevent = (flag1 | flag2) & FLAG_MASK;
-
- /* Return status */
- return lastevent;
-}
-
-/*
- ===============================================================================
- 3. Flag-based state monitoring
- ===============================================================================
- */
-
-/**
- * @brief Checks whether the specified I2C flag is set or not.
- * @param I2Cx: where x can be 1, 2 or 3 to select the I2C peripheral.
- * @param I2C_FLAG: specifies the flag to check.
- * This parameter can be one of the following values:
- * @arg I2C_FLAG_DUALF: Dual flag (Slave mode)
- * @arg I2C_FLAG_SMBHOST: SMBus host header (Slave mode)
- * @arg I2C_FLAG_SMBDEFAULT: SMBus default header (Slave mode)
- * @arg I2C_FLAG_GENCALL: General call header flag (Slave mode)
- * @arg I2C_FLAG_TRA: Transmitter/Receiver flag
- * @arg I2C_FLAG_BUSY: Bus busy flag
- * @arg I2C_FLAG_MSL: Master/Slave flag
- * @arg I2C_FLAG_SMBALERT: SMBus Alert flag
- * @arg I2C_FLAG_TIMEOUT: Timeout or Tlow error flag
- * @arg I2C_FLAG_PECERR: PEC error in reception flag
- * @arg I2C_FLAG_OVR: Overrun/Underrun flag (Slave mode)
- * @arg I2C_FLAG_AF: Acknowledge failure flag
- * @arg I2C_FLAG_ARLO: Arbitration lost flag (Master mode)
- * @arg I2C_FLAG_BERR: Bus error flag
- * @arg I2C_FLAG_TXE: Data register empty flag (Transmitter)
- * @arg I2C_FLAG_RXNE: Data register not empty (Receiver) flag
- * @arg I2C_FLAG_STOPF: Stop detection flag (Slave mode)
- * @arg I2C_FLAG_ADD10: 10-bit header sent flag (Master mode)
- * @arg I2C_FLAG_BTF: Byte transfer finished flag
- * @arg I2C_FLAG_ADDR: Address sent flag (Master mode) "ADSL"
- * Address matched flag (Slave mode)"ENDAD"
- * @arg I2C_FLAG_SB: Start bit flag (Master mode)
- * @retval The new state of I2C_FLAG (SET or RESET).
- */
-FlagStatus I2C_GetFlagStatus(I2C_TypeDef* I2Cx, uint32_t I2C_FLAG)
-{
- FlagStatus bitstatus = RESET;
- __IO uint32_t i2creg = 0, i2cxbase = 0;
-
- /* Check the parameters */
- assert_param(IS_I2C_ALL_PERIPH(I2Cx));
- assert_param(IS_I2C_GET_FLAG(I2C_FLAG));
-
- /* Get the I2Cx peripheral base address */
- i2cxbase = (uint32_t)I2Cx;
-
- /* Read flag register index */
- i2creg = I2C_FLAG >> 28;
-
- /* Get bit[23:0] of the flag */
- I2C_FLAG &= FLAG_MASK;
-
- if(i2creg != 0)
- {
- /* Get the I2Cx SR1 register address */
- i2cxbase += 0x14;
- }
- else
- {
- /* Flag in I2Cx SR2 Register */
- I2C_FLAG = (uint32_t)(I2C_FLAG >> 16);
- /* Get the I2Cx SR2 register address */
- i2cxbase += 0x18;
- }
-
- if(((*(__IO uint32_t *)i2cxbase) & I2C_FLAG) != (uint32_t)RESET)
- {
- /* I2C_FLAG is set */
- bitstatus = SET;
- }
- else
- {
- /* I2C_FLAG is reset */
- bitstatus = RESET;
- }
-
- /* Return the I2C_FLAG status */
- return bitstatus;
-}
-
-/**
- * @brief Clears the I2Cx's pending flags.
- * @param I2Cx: where x can be 1, 2 or 3 to select the I2C peripheral.
- * @param I2C_FLAG: specifies the flag to clear.
- * This parameter can be any combination of the following values:
- * @arg I2C_FLAG_SMBALERT: SMBus Alert flag
- * @arg I2C_FLAG_TIMEOUT: Timeout or Tlow error flag
- * @arg I2C_FLAG_PECERR: PEC error in reception flag
- * @arg I2C_FLAG_OVR: Overrun/Underrun flag (Slave mode)
- * @arg I2C_FLAG_AF: Acknowledge failure flag
- * @arg I2C_FLAG_ARLO: Arbitration lost flag (Master mode)
- * @arg I2C_FLAG_BERR: Bus error flag
- *
- * @note STOPF (STOP detection) is cleared by software sequence: a read operation
- * to I2C_SR1 register (I2C_GetFlagStatus()) followed by a write operation
- * to I2C_CR1 register (I2C_Cmd() to re-enable the I2C peripheral).
- * @note ADD10 (10-bit header sent) is cleared by software sequence: a read
- * operation to I2C_SR1 (I2C_GetFlagStatus()) followed by writing the
- * second byte of the address in DR register.
- * @note BTF (Byte Transfer Finished) is cleared by software sequence: a read
- * operation to I2C_SR1 register (I2C_GetFlagStatus()) followed by a
- * read/write to I2C_DR register (I2C_SendData()).
- * @note ADDR (Address sent) is cleared by software sequence: a read operation to
- * I2C_SR1 register (I2C_GetFlagStatus()) followed by a read operation to
- * I2C_SR2 register ((void)(I2Cx->SR2)).
- * @note SB (Start Bit) is cleared software sequence: a read operation to I2C_SR1
- * register (I2C_GetFlagStatus()) followed by a write operation to I2C_DR
- * register (I2C_SendData()).
- *
- * @retval None
- */
-void I2C_ClearFlag(I2C_TypeDef* I2Cx, uint32_t I2C_FLAG)
-{
- uint32_t flagpos = 0;
- /* Check the parameters */
- assert_param(IS_I2C_ALL_PERIPH(I2Cx));
- assert_param(IS_I2C_CLEAR_FLAG(I2C_FLAG));
- /* Get the I2C flag position */
- flagpos = I2C_FLAG & FLAG_MASK;
- /* Clear the selected I2C flag */
- I2Cx->SR1 = (uint16_t)~flagpos;
-}
-
-/**
- * @brief Checks whether the specified I2C interrupt has occurred or not.
- * @param I2Cx: where x can be 1, 2 or 3 to select the I2C peripheral.
- * @param I2C_IT: specifies the interrupt source to check.
- * This parameter can be one of the following values:
- * @arg I2C_IT_SMBALERT: SMBus Alert flag
- * @arg I2C_IT_TIMEOUT: Timeout or Tlow error flag
- * @arg I2C_IT_PECERR: PEC error in reception flag
- * @arg I2C_IT_OVR: Overrun/Underrun flag (Slave mode)
- * @arg I2C_IT_AF: Acknowledge failure flag
- * @arg I2C_IT_ARLO: Arbitration lost flag (Master mode)
- * @arg I2C_IT_BERR: Bus error flag
- * @arg I2C_IT_TXE: Data register empty flag (Transmitter)
- * @arg I2C_IT_RXNE: Data register not empty (Receiver) flag
- * @arg I2C_IT_STOPF: Stop detection flag (Slave mode)
- * @arg I2C_IT_ADD10: 10-bit header sent flag (Master mode)
- * @arg I2C_IT_BTF: Byte transfer finished flag
- * @arg I2C_IT_ADDR: Address sent flag (Master mode) "ADSL"
- * Address matched flag (Slave mode)"ENDAD"
- * @arg I2C_IT_SB: Start bit flag (Master mode)
- * @retval The new state of I2C_IT (SET or RESET).
- */
-ITStatus I2C_GetITStatus(I2C_TypeDef* I2Cx, uint32_t I2C_IT)
-{
- ITStatus bitstatus = RESET;
- uint32_t enablestatus = 0;
-
- /* Check the parameters */
- assert_param(IS_I2C_ALL_PERIPH(I2Cx));
- assert_param(IS_I2C_GET_IT(I2C_IT));
-
- /* Check if the interrupt source is enabled or not */
- enablestatus = (uint32_t)(((I2C_IT & ITEN_MASK) >> 16) & (I2Cx->CR2)) ;
-
- /* Get bit[23:0] of the flag */
- I2C_IT &= FLAG_MASK;
-
- /* Check the status of the specified I2C flag */
- if (((I2Cx->SR1 & I2C_IT) != (uint32_t)RESET) && enablestatus)
- {
- /* I2C_IT is set */
- bitstatus = SET;
- }
- else
- {
- /* I2C_IT is reset */
- bitstatus = RESET;
- }
- /* Return the I2C_IT status */
- return bitstatus;
-}
-
-/**
- * @brief Clears the I2Cx's interrupt pending bits.
- * @param I2Cx: where x can be 1, 2 or 3 to select the I2C peripheral.
- * @param I2C_IT: specifies the interrupt pending bit to clear.
- * This parameter can be any combination of the following values:
- * @arg I2C_IT_SMBALERT: SMBus Alert interrupt
- * @arg I2C_IT_TIMEOUT: Timeout or Tlow error interrupt
- * @arg I2C_IT_PECERR: PEC error in reception interrupt
- * @arg I2C_IT_OVR: Overrun/Underrun interrupt (Slave mode)
- * @arg I2C_IT_AF: Acknowledge failure interrupt
- * @arg I2C_IT_ARLO: Arbitration lost interrupt (Master mode)
- * @arg I2C_IT_BERR: Bus error interrupt
- *
- * @note STOPF (STOP detection) is cleared by software sequence: a read operation
- * to I2C_SR1 register (I2C_GetITStatus()) followed by a write operation to
- * I2C_CR1 register (I2C_Cmd() to re-enable the I2C peripheral).
- * @note ADD10 (10-bit header sent) is cleared by software sequence: a read
- * operation to I2C_SR1 (I2C_GetITStatus()) followed by writing the second
- * byte of the address in I2C_DR register.
- * @note BTF (Byte Transfer Finished) is cleared by software sequence: a read
- * operation to I2C_SR1 register (I2C_GetITStatus()) followed by a
- * read/write to I2C_DR register (I2C_SendData()).
- * @note ADDR (Address sent) is cleared by software sequence: a read operation to
- * I2C_SR1 register (I2C_GetITStatus()) followed by a read operation to
- * I2C_SR2 register ((void)(I2Cx->SR2)).
- * @note SB (Start Bit) is cleared by software sequence: a read operation to
- * I2C_SR1 register (I2C_GetITStatus()) followed by a write operation to
- * I2C_DR register (I2C_SendData()).
- * @retval None
- */
-void I2C_ClearITPendingBit(I2C_TypeDef* I2Cx, uint32_t I2C_IT)
-{
- uint32_t flagpos = 0;
- /* Check the parameters */
- assert_param(IS_I2C_ALL_PERIPH(I2Cx));
- assert_param(IS_I2C_CLEAR_IT(I2C_IT));
-
- /* Get the I2C flag position */
- flagpos = I2C_IT & FLAG_MASK;
-
- /* Clear the selected I2C flag */
- I2Cx->SR1 = (uint16_t)~flagpos;
-}
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-
-/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/lcd/Kconfig b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/lcd/Kconfig
deleted file mode 100644
index 8b1378917..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/lcd/Kconfig
+++ /dev/null
@@ -1 +0,0 @@
-
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/lcd/Makefile b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/lcd/Makefile
deleted file mode 100644
index 91904d501..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/lcd/Makefile
+++ /dev/null
@@ -1,4 +0,0 @@
-SRC_FILES := hardware_fsmc.c
-
-
-include $(KERNEL_ROOT)/compiler.mk
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/lcd/hardware_fsmc.c b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/lcd/hardware_fsmc.c
deleted file mode 100644
index f1dc4a869..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/lcd/hardware_fsmc.c
+++ /dev/null
@@ -1,1002 +0,0 @@
-/**
- ******************************************************************************
- * @file stm32f4xx_fsmc.c
- * @author MCD Application Team
- * @version V1.0.0
- * @date 30-September-2011
- * @brief This file provides firmware functions to manage the following
- * functionalities of the FSMC peripheral:
- * - Interface with SRAM, PSRAM, NOR and OneNAND memories
- * - Interface with NAND memories
- * - Interface with 16-bit PC Card compatible memories
- * - Interrupts and flags management
- *
- ******************************************************************************
-
- * @attention
- *
- * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
- * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
- * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
- * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
- * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
- * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
- *
- * © COPYRIGHT 2011 STMicroelectronics
- ******************************************************************************
- */
-
-/**
-* @file: hardware_fsmc.c
-* @brief: support hardware fsmc function
-* @version: 1.0
-* @author: AIIT XUOS Lab
-* @date: 2021/4/25
-*/
-
-/*************************************************
-File name: hardware_fsmc.c
-Description: support hardware fsmc function
-Others:
-History:
-1. Date: 2021-04-25
-Author: AIIT XUOS Lab
-Modification:
-1. rename stm32f4xx_fsmc.c for XiUOS
-*************************************************/
-
-/* Includes ------------------------------------------------------------------*/
-#include
-#include
-#include
-
-/** @addtogroup STM32F4xx_StdPeriph_Driver
- * @{
- */
-
-/** @defgroup FSMC
- * @brief FSMC driver modules
- * @{
- */
-
-/* Private typedef -----------------------------------------------------------*/
-/* Private define ------------------------------------------------------------*/
-
-/* --------------------- FSMC registers bit mask ---------------------------- */
-/* FSMC BCRx Mask */
-#define BCR_MBKEN_SET ((uint32_t)0x00000001)
-#define BCR_MBKEN_RESET ((uint32_t)0x000FFFFE)
-#define BCR_FACCEN_SET ((uint32_t)0x00000040)
-
-/* FSMC PCRx Mask */
-#define PCR_PBKEN_SET ((uint32_t)0x00000004)
-#define PCR_PBKEN_RESET ((uint32_t)0x000FFFFB)
-#define PCR_ECCEN_SET ((uint32_t)0x00000040)
-#define PCR_ECCEN_RESET ((uint32_t)0x000FFFBF)
-#define PCR_MEMORYTYPE_NAND ((uint32_t)0x00000008)
-
-/* Private macro -------------------------------------------------------------*/
-/* Private variables ---------------------------------------------------------*/
-/* Private function prototypes -----------------------------------------------*/
-/* Private functions ---------------------------------------------------------*/
-
-/** @defgroup FSMC_Private_Functions
- * @{
- */
-
-/** @defgroup FSMC_Group1 NOR/SRAM Controller functions
- * @brief NOR/SRAM Controller functions
- *
-@verbatim
- ===============================================================================
- NOR/SRAM Controller functions
- ===============================================================================
-
- The following sequence should be followed to configure the FSMC to interface with
- SRAM, PSRAM, NOR or OneNAND memory connected to the NOR/SRAM Bank:
-
- 1. Enable the clock for the FSMC and associated GPIOs using the following functions:
- RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE);
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOx, ENABLE);
-
- 2. FSMC pins configuration
- - Connect the involved FSMC pins to AF12 using the following function
- GPIO_PinAFConfig(GPIOx, GPIO_PinSourcex, GPIO_AF_FSMC);
- - Configure these FSMC pins in alternate function mode by calling the function
- GPIO_Init();
-
- 3. Declare a FSMC_NORSRAMInitTypeDef structure, for example:
- FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
- and fill the FSMC_NORSRAMInitStructure variable with the allowed values of
- the structure member.
-
- 4. Initialize the NOR/SRAM Controller by calling the function
- FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
-
- 5. Then enable the NOR/SRAM Bank, for example:
- FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM2, ENABLE);
-
- 6. At this stage you can read/write from/to the memory connected to the NOR/SRAM Bank.
-
-@endverbatim
- * @{
- */
-
-/**
- * @brief Deinitializes the FSMC NOR/SRAM Banks registers to their default
- * reset values.
- * @param FSMC_Bank: specifies the FSMC Bank to be used
- * This parameter can be one of the following values:
- * @arg FSMC_Bank1_NORSRAM1: FSMC Bank1 NOR/SRAM1
- * @arg FSMC_Bank1_NORSRAM2: FSMC Bank1 NOR/SRAM2
- * @arg FSMC_Bank1_NORSRAM3: FSMC Bank1 NOR/SRAM3
- * @arg FSMC_Bank1_NORSRAM4: FSMC Bank1 NOR/SRAM4
- * @retval None
- */
-void FSMC_NORSRAMDeInit(uint32_t FSMC_Bank)
-{
- /* Check the parameter */
- assert_param(IS_FSMC_NORSRAM_BANK(FSMC_Bank));
-
- /* FSMC_Bank1_NORSRAM1 */
- if(FSMC_Bank == FSMC_Bank1_NORSRAM1)
- {
- FSMC_Bank1->BTCR[FSMC_Bank] = 0x000030DB;
- }
- /* FSMC_Bank1_NORSRAM2, FSMC_Bank1_NORSRAM3 or FSMC_Bank1_NORSRAM4 */
- else
- {
- FSMC_Bank1->BTCR[FSMC_Bank] = 0x000030D2;
- }
- FSMC_Bank1->BTCR[FSMC_Bank + 1] = 0x0FFFFFFF;
- FSMC_Bank1E->BWTR[FSMC_Bank] = 0x0FFFFFFF;
-}
-
-/**
- * @brief Initializes the FSMC NOR/SRAM Banks according to the specified
- * parameters in the FSMC_NORSRAMInitStruct.
- * @param FSMC_NORSRAMInitStruct : pointer to a FSMC_NORSRAMInitTypeDef structure
- * that contains the configuration information for the FSMC NOR/SRAM
- * specified Banks.
- * @retval None
- */
-void FSMC_NORSRAMInit(FSMC_NORSRAMInitTypeDef* FSMC_NORSRAMInitStruct)
-{
- /* Check the parameters */
- assert_param(IS_FSMC_NORSRAM_BANK(FSMC_NORSRAMInitStruct->FSMC_Bank));
- assert_param(IS_FSMC_MUX(FSMC_NORSRAMInitStruct->FSMC_DataAddressMux));
- assert_param(IS_FSMC_MEMORY(FSMC_NORSRAMInitStruct->FSMC_MemoryType));
- assert_param(IS_FSMC_MEMORY_WIDTH(FSMC_NORSRAMInitStruct->FSMC_MemoryDataWidth));
- assert_param(IS_FSMC_BURSTMODE(FSMC_NORSRAMInitStruct->FSMC_BurstAccessMode));
- assert_param(IS_FSMC_ASYNWAIT(FSMC_NORSRAMInitStruct->FSMC_AsynchronousWait));
- assert_param(IS_FSMC_WAIT_POLARITY(FSMC_NORSRAMInitStruct->FSMC_WaitSignalPolarity));
- assert_param(IS_FSMC_WRAP_MODE(FSMC_NORSRAMInitStruct->FSMC_WrapMode));
- assert_param(IS_FSMC_WAIT_SIGNAL_ACTIVE(FSMC_NORSRAMInitStruct->FSMC_WaitSignalActive));
- assert_param(IS_FSMC_WRITE_OPERATION(FSMC_NORSRAMInitStruct->FSMC_WriteOperation));
- assert_param(IS_FSMC_WAITE_SIGNAL(FSMC_NORSRAMInitStruct->FSMC_WaitSignal));
- assert_param(IS_FSMC_EXTENDED_MODE(FSMC_NORSRAMInitStruct->FSMC_ExtendedMode));
- assert_param(IS_FSMC_WRITE_BURST(FSMC_NORSRAMInitStruct->FSMC_WriteBurst));
- assert_param(IS_FSMC_ADDRESS_SETUP_TIME(FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_AddressSetupTime));
- assert_param(IS_FSMC_ADDRESS_HOLD_TIME(FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_AddressHoldTime));
- assert_param(IS_FSMC_DATASETUP_TIME(FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_DataSetupTime));
- assert_param(IS_FSMC_TURNAROUND_TIME(FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_BusTurnAroundDuration));
- assert_param(IS_FSMC_CLK_DIV(FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_CLKDivision));
- assert_param(IS_FSMC_DATA_LATENCY(FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_DataLatency));
- assert_param(IS_FSMC_ACCESS_MODE(FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_AccessMode));
-
- /* Bank1 NOR/SRAM control register configuration */
- FSMC_Bank1->BTCR[FSMC_NORSRAMInitStruct->FSMC_Bank] =
- (uint32_t)FSMC_NORSRAMInitStruct->FSMC_DataAddressMux |
- FSMC_NORSRAMInitStruct->FSMC_MemoryType |
- FSMC_NORSRAMInitStruct->FSMC_MemoryDataWidth |
- FSMC_NORSRAMInitStruct->FSMC_BurstAccessMode |
- FSMC_NORSRAMInitStruct->FSMC_AsynchronousWait |
- FSMC_NORSRAMInitStruct->FSMC_WaitSignalPolarity |
- FSMC_NORSRAMInitStruct->FSMC_WrapMode |
- FSMC_NORSRAMInitStruct->FSMC_WaitSignalActive |
- FSMC_NORSRAMInitStruct->FSMC_WriteOperation |
- FSMC_NORSRAMInitStruct->FSMC_WaitSignal |
- FSMC_NORSRAMInitStruct->FSMC_ExtendedMode |
- FSMC_NORSRAMInitStruct->FSMC_WriteBurst;
- if(FSMC_NORSRAMInitStruct->FSMC_MemoryType == FSMC_MemoryType_NOR)
- {
- FSMC_Bank1->BTCR[FSMC_NORSRAMInitStruct->FSMC_Bank] |= (uint32_t)BCR_FACCEN_SET;
- }
- /* Bank1 NOR/SRAM timing register configuration */
- FSMC_Bank1->BTCR[FSMC_NORSRAMInitStruct->FSMC_Bank+1] =
- (uint32_t)FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_AddressSetupTime |
- (FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_AddressHoldTime << 4) |
- (FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_DataSetupTime << 8) |
- (FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_BusTurnAroundDuration << 16) |
- (FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_CLKDivision << 20) |
- (FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_DataLatency << 24) |
- FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_AccessMode;
-
-
- /* Bank1 NOR/SRAM timing register for write configuration, if extended mode is used */
- if(FSMC_NORSRAMInitStruct->FSMC_ExtendedMode == FSMC_ExtendedMode_Enable)
- {
- assert_param(IS_FSMC_ADDRESS_SETUP_TIME(FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_AddressSetupTime));
- assert_param(IS_FSMC_ADDRESS_HOLD_TIME(FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_AddressHoldTime));
- assert_param(IS_FSMC_DATASETUP_TIME(FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_DataSetupTime));
- assert_param(IS_FSMC_CLK_DIV(FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_CLKDivision));
- assert_param(IS_FSMC_DATA_LATENCY(FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_DataLatency));
- assert_param(IS_FSMC_ACCESS_MODE(FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_AccessMode));
- FSMC_Bank1E->BWTR[FSMC_NORSRAMInitStruct->FSMC_Bank] =
- (uint32_t)FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_AddressSetupTime |
- (FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_AddressHoldTime << 4 )|
- (FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_DataSetupTime << 8) |
- (FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_CLKDivision << 20) |
- (FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_DataLatency << 24) |
- FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_AccessMode;
- }
- else
- {
- FSMC_Bank1E->BWTR[FSMC_NORSRAMInitStruct->FSMC_Bank] = 0x0FFFFFFF;
- }
-}
-
-/**
- * @brief Fills each FSMC_NORSRAMInitStruct member with its default value.
- * @param FSMC_NORSRAMInitStruct: pointer to a FSMC_NORSRAMInitTypeDef structure
- * which will be initialized.
- * @retval None
- */
-void FSMC_NORSRAMStructInit(FSMC_NORSRAMInitTypeDef* FSMC_NORSRAMInitStruct)
-{
- /* Reset NOR/SRAM Init structure parameters values */
- FSMC_NORSRAMInitStruct->FSMC_Bank = FSMC_Bank1_NORSRAM1;
- FSMC_NORSRAMInitStruct->FSMC_DataAddressMux = FSMC_DataAddressMux_Enable;
- FSMC_NORSRAMInitStruct->FSMC_MemoryType = FSMC_MemoryType_SRAM;
- FSMC_NORSRAMInitStruct->FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_8b;
- FSMC_NORSRAMInitStruct->FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
- FSMC_NORSRAMInitStruct->FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable;
- FSMC_NORSRAMInitStruct->FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
- FSMC_NORSRAMInitStruct->FSMC_WrapMode = FSMC_WrapMode_Disable;
- FSMC_NORSRAMInitStruct->FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
- FSMC_NORSRAMInitStruct->FSMC_WriteOperation = FSMC_WriteOperation_Enable;
- FSMC_NORSRAMInitStruct->FSMC_WaitSignal = FSMC_WaitSignal_Enable;
- FSMC_NORSRAMInitStruct->FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
- FSMC_NORSRAMInitStruct->FSMC_WriteBurst = FSMC_WriteBurst_Disable;
- FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_AddressSetupTime = 0xF;
- FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_AddressHoldTime = 0xF;
- FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_DataSetupTime = 0xFF;
- FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_BusTurnAroundDuration = 0xF;
- FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_CLKDivision = 0xF;
- FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_DataLatency = 0xF;
- FSMC_NORSRAMInitStruct->FSMC_ReadWriteTimingStruct->FSMC_AccessMode = FSMC_AccessMode_A;
- FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_AddressSetupTime = 0xF;
- FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_AddressHoldTime = 0xF;
- FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_DataSetupTime = 0xFF;
- FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_BusTurnAroundDuration = 0xF;
- FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_CLKDivision = 0xF;
- FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_DataLatency = 0xF;
- FSMC_NORSRAMInitStruct->FSMC_WriteTimingStruct->FSMC_AccessMode = FSMC_AccessMode_A;
-}
-
-/**
- * @brief Enables or disables the specified NOR/SRAM Memory Bank.
- * @param FSMC_Bank: specifies the FSMC Bank to be used
- * This parameter can be one of the following values:
- * @arg FSMC_Bank1_NORSRAM1: FSMC Bank1 NOR/SRAM1
- * @arg FSMC_Bank1_NORSRAM2: FSMC Bank1 NOR/SRAM2
- * @arg FSMC_Bank1_NORSRAM3: FSMC Bank1 NOR/SRAM3
- * @arg FSMC_Bank1_NORSRAM4: FSMC Bank1 NOR/SRAM4
- * @param NewState: new state of the FSMC_Bank. This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void FSMC_NORSRAMCmd(uint32_t FSMC_Bank, FunctionalState NewState)
-{
- assert_param(IS_FSMC_NORSRAM_BANK(FSMC_Bank));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- if (NewState != DISABLE)
- {
- /* Enable the selected NOR/SRAM Bank by setting the PBKEN bit in the BCRx register */
- FSMC_Bank1->BTCR[FSMC_Bank] |= BCR_MBKEN_SET;
- }
- else
- {
- /* Disable the selected NOR/SRAM Bank by clearing the PBKEN bit in the BCRx register */
- FSMC_Bank1->BTCR[FSMC_Bank] &= BCR_MBKEN_RESET;
- }
-}
-/**
- * @}
- */
-
-/** @defgroup FSMC_Group2 NAND Controller functions
- * @brief NAND Controller functions
- *
-@verbatim
- ===============================================================================
- NAND Controller functions
- ===============================================================================
-
- The following sequence should be followed to configure the FSMC to interface with
- 8-bit or 16-bit NAND memory connected to the NAND Bank:
-
- 1. Enable the clock for the FSMC and associated GPIOs using the following functions:
- RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE);
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOx, ENABLE);
-
- 2. FSMC pins configuration
- - Connect the involved FSMC pins to AF12 using the following function
- GPIO_PinAFConfig(GPIOx, GPIO_PinSourcex, GPIO_AF_FSMC);
- - Configure these FSMC pins in alternate function mode by calling the function
- GPIO_Init();
-
- 3. Declare a FSMC_NANDInitTypeDef structure, for example:
- FSMC_NANDInitTypeDef FSMC_NANDInitStructure;
- and fill the FSMC_NANDInitStructure variable with the allowed values of
- the structure member.
-
- 4. Initialize the NAND Controller by calling the function
- FSMC_NANDInit(&FSMC_NANDInitStructure);
-
- 5. Then enable the NAND Bank, for example:
- FSMC_NANDCmd(FSMC_Bank3_NAND, ENABLE);
-
- 6. At this stage you can read/write from/to the memory connected to the NAND Bank.
-
-@note To enable the Error Correction Code (ECC), you have to use the function
- FSMC_NANDECCCmd(FSMC_Bank3_NAND, ENABLE);
- and to get the current ECC value you have to use the function
- ECCval = FSMC_GetECC(FSMC_Bank3_NAND);
-
-@endverbatim
- * @{
- */
-
-/**
- * @brief Deinitializes the FSMC NAND Banks registers to their default reset values.
- * @param FSMC_Bank: specifies the FSMC Bank to be used
- * This parameter can be one of the following values:
- * @arg FSMC_Bank2_NAND: FSMC Bank2 NAND
- * @arg FSMC_Bank3_NAND: FSMC Bank3 NAND
- * @retval None
- */
-void FSMC_NANDDeInit(uint32_t FSMC_Bank)
-{
- /* Check the parameter */
- assert_param(IS_FSMC_NAND_BANK(FSMC_Bank));
-
- if(FSMC_Bank == FSMC_Bank2_NAND)
- {
- /* Set the FSMC_Bank2 registers to their reset values */
- FSMC_Bank2->PCR2 = 0x00000018;
- FSMC_Bank2->SR2 = 0x00000040;
- FSMC_Bank2->PMEM2 = 0xFCFCFCFC;
- FSMC_Bank2->PATT2 = 0xFCFCFCFC;
- }
- /* FSMC_Bank3_NAND */
- else
- {
- /* Set the FSMC_Bank3 registers to their reset values */
- FSMC_Bank3->PCR3 = 0x00000018;
- FSMC_Bank3->SR3 = 0x00000040;
- FSMC_Bank3->PMEM3 = 0xFCFCFCFC;
- FSMC_Bank3->PATT3 = 0xFCFCFCFC;
- }
-}
-
-/**
- * @brief Initializes the FSMC NAND Banks according to the specified parameters
- * in the FSMC_NANDInitStruct.
- * @param FSMC_NANDInitStruct : pointer to a FSMC_NANDInitTypeDef structure that
- * contains the configuration information for the FSMC NAND specified Banks.
- * @retval None
- */
-void FSMC_NANDInit(FSMC_NANDInitTypeDef* FSMC_NANDInitStruct)
-{
- uint32_t tmppcr = 0x00000000, tmppmem = 0x00000000, tmppatt = 0x00000000;
-
- /* Check the parameters */
- assert_param( IS_FSMC_NAND_BANK(FSMC_NANDInitStruct->FSMC_Bank));
- assert_param( IS_FSMC_WAIT_FEATURE(FSMC_NANDInitStruct->FSMC_Waitfeature));
- assert_param( IS_FSMC_MEMORY_WIDTH(FSMC_NANDInitStruct->FSMC_MemoryDataWidth));
- assert_param( IS_FSMC_ECC_STATE(FSMC_NANDInitStruct->FSMC_ECC));
- assert_param( IS_FSMC_ECCPAGE_SIZE(FSMC_NANDInitStruct->FSMC_ECCPageSize));
- assert_param( IS_FSMC_TCLR_TIME(FSMC_NANDInitStruct->FSMC_TCLRSetupTime));
- assert_param( IS_FSMC_TAR_TIME(FSMC_NANDInitStruct->FSMC_TARSetupTime));
- assert_param(IS_FSMC_SETUP_TIME(FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_SetupTime));
- assert_param(IS_FSMC_WAIT_TIME(FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_WaitSetupTime));
- assert_param(IS_FSMC_HOLD_TIME(FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HoldSetupTime));
- assert_param(IS_FSMC_HIZ_TIME(FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HiZSetupTime));
- assert_param(IS_FSMC_SETUP_TIME(FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_SetupTime));
- assert_param(IS_FSMC_WAIT_TIME(FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_WaitSetupTime));
- assert_param(IS_FSMC_HOLD_TIME(FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HoldSetupTime));
- assert_param(IS_FSMC_HIZ_TIME(FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HiZSetupTime));
-
- /* Set the tmppcr value according to FSMC_NANDInitStruct parameters */
- tmppcr = (uint32_t)FSMC_NANDInitStruct->FSMC_Waitfeature |
- PCR_MEMORYTYPE_NAND |
- FSMC_NANDInitStruct->FSMC_MemoryDataWidth |
- FSMC_NANDInitStruct->FSMC_ECC |
- FSMC_NANDInitStruct->FSMC_ECCPageSize |
- (FSMC_NANDInitStruct->FSMC_TCLRSetupTime << 9 )|
- (FSMC_NANDInitStruct->FSMC_TARSetupTime << 13);
-
- /* Set tmppmem value according to FSMC_CommonSpaceTimingStructure parameters */
- tmppmem = (uint32_t)FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_SetupTime |
- (FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_WaitSetupTime << 8) |
- (FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HoldSetupTime << 16)|
- (FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HiZSetupTime << 24);
-
- /* Set tmppatt value according to FSMC_AttributeSpaceTimingStructure parameters */
- tmppatt = (uint32_t)FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_SetupTime |
- (FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_WaitSetupTime << 8) |
- (FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HoldSetupTime << 16)|
- (FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HiZSetupTime << 24);
-
- if(FSMC_NANDInitStruct->FSMC_Bank == FSMC_Bank2_NAND)
- {
- /* FSMC_Bank2_NAND registers configuration */
- FSMC_Bank2->PCR2 = tmppcr;
- FSMC_Bank2->PMEM2 = tmppmem;
- FSMC_Bank2->PATT2 = tmppatt;
- }
- else
- {
- /* FSMC_Bank3_NAND registers configuration */
- FSMC_Bank3->PCR3 = tmppcr;
- FSMC_Bank3->PMEM3 = tmppmem;
- FSMC_Bank3->PATT3 = tmppatt;
- }
-}
-
-
-/**
- * @brief Fills each FSMC_NANDInitStruct member with its default value.
- * @param FSMC_NANDInitStruct: pointer to a FSMC_NANDInitTypeDef structure which
- * will be initialized.
- * @retval None
- */
-void FSMC_NANDStructInit(FSMC_NANDInitTypeDef* FSMC_NANDInitStruct)
-{
- /* Reset NAND Init structure parameters values */
- FSMC_NANDInitStruct->FSMC_Bank = FSMC_Bank2_NAND;
- FSMC_NANDInitStruct->FSMC_Waitfeature = FSMC_Waitfeature_Disable;
- FSMC_NANDInitStruct->FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_8b;
- FSMC_NANDInitStruct->FSMC_ECC = FSMC_ECC_Disable;
- FSMC_NANDInitStruct->FSMC_ECCPageSize = FSMC_ECCPageSize_256Bytes;
- FSMC_NANDInitStruct->FSMC_TCLRSetupTime = 0x0;
- FSMC_NANDInitStruct->FSMC_TARSetupTime = 0x0;
- FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_SetupTime = 0xFC;
- FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_WaitSetupTime = 0xFC;
- FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HoldSetupTime = 0xFC;
- FSMC_NANDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HiZSetupTime = 0xFC;
- FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_SetupTime = 0xFC;
- FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_WaitSetupTime = 0xFC;
- FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HoldSetupTime = 0xFC;
- FSMC_NANDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HiZSetupTime = 0xFC;
-}
-
-/**
- * @brief Enables or disables the specified NAND Memory Bank.
- * @param FSMC_Bank: specifies the FSMC Bank to be used
- * This parameter can be one of the following values:
- * @arg FSMC_Bank2_NAND: FSMC Bank2 NAND
- * @arg FSMC_Bank3_NAND: FSMC Bank3 NAND
- * @param NewState: new state of the FSMC_Bank. This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void FSMC_NANDCmd(uint32_t FSMC_Bank, FunctionalState NewState)
-{
- assert_param(IS_FSMC_NAND_BANK(FSMC_Bank));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- if (NewState != DISABLE)
- {
- /* Enable the selected NAND Bank by setting the PBKEN bit in the PCRx register */
- if(FSMC_Bank == FSMC_Bank2_NAND)
- {
- FSMC_Bank2->PCR2 |= PCR_PBKEN_SET;
- }
- else
- {
- FSMC_Bank3->PCR3 |= PCR_PBKEN_SET;
- }
- }
- else
- {
- /* Disable the selected NAND Bank by clearing the PBKEN bit in the PCRx register */
- if(FSMC_Bank == FSMC_Bank2_NAND)
- {
- FSMC_Bank2->PCR2 &= PCR_PBKEN_RESET;
- }
- else
- {
- FSMC_Bank3->PCR3 &= PCR_PBKEN_RESET;
- }
- }
-}
-/**
- * @brief Enables or disables the FSMC NAND ECC feature.
- * @param FSMC_Bank: specifies the FSMC Bank to be used
- * This parameter can be one of the following values:
- * @arg FSMC_Bank2_NAND: FSMC Bank2 NAND
- * @arg FSMC_Bank3_NAND: FSMC Bank3 NAND
- * @param NewState: new state of the FSMC NAND ECC feature.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void FSMC_NANDECCCmd(uint32_t FSMC_Bank, FunctionalState NewState)
-{
- assert_param(IS_FSMC_NAND_BANK(FSMC_Bank));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- if (NewState != DISABLE)
- {
- /* Enable the selected NAND Bank ECC function by setting the ECCEN bit in the PCRx register */
- if(FSMC_Bank == FSMC_Bank2_NAND)
- {
- FSMC_Bank2->PCR2 |= PCR_ECCEN_SET;
- }
- else
- {
- FSMC_Bank3->PCR3 |= PCR_ECCEN_SET;
- }
- }
- else
- {
- /* Disable the selected NAND Bank ECC function by clearing the ECCEN bit in the PCRx register */
- if(FSMC_Bank == FSMC_Bank2_NAND)
- {
- FSMC_Bank2->PCR2 &= PCR_ECCEN_RESET;
- }
- else
- {
- FSMC_Bank3->PCR3 &= PCR_ECCEN_RESET;
- }
- }
-}
-
-/**
- * @brief Returns the error correction code register value.
- * @param FSMC_Bank: specifies the FSMC Bank to be used
- * This parameter can be one of the following values:
- * @arg FSMC_Bank2_NAND: FSMC Bank2 NAND
- * @arg FSMC_Bank3_NAND: FSMC Bank3 NAND
- * @retval The Error Correction Code (ECC) value.
- */
-uint32_t FSMC_GetECC(uint32_t FSMC_Bank)
-{
- uint32_t eccval = 0x00000000;
-
- if(FSMC_Bank == FSMC_Bank2_NAND)
- {
- /* Get the ECCR2 register value */
- eccval = FSMC_Bank2->ECCR2;
- }
- else
- {
- /* Get the ECCR3 register value */
- eccval = FSMC_Bank3->ECCR3;
- }
- /* Return the error correction code value */
- return(eccval);
-}
-/**
- * @}
- */
-
-/** @defgroup FSMC_Group3 PCCARD Controller functions
- * @brief PCCARD Controller functions
- *
-@verbatim
- ===============================================================================
- PCCARD Controller functions
- ===============================================================================
-
- The following sequence should be followed to configure the FSMC to interface with
- 16-bit PC Card compatible memory connected to the PCCARD Bank:
-
- 1. Enable the clock for the FSMC and associated GPIOs using the following functions:
- RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE);
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOx, ENABLE);
-
- 2. FSMC pins configuration
- - Connect the involved FSMC pins to AF12 using the following function
- GPIO_PinAFConfig(GPIOx, GPIO_PinSourcex, GPIO_AF_FSMC);
- - Configure these FSMC pins in alternate function mode by calling the function
- GPIO_Init();
-
- 3. Declare a FSMC_PCCARDInitTypeDef structure, for example:
- FSMC_PCCARDInitTypeDef FSMC_PCCARDInitStructure;
- and fill the FSMC_PCCARDInitStructure variable with the allowed values of
- the structure member.
-
- 4. Initialize the PCCARD Controller by calling the function
- FSMC_PCCARDInit(&FSMC_PCCARDInitStructure);
-
- 5. Then enable the PCCARD Bank:
- FSMC_PCCARDCmd(ENABLE);
-
- 6. At this stage you can read/write from/to the memory connected to the PCCARD Bank.
-
-@endverbatim
- * @{
- */
-
-/**
- * @brief Deinitializes the FSMC PCCARD Bank registers to their default reset values.
- * @param None
- * @retval None
- */
-void FSMC_PCCARDDeInit(void)
-{
- /* Set the FSMC_Bank4 registers to their reset values */
- FSMC_Bank4->PCR4 = 0x00000018;
- FSMC_Bank4->SR4 = 0x00000000;
- FSMC_Bank4->PMEM4 = 0xFCFCFCFC;
- FSMC_Bank4->PATT4 = 0xFCFCFCFC;
- FSMC_Bank4->PIO4 = 0xFCFCFCFC;
-}
-
-/**
- * @brief Initializes the FSMC PCCARD Bank according to the specified parameters
- * in the FSMC_PCCARDInitStruct.
- * @param FSMC_PCCARDInitStruct : pointer to a FSMC_PCCARDInitTypeDef structure
- * that contains the configuration information for the FSMC PCCARD Bank.
- * @retval None
- */
-void FSMC_PCCARDInit(FSMC_PCCARDInitTypeDef* FSMC_PCCARDInitStruct)
-{
- /* Check the parameters */
- assert_param(IS_FSMC_WAIT_FEATURE(FSMC_PCCARDInitStruct->FSMC_Waitfeature));
- assert_param(IS_FSMC_TCLR_TIME(FSMC_PCCARDInitStruct->FSMC_TCLRSetupTime));
- assert_param(IS_FSMC_TAR_TIME(FSMC_PCCARDInitStruct->FSMC_TARSetupTime));
-
- assert_param(IS_FSMC_SETUP_TIME(FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_SetupTime));
- assert_param(IS_FSMC_WAIT_TIME(FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_WaitSetupTime));
- assert_param(IS_FSMC_HOLD_TIME(FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HoldSetupTime));
- assert_param(IS_FSMC_HIZ_TIME(FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HiZSetupTime));
-
- assert_param(IS_FSMC_SETUP_TIME(FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_SetupTime));
- assert_param(IS_FSMC_WAIT_TIME(FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_WaitSetupTime));
- assert_param(IS_FSMC_HOLD_TIME(FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HoldSetupTime));
- assert_param(IS_FSMC_HIZ_TIME(FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HiZSetupTime));
- assert_param(IS_FSMC_SETUP_TIME(FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_SetupTime));
- assert_param(IS_FSMC_WAIT_TIME(FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_WaitSetupTime));
- assert_param(IS_FSMC_HOLD_TIME(FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_HoldSetupTime));
- assert_param(IS_FSMC_HIZ_TIME(FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_HiZSetupTime));
-
- /* Set the PCR4 register value according to FSMC_PCCARDInitStruct parameters */
- FSMC_Bank4->PCR4 = (uint32_t)FSMC_PCCARDInitStruct->FSMC_Waitfeature |
- FSMC_MemoryDataWidth_16b |
- (FSMC_PCCARDInitStruct->FSMC_TCLRSetupTime << 9) |
- (FSMC_PCCARDInitStruct->FSMC_TARSetupTime << 13);
-
- /* Set PMEM4 register value according to FSMC_CommonSpaceTimingStructure parameters */
- FSMC_Bank4->PMEM4 = (uint32_t)FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_SetupTime |
- (FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_WaitSetupTime << 8) |
- (FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HoldSetupTime << 16)|
- (FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HiZSetupTime << 24);
-
- /* Set PATT4 register value according to FSMC_AttributeSpaceTimingStructure parameters */
- FSMC_Bank4->PATT4 = (uint32_t)FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_SetupTime |
- (FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_WaitSetupTime << 8) |
- (FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HoldSetupTime << 16)|
- (FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HiZSetupTime << 24);
-
- /* Set PIO4 register value according to FSMC_IOSpaceTimingStructure parameters */
- FSMC_Bank4->PIO4 = (uint32_t)FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_SetupTime |
- (FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_WaitSetupTime << 8) |
- (FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_HoldSetupTime << 16)|
- (FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_HiZSetupTime << 24);
-}
-
-/**
- * @brief Fills each FSMC_PCCARDInitStruct member with its default value.
- * @param FSMC_PCCARDInitStruct: pointer to a FSMC_PCCARDInitTypeDef structure
- * which will be initialized.
- * @retval None
- */
-void FSMC_PCCARDStructInit(FSMC_PCCARDInitTypeDef* FSMC_PCCARDInitStruct)
-{
- /* Reset PCCARD Init structure parameters values */
- FSMC_PCCARDInitStruct->FSMC_Waitfeature = FSMC_Waitfeature_Disable;
- FSMC_PCCARDInitStruct->FSMC_TCLRSetupTime = 0x0;
- FSMC_PCCARDInitStruct->FSMC_TARSetupTime = 0x0;
- FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_SetupTime = 0xFC;
- FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_WaitSetupTime = 0xFC;
- FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HoldSetupTime = 0xFC;
- FSMC_PCCARDInitStruct->FSMC_CommonSpaceTimingStruct->FSMC_HiZSetupTime = 0xFC;
- FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_SetupTime = 0xFC;
- FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_WaitSetupTime = 0xFC;
- FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HoldSetupTime = 0xFC;
- FSMC_PCCARDInitStruct->FSMC_AttributeSpaceTimingStruct->FSMC_HiZSetupTime = 0xFC;
- FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_SetupTime = 0xFC;
- FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_WaitSetupTime = 0xFC;
- FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_HoldSetupTime = 0xFC;
- FSMC_PCCARDInitStruct->FSMC_IOSpaceTimingStruct->FSMC_HiZSetupTime = 0xFC;
-}
-
-/**
- * @brief Enables or disables the PCCARD Memory Bank.
- * @param NewState: new state of the PCCARD Memory Bank.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void FSMC_PCCARDCmd(FunctionalState NewState)
-{
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- if (NewState != DISABLE)
- {
- /* Enable the PCCARD Bank by setting the PBKEN bit in the PCR4 register */
- FSMC_Bank4->PCR4 |= PCR_PBKEN_SET;
- }
- else
- {
- /* Disable the PCCARD Bank by clearing the PBKEN bit in the PCR4 register */
- FSMC_Bank4->PCR4 &= PCR_PBKEN_RESET;
- }
-}
-/**
- * @}
- */
-
-/** @defgroup FSMC_Group4 Interrupts and flags management functions
- * @brief Interrupts and flags management functions
- *
-@verbatim
- ===============================================================================
- Interrupts and flags management functions
- ===============================================================================
-
-@endverbatim
- * @{
- */
-
-/**
- * @brief Enables or disables the specified FSMC interrupts.
- * @param FSMC_Bank: specifies the FSMC Bank to be used
- * This parameter can be one of the following values:
- * @arg FSMC_Bank2_NAND: FSMC Bank2 NAND
- * @arg FSMC_Bank3_NAND: FSMC Bank3 NAND
- * @arg FSMC_Bank4_PCCARD: FSMC Bank4 PCCARD
- * @param FSMC_IT: specifies the FSMC interrupt sources to be enabled or disabled.
- * This parameter can be any combination of the following values:
- * @arg FSMC_IT_RisingEdge: Rising edge detection interrupt.
- * @arg FSMC_IT_Level: Level edge detection interrupt.
- * @arg FSMC_IT_FallingEdge: Falling edge detection interrupt.
- * @param NewState: new state of the specified FSMC interrupts.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void FSMC_ITConfig(uint32_t FSMC_Bank, uint32_t FSMC_IT, FunctionalState NewState)
-{
- assert_param(IS_FSMC_IT_BANK(FSMC_Bank));
- assert_param(IS_FSMC_IT(FSMC_IT));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- if (NewState != DISABLE)
- {
- /* Enable the selected FSMC_Bank2 interrupts */
- if(FSMC_Bank == FSMC_Bank2_NAND)
- {
- FSMC_Bank2->SR2 |= FSMC_IT;
- }
- /* Enable the selected FSMC_Bank3 interrupts */
- else if (FSMC_Bank == FSMC_Bank3_NAND)
- {
- FSMC_Bank3->SR3 |= FSMC_IT;
- }
- /* Enable the selected FSMC_Bank4 interrupts */
- else
- {
- FSMC_Bank4->SR4 |= FSMC_IT;
- }
- }
- else
- {
- /* Disable the selected FSMC_Bank2 interrupts */
- if(FSMC_Bank == FSMC_Bank2_NAND)
- {
-
- FSMC_Bank2->SR2 &= (uint32_t)~FSMC_IT;
- }
- /* Disable the selected FSMC_Bank3 interrupts */
- else if (FSMC_Bank == FSMC_Bank3_NAND)
- {
- FSMC_Bank3->SR3 &= (uint32_t)~FSMC_IT;
- }
- /* Disable the selected FSMC_Bank4 interrupts */
- else
- {
- FSMC_Bank4->SR4 &= (uint32_t)~FSMC_IT;
- }
- }
-}
-
-/**
- * @brief Checks whether the specified FSMC flag is set or not.
- * @param FSMC_Bank: specifies the FSMC Bank to be used
- * This parameter can be one of the following values:
- * @arg FSMC_Bank2_NAND: FSMC Bank2 NAND
- * @arg FSMC_Bank3_NAND: FSMC Bank3 NAND
- * @arg FSMC_Bank4_PCCARD: FSMC Bank4 PCCARD
- * @param FSMC_FLAG: specifies the flag to check.
- * This parameter can be one of the following values:
- * @arg FSMC_FLAG_RisingEdge: Rising edge detection Flag.
- * @arg FSMC_FLAG_Level: Level detection Flag.
- * @arg FSMC_FLAG_FallingEdge: Falling edge detection Flag.
- * @arg FSMC_FLAG_FEMPT: Fifo empty Flag.
- * @retval The new state of FSMC_FLAG (SET or RESET).
- */
-FlagStatus FSMC_GetFlagStatus(uint32_t FSMC_Bank, uint32_t FSMC_FLAG)
-{
- FlagStatus bitstatus = RESET;
- uint32_t tmpsr = 0x00000000;
-
- /* Check the parameters */
- assert_param(IS_FSMC_GETFLAG_BANK(FSMC_Bank));
- assert_param(IS_FSMC_GET_FLAG(FSMC_FLAG));
-
- if(FSMC_Bank == FSMC_Bank2_NAND)
- {
- tmpsr = FSMC_Bank2->SR2;
- }
- else if(FSMC_Bank == FSMC_Bank3_NAND)
- {
- tmpsr = FSMC_Bank3->SR3;
- }
- /* FSMC_Bank4_PCCARD*/
- else
- {
- tmpsr = FSMC_Bank4->SR4;
- }
-
- /* Get the flag status */
- if ((tmpsr & FSMC_FLAG) != (uint16_t)RESET )
- {
- bitstatus = SET;
- }
- else
- {
- bitstatus = RESET;
- }
- /* Return the flag status */
- return bitstatus;
-}
-
-/**
- * @brief Clears the FSMC's pending flags.
- * @param FSMC_Bank: specifies the FSMC Bank to be used
- * This parameter can be one of the following values:
- * @arg FSMC_Bank2_NAND: FSMC Bank2 NAND
- * @arg FSMC_Bank3_NAND: FSMC Bank3 NAND
- * @arg FSMC_Bank4_PCCARD: FSMC Bank4 PCCARD
- * @param FSMC_FLAG: specifies the flag to clear.
- * This parameter can be any combination of the following values:
- * @arg FSMC_FLAG_RisingEdge: Rising edge detection Flag.
- * @arg FSMC_FLAG_Level: Level detection Flag.
- * @arg FSMC_FLAG_FallingEdge: Falling edge detection Flag.
- * @retval None
- */
-void FSMC_ClearFlag(uint32_t FSMC_Bank, uint32_t FSMC_FLAG)
-{
- /* Check the parameters */
- assert_param(IS_FSMC_GETFLAG_BANK(FSMC_Bank));
- assert_param(IS_FSMC_CLEAR_FLAG(FSMC_FLAG)) ;
-
- if(FSMC_Bank == FSMC_Bank2_NAND)
- {
- FSMC_Bank2->SR2 &= ~FSMC_FLAG;
- }
- else if(FSMC_Bank == FSMC_Bank3_NAND)
- {
- FSMC_Bank3->SR3 &= ~FSMC_FLAG;
- }
- /* FSMC_Bank4_PCCARD*/
- else
- {
- FSMC_Bank4->SR4 &= ~FSMC_FLAG;
- }
-}
-
-/**
- * @brief Checks whether the specified FSMC interrupt has occurred or not.
- * @param FSMC_Bank: specifies the FSMC Bank to be used
- * This parameter can be one of the following values:
- * @arg FSMC_Bank2_NAND: FSMC Bank2 NAND
- * @arg FSMC_Bank3_NAND: FSMC Bank3 NAND
- * @arg FSMC_Bank4_PCCARD: FSMC Bank4 PCCARD
- * @param FSMC_IT: specifies the FSMC interrupt source to check.
- * This parameter can be one of the following values:
- * @arg FSMC_IT_RisingEdge: Rising edge detection interrupt.
- * @arg FSMC_IT_Level: Level edge detection interrupt.
- * @arg FSMC_IT_FallingEdge: Falling edge detection interrupt.
- * @retval The new state of FSMC_IT (SET or RESET).
- */
-ITStatus FSMC_GetITStatus(uint32_t FSMC_Bank, uint32_t FSMC_IT)
-{
- ITStatus bitstatus = RESET;
- uint32_t tmpsr = 0x0, itstatus = 0x0, itenable = 0x0;
-
- /* Check the parameters */
- assert_param(IS_FSMC_IT_BANK(FSMC_Bank));
- assert_param(IS_FSMC_GET_IT(FSMC_IT));
-
- if(FSMC_Bank == FSMC_Bank2_NAND)
- {
- tmpsr = FSMC_Bank2->SR2;
- }
- else if(FSMC_Bank == FSMC_Bank3_NAND)
- {
- tmpsr = FSMC_Bank3->SR3;
- }
- /* FSMC_Bank4_PCCARD*/
- else
- {
- tmpsr = FSMC_Bank4->SR4;
- }
-
- itstatus = tmpsr & FSMC_IT;
-
- itenable = tmpsr & (FSMC_IT >> 3);
- if ((itstatus != (uint32_t)RESET) && (itenable != (uint32_t)RESET))
- {
- bitstatus = SET;
- }
- else
- {
- bitstatus = RESET;
- }
- return bitstatus;
-}
-
-/**
- * @brief Clears the FSMC's interrupt pending bits.
- * @param FSMC_Bank: specifies the FSMC Bank to be used
- * This parameter can be one of the following values:
- * @arg FSMC_Bank2_NAND: FSMC Bank2 NAND
- * @arg FSMC_Bank3_NAND: FSMC Bank3 NAND
- * @arg FSMC_Bank4_PCCARD: FSMC Bank4 PCCARD
- * @param FSMC_IT: specifies the interrupt pending bit to clear.
- * This parameter can be any combination of the following values:
- * @arg FSMC_IT_RisingEdge: Rising edge detection interrupt.
- * @arg FSMC_IT_Level: Level edge detection interrupt.
- * @arg FSMC_IT_FallingEdge: Falling edge detection interrupt.
- * @retval None
- */
-void FSMC_ClearITPendingBit(uint32_t FSMC_Bank, uint32_t FSMC_IT)
-{
- /* Check the parameters */
- assert_param(IS_FSMC_IT_BANK(FSMC_Bank));
- assert_param(IS_FSMC_IT(FSMC_IT));
-
- if(FSMC_Bank == FSMC_Bank2_NAND)
- {
- FSMC_Bank2->SR2 &= ~(FSMC_IT >> 3);
- }
- else if(FSMC_Bank == FSMC_Bank3_NAND)
- {
- FSMC_Bank3->SR3 &= ~(FSMC_IT >> 3);
- }
- /* FSMC_Bank4_PCCARD*/
- else
- {
- FSMC_Bank4->SR4 &= ~(FSMC_IT >> 3);
- }
-}
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-
-/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/rtc/Kconfig b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/rtc/Kconfig
deleted file mode 100644
index e853dd40a..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/rtc/Kconfig
+++ /dev/null
@@ -1,11 +0,0 @@
-if BSP_USING_RTC
- config RTC_BUS_NAME
- string "rtc bus name"
- default "rtc"
- config RTC_DRV_NAME
- string "rtc bus driver name"
- default "rtc_drv"
- config RTC_DEVICE_NAME
- string "rtc bus device name"
- default "rtc_dev"
-endif
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/rtc/Makefile b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/rtc/Makefile
deleted file mode 100644
index 15d467623..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/rtc/Makefile
+++ /dev/null
@@ -1,3 +0,0 @@
-SRC_FILES := hardware_rtc.c connect_rtc.c
-
-include $(KERNEL_ROOT)/compiler.mk
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/rtc/connect_rtc.c b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/rtc/connect_rtc.c
deleted file mode 100644
index 9c79afe96..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/rtc/connect_rtc.c
+++ /dev/null
@@ -1,268 +0,0 @@
-/*
-* Copyright (c) 2020 AIIT XUOS Lab
-* XiUOS is licensed under Mulan PSL v2.
-* You can use this software according to the terms and conditions of the Mulan PSL v2.
-* You may obtain a copy of Mulan PSL v2 at:
-* http://license.coscl.org.cn/MulanPSL2
-* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
-* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
-* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
-* See the Mulan PSL v2 for more details.
-*/
-
-/**
-* @file connect_rtc.c
-* @brief support stm32f407-st-discovery-board rtc function and register to bus framework
-* @version 1.0
-* @author AIIT XUOS Lab
-* @date 2021-04-25
-*/
-
-#include
-#include
-#include "connect_rtc.h"
-#include "hardware_rtc.h"
-#include "hardware_rcc.h"
-#include "hardware_pwr.h"
-
-#define RTC_BACKUP_REGISTER 0x32F2
-
-static int GetWeekDay(int year, int month, int day)
-{
- if (month==1||month==2) {
- year -=1;
- month +=12;
- }
- return (day+1+2*month+3*(month+1)/5+year+(year/4)-year/100+year/400)%7+1;
-}
-
-static uint32 RtcConfigure(void *drv, struct BusConfigureInfo *configure_info)
-{
- NULL_PARAM_CHECK(drv);
-
- struct RtcDriver *rtc_drv = (struct RtcDriver *)drv;
- struct RtcDrvConfigureParam *drv_param = (struct RtcDrvConfigureParam *)configure_info->private_data;
-
- int cmd = drv_param->rtc_operation_cmd;
- time_t *time = drv_param->time;
-
- switch (cmd)
- {
- case OPER_RTC_GET_TIME:
- {
- struct tm ct;
- RTC_TimeTypeDef t;
- RTC_DateTypeDef d;
-
- memset(&ct,0,sizeof(struct tm));
- RTC_GetTime(RTC_Format_BIN,&t);
- RTC_GetDate(RTC_Format_BIN,&d);
-
- ct.tm_year = d.RTC_Year + 100;
- ct.tm_mon = d.RTC_Month - 1;
- ct.tm_mday = d.RTC_Date;
- ct.tm_wday = d.RTC_WeekDay;
-
- ct.tm_hour = t.RTC_Hours;
- ct.tm_min = t.RTC_Minutes;
- ct.tm_sec = t.RTC_Seconds;
-
- *time = mktime(&ct);
- }
- break;
-
- case OPER_RTC_SET_TIME:
- {
- struct tm *ct;
- struct tm tm_new;
- x_base lock;
- RTC_TimeTypeDef RTC_TimeStructure;
- RTC_InitTypeDef RTC_InitStructure;
- RTC_DateTypeDef RTC_DateStructure;
-
- lock = CriticalAreaLock();
- ct = localtime(time);
- memcpy(&tm_new, ct, sizeof(struct tm));
- CriticalAreaUnLock(lock);
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
- PWR_BackupAccessCmd(ENABLE);
- RTC_InitStructure.RTC_AsynchPrediv = 0x7F;
- RTC_InitStructure.RTC_SynchPrediv = 0xFF;
- RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;
- RTC_Init(&RTC_InitStructure);
- RTC_DateStructure.RTC_Year = tm_new.tm_year - 100;
- RTC_DateStructure.RTC_Month = tm_new.tm_mon + 1;
- RTC_DateStructure.RTC_Date = tm_new.tm_mday;
- RTC_DateStructure.RTC_WeekDay = GetWeekDay(tm_new.tm_year+1900,tm_new.tm_mon+1,tm_new.tm_mday);
- RTC_SetDate(RTC_Format_BIN, &RTC_DateStructure);
- if (tm_new.tm_hour > 11){
- RTC_TimeStructure.RTC_H12 = RTC_H12_PM;
- }
- else{
- RTC_TimeStructure.RTC_H12 = RTC_H12_AM;
- }
- RTC_TimeStructure.RTC_Hours = tm_new.tm_hour;
- RTC_TimeStructure.RTC_Minutes = tm_new.tm_min;
- RTC_TimeStructure.RTC_Seconds = tm_new.tm_sec;
-
- RTC_SetTime(RTC_Format_BIN, &RTC_TimeStructure);
-
- RTC_WriteBackupRegister(RTC_BKP_DR0, 0x32F2);
- }
- break;
- }
-
- return EOK;
-}
-
-int RtcConfiguration(void)
-{
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
-
- PWR_BackupAccessCmd(ENABLE);
-
-#if defined (RTC_CLOCK_SOURCE_LSI)
- RCC_LSICmd(ENABLE);
-
- while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET);
-
- RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);
-
- /* ck_spre(1Hz) = RTCCLK(LSI) /(uwAsynchPrediv + 1)*(uwSynchPrediv + 1)*/
- //uwSynchPrediv = 0xFF;
- //uwAsynchPrediv = 0x7F;
-
-#elif defined (RTC_CLOCK_SOURCE_LSE)
- RCC_LSEConfig(RCC_LSE_ON);
-
- while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET);
- RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
-
-#else
-#error Please select the RTC Clock source inside the main.c file
-#endif
-
- RCC_RTCCLKCmd(ENABLE);
-
- RTC_WaitForSynchro();
-
- return 0;
-}
-
-/*manage the rtc device operations*/
-static const struct RtcDevDone dev_done =
-{
- .open = NONE,
- .close = NONE,
- .write = NONE,
- .read = NONE,
-};
-
-static int BoardRtcBusInit(struct RtcBus *rtc_bus, struct RtcDriver *rtc_driver)
-{
- x_err_t ret = EOK;
-
- /*Init the rtc bus */
- ret = RtcBusInit(rtc_bus, RTC_BUS_NAME);
- if (EOK != ret) {
- KPrintf("hw_rtc_init RtcBusInit error %d\n", ret);
- return ERROR;
- }
-
- /*Init the rtc driver*/
- ret = RtcDriverInit(rtc_driver, RTC_DRV_NAME);
- if (EOK != ret) {
- KPrintf("hw_rtc_init RtcDriverInit error %d\n", ret);
- return ERROR;
- }
-
- /*Attach the rtc driver to the rtc bus*/
- ret = RtcDriverAttachToBus(RTC_DRV_NAME, RTC_BUS_NAME);
- if (EOK != ret) {
- KPrintf("hw_rtc_init RtcDriverAttachToBus error %d\n", ret);
- return ERROR;
- }
-
- return ret;
-}
-
-/*Attach the rtc device to the rtc bus*/
-static int BoardRtcDevBend(void)
-{
- x_err_t ret = EOK;
-
- static struct RtcHardwareDevice rtc_device;
- memset(&rtc_device, 0, sizeof(struct RtcHardwareDevice));
-
- rtc_device.dev_done = &(dev_done);
-
- ret = RtcDeviceRegister(&rtc_device, NONE, RTC_DEVICE_NAME);
- if (EOK != ret) {
- KPrintf("hw_rtc_init RtcDeviceInit device %s error %d\n", RTC_DEVICE_NAME, ret);
- return ERROR;
- }
-
- ret = RtcDeviceAttachToBus(RTC_DEVICE_NAME, RTC_BUS_NAME);
- if (EOK != ret) {
- KPrintf("hw_rtc_init RtcDeviceAttachToBus device %s error %d\n", RTC_DEVICE_NAME, ret);
- return ERROR;
- }
-
- return ret;
-}
-
-int Stm32HwRtcInit(void)
-{
- x_err_t ret = EOK;
-
- static struct RtcBus rtc_bus;
- memset(&rtc_bus, 0, sizeof(struct RtcBus));
-
- static struct RtcDriver rtc_driver;
- memset(&rtc_driver, 0, sizeof(struct RtcDriver));
-
- rtc_driver.configure = &(RtcConfigure);
-
- ret = BoardRtcBusInit(&rtc_bus, &rtc_driver);
- if (EOK != ret) {
- KPrintf("hw_rtc_init error ret %u\n", ret);
- return ERROR;
- }
-
- ret = BoardRtcDevBend();
- if (EOK != ret) {
- KPrintf("hw_rtc_init error ret %u\n", ret);
- return ERROR;
- }
-
- if (RTC_BACKUP_REGISTER != RTC_ReadBackupRegister(RTC_BKP_DR0)) {
- if (0 != RtcConfiguration()) {
- KPrintf("hw_rtc_init RtcConfiguration error...\n");
- return ERROR;
- }
- } else {
- RTC_WaitForSynchro();
- }
-
- return ret;
-}
-
-#ifdef TOOL_SHELL
-void ShowTime(void)
-{
- RTC_TimeTypeDef time;
- RTC_DateTypeDef date;
- RTC_GetDate(RTC_Format_BIN,&date);
- RTC_GetTime(RTC_Format_BIN, &time);
- KPrintf("Now Time = 20%02d %02d %02d[%02d]-%0.2d:%0.2d:%0.2d \r\n", \
- date.RTC_Year,
- date.RTC_Month,
- date.RTC_Date,
- date.RTC_WeekDay,
- time.RTC_Hours,
- time.RTC_Minutes,
- time.RTC_Seconds);
-}
-SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0),
- ShowTime, ShowTime, Arm test rtc function show time);
-#endif
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/rtc/hardware_rtc.c b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/rtc/hardware_rtc.c
deleted file mode 100644
index b383a2fb6..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/rtc/hardware_rtc.c
+++ /dev/null
@@ -1,2752 +0,0 @@
-/**
- ******************************************************************************
- * @file stm32f4xx_rtc.c
- * @author MCD Application Team
- * @version V1.0.0
- * @date 30-September-2011
- * @brief This file provides firmware functions to manage the following
- * functionalities of the Real-Time Clock (RTC) peripheral:
- * - Initialization
- * - Calendar (Time and Date) configuration
- * - Alarms (Alarm A and Alarm B) configuration
- * - WakeUp Timer configuration
- * - Daylight Saving configuration
- * - Output pin Configuration
- * - Coarse digital Calibration configuration
- * - Smooth digital Calibration configuration
- * - TimeStamp configuration
- * - Tampers configuration
- * - Backup Data Registers configuration
- * - Shift control synchronisation
- * - RTC Tamper and TimeStamp Pins Selection and Output Type Config configuration
- * - Interrupts and flags management
- *
- * @verbatim
- *
- * ===================================================================
- * Backup Domain Operating Condition
- * ===================================================================
- * The real-time clock (RTC), the RTC backup registers, and the backup
- * SRAM (BKP SRAM) can be powered from the VBAT voltage when the main
- * VDD supply is powered off.
- * To retain the content of the RTC backup registers, backup SRAM,
- * and supply the RTC when VDD is turned off, VBAT pin can be connected
- * to an optional standby voltage supplied by a battery or by another
- * source.
- *
- * To allow the RTC to operate even when the main digital supply (VDD)
- * is turned off, the VBAT pin powers the following blocks:
- * 1 - The RTC
- * 2 - The LSE oscillator
- * 3 - The backup SRAM when the low power backup regulator is enabled
- * 4 - PC13 to PC15 I/Os, plus PI8 I/O (when available)
- *
- * When the backup domain is supplied by VDD (analog switch connected
- * to VDD), the following functions are available:
- * 1 - PC14 and PC15 can be used as either GPIO or LSE pins
- * 2 - PC13 can be used as a GPIO or as the RTC_AF1 pin
- * 3 - PI8 can be used as a GPIO or as the RTC_AF2 pin
- *
- * When the backup domain is supplied by VBAT (analog switch connected
- * to VBAT because VDD is not present), the following functions are available:
- * 1 - PC14 and PC15 can be used as LSE pins only
- * 2 - PC13 can be used as the RTC_AF1 pin
- * 3 - PI8 can be used as the RTC_AF2 pin
- *
- * ===================================================================
- * Backup Domain Reset
- * ===================================================================
- * The backup domain reset sets all RTC registers and the RCC_BDCR
- * register to their reset values. The BKPSRAM is not affected by this
- * reset. The only way of resetting the BKPSRAM is through the Flash
- * interface by requesting a protection level change from 1 to 0.
- * A backup domain reset is generated when one of the following events
- * occurs:
- * 1 - Software reset, triggered by setting the BDRST bit in the
- * RCC Backup domain control register (RCC_BDCR). You can use the
- * RCC_BackupResetCmd().
- * 2 - VDD or VBAT power on, if both supplies have previously been
- * powered off.
- *
- * ===================================================================
- * Backup Domain Access
- * ===================================================================
- * After reset, the backup domain (RTC registers, RTC backup data
- * registers and backup SRAM) is protected against possible unwanted
- * write accesses.
- * To enable access to the RTC Domain and RTC registers, proceed as follows:
- * - Enable the Power Controller (PWR) APB1 interface clock using the
- * RCC_APB1PeriphClockCmd() function.
- * - Enable access to RTC domain using the PWR_BackupAccessCmd() function.
- * - Select the RTC clock source using the RCC_RTCCLKConfig() function.
- * - Enable RTC Clock using the RCC_RTCCLKCmd() function.
- *
- * ===================================================================
- * RTC Driver: how to use it
- * ===================================================================
- * - Enable the RTC domain access (see description in the section above)
- * - Configure the RTC Prescaler (Asynchronous and Synchronous) and
- * RTC hour format using the RTC_Init() function.
- *
- * Time and Date configuration
- * ===========================
- * - To configure the RTC Calendar (Time and Date) use the RTC_SetTime()
- * and RTC_SetDate() functions.
- * - To read the RTC Calendar, use the RTC_GetTime() and RTC_GetDate()
- * functions.
- * - Use the RTC_DayLightSavingConfig() function to add or sub one
- * hour to the RTC Calendar.
- *
- * Alarm configuration
- * ===================
- * - To configure the RTC Alarm use the RTC_SetAlarm() function.
- * - Enable the selected RTC Alarm using the RTC_AlarmCmd() function
- * - To read the RTC Alarm, use the RTC_GetAlarm() function.
- * - To read the RTC alarm SubSecond, use the RTC_GetAlarmSubSecond() function.
- *
- * RTC Wakeup configuration
- * ========================
- * - Configure the RTC Wakeup Clock source use the RTC_WakeUpClockConfig()
- * function.
- * - Configure the RTC WakeUp Counter using the RTC_SetWakeUpCounter()
- * function
- * - Enable the RTC WakeUp using the RTC_WakeUpCmd() function
- * - To read the RTC WakeUp Counter register, use the RTC_GetWakeUpCounter()
- * function.
- *
- * Outputs configuration
- * =====================
- * The RTC has 2 different outputs:
- * - AFO_ALARM: this output is used to manage the RTC Alarm A, Alarm B
- * and WaKeUp signals.
- * To output the selected RTC signal on RTC_AF1 pin, use the
- * RTC_OutputConfig() function.
- * - AFO_CALIB: this output is 512Hz signal or 1Hz .
- * To output the RTC Clock on RTC_AF1 pin, use the RTC_CalibOutputCmd()
- * function.
- *
- * Smooth digital Calibration configuration
- * =================================
- * - Configure the RTC Original Digital Calibration Value and the corresponding
- * calibration cycle period (32s,16s and 8s) using the RTC_SmoothCalibConfig()
- * function.
- *
- * Coarse digital Calibration configuration
- * =================================
- * - Configure the RTC Coarse Calibration Value and the corresponding
- * sign using the RTC_CoarseCalibConfig() function.
- * - Enable the RTC Coarse Calibration using the RTC_CoarseCalibCmd()
- * function
- *
- * TimeStamp configuration
- * =======================
- * - Configure the RTC_AF1 trigger and enables the RTC TimeStamp
- * using the RTC_TimeStampCmd() function.
- * - To read the RTC TimeStamp Time and Date register, use the
- * RTC_GetTimeStamp() function.
- * - To read the RTC TimeStamp SubSecond register, use the
- * RTC_GetTimeStampSubSecond() function.
- * - The TAMPER1 alternate function can be mapped either to RTC_AF1(PC13)
- * or RTC_AF2 (PI8) depending on the value of TAMP1INSEL bit in
- * RTC_TAFCR register. You can use the RTC_TamperPinSelection()
- * function to select the corresponding pin.
- *
- * Tamper configuration
- * ====================
- * - Enable the RTC Tamper using the RTC_TamperCmd() function.
- * - Configure the Tamper filter count using RTC_TamperFilterConfig()
- * function.
- * - Configure the RTC Tamper trigger Edge or Level according to the Tamper
- * filter (if equal to 0 Edge else Level) value using the RTC_TamperConfig() function.
- * - Configure the Tamper sampling frequency using RTC_TamperSamplingFreqConfig()
- * function.
- * - Configure the Tamper precharge or discharge duration using
- * RTC_TamperPinsPrechargeDuration() function.
- * - Enable the Tamper Pull-UP using RTC_TamperPullUpDisableCmd() function.
- * - Enable the Time stamp on Tamper detection event using
- * RTC_TSOnTamperDetecCmd() function.
- * - The TIMESTAMP alternate function can be mapped to either RTC_AF1
- * or RTC_AF2 depending on the value of the TSINSEL bit in the
- * RTC_TAFCR register. You can use the RTC_TimeStampPinSelection()
- * function to select the corresponding pin.
- *
- * Backup Data Registers configuration
- * ===================================
- * - To write to the RTC Backup Data registers, use the RTC_WriteBackupRegister()
- * function.
- * - To read the RTC Backup Data registers, use the RTC_ReadBackupRegister()
- * function.
- *
- * ===================================================================
- * RTC and low power modes
- * ===================================================================
- * The MCU can be woken up from a low power mode by an RTC alternate
- * function.
- * The RTC alternate functions are the RTC alarms (Alarm A and Alarm B),
- * RTC wakeup, RTC tamper event detection and RTC time stamp event detection.
- * These RTC alternate functions can wake up the system from the Stop
- * and Standby lowpower modes.
- * The system can also wake up from low power modes without depending
- * on an external interrupt (Auto-wakeup mode), by using the RTC alarm
- * or the RTC wakeup events.
- * The RTC provides a programmable time base for waking up from the
- * Stop or Standby mode at regular intervals.
- * Wakeup from STOP and Standby modes is possible only when the RTC
- * clock source is LSE or LSI.
- *
- * ===================================================================
- * Selection of RTC_AF1 alternate functions
- * ===================================================================
- * The RTC_AF1 pin (PC13) can be used for the following purposes:
- * - AFO_ALARM output
- * - AFO_CALIB output
- * - AFI_TAMPER
- * - AFI_TIMESTAMP
- *
- * +-------------------------------------------------------------------------------------------------------------+
- * | Pin |AFO_ALARM |AFO_CALIB |AFI_TAMPER |AFI_TIMESTAMP | TAMP1INSEL | TSINSEL |ALARMOUTTYPE |
- * | configuration | ENABLED | ENABLED | ENABLED | ENABLED |TAMPER1 pin |TIMESTAMP pin | AFO_ALARM |
- * | and function | | | | | selection | selection |Configuration |
- * |-----------------|----------|----------|-----------|--------------|------------|--------------|--------------|
- * | Alarm out | | | | | Don't | Don't | |
- * | output OD | 1 |Don't care|Don't care | Don't care | care | care | 0 |
- * |-----------------|----------|----------|-----------|--------------|------------|--------------|--------------|
- * | Alarm out | | | | | Don't | Don't | |
- * | output PP | 1 |Don't care|Don't care | Don't care | care | care | 1 |
- * |-----------------|----------|----------|-----------|--------------|------------|--------------|--------------|
- * | Calibration out | | | | | Don't | Don't | |
- * | output PP | 0 | 1 |Don't care | Don't care | care | care | Don't care |
- * |-----------------|----------|----------|-----------|--------------|------------|--------------|--------------|
- * | TAMPER input | | | | | | Don't | |
- * | floating | 0 | 0 | 1 | 0 | 0 | care | Don't care |
- * |-----------------|----------|----------|-----------|--------------|------------|--------------|--------------|
- * | TIMESTAMP and | | | | | | | |
- * | TAMPER input | 0 | 0 | 1 | 1 | 0 | 0 | Don't care |
- * | floating | | | | | | | |
- * |-----------------|----------|----------|-----------|--------------|------------|--------------|--------------|
- * | TIMESTAMP input | | | | | Don't | | |
- * | floating | 0 | 0 | 0 | 1 | care | 0 | Don't care |
- * |-----------------|----------|----------|-----------|--------------|------------|--------------|--------------|
- * | Standard GPIO | 0 | 0 | 0 | 0 | Don't care | Don't care | Don't care |
- * +-------------------------------------------------------------------------------------------------------------+
- *
- *
- * ===================================================================
- * Selection of RTC_AF2 alternate functions
- * ===================================================================
- * The RTC_AF2 pin (PI8) can be used for the following purposes:
- * - AFI_TAMPER
- * - AFI_TIMESTAMP
- *
- * +---------------------------------------------------------------------------------------+
- * | Pin |AFI_TAMPER |AFI_TIMESTAMP | TAMP1INSEL | TSINSEL |ALARMOUTTYPE |
- * | configuration | ENABLED | ENABLED |TAMPER1 pin |TIMESTAMP pin | AFO_ALARM |
- * | and function | | | selection | selection |Configuration |
- * |-----------------|-----------|--------------|------------|--------------|--------------|
- * | TAMPER input | | | | Don't | |
- * | floating | 1 | 0 | 1 | care | Don't care |
- * |-----------------|-----------|--------------|------------|--------------|--------------|
- * | TIMESTAMP and | | | | | |
- * | TAMPER input | 1 | 1 | 1 | 1 | Don't care |
- * | floating | | | | | |
- * |-----------------|-----------|--------------|------------|--------------|--------------|
- * | TIMESTAMP input | | | Don't | | |
- * | floating | 0 | 1 | care | 1 | Don't care |
- * |-----------------|-----------|--------------|------------|--------------|--------------|
- * | Standard GPIO | 0 | 0 | Don't care | Don't care | Don't care |
- * +---------------------------------------------------------------------------------------+
- *
- *
- * @endverbatim
- *
- ******************************************************************************
- * @attention
- *
- * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
- * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
- * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
- * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
- * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
- * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
- *
- * © COPYRIGHT 2011 STMicroelectronics
- ******************************************************************************
- */
-
-/**
-* @file: hardware_rtc.c
-* @brief: support hardware rtc function
-* @version: 1.0
-* @author: AIIT XUOS Lab
-* @date: 2021/4/25
-*/
-
-/*************************************************
-File name: hardware_rtc.c
-Description: support hardware rtc function
-Others:
-History:
-1. Date: 2021-04-25
-Author: AIIT XUOS Lab
-Modification:
-1. rename stm32f4xx_rtc.c for XiUOS
-*************************************************/
-
-/* Includes ------------------------------------------------------------------*/
-#include
-#include
-#include
-
-/** @addtogroup STM32F4xx_StdPeriph_Driver
- * @{
- */
-
-/** @defgroup RTC
- * @brief RTC driver modules
- * @{
- */
-
-/* Private typedef -----------------------------------------------------------*/
-/* Private define ------------------------------------------------------------*/
-
-/* Masks Definition */
-#define RTC_TR_RESERVED_MASK ((uint32_t)0x007F7F7F)
-#define RTC_DR_RESERVED_MASK ((uint32_t)0x00FFFF3F)
-#define RTC_INIT_MASK ((uint32_t)0xFFFFFFFF)
-#define RTC_RSF_MASK ((uint32_t)0xFFFFFF5F)
-#define RTC_FLAGS_MASK ((uint32_t)(RTC_FLAG_TSOVF | RTC_FLAG_TSF | RTC_FLAG_WUTF | \
- RTC_FLAG_ALRBF | RTC_FLAG_ALRAF | RTC_FLAG_INITF | \
- RTC_FLAG_RSF | RTC_FLAG_INITS | RTC_FLAG_WUTWF | \
- RTC_FLAG_ALRBWF | RTC_FLAG_ALRAWF | RTC_FLAG_TAMP1F ))
-
-#define INITMODE_TIMEOUT ((uint32_t) 0x00010000)
-#define SYNCHRO_TIMEOUT ((uint32_t) 0x00020000)
-#define RECALPF_TIMEOUT ((uint32_t) 0x00020000)
-#define SHPF_TIMEOUT ((uint32_t) 0x00001000)
-
-/* Private macro -------------------------------------------------------------*/
-/* Private variables ---------------------------------------------------------*/
-/* Private function prototypes -----------------------------------------------*/
-static uint8_t RTC_ByteToBcd2(uint8_t Value);
-static uint8_t RTC_Bcd2ToByte(uint8_t Value);
-
-/* Private functions ---------------------------------------------------------*/
-
-/** @defgroup RTC_Private_Functions
- * @{
- */
-
-/** @defgroup RTC_Group1 Initialization and Configuration functions
- * @brief Initialization and Configuration functions
- *
-@verbatim
- ===============================================================================
- Initialization and Configuration functions
- ===============================================================================
-
- This section provide functions allowing to initialize and configure the RTC
- Prescaler (Synchronous and Asynchronous), RTC Hour format, disable RTC registers
- Write protection, enter and exit the RTC initialization mode, RTC registers
- synchronization check and reference clock detection enable.
-
- 1. The RTC Prescaler is programmed to generate the RTC 1Hz time base. It is
- split into 2 programmable prescalers to minimize power consumption.
- - A 7-bit asynchronous prescaler and A 13-bit synchronous prescaler.
- - When both prescalers are used, it is recommended to configure the asynchronous
- prescaler to a high value to minimize consumption.
-
- 2. All RTC registers are Write protected. Writing to the RTC registers
- is enabled by writing a key into the Write Protection register, RTC_WPR.
-
- 3. To Configure the RTC Calendar, user application should enter initialization
- mode. In this mode, the calendar counter is stopped and its value can be
- updated. When the initialization sequence is complete, the calendar restarts
- counting after 4 RTCCLK cycles.
-
- 4. To read the calendar through the shadow registers after Calendar initialization,
- calendar update or after wakeup from low power modes the software must first
- clear the RSF flag. The software must then wait until it is set again before
- reading the calendar, which means that the calendar registers have been
- correctly copied into the RTC_TR and RTC_DR shadow registers.
- The RTC_WaitForSynchro() function implements the above software sequence
- (RSF clear and RSF check).
-
-@endverbatim
- * @{
- */
-
-/**
- * @brief Deinitializes the RTC registers to their default reset values.
- * @note This function doesn't reset the RTC Clock source and RTC Backup Data
- * registers.
- * @param None
- * @retval An ErrorStatus enumeration value:
- * - SUCCESS: RTC registers are deinitialized
- * - ST_ERROR: RTC registers are not deinitialized
- */
-ErrorStatus RTC_DeInit(void)
-{
- __IO uint32_t wutcounter = 0x00;
- uint32_t wutwfstatus = 0x00;
- ErrorStatus status = ST_ERROR;
-
- /* Disable the write protection for RTC registers */
- RTC->WPR = 0xCA;
- RTC->WPR = 0x53;
-
- /* Set Initialization mode */
- if (RTC_EnterInitMode() == ST_ERROR)
- {
- status = ST_ERROR;
- }
- else
- {
- /* Reset TR, DR and CR registers */
- RTC->TR = (uint32_t)0x00000000;
- RTC->DR = (uint32_t)0x00002101;
- /* Reset All CR bits except CR[2:0] */
- RTC->CR &= (uint32_t)0x00000007;
-
- /* Wait till RTC WUTWF flag is set and if Time out is reached exit */
- do
- {
- wutwfstatus = RTC->ISR & RTC_ISR_WUTWF;
- wutcounter++;
- } while((wutcounter != INITMODE_TIMEOUT) && (wutwfstatus == 0x00));
-
- if ((RTC->ISR & RTC_ISR_WUTWF) == RESET)
- {
- status = ST_ERROR;
- }
- else
- {
- /* Reset all RTC CR register bits */
- RTC->CR &= (uint32_t)0x00000000;
- RTC->WUTR = (uint32_t)0x0000FFFF;
- RTC->PRER = (uint32_t)0x007F00FF;
- RTC->CALIBR = (uint32_t)0x00000000;
- RTC->ALRMAR = (uint32_t)0x00000000;
- RTC->ALRMBR = (uint32_t)0x00000000;
-
- /* Reset ISR register and exit initialization mode */
- RTC->ISR = (uint32_t)0x00000000;
-
- /* Reset Tamper and alternate functions configuration register */
- RTC->TAFCR = 0x00000000;
-
- if(RTC_WaitForSynchro() == ST_ERROR)
- {
- status = ST_ERROR;
- }
- else
- {
- status = SUCCESS;
- }
- }
- }
-
- /* Enable the write protection for RTC registers */
- RTC->WPR = 0xFF;
-
- return status;
-}
-
-/**
- * @brief Initializes the RTC registers according to the specified parameters
- * in RTC_InitStruct.
- * @param RTC_InitStruct: pointer to a RTC_InitTypeDef structure that contains
- * the configuration information for the RTC peripheral.
- * @note The RTC Prescaler register is write protected and can be written in
- * initialization mode only.
- * @retval An ErrorStatus enumeration value:
- * - SUCCESS: RTC registers are initialized
- * - ST_ERROR: RTC registers are not initialized
- */
-ErrorStatus RTC_Init(RTC_InitTypeDef* RTC_InitStruct)
-{
- ErrorStatus status = ST_ERROR;
-
- /* Check the parameters */
- assert_param(IS_RTC_HOUR_FORMAT(RTC_InitStruct->RTC_HourFormat));
- assert_param(IS_RTC_ASYNCH_PREDIV(RTC_InitStruct->RTC_AsynchPrediv));
- assert_param(IS_RTC_SYNCH_PREDIV(RTC_InitStruct->RTC_SynchPrediv));
-
- /* Disable the write protection for RTC registers */
- RTC->WPR = 0xCA;
- RTC->WPR = 0x53;
-
- /* Set Initialization mode */
- if (RTC_EnterInitMode() == ST_ERROR)
- {
- status = ST_ERROR;
- }
- else
- {
- /* Clear RTC CR FMT Bit */
- RTC->CR &= ((uint32_t)~(RTC_CR_FMT));
- /* Set RTC_CR register */
- RTC->CR |= ((uint32_t)(RTC_InitStruct->RTC_HourFormat));
-
- /* Configure the RTC PRER */
- RTC->PRER = (uint32_t)(RTC_InitStruct->RTC_SynchPrediv);
- RTC->PRER |= (uint32_t)(RTC_InitStruct->RTC_AsynchPrediv << 16);
-
- /* Exit Initialization mode */
- RTC_ExitInitMode();
-
- status = SUCCESS;
- }
- /* Enable the write protection for RTC registers */
- RTC->WPR = 0xFF;
-
- return status;
-}
-
-/**
- * @brief Fills each RTC_InitStruct member with its default value.
- * @param RTC_InitStruct: pointer to a RTC_InitTypeDef structure which will be
- * initialized.
- * @retval None
- */
-void RTC_StructInit(RTC_InitTypeDef* RTC_InitStruct)
-{
- /* Initialize the RTC_HourFormat member */
- RTC_InitStruct->RTC_HourFormat = RTC_HourFormat_24;
-
- /* Initialize the RTC_AsynchPrediv member */
- RTC_InitStruct->RTC_AsynchPrediv = (uint32_t)0x7F;
-
- /* Initialize the RTC_SynchPrediv member */
- RTC_InitStruct->RTC_SynchPrediv = (uint32_t)0xFF;
-}
-
-/**
- * @brief Enables or disables the RTC registers write protection.
- * @note All the RTC registers are write protected except for RTC_ISR[13:8],
- * RTC_TAFCR and RTC_BKPxR.
- * @note Writing a wrong key reactivates the write protection.
- * @note The protection mechanism is not affected by system reset.
- * @param NewState: new state of the write protection.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void RTC_WriteProtectionCmd(FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- if (NewState != DISABLE)
- {
- /* Enable the write protection for RTC registers */
- RTC->WPR = 0xFF;
- }
- else
- {
- /* Disable the write protection for RTC registers */
- RTC->WPR = 0xCA;
- RTC->WPR = 0x53;
- }
-}
-
-/**
- * @brief Enters the RTC Initialization mode.
- * @note The RTC Initialization mode is write protected, use the
- * RTC_WriteProtectionCmd(DISABLE) before calling this function.
- * @param None
- * @retval An ErrorStatus enumeration value:
- * - SUCCESS: RTC is in Init mode
- * - ST_ERROR: RTC is not in Init mode
- */
-ErrorStatus RTC_EnterInitMode(void)
-{
- __IO uint32_t initcounter = 0x00;
- ErrorStatus status = ST_ERROR;
- uint32_t initstatus = 0x00;
-
- /* Check if the Initialization mode is set */
- if ((RTC->ISR & RTC_ISR_INITF) == (uint32_t)RESET)
- {
- /* Set the Initialization mode */
- RTC->ISR = (uint32_t)RTC_INIT_MASK;
-
- /* Wait till RTC is in INIT state and if Time out is reached exit */
- do
- {
- initstatus = RTC->ISR & RTC_ISR_INITF;
- initcounter++;
- } while((initcounter != INITMODE_TIMEOUT) && (initstatus == 0x00));
-
- if ((RTC->ISR & RTC_ISR_INITF) != RESET)
- {
- status = SUCCESS;
- }
- else
- {
- status = ST_ERROR;
- }
- }
- else
- {
- status = SUCCESS;
- }
-
- return (status);
-}
-
-/**
- * @brief Exits the RTC Initialization mode.
- * @note When the initialization sequence is complete, the calendar restarts
- * counting after 4 RTCCLK cycles.
- * @note The RTC Initialization mode is write protected, use the
- * RTC_WriteProtectionCmd(DISABLE) before calling this function.
- * @param None
- * @retval None
- */
-void RTC_ExitInitMode(void)
-{
- /* Exit Initialization mode */
- RTC->ISR &= (uint32_t)~RTC_ISR_INIT;
-}
-
-/**
- * @brief Waits until the RTC Time and Date registers (RTC_TR and RTC_DR) are
- * synchronized with RTC APB clock.
- * @note The RTC Resynchronization mode is write protected, use the
- * RTC_WriteProtectionCmd(DISABLE) before calling this function.
- * @note To read the calendar through the shadow registers after Calendar
- * initialization, calendar update or after wakeup from low power modes
- * the software must first clear the RSF flag.
- * The software must then wait until it is set again before reading
- * the calendar, which means that the calendar registers have been
- * correctly copied into the RTC_TR and RTC_DR shadow registers.
- * @param None
- * @retval An ErrorStatus enumeration value:
- * - SUCCESS: RTC registers are synchronised
- * - ST_ERROR: RTC registers are not synchronised
- */
-ErrorStatus RTC_WaitForSynchro(void)
-{
- __IO uint32_t synchrocounter = 0;
- ErrorStatus status = ST_ERROR;
- uint32_t synchrostatus = 0x00;
-
- /* Disable the write protection for RTC registers */
- RTC->WPR = 0xCA;
- RTC->WPR = 0x53;
-
- /* Clear RSF flag */
- RTC->ISR &= (uint32_t)RTC_RSF_MASK;
-
- /* Wait the registers to be synchronised */
- do
- {
- synchrostatus = RTC->ISR & RTC_ISR_RSF;
- synchrocounter++;
- } while((synchrocounter != SYNCHRO_TIMEOUT) && (synchrostatus == 0x00));
-
- if ((RTC->ISR & RTC_ISR_RSF) != RESET)
- {
- status = SUCCESS;
- }
- else
- {
- status = ST_ERROR;
- }
-
- /* Enable the write protection for RTC registers */
- RTC->WPR = 0xFF;
-
- return (status);
-}
-
-/**
- * @brief Enables or disables the RTC reference clock detection.
- * @param NewState: new state of the RTC reference clock.
- * This parameter can be: ENABLE or DISABLE.
- * @retval An ErrorStatus enumeration value:
- * - SUCCESS: RTC reference clock detection is enabled
- * - ST_ERROR: RTC reference clock detection is disabled
- */
-ErrorStatus RTC_RefClockCmd(FunctionalState NewState)
-{
- ErrorStatus status = ST_ERROR;
-
- /* Check the parameters */
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- /* Disable the write protection for RTC registers */
- RTC->WPR = 0xCA;
- RTC->WPR = 0x53;
-
- /* Set Initialization mode */
- if (RTC_EnterInitMode() == ST_ERROR)
- {
- status = ST_ERROR;
- }
- else
- {
- if (NewState != DISABLE)
- {
- /* Enable the RTC reference clock detection */
- RTC->CR |= RTC_CR_REFCKON;
- }
- else
- {
- /* Disable the RTC reference clock detection */
- RTC->CR &= ~RTC_CR_REFCKON;
- }
- /* Exit Initialization mode */
- RTC_ExitInitMode();
-
- status = SUCCESS;
- }
-
- /* Enable the write protection for RTC registers */
- RTC->WPR = 0xFF;
-
- return status;
-}
-
-/**
- * @brief Enables or Disables the Bypass Shadow feature.
- * @note When the Bypass Shadow is enabled the calendar value are taken
- * directly from the Calendar counter.
- * @param NewState: new state of the Bypass Shadow feature.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
-*/
-void RTC_BypassShadowCmd(FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- /* Disable the write protection for RTC registers */
- RTC->WPR = 0xCA;
- RTC->WPR = 0x53;
-
- if (NewState != DISABLE)
- {
- /* Set the BYPSHAD bit */
- RTC->CR |= (uint8_t)RTC_CR_BYPSHAD;
- }
- else
- {
- /* Reset the BYPSHAD bit */
- RTC->CR &= (uint8_t)~RTC_CR_BYPSHAD;
- }
-
- /* Enable the write protection for RTC registers */
- RTC->WPR = 0xFF;
-}
-
-/**
- * @}
- */
-
-/** @defgroup RTC_Group2 Time and Date configuration functions
- * @brief Time and Date configuration functions
- *
-@verbatim
- ===============================================================================
- Time and Date configuration functions
- ===============================================================================
-
- This section provide functions allowing to program and read the RTC Calendar
- (Time and Date).
-
-@endverbatim
- * @{
- */
-
-/**
- * @brief Set the RTC current time.
- * @param RTC_Format: specifies the format of the entered parameters.
- * This parameter can be one of the following values:
- * @arg RTC_Format_BIN: Binary data format
- * @arg RTC_Format_BCD: BCD data format
- * @param RTC_TimeStruct: pointer to a RTC_TimeTypeDef structure that contains
- * the time configuration information for the RTC.
- * @retval An ErrorStatus enumeration value:
- * - SUCCESS: RTC Time register is configured
- * - ST_ERROR: RTC Time register is not configured
- */
-ErrorStatus RTC_SetTime(uint32_t RTC_Format, RTC_TimeTypeDef* RTC_TimeStruct)
-{
- uint32_t tmpreg = 0;
- ErrorStatus status = ST_ERROR;
-
- /* Check the parameters */
- assert_param(IS_RTC_FORMAT(RTC_Format));
-
- if (RTC_Format == RTC_Format_BIN)
- {
- if ((RTC->CR & RTC_CR_FMT) != (uint32_t)RESET)
- {
- assert_param(IS_RTC_HOUR12(RTC_TimeStruct->RTC_Hours));
- assert_param(IS_RTC_H12(RTC_TimeStruct->RTC_H12));
- }
- else
- {
- RTC_TimeStruct->RTC_H12 = 0x00;
- assert_param(IS_RTC_HOUR24(RTC_TimeStruct->RTC_Hours));
- }
- assert_param(IS_RTC_MINUTES(RTC_TimeStruct->RTC_Minutes));
- assert_param(IS_RTC_SECONDS(RTC_TimeStruct->RTC_Seconds));
- }
- else
- {
- if ((RTC->CR & RTC_CR_FMT) != (uint32_t)RESET)
- {
- tmpreg = RTC_Bcd2ToByte(RTC_TimeStruct->RTC_Hours);
- assert_param(IS_RTC_HOUR12(tmpreg));
- assert_param(IS_RTC_H12(RTC_TimeStruct->RTC_H12));
- }
- else
- {
- RTC_TimeStruct->RTC_H12 = 0x00;
- assert_param(IS_RTC_HOUR24(RTC_Bcd2ToByte(RTC_TimeStruct->RTC_Hours)));
- }
- assert_param(IS_RTC_MINUTES(RTC_Bcd2ToByte(RTC_TimeStruct->RTC_Minutes)));
- assert_param(IS_RTC_SECONDS(RTC_Bcd2ToByte(RTC_TimeStruct->RTC_Seconds)));
- }
-
- /* Check the input parameters format */
- if (RTC_Format != RTC_Format_BIN)
- {
- tmpreg = (((uint32_t)(RTC_TimeStruct->RTC_Hours) << 16) | \
- ((uint32_t)(RTC_TimeStruct->RTC_Minutes) << 8) | \
- ((uint32_t)RTC_TimeStruct->RTC_Seconds) | \
- ((uint32_t)(RTC_TimeStruct->RTC_H12) << 16));
- }
- else
- {
- tmpreg = (uint32_t)(((uint32_t)RTC_ByteToBcd2(RTC_TimeStruct->RTC_Hours) << 16) | \
- ((uint32_t)RTC_ByteToBcd2(RTC_TimeStruct->RTC_Minutes) << 8) | \
- ((uint32_t)RTC_ByteToBcd2(RTC_TimeStruct->RTC_Seconds)) | \
- (((uint32_t)RTC_TimeStruct->RTC_H12) << 16));
- }
-
- /* Disable the write protection for RTC registers */
- RTC->WPR = 0xCA;
- RTC->WPR = 0x53;
-
- /* Set Initialization mode */
- if (RTC_EnterInitMode() == ST_ERROR)
- {
- status = ST_ERROR;
- }
- else
- {
- /* Set the RTC_TR register */
- RTC->TR = (uint32_t)(tmpreg & RTC_TR_RESERVED_MASK);
-
- /* Exit Initialization mode */
- RTC_ExitInitMode();
-
- if(RTC_WaitForSynchro() == ST_ERROR)
- {
- status = ST_ERROR;
- }
- else
- {
- status = SUCCESS;
- }
-
- }
- /* Enable the write protection for RTC registers */
- RTC->WPR = 0xFF;
-
- return status;
-}
-
-/**
- * @brief Fills each RTC_TimeStruct member with its default value
- * (Time = 00h:00min:00sec).
- * @param RTC_TimeStruct: pointer to a RTC_TimeTypeDef structure which will be
- * initialized.
- * @retval None
- */
-void RTC_TimeStructInit(RTC_TimeTypeDef* RTC_TimeStruct)
-{
- /* Time = 00h:00min:00sec */
- RTC_TimeStruct->RTC_H12 = RTC_H12_AM;
- RTC_TimeStruct->RTC_Hours = 0;
- RTC_TimeStruct->RTC_Minutes = 0;
- RTC_TimeStruct->RTC_Seconds = 0;
-}
-
-/**
- * @brief Get the RTC current Time.
- * @param RTC_Format: specifies the format of the returned parameters.
- * This parameter can be one of the following values:
- * @arg RTC_Format_BIN: Binary data format
- * @arg RTC_Format_BCD: BCD data format
- * @param RTC_TimeStruct: pointer to a RTC_TimeTypeDef structure that will
- * contain the returned current time configuration.
- * @retval None
- */
-void RTC_GetTime(uint32_t RTC_Format, RTC_TimeTypeDef* RTC_TimeStruct)
-{
- uint32_t tmpreg = 0;
-
- /* Check the parameters */
- assert_param(IS_RTC_FORMAT(RTC_Format));
-
- /* Get the RTC_TR register */
- tmpreg = (uint32_t)(RTC->TR & RTC_TR_RESERVED_MASK);
-
- /* Fill the structure fields with the read parameters */
- RTC_TimeStruct->RTC_Hours = (uint8_t)((tmpreg & (RTC_TR_HT | RTC_TR_HU)) >> 16);
- RTC_TimeStruct->RTC_Minutes = (uint8_t)((tmpreg & (RTC_TR_MNT | RTC_TR_MNU)) >>8);
- RTC_TimeStruct->RTC_Seconds = (uint8_t)(tmpreg & (RTC_TR_ST | RTC_TR_SU));
- RTC_TimeStruct->RTC_H12 = (uint8_t)((tmpreg & (RTC_TR_PM)) >> 16);
-
- /* Check the input parameters format */
- if (RTC_Format == RTC_Format_BIN)
- {
- /* Convert the structure parameters to Binary format */
- RTC_TimeStruct->RTC_Hours = (uint8_t)RTC_Bcd2ToByte(RTC_TimeStruct->RTC_Hours);
- RTC_TimeStruct->RTC_Minutes = (uint8_t)RTC_Bcd2ToByte(RTC_TimeStruct->RTC_Minutes);
- RTC_TimeStruct->RTC_Seconds = (uint8_t)RTC_Bcd2ToByte(RTC_TimeStruct->RTC_Seconds);
- }
-}
-
-/**
- * @brief Gets the RTC current Calendar Subseconds value.
- * @note This function freeze the Time and Date registers after reading the
- * SSR register.
- * @param None
- * @retval RTC current Calendar Subseconds value.
- */
-uint32_t RTC_GetSubSecond(void)
-{
- uint32_t tmpreg = 0;
-
- /* Get subseconds values from the correspondent registers*/
- tmpreg = (uint32_t)(RTC->SSR);
-
- /* Read DR register to unfroze calendar registers */
- (void) (RTC->DR);
-
- return (tmpreg);
-}
-
-/**
- * @brief Set the RTC current date.
- * @param RTC_Format: specifies the format of the entered parameters.
- * This parameter can be one of the following values:
- * @arg RTC_Format_BIN: Binary data format
- * @arg RTC_Format_BCD: BCD data format
- * @param RTC_DateStruct: pointer to a RTC_DateTypeDef structure that contains
- * the date configuration information for the RTC.
- * @retval An ErrorStatus enumeration value:
- * - SUCCESS: RTC Date register is configured
- * - ST_ERROR: RTC Date register is not configured
- */
-ErrorStatus RTC_SetDate(uint32_t RTC_Format, RTC_DateTypeDef* RTC_DateStruct)
-{
- uint32_t tmpreg = 0;
- ErrorStatus status = ST_ERROR;
-
- /* Check the parameters */
- assert_param(IS_RTC_FORMAT(RTC_Format));
-
- if ((RTC_Format == RTC_Format_BIN) && ((RTC_DateStruct->RTC_Month & 0x10) == 0x10))
- {
- RTC_DateStruct->RTC_Month = (RTC_DateStruct->RTC_Month & (uint32_t)~(0x10)) + 0x0A;
- }
- if (RTC_Format == RTC_Format_BIN)
- {
- assert_param(IS_RTC_YEAR(RTC_DateStruct->RTC_Year));
- assert_param(IS_RTC_MONTH(RTC_DateStruct->RTC_Month));
- assert_param(IS_RTC_DATE(RTC_DateStruct->RTC_Date));
- }
- else
- {
- assert_param(IS_RTC_YEAR(RTC_Bcd2ToByte(RTC_DateStruct->RTC_Year)));
- tmpreg = RTC_Bcd2ToByte(RTC_DateStruct->RTC_Month);
- assert_param(IS_RTC_MONTH(tmpreg));
- tmpreg = RTC_Bcd2ToByte(RTC_DateStruct->RTC_Date);
- assert_param(IS_RTC_DATE(tmpreg));
- }
- assert_param(IS_RTC_WEEKDAY(RTC_DateStruct->RTC_WeekDay));
-
- /* Check the input parameters format */
- if (RTC_Format != RTC_Format_BIN)
- {
- tmpreg = ((((uint32_t)RTC_DateStruct->RTC_Year) << 16) | \
- (((uint32_t)RTC_DateStruct->RTC_Month) << 8) | \
- ((uint32_t)RTC_DateStruct->RTC_Date) | \
- (((uint32_t)RTC_DateStruct->RTC_WeekDay) << 13));
- }
- else
- {
- tmpreg = (((uint32_t)RTC_ByteToBcd2(RTC_DateStruct->RTC_Year) << 16) | \
- ((uint32_t)RTC_ByteToBcd2(RTC_DateStruct->RTC_Month) << 8) | \
- ((uint32_t)RTC_ByteToBcd2(RTC_DateStruct->RTC_Date)) | \
- ((uint32_t)RTC_DateStruct->RTC_WeekDay << 13));
- }
-
- /* Disable the write protection for RTC registers */
- RTC->WPR = 0xCA;
- RTC->WPR = 0x53;
-
- /* Set Initialization mode */
- if (RTC_EnterInitMode() == ST_ERROR)
- {
- status = ST_ERROR;
- }
- else
- {
- /* Set the RTC_DR register */
- RTC->DR = (uint32_t)(tmpreg & RTC_DR_RESERVED_MASK);
-
- /* Exit Initialization mode */
- RTC_ExitInitMode();
-
- if(RTC_WaitForSynchro() == ST_ERROR)
- {
- status = ST_ERROR;
- }
- else
- {
- status = SUCCESS;
- }
- }
- /* Enable the write protection for RTC registers */
- RTC->WPR = 0xFF;
-
- return status;
-}
-
-/**
- * @brief Fills each RTC_DateStruct member with its default value
- * (Monday, January 01 xx00).
- * @param RTC_DateStruct: pointer to a RTC_DateTypeDef structure which will be
- * initialized.
- * @retval None
- */
-void RTC_DateStructInit(RTC_DateTypeDef* RTC_DateStruct)
-{
- /* Monday, January 01 xx00 */
- RTC_DateStruct->RTC_WeekDay = RTC_Weekday_Monday;
- RTC_DateStruct->RTC_Date = 1;
- RTC_DateStruct->RTC_Month = RTC_Month_January;
- RTC_DateStruct->RTC_Year = 0;
-}
-
-/**
- * @brief Get the RTC current date.
- * @param RTC_Format: specifies the format of the returned parameters.
- * This parameter can be one of the following values:
- * @arg RTC_Format_BIN: Binary data format
- * @arg RTC_Format_BCD: BCD data format
- * @param RTC_DateStruct: pointer to a RTC_DateTypeDef structure that will
- * contain the returned current date configuration.
- * @retval None
- */
-void RTC_GetDate(uint32_t RTC_Format, RTC_DateTypeDef* RTC_DateStruct)
-{
- uint32_t tmpreg = 0;
-
- /* Check the parameters */
- assert_param(IS_RTC_FORMAT(RTC_Format));
-
- /* Get the RTC_TR register */
- tmpreg = (uint32_t)(RTC->DR & RTC_DR_RESERVED_MASK);
-
- /* Fill the structure fields with the read parameters */
- RTC_DateStruct->RTC_Year = (uint8_t)((tmpreg & (RTC_DR_YT | RTC_DR_YU)) >> 16);
- RTC_DateStruct->RTC_Month = (uint8_t)((tmpreg & (RTC_DR_MT | RTC_DR_MU)) >> 8);
- RTC_DateStruct->RTC_Date = (uint8_t)(tmpreg & (RTC_DR_DT | RTC_DR_DU));
- RTC_DateStruct->RTC_WeekDay = (uint8_t)((tmpreg & (RTC_DR_WDU)) >> 13);
-
- /* Check the input parameters format */
- if (RTC_Format == RTC_Format_BIN)
- {
- /* Convert the structure parameters to Binary format */
- RTC_DateStruct->RTC_Year = (uint8_t)RTC_Bcd2ToByte(RTC_DateStruct->RTC_Year);
- RTC_DateStruct->RTC_Month = (uint8_t)RTC_Bcd2ToByte(RTC_DateStruct->RTC_Month);
- RTC_DateStruct->RTC_Date = (uint8_t)RTC_Bcd2ToByte(RTC_DateStruct->RTC_Date);
- }
-}
-
-/**
- * @}
- */
-
-/** @defgroup RTC_Group3 Alarms configuration functions
- * @brief Alarms (Alarm A and Alarm B) configuration functions
- *
-@verbatim
- ===============================================================================
- Alarms (Alarm A and Alarm B) configuration functions
- ===============================================================================
-
- This section provide functions allowing to program and read the RTC Alarms.
-
-@endverbatim
- * @{
- */
-
-/**
- * @brief Set the specified RTC Alarm.
- * @note The Alarm register can only be written when the corresponding Alarm
- * is disabled (Use the RTC_AlarmCmd(DISABLE)).
- * @param RTC_Format: specifies the format of the returned parameters.
- * This parameter can be one of the following values:
- * @arg RTC_Format_BIN: Binary data format
- * @arg RTC_Format_BCD: BCD data format
- * @param RTC_Alarm: specifies the alarm to be configured.
- * This parameter can be one of the following values:
- * @arg RTC_Alarm_A: to select Alarm A
- * @arg RTC_Alarm_B: to select Alarm B
- * @param RTC_AlarmStruct: pointer to a RTC_AlarmTypeDef structure that
- * contains the alarm configuration parameters.
- * @retval None
- */
-void RTC_SetAlarm(uint32_t RTC_Format, uint32_t RTC_Alarm, RTC_AlarmTypeDef* RTC_AlarmStruct)
-{
- uint32_t tmpreg = 0;
-
- /* Check the parameters */
- assert_param(IS_RTC_FORMAT(RTC_Format));
- assert_param(IS_RTC_ALARM(RTC_Alarm));
- assert_param(IS_ALARM_MASK(RTC_AlarmStruct->RTC_AlarmMask));
- assert_param(IS_RTC_ALARM_DATE_WEEKDAY_SEL(RTC_AlarmStruct->RTC_AlarmDateWeekDaySel));
-
- if (RTC_Format == RTC_Format_BIN)
- {
- if ((RTC->CR & RTC_CR_FMT) != (uint32_t)RESET)
- {
- assert_param(IS_RTC_HOUR12(RTC_AlarmStruct->RTC_AlarmTime.RTC_Hours));
- assert_param(IS_RTC_H12(RTC_AlarmStruct->RTC_AlarmTime.RTC_H12));
- }
- else
- {
- RTC_AlarmStruct->RTC_AlarmTime.RTC_H12 = 0x00;
- assert_param(IS_RTC_HOUR24(RTC_AlarmStruct->RTC_AlarmTime.RTC_Hours));
- }
- assert_param(IS_RTC_MINUTES(RTC_AlarmStruct->RTC_AlarmTime.RTC_Minutes));
- assert_param(IS_RTC_SECONDS(RTC_AlarmStruct->RTC_AlarmTime.RTC_Seconds));
-
- if(RTC_AlarmStruct->RTC_AlarmDateWeekDaySel == RTC_AlarmDateWeekDaySel_Date)
- {
- assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(RTC_AlarmStruct->RTC_AlarmDateWeekDay));
- }
- else
- {
- assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(RTC_AlarmStruct->RTC_AlarmDateWeekDay));
- }
- }
- else
- {
- if ((RTC->CR & RTC_CR_FMT) != (uint32_t)RESET)
- {
- tmpreg = RTC_Bcd2ToByte(RTC_AlarmStruct->RTC_AlarmTime.RTC_Hours);
- assert_param(IS_RTC_HOUR12(tmpreg));
- assert_param(IS_RTC_H12(RTC_AlarmStruct->RTC_AlarmTime.RTC_H12));
- }
- else
- {
- RTC_AlarmStruct->RTC_AlarmTime.RTC_H12 = 0x00;
- assert_param(IS_RTC_HOUR24(RTC_Bcd2ToByte(RTC_AlarmStruct->RTC_AlarmTime.RTC_Hours)));
- }
-
- assert_param(IS_RTC_MINUTES(RTC_Bcd2ToByte(RTC_AlarmStruct->RTC_AlarmTime.RTC_Minutes)));
- assert_param(IS_RTC_SECONDS(RTC_Bcd2ToByte(RTC_AlarmStruct->RTC_AlarmTime.RTC_Seconds)));
-
- if(RTC_AlarmStruct->RTC_AlarmDateWeekDaySel == RTC_AlarmDateWeekDaySel_Date)
- {
- tmpreg = RTC_Bcd2ToByte(RTC_AlarmStruct->RTC_AlarmDateWeekDay);
- assert_param(IS_RTC_ALARM_DATE_WEEKDAY_DATE(tmpreg));
- }
- else
- {
- tmpreg = RTC_Bcd2ToByte(RTC_AlarmStruct->RTC_AlarmDateWeekDay);
- assert_param(IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(tmpreg));
- }
- }
-
- /* Check the input parameters format */
- if (RTC_Format != RTC_Format_BIN)
- {
- tmpreg = (((uint32_t)(RTC_AlarmStruct->RTC_AlarmTime.RTC_Hours) << 16) | \
- ((uint32_t)(RTC_AlarmStruct->RTC_AlarmTime.RTC_Minutes) << 8) | \
- ((uint32_t)RTC_AlarmStruct->RTC_AlarmTime.RTC_Seconds) | \
- ((uint32_t)(RTC_AlarmStruct->RTC_AlarmTime.RTC_H12) << 16) | \
- ((uint32_t)(RTC_AlarmStruct->RTC_AlarmDateWeekDay) << 24) | \
- ((uint32_t)RTC_AlarmStruct->RTC_AlarmDateWeekDaySel) | \
- ((uint32_t)RTC_AlarmStruct->RTC_AlarmMask));
- }
- else
- {
- tmpreg = (((uint32_t)RTC_ByteToBcd2(RTC_AlarmStruct->RTC_AlarmTime.RTC_Hours) << 16) | \
- ((uint32_t)RTC_ByteToBcd2(RTC_AlarmStruct->RTC_AlarmTime.RTC_Minutes) << 8) | \
- ((uint32_t)RTC_ByteToBcd2(RTC_AlarmStruct->RTC_AlarmTime.RTC_Seconds)) | \
- ((uint32_t)(RTC_AlarmStruct->RTC_AlarmTime.RTC_H12) << 16) | \
- ((uint32_t)RTC_ByteToBcd2(RTC_AlarmStruct->RTC_AlarmDateWeekDay) << 24) | \
- ((uint32_t)RTC_AlarmStruct->RTC_AlarmDateWeekDaySel) | \
- ((uint32_t)RTC_AlarmStruct->RTC_AlarmMask));
- }
-
- /* Disable the write protection for RTC registers */
- RTC->WPR = 0xCA;
- RTC->WPR = 0x53;
-
- /* Configure the Alarm register */
- if (RTC_Alarm == RTC_Alarm_A)
- {
- RTC->ALRMAR = (uint32_t)tmpreg;
- }
- else
- {
- RTC->ALRMBR = (uint32_t)tmpreg;
- }
-
- /* Enable the write protection for RTC registers */
- RTC->WPR = 0xFF;
-}
-
-/**
- * @brief Fills each RTC_AlarmStruct member with its default value
- * (Time = 00h:00mn:00sec / Date = 1st day of the month/Mask =
- * all fields are masked).
- * @param RTC_AlarmStruct: pointer to a @ref RTC_AlarmTypeDef structure which
- * will be initialized.
- * @retval None
- */
-void RTC_AlarmStructInit(RTC_AlarmTypeDef* RTC_AlarmStruct)
-{
- /* Alarm Time Settings : Time = 00h:00mn:00sec */
- RTC_AlarmStruct->RTC_AlarmTime.RTC_H12 = RTC_H12_AM;
- RTC_AlarmStruct->RTC_AlarmTime.RTC_Hours = 0;
- RTC_AlarmStruct->RTC_AlarmTime.RTC_Minutes = 0;
- RTC_AlarmStruct->RTC_AlarmTime.RTC_Seconds = 0;
-
- /* Alarm Date Settings : Date = 1st day of the month */
- RTC_AlarmStruct->RTC_AlarmDateWeekDaySel = RTC_AlarmDateWeekDaySel_Date;
- RTC_AlarmStruct->RTC_AlarmDateWeekDay = 1;
-
- /* Alarm Masks Settings : Mask = all fields are not masked */
- RTC_AlarmStruct->RTC_AlarmMask = RTC_AlarmMask_None;
-}
-
-/**
- * @brief Get the RTC Alarm value and masks.
- * @param RTC_Format: specifies the format of the output parameters.
- * This parameter can be one of the following values:
- * @arg RTC_Format_BIN: Binary data format
- * @arg RTC_Format_BCD: BCD data format
- * @param RTC_Alarm: specifies the alarm to be read.
- * This parameter can be one of the following values:
- * @arg RTC_Alarm_A: to select Alarm A
- * @arg RTC_Alarm_B: to select Alarm B
- * @param RTC_AlarmStruct: pointer to a RTC_AlarmTypeDef structure that will
- * contains the output alarm configuration values.
- * @retval None
- */
-void RTC_GetAlarm(uint32_t RTC_Format, uint32_t RTC_Alarm, RTC_AlarmTypeDef* RTC_AlarmStruct)
-{
- uint32_t tmpreg = 0;
-
- /* Check the parameters */
- assert_param(IS_RTC_FORMAT(RTC_Format));
- assert_param(IS_RTC_ALARM(RTC_Alarm));
-
- /* Get the RTC_ALRMxR register */
- if (RTC_Alarm == RTC_Alarm_A)
- {
- tmpreg = (uint32_t)(RTC->ALRMAR);
- }
- else
- {
- tmpreg = (uint32_t)(RTC->ALRMBR);
- }
-
- /* Fill the structure with the read parameters */
- RTC_AlarmStruct->RTC_AlarmTime.RTC_Hours = (uint32_t)((tmpreg & (RTC_ALRMAR_HT | \
- RTC_ALRMAR_HU)) >> 16);
- RTC_AlarmStruct->RTC_AlarmTime.RTC_Minutes = (uint32_t)((tmpreg & (RTC_ALRMAR_MNT | \
- RTC_ALRMAR_MNU)) >> 8);
- RTC_AlarmStruct->RTC_AlarmTime.RTC_Seconds = (uint32_t)(tmpreg & (RTC_ALRMAR_ST | \
- RTC_ALRMAR_SU));
- RTC_AlarmStruct->RTC_AlarmTime.RTC_H12 = (uint32_t)((tmpreg & RTC_ALRMAR_PM) >> 16);
- RTC_AlarmStruct->RTC_AlarmDateWeekDay = (uint32_t)((tmpreg & (RTC_ALRMAR_DT | RTC_ALRMAR_DU)) >> 24);
- RTC_AlarmStruct->RTC_AlarmDateWeekDaySel = (uint32_t)(tmpreg & RTC_ALRMAR_WDSEL);
- RTC_AlarmStruct->RTC_AlarmMask = (uint32_t)(tmpreg & RTC_AlarmMask_All);
-
- if (RTC_Format == RTC_Format_BIN)
- {
- RTC_AlarmStruct->RTC_AlarmTime.RTC_Hours = RTC_Bcd2ToByte(RTC_AlarmStruct-> \
- RTC_AlarmTime.RTC_Hours);
- RTC_AlarmStruct->RTC_AlarmTime.RTC_Minutes = RTC_Bcd2ToByte(RTC_AlarmStruct-> \
- RTC_AlarmTime.RTC_Minutes);
- RTC_AlarmStruct->RTC_AlarmTime.RTC_Seconds = RTC_Bcd2ToByte(RTC_AlarmStruct-> \
- RTC_AlarmTime.RTC_Seconds);
- RTC_AlarmStruct->RTC_AlarmDateWeekDay = RTC_Bcd2ToByte(RTC_AlarmStruct->RTC_AlarmDateWeekDay);
- }
-}
-
-/**
- * @brief Enables or disables the specified RTC Alarm.
- * @param RTC_Alarm: specifies the alarm to be configured.
- * This parameter can be any combination of the following values:
- * @arg RTC_Alarm_A: to select Alarm A
- * @arg RTC_Alarm_B: to select Alarm B
- * @param NewState: new state of the specified alarm.
- * This parameter can be: ENABLE or DISABLE.
- * @retval An ErrorStatus enumeration value:
- * - SUCCESS: RTC Alarm is enabled/disabled
- * - ST_ERROR: RTC Alarm is not enabled/disabled
- */
-ErrorStatus RTC_AlarmCmd(uint32_t RTC_Alarm, FunctionalState NewState)
-{
- __IO uint32_t alarmcounter = 0x00;
- uint32_t alarmstatus = 0x00;
- ErrorStatus status = ST_ERROR;
-
- /* Check the parameters */
- assert_param(IS_RTC_CMD_ALARM(RTC_Alarm));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- /* Disable the write protection for RTC registers */
- RTC->WPR = 0xCA;
- RTC->WPR = 0x53;
-
- /* Configure the Alarm state */
- if (NewState != DISABLE)
- {
- RTC->CR |= (uint32_t)RTC_Alarm;
-
- status = SUCCESS;
- }
- else
- {
- /* Disable the Alarm in RTC_CR register */
- RTC->CR &= (uint32_t)~RTC_Alarm;
-
- /* Wait till RTC ALRxWF flag is set and if Time out is reached exit */
- do
- {
- alarmstatus = RTC->ISR & (RTC_Alarm >> 8);
- alarmcounter++;
- } while((alarmcounter != INITMODE_TIMEOUT) && (alarmstatus == 0x00));
-
- if ((RTC->ISR & (RTC_Alarm >> 8)) == RESET)
- {
- status = ST_ERROR;
- }
- else
- {
- status = SUCCESS;
- }
- }
-
- /* Enable the write protection for RTC registers */
- RTC->WPR = 0xFF;
-
- return status;
-}
-
-/**
- * @brief Configure the RTC AlarmA/B Subseconds value and mask.*
- * @note This function is performed only when the Alarm is disabled.
- * @param RTC_Alarm: specifies the alarm to be configured.
- * This parameter can be one of the following values:
- * @arg RTC_Alarm_A: to select Alarm A
- * @arg RTC_Alarm_B: to select Alarm B
- * @param RTC_AlarmSubSecondValue: specifies the Subseconds value.
- * This parameter can be a value from 0 to 0x00007FFF.
- * @param RTC_AlarmSubSecondMask: specifies the Subseconds Mask.
- * This parameter can be any combination of the following values:
- * @arg RTC_AlarmSubSecondMask_All : All Alarm SS fields are masked.
- * There is no comparison on sub seconds for Alarm.
- * @arg RTC_AlarmSubSecondMask_SS14_1 : SS[14:1] are don't care in Alarm comparison.
- * Only SS[0] is compared
- * @arg RTC_AlarmSubSecondMask_SS14_2 : SS[14:2] are don't care in Alarm comparison.
- * Only SS[1:0] are compared
- * @arg RTC_AlarmSubSecondMask_SS14_3 : SS[14:3] are don't care in Alarm comparison.
- * Only SS[2:0] are compared
- * @arg RTC_AlarmSubSecondMask_SS14_4 : SS[14:4] are don't care in Alarm comparison.
- * Only SS[3:0] are compared
- * @arg RTC_AlarmSubSecondMask_SS14_5 : SS[14:5] are don't care in Alarm comparison.
- * Only SS[4:0] are compared
- * @arg RTC_AlarmSubSecondMask_SS14_6 : SS[14:6] are don't care in Alarm comparison.
- * Only SS[5:0] are compared
- * @arg RTC_AlarmSubSecondMask_SS14_7 : SS[14:7] are don't care in Alarm comparison.
- * Only SS[6:0] are compared
- * @arg RTC_AlarmSubSecondMask_SS14_8 : SS[14:8] are don't care in Alarm comparison.
- * Only SS[7:0] are compared
- * @arg RTC_AlarmSubSecondMask_SS14_9 : SS[14:9] are don't care in Alarm comparison.
- * Only SS[8:0] are compared
- * @arg RTC_AlarmSubSecondMask_SS14_10: SS[14:10] are don't care in Alarm comparison.
- * Only SS[9:0] are compared
- * @arg RTC_AlarmSubSecondMask_SS14_11: SS[14:11] are don't care in Alarm comparison.
- * Only SS[10:0] are compared
- * @arg RTC_AlarmSubSecondMask_SS14_12: SS[14:12] are don't care in Alarm comparison.
- * Only SS[11:0] are compared
- * @arg RTC_AlarmSubSecondMask_SS14_13: SS[14:13] are don't care in Alarm comparison.
- * Only SS[12:0] are compared
- * @arg RTC_AlarmSubSecondMask_SS14 : SS[14] is don't care in Alarm comparison.
- * Only SS[13:0] are compared
- * @arg RTC_AlarmSubSecondMask_None : SS[14:0] are compared and must match
- * to activate alarm
- * @retval None
- */
-void RTC_AlarmSubSecondConfig(uint32_t RTC_Alarm, uint32_t RTC_AlarmSubSecondValue, uint32_t RTC_AlarmSubSecondMask)
-{
- uint32_t tmpreg = 0;
-
- /* Check the parameters */
- assert_param(IS_RTC_ALARM(RTC_Alarm));
- assert_param(IS_RTC_ALARM_SUB_SECOND_VALUE(RTC_AlarmSubSecondValue));
- assert_param(IS_RTC_ALARM_SUB_SECOND_MASK(RTC_AlarmSubSecondMask));
-
- /* Disable the write protection for RTC registers */
- RTC->WPR = 0xCA;
- RTC->WPR = 0x53;
-
- /* Configure the Alarm A or Alarm B SubSecond registers */
- tmpreg = (uint32_t) (uint32_t)(RTC_AlarmSubSecondValue) | (uint32_t)(RTC_AlarmSubSecondMask);
-
- if (RTC_Alarm == RTC_Alarm_A)
- {
- /* Configure the AlarmA SubSecond register */
- RTC->ALRMASSR = tmpreg;
- }
- else
- {
- /* Configure the Alarm B SubSecond register */
- RTC->ALRMBSSR = tmpreg;
- }
-
- /* Enable the write protection for RTC registers */
- RTC->WPR = 0xFF;
-
-}
-
-/**
- * @brief Gets the RTC Alarm Subseconds value.
- * @param RTC_Alarm: specifies the alarm to be read.
- * This parameter can be one of the following values:
- * @arg RTC_Alarm_A: to select Alarm A
- * @arg RTC_Alarm_B: to select Alarm B
- * @param None
- * @retval RTC Alarm Subseconds value.
- */
-uint32_t RTC_GetAlarmSubSecond(uint32_t RTC_Alarm)
-{
- uint32_t tmpreg = 0;
-
- /* Get the RTC_ALRMxR register */
- if (RTC_Alarm == RTC_Alarm_A)
- {
- tmpreg = (uint32_t)((RTC->ALRMASSR) & RTC_ALRMASSR_SS);
- }
- else
- {
- tmpreg = (uint32_t)((RTC->ALRMBSSR) & RTC_ALRMBSSR_SS);
- }
-
- return (tmpreg);
-}
-
-/**
- * @}
- */
-
-/** @defgroup RTC_Group4 WakeUp Timer configuration functions
- * @brief WakeUp Timer configuration functions
- *
-@verbatim
- ===============================================================================
- WakeUp Timer configuration functions
- ===============================================================================
-
- This section provide functions allowing to program and read the RTC WakeUp.
-
-@endverbatim
- * @{
- */
-
-/**
- * @brief Configures the RTC Wakeup clock source.
- * @note The WakeUp Clock source can only be changed when the RTC WakeUp
- * is disabled (Use the RTC_WakeUpCmd(DISABLE)).
- * @param RTC_WakeUpClock: Wakeup Clock source.
- * This parameter can be one of the following values:
- * @arg RTC_WakeUpClock_RTCCLK_Div16: RTC Wakeup Counter Clock = RTCCLK/16
- * @arg RTC_WakeUpClock_RTCCLK_Div8: RTC Wakeup Counter Clock = RTCCLK/8
- * @arg RTC_WakeUpClock_RTCCLK_Div4: RTC Wakeup Counter Clock = RTCCLK/4
- * @arg RTC_WakeUpClock_RTCCLK_Div2: RTC Wakeup Counter Clock = RTCCLK/2
- * @arg RTC_WakeUpClock_CK_SPRE_16bits: RTC Wakeup Counter Clock = CK_SPRE
- * @arg RTC_WakeUpClock_CK_SPRE_17bits: RTC Wakeup Counter Clock = CK_SPRE
- * @retval None
- */
-void RTC_WakeUpClockConfig(uint32_t RTC_WakeUpClock)
-{
- /* Check the parameters */
- assert_param(IS_RTC_WAKEUP_CLOCK(RTC_WakeUpClock));
-
- /* Disable the write protection for RTC registers */
- RTC->WPR = 0xCA;
- RTC->WPR = 0x53;
-
- /* Clear the Wakeup Timer clock source bits in CR register */
- RTC->CR &= (uint32_t)~RTC_CR_WUCKSEL;
-
- /* Configure the clock source */
- RTC->CR |= (uint32_t)RTC_WakeUpClock;
-
- /* Enable the write protection for RTC registers */
- RTC->WPR = 0xFF;
-}
-
-/**
- * @brief Configures the RTC Wakeup counter.
- * @note The RTC WakeUp counter can only be written when the RTC WakeUp
- * is disabled (Use the RTC_WakeUpCmd(DISABLE)).
- * @param RTC_WakeUpCounter: specifies the WakeUp counter.
- * This parameter can be a value from 0x0000 to 0xFFFF.
- * @retval None
- */
-void RTC_SetWakeUpCounter(uint32_t RTC_WakeUpCounter)
-{
- /* Check the parameters */
- assert_param(IS_RTC_WAKEUP_COUNTER(RTC_WakeUpCounter));
-
- /* Disable the write protection for RTC registers */
- RTC->WPR = 0xCA;
- RTC->WPR = 0x53;
-
- /* Configure the Wakeup Timer counter */
- RTC->WUTR = (uint32_t)RTC_WakeUpCounter;
-
- /* Enable the write protection for RTC registers */
- RTC->WPR = 0xFF;
-}
-
-/**
- * @brief Returns the RTC WakeUp timer counter value.
- * @param None
- * @retval The RTC WakeUp Counter value.
- */
-uint32_t RTC_GetWakeUpCounter(void)
-{
- /* Get the counter value */
- return ((uint32_t)(RTC->WUTR & RTC_WUTR_WUT));
-}
-
-/**
- * @brief Enables or Disables the RTC WakeUp timer.
- * @param NewState: new state of the WakeUp timer.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-ErrorStatus RTC_WakeUpCmd(FunctionalState NewState)
-{
- __IO uint32_t wutcounter = 0x00;
- uint32_t wutwfstatus = 0x00;
- ErrorStatus status = ST_ERROR;
-
- /* Check the parameters */
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- /* Disable the write protection for RTC registers */
- RTC->WPR = 0xCA;
- RTC->WPR = 0x53;
-
- if (NewState != DISABLE)
- {
- /* Enable the Wakeup Timer */
- RTC->CR |= (uint32_t)RTC_CR_WUTE;
- status = SUCCESS;
- }
- else
- {
- /* Disable the Wakeup Timer */
- RTC->CR &= (uint32_t)~RTC_CR_WUTE;
- /* Wait till RTC WUTWF flag is set and if Time out is reached exit */
- do
- {
- wutwfstatus = RTC->ISR & RTC_ISR_WUTWF;
- wutcounter++;
- } while((wutcounter != INITMODE_TIMEOUT) && (wutwfstatus == 0x00));
-
- if ((RTC->ISR & RTC_ISR_WUTWF) == RESET)
- {
- status = ST_ERROR;
- }
- else
- {
- status = SUCCESS;
- }
- }
-
- /* Enable the write protection for RTC registers */
- RTC->WPR = 0xFF;
-
- return status;
-}
-
-/**
- * @}
- */
-
-/** @defgroup RTC_Group5 Daylight Saving configuration functions
- * @brief Daylight Saving configuration functions
- *
-@verbatim
- ===============================================================================
- Daylight Saving configuration functions
- ===============================================================================
-
- This section provide functions allowing to configure the RTC DayLight Saving.
-
-@endverbatim
- * @{
- */
-
-/**
- * @brief Adds or substract one hour from the current time.
- * @param RTC_DayLightSaveOperation: the value of hour adjustment.
- * This parameter can be one of the following values:
- * @arg RTC_DayLightSaving_SUB1H: Substract one hour (winter time)
- * @arg RTC_DayLightSaving_ADD1H: Add one hour (summer time)
- * @param RTC_StoreOperation: Specifies the value to be written in the BCK bit
- * in CR register to store the operation.
- * This parameter can be one of the following values:
- * @arg RTC_StoreOperation_Reset: BCK Bit Reset
- * @arg RTC_StoreOperation_Set: BCK Bit Set
- * @retval None
- */
-void RTC_DayLightSavingConfig(uint32_t RTC_DayLightSaving, uint32_t RTC_StoreOperation)
-{
- /* Check the parameters */
- assert_param(IS_RTC_DAYLIGHT_SAVING(RTC_DayLightSaving));
- assert_param(IS_RTC_STORE_OPERATION(RTC_StoreOperation));
-
- /* Disable the write protection for RTC registers */
- RTC->WPR = 0xCA;
- RTC->WPR = 0x53;
-
- /* Clear the bits to be configured */
- RTC->CR &= (uint32_t)~(RTC_CR_BCK);
-
- /* Configure the RTC_CR register */
- RTC->CR |= (uint32_t)(RTC_DayLightSaving | RTC_StoreOperation);
-
- /* Enable the write protection for RTC registers */
- RTC->WPR = 0xFF;
-}
-
-/**
- * @brief Returns the RTC Day Light Saving stored operation.
- * @param None
- * @retval RTC Day Light Saving stored operation.
- * - RTC_StoreOperation_Reset
- * - RTC_StoreOperation_Set
- */
-uint32_t RTC_GetStoreOperation(void)
-{
- return (RTC->CR & RTC_CR_BCK);
-}
-
-/**
- * @}
- */
-
-/** @defgroup RTC_Group6 Output pin Configuration function
- * @brief Output pin Configuration function
- *
-@verbatim
- ===============================================================================
- Output pin Configuration function
- ===============================================================================
-
- This section provide functions allowing to configure the RTC Output source.
-
-@endverbatim
- * @{
- */
-
-/**
- * @brief Configures the RTC output source (AFO_ALARM).
- * @param RTC_Output: Specifies which signal will be routed to the RTC output.
- * This parameter can be one of the following values:
- * @arg RTC_Output_Disable: No output selected
- * @arg RTC_Output_AlarmA: signal of AlarmA mapped to output
- * @arg RTC_Output_AlarmB: signal of AlarmB mapped to output
- * @arg RTC_Output_WakeUp: signal of WakeUp mapped to output
- * @param RTC_OutputPolarity: Specifies the polarity of the output signal.
- * This parameter can be one of the following:
- * @arg RTC_OutputPolarity_High: The output pin is high when the
- * ALRAF/ALRBF/WUTF is high (depending on OSEL)
- * @arg RTC_OutputPolarity_Low: The output pin is low when the
- * ALRAF/ALRBF/WUTF is high (depending on OSEL)
- * @retval None
- */
-void RTC_OutputConfig(uint32_t RTC_Output, uint32_t RTC_OutputPolarity)
-{
- /* Check the parameters */
- assert_param(IS_RTC_OUTPUT(RTC_Output));
- assert_param(IS_RTC_OUTPUT_POL(RTC_OutputPolarity));
-
- /* Disable the write protection for RTC registers */
- RTC->WPR = 0xCA;
- RTC->WPR = 0x53;
-
- /* Clear the bits to be configured */
- RTC->CR &= (uint32_t)~(RTC_CR_OSEL | RTC_CR_POL);
-
- /* Configure the output selection and polarity */
- RTC->CR |= (uint32_t)(RTC_Output | RTC_OutputPolarity);
-
- /* Enable the write protection for RTC registers */
- RTC->WPR = 0xFF;
-}
-
-/**
- * @}
- */
-
-/** @defgroup RTC_Group7 Digital Calibration configuration functions
- * @brief Coarse Calibration configuration functions
- *
-@verbatim
- ===============================================================================
- Digital Calibration configuration functions
- ===============================================================================
-
-@endverbatim
- * @{
- */
-
-/**
- * @brief Configures the Coarse calibration parameters.
- * @param RTC_CalibSign: specifies the sign of the coarse calibration value.
- * This parameter can be one of the following values:
- * @arg RTC_CalibSign_Positive: The value sign is positive
- * @arg RTC_CalibSign_Negative: The value sign is negative
- * @param Value: value of coarse calibration expressed in ppm (coded on 5 bits).
- *
- * @note This Calibration value should be between 0 and 63 when using negative
- * sign with a 2-ppm step.
- *
- * @note This Calibration value should be between 0 and 126 when using positive
- * sign with a 4-ppm step.
- *
- * @retval An ErrorStatus enumeration value:
- * - SUCCESS: RTC Coarse calibration are initialized
- * - ST_ERROR: RTC Coarse calibration are not initialized
- */
-ErrorStatus RTC_CoarseCalibConfig(uint32_t RTC_CalibSign, uint32_t Value)
-{
- ErrorStatus status = ST_ERROR;
-
- /* Check the parameters */
- assert_param(IS_RTC_CALIB_SIGN(RTC_CalibSign));
- assert_param(IS_RTC_CALIB_VALUE(Value));
-
- /* Disable the write protection for RTC registers */
- RTC->WPR = 0xCA;
- RTC->WPR = 0x53;
-
- /* Set Initialization mode */
- if (RTC_EnterInitMode() == ST_ERROR)
- {
- status = ST_ERROR;
- }
- else
- {
- /* Set the coarse calibration value */
- RTC->CALIBR = (uint32_t)(RTC_CalibSign | Value);
- /* Exit Initialization mode */
- RTC_ExitInitMode();
-
- status = SUCCESS;
- }
-
- /* Enable the write protection for RTC registers */
- RTC->WPR = 0xFF;
-
- return status;
-}
-
-/**
- * @brief Enables or disables the Coarse calibration process.
- * @param NewState: new state of the Coarse calibration.
- * This parameter can be: ENABLE or DISABLE.
- * @retval An ErrorStatus enumeration value:
- * - SUCCESS: RTC Coarse calibration are enabled/disabled
- * - ST_ERROR: RTC Coarse calibration are not enabled/disabled
- */
-ErrorStatus RTC_CoarseCalibCmd(FunctionalState NewState)
-{
- ErrorStatus status = ST_ERROR;
-
- /* Check the parameters */
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- /* Disable the write protection for RTC registers */
- RTC->WPR = 0xCA;
- RTC->WPR = 0x53;
-
- /* Set Initialization mode */
- if (RTC_EnterInitMode() == ST_ERROR)
- {
- status = ST_ERROR;
- }
- else
- {
- if (NewState != DISABLE)
- {
- /* Enable the Coarse Calibration */
- RTC->CR |= (uint32_t)RTC_CR_DCE;
- }
- else
- {
- /* Disable the Coarse Calibration */
- RTC->CR &= (uint32_t)~RTC_CR_DCE;
- }
- /* Exit Initialization mode */
- RTC_ExitInitMode();
-
- status = SUCCESS;
- }
-
- /* Enable the write protection for RTC registers */
- RTC->WPR = 0xFF;
-
- return status;
-}
-
-/**
- * @brief Enables or disables the RTC clock to be output through the relative pin.
- * @param NewState: new state of the digital calibration Output.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void RTC_CalibOutputCmd(FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- /* Disable the write protection for RTC registers */
- RTC->WPR = 0xCA;
- RTC->WPR = 0x53;
-
- if (NewState != DISABLE)
- {
- /* Enable the RTC clock output */
- RTC->CR |= (uint32_t)RTC_CR_COE;
- }
- else
- {
- /* Disable the RTC clock output */
- RTC->CR &= (uint32_t)~RTC_CR_COE;
- }
-
- /* Enable the write protection for RTC registers */
- RTC->WPR = 0xFF;
-}
-
-/**
- * @brief Configure the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz).
- * @param RTC_CalibOutput : Select the Calibration output Selection .
- * This parameter can be one of the following values:
- * @arg RTC_CalibOutput_512Hz: A signal has a regular waveform at 512Hz.
- * @arg RTC_CalibOutput_1Hz : A signal has a regular waveform at 1Hz.
- * @retval None
-*/
-void RTC_CalibOutputConfig(uint32_t RTC_CalibOutput)
-{
- /* Check the parameters */
- assert_param(IS_RTC_CALIB_OUTPUT(RTC_CalibOutput));
-
- /* Disable the write protection for RTC registers */
- RTC->WPR = 0xCA;
- RTC->WPR = 0x53;
-
- /*clear flags before config*/
- RTC->CR &= (uint32_t)~(RTC_CR_COSEL);
-
- /* Configure the RTC_CR register */
- RTC->CR |= (uint32_t)RTC_CalibOutput;
-
- /* Enable the write protection for RTC registers */
- RTC->WPR = 0xFF;
-}
-
-/**
- * @brief Configures the Smooth Calibration Settings.
- * @param RTC_SmoothCalibPeriod : Select the Smooth Calibration Period.
- * This parameter can be can be one of the following values:
- * @arg RTC_SmoothCalibPeriod_32sec : The smooth calibration periode is 32s.
- * @arg RTC_SmoothCalibPeriod_16sec : The smooth calibration periode is 16s.
- * @arg RTC_SmoothCalibPeriod_8sec : The smooth calibartion periode is 8s.
- * @param RTC_SmoothCalibPlusPulses : Select to Set or reset the CALP bit.
- * This parameter can be one of the following values:
- * @arg RTC_SmoothCalibPlusPulses_Set : Add one RTCCLK puls every 2**11 pulses.
- * @arg RTC_SmoothCalibPlusPulses_Reset: No RTCCLK pulses are added.
- * @param RTC_SmouthCalibMinusPulsesValue: Select the value of CALM[8:0] bits.
- * This parameter can be one any value from 0 to 0x000001FF.
- * @retval An ErrorStatus enumeration value:
- * - SUCCESS: RTC Calib registers are configured
- * - ST_ERROR: RTC Calib registers are not configured
-*/
-ErrorStatus RTC_SmoothCalibConfig(uint32_t RTC_SmoothCalibPeriod,
- uint32_t RTC_SmoothCalibPlusPulses,
- uint32_t RTC_SmouthCalibMinusPulsesValue)
-{
- ErrorStatus status = ST_ERROR;
- uint32_t recalpfcount = 0;
-
- /* Check the parameters */
- assert_param(IS_RTC_SMOOTH_CALIB_PERIOD(RTC_SmoothCalibPeriod));
- assert_param(IS_RTC_SMOOTH_CALIB_PLUS(RTC_SmoothCalibPlusPulses));
- assert_param(IS_RTC_SMOOTH_CALIB_MINUS(RTC_SmouthCalibMinusPulsesValue));
-
- /* Disable the write protection for RTC registers */
- RTC->WPR = 0xCA;
- RTC->WPR = 0x53;
-
- /* check if a calibration is pending*/
- if ((RTC->ISR & RTC_ISR_RECALPF) != RESET)
- {
- /* wait until the Calibration is completed*/
- while (((RTC->ISR & RTC_ISR_RECALPF) != RESET) && (recalpfcount != RECALPF_TIMEOUT))
- {
- recalpfcount++;
- }
- }
-
- /* check if the calibration pending is completed or if there is no calibration operation at all*/
- if ((RTC->ISR & RTC_ISR_RECALPF) == RESET)
- {
- /* Configure the Smooth calibration settings */
- RTC->CALR = (uint32_t)((uint32_t)RTC_SmoothCalibPeriod | (uint32_t)RTC_SmoothCalibPlusPulses | (uint32_t)RTC_SmouthCalibMinusPulsesValue);
-
- status = SUCCESS;
- }
- else
- {
- status = ST_ERROR;
- }
-
- /* Enable the write protection for RTC registers */
- RTC->WPR = 0xFF;
-
- return (ErrorStatus)(status);
-}
-
-/**
- * @}
- */
-
-
-/** @defgroup RTC_Group8 TimeStamp configuration functions
- * @brief TimeStamp configuration functions
- *
-@verbatim
- ===============================================================================
- TimeStamp configuration functions
- ===============================================================================
-
-@endverbatim
- * @{
- */
-
-/**
- * @brief Enables or Disables the RTC TimeStamp functionality with the
- * specified time stamp pin stimulating edge.
- * @param RTC_TimeStampEdge: Specifies the pin edge on which the TimeStamp is
- * activated.
- * This parameter can be one of the following:
- * @arg RTC_TimeStampEdge_Rising: the Time stamp event occurs on the rising
- * edge of the related pin.
- * @arg RTC_TimeStampEdge_Falling: the Time stamp event occurs on the
- * falling edge of the related pin.
- * @param NewState: new state of the TimeStamp.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void RTC_TimeStampCmd(uint32_t RTC_TimeStampEdge, FunctionalState NewState)
-{
- uint32_t tmpreg = 0;
-
- /* Check the parameters */
- assert_param(IS_RTC_TIMESTAMP_EDGE(RTC_TimeStampEdge));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- /* Get the RTC_CR register and clear the bits to be configured */
- tmpreg = (uint32_t)(RTC->CR & (uint32_t)~(RTC_CR_TSEDGE | RTC_CR_TSE));
-
- /* Get the new configuration */
- if (NewState != DISABLE)
- {
- tmpreg |= (uint32_t)(RTC_TimeStampEdge | RTC_CR_TSE);
- }
- else
- {
- tmpreg |= (uint32_t)(RTC_TimeStampEdge);
- }
-
- /* Disable the write protection for RTC registers */
- RTC->WPR = 0xCA;
- RTC->WPR = 0x53;
-
- /* Configure the Time Stamp TSEDGE and Enable bits */
- RTC->CR = (uint32_t)tmpreg;
-
- /* Enable the write protection for RTC registers */
- RTC->WPR = 0xFF;
-}
-
-/**
- * @brief Get the RTC TimeStamp value and masks.
- * @param RTC_Format: specifies the format of the output parameters.
- * This parameter can be one of the following values:
- * @arg RTC_Format_BIN: Binary data format
- * @arg RTC_Format_BCD: BCD data format
- * @param RTC_StampTimeStruct: pointer to a RTC_TimeTypeDef structure that will
- * contains the TimeStamp time values.
- * @param RTC_StampDateStruct: pointer to a RTC_DateTypeDef structure that will
- * contains the TimeStamp date values.
- * @retval None
- */
-void RTC_GetTimeStamp(uint32_t RTC_Format, RTC_TimeTypeDef* RTC_StampTimeStruct,
- RTC_DateTypeDef* RTC_StampDateStruct)
-{
- uint32_t tmptime = 0, tmpdate = 0;
-
- /* Check the parameters */
- assert_param(IS_RTC_FORMAT(RTC_Format));
-
- /* Get the TimeStamp time and date registers values */
- tmptime = (uint32_t)(RTC->TSTR & RTC_TR_RESERVED_MASK);
- tmpdate = (uint32_t)(RTC->TSDR & RTC_DR_RESERVED_MASK);
-
- /* Fill the Time structure fields with the read parameters */
- RTC_StampTimeStruct->RTC_Hours = (uint8_t)((tmptime & (RTC_TR_HT | RTC_TR_HU)) >> 16);
- RTC_StampTimeStruct->RTC_Minutes = (uint8_t)((tmptime & (RTC_TR_MNT | RTC_TR_MNU)) >> 8);
- RTC_StampTimeStruct->RTC_Seconds = (uint8_t)(tmptime & (RTC_TR_ST | RTC_TR_SU));
- RTC_StampTimeStruct->RTC_H12 = (uint8_t)((tmptime & (RTC_TR_PM)) >> 16);
-
- /* Fill the Date structure fields with the read parameters */
- RTC_StampDateStruct->RTC_Year = 0;
- RTC_StampDateStruct->RTC_Month = (uint8_t)((tmpdate & (RTC_DR_MT | RTC_DR_MU)) >> 8);
- RTC_StampDateStruct->RTC_Date = (uint8_t)(tmpdate & (RTC_DR_DT | RTC_DR_DU));
- RTC_StampDateStruct->RTC_WeekDay = (uint8_t)((tmpdate & (RTC_DR_WDU)) >> 13);
-
- /* Check the input parameters format */
- if (RTC_Format == RTC_Format_BIN)
- {
- /* Convert the Time structure parameters to Binary format */
- RTC_StampTimeStruct->RTC_Hours = (uint8_t)RTC_Bcd2ToByte(RTC_StampTimeStruct->RTC_Hours);
- RTC_StampTimeStruct->RTC_Minutes = (uint8_t)RTC_Bcd2ToByte(RTC_StampTimeStruct->RTC_Minutes);
- RTC_StampTimeStruct->RTC_Seconds = (uint8_t)RTC_Bcd2ToByte(RTC_StampTimeStruct->RTC_Seconds);
-
- /* Convert the Date structure parameters to Binary format */
- RTC_StampDateStruct->RTC_Month = (uint8_t)RTC_Bcd2ToByte(RTC_StampDateStruct->RTC_Month);
- RTC_StampDateStruct->RTC_Date = (uint8_t)RTC_Bcd2ToByte(RTC_StampDateStruct->RTC_Date);
- RTC_StampDateStruct->RTC_WeekDay = (uint8_t)RTC_Bcd2ToByte(RTC_StampDateStruct->RTC_WeekDay);
- }
-}
-
-/**
- * @brief Get the RTC timestamp Subseconds value.
- * @param None
- * @retval RTC current timestamp Subseconds value.
- */
-uint32_t RTC_GetTimeStampSubSecond(void)
-{
- /* Get timestamp subseconds values from the correspondent registers */
- return (uint32_t)(RTC->TSSSR);
-}
-
-/**
- * @}
- */
-
-/** @defgroup RTC_Group9 Tampers configuration functions
- * @brief Tampers configuration functions
- *
-@verbatim
- ===============================================================================
- Tampers configuration functions
- ===============================================================================
-
-@endverbatim
- * @{
- */
-
-/**
- * @brief Configures the select Tamper pin edge.
- * @param RTC_Tamper: Selected tamper pin.
- * This parameter can be RTC_Tamper_1.
- * @param RTC_TamperTrigger: Specifies the trigger on the tamper pin that
- * stimulates tamper event.
- * This parameter can be one of the following values:
- * @arg RTC_TamperTrigger_RisingEdge: Rising Edge of the tamper pin causes tamper event.
- * @arg RTC_TamperTrigger_FallingEdge: Falling Edge of the tamper pin causes tamper event.
- * @arg RTC_TamperTrigger_LowLevel: Low Level of the tamper pin causes tamper event.
- * @arg RTC_TamperTrigger_HighLevel: High Level of the tamper pin causes tamper event.
- * @retval None
- */
-void RTC_TamperTriggerConfig(uint32_t RTC_Tamper, uint32_t RTC_TamperTrigger)
-{
- /* Check the parameters */
- assert_param(IS_RTC_TAMPER(RTC_Tamper));
- assert_param(IS_RTC_TAMPER_TRIGGER(RTC_TamperTrigger));
-
- if (RTC_TamperTrigger == RTC_TamperTrigger_RisingEdge)
- {
- /* Configure the RTC_TAFCR register */
- RTC->TAFCR &= (uint32_t)((uint32_t)~(RTC_Tamper << 1));
- }
- else
- {
- /* Configure the RTC_TAFCR register */
- RTC->TAFCR |= (uint32_t)(RTC_Tamper << 1);
- }
-}
-
-/**
- * @brief Enables or Disables the Tamper detection.
- * @param RTC_Tamper: Selected tamper pin.
- * This parameter can be RTC_Tamper_1.
- * @param NewState: new state of the tamper pin.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void RTC_TamperCmd(uint32_t RTC_Tamper, FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_RTC_TAMPER(RTC_Tamper));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- if (NewState != DISABLE)
- {
- /* Enable the selected Tamper pin */
- RTC->TAFCR |= (uint32_t)RTC_Tamper;
- }
- else
- {
- /* Disable the selected Tamper pin */
- RTC->TAFCR &= (uint32_t)~RTC_Tamper;
- }
-}
-
-/**
- * @brief Configures the Tampers Filter.
- * @param RTC_TamperFilter: Specifies the tampers filter.
- * This parameter can be one of the following values:
- * @arg RTC_TamperFilter_Disable: Tamper filter is disabled.
- * @arg RTC_TamperFilter_2Sample: Tamper is activated after 2 consecutive
- * samples at the active level
- * @arg RTC_TamperFilter_4Sample: Tamper is activated after 4 consecutive
- * samples at the active level
- * @arg RTC_TamperFilter_8Sample: Tamper is activated after 8 consecutive
- * samples at the active level
- * @retval None
- */
-void RTC_TamperFilterConfig(uint32_t RTC_TamperFilter)
-{
- /* Check the parameters */
- assert_param(IS_RTC_TAMPER_FILTER(RTC_TamperFilter));
-
- /* Clear TAMPFLT[1:0] bits in the RTC_TAFCR register */
- RTC->TAFCR &= (uint32_t)~(RTC_TAFCR_TAMPFLT);
-
- /* Configure the RTC_TAFCR register */
- RTC->TAFCR |= (uint32_t)RTC_TamperFilter;
-}
-
-/**
- * @brief Configures the Tampers Sampling Frequency.
- * @param RTC_TamperSamplingFreq: Specifies the tampers Sampling Frequency.
- * This parameter can be one of the following values:
- * @arg RTC_TamperSamplingFreq_RTCCLK_Div32768: Each of the tamper inputs are sampled
- * with a frequency = RTCCLK / 32768
- * @arg RTC_TamperSamplingFreq_RTCCLK_Div16384: Each of the tamper inputs are sampled
- * with a frequency = RTCCLK / 16384
- * @arg RTC_TamperSamplingFreq_RTCCLK_Div8192: Each of the tamper inputs are sampled
- * with a frequency = RTCCLK / 8192
- * @arg RTC_TamperSamplingFreq_RTCCLK_Div4096: Each of the tamper inputs are sampled
- * with a frequency = RTCCLK / 4096
- * @arg RTC_TamperSamplingFreq_RTCCLK_Div2048: Each of the tamper inputs are sampled
- * with a frequency = RTCCLK / 2048
- * @arg RTC_TamperSamplingFreq_RTCCLK_Div1024: Each of the tamper inputs are sampled
- * with a frequency = RTCCLK / 1024
- * @arg RTC_TamperSamplingFreq_RTCCLK_Div512: Each of the tamper inputs are sampled
- * with a frequency = RTCCLK / 512
- * @arg RTC_TamperSamplingFreq_RTCCLK_Div256: Each of the tamper inputs are sampled
- * with a frequency = RTCCLK / 256
- * @retval None
- */
-void RTC_TamperSamplingFreqConfig(uint32_t RTC_TamperSamplingFreq)
-{
- /* Check the parameters */
- assert_param(IS_RTC_TAMPER_SAMPLING_FREQ(RTC_TamperSamplingFreq));
-
- /* Clear TAMPFREQ[2:0] bits in the RTC_TAFCR register */
- RTC->TAFCR &= (uint32_t)~(RTC_TAFCR_TAMPFREQ);
-
- /* Configure the RTC_TAFCR register */
- RTC->TAFCR |= (uint32_t)RTC_TamperSamplingFreq;
-}
-
-/**
- * @brief Configures the Tampers Pins input Precharge Duration.
- * @param RTC_TamperPrechargeDuration: Specifies the Tampers Pins input
- * Precharge Duration.
- * This parameter can be one of the following values:
- * @arg RTC_TamperPrechargeDuration_1RTCCLK: Tamper pins are pre-charged before sampling during 1 RTCCLK cycle
- * @arg RTC_TamperPrechargeDuration_2RTCCLK: Tamper pins are pre-charged before sampling during 2 RTCCLK cycle
- * @arg RTC_TamperPrechargeDuration_4RTCCLK: Tamper pins are pre-charged before sampling during 4 RTCCLK cycle
- * @arg RTC_TamperPrechargeDuration_8RTCCLK: Tamper pins are pre-charged before sampling during 8 RTCCLK cycle
- * @retval None
- */
-void RTC_TamperPinsPrechargeDuration(uint32_t RTC_TamperPrechargeDuration)
-{
- /* Check the parameters */
- assert_param(IS_RTC_TAMPER_PRECHARGE_DURATION(RTC_TamperPrechargeDuration));
-
- /* Clear TAMPPRCH[1:0] bits in the RTC_TAFCR register */
- RTC->TAFCR &= (uint32_t)~(RTC_TAFCR_TAMPPRCH);
-
- /* Configure the RTC_TAFCR register */
- RTC->TAFCR |= (uint32_t)RTC_TamperPrechargeDuration;
-}
-
-/**
- * @brief Enables or Disables the TimeStamp on Tamper Detection Event.
- * @note The timestamp is valid even the TSE bit in tamper control register
- * is reset.
- * @param NewState: new state of the timestamp on tamper event.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void RTC_TimeStampOnTamperDetectionCmd(FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- if (NewState != DISABLE)
- {
- /* Save timestamp on tamper detection event */
- RTC->TAFCR |= (uint32_t)RTC_TAFCR_TAMPTS;
- }
- else
- {
- /* Tamper detection does not cause a timestamp to be saved */
- RTC->TAFCR &= (uint32_t)~RTC_TAFCR_TAMPTS;
- }
-}
-
-/**
- * @brief Enables or Disables the Precharge of Tamper pin.
- * @param NewState: new state of tamper pull up.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void RTC_TamperPullUpCmd(FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- if (NewState != DISABLE)
- {
- /* Enable precharge of the selected Tamper pin */
- RTC->TAFCR &= (uint32_t)~RTC_TAFCR_TAMPPUDIS;
- }
- else
- {
- /* Disable precharge of the selected Tamper pin */
- RTC->TAFCR |= (uint32_t)RTC_TAFCR_TAMPPUDIS;
- }
-}
-
-/**
- * @}
- */
-
-/** @defgroup RTC_Group10 Backup Data Registers configuration functions
- * @brief Backup Data Registers configuration functions
- *
-@verbatim
- ===============================================================================
- Backup Data Registers configuration functions
- ===============================================================================
-
-@endverbatim
- * @{
- */
-
-/**
- * @brief Writes a data in a specified RTC Backup data register.
- * @param RTC_BKP_DR: RTC Backup data Register number.
- * This parameter can be: RTC_BKP_DRx where x can be from 0 to 19 to
- * specify the register.
- * @param Data: Data to be written in the specified RTC Backup data register.
- * @retval None
- */
-void RTC_WriteBackupRegister(uint32_t RTC_BKP_DR, uint32_t Data)
-{
- __IO uint32_t tmp = 0;
-
- /* Check the parameters */
- assert_param(IS_RTC_BKP(RTC_BKP_DR));
-
- tmp = RTC_BASE + 0x50;
- tmp += (RTC_BKP_DR * 4);
-
- /* Write the specified register */
- *(__IO uint32_t *)tmp = (uint32_t)Data;
-}
-
-/**
- * @brief Reads data from the specified RTC Backup data Register.
- * @param RTC_BKP_DR: RTC Backup data Register number.
- * This parameter can be: RTC_BKP_DRx where x can be from 0 to 19 to
- * specify the register.
- * @retval None
- */
-uint32_t RTC_ReadBackupRegister(uint32_t RTC_BKP_DR)
-{
- __IO uint32_t tmp = 0;
-
- /* Check the parameters */
- assert_param(IS_RTC_BKP(RTC_BKP_DR));
-
- tmp = RTC_BASE + 0x50;
- tmp += (RTC_BKP_DR * 4);
-
- /* Read the specified register */
- return (*(__IO uint32_t *)tmp);
-}
-
-/**
- * @}
- */
-
-/** @defgroup RTC_Group11 RTC Tamper and TimeStamp Pins Selection and Output Type Config configuration functions
- * @brief RTC Tamper and TimeStamp Pins Selection and Output Type Config
- * configuration functions
- *
-@verbatim
- ===============================================================================
- RTC Tamper and TimeStamp Pins Selection and Output Type Config configuration
- functions
- ===============================================================================
-
-@endverbatim
- * @{
- */
-
-/**
- * @brief Selects the RTC Tamper Pin.
- * @param RTC_TamperPin: specifies the RTC Tamper Pin.
- * This parameter can be one of the following values:
- * @arg RTC_TamperPin_PC13: PC13 is selected as RTC Tamper Pin.
- * @arg RTC_TamperPin_PI8: PI8 is selected as RTC Tamper Pin.
- * @retval None
- */
-void RTC_TamperPinSelection(uint32_t RTC_TamperPin)
-{
- /* Check the parameters */
- assert_param(IS_RTC_TAMPER_PIN(RTC_TamperPin));
-
- RTC->TAFCR &= (uint32_t)~(RTC_TAFCR_TAMPINSEL);
- RTC->TAFCR |= (uint32_t)(RTC_TamperPin);
-}
-
-/**
- * @brief Selects the RTC TimeStamp Pin.
- * @param RTC_TimeStampPin: specifies the RTC TimeStamp Pin.
- * This parameter can be one of the following values:
- * @arg RTC_TimeStampPin_PC13: PC13 is selected as RTC TimeStamp Pin.
- * @arg RTC_TimeStampPin_PI8: PI8 is selected as RTC TimeStamp Pin.
- * @retval None
- */
-void RTC_TimeStampPinSelection(uint32_t RTC_TimeStampPin)
-{
- /* Check the parameters */
- assert_param(IS_RTC_TIMESTAMP_PIN(RTC_TimeStampPin));
-
- RTC->TAFCR &= (uint32_t)~(RTC_TAFCR_TSINSEL);
- RTC->TAFCR |= (uint32_t)(RTC_TimeStampPin);
-}
-
-/**
- * @brief Configures the RTC Output Pin mode.
- * @param RTC_OutputType: specifies the RTC Output (PC13) pin mode.
- * This parameter can be one of the following values:
- * @arg RTC_OutputType_OpenDrain: RTC Output (PC13) is configured in
- * Open Drain mode.
- * @arg RTC_OutputType_PushPull: RTC Output (PC13) is configured in
- * Push Pull mode.
- * @retval None
- */
-void RTC_OutputTypeConfig(uint32_t RTC_OutputType)
-{
- /* Check the parameters */
- assert_param(IS_RTC_OUTPUT_TYPE(RTC_OutputType));
-
- RTC->TAFCR &= (uint32_t)~(RTC_TAFCR_ALARMOUTTYPE);
- RTC->TAFCR |= (uint32_t)(RTC_OutputType);
-}
-
-/**
- * @}
- */
-
-/** @defgroup RTC_Group12 Shift control synchronisation functions
- * @brief Shift control synchronisation functions
- *
-@verbatim
- ===============================================================================
- Shift control synchronisation functions
- ===============================================================================
-
-@endverbatim
- * @{
- */
-
-/**
- * @brief Configures the Synchronization Shift Control Settings.
- * @note When REFCKON is set, firmware must not write to Shift control register
- * @param RTC_ShiftAdd1S : Select to add or not 1 second to the time Calendar.
- * This parameter can be one of the following values :
- * @arg RTC_ShiftAdd1S_Set : Add one second to the clock calendar.
- * @arg RTC_ShiftAdd1S_Reset: No effect.
- * @param RTC_ShiftSubFS: Select the number of Second Fractions to Substitute.
- * This parameter can be one any value from 0 to 0x7FFF.
- * @retval An ErrorStatus enumeration value:
- * - SUCCESS: RTC Shift registers are configured
- * - ST_ERROR: RTC Shift registers are not configured
-*/
-ErrorStatus RTC_SynchroShiftConfig(uint32_t RTC_ShiftAdd1S, uint32_t RTC_ShiftSubFS)
-{
- ErrorStatus status = ST_ERROR;
- uint32_t shpfcount = 0;
-
- /* Check the parameters */
- assert_param(IS_RTC_SHIFT_ADD1S(RTC_ShiftAdd1S));
- assert_param(IS_RTC_SHIFT_SUBFS(RTC_ShiftSubFS));
-
- /* Disable the write protection for RTC registers */
- RTC->WPR = 0xCA;
- RTC->WPR = 0x53;
-
- /* Check if a Shift is pending*/
- if ((RTC->ISR & RTC_ISR_SHPF) != RESET)
- {
- /* Wait until the shift is completed*/
- while (((RTC->ISR & RTC_ISR_SHPF) != RESET) && (shpfcount != SHPF_TIMEOUT))
- {
- shpfcount++;
- }
- }
-
- /* Check if the Shift pending is completed or if there is no Shift operation at all*/
- if ((RTC->ISR & RTC_ISR_SHPF) == RESET)
- {
- /* check if the reference clock detection is disabled */
- if((RTC->CR & RTC_CR_REFCKON) == RESET)
- {
- /* Configure the Shift settings */
- RTC->SHIFTR = (uint32_t)(uint32_t)(RTC_ShiftSubFS) | (uint32_t)(RTC_ShiftAdd1S);
-
- if(RTC_WaitForSynchro() == ST_ERROR)
- {
- status = ST_ERROR;
- }
- else
- {
- status = SUCCESS;
- }
- }
- else
- {
- status = ST_ERROR;
- }
- }
- else
- {
- status = ST_ERROR;
- }
-
- /* Enable the write protection for RTC registers */
- RTC->WPR = 0xFF;
-
- return (ErrorStatus)(status);
-}
-
-/**
- * @}
- */
-
-/** @defgroup RTC_Group13 Interrupts and flags management functions
- * @brief Interrupts and flags management functions
- *
-@verbatim
- ===============================================================================
- Interrupts and flags management functions
- ===============================================================================
- All RTC interrupts are connected to the EXTI controller.
-
- - To enable the RTC Alarm interrupt, the following sequence is required:
- - Configure and enable the EXTI Line 17 in interrupt mode and select the rising
- edge sensitivity using the EXTI_Init() function.
- - Configure and enable the RTC_Alarm IRQ channel in the NVIC using the NVIC_Init()
- function.
- - Configure the RTC to generate RTC alarms (Alarm A and/or Alarm B) using
- the RTC_SetAlarm() and RTC_AlarmCmd() functions.
-
- - To enable the RTC Wakeup interrupt, the following sequence is required:
- - Configure and enable the EXTI Line 22 in interrupt mode and select the rising
- edge sensitivity using the EXTI_Init() function.
- - Configure and enable the RTC_WKUP IRQ channel in the NVIC using the NVIC_Init()
- function.
- - Configure the RTC to generate the RTC wakeup timer event using the
- RTC_WakeUpClockConfig(), RTC_SetWakeUpCounter() and RTC_WakeUpCmd() functions.
-
- - To enable the RTC Tamper interrupt, the following sequence is required:
- - Configure and enable the EXTI Line 21 in interrupt mode and select the rising
- edge sensitivity using the EXTI_Init() function.
- - Configure and enable the TAMP_STAMP IRQ channel in the NVIC using the NVIC_Init()
- function.
- - Configure the RTC to detect the RTC tamper event using the
- RTC_TamperTriggerConfig() and RTC_TamperCmd() functions.
-
- - To enable the RTC TimeStamp interrupt, the following sequence is required:
- - Configure and enable the EXTI Line 21 in interrupt mode and select the rising
- edge sensitivity using the EXTI_Init() function.
- - Configure and enable the TAMP_STAMP IRQ channel in the NVIC using the NVIC_Init()
- function.
- - Configure the RTC to detect the RTC time-stamp event using the
- RTC_TimeStampCmd() functions.
-
-@endverbatim
- * @{
- */
-
-/**
- * @brief Enables or disables the specified RTC interrupts.
- * @param RTC_IT: specifies the RTC interrupt sources to be enabled or disabled.
- * This parameter can be any combination of the following values:
- * @arg RTC_IT_TS: Time Stamp interrupt mask
- * @arg RTC_IT_WUT: WakeUp Timer interrupt mask
- * @arg RTC_IT_ALRB: Alarm B interrupt mask
- * @arg RTC_IT_ALRA: Alarm A interrupt mask
- * @arg RTC_IT_TAMP: Tamper event interrupt mask
- * @param NewState: new state of the specified RTC interrupts.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void RTC_ITConfig(uint32_t RTC_IT, FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_RTC_CONFIG_IT(RTC_IT));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- /* Disable the write protection for RTC registers */
- RTC->WPR = 0xCA;
- RTC->WPR = 0x53;
-
- if (NewState != DISABLE)
- {
- /* Configure the Interrupts in the RTC_CR register */
- RTC->CR |= (uint32_t)(RTC_IT & ~RTC_TAFCR_TAMPIE);
- /* Configure the Tamper Interrupt in the RTC_TAFCR */
- RTC->TAFCR |= (uint32_t)(RTC_IT & RTC_TAFCR_TAMPIE);
- }
- else
- {
- /* Configure the Interrupts in the RTC_CR register */
- RTC->CR &= (uint32_t)~(RTC_IT & (uint32_t)~RTC_TAFCR_TAMPIE);
- /* Configure the Tamper Interrupt in the RTC_TAFCR */
- RTC->TAFCR &= (uint32_t)~(RTC_IT & RTC_TAFCR_TAMPIE);
- }
- /* Enable the write protection for RTC registers */
- RTC->WPR = 0xFF;
-}
-
-/**
- * @brief Checks whether the specified RTC flag is set or not.
- * @param RTC_FLAG: specifies the flag to check.
- * This parameter can be one of the following values:
- * @arg RTC_FLAG_TAMP1F: Tamper 1 event flag
- * @arg RTC_FLAG_TSOVF: Time Stamp OverFlow flag
- * @arg RTC_FLAG_TSF: Time Stamp event flag
- * @arg RTC_FLAG_WUTF: WakeUp Timer flag
- * @arg RTC_FLAG_ALRBF: Alarm B flag
- * @arg RTC_FLAG_ALRAF: Alarm A flag
- * @arg RTC_FLAG_INITF: Initialization mode flag
- * @arg RTC_FLAG_RSF: Registers Synchronized flag
- * @arg RTC_FLAG_INITS: Registers Configured flag
- * @arg RTC_FLAG_WUTWF: WakeUp Timer Write flag
- * @arg RTC_FLAG_ALRBWF: Alarm B Write flag
- * @arg RTC_FLAG_ALRAWF: Alarm A write flag
- * @retval The new state of RTC_FLAG (SET or RESET).
- */
-FlagStatus RTC_GetFlagStatus(uint32_t RTC_FLAG)
-{
- FlagStatus bitstatus = RESET;
- uint32_t tmpreg = 0;
-
- /* Check the parameters */
- assert_param(IS_RTC_GET_FLAG(RTC_FLAG));
-
- /* Get all the flags */
- tmpreg = (uint32_t)(RTC->ISR & RTC_FLAGS_MASK);
-
- /* Return the status of the flag */
- if ((tmpreg & RTC_FLAG) != (uint32_t)RESET)
- {
- bitstatus = SET;
- }
- else
- {
- bitstatus = RESET;
- }
- return bitstatus;
-}
-
-/**
- * @brief Clears the RTC's pending flags.
- * @param RTC_FLAG: specifies the RTC flag to clear.
- * This parameter can be any combination of the following values:
- * @arg RTC_FLAG_TAMP1F: Tamper 1 event flag
- * @arg RTC_FLAG_TSOVF: Time Stamp Overflow flag
- * @arg RTC_FLAG_TSF: Time Stamp event flag
- * @arg RTC_FLAG_WUTF: WakeUp Timer flag
- * @arg RTC_FLAG_ALRBF: Alarm B flag
- * @arg RTC_FLAG_ALRAF: Alarm A flag
- * @arg RTC_FLAG_RSF: Registers Synchronized flag
- * @retval None
- */
-void RTC_ClearFlag(uint32_t RTC_FLAG)
-{
- /* Check the parameters */
- assert_param(IS_RTC_CLEAR_FLAG(RTC_FLAG));
-
- /* Clear the Flags in the RTC_ISR register */
- RTC->ISR = (uint32_t)((uint32_t)(~((RTC_FLAG | RTC_ISR_INIT)& 0x0000FFFF) | (uint32_t)(RTC->ISR & RTC_ISR_INIT)));
-}
-
-/**
- * @brief Checks whether the specified RTC interrupt has occurred or not.
- * @param RTC_IT: specifies the RTC interrupt source to check.
- * This parameter can be one of the following values:
- * @arg RTC_IT_TS: Time Stamp interrupt
- * @arg RTC_IT_WUT: WakeUp Timer interrupt
- * @arg RTC_IT_ALRB: Alarm B interrupt
- * @arg RTC_IT_ALRA: Alarm A interrupt
- * @arg RTC_IT_TAMP1: Tamper 1 event interrupt
- * @retval The new state of RTC_IT (SET or RESET).
- */
-ITStatus RTC_GetITStatus(uint32_t RTC_IT)
-{
- ITStatus bitstatus = RESET;
- uint32_t tmpreg = 0, enablestatus = 0;
-
- /* Check the parameters */
- assert_param(IS_RTC_GET_IT(RTC_IT));
-
- /* Get the TAMPER Interrupt enable bit and pending bit */
- tmpreg = (uint32_t)(RTC->TAFCR & (RTC_TAFCR_TAMPIE));
-
- /* Get the Interrupt enable Status */
- enablestatus = (uint32_t)((RTC->CR & RTC_IT) | (tmpreg & (RTC_IT >> 15)));
-
- /* Get the Interrupt pending bit */
- tmpreg = (uint32_t)((RTC->ISR & (uint32_t)(RTC_IT >> 4)));
-
- /* Get the status of the Interrupt */
- if ((enablestatus != (uint32_t)RESET) && ((tmpreg & 0x0000FFFF) != (uint32_t)RESET))
- {
- bitstatus = SET;
- }
- else
- {
- bitstatus = RESET;
- }
- return bitstatus;
-}
-
-/**
- * @brief Clears the RTC's interrupt pending bits.
- * @param RTC_IT: specifies the RTC interrupt pending bit to clear.
- * This parameter can be any combination of the following values:
- * @arg RTC_IT_TS: Time Stamp interrupt
- * @arg RTC_IT_WUT: WakeUp Timer interrupt
- * @arg RTC_IT_ALRB: Alarm B interrupt
- * @arg RTC_IT_ALRA: Alarm A interrupt
- * @arg RTC_IT_TAMP1: Tamper 1 event interrupt
- * @retval None
- */
-void RTC_ClearITPendingBit(uint32_t RTC_IT)
-{
- uint32_t tmpreg = 0;
-
- /* Check the parameters */
- assert_param(IS_RTC_CLEAR_IT(RTC_IT));
-
- /* Get the RTC_ISR Interrupt pending bits mask */
- tmpreg = (uint32_t)(RTC_IT >> 4);
-
- /* Clear the interrupt pending bits in the RTC_ISR register */
- RTC->ISR = (uint32_t)((uint32_t)(~((tmpreg | RTC_ISR_INIT)& 0x0000FFFF) | (uint32_t)(RTC->ISR & RTC_ISR_INIT)));
-}
-
-/**
- * @}
- */
-
-/**
- * @brief Converts a 2 digit decimal to BCD format.
- * @param Value: Byte to be converted.
- * @retval Converted byte
- */
-static uint8_t RTC_ByteToBcd2(uint8_t Value)
-{
- uint8_t bcdhigh = 0;
-
- while (Value >= 10)
- {
- bcdhigh++;
- Value -= 10;
- }
-
- return ((uint8_t)(bcdhigh << 4) | Value);
-}
-
-/**
- * @brief Convert from 2 digit BCD to Binary.
- * @param Value: BCD value to be converted.
- * @retval Converted word
- */
-static uint8_t RTC_Bcd2ToByte(uint8_t Value)
-{
- uint8_t tmp = 0;
- tmp = ((uint8_t)(Value & (uint8_t)0xF0) >> (uint8_t)0x4) * 10;
- return (tmp + (Value & (uint8_t)0x0F));
-}
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-
-/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/sdio/Kconfig b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/sdio/Kconfig
deleted file mode 100644
index a9d1dd365..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/sdio/Kconfig
+++ /dev/null
@@ -1,13 +0,0 @@
-if BSP_USING_SDIO
-config SDIO_BUS_NAME
- string "sdio bus name"
- default "sdio"
-
-config SDIO_DRIVER_NAME
- string "sdio driver name"
- default "sdio_drv"
-
-config SDIO_DEVICE_NAME
- string "sdio device name"
- default "sdio_dev"
-endif
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/sdio/Makefile b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/sdio/Makefile
deleted file mode 100644
index 279499b68..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/sdio/Makefile
+++ /dev/null
@@ -1,4 +0,0 @@
-SRC_FILES := connect_sdio.c sdio_sd.c hardware_sdio.c
-
-
-include $(KERNEL_ROOT)/compiler.mk
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/sdio/connect_sdio.c b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/sdio/connect_sdio.c
deleted file mode 100644
index 9212be4af..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/sdio/connect_sdio.c
+++ /dev/null
@@ -1,240 +0,0 @@
-/*
-* Copyright (c) 2020 AIIT XUOS Lab
-* XiUOS is licensed under Mulan PSL v2.
-* You can use this software according to the terms and conditions of the Mulan PSL v2.
-* You may obtain a copy of Mulan PSL v2 at:
-* http://license.coscl.org.cn/MulanPSL2
-* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
-* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
-* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
-* See the Mulan PSL v2 for more details.
-*/
-
-/**
-* @file connect_sdio.c
-* @brief support sdio function using bus driver framework
-* @version 1.0
-* @author AIIT XUOS Lab
-* @date 2021-04-22
-*/
-
-/*************************************************
-File name: connect_sdio.c
-Description: support sdio function using bus driver framework
-Others: hardware/sdio/sdio.c for references
-History:
-1. Date: 2021-04-22
-Author: AIIT XUOS Lab
-Modification: Support stm32f407-discovery-board sdio configure, write and read functions
-*************************************************/
-
-#include
-#include "connect_sdio.h"
-#include "sdio_sd.h"
-
-#ifndef SDCARD_SECTOR_SIZE
-#define SDCARD_SECTOR_SIZE 512
-#endif
-
-static uint32 SdioConfigure(void *drv, struct BusConfigureInfo *configure_info)
-{
- NULL_PARAM_CHECK(drv);
- NULL_PARAM_CHECK(configure_info);
-
- if (configure_info->configure_cmd == OPER_BLK_GETGEOME) {
- NULL_PARAM_CHECK(configure_info->private_data);
- struct DeviceBlockArrange *args = (struct DeviceBlockArrange *)configure_info->private_data;
- SD_GetCardInfo(&SDCardInfo);
-
- args->size_perbank = SDCardInfo.CardBlockSize;
- args->block_size = SDCardInfo.CardBlockSize;
- if(SDCardInfo.CardType == SDIO_HIGH_CAPACITY_SD_CARD)
- args->bank_num = (SDCardInfo.SD_csd.DeviceSize + 1) * 1024;
- else
- args->bank_num = SDCardInfo.CardCapacity;
- }
-
- return EOK;
-}
-
-static int sd_lock = -1;
-static uint32 SDBuffer[512/sizeof(uint32_t)];
-
-static uint32 SdioOpen(void *dev)
-{
- NULL_PARAM_CHECK(dev);
-
- if(sd_lock >= 0) {
- KSemaphoreDelete(sd_lock);
- }
- sd_lock = KSemaphoreCreate(1);
- if (sd_lock < 0){
- return ERROR;
- }
-
- return EOK;
-}
-
-static uint32 SdioClose(void *dev)
-{
- NULL_PARAM_CHECK(dev);
-
- KSemaphoreDelete(sd_lock);
-
- return EOK;
-}
-
-static uint32 SdioRead(void *dev, struct BusBlockReadParam *read_param)
-{
- uint8 ret = SD_OK;
-
- KSemaphoreObtain(sd_lock, WAITING_FOREVER);
-
- if (((uint32)read_param->buffer & 0x03) != 0) {
- uint64_t sector;
- uint8_t* temp;
-
- sector = (uint64_t)read_param->pos * SDCARD_SECTOR_SIZE;
- temp = (uint8_t*)read_param->buffer;
-
- for (uint8 i = 0; i < read_param->size; i++) {
- ret = SD_ReadBlock((uint8_t *)SDBuffer, sector, 1);
- if(ret != SD_OK) {
- KPrintf("read failed: %d, buffer 0x%08x\n", ret, temp);
- return 0;
- }
-#if defined (SD_DMA_MODE)
- ret = SD_WaitReadOperation();
- if (ret != SD_OK) {
- KPrintf("read failed: %d, buffer 0x%08x\n", ret, temp);
- return 0;
- }
-#endif
- memcpy(temp, SDBuffer, SDCARD_SECTOR_SIZE);
-
- sector += SDCARD_SECTOR_SIZE;
- temp += SDCARD_SECTOR_SIZE;
- }
- } else {
- ret = SD_ReadBlock((uint8_t *)read_param->buffer, (uint64_t)read_param->pos * SDCARD_SECTOR_SIZE, read_param->size);
- if (ret != SD_OK) {
- KPrintf("read failed: %d, buffer 0x%08x\n", ret, (uint8_t *)read_param->buffer);
- return 0;
- }
-#if defined (SD_DMA_MODE)
- ret = SD_WaitReadOperation();
- if (ret != SD_OK) {
- KPrintf("read failed: %d, buffer 0x%08x\n", ret, (uint8_t *)read_param->buffer);
- return 0;
- }
-#endif
- }
-
- KSemaphoreAbandon(sd_lock);
-
- return read_param->size;
-}
-
-static uint32 SdioWrite(void *dev, struct BusBlockWriteParam *write_param)
-{
- uint8 ret = SD_OK;
-
- KSemaphoreObtain(sd_lock, WAITING_FOREVER);
-
- if (((uint32)write_param->buffer & 0x03) != 0) {
- uint64_t sector;
- uint8_t* temp;
-
- sector = (uint64_t)write_param->pos * SDCARD_SECTOR_SIZE;
- temp = (uint8_t*)write_param->buffer;
-
- for (uint8 i = 0; i < write_param->size; i++) {
- memcpy(SDBuffer, temp, SDCARD_SECTOR_SIZE);
-
- ret = SD_WriteBlock((uint8_t *)SDBuffer, sector, 1);
- if(ret != SD_OK) {
- KPrintf("write failed: %d, buffer 0x%08x\n", ret, temp);
- return 0;
- }
-#if defined (SD_DMA_MODE)
- ret = SD_WaitWriteOperation();
- if (ret != SD_OK) {
- KPrintf("write failed: %d, buffer 0x%08x\n", ret, temp);
- return 0;
- }
-#endif
- sector += SDCARD_SECTOR_SIZE;
- temp += SDCARD_SECTOR_SIZE;
- }
- } else {
- ret = SD_WriteBlock((uint8_t *)write_param->buffer, (uint64_t)write_param->pos * SDCARD_SECTOR_SIZE, write_param->size);
- if (ret != SD_OK) {
- KPrintf("write failed: %d, buffer 0x%08x\n", ret, (uint8_t *)write_param->buffer);
- return 0;
- }
-#if defined (SD_DMA_MODE)
- ret = SD_WaitWriteOperation();
- if (ret != SD_OK){
- KPrintf("write failed: %d, buffer 0x%08x\n", ret, (uint8_t *)write_param->buffer);
- return 0;
- }
-#endif
- }
-
- KSemaphoreAbandon(sd_lock);
-
- return write_param->size;
-}
-
-static struct SdioDevDone dev_done =
-{
- SdioOpen,
- SdioClose,
- SdioWrite,
- SdioRead,
-};
-
-int HwSdioInit(void)
-{
- static struct SdioBus bus;
- static struct SdioDriver drv;
- static struct SdioHardwareDevice dev;
-
- x_err_t ret = EOK;
- ret = SD_Init();
- if (ret != SD_OK) {
- KPrintf("SD init failed!");
- return ERROR;
- }
-
- ret = SdioBusInit(&bus, SDIO_BUS_NAME);
- if (ret != EOK) {
- KPrintf("Sdio bus init error %d\n", ret);
- return ERROR;
- }
-
- ret = SdioDriverInit(&drv, SDIO_DRIVER_NAME);
- if (ret != EOK) {
- KPrintf("Sdio driver init error %d\n", ret);
- return ERROR;
- }
- ret = SdioDriverAttachToBus(SDIO_DRIVER_NAME, SDIO_BUS_NAME);
- if (ret != EOK) {
- KPrintf("Sdio driver attach error %d\n", ret);
- return ERROR;
- }
-
- dev.dev_done = &dev_done;
- ret = SdioDeviceRegister(&dev, SDIO_DEVICE_NAME);
- if (ret != EOK) {
- KPrintf("Sdio device register error %d\n", ret);
- return ERROR;
- }
- ret = SdioDeviceAttachToBus(SDIO_DEVICE_NAME, SDIO_BUS_NAME);
- if (ret != EOK) {
- KPrintf("Sdio device register error %d\n", ret);
- return ERROR;
- }
-
- return ret;
-}
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/sdio/hardware_sdio.c b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/sdio/hardware_sdio.c
deleted file mode 100644
index e95f97182..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/sdio/hardware_sdio.c
+++ /dev/null
@@ -1,1024 +0,0 @@
-/**
- ******************************************************************************
- * @file stm32f4xx_sdio.c
- * @author MCD Application Team
- * @version V1.0.0
- * @date 30-September-2011
- * @brief This file provides firmware functions to manage the following
- * functionalities of the Secure digital input/output interface (SDIO)
- * peripheral:
- * - Initialization and Configuration
- * - Command path state machine (CPSM) management
- * - Data path state machine (DPSM) management
- * - SDIO IO Cards mode management
- * - CE-ATA mode management
- * - DMA transfers management
- * - Interrupts and flags management
- *
- * @verbatim
- *
- *
- * ===================================================================
- * How to use this driver
- * ===================================================================
- * 1. The SDIO clock (SDIOCLK = 48 MHz) is coming from a specific output
- * of PLL (PLL48CLK). Before to start working with SDIO peripheral
- * make sure that the PLL is well configured.
- * The SDIO peripheral uses two clock signals:
- * - SDIO adapter clock (SDIOCLK = 48 MHz)
- * - APB2 bus clock (PCLK2)
- * PCLK2 and SDIO_CK clock frequencies must respect the following condition:
- * Frequenc(PCLK2) >= (3 / 8 x Frequency(SDIO_CK))
- *
- * 2. Enable peripheral clock using RCC_APB2PeriphClockCmd(RCC_APB2Periph_SDIO, ENABLE).
- *
- * 3. According to the SDIO mode, enable the GPIO clocks using
- * RCC_AHB1PeriphClockCmd() function.
- * The I/O can be one of the following configurations:
- * - 1-bit data length: SDIO_CMD, SDIO_CK and D0.
- * - 4-bit data length: SDIO_CMD, SDIO_CK and D[3:0].
- * - 8-bit data length: SDIO_CMD, SDIO_CK and D[7:0].
- *
- * 4. Peripheral's alternate function:
- * - Connect the pin to the desired peripherals' Alternate
- * Function (AF) using GPIO_PinAFConfig() function
- * - Configure the desired pin in alternate function by:
- * GPIO_InitStruct->GPIO_Mode = GPIO_Mode_AF
- * - Select the type, pull-up/pull-down and output speed via
- * GPIO_PuPd, GPIO_OType and GPIO_Speed members
- * - Call GPIO_Init() function
- *
- * 5. Program the Clock Edge, Clock Bypass, Clock Power Save, Bus Wide,
- * hardware, flow control and the Clock Divider using the SDIO_Init()
- * function.
- *
- * 6. Enable the Power ON State using the SDIO_SetPowerState(SDIO_PowerState_ON)
- * function.
- *
- * 7. Enable the clock using the SDIO_ClockCmd() function.
- *
- * 8. Enable the NVIC and the corresponding interrupt using the function
- * SDIO_ITConfig() if you need to use interrupt mode.
- *
- * 9. When using the DMA mode
- * - Configure the DMA using DMA_Init() function
- * - Active the needed channel Request using SDIO_DMACmd() function
- *
- * 10. Enable the DMA using the DMA_Cmd() function, when using DMA mode.
- *
- * 11. To control the CPSM (Command Path State Machine) and send
- * commands to the card use the SDIO_SendCommand(),
- * SDIO_GetCommandResponse() and SDIO_GetResponse() functions.
- * First, user has to fill the command structure (pointer to
- * SDIO_CmdInitTypeDef) according to the selected command to be sent.
- * The parameters that should be filled are:
- * - Command Argument
- * - Command Index
- * - Command Response type
- * - Command Wait
- * - CPSM Status (Enable or Disable)
- *
- * To check if the command is well received, read the SDIO_CMDRESP
- * register using the SDIO_GetCommandResponse().
- * The SDIO responses registers (SDIO_RESP1 to SDIO_RESP2), use the
- * SDIO_GetResponse() function.
- *
- * 12. To control the DPSM (Data Path State Machine) and send/receive
- * data to/from the card use the SDIO_DataConfig(), SDIO_GetDataCounter(),
- * SDIO_ReadData(), SDIO_WriteData() and SDIO_GetFIFOCount() functions.
- *
- * Read Operations
- * ---------------
- * a) First, user has to fill the data structure (pointer to
- * SDIO_DataInitTypeDef) according to the selected data type to
- * be received.
- * The parameters that should be filled are:
- * - Data TimeOut
- * - Data Length
- * - Data Block size
- * - Data Transfer direction: should be from card (To SDIO)
- * - Data Transfer mode
- * - DPSM Status (Enable or Disable)
- *
- * b) Configure the SDIO resources to receive the data from the card
- * according to selected transfer mode (Refer to Step 8, 9 and 10).
- *
- * c) Send the selected Read command (refer to step 11).
- *
- * d) Use the SDIO flags/interrupts to check the transfer status.
- *
- * Write Operations
- * ---------------
- * a) First, user has to fill the data structure (pointer to
- * SDIO_DataInitTypeDef) according to the selected data type to
- * be received.
- * The parameters that should be filled are:
- * - Data TimeOut
- * - Data Length
- * - Data Block size
- * - Data Transfer direction: should be to card (To CARD)
- * - Data Transfer mode
- * - DPSM Status (Enable or Disable)
- *
- * b) Configure the SDIO resources to send the data to the card
- * according to selected transfer mode (Refer to Step 8, 9 and 10).
- *
- * c) Send the selected Write command (refer to step 11).
- *
- * d) Use the SDIO flags/interrupts to check the transfer status.
- *
- *
- * @endverbatim
- *
- *
- ******************************************************************************
- * @attention
- *
- * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
- * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
- * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
- * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
- * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
- * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
- *
- * © COPYRIGHT 2011 STMicroelectronics
- ******************************************************************************
- */
-
-/**
-* @file: hardware_sdio.c
-* @brief: support hardware sdio function
-* @version: 1.0
-* @author: AIIT XUOS Lab
-* @date: 2021/4/25
-*/
-
-/*************************************************
-File name: hardware_sdio.c
-Description: support hardware sdio function
-Others:
-History:
-1. Date: 2021-04-25
-Author: AIIT XUOS Lab
-Modification:
-1. rename stm32f4xx_sdio.c for XiUOS
-*************************************************/
-
-/* Includes ------------------------------------------------------------------*/
-#include
-#include
-#include
-
-/** @addtogroup STM32F4xx_StdPeriph_Driver
- * @{
- */
-
-/** @defgroup SDIO
- * @brief SDIO driver modules
- * @{
- */
-
-/* Private typedef -----------------------------------------------------------*/
-/* Private define ------------------------------------------------------------*/
-
-/* ------------ SDIO registers bit address in the alias region ----------- */
-#define SDIO_OFFSET (SDIO_BASE - PERIPH_BASE)
-
-/* --- CLKCR Register ---*/
-/* Alias word address of CLKEN bit */
-#define CLKCR_OFFSET (SDIO_OFFSET + 0x04)
-#define CLKEN_BitNumber 0x08
-#define CLKCR_CLKEN_BB (PERIPH_BB_BASE + (CLKCR_OFFSET * 32) + (CLKEN_BitNumber * 4))
-
-/* --- CMD Register ---*/
-/* Alias word address of SDIOSUSPEND bit */
-#define CMD_OFFSET (SDIO_OFFSET + 0x0C)
-#define SDIOSUSPEND_BitNumber 0x0B
-#define CMD_SDIOSUSPEND_BB (PERIPH_BB_BASE + (CMD_OFFSET * 32) + (SDIOSUSPEND_BitNumber * 4))
-
-/* Alias word address of ENCMDCOMPL bit */
-#define ENCMDCOMPL_BitNumber 0x0C
-#define CMD_ENCMDCOMPL_BB (PERIPH_BB_BASE + (CMD_OFFSET * 32) + (ENCMDCOMPL_BitNumber * 4))
-
-/* Alias word address of NIEN bit */
-#define NIEN_BitNumber 0x0D
-#define CMD_NIEN_BB (PERIPH_BB_BASE + (CMD_OFFSET * 32) + (NIEN_BitNumber * 4))
-
-/* Alias word address of ATACMD bit */
-#define ATACMD_BitNumber 0x0E
-#define CMD_ATACMD_BB (PERIPH_BB_BASE + (CMD_OFFSET * 32) + (ATACMD_BitNumber * 4))
-
-/* --- DCTRL Register ---*/
-/* Alias word address of DMAEN bit */
-#define DCTRL_OFFSET (SDIO_OFFSET + 0x2C)
-#define DMAEN_BitNumber 0x03
-#define DCTRL_DMAEN_BB (PERIPH_BB_BASE + (DCTRL_OFFSET * 32) + (DMAEN_BitNumber * 4))
-
-/* Alias word address of RWSTART bit */
-#define RWSTART_BitNumber 0x08
-#define DCTRL_RWSTART_BB (PERIPH_BB_BASE + (DCTRL_OFFSET * 32) + (RWSTART_BitNumber * 4))
-
-/* Alias word address of RWSTOP bit */
-#define RWSTOP_BitNumber 0x09
-#define DCTRL_RWSTOP_BB (PERIPH_BB_BASE + (DCTRL_OFFSET * 32) + (RWSTOP_BitNumber * 4))
-
-/* Alias word address of RWMOD bit */
-#define RWMOD_BitNumber 0x0A
-#define DCTRL_RWMOD_BB (PERIPH_BB_BASE + (DCTRL_OFFSET * 32) + (RWMOD_BitNumber * 4))
-
-/* Alias word address of SDIOEN bit */
-#define SDIOEN_BitNumber 0x0B
-#define DCTRL_SDIOEN_BB (PERIPH_BB_BASE + (DCTRL_OFFSET * 32) + (SDIOEN_BitNumber * 4))
-
-/* ---------------------- SDIO registers bit mask ------------------------ */
-/* --- CLKCR Register ---*/
-/* CLKCR register clear mask */
-#define CLKCR_CLEAR_MASK ((uint32_t)0xFFFF8100)
-
-/* --- PWRCTRL Register ---*/
-/* SDIO PWRCTRL Mask */
-#define PWR_PWRCTRL_MASK ((uint32_t)0xFFFFFFFC)
-
-/* --- DCTRL Register ---*/
-/* SDIO DCTRL Clear Mask */
-#define DCTRL_CLEAR_MASK ((uint32_t)0xFFFFFF08)
-
-/* --- CMD Register ---*/
-/* CMD Register clear mask */
-#define CMD_CLEAR_MASK ((uint32_t)0xFFFFF800)
-
-/* SDIO RESP Registers Address */
-#define SDIO_RESP_ADDR ((uint32_t)(SDIO_BASE + 0x14))
-
-/* Private macro -------------------------------------------------------------*/
-/* Private variables ---------------------------------------------------------*/
-/* Private function prototypes -----------------------------------------------*/
-/* Private functions ---------------------------------------------------------*/
-
-/** @defgroup SDIO_Private_Functions
- * @{
- */
-
-/** @defgroup SDIO_Group1 Initialization and Configuration functions
- * @brief Initialization and Configuration functions
- *
-@verbatim
- ===============================================================================
- Initialization and Configuration functions
- ===============================================================================
-
-@endverbatim
- * @{
- */
-
-/**
- * @brief Deinitializes the SDIO peripheral registers to their default reset values.
- * @param None
- * @retval None
- */
-void SDIO_DeInit(void)
-{
- RCC_APB2PeriphResetCmd(RCC_APB2Periph_SDIO, ENABLE);
- RCC_APB2PeriphResetCmd(RCC_APB2Periph_SDIO, DISABLE);
-}
-
-/**
- * @brief Initializes the SDIO peripheral according to the specified
- * parameters in the SDIO_InitStruct.
- * @param SDIO_InitStruct : pointer to a SDIO_InitTypeDef structure
- * that contains the configuration information for the SDIO peripheral.
- * @retval None
- */
-void SDIO_Init(SDIO_InitTypeDef* SDIO_InitStruct)
-{
- uint32_t tmpreg = 0;
-
- /* Check the parameters */
- assert_param(IS_SDIO_CLOCK_EDGE(SDIO_InitStruct->SDIO_ClockEdge));
- assert_param(IS_SDIO_CLOCK_BYPASS(SDIO_InitStruct->SDIO_ClockBypass));
- assert_param(IS_SDIO_CLOCK_POWER_SAVE(SDIO_InitStruct->SDIO_ClockPowerSave));
- assert_param(IS_SDIO_BUS_WIDE(SDIO_InitStruct->SDIO_BusWide));
- assert_param(IS_SDIO_HARDWARE_FLOW_CONTROL(SDIO_InitStruct->SDIO_HardwareFlowControl));
-
-/*---------------------------- SDIO CLKCR Configuration ------------------------*/
- /* Get the SDIO CLKCR value */
- tmpreg = SDIO->CLKCR;
-
- /* Clear CLKDIV, PWRSAV, BYPASS, WIDBUS, NEGEDGE, HWFC_EN bits */
- tmpreg &= CLKCR_CLEAR_MASK;
-
- /* Set CLKDIV bits according to SDIO_ClockDiv value */
- /* Set PWRSAV bit according to SDIO_ClockPowerSave value */
- /* Set BYPASS bit according to SDIO_ClockBypass value */
- /* Set WIDBUS bits according to SDIO_BusWide value */
- /* Set NEGEDGE bits according to SDIO_ClockEdge value */
- /* Set HWFC_EN bits according to SDIO_HardwareFlowControl value */
- tmpreg |= (SDIO_InitStruct->SDIO_ClockDiv | SDIO_InitStruct->SDIO_ClockPowerSave |
- SDIO_InitStruct->SDIO_ClockBypass | SDIO_InitStruct->SDIO_BusWide |
- SDIO_InitStruct->SDIO_ClockEdge | SDIO_InitStruct->SDIO_HardwareFlowControl);
-
- /* Write to SDIO CLKCR */
- SDIO->CLKCR = tmpreg;
-}
-
-/**
- * @brief Fills each SDIO_InitStruct member with its default value.
- * @param SDIO_InitStruct: pointer to an SDIO_InitTypeDef structure which
- * will be initialized.
- * @retval None
- */
-void SDIO_StructInit(SDIO_InitTypeDef* SDIO_InitStruct)
-{
- /* SDIO_InitStruct members default value */
- SDIO_InitStruct->SDIO_ClockDiv = 0x00;
- SDIO_InitStruct->SDIO_ClockEdge = SDIO_ClockEdge_Rising;
- SDIO_InitStruct->SDIO_ClockBypass = SDIO_ClockBypass_Disable;
- SDIO_InitStruct->SDIO_ClockPowerSave = SDIO_ClockPowerSave_Disable;
- SDIO_InitStruct->SDIO_BusWide = SDIO_BusWide_1b;
- SDIO_InitStruct->SDIO_HardwareFlowControl = SDIO_HardwareFlowControl_Disable;
-}
-
-/**
- * @brief Enables or disables the SDIO Clock.
- * @param NewState: new state of the SDIO Clock.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void SDIO_ClockCmd(FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- *(__IO uint32_t *) CLKCR_CLKEN_BB = (uint32_t)NewState;
-}
-
-/**
- * @brief Sets the power status of the controller.
- * @param SDIO_PowerState: new state of the Power state.
- * This parameter can be one of the following values:
- * @arg SDIO_PowerState_OFF: SDIO Power OFF
- * @arg SDIO_PowerState_ON: SDIO Power ON
- * @retval None
- */
-void SDIO_SetPowerState(uint32_t SDIO_PowerState)
-{
- /* Check the parameters */
- assert_param(IS_SDIO_POWER_STATE(SDIO_PowerState));
-
- SDIO->POWER = SDIO_PowerState;
-}
-
-/**
- * @brief Gets the power status of the controller.
- * @param None
- * @retval Power status of the controller. The returned value can be one of the
- * following values:
- * - 0x00: Power OFF
- * - 0x02: Power UP
- * - 0x03: Power ON
- */
-uint32_t SDIO_GetPowerState(void)
-{
- return (SDIO->POWER & (~PWR_PWRCTRL_MASK));
-}
-
-/**
- * @}
- */
-
-/** @defgroup SDIO_Group2 Command path state machine (CPSM) management functions
- * @brief Command path state machine (CPSM) management functions
- *
-@verbatim
- ===============================================================================
- Command path state machine (CPSM) management functions
- ===============================================================================
-
- This section provide functions allowing to program and read the Command path
- state machine (CPSM).
-
-@endverbatim
- * @{
- */
-
-/**
- * @brief Initializes the SDIO Command according to the specified
- * parameters in the SDIO_CmdInitStruct and send the command.
- * @param SDIO_CmdInitStruct : pointer to a SDIO_CmdInitTypeDef
- * structure that contains the configuration information for the SDIO
- * command.
- * @retval None
- */
-void SDIO_SendCommand(SDIO_CmdInitTypeDef *SDIO_CmdInitStruct)
-{
- uint32_t tmpreg = 0;
-
- /* Check the parameters */
- assert_param(IS_SDIO_CMD_INDEX(SDIO_CmdInitStruct->SDIO_CmdIndex));
- assert_param(IS_SDIO_RESPONSE(SDIO_CmdInitStruct->SDIO_Response));
- assert_param(IS_SDIO_WAIT(SDIO_CmdInitStruct->SDIO_Wait));
- assert_param(IS_SDIO_CPSM(SDIO_CmdInitStruct->SDIO_CPSM));
-
-/*---------------------------- SDIO ARG Configuration ------------------------*/
- /* Set the SDIO Argument value */
- SDIO->ARG = SDIO_CmdInitStruct->SDIO_Argument;
-
-/*---------------------------- SDIO CMD Configuration ------------------------*/
- /* Get the SDIO CMD value */
- tmpreg = SDIO->CMD;
- /* Clear CMDINDEX, WAITRESP, WAITINT, WAITPEND, CPSMEN bits */
- tmpreg &= CMD_CLEAR_MASK;
- /* Set CMDINDEX bits according to SDIO_CmdIndex value */
- /* Set WAITRESP bits according to SDIO_Response value */
- /* Set WAITINT and WAITPEND bits according to SDIO_Wait value */
- /* Set CPSMEN bits according to SDIO_CPSM value */
- tmpreg |= (uint32_t)SDIO_CmdInitStruct->SDIO_CmdIndex | SDIO_CmdInitStruct->SDIO_Response
- | SDIO_CmdInitStruct->SDIO_Wait | SDIO_CmdInitStruct->SDIO_CPSM;
-
- /* Write to SDIO CMD */
- SDIO->CMD = tmpreg;
-}
-
-/**
- * @brief Fills each SDIO_CmdInitStruct member with its default value.
- * @param SDIO_CmdInitStruct: pointer to an SDIO_CmdInitTypeDef
- * structure which will be initialized.
- * @retval None
- */
-void SDIO_CmdStructInit(SDIO_CmdInitTypeDef* SDIO_CmdInitStruct)
-{
- /* SDIO_CmdInitStruct members default value */
- SDIO_CmdInitStruct->SDIO_Argument = 0x00;
- SDIO_CmdInitStruct->SDIO_CmdIndex = 0x00;
- SDIO_CmdInitStruct->SDIO_Response = SDIO_Response_No;
- SDIO_CmdInitStruct->SDIO_Wait = SDIO_Wait_No;
- SDIO_CmdInitStruct->SDIO_CPSM = SDIO_CPSM_Disable;
-}
-
-/**
- * @brief Returns command index of last command for which response received.
- * @param None
- * @retval Returns the command index of the last command response received.
- */
-uint8_t SDIO_GetCommandResponse(void)
-{
- return (uint8_t)(SDIO->RESPCMD);
-}
-
-/**
- * @brief Returns response received from the card for the last command.
- * @param SDIO_RESP: Specifies the SDIO response register.
- * This parameter can be one of the following values:
- * @arg SDIO_RESP1: Response Register 1
- * @arg SDIO_RESP2: Response Register 2
- * @arg SDIO_RESP3: Response Register 3
- * @arg SDIO_RESP4: Response Register 4
- * @retval The Corresponding response register value.
- */
-uint32_t SDIO_GetResponse(uint32_t SDIO_RESP)
-{
- __IO uint32_t tmp = 0;
-
- /* Check the parameters */
- assert_param(IS_SDIO_RESP(SDIO_RESP));
-
- tmp = SDIO_RESP_ADDR + SDIO_RESP;
-
- return (*(__IO uint32_t *) tmp);
-}
-
-/**
- * @}
- */
-
-/** @defgroup SDIO_Group3 Data path state machine (DPSM) management functions
- * @brief Data path state machine (DPSM) management functions
- *
-@verbatim
- ===============================================================================
- Data path state machine (DPSM) management functions
- ===============================================================================
-
- This section provide functions allowing to program and read the Data path
- state machine (DPSM).
-
-@endverbatim
- * @{
- */
-
-/**
- * @brief Initializes the SDIO data path according to the specified
- * parameters in the SDIO_DataInitStruct.
- * @param SDIO_DataInitStruct : pointer to a SDIO_DataInitTypeDef structure
- * that contains the configuration information for the SDIO command.
- * @retval None
- */
-void SDIO_DataConfig(SDIO_DataInitTypeDef* SDIO_DataInitStruct)
-{
- uint32_t tmpreg = 0;
-
- /* Check the parameters */
- assert_param(IS_SDIO_DATA_LENGTH(SDIO_DataInitStruct->SDIO_DataLength));
- assert_param(IS_SDIO_BLOCK_SIZE(SDIO_DataInitStruct->SDIO_DataBlockSize));
- assert_param(IS_SDIO_TRANSFER_DIR(SDIO_DataInitStruct->SDIO_TransferDir));
- assert_param(IS_SDIO_TRANSFER_MODE(SDIO_DataInitStruct->SDIO_TransferMode));
- assert_param(IS_SDIO_DPSM(SDIO_DataInitStruct->SDIO_DPSM));
-
-/*---------------------------- SDIO DTIMER Configuration ---------------------*/
- /* Set the SDIO Data TimeOut value */
- SDIO->DTIMER = SDIO_DataInitStruct->SDIO_DataTimeOut;
-
-/*---------------------------- SDIO DLEN Configuration -----------------------*/
- /* Set the SDIO DataLength value */
- SDIO->DLEN = SDIO_DataInitStruct->SDIO_DataLength;
-
-/*---------------------------- SDIO DCTRL Configuration ----------------------*/
- /* Get the SDIO DCTRL value */
- tmpreg = SDIO->DCTRL;
- /* Clear DEN, DTMODE, DTDIR and DBCKSIZE bits */
- tmpreg &= DCTRL_CLEAR_MASK;
- /* Set DEN bit according to SDIO_DPSM value */
- /* Set DTMODE bit according to SDIO_TransferMode value */
- /* Set DTDIR bit according to SDIO_TransferDir value */
- /* Set DBCKSIZE bits according to SDIO_DataBlockSize value */
- tmpreg |= (uint32_t)SDIO_DataInitStruct->SDIO_DataBlockSize | SDIO_DataInitStruct->SDIO_TransferDir
- | SDIO_DataInitStruct->SDIO_TransferMode | SDIO_DataInitStruct->SDIO_DPSM;
-
- /* Write to SDIO DCTRL */
- SDIO->DCTRL = tmpreg;
-}
-
-/**
- * @brief Fills each SDIO_DataInitStruct member with its default value.
- * @param SDIO_DataInitStruct: pointer to an SDIO_DataInitTypeDef structure
- * which will be initialized.
- * @retval None
- */
-void SDIO_DataStructInit(SDIO_DataInitTypeDef* SDIO_DataInitStruct)
-{
- /* SDIO_DataInitStruct members default value */
- SDIO_DataInitStruct->SDIO_DataTimeOut = 0xFFFFFFFF;
- SDIO_DataInitStruct->SDIO_DataLength = 0x00;
- SDIO_DataInitStruct->SDIO_DataBlockSize = SDIO_DataBlockSize_1b;
- SDIO_DataInitStruct->SDIO_TransferDir = SDIO_TransferDir_ToCard;
- SDIO_DataInitStruct->SDIO_TransferMode = SDIO_TransferMode_Block;
- SDIO_DataInitStruct->SDIO_DPSM = SDIO_DPSM_Disable;
-}
-
-/**
- * @brief Returns number of remaining data bytes to be transferred.
- * @param None
- * @retval Number of remaining data bytes to be transferred
- */
-uint32_t SDIO_GetDataCounter(void)
-{
- return SDIO->DCOUNT;
-}
-
-/**
- * @brief Read one data word from Rx FIFO.
- * @param None
- * @retval Data received
- */
-uint32_t SDIO_ReadData(void)
-{
- return SDIO->FIFO;
-}
-
-/**
- * @brief Write one data word to Tx FIFO.
- * @param Data: 32-bit data word to write.
- * @retval None
- */
-void SDIO_WriteData(uint32_t Data)
-{
- SDIO->FIFO = Data;
-}
-
-/**
- * @brief Returns the number of words left to be written to or read from FIFO.
- * @param None
- * @retval Remaining number of words.
- */
-uint32_t SDIO_GetFIFOCount(void)
-{
- return SDIO->FIFOCNT;
-}
-
-/**
- * @}
- */
-
-/** @defgroup SDIO_Group4 SDIO IO Cards mode management functions
- * @brief SDIO IO Cards mode management functions
- *
-@verbatim
- ===============================================================================
- SDIO IO Cards mode management functions
- ===============================================================================
-
- This section provide functions allowing to program and read the SDIO IO Cards.
-
-@endverbatim
- * @{
- */
-
-/**
- * @brief Starts the SD I/O Read Wait operation.
- * @param NewState: new state of the Start SDIO Read Wait operation.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void SDIO_StartSDIOReadWait(FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- *(__IO uint32_t *) DCTRL_RWSTART_BB = (uint32_t) NewState;
-}
-
-/**
- * @brief Stops the SD I/O Read Wait operation.
- * @param NewState: new state of the Stop SDIO Read Wait operation.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void SDIO_StopSDIOReadWait(FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- *(__IO uint32_t *) DCTRL_RWSTOP_BB = (uint32_t) NewState;
-}
-
-/**
- * @brief Sets one of the two options of inserting read wait interval.
- * @param SDIO_ReadWaitMode: SD I/O Read Wait operation mode.
- * This parameter can be:
- * @arg SDIO_ReadWaitMode_CLK: Read Wait control by stopping SDIOCLK
- * @arg SDIO_ReadWaitMode_DATA2: Read Wait control using SDIO_DATA2
- * @retval None
- */
-void SDIO_SetSDIOReadWaitMode(uint32_t SDIO_ReadWaitMode)
-{
- /* Check the parameters */
- assert_param(IS_SDIO_READWAIT_MODE(SDIO_ReadWaitMode));
-
- *(__IO uint32_t *) DCTRL_RWMOD_BB = SDIO_ReadWaitMode;
-}
-
-/**
- * @brief Enables or disables the SD I/O Mode Operation.
- * @param NewState: new state of SDIO specific operation.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void SDIO_SetSDIOOperation(FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- *(__IO uint32_t *) DCTRL_SDIOEN_BB = (uint32_t)NewState;
-}
-
-/**
- * @brief Enables or disables the SD I/O Mode suspend command sending.
- * @param NewState: new state of the SD I/O Mode suspend command.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void SDIO_SendSDIOSuspendCmd(FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- *(__IO uint32_t *) CMD_SDIOSUSPEND_BB = (uint32_t)NewState;
-}
-
-/**
- * @}
- */
-
-/** @defgroup SDIO_Group5 CE-ATA mode management functions
- * @brief CE-ATA mode management functions
- *
-@verbatim
- ===============================================================================
- CE-ATA mode management functions
- ===============================================================================
-
- This section provide functions allowing to program and read the CE-ATA card.
-
-@endverbatim
- * @{
- */
-
-/**
- * @brief Enables or disables the command completion signal.
- * @param NewState: new state of command completion signal.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void SDIO_CommandCompletionCmd(FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- *(__IO uint32_t *) CMD_ENCMDCOMPL_BB = (uint32_t)NewState;
-}
-
-/**
- * @brief Enables or disables the CE-ATA interrupt.
- * @param NewState: new state of CE-ATA interrupt.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void SDIO_CEATAITCmd(FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- *(__IO uint32_t *) CMD_NIEN_BB = (uint32_t)((~((uint32_t)NewState)) & ((uint32_t)0x1));
-}
-
-/**
- * @brief Sends CE-ATA command (CMD61).
- * @param NewState: new state of CE-ATA command.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void SDIO_SendCEATACmd(FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- *(__IO uint32_t *) CMD_ATACMD_BB = (uint32_t)NewState;
-}
-
-/**
- * @}
- */
-
-/** @defgroup SDIO_Group6 DMA transfers management functions
- * @brief DMA transfers management functions
- *
-@verbatim
- ===============================================================================
- DMA transfers management functions
- ===============================================================================
-
- This section provide functions allowing to program SDIO DMA transfer.
-
-@endverbatim
- * @{
- */
-
-/**
- * @brief Enables or disables the SDIO DMA request.
- * @param NewState: new state of the selected SDIO DMA request.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void SDIO_DMACmd(FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- *(__IO uint32_t *) DCTRL_DMAEN_BB = (uint32_t)NewState;
-}
-
-/**
- * @}
- */
-
-/** @defgroup SDIO_Group7 Interrupts and flags management functions
- * @brief Interrupts and flags management functions
- *
-@verbatim
- ===============================================================================
- Interrupts and flags management functions
- ===============================================================================
-
-
-@endverbatim
- * @{
- */
-
-/**
- * @brief Enables or disables the SDIO interrupts.
- * @param SDIO_IT: specifies the SDIO interrupt sources to be enabled or disabled.
- * This parameter can be one or a combination of the following values:
- * @arg SDIO_IT_CCRCFAIL: Command response received (CRC check failed) interrupt
- * @arg SDIO_IT_DCRCFAIL: Data block sent/received (CRC check failed) interrupt
- * @arg SDIO_IT_CTIMEOUT: Command response timeout interrupt
- * @arg SDIO_IT_DTIMEOUT: Data timeout interrupt
- * @arg SDIO_IT_TXUNDERR: Transmit FIFO underrun error interrupt
- * @arg SDIO_IT_RXOVERR: Received FIFO overrun error interrupt
- * @arg SDIO_IT_CMDREND: Command response received (CRC check passed) interrupt
- * @arg SDIO_IT_CMDSENT: Command sent (no response required) interrupt
- * @arg SDIO_IT_DATAEND: Data end (data counter, SDIDCOUNT, is zero) interrupt
- * @arg SDIO_IT_STBITERR: Start bit not detected on all data signals in wide
- * bus mode interrupt
- * @arg SDIO_IT_DBCKEND: Data block sent/received (CRC check passed) interrupt
- * @arg SDIO_IT_CMDACT: Command transfer in progress interrupt
- * @arg SDIO_IT_TXACT: Data transmit in progress interrupt
- * @arg SDIO_IT_RXACT: Data receive in progress interrupt
- * @arg SDIO_IT_TXFIFOHE: Transmit FIFO Half Empty interrupt
- * @arg SDIO_IT_RXFIFOHF: Receive FIFO Half Full interrupt
- * @arg SDIO_IT_TXFIFOF: Transmit FIFO full interrupt
- * @arg SDIO_IT_RXFIFOF: Receive FIFO full interrupt
- * @arg SDIO_IT_TXFIFOE: Transmit FIFO empty interrupt
- * @arg SDIO_IT_RXFIFOE: Receive FIFO empty interrupt
- * @arg SDIO_IT_TXDAVL: Data available in transmit FIFO interrupt
- * @arg SDIO_IT_RXDAVL: Data available in receive FIFO interrupt
- * @arg SDIO_IT_SDIOIT: SD I/O interrupt received interrupt
- * @arg SDIO_IT_CEATAEND: CE-ATA command completion signal received for CMD61 interrupt
- * @param NewState: new state of the specified SDIO interrupts.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void SDIO_ITConfig(uint32_t SDIO_IT, FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_SDIO_IT(SDIO_IT));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- if (NewState != DISABLE)
- {
- /* Enable the SDIO interrupts */
- SDIO->MASK |= SDIO_IT;
- }
- else
- {
- /* Disable the SDIO interrupts */
- SDIO->MASK &= ~SDIO_IT;
- }
-}
-
-/**
- * @brief Checks whether the specified SDIO flag is set or not.
- * @param SDIO_FLAG: specifies the flag to check.
- * This parameter can be one of the following values:
- * @arg SDIO_FLAG_CCRCFAIL: Command response received (CRC check failed)
- * @arg SDIO_FLAG_DCRCFAIL: Data block sent/received (CRC check failed)
- * @arg SDIO_FLAG_CTIMEOUT: Command response timeout
- * @arg SDIO_FLAG_DTIMEOUT: Data timeout
- * @arg SDIO_FLAG_TXUNDERR: Transmit FIFO underrun error
- * @arg SDIO_FLAG_RXOVERR: Received FIFO overrun error
- * @arg SDIO_FLAG_CMDREND: Command response received (CRC check passed)
- * @arg SDIO_FLAG_CMDSENT: Command sent (no response required)
- * @arg SDIO_FLAG_DATAEND: Data end (data counter, SDIDCOUNT, is zero)
- * @arg SDIO_FLAG_STBITERR: Start bit not detected on all data signals in wide bus mode.
- * @arg SDIO_FLAG_DBCKEND: Data block sent/received (CRC check passed)
- * @arg SDIO_FLAG_CMDACT: Command transfer in progress
- * @arg SDIO_FLAG_TXACT: Data transmit in progress
- * @arg SDIO_FLAG_RXACT: Data receive in progress
- * @arg SDIO_FLAG_TXFIFOHE: Transmit FIFO Half Empty
- * @arg SDIO_FLAG_RXFIFOHF: Receive FIFO Half Full
- * @arg SDIO_FLAG_TXFIFOF: Transmit FIFO full
- * @arg SDIO_FLAG_RXFIFOF: Receive FIFO full
- * @arg SDIO_FLAG_TXFIFOE: Transmit FIFO empty
- * @arg SDIO_FLAG_RXFIFOE: Receive FIFO empty
- * @arg SDIO_FLAG_TXDAVL: Data available in transmit FIFO
- * @arg SDIO_FLAG_RXDAVL: Data available in receive FIFO
- * @arg SDIO_FLAG_SDIOIT: SD I/O interrupt received
- * @arg SDIO_FLAG_CEATAEND: CE-ATA command completion signal received for CMD61
- * @retval The new state of SDIO_FLAG (SET or RESET).
- */
-FlagStatus SDIO_GetFlagStatus(uint32_t SDIO_FLAG)
-{
- FlagStatus bitstatus = RESET;
-
- /* Check the parameters */
- assert_param(IS_SDIO_FLAG(SDIO_FLAG));
-
- if ((SDIO->STA & SDIO_FLAG) != (uint32_t)RESET)
- {
- bitstatus = SET;
- }
- else
- {
- bitstatus = RESET;
- }
- return bitstatus;
-}
-
-/**
- * @brief Clears the SDIO's pending flags.
- * @param SDIO_FLAG: specifies the flag to clear.
- * This parameter can be one or a combination of the following values:
- * @arg SDIO_FLAG_CCRCFAIL: Command response received (CRC check failed)
- * @arg SDIO_FLAG_DCRCFAIL: Data block sent/received (CRC check failed)
- * @arg SDIO_FLAG_CTIMEOUT: Command response timeout
- * @arg SDIO_FLAG_DTIMEOUT: Data timeout
- * @arg SDIO_FLAG_TXUNDERR: Transmit FIFO underrun error
- * @arg SDIO_FLAG_RXOVERR: Received FIFO overrun error
- * @arg SDIO_FLAG_CMDREND: Command response received (CRC check passed)
- * @arg SDIO_FLAG_CMDSENT: Command sent (no response required)
- * @arg SDIO_FLAG_DATAEND: Data end (data counter, SDIDCOUNT, is zero)
- * @arg SDIO_FLAG_STBITERR: Start bit not detected on all data signals in wide bus mode
- * @arg SDIO_FLAG_DBCKEND: Data block sent/received (CRC check passed)
- * @arg SDIO_FLAG_SDIOIT: SD I/O interrupt received
- * @arg SDIO_FLAG_CEATAEND: CE-ATA command completion signal received for CMD61
- * @retval None
- */
-void SDIO_ClearFlag(uint32_t SDIO_FLAG)
-{
- /* Check the parameters */
- assert_param(IS_SDIO_CLEAR_FLAG(SDIO_FLAG));
-
- SDIO->ICR = SDIO_FLAG;
-}
-
-/**
- * @brief Checks whether the specified SDIO interrupt has occurred or not.
- * @param SDIO_IT: specifies the SDIO interrupt source to check.
- * This parameter can be one of the following values:
- * @arg SDIO_IT_CCRCFAIL: Command response received (CRC check failed) interrupt
- * @arg SDIO_IT_DCRCFAIL: Data block sent/received (CRC check failed) interrupt
- * @arg SDIO_IT_CTIMEOUT: Command response timeout interrupt
- * @arg SDIO_IT_DTIMEOUT: Data timeout interrupt
- * @arg SDIO_IT_TXUNDERR: Transmit FIFO underrun error interrupt
- * @arg SDIO_IT_RXOVERR: Received FIFO overrun error interrupt
- * @arg SDIO_IT_CMDREND: Command response received (CRC check passed) interrupt
- * @arg SDIO_IT_CMDSENT: Command sent (no response required) interrupt
- * @arg SDIO_IT_DATAEND: Data end (data counter, SDIDCOUNT, is zero) interrupt
- * @arg SDIO_IT_STBITERR: Start bit not detected on all data signals in wide
- * bus mode interrupt
- * @arg SDIO_IT_DBCKEND: Data block sent/received (CRC check passed) interrupt
- * @arg SDIO_IT_CMDACT: Command transfer in progress interrupt
- * @arg SDIO_IT_TXACT: Data transmit in progress interrupt
- * @arg SDIO_IT_RXACT: Data receive in progress interrupt
- * @arg SDIO_IT_TXFIFOHE: Transmit FIFO Half Empty interrupt
- * @arg SDIO_IT_RXFIFOHF: Receive FIFO Half Full interrupt
- * @arg SDIO_IT_TXFIFOF: Transmit FIFO full interrupt
- * @arg SDIO_IT_RXFIFOF: Receive FIFO full interrupt
- * @arg SDIO_IT_TXFIFOE: Transmit FIFO empty interrupt
- * @arg SDIO_IT_RXFIFOE: Receive FIFO empty interrupt
- * @arg SDIO_IT_TXDAVL: Data available in transmit FIFO interrupt
- * @arg SDIO_IT_RXDAVL: Data available in receive FIFO interrupt
- * @arg SDIO_IT_SDIOIT: SD I/O interrupt received interrupt
- * @arg SDIO_IT_CEATAEND: CE-ATA command completion signal received for CMD61 interrupt
- * @retval The new state of SDIO_IT (SET or RESET).
- */
-ITStatus SDIO_GetITStatus(uint32_t SDIO_IT)
-{
- ITStatus bitstatus = RESET;
-
- /* Check the parameters */
- assert_param(IS_SDIO_GET_IT(SDIO_IT));
- if ((SDIO->STA & SDIO_IT) != (uint32_t)RESET)
- {
- bitstatus = SET;
- }
- else
- {
- bitstatus = RESET;
- }
- return bitstatus;
-}
-
-/**
- * @brief Clears the SDIO's interrupt pending bits.
- * @param SDIO_IT: specifies the interrupt pending bit to clear.
- * This parameter can be one or a combination of the following values:
- * @arg SDIO_IT_CCRCFAIL: Command response received (CRC check failed) interrupt
- * @arg SDIO_IT_DCRCFAIL: Data block sent/received (CRC check failed) interrupt
- * @arg SDIO_IT_CTIMEOUT: Command response timeout interrupt
- * @arg SDIO_IT_DTIMEOUT: Data timeout interrupt
- * @arg SDIO_IT_TXUNDERR: Transmit FIFO underrun error interrupt
- * @arg SDIO_IT_RXOVERR: Received FIFO overrun error interrupt
- * @arg SDIO_IT_CMDREND: Command response received (CRC check passed) interrupt
- * @arg SDIO_IT_CMDSENT: Command sent (no response required) interrupt
- * @arg SDIO_IT_DATAEND: Data end (data counter, SDIO_DCOUNT, is zero) interrupt
- * @arg SDIO_IT_STBITERR: Start bit not detected on all data signals in wide
- * bus mode interrupt
- * @arg SDIO_IT_SDIOIT: SD I/O interrupt received interrupt
- * @arg SDIO_IT_CEATAEND: CE-ATA command completion signal received for CMD61
- * @retval None
- */
-void SDIO_ClearITPendingBit(uint32_t SDIO_IT)
-{
- /* Check the parameters */
- assert_param(IS_SDIO_CLEAR_IT(SDIO_IT));
-
- SDIO->ICR = SDIO_IT;
-}
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-
-/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/sdio/sdio_sd.c b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/sdio/sdio_sd.c
deleted file mode 100644
index 4e20ff070..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/sdio/sdio_sd.c
+++ /dev/null
@@ -1,2820 +0,0 @@
-/*
- * Copyright (c) Guangzhou Xingyi Electronic Technology Co., Ltd
- *
- * Change Logs:
- * Date Author Notes
- * 2014-7-4 alientek first version
- */
-
-/**
-* @file sdio_sd.c
-* @brief support hal sdio function
-* @version 1.0
-* @author AIIT XUOS Lab
-* @date 2021-04-22
-*/
-
-/*********************************************************************************
- * file :sdio_sd.c
- * description:4bit sdio driver on stm32f407
- * hardware connection:
- * ------------------------------
- * | PC8 -SDIO-D0 :DATA0 |
- * | PC9 -SDIO-D1 :DATA1 |
- * | PC10-SDIO-D2 :DATA2 |
- * | PC11-SDIO-D3 :CD/DATA3 |
- * | PC12-SDIO-CLK:CLK |
- * | PD2 -SDIO-CMD:CMD |
- * ------------------------------
- * ***** : *******************************
- * ***** : *******************************
-**********************************************************************************/
-
-/*************************************************
-File name: sdio_sd.c
-Description: support stm32f407 sdio
-Others: hardware/sdio/sdio.c for references
-History:
-1. Date: 2021-04-22
-Author: AIIT XUOS Lab
-Modification: Support stm32f407-discovery-board sdio using source files
-*************************************************/
-
-#include "sdio_sd.h"
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-/* Private macro -------------------------------------------------------------*/
-/**
- * @brief SDIO Static flags, TimeOut, FIFO Address
- */
-
-/*#define NULL 0*/
-
-#define SDIO_STATIC_FLAGS ((uint32_t)0x000005FF)
-#define SDIO_CMD0TIMEOUT ((uint32_t)0x00010000)
-
-/**
- * @brief Mask for errors Card Status R1 (OCR Register)
- */
-#define SD_OCR_ADDR_OUT_OF_RANGE ((uint32_t)0x80000000)
-#define SD_OCR_ADDR_MISALIGNED ((uint32_t)0x40000000)
-#define SD_OCR_BLOCK_LEN_ERR ((uint32_t)0x20000000)
-#define SD_OCR_ERASE_SEQ_ERR ((uint32_t)0x10000000)
-#define SD_OCR_BAD_ERASE_PARAM ((uint32_t)0x08000000)
-#define SD_OCR_WRITE_PROT_VIOLATION ((uint32_t)0x04000000)
-#define SD_OCR_LOCK_UNLOCK_FAILED ((uint32_t)0x01000000)
-#define SD_OCR_COM_CRC_FAILED ((uint32_t)0x00800000)
-#define SD_OCR_ILLEGAL_CMD ((uint32_t)0x00400000)
-#define SD_OCR_CARD_ECC_FAILED ((uint32_t)0x00200000)
-#define SD_OCR_CC_ERROR ((uint32_t)0x00100000)
-#define SD_OCR_GENERAL_UNKNOWN_ERROR ((uint32_t)0x00080000)
-#define SD_OCR_STREAM_READ_UNDERRUN ((uint32_t)0x00040000)
-#define SD_OCR_STREAM_WRITE_OVERRUN ((uint32_t)0x00020000)
-#define SD_OCR_CID_CSD_OVERWRIETE ((uint32_t)0x00010000)
-#define SD_OCR_WP_ERASE_SKIP ((uint32_t)0x00008000)
-#define SD_OCR_CARD_ECC_DISABLED ((uint32_t)0x00004000)
-#define SD_OCR_ERASE_RESET ((uint32_t)0x00002000)
-#define SD_OCR_AKE_SEQ_ERROR ((uint32_t)0x00000008)
-#define SD_OCR_ERRORBITS ((uint32_t)0xFDFFE008)
-
-/**
- * @brief Masks for R6 Response
- */
-#define SD_R6_GENERAL_UNKNOWN_ERROR ((uint32_t)0x00002000)
-#define SD_R6_ILLEGAL_CMD ((uint32_t)0x00004000)
-#define SD_R6_COM_CRC_FAILED ((uint32_t)0x00008000)
-
-#define SD_VOLTAGE_WINDOW_SD ((uint32_t)0x80100000)
-#define SD_HIGH_CAPACITY ((uint32_t)0x40000000)
-#define SD_STD_CAPACITY ((uint32_t)0x00000000)
-#define SD_CHECK_PATTERN ((uint32_t)0x000001AA)
-
-#define SD_MAX_VOLT_TRIAL ((uint32_t)0x0000FFFF)
-#define SD_ALLZERO ((uint32_t)0x00000000)
-
-#define SD_WIDE_BUS_SUPPORT ((uint32_t)0x00040000)
-#define SD_SINGLE_BUS_SUPPORT ((uint32_t)0x00010000)
-#define SD_CARD_LOCKED ((uint32_t)0x02000000)
-
-#define SD_DATATIMEOUT ((uint32_t)0xFFFFFFFF)
-#define SD_0TO7BITS ((uint32_t)0x000000FF)
-#define SD_8TO15BITS ((uint32_t)0x0000FF00)
-#define SD_16TO23BITS ((uint32_t)0x00FF0000)
-#define SD_24TO31BITS ((uint32_t)0xFF000000)
-#define SD_MAX_DATA_LENGTH ((uint32_t)0x01FFFFFF)
-
-#define SD_HALFFIFO ((uint32_t)0x00000008)
-#define SD_HALFFIFOBYTES ((uint32_t)0x00000020)
-
-/**
- * @brief Command Class Supported
- */
-#define SD_CCCC_LOCK_UNLOCK ((uint32_t)0x00000080)
-#define SD_CCCC_WRITE_PROT ((uint32_t)0x00000040)
-#define SD_CCCC_ERASE ((uint32_t)0x00000020)
-
-/**
- * @brief Following commands are SD Card Specific commands.
- * SDIO_APP_CMD should be sent before sending these commands.
- */
-#define SDIO_SEND_IF_COND ((uint32_t)0x00000008)
-
-
-
-/* Private variables ---------------------------------------------------------*/
-//static uint32_t CardType = SDIO_STD_CAPACITY_SD_CARD_V1_1; //sd card type, init it to v1.1
-static uint32_t CSD_Tab[4], CID_Tab[4], RCA = 0; //CSD,DID,register and card address
-static uint8_t SDSTATUS_Tab[16]; //sd card type, part of CSR
-__IO uint32_t StopCondition = 0; //sign for stopping operate card
-__IO SD_Error TransferError = SD_OK; //sign for showing card error, init as normal
-__IO uint32_t DMAEndOfTransfer = 0;
-__IO uint32_t TransferEnd = 0; //sign for showing if transfer is over, using in irq
-SD_CardInfo SDCardInfo; //SD card info
-
-/*SDIO init struct*/
-SDIO_InitTypeDef SDIO_InitStructure;
-SDIO_CmdInitTypeDef SDIO_CmdInitStructure;
-SDIO_DataInitTypeDef SDIO_DataInitStructure;
-
-
-/* Private function prototypes -----------------------------------------------*/
-static SD_Error CmdError(void);
-static SD_Error CmdResp1Error(uint8_t cmd);
-static SD_Error CmdResp7Error(void);
-static SD_Error CmdResp3Error(void);
-static SD_Error CmdResp2Error(void);
-static SD_Error CmdResp6Error(uint8_t cmd, uint16_t *prca);
-static SD_Error SDEnWideBus(FunctionalState NewState);
-static SD_Error IsCardProgramming(uint8_t *pstatus);
-static SD_Error FindSCR(uint16_t rca, uint32_t *pscr);
-
-static void SD_GPIO_Configuration(void);
-static void SD_DMA_RxConfig(uint32_t *BufferDST, uint32_t BufferSize);
-static void SD_DMA_TxConfig(uint32_t *BufferSRC, uint32_t BufferSize);
-static uint32_t SD_DMAEndOfTransferStatus(void);
-
-uint8_t convert_from_bytes_to_power_of_two(uint16_t NumberOfBytes);
-
-/* Private functions ---------------------------------------------------------*/
-
-
-uint8_t SD_Detect(void)
-{
- __IO uint8_t status = SD_PRESENT;
-
- /*!< Check GPIO to detect SD */
-// if (GPIO_ReadInputDataBit(SD_DETECT_GPIO_PORT, SD_DETECT_PIN) != Bit_RESET)
-// {
-// status = SD_NOT_PRESENT;
-// }
- return status;
-}
-
-/**
- * @brief Configures SDIO IRQ channel.
- * @param None
- * @retval None
- */
-void SD_NVIC_Configuration(void)
-{
- NVIC_InitTypeDef NVIC_InitStructure;
-
- /* Configure the NVIC Preemption Priority Bits */
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
-
- NVIC_InitStructure.NVIC_IRQChannel = SDIO_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
-
- NVIC_InitStructure.NVIC_IRQChannel = DMA2_Stream6_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
-}
-
-/**
- * @brief Returns the DMA End Of Transfer Status.
- * @param None
- * @retval DMA SDIO Channel Status.
- */
-uint32_t SD_DMAEndOfTransferStatus(void)
-{
- return (uint32_t)DMA_GetFlagStatus(SD_SDIO_DMA_STREAM, SD_SDIO_DMA_FLAG_TCIF); //Channel4 transfer complete flag.
-}
-
-
-void SD_DMA_RxConfig(uint32_t *BufferDST, uint32_t BufferSize)
-{
- DMA_InitTypeDef DMA_InitStructure;
-
- DMA_ClearFlag(SD_SDIO_DMA_STREAM, SD_SDIO_DMA_FLAG_FEIF | SD_SDIO_DMA_FLAG_DMEIF | SD_SDIO_DMA_FLAG_TEIF | SD_SDIO_DMA_FLAG_HTIF | SD_SDIO_DMA_FLAG_TCIF);
-
- /*!< DMA2 Stream6 disable */
- DMA_Cmd(SD_SDIO_DMA_STREAM, DISABLE);
-
- DMA_DeInit(SD_SDIO_DMA_STREAM);
- /*!< DMA2 Channel4 Config */
- DMA_InitStructure.DMA_Channel = SD_SDIO_DMA_CHANNEL;
- DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)SDIO_FIFO_ADDRESS;
- DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)BufferDST;
- DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
- //DMA_InitStructure.DMA_BufferSize = BufferSize / 4;
- DMA_InitStructure.DMA_BufferSize = BufferSize;
- DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
- DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
- DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;
- //DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;
- DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
- DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
- DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
- DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Enable;
- DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full;
- DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_INC4;
- DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_INC4;
- DMA_Init(SD_SDIO_DMA_STREAM, &DMA_InitStructure);
- /*!< DMA2 Channel4 enable */
-// DMA_ITConfig(SD_SDIO_DMA_STREAM,DMA_IT_TC,ENABLE);
- DMA_FlowControllerConfig(SD_SDIO_DMA_STREAM, DMA_FlowCtrl_Peripheral);
- DMA_Cmd(SD_SDIO_DMA_STREAM, ENABLE);
-}
-
-
-void SD_DMA_TxConfig(uint32_t *BufferSRC, uint32_t BufferSize)
-{
-
- DMA_InitTypeDef DMA_InitStructure;
-
- DMA_ClearFlag(SD_SDIO_DMA_STREAM, SD_SDIO_DMA_FLAG_FEIF | SD_SDIO_DMA_FLAG_DMEIF | SD_SDIO_DMA_FLAG_TEIF | SD_SDIO_DMA_FLAG_HTIF | SD_SDIO_DMA_FLAG_TCIF);
-
- /*!< DMA2 Stream6 disable */
- DMA_Cmd(SD_SDIO_DMA_STREAM, DISABLE);
- DMA_DeInit(SD_SDIO_DMA_STREAM);
- /*!< DMA2 Channel4 Config */
- DMA_InitStructure.DMA_Channel = SD_SDIO_DMA_CHANNEL;
- DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)SDIO_FIFO_ADDRESS;
- DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)BufferSRC;
- DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral;
- //DMA_InitStructure.DMA_BufferSize = BufferSize / 4;
- DMA_InitStructure.DMA_BufferSize = BufferSize;
- DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
- DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
- DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;
- //DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;
- DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
- DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
- DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
- DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Enable;
- DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full;
- DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_INC4;
- DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_INC4;
- DMA_Init(SD_SDIO_DMA_STREAM, &DMA_InitStructure);
- /*!< DMA2 Channel4 enable */
-// DMA_ITConfig(SD_SDIO_DMA_STREAM,DMA_IT_TC,ENABLE);
- DMA_FlowControllerConfig(SD_SDIO_DMA_STREAM, DMA_FlowCtrl_Peripheral);
- DMA_Cmd(SD_SDIO_DMA_STREAM, ENABLE);
-
-}
-
-
-static void SD_GPIO_Configuration(void)
-{
- GPIO_InitTypeDef gpio_initstructure;
-
- /*!< GPIOC and GPIOD Periph clock enable */
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOD, ENABLE);
-
- GPIO_PinAFConfig(GPIOC, GPIO_PinSource8, GPIO_AF_SDIO);
- GPIO_PinAFConfig(GPIOC, GPIO_PinSource9, GPIO_AF_SDIO);
- GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_SDIO);
- GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_SDIO);
- GPIO_PinAFConfig(GPIOC, GPIO_PinSource12, GPIO_AF_SDIO);
- GPIO_PinAFConfig(GPIOD, GPIO_PinSource2, GPIO_AF_SDIO);
-
- /*!< Configure PC.08, PC.09, PC.10, PC.11, PC.12 pin: D0, D1, D2, D3, CLK pin */
- gpio_initstructure.GPIO_Pin = GPIO_Pin_8;
- gpio_initstructure.GPIO_Speed = GPIO_Speed_50MHz;
- gpio_initstructure.GPIO_Mode = GPIO_Mode_AF;
- gpio_initstructure.GPIO_PuPd = GPIO_PuPd_UP;
- gpio_initstructure.GPIO_OType = GPIO_OType_PP;
- GPIO_Init(GPIOC, &gpio_initstructure);
-
- gpio_initstructure.GPIO_Pin = GPIO_Pin_9;
- GPIO_Init(GPIOC, &gpio_initstructure);
-
- gpio_initstructure.GPIO_Pin = GPIO_Pin_10;
- GPIO_Init(GPIOC, &gpio_initstructure);
-
- gpio_initstructure.GPIO_Pin = GPIO_Pin_11;
- GPIO_Init(GPIOC, &gpio_initstructure);
-
- gpio_initstructure.GPIO_Pin = GPIO_Pin_2;
- GPIO_Init(GPIOD, &gpio_initstructure);
-
- gpio_initstructure.GPIO_Pin = GPIO_Pin_12;
- gpio_initstructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
- GPIO_Init(GPIOC, &gpio_initstructure);
-
- /*!< Configure PD.02 CMD line */
-
- /*!< Configure SD_SPI_DETECT_PIN pin: SD Card detect pin */
-// gpio_initstructure.GPIO_Pin = SD_DETECT_PIN;
-// gpio_initstructure.GPIO_Mode = GPIO_Mode_IN;
-// GPIO_Init(SD_DETECT_GPIO_PORT, &gpio_initstructure);
-
- /*!< Enable the SDIO AHB Clock */
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_SDIO, ENABLE);
- RCC_APB2PeriphResetCmd(RCC_APB2Periph_SDIO, ENABLE);
-
- /*!< Enable the DMA2 Clock */
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE);
-}
-
-
-SD_Error SD_Init(void)
-{
- SD_Error errorstatus = SD_OK;
-
- SD_NVIC_Configuration();
-
- SD_GPIO_Configuration();
-
- SDIO_DeInit();
-
- errorstatus = SD_PowerON();
-
- if (errorstatus != SD_OK)
- {
- /*!< CMD Response TimeOut (wait for CMDSENT flag) */
- return(errorstatus);
- }
-
- errorstatus = SD_InitializeCards();
-
- if (errorstatus != SD_OK)
- {
- /*!< CMD Response TimeOut (wait for CMDSENT flag) */
- return(errorstatus);
- }
-
- /*!< Configure the SDIO peripheral
- !< SDIOCLK = HCLK, SDIO_CK = HCLK/(2 + SDIO_TRANSFER_CLK_DIV) */
- SDIO_InitStructure.SDIO_ClockDiv = SDIO_TRANSFER_CLK_DIV;
- SDIO_InitStructure.SDIO_ClockEdge = SDIO_ClockEdge_Rising;
- SDIO_InitStructure.SDIO_ClockBypass = SDIO_ClockBypass_Disable;
- SDIO_InitStructure.SDIO_ClockPowerSave = SDIO_ClockPowerSave_Disable; //enable the function, close SD_CLK when bus is not busy
- SDIO_InitStructure.SDIO_BusWide = SDIO_BusWide_1b;
- SDIO_InitStructure.SDIO_HardwareFlowControl = SDIO_HardwareFlowControl_Disable;
- SDIO_Init(&SDIO_InitStructure);
-
- if (errorstatus == SD_OK)
- {
- /*----------------- Read CSD/CID MSD registers ------------------*/
- errorstatus = SD_GetCardInfo(&SDCardInfo); //read csd/cid register
- }
-
- if (errorstatus == SD_OK)
- {
- /*----------------- Select Card --------------------------------*/
- errorstatus = SD_SelectDeselect((uint32_t) (SDCardInfo.RCA << 16)); //use cmd7 ,rca choose the card
- }
-
- if (errorstatus == SD_OK)
- {
- errorstatus = SD_EnableWideBusOperation(SDIO_BusWide_4b);
- }
-
- return(errorstatus);
-}
-
-/**
- * @brief Gets the cuurent sd card data transfer status.
- * @param None
- * @retval SDTransferState: Data Transfer state.
- * This value can be:
- * - SD_TRANSFER_OK: No data transfer is acting
- * - SD_TRANSFER_BUSY: Data transfer is acting
- */
-SDTransferState SD_GetStatus(void)
-{
- SDCardState cardstate = SD_CARD_TRANSFER;
-
- cardstate = SD_GetState();
-
- if (cardstate == SD_CARD_TRANSFER)
- {
- return(SD_TRANSFER_OK);
- }
- else if(cardstate == SD_CARD_ERROR)
- {
- return (SD_TRANSFER_ERROR);
- }
- else
- {
- return(SD_TRANSFER_BUSY);
- }
-}
-
-/**
- * @brief Returns the current card's state.
- * @param None
- * @retval SDCardState: SD Card Error or SD Card Current State.
- */
-SDCardState SD_GetState(void)
-{
- uint32_t resp1 = 0;
- if(SD_Detect()== SD_PRESENT)
- {
- if (SD_SendStatus(&resp1) != SD_OK)
- {
- return SD_CARD_ERROR;
- }
- else
- {
- return (SDCardState)((resp1 >> 9) & 0x0F);
- }
- }
- else
- {
- return SD_CARD_ERROR;
- }
-}
-
-
-SD_Error SD_PowerON(void)
-{
- SD_Error errorstatus = SD_OK;
- uint32_t response = 0, count = 0, validvoltage = 0;
- uint32_t SDType = SD_STD_CAPACITY;
-
- /*!< Power ON Sequence -----------------------------------------------------*/
- /*!< Configure the SDIO peripheral */
- /*!< SDIOCLK = HCLK, SDIO_CK = HCLK/(2 + SDIO_INIT_CLK_DIV) */
- /*!< SDIO_CK for initialization should not exceed 400 KHz */
- SDIO_InitStructure.SDIO_ClockDiv = SDIO_INIT_CLK_DIV; /* SDIO_CK = HCLK/(SDIO_INIT_CLK_DIV + 2) */
- SDIO_InitStructure.SDIO_ClockEdge = SDIO_ClockEdge_Rising;
- SDIO_InitStructure.SDIO_ClockBypass = SDIO_ClockBypass_Disable;
- SDIO_InitStructure.SDIO_ClockPowerSave = SDIO_ClockPowerSave_Disable;
- SDIO_InitStructure.SDIO_BusWide = SDIO_BusWide_1b;
- SDIO_InitStructure.SDIO_HardwareFlowControl = SDIO_HardwareFlowControl_Disable;
- SDIO_Init(&SDIO_InitStructure);
-
- /*!< Set Power State to ON */
- SDIO_SetPowerState(SDIO_PowerState_ON);
-
- /*!< Enable SDIO Clock */
- SDIO_ClockCmd(ENABLE);
- /*start to check the card info*/
- /*!< CMD0: GO_IDLE_STATE ---------------------------------------------------*/
- /*!< No CMD response required */
- SDIO_CmdInitStructure.SDIO_Argument = 0x0;
- SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_GO_IDLE_STATE;
- SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_No;
- SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
- SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable; //enable CPSM wait transfer stop before sending cmd
- SDIO_SendCommand(&SDIO_CmdInitStructure);
-
- errorstatus = CmdError();
-
- if (errorstatus != SD_OK)
- {
- /*!< CMD Response TimeOut (wait for CMDSENT flag) */
- return(errorstatus);
- }
- /*!< CMD8: SEND_IF_COND ----------------------------------------------------*/
- /*!< Send CMD8 to verify SD card interface operating condition */
- /*!< Argument: - [31:12]: Reserved (shall be set to '0')
- - [11:8]: Supply Voltage (VHS) 0x1 (Range: 2.7-3.6 V)
- - [7:0]: Check Pattern (recommended 0xAA) */
- /*!< CMD Response: R7 */
- SDIO_CmdInitStructure.SDIO_Argument = SD_CHECK_PATTERN;
- SDIO_CmdInitStructure.SDIO_CmdIndex = SDIO_SEND_IF_COND;
- SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short; //R7
- SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No; //close wait interrupt
- SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
- SDIO_SendCommand(&SDIO_CmdInitStructure);
-
- errorstatus = CmdResp7Error();
-
- if (errorstatus == SD_OK) //follow ver2.0
- {
- SDCardInfo.CardType = SDIO_STD_CAPACITY_SD_CARD_V2_0; /*!< SD Card 2.0 ,define as sdsc firstly */
- SDType = SD_HIGH_CAPACITY; //acmd41, check sdsc or sdhc
- }
- else //no response, v1.x or mmc
- {
- /*!< CMD55 */
- SDIO_CmdInitStructure.SDIO_Argument = 0x00;
- SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_APP_CMD;
- SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
- SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
- SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
- SDIO_SendCommand(&SDIO_CmdInitStructure);
- errorstatus = CmdResp1Error(SD_CMD_APP_CMD);
- }
- /*!< CMD55 */
- //cmd55,check sd or mmc or not support
- SDIO_CmdInitStructure.SDIO_Argument = 0x00;
- SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_APP_CMD;
- SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short; //r1
- SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
- SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
- SDIO_SendCommand(&SDIO_CmdInitStructure);
- errorstatus = CmdResp1Error(SD_CMD_APP_CMD); //check response, if not, mmc or not support
-
- /*!< If errorstatus is Command TimeOut, it is a MMC card */
- /*!< If errorstatus is SD_OK it is a SD card: SD card 2.0 (voltage range mismatch)
- or SD card 1.x */
- if (errorstatus == SD_OK) //response cmd55,sd card, v1.x or v2.0
- {
- /*send voltage cmd */
-
- /*!< SD CARD */
- /*!< Send ACMD41 SD_APP_OP_COND with Argument 0x80100000 */
- while ((!validvoltage) && (count < SD_MAX_VOLT_TRIAL))
- {
- //send CMD55 before ACMD41
- /*!< SEND CMD55 APP_CMD with RCA as 0 */
- SDIO_CmdInitStructure.SDIO_Argument = 0x00;
- SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_APP_CMD;
- SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
- SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
- SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
- SDIO_SendCommand(&SDIO_CmdInitStructure);
-
- errorstatus = CmdResp1Error(SD_CMD_APP_CMD);
-
- if (errorstatus != SD_OK)
- {
- return(errorstatus);
- }
- //ACMD41,cmd param is voltage and HCS(check SDSC or SDHC)
- SDIO_CmdInitStructure.SDIO_Argument = SD_VOLTAGE_WINDOW_SD | SDType;
- SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SD_APP_OP_COND;
- SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short; //r3
- SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
- SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
- SDIO_SendCommand(&SDIO_CmdInitStructure);
-
- errorstatus = CmdResp3Error();
- if (errorstatus != SD_OK)
- {
- return(errorstatus);
- }
-
- response = SDIO_GetResponse(SDIO_RESP1); //read card register and card status
- validvoltage = (((response >> 31) == 1) ? 1 : 0); //read ocr register to check pwr_up bit
- count++;
- }
- if (count >= SD_MAX_VOLT_TRIAL)
- {
- errorstatus = SD_INVALID_VOLTRANGE; //SDIO do not support card voltage
- return(errorstatus);
- }
- /*check HCS bit*/
- if (response &= SD_HIGH_CAPACITY) //check ccs bit of ocr register
- {
- SDCardInfo.CardType = SDIO_HIGH_CAPACITY_SD_CARD;//change SDSC to SDHC
- }
-
- }/*!< else MMC Card */
-
- return(errorstatus);
-}
-
-
-SD_Error SD_PowerOFF(void)
-{
- SD_Error errorstatus = SD_OK;
-
- /*!< Set Power State to OFF */
- SDIO_SetPowerState(SDIO_PowerState_OFF);
-
- return(errorstatus);
-}
-
-
-SD_Error SD_InitializeCards(void)
-{
- SD_Error errorstatus = SD_OK;
- uint16_t rca = 0x01;
-
- if (SDIO_GetPowerState() == SDIO_PowerState_OFF)
- {
- errorstatus = SD_REQUEST_NOT_APPLICABLE;
- return(errorstatus);
- }
-
- if (SDIO_SECURE_DIGITAL_IO_CARD != SDCardInfo.CardType)
- {
- /*!< Send CMD2 ALL_SEND_CID */
- SDIO_CmdInitStructure.SDIO_Argument = 0x0;
- SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_ALL_SEND_CID;
- SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Long;
- SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
- SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
- SDIO_SendCommand(&SDIO_CmdInitStructure);
-
- errorstatus = CmdResp2Error();
-
- if (SD_OK != errorstatus)
- {
- return(errorstatus);
- }
-
- CID_Tab[0] = SDIO_GetResponse(SDIO_RESP1);
- CID_Tab[1] = SDIO_GetResponse(SDIO_RESP2);
- CID_Tab[2] = SDIO_GetResponse(SDIO_RESP3);
- CID_Tab[3] = SDIO_GetResponse(SDIO_RESP4);
- }
-
- /*SD card init*/
- if ((SDIO_STD_CAPACITY_SD_CARD_V1_1 == SDCardInfo.CardType) || (SDIO_STD_CAPACITY_SD_CARD_V2_0 == SDCardInfo.CardType)
- || (SDIO_SECURE_DIGITAL_IO_COMBO_CARD == SDCardInfo.CardType) || (SDIO_HIGH_CAPACITY_SD_CARD == SDCardInfo.CardType)) //使用的是2.0的卡
- {
- /*!< Send CMD3 SET_REL_ADDR with argument 0 */
- /*!< SD Card publishes its RCA. */
- SDIO_CmdInitStructure.SDIO_Argument = 0x00;
- SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SET_REL_ADDR;//CMD3
- SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;//R6
- SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
- SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
- SDIO_SendCommand(&SDIO_CmdInitStructure);
-
- errorstatus = CmdResp6Error(SD_CMD_SET_REL_ADDR, &rca); //store address
-
- if (SD_OK != errorstatus)
- {
- return(errorstatus);
- }
- }
-
- if (SDIO_SECURE_DIGITAL_IO_CARD != SDCardInfo.CardType)
- {
- RCA = rca;
-
- /*!< Send CMD9 SEND_CSD with argument as card's RCA */
- SDIO_CmdInitStructure.SDIO_Argument = (uint32_t)(rca << 16);
- SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SEND_CSD;
- SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Long;
- SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
- SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
- SDIO_SendCommand(&SDIO_CmdInitStructure);
-
- errorstatus = CmdResp2Error();
-
- if (SD_OK != errorstatus)
- {
- return(errorstatus);
- }
-
- CSD_Tab[0] = SDIO_GetResponse(SDIO_RESP1);
- CSD_Tab[1] = SDIO_GetResponse(SDIO_RESP2);
- CSD_Tab[2] = SDIO_GetResponse(SDIO_RESP3);
- CSD_Tab[3] = SDIO_GetResponse(SDIO_RESP4);
- }
-
- errorstatus = SD_OK; /*!< All cards get intialized */
-
- return(errorstatus);
-}
-
-
-SD_Error SD_GetCardInfo(SD_CardInfo *cardinfo)
-{
- SD_Error errorstatus = SD_OK;
- uint8_t tmp = 0;
-
- cardinfo->CardType = (uint8_t)SDCardInfo.CardType;
- cardinfo->RCA = (uint16_t)RCA;
-
- /*!< Byte 0 */
- tmp = (uint8_t)((CSD_Tab[0] & 0xFF000000) >> 24);
- cardinfo->SD_csd.CSDStruct = (tmp & 0xC0) >> 6;
- cardinfo->SD_csd.SysSpecVersion = (tmp & 0x3C) >> 2;
- cardinfo->SD_csd.Reserved1 = tmp & 0x03;
-
- /*!< Byte 1 */
- tmp = (uint8_t)((CSD_Tab[0] & 0x00FF0000) >> 16);
- cardinfo->SD_csd.TAAC = tmp;
-
- /*!< Byte 2 */
- tmp = (uint8_t)((CSD_Tab[0] & 0x0000FF00) >> 8);
- cardinfo->SD_csd.NSAC = tmp;
-
- /*!< Byte 3 */
- tmp = (uint8_t)(CSD_Tab[0] & 0x000000FF);
- cardinfo->SD_csd.MaxBusClkFrec = tmp;
-
- /*!< Byte 4 */
- tmp = (uint8_t)((CSD_Tab[1] & 0xFF000000) >> 24);
- cardinfo->SD_csd.CardComdClasses = tmp << 4;
-
- /*!< Byte 5 */
- tmp = (uint8_t)((CSD_Tab[1] & 0x00FF0000) >> 16);
- cardinfo->SD_csd.CardComdClasses |= (tmp & 0xF0) >> 4;
- cardinfo->SD_csd.RdBlockLen = tmp & 0x0F;
-
- /*!< Byte 6 */
- tmp = (uint8_t)((CSD_Tab[1] & 0x0000FF00) >> 8);
- cardinfo->SD_csd.PartBlockRead = (tmp & 0x80) >> 7;
- cardinfo->SD_csd.WrBlockMisalign = (tmp & 0x40) >> 6;
- cardinfo->SD_csd.RdBlockMisalign = (tmp & 0x20) >> 5;
- cardinfo->SD_csd.DSRImpl = (tmp & 0x10) >> 4;
- cardinfo->SD_csd.Reserved2 = 0; /*!< Reserved */
-
- if ((SDCardInfo.CardType == SDIO_STD_CAPACITY_SD_CARD_V1_1) || (SDCardInfo.CardType == SDIO_STD_CAPACITY_SD_CARD_V2_0))
- {
- cardinfo->SD_csd.DeviceSize = (tmp & 0x03) << 10;
-
- /*!< Byte 7 */
- tmp = (uint8_t)(CSD_Tab[1] & 0x000000FF);
- cardinfo->SD_csd.DeviceSize |= (tmp) << 2;
-
- /*!< Byte 8 */
- tmp = (uint8_t)((CSD_Tab[2] & 0xFF000000) >> 24);
- cardinfo->SD_csd.DeviceSize |= (tmp & 0xC0) >> 6;
-
- cardinfo->SD_csd.MaxRdCurrentVDDMin = (tmp & 0x38) >> 3;
- cardinfo->SD_csd.MaxRdCurrentVDDMax = (tmp & 0x07);
-
- /*!< Byte 9 */
- tmp = (uint8_t)((CSD_Tab[2] & 0x00FF0000) >> 16);
- cardinfo->SD_csd.MaxWrCurrentVDDMin = (tmp & 0xE0) >> 5;
- cardinfo->SD_csd.MaxWrCurrentVDDMax = (tmp & 0x1C) >> 2;
- cardinfo->SD_csd.DeviceSizeMul = (tmp & 0x03) << 1;
- /*!< Byte 10 */
- tmp = (uint8_t)((CSD_Tab[2] & 0x0000FF00) >> 8);
- cardinfo->SD_csd.DeviceSizeMul |= (tmp & 0x80) >> 7;
-
- cardinfo->CardCapacity = (cardinfo->SD_csd.DeviceSize + 1) ;
- cardinfo->CardCapacity *= (1 << (cardinfo->SD_csd.DeviceSizeMul + 2));
- cardinfo->CardBlockSize = 1 << (cardinfo->SD_csd.RdBlockLen);
- cardinfo->CardCapacity *= cardinfo->CardBlockSize;
- }
- else if (SDCardInfo.CardType == SDIO_HIGH_CAPACITY_SD_CARD)
- {
- /*!< Byte 7 */
- tmp = (uint8_t)(CSD_Tab[1] & 0x000000FF);
- cardinfo->SD_csd.DeviceSize = (tmp & 0x3F) << 16;
-
- /*!< Byte 8 */
- tmp = (uint8_t)((CSD_Tab[2] & 0xFF000000) >> 24);
-
- cardinfo->SD_csd.DeviceSize |= (tmp << 8);
-
- /*!< Byte 9 */
- tmp = (uint8_t)((CSD_Tab[2] & 0x00FF0000) >> 16);
-
- cardinfo->SD_csd.DeviceSize |= (tmp);
-
- /*!< Byte 10 */
- tmp = (uint8_t)((CSD_Tab[2] & 0x0000FF00) >> 8);
-
- cardinfo->CardCapacity = (cardinfo->SD_csd.DeviceSize + 1) * 512 * 1024;
- cardinfo->CardBlockSize = 512;
- }
-
-
- cardinfo->SD_csd.EraseGrSize = (tmp & 0x40) >> 6;
- cardinfo->SD_csd.EraseGrMul = (tmp & 0x3F) << 1;
-
- /*!< Byte 11 */
- tmp = (uint8_t)(CSD_Tab[2] & 0x000000FF);
- cardinfo->SD_csd.EraseGrMul |= (tmp & 0x80) >> 7;
- cardinfo->SD_csd.WrProtectGrSize = (tmp & 0x7F);
-
- /*!< Byte 12 */
- tmp = (uint8_t)((CSD_Tab[3] & 0xFF000000) >> 24);
- cardinfo->SD_csd.WrProtectGrEnable = (tmp & 0x80) >> 7;
- cardinfo->SD_csd.ManDeflECC = (tmp & 0x60) >> 5;
- cardinfo->SD_csd.WrSpeedFact = (tmp & 0x1C) >> 2;
- cardinfo->SD_csd.MaxWrBlockLen = (tmp & 0x03) << 2;
-
- /*!< Byte 13 */
- tmp = (uint8_t)((CSD_Tab[3] & 0x00FF0000) >> 16);
- cardinfo->SD_csd.MaxWrBlockLen |= (tmp & 0xC0) >> 6;
- cardinfo->SD_csd.WriteBlockPaPartial = (tmp & 0x20) >> 5;
- cardinfo->SD_csd.Reserved3 = 0;
- cardinfo->SD_csd.ContentProtectAppli = (tmp & 0x01);
-
- /*!< Byte 14 */
- tmp = (uint8_t)((CSD_Tab[3] & 0x0000FF00) >> 8);
- cardinfo->SD_csd.FileFormatGrouop = (tmp & 0x80) >> 7;
- cardinfo->SD_csd.CopyFlag = (tmp & 0x40) >> 6;
- cardinfo->SD_csd.PermWrProtect = (tmp & 0x20) >> 5;
- cardinfo->SD_csd.TempWrProtect = (tmp & 0x10) >> 4;
- cardinfo->SD_csd.FileFormat = (tmp & 0x0C) >> 2;
- cardinfo->SD_csd.ECC = (tmp & 0x03);
-
- /*!< Byte 15 */
- tmp = (uint8_t)(CSD_Tab[3] & 0x000000FF);
- cardinfo->SD_csd.CSD_CRC = (tmp & 0xFE) >> 1;
- cardinfo->SD_csd.Reserved4 = 1;
-
-
- /*!< Byte 0 */
- tmp = (uint8_t)((CID_Tab[0] & 0xFF000000) >> 24);
- cardinfo->SD_cid.ManufacturerID = tmp;
-
- /*!< Byte 1 */
- tmp = (uint8_t)((CID_Tab[0] & 0x00FF0000) >> 16);
- cardinfo->SD_cid.OEM_AppliID = tmp << 8;
-
- /*!< Byte 2 */
- tmp = (uint8_t)((CID_Tab[0] & 0x000000FF00) >> 8);
- cardinfo->SD_cid.OEM_AppliID |= tmp;
-
- /*!< Byte 3 */
- tmp = (uint8_t)(CID_Tab[0] & 0x000000FF);
- cardinfo->SD_cid.ProdName1 = tmp << 24;
-
- /*!< Byte 4 */
- tmp = (uint8_t)((CID_Tab[1] & 0xFF000000) >> 24);
- cardinfo->SD_cid.ProdName1 |= tmp << 16;
-
- /*!< Byte 5 */
- tmp = (uint8_t)((CID_Tab[1] & 0x00FF0000) >> 16);
- cardinfo->SD_cid.ProdName1 |= tmp << 8;
-
- /*!< Byte 6 */
- tmp = (uint8_t)((CID_Tab[1] & 0x0000FF00) >> 8);
- cardinfo->SD_cid.ProdName1 |= tmp;
-
- /*!< Byte 7 */
- tmp = (uint8_t)(CID_Tab[1] & 0x000000FF);
- cardinfo->SD_cid.ProdName2 = tmp;
-
- /*!< Byte 8 */
- tmp = (uint8_t)((CID_Tab[2] & 0xFF000000) >> 24);
- cardinfo->SD_cid.ProdRev = tmp;
-
- /*!< Byte 9 */
- tmp = (uint8_t)((CID_Tab[2] & 0x00FF0000) >> 16);
- cardinfo->SD_cid.ProdSN = tmp << 24;
-
- /*!< Byte 10 */
- tmp = (uint8_t)((CID_Tab[2] & 0x0000FF00) >> 8);
- cardinfo->SD_cid.ProdSN |= tmp << 16;
-
- /*!< Byte 11 */
- tmp = (uint8_t)(CID_Tab[2] & 0x000000FF);
- cardinfo->SD_cid.ProdSN |= tmp << 8;
-
- /*!< Byte 12 */
- tmp = (uint8_t)((CID_Tab[3] & 0xFF000000) >> 24);
- cardinfo->SD_cid.ProdSN |= tmp;
-
- /*!< Byte 13 */
- tmp = (uint8_t)((CID_Tab[3] & 0x00FF0000) >> 16);
- cardinfo->SD_cid.Reserved1 |= (tmp & 0xF0) >> 4;
- cardinfo->SD_cid.ManufactDate = (tmp & 0x0F) << 8;
-
- /*!< Byte 14 */
- tmp = (uint8_t)((CID_Tab[3] & 0x0000FF00) >> 8);
- cardinfo->SD_cid.ManufactDate |= tmp;
-
- /*!< Byte 15 */
- tmp = (uint8_t)(CID_Tab[3] & 0x000000FF);
- cardinfo->SD_cid.CID_CRC = (tmp & 0xFE) >> 1;
- cardinfo->SD_cid.Reserved2 = 1;
-
- return(errorstatus);
-}
-
-/**
- * @brief Enables wide bus opeartion for the requeseted card if supported by
- * card.
- * @param WideMode: Specifies the SD card wide bus mode.
- * This parameter can be one of the following values:
- * @arg SDIO_BusWide_8b: 8-bit data transfer (Only for MMC)
- * @arg SDIO_BusWide_4b: 4-bit data transfer
- * @arg SDIO_BusWide_1b: 1-bit data transfer
- * @retval SD_Error: SD Card Error code.
- */
-SD_Error SD_GetCardStatus(SD_CardStatus *cardstatus)
-{
- SD_Error errorstatus = SD_OK;
- uint8_t tmp = 0;
-
- errorstatus = SD_SendSDStatus((uint32_t *)SDSTATUS_Tab);
-
- if (errorstatus != SD_OK)
- {
- return(errorstatus);
- }
-
- /*!< Byte 0 */
- tmp = (uint8_t)((SDSTATUS_Tab[0] & 0xC0) >> 6);
- cardstatus->DAT_BUS_WIDTH = tmp;
-
- /*!< Byte 0 */
- tmp = (uint8_t)((SDSTATUS_Tab[0] & 0x20) >> 5);
- cardstatus->SECURED_MODE = tmp;
-
- /*!< Byte 2 */
- tmp = (uint8_t)((SDSTATUS_Tab[2] & 0xFF));
- cardstatus->SD_CARD_TYPE = tmp << 8;
-
- /*!< Byte 3 */
- tmp = (uint8_t)((SDSTATUS_Tab[3] & 0xFF));
- cardstatus->SD_CARD_TYPE |= tmp;
-
- /*!< Byte 4 */
- tmp = (uint8_t)(SDSTATUS_Tab[4] & 0xFF);
- cardstatus->SIZE_OF_PROTECTED_AREA = tmp << 24;
-
- /*!< Byte 5 */
- tmp = (uint8_t)(SDSTATUS_Tab[5] & 0xFF);
- cardstatus->SIZE_OF_PROTECTED_AREA |= tmp << 16;
-
- /*!< Byte 6 */
- tmp = (uint8_t)(SDSTATUS_Tab[6] & 0xFF);
- cardstatus->SIZE_OF_PROTECTED_AREA |= tmp << 8;
-
- /*!< Byte 7 */
- tmp = (uint8_t)(SDSTATUS_Tab[7] & 0xFF);
- cardstatus->SIZE_OF_PROTECTED_AREA |= tmp;
-
- /*!< Byte 8 */
- tmp = (uint8_t)((SDSTATUS_Tab[8] & 0xFF));
- cardstatus->SPEED_CLASS = tmp;
-
- /*!< Byte 9 */
- tmp = (uint8_t)((SDSTATUS_Tab[9] & 0xFF));
- cardstatus->PERFORMANCE_MOVE = tmp;
-
- /*!< Byte 10 */
- tmp = (uint8_t)((SDSTATUS_Tab[10] & 0xF0) >> 4);
- cardstatus->AU_SIZE = tmp;
-
- /*!< Byte 11 */
- tmp = (uint8_t)(SDSTATUS_Tab[11] & 0xFF);
- cardstatus->ERASE_SIZE = tmp << 8;
-
- /*!< Byte 12 */
- tmp = (uint8_t)(SDSTATUS_Tab[12] & 0xFF);
- cardstatus->ERASE_SIZE |= tmp;
-
- /*!< Byte 13 */
- tmp = (uint8_t)((SDSTATUS_Tab[13] & 0xFC) >> 2);
- cardstatus->ERASE_TIMEOUT = tmp;
-
- /*!< Byte 13 */
- tmp = (uint8_t)((SDSTATUS_Tab[13] & 0x3));
- cardstatus->ERASE_OFFSET = tmp;
-
- return(errorstatus);
-}
-
-
-/*
- * Function name:SD_EnableWideBusOperation
- * Description :configure the data width of card(depend on the card type)
- * Input:-WideMode data width
- * @arg SDIO_BusWide_8b: 8-bit data transfer (Only for MMC)
- * @arg SDIO_BusWide_4b: 4-bit data transfer
- * @arg SDIO_BusWide_1b: 1-bit data transfer (default)
- * Input :-SD_Error SD card error status
- * when successfully is SD_OK
- * Call:outside callback
- */
-SD_Error SD_EnableWideBusOperation(uint32_t WideMode)
-{
- SD_Error errorstatus = SD_OK;
- /*!< MMC Card doesn't support this feature */
- if (SDIO_MULTIMEDIA_CARD == SDCardInfo.CardType)
- {
- errorstatus = SD_UNSUPPORTED_FEATURE;
- return(errorstatus);
- }
- else if ((SDIO_STD_CAPACITY_SD_CARD_V1_1 == SDCardInfo.CardType) || (SDIO_STD_CAPACITY_SD_CARD_V2_0 == SDCardInfo.CardType)
- || (SDIO_HIGH_CAPACITY_SD_CARD == SDCardInfo.CardType))
- {
- if (SDIO_BusWide_8b == WideMode)
- {
- errorstatus = SD_UNSUPPORTED_FEATURE;
- return(errorstatus);
- }
- else if (SDIO_BusWide_4b == WideMode)
- {
- errorstatus = SDEnWideBus(ENABLE); //ACMD6 set bus wide
-
- if (SD_OK == errorstatus)
- {
- /*!< Configure the SDIO peripheral */
- SDIO_InitStructure.SDIO_ClockDiv = SDIO_TRANSFER_CLK_DIV;
- SDIO_InitStructure.SDIO_ClockEdge = SDIO_ClockEdge_Rising;
- SDIO_InitStructure.SDIO_ClockBypass = SDIO_ClockBypass_Disable;
- SDIO_InitStructure.SDIO_ClockPowerSave = SDIO_ClockPowerSave_Disable;
- SDIO_InitStructure.SDIO_BusWide = SDIO_BusWide_4b;
- SDIO_InitStructure.SDIO_HardwareFlowControl = SDIO_HardwareFlowControl_Disable;
- SDIO_Init(&SDIO_InitStructure);
- }
- }
- else
- {
- errorstatus = SDEnWideBus(DISABLE);
-
- if (SD_OK == errorstatus)
- {
- /*!< Configure the SDIO peripheral */
- SDIO_InitStructure.SDIO_ClockDiv = SDIO_TRANSFER_CLK_DIV;
- SDIO_InitStructure.SDIO_ClockEdge = SDIO_ClockEdge_Rising;
- SDIO_InitStructure.SDIO_ClockBypass = SDIO_ClockBypass_Disable;
- SDIO_InitStructure.SDIO_ClockPowerSave = SDIO_ClockPowerSave_Disable;
- SDIO_InitStructure.SDIO_BusWide = SDIO_BusWide_1b;
- SDIO_InitStructure.SDIO_HardwareFlowControl = SDIO_HardwareFlowControl_Disable;
- SDIO_Init(&SDIO_InitStructure);
- }
- }
- }
-
- return(errorstatus);
-}
-
-/*
- * Function name:SD_SelectDeselect
- * Description:cmd7,select the addr card, if addr = 0, cancel all the card
- * Input :-card address
- * Output :-SD_Error SD card error status
- * when successfully is SD_OK
- * Call :outside callback
- */
-SD_Error SD_SelectDeselect(uint32_t addr)
-{
- SD_Error errorstatus = SD_OK;
-
- /*!< Send CMD7 SDIO_SEL_DESEL_CARD */
- SDIO_CmdInitStructure.SDIO_Argument = addr;
- SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SEL_DESEL_CARD;
- SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
- SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
- SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
- SDIO_SendCommand(&SDIO_CmdInitStructure);
-
- errorstatus = CmdResp1Error(SD_CMD_SEL_DESEL_CARD);
-
- return(errorstatus);
-}
-
-/**
- * @brief Allows to read one block from a specified address in a card. The Data
- * transfer can be managed by DMA mode or Polling mode.
- * @note This operation should be followed by two functions to check if the
- * DMA Controller and SD Card status.
- * - SD_ReadWaitOperation(): this function insure that the DMA
- * controller has finished all data transfer.
- * - SD_GetStatus(): to check that the SD Card has finished the
- * data transfer and it is ready for data.
- * @param readbuff: pointer to the buffer that will contain the received data
- * @param ReadAddr: Address from where data are to be read.
- * @param BlockSize: the SD card Data block size. The Block size should be 512.
- * @retval SD_Error: SD Card Error code.
- */
-SD_Error SD_ReadBlock(uint8_t *readbuff, uint32_t ReadAddr, uint16_t BlockSize)
-{
- SD_Error errorstatus = SD_OK;
-#if defined (SD_POLLING_MODE)
- uint32_t count = 0, *tempbuff = (uint32_t *)readbuff;
-#endif
-
- TransferError = SD_OK;
- TransferEnd = 0; //transfer end flag , set 1 in irq
- StopCondition = 0;
-
- SDIO->DCTRL = 0x0;
-
-
- if (SDCardInfo.CardType == SDIO_HIGH_CAPACITY_SD_CARD)
- {
- BlockSize = 512;
- ReadAddr /= 512;
- }
-
-
- /* Set Block Size for Card */
- SDIO_CmdInitStructure.SDIO_Argument = (uint32_t) BlockSize;
- SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SET_BLOCKLEN;
- SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
- SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
- SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
- SDIO_SendCommand(&SDIO_CmdInitStructure);
-
- errorstatus = CmdResp1Error(SD_CMD_SET_BLOCKLEN);
-
- if (SD_OK != errorstatus)
- {
- return(errorstatus);
- }
-
- SDIO_DataInitStructure.SDIO_DataTimeOut = SD_DATATIMEOUT;
- SDIO_DataInitStructure.SDIO_DataLength = BlockSize;
- SDIO_DataInitStructure.SDIO_DataBlockSize = (uint32_t) 9 << 4;
- SDIO_DataInitStructure.SDIO_TransferDir = SDIO_TransferDir_ToSDIO;
- SDIO_DataInitStructure.SDIO_TransferMode = SDIO_TransferMode_Block;
- SDIO_DataInitStructure.SDIO_DPSM = SDIO_DPSM_Enable;
- SDIO_DataConfig(&SDIO_DataInitStructure);
-
- /*!< Send CMD17 READ_SINGLE_BLOCK */
- SDIO_CmdInitStructure.SDIO_Argument = (uint32_t)ReadAddr;
- SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_READ_SINGLE_BLOCK;
- SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
- SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
- SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
- SDIO_SendCommand(&SDIO_CmdInitStructure);
-
- errorstatus = CmdResp1Error(SD_CMD_READ_SINGLE_BLOCK);
-
- if (errorstatus != SD_OK)
- {
- return(errorstatus);
- }
-
-
-#if defined (SD_POLLING_MODE)
- /*!< In case of single block transfer, no need of stop transfer at all.*/
- /*!< Polling mode */
- while (!(SDIO->STA &(SDIO_FLAG_RXOVERR | SDIO_FLAG_DCRCFAIL | SDIO_FLAG_DTIMEOUT | SDIO_FLAG_DBCKEND | SDIO_FLAG_STBITERR)))
- {
- if (SDIO_GetFlagStatus(SDIO_FLAG_RXFIFOHF) != RESET)
- {
- for (count = 0; count < 8; count++)
- {
- *(tempbuff + count) = SDIO_ReadData();
- }
- tempbuff += 8;
- }
- }
-
- if (SDIO_GetFlagStatus(SDIO_FLAG_DTIMEOUT) != RESET)
- {
- SDIO_ClearFlag(SDIO_FLAG_DTIMEOUT);
- errorstatus = SD_DATA_TIMEOUT;
- return(errorstatus);
- }
- else if (SDIO_GetFlagStatus(SDIO_FLAG_DCRCFAIL) != RESET)
- {
- SDIO_ClearFlag(SDIO_FLAG_DCRCFAIL);
- errorstatus = SD_DATA_CRC_FAIL;
- return(errorstatus);
- }
- else if (SDIO_GetFlagStatus(SDIO_FLAG_RXOVERR) != RESET)
- {
- SDIO_ClearFlag(SDIO_FLAG_RXOVERR);
- errorstatus = SD_RX_OVERRUN;
- return(errorstatus);
- }
- else if (SDIO_GetFlagStatus(SDIO_FLAG_STBITERR) != RESET)
- {
- SDIO_ClearFlag(SDIO_FLAG_STBITERR);
- errorstatus = SD_START_BIT_ERR;
- return(errorstatus);
- }
- while (SDIO_GetFlagStatus(SDIO_FLAG_RXDAVL) != RESET)
- {
- *tempbuff = SDIO_ReadData();
- tempbuff++;
- }
-
- /*!< Clear all the static flags */
- SDIO_ClearFlag(SDIO_STATIC_FLAGS);
-
-#elif defined (SD_DMA_MODE)
- SDIO_ITConfig(SDIO_IT_RXOVERR|SDIO_IT_DTIMEOUT|SDIO_IT_DCRCFAIL|SDIO_IT_DATAEND|SDIO_IT_TXUNDERR|SDIO_IT_STBITERR, ENABLE);
- SDIO_DMACmd(ENABLE);
- SD_DMA_RxConfig((uint32_t *)readbuff, BlockSize);
-#endif
-
- return(errorstatus);
-}
-
-
-
-/**
- * @brief Allows to read blocks from a specified address in a card. The Data
- * transfer can be managed by DMA mode or Polling mode.
- * @note This operation should be followed by two functions to check if the
- * DMA Controller and SD Card status.
- * - SD_ReadWaitOperation(): this function insure that the DMA
- * controller has finished all data transfer.
- * - SD_GetStatus(): to check that the SD Card has finished the
- * data transfer and it is ready for data.
- * @param readbuff: pointer to the buffer that will contain the received data.
- * @param ReadAddr: Address from where data are to be read.
- * @param BlockSize: the SD card Data block size. The Block size should be 512.
- * @param NumberOfBlocks: number of blocks to be read.
- * @retval SD_Error: SD Card Error code.
- */
-SD_Error SD_ReadMultiBlocks(uint8_t *readbuff, uint32_t ReadAddr, uint16_t BlockSize, uint32_t NumberOfBlocks)
-{
- SD_Error errorstatus = SD_OK;
- TransferError = SD_OK;
- TransferEnd = 0;
- StopCondition = 1;
-
- SDIO->DCTRL = 0x0; //reset data control register
-
- if (SDCardInfo.CardType == SDIO_HIGH_CAPACITY_SD_CARD)
- {
- BlockSize = 512;
- ReadAddr /= 512;
- }
-
- /*!< Set Block Size for Card */
- SDIO_CmdInitStructure.SDIO_Argument = (uint32_t) BlockSize;
- SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SET_BLOCKLEN;
- SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
- SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
- SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
- SDIO_SendCommand(&SDIO_CmdInitStructure);
-
- errorstatus = CmdResp1Error(SD_CMD_SET_BLOCKLEN);
-
- if (SD_OK != errorstatus)
- {
- return(errorstatus);
- }
-
- SDIO_DataInitStructure.SDIO_DataTimeOut = SD_DATATIMEOUT;
- SDIO_DataInitStructure.SDIO_DataLength = NumberOfBlocks * BlockSize;
- SDIO_DataInitStructure.SDIO_DataBlockSize = (uint32_t) 9 << 4;
- SDIO_DataInitStructure.SDIO_TransferDir = SDIO_TransferDir_ToSDIO;
- SDIO_DataInitStructure.SDIO_TransferMode = SDIO_TransferMode_Block;
- SDIO_DataInitStructure.SDIO_DPSM = SDIO_DPSM_Enable;
- SDIO_DataConfig(&SDIO_DataInitStructure);
-
- /*!< Send CMD18 READ_MULT_BLOCK with argument data address */
- SDIO_CmdInitStructure.SDIO_Argument = (uint32_t)ReadAddr;
- SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_READ_MULT_BLOCK;
- SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
- SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
- SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
- SDIO_SendCommand(&SDIO_CmdInitStructure);
-
- errorstatus = CmdResp1Error(SD_CMD_READ_MULT_BLOCK);
-
- if (errorstatus != SD_OK)
- {
- return(errorstatus);
- }
-
- SDIO_ITConfig(SDIO_IT_RXOVERR|SDIO_IT_DTIMEOUT|SDIO_IT_DCRCFAIL|SDIO_IT_DATAEND|SDIO_IT_TXUNDERR|SDIO_IT_STBITERR, ENABLE);
- SDIO_DMACmd(ENABLE);
- SD_DMA_RxConfig((uint32_t *)readbuff, (NumberOfBlocks * BlockSize));
- return(errorstatus);
-}
-
-SD_Error SD_LBA_ReadBlocks(uint8_t *readbuff, uint32_t BlockAddr, uint32_t NumberOfBlocks)
-{
- SD_Error errorstatus = SD_OK;
- TransferError = SD_OK;
- TransferEnd = 0;
- StopCondition = 1;
-
- SDIO->DCTRL = 0x0; //reset data control register
-
- if (SDCardInfo.CardType != SDIO_HIGH_CAPACITY_SD_CARD)
- {
- //BlockSize = 512;
- BlockAddr = BlockAddr * 512;
- }
-
- /*!< Set Block Size for Card,cmd16, SDSC can set block size, SDHC block size is 512, not support cmd16*/
- /*SDIO_CmdInitStructure.SDIO_Argument = (uint32_t) BlockSize;
- SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SET_BLOCKLEN;
- SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short; //r1
- SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
- SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
- SDIO_SendCommand(&SDIO_CmdInitStructure);*/
- SDIO->ARG = 512;
- SDIO->CMD = (SDIO->CMD & 0xFFFFF800) | SD_CMD_SET_BLOCKLEN | SDIO_Response_Short | SDIO_CPSM_Enable;
-
- errorstatus = CmdResp1Error(SD_CMD_SET_BLOCKLEN);
-
- if (SD_OK != errorstatus)
- {
- return(errorstatus);
- }
-
- /*SDIO_DataInitStructure.SDIO_DataTimeOut = SD_DATATIMEOUT;
- SDIO_DataInitStructure.SDIO_DataLength = NumberOfBlocks * BlockSize;
- SDIO_DataInitStructure.SDIO_DataBlockSize = (uint32_t) 9 << 4;
- SDIO_DataInitStructure.SDIO_TransferDir = SDIO_TransferDir_ToSDIO;
- SDIO_DataInitStructure.SDIO_TransferMode = SDIO_TransferMode_Block;
- SDIO_DataInitStructure.SDIO_DPSM = SDIO_DPSM_Enable;
- SDIO_DataConfig(&SDIO_DataInitStructure);*/
- SDIO->DTIMER = SD_DATATIMEOUT;
- SDIO->DLEN = NumberOfBlocks * 512;
- SDIO->DCTRL = (SDIO->DCTRL & 0xFFFFFF08) | ((uint32_t) 9 << 4) | SDIO_TransferDir_ToSDIO | SDIO_DPSM_Enable;
-
- /*!< Send CMD18 READ_MULT_BLOCK with argument data address */
- /*SDIO_CmdInitStructure.SDIO_Argument = (uint32_t)ReadAddr;
- SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_READ_MULT_BLOCK;
- SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short; //r1
- SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
- SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
- SDIO_SendCommand(&SDIO_CmdInitStructure);*/
- SDIO->ARG = (uint32_t) BlockAddr;
- SDIO->CMD = (SDIO->CMD & 0xFFFFF800) | SD_CMD_READ_MULT_BLOCK | SDIO_Response_Short | SDIO_CPSM_Enable;
-
-
- errorstatus = CmdResp1Error(SD_CMD_READ_MULT_BLOCK);
-
- if (errorstatus != SD_OK)
- {
- return(errorstatus);
- }
-
- SDIO_ITConfig(SDIO_IT_RXOVERR|SDIO_IT_DTIMEOUT|SDIO_IT_DCRCFAIL|SDIO_IT_DATAEND|SDIO_IT_TXUNDERR|SDIO_IT_STBITERR, ENABLE);
- SDIO_DMACmd(ENABLE);
- SD_DMA_RxConfig((uint32_t *)readbuff, (NumberOfBlocks * 512));
- return(errorstatus);
-}
-
-
-
-/**
- * @brief This function waits until the SDIO DMA data transfer is finished.
- * This function should be called after SDIO_ReadMultiBlocks() function
- * to insure that all data sent by the card are already transferred by
- * the DMA controller.
- * @param None.
- * @retval SD_Error: SD Card Error code.
- */
-SD_Error SD_WaitReadOperation(void)
-{
- SD_Error errorstatus = SD_OK;
- uint32_t timeout;
- timeout = SD_DATATIMEOUT;
- while ((SD_DMAEndOfTransferStatus() == RESET) && (TransferEnd == 0) && (TransferError == SD_OK)&&(timeout > 0))
- {
- timeout--;
- }
-
- DMAEndOfTransfer = 0x00;
-
- timeout = SD_DATATIMEOUT;
-
- if (TransferError != SD_OK)
- {
- return(TransferError);
- }
-
- //wait for transfering data over or timeout
- while(((SDIO->STA & SDIO_FLAG_RXACT)) && (timeout > 0))
- {
- timeout--;
- }
-
- //if StopCondition, stop transfer data
- if (StopCondition == 1)
- {
- errorstatus = SD_StopTransfer();
- }
-
- //check if timeout
- if ((timeout == 0) && (errorstatus == SD_OK))
- {
- errorstatus = SD_DATA_TIMEOUT;
- }
-
- //clear static flag
- SDIO_ClearFlag(SDIO_STATIC_FLAGS);
-
- //check transfer is ok or not
- if (TransferError != SD_OK)
- {
- return(TransferError);
- }
- else
- {
- return(errorstatus);
- }
-}
-
-/**
- * @brief Allows to write one block starting from a specified address in a card.
- * The Data transfer can be managed by DMA mode or Polling mode.
- * @note This operation should be followed by two functions to check if the
- * DMA Controller and SD Card status.
- * - SD_ReadWaitOperation(): this function insure that the DMA
- * controller has finished all data transfer.
- * - SD_GetStatus(): to check that the SD Card has finished the
- * data transfer and it is ready for data.
- * @param writebuff: pointer to the buffer that contain the data to be transferred.
- * @param WriteAddr: Address from where data are to be read.
- * @param BlockSize: the SD card Data block size. The Block size should be 512.
- * @retval SD_Error: SD Card Error code.
- */
-SD_Error SD_WriteBlock(uint8_t *writebuff, uint32_t WriteAddr, uint16_t BlockSize)
-{
- SD_Error errorstatus = SD_OK;
-
-#if defined (SD_POLLING_MODE)
- uint32_t bytestransferred = 0, count = 0, restwords = 0;
- uint32_t *tempbuff = (uint32_t *)writebuff;
-#endif
-
- TransferError = SD_OK;
- TransferEnd = 0;
- StopCondition = 0;
-
- SDIO->DCTRL = 0x0;
-
-
- if (SDCardInfo.CardType == SDIO_HIGH_CAPACITY_SD_CARD)
- {
- BlockSize = 512;
- WriteAddr /= 512;
- }
-
- /*!< Set Block Size for Card,cmd16, SDSC can set block size, SDHC block size is 512, not support cmd16*/
- SDIO_CmdInitStructure.SDIO_Argument = (uint32_t) BlockSize;
- SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SET_BLOCKLEN;
- SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short; //r1
- SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
- SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
- SDIO_SendCommand(&SDIO_CmdInitStructure);
-
- errorstatus = CmdResp1Error(SD_CMD_SET_BLOCKLEN);
-
- if (SD_OK != errorstatus)
- {
- return(errorstatus);
- }
- /*********************************************************************************/
-
- /*!< Send CMD24 WRITE_SINGLE_BLOCK */
- SDIO_CmdInitStructure.SDIO_Argument = WriteAddr;
- SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_WRITE_SINGLE_BLOCK;
- SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short; //R1
- SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
- SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
- SDIO_SendCommand(&SDIO_CmdInitStructure);
-
- errorstatus = CmdResp1Error(SD_CMD_WRITE_SINGLE_BLOCK);
-
- if (errorstatus != SD_OK)
- {
- return(errorstatus);
- }
-
- SDIO_DataInitStructure.SDIO_DataTimeOut = SD_DATATIMEOUT;
- SDIO_DataInitStructure.SDIO_DataLength = BlockSize;
- SDIO_DataInitStructure.SDIO_DataBlockSize = (uint32_t) 9 << 4; //SDIO_DataBlockSize_512b
- SDIO_DataInitStructure.SDIO_TransferDir = SDIO_TransferDir_ToCard;
- SDIO_DataInitStructure.SDIO_TransferMode = SDIO_TransferMode_Block;
- SDIO_DataInitStructure.SDIO_DPSM = SDIO_DPSM_Enable; //enable DPSM mode
- SDIO_DataConfig(&SDIO_DataInitStructure);
-
- /*!< In case of single data block transfer no need of stop command at all */
-#if defined (SD_POLLING_MODE)
- while (!(SDIO->STA & (SDIO_FLAG_DBCKEND | SDIO_FLAG_TXUNDERR | SDIO_FLAG_DCRCFAIL | SDIO_FLAG_DTIMEOUT | SDIO_FLAG_STBITERR)))
- {
- if (SDIO_GetFlagStatus(SDIO_FLAG_TXFIFOHE) != RESET)
- {
- if ((512 - bytestransferred) < 32)
- {
- restwords = ((512 - bytestransferred) % 4 == 0) ? ((512 - bytestransferred) / 4) : (( 512 - bytestransferred) / 4 + 1);
- for (count = 0; count < restwords; count++, tempbuff++, bytestransferred += 4)
- {
- SDIO_WriteData(*tempbuff);
- }
- }
- else
- {
- for (count = 0; count < 8; count++)
- {
- SDIO_WriteData(*(tempbuff + count));
- }
- tempbuff += 8;
- bytestransferred += 32;
- }
- }
- }
- if (SDIO_GetFlagStatus(SDIO_FLAG_DTIMEOUT) != RESET)
- {
- SDIO_ClearFlag(SDIO_FLAG_DTIMEOUT);
- errorstatus = SD_DATA_TIMEOUT;
- return(errorstatus);
- }
- else if (SDIO_GetFlagStatus(SDIO_FLAG_DCRCFAIL) != RESET)
- {
- SDIO_ClearFlag(SDIO_FLAG_DCRCFAIL);
- errorstatus = SD_DATA_CRC_FAIL;
- return(errorstatus);
- }
- else if (SDIO_GetFlagStatus(SDIO_FLAG_TXUNDERR) != RESET)
- {
- SDIO_ClearFlag(SDIO_FLAG_TXUNDERR);
- errorstatus = SD_TX_UNDERRUN;
- return(errorstatus);
- }
- else if (SDIO_GetFlagStatus(SDIO_FLAG_STBITERR) != RESET)
- {
- SDIO_ClearFlag(SDIO_FLAG_STBITERR);
- errorstatus = SD_START_BIT_ERR;
- return(errorstatus);
- }
-#elif defined (SD_DMA_MODE)
- SDIO_ITConfig(SDIO_IT_RXOVERR|SDIO_IT_DTIMEOUT|SDIO_IT_DCRCFAIL|SDIO_IT_DATAEND|SDIO_IT_TXUNDERR|SDIO_IT_STBITERR, ENABLE);
- SD_DMA_TxConfig((uint32_t *)writebuff, BlockSize);
- SDIO_DMACmd(ENABLE);
-#endif
-
- return(errorstatus);
-}
-
-/**
- * @brief Allows to write blocks starting from a specified address in a card.
- * The Data transfer can be managed by DMA mode only.
- * @note This operation should be followed by two functions to check if the
- * DMA Controller and SD Card status.
- * - SD_ReadWaitOperation(): this function insure that the DMA
- * controller has finished all data transfer.
- * - SD_GetStatus(): to check that the SD Card has finished the
- * data transfer and it is ready for data.
- * @param WriteAddr: Address from where data are to be read.
- * @param writebuff: pointer to the buffer that contain the data to be transferred.
- * @param BlockSize: the SD card Data block size. The Block size should be 512.
- * @param NumberOfBlocks: number of blocks to be written.
- * @retval SD_Error: SD Card Error code.
- */
-
- /*
- * Function name:SD_WriteMultiBlocks
- * Description:start to write blocks from input address only supported in DMA mode
- Attention:after SD_WriteMultiBlocks, need to call
- SD_WaitWriteOperation() wait for DMA is stop
- SD_GetStatus() check the FIFO transfer between card and SDIO is over or not
- * Input:
- * @param WriteAddr: Address from where data are to be read.
- * @param writebuff: pointer to the buffer that contain the data to be transferred.
- * @param BlockSize: the SD card Data block size. The Block size should be 512.
- * @param NumberOfBlocks: number of blocks to be written.
- * Output :SD error status
- */
-SD_Error SD_WriteMultiBlocks(uint8_t *writebuff, uint32_t WriteAddr, uint16_t BlockSize, uint32_t NumberOfBlocks)
-{
- SD_Error errorstatus = SD_OK;
- __IO uint32_t count = 0;
-
- TransferError = SD_OK;
- TransferEnd = 0;
- StopCondition = 1;
-
- SDIO->DCTRL = 0x0;
-
- if (SDCardInfo.CardType == SDIO_HIGH_CAPACITY_SD_CARD)
- {
- BlockSize = 512;
- WriteAddr /= 512;
- }
-
- /*******************add, avoid died in checking DMA*************************************/
- /*!< Set Block Size for Card,cmd16, SDSC can set block size, SDHC block size is 512, not support cmd16*/
- SDIO_CmdInitStructure.SDIO_Argument = (uint32_t) BlockSize;
- SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SET_BLOCKLEN;
- SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short; //r1
- SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
- SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
- SDIO_SendCommand(&SDIO_CmdInitStructure);
-
- errorstatus = CmdResp1Error(SD_CMD_SET_BLOCKLEN);
-
- if (SD_OK != errorstatus)
- {
- return(errorstatus);
- }
- /*********************************************************************************/
-
- /*!< To improve performance */
- SDIO_CmdInitStructure.SDIO_Argument = (uint32_t) (RCA << 16);
- SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_APP_CMD; // cmd55
- SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
- SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
- SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
- SDIO_SendCommand(&SDIO_CmdInitStructure);
-
-
- errorstatus = CmdResp1Error(SD_CMD_APP_CMD);
-
- if (errorstatus != SD_OK)
- {
- return(errorstatus);
- }
- /*!< To improve performance */ // pre-erased
- SDIO_CmdInitStructure.SDIO_Argument = (uint32_t)NumberOfBlocks;
- SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SET_BLOCK_COUNT; //CMD23
- SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
- SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
- SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
- SDIO_SendCommand(&SDIO_CmdInitStructure);
-
- errorstatus = CmdResp1Error(SD_CMD_SET_BLOCK_COUNT);
-
- if (errorstatus != SD_OK)
- {
- return(errorstatus);
- }
-
-
- /*!< Send CMD25 WRITE_MULT_BLOCK with argument data address */
- SDIO_CmdInitStructure.SDIO_Argument = (uint32_t)WriteAddr;
- SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_WRITE_MULT_BLOCK;
- SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
- SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
- SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
- SDIO_SendCommand(&SDIO_CmdInitStructure);
-
- errorstatus = CmdResp1Error(SD_CMD_WRITE_MULT_BLOCK);
-
- if (SD_OK != errorstatus)
- {
- return(errorstatus);
- }
-
- SDIO_DataInitStructure.SDIO_DataTimeOut = SD_DATATIMEOUT;
- SDIO_DataInitStructure.SDIO_DataLength = NumberOfBlocks * BlockSize;
- SDIO_DataInitStructure.SDIO_DataBlockSize = (uint32_t) 9 << 4;
- SDIO_DataInitStructure.SDIO_TransferDir = SDIO_TransferDir_ToCard;
- SDIO_DataInitStructure.SDIO_TransferMode = SDIO_TransferMode_Block;
- SDIO_DataInitStructure.SDIO_DPSM = SDIO_DPSM_Enable;
- SDIO_DataConfig(&SDIO_DataInitStructure);
-
- SDIO_ITConfig(SDIO_IT_RXOVERR|SDIO_IT_DTIMEOUT|SDIO_IT_DCRCFAIL|SDIO_IT_DATAEND|SDIO_IT_TXUNDERR|SDIO_IT_STBITERR, ENABLE);
- SDIO_DMACmd(ENABLE);
- SD_DMA_TxConfig((uint32_t *)writebuff, (NumberOfBlocks * BlockSize));
-
- return(errorstatus);
-}
-
-SD_Error SD_LBA_WriteBlocks(uint8_t *writebuff, uint32_t BlockAddr, uint32_t NumberOfBlocks)
-{
- SD_Error errorstatus = SD_OK;
- __IO uint32_t count = 0;
-
- TransferError = SD_OK;
- TransferEnd = 0;
- StopCondition = 1;
-
- SDIO->DCTRL = 0x0;
-
- if (SDCardInfo.CardType != SDIO_HIGH_CAPACITY_SD_CARD)
- {
- //BlockSize = 512;
- BlockAddr = BlockAddr * 512;
- }
-
- /*******************add, avoid died in checking DMA*************************************/
- /*!< Set Block Size for Card,cmd16, SDSC can set block size, SDHC block size is 512, not support cmd16*/
- /*SDIO_CmdInitStructure.SDIO_Argument = (uint32_t) BlockSize;
- SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SET_BLOCKLEN;
- SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short; //r1
- SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
- SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
- SDIO_SendCommand(&SDIO_CmdInitStructure);*/
- SDIO->ARG = 512;
- SDIO->CMD = (SDIO->CMD & 0xFFFFF800) | SD_CMD_SET_BLOCKLEN | SDIO_Response_Short | SDIO_CPSM_Enable;
-
- errorstatus = CmdResp1Error(SD_CMD_SET_BLOCKLEN);
-
- if (SD_OK != errorstatus)
- {
- return(errorstatus);
- }
- /*********************************************************************************/
-
- /*!< To improve performance */
- /*SDIO_CmdInitStructure.SDIO_Argument = (uint32_t) (RCA << 16);
- SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_APP_CMD; // cmd55
- SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
- SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
- SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
- SDIO_SendCommand(&SDIO_CmdInitStructure);*/
- SDIO->ARG = (uint32_t) (RCA << 16);
- SDIO->CMD = (SDIO->CMD & 0xFFFFF800) | SD_CMD_APP_CMD | SDIO_Response_Short | SDIO_CPSM_Enable;
-
- errorstatus = CmdResp1Error(SD_CMD_APP_CMD);
-
- if (errorstatus != SD_OK)
- {
- return(errorstatus);
- }
- /*!< To improve performance */ // pre-erased,when writing multi blocks
- /*SDIO_CmdInitStructure.SDIO_Argument = (uint32_t)NumberOfBlocks;
- SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SET_BLOCK_COUNT; //CMD23
- SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
- SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
- SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
- SDIO_SendCommand(&SDIO_CmdInitStructure);*/
- SDIO->ARG = NumberOfBlocks;
- SDIO->CMD = (SDIO->CMD & 0xFFFFF800) | SD_CMD_SET_BLOCK_COUNT | SDIO_Response_Short | SDIO_CPSM_Enable;
-
- errorstatus = CmdResp1Error(SD_CMD_SET_BLOCK_COUNT);
-
- if (errorstatus != SD_OK)
- {
- return(errorstatus);
- }
-
-
- /*!< Send CMD25 WRITE_MULT_BLOCK with argument data address */
- /*SDIO_CmdInitStructure.SDIO_Argument = (uint32_t)WriteAddr;
- SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_WRITE_MULT_BLOCK;
- SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
- SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
- SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
- SDIO_SendCommand(&SDIO_CmdInitStructure);*/
- SDIO->ARG = BlockAddr;
- SDIO->CMD = (SDIO->CMD & 0xFFFFF800) | SD_CMD_WRITE_MULT_BLOCK | SDIO_Response_Short | SDIO_CPSM_Enable;
-
- errorstatus = CmdResp1Error(SD_CMD_WRITE_MULT_BLOCK);
-
- if (SD_OK != errorstatus)
- {
- return(errorstatus);
- }
-
- /*SDIO_DataInitStructure.SDIO_DataTimeOut = SD_DATATIMEOUT;
- SDIO_DataInitStructure.SDIO_DataLength = NumberOfBlocks * BlockSize;
- SDIO_DataInitStructure.SDIO_DataBlockSize = (uint32_t) 9 << 4;
- SDIO_DataInitStructure.SDIO_TransferDir = SDIO_TransferDir_ToCard;
- SDIO_DataInitStructure.SDIO_TransferMode = SDIO_TransferMode_Block; //0x00000000
- SDIO_DataInitStructure.SDIO_DPSM = SDIO_DPSM_Enable;
- SDIO_DataConfig(&SDIO_DataInitStructure);*/
- SDIO->DTIMER = SD_DATATIMEOUT;
- SDIO->DLEN = NumberOfBlocks * 512;
- SDIO->DCTRL = (SDIO->DCTRL & 0xFFFFFF08) | ((uint32_t) 9 << 4) | SDIO_TransferDir_ToCard | SDIO_DPSM_Enable;
-
-
- SDIO_ITConfig(SDIO_IT_RXOVERR|SDIO_IT_DTIMEOUT|SDIO_IT_DCRCFAIL|SDIO_IT_DATAEND|SDIO_IT_TXUNDERR|SDIO_IT_STBITERR, ENABLE);
- SDIO_DMACmd(ENABLE);
- SD_DMA_TxConfig((uint32_t *)writebuff, (NumberOfBlocks * 512));
-
- return(errorstatus);
-}
-
-/**
- * @brief This function waits until the SDIO DMA data transfer is finished.
- * This function should be called after SDIO_WriteBlock() and
- * SDIO_WriteMultiBlocks() function to insure that all data sent by the
- * card are already transferred by the DMA controller.
- * @param None.
- * @retval SD_Error: SD Card Error code.
- */
-SD_Error SD_WaitWriteOperation(void)
-{
- SD_Error errorstatus = SD_OK;
- uint32_t timeout;
- timeout = SD_DATATIMEOUT;
-
- //wait for DMA Transfer stop
- while ((SD_DMAEndOfTransferStatus() == RESET) && (TransferEnd == 0) && (TransferError == SD_OK)&& (timeout > 0))
- {
- timeout--;
- }
-
- DMAEndOfTransfer = 0x00;
-
- timeout = SD_DATATIMEOUT;
-
- while(((SDIO->STA & SDIO_FLAG_TXACT)) && (timeout > 0))
- {
- timeout--;
- }
-
- if (StopCondition == 1)
- {
- errorstatus = SD_StopTransfer();
- }
-
- if ((timeout == 0) && (errorstatus == SD_OK))
- {
- errorstatus = SD_DATA_TIMEOUT;
- }
-
- /*!< Clear all the static flags */
- SDIO_ClearFlag(SDIO_STATIC_FLAGS);
-
- if (TransferError != SD_OK)
- {
- return(TransferError);
- }
- else
- {
- return(errorstatus);
- }
-}
-
-/**
- * @brief Gets the cuurent data transfer state.
- * @param None
- * @retval SDTransferState: Data Transfer state.
- * This value can be:
- * - SD_TRANSFER_OK: No data transfer is acting
- * - SD_TRANSFER_BUSY: Data transfer is acting
- */
-SDTransferState SD_GetTransferState(void)
-{
- if (SDIO->STA & (SDIO_FLAG_TXACT | SDIO_FLAG_RXACT))
- {
- return(SD_TRANSFER_BUSY);
- }
- else
- {
- return(SD_TRANSFER_OK);
- }
-}
-
-/**
- * @brief Aborts an ongoing data transfer.
- * @param None
- * @retval SD_Error: SD Card Error code.
- */
-SD_Error SD_StopTransfer(void)
-{
- SD_Error errorstatus = SD_OK;
-
- /*!< Send CMD12 STOP_TRANSMISSION */
- SDIO->ARG = 0x0;
- SDIO->CMD = 0x44C;
- errorstatus = CmdResp1Error(SD_CMD_STOP_TRANSMISSION);
-
- return(errorstatus);
-}
-
-/**
- * @brief Allows to erase memory area specified for the given card.
- * @param startaddr: the start address.
- * @param endaddr: the end address.
- * @retval SD_Error: SD Card Error code.
- */
-SD_Error SD_Erase(uint32_t startaddr, uint32_t endaddr)
-{
- SD_Error errorstatus = SD_OK;
- uint32_t delay = 0;
- __IO uint32_t maxdelay = 0;
- uint8_t cardstate = 0;
-
- /*!< Check if the card coomnd class supports erase command */
- if (((CSD_Tab[1] >> 20) & SD_CCCC_ERASE) == 0)
- {
- errorstatus = SD_REQUEST_NOT_APPLICABLE;
- return(errorstatus);
- }
-
- maxdelay = 120000 / ((SDIO->CLKCR & 0xFF) + 2); //delay
-
- if (SDIO_GetResponse(SDIO_RESP1) & SD_CARD_LOCKED) //card is locked
- {
- errorstatus = SD_LOCK_UNLOCK_FAILED;
- return(errorstatus);
- }
-
- if (SDCardInfo.CardType == SDIO_HIGH_CAPACITY_SD_CARD)
- { //SDHC address param is block address, SDSC is byte address
- startaddr /= 512;
- endaddr /= 512;
- }
-
- /*!< According to sd-card spec 1.0 ERASE_GROUP_START (CMD32) and erase_group_end(CMD33) */
- if ((SDIO_STD_CAPACITY_SD_CARD_V1_1 == SDCardInfo.CardType) || (SDIO_STD_CAPACITY_SD_CARD_V2_0 == SDCardInfo.CardType)
- || (SDIO_HIGH_CAPACITY_SD_CARD == SDCardInfo.CardType))
- {
- /*!< Send CMD32 SD_ERASE_GRP_START with argument as addr */
- SDIO_CmdInitStructure.SDIO_Argument = startaddr;
- SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SD_ERASE_GRP_START;
- SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short; //R1
- SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
- SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
- SDIO_SendCommand(&SDIO_CmdInitStructure);
-
- errorstatus = CmdResp1Error(SD_CMD_SD_ERASE_GRP_START);
- if (errorstatus != SD_OK)
- {
- return(errorstatus);
- }
-
- /*!< Send CMD33 SD_ERASE_GRP_END with argument as addr */
- SDIO_CmdInitStructure.SDIO_Argument = endaddr;
- SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SD_ERASE_GRP_END;
- SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
- SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
- SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
- SDIO_SendCommand(&SDIO_CmdInitStructure);
-
- errorstatus = CmdResp1Error(SD_CMD_SD_ERASE_GRP_END);
- if (errorstatus != SD_OK)
- {
- return(errorstatus);
- }
- }
-
- /*!< Send CMD38 ERASE */
- SDIO_CmdInitStructure.SDIO_Argument = 0;
- SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_ERASE;
- SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
- SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
- SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
- SDIO_SendCommand(&SDIO_CmdInitStructure);
-
- errorstatus = CmdResp1Error(SD_CMD_ERASE);
-
- if (errorstatus != SD_OK)
- {
- return(errorstatus);
- }
-
- for (delay = 0; delay < maxdelay; delay++)
- {}
-
- /*!< Wait till the card is in programming state */
- errorstatus = IsCardProgramming(&cardstate);
- delay = SD_DATATIMEOUT;
- while ((errorstatus == SD_OK) && ((SD_CARD_PROGRAMMING == cardstate) || (SD_CARD_RECEIVING == cardstate)))
- {
- errorstatus = IsCardProgramming(&cardstate);
- delay--;
- }
-
- return(errorstatus);
-}
-
-/**
- * @brief Returns the current card's status.
- * @param pcardstatus: pointer to the buffer that will contain the SD card
- * status (Card Status register).
- * @retval SD_Error: SD Card Error code.
- */
-SD_Error SD_SendStatus(uint32_t *pcardstatus)
-{
- SD_Error errorstatus = SD_OK;
-
- SDIO->ARG = (uint32_t) RCA << 16;
- SDIO->CMD = 0x44D;
-
- errorstatus = CmdResp1Error(SD_CMD_SEND_STATUS);
-
- if (errorstatus != SD_OK)
- {
- return(errorstatus);
- }
-
- *pcardstatus = SDIO->RESP1;
- return(errorstatus);
-}
-
-/**
- * @brief Returns the current SD card's status.
- * @param psdstatus: pointer to the buffer that will contain the SD card status
- * (SD Status register).
- * @retval SD_Error: SD Card Error code.
- */
-SD_Error SD_SendSDStatus(uint32_t *psdstatus)
-{
- SD_Error errorstatus = SD_OK;
- uint32_t count = 0;
-
- if (SDIO_GetResponse(SDIO_RESP1) & SD_CARD_LOCKED)
- {
- errorstatus = SD_LOCK_UNLOCK_FAILED;
- return(errorstatus);
- }
-
- /*!< Set block size for card if it is not equal to current block size for card. */
- SDIO_CmdInitStructure.SDIO_Argument = 64;
- SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SET_BLOCKLEN;
- SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
- SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
- SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
- SDIO_SendCommand(&SDIO_CmdInitStructure);
-
- errorstatus = CmdResp1Error(SD_CMD_SET_BLOCKLEN);
-
- if (errorstatus != SD_OK)
- {
- return(errorstatus);
- }
-
- /*!< CMD55 */
- SDIO_CmdInitStructure.SDIO_Argument = (uint32_t) RCA << 16;
- SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_APP_CMD;
- SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
- SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
- SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
- SDIO_SendCommand(&SDIO_CmdInitStructure);
- errorstatus = CmdResp1Error(SD_CMD_APP_CMD);
-
- if (errorstatus != SD_OK)
- {
- return(errorstatus);
- }
-
- SDIO_DataInitStructure.SDIO_DataTimeOut = SD_DATATIMEOUT;
- SDIO_DataInitStructure.SDIO_DataLength = 64;
- SDIO_DataInitStructure.SDIO_DataBlockSize = SDIO_DataBlockSize_64b;
- SDIO_DataInitStructure.SDIO_TransferDir = SDIO_TransferDir_ToSDIO;
- SDIO_DataInitStructure.SDIO_TransferMode = SDIO_TransferMode_Block;
- SDIO_DataInitStructure.SDIO_DPSM = SDIO_DPSM_Enable;
- SDIO_DataConfig(&SDIO_DataInitStructure);
-
- /*!< Send ACMD13 SD_APP_STAUS with argument as card's RCA.*/
- SDIO_CmdInitStructure.SDIO_Argument = 0;
- SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SD_APP_STAUS;
- SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
- SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
- SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
- SDIO_SendCommand(&SDIO_CmdInitStructure);
- errorstatus = CmdResp1Error(SD_CMD_SD_APP_STAUS);
-
- if (errorstatus != SD_OK)
- {
- return(errorstatus);
- }
-
- while (!(SDIO->STA &(SDIO_FLAG_RXOVERR | SDIO_FLAG_DCRCFAIL | SDIO_FLAG_DTIMEOUT | SDIO_FLAG_DBCKEND | SDIO_FLAG_STBITERR)))
- {
- if (SDIO_GetFlagStatus(SDIO_FLAG_RXFIFOHF) != RESET)
- {
- for (count = 0; count < 8; count++)
- {
- *(psdstatus + count) = SDIO_ReadData();
- }
- psdstatus += 8;
- }
- }
-
- if (SDIO_GetFlagStatus(SDIO_FLAG_DTIMEOUT) != RESET)
- {
- SDIO_ClearFlag(SDIO_FLAG_DTIMEOUT);
- errorstatus = SD_DATA_TIMEOUT;
- return(errorstatus);
- }
- else if (SDIO_GetFlagStatus(SDIO_FLAG_DCRCFAIL) != RESET)
- {
- SDIO_ClearFlag(SDIO_FLAG_DCRCFAIL);
- errorstatus = SD_DATA_CRC_FAIL;
- return(errorstatus);
- }
- else if (SDIO_GetFlagStatus(SDIO_FLAG_RXOVERR) != RESET)
- {
- SDIO_ClearFlag(SDIO_FLAG_RXOVERR);
- errorstatus = SD_RX_OVERRUN;
- return(errorstatus);
- }
- else if (SDIO_GetFlagStatus(SDIO_FLAG_STBITERR) != RESET)
- {
- SDIO_ClearFlag(SDIO_FLAG_STBITERR);
- errorstatus = SD_START_BIT_ERR;
- return(errorstatus);
- }
-
- while (SDIO_GetFlagStatus(SDIO_FLAG_RXDAVL) != RESET)
- {
- *psdstatus = SDIO_ReadData();
- psdstatus++;
- }
-
- /*!< Clear all the static status flags*/
- SDIO_ClearFlag(SDIO_STATIC_FLAGS);
-
- return(errorstatus);
-}
-
-
-static SD_Error CmdError(void)
-{
-
- SD_Error errorstatus = SD_OK;
- uint32_t timeout;
-
- timeout = SDIO_CMD0TIMEOUT; /*!< 10000 */
-
- /*check the cmd is send normal or not*/
- while ((timeout > 0) && (SDIO_GetFlagStatus(SDIO_FLAG_CMDSENT) == RESET))
- {
- timeout--;
- }
-
- if (timeout == 0)
- {
- KPrintf("\nsdio:2098:timeout\n");
- errorstatus = SD_CMD_RSP_TIMEOUT;
- return(errorstatus);
- }
-
- /*!< Clear all the static flags */
- SDIO_ClearFlag(SDIO_STATIC_FLAGS);//clear static flag
-
- return(errorstatus);
-}
-
-
- /*
- * Function name:CmdResp7Error
- * Description:check response R7 cmd
- * Input :
- * Output :SD error status
- */
-static SD_Error CmdResp7Error(void)
-{
- SD_Error errorstatus = SD_OK;
- uint32_t status;
- uint32_t timeout = SDIO_CMD0TIMEOUT;
-
- status = SDIO->STA; //read SDIO status register of stm32
-
- /* Command response received (CRC check failed) :Command response received (CRC check passed):Command response timeout */
-
- while (!(status & (SDIO_FLAG_CCRCFAIL | SDIO_FLAG_CMDREND | SDIO_FLAG_CTIMEOUT)) && (timeout > 0))
- {
- timeout--;
- status = SDIO->STA;
- }
- //not support cmd8
- if ((timeout == 0) || (status & SDIO_FLAG_CTIMEOUT))
- {
- /*!< Card is not V2.0 complient or card does not support the set voltage range */
- errorstatus = SD_CMD_RSP_TIMEOUT;
- SDIO_ClearFlag(SDIO_FLAG_CTIMEOUT);
- return(errorstatus);
- }
-
- if (status & SDIO_FLAG_CMDREND)
- {
- /*!< Card is SD V2.0 compliant */
- errorstatus = SD_OK;
- SDIO_ClearFlag(SDIO_FLAG_CMDREND);
- return(errorstatus);
- }
- return(errorstatus);
-}
-
-
- /*
- * Function name:CmdResp1Error
- * Description:check response R1 cmd
- * Input :
- * Output :SD error status
- */
-static SD_Error CmdResp1Error(uint8_t cmd)
-{
- /*wait for these status*/
- while (!(SDIO->STA & (SDIO_FLAG_CCRCFAIL | SDIO_FLAG_CMDREND | SDIO_FLAG_CTIMEOUT)))
- {;}
-
- SDIO->ICR = SDIO_STATIC_FLAGS; //release interrupt sign
-
- return (SD_Error)(SDIO->RESP1 & SD_OCR_ERRORBITS);
-}
-
- /*
- * Function name:CmdResp3Error
- * Description:check response R3 cmd
- * Input :
- * Output :SD error status
- */
-static SD_Error CmdResp3Error(void)
-{
- SD_Error errorstatus = SD_OK;
- uint32_t status;
-
- status = SDIO->STA;
-
- while (!(status & (SDIO_FLAG_CCRCFAIL | SDIO_FLAG_CMDREND | SDIO_FLAG_CTIMEOUT)))
- {
- status = SDIO->STA;
- }
-
- if (status & SDIO_FLAG_CTIMEOUT)
- {
- errorstatus = SD_CMD_RSP_TIMEOUT;
- SDIO_ClearFlag(SDIO_FLAG_CTIMEOUT);
- return(errorstatus);
- }
- /*!< Clear all the static flags */
- SDIO_ClearFlag(SDIO_STATIC_FLAGS);
- return(errorstatus);
-}
-
- /*
- * Function name:CmdResp2Error
- * Description:check response R6 cmd
- * Input :
- * Output :SD error status
- */
-static SD_Error CmdResp2Error(void)
-{
- SD_Error errorstatus = SD_OK;
- uint32_t status;
-
- status = SDIO->STA;
-
- while (!(status & (SDIO_FLAG_CCRCFAIL | SDIO_FLAG_CTIMEOUT | SDIO_FLAG_CMDREND)))
- {
- status = SDIO->STA;
- }
-
- if (status & SDIO_FLAG_CTIMEOUT)
- {
- errorstatus = SD_CMD_RSP_TIMEOUT;
- SDIO_ClearFlag(SDIO_FLAG_CTIMEOUT);
- return(errorstatus);
- }
- else if (status & SDIO_FLAG_CCRCFAIL)
- {
- errorstatus = SD_CMD_CRC_FAIL;
- SDIO_ClearFlag(SDIO_FLAG_CCRCFAIL);
- return(errorstatus);
- }
-
- /*!< Clear all the static flags */
- SDIO_ClearFlag(SDIO_STATIC_FLAGS);
-
- return(errorstatus);
-}
-
- /*
- * Function name:CmdResp6Error
- * Description:check response R6 cmd
- * Input :cmd ,
- prca address
- * Output :SD error status
- */
-static SD_Error CmdResp6Error(uint8_t cmd, uint16_t *prca)
-{
- SD_Error errorstatus = SD_OK;
- uint32_t status;
- uint32_t ResponseR1;
-
- status = SDIO->STA;
-
- while (!(status & (SDIO_FLAG_CCRCFAIL | SDIO_FLAG_CTIMEOUT | SDIO_FLAG_CMDREND)))
- {
- status = SDIO->STA;
- }
-
- if (status & SDIO_FLAG_CTIMEOUT)
- {
- errorstatus = SD_CMD_RSP_TIMEOUT;
- SDIO_ClearFlag(SDIO_FLAG_CTIMEOUT);
- return(errorstatus);
- }
- else if (status & SDIO_FLAG_CCRCFAIL)
- {
- errorstatus = SD_CMD_CRC_FAIL;
- SDIO_ClearFlag(SDIO_FLAG_CCRCFAIL);
- return(errorstatus);
- }
-
- /*!< Check response received is of desired command */
- if (SDIO_GetCommandResponse() != cmd) //check get cmd successfully
- {
- errorstatus = SD_ILLEGAL_CMD;
- return(errorstatus);
- }
-
- /*!< Clear all the static flags */
- SDIO_ClearFlag(SDIO_STATIC_FLAGS);
-
- /*!< We have received response, retrieve it. */
- ResponseR1 = SDIO_GetResponse(SDIO_RESP1);
-
- /*SD_ALLZERO means get rca successfully*/
- if (SD_ALLZERO == (ResponseR1 & (SD_R6_GENERAL_UNKNOWN_ERROR | SD_R6_ILLEGAL_CMD | SD_R6_COM_CRC_FAILED)))
- {
- *prca = (uint16_t) (ResponseR1 >> 16);//>>16 bit, rca
- return(errorstatus);
- }
-
- if (ResponseR1 & SD_R6_GENERAL_UNKNOWN_ERROR)
- {
- return(SD_GENERAL_UNKNOWN_ERROR);
- }
-
- if (ResponseR1 & SD_R6_ILLEGAL_CMD)
- {
- return(SD_ILLEGAL_CMD);
- }
-
- if (ResponseR1 & SD_R6_COM_CRC_FAILED)
- {
- return(SD_COM_CRC_FAILED);
- }
-
- return(errorstatus);
-}
-
- /*
- * Function name:SDEnWideBus
- * Description :enable or disable SDIO 4bit mode
- * Input : ENABLE or DISABLE
- * Output :SD error status
- */
-static SD_Error SDEnWideBus(FunctionalState NewState)
-{
- SD_Error errorstatus = SD_OK;
-
- uint32_t scr[2] = {0, 0};
-
- if (SDIO_GetResponse(SDIO_RESP1) & SD_CARD_LOCKED) //check card is locked or not
- {
- errorstatus = SD_LOCK_UNLOCK_FAILED;
- return(errorstatus);
- }
-
- /*!< Get SCR Register */
- errorstatus = FindSCR(RCA, scr);//get scr register and store to scr[]
-
- if (errorstatus != SD_OK) //degug,crc error,scr can not read data
- {
- return(errorstatus);
- }
-
- /*!< If wide bus operation to be enabled */
- if (NewState == ENABLE)
- {
- /*!< If requested card supports wide bus operation */
- if ((scr[1] & SD_WIDE_BUS_SUPPORT) != SD_ALLZERO) //check card if support 4 bit
- {
- /*!< Send CMD55 APP_CMD with argument as card's RCA.*/
- SDIO_CmdInitStructure.SDIO_Argument = (uint32_t) RCA << 16;
- SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_APP_CMD;
- SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
- SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
- SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
- SDIO_SendCommand(&SDIO_CmdInitStructure);
-
- errorstatus = CmdResp1Error(SD_CMD_APP_CMD);
-
- if (errorstatus != SD_OK)
- {
- return(errorstatus);
- }
-
- /*!< Send ACMD6 APP_CMD with argument as 2 for wide bus mode */
- /*4bit acmd6*/
- SDIO_CmdInitStructure.SDIO_Argument = 0x2;
- SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_APP_SD_SET_BUSWIDTH;
- SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
- SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
- SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
- SDIO_SendCommand(&SDIO_CmdInitStructure);
-
- errorstatus = CmdResp1Error(SD_CMD_APP_SD_SET_BUSWIDTH);
-
- if (errorstatus != SD_OK)
- {
- return(errorstatus);
- }
- return(errorstatus);
- }
- else
- {
- errorstatus = SD_REQUEST_NOT_APPLICABLE;
- return(errorstatus);
- }
- } /*!< If wide bus operation to be disabled */
- else
- {
- /*!< If requested card supports 1 bit mode operation */
- if ((scr[1] & SD_SINGLE_BUS_SUPPORT) != SD_ALLZERO)
- {
- /*!< Send CMD55 APP_CMD with argument as card's RCA.*/
- SDIO_CmdInitStructure.SDIO_Argument = (uint32_t) RCA << 16;
- SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_APP_CMD;
- SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
- SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
- SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
- SDIO_SendCommand(&SDIO_CmdInitStructure);
-
-
- errorstatus = CmdResp1Error(SD_CMD_APP_CMD);
-
- if (errorstatus != SD_OK)
- {
- return(errorstatus);
- }
-
- /*!< Send ACMD6 APP_CMD with argument as 0 for single bus mode */
- SDIO_CmdInitStructure.SDIO_Argument = 0x00;
- SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_APP_SD_SET_BUSWIDTH;
- SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
- SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
- SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
- SDIO_SendCommand(&SDIO_CmdInitStructure);
-
- errorstatus = CmdResp1Error(SD_CMD_APP_SD_SET_BUSWIDTH);
-
- if (errorstatus != SD_OK)
- {
- return(errorstatus);
- }
-
- return(errorstatus);
- }
- else
- {
- errorstatus = SD_REQUEST_NOT_APPLICABLE;
- return(errorstatus);
- }
- }
-}
-
-
- /*
- * Function name:IsCardProgramming
- * Description:check SD card if is writing or reading inside the chip
- * Input:SD state pointer
- * Output:SD error status
- */
-static SD_Error IsCardProgramming(uint8_t *pstatus)
-{
- SD_Error errorstatus = SD_OK;
- __IO uint32_t respR1 = 0, status = 0;
-
- /*cmd13 send card status register, store to sdio_sta register of m3*/
- SDIO_CmdInitStructure.SDIO_Argument = (uint32_t) RCA << 16; //card address param
- SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SEND_STATUS;
- SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
- SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
- SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
- SDIO_SendCommand(&SDIO_CmdInitStructure);
-
- status = SDIO->STA;
- while (!(status & (SDIO_FLAG_CCRCFAIL | SDIO_FLAG_CMDREND | SDIO_FLAG_CTIMEOUT)))
- {
- status = SDIO->STA;
- }
- /*check status*/
- if (status & SDIO_FLAG_CTIMEOUT)
- {
- errorstatus = SD_CMD_RSP_TIMEOUT;
- SDIO_ClearFlag(SDIO_FLAG_CTIMEOUT);
- return(errorstatus);
- }
- else if (status & SDIO_FLAG_CCRCFAIL)
- {
- errorstatus = SD_CMD_CRC_FAIL;
- SDIO_ClearFlag(SDIO_FLAG_CCRCFAIL);
- return(errorstatus);
- }
-
- status = (uint32_t)SDIO_GetCommandResponse();
-
- /*!< Check response received is of desired command */
- if (status != SD_CMD_SEND_STATUS)
- {
- errorstatus = SD_ILLEGAL_CMD;
- return(errorstatus);
- }
-
- /*!< Clear all the static flags */
- SDIO_ClearFlag(SDIO_STATIC_FLAGS);
-
-
- /*!< We have received response, retrieve it for analysis */
- respR1 = SDIO_GetResponse(SDIO_RESP1);
-
- /*!< Find out card status */
- *pstatus = (uint8_t) ((respR1 >> 9) & 0x0000000F); //status[12:9] :cardstate
-
- if ((respR1 & SD_OCR_ERRORBITS) == SD_ALLZERO)
- {
- return(errorstatus);
- }
-
- if (respR1 & SD_OCR_ADDR_OUT_OF_RANGE)
- {
- return(SD_ADDR_OUT_OF_RANGE);
- }
-
- if (respR1 & SD_OCR_ADDR_MISALIGNED)
- {
- return(SD_ADDR_MISALIGNED);
- }
-
- if (respR1 & SD_OCR_BLOCK_LEN_ERR)
- {
- return(SD_BLOCK_LEN_ERR);
- }
-
- if (respR1 & SD_OCR_ERASE_SEQ_ERR)
- {
- return(SD_ERASE_SEQ_ERR);
- }
-
- if (respR1 & SD_OCR_BAD_ERASE_PARAM)
- {
- return(SD_BAD_ERASE_PARAM);
- }
-
- if (respR1 & SD_OCR_WRITE_PROT_VIOLATION)
- {
- return(SD_WRITE_PROT_VIOLATION);
- }
-
- if (respR1 & SD_OCR_LOCK_UNLOCK_FAILED)
- {
- return(SD_LOCK_UNLOCK_FAILED);
- }
-
- if (respR1 & SD_OCR_COM_CRC_FAILED)
- {
- return(SD_COM_CRC_FAILED);
- }
-
- if (respR1 & SD_OCR_ILLEGAL_CMD)
- {
- return(SD_ILLEGAL_CMD);
- }
-
- if (respR1 & SD_OCR_CARD_ECC_FAILED)
- {
- return(SD_CARD_ECC_FAILED);
- }
-
- if (respR1 & SD_OCR_CC_ERROR)
- {
- return(SD_CC_ERROR);
- }
-
- if (respR1 & SD_OCR_GENERAL_UNKNOWN_ERROR)
- {
- return(SD_GENERAL_UNKNOWN_ERROR);
- }
-
- if (respR1 & SD_OCR_STREAM_READ_UNDERRUN)
- {
- return(SD_STREAM_READ_UNDERRUN);
- }
-
- if (respR1 & SD_OCR_STREAM_WRITE_OVERRUN)
- {
- return(SD_STREAM_WRITE_OVERRUN);
- }
-
- if (respR1 & SD_OCR_CID_CSD_OVERWRIETE)
- {
- return(SD_CID_CSD_OVERWRITE);
- }
-
- if (respR1 & SD_OCR_WP_ERASE_SKIP)
- {
- return(SD_WP_ERASE_SKIP);
- }
-
- if (respR1 & SD_OCR_CARD_ECC_DISABLED)
- {
- return(SD_CARD_ECC_DISABLED);
- }
-
- if (respR1 & SD_OCR_ERASE_RESET)
- {
- return(SD_ERASE_RESET);
- }
-
- if (respR1 & SD_OCR_AKE_SEQ_ERROR)
- {
- return(SD_AKE_SEQ_ERROR);
- }
-
- return(errorstatus);
-}
-
-
-static SD_Error FindSCR(uint16_t rca, uint32_t *pscr)
-{
-
- uint32_t index = 0;
- SD_Error errorstatus = SD_OK;
- uint32_t tempscr[2] = {0, 0};
-
- /*!< Set Block Size To 8 Bytes */
- SDIO_CmdInitStructure.SDIO_Argument = (uint32_t)8; //SDHC card not support configure
- SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SET_BLOCKLEN; // cmd16
- SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short; //r1
- SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
- SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
- SDIO_SendCommand(&SDIO_CmdInitStructure);
-
- errorstatus = CmdResp1Error(SD_CMD_SET_BLOCKLEN);
-
- if (errorstatus != SD_OK)
- {
- return(errorstatus);
- }
-
- /*!< Send CMD55 APP_CMD with argument as card's RCA */
- SDIO_CmdInitStructure.SDIO_Argument = (uint32_t) RCA << 16;
- SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_APP_CMD;
- SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
- SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
- SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
- SDIO_SendCommand(&SDIO_CmdInitStructure);
-
- errorstatus = CmdResp1Error(SD_CMD_APP_CMD);
-
- if (errorstatus != SD_OK)
- {
- return(errorstatus);
- }
- /*set recv data register*/
- SDIO_DataInitStructure.SDIO_DataTimeOut = SD_DATATIMEOUT;
- SDIO_DataInitStructure.SDIO_DataLength = 8; //8byte,64 bit
- SDIO_DataInitStructure.SDIO_DataBlockSize = SDIO_DataBlockSize_8b ; //block size 8 byte
- SDIO_DataInitStructure.SDIO_TransferDir = SDIO_TransferDir_ToSDIO;
- SDIO_DataInitStructure.SDIO_TransferMode = SDIO_TransferMode_Block;
- SDIO_DataInitStructure.SDIO_DPSM = SDIO_DPSM_Enable;
- SDIO_DataConfig(&SDIO_DataInitStructure);
-
- /*!< Send ACMD51 SD_APP_SEND_SCR with argument as 0 */
- SDIO_CmdInitStructure.SDIO_Argument = 0x0;
- SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SD_APP_SEND_SCR;
- SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short; //r1
- SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
- SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
- SDIO_SendCommand(&SDIO_CmdInitStructure);
-
- errorstatus = CmdResp1Error(SD_CMD_SD_APP_SEND_SCR);
-
- if (errorstatus != SD_OK)
- {
- return(errorstatus);
- }
-
- while (!(SDIO->STA & (SDIO_FLAG_RXOVERR | SDIO_FLAG_DCRCFAIL | SDIO_FLAG_DTIMEOUT | SDIO_FLAG_DBCKEND| SDIO_FLAG_STBITERR)))
- {
- if (SDIO_GetFlagStatus(SDIO_FLAG_RXDAVL) != RESET) //check the data
- {
- *(tempscr + index) = SDIO_ReadData();
- index++;
-
- //add check
- if(index > 1 )
- break;
- }
- }
-
- if (SDIO_GetFlagStatus(SDIO_FLAG_DTIMEOUT) != RESET)
- {
- SDIO_ClearFlag(SDIO_FLAG_DTIMEOUT);
- errorstatus = SD_DATA_TIMEOUT;
- return(errorstatus);
- }
- else if (SDIO_GetFlagStatus(SDIO_FLAG_DCRCFAIL) != RESET)
- {
- SDIO_ClearFlag(SDIO_FLAG_DCRCFAIL);
- errorstatus = SD_DATA_CRC_FAIL;
- return(errorstatus);
- }
- else if (SDIO_GetFlagStatus(SDIO_FLAG_RXOVERR) != RESET)
- {
- SDIO_ClearFlag(SDIO_FLAG_RXOVERR);
- errorstatus = SD_RX_OVERRUN;
- return(errorstatus);
- }
- else if (SDIO_GetFlagStatus(SDIO_FLAG_STBITERR) != RESET)
- {
- SDIO_ClearFlag(SDIO_FLAG_STBITERR);
- errorstatus = SD_START_BIT_ERR;
- return(errorstatus);
- }
-
- /*!< Clear all the static flags */
- SDIO_ClearFlag(SDIO_STATIC_FLAGS);
-
- *(pscr + 1) = ((tempscr[0] & SD_0TO7BITS) << 24) | ((tempscr[0] & SD_8TO15BITS) << 8) | ((tempscr[0] & SD_16TO23BITS) >> 8) | ((tempscr[0] & SD_24TO31BITS) >> 24);
-
- *(pscr) = ((tempscr[1] & SD_0TO7BITS) << 24) | ((tempscr[1] & SD_8TO15BITS) << 8) | ((tempscr[1] & SD_16TO23BITS) >> 8) | ((tempscr[1] & SD_24TO31BITS) >> 24);
-
- return(errorstatus);
-}
-
-
-/**
- * @brief Converts the number of bytes in power of two and returns the power.
- * @param NumberOfBytes: number of bytes.
- * @retval None
- */
-uint8_t convert_from_bytes_to_power_of_two(uint16_t NumberOfBytes)
-{
- uint8_t count = 0;
-
- while (NumberOfBytes != 1)
- {
- NumberOfBytes >>= 1;
- count++;
- }
- return(count);
-}
-
-
-
-
-
-void SD_ProcessDMAIRQ()
-{
- #ifdef SD_SDIO_DMA_STREAM3
- {
- if (DMA2->LISR&SD_SDIO_DMA_FLAG_TCIF)
- {
- DMAEndOfTransfer=0x01;
- DMA_ClearFlag(SD_SDIO_DMA_STREAM, SD_SDIO_DMA_FLAG_TCIF | SD_SDIO_DMA_FLAG_FEIF);
- }
- }
- #elif defined SD_SDIO_DMA_STREAM6
- {
- if (DMA2->HISR&SD_SDIO_DMA_FLAG_TCIF)
- {
- DMAEndOfTransfer=0x01;
- DMA_ClearFlag(SD_SDIO_DMA_STREAM, SD_SDIO_DMA_FLAG_TCIF | SD_SDIO_DMA_FLAG_FEIF);
- }
- }
- #endif
-}
-
-
-SD_Error SD_ProcessIRQSrc(void)
-{
- if (SDIO_GetFlagStatus(SDIO_FLAG_DTIMEOUT) != RESET)
- {
- SDIO_ClearFlag(SDIO_FLAG_DTIMEOUT);
- TransferError = SD_DATA_TIMEOUT;
- }
- else if (SDIO_GetFlagStatus(SDIO_FLAG_DCRCFAIL) != RESET)
- {
- SDIO_ClearFlag(SDIO_FLAG_DCRCFAIL);
- TransferError = SD_DATA_CRC_FAIL;
- }
- else if (SDIO_GetFlagStatus(SDIO_FLAG_RXOVERR) != RESET)
- {
- SDIO_ClearFlag(SDIO_FLAG_RXOVERR);
- TransferError = SD_RX_OVERRUN;
- }
- else if (SDIO_GetFlagStatus(SDIO_FLAG_STBITERR) != RESET)
- {
- SDIO_ClearFlag(SDIO_FLAG_STBITERR);
- TransferError = SD_START_BIT_ERR;
- }
- else if (SDIO_GetFlagStatus(SDIO_FLAG_TXUNDERR) != RESET)
- {
- SDIO_ClearFlag(SDIO_FLAG_TXUNDERR);
- }
- else if (SDIO_GetFlagStatus(SDIO_FLAG_DATAEND) != RESET)
- {
- TransferError = SD_OK;
- TransferEnd = 1;
- SDIO_ClearFlag(SDIO_FLAG_DATAEND);
- }
- SDIO_ClearITPendingBit(SDIO_IT_RXOVERR|SDIO_IT_DTIMEOUT|SDIO_IT_DCRCFAIL|SDIO_IT_DATAEND|SDIO_IT_TXUNDERR|SDIO_IT_STBITERR); //清中断
- SDIO_ITConfig(SDIO_IT_RXOVERR|SDIO_IT_DTIMEOUT|SDIO_IT_DCRCFAIL|SDIO_IT_DATAEND|SDIO_IT_TXUNDERR|SDIO_IT_STBITERR, DISABLE);
- return(TransferError);
-}
-
-
-/*****************************END OF FILE*****************************/
-
-/*******************************************************************************
-* Function Name : SD_GetCapacity
-* Description : get sd card capacity
-* Input : None
-* Output : None
-* Return : u32 capacity
-* 0: error
-*******************************************************************************/
-uint32_t SD_GetCapacity(void)
-{
- return SDCardInfo.CardCapacity;
-}
-
-
-void SDIO_IRQHandler(int irq_num, void *arg)
-{
- SD_ProcessIRQSrc();
-}
-DECLARE_HW_IRQ(SDIO_IRQn, SDIO_IRQHandler, NONE);
-
-void DMA2_Stream3_IRQHandler(int irq_num, void *arg)
-{
- SD_ProcessDMAIRQ();
-}
-DECLARE_HW_IRQ(DMA2_Stream3_IRQn, DMA2_Stream3_IRQHandler, NONE);
-
-void DMA2_Stream6_IRQHandler(int irq_num, void *arg)
-{
- SD_ProcessDMAIRQ();
-}
-DECLARE_HW_IRQ(DMA2_Stream6_IRQn, DMA2_Stream6_IRQHandler, NONE);
-
-
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/sdio/sdio_sd.h b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/sdio/sdio_sd.h
deleted file mode 100644
index 67c3c7db6..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/sdio/sdio_sd.h
+++ /dev/null
@@ -1,399 +0,0 @@
-/*
- * Copyright (c) Guangzhou Xingyi Electronic Technology Co., Ltd
- *
- * Change Logs:
- * Date Author Notes
- * 2014-7-4 alientek first version
- */
-
-/**
-* @file sdio_sd.h
-* @brief define std sdio function and struct
-* @version 1.0
-* @author AIIT XUOS Lab
-* @date 2021-04-22
-*/
-
-/*************************************************
-File name: sdio_sd.h
-Description: define std sdio function and struct
-Others: hardware/sdio/sdio.h for references
-History:
-1. Date: 2021-04-22
-Author: AIIT XUOS Lab
-Modification: Support stm32f407-discovery-board sdio using source files
-*************************************************/
-
-/* Define to prevent recursive inclusion -------------------------------------*/
-#ifndef __SDIO_SDCARD_H
-#define __SDIO_SDCARD_H
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-/* Includes ------------------------------------------------------------------*/
-#include "stm32f4xx.h"
-/* Exported types ------------------------------------------------------------*/
-/**
- * @brief SDIO Intialization Frequency (400KHz max)
- */
-#define SDIO_INIT_CLK_DIV ((uint8_t)0xB4)
-/**
- * @brief SDIO Data Transfer Frequency (25MHz max)
- */
-/*!< SDIOCLK = HCLK, SDIO_CK = HCLK/(2 + SDIO_TRANSFER_CLK_DIV) */
-
-// #define SDIO_TRANSFER_CLK_DIV ((uint8_t)0x01)
-#define SDIO_TRANSFER_CLK_DIV ((uint8_t)0x4)
-
-
-/* Uncomment the following line to select the SDIO Data transfer mode */
-#define SD_DMA_MODE ((uint32_t)0x00000000)
-//#define SD_POLLING_MODE ((uint32_t)0x00000002)
-
-
-typedef enum
-{
-/**
- * @brief SDIO specific error defines
- */
- SD_CMD_CRC_FAIL = (1), /*!< Command response received (but CRC check failed) */
- SD_DATA_CRC_FAIL = (2), /*!< Data bock sent/received (CRC check Failed) */
- SD_CMD_RSP_TIMEOUT = (3), /*!< Command response timeout */
- SD_DATA_TIMEOUT = (4), /*!< Data time out */
- SD_TX_UNDERRUN = (5), /*!< Transmit FIFO under-run */
- SD_RX_OVERRUN = (6), /*!< Receive FIFO over-run */
- SD_START_BIT_ERR = (7), /*!< Start bit not detected on all data signals in widE bus mode */
- SD_CMD_OUT_OF_RANGE = (8), /*!< CMD's argument was out of range.*/
- SD_ADDR_MISALIGNED = (9), /*!< Misaligned address */
- SD_BLOCK_LEN_ERR = (10), /*!< Transferred block length is not allowed for the card or the number of transferred bytes does not match the block length */
- SD_ERASE_SEQ_ERR = (11), /*!< An error in the sequence of erase command occurs.*/
- SD_BAD_ERASE_PARAM = (12), /*!< An Invalid selection for erase groups */
- SD_WRITE_PROT_VIOLATION = (13), /*!< Attempt to program a write protect block */
- SD_LOCK_UNLOCK_FAILED = (14), /*!< Sequence or password error has been detected in unlock command or if there was an attempt to access a locked card */
- SD_COM_CRC_FAILED = (15), /*!< CRC check of the previous command failed */
- SD_ILLEGAL_CMD = (16), /*!< Command is not legal for the card state */
- SD_CARD_ECC_FAILED = (17), /*!< Card internal ECC was applied but failed to correct the data */
- SD_CC_ERROR = (18), /*!< Internal card controller error */
- SD_GENERAL_UNKNOWN_ERROR = (19), /*!< General or Unknown error */
- SD_STREAM_READ_UNDERRUN = (20), /*!< The card could not sustain data transfer in stream read operation. */
- SD_STREAM_WRITE_OVERRUN = (21), /*!< The card could not sustain data programming in stream mode */
- SD_CID_CSD_OVERWRITE = (22), /*!< CID/CSD overwrite error */
- SD_WP_ERASE_SKIP = (23), /*!< only partial address space was erased */
- SD_CARD_ECC_DISABLED = (24), /*!< Command has been executed without using internal ECC */
- SD_ERASE_RESET = (25), /*!< Erase sequence was cleared before executing because an out of erase sequence command was received */
- SD_AKE_SEQ_ERROR = (26), /*!< Error in sequence of authentication. */
- SD_INVALID_VOLTRANGE = (27),
- SD_ADDR_OUT_OF_RANGE = (28),
- SD_SWITCH_ERROR = (29),
- SD_SDIO_DISABLED = (30),
- SD_SDIO_FUNCTION_BUSY = (31),
- SD_SDIO_FUNCTION_FAILED = (32),
- SD_SDIO_UNKNOWN_FUNCTION = (33),
-
-/**
- * @brief Standard error defines
- */
- SD_INTERNAL_ERROR,
- SD_NOT_CONFIGURED,
- SD_REQUEST_PENDING,
- SD_REQUEST_NOT_APPLICABLE,
- SD_INVALID_PARAMETER,
- SD_UNSUPPORTED_FEATURE,
- SD_UNSUPPORTED_HW,
- SD_ERROR,
- SD_OK = 0
-} SD_Error;
-
-/**
- * @brief SDIO Transfer state
- */
-typedef enum
-{
- SD_TRANSFER_OK = 0,
- SD_TRANSFER_BUSY = 1,
- SD_TRANSFER_ERROR
-} SDTransferState;
-
-/**
- * @brief SD Card States
- */
-typedef enum
-{
- SD_CARD_READY = ((uint32_t)0x00000001),
- SD_CARD_IDENTIFICATION = ((uint32_t)0x00000002),
- SD_CARD_STANDBY = ((uint32_t)0x00000003),
- SD_CARD_TRANSFER = ((uint32_t)0x00000004),
- SD_CARD_SENDING = ((uint32_t)0x00000005),
- SD_CARD_RECEIVING = ((uint32_t)0x00000006),
- SD_CARD_PROGRAMMING = ((uint32_t)0x00000007),
- SD_CARD_DISCONNECTED = ((uint32_t)0x00000008),
- SD_CARD_ERROR = ((uint32_t)0x000000FF)
-}SDCardState;
-
-
-/**
- * @brief Card Specific Data: CSD Register
- */
-typedef struct
-{
- __IO uint8_t CSDStruct; /*!< CSD structure */
- __IO uint8_t SysSpecVersion; /*!< System specification version */
- __IO uint8_t Reserved1; /*!< Reserved */
- __IO uint8_t TAAC; /*!< Data read access-time 1 */
- __IO uint8_t NSAC; /*!< Data read access-time 2 in CLK cycles */
- __IO uint8_t MaxBusClkFrec; /*!< Max. bus clock frequency */
- __IO uint16_t CardComdClasses; /*!< Card command classes */
- __IO uint8_t RdBlockLen; /*!< Max. read data block length */
- __IO uint8_t PartBlockRead; /*!< Partial blocks for read allowed */
- __IO uint8_t WrBlockMisalign; /*!< Write block misalignment */
- __IO uint8_t RdBlockMisalign; /*!< Read block misalignment */
- __IO uint8_t DSRImpl; /*!< DSR implemented */
- __IO uint8_t Reserved2; /*!< Reserved */
- __IO uint32_t DeviceSize; /*!< Device Size */
- __IO uint8_t MaxRdCurrentVDDMin; /*!< Max. read current @ VDD min */
- __IO uint8_t MaxRdCurrentVDDMax; /*!< Max. read current @ VDD max */
- __IO uint8_t MaxWrCurrentVDDMin; /*!< Max. write current @ VDD min */
- __IO uint8_t MaxWrCurrentVDDMax; /*!< Max. write current @ VDD max */
- __IO uint8_t DeviceSizeMul; /*!< Device size multiplier */
- __IO uint8_t EraseGrSize; /*!< Erase group size */
- __IO uint8_t EraseGrMul; /*!< Erase group size multiplier */
- __IO uint8_t WrProtectGrSize; /*!< Write protect group size */
- __IO uint8_t WrProtectGrEnable; /*!< Write protect group enable */
- __IO uint8_t ManDeflECC; /*!< Manufacturer default ECC */
- __IO uint8_t WrSpeedFact; /*!< Write speed factor */
- __IO uint8_t MaxWrBlockLen; /*!< Max. write data block length */
- __IO uint8_t WriteBlockPaPartial; /*!< Partial blocks for write allowed */
- __IO uint8_t Reserved3; /*!< Reserded */
- __IO uint8_t ContentProtectAppli; /*!< Content protection application */
- __IO uint8_t FileFormatGrouop; /*!< File format group */
- __IO uint8_t CopyFlag; /*!< Copy flag (OTP) */
- __IO uint8_t PermWrProtect; /*!< Permanent write protection */
- __IO uint8_t TempWrProtect; /*!< Temporary write protection */
- __IO uint8_t FileFormat; /*!< File Format */
- __IO uint8_t ECC; /*!< ECC code */
- __IO uint8_t CSD_CRC; /*!< CSD CRC */
- __IO uint8_t Reserved4; /*!< always 1*/
-} SD_CSD;
-
-/**
- * @brief Card Identification Data: CID Register
- */
-typedef struct
-{
- __IO uint8_t ManufacturerID; /*!< ManufacturerID */
- __IO uint16_t OEM_AppliID; /*!< OEM/Application ID */
- __IO uint32_t ProdName1; /*!< Product Name part1 */
- __IO uint8_t ProdName2; /*!< Product Name part2*/
- __IO uint8_t ProdRev; /*!< Product Revision */
- __IO uint32_t ProdSN; /*!< Product Serial Number */
- __IO uint8_t Reserved1; /*!< Reserved1 */
- __IO uint16_t ManufactDate; /*!< Manufacturing Date */
- __IO uint8_t CID_CRC; /*!< CID CRC */
- __IO uint8_t Reserved2; /*!< always 1 */
-} SD_CID;
-
-/**
- * @brief SD Card Status
- */
-typedef struct
-{
- __IO uint8_t DAT_BUS_WIDTH;
- __IO uint8_t SECURED_MODE;
- __IO uint16_t SD_CARD_TYPE;
- __IO uint32_t SIZE_OF_PROTECTED_AREA;
- __IO uint8_t SPEED_CLASS;
- __IO uint8_t PERFORMANCE_MOVE;
- __IO uint8_t AU_SIZE;
- __IO uint16_t ERASE_SIZE;
- __IO uint8_t ERASE_TIMEOUT;
- __IO uint8_t ERASE_OFFSET;
-} SD_CardStatus;
-
-
-/**
- * @brief SD Card information
- */
-typedef struct
-{
- SD_CSD SD_csd;
- SD_CID SD_cid;
- uint32_t CardCapacity; /*!< Card Capacity */
- uint32_t CardBlockSize; /*!< Card Block Size */
- uint16_t RCA;
- uint8_t CardType;
-} SD_CardInfo;
-
-#define SDIO_FIFO_ADDRESS SDIO_BASE+0x80 //SDIO_FIOF address =SDIO address+0x80 to SDIO address+0xfc
-
-#define SD_SDIO_DMA DMA2
-#define SD_SDIO_DMA_CLK RCC_AHB1Periph_DMA2
-
-//#define SD_SDIO_DMA_STREAM3 3
-#define SD_SDIO_DMA_STREAM6 6
-
-#ifdef SD_SDIO_DMA_STREAM3
- #define SD_SDIO_DMA_STREAM DMA2_Stream3
- #define SD_SDIO_DMA_CHANNEL DMA_Channel_4
- #define SD_SDIO_DMA_FLAG_FEIF DMA_FLAG_FEIF3
- #define SD_SDIO_DMA_FLAG_DMEIF DMA_FLAG_DMEIF3
- #define SD_SDIO_DMA_FLAG_TEIF DMA_FLAG_TEIF3
- #define SD_SDIO_DMA_FLAG_HTIF DMA_FLAG_HTIF3
- #define SD_SDIO_DMA_FLAG_TCIF DMA_FLAG_TCIF3
- #define SD_SDIO_DMA_IRQn DMA2_Stream3_IRQn
- #define SD_SDIO_DMA_IRQHANDLER DMA2_Stream3_IRQHandler
-#elif defined SD_SDIO_DMA_STREAM6
- #define SD_SDIO_DMA_STREAM DMA2_Stream6
- #define SD_SDIO_DMA_CHANNEL DMA_Channel_4
- #define SD_SDIO_DMA_FLAG_FEIF DMA_FLAG_FEIF6
- #define SD_SDIO_DMA_FLAG_DMEIF DMA_FLAG_DMEIF6
- #define SD_SDIO_DMA_FLAG_TEIF DMA_FLAG_TEIF6
- #define SD_SDIO_DMA_FLAG_HTIF DMA_FLAG_HTIF6
- #define SD_SDIO_DMA_FLAG_TCIF DMA_FLAG_TCIF6
- #define SD_SDIO_DMA_IRQn DMA2_Stream6_IRQn
- #define SD_SDIO_DMA_IRQHANDLER DMA2_Stream6_IRQHandler
-#endif /* SD_SDIO_DMA_STREAM3 */
-/**
- * @brief SDIO Commands Index
- */
-#define SD_CMD_GO_IDLE_STATE ((uint8_t)0)
-#define SD_CMD_SEND_OP_COND ((uint8_t)1)
-#define SD_CMD_ALL_SEND_CID ((uint8_t)2)
-#define SD_CMD_SET_REL_ADDR ((uint8_t)3) /*!< SDIO_SEND_REL_ADDR for SD Card */
-#define SD_CMD_SET_DSR ((uint8_t)4)
-#define SD_CMD_SDIO_SEN_OP_COND ((uint8_t)5)
-#define SD_CMD_HS_SWITCH ((uint8_t)6)
-#define SD_CMD_SEL_DESEL_CARD ((uint8_t)7)
-#define SD_CMD_HS_SEND_EXT_CSD ((uint8_t)8)
-#define SD_CMD_SEND_CSD ((uint8_t)9)
-#define SD_CMD_SEND_CID ((uint8_t)10)
-#define SD_CMD_READ_DAT_UNTIL_STOP ((uint8_t)11) /*!< SD Card doesn't support it */
-#define SD_CMD_STOP_TRANSMISSION ((uint8_t)12)
-#define SD_CMD_SEND_STATUS ((uint8_t)13)
-#define SD_CMD_HS_BUSTEST_READ ((uint8_t)14)
-#define SD_CMD_GO_INACTIVE_STATE ((uint8_t)15)
-#define SD_CMD_SET_BLOCKLEN ((uint8_t)16)
-#define SD_CMD_READ_SINGLE_BLOCK ((uint8_t)17)
-#define SD_CMD_READ_MULT_BLOCK ((uint8_t)18)
-#define SD_CMD_HS_BUSTEST_WRITE ((uint8_t)19)
-#define SD_CMD_WRITE_DAT_UNTIL_STOP ((uint8_t)20) /*!< SD Card doesn't support it */
-#define SD_CMD_SET_BLOCK_COUNT ((uint8_t)23) /*!< SD Card doesn't support it */
-#define SD_CMD_WRITE_SINGLE_BLOCK ((uint8_t)24)
-#define SD_CMD_WRITE_MULT_BLOCK ((uint8_t)25)
-#define SD_CMD_PROG_CID ((uint8_t)26) /*!< reserved for manufacturers */
-#define SD_CMD_PROG_CSD ((uint8_t)27)
-#define SD_CMD_SET_WRITE_PROT ((uint8_t)28)
-#define SD_CMD_CLR_WRITE_PROT ((uint8_t)29)
-#define SD_CMD_SEND_WRITE_PROT ((uint8_t)30)
-#define SD_CMD_SD_ERASE_GRP_START ((uint8_t)32) /*!< To set the address of the first write
- block to be erased. (For SD card only) */
-#define SD_CMD_SD_ERASE_GRP_END ((uint8_t)33) /*!< To set the address of the last write block of the
- continuous range to be erased. (For SD card only) */
-#define SD_CMD_ERASE_GRP_START ((uint8_t)35) /*!< To set the address of the first write block to be erased.
- (For MMC card only spec 3.31) */
-
-#define SD_CMD_ERASE_GRP_END ((uint8_t)36) /*!< To set the address of the last write block of the
- continuous range to be erased. (For MMC card only spec 3.31) */
-
-#define SD_CMD_ERASE ((uint8_t)38)
-#define SD_CMD_FAST_IO ((uint8_t)39) /*!< SD Card doesn't support it */
-#define SD_CMD_GO_IRQ_STATE ((uint8_t)40) /*!< SD Card doesn't support it */
-#define SD_CMD_LOCK_UNLOCK ((uint8_t)42)
-#define SD_CMD_APP_CMD ((uint8_t)55)
-#define SD_CMD_GEN_CMD ((uint8_t)56)
-#define SD_CMD_NO_CMD ((uint8_t)64)
-
-/**
- * @brief Following commands are SD Card Specific commands.
- * SDIO_APP_CMD :CMD55 should be sent before sending these commands.
- */
-#define SD_CMD_APP_SD_SET_BUSWIDTH ((uint8_t)6) /*!< For SD Card only */
-#define SD_CMD_SD_APP_STAUS ((uint8_t)13) /*!< For SD Card only */
-#define SD_CMD_SD_APP_SEND_NUM_WRITE_BLOCKS ((uint8_t)22) /*!< For SD Card only */
-#define SD_CMD_SD_APP_OP_COND ((uint8_t)41) /*!< For SD Card only */
-#define SD_CMD_SD_APP_SET_CLR_CARD_DETECT ((uint8_t)42) /*!< For SD Card only */
-#define SD_CMD_SD_APP_SEND_SCR ((uint8_t)51) /*!< For SD Card only */
-#define SD_CMD_SDIO_RW_DIRECT ((uint8_t)52) /*!< For SD I/O Card only */
-#define SD_CMD_SDIO_RW_EXTENDED ((uint8_t)53) /*!< For SD I/O Card only */
-
-/**
- * @brief Following commands are SD Card Specific security commands.
- * SDIO_APP_CMD should be sent before sending these commands.
- */
-#define SD_CMD_SD_APP_GET_MKB ((uint8_t)43) /*!< For SD Card only */
-#define SD_CMD_SD_APP_GET_MID ((uint8_t)44) /*!< For SD Card only */
-#define SD_CMD_SD_APP_SET_CER_RN1 ((uint8_t)45) /*!< For SD Card only */
-#define SD_CMD_SD_APP_GET_CER_RN2 ((uint8_t)46) /*!< For SD Card only */
-#define SD_CMD_SD_APP_SET_CER_RES2 ((uint8_t)47) /*!< For SD Card only */
-#define SD_CMD_SD_APP_GET_CER_RES1 ((uint8_t)48) /*!< For SD Card only */
-#define SD_CMD_SD_APP_SECURE_READ_MULTIPLE_BLOCK ((uint8_t)18) /*!< For SD Card only */
-#define SD_CMD_SD_APP_SECURE_WRITE_MULTIPLE_BLOCK ((uint8_t)25) /*!< For SD Card only */
-#define SD_CMD_SD_APP_SECURE_ERASE ((uint8_t)38) /*!< For SD Card only */
-#define SD_CMD_SD_APP_CHANGE_SECURE_AREA ((uint8_t)49) /*!< For SD Card only */
-#define SD_CMD_SD_APP_SECURE_WRITE_MKB ((uint8_t)48) /*!< For SD Card only */
-
-
-/**
- * @brief SD detection on its memory slot
- */
-#define SD_PRESENT ((uint8_t)0x01)
-#define SD_NOT_PRESENT ((uint8_t)0x00)
-
-/**
- * @brief Supported SD Memory Cards
- */
-#define SDIO_STD_CAPACITY_SD_CARD_V1_1 ((uint32_t)0x00000000)
-#define SDIO_STD_CAPACITY_SD_CARD_V2_0 ((uint32_t)0x00000001)
-#define SDIO_HIGH_CAPACITY_SD_CARD ((uint32_t)0x00000002)
-#define SDIO_MULTIMEDIA_CARD ((uint32_t)0x00000003)
-#define SDIO_SECURE_DIGITAL_IO_CARD ((uint32_t)0x00000004)
-#define SDIO_HIGH_SPEED_MULTIMEDIA_CARD ((uint32_t)0x00000005)
-#define SDIO_SECURE_DIGITAL_IO_COMBO_CARD ((uint32_t)0x00000006)
-#define SDIO_HIGH_CAPACITY_MMC_CARD ((uint32_t)0x00000007)
-
-
-
-/* Exported functions ------------------------------------------------------- */
-void SD_DeInit(void);
-SD_Error SD_Init(void);
-SDTransferState SD_GetStatus(void);
-SDCardState SD_GetState(void);
-uint8_t SD_Detect(void);
-SD_Error SD_PowerON(void);
-SD_Error SD_PowerOFF(void);
-SD_Error SD_InitializeCards(void);
-SD_Error SD_GetCardInfo(SD_CardInfo *cardinfo);
-SD_Error SD_GetCardStatus(SD_CardStatus *cardstatus);
-SD_Error SD_EnableWideBusOperation(uint32_t WideMode);
-SD_Error SD_SelectDeselect(uint32_t addr);
-SD_Error SD_ReadBlock(uint8_t *readbuff, uint32_t ReadAddr, uint16_t BlockSize);
-SD_Error SD_ReadMultiBlocks(uint8_t *readbuff, uint32_t ReadAddr, uint16_t BlockSize, uint32_t NumberOfBlocks);
-SD_Error SD_WriteBlock(uint8_t *writebuff, uint32_t WriteAddr, uint16_t BlockSize);
-SD_Error SD_WriteMultiBlocks(uint8_t *writebuff, uint32_t WriteAddr, uint16_t BlockSize, uint32_t NumberOfBlocks);
-SDTransferState SD_GetTransferState(void);
-SD_Error SD_StopTransfer(void);
-SD_Error SD_Erase(uint32_t startaddr, uint32_t endaddr);
-SD_Error SD_SendStatus(uint32_t *pcardstatus);
-SD_Error SD_SendSDStatus(uint32_t *psdstatus);
-SD_Error SD_ProcessIRQSrc(void);
-SD_Error SD_WaitReadOperation(void);
-SD_Error SD_WaitWriteOperation(void);
-void SD_ProcessDMAIRQ(void);
-void NVIC_Configuration(void);
-
-
-
-SD_Error SD_LBA_ReadBlocks(uint8_t *readbuff, uint32_t BlockAddr, uint32_t NumberOfBlocks);
-SD_Error SD_LBA_WriteBlocks(uint8_t *writebuff, uint32_t BlockAddr, uint32_t NumberOfBlocks);
-
-extern SD_CardInfo SDCardInfo;
-
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __SDCARD_H */
-
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/spi/Kconfig b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/spi/Kconfig
deleted file mode 100644
index 8ff3c9f8b..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/spi/Kconfig
+++ /dev/null
@@ -1,66 +0,0 @@
-config BSP_USING_SPI1
-bool "Using spi1 "
-default y
-
-
-if BSP_USING_SPI1
- config SPI_BUS_NAME_1
- string "spi bus 1 name"
- default "spi1"
- config SPI_1_DRV_NAME
- string "spi bus 1 driver name"
- default "spi1_drv"
- config BSP_SPI1_CLK_PIN
- int "spi1 clk pin number"
- default 29
- config BSP_SPI1_D0_PIN
- int "spi1 d0 pin number"
- default 30
- config BSP_SPI1_D1_PIN
- int "spi1 d1 pin number"
- default 31
- menuconfig BSP_SPI1_USING_SS0
- bool "SPI1 Enable SS0"
- default y
- if BSP_SPI1_USING_SS0
- config SPI_1_DEVICE_NAME_0
- string "spi bus 1 device 0 name"
- default "spi1_dev0"
- config BSP_SPI1_SS0_PIN
- int "spi1 ss0 pin number"
- default 32
- endif
- menuconfig BSP_SPI1_USING_SS1
- bool "SPI1 Enable SS1"
- default y
- if BSP_SPI1_USING_SS1
- config SPI_1_DEVICE_NAME_1
- string "spi bus 1 device 1 name"
- default "spi1_dev1"
- config BSP_SPI1_SS1_PIN
- int "spi1 ss1 pin number"
- default 33
- endif
- menuconfig BSP_SPI1_USING_SS2
- bool "SPI1 Enable SS2"
- default n
- if BSP_SPI1_USING_SS2
- config SPI_1_DEVICE_NAME_2
- string "spi bus 1 device 2 name"
- default "spi1_dev2"
- config BSP_SPI1_SS2_PIN
- int "spi1 ss2 pin number"
- default 26
- endif
- menuconfig BSP_SPI1_USING_SS3
- bool "SPI1 Enable SS3"
- default n
- if BSP_SPI1_USING_SS3
- config SPI_1_DEVICE_NAME_3
- string "spi bus 1 device 3 name"
- default "spi1_dev3"
- config BSP_SPI1_SS3_PIN
- int "spi1 ss3 pin number"
- default 27
- endif
-endif
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/spi/Makefile b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/spi/Makefile
deleted file mode 100644
index 006b43eb1..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/spi/Makefile
+++ /dev/null
@@ -1,7 +0,0 @@
-SRC_FILES := hardware_spi.c connect_spi.c
-
-ifeq ($(CONFIG_RESOURCES_SPI_SFUD),y)
- SRC_FILES += connect_flash_spi.c
-endif
-
-include $(KERNEL_ROOT)/compiler.mk
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/spi/connect_flash_spi.c b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/spi/connect_flash_spi.c
deleted file mode 100644
index 26dc2ddd9..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/spi/connect_flash_spi.c
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (c) 2020 RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2018-11-27 SummerGift add spi flash port file
- */
-
-/**
-* @file connect_flash_spi.c
-* @brief support stm32f407-st-discovery-board spi flash function and register to bus framework
-* @version 1.0
-* @author AIIT XUOS Lab
-* @date 2021-04-25
-*/
-
-/*************************************************
-File name: connect_flash_spi.c
-Description: support stm32f407-st-discovery-board spi flash bus register function
-Others: take RT-Thread v4.0.2/bsp/stm32/stm32f407-atk-explorer/board/ports/spi-flash-init.c
- https://github.com/RT-Thread/rt-thread/tree/v4.0.2
-History:
-1. Date: 2021-04-25
-Author: AIIT XUOS Lab
-Modification:
-1. support stm32f407-st-discovery-board spi flash register to spi bus
-2. support stm32f407-st-discovery-board spi flash init
-*************************************************/
-
-#include "hardware_gpio.h"
-#include "connect_spi.h"
-#include "flash_spi.h"
-
-int FlashW25qxxSpiDeviceInit(void)
-{
-#ifdef BSP_USING_SPI1
-
- __IO uint32_t tmpreg = 0x00U;
- RCC->AHB1ENR |= RCC_AHB1ENR_GPIOBEN;
- tmpreg = RCC->AHB1ENR & RCC_AHB1ENR_GPIOBEN;
- (void)tmpreg;
-
- if (EOK != HwSpiDeviceAttach(SPI_BUS_NAME_1, "spi1_dev0", GPIOB, GPIO_Pin_0)) {
- return ERROR;
- }
-
- if (NONE == SpiFlashInit(SPI_BUS_NAME_1, "spi1_dev0", SPI_1_DRV_NAME, "spi1_W25Q64")) {
- return ERROR;
- }
-
-#endif
-
- return EOK;
-}
\ No newline at end of file
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/spi/connect_spi.c b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/spi/connect_spi.c
deleted file mode 100644
index 9e68aac22..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/spi/connect_spi.c
+++ /dev/null
@@ -1,1638 +0,0 @@
-/*
- * Copyright (c) 2020 RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2018-11-5 SummerGift first version
- * 2018-12-11 greedyhao Porting for stm32f7xx
- * 2019-01-03 zylx modify DMA initialization and spixfer function
- * 2020-01-15 whj4674672 Porting for stm32h7xx
- * 2020-06-18 thread-liu Porting for stm32mp1xx
- * 2020-10-14 Dozingfiretruck Porting for stm32wbxx
- */
-
-/**
-* @file connect_spi.c
-* @brief support stm32f407-st-discovery-board spi function and register to bus framework
-* @version 1.0
-* @author AIIT XUOS Lab
-* @date 2021-04-25
-*/
-
-/*************************************************
-File name: connect_spi.c
-Description: support stm32f407-st-discovery-board spi configure and spi bus register function
-Others: take RT-Thread v4.0.2/bsp/stm32/libraries/HAL_Drivers/drv_spi.c for references
- https://github.com/RT-Thread/rt-thread/tree/v4.0.2
-History:
-1. Date: 2021-04-25
-Author: AIIT XUOS Lab
-Modification:
-1. support stm32f407-st-discovery-board spi configure, write and read
-2. support stm32f407-st-discovery-board spi bus device and driver register
-*************************************************/
-
-#include "stm32f4xx.h"
-#include "connect_spi.h"
-#include "board.h"
-#include "misc.h"
-#include "hardware_spi.h"
-#include "hardware_dma.h"
-#include "hardware_gpio.h"
-#include "hardware_rcc.h"
-
-#include
-#include
-
-/* SPI GPIO define */
-#ifdef BSP_USING_SPI1
-#define SPI1_GPIO_NSS GPIO_Pin_4
-#define SPI1_NSS_PIN_SOURCE GPIO_PinSource4
-#define SPI1_GPIO_SCK GPIO_Pin_5
-#define SPI1_SCK_PIN_SOURCE GPIO_PinSource5
-#define SPI1_GPIO_MISO GPIO_Pin_6
-#define SPI1_MISO_PIN_SOURCE GPIO_PinSource6
-#define SPI1_GPIO_MOSI GPIO_Pin_7
-#define SPI1_MOSI_PIN_SOURCE GPIO_PinSource7
-#define SPI1_GPIO GPIOA
-#define SPI1_GPIO_RCC RCC_AHB1Periph_GPIOA
-#define RCC_APBPeriph_SPI1 RCC_APB2Periph_SPI1
-#endif
-
-#ifdef BSP_USING_SPI2
-#define SPI2_GPIO_NSS GPIO_Pin_6
-#define SPI2_NSS_PIN_SOURCE GPIO_PinSource6
-#define SPI2_GPIO_SCK GPIO_Pin_13
-#define SPI2_SCK_PIN_SOURCE GPIO_PinSource13
-#define SPI2_GPIO_MISO GPIO_Pin_2
-#define SPI2_MISO_PIN_SOURCE GPIO_PinSource2
-#define SPI2_GPIO_MOSI GPIO_Pin_3
-#define SPI2_MOSI_PIN_SOURCE GPIO_PinSource3
-#define SPI2_GPIO GPIOC
-#define SPI2_SCK GPIOB
-#define SPI2_GPIO_RCC RCC_AHB1Periph_GPIOC
-#define SPI2_GPIO_RCC_SCK RCC_AHB1Periph_GPIOB
-#define RCC_APBPeriph_SPI2 RCC_APB1Periph_SPI2
-#endif
-
-#ifdef BSP_USING_SPI3
-#define SPI3_GPIO_NSS GPIO_Pin_15
-#define SPI3_NSS_PIN_SOURCE GPIO_PinSource15
-#define SPI3_GPIO_SCK GPIO_Pin_10
-#define SPI3_SCK_PIN_SOURCE GPIO_PinSource10
-#define SPI3_GPIO_MISO GPIO_Pin_11
-#define SPI3_MISO_PIN_SOURCE GPIO_PinSource11
-#define SPI3_GPIO_MOSI GPIO_Pin_12
-#define SPI3_MOSI_PIN_SOURCE GPIO_PinSource12
-#define SPI3_GPIO GPIOC
-#define SPI3_NSS GPIOA
-#define SPI3_GPIO_RCC RCC_AHB1Periph_GPIOC
-#define SPI3_GPIO_RCC_NSS RCC_AHB1Periph_GPIOA
-#define RCC_APBPeriph_SPI3 RCC_APB2Periph_SPI3
-#endif
-
-/**
- * This function SPI device initialization
- *
- * @param spi_drv SPI device structure pointer
- *
- * @param cfg SPI device operating mode configuration structure pointer
- *
- * @return if successful return EOK
- */
-
-static x_err_t Stm32SpiInit(struct Stm32Spi *spi_drv, struct SpiMasterParam *cfg)
-{
- NULL_PARAM_CHECK(spi_drv);
- NULL_PARAM_CHECK(cfg);
-
- SPI_InitTypeDef *spi_init = &spi_drv->init;
-
- if (cfg->spi_work_mode & DEV_SPI_SLAVE){
- spi_init->SPI_Mode = SPI_Mode_Slave;
- }
- else{
- spi_init->SPI_Mode = SPI_Mode_Master;
- }
-
- if (cfg->spi_work_mode & SPI_3WIRE){
- spi_init->SPI_Direction = SPI_Direction_1Line_Rx;
- }
- else{
- spi_init->SPI_Direction = SPI_Direction_2Lines_FullDuplex;
- }
-
- if (cfg->spi_data_bit_width == 8){
- spi_init->SPI_DataSize = SPI_DataSize_8b;
- }
- else if (cfg->spi_data_bit_width == 16){
- spi_init->SPI_DataSize = SPI_DataSize_16b;
- }
- else{
- return EPIO;
- }
-
- if (cfg->spi_work_mode & SPI_LINE_CPHA){
- spi_init->SPI_CPHA = SPI_CPHA_2Edge;
- }
- else {
- spi_init->SPI_CPHA = SPI_CPHA_1Edge;
- }
-
- if (cfg->spi_work_mode & SPI_LINE_CPOL) {
- spi_init->SPI_CPOL = SPI_CPOL_High;
- }
- else{
- spi_init->SPI_CPOL = SPI_CPOL_Low;
- }
-
- if (cfg->spi_work_mode & SPI_NO_CS) {
- spi_init->SPI_NSS = SPI_NSS_Soft;
- }
- else{
- spi_init->SPI_NSS = SPI_NSS_Soft;
- }
-
- uint32_t SPI_APB_CLOCK;
-
- SPI_APB_CLOCK = system_core_clock>>apb_presc_table[(RCC->CFGR & RCC_CFGR_PPRE2)>> 13U];
-
- if (cfg->spi_maxfrequency >= SPI_APB_CLOCK / 2){
- spi_init->SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;
- }
- else if (cfg->spi_maxfrequency >= SPI_APB_CLOCK / 4){
- spi_init->SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;
- }
- else if (cfg->spi_maxfrequency >= SPI_APB_CLOCK / 8){
- spi_init->SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8;
- }
- else if (cfg->spi_maxfrequency >= SPI_APB_CLOCK / 16){
- spi_init->SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_16;
- }
- else if (cfg->spi_maxfrequency >= SPI_APB_CLOCK / 32){
- spi_init->SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_32;
- }
- else if (cfg->spi_maxfrequency >= SPI_APB_CLOCK / 64){
- spi_init->SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_64;
- }
- else if (cfg->spi_maxfrequency >= SPI_APB_CLOCK / 128) {
- spi_init->SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_128;
- }
- else {
- /* min prescaler 256 */
- spi_init->SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256;
- }
- RCC_ClocksTypeDef RCC_ClocksStatus;
- RCC_GetClocksFreq(&RCC_ClocksStatus);
-
- if (cfg->spi_work_mode & SPI_MSB){
- spi_init->SPI_FirstBit = SPI_FirstBit_MSB; /*Highest bit transmit first*/
- }
- else{
- spi_init->SPI_FirstBit = SPI_FirstBit_LSB; /*lowest bit transmit first*/
- }
-
- spi_init->SPI_CRCPolynomial = 7;
-
- SPI_Init(spi_drv->instance, spi_init);
-
- SPI_Cmd(spi_drv->instance, ENABLE);
-
- uint32_t prioritygroup = 0x00U;
- /* DMA configuration */
- if (spi_drv->spi_dma_flag & SPI_USING_RX_DMA_FLAG){
- DMA_Init(spi_drv->dma.dma_rx.instance, &spi_drv->dma.dma_rx.init);
-
- prioritygroup = NVIC_GetPriorityGrouping();
-
- NVIC_SetPriority(spi_drv->dma.dma_rx.dma_irq, NVIC_EncodePriority(prioritygroup, 0, 0));
-
- NVIC_EnableIRQ(spi_drv->dma.dma_rx.dma_irq);
- }
-
- if (spi_drv->spi_dma_flag & SPI_USING_TX_DMA_FLAG){
- DMA_Init(spi_drv->dma.dma_tx.instance, &spi_drv->dma.dma_tx.init);
-
- prioritygroup = NVIC_GetPriorityGrouping();
-
- NVIC_SetPriority(spi_drv->dma.dma_tx.dma_irq, NVIC_EncodePriority(prioritygroup, 0, 1));
-
- NVIC_EnableIRQ(spi_drv->dma.dma_tx.dma_irq);
- }
-
- spi_drv->instance->CR1 |= SPI_CR1_SPE;
-
- return EOK;
-}
-
-static void DmaSpiConfig(struct SpiBus *spi_bus, uint32_t setting_len, void *rx_base_addr, void *tx_base_addr)
-{
- struct Stm32Spi *spi = (struct Stm32Spi *)spi_bus->private_data;
- uint32 tmpreg = 0x00U;
- NVIC_InitTypeDef NVIC_InitStructure;
-
- if(spi->spi_dma_flag & SPI_USING_RX_DMA_FLAG)
- {
- spi->dma.dma_rx.setting_len = setting_len;
- DMA_DeInit(spi->dma.dma_rx.instance);
- while(DMA_GetCmdStatus(spi->dma.dma_rx.instance) != DISABLE);
- spi->dma.dma_rx.init.DMA_Channel = spi->dma.dma_rx.channel;
- spi->dma.dma_rx.init.DMA_PeripheralBaseAddr = (uint32_t)&(spi->instance->DR);
- spi->dma.dma_rx.init.DMA_Memory0BaseAddr = (uint32_t)rx_base_addr;
- spi->dma.dma_rx.init.DMA_DIR = DMA_DIR_PeripheralToMemory;
- spi->dma.dma_rx.init.DMA_BufferSize = spi->dma.dma_rx.setting_len;
- spi->dma.dma_rx.init.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
- spi->dma.dma_rx.init.DMA_MemoryInc = DMA_MemoryInc_Enable;
- spi->dma.dma_rx.init.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
- spi->dma.dma_rx.init.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
- spi->dma.dma_rx.init.DMA_Mode = DMA_Mode_Normal;
- spi->dma.dma_rx.init.DMA_Priority = DMA_Priority_High;
- spi->dma.dma_rx.init.DMA_FIFOMode = DMA_FIFOMode_Disable;
- spi->dma.dma_rx.init.DMA_FIFOThreshold = DMA_FIFOThreshold_Full;
- spi->dma.dma_rx.init.DMA_MemoryBurst = DMA_MemoryBurst_INC4;
- spi->dma.dma_rx.init.DMA_PeripheralBurst = DMA_PeripheralBurst_INC4;
- DMA_Init(spi->dma.dma_rx.instance, &spi->dma.dma_rx.init);
- DMA_ITConfig(spi->dma.dma_rx.instance, DMA_IT_TC, ENABLE);
-
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE);
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE);
-
- DMA_Cmd(spi->dma.dma_rx.instance, ENABLE);
-
- NVIC_InitStructure.NVIC_IRQChannel = spi->dma.dma_rx.dma_irq;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
-
- tmpreg = 0x00U;
- RCC->AHB1ENR |= spi->dma.dma_rx.dma_rcc;
- tmpreg = RCC->AHB1ENR & spi->dma.dma_rx.dma_rcc;
- (void)tmpreg;
- }
-
- if(spi->spi_dma_flag & SPI_USING_TX_DMA_FLAG)
- {
- spi->dma.dma_tx.setting_len = setting_len;
- DMA_DeInit(spi->dma.dma_tx.instance);
- while(DMA_GetCmdStatus(spi->dma.dma_tx.instance) != DISABLE);
- spi->dma.dma_tx.init.DMA_PeripheralBaseAddr = (uint32_t)&(spi->instance->DR);
- spi->dma.dma_tx.init.DMA_Memory0BaseAddr = (uint32_t)tx_base_addr;
- spi->dma.dma_tx.init.DMA_DIR = DMA_DIR_MemoryToPeripheral;
- spi->dma.dma_tx.init.DMA_BufferSize = spi->dma.dma_tx.setting_len;
- spi->dma.dma_tx.init.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
- spi->dma.dma_tx.init.DMA_MemoryInc = DMA_MemoryInc_Enable;
- spi->dma.dma_tx.init.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
- spi->dma.dma_tx.init.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
- spi->dma.dma_tx.init.DMA_Mode = DMA_Mode_Normal;
- spi->dma.dma_tx.init.DMA_Priority = DMA_Priority_Low;
- spi->dma.dma_tx.init.DMA_FIFOMode = DMA_FIFOMode_Disable;
- spi->dma.dma_tx.init.DMA_FIFOThreshold = DMA_FIFOThreshold_Full;
- spi->dma.dma_tx.init.DMA_MemoryBurst = DMA_MemoryBurst_INC4;
- spi->dma.dma_tx.init.DMA_PeripheralBurst = DMA_PeripheralBurst_INC4;
- DMA_Init(spi->dma.dma_tx.instance, &spi->dma.dma_tx.init);
- DMA_ITConfig(spi->dma.dma_tx.instance, DMA_IT_TC, ENABLE);
-
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE);
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE);
-
- DMA_Cmd(spi->dma.dma_tx.instance, ENABLE);
-
- NVIC_InitStructure.NVIC_IRQChannel = spi->dma.dma_tx.dma_irq;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
-
- tmpreg = 0x00U;
- RCC->AHB1ENR |= spi->dma.dma_rx.dma_rcc;
- tmpreg = RCC->AHB1ENR & spi->dma.dma_rx.dma_rcc;
- (void)tmpreg;
- }
-}
-
-
-static void DmaRxDoneIsr(struct SpiBus *spi_bus)
-{
- struct Stm32Spi *spi = (struct Stm32Spi *) spi_bus->bus.private_data;
- x_size_t recv_len;
- x_base level;
-
- if (DMA_GetFlagStatus(spi->dma.dma_rx.instance, spi->spi_dma_flag) != RESET)
- {
- level = CriticalAreaLock();
-
- recv_len = spi->dma.dma_rx.setting_len - spi->dma.dma_rx.last_index;
- spi->dma.dma_rx.last_index = 0;
- CriticalAreaUnLock(level);
- DMA_ClearFlag(spi->dma.dma_rx.instance, spi->spi_dma_flag);
- }
-}
-
-
-static void DmaTxDoneIsr(struct SpiBus *spi_bus)
-{
- struct Stm32Spi *spi = (struct Stm32Spi *) spi_bus->bus.private_data;
- x_size_t send_len;
- x_base level;
-
- if (DMA_GetFlagStatus(spi->dma.dma_tx.instance, spi->spi_dma_flag) != RESET)
- {
- level = CriticalAreaLock();
-
- send_len = spi->dma.dma_tx.setting_len - spi->dma.dma_tx.last_index;
- spi->dma.dma_tx.last_index = 0;
- CriticalAreaUnLock(level);
- DMA_ClearFlag(spi->dma.dma_tx.instance, spi->spi_dma_flag);
- }
-}
-
-
-static int SpiWaitUntilTimeout(SPI_InitTypeDef spi_init, SPI_TypeDef *spi_instance, uint32_t flag, uint32_t state, uint32_t time_out, uint32_t tick_start)
-{
- while((((spi_instance->SR & flag) == (flag)) ? SET : RESET) != state)
- {
- if(time_out != 0xFFFFFFFFU)
- {
- if((time_out == 0U) || ((CurrentTicksGain() * 1000 / TICK_PER_SECOND-tick_start) >= time_out))
- {
- spi_instance->CR2 &= (~(SPI_IT_TXE | SPI_IT_RXNE | SPI_IT_ERR));
-
- if((spi_init.SPI_Mode == SPI_Mode_Master)&&((spi_init.SPI_Direction == SPI_Direction_1Line_Rx)||(spi_init.SPI_Direction == SPI_Direction_2Lines_RxOnly))) {
- /* Disable SPI peripheral */
- spi_instance->CR1 &= (~SPI_CR1_SPE);
- }
-
- return 3;
- }
- }
- }
- return 0;
-}
-/**
- * This function SPI sends data through DMA
- *
- * @param spi_init SPI Init structure
- *
- * @param spi_instance SPI control handle
- *
- * @param dma_init DMA Init structure
- *
- * @param dma_instance DMA Controller
- *
- * @param p_data Send data buffer address
- *
- * @param size Amount of data sent
- *
- * @return if successful return EOK
- */
-int SpiTransmitDma(SPI_InitTypeDef spi_init, SPI_TypeDef *spi_instance, DMA_InitTypeDef dma_init, DMA_Stream_TypeDef *dma_instance, uint8_t *p_data, uint16_t size)
-{
- int errorcode = 0;
- __IO uint16_t tx_xfer_count;
- uint8_t *p_txbuff_ptr;
- uint16_t tx_xfer_size;
-
- if((p_data == NONE) || (size == 0)){
- errorcode = 1;
- goto error;
- }
-
- tx_xfer_count = size;
- p_txbuff_ptr = (uint8_t *)p_data;
- tx_xfer_size = size;
-
- /* Configure communication direction : 1Line */
- if(spi_init.SPI_Direction == SPI_Direction_1Line_Rx){
- spi_instance->CR1 |= SPI_CR1_BIDIOE;
- }
-
- /* Clear DBM bit */
- dma_instance->CR &= (uint32_t)(~DMA_SxCR_DBM);
-
- /* Configure DMA Stream data length */
- dma_instance->NDTR = tx_xfer_count;
-
- /* Memory to Peripheral */
- if((dma_init.DMA_DIR) == DMA_DIR_MemoryToPeripheral)
- {
- /* Configure DMA Stream destination address */
- dma_instance->PAR = spi_instance->DR;
-
- /* Configure DMA Stream source address */
- dma_instance->M0AR = *p_txbuff_ptr;
- }
- /* Peripheral to Memory */
- else
- {
- /* Configure DMA Stream source address */
- dma_instance->PAR = *p_txbuff_ptr;
-
- /* Configure DMA Stream destination address */
- dma_instance->M0AR = spi_instance->DR;
- }
-
- /* Enable Common interrupts*/
- dma_instance->CR |= DMA_IT_TC | DMA_IT_TE | DMA_IT_DME | DMA_IT_HT;
- dma_instance->FCR |= DMA_IT_FE;
- dma_instance->CR |= DMA_SxCR_EN;
-
- /* Check if the SPI is already enabled */
- if((spi_instance->CR1 &SPI_CR1_SPE) != SPI_CR1_SPE){
- /* Enable SPI peripheral */
- spi_instance->CR1 |= SPI_CR1_SPE;
- }
-
- /* Enable the SPI Error Interrupt Bit */
- spi_instance->CR2 |= SPI_CR2_ERRIE;
-
- /* Enable Tx DMA Request */
- spi_instance->CR2 |=SPI_CR2_TXDMAEN;
-
-error :
- return errorcode;
-}
-/**
- * This function SPI carries out duplex communication through DMA
- *
- * @param spi_init SPI Init structure
- *
- * @param spi_instance SPI control handle
- *
- * @param dmarx_init DMA Init structure---Rx
- *
- * @param dmarx_instance DMA Controller
- *
- * @param dmatx_init DMA Init structure---Tx
- *
- * @param dmatx_instance DMA Controller
- *
- * @param p_txdata Send data buffer address
- *
- * @param p_rxdata Receive data buffer address
- *
- * @param size Amount of data
- *
- * @return if successful return EOK
- */
-int SpiTransmitreceiveDma(SPI_InitTypeDef spi_init, SPI_TypeDef *spi_instance, DMA_InitTypeDef dmarx_init, DMA_Stream_TypeDef *dmarx_instance, DMA_InitTypeDef dmatx_init, DMA_Stream_TypeDef *dmatx_instance, uint8_t *p_txdata, uint8_t *p_rxdata, uint16_t size)
-{
- uint32_t tmp = 0U;
- int errorcode = 0;
- __IO uint16_t tx_xfer_count;
- __IO uint16_t rx_xfer_count;
- uint8_t *p_txbuff_ptr;
- uint8_t *p_rxbuff_ptr;
- uint16_t tx_xfer_size;
- uint16_t rx_xfer_size;
-
- tmp = spi_init.SPI_Mode;
- if(!((tmp == SPI_Mode_Master) && (spi_init.SPI_Direction == SPI_Direction_2Lines_FullDuplex)))
- {
- errorcode = 2;
- goto error;
- }
-
- if((p_txdata == NONE ) || (p_rxdata == NONE ) || (size == 0))
- {
- errorcode = 1;
- goto error;
- }
-
- /* Set the transaction information */
- p_txbuff_ptr = (uint8_t*)p_txdata;
- tx_xfer_size = size;
- tx_xfer_count = size;
- p_rxbuff_ptr = (uint8_t*)p_rxdata;
- rx_xfer_size = size;
- rx_xfer_count = size;
-
- /* Clear DBM bit */
- dmarx_instance->CR &= (uint32_t)(~DMA_SxCR_DBM);
-
- /* Configure DMA Stream data length */
- dmarx_instance->NDTR = rx_xfer_count;
-
- /* Memory to Peripheral */
- if((dmarx_init.DMA_DIR) == DMA_DIR_MemoryToPeripheral)
- {
- /* Configure DMA Stream destination address */
- dmarx_instance->PAR = spi_instance->DR;
-
- /* Configure DMA Stream source address */
- dmarx_instance->M0AR = *p_rxbuff_ptr;
- }
- /* Peripheral to Memory */
- else
- {
- /* Configure DMA Stream source address */
- dmarx_instance->PAR = *p_rxbuff_ptr;
-
- /* Configure DMA Stream destination address */
- dmarx_instance->M0AR = spi_instance->DR;
- }
-
- /* Enable Common interrupts*/
- dmarx_instance->CR |= DMA_IT_TC | DMA_IT_TE | DMA_IT_DME | DMA_IT_HT;
- dmarx_instance->FCR |= DMA_IT_FE;
- dmarx_instance->CR |= DMA_SxCR_EN;
-
- /* Enable Rx DMA Request */
- spi_instance->CR2 |= SPI_CR2_RXDMAEN;
-
- /* Clear DBM bit */
- dmatx_instance->CR &= (uint32_t)(~DMA_SxCR_DBM);
-
- /* Configure DMA Stream data length */
- dmatx_instance->NDTR = tx_xfer_count;
-
- /* Memory to Peripheral */
- if((dmatx_init.DMA_DIR) == DMA_DIR_MemoryToPeripheral)
- {
- /* Configure DMA Stream destination address */
- dmatx_instance->PAR = spi_instance->DR;
-
- /* Configure DMA Stream source address */
- dmatx_instance->M0AR = *p_txbuff_ptr;
- }
- /* Peripheral to Memory */
- else{
- /* Configure DMA Stream source address */
- dmatx_instance->PAR = *p_txbuff_ptr;
-
- /* Configure DMA Stream destination address */
- dmatx_instance->M0AR = spi_instance->DR;
- }
-
- /* Enable Common interrupts*/
- dmatx_instance->CR |= DMA_IT_TC | DMA_IT_TE | DMA_IT_DME | DMA_IT_HT;
- dmatx_instance->FCR |= DMA_IT_FE;
- dmatx_instance->CR |= DMA_SxCR_EN;
-
- /* Check if the SPI is already enabled */
- if((spi_instance->CR1 &SPI_CR1_SPE) != SPI_CR1_SPE){
- /* Enable SPI peripheral */
- spi_instance->CR1 |= SPI_CR1_SPE;
- }
- /* Enable the SPI Error Interrupt Bit */
- spi_instance->CR2 |= SPI_CR2_ERRIE;
-
- /* Enable Tx DMA Request */
- spi_instance->CR2 |= SPI_CR2_TXDMAEN;
-
-error :
- return errorcode;
-}
-/**
- * This function SPI receives data through DMA
- *
- * @param spi_init SPI Init structure
- *
- * @param spi_instance SPI control handle
- *
- * @param dmarx_init DMA Init structure---Rx
- *
- * @param dmarx_instance DMA Controller
- *
- * @param dmatx_init DMA Init structure---Tx
- *
- * @param dmatx_instance DMA Controller
- *
- * @param p_data Receive data buffer address
- *
- * @param size Amount of data
- *
- * @return if successful return EOK
- */
-int SpiReceiveDma(SPI_InitTypeDef spi_init, SPI_TypeDef *spi_instance, DMA_InitTypeDef dmarx_init, DMA_Stream_TypeDef *dmarx_instance, DMA_InitTypeDef dmatx_init, DMA_Stream_TypeDef *dmatx_instance, uint8_t *p_data, uint16_t size)
-{
- int errorcode = 0;
- __IO uint16_t rx_xfer_count;
- uint8_t *p_rxbuff_ptr;
- uint16_t rx_xfer_size;
-
- if((spi_init.SPI_Direction == SPI_Direction_2Lines_FullDuplex)&&(spi_init.SPI_Mode == SPI_Mode_Master)) {
- /* Call transmit-receive function to send Dummy data on Tx line and generate clock on CLK line */
- return SpiTransmitreceiveDma(spi_init, spi_instance, dmarx_init, dmarx_instance, dmatx_init, dmatx_instance, p_data, p_data, size);
- }
-
- if((p_data == NONE) || (size == 0))
- {
- errorcode = 1;
- goto error;
- }
-
- rx_xfer_count = size;
- rx_xfer_size = size;
- p_rxbuff_ptr = (uint8_t *)p_data;
-
- /* Configure communication direction : 1Line */
- if(spi_init.SPI_Direction == SPI_Direction_1Line_Rx) {
- spi_instance->CR1 &= (~SPI_CR1_BIDIOE);
- }
- /* Clear DBM bit */
- dmarx_instance->CR &= (uint32_t)(~DMA_SxCR_DBM);
-
- /* Configure DMA Stream data length */
- dmarx_instance->NDTR = rx_xfer_count;
-
- /* Memory to Peripheral */
- if((dmarx_init.DMA_DIR) == DMA_DIR_MemoryToPeripheral){
- /* Configure DMA Stream destination address */
- dmarx_instance->PAR = spi_instance->DR;
- /* Configure DMA Stream source address */
- dmarx_instance->M0AR = *p_rxbuff_ptr;
- }
- /* Peripheral to Memory */
- else
- {
- /* Configure DMA Stream source address */
- dmarx_instance->PAR = *p_rxbuff_ptr;
-
- /* Configure DMA Stream destination address */
- dmarx_instance->M0AR = spi_instance->DR;
- }
-
- /* Enable Common interrupts*/
- dmarx_instance->CR |= DMA_IT_TC | DMA_IT_TE | DMA_IT_DME | DMA_IT_HT;
- dmarx_instance->FCR |= DMA_IT_FE;
- dmarx_instance->CR |= DMA_SxCR_EN;
-
- /* Check if the SPI is already enabled */
- if((spi_instance->CR1 &SPI_CR1_SPE) != SPI_CR1_SPE){
- /* Enable SPI peripheral */
- spi_instance->CR1 |= SPI_CR1_SPE;
- }
-
- /* Enable the SPI Error Interrupt Bit */
- spi_instance->CR2 |= SPI_CR2_ERRIE;
-
- /* Enable Rx DMA Request */
- spi_instance->CR2 |= SPI_CR2_RXDMAEN;
-
-error:
- return errorcode;
-}
-/**
- * This function SPI receives data
- *
- * @param spi_init SPI Init structure
- *
- * @param spi_instance SPI control handle
- *
- * @param p_data Transmit data buffer address
- *
- * @param size Amount of data
- *
- * @param Timeout waiting time
- *
- * @return if successful return EOK
- */
-int SpiTransmit(SPI_InitTypeDef spi_init, SPI_TypeDef *spi_instance, uint8_t *p_data, uint16_t size, uint32_t Timeout)
-{
- uint32_t tickstart = 0U;
- int errorcode = 0;
- __IO uint16_t tx_xfer_count;
- __IO uint32_t SPITimeout;
-
- /* Init tickstart for timeout management*/
- tickstart = CurrentTicksGain() * 1000 / TICK_PER_SECOND;
-
- if((p_data == NONE ) || (size == 0)){
- errorcode = 1;
- goto error;
- }
-
- tx_xfer_count = size;
-
- /* Configure communication direction : 1Line */
- if(spi_init.SPI_Direction == SPI_Direction_1Line_Rx){
- spi_instance->CR1 |= SPI_CR1_BIDIOE;
- }
-
- /* Check if the SPI is already enabled */
- if((spi_instance->CR1 & SPI_CR1_SPE) != SPI_CR1_SPE){
- /* Enable SPI peripheral */
- spi_instance->CR1 |= SPI_CR1_SPE;
- }
-
- /* Transmit data in 16 Bit mode */
- if(spi_init.SPI_DataSize == SPI_DataSize_16b)
- {
- if((spi_init.SPI_Mode == SPI_Mode_Slave) || (tx_xfer_count == 0x01)){
- spi_instance->DR = *((uint16_t *)p_data);
-
- p_data += sizeof(uint16_t);
- tx_xfer_count--;
- }
- /* Transmit data in 16 Bit mode */
- while (tx_xfer_count > 0U)
- {
- SPITimeout = 0x1000;
- /* Wait until TXE flag is set to send data */
- while (SPI_I2S_GetFlagStatus(spi_instance, SPI_I2S_FLAG_TXE) == RESET)
- {
- if((SPITimeout--) == 0) {
- KPrintf("spi time out\n");
- errorcode = 3;
- goto error;
- }
- }
- /* Write to the data register and write the data to be written into the transmit buffer */
- spi_instance->DR = *((uint16_t *)p_data);
-
- p_data += sizeof(uint16_t);
- tx_xfer_count--;
- }
- }
- /* Transmit data in 8 Bit mode */
- else
- {
- if((spi_init.SPI_Mode == SPI_Mode_Slave) || (tx_xfer_count == 0x01U)){
- *((__IO uint8_t*)&spi_instance->DR) = (*p_data);
-
- p_data += sizeof(uint8_t);
- tx_xfer_count--;
- }
-
- while(tx_xfer_count > 0)
- {
- SPITimeout = 0x1000;
-
- /* Wait for the send buffer to be empty, TXE event*/
- while (SPI_I2S_GetFlagStatus(spi_instance, SPI_I2S_FLAG_TXE) == RESET)
- {
- if((SPITimeout--) == 0){
- KPrintf("spi time out\n");
- errorcode = 3;
- goto error;
- }
- }
-
- /* Write to the data register and write the data to be written into the transmit buffer*/
- *((__IO uint8_t*)&spi_instance->DR) = (*p_data);
-
- p_data += sizeof(uint8_t);
- tx_xfer_count--;
- }
-}
-
- /* Wait until TXE flag */
- if(SpiWaitUntilTimeout(spi_init, spi_instance, SPI_FLAG_TXE, SET, Timeout, tickstart) != 0){
- errorcode = 3;
- goto error;
- }
-
- /* Check Busy flag */
- if(SpiWaitUntilTimeout(spi_init, spi_instance, SPI_FLAG_BSY, RESET, Timeout, tickstart) != 0){
- errorcode = 1;
- goto error;
- }
-
-error:
- return errorcode;
-}
-/**
- * This function SPI Transmit and receive
- *
- * @param spi_init SPI Init structure
- *
- * @param spi_instance SPI control handle
- *
- * @param p_txdata Transmit data buffer address
- *
- * @param p_rxdata receive data buffer address
- *
- * @param size Amount of data
- *
- * @param Timeout waiting time
- *
- * @return if successful return EOK
- */
-int SpiTransmitreceive(SPI_InitTypeDef spi_init, SPI_TypeDef *spi_instance, uint8_t *p_txdata, uint8_t *p_rxdata, uint16_t size, uint32_t Timeout)
-{
- uint32_t tmp = 0U;
-
- uint32_t tickstart = 0U;
- /* Variable used to alternate Rx and Tx during transfer */
- uint32_t txallowed = 1U;
- int errorcode = 0;
- __IO uint16_t tx_xfer_count;
- __IO uint16_t rx_xfer_count;
-
- /* Init tickstart for timeout management*/
- tickstart = CurrentTicksGain() * 1000 / TICK_PER_SECOND;
-
- tmp = spi_init.SPI_Mode;
-
- if(!((tmp == SPI_Mode_Master) && (spi_init.SPI_Direction == SPI_Direction_2Lines_FullDuplex))){
- errorcode = 2;
- goto error;
- }
-
- if((p_txdata == NONE) || (p_rxdata == NONE) || (size == 0)){
- errorcode = 1;
- goto error;
- }
-
- tx_xfer_count = size;
- rx_xfer_count = size;
-
- /* Check if the SPI is already enabled */
- if((spi_instance->CR1 &SPI_CR1_SPE) != SPI_CR1_SPE) {
- /* Enable SPI peripheral */
- spi_instance->CR1 |= SPI_CR1_SPE;
- }
-
- /* Transmit and Receive data in 16 Bit mode */
- if(spi_init.SPI_DataSize == SPI_DataSize_16b)
- {
- if((spi_init.SPI_Mode == SPI_Mode_Slave) || (tx_xfer_count == 0x01U)) {
- SPI_I2S_ReceiveData(spi_instance);
- spi_instance->DR = *((uint16_t *)p_txdata);
-
- p_txdata += sizeof(uint16_t);
- tx_xfer_count--;
- }
- while ((tx_xfer_count > 0U) || (rx_xfer_count > 0U))
- {
- /* Check TXE flag */
- if(txallowed && (tx_xfer_count > 0U) && (SPI_I2S_GetFlagStatus(spi_instance, SPI_I2S_FLAG_TXE) == SET)) {
- SPI_I2S_ReceiveData(spi_instance);
- spi_instance->DR = *((uint16_t *)p_txdata);
- p_txdata += sizeof(uint16_t);
- tx_xfer_count--;
- /* Next Data is a reception (Rx). Tx not allowed */
- txallowed = 0U;
- }
-
- /* Check RXNE flag */
- if((rx_xfer_count > 0U) && (SPI_I2S_GetFlagStatus(spi_instance, SPI_I2S_FLAG_RXNE) == SET))
- {
- *((uint16_t *)p_rxdata) = spi_instance->DR;
- p_rxdata += sizeof(uint16_t);
- rx_xfer_count--;
- /* Next Data is a Transmission (Tx). Tx is allowed */
- txallowed = 1U;
- }
- if((Timeout != 0xFFFFFFFFU) && ((CurrentTicksGain() * 1000 / TICK_PER_SECOND-tickstart) >= Timeout)){
- errorcode = 3;
- goto error;
- }
- }
- }
- /* Transmit and Receive data in 8 Bit mode */
- else
- {
- if((spi_init.SPI_Mode == SPI_Mode_Slave) || (tx_xfer_count == 0x01U))
- {
- SPI_I2S_ReceiveData(spi_instance);
- *((__IO uint8_t*)&spi_instance->DR) = (*p_txdata);
-
- p_txdata += sizeof(uint8_t);
- tx_xfer_count--;
- }
- while((tx_xfer_count > 0U) || (rx_xfer_count > 0U))
- {
- /* Wait for the send buffer to be empty, TXE event */
- if (txallowed && (tx_xfer_count > 0U) && (SPI_I2S_GetFlagStatus(spi_instance, SPI_I2S_FLAG_TXE) == SET))
- {
- /* Write to the data register and write the data to be written into the transmit buffer */
- SPI_I2S_ReceiveData(spi_instance);
- *((__IO uint8_t*)&spi_instance->DR) = (*p_txdata);
-
- p_txdata += sizeof(uint8_t);
- tx_xfer_count--;
- txallowed = 0U;
- }
-
- if ((rx_xfer_count > 0U) && SPI_I2S_GetFlagStatus(spi_instance, SPI_I2S_FLAG_RXNE) == SET)
- {
- *(uint8_t *)p_rxdata = spi_instance->DR;
-
- p_rxdata += sizeof(uint8_t);
- rx_xfer_count--;
- txallowed = 1U;
- }
- if((Timeout != 0xFFFFFFFFU) && ((CurrentTicksGain() * 1000 / TICK_PER_SECOND-tickstart) >= Timeout)) {
- errorcode = 3;
- goto error;
- }
- }
- }
-
- /* Wait until TXE flag */
- if(SpiWaitUntilTimeout(spi_init, spi_instance, SPI_FLAG_TXE, SET, Timeout, tickstart) != 0){
- errorcode = 3;
- goto error;
- }
-
- /* Check Busy flag */
- if(SpiWaitUntilTimeout(spi_init, spi_instance, SPI_FLAG_BSY, RESET, Timeout, tickstart) != 0){
- errorcode = 1;
- goto error;
- }
-
-error :
- return errorcode;
-}
-/**
- * This function SPI receive data
- *
- * @param spi_init SPI Init structure
- *
- * @param spi_instance SPI control handle
- *
- * @param p_data data buffer address
- *
- * @param size Amount of data
- *
- * @param Timeout waiting time
- *
- * @return if successful return EOK
- */
-int SpiReceive(SPI_InitTypeDef spi_init, SPI_TypeDef *spi_instance, uint8_t *p_data, uint16_t size, uint32_t Timeout)
-{
- uint32_t tickstart = 0U;
- int errorcode = 0;
- __IO uint16_t rx_xfer_count;
- __IO uint32_t SPITimeout;
-
- if((spi_init.SPI_Mode == SPI_Mode_Master) && (spi_init.SPI_Direction == SPI_Direction_2Lines_FullDuplex)) {
- /* Call transmit-receive function to send Dummy data on Tx line and generate clock on CLK line */
- return SpiTransmitreceive(spi_init, spi_instance,p_data,p_data,size,Timeout);
- }
-
- /* Init tickstart for timeout management*/
- tickstart = CurrentTicksGain() * 1000 / TICK_PER_SECOND;
-
- if((p_data == NONE ) || (size == 0)){
- errorcode = 1;
- goto error;
- }
-
- rx_xfer_count = size;
-
- /* Configure communication direction: 1Line */
- if(spi_init.SPI_Direction == SPI_Direction_1Line_Rx){
- spi_instance->CR1 &= (~SPI_CR1_BIDIOE);
- }
-
- /* Check if the SPI is already enabled */
- if((spi_instance->CR1 & SPI_CR1_SPE) != SPI_CR1_SPE){
- /* Enable SPI peripheral */
- spi_instance->CR1 |= SPI_CR1_SPE;
- }
-
- /* Receive data in 8 Bit mode */
- if(spi_init.SPI_DataSize == SPI_DataSize_8b)
- {
- /* Transfer loop */
- while(rx_xfer_count > 0U)
- {
- SPITimeout = 0x1000;
-
- /* Wait for the send buffer to be empty, TXE event*/
- while (SPI_I2S_GetFlagStatus(spi_instance, SPI_I2S_FLAG_RXNE) == RESET)
- {
- if((SPITimeout--) == 0){
- KPrintf("spi time out\n");
- errorcode = 3;
- goto error;
- }
- }
-
- *(uint8_t *)p_data = spi_instance->DR;
-
- p_data += sizeof(uint8_t);
- rx_xfer_count--;
- }
- }
- else
- {
- /* Transfer loop */
- while(rx_xfer_count > 0U)
- {
- SPITimeout = 0x1000;
- /* Check the RXNE flag */
- while (SPI_I2S_GetFlagStatus(spi_instance, SPI_I2S_FLAG_RXNE) == RESET)
- {
- if((SPITimeout--) == 0)
- {
- KPrintf("spi time out\n");
- errorcode = 3;
- goto error;
- }
- }
- *((uint16_t*)p_data) = spi_instance->DR;
- p_data += sizeof(uint16_t);
- rx_xfer_count--;
- }
- }
-
- /* Check the end of the transaction */
- if((spi_init.SPI_Mode == SPI_Mode_Master)&&((spi_init.SPI_Direction == SPI_Direction_1Line_Rx)||(spi_init.SPI_Direction == SPI_Direction_2Lines_RxOnly)))
- {
- /* Disable SPI peripheral */
- spi_instance->CR1 &= (~SPI_CR1_SPE);
- }
-
-error :
- return errorcode;
-}
-
-/**
- * This function SPI write data
- *
- * @param spi_dev SPI device structure handle
- *
- * @param spi_datacfg SPI device information structure handle
- *
- * @return datacfg length
- */
-static uint32 Stm32SpiWriteData(struct SpiHardwareDevice *spi_dev, struct SpiDataStandard *spi_datacfg)
-{
- int state;
- x_size_t message_length, already_send_length;
- uint16 send_length;
- const uint8 *WriteBuf;
-
- NULL_PARAM_CHECK(spi_dev);
- NULL_PARAM_CHECK(spi_datacfg);
-
- struct Stm32Spi *StmSpi = CONTAINER_OF(spi_dev->haldev.owner_bus, struct Stm32Spi, spi_bus);
- SPI_TypeDef *spi_instance = StmSpi->instance;
- SPI_InitTypeDef *spi_init = &StmSpi->init;
- struct Stm32HwSpiCs *cs = (struct Stm32HwSpiCs *)spi_dev->private_data;
-
- while(NONE != spi_datacfg) {
- if(spi_datacfg->spi_chip_select) {
- GPIO_WriteBit(cs->GPIOx, cs->GPIO_Pin, Bit_RESET);
- }
-
- message_length = spi_datacfg->length;
- WriteBuf = spi_datacfg->tx_buff;
- while (message_length) {
- if (message_length > 65535){
- send_length = 65535;
- message_length = message_length - 65535;
- } else {
- send_length = message_length;
- message_length = 0;
- }
-
- /* calculate the start address */
- already_send_length = spi_datacfg->length - send_length - message_length;
- WriteBuf = (uint8 *)spi_datacfg->tx_buff + already_send_length;
-
- /* start once data exchange in DMA mode */
- if (spi_datacfg->tx_buff) {
- if (StmSpi->spi_dma_flag & SPI_USING_TX_DMA_FLAG) {
- state = SpiTransmitDma(*spi_init, spi_instance, StmSpi->dma.dma_tx.init, StmSpi->dma.dma_tx.instance, (uint8_t *)WriteBuf, send_length);
- } else {
- state = SpiTransmit(*spi_init, spi_instance, (uint8_t *)WriteBuf, send_length, 1000);
- }
- }
-
- if (state != 0) {
- KPrintf("spi transfer error : %d\n", state);
- spi_datacfg->length = 0;
- }
- }
-
- if (spi_datacfg->spi_cs_release) {
- GPIO_WriteBit(cs->GPIOx, cs->GPIO_Pin, Bit_SET);
- }
-
- spi_datacfg = spi_datacfg->next;
- }
-
- return spi_datacfg->length;
-}
-
-/**
- * This function SPI read data
- *
- * @param spi_dev SPI device structure handle
- *
- * @param spi_datacfg SPI device information structure handle
- *
- * @return datacfg length
- */
-static uint32 Stm32SpiReadData(struct SpiHardwareDevice *spi_dev, struct SpiDataStandard *spi_datacfg)
-{
- int state;
- x_size_t message_length, already_send_length;
- uint16 send_length;
- const uint8 *ReadBuf;
-
- NULL_PARAM_CHECK(spi_dev);
- NULL_PARAM_CHECK(spi_datacfg);
-
- struct Stm32Spi *StmSpi = CONTAINER_OF(spi_dev->haldev.owner_bus, struct Stm32Spi, spi_bus);
- SPI_TypeDef *spi_instance = StmSpi->instance;
- SPI_InitTypeDef *spi_init = &StmSpi->init;
- struct Stm32HwSpiCs *cs = (struct Stm32HwSpiCs *)spi_dev->private_data;
-
- while (NONE != spi_datacfg) {
- if (spi_datacfg->spi_chip_select) {
- GPIO_WriteBit(cs->GPIOx, cs->GPIO_Pin, Bit_RESET);
- }
-
- message_length = spi_datacfg->length;
- ReadBuf = spi_datacfg->rx_buff;
- while (message_length) {
- if (message_length > 65535) {
- send_length = 65535;
- message_length = message_length - 65535;
- } else {
- send_length = message_length;
- message_length = 0;
- }
-
- /* calculate the start address */
- already_send_length = spi_datacfg->length - send_length - message_length;
- ReadBuf = (uint8 *)spi_datacfg->rx_buff + already_send_length;
-
- /* start once data exchange in DMA mode */
- if (spi_datacfg->rx_buff) {
- memset((uint8_t *)ReadBuf, 0xff, send_length);
- if (StmSpi->spi_dma_flag & SPI_USING_RX_DMA_FLAG) {
- state = SpiReceiveDma(*spi_init, spi_instance, StmSpi->dma.dma_rx.init, StmSpi->dma.dma_rx.instance, StmSpi->dma.dma_tx.init, StmSpi->dma.dma_tx.instance, (uint8_t *)ReadBuf, send_length);
- } else {
- state = SpiReceive(*spi_init, spi_instance, (uint8_t *)ReadBuf, send_length, 1000);
- }
- }
-
- if (state != 0) {
- KPrintf("spi transfer error : %d\n", state);
- spi_datacfg->length = 0;
- }
- }
-
- if (spi_datacfg->spi_cs_release) {
- GPIO_WriteBit(cs->GPIOx, cs->GPIO_Pin, Bit_SET);
- }
-
- spi_datacfg = spi_datacfg->next;
- }
-
- return spi_datacfg->length;
-}
-
-/**
- * This function SPI driver initialization function
- *
- * @param spi_drv SPI driver structure handle
- *
- * @return if successful return EOK
- */
-static uint32 SpiDrvInit(struct SpiDriver *spi_drv)
-{
- NULL_PARAM_CHECK(spi_drv);
-
- SpiDeviceParam *dev_param = (SpiDeviceParam *)(spi_drv->driver.private_data);
-
- struct Stm32Spi *StmSpi = CONTAINER_OF(spi_drv->driver.owner_bus, struct Stm32Spi, spi_bus);
-
- return Stm32SpiInit(StmSpi, dev_param->spi_master_param);
-}
-
-/**
- * This function SPI driver configuration param
- *
- * @param spi_drv SPI driver structure handle
- *
- * @param spi_param SPI master param structure handle
- *
- * @return if successful return EOK
- */
-static uint32 SpiDrvConfigure(struct SpiDriver *spi_drv, struct SpiMasterParam *spi_param)
-{
- NULL_PARAM_CHECK(spi_drv);
- NULL_PARAM_CHECK(spi_param);
-
- SpiDeviceParam *dev_param = (SpiDeviceParam *)(spi_drv->driver.private_data);
-
- dev_param->spi_master_param = spi_param;
- dev_param->spi_master_param->spi_work_mode = dev_param->spi_master_param->spi_work_mode & SPI_MODE_MASK;
-
- return EOK;
-}
-
-/*Configure the spi device param, make sure struct (configure_info->private_data) = (SpiMasterParam)*/
-static uint32 Stm32SpiDrvConfigure(void *drv, struct BusConfigureInfo *configure_info)
-{
- NULL_PARAM_CHECK(drv);
- NULL_PARAM_CHECK(configure_info);
-
- x_err_t ret = EOK;
- struct SpiDriver *spi_drv = (struct SpiDriver *)drv;
- struct SpiMasterParam *spi_param;
-
- switch (configure_info->configure_cmd)
- {
- case OPE_INT:
- ret = SpiDrvInit(spi_drv);
- break;
- case OPE_CFG:
- spi_param = (struct SpiMasterParam *)configure_info->private_data;
- ret = SpiDrvConfigure(spi_drv, spi_param);
- break;
- default:
- break;
- }
-
- return ret;
-}
-
-/*manage the spi device operations*/
-static const struct SpiDevDone spi_dev_done =
-{
- .dev_open = NONE,
- .dev_close = NONE,
- .dev_write = Stm32SpiWriteData,
- .dev_read = Stm32SpiReadData,
-};
-
-#if defined(BSP_USING_SPI1)
-struct Stm32Spi spi1;
-#if defined(BSP_SPI1_TX_USING_DMA)
-void DMA2_Stream3_IRQHandler(int irq_num, void *arg)
-{
- DmaTxDoneIsr(&spi1.spi_bus);
-}
-DECLARE_HW_IRQ(DMA2_Stream3_IRQn, DMA2_Stream3_IRQHandler, NONE);
-#endif
-
-#if defined(BSP_SPI1_RX_USING_DMA)
-void DMA2_Stream0_IRQHandler(int irq_num, void *arg)
-{
- DmaRxDoneIsr(&spi1.spi_bus);
-}
-DECLARE_HW_IRQ(DMA2_Stream0_IRQn, DMA2_Stream0_IRQHandler, NONE);
-#endif
-#endif
-
-#if defined(BSP_USING_SPI2)
-struct Stm32Spi spi2;
-#if defined(BSP_SPI2_TX_USING_DMA)
-void DMA1_Stream4_IRQHandler(int irq_num, void *arg)
-{
- DmaTxDoneIsr(&spi2.spi_bus);
-}
-DECLARE_HW_IRQ(DMA1_Stream4_IRQn, DMA1_Stream4_IRQHandler, NONE);
-#endif
-
-#if defined(BSP_SPI2_RX_USING_DMA)
-void DMA1_Stream3_IRQHandler(int irq_num, void *arg)
-{
- DmaTxDoneIsr(&spi2.spi_bus);
-}
-DECLARE_HW_IRQ(DMA1_Stream3_IRQn, DMA1_Stream3_IRQHandler, NONE);
-#endif
-#endif
-
-#if defined(BSP_USING_SPI3)
-struct Stm32Spi spi3;
-#if defined(BSP_SPI3_TX_USING_DMA)
-void DMA1_Stream7_IRQHandler(int irq_num, void *arg)
-{
- DmaTxDoneIsr(&spi3.spi_bus);
-}
-DECLARE_HW_IRQ(DMA1_Stream7_IRQn, DMA1_Stream7_IRQHandler, NONE);
-#endif
-
-#if defined(BSP_SPI3_RX_USING_DMA)
-/**
- * This function DMA2 Stream2 Interrupt service function
- *
- * @return none
- */
-void DMA1_Stream2_IRQHandler(int irq_num, void *arg)
-{
- DmaRxDoneIsr(&spi3.spi_bus);
-}
-DECLARE_HW_IRQ(DMA1_Stream2_IRQn, DMA1_Stream2_IRQHandler, NONE);
-#endif
-#endif
-
-/**
- * This function RCC clock configuration function
- *
- * @return none
- */
-static void RCCConfiguration(void)
-{
-#ifdef BSP_USING_SPI1
- RCC_AHB1PeriphClockCmd(SPI1_GPIO_RCC, ENABLE);
-
- RCC_APB2PeriphClockCmd(RCC_APBPeriph_SPI1, ENABLE);
-#endif
-
-#ifdef BSP_USING_SPI2
- RCC_AHB1PeriphClockCmd(SPI2_GPIO_RCC | SPI2_GPIO_RCC_SCK, ENABLE);
-
- RCC_APB1PeriphClockCmd(RCC_APBPeriph_SPI2, ENABLE);
-#endif
-
-#ifdef BSP_USING_SPI3
- RCC_AHB1PeriphClockCmd(SPI3_GPIO_RCC | SPI3_GPIO_RCC_NSS, ENABLE);
-
- RCC_APB2PeriphClockCmd(RCC_APBPeriph_SPI3, ENABLE);
-#endif
-}
-/**
- * This function GPIO Configuration function
- *
- * @return none
- */
-static void GPIOConfiguration(void)
-{
- GPIO_InitTypeDef gpio_initstructure;
-
- gpio_initstructure.GPIO_Mode = GPIO_Mode_AF; /* Reuse function */
- gpio_initstructure.GPIO_OType = GPIO_OType_PP; /* Multiplex push-pull*/
- gpio_initstructure.GPIO_PuPd = GPIO_PuPd_UP; /* pull up */
- gpio_initstructure.GPIO_Speed = GPIO_Speed_2MHz; /* Level reversal speed */
-
-#ifdef BSP_USING_SPI1
- gpio_initstructure.GPIO_Pin = SPI1_GPIO_NSS | SPI1_GPIO_SCK | SPI1_GPIO_MISO | SPI1_GPIO_MOSI;
- /* Connect alternate function */
- GPIO_PinAFConfig(SPI1_GPIO, SPI1_NSS_PIN_SOURCE, GPIO_AF_SPI1);
- GPIO_PinAFConfig(SPI1_GPIO, SPI1_SCK_PIN_SOURCE, GPIO_AF_SPI1);
- GPIO_PinAFConfig(SPI1_GPIO, SPI1_MISO_PIN_SOURCE, GPIO_AF_SPI1);
- GPIO_PinAFConfig(SPI1_GPIO, SPI1_MOSI_PIN_SOURCE, GPIO_AF_SPI1);
-
- GPIO_Init(SPI1_GPIO, &gpio_initstructure); /*SPI pin initialization*/
-#endif
-
-#ifdef BSP_USING_SPI2
- gpio_initstructure.GPIO_Pin = SPI2_GPIO_SCK;
- /* Connect alternate function */
- GPIO_PinAFConfig(SPI2_SCK, SPI2_SCK_PIN_SOURCE, GPIO_AF_SPI2);
-
- GPIO_Init(SPI2_SCK, &gpio_initstructure);
-
- gpio_initstructure.GPIO_Pin = SPI2_GPIO_NSS | SPI2_GPIO_MISO | SPI2_GPIO_MOSI;
- /* Connect alternate function */
- GPIO_PinAFConfig(SPI2_GPIO, SPI2_NSS_PIN_SOURCE, GPIO_AF_SPI2);
- GPIO_PinAFConfig(SPI2_GPIO, SPI2_MISO_PIN_SOURCE, GPIO_AF_SPI2);
- GPIO_PinAFConfig(SPI2_GPIO, SPI2_MOSI_PIN_SOURCE, GPIO_AF_SPI2);
-
- GPIO_Init(SPI2_GPIO, &gpio_initstructure);
-#endif
-
-#ifdef BSP_USING_SPI3
- gpio_initstructure.GPIO_Pin = SPI3_GPIO_NSS;
- /* Connect alternate function */
- GPIO_PinAFConfig(SPI3_NSS, SPI3_NSS_PIN_SOURCE, GPIO_AF_SPI3);
-
- GPIO_Init(SPI3_NSS, &gpio_initstructure);
-
- gpio_initstructure.GPIO_Pin = SPI3_GPIO_SCK | SPI3_GPIO_MISO | SPI3_GPIO_MOSI;
- GPIO_PinAFConfig(SPI3_GPIO, SPI3_SCK_PIN_SOURCE, GPIO_AF_SPI3);
- GPIO_PinAFConfig(SPI3_GPIO, SPI3_MISO_PIN_SOURCE, GPIO_AF_SPI3);
- GPIO_PinAFConfig(SPI3_GPIO, SPI3_MOSI_PIN_SOURCE, GPIO_AF_SPI3);
-
- GPIO_Init(SPI3_GPIO, &gpio_initstructure);
-#endif
-}
-
-/**
- * This function Init the spi bus 、spi driver and attach to the bus
- *
- * @param spi_bus Spi bus info pointer
- *
- * @param spi_driver Spi driver info pointer
- *
- * @return EOK
- */
-static int BoardSpiBusInit(struct Stm32Spi *stm32spi_bus, struct SpiDriver *spi_driver, char* drv_name)
-{
- x_err_t ret = EOK;
-
- /*Init the spi bus */
- ret = SpiBusInit(&stm32spi_bus->spi_bus, stm32spi_bus->bus_name);
- if (EOK != ret) {
- KPrintf("Board_Spi_init SpiBusInit error %d\n", ret);
- return ERROR;
- }
-
- /*Init the spi driver*/
- ret = SpiDriverInit(spi_driver, drv_name);
- if (EOK != ret) {
- KPrintf("Board_Spi_init SpiDriverInit error %d\n", ret);
- return ERROR;
- }
-
- /*Attach the spi driver to the spi bus*/
- ret = SpiDriverAttachToBus(drv_name, stm32spi_bus->bus_name);
- if (EOK != ret) {
- KPrintf("Board_Spi_init SpiDriverAttachToBus error %d\n", ret);
- return ERROR;
- }
-
- return ret;
-}
-
-
-/**
- * This function SPI bus initialization
- *
- * @return EOK
- */
-static int Stm32HwSpiBusInit(void)
-{
- x_err_t ret = EOK;
- struct Stm32Spi *StmSpiBus;
-
- RCCConfiguration();
- GPIOConfiguration();
-
-#ifdef BSP_USING_SPI1
- StmSpiBus = &spi1;
- StmSpiBus->instance = SPI1;
- StmSpiBus->bus_name = SPI_BUS_NAME_1;
- StmSpiBus->spi_bus.private_data = &spi1;
- DmaSpiConfig(&StmSpiBus->spi_bus, 0, NONE, NONE);
-
- static struct SpiDriver spi_driver_1;
- memset(&spi_driver_1, 0, sizeof(struct SpiDriver));
-
- spi_driver_1.configure = &(Stm32SpiDrvConfigure);
-
- ret = BoardSpiBusInit(StmSpiBus, &spi_driver_1, SPI_1_DRV_NAME);
- if (EOK != ret) {
- KPrintf("Board_Spi_Init spi_bus_init %s error ret %u\n", StmSpiBus->bus_name, ret);
- return ERROR;
- }
-#endif
-
-#ifdef BSP_USING_SPI2
- StmSpiBus = &spi2;
- StmSpiBus->instance = SPI2;
- StmSpiBus->bus_name = SPI_BUS_NAME_2;
- StmSpiBus->spi_bus.private_data = &spi2;
- DmaSpiConfig(&StmSpiBus->spi_bus, 0, NONE, NONE);
-
- static struct SpiDriver spi_driver_2;
- memset(&spi_driver_2, 0, sizeof(struct SpiDriver));
-
- spi_driver_2.configure = &(Stm32SpiDrvConfigure);
-
- ret = BoardSpiBusInit(StmSpiBus, &spi_driver_2, SPI_2_DRV_NAME);
- if (EOK != ret) {
- KPrintf("Board_Spi_Init spi_bus_init %s error ret %u\n", StmSpiBus->bus_name, ret);
- return ERROR;
- }
-#endif
-
-#ifdef BSP_USING_SPI3
- StmSpiBus = &spi3;
- StmSpiBus->instance = SPI3;
- StmSpiBus->bus_name = SPI_BUS_NAME_3;
- StmSpiBus->spi_bus.private_data = &spi3;
- DmaSpiConfig(&StmSpiBus->spi_bus, 0, NONE, NONE);
-
- static struct SpiDriver spi_driver_3;
- memset(&spi_driver_3, 0, sizeof(struct SpiDriver));
-
- spi_driver_3.configure = &(Stm32SpiDrvConfigure);
-
- ret = BoardSpiBusInit(StmSpiBus, &spi_driver_3, SPI_3_DRV_NAME);
- if (EOK != ret) {
- KPrintf("Board_Spi_Init spi_bus_init %s error ret %u\n", StmSpiBus->bus_name, ret);
- return ERROR;
- }
-#endif
- return EOK;
-}
-
-/**
- * This function Mount the spi device to the bus
- *
- * @param bus_name Bus Name
- *
- * @param device_name spi device name
- *
- * @param cs_gpiox GPIO pin configuration handle
- *
- * @param cs_gpio_pin GPIO number
- *
- * @return EOK
- */
-x_err_t HwSpiDeviceAttach(const char *bus_name, const char *device_name, GPIO_TypeDef *cs_gpiox, uint16_t cs_gpio_pin)
-
-{
- NULL_PARAM_CHECK(bus_name);
- NULL_PARAM_CHECK(device_name);
-
- x_err_t result;
- struct SpiHardwareDevice *spi_device;
- struct Stm32HwSpiCs *cs_pin_param;
- static SpiDeviceParam spi_dev_param;
- memset(&spi_dev_param, 0, sizeof(SpiDeviceParam));
-
- /* initialize the cs pin && select the slave*/
- GPIO_InitTypeDef GPIO_Initure;
- GPIO_Initure.GPIO_Pin = cs_gpio_pin;
- GPIO_Initure.GPIO_Mode = GPIO_Mode_OUT;
- GPIO_Initure.GPIO_PuPd = GPIO_PuPd_UP;
- GPIO_Initure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(cs_gpiox, &GPIO_Initure);
- GPIO_WriteBit(cs_gpiox, cs_gpio_pin, Bit_SET);
-
- /* attach the device to spi bus*/
- spi_device = (struct SpiHardwareDevice *)x_malloc(sizeof(struct SpiHardwareDevice));
- CHECK(spi_device);
- memset(spi_device, 0, sizeof(struct SpiHardwareDevice));
- cs_pin_param = (struct Stm32HwSpiCs *)x_malloc(sizeof(struct Stm32HwSpiCs));
- CHECK(cs_pin_param);
- memset(cs_pin_param, 0, sizeof(struct Stm32HwSpiCs));
- cs_pin_param->GPIOx = cs_gpiox;
- cs_pin_param->GPIO_Pin = cs_gpio_pin;
-
- spi_device->spi_dev_done = &spi_dev_done;
- spi_device->private_data = (void *)cs_pin_param;
-
- result = SpiDeviceRegister(spi_device, (void *)&spi_dev_param, device_name);
- if (result != EOK) {
- SYS_ERR("%s device %p register faild, %d\n", device_name, spi_device, result);
- }
-
- result = SpiDeviceAttachToBus(device_name, bus_name);
- if (result != EOK) {
- SYS_ERR("%s attach to %s faild, %d\n", device_name, bus_name, result);
- }
-
- CHECK(result == EOK);
-
- return result;
-}
-
-/**
- * This function Get DMA information
- *
- * @return none
- */
-static void Stm32GetDmaInfo(void)
-{
-#ifdef BSP_SPI1_RX_USING_DMA /*SPI1 uses DMA receive enable*/
- spi1.spi_dma_flag |= SPI_USING_RX_DMA_FLAG;
- spi1.dma.dma_rx.instance = DMA2_Stream0;
- spi1.dma.dma_rx.dma_rcc = RCC_AHB1ENR_DMA2EN;
- spi1.dma.dma_rx.channel = DMA_Channel_3;
- spi1.dma.dma_rx.dma_irq = DMA2_Stream0_IRQn;
-#endif
-#ifdef BSP_SPI1_TX_USING_DMA /*SPI1 uses DMA send enable*/
- spi1.spi_dma_flag |= SPI_USING_TX_DMA_FLAG;
- spi1.dma.dma_tx.instance = DMA2_Stream3;
- spi1.dma.dma_tx.dma_rcc = RCC_AHB1ENR_DMA2EN;
- spi1.dma.dma_tx.channel = DMA_Channel_3;
- spi1.dma.dma_tx.dma_irq = DMA2_Stream3_IRQn;
-#endif
-
-#ifdef BSP_SPI2_RX_USING_DMA /*SPI2 uses DMA receive enable*/
- spi2.spi_dma_flag |= SPI_USING_RX_DMA_FLAG;
- spi2.dma.dma_rx.instance = DMA1_Stream3; /* DMA1 Data stream 3*/
- spi2.dma.dma_rx.dma_rcc = RCC_AHB1ENR_DMA1EN;
- spi2.dma.dma_rx.channel = DMA_Channel_0;
- spi2.dma.dma_rx.dma_irq = DMA1_Stream3_IRQn;
-#endif
-#ifdef BSP_SPI2_TX_USING_DMA /*SPI2 uses DMA send enable*/
- spi2.spi_dma_flag |= SPI_USING_TX_DMA_FLAG;
- spi2.dma.dma_tx.instance = DMA1_Stream4; /* DMA1 Data stream 4*/
- spi2.dma.dma_tx.dma_rcc = RCC_AHB1ENR_DMA1EN;
- spi2.dma.dma_tx.channel = DMA_Channel_0;
- spi2.dma.dma_tx.dma_irq = DMA1_Stream4_IRQn; /*Enable DMA interrupt line*/
-#endif
-
-#ifdef BSP_SPI3_RX_USING_DMA /*SPI3 uses DMA receive enable*/
- spi3.spi_dma_flag |= SPI_USING_RX_DMA_FLAG;
- spi3.dma.dma_rx.instance = DMA1_Stream2; /* DMA1 Data stream 2*/
- spi3.dma.dma_rx.dma_rcc = RCC_AHB1ENR_DMA1EN;
- spi3.dma.dma_rx.channel = DMA_Channel_0;
- spi3.dma.dma_rx.dma_irq = DMA1_Stream2_IRQn; /*Enable DMA interrupt line*/
-#endif
-#ifdef BSP_SPI3_TX_USING_DMA /*SPI3 uses DMA send enable*/
- spi3.spi_dma_flag |= SPI_USING_TX_DMA_FLAG;
- spi3.dma.dma_tx.instance = DMA1_Stream7; /* DMA1 Data stream 7*/
- spi3.dma.dma_tx.dma_rcc = RCC_AHB1ENR_DMA1EN;
- spi3.dma.dma_tx.channel = DMA_Channel_0;
- spi3.dma.dma_tx.dma_irq = DMA1_Stream7_IRQn; /*Enable DMA interrupt line*/
-#endif
-}
-
-/**
- * This function hardware spi initialization
- *
- * @return EOK
- */
-int Stm32HwSpiInit(void)
-{
- Stm32GetDmaInfo();
- return Stm32HwSpiBusInit();
-}
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/spi/hardware_spi.c b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/spi/hardware_spi.c
deleted file mode 100644
index e400763b1..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/spi/hardware_spi.c
+++ /dev/null
@@ -1,1306 +0,0 @@
-/**
- ******************************************************************************
- * @file stm32f4xx_spi.c
- * @author MCD Application Team
- * @version V1.0.0
- * @date 30-September-2011
- * @brief This file provides firmware functions to manage the following
- * functionalities of the Serial peripheral interface (SPI):
- * - Initialization and Configuration
- * - Data transfers functions
- * - Hardware CRC Calculation
- * - DMA transfers management
- * - Interrupts and flags management
- *
- * @verbatim
- *
- *
- * ===================================================================
- * How to use this driver
- * ===================================================================
- *
- * 1. Enable peripheral clock using the following functions
- * RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE) for SPI1
- * RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE) for SPI2
- * RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI3, ENABLE) for SPI3.
- *
- * 2. Enable SCK, MOSI, MISO and NSS GPIO clocks using RCC_AHB1PeriphClockCmd()
- * function.
- * In I2S mode, if an external clock source is used then the I2S CKIN pin GPIO
- * clock should also be enabled.
- *
- * 3. Peripherals alternate function:
- * - Connect the pin to the desired peripherals' Alternate
- * Function (AF) using GPIO_PinAFConfig() function
- * - Configure the desired pin in alternate function by:
- * GPIO_InitStruct->GPIO_Mode = GPIO_Mode_AF
- * - Select the type, pull-up/pull-down and output speed via
- * GPIO_PuPd, GPIO_OType and GPIO_Speed members
- * - Call GPIO_Init() function
- * In I2S mode, if an external clock source is used then the I2S CKIN pin
- * should be also configured in Alternate function Push-pull pull-up mode.
- *
- * 4. Program the Polarity, Phase, First Data, Baud Rate Prescaler, Slave
- * Management, Peripheral Mode and CRC Polynomial values using the SPI_Init()
- * function.
- * In I2S mode, program the Mode, Standard, Data Format, MCLK Output, Audio
- * frequency and Polarity using I2S_Init() function.
- * For I2S mode, make sure that either:
- * - I2S PLL is configured using the functions RCC_I2SCLKConfig(RCC_I2S2CLKSource_PLLI2S),
- * RCC_PLLI2SCmd(ENABLE) and RCC_GetFlagStatus(RCC_FLAG_PLLI2SRDY).
- * or
- * - External clock source is configured using the function
- * RCC_I2SCLKConfig(RCC_I2S2CLKSource_Ext) and after setting correctly the define constant
- * I2S_EXTERNAL_CLOCK_VAL in the stm32f4xx_conf.h file.
- *
- * 5. Enable the NVIC and the corresponding interrupt using the function
- * SPI_ITConfig() if you need to use interrupt mode.
- *
- * 6. When using the DMA mode
- * - Configure the DMA using DMA_Init() function
- * - Active the needed channel Request using SPI_I2S_DMACmd() function
- *
- * 7. Enable the SPI using the SPI_Cmd() function or enable the I2S using
- * I2S_Cmd().
- *
- * 8. Enable the DMA using the DMA_Cmd() function when using DMA mode.
- *
- * 9. Optionally, you can enable/configure the following parameters without
- * re-initialization (i.e there is no need to call again SPI_Init() function):
- * - When bidirectional mode (SPI_Direction_1Line_Rx or SPI_Direction_1Line_Tx)
- * is programmed as Data direction parameter using the SPI_Init() function
- * it can be possible to switch between SPI_Direction_Tx or SPI_Direction_Rx
- * using the SPI_BiDirectionalLineConfig() function.
- * - When SPI_NSS_Soft is selected as Slave Select Management parameter
- * using the SPI_Init() function it can be possible to manage the
- * NSS internal signal using the SPI_NSSInternalSoftwareConfig() function.
- * - Reconfigure the data size using the SPI_DataSizeConfig() function
- * - Enable or disable the SS output using the SPI_SSOutputCmd() function
- *
- * 10. To use the CRC Hardware calculation feature refer to the Peripheral
- * CRC hardware Calculation subsection.
- *
- *
- * It is possible to use SPI in I2S full duplex mode, in this case, each SPI
- * peripheral is able to manage sending and receiving data simultaneously
- * using two data lines. Each SPI peripheral has an extended block called I2Sxext
- * (ie. I2S2ext for SPI2 and I2S3ext for SPI3).
- * The extension block is not a full SPI IP, it is used only as I2S slave to
- * implement full duplex mode. The extension block uses the same clock sources
- * as its master.
- * To configure I2S full duplex you have to:
- *
- * 1. Configure SPIx in I2S mode (I2S_Init() function) as described above.
- *
- * 2. Call the I2S_FullDuplexConfig() function using the same strucutre passed to
- * I2S_Init() function.
- *
- * 3. Call I2S_Cmd() for SPIx then for its extended block.
- *
- * 4. To configure interrupts or DMA requests and to get/clear flag status,
- * use I2Sxext instance for the extension block.
- *
- * Functions that can be called with I2Sxext instances are:
- * I2S_Cmd(), I2S_FullDuplexConfig(), SPI_I2S_ReceiveData(), SPI_I2S_SendData(),
- * SPI_I2S_DMACmd(), SPI_I2S_ITConfig(), SPI_I2S_GetFlagStatus(), SPI_I2S_ClearFlag(),
- * SPI_I2S_GetITStatus() and SPI_I2S_ClearITPendingBit().
- *
- * Example: To use SPI3 in Full duplex mode (SPI3 is Master Tx, I2S3ext is Slave Rx):
- *
- * RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI3, ENABLE);
- * I2S_StructInit(&I2SInitStruct);
- * I2SInitStruct.Mode = I2S_Mode_MasterTx;
- * I2S_Init(SPI3, &I2SInitStruct);
- * I2S_FullDuplexConfig(SPI3ext, &I2SInitStruct)
- * I2S_Cmd(SPI3, ENABLE);
- * I2S_Cmd(SPI3ext, ENABLE);
- * ...
- * while (SPI_I2S_GetFlagStatus(SPI2, SPI_FLAG_TXE) == RESET)
- * {}
- * SPI_I2S_SendData(SPI3, txdata[i]);
- * ...
- * while (SPI_I2S_GetFlagStatus(I2S3ext, SPI_FLAG_RXNE) == RESET)
- * {}
- * rxdata[i] = SPI_I2S_ReceiveData(I2S3ext);
- * ...
- *
- *
- * @note In I2S mode: if an external clock is used as source clock for the I2S,
- * then the define I2S_EXTERNAL_CLOCK_VAL in file stm32f4xx_conf.h should
- * be enabled and set to the value of the source clock frequency (in Hz).
- *
- * @note In SPI mode: To use the SPI TI mode, call the function SPI_TIModeCmd()
- * just after calling the function SPI_Init().
- *
- * @endverbatim
- *
- ******************************************************************************
- * @attention
- *
- * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
- * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
- * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
- * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
- * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
- * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
- *
- * © COPYRIGHT 2011 STMicroelectronics
- ******************************************************************************
- */
-
-/**
-* @file: hardware_spi.c
-* @brief: support hardware spi function
-* @version: 1.0
-* @author: AIIT XUOS Lab
-* @date: 2021/4/25
-*/
-
-/*************************************************
-File name: hardware_spi.c
-Description: support hardware spi function
-Others:
-History:
-1. Date: 2021-04-25
-Author: AIIT XUOS Lab
-Modification:
-1. rename stm32f4xx_spi.c for XiUOS
-*************************************************/
-
-/* Includes ------------------------------------------------------------------*/
-#include
-#include
-#include
-
-/** @addtogroup STM32F4xx_StdPeriph_Driver
- * @{
- */
-
-/** @defgroup SPI
- * @brief SPI driver modules
- * @{
- */
-
-/* Private typedef -----------------------------------------------------------*/
-/* Private define ------------------------------------------------------------*/
-
-/* SPI registers Masks */
-#define CR1_CLEAR_MASK ((uint16_t)0x3040)
-#define I2SCFGR_CLEAR_MASK ((uint16_t)0xF040)
-
-/* RCC PLLs masks */
-#define PLLCFGR_PPLR_MASK ((uint32_t)0x70000000)
-#define PLLCFGR_PPLN_MASK ((uint32_t)0x00007FC0)
-
-#define SPI_CR2_FRF ((uint16_t)0x0010)
-#define SPI_SR_TIFRFE ((uint16_t)0x0100)
-
-/* Private macro -------------------------------------------------------------*/
-/* Private variables ---------------------------------------------------------*/
-/* Private function prototypes -----------------------------------------------*/
-/* Private functions ---------------------------------------------------------*/
-
-/** @defgroup SPI_Private_Functions
- * @{
- */
-
-/** @defgroup SPI_Group1 Initialization and Configuration functions
- * @brief Initialization and Configuration functions
- *
-@verbatim
- ===============================================================================
- Initialization and Configuration functions
- ===============================================================================
-
- This section provides a set of functions allowing to initialize the SPI Direction,
- SPI Mode, SPI Data Size, SPI Polarity, SPI Phase, SPI NSS Management, SPI Baud
- Rate Prescaler, SPI First Bit and SPI CRC Polynomial.
-
- The SPI_Init() function follows the SPI configuration procedures for Master mode
- and Slave mode (details for these procedures are available in reference manual
- (RM0090)).
-
-@endverbatim
- * @{
- */
-
-/**
- * @brief Deinitialize the SPIx peripheral registers to their default reset values.
- * @param SPIx: To select the SPIx/I2Sx peripheral, where x can be: 1, 2 or 3
- * in SPI mode or 2 or 3 in I2S mode.
- *
- * @note The extended I2S blocks (ie. I2S2ext and I2S3ext blocks) are deinitialized
- * when the relative I2S peripheral is deinitialized (the extended block's clock
- * is managed by the I2S peripheral clock).
- *
- * @retval None
- */
-void SPI_I2S_DeInit(SPI_TypeDef* SPIx)
-{
- /* Check the parameters */
- assert_param(IS_SPI_ALL_PERIPH(SPIx));
-
- if (SPIx == SPI1)
- {
- /* Enable SPI1 reset state */
- RCC_APB2PeriphResetCmd(RCC_APB2Periph_SPI1, ENABLE);
- /* Release SPI1 from reset state */
- RCC_APB2PeriphResetCmd(RCC_APB2Periph_SPI1, DISABLE);
- }
- else if (SPIx == SPI2)
- {
- /* Enable SPI2 reset state */
- RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI2, ENABLE);
- /* Release SPI2 from reset state */
- RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI2, DISABLE);
- }
- else
- {
- if (SPIx == SPI3)
- {
- /* Enable SPI3 reset state */
- RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI3, ENABLE);
- /* Release SPI3 from reset state */
- RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI3, DISABLE);
- }
- }
-}
-
-/**
- * @brief Initializes the SPIx peripheral according to the specified
- * parameters in the SPI_InitStruct.
- * @param SPIx: where x can be 1, 2 or 3 to select the SPI peripheral.
- * @param SPI_InitStruct: pointer to a SPI_InitTypeDef structure that
- * contains the configuration information for the specified SPI peripheral.
- * @retval None
- */
-void SPI_Init(SPI_TypeDef* SPIx, SPI_InitTypeDef* SPI_InitStruct)
-{
- uint16_t tmpreg = 0;
-
- /* check the parameters */
- assert_param(IS_SPI_ALL_PERIPH(SPIx));
-
- /* Check the SPI parameters */
- assert_param(IS_SPI_DIRECTION_MODE(SPI_InitStruct->SPI_Direction));
- assert_param(IS_SPI_MODE(SPI_InitStruct->SPI_Mode));
- assert_param(IS_SPI_DATASIZE(SPI_InitStruct->SPI_DataSize));
- assert_param(IS_SPI_CPOL(SPI_InitStruct->SPI_CPOL));
- assert_param(IS_SPI_CPHA(SPI_InitStruct->SPI_CPHA));
- assert_param(IS_SPI_NSS(SPI_InitStruct->SPI_NSS));
- assert_param(IS_SPI_BAUDRATE_PRESCALER(SPI_InitStruct->SPI_BaudRatePrescaler));
- assert_param(IS_SPI_FIRST_BIT(SPI_InitStruct->SPI_FirstBit));
- assert_param(IS_SPI_CRC_POLYNOMIAL(SPI_InitStruct->SPI_CRCPolynomial));
-
-/*---------------------------- SPIx CR1 Configuration ------------------------*/
- /* Get the SPIx CR1 value */
- tmpreg = SPIx->CR1;
- /* Clear BIDIMode, BIDIOE, RxONLY, SSM, SSI, LSBFirst, BR, MSTR, CPOL and CPHA bits */
- tmpreg &= CR1_CLEAR_MASK;
- /* Configure SPIx: direction, NSS management, first transmitted bit, BaudRate prescaler
- master/salve mode, CPOL and CPHA */
- /* Set BIDImode, BIDIOE and RxONLY bits according to SPI_Direction value */
- /* Set SSM, SSI and MSTR bits according to SPI_Mode and SPI_NSS values */
- /* Set LSBFirst bit according to SPI_FirstBit value */
- /* Set BR bits according to SPI_BaudRatePrescaler value */
- /* Set CPOL bit according to SPI_CPOL value */
- /* Set CPHA bit according to SPI_CPHA value */
- tmpreg |= (uint16_t)((uint32_t)SPI_InitStruct->SPI_Direction | SPI_InitStruct->SPI_Mode |
- SPI_InitStruct->SPI_DataSize | SPI_InitStruct->SPI_CPOL |
- SPI_InitStruct->SPI_CPHA | SPI_InitStruct->SPI_NSS |
- SPI_InitStruct->SPI_BaudRatePrescaler | SPI_InitStruct->SPI_FirstBit);
- /* Write to SPIx CR1 */
- SPIx->CR1 = tmpreg;
-
- /* Activate the SPI mode (Reset I2SMOD bit in I2SCFGR register) */
- SPIx->I2SCFGR &= (uint16_t)~((uint16_t)SPI_I2SCFGR_I2SMOD);
-/*---------------------------- SPIx CRCPOLY Configuration --------------------*/
- /* Write to SPIx CRCPOLY */
- SPIx->CRCPR = SPI_InitStruct->SPI_CRCPolynomial;
-}
-
-/**
- * @brief Initializes the SPIx peripheral according to the specified
- * parameters in the I2S_InitStruct.
- * @param SPIx: where x can be 2 or 3 to select the SPI peripheral (configured in I2S mode).
- * @param I2S_InitStruct: pointer to an I2S_InitTypeDef structure that
- * contains the configuration information for the specified SPI peripheral
- * configured in I2S mode.
- *
- * @note The function calculates the optimal prescaler needed to obtain the most
- * accurate audio frequency (depending on the I2S clock source, the PLL values
- * and the product configuration). But in case the prescaler value is greater
- * than 511, the default value (0x02) will be configured instead.
- *
- * @note if an external clock is used as source clock for the I2S, then the define
- * I2S_EXTERNAL_CLOCK_VAL in file stm32f4xx_conf.h should be enabled and set
- * to the value of the the source clock frequency (in Hz).
- *
- * @retval None
- */
-void I2S_Init(SPI_TypeDef* SPIx, I2S_InitTypeDef* I2S_InitStruct)
-{
- uint16_t tmpreg = 0, i2sdiv = 2, i2sodd = 0, packetlength = 1;
- uint32_t tmp = 0, i2sclk = 0;
-#ifndef I2S_EXTERNAL_CLOCK_VAL
- uint32_t pllm = 0, plln = 0, pllr = 0;
-#endif /* I2S_EXTERNAL_CLOCK_VAL */
-
- /* Check the I2S parameters */
- assert_param(IS_SPI_23_PERIPH(SPIx));
- assert_param(IS_I2S_MODE(I2S_InitStruct->I2S_Mode));
- assert_param(IS_I2S_STANDARD(I2S_InitStruct->I2S_Standard));
- assert_param(IS_I2S_DATA_FORMAT(I2S_InitStruct->I2S_DataFormat));
- assert_param(IS_I2S_MCLK_OUTPUT(I2S_InitStruct->I2S_MCLKOutput));
- assert_param(IS_I2S_AUDIO_FREQ(I2S_InitStruct->I2S_AudioFreq));
- assert_param(IS_I2S_CPOL(I2S_InitStruct->I2S_CPOL));
-
-/*----------------------- SPIx I2SCFGR & I2SPR Configuration -----------------*/
- /* Clear I2SMOD, I2SE, I2SCFG, PCMSYNC, I2SSTD, CKPOL, DATLEN and CHLEN bits */
- SPIx->I2SCFGR &= I2SCFGR_CLEAR_MASK;
- SPIx->I2SPR = 0x0002;
-
- /* Get the I2SCFGR register value */
- tmpreg = SPIx->I2SCFGR;
-
- /* If the default value has to be written, reinitialize i2sdiv and i2sodd*/
- if(I2S_InitStruct->I2S_AudioFreq == I2S_AudioFreq_Default)
- {
- i2sodd = (uint16_t)0;
- i2sdiv = (uint16_t)2;
- }
- /* If the requested audio frequency is not the default, compute the prescaler */
- else
- {
- /* Check the frame length (For the Prescaler computing) *******************/
- if(I2S_InitStruct->I2S_DataFormat == I2S_DataFormat_16b)
- {
- /* Packet length is 16 bits */
- packetlength = 1;
- }
- else
- {
- /* Packet length is 32 bits */
- packetlength = 2;
- }
-
- /* Get I2S source Clock frequency ****************************************/
-
- /* If an external I2S clock has to be used, this define should be set
- in the project configuration or in the stm32f4xx_conf.h file */
- #ifdef I2S_EXTERNAL_CLOCK_VAL
- /* Set external clock as I2S clock source */
- if ((RCC->CFGR & RCC_CFGR_I2SSRC) == 0)
- {
- RCC->CFGR |= (uint32_t)RCC_CFGR_I2SSRC;
- }
-
- /* Set the I2S clock to the external clock value */
- i2sclk = I2S_EXTERNAL_CLOCK_VAL;
-
- #else /* There is no define for External I2S clock source */
- /* Set PLLI2S as I2S clock source */
- if ((RCC->CFGR & RCC_CFGR_I2SSRC) != 0)
- {
- RCC->CFGR &= ~(uint32_t)RCC_CFGR_I2SSRC;
- }
-
- /* Get the PLLI2SN value */
- plln = (uint32_t)(((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SN) >> 6) & \
- (RCC_PLLI2SCFGR_PLLI2SN >> 6));
-
- /* Get the PLLI2SR value */
- pllr = (uint32_t)(((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SR) >> 28) & \
- (RCC_PLLI2SCFGR_PLLI2SR >> 28));
-
- /* Get the PLLM value */
- pllm = (uint32_t)(RCC->PLLCFGR & RCC_PLLCFGR_PLLM);
-
- /* Get the I2S source clock value */
- i2sclk = (uint32_t)(((HSE_VALUE / pllm) * plln) / pllr);
- #endif /* I2S_EXTERNAL_CLOCK_VAL */
-
- /* Compute the Real divider depending on the MCLK output state, with a floating point */
- if(I2S_InitStruct->I2S_MCLKOutput == I2S_MCLKOutput_Enable)
- {
- /* MCLK output is enabled */
- tmp = (uint16_t)(((((i2sclk / 256) * 10) / I2S_InitStruct->I2S_AudioFreq)) + 5);
- }
- else
- {
- /* MCLK output is disabled */
- tmp = (uint16_t)(((((i2sclk / (32 * packetlength)) *10 ) / I2S_InitStruct->I2S_AudioFreq)) + 5);
- }
-
- /* Remove the flatting point */
- tmp = tmp / 10;
-
- /* Check the parity of the divider */
- i2sodd = (uint16_t)(tmp & (uint16_t)0x0001);
-
- /* Compute the i2sdiv prescaler */
- i2sdiv = (uint16_t)((tmp - i2sodd) / 2);
-
- /* Get the Mask for the Odd bit (SPI_I2SPR[8]) register */
- i2sodd = (uint16_t) (i2sodd << 8);
- }
-
- /* Test if the divider is 1 or 0 or greater than 0xFF */
- if ((i2sdiv < 2) || (i2sdiv > 0xFF))
- {
- /* Set the default values */
- i2sdiv = 2;
- i2sodd = 0;
- }
-
- /* Write to SPIx I2SPR register the computed value */
- SPIx->I2SPR = (uint16_t)((uint16_t)i2sdiv | (uint16_t)(i2sodd | (uint16_t)I2S_InitStruct->I2S_MCLKOutput));
-
- /* Configure the I2S with the SPI_InitStruct values */
- tmpreg |= (uint16_t)((uint16_t)SPI_I2SCFGR_I2SMOD | (uint16_t)(I2S_InitStruct->I2S_Mode | \
- (uint16_t)(I2S_InitStruct->I2S_Standard | (uint16_t)(I2S_InitStruct->I2S_DataFormat | \
- (uint16_t)I2S_InitStruct->I2S_CPOL))));
-
- /* Write to SPIx I2SCFGR */
- SPIx->I2SCFGR = tmpreg;
-}
-
-/**
- * @brief Fills each SPI_InitStruct member with its default value.
- * @param SPI_InitStruct: pointer to a SPI_InitTypeDef structure which will be initialized.
- * @retval None
- */
-void SPI_StructInit(SPI_InitTypeDef* SPI_InitStruct)
-{
-/*--------------- Reset SPI init structure parameters values -----------------*/
- /* Initialize the SPI_Direction member */
- SPI_InitStruct->SPI_Direction = SPI_Direction_2Lines_FullDuplex;
- /* initialize the SPI_Mode member */
- SPI_InitStruct->SPI_Mode = SPI_Mode_Slave;
- /* initialize the SPI_DataSize member */
- SPI_InitStruct->SPI_DataSize = SPI_DataSize_8b;
- /* Initialize the SPI_CPOL member */
- SPI_InitStruct->SPI_CPOL = SPI_CPOL_Low;
- /* Initialize the SPI_CPHA member */
- SPI_InitStruct->SPI_CPHA = SPI_CPHA_1Edge;
- /* Initialize the SPI_NSS member */
- SPI_InitStruct->SPI_NSS = SPI_NSS_Hard;
- /* Initialize the SPI_BaudRatePrescaler member */
- SPI_InitStruct->SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;
- /* Initialize the SPI_FirstBit member */
- SPI_InitStruct->SPI_FirstBit = SPI_FirstBit_MSB;
- /* Initialize the SPI_CRCPolynomial member */
- SPI_InitStruct->SPI_CRCPolynomial = 7;
-}
-
-/**
- * @brief Fills each I2S_InitStruct member with its default value.
- * @param I2S_InitStruct: pointer to a I2S_InitTypeDef structure which will be initialized.
- * @retval None
- */
-void I2S_StructInit(I2S_InitTypeDef* I2S_InitStruct)
-{
-/*--------------- Reset I2S init structure parameters values -----------------*/
- /* Initialize the I2S_Mode member */
- I2S_InitStruct->I2S_Mode = I2S_Mode_SlaveTx;
-
- /* Initialize the I2S_Standard member */
- I2S_InitStruct->I2S_Standard = I2S_Standard_Phillips;
-
- /* Initialize the I2S_DataFormat member */
- I2S_InitStruct->I2S_DataFormat = I2S_DataFormat_16b;
-
- /* Initialize the I2S_MCLKOutput member */
- I2S_InitStruct->I2S_MCLKOutput = I2S_MCLKOutput_Disable;
-
- /* Initialize the I2S_AudioFreq member */
- I2S_InitStruct->I2S_AudioFreq = I2S_AudioFreq_Default;
-
- /* Initialize the I2S_CPOL member */
- I2S_InitStruct->I2S_CPOL = I2S_CPOL_Low;
-}
-
-/**
- * @brief Enables or disables the specified SPI peripheral.
- * @param SPIx: where x can be 1, 2 or 3 to select the SPI peripheral.
- * @param NewState: new state of the SPIx peripheral.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void SPI_Cmd(SPI_TypeDef* SPIx, FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_SPI_ALL_PERIPH(SPIx));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
- if (NewState != DISABLE)
- {
- /* Enable the selected SPI peripheral */
- SPIx->CR1 |= SPI_CR1_SPE;
- }
- else
- {
- /* Disable the selected SPI peripheral */
- SPIx->CR1 &= (uint16_t)~((uint16_t)SPI_CR1_SPE);
- }
-}
-
-/**
- * @brief Enables or disables the specified SPI peripheral (in I2S mode).
- * @param SPIx: where x can be 2 or 3 to select the SPI peripheral (or I2Sxext
- * for full duplex mode).
- * @param NewState: new state of the SPIx peripheral.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void I2S_Cmd(SPI_TypeDef* SPIx, FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_SPI_23_PERIPH_EXT(SPIx));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- if (NewState != DISABLE)
- {
- /* Enable the selected SPI peripheral (in I2S mode) */
- SPIx->I2SCFGR |= SPI_I2SCFGR_I2SE;
- }
- else
- {
- /* Disable the selected SPI peripheral in I2S mode */
- SPIx->I2SCFGR &= (uint16_t)~((uint16_t)SPI_I2SCFGR_I2SE);
- }
-}
-
-/**
- * @brief Configures the data size for the selected SPI.
- * @param SPIx: where x can be 1, 2 or 3 to select the SPI peripheral.
- * @param SPI_DataSize: specifies the SPI data size.
- * This parameter can be one of the following values:
- * @arg SPI_DataSize_16b: Set data frame format to 16bit
- * @arg SPI_DataSize_8b: Set data frame format to 8bit
- * @retval None
- */
-void SPI_DataSizeConfig(SPI_TypeDef* SPIx, uint16_t SPI_DataSize)
-{
- /* Check the parameters */
- assert_param(IS_SPI_ALL_PERIPH(SPIx));
- assert_param(IS_SPI_DATASIZE(SPI_DataSize));
- /* Clear DFF bit */
- SPIx->CR1 &= (uint16_t)~SPI_DataSize_16b;
- /* Set new DFF bit value */
- SPIx->CR1 |= SPI_DataSize;
-}
-
-/**
- * @brief Selects the data transfer direction in bidirectional mode for the specified SPI.
- * @param SPIx: where x can be 1, 2 or 3 to select the SPI peripheral.
- * @param SPI_Direction: specifies the data transfer direction in bidirectional mode.
- * This parameter can be one of the following values:
- * @arg SPI_Direction_Tx: Selects Tx transmission direction
- * @arg SPI_Direction_Rx: Selects Rx receive direction
- * @retval None
- */
-void SPI_BiDirectionalLineConfig(SPI_TypeDef* SPIx, uint16_t SPI_Direction)
-{
- /* Check the parameters */
- assert_param(IS_SPI_ALL_PERIPH(SPIx));
- assert_param(IS_SPI_DIRECTION(SPI_Direction));
- if (SPI_Direction == SPI_Direction_Tx)
- {
- /* Set the Tx only mode */
- SPIx->CR1 |= SPI_Direction_Tx;
- }
- else
- {
- /* Set the Rx only mode */
- SPIx->CR1 &= SPI_Direction_Rx;
- }
-}
-
-/**
- * @brief Configures internally by software the NSS pin for the selected SPI.
- * @param SPIx: where x can be 1, 2 or 3 to select the SPI peripheral.
- * @param SPI_NSSInternalSoft: specifies the SPI NSS internal state.
- * This parameter can be one of the following values:
- * @arg SPI_NSSInternalSoft_Set: Set NSS pin internally
- * @arg SPI_NSSInternalSoft_Reset: Reset NSS pin internally
- * @retval None
- */
-void SPI_NSSInternalSoftwareConfig(SPI_TypeDef* SPIx, uint16_t SPI_NSSInternalSoft)
-{
- /* Check the parameters */
- assert_param(IS_SPI_ALL_PERIPH(SPIx));
- assert_param(IS_SPI_NSS_INTERNAL(SPI_NSSInternalSoft));
- if (SPI_NSSInternalSoft != SPI_NSSInternalSoft_Reset)
- {
- /* Set NSS pin internally by software */
- SPIx->CR1 |= SPI_NSSInternalSoft_Set;
- }
- else
- {
- /* Reset NSS pin internally by software */
- SPIx->CR1 &= SPI_NSSInternalSoft_Reset;
- }
-}
-
-/**
- * @brief Enables or disables the SS output for the selected SPI.
- * @param SPIx: where x can be 1, 2 or 3 to select the SPI peripheral.
- * @param NewState: new state of the SPIx SS output.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void SPI_SSOutputCmd(SPI_TypeDef* SPIx, FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_SPI_ALL_PERIPH(SPIx));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
- if (NewState != DISABLE)
- {
- /* Enable the selected SPI SS output */
- SPIx->CR2 |= (uint16_t)SPI_CR2_SSOE;
- }
- else
- {
- /* Disable the selected SPI SS output */
- SPIx->CR2 &= (uint16_t)~((uint16_t)SPI_CR2_SSOE);
- }
-}
-
-/**
- * @brief Enables or disables the SPIx/I2Sx DMA interface.
- *
- * @note This function can be called only after the SPI_Init() function has
- * been called.
- * @note When TI mode is selected, the control bits SSM, SSI, CPOL and CPHA
- * are not taken into consideration and are configured by hardware
- * respectively to the TI mode requirements.
- *
- * @param SPIx: where x can be 1, 2 or 3
- * @param NewState: new state of the selected SPI TI communication mode.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void SPI_TIModeCmd(SPI_TypeDef* SPIx, FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_SPI_ALL_PERIPH(SPIx));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- if (NewState != DISABLE)
- {
- /* Enable the TI mode for the selected SPI peripheral */
- SPIx->CR2 |= SPI_CR2_FRF;
- }
- else
- {
- /* Disable the TI mode for the selected SPI peripheral */
- SPIx->CR2 &= (uint16_t)~SPI_CR2_FRF;
- }
-}
-
-/**
- * @brief Configures the full duplex mode for the I2Sx peripheral using its
- * extension I2Sxext according to the specified parameters in the
- * I2S_InitStruct.
- * @param I2Sxext: where x can be 2 or 3 to select the I2S peripheral extension block.
- * @param I2S_InitStruct: pointer to an I2S_InitTypeDef structure that
- * contains the configuration information for the specified I2S peripheral
- * extension.
- *
- * @note The structure pointed by I2S_InitStruct parameter should be the same
- * used for the master I2S peripheral. In this case, if the master is
- * configured as transmitter, the slave will be receiver and vice versa.
- * Or you can force a different mode by modifying the field I2S_Mode to the
- * value I2S_SlaveRx or I2S_SlaveTx indepedently of the master configuration.
- *
- * @note The I2S full duplex extension can be configured in slave mode only.
- *
- * @retval None
- */
-void I2S_FullDuplexConfig(SPI_TypeDef* I2Sxext, I2S_InitTypeDef* I2S_InitStruct)
-{
- uint16_t tmpreg = 0, tmp = 0;
-
- /* Check the I2S parameters */
- assert_param(IS_I2S_EXT_PERIPH(I2Sxext));
- assert_param(IS_I2S_MODE(I2S_InitStruct->I2S_Mode));
- assert_param(IS_I2S_STANDARD(I2S_InitStruct->I2S_Standard));
- assert_param(IS_I2S_DATA_FORMAT(I2S_InitStruct->I2S_DataFormat));
- assert_param(IS_I2S_CPOL(I2S_InitStruct->I2S_CPOL));
-
-/*----------------------- SPIx I2SCFGR & I2SPR Configuration -----------------*/
- /* Clear I2SMOD, I2SE, I2SCFG, PCMSYNC, I2SSTD, CKPOL, DATLEN and CHLEN bits */
- I2Sxext->I2SCFGR &= I2SCFGR_CLEAR_MASK;
- I2Sxext->I2SPR = 0x0002;
-
- /* Get the I2SCFGR register value */
- tmpreg = I2Sxext->I2SCFGR;
-
- /* Get the mode to be configured for the extended I2S */
- if ((I2S_InitStruct->I2S_Mode == I2S_Mode_MasterTx) || (I2S_InitStruct->I2S_Mode == I2S_Mode_SlaveTx))
- {
- tmp = I2S_Mode_SlaveRx;
- }
- else
- {
- if ((I2S_InitStruct->I2S_Mode == I2S_Mode_MasterRx) || (I2S_InitStruct->I2S_Mode == I2S_Mode_SlaveRx))
- {
- tmp = I2S_Mode_SlaveTx;
- }
- }
-
-
- /* Configure the I2S with the SPI_InitStruct values */
- tmpreg |= (uint16_t)((uint16_t)SPI_I2SCFGR_I2SMOD | (uint16_t)(tmp | \
- (uint16_t)(I2S_InitStruct->I2S_Standard | (uint16_t)(I2S_InitStruct->I2S_DataFormat | \
- (uint16_t)I2S_InitStruct->I2S_CPOL))));
-
- /* Write to SPIx I2SCFGR */
- I2Sxext->I2SCFGR = tmpreg;
-}
-
-/**
- * @}
- */
-
-/** @defgroup SPI_Group2 Data transfers functions
- * @brief Data transfers functions
- *
-@verbatim
- ===============================================================================
- Data transfers functions
- ===============================================================================
-
- This section provides a set of functions allowing to manage the SPI data transfers
-
- In reception, data are received and then stored into an internal Rx buffer while
- In transmission, data are first stored into an internal Tx buffer before being
- transmitted.
-
- The read access of the SPI_DR register can be done using the SPI_I2S_ReceiveData()
- function and returns the Rx buffered value. Whereas a write access to the SPI_DR
- can be done using SPI_I2S_SendData() function and stores the written data into
- Tx buffer.
-
-@endverbatim
- * @{
- */
-
-/**
- * @brief Returns the most recent received data by the SPIx/I2Sx peripheral.
- * @param SPIx: To select the SPIx/I2Sx peripheral, where x can be: 1, 2 or 3
- * in SPI mode or 2 or 3 in I2S mode or I2Sxext for I2S full duplex mode.
- * @retval The value of the received data.
- */
-uint16_t SPI_I2S_ReceiveData(SPI_TypeDef* SPIx)
-{
- /* Check the parameters */
- assert_param(IS_SPI_ALL_PERIPH_EXT(SPIx));
-
- /* Return the data in the DR register */
- return SPIx->DR;
-}
-
-/**
- * @brief Transmits a Data through the SPIx/I2Sx peripheral.
- * @param SPIx: To select the SPIx/I2Sx peripheral, where x can be: 1, 2 or 3
- * in SPI mode or 2 or 3 in I2S mode or I2Sxext for I2S full duplex mode.
- * @param Data: Data to be transmitted.
- * @retval None
- */
-void SPI_I2S_SendData(SPI_TypeDef* SPIx, uint16_t Data)
-{
- /* Check the parameters */
- assert_param(IS_SPI_ALL_PERIPH_EXT(SPIx));
-
- /* Write in the DR register the data to be sent */
- SPIx->DR = Data;
-}
-
-/**
- * @}
- */
-
-/** @defgroup SPI_Group3 Hardware CRC Calculation functions
- * @brief Hardware CRC Calculation functions
- *
-@verbatim
- ===============================================================================
- Hardware CRC Calculation functions
- ===============================================================================
-
- This section provides a set of functions allowing to manage the SPI CRC hardware
- calculation
-
- SPI communication using CRC is possible through the following procedure:
- 1. Program the Data direction, Polarity, Phase, First Data, Baud Rate Prescaler,
- Slave Management, Peripheral Mode and CRC Polynomial values using the SPI_Init()
- function.
- 2. Enable the CRC calculation using the SPI_CalculateCRC() function.
- 3. Enable the SPI using the SPI_Cmd() function
- 4. Before writing the last data to the TX buffer, set the CRCNext bit using the
- SPI_TransmitCRC() function to indicate that after transmission of the last
- data, the CRC should be transmitted.
- 5. After transmitting the last data, the SPI transmits the CRC. The SPI_CR1_CRCNEXT
- bit is reset. The CRC is also received and compared against the SPI_RXCRCR
- value.
- If the value does not match, the SPI_FLAG_CRCERR flag is set and an interrupt
- can be generated when the SPI_I2S_IT_ERR interrupt is enabled.
-
-@note It is advised not to read the calculated CRC values during the communication.
-
-@note When the SPI is in slave mode, be careful to enable CRC calculation only
- when the clock is stable, that is, when the clock is in the steady state.
- If not, a wrong CRC calculation may be done. In fact, the CRC is sensitive
- to the SCK slave input clock as soon as CRCEN is set, and this, whatever
- the value of the SPE bit.
-
-@note With high bitrate frequencies, be careful when transmitting the CRC.
- As the number of used CPU cycles has to be as low as possible in the CRC
- transfer phase, it is forbidden to call software functions in the CRC
- transmission sequence to avoid errors in the last data and CRC reception.
- In fact, CRCNEXT bit has to be written before the end of the transmission/reception
- of the last data.
-
-@note For high bit rate frequencies, it is advised to use the DMA mode to avoid the
- degradation of the SPI speed performance due to CPU accesses impacting the
- SPI bandwidth.
-
-@note When the STM32F4xx is configured as slave and the NSS hardware mode is
- used, the NSS pin needs to be kept low between the data phase and the CRC
- phase.
-
-@note When the SPI is configured in slave mode with the CRC feature enabled, CRC
- calculation takes place even if a high level is applied on the NSS pin.
- This may happen for example in case of a multi-slave environment where the
- communication master addresses slaves alternately.
-
-@note Between a slave de-selection (high level on NSS) and a new slave selection
- (low level on NSS), the CRC value should be cleared on both master and slave
- sides in order to resynchronize the master and slave for their respective
- CRC calculation.
-
-@note To clear the CRC, follow the procedure below:
- 1. Disable SPI using the SPI_Cmd() function
- 2. Disable the CRC calculation using the SPI_CalculateCRC() function.
- 3. Enable the CRC calculation using the SPI_CalculateCRC() function.
- 4. Enable SPI using the SPI_Cmd() function.
-
-@endverbatim
- * @{
- */
-
-/**
- * @brief Enables or disables the CRC value calculation of the transferred bytes.
- * @param SPIx: where x can be 1, 2 or 3 to select the SPI peripheral.
- * @param NewState: new state of the SPIx CRC value calculation.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void SPI_CalculateCRC(SPI_TypeDef* SPIx, FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_SPI_ALL_PERIPH(SPIx));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
- if (NewState != DISABLE)
- {
- /* Enable the selected SPI CRC calculation */
- SPIx->CR1 |= SPI_CR1_CRCEN;
- }
- else
- {
- /* Disable the selected SPI CRC calculation */
- SPIx->CR1 &= (uint16_t)~((uint16_t)SPI_CR1_CRCEN);
- }
-}
-
-/**
- * @brief Transmit the SPIx CRC value.
- * @param SPIx: where x can be 1, 2 or 3 to select the SPI peripheral.
- * @retval None
- */
-void SPI_TransmitCRC(SPI_TypeDef* SPIx)
-{
- /* Check the parameters */
- assert_param(IS_SPI_ALL_PERIPH(SPIx));
-
- /* Enable the selected SPI CRC transmission */
- SPIx->CR1 |= SPI_CR1_CRCNEXT;
-}
-
-/**
- * @brief Returns the transmit or the receive CRC register value for the specified SPI.
- * @param SPIx: where x can be 1, 2 or 3 to select the SPI peripheral.
- * @param SPI_CRC: specifies the CRC register to be read.
- * This parameter can be one of the following values:
- * @arg SPI_CRC_Tx: Selects Tx CRC register
- * @arg SPI_CRC_Rx: Selects Rx CRC register
- * @retval The selected CRC register value..
- */
-uint16_t SPI_GetCRC(SPI_TypeDef* SPIx, uint8_t SPI_CRC)
-{
- uint16_t crcreg = 0;
- /* Check the parameters */
- assert_param(IS_SPI_ALL_PERIPH(SPIx));
- assert_param(IS_SPI_CRC(SPI_CRC));
- if (SPI_CRC != SPI_CRC_Rx)
- {
- /* Get the Tx CRC register */
- crcreg = SPIx->TXCRCR;
- }
- else
- {
- /* Get the Rx CRC register */
- crcreg = SPIx->RXCRCR;
- }
- /* Return the selected CRC register */
- return crcreg;
-}
-
-/**
- * @brief Returns the CRC Polynomial register value for the specified SPI.
- * @param SPIx: where x can be 1, 2 or 3 to select the SPI peripheral.
- * @retval The CRC Polynomial register value.
- */
-uint16_t SPI_GetCRCPolynomial(SPI_TypeDef* SPIx)
-{
- /* Check the parameters */
- assert_param(IS_SPI_ALL_PERIPH(SPIx));
-
- /* Return the CRC polynomial register */
- return SPIx->CRCPR;
-}
-
-/**
- * @}
- */
-
-/** @defgroup SPI_Group4 DMA transfers management functions
- * @brief DMA transfers management functions
- *
-@verbatim
- ===============================================================================
- DMA transfers management functions
- ===============================================================================
-
-@endverbatim
- * @{
- */
-
-/**
- * @brief Enables or disables the SPIx/I2Sx DMA interface.
- * @param SPIx: To select the SPIx/I2Sx peripheral, where x can be: 1, 2 or 3
- * in SPI mode or 2 or 3 in I2S mode or I2Sxext for I2S full duplex mode.
- * @param SPI_I2S_DMAReq: specifies the SPI DMA transfer request to be enabled or disabled.
- * This parameter can be any combination of the following values:
- * @arg SPI_I2S_DMAReq_Tx: Tx buffer DMA transfer request
- * @arg SPI_I2S_DMAReq_Rx: Rx buffer DMA transfer request
- * @param NewState: new state of the selected SPI DMA transfer request.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void SPI_I2S_DMACmd(SPI_TypeDef* SPIx, uint16_t SPI_I2S_DMAReq, FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_SPI_ALL_PERIPH_EXT(SPIx));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
- assert_param(IS_SPI_I2S_DMAREQ(SPI_I2S_DMAReq));
-
- if (NewState != DISABLE)
- {
- /* Enable the selected SPI DMA requests */
- SPIx->CR2 |= SPI_I2S_DMAReq;
- }
- else
- {
- /* Disable the selected SPI DMA requests */
- SPIx->CR2 &= (uint16_t)~SPI_I2S_DMAReq;
- }
-}
-
-/**
- * @}
- */
-
-/** @defgroup SPI_Group5 Interrupts and flags management functions
- * @brief Interrupts and flags management functions
- *
-@verbatim
- ===============================================================================
- Interrupts and flags management functions
- ===============================================================================
-
- This section provides a set of functions allowing to configure the SPI Interrupts
- sources and check or clear the flags or pending bits status.
- The user should identify which mode will be used in his application to manage
- the communication: Polling mode, Interrupt mode or DMA mode.
-
- Polling Mode
- =============
- In Polling Mode, the SPI/I2S communication can be managed by 9 flags:
- 1. SPI_I2S_FLAG_TXE : to indicate the status of the transmit buffer register
- 2. SPI_I2S_FLAG_RXNE : to indicate the status of the receive buffer register
- 3. SPI_I2S_FLAG_BSY : to indicate the state of the communication layer of the SPI.
- 4. SPI_FLAG_CRCERR : to indicate if a CRC Calculation error occur
- 5. SPI_FLAG_MODF : to indicate if a Mode Fault error occur
- 6. SPI_I2S_FLAG_OVR : to indicate if an Overrun error occur
- 7. I2S_FLAG_TIFRFE: to indicate a Frame Format error occurs.
- 8. I2S_FLAG_UDR: to indicate an Underrun error occurs.
- 9. I2S_FLAG_CHSIDE: to indicate Channel Side.
-
-@note Do not use the BSY flag to handle each data transmission or reception. It is
- better to use the TXE and RXNE flags instead.
-
- In this Mode it is advised to use the following functions:
- - FlagStatus SPI_I2S_GetFlagStatus(SPI_TypeDef* SPIx, uint16_t SPI_I2S_FLAG);
- - void SPI_I2S_ClearFlag(SPI_TypeDef* SPIx, uint16_t SPI_I2S_FLAG);
-
- Interrupt Mode
- ===============
- In Interrupt Mode, the SPI communication can be managed by 3 interrupt sources
- and 7 pending bits:
- Pending Bits:
- -------------
- 1. SPI_I2S_IT_TXE : to indicate the status of the transmit buffer register
- 2. SPI_I2S_IT_RXNE : to indicate the status of the receive buffer register
- 3. SPI_IT_CRCERR : to indicate if a CRC Calculation error occur (available in SPI mode only)
- 4. SPI_IT_MODF : to indicate if a Mode Fault error occur (available in SPI mode only)
- 5. SPI_I2S_IT_OVR : to indicate if an Overrun error occur
- 6. I2S_IT_UDR : to indicate an Underrun Error occurs (available in I2S mode only).
- 7. I2S_FLAG_TIFRFE : to indicate a Frame Format error occurs (available in TI mode only).
-
- Interrupt Source:
- -----------------
- 1. SPI_I2S_IT_TXE: specifies the interrupt source for the Tx buffer empty
- interrupt.
- 2. SPI_I2S_IT_RXNE : specifies the interrupt source for the Rx buffer not
- empty interrupt.
- 3. SPI_I2S_IT_ERR : specifies the interrupt source for the errors interrupt.
-
- In this Mode it is advised to use the following functions:
- - void SPI_I2S_ITConfig(SPI_TypeDef* SPIx, uint8_t SPI_I2S_IT, FunctionalState NewState);
- - ITStatus SPI_I2S_GetITStatus(SPI_TypeDef* SPIx, uint8_t SPI_I2S_IT);
- - void SPI_I2S_ClearITPendingBit(SPI_TypeDef* SPIx, uint8_t SPI_I2S_IT);
-
- DMA Mode
- ========
- In DMA Mode, the SPI communication can be managed by 2 DMA Channel requests:
- 1. SPI_I2S_DMAReq_Tx: specifies the Tx buffer DMA transfer request
- 2. SPI_I2S_DMAReq_Rx: specifies the Rx buffer DMA transfer request
-
- In this Mode it is advised to use the following function:
- - void SPI_I2S_DMACmd(SPI_TypeDef* SPIx, uint16_t SPI_I2S_DMAReq, FunctionalState NewState);
-
-@endverbatim
- * @{
- */
-
-/**
- * @brief Enables or disables the specified SPI/I2S interrupts.
- * @param SPIx: To select the SPIx/I2Sx peripheral, where x can be: 1, 2 or 3
- * in SPI mode or 2 or 3 in I2S mode or I2Sxext for I2S full duplex mode.
- * @param SPI_I2S_IT: specifies the SPI interrupt source to be enabled or disabled.
- * This parameter can be one of the following values:
- * @arg SPI_I2S_IT_TXE: Tx buffer empty interrupt mask
- * @arg SPI_I2S_IT_RXNE: Rx buffer not empty interrupt mask
- * @arg SPI_I2S_IT_ERR: Error interrupt mask
- * @param NewState: new state of the specified SPI interrupt.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void SPI_I2S_ITConfig(SPI_TypeDef* SPIx, uint8_t SPI_I2S_IT, FunctionalState NewState)
-{
- uint16_t itpos = 0, itmask = 0 ;
-
- /* Check the parameters */
- assert_param(IS_SPI_ALL_PERIPH_EXT(SPIx));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
- assert_param(IS_SPI_I2S_CONFIG_IT(SPI_I2S_IT));
-
- /* Get the SPI IT index */
- itpos = SPI_I2S_IT >> 4;
-
- /* Set the IT mask */
- itmask = (uint16_t)1 << (uint16_t)itpos;
-
- if (NewState != DISABLE)
- {
- /* Enable the selected SPI interrupt */
- SPIx->CR2 |= itmask;
- }
- else
- {
- /* Disable the selected SPI interrupt */
- SPIx->CR2 &= (uint16_t)~itmask;
- }
-}
-
-/**
- * @brief Checks whether the specified SPIx/I2Sx flag is set or not.
- * @param SPIx: To select the SPIx/I2Sx peripheral, where x can be: 1, 2 or 3
- * in SPI mode or 2 or 3 in I2S mode or I2Sxext for I2S full duplex mode.
- * @param SPI_I2S_FLAG: specifies the SPI flag to check.
- * This parameter can be one of the following values:
- * @arg SPI_I2S_FLAG_TXE: Transmit buffer empty flag.
- * @arg SPI_I2S_FLAG_RXNE: Receive buffer not empty flag.
- * @arg SPI_I2S_FLAG_BSY: Busy flag.
- * @arg SPI_I2S_FLAG_OVR: Overrun flag.
- * @arg SPI_FLAG_MODF: Mode Fault flag.
- * @arg SPI_FLAG_CRCERR: CRC Error flag.
- * @arg SPI_I2S_FLAG_TIFRFE: Format Error.
- * @arg I2S_FLAG_UDR: Underrun Error flag.
- * @arg I2S_FLAG_CHSIDE: Channel Side flag.
- * @retval The new state of SPI_I2S_FLAG (SET or RESET).
- */
-FlagStatus SPI_I2S_GetFlagStatus(SPI_TypeDef* SPIx, uint16_t SPI_I2S_FLAG)
-{
- FlagStatus bitstatus = RESET;
- /* Check the parameters */
- assert_param(IS_SPI_ALL_PERIPH_EXT(SPIx));
- assert_param(IS_SPI_I2S_GET_FLAG(SPI_I2S_FLAG));
-
- /* Check the status of the specified SPI flag */
- if ((SPIx->SR & SPI_I2S_FLAG) != (uint16_t)RESET)
- {
- /* SPI_I2S_FLAG is set */
- bitstatus = SET;
- }
- else
- {
- /* SPI_I2S_FLAG is reset */
- bitstatus = RESET;
- }
- /* Return the SPI_I2S_FLAG status */
- return bitstatus;
-}
-
-/**
- * @brief Clears the SPIx CRC Error (CRCERR) flag.
- * @param SPIx: To select the SPIx/I2Sx peripheral, where x can be: 1, 2 or 3
- * in SPI mode or 2 or 3 in I2S mode or I2Sxext for I2S full duplex mode.
- * @param SPI_I2S_FLAG: specifies the SPI flag to clear.
- * This function clears only CRCERR flag.
- * @arg SPI_FLAG_CRCERR: CRC Error flag.
- *
- * @note OVR (OverRun error) flag is cleared by software sequence: a read
- * operation to SPI_DR register (SPI_I2S_ReceiveData()) followed by a read
- * operation to SPI_SR register (SPI_I2S_GetFlagStatus()).
- * @note UDR (UnderRun error) flag is cleared by a read operation to
- * SPI_SR register (SPI_I2S_GetFlagStatus()).
- * @note MODF (Mode Fault) flag is cleared by software sequence: a read/write
- * operation to SPI_SR register (SPI_I2S_GetFlagStatus()) followed by a
- * write operation to SPI_CR1 register (SPI_Cmd() to enable the SPI).
- *
- * @retval None
- */
-void SPI_I2S_ClearFlag(SPI_TypeDef* SPIx, uint16_t SPI_I2S_FLAG)
-{
- /* Check the parameters */
- assert_param(IS_SPI_ALL_PERIPH_EXT(SPIx));
- assert_param(IS_SPI_I2S_CLEAR_FLAG(SPI_I2S_FLAG));
-
- /* Clear the selected SPI CRC Error (CRCERR) flag */
- SPIx->SR = (uint16_t)~SPI_I2S_FLAG;
-}
-
-/**
- * @brief Checks whether the specified SPIx/I2Sx interrupt has occurred or not.
- * @param SPIx: To select the SPIx/I2Sx peripheral, where x can be: 1, 2 or 3
- * in SPI mode or 2 or 3 in I2S mode or I2Sxext for I2S full duplex mode.
- * @param SPI_I2S_IT: specifies the SPI interrupt source to check.
- * This parameter can be one of the following values:
- * @arg SPI_I2S_IT_TXE: Transmit buffer empty interrupt.
- * @arg SPI_I2S_IT_RXNE: Receive buffer not empty interrupt.
- * @arg SPI_I2S_IT_OVR: Overrun interrupt.
- * @arg SPI_IT_MODF: Mode Fault interrupt.
- * @arg SPI_IT_CRCERR: CRC Error interrupt.
- * @arg I2S_IT_UDR: Underrun interrupt.
- * @arg SPI_I2S_IT_TIFRFE: Format Error interrupt.
- * @retval The new state of SPI_I2S_IT (SET or RESET).
- */
-ITStatus SPI_I2S_GetITStatus(SPI_TypeDef* SPIx, uint8_t SPI_I2S_IT)
-{
- ITStatus bitstatus = RESET;
- uint16_t itpos = 0, itmask = 0, enablestatus = 0;
-
- /* Check the parameters */
- assert_param(IS_SPI_ALL_PERIPH_EXT(SPIx));
- assert_param(IS_SPI_I2S_GET_IT(SPI_I2S_IT));
-
- /* Get the SPI_I2S_IT index */
- itpos = 0x01 << (SPI_I2S_IT & 0x0F);
-
- /* Get the SPI_I2S_IT IT mask */
- itmask = SPI_I2S_IT >> 4;
-
- /* Set the IT mask */
- itmask = 0x01 << itmask;
-
- /* Get the SPI_I2S_IT enable bit status */
- enablestatus = (SPIx->CR2 & itmask) ;
-
- /* Check the status of the specified SPI interrupt */
- if (((SPIx->SR & itpos) != (uint16_t)RESET) && enablestatus)
- {
- /* SPI_I2S_IT is set */
- bitstatus = SET;
- }
- else
- {
- /* SPI_I2S_IT is reset */
- bitstatus = RESET;
- }
- /* Return the SPI_I2S_IT status */
- return bitstatus;
-}
-
-/**
- * @brief Clears the SPIx CRC Error (CRCERR) interrupt pending bit.
- * @param SPIx: To select the SPIx/I2Sx peripheral, where x can be: 1, 2 or 3
- * in SPI mode or 2 or 3 in I2S mode or I2Sxext for I2S full duplex mode.
- * @param SPI_I2S_IT: specifies the SPI interrupt pending bit to clear.
- * This function clears only CRCERR interrupt pending bit.
- * @arg SPI_IT_CRCERR: CRC Error interrupt.
- *
- * @note OVR (OverRun Error) interrupt pending bit is cleared by software
- * sequence: a read operation to SPI_DR register (SPI_I2S_ReceiveData())
- * followed by a read operation to SPI_SR register (SPI_I2S_GetITStatus()).
- * @note UDR (UnderRun Error) interrupt pending bit is cleared by a read
- * operation to SPI_SR register (SPI_I2S_GetITStatus()).
- * @note MODF (Mode Fault) interrupt pending bit is cleared by software sequence:
- * a read/write operation to SPI_SR register (SPI_I2S_GetITStatus())
- * followed by a write operation to SPI_CR1 register (SPI_Cmd() to enable
- * the SPI).
- * @retval None
- */
-void SPI_I2S_ClearITPendingBit(SPI_TypeDef* SPIx, uint8_t SPI_I2S_IT)
-{
- uint16_t itpos = 0;
- /* Check the parameters */
- assert_param(IS_SPI_ALL_PERIPH_EXT(SPIx));
- assert_param(IS_SPI_I2S_CLEAR_IT(SPI_I2S_IT));
-
- /* Get the SPI_I2S IT index */
- itpos = 0x01 << (SPI_I2S_IT & 0x0F);
-
- /* Clear the selected SPI CRC Error (CRCERR) interrupt pending bit */
- SPIx->SR = (uint16_t)~itpos;
-}
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-
-/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/timer/Kconfig b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/timer/Kconfig
deleted file mode 100644
index 33f325e1b..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/timer/Kconfig
+++ /dev/null
@@ -1,19 +0,0 @@
-if BSP_USING_HWTIMER
- config HWTIMER_BUS_NAME_2
- string "hwtimer bus name"
- default "hwtim2"
-
- menuconfig ENABLE_TIM2
- bool "enable TIM2"
- default y
-
- if ENABLE_TIM2
- config HWTIMER_2_DEVICE_NAME_2
- string "TIM2 dev name"
- default "hwtim2_dev2"
-
- config HWTIMER_DRIVER_NAME_2
- string "TIM2 drv name"
- default "hwtim2_drv"
- endif
-endif
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/timer/Makefile b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/timer/Makefile
deleted file mode 100644
index 344a8d9e2..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/timer/Makefile
+++ /dev/null
@@ -1,3 +0,0 @@
-SRC_FILES := connect_hwtimer.c hardware_tim.c
-
-include $(KERNEL_ROOT)/compiler.mk
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/timer/connect_hwtimer.c b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/timer/connect_hwtimer.c
deleted file mode 100644
index 2d626777f..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/timer/connect_hwtimer.c
+++ /dev/null
@@ -1,186 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2018-12-10 zylx first version
- * 2020-06-16 thread-liu Porting for stm32mp1
- * 2020-08-25 linyongkang Fix the timer clock frequency doubling problem
- * 2020-10-14 Dozingfiretruck Porting for stm32wbxx
- */
-
-/**
-* @file connect_hwtimer.c
-* @brief support stm32f407-st-discovery-board hwtimer function and register to bus framework
-* @version 1.0
-* @author AIIT XUOS Lab
-* @date 2021-04-25
-*/
-
-/*************************************************
-File name: connect_hwtimer.c
-Description: support stm32f407-st-discovery-board hwtimer configure and spi bus register function
-Others: take RT-Thread v4.0.2/bsp/stm32/libraries/HAL_Drivers/drv_hwtimer.c for references
- https://github.com/RT-Thread/rt-thread/tree/v4.0.2
-History:
-1. Date: 2021-04-25
-Author: AIIT XUOS Lab
-Modification:
-1. support stm32f407-st-discovery-board hwtimer configure
-2. support stm32f407-st-discovery-board hwtimer bus device and driver register
-*************************************************/
-
-#include
-#include
-#include
-#include
-#include
-#include "connect_hwtimer.h"
-
-static struct HwtimerCallBackInfo *ptim2_cb_info = NULL;
-
-#ifdef ENABLE_TIM2
-void TIM2_IRQHandler(int irq_num, void *arg)
-{
- TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
- KPrintf("hwtimer 2 ... come ...\n");
-
- if (ptim2_cb_info) {
- if (ptim2_cb_info->timeout_callback) {
- ptim2_cb_info->timeout_callback(ptim2_cb_info->param);
- }
- }
-}
-DECLARE_HW_IRQ(TIM2_IRQn, TIM2_IRQHandler, NONE);
-#endif
-
-uint32 HwtimerOpen(void *dev)
-{
- struct HwtimerHardwareDevice *hwtimer_dev = dev;
-
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
-
- TIM_DeInit(TIM2);
-
- TIM_TimeBaseInitTypeDef timer_def;
- timer_def.TIM_Period = (hwtimer_dev->hwtimer_param.period_millisecond) * 10 - 1;
- timer_def.TIM_Prescaler = 8400 - 1;
- timer_def.TIM_CounterMode = TIM_CounterMode_Up;
- timer_def.TIM_ClockDivision = TIM_CKD_DIV1;
- timer_def.TIM_RepetitionCounter = 0;
- TIM_TimeBaseInit(TIM2, &timer_def);
-
- NVIC_InitTypeDef NVIC_InitStructure;
- NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn; /*Configure the timer interrupt line*/
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x01; /*Configure preemption priority*/
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x01; /*Configure sub-priority*/
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; /*Enable interrupt line*/
- NVIC_Init(&NVIC_InitStructure);
-
- ptim2_cb_info = &hwtimer_dev->hwtimer_param.cb_info;
-
- TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
-
- TIM_Cmd(TIM2, ENABLE);
- return EOK;
-}
-
-uint32 HwtimerClose(void *dev)
-{
- TIM_Cmd(TIM2, DISABLE);
- return EOK;
-}
-
-/*manage the hwtimer device operations*/
-static const struct HwtimerDevDone dev_done =
-{
- .open = HwtimerOpen,
- .close = HwtimerClose,
- .write = NONE,
- .read = NONE,
-};
-
-/*Init hwtimer bus*/
-static int BoardHwtimerBusInit(struct HwtimerBus *hwtimer_bus, struct HwtimerDriver *hwtimer_driver)
-{
- x_err_t ret = EOK;
-
- /*Init the hwtimer bus */
- ret = HwtimerBusInit(hwtimer_bus, HWTIMER_BUS_NAME_2);
- if (EOK != ret) {
- KPrintf("board_hwtimer_init HwtimerBusInit error %d\n", ret);
- return ERROR;
- }
-
- #ifdef ENABLE_TIM2
- /*Init the hwtimer driver*/
- hwtimer_driver->configure = NONE;
- ret = HwtimerDriverInit(hwtimer_driver, HWTIMER_DRIVER_NAME_2);
- if (EOK != ret) {
- KPrintf("board_hwtimer_init HwtimerDriverInit error %d\n", ret);
- return ERROR;
- }
-
- /*Attach the hwtimer driver to the hwtimer bus*/
- ret = HwtimerDriverAttachToBus(HWTIMER_DRIVER_NAME_2, HWTIMER_BUS_NAME_2);
- if (EOK != ret) {
- KPrintf("board_hwtimer_init USEDriverAttachToBus error %d\n", ret);
- return ERROR;
- }
- #endif
-
- return ret;
-}
-
-/*Attach the hwtimer device to the hwtimer bus*/
-static int BoardHwtimerDevBend(void)
-{
- #ifdef ENABLE_TIM2
- x_err_t ret = EOK;
- static struct HwtimerHardwareDevice hwtimer_device_2;
- memset(&hwtimer_device_2, 0, sizeof(struct HwtimerHardwareDevice));
-
- hwtimer_device_2.dev_done = &dev_done;
-
- ret = HwtimerDeviceRegister(&hwtimer_device_2, NONE, HWTIMER_2_DEVICE_NAME_2);
- if (EOK != ret) {
- KPrintf("board_hwtimer_init HWTIMERDeviceInit device %s error %d\n", HWTIMER_2_DEVICE_NAME_2, ret);
- return ERROR;
- }
-
- ret = HwtimerDeviceAttachToBus(HWTIMER_2_DEVICE_NAME_2, HWTIMER_BUS_NAME_2);
- if (EOK != ret) {
- KPrintf("board_hwtimer_init HwtimerDeviceAttachToBus device %s error %d\n", HWTIMER_2_DEVICE_NAME_2, ret);
- return ERROR;
- }
-
- return ret;
- #endif
-}
-
-/*ARM-32 BOARD HWTIMER INIT*/
-int Stm32HwTimerInit(void)
-{
- x_err_t ret = EOK;
- static struct HwtimerBus hwtimer_bus;
- memset(&hwtimer_bus, 0, sizeof(struct HwtimerBus));
-
- static struct HwtimerDriver hwtimer_driver;
- memset(&hwtimer_driver, 0, sizeof(struct HwtimerDriver));
-
- ret = BoardHwtimerBusInit(&hwtimer_bus, &hwtimer_driver);
- if (EOK != ret) {
- KPrintf("board_hwtimer_Init error ret %u\n", ret);
- return ERROR;
- }
-
- ret = BoardHwtimerDevBend();
- if (EOK != ret) {
- KPrintf("board_hwtimer_Init error ret %u\n", ret);
- return ERROR;
- }
-
- return ret;
-}
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/timer/hardware_tim.c b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/timer/hardware_tim.c
deleted file mode 100644
index 1e3dc06b4..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/timer/hardware_tim.c
+++ /dev/null
@@ -1,3372 +0,0 @@
-/**
- ******************************************************************************
- * @file stm32f4xx_tim.c
- * @author MCD Application Team
- * @version V1.0.0
- * @date 30-September-2011
- * @brief This file provides firmware functions to manage the following
- * functionalities of the TIM peripheral:
- * - TimeBase management
- * - Output Compare management
- * - Input Capture management
- * - Advanced-control timers (TIM1 and TIM8) specific features
- * - Interrupts, DMA and flags management
- * - Clocks management
- * - Synchronization management
- * - Specific interface management
- * - Specific remapping management
- *
- * @verbatim
- *
- * ===================================================================
- * How to use this driver
- * ===================================================================
- * This driver provides functions to configure and program the TIM
- * of all STM32F4xx devices.
- * These functions are split in 9 groups:
- *
- * 1. TIM TimeBase management: this group includes all needed functions
- * to configure the TM Timebase unit:
- * - Set/Get Prescaler
- * - Set/Get Autoreload
- * - Counter modes configuration
- * - Set Clock division
- * - Select the One Pulse mode
- * - Update Request Configuration
- * - Update Disable Configuration
- * - Auto-Preload Configuration
- * - Enable/Disable the counter
- *
- * 2. TIM Output Compare management: this group includes all needed
- * functions to configure the Capture/Compare unit used in Output
- * compare mode:
- * - Configure each channel, independently, in Output Compare mode
- * - Select the output compare modes
- * - Select the Polarities of each channel
- * - Set/Get the Capture/Compare register values
- * - Select the Output Compare Fast mode
- * - Select the Output Compare Forced mode
- * - Output Compare-Preload Configuration
- * - Clear Output Compare Reference
- * - Select the OCREF Clear signal
- * - Enable/Disable the Capture/Compare Channels
- *
- * 3. TIM Input Capture management: this group includes all needed
- * functions to configure the Capture/Compare unit used in
- * Input Capture mode:
- * - Configure each channel in input capture mode
- * - Configure Channel1/2 in PWM Input mode
- * - Set the Input Capture Prescaler
- * - Get the Capture/Compare values
- *
- * 4. Advanced-control timers (TIM1 and TIM8) specific features
- * - Configures the Break input, dead time, Lock level, the OSSI,
- * the OSSR State and the AOE(automatic output enable)
- * - Enable/Disable the TIM peripheral Main Outputs
- * - Select the Commutation event
- * - Set/Reset the Capture Compare Preload Control bit
- *
- * 5. TIM interrupts, DMA and flags management
- * - Enable/Disable interrupt sources
- * - Get flags status
- * - Clear flags/ Pending bits
- * - Enable/Disable DMA requests
- * - Configure DMA burst mode
- * - Select CaptureCompare DMA request
- *
- * 6. TIM clocks management: this group includes all needed functions
- * to configure the clock controller unit:
- * - Select internal/External clock
- * - Select the external clock mode: ETR(Mode1/Mode2), TIx or ITRx
- *
- * 7. TIM synchronization management: this group includes all needed
- * functions to configure the Synchronization unit:
- * - Select Input Trigger
- * - Select Output Trigger
- * - Select Master Slave Mode
- * - ETR Configuration when used as external trigger
- *
- * 8. TIM specific interface management, this group includes all
- * needed functions to use the specific TIM interface:
- * - Encoder Interface Configuration
- * - Select Hall Sensor
- *
- * 9. TIM specific remapping management includes the Remapping
- * configuration of specific timers
- *
- * @endverbatim
- *
- ******************************************************************************
- * @attention
- *
- * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
- * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
- * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
- * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
- * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
- * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
- *
- * © COPYRIGHT 2011 STMicroelectronics
- ******************************************************************************
- */
-
-/**
-* @file: hardware_tim.c
-* @brief: support hardware tim function
-* @version: 1.0
-* @author: AIIT XUOS Lab
-* @date: 2021/4/25
-*/
-
-/*************************************************
-File name: hardware_tim.c
-Description: support hardware tim function
-Others:
-History:
-1. Date: 2021-04-25
-Author: AIIT XUOS Lab
-Modification:
-1. rename stm32f4xx_tim.c for XiUOS
-*************************************************/
-
-/* Includes ------------------------------------------------------------------*/
-#include
-#include
-#include
-
-/** @addtogroup STM32F4xx_StdPeriph_Driver
- * @{
- */
-
-/** @defgroup TIM
- * @brief TIM driver modules
- * @{
- */
-
-/* Private typedef -----------------------------------------------------------*/
-/* Private define ------------------------------------------------------------*/
-
-/* ---------------------- TIM registers bit mask ------------------------ */
-#define SMCR_ETR_MASK ((uint16_t)0x00FF)
-#define CCMR_OFFSET ((uint16_t)0x0018)
-#define CCER_CCE_SET ((uint16_t)0x0001)
-#define CCER_CCNE_SET ((uint16_t)0x0004)
-#define CCMR_OC13M_MASK ((uint16_t)0xFF8F)
-#define CCMR_OC24M_MASK ((uint16_t)0x8FFF)
-
-/* Private macro -------------------------------------------------------------*/
-/* Private variables ---------------------------------------------------------*/
-/* Private function prototypes -----------------------------------------------*/
-static void TI1_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection,
- uint16_t TIM_ICFilter);
-static void TI2_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection,
- uint16_t TIM_ICFilter);
-static void TI3_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection,
- uint16_t TIM_ICFilter);
-static void TI4_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection,
- uint16_t TIM_ICFilter);
-
-/* Private functions ---------------------------------------------------------*/
-
-/** @defgroup TIM_Private_Functions
- * @{
- */
-
-/** @defgroup TIM_Group1 TimeBase management functions
- * @brief TimeBase management functions
- *
-@verbatim
- ===============================================================================
- TimeBase management functions
- ===============================================================================
-
- ===================================================================
- TIM Driver: how to use it in Timing(Time base) Mode
- ===================================================================
- To use the Timer in Timing(Time base) mode, the following steps are mandatory:
-
- 1. Enable TIM clock using RCC_APBxPeriphClockCmd(RCC_APBxPeriph_TIMx, ENABLE) function
-
- 2. Fill the TIM_TimeBaseInitStruct with the desired parameters.
-
- 3. Call TIM_TimeBaseInit(TIMx, &TIM_TimeBaseInitStruct) to configure the Time Base unit
- with the corresponding configuration
-
- 4. Enable the NVIC if you need to generate the update interrupt.
-
- 5. Enable the corresponding interrupt using the function TIM_ITConfig(TIMx, TIM_IT_Update)
-
- 6. Call the TIM_Cmd(ENABLE) function to enable the TIM counter.
-
- Note1: All other functions can be used separately to modify, if needed,
- a specific feature of the Timer.
-
-@endverbatim
- * @{
- */
-
-/**
- * @brief Deinitializes the TIMx peripheral registers to their default reset values.
- * @param TIMx: where x can be 1 to 14 to select the TIM peripheral.
- * @retval None
-
- */
-void TIM_DeInit(TIM_TypeDef* TIMx)
-{
- /* Check the parameters */
- assert_param(IS_TIM_ALL_PERIPH(TIMx));
-
- if (TIMx == TIM1)
- {
- RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM1, ENABLE);
- RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM1, DISABLE);
- }
- else if (TIMx == TIM2)
- {
- RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM2, ENABLE);
- RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM2, DISABLE);
- }
- else if (TIMx == TIM3)
- {
- RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM3, ENABLE);
- RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM3, DISABLE);
- }
- else if (TIMx == TIM4)
- {
- RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM4, ENABLE);
- RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM4, DISABLE);
- }
- else if (TIMx == TIM5)
- {
- RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM5, ENABLE);
- RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM5, DISABLE);
- }
- else if (TIMx == TIM6)
- {
- RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM6, ENABLE);
- RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM6, DISABLE);
- }
- else if (TIMx == TIM7)
- {
- RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM7, ENABLE);
- RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM7, DISABLE);
- }
- else if (TIMx == TIM8)
- {
- RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM8, ENABLE);
- RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM8, DISABLE);
- }
- else if (TIMx == TIM9)
- {
- RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM9, ENABLE);
- RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM9, DISABLE);
- }
- else if (TIMx == TIM10)
- {
- RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM10, ENABLE);
- RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM10, DISABLE);
- }
- else if (TIMx == TIM11)
- {
- RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM11, ENABLE);
- RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM11, DISABLE);
- }
- else if (TIMx == TIM12)
- {
- RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM12, ENABLE);
- RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM12, DISABLE);
- }
- else if (TIMx == TIM13)
- {
- RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM13, ENABLE);
- RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM13, DISABLE);
- }
- else
- {
- if (TIMx == TIM14)
- {
- RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM14, ENABLE);
- RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM14, DISABLE);
- }
- }
-}
-
-/**
- * @brief Initializes the TIMx Time Base Unit peripheral according to
- * the specified parameters in the TIM_TimeBaseInitStruct.
- * @param TIMx: where x can be 1 to 14 to select the TIM peripheral.
- * @param TIM_TimeBaseInitStruct: pointer to a TIM_TimeBaseInitTypeDef structure
- * that contains the configuration information for the specified TIM peripheral.
- * @retval None
- */
-void TIM_TimeBaseInit(TIM_TypeDef* TIMx, TIM_TimeBaseInitTypeDef* TIM_TimeBaseInitStruct)
-{
- uint16_t tmpcr1 = 0;
-
- /* Check the parameters */
- assert_param(IS_TIM_ALL_PERIPH(TIMx));
- assert_param(IS_TIM_COUNTER_MODE(TIM_TimeBaseInitStruct->TIM_CounterMode));
- assert_param(IS_TIM_CKD_DIV(TIM_TimeBaseInitStruct->TIM_ClockDivision));
-
- tmpcr1 = TIMx->CR1;
-
- if((TIMx == TIM1) || (TIMx == TIM8)||
- (TIMx == TIM2) || (TIMx == TIM3)||
- (TIMx == TIM4) || (TIMx == TIM5))
- {
- /* Select the Counter Mode */
- tmpcr1 &= (uint16_t)(~(TIM_CR1_DIR | TIM_CR1_CMS));
- tmpcr1 |= (uint32_t)TIM_TimeBaseInitStruct->TIM_CounterMode;
- }
-
- if((TIMx != TIM6) && (TIMx != TIM7))
- {
- /* Set the clock division */
- tmpcr1 &= (uint16_t)(~TIM_CR1_CKD);
- tmpcr1 |= (uint32_t)TIM_TimeBaseInitStruct->TIM_ClockDivision;
- }
-
- TIMx->CR1 = tmpcr1;
-
- /* Set the Autoreload value */
- TIMx->ARR = TIM_TimeBaseInitStruct->TIM_Period ;
-
- /* Set the Prescaler value */
- TIMx->PSC = TIM_TimeBaseInitStruct->TIM_Prescaler;
-
- if ((TIMx == TIM1) || (TIMx == TIM8))
- {
- /* Set the Repetition Counter value */
- TIMx->RCR = TIM_TimeBaseInitStruct->TIM_RepetitionCounter;
- }
-
- /* Generate an update event to reload the Prescaler
- and the repetition counter(only for TIM1 and TIM8) value immediatly */
- TIMx->EGR = TIM_PSCReloadMode_Immediate;
-}
-
-/**
- * @brief Fills each TIM_TimeBaseInitStruct member with its default value.
- * @param TIM_TimeBaseInitStruct : pointer to a TIM_TimeBaseInitTypeDef
- * structure which will be initialized.
- * @retval None
- */
-void TIM_TimeBaseStructInit(TIM_TimeBaseInitTypeDef* TIM_TimeBaseInitStruct)
-{
- /* Set the default configuration */
- TIM_TimeBaseInitStruct->TIM_Period = 0xFFFFFFFF;
- TIM_TimeBaseInitStruct->TIM_Prescaler = 0x0000;
- TIM_TimeBaseInitStruct->TIM_ClockDivision = TIM_CKD_DIV1;
- TIM_TimeBaseInitStruct->TIM_CounterMode = TIM_CounterMode_Up;
- TIM_TimeBaseInitStruct->TIM_RepetitionCounter = 0x0000;
-}
-
-/**
- * @brief Configures the TIMx Prescaler.
- * @param TIMx: where x can be 1 to 14 to select the TIM peripheral.
- * @param Prescaler: specifies the Prescaler Register value
- * @param TIM_PSCReloadMode: specifies the TIM Prescaler Reload mode
- * This parameter can be one of the following values:
- * @arg TIM_PSCReloadMode_Update: The Prescaler is loaded at the update event.
- * @arg TIM_PSCReloadMode_Immediate: The Prescaler is loaded immediatly.
- * @retval None
- */
-void TIM_PrescalerConfig(TIM_TypeDef* TIMx, uint16_t Prescaler, uint16_t TIM_PSCReloadMode)
-{
- /* Check the parameters */
- assert_param(IS_TIM_ALL_PERIPH(TIMx));
- assert_param(IS_TIM_PRESCALER_RELOAD(TIM_PSCReloadMode));
- /* Set the Prescaler value */
- TIMx->PSC = Prescaler;
- /* Set or reset the UG Bit */
- TIMx->EGR = TIM_PSCReloadMode;
-}
-
-/**
- * @brief Specifies the TIMx Counter Mode to be used.
- * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
- * @param TIM_CounterMode: specifies the Counter Mode to be used
- * This parameter can be one of the following values:
- * @arg TIM_CounterMode_Up: TIM Up Counting Mode
- * @arg TIM_CounterMode_Down: TIM Down Counting Mode
- * @arg TIM_CounterMode_CenterAligned1: TIM Center Aligned Mode1
- * @arg TIM_CounterMode_CenterAligned2: TIM Center Aligned Mode2
- * @arg TIM_CounterMode_CenterAligned3: TIM Center Aligned Mode3
- * @retval None
- */
-void TIM_CounterModeConfig(TIM_TypeDef* TIMx, uint16_t TIM_CounterMode)
-{
- uint16_t tmpcr1 = 0;
-
- /* Check the parameters */
- assert_param(IS_TIM_LIST3_PERIPH(TIMx));
- assert_param(IS_TIM_COUNTER_MODE(TIM_CounterMode));
-
- tmpcr1 = TIMx->CR1;
-
- /* Reset the CMS and DIR Bits */
- tmpcr1 &= (uint16_t)~(TIM_CR1_DIR | TIM_CR1_CMS);
-
- /* Set the Counter Mode */
- tmpcr1 |= TIM_CounterMode;
-
- /* Write to TIMx CR1 register */
- TIMx->CR1 = tmpcr1;
-}
-
-/**
- * @brief Sets the TIMx Counter Register value
- * @param TIMx: where x can be 1 to 14 to select the TIM peripheral.
- * @param Counter: specifies the Counter register new value.
- * @retval None
- */
-void TIM_SetCounter(TIM_TypeDef* TIMx, uint32_t Counter)
-{
- /* Check the parameters */
- assert_param(IS_TIM_ALL_PERIPH(TIMx));
-
- /* Set the Counter Register value */
- TIMx->CNT = Counter;
-}
-
-/**
- * @brief Sets the TIMx Autoreload Register value
- * @param TIMx: where x can be 1 to 14 to select the TIM peripheral.
- * @param Autoreload: specifies the Autoreload register new value.
- * @retval None
- */
-void TIM_SetAutoreload(TIM_TypeDef* TIMx, uint32_t Autoreload)
-{
- /* Check the parameters */
- assert_param(IS_TIM_ALL_PERIPH(TIMx));
-
- /* Set the Autoreload Register value */
- TIMx->ARR = Autoreload;
-}
-
-/**
- * @brief Gets the TIMx Counter value.
- * @param TIMx: where x can be 1 to 14 to select the TIM peripheral.
- * @retval Counter Register value
- */
-uint32_t TIM_GetCounter(TIM_TypeDef* TIMx)
-{
- /* Check the parameters */
- assert_param(IS_TIM_ALL_PERIPH(TIMx));
-
- /* Get the Counter Register value */
- return TIMx->CNT;
-}
-
-/**
- * @brief Gets the TIMx Prescaler value.
- * @param TIMx: where x can be 1 to 14 to select the TIM peripheral.
- * @retval Prescaler Register value.
- */
-uint16_t TIM_GetPrescaler(TIM_TypeDef* TIMx)
-{
- /* Check the parameters */
- assert_param(IS_TIM_ALL_PERIPH(TIMx));
-
- /* Get the Prescaler Register value */
- return TIMx->PSC;
-}
-
-/**
- * @brief Enables or Disables the TIMx Update event.
- * @param TIMx: where x can be 1 to 14 to select the TIM peripheral.
- * @param NewState: new state of the TIMx UDIS bit
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void TIM_UpdateDisableConfig(TIM_TypeDef* TIMx, FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_TIM_ALL_PERIPH(TIMx));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- if (NewState != DISABLE)
- {
- /* Set the Update Disable Bit */
- TIMx->CR1 |= TIM_CR1_UDIS;
- }
- else
- {
- /* Reset the Update Disable Bit */
- TIMx->CR1 &= (uint16_t)~TIM_CR1_UDIS;
- }
-}
-
-/**
- * @brief Configures the TIMx Update Request Interrupt source.
- * @param TIMx: where x can be 1 to 14 to select the TIM peripheral.
- * @param TIM_UpdateSource: specifies the Update source.
- * This parameter can be one of the following values:
- * @arg TIM_UpdateSource_Global: Source of update is the counter
- * overflow/underflow or the setting of UG bit, or an update
- * generation through the slave mode controller.
- * @arg TIM_UpdateSource_Regular: Source of update is counter overflow/underflow.
- * @retval None
- */
-void TIM_UpdateRequestConfig(TIM_TypeDef* TIMx, uint16_t TIM_UpdateSource)
-{
- /* Check the parameters */
- assert_param(IS_TIM_ALL_PERIPH(TIMx));
- assert_param(IS_TIM_UPDATE_SOURCE(TIM_UpdateSource));
-
- if (TIM_UpdateSource != TIM_UpdateSource_Global)
- {
- /* Set the URS Bit */
- TIMx->CR1 |= TIM_CR1_URS;
- }
- else
- {
- /* Reset the URS Bit */
- TIMx->CR1 &= (uint16_t)~TIM_CR1_URS;
- }
-}
-
-/**
- * @brief Enables or disables TIMx peripheral Preload register on ARR.
- * @param TIMx: where x can be 1 to 14 to select the TIM peripheral.
- * @param NewState: new state of the TIMx peripheral Preload register
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void TIM_ARRPreloadConfig(TIM_TypeDef* TIMx, FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_TIM_ALL_PERIPH(TIMx));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- if (NewState != DISABLE)
- {
- /* Set the ARR Preload Bit */
- TIMx->CR1 |= TIM_CR1_ARPE;
- }
- else
- {
- /* Reset the ARR Preload Bit */
- TIMx->CR1 &= (uint16_t)~TIM_CR1_ARPE;
- }
-}
-
-/**
- * @brief Selects the TIMx's One Pulse Mode.
- * @param TIMx: where x can be 1 to 14 to select the TIM peripheral.
- * @param TIM_OPMode: specifies the OPM Mode to be used.
- * This parameter can be one of the following values:
- * @arg TIM_OPMode_Single
- * @arg TIM_OPMode_Repetitive
- * @retval None
- */
-void TIM_SelectOnePulseMode(TIM_TypeDef* TIMx, uint16_t TIM_OPMode)
-{
- /* Check the parameters */
- assert_param(IS_TIM_ALL_PERIPH(TIMx));
- assert_param(IS_TIM_OPM_MODE(TIM_OPMode));
-
- /* Reset the OPM Bit */
- TIMx->CR1 &= (uint16_t)~TIM_CR1_OPM;
-
- /* Configure the OPM Mode */
- TIMx->CR1 |= TIM_OPMode;
-}
-
-/**
- * @brief Sets the TIMx Clock Division value.
- * @param TIMx: where x can be 1 to 14 except 6 and 7, to select the TIM peripheral.
- * @param TIM_CKD: specifies the clock division value.
- * This parameter can be one of the following value:
- * @arg TIM_CKD_DIV1: TDTS = Tck_tim
- * @arg TIM_CKD_DIV2: TDTS = 2*Tck_tim
- * @arg TIM_CKD_DIV4: TDTS = 4*Tck_tim
- * @retval None
- */
-void TIM_SetClockDivision(TIM_TypeDef* TIMx, uint16_t TIM_CKD)
-{
- /* Check the parameters */
- assert_param(IS_TIM_LIST1_PERIPH(TIMx));
- assert_param(IS_TIM_CKD_DIV(TIM_CKD));
-
- /* Reset the CKD Bits */
- TIMx->CR1 &= (uint16_t)(~TIM_CR1_CKD);
-
- /* Set the CKD value */
- TIMx->CR1 |= TIM_CKD;
-}
-
-/**
- * @brief Enables or disables the specified TIM peripheral.
- * @param TIMx: where x can be 1 to 14 to select the TIMx peripheral.
- * @param NewState: new state of the TIMx peripheral.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void TIM_Cmd(TIM_TypeDef* TIMx, FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_TIM_ALL_PERIPH(TIMx));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- if (NewState != DISABLE)
- {
- /* Enable the TIM Counter */
- TIMx->CR1 |= TIM_CR1_CEN;
- }
- else
- {
- /* Disable the TIM Counter */
- TIMx->CR1 &= (uint16_t)~TIM_CR1_CEN;
- }
-}
-/**
- * @}
- */
-
-/** @defgroup TIM_Group2 Output Compare management functions
- * @brief Output Compare management functions
- *
-@verbatim
- ===============================================================================
- Output Compare management functions
- ===============================================================================
-
- ===================================================================
- TIM Driver: how to use it in Output Compare Mode
- ===================================================================
- To use the Timer in Output Compare mode, the following steps are mandatory:
-
- 1. Enable TIM clock using RCC_APBxPeriphClockCmd(RCC_APBxPeriph_TIMx, ENABLE) function
-
- 2. Configure the TIM pins by configuring the corresponding GPIO pins
-
- 2. Configure the Time base unit as described in the first part of this driver,
- if needed, else the Timer will run with the default configuration:
- - Autoreload value = 0xFFFF
- - Prescaler value = 0x0000
- - Counter mode = Up counting
- - Clock Division = TIM_CKD_DIV1
-
- 3. Fill the TIM_OCInitStruct with the desired parameters including:
- - The TIM Output Compare mode: TIM_OCMode
- - TIM Output State: TIM_OutputState
- - TIM Pulse value: TIM_Pulse
- - TIM Output Compare Polarity : TIM_OCPolarity
-
- 4. Call TIM_OCxInit(TIMx, &TIM_OCInitStruct) to configure the desired channel with the
- corresponding configuration
-
- 5. Call the TIM_Cmd(ENABLE) function to enable the TIM counter.
-
- Note1: All other functions can be used separately to modify, if needed,
- a specific feature of the Timer.
-
- Note2: In case of PWM mode, this function is mandatory:
- TIM_OCxPreloadConfig(TIMx, TIM_OCPreload_ENABLE);
-
- Note3: If the corresponding interrupt or DMA request are needed, the user should:
- 1. Enable the NVIC (or the DMA) to use the TIM interrupts (or DMA requests).
- 2. Enable the corresponding interrupt (or DMA request) using the function
- TIM_ITConfig(TIMx, TIM_IT_CCx) (or TIM_DMA_Cmd(TIMx, TIM_DMA_CCx))
-
-@endverbatim
- * @{
- */
-
-/**
- * @brief Initializes the TIMx Channel1 according to the specified parameters in
- * the TIM_OCInitStruct.
- * @param TIMx: where x can be 1 to 14 except 6 and 7, to select the TIM peripheral.
- * @param TIM_OCInitStruct: pointer to a TIM_OCInitTypeDef structure that contains
- * the configuration information for the specified TIM peripheral.
- * @retval None
- */
-void TIM_OC1Init(TIM_TypeDef* TIMx, TIM_OCInitTypeDef* TIM_OCInitStruct)
-{
- uint16_t tmpccmrx = 0, tmpccer = 0, tmpcr2 = 0;
-
- /* Check the parameters */
- assert_param(IS_TIM_LIST1_PERIPH(TIMx));
- assert_param(IS_TIM_OC_MODE(TIM_OCInitStruct->TIM_OCMode));
- assert_param(IS_TIM_OUTPUT_STATE(TIM_OCInitStruct->TIM_OutputState));
- assert_param(IS_TIM_OC_POLARITY(TIM_OCInitStruct->TIM_OCPolarity));
-
- /* Disable the Channel 1: Reset the CC1E Bit */
- TIMx->CCER &= (uint16_t)~TIM_CCER_CC1E;
-
- /* Get the TIMx CCER register value */
- tmpccer = TIMx->CCER;
- /* Get the TIMx CR2 register value */
- tmpcr2 = TIMx->CR2;
-
- /* Get the TIMx CCMR1 register value */
- tmpccmrx = TIMx->CCMR1;
-
- /* Reset the Output Compare Mode Bits */
- tmpccmrx &= (uint16_t)~TIM_CCMR1_OC1M;
- tmpccmrx &= (uint16_t)~TIM_CCMR1_CC1S;
- /* Select the Output Compare Mode */
- tmpccmrx |= TIM_OCInitStruct->TIM_OCMode;
-
- /* Reset the Output Polarity level */
- tmpccer &= (uint16_t)~TIM_CCER_CC1P;
- /* Set the Output Compare Polarity */
- tmpccer |= TIM_OCInitStruct->TIM_OCPolarity;
-
- /* Set the Output State */
- tmpccer |= TIM_OCInitStruct->TIM_OutputState;
-
- if((TIMx == TIM1) || (TIMx == TIM8))
- {
- assert_param(IS_TIM_OUTPUTN_STATE(TIM_OCInitStruct->TIM_OutputNState));
- assert_param(IS_TIM_OCN_POLARITY(TIM_OCInitStruct->TIM_OCNPolarity));
- assert_param(IS_TIM_OCNIDLE_STATE(TIM_OCInitStruct->TIM_OCNIdleState));
- assert_param(IS_TIM_OCIDLE_STATE(TIM_OCInitStruct->TIM_OCIdleState));
-
- /* Reset the Output N Polarity level */
- tmpccer &= (uint16_t)~TIM_CCER_CC1NP;
- /* Set the Output N Polarity */
- tmpccer |= TIM_OCInitStruct->TIM_OCNPolarity;
- /* Reset the Output N State */
- tmpccer &= (uint16_t)~TIM_CCER_CC1NE;
-
- /* Set the Output N State */
- tmpccer |= TIM_OCInitStruct->TIM_OutputNState;
- /* Reset the Output Compare and Output Compare N IDLE State */
- tmpcr2 &= (uint16_t)~TIM_CR2_OIS1;
- tmpcr2 &= (uint16_t)~TIM_CR2_OIS1N;
- /* Set the Output Idle state */
- tmpcr2 |= TIM_OCInitStruct->TIM_OCIdleState;
- /* Set the Output N Idle state */
- tmpcr2 |= TIM_OCInitStruct->TIM_OCNIdleState;
- }
- /* Write to TIMx CR2 */
- TIMx->CR2 = tmpcr2;
-
- /* Write to TIMx CCMR1 */
- TIMx->CCMR1 = tmpccmrx;
-
- /* Set the Capture Compare Register value */
- TIMx->CCR1 = TIM_OCInitStruct->TIM_Pulse;
-
- /* Write to TIMx CCER */
- TIMx->CCER = tmpccer;
-}
-
-/**
- * @brief Initializes the TIMx Channel2 according to the specified parameters
- * in the TIM_OCInitStruct.
- * @param TIMx: where x can be 1, 2, 3, 4, 5, 8, 9 or 12 to select the TIM
- * peripheral.
- * @param TIM_OCInitStruct: pointer to a TIM_OCInitTypeDef structure that contains
- * the configuration information for the specified TIM peripheral.
- * @retval None
- */
-void TIM_OC2Init(TIM_TypeDef* TIMx, TIM_OCInitTypeDef* TIM_OCInitStruct)
-{
- uint16_t tmpccmrx = 0, tmpccer = 0, tmpcr2 = 0;
-
- /* Check the parameters */
- assert_param(IS_TIM_LIST2_PERIPH(TIMx));
- assert_param(IS_TIM_OC_MODE(TIM_OCInitStruct->TIM_OCMode));
- assert_param(IS_TIM_OUTPUT_STATE(TIM_OCInitStruct->TIM_OutputState));
- assert_param(IS_TIM_OC_POLARITY(TIM_OCInitStruct->TIM_OCPolarity));
-
- /* Disable the Channel 2: Reset the CC2E Bit */
- TIMx->CCER &= (uint16_t)~TIM_CCER_CC2E;
-
- /* Get the TIMx CCER register value */
- tmpccer = TIMx->CCER;
- /* Get the TIMx CR2 register value */
- tmpcr2 = TIMx->CR2;
-
- /* Get the TIMx CCMR1 register value */
- tmpccmrx = TIMx->CCMR1;
-
- /* Reset the Output Compare mode and Capture/Compare selection Bits */
- tmpccmrx &= (uint16_t)~TIM_CCMR1_OC2M;
- tmpccmrx &= (uint16_t)~TIM_CCMR1_CC2S;
-
- /* Select the Output Compare Mode */
- tmpccmrx |= (uint16_t)(TIM_OCInitStruct->TIM_OCMode << 8);
-
- /* Reset the Output Polarity level */
- tmpccer &= (uint16_t)~TIM_CCER_CC2P;
- /* Set the Output Compare Polarity */
- tmpccer |= (uint16_t)(TIM_OCInitStruct->TIM_OCPolarity << 4);
-
- /* Set the Output State */
- tmpccer |= (uint16_t)(TIM_OCInitStruct->TIM_OutputState << 4);
-
- if((TIMx == TIM1) || (TIMx == TIM8))
- {
- assert_param(IS_TIM_OUTPUTN_STATE(TIM_OCInitStruct->TIM_OutputNState));
- assert_param(IS_TIM_OCN_POLARITY(TIM_OCInitStruct->TIM_OCNPolarity));
- assert_param(IS_TIM_OCNIDLE_STATE(TIM_OCInitStruct->TIM_OCNIdleState));
- assert_param(IS_TIM_OCIDLE_STATE(TIM_OCInitStruct->TIM_OCIdleState));
-
- /* Reset the Output N Polarity level */
- tmpccer &= (uint16_t)~TIM_CCER_CC2NP;
- /* Set the Output N Polarity */
- tmpccer |= (uint16_t)(TIM_OCInitStruct->TIM_OCNPolarity << 4);
- /* Reset the Output N State */
- tmpccer &= (uint16_t)~TIM_CCER_CC2NE;
-
- /* Set the Output N State */
- tmpccer |= (uint16_t)(TIM_OCInitStruct->TIM_OutputNState << 4);
- /* Reset the Output Compare and Output Compare N IDLE State */
- tmpcr2 &= (uint16_t)~TIM_CR2_OIS2;
- tmpcr2 &= (uint16_t)~TIM_CR2_OIS2N;
- /* Set the Output Idle state */
- tmpcr2 |= (uint16_t)(TIM_OCInitStruct->TIM_OCIdleState << 2);
- /* Set the Output N Idle state */
- tmpcr2 |= (uint16_t)(TIM_OCInitStruct->TIM_OCNIdleState << 2);
- }
- /* Write to TIMx CR2 */
- TIMx->CR2 = tmpcr2;
-
- /* Write to TIMx CCMR1 */
- TIMx->CCMR1 = tmpccmrx;
-
- /* Set the Capture Compare Register value */
- TIMx->CCR2 = TIM_OCInitStruct->TIM_Pulse;
-
- /* Write to TIMx CCER */
- TIMx->CCER = tmpccer;
-}
-
-/**
- * @brief Initializes the TIMx Channel3 according to the specified parameters
- * in the TIM_OCInitStruct.
- * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
- * @param TIM_OCInitStruct: pointer to a TIM_OCInitTypeDef structure that contains
- * the configuration information for the specified TIM peripheral.
- * @retval None
- */
-void TIM_OC3Init(TIM_TypeDef* TIMx, TIM_OCInitTypeDef* TIM_OCInitStruct)
-{
- uint16_t tmpccmrx = 0, tmpccer = 0, tmpcr2 = 0;
-
- /* Check the parameters */
- assert_param(IS_TIM_LIST3_PERIPH(TIMx));
- assert_param(IS_TIM_OC_MODE(TIM_OCInitStruct->TIM_OCMode));
- assert_param(IS_TIM_OUTPUT_STATE(TIM_OCInitStruct->TIM_OutputState));
- assert_param(IS_TIM_OC_POLARITY(TIM_OCInitStruct->TIM_OCPolarity));
-
- /* Disable the Channel 3: Reset the CC2E Bit */
- TIMx->CCER &= (uint16_t)~TIM_CCER_CC3E;
-
- /* Get the TIMx CCER register value */
- tmpccer = TIMx->CCER;
- /* Get the TIMx CR2 register value */
- tmpcr2 = TIMx->CR2;
-
- /* Get the TIMx CCMR2 register value */
- tmpccmrx = TIMx->CCMR2;
-
- /* Reset the Output Compare mode and Capture/Compare selection Bits */
- tmpccmrx &= (uint16_t)~TIM_CCMR2_OC3M;
- tmpccmrx &= (uint16_t)~TIM_CCMR2_CC3S;
- /* Select the Output Compare Mode */
- tmpccmrx |= TIM_OCInitStruct->TIM_OCMode;
-
- /* Reset the Output Polarity level */
- tmpccer &= (uint16_t)~TIM_CCER_CC3P;
- /* Set the Output Compare Polarity */
- tmpccer |= (uint16_t)(TIM_OCInitStruct->TIM_OCPolarity << 8);
-
- /* Set the Output State */
- tmpccer |= (uint16_t)(TIM_OCInitStruct->TIM_OutputState << 8);
-
- if((TIMx == TIM1) || (TIMx == TIM8))
- {
- assert_param(IS_TIM_OUTPUTN_STATE(TIM_OCInitStruct->TIM_OutputNState));
- assert_param(IS_TIM_OCN_POLARITY(TIM_OCInitStruct->TIM_OCNPolarity));
- assert_param(IS_TIM_OCNIDLE_STATE(TIM_OCInitStruct->TIM_OCNIdleState));
- assert_param(IS_TIM_OCIDLE_STATE(TIM_OCInitStruct->TIM_OCIdleState));
-
- /* Reset the Output N Polarity level */
- tmpccer &= (uint16_t)~TIM_CCER_CC3NP;
- /* Set the Output N Polarity */
- tmpccer |= (uint16_t)(TIM_OCInitStruct->TIM_OCNPolarity << 8);
- /* Reset the Output N State */
- tmpccer &= (uint16_t)~TIM_CCER_CC3NE;
-
- /* Set the Output N State */
- tmpccer |= (uint16_t)(TIM_OCInitStruct->TIM_OutputNState << 8);
- /* Reset the Output Compare and Output Compare N IDLE State */
- tmpcr2 &= (uint16_t)~TIM_CR2_OIS3;
- tmpcr2 &= (uint16_t)~TIM_CR2_OIS3N;
- /* Set the Output Idle state */
- tmpcr2 |= (uint16_t)(TIM_OCInitStruct->TIM_OCIdleState << 4);
- /* Set the Output N Idle state */
- tmpcr2 |= (uint16_t)(TIM_OCInitStruct->TIM_OCNIdleState << 4);
- }
- /* Write to TIMx CR2 */
- TIMx->CR2 = tmpcr2;
-
- /* Write to TIMx CCMR2 */
- TIMx->CCMR2 = tmpccmrx;
-
- /* Set the Capture Compare Register value */
- TIMx->CCR3 = TIM_OCInitStruct->TIM_Pulse;
-
- /* Write to TIMx CCER */
- TIMx->CCER = tmpccer;
-}
-
-/**
- * @brief Initializes the TIMx Channel4 according to the specified parameters
- * in the TIM_OCInitStruct.
- * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
- * @param TIM_OCInitStruct: pointer to a TIM_OCInitTypeDef structure that contains
- * the configuration information for the specified TIM peripheral.
- * @retval None
- */
-void TIM_OC4Init(TIM_TypeDef* TIMx, TIM_OCInitTypeDef* TIM_OCInitStruct)
-{
- uint16_t tmpccmrx = 0, tmpccer = 0, tmpcr2 = 0;
-
- /* Check the parameters */
- assert_param(IS_TIM_LIST3_PERIPH(TIMx));
- assert_param(IS_TIM_OC_MODE(TIM_OCInitStruct->TIM_OCMode));
- assert_param(IS_TIM_OUTPUT_STATE(TIM_OCInitStruct->TIM_OutputState));
- assert_param(IS_TIM_OC_POLARITY(TIM_OCInitStruct->TIM_OCPolarity));
-
- /* Disable the Channel 4: Reset the CC4E Bit */
- TIMx->CCER &= (uint16_t)~TIM_CCER_CC4E;
-
- /* Get the TIMx CCER register value */
- tmpccer = TIMx->CCER;
- /* Get the TIMx CR2 register value */
- tmpcr2 = TIMx->CR2;
-
- /* Get the TIMx CCMR2 register value */
- tmpccmrx = TIMx->CCMR2;
-
- /* Reset the Output Compare mode and Capture/Compare selection Bits */
- tmpccmrx &= (uint16_t)~TIM_CCMR2_OC4M;
- tmpccmrx &= (uint16_t)~TIM_CCMR2_CC4S;
-
- /* Select the Output Compare Mode */
- tmpccmrx |= (uint16_t)(TIM_OCInitStruct->TIM_OCMode << 8);
-
- /* Reset the Output Polarity level */
- tmpccer &= (uint16_t)~TIM_CCER_CC4P;
- /* Set the Output Compare Polarity */
- tmpccer |= (uint16_t)(TIM_OCInitStruct->TIM_OCPolarity << 12);
-
- /* Set the Output State */
- tmpccer |= (uint16_t)(TIM_OCInitStruct->TIM_OutputState << 12);
-
- if((TIMx == TIM1) || (TIMx == TIM8))
- {
- assert_param(IS_TIM_OCIDLE_STATE(TIM_OCInitStruct->TIM_OCIdleState));
- /* Reset the Output Compare IDLE State */
- tmpcr2 &=(uint16_t) ~TIM_CR2_OIS4;
- /* Set the Output Idle state */
- tmpcr2 |= (uint16_t)(TIM_OCInitStruct->TIM_OCIdleState << 6);
- }
- /* Write to TIMx CR2 */
- TIMx->CR2 = tmpcr2;
-
- /* Write to TIMx CCMR2 */
- TIMx->CCMR2 = tmpccmrx;
-
- /* Set the Capture Compare Register value */
- TIMx->CCR4 = TIM_OCInitStruct->TIM_Pulse;
-
- /* Write to TIMx CCER */
- TIMx->CCER = tmpccer;
-}
-
-/**
- * @brief Fills each TIM_OCInitStruct member with its default value.
- * @param TIM_OCInitStruct: pointer to a TIM_OCInitTypeDef structure which will
- * be initialized.
- * @retval None
- */
-void TIM_OCStructInit(TIM_OCInitTypeDef* TIM_OCInitStruct)
-{
- /* Set the default configuration */
- TIM_OCInitStruct->TIM_OCMode = TIM_OCMode_Timing;
- TIM_OCInitStruct->TIM_OutputState = TIM_OutputState_Disable;
- TIM_OCInitStruct->TIM_OutputNState = TIM_OutputNState_Disable;
- TIM_OCInitStruct->TIM_Pulse = 0x00000000;
- TIM_OCInitStruct->TIM_OCPolarity = TIM_OCPolarity_High;
- TIM_OCInitStruct->TIM_OCNPolarity = TIM_OCPolarity_High;
- TIM_OCInitStruct->TIM_OCIdleState = TIM_OCIdleState_Reset;
- TIM_OCInitStruct->TIM_OCNIdleState = TIM_OCNIdleState_Reset;
-}
-
-/**
- * @brief Selects the TIM Output Compare Mode.
- * @note This function disables the selected channel before changing the Output
- * Compare Mode. If needed, user has to enable this channel using
- * TIM_CCxCmd() and TIM_CCxNCmd() functions.
- * @param TIMx: where x can be 1 to 14 except 6 and 7, to select the TIM peripheral.
- * @param TIM_Channel: specifies the TIM Channel
- * This parameter can be one of the following values:
- * @arg TIM_Channel_1: TIM Channel 1
- * @arg TIM_Channel_2: TIM Channel 2
- * @arg TIM_Channel_3: TIM Channel 3
- * @arg TIM_Channel_4: TIM Channel 4
- * @param TIM_OCMode: specifies the TIM Output Compare Mode.
- * This parameter can be one of the following values:
- * @arg TIM_OCMode_Timing
- * @arg TIM_OCMode_Active
- * @arg TIM_OCMode_Toggle
- * @arg TIM_OCMode_PWM1
- * @arg TIM_OCMode_PWM2
- * @arg TIM_ForcedAction_Active
- * @arg TIM_ForcedAction_InActive
- * @retval None
- */
-void TIM_SelectOCxM(TIM_TypeDef* TIMx, uint16_t TIM_Channel, uint16_t TIM_OCMode)
-{
- uint32_t tmp = 0;
- uint16_t tmp1 = 0;
-
- /* Check the parameters */
- assert_param(IS_TIM_LIST1_PERIPH(TIMx));
- assert_param(IS_TIM_CHANNEL(TIM_Channel));
- assert_param(IS_TIM_OCM(TIM_OCMode));
-
- tmp = (uint32_t) TIMx;
- tmp += CCMR_OFFSET;
-
- tmp1 = CCER_CCE_SET << (uint16_t)TIM_Channel;
-
- /* Disable the Channel: Reset the CCxE Bit */
- TIMx->CCER &= (uint16_t) ~tmp1;
-
- if((TIM_Channel == TIM_Channel_1) ||(TIM_Channel == TIM_Channel_3))
- {
- tmp += (TIM_Channel>>1);
-
- /* Reset the OCxM bits in the CCMRx register */
- *(__IO uint32_t *) tmp &= CCMR_OC13M_MASK;
-
- /* Configure the OCxM bits in the CCMRx register */
- *(__IO uint32_t *) tmp |= TIM_OCMode;
- }
- else
- {
- tmp += (uint16_t)(TIM_Channel - (uint16_t)4)>> (uint16_t)1;
-
- /* Reset the OCxM bits in the CCMRx register */
- *(__IO uint32_t *) tmp &= CCMR_OC24M_MASK;
-
- /* Configure the OCxM bits in the CCMRx register */
- *(__IO uint32_t *) tmp |= (uint16_t)(TIM_OCMode << 8);
- }
-}
-
-/**
- * @brief Sets the TIMx Capture Compare1 Register value
- * @param TIMx: where x can be 1 to 14 except 6 and 7, to select the TIM peripheral.
- * @param Compare1: specifies the Capture Compare1 register new value.
- * @retval None
- */
-void TIM_SetCompare1(TIM_TypeDef* TIMx, uint32_t Compare1)
-{
- /* Check the parameters */
- assert_param(IS_TIM_LIST1_PERIPH(TIMx));
-
- /* Set the Capture Compare1 Register value */
- TIMx->CCR1 = Compare1;
-}
-
-/**
- * @brief Sets the TIMx Capture Compare2 Register value
- * @param TIMx: where x can be 1, 2, 3, 4, 5, 8, 9 or 12 to select the TIM
- * peripheral.
- * @param Compare2: specifies the Capture Compare2 register new value.
- * @retval None
- */
-void TIM_SetCompare2(TIM_TypeDef* TIMx, uint32_t Compare2)
-{
- /* Check the parameters */
- assert_param(IS_TIM_LIST2_PERIPH(TIMx));
-
- /* Set the Capture Compare2 Register value */
- TIMx->CCR2 = Compare2;
-}
-
-/**
- * @brief Sets the TIMx Capture Compare3 Register value
- * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
- * @param Compare3: specifies the Capture Compare3 register new value.
- * @retval None
- */
-void TIM_SetCompare3(TIM_TypeDef* TIMx, uint32_t Compare3)
-{
- /* Check the parameters */
- assert_param(IS_TIM_LIST3_PERIPH(TIMx));
-
- /* Set the Capture Compare3 Register value */
- TIMx->CCR3 = Compare3;
-}
-
-/**
- * @brief Sets the TIMx Capture Compare4 Register value
- * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
- * @param Compare4: specifies the Capture Compare4 register new value.
- * @retval None
- */
-void TIM_SetCompare4(TIM_TypeDef* TIMx, uint32_t Compare4)
-{
- /* Check the parameters */
- assert_param(IS_TIM_LIST3_PERIPH(TIMx));
-
- /* Set the Capture Compare4 Register value */
- TIMx->CCR4 = Compare4;
-}
-
-/**
- * @brief Forces the TIMx output 1 waveform to active or inactive level.
- * @param TIMx: where x can be 1 to 14 except 6 and 7, to select the TIM peripheral.
- * @param TIM_ForcedAction: specifies the forced Action to be set to the output waveform.
- * This parameter can be one of the following values:
- * @arg TIM_ForcedAction_Active: Force active level on OC1REF
- * @arg TIM_ForcedAction_InActive: Force inactive level on OC1REF.
- * @retval None
- */
-void TIM_ForcedOC1Config(TIM_TypeDef* TIMx, uint16_t TIM_ForcedAction)
-{
- uint16_t tmpccmr1 = 0;
-
- /* Check the parameters */
- assert_param(IS_TIM_LIST1_PERIPH(TIMx));
- assert_param(IS_TIM_FORCED_ACTION(TIM_ForcedAction));
- tmpccmr1 = TIMx->CCMR1;
-
- /* Reset the OC1M Bits */
- tmpccmr1 &= (uint16_t)~TIM_CCMR1_OC1M;
-
- /* Configure The Forced output Mode */
- tmpccmr1 |= TIM_ForcedAction;
-
- /* Write to TIMx CCMR1 register */
- TIMx->CCMR1 = tmpccmr1;
-}
-
-/**
- * @brief Forces the TIMx output 2 waveform to active or inactive level.
- * @param TIMx: where x can be 1, 2, 3, 4, 5, 8, 9 or 12 to select the TIM
- * peripheral.
- * @param TIM_ForcedAction: specifies the forced Action to be set to the output waveform.
- * This parameter can be one of the following values:
- * @arg TIM_ForcedAction_Active: Force active level on OC2REF
- * @arg TIM_ForcedAction_InActive: Force inactive level on OC2REF.
- * @retval None
- */
-void TIM_ForcedOC2Config(TIM_TypeDef* TIMx, uint16_t TIM_ForcedAction)
-{
- uint16_t tmpccmr1 = 0;
-
- /* Check the parameters */
- assert_param(IS_TIM_LIST2_PERIPH(TIMx));
- assert_param(IS_TIM_FORCED_ACTION(TIM_ForcedAction));
- tmpccmr1 = TIMx->CCMR1;
-
- /* Reset the OC2M Bits */
- tmpccmr1 &= (uint16_t)~TIM_CCMR1_OC2M;
-
- /* Configure The Forced output Mode */
- tmpccmr1 |= (uint16_t)(TIM_ForcedAction << 8);
-
- /* Write to TIMx CCMR1 register */
- TIMx->CCMR1 = tmpccmr1;
-}
-
-/**
- * @brief Forces the TIMx output 3 waveform to active or inactive level.
- * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
- * @param TIM_ForcedAction: specifies the forced Action to be set to the output waveform.
- * This parameter can be one of the following values:
- * @arg TIM_ForcedAction_Active: Force active level on OC3REF
- * @arg TIM_ForcedAction_InActive: Force inactive level on OC3REF.
- * @retval None
- */
-void TIM_ForcedOC3Config(TIM_TypeDef* TIMx, uint16_t TIM_ForcedAction)
-{
- uint16_t tmpccmr2 = 0;
-
- /* Check the parameters */
- assert_param(IS_TIM_LIST3_PERIPH(TIMx));
- assert_param(IS_TIM_FORCED_ACTION(TIM_ForcedAction));
-
- tmpccmr2 = TIMx->CCMR2;
-
- /* Reset the OC1M Bits */
- tmpccmr2 &= (uint16_t)~TIM_CCMR2_OC3M;
-
- /* Configure The Forced output Mode */
- tmpccmr2 |= TIM_ForcedAction;
-
- /* Write to TIMx CCMR2 register */
- TIMx->CCMR2 = tmpccmr2;
-}
-
-/**
- * @brief Forces the TIMx output 4 waveform to active or inactive level.
- * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
- * @param TIM_ForcedAction: specifies the forced Action to be set to the output waveform.
- * This parameter can be one of the following values:
- * @arg TIM_ForcedAction_Active: Force active level on OC4REF
- * @arg TIM_ForcedAction_InActive: Force inactive level on OC4REF.
- * @retval None
- */
-void TIM_ForcedOC4Config(TIM_TypeDef* TIMx, uint16_t TIM_ForcedAction)
-{
- uint16_t tmpccmr2 = 0;
-
- /* Check the parameters */
- assert_param(IS_TIM_LIST3_PERIPH(TIMx));
- assert_param(IS_TIM_FORCED_ACTION(TIM_ForcedAction));
- tmpccmr2 = TIMx->CCMR2;
-
- /* Reset the OC2M Bits */
- tmpccmr2 &= (uint16_t)~TIM_CCMR2_OC4M;
-
- /* Configure The Forced output Mode */
- tmpccmr2 |= (uint16_t)(TIM_ForcedAction << 8);
-
- /* Write to TIMx CCMR2 register */
- TIMx->CCMR2 = tmpccmr2;
-}
-
-/**
- * @brief Enables or disables the TIMx peripheral Preload register on CCR1.
- * @param TIMx: where x can be 1 to 14 except 6 and 7, to select the TIM peripheral.
- * @param TIM_OCPreload: new state of the TIMx peripheral Preload register
- * This parameter can be one of the following values:
- * @arg TIM_OCPreload_Enable
- * @arg TIM_OCPreload_Disable
- * @retval None
- */
-void TIM_OC1PreloadConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCPreload)
-{
- uint16_t tmpccmr1 = 0;
-
- /* Check the parameters */
- assert_param(IS_TIM_LIST1_PERIPH(TIMx));
- assert_param(IS_TIM_OCPRELOAD_STATE(TIM_OCPreload));
-
- tmpccmr1 = TIMx->CCMR1;
-
- /* Reset the OC1PE Bit */
- tmpccmr1 &= (uint16_t)(~TIM_CCMR1_OC1PE);
-
- /* Enable or Disable the Output Compare Preload feature */
- tmpccmr1 |= TIM_OCPreload;
-
- /* Write to TIMx CCMR1 register */
- TIMx->CCMR1 = tmpccmr1;
-}
-
-/**
- * @brief Enables or disables the TIMx peripheral Preload register on CCR2.
- * @param TIMx: where x can be 1, 2, 3, 4, 5, 8, 9 or 12 to select the TIM
- * peripheral.
- * @param TIM_OCPreload: new state of the TIMx peripheral Preload register
- * This parameter can be one of the following values:
- * @arg TIM_OCPreload_Enable
- * @arg TIM_OCPreload_Disable
- * @retval None
- */
-void TIM_OC2PreloadConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCPreload)
-{
- uint16_t tmpccmr1 = 0;
-
- /* Check the parameters */
- assert_param(IS_TIM_LIST2_PERIPH(TIMx));
- assert_param(IS_TIM_OCPRELOAD_STATE(TIM_OCPreload));
-
- tmpccmr1 = TIMx->CCMR1;
-
- /* Reset the OC2PE Bit */
- tmpccmr1 &= (uint16_t)(~TIM_CCMR1_OC2PE);
-
- /* Enable or Disable the Output Compare Preload feature */
- tmpccmr1 |= (uint16_t)(TIM_OCPreload << 8);
-
- /* Write to TIMx CCMR1 register */
- TIMx->CCMR1 = tmpccmr1;
-}
-
-/**
- * @brief Enables or disables the TIMx peripheral Preload register on CCR3.
- * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
- * @param TIM_OCPreload: new state of the TIMx peripheral Preload register
- * This parameter can be one of the following values:
- * @arg TIM_OCPreload_Enable
- * @arg TIM_OCPreload_Disable
- * @retval None
- */
-void TIM_OC3PreloadConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCPreload)
-{
- uint16_t tmpccmr2 = 0;
-
- /* Check the parameters */
- assert_param(IS_TIM_LIST3_PERIPH(TIMx));
- assert_param(IS_TIM_OCPRELOAD_STATE(TIM_OCPreload));
-
- tmpccmr2 = TIMx->CCMR2;
-
- /* Reset the OC3PE Bit */
- tmpccmr2 &= (uint16_t)(~TIM_CCMR2_OC3PE);
-
- /* Enable or Disable the Output Compare Preload feature */
- tmpccmr2 |= TIM_OCPreload;
-
- /* Write to TIMx CCMR2 register */
- TIMx->CCMR2 = tmpccmr2;
-}
-
-/**
- * @brief Enables or disables the TIMx peripheral Preload register on CCR4.
- * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
- * @param TIM_OCPreload: new state of the TIMx peripheral Preload register
- * This parameter can be one of the following values:
- * @arg TIM_OCPreload_Enable
- * @arg TIM_OCPreload_Disable
- * @retval None
- */
-void TIM_OC4PreloadConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCPreload)
-{
- uint16_t tmpccmr2 = 0;
-
- /* Check the parameters */
- assert_param(IS_TIM_LIST3_PERIPH(TIMx));
- assert_param(IS_TIM_OCPRELOAD_STATE(TIM_OCPreload));
-
- tmpccmr2 = TIMx->CCMR2;
-
- /* Reset the OC4PE Bit */
- tmpccmr2 &= (uint16_t)(~TIM_CCMR2_OC4PE);
-
- /* Enable or Disable the Output Compare Preload feature */
- tmpccmr2 |= (uint16_t)(TIM_OCPreload << 8);
-
- /* Write to TIMx CCMR2 register */
- TIMx->CCMR2 = tmpccmr2;
-}
-
-/**
- * @brief Configures the TIMx Output Compare 1 Fast feature.
- * @param TIMx: where x can be 1 to 14 except 6 and 7, to select the TIM peripheral.
- * @param TIM_OCFast: new state of the Output Compare Fast Enable Bit.
- * This parameter can be one of the following values:
- * @arg TIM_OCFast_Enable: TIM output compare fast enable
- * @arg TIM_OCFast_Disable: TIM output compare fast disable
- * @retval None
- */
-void TIM_OC1FastConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCFast)
-{
- uint16_t tmpccmr1 = 0;
-
- /* Check the parameters */
- assert_param(IS_TIM_LIST1_PERIPH(TIMx));
- assert_param(IS_TIM_OCFAST_STATE(TIM_OCFast));
-
- /* Get the TIMx CCMR1 register value */
- tmpccmr1 = TIMx->CCMR1;
-
- /* Reset the OC1FE Bit */
- tmpccmr1 &= (uint16_t)~TIM_CCMR1_OC1FE;
-
- /* Enable or Disable the Output Compare Fast Bit */
- tmpccmr1 |= TIM_OCFast;
-
- /* Write to TIMx CCMR1 */
- TIMx->CCMR1 = tmpccmr1;
-}
-
-/**
- * @brief Configures the TIMx Output Compare 2 Fast feature.
- * @param TIMx: where x can be 1, 2, 3, 4, 5, 8, 9 or 12 to select the TIM
- * peripheral.
- * @param TIM_OCFast: new state of the Output Compare Fast Enable Bit.
- * This parameter can be one of the following values:
- * @arg TIM_OCFast_Enable: TIM output compare fast enable
- * @arg TIM_OCFast_Disable: TIM output compare fast disable
- * @retval None
- */
-void TIM_OC2FastConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCFast)
-{
- uint16_t tmpccmr1 = 0;
-
- /* Check the parameters */
- assert_param(IS_TIM_LIST2_PERIPH(TIMx));
- assert_param(IS_TIM_OCFAST_STATE(TIM_OCFast));
-
- /* Get the TIMx CCMR1 register value */
- tmpccmr1 = TIMx->CCMR1;
-
- /* Reset the OC2FE Bit */
- tmpccmr1 &= (uint16_t)(~TIM_CCMR1_OC2FE);
-
- /* Enable or Disable the Output Compare Fast Bit */
- tmpccmr1 |= (uint16_t)(TIM_OCFast << 8);
-
- /* Write to TIMx CCMR1 */
- TIMx->CCMR1 = tmpccmr1;
-}
-
-/**
- * @brief Configures the TIMx Output Compare 3 Fast feature.
- * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
- * @param TIM_OCFast: new state of the Output Compare Fast Enable Bit.
- * This parameter can be one of the following values:
- * @arg TIM_OCFast_Enable: TIM output compare fast enable
- * @arg TIM_OCFast_Disable: TIM output compare fast disable
- * @retval None
- */
-void TIM_OC3FastConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCFast)
-{
- uint16_t tmpccmr2 = 0;
-
- /* Check the parameters */
- assert_param(IS_TIM_LIST3_PERIPH(TIMx));
- assert_param(IS_TIM_OCFAST_STATE(TIM_OCFast));
-
- /* Get the TIMx CCMR2 register value */
- tmpccmr2 = TIMx->CCMR2;
-
- /* Reset the OC3FE Bit */
- tmpccmr2 &= (uint16_t)~TIM_CCMR2_OC3FE;
-
- /* Enable or Disable the Output Compare Fast Bit */
- tmpccmr2 |= TIM_OCFast;
-
- /* Write to TIMx CCMR2 */
- TIMx->CCMR2 = tmpccmr2;
-}
-
-/**
- * @brief Configures the TIMx Output Compare 4 Fast feature.
- * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
- * @param TIM_OCFast: new state of the Output Compare Fast Enable Bit.
- * This parameter can be one of the following values:
- * @arg TIM_OCFast_Enable: TIM output compare fast enable
- * @arg TIM_OCFast_Disable: TIM output compare fast disable
- * @retval None
- */
-void TIM_OC4FastConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCFast)
-{
- uint16_t tmpccmr2 = 0;
-
- /* Check the parameters */
- assert_param(IS_TIM_LIST3_PERIPH(TIMx));
- assert_param(IS_TIM_OCFAST_STATE(TIM_OCFast));
-
- /* Get the TIMx CCMR2 register value */
- tmpccmr2 = TIMx->CCMR2;
-
- /* Reset the OC4FE Bit */
- tmpccmr2 &= (uint16_t)(~TIM_CCMR2_OC4FE);
-
- /* Enable or Disable the Output Compare Fast Bit */
- tmpccmr2 |= (uint16_t)(TIM_OCFast << 8);
-
- /* Write to TIMx CCMR2 */
- TIMx->CCMR2 = tmpccmr2;
-}
-
-/**
- * @brief Clears or safeguards the OCREF1 signal on an external event
- * @param TIMx: where x can be 1 to 14 except 6 and 7, to select the TIM peripheral.
- * @param TIM_OCClear: new state of the Output Compare Clear Enable Bit.
- * This parameter can be one of the following values:
- * @arg TIM_OCClear_Enable: TIM Output clear enable
- * @arg TIM_OCClear_Disable: TIM Output clear disable
- * @retval None
- */
-void TIM_ClearOC1Ref(TIM_TypeDef* TIMx, uint16_t TIM_OCClear)
-{
- uint16_t tmpccmr1 = 0;
-
- /* Check the parameters */
- assert_param(IS_TIM_LIST1_PERIPH(TIMx));
- assert_param(IS_TIM_OCCLEAR_STATE(TIM_OCClear));
-
- tmpccmr1 = TIMx->CCMR1;
-
- /* Reset the OC1CE Bit */
- tmpccmr1 &= (uint16_t)~TIM_CCMR1_OC1CE;
-
- /* Enable or Disable the Output Compare Clear Bit */
- tmpccmr1 |= TIM_OCClear;
-
- /* Write to TIMx CCMR1 register */
- TIMx->CCMR1 = tmpccmr1;
-}
-
-/**
- * @brief Clears or safeguards the OCREF2 signal on an external event
- * @param TIMx: where x can be 1, 2, 3, 4, 5, 8, 9 or 12 to select the TIM
- * peripheral.
- * @param TIM_OCClear: new state of the Output Compare Clear Enable Bit.
- * This parameter can be one of the following values:
- * @arg TIM_OCClear_Enable: TIM Output clear enable
- * @arg TIM_OCClear_Disable: TIM Output clear disable
- * @retval None
- */
-void TIM_ClearOC2Ref(TIM_TypeDef* TIMx, uint16_t TIM_OCClear)
-{
- uint16_t tmpccmr1 = 0;
-
- /* Check the parameters */
- assert_param(IS_TIM_LIST2_PERIPH(TIMx));
- assert_param(IS_TIM_OCCLEAR_STATE(TIM_OCClear));
-
- tmpccmr1 = TIMx->CCMR1;
-
- /* Reset the OC2CE Bit */
- tmpccmr1 &= (uint16_t)~TIM_CCMR1_OC2CE;
-
- /* Enable or Disable the Output Compare Clear Bit */
- tmpccmr1 |= (uint16_t)(TIM_OCClear << 8);
-
- /* Write to TIMx CCMR1 register */
- TIMx->CCMR1 = tmpccmr1;
-}
-
-/**
- * @brief Clears or safeguards the OCREF3 signal on an external event
- * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
- * @param TIM_OCClear: new state of the Output Compare Clear Enable Bit.
- * This parameter can be one of the following values:
- * @arg TIM_OCClear_Enable: TIM Output clear enable
- * @arg TIM_OCClear_Disable: TIM Output clear disable
- * @retval None
- */
-void TIM_ClearOC3Ref(TIM_TypeDef* TIMx, uint16_t TIM_OCClear)
-{
- uint16_t tmpccmr2 = 0;
-
- /* Check the parameters */
- assert_param(IS_TIM_LIST3_PERIPH(TIMx));
- assert_param(IS_TIM_OCCLEAR_STATE(TIM_OCClear));
-
- tmpccmr2 = TIMx->CCMR2;
-
- /* Reset the OC3CE Bit */
- tmpccmr2 &= (uint16_t)~TIM_CCMR2_OC3CE;
-
- /* Enable or Disable the Output Compare Clear Bit */
- tmpccmr2 |= TIM_OCClear;
-
- /* Write to TIMx CCMR2 register */
- TIMx->CCMR2 = tmpccmr2;
-}
-
-/**
- * @brief Clears or safeguards the OCREF4 signal on an external event
- * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
- * @param TIM_OCClear: new state of the Output Compare Clear Enable Bit.
- * This parameter can be one of the following values:
- * @arg TIM_OCClear_Enable: TIM Output clear enable
- * @arg TIM_OCClear_Disable: TIM Output clear disable
- * @retval None
- */
-void TIM_ClearOC4Ref(TIM_TypeDef* TIMx, uint16_t TIM_OCClear)
-{
- uint16_t tmpccmr2 = 0;
-
- /* Check the parameters */
- assert_param(IS_TIM_LIST3_PERIPH(TIMx));
- assert_param(IS_TIM_OCCLEAR_STATE(TIM_OCClear));
-
- tmpccmr2 = TIMx->CCMR2;
-
- /* Reset the OC4CE Bit */
- tmpccmr2 &= (uint16_t)~TIM_CCMR2_OC4CE;
-
- /* Enable or Disable the Output Compare Clear Bit */
- tmpccmr2 |= (uint16_t)(TIM_OCClear << 8);
-
- /* Write to TIMx CCMR2 register */
- TIMx->CCMR2 = tmpccmr2;
-}
-
-/**
- * @brief Configures the TIMx channel 1 polarity.
- * @param TIMx: where x can be 1 to 14 except 6 and 7, to select the TIM peripheral.
- * @param TIM_OCPolarity: specifies the OC1 Polarity
- * This parameter can be one of the following values:
- * @arg TIM_OCPolarity_High: Output Compare active high
- * @arg TIM_OCPolarity_Low: Output Compare active low
- * @retval None
- */
-void TIM_OC1PolarityConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCPolarity)
-{
- uint16_t tmpccer = 0;
-
- /* Check the parameters */
- assert_param(IS_TIM_LIST1_PERIPH(TIMx));
- assert_param(IS_TIM_OC_POLARITY(TIM_OCPolarity));
-
- tmpccer = TIMx->CCER;
-
- /* Set or Reset the CC1P Bit */
- tmpccer &= (uint16_t)(~TIM_CCER_CC1P);
- tmpccer |= TIM_OCPolarity;
-
- /* Write to TIMx CCER register */
- TIMx->CCER = tmpccer;
-}
-
-/**
- * @brief Configures the TIMx Channel 1N polarity.
- * @param TIMx: where x can be 1 or 8 to select the TIM peripheral.
- * @param TIM_OCNPolarity: specifies the OC1N Polarity
- * This parameter can be one of the following values:
- * @arg TIM_OCNPolarity_High: Output Compare active high
- * @arg TIM_OCNPolarity_Low: Output Compare active low
- * @retval None
- */
-void TIM_OC1NPolarityConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCNPolarity)
-{
- uint16_t tmpccer = 0;
- /* Check the parameters */
- assert_param(IS_TIM_LIST4_PERIPH(TIMx));
- assert_param(IS_TIM_OCN_POLARITY(TIM_OCNPolarity));
-
- tmpccer = TIMx->CCER;
-
- /* Set or Reset the CC1NP Bit */
- tmpccer &= (uint16_t)~TIM_CCER_CC1NP;
- tmpccer |= TIM_OCNPolarity;
-
- /* Write to TIMx CCER register */
- TIMx->CCER = tmpccer;
-}
-
-/**
- * @brief Configures the TIMx channel 2 polarity.
- * @param TIMx: where x can be 1, 2, 3, 4, 5, 8, 9 or 12 to select the TIM
- * peripheral.
- * @param TIM_OCPolarity: specifies the OC2 Polarity
- * This parameter can be one of the following values:
- * @arg TIM_OCPolarity_High: Output Compare active high
- * @arg TIM_OCPolarity_Low: Output Compare active low
- * @retval None
- */
-void TIM_OC2PolarityConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCPolarity)
-{
- uint16_t tmpccer = 0;
-
- /* Check the parameters */
- assert_param(IS_TIM_LIST2_PERIPH(TIMx));
- assert_param(IS_TIM_OC_POLARITY(TIM_OCPolarity));
-
- tmpccer = TIMx->CCER;
-
- /* Set or Reset the CC2P Bit */
- tmpccer &= (uint16_t)(~TIM_CCER_CC2P);
- tmpccer |= (uint16_t)(TIM_OCPolarity << 4);
-
- /* Write to TIMx CCER register */
- TIMx->CCER = tmpccer;
-}
-
-/**
- * @brief Configures the TIMx Channel 2N polarity.
- * @param TIMx: where x can be 1 or 8 to select the TIM peripheral.
- * @param TIM_OCNPolarity: specifies the OC2N Polarity
- * This parameter can be one of the following values:
- * @arg TIM_OCNPolarity_High: Output Compare active high
- * @arg TIM_OCNPolarity_Low: Output Compare active low
- * @retval None
- */
-void TIM_OC2NPolarityConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCNPolarity)
-{
- uint16_t tmpccer = 0;
-
- /* Check the parameters */
- assert_param(IS_TIM_LIST4_PERIPH(TIMx));
- assert_param(IS_TIM_OCN_POLARITY(TIM_OCNPolarity));
-
- tmpccer = TIMx->CCER;
-
- /* Set or Reset the CC2NP Bit */
- tmpccer &= (uint16_t)~TIM_CCER_CC2NP;
- tmpccer |= (uint16_t)(TIM_OCNPolarity << 4);
-
- /* Write to TIMx CCER register */
- TIMx->CCER = tmpccer;
-}
-
-/**
- * @brief Configures the TIMx channel 3 polarity.
- * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
- * @param TIM_OCPolarity: specifies the OC3 Polarity
- * This parameter can be one of the following values:
- * @arg TIM_OCPolarity_High: Output Compare active high
- * @arg TIM_OCPolarity_Low: Output Compare active low
- * @retval None
- */
-void TIM_OC3PolarityConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCPolarity)
-{
- uint16_t tmpccer = 0;
-
- /* Check the parameters */
- assert_param(IS_TIM_LIST3_PERIPH(TIMx));
- assert_param(IS_TIM_OC_POLARITY(TIM_OCPolarity));
-
- tmpccer = TIMx->CCER;
-
- /* Set or Reset the CC3P Bit */
- tmpccer &= (uint16_t)~TIM_CCER_CC3P;
- tmpccer |= (uint16_t)(TIM_OCPolarity << 8);
-
- /* Write to TIMx CCER register */
- TIMx->CCER = tmpccer;
-}
-
-/**
- * @brief Configures the TIMx Channel 3N polarity.
- * @param TIMx: where x can be 1 or 8 to select the TIM peripheral.
- * @param TIM_OCNPolarity: specifies the OC3N Polarity
- * This parameter can be one of the following values:
- * @arg TIM_OCNPolarity_High: Output Compare active high
- * @arg TIM_OCNPolarity_Low: Output Compare active low
- * @retval None
- */
-void TIM_OC3NPolarityConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCNPolarity)
-{
- uint16_t tmpccer = 0;
-
- /* Check the parameters */
- assert_param(IS_TIM_LIST4_PERIPH(TIMx));
- assert_param(IS_TIM_OCN_POLARITY(TIM_OCNPolarity));
-
- tmpccer = TIMx->CCER;
-
- /* Set or Reset the CC3NP Bit */
- tmpccer &= (uint16_t)~TIM_CCER_CC3NP;
- tmpccer |= (uint16_t)(TIM_OCNPolarity << 8);
-
- /* Write to TIMx CCER register */
- TIMx->CCER = tmpccer;
-}
-
-/**
- * @brief Configures the TIMx channel 4 polarity.
- * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
- * @param TIM_OCPolarity: specifies the OC4 Polarity
- * This parameter can be one of the following values:
- * @arg TIM_OCPolarity_High: Output Compare active high
- * @arg TIM_OCPolarity_Low: Output Compare active low
- * @retval None
- */
-void TIM_OC4PolarityConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCPolarity)
-{
- uint16_t tmpccer = 0;
-
- /* Check the parameters */
- assert_param(IS_TIM_LIST3_PERIPH(TIMx));
- assert_param(IS_TIM_OC_POLARITY(TIM_OCPolarity));
-
- tmpccer = TIMx->CCER;
-
- /* Set or Reset the CC4P Bit */
- tmpccer &= (uint16_t)~TIM_CCER_CC4P;
- tmpccer |= (uint16_t)(TIM_OCPolarity << 12);
-
- /* Write to TIMx CCER register */
- TIMx->CCER = tmpccer;
-}
-
-/**
- * @brief Enables or disables the TIM Capture Compare Channel x.
- * @param TIMx: where x can be 1 to 14 except 6 and 7, to select the TIM peripheral.
- * @param TIM_Channel: specifies the TIM Channel
- * This parameter can be one of the following values:
- * @arg TIM_Channel_1: TIM Channel 1
- * @arg TIM_Channel_2: TIM Channel 2
- * @arg TIM_Channel_3: TIM Channel 3
- * @arg TIM_Channel_4: TIM Channel 4
- * @param TIM_CCx: specifies the TIM Channel CCxE bit new state.
- * This parameter can be: TIM_CCx_Enable or TIM_CCx_Disable.
- * @retval None
- */
-void TIM_CCxCmd(TIM_TypeDef* TIMx, uint16_t TIM_Channel, uint16_t TIM_CCx)
-{
- uint16_t tmp = 0;
-
- /* Check the parameters */
- assert_param(IS_TIM_LIST1_PERIPH(TIMx));
- assert_param(IS_TIM_CHANNEL(TIM_Channel));
- assert_param(IS_TIM_CCX(TIM_CCx));
-
- tmp = CCER_CCE_SET << TIM_Channel;
-
- /* Reset the CCxE Bit */
- TIMx->CCER &= (uint16_t)~ tmp;
-
- /* Set or reset the CCxE Bit */
- TIMx->CCER |= (uint16_t)(TIM_CCx << TIM_Channel);
-}
-
-/**
- * @brief Enables or disables the TIM Capture Compare Channel xN.
- * @param TIMx: where x can be 1 or 8 to select the TIM peripheral.
- * @param TIM_Channel: specifies the TIM Channel
- * This parameter can be one of the following values:
- * @arg TIM_Channel_1: TIM Channel 1
- * @arg TIM_Channel_2: TIM Channel 2
- * @arg TIM_Channel_3: TIM Channel 3
- * @param TIM_CCxN: specifies the TIM Channel CCxNE bit new state.
- * This parameter can be: TIM_CCxN_Enable or TIM_CCxN_Disable.
- * @retval None
- */
-void TIM_CCxNCmd(TIM_TypeDef* TIMx, uint16_t TIM_Channel, uint16_t TIM_CCxN)
-{
- uint16_t tmp = 0;
-
- /* Check the parameters */
- assert_param(IS_TIM_LIST4_PERIPH(TIMx));
- assert_param(IS_TIM_COMPLEMENTARY_CHANNEL(TIM_Channel));
- assert_param(IS_TIM_CCXN(TIM_CCxN));
-
- tmp = CCER_CCNE_SET << TIM_Channel;
-
- /* Reset the CCxNE Bit */
- TIMx->CCER &= (uint16_t) ~tmp;
-
- /* Set or reset the CCxNE Bit */
- TIMx->CCER |= (uint16_t)(TIM_CCxN << TIM_Channel);
-}
-/**
- * @}
- */
-
-/** @defgroup TIM_Group3 Input Capture management functions
- * @brief Input Capture management functions
- *
-@verbatim
- ===============================================================================
- Input Capture management functions
- ===============================================================================
-
- ===================================================================
- TIM Driver: how to use it in Input Capture Mode
- ===================================================================
- To use the Timer in Input Capture mode, the following steps are mandatory:
-
- 1. Enable TIM clock using RCC_APBxPeriphClockCmd(RCC_APBxPeriph_TIMx, ENABLE) function
-
- 2. Configure the TIM pins by configuring the corresponding GPIO pins
-
- 2. Configure the Time base unit as described in the first part of this driver,
- if needed, else the Timer will run with the default configuration:
- - Autoreload value = 0xFFFF
- - Prescaler value = 0x0000
- - Counter mode = Up counting
- - Clock Division = TIM_CKD_DIV1
-
- 3. Fill the TIM_ICInitStruct with the desired parameters including:
- - TIM Channel: TIM_Channel
- - TIM Input Capture polarity: TIM_ICPolarity
- - TIM Input Capture selection: TIM_ICSelection
- - TIM Input Capture Prescaler: TIM_ICPrescaler
- - TIM Input CApture filter value: TIM_ICFilter
-
- 4. Call TIM_ICInit(TIMx, &TIM_ICInitStruct) to configure the desired channel with the
- corresponding configuration and to measure only frequency or duty cycle of the input signal,
- or,
- Call TIM_PWMIConfig(TIMx, &TIM_ICInitStruct) to configure the desired channels with the
- corresponding configuration and to measure the frequency and the duty cycle of the input signal
-
- 5. Enable the NVIC or the DMA to read the measured frequency.
-
- 6. Enable the corresponding interrupt (or DMA request) to read the Captured value,
- using the function TIM_ITConfig(TIMx, TIM_IT_CCx) (or TIM_DMA_Cmd(TIMx, TIM_DMA_CCx))
-
- 7. Call the TIM_Cmd(ENABLE) function to enable the TIM counter.
-
- 8. Use TIM_GetCapturex(TIMx); to read the captured value.
-
- Note1: All other functions can be used separately to modify, if needed,
- a specific feature of the Timer.
-
-@endverbatim
- * @{
- */
-
-/**
- * @brief Initializes the TIM peripheral according to the specified parameters
- * in the TIM_ICInitStruct.
- * @param TIMx: where x can be 1 to 14 except 6 and 7, to select the TIM peripheral.
- * @param TIM_ICInitStruct: pointer to a TIM_ICInitTypeDef structure that contains
- * the configuration information for the specified TIM peripheral.
- * @retval None
- */
-void TIM_ICInit(TIM_TypeDef* TIMx, TIM_ICInitTypeDef* TIM_ICInitStruct)
-{
- /* Check the parameters */
- assert_param(IS_TIM_LIST1_PERIPH(TIMx));
- assert_param(IS_TIM_IC_POLARITY(TIM_ICInitStruct->TIM_ICPolarity));
- assert_param(IS_TIM_IC_SELECTION(TIM_ICInitStruct->TIM_ICSelection));
- assert_param(IS_TIM_IC_PRESCALER(TIM_ICInitStruct->TIM_ICPrescaler));
- assert_param(IS_TIM_IC_FILTER(TIM_ICInitStruct->TIM_ICFilter));
-
- if (TIM_ICInitStruct->TIM_Channel == TIM_Channel_1)
- {
- /* TI1 Configuration */
- TI1_Config(TIMx, TIM_ICInitStruct->TIM_ICPolarity,
- TIM_ICInitStruct->TIM_ICSelection,
- TIM_ICInitStruct->TIM_ICFilter);
- /* Set the Input Capture Prescaler value */
- TIM_SetIC1Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler);
- }
- else if (TIM_ICInitStruct->TIM_Channel == TIM_Channel_2)
- {
- /* TI2 Configuration */
- assert_param(IS_TIM_LIST2_PERIPH(TIMx));
- TI2_Config(TIMx, TIM_ICInitStruct->TIM_ICPolarity,
- TIM_ICInitStruct->TIM_ICSelection,
- TIM_ICInitStruct->TIM_ICFilter);
- /* Set the Input Capture Prescaler value */
- TIM_SetIC2Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler);
- }
- else if (TIM_ICInitStruct->TIM_Channel == TIM_Channel_3)
- {
- /* TI3 Configuration */
- assert_param(IS_TIM_LIST3_PERIPH(TIMx));
- TI3_Config(TIMx, TIM_ICInitStruct->TIM_ICPolarity,
- TIM_ICInitStruct->TIM_ICSelection,
- TIM_ICInitStruct->TIM_ICFilter);
- /* Set the Input Capture Prescaler value */
- TIM_SetIC3Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler);
- }
- else
- {
- /* TI4 Configuration */
- assert_param(IS_TIM_LIST3_PERIPH(TIMx));
- TI4_Config(TIMx, TIM_ICInitStruct->TIM_ICPolarity,
- TIM_ICInitStruct->TIM_ICSelection,
- TIM_ICInitStruct->TIM_ICFilter);
- /* Set the Input Capture Prescaler value */
- TIM_SetIC4Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler);
- }
-}
-
-/**
- * @brief Fills each TIM_ICInitStruct member with its default value.
- * @param TIM_ICInitStruct: pointer to a TIM_ICInitTypeDef structure which will
- * be initialized.
- * @retval None
- */
-void TIM_ICStructInit(TIM_ICInitTypeDef* TIM_ICInitStruct)
-{
- /* Set the default configuration */
- TIM_ICInitStruct->TIM_Channel = TIM_Channel_1;
- TIM_ICInitStruct->TIM_ICPolarity = TIM_ICPolarity_Rising;
- TIM_ICInitStruct->TIM_ICSelection = TIM_ICSelection_DirectTI;
- TIM_ICInitStruct->TIM_ICPrescaler = TIM_ICPSC_DIV1;
- TIM_ICInitStruct->TIM_ICFilter = 0x00;
-}
-
-/**
- * @brief Configures the TIM peripheral according to the specified parameters
- * in the TIM_ICInitStruct to measure an external PWM signal.
- * @param TIMx: where x can be 1, 2, 3, 4, 5,8, 9 or 12 to select the TIM
- * peripheral.
- * @param TIM_ICInitStruct: pointer to a TIM_ICInitTypeDef structure that contains
- * the configuration information for the specified TIM peripheral.
- * @retval None
- */
-void TIM_PWMIConfig(TIM_TypeDef* TIMx, TIM_ICInitTypeDef* TIM_ICInitStruct)
-{
- uint16_t icoppositepolarity = TIM_ICPolarity_Rising;
- uint16_t icoppositeselection = TIM_ICSelection_DirectTI;
-
- /* Check the parameters */
- assert_param(IS_TIM_LIST2_PERIPH(TIMx));
-
- /* Select the Opposite Input Polarity */
- if (TIM_ICInitStruct->TIM_ICPolarity == TIM_ICPolarity_Rising)
- {
- icoppositepolarity = TIM_ICPolarity_Falling;
- }
- else
- {
- icoppositepolarity = TIM_ICPolarity_Rising;
- }
- /* Select the Opposite Input */
- if (TIM_ICInitStruct->TIM_ICSelection == TIM_ICSelection_DirectTI)
- {
- icoppositeselection = TIM_ICSelection_IndirectTI;
- }
- else
- {
- icoppositeselection = TIM_ICSelection_DirectTI;
- }
- if (TIM_ICInitStruct->TIM_Channel == TIM_Channel_1)
- {
- /* TI1 Configuration */
- TI1_Config(TIMx, TIM_ICInitStruct->TIM_ICPolarity, TIM_ICInitStruct->TIM_ICSelection,
- TIM_ICInitStruct->TIM_ICFilter);
- /* Set the Input Capture Prescaler value */
- TIM_SetIC1Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler);
- /* TI2 Configuration */
- TI2_Config(TIMx, icoppositepolarity, icoppositeselection, TIM_ICInitStruct->TIM_ICFilter);
- /* Set the Input Capture Prescaler value */
- TIM_SetIC2Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler);
- }
- else
- {
- /* TI2 Configuration */
- TI2_Config(TIMx, TIM_ICInitStruct->TIM_ICPolarity, TIM_ICInitStruct->TIM_ICSelection,
- TIM_ICInitStruct->TIM_ICFilter);
- /* Set the Input Capture Prescaler value */
- TIM_SetIC2Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler);
- /* TI1 Configuration */
- TI1_Config(TIMx, icoppositepolarity, icoppositeselection, TIM_ICInitStruct->TIM_ICFilter);
- /* Set the Input Capture Prescaler value */
- TIM_SetIC1Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler);
- }
-}
-
-/**
- * @brief Gets the TIMx Input Capture 1 value.
- * @param TIMx: where x can be 1 to 14 except 6 and 7, to select the TIM peripheral.
- * @retval Capture Compare 1 Register value.
- */
-uint32_t TIM_GetCapture1(TIM_TypeDef* TIMx)
-{
- /* Check the parameters */
- assert_param(IS_TIM_LIST1_PERIPH(TIMx));
-
- /* Get the Capture 1 Register value */
- return TIMx->CCR1;
-}
-
-/**
- * @brief Gets the TIMx Input Capture 2 value.
- * @param TIMx: where x can be 1, 2, 3, 4, 5, 8, 9 or 12 to select the TIM
- * peripheral.
- * @retval Capture Compare 2 Register value.
- */
-uint32_t TIM_GetCapture2(TIM_TypeDef* TIMx)
-{
- /* Check the parameters */
- assert_param(IS_TIM_LIST2_PERIPH(TIMx));
-
- /* Get the Capture 2 Register value */
- return TIMx->CCR2;
-}
-
-/**
- * @brief Gets the TIMx Input Capture 3 value.
- * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
- * @retval Capture Compare 3 Register value.
- */
-uint32_t TIM_GetCapture3(TIM_TypeDef* TIMx)
-{
- /* Check the parameters */
- assert_param(IS_TIM_LIST3_PERIPH(TIMx));
-
- /* Get the Capture 3 Register value */
- return TIMx->CCR3;
-}
-
-/**
- * @brief Gets the TIMx Input Capture 4 value.
- * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
- * @retval Capture Compare 4 Register value.
- */
-uint32_t TIM_GetCapture4(TIM_TypeDef* TIMx)
-{
- /* Check the parameters */
- assert_param(IS_TIM_LIST3_PERIPH(TIMx));
-
- /* Get the Capture 4 Register value */
- return TIMx->CCR4;
-}
-
-/**
- * @brief Sets the TIMx Input Capture 1 prescaler.
- * @param TIMx: where x can be 1 to 14 except 6 and 7, to select the TIM peripheral.
- * @param TIM_ICPSC: specifies the Input Capture1 prescaler new value.
- * This parameter can be one of the following values:
- * @arg TIM_ICPSC_DIV1: no prescaler
- * @arg TIM_ICPSC_DIV2: capture is done once every 2 events
- * @arg TIM_ICPSC_DIV4: capture is done once every 4 events
- * @arg TIM_ICPSC_DIV8: capture is done once every 8 events
- * @retval None
- */
-void TIM_SetIC1Prescaler(TIM_TypeDef* TIMx, uint16_t TIM_ICPSC)
-{
- /* Check the parameters */
- assert_param(IS_TIM_LIST1_PERIPH(TIMx));
- assert_param(IS_TIM_IC_PRESCALER(TIM_ICPSC));
-
- /* Reset the IC1PSC Bits */
- TIMx->CCMR1 &= (uint16_t)~TIM_CCMR1_IC1PSC;
-
- /* Set the IC1PSC value */
- TIMx->CCMR1 |= TIM_ICPSC;
-}
-
-/**
- * @brief Sets the TIMx Input Capture 2 prescaler.
- * @param TIMx: where x can be 1, 2, 3, 4, 5, 8, 9 or 12 to select the TIM
- * peripheral.
- * @param TIM_ICPSC: specifies the Input Capture2 prescaler new value.
- * This parameter can be one of the following values:
- * @arg TIM_ICPSC_DIV1: no prescaler
- * @arg TIM_ICPSC_DIV2: capture is done once every 2 events
- * @arg TIM_ICPSC_DIV4: capture is done once every 4 events
- * @arg TIM_ICPSC_DIV8: capture is done once every 8 events
- * @retval None
- */
-void TIM_SetIC2Prescaler(TIM_TypeDef* TIMx, uint16_t TIM_ICPSC)
-{
- /* Check the parameters */
- assert_param(IS_TIM_LIST2_PERIPH(TIMx));
- assert_param(IS_TIM_IC_PRESCALER(TIM_ICPSC));
-
- /* Reset the IC2PSC Bits */
- TIMx->CCMR1 &= (uint16_t)~TIM_CCMR1_IC2PSC;
-
- /* Set the IC2PSC value */
- TIMx->CCMR1 |= (uint16_t)(TIM_ICPSC << 8);
-}
-
-/**
- * @brief Sets the TIMx Input Capture 3 prescaler.
- * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
- * @param TIM_ICPSC: specifies the Input Capture3 prescaler new value.
- * This parameter can be one of the following values:
- * @arg TIM_ICPSC_DIV1: no prescaler
- * @arg TIM_ICPSC_DIV2: capture is done once every 2 events
- * @arg TIM_ICPSC_DIV4: capture is done once every 4 events
- * @arg TIM_ICPSC_DIV8: capture is done once every 8 events
- * @retval None
- */
-void TIM_SetIC3Prescaler(TIM_TypeDef* TIMx, uint16_t TIM_ICPSC)
-{
- /* Check the parameters */
- assert_param(IS_TIM_LIST3_PERIPH(TIMx));
- assert_param(IS_TIM_IC_PRESCALER(TIM_ICPSC));
-
- /* Reset the IC3PSC Bits */
- TIMx->CCMR2 &= (uint16_t)~TIM_CCMR2_IC3PSC;
-
- /* Set the IC3PSC value */
- TIMx->CCMR2 |= TIM_ICPSC;
-}
-
-/**
- * @brief Sets the TIMx Input Capture 4 prescaler.
- * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
- * @param TIM_ICPSC: specifies the Input Capture4 prescaler new value.
- * This parameter can be one of the following values:
- * @arg TIM_ICPSC_DIV1: no prescaler
- * @arg TIM_ICPSC_DIV2: capture is done once every 2 events
- * @arg TIM_ICPSC_DIV4: capture is done once every 4 events
- * @arg TIM_ICPSC_DIV8: capture is done once every 8 events
- * @retval None
- */
-void TIM_SetIC4Prescaler(TIM_TypeDef* TIMx, uint16_t TIM_ICPSC)
-{
- /* Check the parameters */
- assert_param(IS_TIM_LIST3_PERIPH(TIMx));
- assert_param(IS_TIM_IC_PRESCALER(TIM_ICPSC));
-
- /* Reset the IC4PSC Bits */
- TIMx->CCMR2 &= (uint16_t)~TIM_CCMR2_IC4PSC;
-
- /* Set the IC4PSC value */
- TIMx->CCMR2 |= (uint16_t)(TIM_ICPSC << 8);
-}
-/**
- * @}
- */
-
-/** @defgroup TIM_Group4 Advanced-control timers (TIM1 and TIM8) specific features
- * @brief Advanced-control timers (TIM1 and TIM8) specific features
- *
-@verbatim
- ===============================================================================
- Advanced-control timers (TIM1 and TIM8) specific features
- ===============================================================================
-
- ===================================================================
- TIM Driver: how to use the Break feature
- ===================================================================
- After configuring the Timer channel(s) in the appropriate Output Compare mode:
-
- 1. Fill the TIM_BDTRInitStruct with the desired parameters for the Timer
- Break Polarity, dead time, Lock level, the OSSI/OSSR State and the
- AOE(automatic output enable).
-
- 2. Call TIM_BDTRConfig(TIMx, &TIM_BDTRInitStruct) to configure the Timer
-
- 3. Enable the Main Output using TIM_CtrlPWMOutputs(TIM1, ENABLE)
-
- 4. Once the break even occurs, the Timer's output signals are put in reset
- state or in a known state (according to the configuration made in
- TIM_BDTRConfig() function).
-
-@endverbatim
- * @{
- */
-
-/**
- * @brief Configures the Break feature, dead time, Lock level, OSSI/OSSR State
- * and the AOE(automatic output enable).
- * @param TIMx: where x can be 1 or 8 to select the TIM
- * @param TIM_BDTRInitStruct: pointer to a TIM_BDTRInitTypeDef structure that
- * contains the BDTR Register configuration information for the TIM peripheral.
- * @retval None
- */
-void TIM_BDTRConfig(TIM_TypeDef* TIMx, TIM_BDTRInitTypeDef *TIM_BDTRInitStruct)
-{
- /* Check the parameters */
- assert_param(IS_TIM_LIST4_PERIPH(TIMx));
- assert_param(IS_TIM_OSSR_STATE(TIM_BDTRInitStruct->TIM_OSSRState));
- assert_param(IS_TIM_OSSI_STATE(TIM_BDTRInitStruct->TIM_OSSIState));
- assert_param(IS_TIM_LOCK_LEVEL(TIM_BDTRInitStruct->TIM_LOCKLevel));
- assert_param(IS_TIM_BREAK_STATE(TIM_BDTRInitStruct->TIM_Break));
- assert_param(IS_TIM_BREAK_POLARITY(TIM_BDTRInitStruct->TIM_BreakPolarity));
- assert_param(IS_TIM_AUTOMATIC_OUTPUT_STATE(TIM_BDTRInitStruct->TIM_AutomaticOutput));
-
- /* Set the Lock level, the Break enable Bit and the Polarity, the OSSR State,
- the OSSI State, the dead time value and the Automatic Output Enable Bit */
- TIMx->BDTR = (uint32_t)TIM_BDTRInitStruct->TIM_OSSRState | TIM_BDTRInitStruct->TIM_OSSIState |
- TIM_BDTRInitStruct->TIM_LOCKLevel | TIM_BDTRInitStruct->TIM_DeadTime |
- TIM_BDTRInitStruct->TIM_Break | TIM_BDTRInitStruct->TIM_BreakPolarity |
- TIM_BDTRInitStruct->TIM_AutomaticOutput;
-}
-
-/**
- * @brief Fills each TIM_BDTRInitStruct member with its default value.
- * @param TIM_BDTRInitStruct: pointer to a TIM_BDTRInitTypeDef structure which
- * will be initialized.
- * @retval None
- */
-void TIM_BDTRStructInit(TIM_BDTRInitTypeDef* TIM_BDTRInitStruct)
-{
- /* Set the default configuration */
- TIM_BDTRInitStruct->TIM_OSSRState = TIM_OSSRState_Disable;
- TIM_BDTRInitStruct->TIM_OSSIState = TIM_OSSIState_Disable;
- TIM_BDTRInitStruct->TIM_LOCKLevel = TIM_LOCKLevel_OFF;
- TIM_BDTRInitStruct->TIM_DeadTime = 0x00;
- TIM_BDTRInitStruct->TIM_Break = TIM_Break_Disable;
- TIM_BDTRInitStruct->TIM_BreakPolarity = TIM_BreakPolarity_Low;
- TIM_BDTRInitStruct->TIM_AutomaticOutput = TIM_AutomaticOutput_Disable;
-}
-
-/**
- * @brief Enables or disables the TIM peripheral Main Outputs.
- * @param TIMx: where x can be 1 or 8 to select the TIMx peripheral.
- * @param NewState: new state of the TIM peripheral Main Outputs.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void TIM_CtrlPWMOutputs(TIM_TypeDef* TIMx, FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_TIM_LIST4_PERIPH(TIMx));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- if (NewState != DISABLE)
- {
- /* Enable the TIM Main Output */
- TIMx->BDTR |= TIM_BDTR_MOE;
- }
- else
- {
- /* Disable the TIM Main Output */
- TIMx->BDTR &= (uint16_t)~TIM_BDTR_MOE;
- }
-}
-
-/**
- * @brief Selects the TIM peripheral Commutation event.
- * @param TIMx: where x can be 1 or 8 to select the TIMx peripheral
- * @param NewState: new state of the Commutation event.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void TIM_SelectCOM(TIM_TypeDef* TIMx, FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_TIM_LIST4_PERIPH(TIMx));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- if (NewState != DISABLE)
- {
- /* Set the COM Bit */
- TIMx->CR2 |= TIM_CR2_CCUS;
- }
- else
- {
- /* Reset the COM Bit */
- TIMx->CR2 &= (uint16_t)~TIM_CR2_CCUS;
- }
-}
-
-/**
- * @brief Sets or Resets the TIM peripheral Capture Compare Preload Control bit.
- * @param TIMx: where x can be 1 or 8 to select the TIMx peripheral
- * @param NewState: new state of the Capture Compare Preload Control bit
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void TIM_CCPreloadControl(TIM_TypeDef* TIMx, FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_TIM_LIST4_PERIPH(TIMx));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
- if (NewState != DISABLE)
- {
- /* Set the CCPC Bit */
- TIMx->CR2 |= TIM_CR2_CCPC;
- }
- else
- {
- /* Reset the CCPC Bit */
- TIMx->CR2 &= (uint16_t)~TIM_CR2_CCPC;
- }
-}
-/**
- * @}
- */
-
-/** @defgroup TIM_Group5 Interrupts DMA and flags management functions
- * @brief Interrupts, DMA and flags management functions
- *
-@verbatim
- ===============================================================================
- Interrupts, DMA and flags management functions
- ===============================================================================
-
-@endverbatim
- * @{
- */
-
-/**
- * @brief Enables or disables the specified TIM interrupts.
- * @param TIMx: where x can be 1 to 14 to select the TIMx peripheral.
- * @param TIM_IT: specifies the TIM interrupts sources to be enabled or disabled.
- * This parameter can be any combination of the following values:
- * @arg TIM_IT_Update: TIM update Interrupt source
- * @arg TIM_IT_CC1: TIM Capture Compare 1 Interrupt source
- * @arg TIM_IT_CC2: TIM Capture Compare 2 Interrupt source
- * @arg TIM_IT_CC3: TIM Capture Compare 3 Interrupt source
- * @arg TIM_IT_CC4: TIM Capture Compare 4 Interrupt source
- * @arg TIM_IT_COM: TIM Commutation Interrupt source
- * @arg TIM_IT_Trigger: TIM Trigger Interrupt source
- * @arg TIM_IT_Break: TIM Break Interrupt source
- *
- * @note For TIM6 and TIM7 only the parameter TIM_IT_Update can be used
- * @note For TIM9 and TIM12 only one of the following parameters can be used: TIM_IT_Update,
- * TIM_IT_CC1, TIM_IT_CC2 or TIM_IT_Trigger.
- * @note For TIM10, TIM11, TIM13 and TIM14 only one of the following parameters can
- * be used: TIM_IT_Update or TIM_IT_CC1
- * @note TIM_IT_COM and TIM_IT_Break can be used only with TIM1 and TIM8
- *
- * @param NewState: new state of the TIM interrupts.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void TIM_ITConfig(TIM_TypeDef* TIMx, uint16_t TIM_IT, FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_TIM_ALL_PERIPH(TIMx));
- assert_param(IS_TIM_IT(TIM_IT));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- if (NewState != DISABLE)
- {
- /* Enable the Interrupt sources */
- TIMx->DIER |= TIM_IT;
- }
- else
- {
- /* Disable the Interrupt sources */
- TIMx->DIER &= (uint16_t)~TIM_IT;
- }
-}
-
-/**
- * @brief Configures the TIMx event to be generate by software.
- * @param TIMx: where x can be 1 to 14 to select the TIM peripheral.
- * @param TIM_EventSource: specifies the event source.
- * This parameter can be one or more of the following values:
- * @arg TIM_EventSource_Update: Timer update Event source
- * @arg TIM_EventSource_CC1: Timer Capture Compare 1 Event source
- * @arg TIM_EventSource_CC2: Timer Capture Compare 2 Event source
- * @arg TIM_EventSource_CC3: Timer Capture Compare 3 Event source
- * @arg TIM_EventSource_CC4: Timer Capture Compare 4 Event source
- * @arg TIM_EventSource_COM: Timer COM event source
- * @arg TIM_EventSource_Trigger: Timer Trigger Event source
- * @arg TIM_EventSource_Break: Timer Break event source
- *
- * @note TIM6 and TIM7 can only generate an update event.
- * @note TIM_EventSource_COM and TIM_EventSource_Break are used only with TIM1 and TIM8.
- *
- * @retval None
- */
-void TIM_GenerateEvent(TIM_TypeDef* TIMx, uint16_t TIM_EventSource)
-{
- /* Check the parameters */
- assert_param(IS_TIM_ALL_PERIPH(TIMx));
- assert_param(IS_TIM_EVENT_SOURCE(TIM_EventSource));
-
- /* Set the event sources */
- TIMx->EGR = TIM_EventSource;
-}
-
-/**
- * @brief Checks whether the specified TIM flag is set or not.
- * @param TIMx: where x can be 1 to 14 to select the TIM peripheral.
- * @param TIM_FLAG: specifies the flag to check.
- * This parameter can be one of the following values:
- * @arg TIM_FLAG_Update: TIM update Flag
- * @arg TIM_FLAG_CC1: TIM Capture Compare 1 Flag
- * @arg TIM_FLAG_CC2: TIM Capture Compare 2 Flag
- * @arg TIM_FLAG_CC3: TIM Capture Compare 3 Flag
- * @arg TIM_FLAG_CC4: TIM Capture Compare 4 Flag
- * @arg TIM_FLAG_COM: TIM Commutation Flag
- * @arg TIM_FLAG_Trigger: TIM Trigger Flag
- * @arg TIM_FLAG_Break: TIM Break Flag
- * @arg TIM_FLAG_CC1OF: TIM Capture Compare 1 over capture Flag
- * @arg TIM_FLAG_CC2OF: TIM Capture Compare 2 over capture Flag
- * @arg TIM_FLAG_CC3OF: TIM Capture Compare 3 over capture Flag
- * @arg TIM_FLAG_CC4OF: TIM Capture Compare 4 over capture Flag
- *
- * @note TIM6 and TIM7 can have only one update flag.
- * @note TIM_FLAG_COM and TIM_FLAG_Break are used only with TIM1 and TIM8.
- *
- * @retval The new state of TIM_FLAG (SET or RESET).
- */
-FlagStatus TIM_GetFlagStatus(TIM_TypeDef* TIMx, uint16_t TIM_FLAG)
-{
- ITStatus bitstatus = RESET;
- /* Check the parameters */
- assert_param(IS_TIM_ALL_PERIPH(TIMx));
- assert_param(IS_TIM_GET_FLAG(TIM_FLAG));
-
-
- if ((TIMx->SR & TIM_FLAG) != (uint16_t)RESET)
- {
- bitstatus = SET;
- }
- else
- {
- bitstatus = RESET;
- }
- return bitstatus;
-}
-
-/**
- * @brief Clears the TIMx's pending flags.
- * @param TIMx: where x can be 1 to 14 to select the TIM peripheral.
- * @param TIM_FLAG: specifies the flag bit to clear.
- * This parameter can be any combination of the following values:
- * @arg TIM_FLAG_Update: TIM update Flag
- * @arg TIM_FLAG_CC1: TIM Capture Compare 1 Flag
- * @arg TIM_FLAG_CC2: TIM Capture Compare 2 Flag
- * @arg TIM_FLAG_CC3: TIM Capture Compare 3 Flag
- * @arg TIM_FLAG_CC4: TIM Capture Compare 4 Flag
- * @arg TIM_FLAG_COM: TIM Commutation Flag
- * @arg TIM_FLAG_Trigger: TIM Trigger Flag
- * @arg TIM_FLAG_Break: TIM Break Flag
- * @arg TIM_FLAG_CC1OF: TIM Capture Compare 1 over capture Flag
- * @arg TIM_FLAG_CC2OF: TIM Capture Compare 2 over capture Flag
- * @arg TIM_FLAG_CC3OF: TIM Capture Compare 3 over capture Flag
- * @arg TIM_FLAG_CC4OF: TIM Capture Compare 4 over capture Flag
- *
- * @note TIM6 and TIM7 can have only one update flag.
- * @note TIM_FLAG_COM and TIM_FLAG_Break are used only with TIM1 and TIM8.
- *
- * @retval None
- */
-void TIM_ClearFlag(TIM_TypeDef* TIMx, uint16_t TIM_FLAG)
-{
- /* Check the parameters */
- assert_param(IS_TIM_ALL_PERIPH(TIMx));
-
- /* Clear the flags */
- TIMx->SR = (uint16_t)~TIM_FLAG;
-}
-
-/**
- * @brief Checks whether the TIM interrupt has occurred or not.
- * @param TIMx: where x can be 1 to 14 to select the TIM peripheral.
- * @param TIM_IT: specifies the TIM interrupt source to check.
- * This parameter can be one of the following values:
- * @arg TIM_IT_Update: TIM update Interrupt source
- * @arg TIM_IT_CC1: TIM Capture Compare 1 Interrupt source
- * @arg TIM_IT_CC2: TIM Capture Compare 2 Interrupt source
- * @arg TIM_IT_CC3: TIM Capture Compare 3 Interrupt source
- * @arg TIM_IT_CC4: TIM Capture Compare 4 Interrupt source
- * @arg TIM_IT_COM: TIM Commutation Interrupt source
- * @arg TIM_IT_Trigger: TIM Trigger Interrupt source
- * @arg TIM_IT_Break: TIM Break Interrupt source
- *
- * @note TIM6 and TIM7 can generate only an update interrupt.
- * @note TIM_IT_COM and TIM_IT_Break are used only with TIM1 and TIM8.
- *
- * @retval The new state of the TIM_IT(SET or RESET).
- */
-ITStatus TIM_GetITStatus(TIM_TypeDef* TIMx, uint16_t TIM_IT)
-{
- ITStatus bitstatus = RESET;
- uint16_t itstatus = 0x0, itenable = 0x0;
- /* Check the parameters */
- assert_param(IS_TIM_ALL_PERIPH(TIMx));
- assert_param(IS_TIM_GET_IT(TIM_IT));
-
- itstatus = TIMx->SR & TIM_IT;
-
- itenable = TIMx->DIER & TIM_IT;
- if ((itstatus != (uint16_t)RESET) && (itenable != (uint16_t)RESET))
- {
- bitstatus = SET;
- }
- else
- {
- bitstatus = RESET;
- }
- return bitstatus;
-}
-
-/**
- * @brief Clears the TIMx's interrupt pending bits.
- * @param TIMx: where x can be 1 to 14 to select the TIM peripheral.
- * @param TIM_IT: specifies the pending bit to clear.
- * This parameter can be any combination of the following values:
- * @arg TIM_IT_Update: TIM1 update Interrupt source
- * @arg TIM_IT_CC1: TIM Capture Compare 1 Interrupt source
- * @arg TIM_IT_CC2: TIM Capture Compare 2 Interrupt source
- * @arg TIM_IT_CC3: TIM Capture Compare 3 Interrupt source
- * @arg TIM_IT_CC4: TIM Capture Compare 4 Interrupt source
- * @arg TIM_IT_COM: TIM Commutation Interrupt source
- * @arg TIM_IT_Trigger: TIM Trigger Interrupt source
- * @arg TIM_IT_Break: TIM Break Interrupt source
- *
- * @note TIM6 and TIM7 can generate only an update interrupt.
- * @note TIM_IT_COM and TIM_IT_Break are used only with TIM1 and TIM8.
- *
- * @retval None
- */
-void TIM_ClearITPendingBit(TIM_TypeDef* TIMx, uint16_t TIM_IT)
-{
- /* Check the parameters */
- assert_param(IS_TIM_ALL_PERIPH(TIMx));
-
- /* Clear the IT pending Bit */
- TIMx->SR = (uint16_t)~TIM_IT;
-}
-
-/**
- * @brief Configures the TIMx's DMA interface.
- * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
- * @param TIM_DMABase: DMA Base address.
- * This parameter can be one of the following values:
- * @arg TIM_DMABase_CR1
- * @arg TIM_DMABase_CR2
- * @arg TIM_DMABase_SMCR
- * @arg TIM_DMABase_DIER
- * @arg TIM1_DMABase_SR
- * @arg TIM_DMABase_EGR
- * @arg TIM_DMABase_CCMR1
- * @arg TIM_DMABase_CCMR2
- * @arg TIM_DMABase_CCER
- * @arg TIM_DMABase_CNT
- * @arg TIM_DMABase_PSC
- * @arg TIM_DMABase_ARR
- * @arg TIM_DMABase_RCR
- * @arg TIM_DMABase_CCR1
- * @arg TIM_DMABase_CCR2
- * @arg TIM_DMABase_CCR3
- * @arg TIM_DMABase_CCR4
- * @arg TIM_DMABase_BDTR
- * @arg TIM_DMABase_DCR
- * @param TIM_DMABurstLength: DMA Burst length. This parameter can be one value
- * between: TIM_DMABurstLength_1Transfer and TIM_DMABurstLength_18Transfers.
- * @retval None
- */
-void TIM_DMAConfig(TIM_TypeDef* TIMx, uint16_t TIM_DMABase, uint16_t TIM_DMABurstLength)
-{
- /* Check the parameters */
- assert_param(IS_TIM_LIST3_PERIPH(TIMx));
- assert_param(IS_TIM_DMA_BASE(TIM_DMABase));
- assert_param(IS_TIM_DMA_LENGTH(TIM_DMABurstLength));
-
- /* Set the DMA Base and the DMA Burst Length */
- TIMx->DCR = TIM_DMABase | TIM_DMABurstLength;
-}
-
-/**
- * @brief Enables or disables the TIMx's DMA Requests.
- * @param TIMx: where x can be 1, 2, 3, 4, 5, 6, 7 or 8 to select the TIM peripheral.
- * @param TIM_DMASource: specifies the DMA Request sources.
- * This parameter can be any combination of the following values:
- * @arg TIM_DMA_Update: TIM update Interrupt source
- * @arg TIM_DMA_CC1: TIM Capture Compare 1 DMA source
- * @arg TIM_DMA_CC2: TIM Capture Compare 2 DMA source
- * @arg TIM_DMA_CC3: TIM Capture Compare 3 DMA source
- * @arg TIM_DMA_CC4: TIM Capture Compare 4 DMA source
- * @arg TIM_DMA_COM: TIM Commutation DMA source
- * @arg TIM_DMA_Trigger: TIM Trigger DMA source
- * @param NewState: new state of the DMA Request sources.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void TIM_DMACmd(TIM_TypeDef* TIMx, uint16_t TIM_DMASource, FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_TIM_LIST5_PERIPH(TIMx));
- assert_param(IS_TIM_DMA_SOURCE(TIM_DMASource));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- if (NewState != DISABLE)
- {
- /* Enable the DMA sources */
- TIMx->DIER |= TIM_DMASource;
- }
- else
- {
- /* Disable the DMA sources */
- TIMx->DIER &= (uint16_t)~TIM_DMASource;
- }
-}
-
-/**
- * @brief Selects the TIMx peripheral Capture Compare DMA source.
- * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
- * @param NewState: new state of the Capture Compare DMA source
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void TIM_SelectCCDMA(TIM_TypeDef* TIMx, FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_TIM_LIST3_PERIPH(TIMx));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- if (NewState != DISABLE)
- {
- /* Set the CCDS Bit */
- TIMx->CR2 |= TIM_CR2_CCDS;
- }
- else
- {
- /* Reset the CCDS Bit */
- TIMx->CR2 &= (uint16_t)~TIM_CR2_CCDS;
- }
-}
-/**
- * @}
- */
-
-/** @defgroup TIM_Group6 Clocks management functions
- * @brief Clocks management functions
- *
-@verbatim
- ===============================================================================
- Clocks management functions
- ===============================================================================
-
-@endverbatim
- * @{
- */
-
-/**
- * @brief Configures the TIMx internal Clock
- * @param TIMx: where x can be 1, 2, 3, 4, 5, 8, 9 or 12 to select the TIM
- * peripheral.
- * @retval None
- */
-void TIM_InternalClockConfig(TIM_TypeDef* TIMx)
-{
- /* Check the parameters */
- assert_param(IS_TIM_LIST2_PERIPH(TIMx));
-
- /* Disable slave mode to clock the prescaler directly with the internal clock */
- TIMx->SMCR &= (uint16_t)~TIM_SMCR_SMS;
-}
-
-/**
- * @brief Configures the TIMx Internal Trigger as External Clock
- * @param TIMx: where x can be 1, 2, 3, 4, 5, 8, 9 or 12 to select the TIM
- * peripheral.
- * @param TIM_InputTriggerSource: Trigger source.
- * This parameter can be one of the following values:
- * @arg TIM_TS_ITR0: Internal Trigger 0
- * @arg TIM_TS_ITR1: Internal Trigger 1
- * @arg TIM_TS_ITR2: Internal Trigger 2
- * @arg TIM_TS_ITR3: Internal Trigger 3
- * @retval None
- */
-void TIM_ITRxExternalClockConfig(TIM_TypeDef* TIMx, uint16_t TIM_InputTriggerSource)
-{
- /* Check the parameters */
- assert_param(IS_TIM_LIST2_PERIPH(TIMx));
- assert_param(IS_TIM_INTERNAL_TRIGGER_SELECTION(TIM_InputTriggerSource));
-
- /* Select the Internal Trigger */
- TIM_SelectInputTrigger(TIMx, TIM_InputTriggerSource);
-
- /* Select the External clock mode1 */
- TIMx->SMCR |= TIM_SlaveMode_External1;
-}
-
-/**
- * @brief Configures the TIMx Trigger as External Clock
- * @param TIMx: where x can be 1, 2, 3, 4, 5, 8, 9, 10, 11, 12, 13 or 14
- * to select the TIM peripheral.
- * @param TIM_TIxExternalCLKSource: Trigger source.
- * This parameter can be one of the following values:
- * @arg TIM_TIxExternalCLK1Source_TI1ED: TI1 Edge Detector
- * @arg TIM_TIxExternalCLK1Source_TI1: Filtered Timer Input 1
- * @arg TIM_TIxExternalCLK1Source_TI2: Filtered Timer Input 2
- * @param TIM_ICPolarity: specifies the TIx Polarity.
- * This parameter can be one of the following values:
- * @arg TIM_ICPolarity_Rising
- * @arg TIM_ICPolarity_Falling
- * @param ICFilter: specifies the filter value.
- * This parameter must be a value between 0x0 and 0xF.
- * @retval None
- */
-void TIM_TIxExternalClockConfig(TIM_TypeDef* TIMx, uint16_t TIM_TIxExternalCLKSource,
- uint16_t TIM_ICPolarity, uint16_t ICFilter)
-{
- /* Check the parameters */
- assert_param(IS_TIM_LIST1_PERIPH(TIMx));
- assert_param(IS_TIM_IC_POLARITY(TIM_ICPolarity));
- assert_param(IS_TIM_IC_FILTER(ICFilter));
-
- /* Configure the Timer Input Clock Source */
- if (TIM_TIxExternalCLKSource == TIM_TIxExternalCLK1Source_TI2)
- {
- TI2_Config(TIMx, TIM_ICPolarity, TIM_ICSelection_DirectTI, ICFilter);
- }
- else
- {
- TI1_Config(TIMx, TIM_ICPolarity, TIM_ICSelection_DirectTI, ICFilter);
- }
- /* Select the Trigger source */
- TIM_SelectInputTrigger(TIMx, TIM_TIxExternalCLKSource);
- /* Select the External clock mode1 */
- TIMx->SMCR |= TIM_SlaveMode_External1;
-}
-
-/**
- * @brief Configures the External clock Mode1
- * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
- * @param TIM_ExtTRGPrescaler: The external Trigger Prescaler.
- * This parameter can be one of the following values:
- * @arg TIM_ExtTRGPSC_OFF: ETRP Prescaler OFF.
- * @arg TIM_ExtTRGPSC_DIV2: ETRP frequency divided by 2.
- * @arg TIM_ExtTRGPSC_DIV4: ETRP frequency divided by 4.
- * @arg TIM_ExtTRGPSC_DIV8: ETRP frequency divided by 8.
- * @param TIM_ExtTRGPolarity: The external Trigger Polarity.
- * This parameter can be one of the following values:
- * @arg TIM_ExtTRGPolarity_Inverted: active low or falling edge active.
- * @arg TIM_ExtTRGPolarity_NonInverted: active high or rising edge active.
- * @param ExtTRGFilter: External Trigger Filter.
- * This parameter must be a value between 0x00 and 0x0F
- * @retval None
- */
-void TIM_ETRClockMode1Config(TIM_TypeDef* TIMx, uint16_t TIM_ExtTRGPrescaler,
- uint16_t TIM_ExtTRGPolarity, uint16_t ExtTRGFilter)
-{
- uint16_t tmpsmcr = 0;
-
- /* Check the parameters */
- assert_param(IS_TIM_LIST3_PERIPH(TIMx));
- assert_param(IS_TIM_EXT_PRESCALER(TIM_ExtTRGPrescaler));
- assert_param(IS_TIM_EXT_POLARITY(TIM_ExtTRGPolarity));
- assert_param(IS_TIM_EXT_FILTER(ExtTRGFilter));
- /* Configure the ETR Clock source */
- TIM_ETRConfig(TIMx, TIM_ExtTRGPrescaler, TIM_ExtTRGPolarity, ExtTRGFilter);
-
- /* Get the TIMx SMCR register value */
- tmpsmcr = TIMx->SMCR;
-
- /* Reset the SMS Bits */
- tmpsmcr &= (uint16_t)~TIM_SMCR_SMS;
-
- /* Select the External clock mode1 */
- tmpsmcr |= TIM_SlaveMode_External1;
-
- /* Select the Trigger selection : ETRF */
- tmpsmcr &= (uint16_t)~TIM_SMCR_TS;
- tmpsmcr |= TIM_TS_ETRF;
-
- /* Write to TIMx SMCR */
- TIMx->SMCR = tmpsmcr;
-}
-
-/**
- * @brief Configures the External clock Mode2
- * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
- * @param TIM_ExtTRGPrescaler: The external Trigger Prescaler.
- * This parameter can be one of the following values:
- * @arg TIM_ExtTRGPSC_OFF: ETRP Prescaler OFF.
- * @arg TIM_ExtTRGPSC_DIV2: ETRP frequency divided by 2.
- * @arg TIM_ExtTRGPSC_DIV4: ETRP frequency divided by 4.
- * @arg TIM_ExtTRGPSC_DIV8: ETRP frequency divided by 8.
- * @param TIM_ExtTRGPolarity: The external Trigger Polarity.
- * This parameter can be one of the following values:
- * @arg TIM_ExtTRGPolarity_Inverted: active low or falling edge active.
- * @arg TIM_ExtTRGPolarity_NonInverted: active high or rising edge active.
- * @param ExtTRGFilter: External Trigger Filter.
- * This parameter must be a value between 0x00 and 0x0F
- * @retval None
- */
-void TIM_ETRClockMode2Config(TIM_TypeDef* TIMx, uint16_t TIM_ExtTRGPrescaler,
- uint16_t TIM_ExtTRGPolarity, uint16_t ExtTRGFilter)
-{
- /* Check the parameters */
- assert_param(IS_TIM_LIST3_PERIPH(TIMx));
- assert_param(IS_TIM_EXT_PRESCALER(TIM_ExtTRGPrescaler));
- assert_param(IS_TIM_EXT_POLARITY(TIM_ExtTRGPolarity));
- assert_param(IS_TIM_EXT_FILTER(ExtTRGFilter));
-
- /* Configure the ETR Clock source */
- TIM_ETRConfig(TIMx, TIM_ExtTRGPrescaler, TIM_ExtTRGPolarity, ExtTRGFilter);
-
- /* Enable the External clock mode2 */
- TIMx->SMCR |= TIM_SMCR_ECE;
-}
-/**
- * @}
- */
-
-/** @defgroup TIM_Group7 Synchronization management functions
- * @brief Synchronization management functions
- *
-@verbatim
- ===============================================================================
- Synchronization management functions
- ===============================================================================
-
- ===================================================================
- TIM Driver: how to use it in synchronization Mode
- ===================================================================
- Case of two/several Timers
- **************************
- 1. Configure the Master Timers using the following functions:
- - void TIM_SelectOutputTrigger(TIM_TypeDef* TIMx, uint16_t TIM_TRGOSource);
- - void TIM_SelectMasterSlaveMode(TIM_TypeDef* TIMx, uint16_t TIM_MasterSlaveMode);
- 2. Configure the Slave Timers using the following functions:
- - void TIM_SelectInputTrigger(TIM_TypeDef* TIMx, uint16_t TIM_InputTriggerSource);
- - void TIM_SelectSlaveMode(TIM_TypeDef* TIMx, uint16_t TIM_SlaveMode);
-
- Case of Timers and external trigger(ETR pin)
- ********************************************
- 1. Configure the External trigger using this function:
- - void TIM_ETRConfig(TIM_TypeDef* TIMx, uint16_t TIM_ExtTRGPrescaler, uint16_t TIM_ExtTRGPolarity,
- uint16_t ExtTRGFilter);
- 2. Configure the Slave Timers using the following functions:
- - void TIM_SelectInputTrigger(TIM_TypeDef* TIMx, uint16_t TIM_InputTriggerSource);
- - void TIM_SelectSlaveMode(TIM_TypeDef* TIMx, uint16_t TIM_SlaveMode);
-
-@endverbatim
- * @{
- */
-
-/**
- * @brief Selects the Input Trigger source
- * @param TIMx: where x can be 1, 2, 3, 4, 5, 8, 9, 10, 11, 12, 13 or 14
- * to select the TIM peripheral.
- * @param TIM_InputTriggerSource: The Input Trigger source.
- * This parameter can be one of the following values:
- * @arg TIM_TS_ITR0: Internal Trigger 0
- * @arg TIM_TS_ITR1: Internal Trigger 1
- * @arg TIM_TS_ITR2: Internal Trigger 2
- * @arg TIM_TS_ITR3: Internal Trigger 3
- * @arg TIM_TS_TI1F_ED: TI1 Edge Detector
- * @arg TIM_TS_TI1FP1: Filtered Timer Input 1
- * @arg TIM_TS_TI2FP2: Filtered Timer Input 2
- * @arg TIM_TS_ETRF: External Trigger input
- * @retval None
- */
-void TIM_SelectInputTrigger(TIM_TypeDef* TIMx, uint16_t TIM_InputTriggerSource)
-{
- uint16_t tmpsmcr = 0;
-
- /* Check the parameters */
- assert_param(IS_TIM_LIST1_PERIPH(TIMx));
- assert_param(IS_TIM_TRIGGER_SELECTION(TIM_InputTriggerSource));
-
- /* Get the TIMx SMCR register value */
- tmpsmcr = TIMx->SMCR;
-
- /* Reset the TS Bits */
- tmpsmcr &= (uint16_t)~TIM_SMCR_TS;
-
- /* Set the Input Trigger source */
- tmpsmcr |= TIM_InputTriggerSource;
-
- /* Write to TIMx SMCR */
- TIMx->SMCR = tmpsmcr;
-}
-
-/**
- * @brief Selects the TIMx Trigger Output Mode.
- * @param TIMx: where x can be 1, 2, 3, 4, 5, 6, 7 or 8 to select the TIM peripheral.
- *
- * @param TIM_TRGOSource: specifies the Trigger Output source.
- * This parameter can be one of the following values:
- *
- * - For all TIMx
- * @arg TIM_TRGOSource_Reset: The UG bit in the TIM_EGR register is used as the trigger output(TRGO)
- * @arg TIM_TRGOSource_Enable: The Counter Enable CEN is used as the trigger output(TRGO)
- * @arg TIM_TRGOSource_Update: The update event is selected as the trigger output(TRGO)
- *
- * - For all TIMx except TIM6 and TIM7
- * @arg TIM_TRGOSource_OC1: The trigger output sends a positive pulse when the CC1IF flag
- * is to be set, as soon as a capture or compare match occurs(TRGO)
- * @arg TIM_TRGOSource_OC1Ref: OC1REF signal is used as the trigger output(TRGO)
- * @arg TIM_TRGOSource_OC2Ref: OC2REF signal is used as the trigger output(TRGO)
- * @arg TIM_TRGOSource_OC3Ref: OC3REF signal is used as the trigger output(TRGO)
- * @arg TIM_TRGOSource_OC4Ref: OC4REF signal is used as the trigger output(TRGO)
- *
- * @retval None
- */
-void TIM_SelectOutputTrigger(TIM_TypeDef* TIMx, uint16_t TIM_TRGOSource)
-{
- /* Check the parameters */
- assert_param(IS_TIM_LIST5_PERIPH(TIMx));
- assert_param(IS_TIM_TRGO_SOURCE(TIM_TRGOSource));
-
- /* Reset the MMS Bits */
- TIMx->CR2 &= (uint16_t)~TIM_CR2_MMS;
- /* Select the TRGO source */
- TIMx->CR2 |= TIM_TRGOSource;
-}
-
-/**
- * @brief Selects the TIMx Slave Mode.
- * @param TIMx: where x can be 1, 2, 3, 4, 5, 8, 9 or 12 to select the TIM peripheral.
- * @param TIM_SlaveMode: specifies the Timer Slave Mode.
- * This parameter can be one of the following values:
- * @arg TIM_SlaveMode_Reset: Rising edge of the selected trigger signal(TRGI) reinitialize
- * the counter and triggers an update of the registers
- * @arg TIM_SlaveMode_Gated: The counter clock is enabled when the trigger signal (TRGI) is high
- * @arg TIM_SlaveMode_Trigger: The counter starts at a rising edge of the trigger TRGI
- * @arg TIM_SlaveMode_External1: Rising edges of the selected trigger (TRGI) clock the counter
- * @retval None
- */
-void TIM_SelectSlaveMode(TIM_TypeDef* TIMx, uint16_t TIM_SlaveMode)
-{
- /* Check the parameters */
- assert_param(IS_TIM_LIST2_PERIPH(TIMx));
- assert_param(IS_TIM_SLAVE_MODE(TIM_SlaveMode));
-
- /* Reset the SMS Bits */
- TIMx->SMCR &= (uint16_t)~TIM_SMCR_SMS;
-
- /* Select the Slave Mode */
- TIMx->SMCR |= TIM_SlaveMode;
-}
-
-/**
- * @brief Sets or Resets the TIMx Master/Slave Mode.
- * @param TIMx: where x can be 1, 2, 3, 4, 5, 8, 9 or 12 to select the TIM peripheral.
- * @param TIM_MasterSlaveMode: specifies the Timer Master Slave Mode.
- * This parameter can be one of the following values:
- * @arg TIM_MasterSlaveMode_Enable: synchronization between the current timer
- * and its slaves (through TRGO)
- * @arg TIM_MasterSlaveMode_Disable: No action
- * @retval None
- */
-void TIM_SelectMasterSlaveMode(TIM_TypeDef* TIMx, uint16_t TIM_MasterSlaveMode)
-{
- /* Check the parameters */
- assert_param(IS_TIM_LIST2_PERIPH(TIMx));
- assert_param(IS_TIM_MSM_STATE(TIM_MasterSlaveMode));
-
- /* Reset the MSM Bit */
- TIMx->SMCR &= (uint16_t)~TIM_SMCR_MSM;
-
- /* Set or Reset the MSM Bit */
- TIMx->SMCR |= TIM_MasterSlaveMode;
-}
-
-/**
- * @brief Configures the TIMx External Trigger (ETR).
- * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
- * @param TIM_ExtTRGPrescaler: The external Trigger Prescaler.
- * This parameter can be one of the following values:
- * @arg TIM_ExtTRGPSC_OFF: ETRP Prescaler OFF.
- * @arg TIM_ExtTRGPSC_DIV2: ETRP frequency divided by 2.
- * @arg TIM_ExtTRGPSC_DIV4: ETRP frequency divided by 4.
- * @arg TIM_ExtTRGPSC_DIV8: ETRP frequency divided by 8.
- * @param TIM_ExtTRGPolarity: The external Trigger Polarity.
- * This parameter can be one of the following values:
- * @arg TIM_ExtTRGPolarity_Inverted: active low or falling edge active.
- * @arg TIM_ExtTRGPolarity_NonInverted: active high or rising edge active.
- * @param ExtTRGFilter: External Trigger Filter.
- * This parameter must be a value between 0x00 and 0x0F
- * @retval None
- */
-void TIM_ETRConfig(TIM_TypeDef* TIMx, uint16_t TIM_ExtTRGPrescaler,
- uint16_t TIM_ExtTRGPolarity, uint16_t ExtTRGFilter)
-{
- uint16_t tmpsmcr = 0;
-
- /* Check the parameters */
- assert_param(IS_TIM_LIST3_PERIPH(TIMx));
- assert_param(IS_TIM_EXT_PRESCALER(TIM_ExtTRGPrescaler));
- assert_param(IS_TIM_EXT_POLARITY(TIM_ExtTRGPolarity));
- assert_param(IS_TIM_EXT_FILTER(ExtTRGFilter));
-
- tmpsmcr = TIMx->SMCR;
-
- /* Reset the ETR Bits */
- tmpsmcr &= SMCR_ETR_MASK;
-
- /* Set the Prescaler, the Filter value and the Polarity */
- tmpsmcr |= (uint16_t)(TIM_ExtTRGPrescaler | (uint16_t)(TIM_ExtTRGPolarity | (uint16_t)(ExtTRGFilter << (uint16_t)8)));
-
- /* Write to TIMx SMCR */
- TIMx->SMCR = tmpsmcr;
-}
-/**
- * @}
- */
-
-/** @defgroup TIM_Group8 Specific interface management functions
- * @brief Specific interface management functions
- *
-@verbatim
- ===============================================================================
- Specific interface management functions
- ===============================================================================
-
-@endverbatim
- * @{
- */
-
-/**
- * @brief Configures the TIMx Encoder Interface.
- * @param TIMx: where x can be 1, 2, 3, 4, 5, 8, 9 or 12 to select the TIM
- * peripheral.
- * @param TIM_EncoderMode: specifies the TIMx Encoder Mode.
- * This parameter can be one of the following values:
- * @arg TIM_EncoderMode_TI1: Counter counts on TI1FP1 edge depending on TI2FP2 level.
- * @arg TIM_EncoderMode_TI2: Counter counts on TI2FP2 edge depending on TI1FP1 level.
- * @arg TIM_EncoderMode_TI12: Counter counts on both TI1FP1 and TI2FP2 edges depending
- * on the level of the other input.
- * @param TIM_IC1Polarity: specifies the IC1 Polarity
- * This parameter can be one of the following values:
- * @arg TIM_ICPolarity_Falling: IC Falling edge.
- * @arg TIM_ICPolarity_Rising: IC Rising edge.
- * @param TIM_IC2Polarity: specifies the IC2 Polarity
- * This parameter can be one of the following values:
- * @arg TIM_ICPolarity_Falling: IC Falling edge.
- * @arg TIM_ICPolarity_Rising: IC Rising edge.
- * @retval None
- */
-void TIM_EncoderInterfaceConfig(TIM_TypeDef* TIMx, uint16_t TIM_EncoderMode,
- uint16_t TIM_IC1Polarity, uint16_t TIM_IC2Polarity)
-{
- uint16_t tmpsmcr = 0;
- uint16_t tmpccmr1 = 0;
- uint16_t tmpccer = 0;
-
- /* Check the parameters */
- assert_param(IS_TIM_LIST2_PERIPH(TIMx));
- assert_param(IS_TIM_ENCODER_MODE(TIM_EncoderMode));
- assert_param(IS_TIM_IC_POLARITY(TIM_IC1Polarity));
- assert_param(IS_TIM_IC_POLARITY(TIM_IC2Polarity));
-
- /* Get the TIMx SMCR register value */
- tmpsmcr = TIMx->SMCR;
-
- /* Get the TIMx CCMR1 register value */
- tmpccmr1 = TIMx->CCMR1;
-
- /* Get the TIMx CCER register value */
- tmpccer = TIMx->CCER;
-
- /* Set the encoder Mode */
- tmpsmcr &= (uint16_t)~TIM_SMCR_SMS;
- tmpsmcr |= TIM_EncoderMode;
-
- /* Select the Capture Compare 1 and the Capture Compare 2 as input */
- tmpccmr1 &= ((uint16_t)~TIM_CCMR1_CC1S) & ((uint16_t)~TIM_CCMR1_CC2S);
- tmpccmr1 |= TIM_CCMR1_CC1S_0 | TIM_CCMR1_CC2S_0;
-
- /* Set the TI1 and the TI2 Polarities */
- tmpccer &= ((uint16_t)~TIM_CCER_CC1P) & ((uint16_t)~TIM_CCER_CC2P);
- tmpccer |= (uint16_t)(TIM_IC1Polarity | (uint16_t)(TIM_IC2Polarity << (uint16_t)4));
-
- /* Write to TIMx SMCR */
- TIMx->SMCR = tmpsmcr;
-
- /* Write to TIMx CCMR1 */
- TIMx->CCMR1 = tmpccmr1;
-
- /* Write to TIMx CCER */
- TIMx->CCER = tmpccer;
-}
-
-/**
- * @brief Enables or disables the TIMx's Hall sensor interface.
- * @param TIMx: where x can be 1, 2, 3, 4, 5, 8, 9 or 12 to select the TIM
- * peripheral.
- * @param NewState: new state of the TIMx Hall sensor interface.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
-void TIM_SelectHallSensor(TIM_TypeDef* TIMx, FunctionalState NewState)
-{
- /* Check the parameters */
- assert_param(IS_TIM_LIST2_PERIPH(TIMx));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- if (NewState != DISABLE)
- {
- /* Set the TI1S Bit */
- TIMx->CR2 |= TIM_CR2_TI1S;
- }
- else
- {
- /* Reset the TI1S Bit */
- TIMx->CR2 &= (uint16_t)~TIM_CR2_TI1S;
- }
-}
-/**
- * @}
- */
-
-/** @defgroup TIM_Group9 Specific remapping management function
- * @brief Specific remapping management function
- *
-@verbatim
- ===============================================================================
- Specific remapping management function
- ===============================================================================
-
-@endverbatim
- * @{
- */
-
-/**
- * @brief Configures the TIM2, TIM5 and TIM11 Remapping input capabilities.
- * @param TIMx: where x can be 2, 5 or 11 to select the TIM peripheral.
- * @param TIM_Remap: specifies the TIM input remapping source.
- * This parameter can be one of the following values:
- * @arg TIM2_TIM8_TRGO: TIM2 ITR1 input is connected to TIM8 Trigger output(default)
- * @arg TIM2_ETH_PTP: TIM2 ITR1 input is connected to ETH PTP trogger output.
- * @arg TIM2_USBFS_SOF: TIM2 ITR1 input is connected to USB FS SOF.
- * @arg TIM2_USBHS_SOF: TIM2 ITR1 input is connected to USB HS SOF.
- * @arg TIM5_GPIO: TIM5 CH4 input is connected to dedicated Timer pin(default)
- * @arg TIM5_LSI: TIM5 CH4 input is connected to LSI clock.
- * @arg TIM5_LSE: TIM5 CH4 input is connected to LSE clock.
- * @arg TIM5_RTC: TIM5 CH4 input is connected to RTC Output event.
- * @arg TIM11_GPIO: TIM11 CH4 input is connected to dedicated Timer pin(default)
- * @arg TIM11_HSE: TIM11 CH4 input is connected to HSE_RTC clock
- * (HSE divided by a programmable prescaler)
- * @retval None
- */
-void TIM_RemapConfig(TIM_TypeDef* TIMx, uint16_t TIM_Remap)
-{
- /* Check the parameters */
- assert_param(IS_TIM_LIST6_PERIPH(TIMx));
- assert_param(IS_TIM_REMAP(TIM_Remap));
-
- /* Set the Timer remapping configuration */
- TIMx->OR = TIM_Remap;
-}
-/**
- * @}
- */
-
-/**
- * @brief Configure the TI1 as Input.
- * @param TIMx: where x can be 1, 2, 3, 4, 5, 8, 9, 10, 11, 12, 13 or 14
- * to select the TIM peripheral.
- * @param TIM_ICPolarity : The Input Polarity.
- * This parameter can be one of the following values:
- * @arg TIM_ICPolarity_Rising
- * @arg TIM_ICPolarity_Falling
- * @arg TIM_ICPolarity_BothEdge
- * @param TIM_ICSelection: specifies the input to be used.
- * This parameter can be one of the following values:
- * @arg TIM_ICSelection_DirectTI: TIM Input 1 is selected to be connected to IC1.
- * @arg TIM_ICSelection_IndirectTI: TIM Input 1 is selected to be connected to IC2.
- * @arg TIM_ICSelection_TRC: TIM Input 1 is selected to be connected to TRC.
- * @param TIM_ICFilter: Specifies the Input Capture Filter.
- * This parameter must be a value between 0x00 and 0x0F.
- * @retval None
- */
-static void TI1_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection,
- uint16_t TIM_ICFilter)
-{
- uint16_t tmpccmr1 = 0, tmpccer = 0;
-
- /* Disable the Channel 1: Reset the CC1E Bit */
- TIMx->CCER &= (uint16_t)~TIM_CCER_CC1E;
- tmpccmr1 = TIMx->CCMR1;
- tmpccer = TIMx->CCER;
-
- /* Select the Input and set the filter */
- tmpccmr1 &= ((uint16_t)~TIM_CCMR1_CC1S) & ((uint16_t)~TIM_CCMR1_IC1F);
- tmpccmr1 |= (uint16_t)(TIM_ICSelection | (uint16_t)(TIM_ICFilter << (uint16_t)4));
-
- /* Select the Polarity and set the CC1E Bit */
- tmpccer &= (uint16_t)~(TIM_CCER_CC1P | TIM_CCER_CC1NP);
- tmpccer |= (uint16_t)(TIM_ICPolarity | (uint16_t)TIM_CCER_CC1E);
-
- /* Write to TIMx CCMR1 and CCER registers */
- TIMx->CCMR1 = tmpccmr1;
- TIMx->CCER = tmpccer;
-}
-
-/**
- * @brief Configure the TI2 as Input.
- * @param TIMx: where x can be 1, 2, 3, 4, 5, 8, 9 or 12 to select the TIM
- * peripheral.
- * @param TIM_ICPolarity : The Input Polarity.
- * This parameter can be one of the following values:
- * @arg TIM_ICPolarity_Rising
- * @arg TIM_ICPolarity_Falling
- * @arg TIM_ICPolarity_BothEdge
- * @param TIM_ICSelection: specifies the input to be used.
- * This parameter can be one of the following values:
- * @arg TIM_ICSelection_DirectTI: TIM Input 2 is selected to be connected to IC2.
- * @arg TIM_ICSelection_IndirectTI: TIM Input 2 is selected to be connected to IC1.
- * @arg TIM_ICSelection_TRC: TIM Input 2 is selected to be connected to TRC.
- * @param TIM_ICFilter: Specifies the Input Capture Filter.
- * This parameter must be a value between 0x00 and 0x0F.
- * @retval None
- */
-static void TI2_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection,
- uint16_t TIM_ICFilter)
-{
- uint16_t tmpccmr1 = 0, tmpccer = 0, tmp = 0;
-
- /* Disable the Channel 2: Reset the CC2E Bit */
- TIMx->CCER &= (uint16_t)~TIM_CCER_CC2E;
- tmpccmr1 = TIMx->CCMR1;
- tmpccer = TIMx->CCER;
- tmp = (uint16_t)(TIM_ICPolarity << 4);
-
- /* Select the Input and set the filter */
- tmpccmr1 &= ((uint16_t)~TIM_CCMR1_CC2S) & ((uint16_t)~TIM_CCMR1_IC2F);
- tmpccmr1 |= (uint16_t)(TIM_ICFilter << 12);
- tmpccmr1 |= (uint16_t)(TIM_ICSelection << 8);
-
- /* Select the Polarity and set the CC2E Bit */
- tmpccer &= (uint16_t)~(TIM_CCER_CC2P | TIM_CCER_CC2NP);
- tmpccer |= (uint16_t)(tmp | (uint16_t)TIM_CCER_CC2E);
-
- /* Write to TIMx CCMR1 and CCER registers */
- TIMx->CCMR1 = tmpccmr1 ;
- TIMx->CCER = tmpccer;
-}
-
-/**
- * @brief Configure the TI3 as Input.
- * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
- * @param TIM_ICPolarity : The Input Polarity.
- * This parameter can be one of the following values:
- * @arg TIM_ICPolarity_Rising
- * @arg TIM_ICPolarity_Falling
- * @arg TIM_ICPolarity_BothEdge
- * @param TIM_ICSelection: specifies the input to be used.
- * This parameter can be one of the following values:
- * @arg TIM_ICSelection_DirectTI: TIM Input 3 is selected to be connected to IC3.
- * @arg TIM_ICSelection_IndirectTI: TIM Input 3 is selected to be connected to IC4.
- * @arg TIM_ICSelection_TRC: TIM Input 3 is selected to be connected to TRC.
- * @param TIM_ICFilter: Specifies the Input Capture Filter.
- * This parameter must be a value between 0x00 and 0x0F.
- * @retval None
- */
-static void TI3_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection,
- uint16_t TIM_ICFilter)
-{
- uint16_t tmpccmr2 = 0, tmpccer = 0, tmp = 0;
-
- /* Disable the Channel 3: Reset the CC3E Bit */
- TIMx->CCER &= (uint16_t)~TIM_CCER_CC3E;
- tmpccmr2 = TIMx->CCMR2;
- tmpccer = TIMx->CCER;
- tmp = (uint16_t)(TIM_ICPolarity << 8);
-
- /* Select the Input and set the filter */
- tmpccmr2 &= ((uint16_t)~TIM_CCMR1_CC1S) & ((uint16_t)~TIM_CCMR2_IC3F);
- tmpccmr2 |= (uint16_t)(TIM_ICSelection | (uint16_t)(TIM_ICFilter << (uint16_t)4));
-
- /* Select the Polarity and set the CC3E Bit */
- tmpccer &= (uint16_t)~(TIM_CCER_CC3P | TIM_CCER_CC3NP);
- tmpccer |= (uint16_t)(tmp | (uint16_t)TIM_CCER_CC3E);
-
- /* Write to TIMx CCMR2 and CCER registers */
- TIMx->CCMR2 = tmpccmr2;
- TIMx->CCER = tmpccer;
-}
-
-/**
- * @brief Configure the TI4 as Input.
- * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
- * @param TIM_ICPolarity : The Input Polarity.
- * This parameter can be one of the following values:
- * @arg TIM_ICPolarity_Rising
- * @arg TIM_ICPolarity_Falling
- * @arg TIM_ICPolarity_BothEdge
- * @param TIM_ICSelection: specifies the input to be used.
- * This parameter can be one of the following values:
- * @arg TIM_ICSelection_DirectTI: TIM Input 4 is selected to be connected to IC4.
- * @arg TIM_ICSelection_IndirectTI: TIM Input 4 is selected to be connected to IC3.
- * @arg TIM_ICSelection_TRC: TIM Input 4 is selected to be connected to TRC.
- * @param TIM_ICFilter: Specifies the Input Capture Filter.
- * This parameter must be a value between 0x00 and 0x0F.
- * @retval None
- */
-static void TI4_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection,
- uint16_t TIM_ICFilter)
-{
- uint16_t tmpccmr2 = 0, tmpccer = 0, tmp = 0;
-
- /* Disable the Channel 4: Reset the CC4E Bit */
- TIMx->CCER &= (uint16_t)~TIM_CCER_CC4E;
- tmpccmr2 = TIMx->CCMR2;
- tmpccer = TIMx->CCER;
- tmp = (uint16_t)(TIM_ICPolarity << 12);
-
- /* Select the Input and set the filter */
- tmpccmr2 &= ((uint16_t)~TIM_CCMR1_CC2S) & ((uint16_t)~TIM_CCMR1_IC2F);
- tmpccmr2 |= (uint16_t)(TIM_ICSelection << 8);
- tmpccmr2 |= (uint16_t)(TIM_ICFilter << 12);
-
- /* Select the Polarity and set the CC4E Bit */
- tmpccer &= (uint16_t)~(TIM_CCER_CC4P | TIM_CCER_CC4NP);
- tmpccer |= (uint16_t)(tmp | (uint16_t)TIM_CCER_CC4E);
-
- /* Write to TIMx CCMR2 and CCER registers */
- TIMx->CCMR2 = tmpccmr2;
- TIMx->CCER = tmpccer ;
-}
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-
-/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/Kconfig b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/Kconfig
deleted file mode 100644
index 1aeabc314..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/Kconfig
+++ /dev/null
@@ -1,12 +0,0 @@
-config BSP_USING_USBH
- bool "Using usb host"
- default y
- config USB_BUS_NAME
- string "usb bus name"
- default "usb"
- config USB_DRIVER_NAME
- string "usb bus driver name"
- default "usb_drv"
- config USB_DEVICE_NAME
- string "usb bus device name"
- default "usb_dev"
\ No newline at end of file
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/Makefile b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/Makefile
deleted file mode 100644
index 6331e6ea1..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/Makefile
+++ /dev/null
@@ -1,4 +0,0 @@
-SRC_FILES := usb_bsp.c usbh.c connect_usb.c
-SRC_FILES += STM32_USB_OTG_Driver/src/usb_core.c STM32_USB_OTG_Driver/src/usb_hcd.c STM32_USB_OTG_Driver/src/usb_hcd_int.c
-
-include $(KERNEL_ROOT)/compiler.mk
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/Release_Notes.html b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/Release_Notes.html
deleted file mode 100644
index ff42dd3db..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/Release_Notes.html
+++ /dev/null
@@ -1,953 +0,0 @@
-
-
-
-
-
-Release Notes for STM32F105/7xx, STM32F2xx and STM32F4xx USB OTG Driver
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Back to Release page
-
-
-
-
- Release Notes for STM32F105/7xx, STM32F2xx and STM32F4xx USB OTG Driver
- Copyright
- 2017 STMicroelectronics
-
-
-
-
-
-
-
-
- Update History V2.2.1 / 17-March-2018 Main
-Changes
-
- usb_core.c Bug Fix: Update VBUS sensing support for STM32F446xx and STM32F469 devices Bug Fix: deactivate endpoints per endpoint number usb_reg.h Add bit mapping of GCCFG register for STM32F446xx and STM32F469 devices V2.2.0 / 9-November-2015 Main
-Changes
-
-
- Add support of STM32F469/479xx and STM32F446 devices
-usb_dcd_int.c Bug
-Fix: Masking the TxFIFOempty interrupt of the endpoint after
-finishing writing data packet to TxFIFO in DCD_WriteEmptyTxFifo function Bug Fix: The USB TRD (Turnaround) is configured depending on AHB frequency used by application. Bug Fix: Handle multi-packet for OUT transfer with DMA in HS mode Remove CLEAR_IN_EP_INTR(epnum, emptyintr) in USBD_OTG_EP1IN_ISR_Handler and DCD_HandleInEP_ISR Correct PCFCCTL register access usb_core.c USB_OTG_HC_Halt function: Modify Channel halt function to disable the channel at the end Correct PCFCCTL register access Bug Fix: Handle multi-packet for OUT transfer with DMA in HS mode Bug Fix: Keep the disconnect interrupt masked In function USB_OTG_EnableHostInt for correct handling of connection/disconnection In function USB_OTG_ResetPort change reset time to 100ms instead of 10ms for better stability during enumeration usb_hcd.c Add function HCD_IsPortEnabled to check portenabled for correct handling of connection/disconnection usb_hcd_int.c Remove USB_OTG_ResetPort(pdev) calling Update USB_OTG_USBH_handle_port_ISR for correct handling of connection/disconnection Disconnect interrupt is unmasked after a connection Creation of PortEnabled event (need to wait for this event before starting enumerating device) Halt channel and restart transfer is removed When using DMA (HS) In case of NAK or NYET in USB_OTG_USBH_handle_hc_n_Out_ISR and USB_OTG_USBH_handle_hc_n_In_ISR Clearing the NAK interrupt flag before re-enabling the channel for a new transfer in USB_OTG_USBH_handle_hc_n_In_ISR function V2.1.0 / 19-March-2012
- Main
-Changes
-
- Official support of STM32F4xx devicesAll source files: license disclaimer text update and add link to the License file on ST Internet Unmask Session request interrupt to handle the connect event during the core start-up Remove any reference to the USB HS external I2C PHY Update optimization pragma for AR Compiler Handle Correctly the Low Speed device connection in HS mode Add a wrapper to isolate the library from the low level driver: connection done through ISR structure Miscellaneous bug fix V2.0.0 / 22-July-2011 Main
-Changes
-Second official version supporting STM32F105/7 and STM32F2xx devices Rename the Library from "STM32_USB_HOST_Driver " to "STM32_USB_OTG_Driver " Add support for STM32F2xx devices Add support for Device and OTG modes Change HCD layer to support High speed core Change the Low level driver to support multi core support for Host mode Add Stop mechanism for Host and Device modes Change VBUS enabling method, to use the external or the internal VBUS when using the ULPI V1.0.0 - 11/29/2010
-License This
-software component is licensed by ST under Ultimate Liberty license
-SLA0044, the "License"; You may not use this component except in
-compliance with the License. You may obtain a copy of the License at:
http://www.st.com/SLA0044
-
-
-
- For
- complete documentation on STM32
- Microcontrollers visit www.st.com/STM32
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/inc/usb_bsp.h b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/inc/usb_bsp.h
deleted file mode 100644
index 1bdb13da8..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/inc/usb_bsp.h
+++ /dev/null
@@ -1,105 +0,0 @@
-/**
- ******************************************************************************
- * @file usb_bsp.h
- * @author xiuos Team
- * @version V1.0.0
- * @date 2020-9-3
- * @brief Specific api's relative to the used hardware platform
- ******************************************************************************
- * @file usb_bsp.h
- * @author MCD Application Team
- * @version V1.0.0
- * @date 30-September-2011
- * ************************************************************************************
- * @attention
- *
- * © Copyright (c) 2015 STMicroelectronics.
- * All rights reserved.
- *
- * This software component is licensed by ST under Ultimate Liberty license
- * SLA0044, the "License"; You may not use this file except in compliance with
- * the License. You may obtain a copy of the License at:
- *
- *
- ******************************************************************************
- */
-
-/* Define to prevent recursive inclusion -------------------------------------*/
-#ifndef __USB_BSP__H__
-#define __USB_BSP__H__
-
-/* Includes ------------------------------------------------------------------*/
-#include "usb_core.h"
-
-/** @addtogroup USB_OTG_DRIVER
- * @{
- */
-
-/** @defgroup USB_BSP
- * @brief This file is the
- * @{
- */
-
-
-/** @defgroup USB_BSP_Exported_Defines
- * @{
- */
-/**
- * @}
- */
-
-
-/** @defgroup USB_BSP_Exported_Types
- * @{
- */
-/**
- * @}
- */
-
-
-/** @defgroup USB_BSP_Exported_Macros
- * @{
- */
-/**
- * @}
- */
-
-/** @defgroup USB_BSP_Exported_Variables
- * @{
- */
-/**
- * @}
- */
-
-/** @defgroup USB_BSP_Exported_FunctionsPrototype
- * @{
- */
-void BSP_Init(void);
-
-void USB_OTG_BSP_Init (USB_OTG_CORE_HANDLE *pdev);
-void USB_OTG_BSP_uDelay (const uint32_t usec);
-void USB_OTG_BSP_mDelay (const uint32_t msec);
-void USB_OTG_BSP_ENABLE_INTERRUPT (USB_OTG_CORE_HANDLE *pdev);
-void USB_OTG_BSP_TimerIRQ (void);
-#ifdef USE_HOST_MODE
-void USB_OTG_BSP_ConfigVBUS(USB_OTG_CORE_HANDLE *pdev);
-void USB_OTG_BSP_DriveVBUS(USB_OTG_CORE_HANDLE *pdev,uint8_t state);
-void USB_OTG_BSP_Resume(USB_OTG_CORE_HANDLE *pdev) ;
-void USB_OTG_BSP_Suspend(USB_OTG_CORE_HANDLE *pdev);
-
-#endif /* USE_HOST_MODE */
-/**
- * @}
- */
-
-#endif /* __USB_BSP__H__ */
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
-
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/inc/usb_conf.h b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/inc/usb_conf.h
deleted file mode 100644
index ec7e39df1..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/inc/usb_conf.h
+++ /dev/null
@@ -1,293 +0,0 @@
-/**
- ******************************************************************************
- * @file usb_conf.h
- * @author xiuos Team
- * @version V1.0.0
- * @date 2020-9-3
- * @brief General low level driver configuration
- ******************************************************************************
- * @file usb_conf.h
- * @author MCD Application Team
- * @version V1.0.0
- * @date 30-September-2011
- * ************************************************************************************
- * @attention
- *
- * © Copyright (c) 2015 STMicroelectronics.
- * All rights reserved.
- *
- * This software component is licensed by ST under Ultimate Liberty license
- * SLA0044, the "License"; You may not use this file except in compliance with
- * the License. You may obtain a copy of the License at:
- *
- *
- ******************************************************************************
- */
-
-/* Define to prevent recursive inclusion -------------------------------------*/
-#ifndef __USB_CONF__H__
-#define __USB_CONF__H__
-
-/* Includes ------------------------------------------------------------------*/
-#include
-
-/** @addtogroup USB_OTG_DRIVER
- * @{
- */
-
-/** @defgroup USB_CONF
- * @brief USB low level driver configuration file
- * @{
- */
-
-/** @defgroup USB_CONF_Exported_Defines
- * @{
- */
-
-/* USB Core and PHY interface configuration.
- Tip: To avoid modifying these defines each time you need to change the USB
- configuration, you can declare the needed define in your toolchain
- compiler preprocessor.
- */
-/****************** USB OTG FS PHY CONFIGURATION *******************************
-* The USB OTG FS Core supports one on-chip Full Speed PHY.
-*
-* The USE_EMBEDDED_PHY symbol is defined in the project compiler preprocessor
-* when FS core is used.
-*******************************************************************************/
-#ifndef USE_USB_OTG_FS
- #define USE_USB_OTG_FS
-#endif /* USE_USB_OTG_FS */
-
-#ifdef USE_USB_OTG_FS
- #define USB_OTG_FS_CORE
-#endif
-
-/****************** USB OTG HS PHY CONFIGURATION *******************************
-* The USB OTG HS Core supports two PHY interfaces:
-* (i) An ULPI interface for the external High Speed PHY: the USB HS Core will
-* operate in High speed mode
-* (ii) An on-chip Full Speed PHY: the USB HS Core will operate in Full speed mode
-*
-* You can select the PHY to be used using one of these two defines:
-* (i) USE_ULPI_PHY: if the USB OTG HS Core is to be used in High speed mode
-* (ii) USE_EMBEDDED_PHY: if the USB OTG HS Core is to be used in Full speed mode
-*
-* Notes:
-* - The USE_ULPI_PHY symbol is defined in the project compiler preprocessor as
-* default PHY when HS core is used.
-* - On STM322xG-EVAL and STM324xG-EVAL boards, only configuration(i) is available.
-* Configuration (ii) need a different hardware, for more details refer to your
-* STM32 device datasheet.
-*******************************************************************************/
-#ifndef USE_USB_OTG_HS
- //#define USE_USB_OTG_HS
-#endif /* USE_USB_OTG_HS */
-
-#ifndef USE_ULPI_PHY
- //#define USE_ULPI_PHY
-#endif /* USE_ULPI_PHY */
-
-#ifndef USE_EMBEDDED_PHY
- //#define USE_EMBEDDED_PHY
-#endif /* USE_EMBEDDED_PHY */
-
-#ifdef USE_USB_OTG_HS
- #define USB_OTG_HS_CORE
-#endif
-
-/*******************************************************************************
-* FIFO Size Configuration in Device mode
-*
-* (i) Receive data FIFO size = RAM for setup packets +
-* OUT endpoint control information +
-* data OUT packets + miscellaneous
-* Space = ONE 32-bits words
-* --> RAM for setup packets = 10 spaces
-* (n is the nbr of CTRL EPs the device core supports)
-* --> OUT EP CTRL info = 1 space
-* (one space for status information written to the FIFO along with each
-* received packet)
-* --> data OUT packets = (Largest Packet Size / 4) + 1 spaces
-* (MINIMUM to receive packets)
-* --> OR data OUT packets = at least 2*(Largest Packet Size / 4) + 1 spaces
-* (if high-bandwidth EP is enabled or multiple isochronous EPs)
-* --> miscellaneous = 1 space per OUT EP
-* (one space for transfer complete status information also pushed to the
-* FIFO with each endpoint's last packet)
-*
-* (ii)MINIMUM RAM space required for each IN EP Tx FIFO = MAX packet size for
-* that particular IN EP. More space allocated in the IN EP Tx FIFO results
-* in a better performance on the USB and can hide latencies on the AHB.
-*
-* (iii) TXn min size = 16 words. (n : Transmit FIFO index)
-* (iv) When a TxFIFO is not used, the Configuration should be as follows:
-* case 1 : n > m and Txn is not used (n,m : Transmit FIFO indexes)
-* --> Txm can use the space allocated for Txn.
-* case2 : n < m and Txn is not used (n,m : Transmit FIFO indexes)
-* --> Txn should be configured with the minimum space of 16 words
-* (v) The FIFO is used optimally when used TxFIFOs are allocated in the top
-* of the FIFO.Ex: use EP1 and EP2 as IN instead of EP1 and EP3 as IN ones.
-*******************************************************************************/
-
-/*******************************************************************************
-* FIFO Size Configuration in Host mode
-*
-* (i) Receive data FIFO size = (Largest Packet Size / 4) + 1 or
-* 2x (Largest Packet Size / 4) + 1, If a
-* high-bandwidth channel or multiple isochronous
-* channels are enabled
-*
-* (ii) For the host nonperiodic Transmit FIFO is the largest maximum packet size
-* for all supported nonperiodic OUT channels. Typically, a space
-* corresponding to two Largest Packet Size is recommended.
-*
-* (iii) The minimum amount of RAM required for Host periodic Transmit FIFO is
-* the largest maximum packet size for all supported periodic OUT channels.
-* If there is at least one High Bandwidth Isochronous OUT endpoint,
-* then the space must be at least two times the maximum packet size for
-* that channel.
-*******************************************************************************/
-
-/****************** USB OTG HS CONFIGURATION **********************************/
-#ifdef USB_OTG_HS_CORE
- #define RX_FIFO_HS_SIZE 512
- #define TX0_FIFO_HS_SIZE 512
- #define TX1_FIFO_HS_SIZE 512
- #define TX2_FIFO_HS_SIZE 0
- #define TX3_FIFO_HS_SIZE 0
- #define TX4_FIFO_HS_SIZE 0
- #define TX5_FIFO_HS_SIZE 0
- #define TXH_NP_HS_FIFOSIZ 96
- #define TXH_P_HS_FIFOSIZ 96
-
-// #define USB_OTG_HS_LOW_PWR_MGMT_SUPPORT
-// #define USB_OTG_HS_SOF_OUTPUT_ENABLED
-
-// #define USB_OTG_INTERNAL_VBUS_ENABLED
- #define USB_OTG_EXTERNAL_VBUS_ENABLED
-
- #ifdef USE_ULPI_PHY
- #define USB_OTG_ULPI_PHY_ENABLED
- #endif
- #ifdef USE_EMBEDDED_PHY
- #define USB_OTG_EMBEDDED_PHY_ENABLED
- #endif
- #define USB_OTG_HS_INTERNAL_DMA_ENABLED
- #define USB_OTG_HS_DEDICATED_EP1_ENABLED
-#endif
-
-/****************** USB OTG FS CONFIGURATION **********************************/
-#ifdef USB_OTG_FS_CORE
- #define RX_FIFO_FS_SIZE 128
- #define TX0_FIFO_FS_SIZE 64
- #define TX1_FIFO_FS_SIZE 128
- #define TX2_FIFO_FS_SIZE 0
- #define TX3_FIFO_FS_SIZE 0
- #define TXH_NP_FS_FIFOSIZ 96
- #define TXH_P_FS_FIFOSIZ 96
-
-// #define USB_OTG_FS_LOW_PWR_MGMT_SUPPORT
-// #define USB_OTG_FS_SOF_OUTPUT_ENABLED
-#endif
-
-/****************** USB OTG MISC CONFIGURATION ********************************/
-//#define VBUS_SENSING_ENABLED
-
-/****************** USB OTG MODE CONFIGURATION ********************************/
-#define USE_HOST_MODE
-// #define USE_DEVICE_MODE
-//#define USE_OTG_MODE
-
-#ifndef USB_OTG_FS_CORE
- #ifndef USB_OTG_HS_CORE
- #error "USB_OTG_HS_CORE or USB_OTG_FS_CORE should be defined"
- #endif
-#endif
-
-#ifndef USE_DEVICE_MODE
- #ifndef USE_HOST_MODE
- #error "USE_DEVICE_MODE or USE_HOST_MODE should be defined"
- #endif
-#endif
-
-#ifndef USE_USB_OTG_HS
- #ifndef USE_USB_OTG_FS
- #error "USE_USB_OTG_HS or USE_USB_OTG_FS should be defined"
- #endif
-#else //USE_USB_OTG_HS
- #ifndef USE_ULPI_PHY
- #ifndef USE_EMBEDDED_PHY
- #error "USE_ULPI_PHY or USE_EMBEDDED_PHY should be defined"
- #endif
- #endif
-#endif
-
-/****************** C Compilers dependant keywords ****************************/
-/* In HS mode and when the DMA is used, all variables and data structures dealing
- with the DMA during the transaction process should be 4-bytes aligned */
-#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
- #if defined (__GNUC__) /* GNU Compiler */
- #define __ALIGN_END __attribute__ ((aligned (4)))
- #define __ALIGN_BEGIN
- #else
- #define __ALIGN_END
-
- #endif /* __GNUC__ */
-#else
- #define __ALIGN_BEGIN
- #define __ALIGN_END
-#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
-
-
-#if defined ( __GNUC__ ) /* GNU Compiler */
- #define __packed __attribute__ ((__packed__))
-#endif
-
-/**
- * @}
- */
-
-
-/** @defgroup USB_CONF_Exported_Types
- * @{
- */
-/**
- * @}
- */
-
-
-/** @defgroup USB_CONF_Exported_Macros
- * @{
- */
-/**
- * @}
- */
-
-/** @defgroup USB_CONF_Exported_Variables
- * @{
- */
-/**
- * @}
- */
-
-/** @defgroup USB_CONF_Exported_FunctionsPrototype
- * @{
- */
-/**
- * @}
- */
-
-
-#endif //__USB_CONF__H__
-
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
-
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/inc/usb_conf_template.h b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/inc/usb_conf_template.h
deleted file mode 100644
index ea5272819..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/inc/usb_conf_template.h
+++ /dev/null
@@ -1,294 +0,0 @@
-/**
- ******************************************************************************
- * @file usb_conf_template.h
- * @author xiuos Team
- * @version V1.0.0
- * @date 2020-9-3
- * @brief General low level driver configuration
- ******************************************************************************
- * @file usb_conf_template.h
- * @author MCD Application Team
- * @version V1.0.0
- * @date 30-September-2011
- * ********************************************************************************
- * @attention
- *
- * © Copyright (c) 2015 STMicroelectronics.
- * All rights reserved.
- *
- * This software component is licensed by ST under Ultimate Liberty license
- * SLA0044, the "License"; You may not use this file except in compliance with
- * the License. You may obtain a copy of the License at:
- *
- *
- ******************************************************************************
- */
-
-/* Define to prevent recursive inclusion -------------------------------------*/
-#ifndef __USB_CONF__H__
-#define __USB_CONF__H__
-
-/* Includes ------------------------------------------------------------------*/
-#include "usb_conf.h"
-
-/** @addtogroup USB_OTG_DRIVER
- * @{
- */
-
-/** @defgroup USB_CONF
- * @brief USB low level driver configuration file
- * @{
- */
-
-/** @defgroup USB_CONF_Exported_Defines
- * @{
- */
-
-/* USB Core and PHY interface configuration.
- Tip: To avoid modifying these defines each time you need to change the USB
- configuration, you can declare the needed define in your toolchain
- compiler preprocessor.
- */
-/****************** USB OTG FS PHY CONFIGURATION *******************************
-* The USB OTG FS Core supports one on-chip Full Speed PHY.
-*
-* The USE_EMBEDDED_PHY symbol is defined in the project compiler preprocessor
-* when FS core is used.
-*******************************************************************************/
-#ifndef USE_USB_OTG_FS
- //#define USE_USB_OTG_FS
-#endif /* USE_USB_OTG_FS */
-
-#ifdef USE_USB_OTG_FS
- #define USB_OTG_FS_CORE
-#endif
-
-/****************** USB OTG HS PHY CONFIGURATION *******************************
-* The USB OTG HS Core supports two PHY interfaces:
-* (i) An ULPI interface for the external High Speed PHY: the USB HS Core will
-* operate in High speed mode
-* (ii) An on-chip Full Speed PHY: the USB HS Core will operate in Full speed mode
-*
-* You can select the PHY to be used using one of these two defines:
-* (i) USE_ULPI_PHY: if the USB OTG HS Core is to be used in High speed mode
-* (ii) USE_EMBEDDED_PHY: if the USB OTG HS Core is to be used in Full speed mode
-*
-* Notes:
-* - The USE_ULPI_PHY symbol is defined in the project compiler preprocessor as
-* default PHY when HS core is used.
-* - On STM322xG-EVAL and STM324xG-EVAL boards, only configuration(i) is available.
-* Configuration (ii) need a different hardware, for more details refer to your
-* STM32 device datasheet.
-*******************************************************************************/
-#ifndef USE_USB_OTG_HS
- //#define USE_USB_OTG_HS
-#endif /* USE_USB_OTG_HS */
-
-#ifndef USE_ULPI_PHY
- //#define USE_ULPI_PHY
-#endif /* USE_ULPI_PHY */
-
-#ifndef USE_EMBEDDED_PHY
- //#define USE_EMBEDDED_PHY
-#endif /* USE_EMBEDDED_PHY */
-
-#ifdef USE_USB_OTG_HS
- #define USB_OTG_HS_CORE
-#endif
-
-/*******************************************************************************
-* FIFO Size Configuration in Device mode
-*
-* (i) Receive data FIFO size = RAM for setup packets +
-* OUT endpoint control information +
-* data OUT packets + miscellaneous
-* Space = ONE 32-bits words
-* --> RAM for setup packets = 10 spaces
-* (n is the nbr of CTRL EPs the device core supports)
-* --> OUT EP CTRL info = 1 space
-* (one space for status information written to the FIFO along with each
-* received packet)
-* --> data OUT packets = (Largest Packet Size / 4) + 1 spaces
-* (MINIMUM to receive packets)
-* --> OR data OUT packets = at least 2*(Largest Packet Size / 4) + 1 spaces
-* (if high-bandwidth EP is enabled or multiple isochronous EPs)
-* --> miscellaneous = 1 space per OUT EP
-* (one space for transfer complete status information also pushed to the
-* FIFO with each endpoint's last packet)
-*
-* (ii)MINIMUM RAM space required for each IN EP Tx FIFO = MAX packet size for
-* that particular IN EP. More space allocated in the IN EP Tx FIFO results
-* in a better performance on the USB and can hide latencies on the AHB.
-*
-* (iii) TXn min size = 16 words. (n : Transmit FIFO index)
-* (iv) When a TxFIFO is not used, the Configuration should be as follows:
-* case 1 : n > m and Txn is not used (n,m : Transmit FIFO indexes)
-* --> Txm can use the space allocated for Txn.
-* case2 : n < m and Txn is not used (n,m : Transmit FIFO indexes)
-* --> Txn should be configured with the minimum space of 16 words
-* (v) The FIFO is used optimally when used TxFIFOs are allocated in the top
-* of the FIFO.Ex: use EP1 and EP2 as IN instead of EP1 and EP3 as IN ones.
-*******************************************************************************/
-
-/*******************************************************************************
-* FIFO Size Configuration in Host mode
-*
-* (i) Receive data FIFO size = (Largest Packet Size / 4) + 1 or
-* 2x (Largest Packet Size / 4) + 1, If a
-* high-bandwidth channel or multiple isochronous
-* channels are enabled
-*
-* (ii) For the host nonperiodic Transmit FIFO is the largest maximum packet size
-* for all supported nonperiodic OUT channels. Typically, a space
-* corresponding to two Largest Packet Size is recommended.
-*
-* (iii) The minimum amount of RAM required for Host periodic Transmit FIFO is
-* the largest maximum packet size for all supported periodic OUT channels.
-* If there is at least one High Bandwidth Isochronous OUT endpoint,
-* then the space must be at least two times the maximum packet size for
-* that channel.
-*******************************************************************************/
-
-/****************** USB OTG HS CONFIGURATION **********************************/
-#ifdef USB_OTG_HS_CORE
- #define RX_FIFO_HS_SIZE 512
- #define TX0_FIFO_HS_SIZE 512
- #define TX1_FIFO_HS_SIZE 512
- #define TX2_FIFO_HS_SIZE 0
- #define TX3_FIFO_HS_SIZE 0
- #define TX4_FIFO_HS_SIZE 0
- #define TX5_FIFO_HS_SIZE 0
- #define TXH_NP_HS_FIFOSIZ 96
- #define TXH_P_HS_FIFOSIZ 96
-
-// #define USB_OTG_HS_LOW_PWR_MGMT_SUPPORT
-// #define USB_OTG_HS_SOF_OUTPUT_ENABLED
-
-// #define USB_OTG_INTERNAL_VBUS_ENABLED
- #define USB_OTG_EXTERNAL_VBUS_ENABLED
-
- #ifdef USE_ULPI_PHY
- #define USB_OTG_ULPI_PHY_ENABLED
- #endif
- #ifdef USE_EMBEDDED_PHY
- #define USB_OTG_EMBEDDED_PHY_ENABLED
- #endif
- #define USB_OTG_HS_INTERNAL_DMA_ENABLED
- #define USB_OTG_HS_DEDICATED_EP1_ENABLED
-#endif
-
-/****************** USB OTG FS CONFIGURATION **********************************/
-#ifdef USB_OTG_FS_CORE
- #define RX_FIFO_FS_SIZE 128
- #define TX0_FIFO_FS_SIZE 64
- #define TX1_FIFO_FS_SIZE 128
- #define TX2_FIFO_FS_SIZE 0
- #define TX3_FIFO_FS_SIZE 0
- #define TXH_NP_HS_FIFOSIZ 96
- #define TXH_P_HS_FIFOSIZ 96
-
-// #define USB_OTG_FS_LOW_PWR_MGMT_SUPPORT
-// #define USB_OTG_FS_SOF_OUTPUT_ENABLED
-#endif
-
-/****************** USB OTG MISC CONFIGURATION ********************************/
-//#define VBUS_SENSING_ENABLED
-
-/****************** USB OTG MODE CONFIGURATION ********************************/
-//#define USE_HOST_MODE
-#define USE_DEVICE_MODE
-//#define USE_OTG_MODE
-
-#ifndef USB_OTG_FS_CORE
- #ifndef USB_OTG_HS_CORE
- #error "USB_OTG_HS_CORE or USB_OTG_FS_CORE should be defined"
- #endif
-#endif
-
-#ifndef USE_DEVICE_MODE
- #ifndef USE_HOST_MODE
- #error "USE_DEVICE_MODE or USE_HOST_MODE should be defined"
- #endif
-#endif
-
-#ifndef USE_USB_OTG_HS
- #ifndef USE_USB_OTG_FS
- #error "USE_USB_OTG_HS or USE_USB_OTG_FS should be defined"
- #endif
-#else //USE_USB_OTG_HS
- #ifndef USE_ULPI_PHY
- #ifndef USE_EMBEDDED_PHY
- #error "USE_ULPI_PHY or USE_EMBEDDED_PHY should be defined"
- #endif
- #endif
-#endif
-
-/****************** C Compilers dependant keywords ****************************/
-/* In HS mode and when the DMA is used, all variables and data structures dealing
- with the DMA during the transaction process should be 4-bytes aligned */
-#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
- #if defined (__GNUC__) /* GNU Compiler */
- #define __ALIGN_END __attribute__ ((aligned (4)))
- #define __ALIGN_BEGIN
- #else
- #define __ALIGN_END
-
- #endif /* __GNUC__ */
-#else
- #define __ALIGN_BEGIN
- #define __ALIGN_END
-#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
-
-/* __packed keyword used to decrease the data type alignment to 1-byte */
-
-#if defined ( __GNUC__ ) /* GNU Compiler */
- #define __packed __attribute__ ((__packed__))
-#endif
-
-/**
- * @}
- */
-
-
-/** @defgroup USB_CONF_Exported_Types
- * @{
- */
-/**
- * @}
- */
-
-
-/** @defgroup USB_CONF_Exported_Macros
- * @{
- */
-/**
- * @}
- */
-
-/** @defgroup USB_CONF_Exported_Variables
- * @{
- */
-/**
- * @}
- */
-
-/** @defgroup USB_CONF_Exported_FunctionsPrototype
- * @{
- */
-/**
- * @}
- */
-
-
-#endif //__USB_CONF__H__
-
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
-
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/inc/usb_core.h b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/inc/usb_core.h
deleted file mode 100644
index f48f73d04..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/inc/usb_core.h
+++ /dev/null
@@ -1,412 +0,0 @@
-/**
- ******************************************************************************
- * @file usb_core.h
- * @author xiuos Team
- * @version V1.0.0
- * @date 2020-9-3
- * @brief This file is based on usb_core.h
- * Header of the Core Layer
- ******************************************************************************
- * @file usb_core.h
- * @author MCD Application Team
- * @version V1.0.0
- * @date 30-September-2011
- * ********************************************************************************
- * @attention
- *
- * © Copyright (c) 2015 STMicroelectronics.
- * All rights reserved.
- *
- * This software component is licensed by ST under Ultimate Liberty license
- * SLA0044, the "License"; You may not use this file except in compliance with
- * the License. You may obtain a copy of the License at:
- *
- *
- ******************************************************************************
- */
-
-/* Define to prevent recursive inclusion -------------------------------------*/
-#ifndef __USB_CORE_H__
-#define __USB_CORE_H__
-
-/* Includes ------------------------------------------------------------------*/
-#include "usb_conf.h"
-#include "usb_regs.h"
-#include "usb_defines.h"
-
-
-/** @addtogroup USB_OTG_DRIVER
- * @{
- */
-
-/** @defgroup USB_CORE
- * @brief usb otg driver core layer
- * @{
- */
-
-
-/** @defgroup USB_CORE_Exported_Defines
- * @{
- */
-
-#define USB_OTG_EP0_IDLE 0
-#define USB_OTG_EP0_SETUP 1
-#define USB_OTG_EP0_DATA_IN 2
-#define USB_OTG_EP0_DATA_OUT 3
-#define USB_OTG_EP0_STATUS_IN 4
-#define USB_OTG_EP0_STATUS_OUT 5
-#define USB_OTG_EP0_STALL 6
-
-#define USB_OTG_EP_TX_DIS 0x0000
-#define USB_OTG_EP_TX_STALL 0x0010
-#define USB_OTG_EP_TX_NAK 0x0020
-#define USB_OTG_EP_TX_VALID 0x0030
-
-#define USB_OTG_EP_RX_DIS 0x0000
-#define USB_OTG_EP_RX_STALL 0x1000
-#define USB_OTG_EP_RX_NAK 0x2000
-#define USB_OTG_EP_RX_VALID 0x3000
-/**
- * @}
- */
-#define MAX_DATA_LENGTH 0x200
-
-/** @defgroup USB_CORE_Exported_Types
- * @{
- */
-
-
-typedef enum {
- USB_OTG_OK = 0,
- USB_OTG_FAIL
-}USB_OTG_STS;
-
-typedef enum {
- HC_IDLE = 0,
- HC_XFRC,
- HC_HALTED,
- HC_NAK,
- HC_NYET,
- HC_STALL,
- HC_XACTERR,
- HC_BBLERR,
- HC_DATATGLERR,
-}HC_STATUS;
-
-typedef enum {
- URB_IDLE = 0,
- URB_DONE,
- URB_NOTREADY,
- URB_ERROR,
- URB_STALL
-}URB_STATE;
-
-typedef enum {
- CTRL_START = 0,
- CTRL_XFRC,
- CTRL_HALTED,
- CTRL_NAK,
- CTRL_STALL,
- CTRL_XACTERR,
- CTRL_BBLERR,
- CTRL_DATATGLERR,
- CTRL_FAIL
-}CTRL_STATUS;
-
-
-typedef struct USB_OTG_hc
-{
- uint8_t DevAddr ;
- uint8_t ep_num;
- uint8_t ep_is_in;
- uint8_t speed;
- uint8_t do_ping;
- uint8_t ep_type;
- uint16_t max_packet;
- uint8_t data_pid;
- uint8_t *xfer_buff;
- uint32_t XferLen;
- uint32_t xfer_count;
- uint8_t toggle_in;
- uint8_t toggle_out;
- uint32_t dma_addr;
-}
-USB_OTG_HC , *PUSB_OTG_HC;
-
-typedef struct USB_OTG_ep
-{
- uint8_t num;
- uint8_t is_in;
- uint8_t is_stall;
- uint8_t type;
- uint8_t data_pid_start;
- uint8_t even_odd_frame;
- uint16_t tx_fifo_num;
- uint32_t maxpacket;
- /* transaction level variables*/
- uint8_t *xfer_buff;
- uint32_t dma_addr;
- uint32_t XferLen;
- uint32_t xfer_count;
- /* Transfer level variables*/
- uint32_t rem_data_len;
- uint32_t total_data_len;
- uint32_t ctl_data_len;
-
-}
-
-USB_OTG_EP , *PUSB_OTG_EP;
-
-
-
-typedef struct USB_OTG_core_cfg
-{
- uint8_t host_channels;
- uint8_t dev_endpoints;
- uint8_t speed;
- uint8_t dma_enable;
- uint16_t mps;
- uint16_t TotalFifoSize;
- uint8_t phy_itface;
- uint8_t Sof_output;
- uint8_t low_power;
- uint8_t coreID;
-
-}
-USB_OTG_CORE_CFGS, *PUSB_OTG_CORE_CFGS;
-
-
-
-typedef struct usb_setup_req {
-
- uint8_t bmRequest;
- uint8_t bRequest;
- uint16_t wValue;
- uint16_t wIndex;
- uint16_t wLength;
-} USB_SETUP_REQ;
-
-typedef struct _Device_TypeDef
-{
- uint8_t *(*GetDeviceDescriptor)( uint8_t speed , uint16_t *length);
- uint8_t *(*GetLangIDStrDescriptor)( uint8_t speed , uint16_t *length);
- uint8_t *(*GetManufacturerStrDescriptor)( uint8_t speed , uint16_t *length);
- uint8_t *(*GetProductStrDescriptor)( uint8_t speed , uint16_t *length);
- uint8_t *(*GetSerialStrDescriptor)( uint8_t speed , uint16_t *length);
- uint8_t *(*GetConfigurationStrDescriptor)( uint8_t speed , uint16_t *length);
- uint8_t *(*GetInterfaceStrDescriptor)( uint8_t speed , uint16_t *length);
-
-#if (USBD_LPM_ENABLED == 1)
- uint8_t *(*GetBOSDescriptor)( uint8_t speed , uint16_t *length);
-#endif
-} USBD_DEVICE, *pUSBD_DEVICE;
-
-typedef struct _Device_cb
-{
- uint8_t (*Init) (void *pdev , uint8_t cfgidx);
- uint8_t (*DeInit) (void *pdev , uint8_t cfgidx);
- /* Control Endpoints*/
- uint8_t (*Setup) (void *pdev , USB_SETUP_REQ *req);
- uint8_t (*EP0_TxSent) (void *pdev );
- uint8_t (*EP0_RxReady) (void *pdev );
- /* Class Specific Endpoints*/
- uint8_t (*DataIn) (void *pdev , uint8_t epnum);
- uint8_t (*DataOut) (void *pdev , uint8_t epnum);
- uint8_t (*SOF) (void *pdev);
- uint8_t (*IsoINIncomplete) (void *pdev);
- uint8_t (*IsoOUTIncomplete) (void *pdev);
-
- uint8_t *(*GetConfigDescriptor)( uint8_t speed , uint16_t *length);
-#ifdef USB_OTG_HS_CORE
- uint8_t *(*GetOtherConfigDescriptor)( uint8_t speed , uint16_t *length);
-#endif
-
-#ifdef USB_SUPPORT_USER_STRING_DESC
- uint8_t *(*GetUsrStrDescriptor)( uint8_t speed ,uint8_t index, uint16_t *length);
-#endif
-
-} USBD_Class_cb_TypeDef;
-
-
-
-typedef struct _USBD_USR_PROP
-{
- void (*Init)(void);
- void (*DeviceReset)(uint8_t speed);
- void (*DeviceConfigured)(void);
- void (*DeviceSuspended)(void);
- void (*DeviceResumed)(void);
-
- void (*DeviceConnected)(void);
- void (*DeviceDisconnected)(void);
-
-}
-USBD_Usr_cb_TypeDef;
-
-typedef struct _DCD
-{
- uint8_t device_config;
- uint8_t device_state;
- uint8_t device_status;
- uint8_t device_old_status;
- uint8_t device_address;
- uint8_t connection_status;
- uint8_t test_mode;
- uint32_t DevRemoteWakeup;
- USB_OTG_EP in_ep [USB_OTG_MAX_TX_FIFOS];
- USB_OTG_EP out_ep [USB_OTG_MAX_TX_FIFOS];
- uint8_t setup_packet [8*3];
- USBD_Class_cb_TypeDef *class_cb;
- USBD_Usr_cb_TypeDef *usr_cb;
- USBD_DEVICE *usr_device;
- uint8_t *pConfig_descriptor;
- }
-DCD_DEV , *DCD_PDEV;
-
-
-typedef struct _HCD
-{
- uint8_t Rx_Buffer [MAX_DATA_LENGTH];
- __IO uint32_t ConnSts;
- __IO uint32_t PortEnabled;
- __IO uint32_t ErrCnt[USB_OTG_MAX_TX_FIFOS];
- __IO uint32_t XferCnt[USB_OTG_MAX_TX_FIFOS];
- __IO HC_STATUS HC_Status[USB_OTG_MAX_TX_FIFOS];
- __IO URB_STATE URB_State[USB_OTG_MAX_TX_FIFOS];
- USB_OTG_HC hc [USB_OTG_MAX_TX_FIFOS];
- uint16_t channel [USB_OTG_MAX_TX_FIFOS];
-}
-HCD_DEV , *USB_OTG_USBH_PDEV;
-
-
-typedef struct _OTG
-{
- uint8_t OTG_State;
- uint8_t OTG_PrevState;
- uint8_t OTG_Mode;
-}
-OTG_DEV , *USB_OTG_USBO_PDEV;
-
-typedef struct USB_OTG_handle
-{
- USB_OTG_CORE_CFGS cfg;
- USB_OTG_CORE_REGS regs;
-#ifdef USE_DEVICE_MODE
- DCD_DEV dev;
-#endif
-#ifdef USE_HOST_MODE
- HCD_DEV host;
-#endif
-#ifdef USE_OTG_MODE
- OTG_DEV otg;
-#endif
- void *data;
-}
-USB_OTG_CORE_HANDLE , *PUSB_OTG_CORE_HANDLE;
-
-/**
- * @}
- */
-
-
-/** @defgroup USB_CORE_Exported_Macros
- * @{
- */
-
-/**
- * @}
- */
-
-/** @defgroup USB_CORE_Exported_Variables
- * @{
- */
-/**
- * @}
- */
-
-/** @defgroup USB_CORE_Exported_FunctionsPrototype
- * @{
- */
-
-
-USB_OTG_STS USB_OTG_CoreInit (USB_OTG_CORE_HANDLE *pdev);
-USB_OTG_STS USB_OTG_SelectCore (USB_OTG_CORE_HANDLE *pdev,
- USB_OTG_CORE_ID_TypeDef coreID);
-USB_OTG_STS USB_OTG_EnableGlobalInt (USB_OTG_CORE_HANDLE *pdev);
-USB_OTG_STS USB_OTG_DisableGlobalInt(USB_OTG_CORE_HANDLE *pdev);
-void* USB_OTG_ReadPacket (USB_OTG_CORE_HANDLE *pdev ,
- uint8_t *dest,
- uint16_t len);
-USB_OTG_STS USB_OTG_WritePacket (USB_OTG_CORE_HANDLE *pdev ,
- uint8_t *src,
- uint8_t ch_ep_num,
- uint16_t len);
-USB_OTG_STS USB_OTG_FlushTxFifo (USB_OTG_CORE_HANDLE *pdev , uint32_t num);
-USB_OTG_STS USB_OTG_FlushRxFifo (USB_OTG_CORE_HANDLE *pdev);
-
-uint32_t USB_OTG_ReadCoreItr (USB_OTG_CORE_HANDLE *pdev);
-uint32_t USB_OTG_ReadOtgItr (USB_OTG_CORE_HANDLE *pdev);
-uint8_t USB_OTG_IsHostMode (USB_OTG_CORE_HANDLE *pdev);
-uint8_t USB_OTG_IsDeviceMode (USB_OTG_CORE_HANDLE *pdev);
-uint32_t USB_OTG_GetMode (USB_OTG_CORE_HANDLE *pdev);
-USB_OTG_STS USB_OTG_PhyInit (USB_OTG_CORE_HANDLE *pdev);
-USB_OTG_STS USB_OTG_SetCurrentMode (USB_OTG_CORE_HANDLE *pdev,
- uint8_t mode);
-
-/*********************** HOST APIs ********************************************/
-#ifdef USE_HOST_MODE
-USB_OTG_STS USB_OTG_CoreInitHost (USB_OTG_CORE_HANDLE *pdev);
-USB_OTG_STS USB_OTG_EnableHostInt (USB_OTG_CORE_HANDLE *pdev);
-USB_OTG_STS USB_OTG_HC_Init (USB_OTG_CORE_HANDLE *pdev, uint8_t hc_num);
-USB_OTG_STS USB_OTG_HC_Halt (USB_OTG_CORE_HANDLE *pdev, uint8_t hc_num);
-USB_OTG_STS USB_OTG_HC_StartXfer (USB_OTG_CORE_HANDLE *pdev, uint8_t hc_num);
-USB_OTG_STS USB_OTG_HC_DoPing (USB_OTG_CORE_HANDLE *pdev , uint8_t hc_num);
-uint32_t USB_OTG_ReadHostAllChannels_intr (USB_OTG_CORE_HANDLE *pdev);
-uint32_t USB_OTG_ResetPort (USB_OTG_CORE_HANDLE *pdev);
-uint32_t USB_OTG_ReadHPRT0 (USB_OTG_CORE_HANDLE *pdev);
-void USB_OTG_DriveVbus (USB_OTG_CORE_HANDLE *pdev, uint8_t state);
-void USB_OTG_InitFSLSPClkSel (USB_OTG_CORE_HANDLE *pdev ,uint8_t freq);
-uint8_t USB_OTG_IsEvenFrame (USB_OTG_CORE_HANDLE *pdev) ;
-void USB_OTG_StopHost (USB_OTG_CORE_HANDLE *pdev);
-#endif
-/********************* DEVICE APIs ********************************************/
-#ifdef USE_DEVICE_MODE
-USB_OTG_STS USB_OTG_CoreInitDev (USB_OTG_CORE_HANDLE *pdev);
-USB_OTG_STS USB_OTG_EnableDevInt (USB_OTG_CORE_HANDLE *pdev);
-uint32_t USB_OTG_ReadDevAllInEPItr (USB_OTG_CORE_HANDLE *pdev);
-enum USB_OTG_SPEED USB_OTG_GetDeviceSpeed (USB_OTG_CORE_HANDLE *pdev);
-USB_OTG_STS USB_OTG_EP0Activate (USB_OTG_CORE_HANDLE *pdev);
-USB_OTG_STS USB_OTG_EPActivate (USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep);
-USB_OTG_STS USB_OTG_EPDeactivate(USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep);
-USB_OTG_STS USB_OTG_EPStartXfer (USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep);
-USB_OTG_STS USB_OTG_EP0StartXfer(USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep);
-USB_OTG_STS USB_OTG_EPSetStall (USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep);
-USB_OTG_STS USB_OTG_EPClearStall (USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep);
-uint32_t USB_OTG_ReadDevAllOutEp_itr (USB_OTG_CORE_HANDLE *pdev);
-uint32_t USB_OTG_ReadDevOutEP_itr (USB_OTG_CORE_HANDLE *pdev , uint8_t epnum);
-uint32_t USB_OTG_ReadDevAllInEPItr (USB_OTG_CORE_HANDLE *pdev);
-void USB_OTG_InitDevSpeed (USB_OTG_CORE_HANDLE *pdev , uint8_t speed);
-uint8_t USBH_IsEvenFrame (USB_OTG_CORE_HANDLE *pdev);
-void USB_OTG_EP0_OutStart(USB_OTG_CORE_HANDLE *pdev);
-void USB_OTG_ActiveRemoteWakeup(USB_OTG_CORE_HANDLE *pdev);
-void USB_OTG_UngateClock(USB_OTG_CORE_HANDLE *pdev);
-void USB_OTG_StopDevice(USB_OTG_CORE_HANDLE *pdev);
-void USB_OTG_SetEPStatus (USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep , uint32_t Status);
-uint32_t USB_OTG_GetEPStatus(USB_OTG_CORE_HANDLE *pdev ,USB_OTG_EP *ep);
-#endif
-/**
- * @}
- */
-
-#endif /* __USB_CORE_H__ */
-
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
-
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/inc/usb_dcd.h b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/inc/usb_dcd.h
deleted file mode 100644
index 9e5bf5eb5..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/inc/usb_dcd.h
+++ /dev/null
@@ -1,164 +0,0 @@
-/**
- ******************************************************************************
- * @file usb_dcd.h
- * @author xiuos Team
- * @version V1.0.0
- * @date 2020-9-3
- * @brief This file is based on usb_dcd.h
- * Peripheral Driver Header file
- ******************************************************************************
- * @file usb_dcd.h
- * @author MCD Application Team
- * @version V1.0.0
- * @date 30-September-2011
- * ********************************************************************************
- * @attention
- *
- * © Copyright (c) 2015 STMicroelectronics.
- * All rights reserved.
- *
- * This software component is licensed by ST under Ultimate Liberty license
- * SLA0044, the "License"; You may not use this file except in compliance with
- * the License. You may obtain a copy of the License at:
- *
- *
- ******************************************************************************
- */
-
-/* Define to prevent recursive inclusion -------------------------------------*/
-#ifndef __DCD_H__
-#define __DCD_H__
-
-/* Includes ------------------------------------------------------------------*/
-#include "usb_core.h"
-
-
-/** @addtogroup USB_OTG_DRIVER
-* @{
-*/
-
-/** @defgroup USB_DCD
-* @brief This file is the
-* @{
-*/
-
-
-/** @defgroup USB_DCD_Exported_Defines
-* @{
-*/
-#define USB_OTG_EP_CONTROL 0
-#define USB_OTG_EP_ISOC 1
-#define USB_OTG_EP_BULK 2
-#define USB_OTG_EP_INT 3
-#define USB_OTG_EP_MASK 3
-
-/* Device Status */
-#define USB_OTG_DEFAULT 1
-#define USB_OTG_ADDRESSED 2
-#define USB_OTG_CONFIGURED 3
-#define USB_OTG_SUSPENDED 4
-
-/**
-* @}
-*/
-
-
-/** @defgroup USB_DCD_Exported_Types
-* @{
-*/
-/********************************************************************************
-Data structure type
-********************************************************************************/
-typedef struct
-{
- uint8_t bLength;
- uint8_t bDescriptorType;
- uint8_t bEndpointAddress;
- uint8_t bmAttributes;
- uint16_t wMaxPacketSize;
- uint8_t bInterval;
-}
-EP_DESCRIPTOR , *PEP_DESCRIPTOR;
-
-/**
-* @}
-*/
-
-
-/** @defgroup USB_DCD_Exported_Macros
-* @{
-*/
-/**
-* @}
-*/
-
-/** @defgroup USB_DCD_Exported_Variables
-* @{
-*/
-/**
-* @}
-*/
-
-/** @defgroup USB_DCD_Exported_FunctionsPrototype
-* @{
-*/
-/********************************************************************************
-EXPORTED FUNCTION FROM THE USB-OTG LAYER
-********************************************************************************/
-void DCD_Init(USB_OTG_CORE_HANDLE *pdev ,
- USB_OTG_CORE_ID_TypeDef coreID);
-
-void DCD_DevConnect (USB_OTG_CORE_HANDLE *pdev);
-void DCD_DevDisconnect (USB_OTG_CORE_HANDLE *pdev);
-void DCD_EP_SetAddress (USB_OTG_CORE_HANDLE *pdev,
- uint8_t address);
-uint32_t DCD_EP_Open(USB_OTG_CORE_HANDLE *pdev ,
- uint8_t EpAddr,
- uint16_t ep_mps,
- uint8_t ep_type);
-
-uint32_t DCD_EP_Close (USB_OTG_CORE_HANDLE *pdev,
- uint8_t EpAddr);
-
-
-uint32_t DCD_EP_PrepareRx ( USB_OTG_CORE_HANDLE *pdev,
- uint8_t EpAddr,
- uint8_t *pbuf,
- uint16_t BufLen);
-
-uint32_t DCD_EP_Tx (USB_OTG_CORE_HANDLE *pdev,
- uint8_t EpAddr,
- uint8_t *pbuf,
- uint32_t BufLen);
-uint32_t DCD_EP_Stall (USB_OTG_CORE_HANDLE *pdev,
- uint8_t epnum);
-uint32_t DCD_EP_ClrStall (USB_OTG_CORE_HANDLE *pdev,
- uint8_t epnum);
-uint32_t DCD_EP_Flush (USB_OTG_CORE_HANDLE *pdev,
- uint8_t epnum);
-uint32_t DCD_Handle_ISR(USB_OTG_CORE_HANDLE *pdev);
-
-uint32_t DCD_GetEPStatus(USB_OTG_CORE_HANDLE *pdev ,
- uint8_t epnum);
-
-void DCD_SetEPStatus (USB_OTG_CORE_HANDLE *pdev ,
- uint8_t epnum ,
- uint32_t Status);
-
-/**
-* @}
-*/
-
-
-#endif /* __DCD_H__ */
-
-
-/**
-* @}
-*/
-
-/**
-* @}
-*/
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
-
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/inc/usb_dcd_int.h b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/inc/usb_dcd_int.h
deleted file mode 100644
index 017cbb128..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/inc/usb_dcd_int.h
+++ /dev/null
@@ -1,128 +0,0 @@
-/**
- ******************************************************************************
- * @file usb_dcd_int.h
- * @author xiuos Team
- * @version V1.0.0
- * @date 2020-9-3
- * @brief This file is based on usb_dcd_int.h
- * Peripheral Device Interface Layer
- ******************************************************************************
- * @file usb_dcd_int.h
- * @author MCD Application Team
- * @version V1.0.0
- * @date 30-September-2011
- * ********************************************************************************
- * @attention
- *
- * © Copyright (c) 2015 STMicroelectronics.
- * All rights reserved.
- *
- * This software component is licensed by ST under Ultimate Liberty license
- * SLA0044, the "License"; You may not use this file except in compliance with
- * the License. You may obtain a copy of the License at:
- *
- *
- ******************************************************************************
- */
-
-/* Define to prevent recursive inclusion -------------------------------------*/
-#ifndef USB_DCD_INT_H__
-#define USB_DCD_INT_H__
-
-/* Includes ------------------------------------------------------------------*/
-#include "usb_dcd.h"
-
-
-
-/** @addtogroup USB_OTG_DRIVER
- * @{
- */
-
-/** @defgroup USB_DCD_INT
- * @brief This file is the
- * @{
- */
-
-
-/** @defgroup USB_DCD_INT_Exported_Defines
- * @{
- */
-
-typedef struct _USBD_DCD_INT
-{
- uint8_t (* DataOutStage) (USB_OTG_CORE_HANDLE *pdev , uint8_t epnum);
- uint8_t (* DataInStage) (USB_OTG_CORE_HANDLE *pdev , uint8_t epnum);
- uint8_t (* SetupStage) (USB_OTG_CORE_HANDLE *pdev);
- uint8_t (* SOF) (USB_OTG_CORE_HANDLE *pdev);
- uint8_t (* Reset) (USB_OTG_CORE_HANDLE *pdev);
- uint8_t (* Suspend) (USB_OTG_CORE_HANDLE *pdev);
- uint8_t (* Resume) (USB_OTG_CORE_HANDLE *pdev);
- uint8_t (* IsoINIncomplete) (USB_OTG_CORE_HANDLE *pdev);
- uint8_t (* IsoOUTIncomplete) (USB_OTG_CORE_HANDLE *pdev);
-
- uint8_t (* DevConnected) (USB_OTG_CORE_HANDLE *pdev);
- uint8_t (* DevDisconnected) (USB_OTG_CORE_HANDLE *pdev);
-
-}USBD_DCD_INT_cb_TypeDef;
-
-extern USBD_DCD_INT_cb_TypeDef *USBD_DCD_INT_fops;
-/**
- * @}
- */
-
-
-/** @defgroup USB_DCD_INT_Exported_Types
- * @{
- */
-/**
- * @}
- */
-
-/** @defgroup USB_DCD_INT_Exported_Macros
- * @{
- */
-
-#define CLEAR_IN_EP_INTR(epnum,intr) \
- diepint.d32=0; \
- diepint.b.intr = 1; \
- USB_OTG_WRITE_REG32(&pdev->regs.INEP_REGS[epnum]->DIEPINT,diepint.d32);
-
-#define CLEAR_OUT_EP_INTR(epnum,intr) \
- doepint.d32=0; \
- doepint.b.intr = 1; \
- USB_OTG_WRITE_REG32(&pdev->regs.OUTEP_REGS[(epnum)]->DOEPINT,doepint.d32);
-
-/**
- * @}
- */
-
-/** @defgroup USB_DCD_INT_Exported_Variables
- * @{
- */
-/**
- * @}
- */
-
-/** @defgroup USB_DCD_INT_Exported_FunctionsPrototype
- * @{
- */
-
-uint32_t USBD_OTG_ISR_Handler (USB_OTG_CORE_HANDLE *pdev);
-uint32_t USBD_OTG_EP1OUT_ISR_Handler (USB_OTG_CORE_HANDLE *pdev);
-uint32_t USBD_OTG_EP1IN_ISR_Handler (USB_OTG_CORE_HANDLE *pdev);
-/**
- * @}
- */
-
-
-#endif /* USB_DCD_INT_H__ */
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
-
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/inc/usb_defines.h b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/inc/usb_defines.h
deleted file mode 100644
index 8caf31fc2..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/inc/usb_defines.h
+++ /dev/null
@@ -1,271 +0,0 @@
-/**
- ******************************************************************************
- * @file usb_defines.h
- * @author xiuos Team
- * @version V1.0.0
- * @date 2020-9-3
- * @brief Header of the Core Layer
- ******************************************************************************
- * @file usb_defines.h
- * @author MCD Application Team
- * @version V1.0.0
- * @date 30-September-2011
- * ********************************************************************************
- * @attention
- *
- * © Copyright (c) 2015 STMicroelectronics.
- * All rights reserved.
- *
- * This software component is licensed by ST under Ultimate Liberty license
- * SLA0044, the "License"; You may not use this file except in compliance with
- * the License. You may obtain a copy of the License at:
- *
- *
- ******************************************************************************
- */
-
-/* Define to prevent recursive inclusion -------------------------------------*/
-#ifndef __USB_DEF_H__
-#define __USB_DEF_H__
-
-/* Includes ------------------------------------------------------------------*/
-#include "usb_conf.h"
-
-/** @addtogroup USB_OTG_DRIVER
- * @{
- */
-
-/** @defgroup USB_DEFINES
- * @brief This file is the
- * @{
- */
-
-
-/** @defgroup USB_DEFINES_Exported_Defines
- * @{
- */
-/**
- * @}
- */
-
-
-/** @defgroup _CORE_DEFINES_
- * @{
- */
-
-#define USB_OTG_SPEED_PARAM_HIGH 0
-#define USB_OTG_SPEED_PARAM_HIGH_IN_FULL 1
-#define USB_OTG_SPEED_PARAM_FULL 3
-
-#define USB_OTG_SPEED_HIGH 0
-#define USB_OTG_SPEED_FULL 1
-
-#define USB_OTG_ULPI_PHY 1
-#define USB_OTG_EMBEDDED_PHY 2
-
-/**
- * @}
- */
-
-
-/** @defgroup _GLOBAL_DEFINES_
- * @{
- */
-#define GAHBCFG_TXFEMPTYLVL_EMPTY 1
-#define GAHBCFG_TXFEMPTYLVL_HALFEMPTY 0
-#define GAHBCFG_GLBINT_ENABLE 1
-#define GAHBCFG_INT_DMA_BURST_SINGLE 0
-#define GAHBCFG_INT_DMA_BURST_INCR 1
-#define GAHBCFG_INT_DMA_BURST_INCR4 3
-#define GAHBCFG_INT_DMA_BURST_INCR8 5
-#define GAHBCFG_INT_DMA_BURST_INCR16 7
-#define GAHBCFG_DMAENABLE 1
-#define GAHBCFG_TXFEMPTYLVL_EMPTY 1
-#define GAHBCFG_TXFEMPTYLVL_HALFEMPTY 0
-#define GRXSTS_PKTSTS_IN 2
-#define GRXSTS_PKTSTS_IN_XFER_COMP 3
-#define GRXSTS_PKTSTS_DATA_TOGGLE_ERR 5
-#define GRXSTS_PKTSTS_CH_HALTED 7
-/**
- * @}
- */
-
-
-/** @defgroup _OnTheGo_DEFINES_
- * @{
- */
-#define MODE_HNP_SRP_CAPABLE 0
-#define MODE_SRP_ONLY_CAPABLE 1
-#define MODE_NO_HNP_SRP_CAPABLE 2
-#define MODE_SRP_CAPABLE_DEVICE 3
-#define MODE_NO_SRP_CAPABLE_DEVICE 4
-#define MODE_SRP_CAPABLE_HOST 5
-#define MODE_NO_SRP_CAPABLE_HOST 6
-#define A_HOST 1
-#define A_SUSPEND 2
-#define A_PERIPHERAL 3
-#define B_PERIPHERAL 4
-#define B_HOST 5
-#define DEVICE_MODE 0
-#define HOST_MODE 1
-#define OTG_MODE 2
-/**
- * @}
- */
-
-
-/** @defgroup __DEVICE_DEFINES_
- * @{
- */
-#define DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ 0
-#define DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ 1
-#define DSTS_ENUMSPD_LS_PHY_6MHZ 2
-#define DSTS_ENUMSPD_FS_PHY_48MHZ 3
-
-#define DCFG_FRAME_INTERVAL_80 0
-#define DCFG_FRAME_INTERVAL_85 1
-#define DCFG_FRAME_INTERVAL_90 2
-#define DCFG_FRAME_INTERVAL_95 3
-
-#define DEP0CTL_MPS_64 0
-#define DEP0CTL_MPS_32 1
-#define DEP0CTL_MPS_16 2
-#define DEP0CTL_MPS_8 3
-
-#define EP_SPEED_LOW 0
-#define EP_SPEED_FULL 1
-#define EP_SPEED_HIGH 2
-
-#define EP_TYPE_CTRL 0
-#define EP_TYPE_ISOC 1
-#define EP_TYPE_BULK 2
-#define EP_TYPE_INTR 3
-#define EP_TYPE_MSK 3
-
-#define STS_GOUT_NAK 1
-#define STS_DATA_UPDT 2
-#define STS_XFER_COMP 3
-#define STS_SETUP_COMP 4
-#define STS_SETUP_UPDT 6
-/**
- * @}
- */
-
-
-/** @defgroup __HOST_DEFINES_
- * @{
- */
-#define HC_PID_DATA0 0
-#define HC_PID_DATA2 1
-#define HC_PID_DATA1 2
-#define HC_PID_SETUP 3
-
-#define HPRT0_PRTSPD_HIGH_SPEED 0
-#define HPRT0_PRTSPD_FULL_SPEED 1
-#define HPRT0_PRTSPD_LOW_SPEED 2
-
-#define HCFG_30_60_MHZ 0
-#define HCFG_48_MHZ 1
-#define HCFG_6_MHZ 2
-
-#define HCCHAR_CTRL 0
-#define HCCHAR_ISOC 1
-#define HCCHAR_BULK 2
-#define HCCHAR_INTR 3
-
-#ifndef MIN
-#define MIN(a, b) (((a) < (b)) ? (a) : (b))
-#endif
-
-/**
- * @}
- */
-
-
-/** @defgroup USB_DEFINES_Exported_Types
- * @{
- */
-
-typedef enum
-{
- USB_OTG_HS_CORE_ID = 0,
- USB_OTG_FS_CORE_ID = 1
-}USB_OTG_CORE_ID_TypeDef;
-/**
- * @}
- */
-
-
-/** @defgroup USB_DEFINES_Exported_Macros
- * @{
- */
-/**
- * @}
- */
-
-/** @defgroup USB_DEFINES_Exported_Variables
- * @{
- */
-/**
- * @}
- */
-
-/** @defgroup USB_DEFINES_Exported_FunctionsPrototype
- * @{
- */
-/**
- * @}
- */
-
-
-/** @defgroup Internal_Macro's
- * @{
- */
-#define USB_OTG_READ_REG32(reg) (*(__IO uint32_t *)(reg))
-
-// #define DEBUG_USB_REG
-
-#ifndef DEBUG_USB_REG
-#define USB_OTG_WRITE_REG32(reg,value) (*(__IO uint32_t *)(reg) = (value))
-#else
-#define DO_USB_OTG_WRITE_REG32(reg,value) (*(__IO uint32_t *)(reg) = (value))
-#define USB_OTG_WRITE_REG32(reg,value) \
- do { \
- uint32_t tmpreg = USB_OTG_READ_REG32(reg); \
- rt_kprintf( \
- "%s:\n" \
- " writing register " #reg " at address 0x%p:\n", \
- __func__, reg \
- ); \
- rt_kprintf(" written value: 0x%08X\n", value); \
- rt_kprintf(" old value: 0x%08X\n", tmpreg); \
- DO_USB_OTG_WRITE_REG32(reg, value); \
- rt_kprintf(" new value: 0x%08X\n", USB_OTG_READ_REG32(reg)); \
- } while (0)
-#endif
-
-#define USB_OTG_MODIFY_REG32(reg,clear_mask,set_mask) \
- USB_OTG_WRITE_REG32((reg), (((USB_OTG_READ_REG32(reg)) & ~(clear_mask)) | (set_mask)) )
-
-/********************************************************************************
- ENUMERATION TYPE
-********************************************************************************/
-enum USB_OTG_SPEED {
- USB_SPEED_UNKNOWN = 0,
- USB_SPEED_LOW,
- USB_SPEED_FULL,
- USB_SPEED_HIGH
-};
-
-#endif /* __USB_DEFINES__H__ */
-
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
-
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/inc/usb_hcd.h b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/inc/usb_hcd.h
deleted file mode 100644
index d8261d7f7..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/inc/usb_hcd.h
+++ /dev/null
@@ -1,110 +0,0 @@
-/**
- ******************************************************************************
- * @file usb_hcd.h
- * @author xiuos Team
- * @version V1.0.0
- * @date 2020-9-3
- * @brief This file is based on usb_hcd.h
- * Host layer Header file
- ******************************************************************************
- * @file usb_hcd.h
- * @author MCD Application Team
- * @version V1.0.0
- * @date 30-September-2011
- * ********************************************************************************
- * @attention
- *
- * © Copyright (c) 2015 STMicroelectronics.
- * All rights reserved.
- *
- * This software component is licensed by ST under Ultimate Liberty license
- * SLA0044, the "License"; You may not use this file except in compliance with
- * the License. You may obtain a copy of the License at:
- *
- *
- ******************************************************************************
- */
-
-/* Define to prevent recursive inclusion -------------------------------------*/
-#ifndef __USB_HCD_H__
-#define __USB_HCD_H__
-
-/* Includes ------------------------------------------------------------------*/
-#include "usb_regs.h"
-#include "usb_core.h"
-
-
-/** @addtogroup USB_OTG_DRIVER
- * @{
- */
-
-/** @defgroup USB_HCD
- * @brief This file is the
- * @{
- */
-
-
-/** @defgroup USB_HCD_Exported_Defines
- * @{
- */
-/**
- * @}
- */
-
-
-/** @defgroup USB_HCD_Exported_Types
- * @{
- */
-/**
- * @}
- */
-
-
-/** @defgroup USB_HCD_Exported_Macros
- * @{
- */
-/**
- * @}
- */
-
-/** @defgroup USB_HCD_Exported_Variables
- * @{
- */
-/**
- * @}
- */
-
-/** @defgroup USB_HCD_Exported_FunctionsPrototype
- * @{
- */
-uint32_t HCD_Init (USB_OTG_CORE_HANDLE *pdev ,
- USB_OTG_CORE_ID_TypeDef coreID);
-uint32_t HCD_HC_Init (USB_OTG_CORE_HANDLE *pdev ,
- uint8_t hc_num);
-uint32_t HCD_SubmitRequest (USB_OTG_CORE_HANDLE *pdev ,
- uint8_t hc_num) ;
-uint32_t HCD_GetCurrentSpeed (USB_OTG_CORE_HANDLE *pdev);
-uint32_t HCD_ResetPort (USB_OTG_CORE_HANDLE *pdev);
-uint32_t HCD_IsDeviceConnected (USB_OTG_CORE_HANDLE *pdev);
-uint32_t HCD_IsPortEnabled (USB_OTG_CORE_HANDLE *pdev);
-
-uint32_t HCD_GetCurrentFrame (USB_OTG_CORE_HANDLE *pdev) ;
-URB_STATE HCD_GetURB_State (USB_OTG_CORE_HANDLE *pdev, uint8_t ch_num);
-uint32_t HCD_GetXferCnt (USB_OTG_CORE_HANDLE *pdev, uint8_t ch_num);
-HC_STATUS HCD_GetHCState (USB_OTG_CORE_HANDLE *pdev, uint8_t ch_num) ;
-/**
- * @}
- */
-
-#endif //__USB_HCD_H__
-
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
-
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/inc/usb_hcd_int.h b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/inc/usb_hcd_int.h
deleted file mode 100644
index 72fcd4543..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/inc/usb_hcd_int.h
+++ /dev/null
@@ -1,144 +0,0 @@
-/**
- ******************************************************************************
- * @file usb_hcd_int.h
- * @author xiuos Team
- * @version V1.0.0
- * @date 2020-9-3
- * @brief This file is based on usb_hcd_int.h
- * Peripheral Device Interface Layer
- ******************************************************************************
- * @file usb_hcd_int.h
- * @author MCD Application Team
- * @version V1.0.0
- * @date 30-September-2011
- * ********************************************************************************
- * @attention
- *
- * © Copyright (c) 2015 STMicroelectronics.
- * All rights reserved.
- *
- * This software component is licensed by ST under Ultimate Liberty license
- * SLA0044, the "License"; You may not use this file except in compliance with
- * the License. You may obtain a copy of the License at:
- *
- *
- ******************************************************************************
- */
-
-/* Define to prevent recursive inclusion -------------------------------------*/
-#ifndef __HCD_INT_H__
-#define __HCD_INT_H__
-
-/* Includes ------------------------------------------------------------------*/
-#include "usb_hcd.h"
-
-
-/** @addtogroup USB_OTG_DRIVER
- * @{
- */
-
-/** @defgroup USB_HCD_INT
- * @brief This file is the
- * @{
- */
-
-
-/** @defgroup USB_HCD_INT_Exported_Defines
- * @{
- */
-/**
- * @}
- */
-
-
-/** @defgroup USB_HCD_INT_Exported_Types
- * @{
- */
-
-typedef struct _USBH_HCD_INT
-{
- uint8_t (* SOF) (USB_OTG_CORE_HANDLE *pdev);
- uint8_t (* DevConnected) (USB_OTG_CORE_HANDLE *pdev);
- uint8_t (* DevDisconnected) (USB_OTG_CORE_HANDLE *pdev);
- uint8_t (* DevPortEnabled) (USB_OTG_CORE_HANDLE *pdev);
- uint8_t (* DevPortDisabled) (USB_OTG_CORE_HANDLE *pdev);
- uint8_t (* URBChangeNotify) (USB_OTG_CORE_HANDLE *pdev);
-
-}USBH_HCD_INT_cb_TypeDef;
-
-extern USBH_HCD_INT_cb_TypeDef *USBH_HCD_INT_fops;
-/**
- * @}
- */
-
-
-/** @defgroup USB_HCD_INT_Exported_Macros
- * @{
- */
-
-#define CLEAR_HC_INT(HC_REGS, intr) \
- {\
- USB_OTG_HCINTn_TypeDef hcint_clear; \
- hcint_clear.d32 = 0; \
- hcint_clear.b.intr = 1; \
- USB_OTG_WRITE_REG32(&((HC_REGS)->HCINT), hcint_clear.d32);\
- }\
-
-#define MASK_HOST_INT_CHH(hc_num) { USB_OTG_HCINTMSK_TypeDef INTMSK; \
- INTMSK.d32 = USB_OTG_READ_REG32(&pdev->regs.HC_REGS[hc_num]->HCINTMSK); \
- INTMSK.b.chhltd = 0; \
- USB_OTG_WRITE_REG32(&pdev->regs.HC_REGS[hc_num]->HCINTMSK, INTMSK.d32);}
-
-#define UNMASK_HOST_INT_CHH(hc_num) { USB_OTG_HCINTMSK_TypeDef INTMSK; \
- INTMSK.d32 = USB_OTG_READ_REG32(&pdev->regs.HC_REGS[hc_num]->HCINTMSK); \
- INTMSK.b.chhltd = 1; \
- USB_OTG_WRITE_REG32(&pdev->regs.HC_REGS[hc_num]->HCINTMSK, INTMSK.d32);}
-
-#define MASK_HOST_INT_ACK(hc_num) { USB_OTG_HCINTMSK_TypeDef INTMSK; \
- INTMSK.d32 = USB_OTG_READ_REG32(&pdev->regs.HC_REGS[hc_num]->HCINTMSK); \
- INTMSK.b.ack = 0; \
- USB_OTG_WRITE_REG32(&pdev->regs.HC_REGS[hc_num]->HCINTMSK, GINTMSK.d32);}
-
-#define UNMASK_HOST_INT_ACK(hc_num) { USB_OTG_HCGINTMSK_TypeDef INTMSK; \
- INTMSK.d32 = USB_OTG_READ_REG32(&pdev->regs.HC_REGS[hc_num]->HCINTMSK); \
- INTMSK.b.ack = 1; \
- USB_OTG_WRITE_REG32(&pdev->regs.HC_REGS[hc_num]->HCINTMSK, INTMSK.d32);}
-
-/**
- * @}
- */
-
-/** @defgroup USB_HCD_INT_Exported_Variables
- * @{
- */
-/**
- * @}
- */
-
-/** @defgroup USB_HCD_INT_Exported_FunctionsPrototype
- * @{
- */
-/* Callbacks handler */
-void ConnectCallback_Handler(USB_OTG_CORE_HANDLE *pdev);
-void Disconnect_Callback_Handler(USB_OTG_CORE_HANDLE *pdev);
-void Overcurrent_Callback_Handler(USB_OTG_CORE_HANDLE *pdev);
-uint32_t USBH_OTG_ISR_Handler (USB_OTG_CORE_HANDLE *pdev);
-
-/**
- * @}
- */
-
-
-
-#endif //__HCD_INT_H__
-
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
-
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/inc/usb_otg.h b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/inc/usb_otg.h
deleted file mode 100644
index 3cc9e617b..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/inc/usb_otg.h
+++ /dev/null
@@ -1,99 +0,0 @@
-/**
- ******************************************************************************
- * @file usb_otg.h
- * @author xiuos Team
- * @version V1.0.0
- * @date 2020-9-3
- * @brief This file is based on usb_otg.h
- * OTG Core Header
- ******************************************************************************
- * @file usb_otg.h
- * @author MCD Application Team
- * @version V1.0.0
- * @date 30-September-2011
- * ********************************************************************************
- * @attention
- *
- * © Copyright (c) 2015 STMicroelectronics.
- * All rights reserved.
- *
- * This software component is licensed by ST under Ultimate Liberty license
- * SLA0044, the "License"; You may not use this file except in compliance with
- * the License. You may obtain a copy of the License at:
- *
- *
- ******************************************************************************
- */
-
-/* Define to prevent recursive inclusion -------------------------------------*/
-#ifndef __USB_OTG__
-#define __USB_OTG__
-
-
-/** @addtogroup USB_OTG_DRIVER
- * @{
- */
-
-/** @defgroup USB_OTG
- * @brief This file is the
- * @{
- */
-
-
-/** @defgroup USB_OTG_Exported_Defines
- * @{
- */
-
-
-void USB_OTG_InitiateSRP(void);
-void USB_OTG_InitiateHNP(uint8_t state , uint8_t mode);
-void USB_OTG_Switchback (USB_OTG_CORE_HANDLE *pdev);
-uint32_t USB_OTG_GetCurrentState (USB_OTG_CORE_HANDLE *pdev);
-
-/**
- * @}
- */
-
-
-/** @defgroup USB_OTG_Exported_Types
- * @{
- */
-/**
- * @}
- */
-
-
-/** @defgroup USB_OTG_Exported_Macros
- * @{
- */
-/**
- * @}
- */
-
-/** @defgroup USB_OTG_Exported_Variables
- * @{
- */
-/**
- * @}
- */
-
-/** @defgroup USB_OTG_Exported_FunctionsPrototype
- * @{
- */
-/**
- * @}
- */
-
-
-#endif //__USB_OTG__
-
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
-
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/inc/usb_regs.h b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/inc/usb_regs.h
deleted file mode 100644
index 6e7e312fe..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/inc/usb_regs.h
+++ /dev/null
@@ -1,1216 +0,0 @@
-/**
- ******************************************************************************
- * @file usb_regs.h
- * @author xiuos Team
- * @version V1.0.0
- * @date 2020-9-3
- * @brief This file is based on usb_regs.h
- * hardware registers
- ******************************************************************************
- * @file usb_regs.h
- * @author MCD Application Team
- * @version V1.0.0
- * @date 30-September-2011
- * ********************************************************************************
- * @attention
- *
- * © Copyright (c) 2015 STMicroelectronics.
- * All rights reserved.
- *
- * This software component is licensed by ST under Ultimate Liberty license
- * SLA0044, the "License"; You may not use this file except in compliance with
- * the License. You may obtain a copy of the License at:
- *
- *
- ******************************************************************************
- */
-
-/* Define to prevent recursive inclusion -------------------------------------*/
-#ifndef __USB_OTG_REGS_H__
-#define __USB_OTG_REGS_H__
-
-/* Includes ------------------------------------------------------------------*/
-#include "usb_conf.h"
-
-
-/** @addtogroup USB_OTG_DRIVER
- * @{
- */
-
-/** @defgroup USB_REGS
- * @brief This file is the
- * @{
- */
-
-
-/** @defgroup USB_REGS_Exported_Defines
- * @{
- */
-
-#define USB_OTG_HS_BASE_ADDR 0x40040000
-#define USB_OTG_FS_BASE_ADDR 0x50000000
-
-#define USB_OTG_CORE_GLOBAL_REGS_OFFSET 0x000
-#define USB_OTG_DEV_GLOBAL_REG_OFFSET 0x800
-#define USB_OTG_DEV_IN_EP_REG_OFFSET 0x900
-#define USB_OTG_EP_REG_OFFSET 0x20
-#define USB_OTG_DEV_OUT_EP_REG_OFFSET 0xB00
-#define USB_OTG_HOST_GLOBAL_REG_OFFSET 0x400
-#define USB_OTG_HOST_PORT_REGS_OFFSET 0x440
-#define USB_OTG_HOST_CHAN_REGS_OFFSET 0x500
-#define USB_OTG_CHAN_REGS_OFFSET 0x20
-#define USB_OTG_PCGCCTL_OFFSET 0xE00
-#define USB_OTG_DATA_FIFO_OFFSET 0x1000
-#define USB_OTG_DATA_FIFO_SIZE 0x1000
-
-
-#define USB_OTG_MAX_TX_FIFOS 15
-
-#define USB_OTG_HS_MAX_PACKET_SIZE 512
-#define USB_OTG_FS_MAX_PACKET_SIZE 64
-#define USB_OTG_MAX_EP0_SIZE 64
-/**
- * @}
- */
-
-/** @defgroup USB_REGS_Exported_Types
- * @{
- */
-
-/** @defgroup __USB_OTG_Core_register
- * @{
- */
-typedef struct _USB_OTG_GREGS /* 000h */
-{
- __IO uint32_t GOTGCTL; /* USB_OTG Control and Status Register 000h*/
- __IO uint32_t GOTGINT; /* USB_OTG Interrupt Register 004h*/
- __IO uint32_t GAHBCFG; /* Core AHB Configuration Register 008h*/
- __IO uint32_t GUSBCFG; /* Core USB Configuration Register 00Ch*/
- __IO uint32_t GRSTCTL; /* Core Reset Register 010h*/
- __IO uint32_t GINTSTS; /* Core Interrupt Register 014h*/
- __IO uint32_t GINTMSK; /* Core Interrupt Mask Register 018h*/
- __IO uint32_t GRXSTSR; /* Receive Sts Q Read Register 01Ch*/
- __IO uint32_t GRXSTSP; /* Receive Sts Q Read & POP Register 020h*/
- __IO uint32_t GRXFSIZ; /* Receive FIFO Size Register 024h*/
- __IO uint32_t DIEPTXF0_HNPTXFSIZ; /* EP0 / Non Periodic Tx FIFO Size Register 028h*/
- __IO uint32_t HNPTXSTS; /* Non Periodic Tx FIFO/Queue Sts reg 02Ch*/
- uint32_t Reserved30[2]; /* Reserved 030h*/
- __IO uint32_t GCCFG; /* General Purpose IO Register 038h*/
- __IO uint32_t CID; /* User ID Register 03Ch*/
- uint32_t Reserved40[48]; /* Reserved 040h-0FFh*/
- __IO uint32_t HPTXFSIZ; /* Host Periodic Tx FIFO Size Reg 100h*/
- __IO uint32_t DIEPTXF[USB_OTG_MAX_TX_FIFOS];/* dev Periodic Transmit FIFO */
-}
-USB_OTG_GREGS;
-/**
- * @}
- */
-
-
-/** @defgroup __device_Registers
- * @{
- */
-typedef struct _USB_OTG_DREGS /* 800h */
-{
- __IO uint32_t DCFG; /* dev Configuration Register 800h*/
- __IO uint32_t DCTL; /* dev Control Register 804h*/
- __IO uint32_t DSTS; /* dev Status Register (RO) 808h*/
- uint32_t Reserved0C; /* Reserved 80Ch*/
- __IO uint32_t DIEPMSK; /* dev IN Endpoint Mask 810h*/
- __IO uint32_t DOEPMSK; /* dev OUT Endpoint Mask 814h*/
- __IO uint32_t DAINT; /* dev All Endpoints Itr Reg 818h*/
- __IO uint32_t DAINTMSK; /* dev All Endpoints Itr Mask 81Ch*/
- uint32_t Reserved20; /* Reserved 820h*/
- uint32_t Reserved9; /* Reserved 824h*/
- __IO uint32_t DVBUSDIS; /* dev VBUS discharge Register 828h*/
- __IO uint32_t DVBUSPULSE; /* dev VBUS Pulse Register 82Ch*/
- __IO uint32_t DTHRCTL; /* dev thr 830h*/
- __IO uint32_t DIEPEMPMSK; /* dev empty msk 834h*/
- __IO uint32_t DEACHINT; /* dedicated EP interrupt 838h*/
- __IO uint32_t DEACHMSK; /* dedicated EP msk 83Ch*/
- uint32_t Reserved40; /* dedicated EP mask 840h*/
- __IO uint32_t DINEP1MSK; /* dedicated EP mask 844h*/
- uint32_t Reserved44[15]; /* Reserved 844-87Ch*/
- __IO uint32_t DOUTEP1MSK; /* dedicated EP msk 884h*/
-}
-USB_OTG_DREGS;
-/**
- * @}
- */
-
-
-/** @defgroup __IN_Endpoint-Specific_Register
- * @{
- */
-typedef struct _USB_OTG_INEPREGS
-{
- __IO uint32_t DIEPCTL; /* dev IN Endpoint Control Reg 900h + (ep_num * 20h) + 00h*/
- uint32_t Reserved04; /* Reserved 900h + (ep_num * 20h) + 04h*/
- __IO uint32_t DIEPINT; /* dev IN Endpoint Itr Reg 900h + (ep_num * 20h) + 08h*/
- uint32_t Reserved0C; /* Reserved 900h + (ep_num * 20h) + 0Ch*/
- __IO uint32_t DIEPTSIZ; /* IN Endpoint Txfer Size 900h + (ep_num * 20h) + 10h*/
- __IO uint32_t DIEPDMA; /* IN Endpoint DMA Address Reg 900h + (ep_num * 20h) + 14h*/
- __IO uint32_t DTXFSTS;/*IN Endpoint Tx FIFO Status Reg 900h + (ep_num * 20h) + 18h*/
- uint32_t Reserved18; /* Reserved 900h+(ep_num*20h)+1Ch-900h+ (ep_num * 20h) + 1Ch*/
-}
-USB_OTG_INEPREGS;
-/**
- * @}
- */
-
-
-/** @defgroup __OUT_Endpoint-Specific_Registers
- * @{
- */
-typedef struct _USB_OTG_OUTEPREGS
-{
- __IO uint32_t DOEPCTL; /* dev OUT Endpoint Control Reg B00h + (ep_num * 20h) + 00h*/
- uint32_t Reserved04; /* Reserved B00h + (ep_num * 20h) + 04h*/
- __IO uint32_t DOEPINT; /* dev OUT Endpoint Itr Reg B00h + (ep_num * 20h) + 08h*/
- uint32_t Reserved0C; /* Reserved B00h + (ep_num * 20h) + 0Ch*/
- __IO uint32_t DOEPTSIZ; /* dev OUT Endpoint Txfer Size B00h + (ep_num * 20h) + 10h*/
- __IO uint32_t DOEPDMA; /* dev OUT Endpoint DMA Address B00h + (ep_num * 20h) + 14h*/
- uint32_t Reserved18[2]; /* Reserved B00h + (ep_num * 20h) + 18h - B00h + (ep_num * 20h) + 1Ch*/
-}
-USB_OTG_OUTEPREGS;
-/**
- * @}
- */
-
-
-/** @defgroup __Host_Mode_Register_Structures
- * @{
- */
-typedef struct _USB_OTG_HREGS
-{
- __IO uint32_t HCFG; /* Host Configuration Register 400h*/
- __IO uint32_t HFIR; /* Host Frame Interval Register 404h*/
- __IO uint32_t HFNUM; /* Host Frame Nbr/Frame Remaining 408h*/
- uint32_t Reserved40C; /* Reserved 40Ch*/
- __IO uint32_t HPTXSTS; /* Host Periodic Tx FIFO/ Queue Status 410h*/
- __IO uint32_t HAINT; /* Host All Channels Interrupt Register 414h*/
- __IO uint32_t HAINTMSK; /* Host All Channels Interrupt Mask 418h*/
-}
-USB_OTG_HREGS;
-/**
- * @}
- */
-
-
-/** @defgroup __Host_Channel_Specific_Registers
- * @{
- */
-typedef struct _USB_OTG_HC_REGS
-{
- __IO uint32_t HCCHAR;
- __IO uint32_t HCSPLT;
- __IO uint32_t HCINT;
- __IO uint32_t HCINTMSK;
- __IO uint32_t HCTSIZ;
- __IO uint32_t HCDMA;
- uint32_t Reserved[2];
-}
-USB_OTG_HC_REGS;
-/**
- * @}
- */
-
-
-/** @defgroup __otg_Core_registers
- * @{
- */
-typedef struct USB_OTG_core_regs /* 000h */
-{
- USB_OTG_GREGS *GREGS;
- USB_OTG_DREGS *DREGS;
- USB_OTG_HREGS *HREGS;
- USB_OTG_INEPREGS *INEP_REGS[USB_OTG_MAX_TX_FIFOS];
- USB_OTG_OUTEPREGS *OUTEP_REGS[USB_OTG_MAX_TX_FIFOS];
- USB_OTG_HC_REGS *HC_REGS[USB_OTG_MAX_TX_FIFOS];
- __IO uint32_t *HPRT0;
- __IO uint32_t *DFIFO[USB_OTG_MAX_TX_FIFOS];
- __IO uint32_t *PCGCCTL;
-}
-USB_OTG_CORE_REGS , *PUSB_OTG_CORE_REGS;
-typedef union _USB_OTG_GOTGCTL_TypeDef
-{
- uint32_t d32;
- struct
- {
-uint32_t sesreqscs :
- 1;
-uint32_t sesreq :
- 1;
-uint32_t Reserved2_7 :
- 6;
-uint32_t hstnegscs :
- 1;
-uint32_t hnpreq :
- 1;
-uint32_t hstsethnpen :
- 1;
-uint32_t devhnpen :
- 1;
-uint32_t Reserved12_15 :
- 4;
-uint32_t conidsts :
- 1;
-uint32_t dbct :
- 1;
-uint32_t asesvld :
- 1;
-uint32_t bsesvld :
- 1;
-uint32_t Reserved20_31 :
- 12;
- }
- b;
-} USB_OTG_GOTGCTL_TypeDef ;
-
-typedef union _USB_OTG_GOTGINT_TypeDef
-{
- uint32_t d32;
- struct
- {
-uint32_t Reserved0_1 :
- 2;
-uint32_t sesenddet :
- 1;
-uint32_t Reserved3_7 :
- 5;
-uint32_t sesreqsucstschng :
- 1;
-uint32_t hstnegsucstschng :
- 1;
-uint32_t reserver10_16 :
- 7;
-uint32_t hstnegdet :
- 1;
-uint32_t adevtoutchng :
- 1;
-uint32_t debdone :
- 1;
-uint32_t Reserved31_20 :
- 12;
- }
- b;
-} USB_OTG_GOTGINT_TypeDef ;
-typedef union _USB_OTG_GAHBCFG_TypeDef
-{
- uint32_t d32;
- struct
- {
-uint32_t glblintrmsk :
- 1;
-uint32_t hburstlen :
- 4;
-uint32_t dmaenable :
- 1;
-uint32_t Reserved :
- 1;
-uint32_t nptxfemplvl_txfemplvl :
- 1;
-uint32_t ptxfemplvl :
- 1;
-uint32_t Reserved9_31 :
- 23;
- }
- b;
-} USB_OTG_GAHBCFG_TypeDef ;
-typedef union _USB_OTG_GUSBCFG_TypeDef
-{
- uint32_t d32;
- struct
- {
-uint32_t toutcal :
- 3;
-uint32_t Reserved3_5 :
- 3;
-uint32_t physel :
- 1;
-uint32_t Reserved7 :
- 1;
-uint32_t srpcap :
- 1;
-uint32_t hnpcap :
- 1;
-uint32_t usbtrdtim :
- 4;
-uint32_t Reserved14 :
- 1;
-uint32_t phylpwrclksel :
- 1;
-uint32_t Reserved16 :
- 1;
-uint32_t ulpi_fsls :
- 1;
-uint32_t ulpi_auto_res :
- 1;
-uint32_t ulpi_clk_sus_m :
- 1;
-uint32_t ulpi_ext_vbus_drv :
- 1;
-uint32_t ulpi_int_vbus_ind :
- 1;
-uint32_t term_sel_dl_pulse :
- 1;
-uint32_t ulpi_ind_cpl :
- 1;
-uint32_t ulpi_passthrough :
- 1;
-uint32_t ulpi_protect_disable :
- 1;
-uint32_t Reserved26_28 :
- 3;
-uint32_t force_host :
- 1;
-uint32_t force_dev :
- 1;
-uint32_t corrupt_tx :
- 1;
- }
- b;
-} USB_OTG_GUSBCFG_TypeDef ;
-typedef union _USB_OTG_GRSTCTL_TypeDef
-{
- uint32_t d32;
- struct
- {
-uint32_t csftrst :
- 1;
-uint32_t hsftrst :
- 1;
-uint32_t hstfrm :
- 1;
-uint32_t Reserved3 :
- 1;
-uint32_t rxfflsh :
- 1;
-uint32_t txfflsh :
- 1;
-uint32_t txfnum :
- 5;
-uint32_t Reserved11_29 :
- 19;
-uint32_t dmareq :
- 1;
-uint32_t ahbidle :
- 1;
- }
- b;
-} USB_OTG_GRSTCTL_TypeDef ;
-typedef union _USB_OTG_GINTMSK_TypeDef
-{
- uint32_t d32;
- struct
- {
-uint32_t Reserved0 :
- 1;
-uint32_t modemismatch :
- 1;
-uint32_t otgintr :
- 1;
-uint32_t sofintr :
- 1;
-uint32_t rxstsqlvl :
- 1;
-uint32_t nptxfempty :
- 1;
-uint32_t ginnakeff :
- 1;
-uint32_t goutnakeff :
- 1;
-uint32_t Reserved8_9 :
- 2;
-uint32_t erlysuspend :
- 1;
-uint32_t usbsuspend :
- 1;
-uint32_t usbreset :
- 1;
-uint32_t enumdone :
- 1;
-uint32_t isooutdrop :
- 1;
-uint32_t eopframe :
- 1;
-uint32_t Reserved16 :
- 1;
-uint32_t epmismatch :
- 1;
-uint32_t inepintr :
- 1;
-uint32_t outepintr :
- 1;
-uint32_t incomplisoin :
- 1;
-uint32_t incomplisoout :
- 1;
-uint32_t Reserved22_23 :
- 2;
-uint32_t portintr :
- 1;
-uint32_t hcintr :
- 1;
-uint32_t ptxfempty :
- 1;
-uint32_t Reserved27 :
- 1;
-uint32_t conidstschng :
- 1;
-uint32_t disconnect :
- 1;
-uint32_t sessreqintr :
- 1;
-uint32_t wkupintr :
- 1;
- }
- b;
-} USB_OTG_GINTMSK_TypeDef ;
-typedef union _USB_OTG_GINTSTS_TypeDef
-{
- uint32_t d32;
- struct
- {
-uint32_t curmode :
- 1;
-uint32_t modemismatch :
- 1;
-uint32_t otgintr :
- 1;
-uint32_t sofintr :
- 1;
-uint32_t rxstsqlvl :
- 1;
-uint32_t nptxfempty :
- 1;
-uint32_t ginnakeff :
- 1;
-uint32_t goutnakeff :
- 1;
-uint32_t Reserved8_9 :
- 2;
-uint32_t erlysuspend :
- 1;
-uint32_t usbsuspend :
- 1;
-uint32_t usbreset :
- 1;
-uint32_t enumdone :
- 1;
-uint32_t isooutdrop :
- 1;
-uint32_t eopframe :
- 1;
-uint32_t Reserved16_17 :
- 2;
-uint32_t inepint:
- 1;
-uint32_t outepintr :
- 1;
-uint32_t incomplisoin :
- 1;
-uint32_t incomplisoout :
- 1;
-uint32_t Reserved22_23 :
- 2;
-uint32_t portintr :
- 1;
-uint32_t hcintr :
- 1;
-uint32_t ptxfempty :
- 1;
-uint32_t Reserved27 :
- 1;
-uint32_t conidstschng :
- 1;
-uint32_t disconnect :
- 1;
-uint32_t sessreqintr :
- 1;
-uint32_t wkupintr :
- 1;
- }
- b;
-} USB_OTG_GINTSTS_TypeDef ;
-typedef union _USB_OTG_DRXSTS_TypeDef
-{
- uint32_t d32;
- struct
- {
-uint32_t epnum :
- 4;
-uint32_t bcnt :
- 11;
-uint32_t dpid :
- 2;
-uint32_t pktsts :
- 4;
-uint32_t fn :
- 4;
-uint32_t Reserved :
- 7;
- }
- b;
-} USB_OTG_DRXSTS_TypeDef ;
-typedef union _USB_OTG_GRXSTS_TypeDef
-{
- uint32_t d32;
- struct
- {
-uint32_t chnum :
- 4;
-uint32_t bcnt :
- 11;
-uint32_t dpid :
- 2;
-uint32_t pktsts :
- 4;
-uint32_t Reserved :
- 11;
- }
- b;
-} USB_OTG_GRXFSTS_TypeDef ;
-typedef union _USB_OTG_FSIZ_TypeDef
-{
- uint32_t d32;
- struct
- {
-uint32_t startaddr :
- 16;
-uint32_t depth :
- 16;
- }
- b;
-} USB_OTG_FSIZ_TypeDef ;
-typedef union _USB_OTG_HNPTXSTS_TypeDef
-{
- uint32_t d32;
- struct
- {
- uint32_t nptxfspcavail :
- 16;
- uint32_t nptxqspcavail :
- 8;
- struct
- {
- uint32_t terminate :
- 1;
- uint32_t token :
- 2;
- uint32_t chnum :
- 4;
- } nptxqtop;
- uint32_t Reserved :
- 1;
- }
- b;
-} USB_OTG_HNPTXSTS_TypeDef ;
-typedef union _USB_OTG_DTXFSTSn_TypeDef
-{
- uint32_t d32;
- struct
- {
-uint32_t txfspcavail :
- 16;
-uint32_t Reserved :
- 16;
- }
- b;
-} USB_OTG_DTXFSTSn_TypeDef ;
-
-#if defined (STM32F446xx) || defined (STM32F469_479xx)
-typedef union _USB_OTG_GCCFG_TypeDef
-{
- uint32_t d32;
- struct
- {
-uint32_t Reserved_in :
- 16;
-uint32_t pwdn :
- 1;
-uint32_t Reserved_17 :
- 1;
-uint32_t Reserved_18 :
- 1;
-uint32_t Reserved_19 :
- 1;
-uint32_t Reserved_20 :
- 1;
-uint32_t vbden :
- 1;
-uint32_t Reserved_out :
- 10;
- }
- b;
-} USB_OTG_GCCFG_TypeDef ;
-#else
-typedef union _USB_OTG_GCCFG_TypeDef
-{
- uint32_t d32;
- struct
- {
-uint32_t Reserved_in :
- 16;
-uint32_t pwdn :
- 1;
-uint32_t Reserved_17 :
- 1;
-uint32_t vbussensingA :
- 1;
-uint32_t vbussensingB :
- 1;
-uint32_t sofouten :
- 1;
-uint32_t disablevbussensing :
- 1;
-uint32_t Reserved_out :
- 10;
- }
- b;
-} USB_OTG_GCCFG_TypeDef ;
-#endif
-
-typedef union _USB_OTG_DCFG_TypeDef
-{
- uint32_t d32;
- struct
- {
-uint32_t devspd :
- 2;
-uint32_t nzstsouthshk :
- 1;
-uint32_t Reserved3 :
- 1;
-uint32_t devaddr :
- 7;
-uint32_t perfrint :
- 2;
-uint32_t Reserved12_31 :
- 19;
- }
- b;
-} USB_OTG_DCFG_TypeDef ;
-typedef union _USB_OTG_DCTL_TypeDef
-{
- uint32_t d32;
- struct
- {
-uint32_t rmtwkupsig :
- 1;
-uint32_t sftdiscon :
- 1;
-uint32_t gnpinnaksts :
- 1;
-uint32_t goutnaksts :
- 1;
-uint32_t tstctl :
- 3;
-uint32_t sgnpinnak :
- 1;
-uint32_t cgnpinnak :
- 1;
-uint32_t sgoutnak :
- 1;
-uint32_t cgoutnak :
- 1;
-uint32_t poprg_done :
- 1;
-uint32_t Reserved :
- 20;
- }
- b;
-} USB_OTG_DCTL_TypeDef ;
-typedef union _USB_OTG_DSTS_TypeDef
-{
- uint32_t d32;
- struct
- {
-uint32_t suspsts :
- 1;
-uint32_t enumspd :
- 2;
-uint32_t errticerr :
- 1;
-uint32_t Reserved4_7:
- 4;
-uint32_t soffn :
- 14;
-uint32_t Reserved22_31 :
- 10;
- }
- b;
-} USB_OTG_DSTS_TypeDef ;
-typedef union _USB_OTG_DIEPINTn_TypeDef
-{
- uint32_t d32;
- struct
- {
-uint32_t xfercompl :
- 1;
-uint32_t epdisabled :
- 1;
-uint32_t Reserved2 :
- 1;
-uint32_t timeout :
- 1;
-uint32_t intktxfemp :
- 1;
-uint32_t Reserved5 :
- 1;
-uint32_t inepnakeff :
- 1;
-uint32_t emptyintr :
- 1;
-uint32_t txfifoundrn :
- 1;
-uint32_t Reserved14_31 :
- 23;
- }
- b;
-} USB_OTG_DIEPINTn_TypeDef ;
-typedef union _USB_OTG_DIEPINTn_TypeDef USB_OTG_DIEPMSK_TypeDef ;
-typedef union _USB_OTG_DOEPINTn_TypeDef
-{
- uint32_t d32;
- struct
- {
-uint32_t xfercompl :
- 1;
-uint32_t epdisabled :
- 1;
-uint32_t Reserved2 :
- 1;
-uint32_t setup :
- 1;
-uint32_t Reserved04_31 :
- 28;
- }
- b;
-} USB_OTG_DOEPINTn_TypeDef ;
-typedef union _USB_OTG_DOEPINTn_TypeDef USB_OTG_DOEPMSK_TypeDef ;
-
-typedef union _USB_OTG_DAINT_TypeDef
-{
- uint32_t d32;
- struct
- {
-uint32_t in :
- 16;
-uint32_t out :
- 16;
- }
- ep;
-} USB_OTG_DAINT_TypeDef ;
-
-typedef union _USB_OTG_DTHRCTL_TypeDef
-{
- uint32_t d32;
- struct
- {
-uint32_t non_iso_thr_en :
- 1;
-uint32_t iso_thr_en :
- 1;
-uint32_t tx_thr_len :
- 9;
-uint32_t Reserved11_15 :
- 5;
-uint32_t rx_thr_en :
- 1;
-uint32_t rx_thr_len :
- 9;
-uint32_t Reserved26 :
- 1;
-uint32_t arp_en :
- 1;
-uint32_t Reserved28_31 :
- 4;
- }
- b;
-} USB_OTG_DTHRCTL_TypeDef ;
-typedef union _USB_OTG_DEPCTL_TypeDef
-{
- uint32_t d32;
- struct
- {
-uint32_t mps :
- 11;
-uint32_t reserved :
- 4;
-uint32_t usbactep :
- 1;
-uint32_t dpid :
- 1;
-uint32_t naksts :
- 1;
-uint32_t eptype :
- 2;
-uint32_t snp :
- 1;
-uint32_t stall :
- 1;
-uint32_t txfnum :
- 4;
-uint32_t cnak :
- 1;
-uint32_t snak :
- 1;
-uint32_t setd0pid :
- 1;
-uint32_t setd1pid :
- 1;
-uint32_t epdis :
- 1;
-uint32_t epena :
- 1;
- }
- b;
-} USB_OTG_DEPCTL_TypeDef ;
-typedef union _USB_OTG_DEPXFRSIZ_TypeDef
-{
- uint32_t d32;
- struct
- {
-uint32_t xfersize :
- 19;
-uint32_t pktcnt :
- 10;
-uint32_t mc :
- 2;
-uint32_t Reserved :
- 1;
- }
- b;
-} USB_OTG_DEPXFRSIZ_TypeDef ;
-typedef union _USB_OTG_DEP0XFRSIZ_TypeDef
-{
- uint32_t d32;
- struct
- {
-uint32_t xfersize :
- 7;
-uint32_t Reserved7_18 :
- 12;
-uint32_t pktcnt :
- 1;
-uint32_t Reserved20_28 :
- 9;
-uint32_t supcnt :
- 2;
-uint32_t Reserved31 :
- 1;
- }
- b;
-} USB_OTG_DEP0XFRSIZ_TypeDef ;
-typedef union _USB_OTG_HCFG_TypeDef
-{
- uint32_t d32;
- struct
- {
-uint32_t fslspclksel :
- 2;
-uint32_t fslssupp :
- 1;
- }
- b;
-} USB_OTG_HCFG_TypeDef ;
-typedef union _USB_OTG_HFRMINTRVL_TypeDef
-{
- uint32_t d32;
- struct
- {
-uint32_t frint :
- 16;
-uint32_t Reserved :
- 16;
- }
- b;
-} USB_OTG_HFRMINTRVL_TypeDef ;
-
-typedef union _USB_OTG_HFNUM_TypeDef
-{
- uint32_t d32;
- struct
- {
-uint32_t frnum :
- 16;
-uint32_t frrem :
- 16;
- }
- b;
-} USB_OTG_HFNUM_TypeDef ;
-typedef union _USB_OTG_HPTXSTS_TypeDef
-{
- uint32_t d32;
- struct
- {
-uint32_t ptxfspcavail :
- 16;
-uint32_t ptxqspcavail :
- 8;
- struct
- {
- uint32_t terminate :
- 1;
- uint32_t token :
- 2;
- uint32_t chnum :
- 4;
- uint32_t odd_even :
- 1;
- } ptxqtop;
- }
- b;
-} USB_OTG_HPTXSTS_TypeDef ;
-typedef union _USB_OTG_HPRT0_TypeDef
-{
- uint32_t d32;
- struct
- {
-uint32_t prtconnsts :
- 1;
-uint32_t prtconndet :
- 1;
-uint32_t prtena :
- 1;
-uint32_t prtenchng :
- 1;
-uint32_t prtovrcurract :
- 1;
-uint32_t prtovrcurrchng :
- 1;
-uint32_t prtres :
- 1;
-uint32_t prtsusp :
- 1;
-uint32_t prtrst :
- 1;
-uint32_t Reserved9 :
- 1;
-uint32_t prtlnsts :
- 2;
-uint32_t prtpwr :
- 1;
-uint32_t prttstctl :
- 4;
-uint32_t prtspd :
- 2;
-uint32_t Reserved19_31 :
- 13;
- }
- b;
-} USB_OTG_HPRT0_TypeDef ;
-typedef union _USB_OTG_HAINT_TypeDef
-{
- uint32_t d32;
- struct
- {
-uint32_t chint :
- 16;
-uint32_t Reserved :
- 16;
- }
- b;
-} USB_OTG_HAINT_TypeDef ;
-typedef union _USB_OTG_HAINTMSK_TypeDef
-{
- uint32_t d32;
- struct
- {
-uint32_t chint :
- 16;
-uint32_t Reserved :
- 16;
- }
- b;
-} USB_OTG_HAINTMSK_TypeDef ;
-typedef union _USB_OTG_HCCHAR_TypeDef
-{
- uint32_t d32;
- struct
- {
-uint32_t mps :
- 11;
-uint32_t epnum :
- 4;
-uint32_t epdir :
- 1;
-uint32_t Reserved :
- 1;
-uint32_t lspddev :
- 1;
-uint32_t eptype :
- 2;
-uint32_t multicnt :
- 2;
-uint32_t devaddr :
- 7;
-uint32_t oddfrm :
- 1;
-uint32_t chdis :
- 1;
-uint32_t chen :
- 1;
- }
- b;
-} USB_OTG_HCCHAR_TypeDef ;
-typedef union _USB_OTG_HCSPLT_TypeDef
-{
- uint32_t d32;
- struct
- {
-uint32_t prtaddr :
- 7;
-uint32_t hubaddr :
- 7;
-uint32_t xactpos :
- 2;
-uint32_t compsplt :
- 1;
-uint32_t Reserved :
- 14;
-uint32_t spltena :
- 1;
- }
- b;
-} USB_OTG_HCSPLT_TypeDef ;
-typedef union _USB_OTG_HCINTn_TypeDef
-{
- uint32_t d32;
- struct
- {
-uint32_t xfercompl :
- 1;
-uint32_t chhltd :
- 1;
-uint32_t ahberr :
- 1;
-uint32_t stall :
- 1;
-uint32_t nak :
- 1;
-uint32_t ack :
- 1;
-uint32_t nyet :
- 1;
-uint32_t xacterr :
- 1;
-uint32_t bblerr :
- 1;
-uint32_t frmovrun :
- 1;
-uint32_t datatglerr :
- 1;
-uint32_t Reserved :
- 21;
- }
- b;
-} USB_OTG_HCINTn_TypeDef ;
-typedef union _USB_OTG_HCTSIZn_TypeDef
-{
- uint32_t d32;
- struct
- {
-uint32_t xfersize :
- 19;
-uint32_t pktcnt :
- 10;
-uint32_t pid :
- 2;
-uint32_t dopng :
- 1;
- }
- b;
-} USB_OTG_HCTSIZn_TypeDef ;
-typedef union _USB_OTG_HCINTMSK_TypeDef
-{
- uint32_t d32;
- struct
- {
-uint32_t xfercompl :
- 1;
-uint32_t chhltd :
- 1;
-uint32_t ahberr :
- 1;
-uint32_t stall :
- 1;
-uint32_t nak :
- 1;
-uint32_t ack :
- 1;
-uint32_t nyet :
- 1;
-uint32_t xacterr :
- 1;
-uint32_t bblerr :
- 1;
-uint32_t frmovrun :
- 1;
-uint32_t datatglerr :
- 1;
-uint32_t Reserved :
- 21;
- }
- b;
-} USB_OTG_HCINTMSK_TypeDef ;
-
-typedef union _USB_OTG_PCGCCTL_TypeDef
-{
- uint32_t d32;
- struct
- {
-uint32_t stoppclk :
- 1;
-uint32_t gatehclk :
- 1;
-uint32_t Reserved2_3 :
- 2;
-uint32_t phy_susp :
- 1;
-uint32_t Reserved5_31 :
- 27;
- }
- b;
-} USB_OTG_PCGCCTL_TypeDef ;
-
-/**
- * @}
- */
-
-
-/** @defgroup USB_REGS_Exported_Macros
- * @{
- */
-/**
- * @}
- */
-
-/** @defgroup USB_REGS_Exported_Variables
- * @{
- */
-/**
- * @}
- */
-
-/** @defgroup USB_REGS_Exported_FunctionsPrototype
- * @{
- */
-/**
- * @}
- */
-
-
-#endif /* __USB_OTG_REGS_H__ */
-
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
-
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/src/usb_bsp_template.c b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/src/usb_bsp_template.c
deleted file mode 100644
index c6d188691..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/src/usb_bsp_template.c
+++ /dev/null
@@ -1,206 +0,0 @@
-/**
- ******************************************************************************
- * @file usb_bsp_template.c
- * @author xiuos Team
- * @version V1.0.0
- * @date 2020-9-3
- * @brief This file is based on usb_bsp.c
- * This file is responsible to offer board support package and is
- * configurable by user.
- ******************************************************************************
- * @file usb_bsp.c
- * @author MCD Application Team
- * @version V1.0.0
- * @date 30-September-2011
- * ********************************************************************************
- * @attention
- *
- * © Copyright (c) 2015 STMicroelectronics.
- * All rights reserved.
- *
- * This software component is licensed by ST under Ultimate Liberty license
- * SLA0044, the "License"; You may not use this file except in compliance with
- * the License. You may obtain a copy of the License at:
- *
- *
- ******************************************************************************
- */
-
-/* Includes ------------------------------------------------------------------*/
-#include "usb_bsp.h"
-
-/** @addtogroup USB_OTG_DRIVER
-* @{
-*/
-
-/** @defgroup USB_BSP
- * @brief This file is responsible to offer board support package
- * @{
- */
-
-/** @defgroup USB_BSP_Private_Defines
- * @{
- */
-/**
- * @}
- */
-
-
-/** @defgroup USB_BSP_Private_TypesDefinitions
- * @{
- */
-/**
- * @}
- */
-
-
-
-
-
-/** @defgroup USB_BSP_Private_Macros
- * @{
- */
-/**
- * @}
- */
-
-/** @defgroup USBH_BSP_Private_Variables
- * @{
- */
-
-/**
- * @}
- */
-
-/** @defgroup USBH_BSP_Private_FunctionPrototypes
- * @{
- */
-/**
- * @}
- */
-
-/** @defgroup USB_BSP_Private_Functions
- * @{
- */
-
-
-/**
- * @brief USB_OTG_BSP_Init
- * Initializes BSP configurations
- * @param None
- * @retval None
- */
-
-void USB_OTG_BSP_Init(void)
-{
-
-}
-/**
- * @brief USB_OTG_BSP_ENABLE_INTERRUPT
- * Enable USB Global interrupt
- * @param None
- * @retval None
- */
-void USB_OTG_BSP_ENABLE_INTERRUPT(void)
-{
-
-}
-
-/**
- * @brief BSP_Drive_VBUS
- * Drives the Vbus signal through IO
- * @param speed : Full, Low
- * @param state : VBUS states
- * @retval None
- */
-
-void USB_OTG_BSP_DriveVBUS(uint32_t speed, uint8_t state)
-{
-
-}
-
-/**
- * @brief USB_OTG_BSP_ConfigVBUS
- * Configures the IO for the Vbus and OverCurrent
- * @param Speed : Full, Low
- * @retval None
- */
-
-void USB_OTG_BSP_ConfigVBUS(uint32_t speed)
-{
-
-}
-
-/**
- * @brief USB_OTG_BSP_TimeInit
- * Initialises delay unit Systick timer /Timer2
- * @param None
- * @retval None
- */
-void USB_OTG_BSP_TimeInit ( void )
-{
-
-}
-
-/**
- * @brief USB_OTG_BSP_uDelay
- * This function provides delay time in micro sec
- * @param usec : Value of delay required in micro sec
- * @retval None
- */
-void USB_OTG_BSP_uDelay (const uint32_t usec)
-{
-
- uint32_t count = 0;
- const uint32_t utime = (120 * usec / 7);
- do
- {
- if ( ++count > utime )
- {
- return ;
- }
- }
- while (1);
-
-}
-
-
-/**
- * @brief USB_OTG_BSP_mDelay
- * This function provides delay time in milli sec
- * @param msec : Value of delay required in milli sec
- * @retval None
- */
-void USB_OTG_BSP_mDelay (const uint32_t msec)
-{
-
- USB_OTG_BSP_uDelay(msec * 1000);
-
-}
-
-
-/**
- * @brief USB_OTG_BSP_TimerIRQ
- * Time base IRQ
- * @param None
- * @retval None
- */
-
-void USB_OTG_BSP_TimerIRQ (void)
-{
-
-}
-
-/**
-* @}
-*/
-
-/**
-* @}
-*/
-
-/**
-* @}
-*/
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/src/usb_core.c b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/src/usb_core.c
deleted file mode 100644
index 6c51e449d..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/src/usb_core.c
+++ /dev/null
@@ -1,2253 +0,0 @@
-/**
- ******************************************************************************
- * @file usb_core.c
- * @author xiuos Team
- * @version V1.0.0
- * @date 2020-9-3
- * @brief This file is based on usb_core.c
- * USB-OTG Core Layer
- ******************************************************************************
- * @file usb_core.c
- * @author MCD Application Team
- * @version V1.0.0
- * @date 30-September-2011
- * ********************************************************************************
- * @attention
- *
- * © Copyright (c) 2015 STMicroelectronics.
- * All rights reserved.
- *
- * This software component is licensed by ST under Ultimate Liberty license
- * SLA0044, the "License"; You may not use this file except in compliance with
- * the License. You may obtain a copy of the License at:
- *
- *
- ******************************************************************************
- */
-
-/* Includes ------------------------------------------------------------------*/
-#include "usb_core.h"
-#include "usb_bsp.h"
-
-
-/** @addtogroup USB_OTG_DRIVER
-* @{
-*/
-
-/** @defgroup USB_CORE
-* @brief This file includes the USB-OTG Core Layer
-* @{
-*/
-
-
-/** @defgroup USB_CORE_Private_Defines
-* @{
-*/
-
-/**
-* @}
-*/
-
-
-/** @defgroup USB_CORE_Private_TypesDefinitions
-* @{
-*/
-/**
-* @}
-*/
-
-
-
-/** @defgroup USB_CORE_Private_Macros
-* @{
-*/
-/**
-* @}
-*/
-
-
-/** @defgroup USB_CORE_Private_Variables
-* @{
-*/
-/**
-* @}
-*/
-
-
-/** @defgroup USB_CORE_Private_FunctionPrototypes
-* @{
-*/
-/**
-* @}
-*/
-
-
-/** @defgroup USB_CORE_Private_Functions
-* @{
-*/
-
-/**
-* @brief USB_OTG_EnableCommonInt
-* Initializes the commmon interrupts, used in both device and modes
-* @param pdev : Selected device
-* @retval None
-*/
-static void USB_OTG_EnableCommonInt(USB_OTG_CORE_HANDLE *pdev)
-{
- USB_OTG_GINTMSK_TypeDef int_mask;
-
- int_mask.d32 = 0;
- /* Clear any pending USB_OTG Interrupts */
-#ifndef USE_OTG_MODE
- USB_OTG_WRITE_REG32( &pdev->regs.GREGS->GOTGINT, 0xFFFFFFFF);
-#endif
- /* Clear any pending interrupts */
- USB_OTG_WRITE_REG32( &pdev->regs.GREGS->GINTSTS, 0xBFFFFFFF);
- /* Enable the interrupts in the INTMSK */
- int_mask.b.wkupintr = 1;
- int_mask.b.usbsuspend = 1;
-
-#ifdef USE_OTG_MODE
- int_mask.b.otgintr = 1;
- int_mask.b.sessreqintr = 1;
- int_mask.b.conidstschng = 1;
-#endif
- USB_OTG_WRITE_REG32( &pdev->regs.GREGS->GINTMSK, int_mask.d32);
-}
-
-/**
-* @brief USB_OTG_CoreReset : Soft reset of the core
-* @param pdev : Selected device
-* @retval USB_OTG_STS : status
-*/
-static USB_OTG_STS USB_OTG_CoreReset(USB_OTG_CORE_HANDLE *pdev)
-{
- USB_OTG_STS status = USB_OTG_OK;
- __IO USB_OTG_GRSTCTL_TypeDef greset;
- uint32_t count = 0;
-
- greset.d32 = 0;
- /* Wait for AHB master IDLE state. */
- do
- {
- USB_OTG_BSP_uDelay(3);
- greset.d32 = USB_OTG_READ_REG32(&pdev->regs.GREGS->GRSTCTL);
- if (++count > 200000)
- {
- return USB_OTG_OK;
- }
- }
- while (greset.b.ahbidle == 0);
- /* Core Soft Reset */
- count = 0;
- greset.b.csftrst = 1;
- USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GRSTCTL, greset.d32 );
- do
- {
- greset.d32 = USB_OTG_READ_REG32(&pdev->regs.GREGS->GRSTCTL);
- if (++count > 200000)
- {
- break;
- }
- }
- while (greset.b.csftrst == 1);
- /* Wait for 3 PHY Clocks*/
- USB_OTG_BSP_uDelay(3);
- return status;
-}
-
-/**
-* @brief USB_OTG_WritePacket : Writes a packet into the Tx FIFO associated
-* with the EP
-* @param pdev : Selected device
-* @param src : source pointer
-* @param ch_ep_num : end point number
-* @param bytes : No. of bytes
-* @retval USB_OTG_STS : status
-*/
-USB_OTG_STS USB_OTG_WritePacket(USB_OTG_CORE_HANDLE *pdev,
- uint8_t *src,
- uint8_t ch_ep_num,
- uint16_t len)
-{
- USB_OTG_STS status = USB_OTG_OK;
- uint32_t count32b= 0 , i= 0;
- __IO uint32_t *fifo;
-
- if (pdev->cfg.dma_enable == 0)
- {
- count32b = (len + 3) / 4;
- fifo = pdev->regs.DFIFO[ch_ep_num];
- for (i = 0; i < count32b; i++)
- {
- USB_OTG_WRITE_REG32( fifo, *((__packed uint32_t *)src) );
- src+=4;
- }
- }
- return status;
-}
-
-
-/**
-* @brief USB_OTG_ReadPacket : Reads a packet from the Rx FIFO
-* @param pdev : Selected device
-* @param dest : Destination Pointer
-* @param bytes : No. of bytes
-* @retval None
-*/
-void *USB_OTG_ReadPacket(USB_OTG_CORE_HANDLE *pdev,
- uint8_t *dest,
- uint16_t len)
-{
- uint32_t i=0;
- uint32_t count32b = (len + 3) / 4;
-
- __IO uint32_t *fifo = pdev->regs.DFIFO[0];
-
- for( i = 0; i < count32b; i++)
- {
- *(__packed uint32_t *)dest = USB_OTG_READ_REG32(fifo);
- dest += 4 ;
- }
- return ((void *)dest);
-}
-
-/**
-* @brief USB_OTG_SelectCore
-* Initialize core registers address.
-* @param pdev : Selected device
-* @param coreID : USB OTG Core ID
-* @retval USB_OTG_STS : status
-*/
-USB_OTG_STS USB_OTG_SelectCore(USB_OTG_CORE_HANDLE *pdev,
- USB_OTG_CORE_ID_TypeDef coreID)
-{
- uint32_t i , baseAddress = 0;
- USB_OTG_STS status = USB_OTG_OK;
-
- pdev->cfg.dma_enable = 0;
-
- /* at startup the core is in FS mode */
- pdev->cfg.speed = USB_OTG_SPEED_FULL;
- pdev->cfg.mps = USB_OTG_FS_MAX_PACKET_SIZE ;
-
- /* initialize device cfg following its address */
- if (coreID == USB_OTG_FS_CORE_ID)
- {
- baseAddress = USB_OTG_FS_BASE_ADDR;
- pdev->cfg.coreID = USB_OTG_FS_CORE_ID;
- pdev->cfg.host_channels = 8 ;
- pdev->cfg.dev_endpoints = 4 ;
- pdev->cfg.TotalFifoSize = 320; /* in 32-bits */
- pdev->cfg.phy_itface = USB_OTG_EMBEDDED_PHY;
-
-#ifdef USB_OTG_FS_SOF_OUTPUT_ENABLED
- pdev->cfg.Sof_output = 1;
-#endif
-
-#ifdef USB_OTG_FS_LOW_PWR_MGMT_SUPPORT
- pdev->cfg.low_power = 0;
-#endif
- }
- else if (coreID == USB_OTG_HS_CORE_ID)
- {
- baseAddress = USB_OTG_HS_BASE_ADDR;
- pdev->cfg.coreID = USB_OTG_HS_CORE_ID;
- pdev->cfg.host_channels = 12 ;
- pdev->cfg.dev_endpoints = 6 ;
- pdev->cfg.TotalFifoSize = 1280;/* in 32-bits */
-
-#ifdef USB_OTG_ULPI_PHY_ENABLED
- pdev->cfg.phy_itface = USB_OTG_ULPI_PHY;
-#else
-#ifdef USB_OTG_EMBEDDED_PHY_ENABLED
- pdev->cfg.phy_itface = USB_OTG_EMBEDDED_PHY;
-#endif
-#endif
-
-#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
- pdev->cfg.dma_enable = 1;
-#endif
-
-#ifdef USB_OTG_HS_SOF_OUTPUT_ENABLED
- pdev->cfg.Sof_output = 1;
-#endif
-
-#ifdef USB_OTG_HS_LOW_PWR_MGMT_SUPPORT
- pdev->cfg.low_power = 1;
-#endif
-
- }
-
- else
- {
- /* Do Nothing */
- }
-
- pdev->regs.GREGS = (USB_OTG_GREGS *)(baseAddress + \
- USB_OTG_CORE_GLOBAL_REGS_OFFSET);
- pdev->regs.DREGS = (USB_OTG_DREGS *) (baseAddress + \
- USB_OTG_DEV_GLOBAL_REG_OFFSET);
-
- for (i = 0; i < pdev->cfg.dev_endpoints; i++)
- {
- pdev->regs.INEP_REGS[i] = (USB_OTG_INEPREGS *) \
- (baseAddress + USB_OTG_DEV_IN_EP_REG_OFFSET + \
- (i * USB_OTG_EP_REG_OFFSET));
- pdev->regs.OUTEP_REGS[i] = (USB_OTG_OUTEPREGS *) \
- (baseAddress + USB_OTG_DEV_OUT_EP_REG_OFFSET + \
- (i * USB_OTG_EP_REG_OFFSET));
- }
- pdev->regs.HREGS = (USB_OTG_HREGS *)(baseAddress + \
- USB_OTG_HOST_GLOBAL_REG_OFFSET);
- pdev->regs.HPRT0 = (uint32_t *)(baseAddress + USB_OTG_HOST_PORT_REGS_OFFSET);
-
- for (i = 0; i < pdev->cfg.host_channels; i++)
- {
- pdev->regs.HC_REGS[i] = (USB_OTG_HC_REGS *)(baseAddress + \
- USB_OTG_HOST_CHAN_REGS_OFFSET + \
- (i * USB_OTG_CHAN_REGS_OFFSET));
- }
- for (i = 0; i < pdev->cfg.host_channels; i++)
- {
- pdev->regs.DFIFO[i] = (uint32_t *)(baseAddress + USB_OTG_DATA_FIFO_OFFSET +\
- (i * USB_OTG_DATA_FIFO_SIZE));
- }
- pdev->regs.PCGCCTL = (uint32_t *)(baseAddress + USB_OTG_PCGCCTL_OFFSET);
-
- return status;
-}
-
-
-/**
-* @brief USB_OTG_CoreInit
-* Initializes the USB_OTG controller registers and prepares the core
-* device mode or host mode operation.
-* @param pdev : Selected device
-* @retval USB_OTG_STS : status
-*/
-USB_OTG_STS USB_OTG_CoreInit(USB_OTG_CORE_HANDLE *pdev)
-{
- USB_OTG_STS status = USB_OTG_OK;
- USB_OTG_GUSBCFG_TypeDef usbcfg;
- USB_OTG_GCCFG_TypeDef gccfg;
- USB_OTG_GAHBCFG_TypeDef ahbcfg;
-#if defined (STM32F446xx) || defined (STM32F469_479xx)
- USB_OTG_DCTL_TypeDef dctl;
-#endif
- usbcfg.d32 = 0;
- gccfg.d32 = 0;
- ahbcfg.d32 = 0;
-
- if (pdev->cfg.phy_itface == USB_OTG_ULPI_PHY)
- {
- gccfg.d32 = USB_OTG_READ_REG32(&pdev->regs.GREGS->GCCFG);
- gccfg.b.pwdn = 0;
-
-#if defined (STM32F446xx) || defined (STM32F469_479xx)
-#else
- if (pdev->cfg.Sof_output)
- {
- gccfg.b.sofouten = 1;
- }
-#endif
- USB_OTG_WRITE_REG32 (&pdev->regs.GREGS->GCCFG, gccfg.d32);
-
- /* Init The ULPI Interface */
- usbcfg.d32 = 0;
- usbcfg.d32 = USB_OTG_READ_REG32(&pdev->regs.GREGS->GUSBCFG);
-
- usbcfg.b.physel = 0; /* HS Interface */
-#ifdef USB_OTG_INTERNAL_VBUS_ENABLED
- usbcfg.b.ulpi_ext_vbus_drv = 0; /* Use internal VBUS */
-#else
-#ifdef USB_OTG_EXTERNAL_VBUS_ENABLED
- usbcfg.b.ulpi_ext_vbus_drv = 1; /* Use external VBUS */
-#endif
-#endif
- usbcfg.b.term_sel_dl_pulse = 0; /* Data line pulsing using utmi_txvalid */
-
- usbcfg.b.ulpi_fsls = 0;
- usbcfg.b.ulpi_clk_sus_m = 0;
- USB_OTG_WRITE_REG32 (&pdev->regs.GREGS->GUSBCFG, usbcfg.d32);
-
- /* Reset after a PHY select */
- USB_OTG_CoreReset(pdev);
-
- if(pdev->cfg.dma_enable == 1)
- {
-
- ahbcfg.b.hburstlen = 5; /* 64 x 32-bits*/
- ahbcfg.b.dmaenable = 1;
- USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GAHBCFG, ahbcfg.d32);
-
- }
- }
- else /* FS interface (embedded Phy) */
- {
-
- usbcfg.d32 = USB_OTG_READ_REG32(&pdev->regs.GREGS->GUSBCFG);;
- usbcfg.b.physel = 1; /* FS Interface */
- USB_OTG_WRITE_REG32 (&pdev->regs.GREGS->GUSBCFG, usbcfg.d32);
- /* Reset after a PHY select and set Host mode */
- USB_OTG_CoreReset(pdev);
- /* Deactivate the power down*/
- gccfg.d32 = 0;
- gccfg.b.pwdn = 1;
-
-#if defined (STM32F446xx) || defined (STM32F469_479xx)
- gccfg.b.vbden = 1;
-#else
- gccfg.b.vbussensingA = 1 ;
- gccfg.b.vbussensingB = 1 ;
-#endif
-
-
-#ifndef VBUS_SENSING_ENABLED
- gccfg.b.disablevbussensing = 1;
-#endif
-
-#if defined (STM32F446xx) || defined (STM32F469_479xx)
-#else
- if(pdev->cfg.Sof_output)
- {
- gccfg.b.sofouten = 1;
- }
-#endif
-
- USB_OTG_WRITE_REG32 (&pdev->regs.GREGS->GCCFG, gccfg.d32);
- USB_OTG_BSP_mDelay(20);
- }
- /* case the HS core is working in FS mode */
- if(pdev->cfg.dma_enable == 1)
- {
-
- ahbcfg.d32 = USB_OTG_READ_REG32(&pdev->regs.GREGS->GAHBCFG);
- ahbcfg.b.hburstlen = 5; /* 64 x 32-bits*/
- ahbcfg.b.dmaenable = 1;
- USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GAHBCFG, ahbcfg.d32);
-
- }
- /* initialize OTG features */
-#ifdef USE_OTG_MODE
- usbcfg.d32 = USB_OTG_READ_REG32(&pdev->regs.GREGS->GUSBCFG);
- usbcfg.b.hnpcap = 1;
- usbcfg.b.srpcap = 1;
- USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GUSBCFG, usbcfg.d32);
- USB_OTG_EnableCommonInt(pdev);
-#endif
-
-#if defined (STM32F446xx) || defined (STM32F469_479xx)
- usbcfg.d32 = USB_OTG_READ_REG32(&pdev->regs.GREGS->GUSBCFG);
- usbcfg.b.srpcap = 1;
- /*clear sdis bit in dctl */
- dctl.d32 = USB_OTG_READ_REG32(&pdev->regs.DREGS->DCTL);
- /* Connect device */
- dctl.b.sftdiscon = 0;
- USB_OTG_WRITE_REG32(&pdev->regs.DREGS->DCTL, dctl.d32);
- dctl.d32 = USB_OTG_READ_REG32(&pdev->regs.DREGS->DCTL);
- USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GUSBCFG, usbcfg.d32);
- USB_OTG_EnableCommonInt(pdev);
-#endif
-
- return status;
-}
-/**
-* @brief USB_OTG_EnableGlobalInt
-* Enables the controller's Global Int in the AHB Config reg
-* @param pdev : Selected device
-* @retval USB_OTG_STS : status
-*/
-USB_OTG_STS USB_OTG_EnableGlobalInt(USB_OTG_CORE_HANDLE *pdev)
-{
- USB_OTG_STS status = USB_OTG_OK;
- USB_OTG_GAHBCFG_TypeDef ahbcfg;
-
- ahbcfg.d32 = 0;
- ahbcfg.b.glblintrmsk = 1; /* Enable interrupts */
- USB_OTG_MODIFY_REG32(&pdev->regs.GREGS->GAHBCFG, 0, ahbcfg.d32);
- return status;
-}
-
-
-/**
-* @brief USB_OTG_DisableGlobalInt
-* Enables the controller's Global Int in the AHB Config reg
-* @param pdev : Selected device
-* @retval USB_OTG_STS : status
-*/
-USB_OTG_STS USB_OTG_DisableGlobalInt(USB_OTG_CORE_HANDLE *pdev)
-{
- USB_OTG_STS status = USB_OTG_OK;
- USB_OTG_GAHBCFG_TypeDef ahbcfg;
- ahbcfg.d32 = 0;
- ahbcfg.b.glblintrmsk = 1; /* Enable interrupts */
- USB_OTG_MODIFY_REG32(&pdev->regs.GREGS->GAHBCFG, ahbcfg.d32, 0);
- return status;
-}
-
-
-/**
-* @brief USB_OTG_FlushTxFifo : Flush a Tx FIFO
-* @param pdev : Selected device
-* @param num : FO num
-* @retval USB_OTG_STS : status
-*/
-USB_OTG_STS USB_OTG_FlushTxFifo (USB_OTG_CORE_HANDLE *pdev , uint32_t num )
-{
- USB_OTG_STS status = USB_OTG_OK;
- __IO USB_OTG_GRSTCTL_TypeDef greset;
-
- uint32_t count = 0;
- greset.d32 = 0;
- greset.b.txfflsh = 1;
- greset.b.txfnum = num;
- USB_OTG_WRITE_REG32( &pdev->regs.GREGS->GRSTCTL, greset.d32 );
- do
- {
- greset.d32 = USB_OTG_READ_REG32( &pdev->regs.GREGS->GRSTCTL);
- if (++count > 200000)
- {
- break;
- }
- }
- while (greset.b.txfflsh == 1);
- /* Wait for 3 PHY Clocks*/
- USB_OTG_BSP_uDelay(3);
- return status;
-}
-
-
-/**
-* @brief USB_OTG_FlushRxFifo : Flush a Rx FIFO
-* @param pdev : Selected device
-* @retval USB_OTG_STS : status
-*/
-USB_OTG_STS USB_OTG_FlushRxFifo( USB_OTG_CORE_HANDLE *pdev )
-{
- USB_OTG_STS status = USB_OTG_OK;
- __IO USB_OTG_GRSTCTL_TypeDef greset;
- uint32_t count = 0;
-
- greset.d32 = 0;
- greset.b.rxfflsh = 1;
- USB_OTG_WRITE_REG32( &pdev->regs.GREGS->GRSTCTL, greset.d32 );
- do
- {
- greset.d32 = USB_OTG_READ_REG32( &pdev->regs.GREGS->GRSTCTL);
- if (++count > 200000)
- {
- break;
- }
- }
- while (greset.b.rxfflsh == 1);
- /* Wait for 3 PHY Clocks*/
- USB_OTG_BSP_uDelay(3);
- return status;
-}
-
-
-/**
-* @brief USB_OTG_SetCurrentMode : Set ID line
-* @param pdev : Selected device
-* @param mode : (Host/device)
-* @retval USB_OTG_STS : status
-*/
-USB_OTG_STS USB_OTG_SetCurrentMode(USB_OTG_CORE_HANDLE *pdev , uint8_t mode)
-{
- USB_OTG_STS status = USB_OTG_OK;
- USB_OTG_GUSBCFG_TypeDef usbcfg;
-
- usbcfg.d32 = USB_OTG_READ_REG32(&pdev->regs.GREGS->GUSBCFG);
-
- usbcfg.b.force_host = 0;
- usbcfg.b.force_dev = 0;
-
- if ( mode == HOST_MODE)
- {
- usbcfg.b.force_host = 1;
- }
- else if ( mode == DEVICE_MODE)
- {
- usbcfg.b.force_dev = 1;
- }
-
- else
- {
- /* Do Nothing */
- }
-
- USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GUSBCFG, usbcfg.d32);
- USB_OTG_BSP_mDelay(50);
- return status;
-}
-
-
-/**
-* @brief USB_OTG_GetMode : Get current mode
-* @param pdev : Selected device
-* @retval current mode
-*/
-uint32_t USB_OTG_GetMode(USB_OTG_CORE_HANDLE *pdev)
-{
- return (USB_OTG_READ_REG32(&pdev->regs.GREGS->GINTSTS ) & 0x1);
-}
-
-
-/**
-* @brief USB_OTG_IsDeviceMode : Check if it is device mode
-* @param pdev : Selected device
-* @retval num_in_ep
-*/
-uint8_t USB_OTG_IsDeviceMode(USB_OTG_CORE_HANDLE *pdev)
-{
- return (USB_OTG_GetMode(pdev) != HOST_MODE);
-}
-
-
-/**
-* @brief USB_OTG_IsHostMode : Check if it is host mode
-* @param pdev : Selected device
-* @retval num_in_ep
-*/
-uint8_t USB_OTG_IsHostMode(USB_OTG_CORE_HANDLE *pdev)
-{
- return (USB_OTG_GetMode(pdev) == HOST_MODE);
-}
-
-
-/**
-* @brief USB_OTG_ReadCoreItr : returns the Core Interrupt register
-* @param pdev : Selected device
-* @retval Status
-*/
-uint32_t USB_OTG_ReadCoreItr(USB_OTG_CORE_HANDLE *pdev)
-{
- uint32_t v = 0;
- v = USB_OTG_READ_REG32(&pdev->regs.GREGS->GINTSTS);
- v &= USB_OTG_READ_REG32(&pdev->regs.GREGS->GINTMSK);
- return v;
-}
-
-
-/**
-* @brief USB_OTG_ReadOtgItr : returns the USB_OTG Interrupt register
-* @param pdev : Selected device
-* @retval Status
-*/
-uint32_t USB_OTG_ReadOtgItr (USB_OTG_CORE_HANDLE *pdev)
-{
- return (USB_OTG_READ_REG32 (&pdev->regs.GREGS->GOTGINT));
-}
-
-#ifdef USE_HOST_MODE
-/**
-* @brief USB_OTG_CoreInitHost : Initializes USB_OTG controller for host mode
-* @param pdev : Selected device
-* @retval status
-*/
-USB_OTG_STS USB_OTG_CoreInitHost(USB_OTG_CORE_HANDLE *pdev)
-{
- USB_OTG_STS status = USB_OTG_OK;
- USB_OTG_FSIZ_TypeDef nptxfifosize;
- USB_OTG_FSIZ_TypeDef ptxfifosize;
- USB_OTG_HCFG_TypeDef hcfg;
-
-#ifdef USE_OTG_MODE
- USB_OTG_OTGCTL_TypeDef gotgctl;
-#endif
-
- uint32_t i = 0;
-
- nptxfifosize.d32 = 0;
- ptxfifosize.d32 = 0;
-#ifdef USE_OTG_MODE
- gotgctl.d32 = 0;
-#endif
- hcfg.d32 = 0;
-
-
- /* configure charge pump IO */
- USB_OTG_BSP_ConfigVBUS(pdev);
-
- /* Restart the Phy Clock */
- USB_OTG_WRITE_REG32(pdev->regs.PCGCCTL, 0);
-
- /* Initialize Host Configuration Register */
- if (pdev->cfg.phy_itface == USB_OTG_ULPI_PHY)
- {
- USB_OTG_InitFSLSPClkSel(pdev , HCFG_30_60_MHZ);
- }
- else
- {
- USB_OTG_InitFSLSPClkSel(pdev , HCFG_48_MHZ);
- }
- USB_OTG_ResetPort(pdev);
-
- hcfg.d32 = USB_OTG_READ_REG32(&pdev->regs.HREGS->HCFG);
- hcfg.b.fslssupp = 0;
- USB_OTG_WRITE_REG32(&pdev->regs.HREGS->HCFG, hcfg.d32);
-
- /* Configure data FIFO sizes */
- /* Rx FIFO */
-#ifdef USB_OTG_FS_CORE
- if(pdev->cfg.coreID == USB_OTG_FS_CORE_ID)
- {
- /* set Rx FIFO size */
- USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GRXFSIZ, RX_FIFO_FS_SIZE);
- nptxfifosize.b.startaddr = RX_FIFO_FS_SIZE;
- nptxfifosize.b.depth = TXH_NP_FS_FIFOSIZ;
- USB_OTG_WRITE_REG32(&pdev->regs.GREGS->DIEPTXF0_HNPTXFSIZ, nptxfifosize.d32);
-
- ptxfifosize.b.startaddr = RX_FIFO_FS_SIZE + TXH_NP_FS_FIFOSIZ;
- ptxfifosize.b.depth = TXH_P_FS_FIFOSIZ;
- USB_OTG_WRITE_REG32(&pdev->regs.GREGS->HPTXFSIZ, ptxfifosize.d32);
- }
-#endif
-#ifdef USB_OTG_HS_CORE
- if (pdev->cfg.coreID == USB_OTG_HS_CORE_ID)
- {
- /* set Rx FIFO size */
- USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GRXFSIZ, RX_FIFO_HS_SIZE);
- nptxfifosize.b.startaddr = RX_FIFO_HS_SIZE;
- nptxfifosize.b.depth = TXH_NP_HS_FIFOSIZ;
- USB_OTG_WRITE_REG32(&pdev->regs.GREGS->DIEPTXF0_HNPTXFSIZ, nptxfifosize.d32);
-
- ptxfifosize.b.startaddr = RX_FIFO_HS_SIZE + TXH_NP_HS_FIFOSIZ;
- ptxfifosize.b.depth = TXH_P_HS_FIFOSIZ;
- USB_OTG_WRITE_REG32(&pdev->regs.GREGS->HPTXFSIZ, ptxfifosize.d32);
- }
-#endif
-
-#ifdef USE_OTG_MODE
- /* Clear Host Set HNP Enable in the USB_OTG Control Register */
- gotgctl.b.hstsethnpen = 1;
- USB_OTG_MODIFY_REG32( &pdev->regs.GREGS->GOTGCTL, gotgctl.d32, 0);
-#endif
-
- /* Make sure the FIFOs are flushed. */
- USB_OTG_FlushTxFifo(pdev, 0x10 ); /* all Tx FIFOs */
- USB_OTG_FlushRxFifo(pdev);
-
-
- /* Clear all pending HC Interrupts */
- for (i = 0; i < pdev->cfg.host_channels; i++)
- {
- USB_OTG_WRITE_REG32( &pdev->regs.HC_REGS[i]->HCINT, 0xFFFFFFFF );
- USB_OTG_WRITE_REG32( &pdev->regs.HC_REGS[i]->HCINTMSK, 0 );
- }
-#ifndef USE_OTG_MODE
- USB_OTG_DriveVbus(pdev, 1);
-#endif
-
- USB_OTG_EnableHostInt(pdev);
- return status;
-}
-
-/**
-* @brief USB_OTG_IsEvenFrame
-* This function returns the frame number for sof packet
-* @param pdev : Selected device
-* @retval Frame number
-*/
-uint8_t USB_OTG_IsEvenFrame (USB_OTG_CORE_HANDLE *pdev)
-{
- return !(USB_OTG_READ_REG32(&pdev->regs.HREGS->HFNUM) & 0x1);
-}
-
-/**
-* @brief USB_OTG_DriveVbus : set/reset vbus
-* @param pdev : Selected device
-* @param state : VBUS state
-* @retval None
-*/
-void USB_OTG_DriveVbus (USB_OTG_CORE_HANDLE *pdev, uint8_t state)
-{
- USB_OTG_HPRT0_TypeDef hprt0;
-
- hprt0.d32 = 0;
-
- /* enable disable the external charge pump */
- USB_OTG_BSP_DriveVBUS(pdev, state);
-
- /* Turn on the Host port power. */
- hprt0.d32 = USB_OTG_ReadHPRT0(pdev);
- if ((hprt0.b.prtpwr == 0 ) && (state == 1 ))
- {
- hprt0.b.prtpwr = 1;
- USB_OTG_WRITE_REG32(pdev->regs.HPRT0, hprt0.d32);
- }
- if ((hprt0.b.prtpwr == 1 ) && (state == 0 ))
- {
- hprt0.b.prtpwr = 0;
- USB_OTG_WRITE_REG32(pdev->regs.HPRT0, hprt0.d32);
- }
-
- USB_OTG_BSP_mDelay(200);
-}
-/**
-* @brief USB_OTG_EnableHostInt: Enables the Host mode interrupts
-* @param pdev : Selected device
-* @retval USB_OTG_STS : status
-*/
-USB_OTG_STS USB_OTG_EnableHostInt(USB_OTG_CORE_HANDLE *pdev)
-{
- USB_OTG_STS status = USB_OTG_OK;
- USB_OTG_GINTMSK_TypeDef intmsk;
- intmsk.d32 = 0;
- /* Disable all interrupts. */
- USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GINTMSK, 0);
-
- /* Clear any pending interrupts. */
- USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GINTSTS, 0xFFFFFFFF);
-
- /* Enable the common interrupts */
- USB_OTG_EnableCommonInt(pdev);
-
- if (pdev->cfg.dma_enable == 0)
- {
- intmsk.b.rxstsqlvl = 1;
- }
-
-
- intmsk.b.incomplisoout = 1;
- intmsk.b.hcintr = 1;
-intmsk.b.portintr = 1;
- intmsk.b.sofintr = 1;
- intmsk.b.disconnect = 1;
- intmsk.b.incomplisoout = 1;
- intmsk.b.wkupintr = 1;
-
- intmsk.b.disconnect = 1;
-
- intmsk.b.sofintr = 1;
- USB_OTG_MODIFY_REG32(&pdev->regs.GREGS->GINTMSK, intmsk.d32, intmsk.d32);
-
- return status;
-}
-
-/**
-* @brief USB_OTG_InitFSLSPClkSel : Initializes the FSLSPClkSel field of the
-* HCFG register on the PHY type
-* @param pdev : Selected device
-* @param freq : clock frequency
-* @retval None
-*/
-void USB_OTG_InitFSLSPClkSel(USB_OTG_CORE_HANDLE *pdev , uint8_t freq)
-{
- USB_OTG_HCFG_TypeDef hcfg;
-
- hcfg.d32 = USB_OTG_READ_REG32(&pdev->regs.HREGS->HCFG);
- hcfg.b.fslspclksel = freq;
- USB_OTG_WRITE_REG32(&pdev->regs.HREGS->HCFG, hcfg.d32);
-}
-
-
-/**
-* @brief USB_OTG_ReadHPRT0 : Reads HPRT0 to modify later
-* @param pdev : Selected device
-* @retval HPRT0 value
-*/
-uint32_t USB_OTG_ReadHPRT0(USB_OTG_CORE_HANDLE *pdev)
-{
- USB_OTG_HPRT0_TypeDef hprt0;
-
- hprt0.d32 = USB_OTG_READ_REG32(pdev->regs.HPRT0);
- hprt0.b.prtena = 0;
- hprt0.b.prtconndet = 0;
- hprt0.b.prtenchng = 0;
- hprt0.b.prtovrcurrchng = 0;
- return hprt0.d32;
-}
-
-
-/**
-* @brief USB_OTG_ReadHostAllChannels_intr : Register PCD Callbacks
-* @param pdev : Selected device
-* @retval Status
-*/
-uint32_t USB_OTG_ReadHostAllChannels_intr (USB_OTG_CORE_HANDLE *pdev)
-{
- return (USB_OTG_READ_REG32 (&pdev->regs.HREGS->HAINT));
-}
-
-
-/**
-* @brief USB_OTG_ResetPort : Reset Host Port
-* @param pdev : Selected device
-* @retval status
-* @note : (1)The application must wait at least 10 ms (+ 10 ms security)
-* before clearing the reset bit.
-*/
-uint32_t USB_OTG_ResetPort(USB_OTG_CORE_HANDLE *pdev)
-{
- USB_OTG_HPRT0_TypeDef hprt0;
-
- hprt0.d32 = USB_OTG_ReadHPRT0(pdev);
- hprt0.b.prtrst = 1;
- USB_OTG_WRITE_REG32(pdev->regs.HPRT0, hprt0.d32);
- USB_OTG_BSP_mDelay (100); /* See Note #1 */
- hprt0.b.prtrst = 0;
- USB_OTG_WRITE_REG32(pdev->regs.HPRT0, hprt0.d32);
- USB_OTG_BSP_mDelay (20);
- return 1;
-}
-
-
-/**
-* @brief USB_OTG_HC_Init : Prepares a host channel for transferring packets
-* @param pdev : Selected device
-* @param hc_num : channel number
-* @retval USB_OTG_STS : status
-*/
-USB_OTG_STS USB_OTG_HC_Init(USB_OTG_CORE_HANDLE *pdev , uint8_t hc_num)
-{
- USB_OTG_STS status = USB_OTG_OK;
- uint32_t intr_enable = 0;
- USB_OTG_HCINTMSK_TypeDef hcintmsk;
- USB_OTG_GINTMSK_TypeDef gintmsk;
- USB_OTG_HCCHAR_TypeDef hcchar;
- USB_OTG_HCINTn_TypeDef hcint;
-
-
- gintmsk.d32 = 0;
- hcintmsk.d32 = 0;
- hcchar.d32 = 0;
-
- /* Clear old interrupt conditions for this host channel. */
- hcint.d32 = 0xFFFFFFFF;
- USB_OTG_WRITE_REG32(&pdev->regs.HC_REGS[hc_num]->HCINT, hcint.d32);
-
- /* Enable channel interrupts required for this transfer. */
- hcintmsk.d32 = 0;
-
- if (pdev->cfg.dma_enable == 1)
- {
- hcintmsk.b.ahberr = 1;
- }
-
- switch (pdev->host.hc[hc_num].ep_type)
- {
- case EP_TYPE_CTRL:
- case EP_TYPE_BULK:
- hcintmsk.b.xfercompl = 1;
- hcintmsk.b.stall = 1;
- hcintmsk.b.xacterr = 1;
- hcintmsk.b.datatglerr = 1;
- hcintmsk.b.nak = 1;
- if (pdev->host.hc[hc_num].ep_is_in)
- {
- hcintmsk.b.bblerr = 1;
- }
- else
- {
- hcintmsk.b.nyet = 1;
- if (pdev->host.hc[hc_num].do_ping)
- {
- hcintmsk.b.ack = 1;
- }
- }
- break;
- case EP_TYPE_INTR:
- hcintmsk.b.xfercompl = 1;
- hcintmsk.b.nak = 1;
- hcintmsk.b.stall = 1;
- hcintmsk.b.xacterr = 1;
- hcintmsk.b.datatglerr = 1;
- hcintmsk.b.frmovrun = 1;
-
- if (pdev->host.hc[hc_num].ep_is_in)
- {
- hcintmsk.b.bblerr = 1;
- }
-
- break;
- case EP_TYPE_ISOC:
- hcintmsk.b.xfercompl = 1;
- hcintmsk.b.frmovrun = 1;
- hcintmsk.b.ack = 1;
-
- if (pdev->host.hc[hc_num].ep_is_in)
- {
- hcintmsk.b.xacterr = 1;
- hcintmsk.b.bblerr = 1;
- }
- break;
- }
-
-
- USB_OTG_WRITE_REG32(&pdev->regs.HC_REGS[hc_num]->HCINTMSK, hcintmsk.d32);
-
-
- /* Enable the top level host channel interrupt. */
- intr_enable = (1 << hc_num);
- USB_OTG_MODIFY_REG32(&pdev->regs.HREGS->HAINTMSK, 0, intr_enable);
-
- /* Make sure host channel interrupts are enabled. */
- gintmsk.b.hcintr = 1;
- USB_OTG_MODIFY_REG32(&pdev->regs.GREGS->GINTMSK, 0, gintmsk.d32);
-
- /* Program the HCCHAR register */
- hcchar.d32 = 0;
- hcchar.b.devaddr = pdev->host.hc[hc_num].DevAddr;
- hcchar.b.epnum = pdev->host.hc[hc_num].ep_num;
- hcchar.b.epdir = pdev->host.hc[hc_num].ep_is_in;
- hcchar.b.lspddev = (pdev->host.hc[hc_num].speed == HPRT0_PRTSPD_LOW_SPEED);
- hcchar.b.eptype = pdev->host.hc[hc_num].ep_type;
- hcchar.b.mps = pdev->host.hc[hc_num].max_packet;
- if (pdev->host.hc[hc_num].ep_type == HCCHAR_INTR)
- {
- hcchar.b.oddfrm = 1;
- }
- USB_OTG_WRITE_REG32(&pdev->regs.HC_REGS[hc_num]->HCCHAR, hcchar.d32);
- return status;
-}
-
-
-/**
-* @brief USB_OTG_HC_StartXfer : Start transfer
-* @param pdev : Selected device
-* @param hc_num : channel number
-* @retval USB_OTG_STS : status
-*/
-USB_OTG_STS USB_OTG_HC_StartXfer(USB_OTG_CORE_HANDLE *pdev , uint8_t hc_num)
-{
- USB_OTG_STS status = USB_OTG_OK;
- USB_OTG_HCCHAR_TypeDef hcchar;
- USB_OTG_HCTSIZn_TypeDef hctsiz;
- USB_OTG_HNPTXSTS_TypeDef hnptxsts;
- USB_OTG_HPTXSTS_TypeDef hptxsts;
- USB_OTG_GINTMSK_TypeDef intmsk;
- uint16_t len_words = 0;
-
- uint16_t num_packets;
- uint16_t max_hc_pkt_count;
-
- max_hc_pkt_count = 256;
- hctsiz.d32 = 0;
- hcchar.d32 = 0;
- intmsk.d32 = 0;
-
- /* Compute the expected number of packets associated to the transfer */
- if (pdev->host.hc[hc_num].XferLen > 0)
- {
- num_packets = (pdev->host.hc[hc_num].XferLen + \
- pdev->host.hc[hc_num].max_packet - 1) / pdev->host.hc[hc_num].max_packet;
-
- if (num_packets > max_hc_pkt_count)
- {
- num_packets = max_hc_pkt_count;
- pdev->host.hc[hc_num].XferLen = num_packets * \
- pdev->host.hc[hc_num].max_packet;
- }
- }
- else
- {
- num_packets = 1;
- }
- if (pdev->host.hc[hc_num].ep_is_in)
- {
- pdev->host.hc[hc_num].XferLen = num_packets * \
- pdev->host.hc[hc_num].max_packet;
- }
- /* Initialize the HCTSIZn register */
- hctsiz.b.xfersize = pdev->host.hc[hc_num].XferLen;
- hctsiz.b.pktcnt = num_packets;
- hctsiz.b.pid = pdev->host.hc[hc_num].data_pid;
- USB_OTG_WRITE_REG32(&pdev->regs.HC_REGS[hc_num]->HCTSIZ, hctsiz.d32);
-
- if (pdev->cfg.dma_enable == 1)
- {
- USB_OTG_WRITE_REG32(&pdev->regs.HC_REGS[hc_num]->HCDMA, (unsigned int)pdev->host.hc[hc_num].xfer_buff);
- }
-
-
- hcchar.d32 = USB_OTG_READ_REG32(&pdev->regs.HC_REGS[hc_num]->HCCHAR);
- hcchar.b.oddfrm = USB_OTG_IsEvenFrame(pdev);
-
- /* Set host channel enable */
- hcchar.b.chen = 1;
- hcchar.b.chdis = 0;
- USB_OTG_WRITE_REG32(&pdev->regs.HC_REGS[hc_num]->HCCHAR, hcchar.d32);
-
- if (pdev->cfg.dma_enable == 0) /* Slave mode */
- {
- if((pdev->host.hc[hc_num].ep_is_in == 0) &&
- (pdev->host.hc[hc_num].XferLen > 0))
- {
- switch(pdev->host.hc[hc_num].ep_type)
- {
- /* Non periodic transfer */
- case EP_TYPE_CTRL:
- case EP_TYPE_BULK:
-
- hnptxsts.d32 = USB_OTG_READ_REG32(&pdev->regs.GREGS->HNPTXSTS);
- len_words = (pdev->host.hc[hc_num].XferLen + 3) / 4;
-
- /* check if there is enough space in FIFO space */
- if(len_words > hnptxsts.b.nptxfspcavail)
- {
- /* need to process data in nptxfempty interrupt */
- intmsk.b.nptxfempty = 1;
- USB_OTG_MODIFY_REG32( &pdev->regs.GREGS->GINTMSK, 0, intmsk.d32);
- }
-
- break;
- /* Periodic transfer */
- case EP_TYPE_INTR:
- case EP_TYPE_ISOC:
- hptxsts.d32 = USB_OTG_READ_REG32(&pdev->regs.HREGS->HPTXSTS);
- len_words = (pdev->host.hc[hc_num].XferLen + 3) / 4;
- /* check if there is enough space in FIFO space */
- if(len_words > hptxsts.b.ptxfspcavail) /* split the transfer */
- {
- /* need to process data in ptxfempty interrupt */
- intmsk.b.ptxfempty = 1;
- USB_OTG_MODIFY_REG32( &pdev->regs.GREGS->GINTMSK, 0, intmsk.d32);
- }
- break;
-
- default:
- break;
- }
-
- /* Write packet into the Tx FIFO. */
- USB_OTG_WritePacket(pdev,
- pdev->host.hc[hc_num].xfer_buff ,
- hc_num, pdev->host.hc[hc_num].XferLen);
- }
- }
- return status;
-}
-
-
-/**
-* @brief USB_OTG_HC_Halt : Halt channel
-* @param pdev : Selected device
-* @param hc_num : channel number
-* @retval USB_OTG_STS : status
-*/
-USB_OTG_STS USB_OTG_HC_Halt(USB_OTG_CORE_HANDLE *pdev , uint8_t hc_num)
-{
- USB_OTG_STS status = USB_OTG_OK;
- USB_OTG_HNPTXSTS_TypeDef nptxsts;
- USB_OTG_HPTXSTS_TypeDef hptxsts;
- USB_OTG_HCCHAR_TypeDef hcchar;
-
- nptxsts.d32 = 0;
- hptxsts.d32 = 0;
- hcchar.d32 = USB_OTG_READ_REG32(&pdev->regs.HC_REGS[hc_num]->HCCHAR);
-
- hcchar.b.chdis = 1;
-
- /* Check for space in the request queue to issue the halt. */
- if (hcchar.b.eptype == HCCHAR_CTRL || hcchar.b.eptype == HCCHAR_BULK)
- {
- nptxsts.d32 = USB_OTG_READ_REG32(&pdev->regs.GREGS->HNPTXSTS);
- if (nptxsts.b.nptxqspcavail == 0)
- {
- hcchar.b.chen = 0;
- USB_OTG_WRITE_REG32(&pdev->regs.HC_REGS[hc_num]->HCCHAR, hcchar.d32);
- }
- }
- else
- {
- hptxsts.d32 = USB_OTG_READ_REG32(&pdev->regs.HREGS->HPTXSTS);
- if (hptxsts.b.ptxqspcavail == 0)
- {
- hcchar.b.chen = 0;
- USB_OTG_WRITE_REG32(&pdev->regs.HC_REGS[hc_num]->HCCHAR, hcchar.d32);
- }
- }
- hcchar.b.chen = 1;
- USB_OTG_WRITE_REG32(&pdev->regs.HC_REGS[hc_num]->HCCHAR, hcchar.d32);
- return status;
-}
-
-/**
-* @brief Issue a ping token
-* @param None
-* @retval : None
-*/
-USB_OTG_STS USB_OTG_HC_DoPing(USB_OTG_CORE_HANDLE *pdev , uint8_t hc_num)
-{
- USB_OTG_STS status = USB_OTG_OK;
- USB_OTG_HCCHAR_TypeDef hcchar;
- USB_OTG_HCTSIZn_TypeDef hctsiz;
-
- hctsiz.d32 = 0;
- hctsiz.b.dopng = 1;
- hctsiz.b.pktcnt = 1;
- USB_OTG_WRITE_REG32(&pdev->regs.HC_REGS[hc_num]->HCTSIZ, hctsiz.d32);
-
- hcchar.d32 = USB_OTG_READ_REG32(&pdev->regs.HC_REGS[hc_num]->HCCHAR);
- hcchar.b.chen = 1;
- hcchar.b.chdis = 0;
- USB_OTG_WRITE_REG32(&pdev->regs.HC_REGS[hc_num]->HCCHAR, hcchar.d32);
- return status;
-}
-
-/**
-* @brief Stop the device and clean up fifo's
-* @param None
-* @retval : None
-*/
-void USB_OTG_StopHost(USB_OTG_CORE_HANDLE *pdev)
-{
- USB_OTG_HCCHAR_TypeDef hcchar;
- uint32_t i;
-
- USB_OTG_WRITE_REG32(&pdev->regs.HREGS->HAINTMSK , 0);
- USB_OTG_WRITE_REG32(&pdev->regs.HREGS->HAINT, 0xFFFFFFFF);
- /* Flush out any leftover queued requests. */
-
- for (i = 0; i < pdev->cfg.host_channels; i++)
- {
- hcchar.d32 = USB_OTG_READ_REG32(&pdev->regs.HC_REGS[i]->HCCHAR);
- hcchar.b.chen = 0;
- hcchar.b.chdis = 1;
- hcchar.b.epdir = 0;
- USB_OTG_WRITE_REG32(&pdev->regs.HC_REGS[i]->HCCHAR, hcchar.d32);
- }
-
- /* Flush the FIFO */
- USB_OTG_FlushRxFifo(pdev);
- USB_OTG_FlushTxFifo(pdev , 0x10 );
-}
-#endif
-#ifdef USE_DEVICE_MODE
-/* PCD Core Layer */
-
-/**
-* @brief USB_OTG_InitDevSpeed :Initializes the DevSpd field of DCFG register
-* depending the PHY type and the enumeration speed of the device.
-* @param pdev : Selected device
-* @retval : None
-*/
-void USB_OTG_InitDevSpeed(USB_OTG_CORE_HANDLE *pdev , uint8_t speed)
-{
- USB_OTG_DCFG_TypeDef dcfg;
-
- dcfg.d32 = USB_OTG_READ_REG32(&pdev->regs.DREGS->DCFG);
- dcfg.b.devspd = speed;
- USB_OTG_WRITE_REG32(&pdev->regs.DREGS->DCFG, dcfg.d32);
-}
-
-
-/**
-* @brief USB_OTG_CoreInitDev : Initializes the USB_OTG controller registers
-* for device mode
-* @param pdev : Selected device
-* @retval USB_OTG_STS : status
-*/
-USB_OTG_STS USB_OTG_CoreInitDev (USB_OTG_CORE_HANDLE *pdev)
-{
- USB_OTG_STS status = USB_OTG_OK;
- USB_OTG_DEPCTL_TypeDef depctl;
- uint32_t i;
- USB_OTG_DCFG_TypeDef dcfg;
- USB_OTG_FSIZ_TypeDef nptxfifosize;
- USB_OTG_FSIZ_TypeDef txfifosize;
- USB_OTG_DIEPMSK_TypeDef msk;
- USB_OTG_DTHRCTL_TypeDef dthrctl;
-
- depctl.d32 = 0;
- dcfg.d32 = 0;
- nptxfifosize.d32 = 0;
- txfifosize.d32 = 0;
- msk.d32 = 0;
-
- /* Restart the Phy Clock */
- USB_OTG_WRITE_REG32(pdev->regs.PCGCCTL, 0);
- /* Device configuration register */
- dcfg.d32 = USB_OTG_READ_REG32( &pdev->regs.DREGS->DCFG);
- dcfg.b.perfrint = DCFG_FRAME_INTERVAL_80;
- USB_OTG_WRITE_REG32( &pdev->regs.DREGS->DCFG, dcfg.d32 );
-
-#ifdef USB_OTG_FS_CORE
- if(pdev->cfg.coreID == USB_OTG_FS_CORE_ID )
- {
-
- /* Set Full speed phy */
- USB_OTG_InitDevSpeed (pdev , USB_OTG_SPEED_PARAM_FULL);
-
- /* set Rx FIFO size */
- USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GRXFSIZ, RX_FIFO_FS_SIZE);
-
- /* EP0 TX*/
- nptxfifosize.b.depth = TX0_FIFO_FS_SIZE;
- nptxfifosize.b.startaddr = RX_FIFO_FS_SIZE;
- USB_OTG_WRITE_REG32( &pdev->regs.GREGS->DIEPTXF0_HNPTXFSIZ, nptxfifosize.d32 );
-
-
- /* EP1 TX*/
- txfifosize.b.startaddr = nptxfifosize.b.startaddr + nptxfifosize.b.depth;
- txfifosize.b.depth = TX1_FIFO_FS_SIZE;
- USB_OTG_WRITE_REG32( &pdev->regs.GREGS->DIEPTXF[0], txfifosize.d32 );
-
-
- /* EP2 TX*/
- txfifosize.b.startaddr += txfifosize.b.depth;
- txfifosize.b.depth = TX2_FIFO_FS_SIZE;
- USB_OTG_WRITE_REG32( &pdev->regs.GREGS->DIEPTXF[1], txfifosize.d32 );
-
-
- /* EP3 TX*/
- txfifosize.b.startaddr += txfifosize.b.depth;
- txfifosize.b.depth = TX3_FIFO_FS_SIZE;
- USB_OTG_WRITE_REG32( &pdev->regs.GREGS->DIEPTXF[2], txfifosize.d32 );
- }
-#endif
-#ifdef USB_OTG_HS_CORE
- if(pdev->cfg.coreID == USB_OTG_HS_CORE_ID )
- {
-
- /* Set High speed phy */
-
- if(pdev->cfg.phy_itface == USB_OTG_ULPI_PHY)
- {
- USB_OTG_InitDevSpeed (pdev , USB_OTG_SPEED_PARAM_HIGH);
- }
- else /* set High speed phy in Full speed mode */
- {
- USB_OTG_InitDevSpeed (pdev , USB_OTG_SPEED_PARAM_HIGH_IN_FULL);
- }
-
- /* set Rx FIFO size */
- USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GRXFSIZ, RX_FIFO_HS_SIZE);
-
- /* EP0 TX*/
- nptxfifosize.b.depth = TX0_FIFO_HS_SIZE;
- nptxfifosize.b.startaddr = RX_FIFO_HS_SIZE;
- USB_OTG_WRITE_REG32( &pdev->regs.GREGS->DIEPTXF0_HNPTXFSIZ, nptxfifosize.d32 );
-
-
- /* EP1 TX*/
- txfifosize.b.startaddr = nptxfifosize.b.startaddr + nptxfifosize.b.depth;
- txfifosize.b.depth = TX1_FIFO_HS_SIZE;
- USB_OTG_WRITE_REG32( &pdev->regs.GREGS->DIEPTXF[0], txfifosize.d32 );
-
-
- /* EP2 TX*/
- txfifosize.b.startaddr += txfifosize.b.depth;
- txfifosize.b.depth = TX2_FIFO_HS_SIZE;
- USB_OTG_WRITE_REG32( &pdev->regs.GREGS->DIEPTXF[1], txfifosize.d32 );
-
-
- /* EP3 TX*/
- txfifosize.b.startaddr += txfifosize.b.depth;
- txfifosize.b.depth = TX3_FIFO_HS_SIZE;
- USB_OTG_WRITE_REG32( &pdev->regs.GREGS->DIEPTXF[2], txfifosize.d32 );
-
- /* EP4 TX*/
- txfifosize.b.startaddr += txfifosize.b.depth;
- txfifosize.b.depth = TX4_FIFO_HS_SIZE;
- USB_OTG_WRITE_REG32( &pdev->regs.GREGS->DIEPTXF[3], txfifosize.d32 );
-
-
- /* EP5 TX*/
- txfifosize.b.startaddr += txfifosize.b.depth;
- txfifosize.b.depth = TX5_FIFO_HS_SIZE;
- USB_OTG_WRITE_REG32( &pdev->regs.GREGS->DIEPTXF[4], txfifosize.d32 );
- }
-#endif
- /* Flush the FIFOs */
- USB_OTG_FlushTxFifo(pdev , 0x10); /* all Tx FIFOs */
- USB_OTG_FlushRxFifo(pdev);
- /* Clear all pending Device Interrupts */
- USB_OTG_WRITE_REG32( &pdev->regs.DREGS->DIEPMSK, 0 );
- USB_OTG_WRITE_REG32( &pdev->regs.DREGS->DOEPMSK, 0 );
- USB_OTG_WRITE_REG32( &pdev->regs.DREGS->DAINT, 0xFFFFFFFF );
- USB_OTG_WRITE_REG32( &pdev->regs.DREGS->DAINTMSK, 0 );
-
- for (i = 0; i < pdev->cfg.dev_endpoints; i++)
- {
- depctl.d32 = USB_OTG_READ_REG32(&pdev->regs.INEP_REGS[i]->DIEPCTL);
- if (depctl.b.epena)
- {
- depctl.d32 = 0;
- depctl.b.epdis = 1;
- depctl.b.snak = 1;
- }
- else
- {
- depctl.d32 = 0;
- }
- USB_OTG_WRITE_REG32( &pdev->regs.INEP_REGS[i]->DIEPCTL, depctl.d32);
- USB_OTG_WRITE_REG32( &pdev->regs.INEP_REGS[i]->DIEPTSIZ, 0);
- USB_OTG_WRITE_REG32( &pdev->regs.INEP_REGS[i]->DIEPINT, 0xFF);
- }
- for (i = 0; i < pdev->cfg.dev_endpoints; i++)
- {
- USB_OTG_DEPCTL_TypeDef depctl;
- depctl.d32 = USB_OTG_READ_REG32(&pdev->regs.OUTEP_REGS[i]->DOEPCTL);
- if (depctl.b.epena)
- {
- depctl.d32 = 0;
- depctl.b.epdis = 1;
- depctl.b.snak = 1;
- }
- else
- {
- depctl.d32 = 0;
- }
- USB_OTG_WRITE_REG32( &pdev->regs.OUTEP_REGS[i]->DOEPCTL, depctl.d32);
- USB_OTG_WRITE_REG32( &pdev->regs.OUTEP_REGS[i]->DOEPTSIZ, 0);
- USB_OTG_WRITE_REG32( &pdev->regs.OUTEP_REGS[i]->DOEPINT, 0xFF);
- }
- msk.d32 = 0;
- msk.b.txfifoundrn = 1;
- USB_OTG_MODIFY_REG32(&pdev->regs.DREGS->DIEPMSK, msk.d32, msk.d32);
-
- if (pdev->cfg.dma_enable == 1)
- {
- dthrctl.d32 = 0;
- dthrctl.b.non_iso_thr_en = 1;
- dthrctl.b.iso_thr_en = 1;
- dthrctl.b.tx_thr_len = 64;
- dthrctl.b.rx_thr_en = 1;
- dthrctl.b.rx_thr_len = 64;
- USB_OTG_WRITE_REG32(&pdev->regs.DREGS->DTHRCTL, dthrctl.d32);
- }
- USB_OTG_EnableDevInt(pdev);
- return status;
-}
-
-
-/**
-* @brief USB_OTG_EnableDevInt : Enables the Device mode interrupts
-* @param pdev : Selected device
-* @retval USB_OTG_STS : status
-*/
-USB_OTG_STS USB_OTG_EnableDevInt(USB_OTG_CORE_HANDLE *pdev)
-{
- USB_OTG_STS status = USB_OTG_OK;
- USB_OTG_GINTMSK_TypeDef intmsk;
-
- intmsk.d32 = 0;
-
- /* Disable all interrupts. */
- USB_OTG_WRITE_REG32( &pdev->regs.GREGS->GINTMSK, 0);
- /* Clear any pending interrupts */
- USB_OTG_WRITE_REG32( &pdev->regs.GREGS->GINTSTS, 0xBFFFFFFF);
- /* Enable the common interrupts */
- USB_OTG_EnableCommonInt(pdev);
-
- if (pdev->cfg.dma_enable == 0)
- {
- intmsk.b.rxstsqlvl = 1;
- }
-
- /* Enable interrupts matching to the Device mode ONLY */
- intmsk.b.usbsuspend = 1;
- intmsk.b.usbreset = 1;
- intmsk.b.enumdone = 1;
- intmsk.b.inepintr = 1;
- intmsk.b.outepintr = 1;
- intmsk.b.sofintr = 1;
-
- intmsk.b.incomplisoin = 1;
- intmsk.b.incomplisoout = 1;
-#ifdef VBUS_SENSING_ENABLED
- intmsk.b.sessreqintr = 1;
- intmsk.b.otgintr = 1;
-#endif
- USB_OTG_MODIFY_REG32( &pdev->regs.GREGS->GINTMSK, intmsk.d32, intmsk.d32);
- return status;
-}
-
-
-/**
-* @brief USB_OTG_GetDeviceSpeed
-* Get the device speed from the device status register
-* @param None
-* @retval status
-*/
-enum USB_OTG_SPEED USB_OTG_GetDeviceSpeed (USB_OTG_CORE_HANDLE *pdev)
-{
- USB_OTG_DSTS_TypeDef dsts;
- enum USB_OTG_SPEED speed = USB_SPEED_UNKNOWN;
-
-
- dsts.d32 = USB_OTG_READ_REG32(&pdev->regs.DREGS->DSTS);
-
- switch (dsts.b.enumspd)
- {
- case DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ:
- speed = USB_SPEED_HIGH;
- break;
- case DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ:
- case DSTS_ENUMSPD_FS_PHY_48MHZ:
- speed = USB_SPEED_FULL;
- break;
-
- case DSTS_ENUMSPD_LS_PHY_6MHZ:
- speed = USB_SPEED_LOW;
- break;
- default:
- speed = USB_SPEED_FULL;
- break;
- }
-
- return speed;
-}
-
-/**
-* @brief enables EP0 OUT to receive SETUP packets and configures EP0
-* for transmitting packets
-* @param None
-* @retval USB_OTG_STS : status
-*/
-USB_OTG_STS USB_OTG_EP0Activate(USB_OTG_CORE_HANDLE *pdev)
-{
- USB_OTG_STS status = USB_OTG_OK;
- USB_OTG_DSTS_TypeDef dsts;
- USB_OTG_DEPCTL_TypeDef diepctl;
- USB_OTG_DCTL_TypeDef dctl;
-
- dctl.d32 = 0;
- /* Read the Device Status and Endpoint 0 Control registers */
- dsts.d32 = USB_OTG_READ_REG32(&pdev->regs.DREGS->DSTS);
- diepctl.d32 = USB_OTG_READ_REG32(&pdev->regs.INEP_REGS[0]->DIEPCTL);
- /* Set the MPS of the IN EP based on the enumeration speed */
- switch (dsts.b.enumspd)
- {
- case DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ:
- case DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ:
- case DSTS_ENUMSPD_FS_PHY_48MHZ:
- diepctl.b.mps = DEP0CTL_MPS_64;
- break;
- case DSTS_ENUMSPD_LS_PHY_6MHZ:
- diepctl.b.mps = DEP0CTL_MPS_8;
- break;
- default:
- diepctl.b.mps = DEP0CTL_MPS_64;
- break;
- }
- USB_OTG_WRITE_REG32(&pdev->regs.INEP_REGS[0]->DIEPCTL, diepctl.d32);
- dctl.b.cgnpinnak = 1;
- USB_OTG_MODIFY_REG32(&pdev->regs.DREGS->DCTL, dctl.d32, dctl.d32);
- return status;
-}
-
-
-/**
-* @brief USB_OTG_EPActivate : Activates an EP
-* @param pdev : Selected device
-* @retval USB_OTG_STS : status
-*/
-USB_OTG_STS USB_OTG_EPActivate(USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep)
-{
- USB_OTG_STS status = USB_OTG_OK;
- USB_OTG_DEPCTL_TypeDef depctl;
- USB_OTG_DAINT_TypeDef daintmsk;
- __IO uint32_t *addr;
-
-
- depctl.d32 = 0;
- daintmsk.d32 = 0;
- /* Read DEPCTLn register */
- if (ep->is_in == 1)
- {
- addr = &pdev->regs.INEP_REGS[ep->num]->DIEPCTL;
- daintmsk.ep.in = 1 << ep->num;
- }
- else
- {
- addr = &pdev->regs.OUTEP_REGS[ep->num]->DOEPCTL;
- daintmsk.ep.out = 1 << ep->num;
- }
- /* If the EP is already active don't change the EP Control
- * register. */
- depctl.d32 = USB_OTG_READ_REG32(addr);
- if (!depctl.b.usbactep)
- {
- depctl.b.mps = ep->maxpacket;
- depctl.b.eptype = ep->type;
- depctl.b.txfnum = ep->tx_fifo_num;
- depctl.b.setd0pid = 1;
- depctl.b.usbactep = 1;
- USB_OTG_WRITE_REG32(addr, depctl.d32);
- }
- /* Enable the Interrupt for this EP */
-#ifdef USB_OTG_HS_DEDICATED_EP1_ENABLED
- if((ep->num == 1)&&(pdev->cfg.coreID == USB_OTG_HS_CORE_ID))
- {
- USB_OTG_MODIFY_REG32(&pdev->regs.DREGS->DEACHMSK, 0, daintmsk.d32);
- }
- else
-#endif
- USB_OTG_MODIFY_REG32(&pdev->regs.DREGS->DAINTMSK, 0, daintmsk.d32);
- return status;
-}
-
-
-/**
-* @brief USB_OTG_EPDeactivate : Deactivates an EP
-* @param pdev : Selected device
-* @retval USB_OTG_STS : status
-*/
-USB_OTG_STS USB_OTG_EPDeactivate(USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep)
-{
- USB_OTG_STS status = USB_OTG_OK;
- USB_OTG_DEPCTL_TypeDef depctl;
-
- /* Read DEPCTLn register and Disable the IN endpoint*/
- if (ep->is_in == 1)
- {
- depctl.d32 = USB_OTG_READ_REG32(&pdev->regs.INEP_REGS[ep->num]->DIEPCTL);
- if (depctl.b.epena)
- {
- depctl.d32 = 0;
- depctl.b.epdis = 1;
- depctl.b.snak = 1;
- }
- else
- {
- depctl.d32 = 0;
- }
- USB_OTG_WRITE_REG32( &pdev->regs.INEP_REGS[ep->num]->DIEPCTL, depctl.d32);
- }
-
- else /* Disable the OUT endpoint */
-
- {
- USB_OTG_DEPCTL_TypeDef depctl;
- depctl.d32 = USB_OTG_READ_REG32(&pdev->regs.OUTEP_REGS[ep->num]->DOEPCTL);
- if (depctl.b.epena)
- {
- depctl.d32 = 0;
- depctl.b.epdis = 1;
- depctl.b.snak = 1;
- }
- else
- {
- depctl.d32 = 0;
- }
- USB_OTG_WRITE_REG32( &pdev->regs.OUTEP_REGS[ep->num]->DOEPCTL, depctl.d32);
- }
- return status;
-}
-
-
-/**
-* @brief USB_OTG_EPStartXfer : Handle the setup for data xfer for an EP and
-* starts the xfer
-* @param pdev : Selected device
-* @retval USB_OTG_STS : status
-*/
-USB_OTG_STS USB_OTG_EPStartXfer(USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep)
-{
- USB_OTG_STS status = USB_OTG_OK;
- USB_OTG_DEPCTL_TypeDef depctl;
- USB_OTG_DEPXFRSIZ_TypeDef deptsiz;
- USB_OTG_DSTS_TypeDef dsts;
- uint32_t fifoemptymsk = 0;
-
- depctl.d32 = 0;
- deptsiz.d32 = 0;
- /* IN endpoint */
- if (ep->is_in == 1)
- {
- depctl.d32 = USB_OTG_READ_REG32(&(pdev->regs.INEP_REGS[ep->num]->DIEPCTL));
- deptsiz.d32 = USB_OTG_READ_REG32(&(pdev->regs.INEP_REGS[ep->num]->DIEPTSIZ));
- /* Zero Length Packet? */
- if (ep->XferLen == 0)
- {
- deptsiz.b.xfersize = 0;
- deptsiz.b.pktcnt = 1;
- }
- else
- {
- /* Program the transfer size and packet count
- * as follows: xfersize = N * maxpacket +
- * short_packet pktcnt = N + (short_packet
- * exist ? 1 : 0)
- */
- deptsiz.b.xfersize = ep->XferLen;
- deptsiz.b.pktcnt = (ep->XferLen - 1 + ep->maxpacket) / ep->maxpacket;
-
- if (ep->type == EP_TYPE_ISOC)
- {
- deptsiz.b.mc = 1;
- }
- }
- USB_OTG_WRITE_REG32(&pdev->regs.INEP_REGS[ep->num]->DIEPTSIZ, deptsiz.d32);
-
- if (pdev->cfg.dma_enable == 1)
- {
- USB_OTG_WRITE_REG32(&pdev->regs.INEP_REGS[ep->num]->DIEPDMA, ep->dma_addr);
- }
- else
- {
- if (ep->type != EP_TYPE_ISOC)
- {
- /* Enable the Tx FIFO Empty Interrupt for this EP */
- if (ep->XferLen > 0)
- {
- fifoemptymsk = 1 << ep->num;
- USB_OTG_MODIFY_REG32(&pdev->regs.DREGS->DIEPEMPMSK, 0, fifoemptymsk);
- }
- }
- }
-
-
- if (ep->type == EP_TYPE_ISOC)
- {
- dsts.d32 = USB_OTG_READ_REG32(&pdev->regs.DREGS->DSTS);
-
- if (((dsts.b.soffn)&0x1) == 0)
- {
- depctl.b.setd1pid = 1;
- }
- else
- {
- depctl.b.setd0pid = 1;
- }
- }
-
- /* EP enable, IN data in FIFO */
- depctl.b.cnak = 1;
- depctl.b.epena = 1;
- USB_OTG_WRITE_REG32(&pdev->regs.INEP_REGS[ep->num]->DIEPCTL, depctl.d32);
-
- if (ep->type == EP_TYPE_ISOC)
- {
- USB_OTG_WritePacket(pdev, ep->xfer_buff, ep->num, ep->XferLen);
- }
- }
- else
- {
- /* OUT endpoint */
- depctl.d32 = USB_OTG_READ_REG32(&(pdev->regs.OUTEP_REGS[ep->num]->DOEPCTL));
- deptsiz.d32 = USB_OTG_READ_REG32(&(pdev->regs.OUTEP_REGS[ep->num]->DOEPTSIZ));
- /* Program the transfer size and packet count as follows:
- * pktcnt = N
- * xfersize = N * maxpacket
- */
- if (ep->XferLen == 0)
- {
- deptsiz.b.xfersize = ep->maxpacket;
- deptsiz.b.pktcnt = 1;
- }
- else
- {
- deptsiz.b.pktcnt = (ep->XferLen + (ep->maxpacket - 1)) / ep->maxpacket;
- deptsiz.b.xfersize = deptsiz.b.pktcnt * ep->maxpacket;
- ep->XferLen = deptsiz.b.xfersize ;
- }
- USB_OTG_WRITE_REG32(&pdev->regs.OUTEP_REGS[ep->num]->DOEPTSIZ, deptsiz.d32);
-
- if (pdev->cfg.dma_enable == 1)
- {
- USB_OTG_WRITE_REG32(&pdev->regs.OUTEP_REGS[ep->num]->DOEPDMA, ep->dma_addr);
- }
-
- if (ep->type == EP_TYPE_ISOC)
- {
- if (ep->even_odd_frame)
- {
- depctl.b.setd1pid = 1;
- }
- else
- {
- depctl.b.setd0pid = 1;
- }
- }
- /* EP enable */
- depctl.b.cnak = 1;
- depctl.b.epena = 1;
- USB_OTG_WRITE_REG32(&pdev->regs.OUTEP_REGS[ep->num]->DOEPCTL, depctl.d32);
- }
- return status;
-}
-
-
-/**
-* @brief USB_OTG_EP0StartXfer : Handle the setup for a data xfer for EP0 and
-* starts the xfer
-* @param pdev : Selected device
-* @retval USB_OTG_STS : status
-*/
-USB_OTG_STS USB_OTG_EP0StartXfer(USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep)
-{
- USB_OTG_STS status = USB_OTG_OK;
- USB_OTG_DEPCTL_TypeDef depctl;
- USB_OTG_DEP0XFRSIZ_TypeDef deptsiz;
- USB_OTG_INEPREGS *in_regs;
- uint32_t fifoemptymsk = 0;
-
- depctl.d32 = 0;
- deptsiz.d32 = 0;
- /* IN endpoint */
- if (ep->is_in == 1)
- {
- in_regs = pdev->regs.INEP_REGS[0];
- depctl.d32 = USB_OTG_READ_REG32(&in_regs->DIEPCTL);
- deptsiz.d32 = USB_OTG_READ_REG32(&in_regs->DIEPTSIZ);
- /* Zero Length Packet? */
- if (ep->XferLen == 0)
- {
- deptsiz.b.xfersize = 0;
- deptsiz.b.pktcnt = 1;
-
- }
- else
- {
- if (ep->XferLen > ep->maxpacket)
- {
- ep->XferLen = ep->maxpacket;
- deptsiz.b.xfersize = ep->maxpacket;
- }
- else
- {
- deptsiz.b.xfersize = ep->XferLen;
- }
- deptsiz.b.pktcnt = 1;
- }
- USB_OTG_WRITE_REG32(&in_regs->DIEPTSIZ, deptsiz.d32);
-
- if (pdev->cfg.dma_enable == 1)
- {
- USB_OTG_WRITE_REG32(&pdev->regs.INEP_REGS[ep->num]->DIEPDMA, ep->dma_addr);
- }
-
- /* EP enable, IN data in FIFO */
- depctl.b.cnak = 1;
- depctl.b.epena = 1;
- USB_OTG_WRITE_REG32(&in_regs->DIEPCTL, depctl.d32);
-
-
-
- if (pdev->cfg.dma_enable == 0)
- {
- /* Enable the Tx FIFO Empty Interrupt for this EP */
- if (ep->XferLen > 0)
- {
- {
- fifoemptymsk |= 1 << ep->num;
- USB_OTG_MODIFY_REG32(&pdev->regs.DREGS->DIEPEMPMSK, 0, fifoemptymsk);
- }
- }
- }
- }
- else
- {
- /* OUT endpoint */
- depctl.d32 = USB_OTG_READ_REG32(&pdev->regs.OUTEP_REGS[ep->num]->DOEPCTL);
- deptsiz.d32 = USB_OTG_READ_REG32(&pdev->regs.OUTEP_REGS[ep->num]->DOEPTSIZ);
- /* Program the transfer size and packet count as follows:
- * xfersize = N * (maxpacket + 4 - (maxpacket % 4))
- * pktcnt = N */
- if (ep->XferLen == 0)
- {
- deptsiz.b.xfersize = ep->maxpacket;
- deptsiz.b.pktcnt = 1;
- }
- else
- {
- ep->XferLen = ep->maxpacket;
- deptsiz.b.xfersize = ep->maxpacket;
- deptsiz.b.pktcnt = 1;
- }
- USB_OTG_WRITE_REG32(&pdev->regs.OUTEP_REGS[ep->num]->DOEPTSIZ, deptsiz.d32);
- if (pdev->cfg.dma_enable == 1)
- {
- USB_OTG_WRITE_REG32(&pdev->regs.OUTEP_REGS[ep->num]->DOEPDMA, ep->dma_addr);
- }
- /* EP enable */
- depctl.b.cnak = 1;
- depctl.b.epena = 1;
- USB_OTG_WRITE_REG32 (&(pdev->regs.OUTEP_REGS[ep->num]->DOEPCTL), depctl.d32);
-
- }
- return status;
-}
-
-
-/**
-* @brief USB_OTG_EPSetStall : Set the EP STALL
-* @param pdev : Selected device
-* @retval USB_OTG_STS : status
-*/
-USB_OTG_STS USB_OTG_EPSetStall(USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep)
-{
- USB_OTG_STS status = USB_OTG_OK;
- USB_OTG_DEPCTL_TypeDef depctl;
- __IO uint32_t *depctl_addr;
-
- depctl.d32 = 0;
- if (ep->is_in == 1)
- {
- depctl_addr = &(pdev->regs.INEP_REGS[ep->num]->DIEPCTL);
- depctl.d32 = USB_OTG_READ_REG32(depctl_addr);
- /* set the disable and stall bits */
- if (depctl.b.epena)
- {
- depctl.b.epdis = 1;
- }
- depctl.b.stall = 1;
- USB_OTG_WRITE_REG32(depctl_addr, depctl.d32);
- }
- else
- {
- depctl_addr = &(pdev->regs.OUTEP_REGS[ep->num]->DOEPCTL);
- depctl.d32 = USB_OTG_READ_REG32(depctl_addr);
- /* set the stall bit */
- depctl.b.stall = 1;
- USB_OTG_WRITE_REG32(depctl_addr, depctl.d32);
- }
- return status;
-}
-
-
-/**
-* @brief Clear the EP STALL
-* @param pdev : Selected device
-* @retval USB_OTG_STS : status
-*/
-USB_OTG_STS USB_OTG_EPClearStall(USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep)
-{
- USB_OTG_STS status = USB_OTG_OK;
- USB_OTG_DEPCTL_TypeDef depctl;
- __IO uint32_t *depctl_addr;
-
- depctl.d32 = 0;
-
- if (ep->is_in == 1)
- {
- depctl_addr = &(pdev->regs.INEP_REGS[ep->num]->DIEPCTL);
- }
- else
- {
- depctl_addr = &(pdev->regs.OUTEP_REGS[ep->num]->DOEPCTL);
- }
- depctl.d32 = USB_OTG_READ_REG32(depctl_addr);
- /* clear the stall bits */
- depctl.b.stall = 0;
- if (ep->type == EP_TYPE_INTR || ep->type == EP_TYPE_BULK)
- {
- depctl.b.setd0pid = 1; /* DATA0 */
- }
- USB_OTG_WRITE_REG32(depctl_addr, depctl.d32);
- return status;
-}
-
-
-/**
-* @brief USB_OTG_ReadDevAllOutEp_itr : returns OUT endpoint interrupt bits
-* @param pdev : Selected device
-* @retval OUT endpoint interrupt bits
-*/
-uint32_t USB_OTG_ReadDevAllOutEp_itr(USB_OTG_CORE_HANDLE *pdev)
-{
- uint32_t v;
- v = USB_OTG_READ_REG32(&pdev->regs.DREGS->DAINT);
- v &= USB_OTG_READ_REG32(&pdev->regs.DREGS->DAINTMSK);
- return ((v & 0xffff0000) >> 16);
-}
-
-
-/**
-* @brief USB_OTG_ReadDevOutEP_itr : returns Device OUT EP Interrupt register
-* @param pdev : Selected device
-* @param ep : end point number
-* @retval Device OUT EP Interrupt register
-*/
-uint32_t USB_OTG_ReadDevOutEP_itr(USB_OTG_CORE_HANDLE *pdev , uint8_t epnum)
-{
- uint32_t v;
- v = USB_OTG_READ_REG32(&pdev->regs.OUTEP_REGS[epnum]->DOEPINT);
- v &= USB_OTG_READ_REG32(&pdev->regs.DREGS->DOEPMSK);
- return v;
-}
-
-
-/**
-* @brief USB_OTG_ReadDevAllInEPItr : Get int status register
-* @param pdev : Selected device
-* @retval int status register
-*/
-uint32_t USB_OTG_ReadDevAllInEPItr(USB_OTG_CORE_HANDLE *pdev)
-{
- uint32_t v;
- v = USB_OTG_READ_REG32(&pdev->regs.DREGS->DAINT);
- v &= USB_OTG_READ_REG32(&pdev->regs.DREGS->DAINTMSK);
- return (v & 0xffff);
-}
-
-/**
-* @brief configures EPO to receive SETUP packets
-* @param None
-* @retval : None
-*/
-void USB_OTG_EP0_OutStart(USB_OTG_CORE_HANDLE *pdev)
-{
- USB_OTG_DEP0XFRSIZ_TypeDef doeptsize0;
- doeptsize0.d32 = 0;
- doeptsize0.b.supcnt = 3;
- doeptsize0.b.pktcnt = 1;
- doeptsize0.b.xfersize = 8 * 3;
- USB_OTG_WRITE_REG32( &pdev->regs.OUTEP_REGS[0]->DOEPTSIZ, doeptsize0.d32 );
-
- if (pdev->cfg.dma_enable == 1)
- {
- USB_OTG_DEPCTL_TypeDef doepctl;
- doepctl.d32 = 0;
- USB_OTG_WRITE_REG32( &pdev->regs.OUTEP_REGS[0]->DOEPDMA,
- (uint32_t)&pdev->dev.setup_packet);
-
- /* EP enable */
- doepctl.d32 = USB_OTG_READ_REG32(&pdev->regs.OUTEP_REGS[0]->DOEPCTL);
- doepctl.b.epena = 1;
- doepctl.d32 = 0x80008000;
- USB_OTG_WRITE_REG32( &pdev->regs.OUTEP_REGS[0]->DOEPCTL, doepctl.d32);
- }
-}
-
-/**
-* @brief USB_OTG_RemoteWakeup : active remote wakeup signalling
-* @param None
-* @retval : None
-*/
-void USB_OTG_ActiveRemoteWakeup(USB_OTG_CORE_HANDLE *pdev)
-{
-
- USB_OTG_DCTL_TypeDef dctl;
- USB_OTG_DSTS_TypeDef dsts;
- USB_OTG_PCGCCTL_TypeDef power;
-
- if (pdev->dev.DevRemoteWakeup)
- {
- dsts.d32 = USB_OTG_READ_REG32(&pdev->regs.DREGS->DSTS);
- if(dsts.b.suspsts == 1)
- {
- if(pdev->cfg.low_power)
- {
- /* un-gate USB Core clock */
- power.d32 = USB_OTG_READ_REG32(pdev->regs.PCGCCTL);
- power.b.gatehclk = 0;
- power.b.stoppclk = 0;
- USB_OTG_WRITE_REG32(pdev->regs.PCGCCTL, power.d32);
- }
- /* active Remote wakeup signaling */
- dctl.d32 = 0;
- dctl.b.rmtwkupsig = 1;
- USB_OTG_MODIFY_REG32(&pdev->regs.DREGS->DCTL, 0, dctl.d32);
- USB_OTG_BSP_mDelay(5);
- USB_OTG_MODIFY_REG32(&pdev->regs.DREGS->DCTL, dctl.d32, 0 );
- }
- }
-}
-
-
-/**
-* @brief USB_OTG_UngateClock : active USB Core clock
-* @param None
-* @retval : None
-*/
-void USB_OTG_UngateClock(USB_OTG_CORE_HANDLE *pdev)
-{
- if(pdev->cfg.low_power)
- {
-
- USB_OTG_DSTS_TypeDef dsts;
- USB_OTG_PCGCCTL_TypeDef power;
-
- dsts.d32 = USB_OTG_READ_REG32(&pdev->regs.DREGS->DSTS);
-
- if(dsts.b.suspsts == 1)
- {
- /* un-gate USB Core clock */
- power.d32 = USB_OTG_READ_REG32(pdev->regs.PCGCCTL);
- power.b.gatehclk = 0;
- power.b.stoppclk = 0;
- USB_OTG_WRITE_REG32(pdev->regs.PCGCCTL, power.d32);
-
- }
- }
-}
-
-/**
-* @brief Stop the device and clean up fifo's
-* @param None
-* @retval : None
-*/
-void USB_OTG_StopDevice(USB_OTG_CORE_HANDLE *pdev)
-{
- uint32_t i;
-
- pdev->dev.device_status = 1;
-
- for (i = 0; i < pdev->cfg.dev_endpoints ; i++)
- {
- USB_OTG_WRITE_REG32( &pdev->regs.INEP_REGS[i]->DIEPINT, 0xFF);
- USB_OTG_WRITE_REG32( &pdev->regs.OUTEP_REGS[i]->DOEPINT, 0xFF);
- }
-
- USB_OTG_WRITE_REG32( &pdev->regs.DREGS->DIEPMSK, 0 );
- USB_OTG_WRITE_REG32( &pdev->regs.DREGS->DOEPMSK, 0 );
- USB_OTG_WRITE_REG32( &pdev->regs.DREGS->DAINTMSK, 0 );
- USB_OTG_WRITE_REG32( &pdev->regs.DREGS->DAINT, 0xFFFFFFFF );
-
- /* Flush the FIFO */
- USB_OTG_FlushRxFifo(pdev);
- USB_OTG_FlushTxFifo(pdev , 0x10 );
-}
-
-/**
-* @brief returns the EP Status
-* @param pdev : Selected device
-* ep : endpoint structure
-* @retval : EP status
-*/
-
-uint32_t USB_OTG_GetEPStatus(USB_OTG_CORE_HANDLE *pdev ,USB_OTG_EP *ep)
-{
- USB_OTG_DEPCTL_TypeDef depctl;
- __IO uint32_t *depctl_addr;
- uint32_t Status = 0;
-
- depctl.d32 = 0;
- if (ep->is_in == 1)
- {
- depctl_addr = &(pdev->regs.INEP_REGS[ep->num]->DIEPCTL);
- depctl.d32 = USB_OTG_READ_REG32(depctl_addr);
-
- if (depctl.b.stall == 1)
- {
- Status = USB_OTG_EP_TX_STALL;
- }
- else if (depctl.b.naksts == 1)
- {
- Status = USB_OTG_EP_TX_NAK;
- }
- else
- {
- Status = USB_OTG_EP_TX_VALID;
- }
- }
- else
- {
- depctl_addr = &(pdev->regs.OUTEP_REGS[ep->num]->DOEPCTL);
- depctl.d32 = USB_OTG_READ_REG32(depctl_addr);
- if (depctl.b.stall == 1)
- {
- Status = USB_OTG_EP_RX_STALL;
- }
- else if (depctl.b.naksts == 1)
- {
- Status = USB_OTG_EP_RX_NAK;
- }
- else
- {
- Status = USB_OTG_EP_RX_VALID;
- }
- }
-
- /* Return the current status */
- return Status;
-}
-
-/**
-* @brief Set the EP Status
-* @param pdev : Selected device
-* Status : new Status
-* ep : EP structure
-* @retval : None
-*/
-void USB_OTG_SetEPStatus (USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep , uint32_t Status)
-{
- USB_OTG_DEPCTL_TypeDef depctl;
- __IO uint32_t *depctl_addr;
-
- depctl.d32 = 0;
-
- /* Process for IN endpoint */
- if (ep->is_in == 1)
- {
- depctl_addr = &(pdev->regs.INEP_REGS[ep->num]->DIEPCTL);
- depctl.d32 = USB_OTG_READ_REG32(depctl_addr);
-
- if (Status == USB_OTG_EP_TX_STALL)
- {
- USB_OTG_EPSetStall(pdev, ep); return;
- }
- else if (Status == USB_OTG_EP_TX_NAK)
- {
- depctl.b.snak = 1;
- }
- else if (Status == USB_OTG_EP_TX_VALID)
- {
- if (depctl.b.stall == 1)
- {
- ep->even_odd_frame = 0;
- USB_OTG_EPClearStall(pdev, ep);
- return;
- }
- depctl.b.cnak = 1;
- depctl.b.usbactep = 1;
- depctl.b.epena = 1;
- }
- else if (Status == USB_OTG_EP_TX_DIS)
- {
- depctl.b.usbactep = 0;
- }
-
- else
- {
- /* Do Nothing */
- }
- }
- else /* Process for OUT endpoint */
- {
- depctl_addr = &(pdev->regs.OUTEP_REGS[ep->num]->DOEPCTL);
- depctl.d32 = USB_OTG_READ_REG32(depctl_addr);
-
- if (Status == USB_OTG_EP_RX_STALL) {
- depctl.b.stall = 1;
- }
- else if (Status == USB_OTG_EP_RX_NAK)
- {
- depctl.b.snak = 1;
- }
- else if (Status == USB_OTG_EP_RX_VALID)
- {
- if (depctl.b.stall == 1)
- {
- ep->even_odd_frame = 0;
- USB_OTG_EPClearStall(pdev, ep);
- return;
- }
- depctl.b.cnak = 1;
- depctl.b.usbactep = 1;
- depctl.b.epena = 1;
- }
- else if (Status == USB_OTG_EP_RX_DIS)
- {
- depctl.b.usbactep = 0;
- }
-
- else
- {
- /* Do Nothing */
- }
- }
-
- USB_OTG_WRITE_REG32(depctl_addr, depctl.d32);
-}
-
-#endif
-/**
-* @}
-*/
-
-/**
-* @}
-*/
-
-/**
-* @}
-*/
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/src/usb_dcd.c b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/src/usb_dcd.c
deleted file mode 100644
index 3adcbc732..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/src/usb_dcd.c
+++ /dev/null
@@ -1,488 +0,0 @@
-/**
- ******************************************************************************
- * @file usb_dcd.c
- * @author xiuos Team
- * @version V1.0.0
- * @date 2020-9-3
- * @brief This file is based on usb_dcd.c
- * Peripheral Device Interface Layer
- ******************************************************************************
- * @file usb_dcd.c
- * @author MCD Application Team
- * @version V1.0.0
- * @date 30-September-2011
- * ********************************************************************************
- * @attention
- *
- * © Copyright (c) 2015 STMicroelectronics.
- * All rights reserved.
- *
- * This software component is licensed by ST under Ultimate Liberty license
- * SLA0044, the "License"; You may not use this file except in compliance with
- * the License. You may obtain a copy of the License at:
- *
- *
- ******************************************************************************
- */
-
-/* Includes ------------------------------------------------------------------*/
-#include "usb_dcd.h"
-#include "usb_bsp.h"
-
-
-/** @addtogroup USB_OTG_DRIVER
-* @{
-*/
-
-/** @defgroup USB_DCD
-* @brief This file is the interface between EFSL ans Host mass-storage class
-* @{
-*/
-
-
-/** @defgroup USB_DCD_Private_Defines
-* @{
-*/
-/**
-* @}
-*/
-
-
-/** @defgroup USB_DCD_Private_TypesDefinitions
-* @{
-*/
-/**
-* @}
-*/
-
-
-
-/** @defgroup USB_DCD_Private_Macros
-* @{
-*/
-/**
-* @}
-*/
-
-
-/** @defgroup USB_DCD_Private_Variables
-* @{
-*/
-/**
-* @}
-*/
-
-
-/** @defgroup USB_DCD_Private_FunctionPrototypes
-* @{
-*/
-
-/**
-* @}
-*/
-
-
-/** @defgroup USB_DCD_Private_Functions
-* @{
-*/
-
-
-
-void DCD_Init(USB_OTG_CORE_HANDLE *pdev ,
- USB_OTG_CORE_ID_TypeDef coreID)
-{
- uint32_t i;
- USB_OTG_EP *ep;
-
- USB_OTG_SelectCore (pdev , coreID);
-
- pdev->dev.device_status = USB_OTG_DEFAULT;
- pdev->dev.device_address = 0;
-
- /* Init ep structure */
- for (i = 0; i < pdev->cfg.dev_endpoints ; i++)
- {
- ep = &pdev->dev.in_ep[i];
- /* Init ep structure */
- ep->is_in = 1;
- ep->num = i;
- ep->tx_fifo_num = i;
- /* Control until ep is activated */
- ep->type = EP_TYPE_CTRL;
- ep->maxpacket = USB_OTG_MAX_EP0_SIZE;
- ep->xfer_buff = 0;
- ep->XferLen = 0;
- }
-
- for (i = 0; i < pdev->cfg.dev_endpoints; i++)
- {
- ep = &pdev->dev.out_ep[i];
- /* Init ep structure */
- ep->is_in = 0;
- ep->num = i;
- ep->tx_fifo_num = i;
- /* Control until ep is activated */
- ep->type = EP_TYPE_CTRL;
- ep->maxpacket = USB_OTG_MAX_EP0_SIZE;
- ep->xfer_buff = 0;
- ep->XferLen = 0;
- }
-
- USB_OTG_DisableGlobalInt(pdev);
-
-#if defined (STM32F446xx) || defined (STM32F469_479xx)
-
- /* Force Device Mode*/
- USB_OTG_SetCurrentMode(pdev, DEVICE_MODE);
-
- /*Init the Core (common init.) */
- USB_OTG_CoreInit(pdev);
-
-#else
-
- /*Init the Core (common init.) */
- USB_OTG_CoreInit(pdev);
-
- /* Force Device Mode*/
- USB_OTG_SetCurrentMode(pdev, DEVICE_MODE);
-
-#endif
-
- /* Init Device */
- USB_OTG_CoreInitDev(pdev);
-
- /* Enable USB Global interrupt */
- USB_OTG_EnableGlobalInt(pdev);
-}
-
-
-/**
-* @brief Configure an EP
-* @param pdev : Device instance
-* @param epdesc : Endpoint Descriptor
-* @retval : status
-*/
-uint32_t DCD_EP_Open(USB_OTG_CORE_HANDLE *pdev ,
- uint8_t EpAddr,
- uint16_t ep_mps,
- uint8_t ep_type)
-{
- USB_OTG_EP *ep;
-
- if ((EpAddr & 0x80) == 0x80)
- {
- ep = &pdev->dev.in_ep[EpAddr & 0x7F];
- }
- else
- {
- ep = &pdev->dev.out_ep[EpAddr & 0x7F];
- }
- ep->num = EpAddr & 0x7F;
-
- ep->is_in = (0x80 & EpAddr) != 0;
- ep->maxpacket = ep_mps;
- ep->type = ep_type;
- if (ep->is_in)
- {
- /* Assign a Tx FIFO */
- ep->tx_fifo_num = ep->num;
- }
- /* Set initial data PID. */
- if (ep_type == USB_OTG_EP_BULK )
- {
- ep->data_pid_start = 0;
- }
- USB_OTG_EPActivate(pdev , ep );
- return 0;
-}
-/**
-* @brief called when an EP is disabled
-* @param pdev: device instance
-* @param EpAddr: endpoint address
-* @retval : status
-*/
-uint32_t DCD_EP_Close(USB_OTG_CORE_HANDLE *pdev , uint8_t EpAddr)
-{
- USB_OTG_EP *ep;
-
- if ((EpAddr&0x80) == 0x80)
- {
- ep = &pdev->dev.in_ep[EpAddr & 0x7F];
- }
- else
- {
- ep = &pdev->dev.out_ep[EpAddr & 0x7F];
- }
- ep->num = EpAddr & 0x7F;
- ep->is_in = (0x80 & EpAddr) != 0;
- USB_OTG_EPDeactivate(pdev , ep );
- return 0;
-}
-
-
-/**
-* @brief DCD_EP_PrepareRx
-* @param pdev: device instance
-* @param EpAddr: endpoint address
-* @param pbuf: pointer to Rx buffer
-* @param BufLen: data length
-* @retval : status
-*/
-uint32_t DCD_EP_PrepareRx( USB_OTG_CORE_HANDLE *pdev,
- uint8_t EpAddr,
- uint8_t *pbuf,
- uint16_t BufLen)
-{
- USB_OTG_EP *ep;
-
- ep = &pdev->dev.out_ep[EpAddr & 0x7F];
-
- /*setup and start the Xfer */
- ep->xfer_buff = pbuf;
- ep->XferLen = BufLen;
- ep->xfer_count = 0;
- ep->is_in = 0;
- ep->num = EpAddr & 0x7F;
-
- if (pdev->cfg.dma_enable == 1)
- {
- ep->dma_addr = (uint32_t)pbuf;
- }
-
- if ( ep->num == 0 )
- {
- USB_OTG_EP0StartXfer(pdev , ep);
- }
- else
- {
- USB_OTG_EPStartXfer(pdev, ep );
- }
- return 0;
-}
-
-/**
-* @brief Transmit data over USB
-* @param pdev: device instance
-* @param EpAddr: endpoint address
-* @param pbuf: pointer to Tx buffer
-* @param BufLen: data length
-* @retval : status
-*/
-uint32_t DCD_EP_Tx ( USB_OTG_CORE_HANDLE *pdev,
- uint8_t EpAddr,
- uint8_t *pbuf,
- uint32_t BufLen)
-{
- USB_OTG_EP *ep;
-
- ep = &pdev->dev.in_ep[EpAddr & 0x7F];
-
- /* Setup and start the Transfer */
- ep->is_in = 1;
- ep->num = EpAddr & 0x7F;
- ep->xfer_buff = pbuf;
- ep->dma_addr = (uint32_t)pbuf;
- ep->xfer_count = 0;
- ep->XferLen = BufLen;
-
- if ( ep->num == 0 )
- {
- USB_OTG_EP0StartXfer(pdev , ep);
- }
- else
- {
- USB_OTG_EPStartXfer(pdev, ep );
- }
- return 0;
-}
-
-
-/**
-* @brief Stall an endpoint.
-* @param pdev: device instance
-* @param epnum: endpoint address
-* @retval : status
-*/
-uint32_t DCD_EP_Stall (USB_OTG_CORE_HANDLE *pdev, uint8_t epnum)
-{
- USB_OTG_EP *ep;
- if ((0x80 & epnum) == 0x80)
- {
- ep = &pdev->dev.in_ep[epnum & 0x7F];
- }
- else
- {
- ep = &pdev->dev.out_ep[epnum];
- }
-
- ep->is_stall = 1;
- ep->num = epnum & 0x7F;
- ep->is_in = ((epnum & 0x80) == 0x80);
-
- USB_OTG_EPSetStall(pdev , ep);
- return (0);
-}
-
-
-/**
-* @brief Clear stall condition on endpoints.
-* @param pdev: device instance
-* @param epnum: endpoint address
-* @retval : status
-*/
-uint32_t DCD_EP_ClrStall (USB_OTG_CORE_HANDLE *pdev, uint8_t epnum)
-{
- USB_OTG_EP *ep;
- if ((0x80 & epnum) == 0x80)
- {
- ep = &pdev->dev.in_ep[epnum & 0x7F];
- }
- else
- {
- ep = &pdev->dev.out_ep[epnum];
- }
-
- ep->is_stall = 0;
- ep->num = epnum & 0x7F;
- ep->is_in = ((epnum & 0x80) == 0x80);
-
- USB_OTG_EPClearStall(pdev , ep);
- return (0);
-}
-
-
-/**
-* @brief This Function flushes the FIFOs.
-* @param pdev: device instance
-* @param epnum: endpoint address
-* @retval : status
-*/
-uint32_t DCD_EP_Flush (USB_OTG_CORE_HANDLE *pdev , uint8_t epnum)
-{
-
- if ((epnum & 0x80) == 0x80)
- {
- USB_OTG_FlushTxFifo(pdev, epnum & 0x7F);
- }
- else
- {
- USB_OTG_FlushRxFifo(pdev);
- }
-
- return (0);
-}
-
-
-/**
-* @brief This Function set USB device address
-* @param pdev: device instance
-* @param address: new device address
-* @retval : status
-*/
-void DCD_EP_SetAddress (USB_OTG_CORE_HANDLE *pdev, uint8_t address)
-{
- USB_OTG_DCFG_TypeDef dcfg;
- dcfg.d32 = 0;
- dcfg.b.devaddr = address;
- USB_OTG_MODIFY_REG32( &pdev->regs.DREGS->DCFG, 0, dcfg.d32);
-}
-
-/**
-* @brief Connect device (enable internal pull-up)
-* @param pdev: device instance
-* @retval : None
-*/
-void DCD_DevConnect (USB_OTG_CORE_HANDLE *pdev)
-{
-#ifndef USE_OTG_MODE
- USB_OTG_DCTL_TypeDef dctl;
- dctl.d32 = USB_OTG_READ_REG32(&pdev->regs.DREGS->DCTL);
- /* Connect device */
- dctl.b.sftdiscon = 0;
- USB_OTG_WRITE_REG32(&pdev->regs.DREGS->DCTL, dctl.d32);
- USB_OTG_BSP_mDelay(3);
-#endif
-}
-
-
-/**
-* @brief Disconnect device (disable internal pull-up)
-* @param pdev: device instance
-* @retval : None
-*/
-void DCD_DevDisconnect (USB_OTG_CORE_HANDLE *pdev)
-{
-#ifndef USE_OTG_MODE
- USB_OTG_DCTL_TypeDef dctl;
- dctl.d32 = USB_OTG_READ_REG32(&pdev->regs.DREGS->DCTL);
- /* Disconnect device for 3ms */
- dctl.b.sftdiscon = 1;
- USB_OTG_WRITE_REG32(&pdev->regs.DREGS->DCTL, dctl.d32);
- USB_OTG_BSP_mDelay(3);
-#endif
-}
-
-
-/**
-* @brief returns the EP Status
-* @param pdev : Selected device
-* epnum : endpoint address
-* @retval : EP status
-*/
-
-uint32_t DCD_GetEPStatus(USB_OTG_CORE_HANDLE *pdev ,uint8_t epnum)
-{
- USB_OTG_EP *ep;
- uint32_t Status = 0;
-
- if ((0x80 & epnum) == 0x80)
- {
- ep = &pdev->dev.in_ep[epnum & 0x7F];
- }
- else
- {
- ep = &pdev->dev.out_ep[epnum];
- }
-
- Status = USB_OTG_GetEPStatus(pdev ,ep);
-
- /* Return the current status */
- return Status;
-}
-
-/**
-* @brief Set the EP Status
-* @param pdev : Selected device
-* Status : new Status
-* epnum : EP address
-* @retval : None
-*/
-void DCD_SetEPStatus (USB_OTG_CORE_HANDLE *pdev , uint8_t epnum , uint32_t Status)
-{
- USB_OTG_EP *ep;
-
- if ((0x80 & epnum) == 0x80)
- {
- ep = &pdev->dev.in_ep[epnum & 0x7F];
- }
- else
- {
- ep = &pdev->dev.out_ep[epnum];
- }
-
- USB_OTG_SetEPStatus(pdev ,ep , Status);
-}
-
-/**
-* @}
-*/
-
-/**
-* @}
-*/
-
-/**
-* @}
-*/
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/src/usb_dcd_int.c b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/src/usb_dcd_int.c
deleted file mode 100644
index 8a975f1f0..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/src/usb_dcd_int.c
+++ /dev/null
@@ -1,943 +0,0 @@
-/**
- ******************************************************************************
- * @file usb_dcd_int.c
- * @author xiuos Team
- * @version V1.0.0
- * @date 2020-9-3
- * @brief This file is based on usb_dcd_int.c
- * Peripheral Device interrupt subroutines
- ******************************************************************************
- * @file usb_dcd_int.c
- * @author MCD Application Team
- * @version V1.0.0
- * @date 30-September-2011
- * ********************************************************************************
- * @attention
- *
- * © Copyright (c) 2015 STMicroelectronics.
- * All rights reserved.
- *
- * This software component is licensed by ST under Ultimate Liberty license
- * SLA0044, the "License"; You may not use this file except in compliance with
- * the License. You may obtain a copy of the License at:
- *
- *
- ******************************************************************************
- */
-
-/* Includes ------------------------------------------------------------------*/
-#include "usb_dcd_int.h"
-/** @addtogroup USB_OTG_DRIVER
-* @{
-*/
-
-/** @defgroup USB_DCD_INT
-* @brief This file contains the interrupt subroutines for the Device mode.
-* @{
-*/
-
-
-/** @defgroup USB_DCD_INT_Private_Defines
-* @{
-*/
-/**
-* @}
-*/
-
-
-/** @defgroup USB_DCD_INT_Private_TypesDefinitions
-* @{
-*/
-/**
-* @}
-*/
-
-
-
-/** @defgroup USB_DCD_INT_Private_Macros
-* @{
-*/
-/**
-* @}
-*/
-
-
-/** @defgroup USB_DCD_INT_Private_Variables
-* @{
-*/
-/**
-* @}
-*/
-
-
-/** @defgroup USB_DCD_INT_Private_FunctionPrototypes
-* @{
-*/
-/* static functions */
-static uint32_t DCD_ReadDevInEP (USB_OTG_CORE_HANDLE *pdev, uint8_t epnum);
-
-/* Interrupt Handlers */
-static uint32_t DCD_HandleInEP_ISR(USB_OTG_CORE_HANDLE *pdev);
-static uint32_t DCD_HandleOutEP_ISR(USB_OTG_CORE_HANDLE *pdev);
-static uint32_t DCD_HandleSof_ISR(USB_OTG_CORE_HANDLE *pdev);
-
-static uint32_t DCD_HandleRxStatusQueueLevel_ISR(USB_OTG_CORE_HANDLE *pdev);
-static uint32_t DCD_WriteEmptyTxFifo(USB_OTG_CORE_HANDLE *pdev , uint32_t epnum);
-
-static uint32_t DCD_HandleUsbReset_ISR(USB_OTG_CORE_HANDLE *pdev);
-static uint32_t DCD_HandleEnumDone_ISR(USB_OTG_CORE_HANDLE *pdev);
-static uint32_t DCD_HandleResume_ISR(USB_OTG_CORE_HANDLE *pdev);
-static uint32_t DCD_HandleUSBSuspend_ISR(USB_OTG_CORE_HANDLE *pdev);
-
-static uint32_t DCD_IsoINIncomplete_ISR(USB_OTG_CORE_HANDLE *pdev);
-static uint32_t DCD_IsoOUTIncomplete_ISR(USB_OTG_CORE_HANDLE *pdev);
-#ifdef VBUS_SENSING_ENABLED
-static uint32_t DCD_SessionRequest_ISR(USB_OTG_CORE_HANDLE *pdev);
-static uint32_t DCD_OTG_ISR(USB_OTG_CORE_HANDLE *pdev);
-#endif
-
-/**
-* @}
-*/
-
-
-/** @defgroup USB_DCD_INT_Private_Functions
-* @{
-*/
-
-
-#ifdef USB_OTG_HS_DEDICATED_EP1_ENABLED
-/**
-* @brief USBD_OTG_EP1OUT_ISR_Handler
-* handles all USB Interrupts
-* @param pdev: device instance
-* @retval status
-*/
-uint32_t USBD_OTG_EP1OUT_ISR_Handler (USB_OTG_CORE_HANDLE *pdev)
-{
-
- USB_OTG_DOEPINTn_TypeDef doepint;
- USB_OTG_DEPXFRSIZ_TypeDef deptsiz;
-
- doepint.d32 = USB_OTG_READ_REG32(&pdev->regs.OUTEP_REGS[1]->DOEPINT);
- doepint.d32&= USB_OTG_READ_REG32(&pdev->regs.DREGS->DOUTEP1MSK);
-
- /* Transfer complete */
- if ( doepint.b.xfercompl )
- {
- /* Clear the bit in DOEPINTn for this interrupt */
- CLEAR_OUT_EP_INTR(1, xfercompl);
- if (pdev->cfg.dma_enable == 1)
- {
- deptsiz.d32 = USB_OTG_READ_REG32(&(pdev->regs.OUTEP_REGS[1]->DOEPTSIZ));
- pdev->dev.out_ep[1].xfer_count = pdev->dev.out_ep[1].XferLen- \
- deptsiz.b.xfersize;
- }
- /* Inform upper layer: data ready */
- /* RX COMPLETE */
- USBD_DCD_INT_fops->DataOutStage(pdev , 1);
-
- }
-
- /* Endpoint disable */
- if ( doepint.b.epdisabled )
- {
- /* Clear the bit in DOEPINTn for this interrupt */
- CLEAR_OUT_EP_INTR(1, epdisabled);
- }
-
- return 1;
-}
-
-/**
-* @brief USBD_OTG_EP1IN_ISR_Handler
-* handles all USB Interrupts
-* @param pdev: device instance
-* @retval status
-*/
-uint32_t USBD_OTG_EP1IN_ISR_Handler (USB_OTG_CORE_HANDLE *pdev)
-{
-
- USB_OTG_DIEPINTn_TypeDef diepint;
- uint32_t fifoemptymsk, msk, emp;
-
- msk = USB_OTG_READ_REG32(&pdev->regs.DREGS->DINEP1MSK);
- emp = USB_OTG_READ_REG32(&pdev->regs.DREGS->DIEPEMPMSK);
- msk |= ((emp >> 1 ) & 0x1) << 7;
- diepint.d32 = USB_OTG_READ_REG32(&pdev->regs.INEP_REGS[1]->DIEPINT) & msk;
-
- if ( diepint.b.xfercompl )
- {
- fifoemptymsk = 0x1 << 1;
- USB_OTG_MODIFY_REG32(&pdev->regs.DREGS->DIEPEMPMSK, fifoemptymsk, 0);
- CLEAR_IN_EP_INTR(1, xfercompl);
- /* TX COMPLETE */
- USBD_DCD_INT_fops->DataInStage(pdev , 1);
- }
- if ( diepint.b.epdisabled )
- {
- CLEAR_IN_EP_INTR(1, epdisabled);
- }
- if ( diepint.b.timeout )
- {
- CLEAR_IN_EP_INTR(1, timeout);
- }
- if (diepint.b.intktxfemp)
- {
- CLEAR_IN_EP_INTR(1, intktxfemp);
- }
- if (diepint.b.inepnakeff)
- {
- CLEAR_IN_EP_INTR(1, inepnakeff);
- }
- if (diepint.b.emptyintr)
- {
- DCD_WriteEmptyTxFifo(pdev , 1);
- }
- return 1;
-}
-#endif
-
-/**
-* @brief STM32_USBF_OTG_ISR_Handler
-* handles all USB Interrupts
-* @param pdev: device instance
-* @retval status
-*/
-uint32_t USBD_OTG_ISR_Handler (USB_OTG_CORE_HANDLE *pdev)
-{
- USB_OTG_GINTSTS_TypeDef gintr_status;
- uint32_t retval = 0;
-
- if (USB_OTG_IsDeviceMode(pdev)) /* ensure that we are in device mode */
- {
- gintr_status.d32 = USB_OTG_ReadCoreItr(pdev);
- if (!gintr_status.d32) /* avoid spurious interrupt */
- {
- return 0;
- }
-
- if (gintr_status.b.outepintr)
- {
- retval |= DCD_HandleOutEP_ISR(pdev);
- }
-
- if (gintr_status.b.inepint)
- {
- retval |= DCD_HandleInEP_ISR(pdev);
- }
-
- if (gintr_status.b.modemismatch)
- {
- USB_OTG_GINTSTS_TypeDef gintsts;
-
- /* Clear interrupt */
- gintsts.d32 = 0;
- gintsts.b.modemismatch = 1;
- USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GINTSTS, gintsts.d32);
- }
-
- if (gintr_status.b.wkupintr)
- {
- retval |= DCD_HandleResume_ISR(pdev);
- }
-
- if (gintr_status.b.usbsuspend)
- {
- retval |= DCD_HandleUSBSuspend_ISR(pdev);
- }
- if (gintr_status.b.sofintr)
- {
- retval |= DCD_HandleSof_ISR(pdev);
-
- }
-
- if (gintr_status.b.rxstsqlvl)
- {
- retval |= DCD_HandleRxStatusQueueLevel_ISR(pdev);
-
- }
-
- if (gintr_status.b.usbreset)
- {
- retval |= DCD_HandleUsbReset_ISR(pdev);
-
- }
- if (gintr_status.b.enumdone)
- {
- retval |= DCD_HandleEnumDone_ISR(pdev);
- }
-
- if (gintr_status.b.incomplisoin)
- {
- retval |= DCD_IsoINIncomplete_ISR(pdev);
- }
-
- if (gintr_status.b.incomplisoout)
- {
- retval |= DCD_IsoOUTIncomplete_ISR(pdev);
- }
-#ifdef VBUS_SENSING_ENABLED
- if (gintr_status.b.sessreqintr)
- {
- retval |= DCD_SessionRequest_ISR(pdev);
- }
-
- if (gintr_status.b.otgintr)
- {
- retval |= DCD_OTG_ISR(pdev);
- }
-#endif
- }
- return retval;
-}
-
-#ifdef VBUS_SENSING_ENABLED
-/**
-* @brief DCD_SessionRequest_ISR
-* Indicates that the USB_OTG controller has detected a connection
-* @param pdev: device instance
-* @retval status
-*/
-static uint32_t DCD_SessionRequest_ISR(USB_OTG_CORE_HANDLE *pdev)
-{
- USB_OTG_GINTSTS_TypeDef gintsts;
- USBD_DCD_INT_fops->DevConnected (pdev);
-
- /* Clear interrupt */
- gintsts.d32 = 0;
- gintsts.b.sessreqintr = 1;
- USB_OTG_WRITE_REG32 (&pdev->regs.GREGS->GINTSTS, gintsts.d32);
- return 1;
-}
-
-/**
-* @brief DCD_OTG_ISR
-* Indicates that the USB_OTG controller has detected an OTG event:
-* used to detect the end of session i.e. disconnection
-* @param pdev: device instance
-* @retval status
-*/
-static uint32_t DCD_OTG_ISR(USB_OTG_CORE_HANDLE *pdev)
-{
-
- USB_OTG_GOTGINT_TypeDef gotgint;
-
- gotgint.d32 = USB_OTG_READ_REG32(&pdev->regs.GREGS->GOTGINT);
-
- if (gotgint.b.sesenddet)
- {
- USBD_DCD_INT_fops->DevDisconnected (pdev);
- }
- /* Clear OTG interrupt */
- USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GOTGINT, gotgint.d32);
- return 1;
-}
-#endif
-/**
-* @brief DCD_HandleResume_ISR
-* Indicates that the USB_OTG controller has detected a resume or
-* remote Wake-up sequence
-* @param pdev: device instance
-* @retval status
-*/
-static uint32_t DCD_HandleResume_ISR(USB_OTG_CORE_HANDLE *pdev)
-{
- USB_OTG_GINTSTS_TypeDef gintsts;
- USB_OTG_DCTL_TypeDef devctl;
- USB_OTG_PCGCCTL_TypeDef power;
-
- if(pdev->cfg.low_power)
- {
- /* un-gate USB Core clock */
- power.d32 = USB_OTG_READ_REG32(pdev->regs.PCGCCTL);
- power.b.gatehclk = 0;
- power.b.stoppclk = 0;
- USB_OTG_WRITE_REG32(pdev->regs.PCGCCTL, power.d32);
- }
-
- /* Clear the Remote Wake-up Signaling */
- devctl.d32 = 0;
- devctl.b.rmtwkupsig = 1;
- USB_OTG_MODIFY_REG32(&pdev->regs.DREGS->DCTL, devctl.d32, 0);
-
- /* Inform upper layer by the Resume Event */
- USBD_DCD_INT_fops->Resume (pdev);
-
- /* Clear interrupt */
- gintsts.d32 = 0;
- gintsts.b.wkupintr = 1;
- USB_OTG_WRITE_REG32 (&pdev->regs.GREGS->GINTSTS, gintsts.d32);
- return 1;
-}
-
-/**
-* @brief USB_OTG_HandleUSBSuspend_ISR
-* Indicates that SUSPEND state has been detected on the USB
-* @param pdev: device instance
-* @retval status
-*/
-static uint32_t DCD_HandleUSBSuspend_ISR(USB_OTG_CORE_HANDLE *pdev)
-{
- USB_OTG_GINTSTS_TypeDef gintsts;
- USB_OTG_PCGCCTL_TypeDef power;
- USB_OTG_DSTS_TypeDef dsts;
- __IO uint8_t prev_status = 0;
-
- prev_status = pdev->dev.device_status;
- USBD_DCD_INT_fops->Suspend (pdev);
-
- dsts.d32 = USB_OTG_READ_REG32(&pdev->regs.DREGS->DSTS);
-
- /* Clear interrupt */
- gintsts.d32 = 0;
- gintsts.b.usbsuspend = 1;
- USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GINTSTS, gintsts.d32);
-
- if((pdev->cfg.low_power) && (dsts.b.suspsts == 1) &&
- (pdev->dev.connection_status == 1) &&
- (prev_status == USB_OTG_CONFIGURED))
- {
- /* switch-off the clocks */
- power.d32 = 0;
- power.b.stoppclk = 1;
- USB_OTG_MODIFY_REG32(pdev->regs.PCGCCTL, 0, power.d32);
-
- power.b.gatehclk = 1;
- USB_OTG_MODIFY_REG32(pdev->regs.PCGCCTL, 0, power.d32);
-
- /* Request to enter Sleep mode after exit from current ISR */
- SCB->SCR |= (SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk);
- }
- return 1;
-}
-
-/**
-* @brief DCD_HandleInEP_ISR
-* Indicates that an IN EP has a pending Interrupt
-* @param pdev: device instance
-* @retval status
-*/
-static uint32_t DCD_HandleInEP_ISR(USB_OTG_CORE_HANDLE *pdev)
-{
- USB_OTG_DIEPINTn_TypeDef diepint;
-
- uint32_t ep_intr;
- uint32_t epnum = 0;
- uint32_t fifoemptymsk;
- diepint.d32 = 0;
- ep_intr = USB_OTG_ReadDevAllInEPItr(pdev);
-
- while ( ep_intr )
- {
- if ((ep_intr & 0x1) == 0x01) /* In ITR */
- {
- diepint.d32 = DCD_ReadDevInEP(pdev , epnum); /* Get In ITR status */
- if ( diepint.b.xfercompl )
- {
- fifoemptymsk = 0x1 << epnum;
- USB_OTG_MODIFY_REG32(&pdev->regs.DREGS->DIEPEMPMSK, fifoemptymsk, 0);
- CLEAR_IN_EP_INTR(epnum, xfercompl);
- /* TX COMPLETE */
- USBD_DCD_INT_fops->DataInStage(pdev , epnum);
-
- if (pdev->cfg.dma_enable == 1)
- {
- if((epnum == 0) && (pdev->dev.device_state == USB_OTG_EP0_STATUS_IN))
- {
- /* prepare to rx more setup packets */
- USB_OTG_EP0_OutStart(pdev);
- }
- }
- }
- if ( diepint.b.timeout )
- {
- CLEAR_IN_EP_INTR(epnum, timeout);
- }
- if (diepint.b.intktxfemp)
- {
- CLEAR_IN_EP_INTR(epnum, intktxfemp);
- }
- if (diepint.b.inepnakeff)
- {
- CLEAR_IN_EP_INTR(epnum, inepnakeff);
- }
- if ( diepint.b.epdisabled )
- {
- CLEAR_IN_EP_INTR(epnum, epdisabled);
- }
- if (diepint.b.emptyintr)
- {
- DCD_WriteEmptyTxFifo(pdev , epnum);
- }
- }
- epnum++;
- ep_intr >>= 1;
- }
-
- return 1;
-}
-
-/**
-* @brief DCD_HandleOutEP_ISR
-* Indicates that an OUT EP has a pending Interrupt
-* @param pdev: device instance
-* @retval status
-*/
-static uint32_t DCD_HandleOutEP_ISR(USB_OTG_CORE_HANDLE *pdev)
-{
- uint32_t ep_intr;
- USB_OTG_DOEPINTn_TypeDef doepint;
- USB_OTG_DEPXFRSIZ_TypeDef deptsiz;
- uint32_t epnum = 0;
-
- doepint.d32 = 0;
-
- /* Read in the device interrupt bits */
- ep_intr = USB_OTG_ReadDevAllOutEp_itr(pdev);
-
- while ( ep_intr )
- {
- if (ep_intr&0x1)
- {
-
- doepint.d32 = USB_OTG_ReadDevOutEP_itr(pdev, epnum);
-
- /* Transfer complete */
- if ( doepint.b.xfercompl )
- {
- /* Clear the bit in DOEPINTn for this interrupt */
- CLEAR_OUT_EP_INTR(epnum, xfercompl);
- if (pdev->cfg.dma_enable == 1)
- {
- deptsiz.d32 = USB_OTG_READ_REG32(&(pdev->regs.OUTEP_REGS[epnum]->DOEPTSIZ));
- /*ToDo : handle more than one single MPS size packet */
- pdev->dev.out_ep[epnum].xfer_count = pdev->dev.out_ep[epnum].maxpacket - \
- deptsiz.b.xfersize;
- }
- /* Inform upper layer: data ready */
- /* RX COMPLETE */
- USBD_DCD_INT_fops->DataOutStage(pdev , epnum);
-
- if (pdev->cfg.dma_enable == 1)
- {
- if((epnum == 0) && (pdev->dev.device_state == USB_OTG_EP0_STATUS_OUT))
- {
- /* prepare to rx more setup packets */
- USB_OTG_EP0_OutStart(pdev);
- }
- }
- }
- /* Endpoint disable */
- if ( doepint.b.epdisabled )
- {
- /* Clear the bit in DOEPINTn for this interrupt */
- CLEAR_OUT_EP_INTR(epnum, epdisabled);
- }
- /* Setup Phase Done (control EPs) */
- if ( doepint.b.setup )
- {
-
- /* inform the upper layer that a setup packet is available */
- /* SETUP COMPLETE */
- USBD_DCD_INT_fops->SetupStage(pdev);
- CLEAR_OUT_EP_INTR(epnum, setup);
- }
- }
- epnum++;
- ep_intr >>= 1;
- }
- return 1;
-}
-
-/**
-* @brief DCD_HandleSof_ISR
-* Handles the SOF Interrupts
-* @param pdev: device instance
-* @retval status
-*/
-static uint32_t DCD_HandleSof_ISR(USB_OTG_CORE_HANDLE *pdev)
-{
- USB_OTG_GINTSTS_TypeDef GINTSTS;
-
-
- USBD_DCD_INT_fops->SOF(pdev);
-
- /* Clear interrupt */
- GINTSTS.d32 = 0;
- GINTSTS.b.sofintr = 1;
- USB_OTG_WRITE_REG32 (&pdev->regs.GREGS->GINTSTS, GINTSTS.d32);
-
- return 1;
-}
-
-/**
-* @brief DCD_HandleRxStatusQueueLevel_ISR
-* Handles the Rx Status Queue Level Interrupt
-* @param pdev: device instance
-* @retval status
-*/
-static uint32_t DCD_HandleRxStatusQueueLevel_ISR(USB_OTG_CORE_HANDLE *pdev)
-{
- USB_OTG_GINTMSK_TypeDef int_mask;
- USB_OTG_DRXSTS_TypeDef status;
- USB_OTG_EP *ep;
-
- /* Disable the Rx Status Queue Level interrupt */
- int_mask.d32 = 0;
- int_mask.b.rxstsqlvl = 1;
- USB_OTG_MODIFY_REG32( &pdev->regs.GREGS->GINTMSK, int_mask.d32, 0);
-
- /* Get the Status from the top of the FIFO */
- status.d32 = USB_OTG_READ_REG32( &pdev->regs.GREGS->GRXSTSP );
-
- ep = &pdev->dev.out_ep[status.b.epnum];
-
- switch (status.b.pktsts)
- {
- case STS_GOUT_NAK:
- break;
- case STS_DATA_UPDT:
- if (status.b.bcnt)
- {
- USB_OTG_ReadPacket(pdev,ep->xfer_buff, status.b.bcnt);
- ep->xfer_buff += status.b.bcnt;
- ep->xfer_count += status.b.bcnt;
- }
- break;
- case STS_XFER_COMP:
- break;
- case STS_SETUP_COMP:
- break;
- case STS_SETUP_UPDT:
- /* Copy the setup packet received in FIFO into the setup buffer in RAM */
- USB_OTG_ReadPacket(pdev , pdev->dev.setup_packet, 8);
- ep->xfer_count += status.b.bcnt;
- break;
- default:
- break;
- }
-
- /* Enable the Rx Status Queue Level interrupt */
- USB_OTG_MODIFY_REG32( &pdev->regs.GREGS->GINTMSK, 0, int_mask.d32);
-
- return 1;
-}
-
-/**
-* @brief DCD_WriteEmptyTxFifo
-* check FIFO for the next packet to be loaded
-* @param pdev: device instance
-* @retval status
-*/
-static uint32_t DCD_WriteEmptyTxFifo(USB_OTG_CORE_HANDLE *pdev, uint32_t epnum)
-{
- USB_OTG_DTXFSTSn_TypeDef txstatus;
- USB_OTG_EP *ep;
- uint32_t len = 0;
- uint32_t len32b;
- txstatus.d32 = 0;
- uint32_t fifoemptymsk;
-
- ep = &pdev->dev.in_ep[epnum];
-
- len = ep->XferLen - ep->xfer_count;
-
- if (len > ep->maxpacket)
- {
- len = ep->maxpacket;
- }
-
- len32b = (len + 3) / 4;
- txstatus.d32 = USB_OTG_READ_REG32( &pdev->regs.INEP_REGS[epnum]->DTXFSTS);
-
- while (txstatus.b.txfspcavail > len32b &&
- ep->xfer_count < ep->XferLen &&
- ep->XferLen != 0)
- {
- /* Write the FIFO */
- len = ep->XferLen - ep->xfer_count;
-
- if (len > ep->maxpacket)
- {
- len = ep->maxpacket;
- }
- len32b = (len + 3) / 4;
-
- USB_OTG_WritePacket (pdev , ep->xfer_buff, epnum, len);
-
- ep->xfer_buff += len;
- ep->xfer_count += len;
-
- txstatus.d32 = USB_OTG_READ_REG32(&pdev->regs.INEP_REGS[epnum]->DTXFSTS);
-
- /* Mask the TxFIFOEmpty interrupt */
- if (ep->XferLen == ep->xfer_count)
- {
- fifoemptymsk = 0x1 << ep->num;
- USB_OTG_MODIFY_REG32(&pdev->regs.DREGS->DIEPEMPMSK,
- fifoemptymsk, 0);
- }
- }
-
- return 1;
-}
-
-/**
-* @brief DCD_HandleUsbReset_ISR
-* This interrupt occurs when a USB Reset is detected
-* @param pdev: device instance
-* @retval status
-*/
-static uint32_t DCD_HandleUsbReset_ISR(USB_OTG_CORE_HANDLE *pdev)
-{
- USB_OTG_DAINT_TypeDef daintmsk;
- USB_OTG_DOEPMSK_TypeDef doepmsk;
- USB_OTG_DIEPMSK_TypeDef diepmsk;
- USB_OTG_DCFG_TypeDef dcfg;
- USB_OTG_DCTL_TypeDef dctl;
- USB_OTG_GINTSTS_TypeDef gintsts;
- uint32_t i;
-
- dctl.d32 = 0;
- daintmsk.d32 = 0;
- doepmsk.d32 = 0;
- diepmsk.d32 = 0;
- dcfg.d32 = 0;
- gintsts.d32 = 0;
-
- /* Clear the Remote Wake-up Signaling */
- dctl.b.rmtwkupsig = 1;
- USB_OTG_MODIFY_REG32(&pdev->regs.DREGS->DCTL, dctl.d32, 0 );
-
- /* Flush the Tx FIFO */
- USB_OTG_FlushTxFifo(pdev , 0 );
-
- for (i = 0; i < pdev->cfg.dev_endpoints ; i++)
- {
- USB_OTG_WRITE_REG32( &pdev->regs.INEP_REGS[i]->DIEPINT, 0xFF);
- USB_OTG_WRITE_REG32( &pdev->regs.OUTEP_REGS[i]->DOEPINT, 0xFF);
- }
- USB_OTG_WRITE_REG32( &pdev->regs.DREGS->DAINT, 0xFFFFFFFF );
-
- daintmsk.ep.in = 1;
- daintmsk.ep.out = 1;
- USB_OTG_WRITE_REG32( &pdev->regs.DREGS->DAINTMSK, daintmsk.d32 );
-
- doepmsk.b.setup = 1;
- doepmsk.b.xfercompl = 1;
- doepmsk.b.epdisabled = 1;
- USB_OTG_WRITE_REG32( &pdev->regs.DREGS->DOEPMSK, doepmsk.d32 );
-#ifdef USB_OTG_HS_DEDICATED_EP1_ENABLED
- USB_OTG_WRITE_REG32( &pdev->regs.DREGS->DOUTEP1MSK, doepmsk.d32 );
-#endif
- diepmsk.b.xfercompl = 1;
- diepmsk.b.timeout = 1;
- diepmsk.b.epdisabled = 1;
-
- USB_OTG_WRITE_REG32( &pdev->regs.DREGS->DIEPMSK, diepmsk.d32 );
-#ifdef USB_OTG_HS_DEDICATED_EP1_ENABLED
- USB_OTG_WRITE_REG32( &pdev->regs.DREGS->DINEP1MSK, diepmsk.d32 );
-#endif
- /* Reset Device Address */
- dcfg.d32 = USB_OTG_READ_REG32( &pdev->regs.DREGS->DCFG);
- dcfg.b.devaddr = 0;
- USB_OTG_WRITE_REG32( &pdev->regs.DREGS->DCFG, dcfg.d32);
-
-
- /* setup EP0 to receive SETUP packets */
- USB_OTG_EP0_OutStart(pdev);
-
- /* Clear interrupt */
- gintsts.d32 = 0;
- gintsts.b.usbreset = 1;
- USB_OTG_WRITE_REG32 (&pdev->regs.GREGS->GINTSTS, gintsts.d32);
-
- /*Reset internal state machine */
- USBD_DCD_INT_fops->Reset(pdev);
- return 1;
-}
-
-/**
-* @brief DCD_HandleEnumDone_ISR
-* Read the device status register and set the device speed
-* @param pdev: device instance
-* @retval status
-*/
-static uint32_t DCD_HandleEnumDone_ISR(USB_OTG_CORE_HANDLE *pdev)
-{
- uint32_t hclk = 168000000;
-
- USB_OTG_GINTSTS_TypeDef gintsts;
- USB_OTG_GUSBCFG_TypeDef gusbcfg;
- RCC_ClocksTypeDef RCC_Clocks;
- USB_OTG_EP0Activate(pdev);
-
- /* Get HCLK frequency */
- RCC_GetClocksFreq(&RCC_Clocks);
- hclk = RCC_Clocks.HCLK_Frequency;
-
- /* Clear default TRDT value and Set USB turn-around time based on device speed and PHY interface. */
- gusbcfg.d32 = USB_OTG_READ_REG32(&pdev->regs.GREGS->GUSBCFG);
- gusbcfg.b.usbtrdtim = 0;
- USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GUSBCFG, gusbcfg.d32);
-
- /* Full or High speed */
- if ( USB_OTG_GetDeviceSpeed(pdev) == USB_SPEED_HIGH)
- {
- pdev->cfg.speed = USB_OTG_SPEED_HIGH;
- pdev->cfg.mps = USB_OTG_HS_MAX_PACKET_SIZE ;
-
- /*USBTRD min For HS device*/
- gusbcfg.b.usbtrdtim = 9;
- }
- else
- {
- pdev->cfg.speed = USB_OTG_SPEED_FULL;
- pdev->cfg.mps = USB_OTG_FS_MAX_PACKET_SIZE ;
-
- /* The USBTRD is configured according to the tables below, depending on AHB frequency
- used by application. In the low AHB frequency range it is used to stretch enough the USB response
- time to IN tokens, the USB turnaround time, so to compensate for the longer AHB read access
- latency to the Data FIFO */
-
- if((hclk >= 15000000)&&(hclk < 16000000))
- {
- /* hclk Clock Range between 15-16 MHz */
- gusbcfg.b.usbtrdtim = 0xE;
- }
-
- else if((hclk >= 16000000)&&(hclk < 17100000))
- {
- /* hclk Clock Range between 16-17.1 MHz */
- gusbcfg.b.usbtrdtim = 0xD;
- }
-
- else if((hclk >= 17100000)&&(hclk < 18400000))
- {
- /* hclk Clock Range between 17-18.4 MHz */
- gusbcfg.b.usbtrdtim = 0xC;
- }
-
- else if((hclk >= 18400000)&&(hclk < 20000000))
- {
- /* hclk Clock Range between 18.4-20 MHz */
- gusbcfg.b.usbtrdtim = 0xB;
- }
-
- else if((hclk >= 20000000)&&(hclk < 21800000))
- {
- /* hclk Clock Range between 20-21.8 MHz */
- gusbcfg.b.usbtrdtim = 0xA;
- }
-
- else if((hclk >= 21800000)&&(hclk < 24000000))
- {
- /* hclk Clock Range between 21.8-24 MHz */
- gusbcfg.b.usbtrdtim = 0x9;
- }
-
- else if((hclk >= 24000000)&&(hclk < 26600000))
- {
- /* hclk Clock Range between 24-26.6 MHz */
- gusbcfg.b.usbtrdtim = 0x8;
- }
-
- else if((hclk >= 26600000)&&(hclk < 30000000))
- {
- /* hclk Clock Range between 26.6-30 MHz */
- gusbcfg.b.usbtrdtim = 0x7;
- }
-
- else if((hclk >= 30000000)&&(hclk < 34300000))
- {
- /* hclk Clock Range between 30-34.3 MHz */
- gusbcfg.b.usbtrdtim= 0x6;
- }
-
- else /* if(hclk >= 34300000) */
- {
- /* hclk Clock Range between 34.3-168 MHz */
- gusbcfg.b.usbtrdtim = 0x5;
- }
- }
-
- USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GUSBCFG, gusbcfg.d32);
-
- /* Clear interrupt */
- gintsts.d32 = 0;
- gintsts.b.enumdone = 1;
- USB_OTG_WRITE_REG32( &pdev->regs.GREGS->GINTSTS, gintsts.d32 );
- return 1;
-}
-
-
-/**
-* @brief DCD_IsoINIncomplete_ISR
-* handle the ISO IN incomplete interrupt
-* @param pdev: device instance
-* @retval status
-*/
-static uint32_t DCD_IsoINIncomplete_ISR(USB_OTG_CORE_HANDLE *pdev)
-{
- USB_OTG_GINTSTS_TypeDef gintsts;
-
- gintsts.d32 = 0;
-
- USBD_DCD_INT_fops->IsoINIncomplete (pdev);
-
- /* Clear interrupt */
- gintsts.b.incomplisoin = 1;
- USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GINTSTS, gintsts.d32);
-
- return 1;
-}
-
-/**
-* @brief DCD_IsoOUTIncomplete_ISR
-* handle the ISO OUT incomplete interrupt
-* @param pdev: device instance
-* @retval status
-*/
-static uint32_t DCD_IsoOUTIncomplete_ISR(USB_OTG_CORE_HANDLE *pdev)
-{
- USB_OTG_GINTSTS_TypeDef gintsts;
-
- gintsts.d32 = 0;
-
- USBD_DCD_INT_fops->IsoOUTIncomplete (pdev);
-
- /* Clear interrupt */
- gintsts.b.incomplisoout = 1;
- USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GINTSTS, gintsts.d32);
- return 1;
-}
-/**
-* @brief DCD_ReadDevInEP
-* Reads ep flags
-* @param pdev: device instance
-* @retval status
-*/
-static uint32_t DCD_ReadDevInEP (USB_OTG_CORE_HANDLE *pdev, uint8_t epnum)
-{
- uint32_t v, msk, emp;
- msk = USB_OTG_READ_REG32(&pdev->regs.DREGS->DIEPMSK);
- emp = USB_OTG_READ_REG32(&pdev->regs.DREGS->DIEPEMPMSK);
- msk |= ((emp >> epnum) & 0x1) << 7;
- v = USB_OTG_READ_REG32(&pdev->regs.INEP_REGS[epnum]->DIEPINT) & msk;
- return v;
-}
-
-/**
-* @}
-*/
-
-/**
-* @}
-*/
-
-/**
-* @}
-*/
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/src/usb_hcd.c b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/src/usb_hcd.c
deleted file mode 100644
index aab6d67aa..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/src/usb_hcd.c
+++ /dev/null
@@ -1,275 +0,0 @@
-/**
- ******************************************************************************
- * @file usb_hcd.c
- * @author xiuos Team
- * @version V1.0.0
- * @date 2020-9-3
- * @brief This file is based on usb_hcd.c
- * Host Interface Layer
- ******************************************************************************
- * @file usb_hcd.c
- * @author MCD Application Team
- * @version V1.0.0
- * @date 30-September-2011
- * ********************************************************************************
- * @attention
- *
- * © Copyright (c) 2015 STMicroelectronics.
- * All rights reserved.
- *
- * This software component is licensed by ST under Ultimate Liberty license
- * SLA0044, the "License"; You may not use this file except in compliance with
- * the License. You may obtain a copy of the License at:
- *
- *
- ******************************************************************************
- */
-
-/* Includes ------------------------------------------------------------------*/
-#include "usb_core.h"
-#include "usb_hcd.h"
-#include "usb_conf.h"
-#include "usb_bsp.h"
-
-
-/** @addtogroup USB_OTG_DRIVER
- * @{
- */
-
-/** @defgroup USB_HCD
- * @brief This file is the interface between EFSL ans Host mass-storage class
- * @{
- */
-
-
-/** @defgroup USB_HCD_Private_Defines
- * @{
- */
-/**
- * @}
- */
-
-
-/** @defgroup USB_HCD_Private_TypesDefinitions
- * @{
- */
-/**
- * @}
- */
-
-
-
-/** @defgroup USB_HCD_Private_Macros
- * @{
- */
-/**
- * @}
- */
-
-
-/** @defgroup USB_HCD_Private_Variables
- * @{
- */
-/**
- * @}
- */
-
-
-/** @defgroup USB_HCD_Private_FunctionPrototypes
- * @{
- */
-/**
- * @}
- */
-
-
-/** @defgroup USB_HCD_Private_Functions
- * @{
- */
-
-/**
- * @brief HCD_Init
- * Initialize the HOST portion of the driver.
- * @param pdev: Selected device
- * @param base_address: OTG base address
- * @retval Status
- */
-uint32_t HCD_Init(USB_OTG_CORE_HANDLE *pdev ,
- USB_OTG_CORE_ID_TypeDef coreID)
-{
- uint8_t i = 0;
- pdev->host.ConnSts = 0;
-
- for (i= 0; i< USB_OTG_MAX_TX_FIFOS; i++)
- {
- pdev->host.ErrCnt[i] = 0;
- pdev->host.XferCnt[i] = 0;
- pdev->host.HC_Status[i] = HC_IDLE;
- }
- pdev->host.hc[0].max_packet = 8;
-
- USB_OTG_SelectCore(pdev, coreID);
-#ifndef DUAL_ROLE_MODE_ENABLED
- USB_OTG_DisableGlobalInt(pdev);
- USB_OTG_CoreInit(pdev);
-
- /* Force Host Mode*/
- USB_OTG_SetCurrentMode(pdev , HOST_MODE);
- USB_OTG_CoreInitHost(pdev);
- USB_OTG_EnableGlobalInt(pdev);
-#endif
-
- return 0;
-}
-
-
-/**
- * @brief HCD_GetCurrentSpeed
- * Get Current device Speed.
- * @param pdev : Selected device
- * @retval Status
- */
-
-uint32_t HCD_GetCurrentSpeed (USB_OTG_CORE_HANDLE *pdev)
-{
- USB_OTG_HPRT0_TypeDef HPRT0;
- HPRT0.d32 = USB_OTG_READ_REG32(pdev->regs.HPRT0);
-
- return HPRT0.b.prtspd;
-}
-
-/**
- * @brief HCD_ResetPort
- * Issues the reset command to device
- * @param pdev : Selected device
- * @retval Status
- */
-uint32_t HCD_ResetPort(USB_OTG_CORE_HANDLE *pdev)
-{
- /*
- Before starting to drive a USB reset, the application waits for the OTG
- interrupt triggered by the denounce done bit (DBCDNE bit in OTG_FS_GOTGINT),
- which indicates that the bus is stable again after the electrical denounce
- caused by the attachment of a pull-up resistor on DP (FS) or DM (LS).
- */
-
- USB_OTG_ResetPort(pdev);
- return 0;
-}
-
-/**
- * @brief HCD_IsDeviceConnected
- * Check if the device is connected.
- * @param pdev : Selected device
- * @retval Device connection status. 1 -> connected and 0 -> disconnected
- *
- */
-uint32_t HCD_IsDeviceConnected(USB_OTG_CORE_HANDLE *pdev)
-{
- return (pdev->host.ConnSts);
-}
-
-
-/**
- * @brief HCD_IsPortEnabled
- * This function checks if port is enabled
- * @param pdev : Selected device
- * @retval Frame number
- *
- */
-uint32_t HCD_IsPortEnabled(USB_OTG_CORE_HANDLE *pdev)
-{
- return (pdev->host.PortEnabled);
-}
-
-/**
- * @brief HCD_GetCurrentFrame
- * This function returns the frame number for sof packet
- * @param pdev : Selected device
- * @retval Frame number
- *
- */
-uint32_t HCD_GetCurrentFrame (USB_OTG_CORE_HANDLE *pdev)
-{
- return (USB_OTG_READ_REG32(&pdev->regs.HREGS->HFNUM) & 0xFFFF) ;
-}
-
-/**
- * @brief HCD_GetURB_State
- * This function returns the last URBstate
- * @param pdev: Selected device
- * @retval URB_STATE
- *
- */
-URB_STATE HCD_GetURB_State (USB_OTG_CORE_HANDLE *pdev , uint8_t ch_num)
-{
- return pdev->host.URB_State[ch_num] ;
-}
-
-/**
- * @brief HCD_GetXferCnt
- * This function returns the last URBstate
- * @param pdev: Selected device
- * @retval No. of data bytes transferred
- *
- */
-uint32_t HCD_GetXferCnt (USB_OTG_CORE_HANDLE *pdev, uint8_t ch_num)
-{
- return pdev->host.XferCnt[ch_num] ;
-}
-
-
-
-/**
- * @brief HCD_GetHCState
- * This function returns the HC Status
- * @param pdev: Selected device
- * @retval HC_STATUS
- *
- */
-HC_STATUS HCD_GetHCState (USB_OTG_CORE_HANDLE *pdev , uint8_t ch_num)
-{
- return pdev->host.HC_Status[ch_num] ;
-}
-
-/**
- * @brief HCD_HC_Init
- * This function prepare a HC and start a transfer
- * @param pdev: Selected device
- * @param hc_num: Channel number
- * @retval status
- */
-uint32_t HCD_HC_Init (USB_OTG_CORE_HANDLE *pdev , uint8_t hc_num)
-{
- return USB_OTG_HC_Init(pdev, hc_num);
-}
-
-/**
- * @brief HCD_SubmitRequest
- * This function prepare a HC and start a transfer
- * @param pdev: Selected device
- * @param hc_num: Channel number
- * @retval status
- */
-uint32_t HCD_SubmitRequest (USB_OTG_CORE_HANDLE *pdev , uint8_t hc_num)
-{
-
- pdev->host.URB_State[hc_num] = URB_IDLE;
- pdev->host.hc[hc_num].xfer_count = 0 ;
- return USB_OTG_HC_StartXfer(pdev, hc_num);
-}
-
-
-/**
-* @}
-*/
-
-/**
-* @}
-*/
-
-/**
-* @}
-*/
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/src/usb_hcd_int.c b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/src/usb_hcd_int.c
deleted file mode 100644
index 2ac302ba7..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/src/usb_hcd_int.c
+++ /dev/null
@@ -1,846 +0,0 @@
-/**
- ******************************************************************************
- * @file usb_hcd_int.c
- * @author xiuos Team
- * @version V1.0.0
- * @date 2020-9-3
- * @brief This file is based on usb_hcd_int.c
- * Host driver interrupt subroutines
- ******************************************************************************
- * @file usb_hcd_int.c
- * @author MCD Application Team
- * @version V1.0.0
- * @date 30-September-2011
- * ********************************************************************************
- * @attention
- *
- * © Copyright (c) 2015 STMicroelectronics.
- * All rights reserved.
- *
- * This software component is licensed by ST under Ultimate Liberty license
- * SLA0044, the "License"; You may not use this file except in compliance with
- * the License. You may obtain a copy of the License at:
- *
- *
- ******************************************************************************
- */
-
-/* Includes ------------------------------------------------------------------*/
-#include "usb_core.h"
-#include "usb_defines.h"
-#include "usb_hcd_int.h"
-
-#if defined (__GNUC__) /*!< GNU Compiler */
-#pragma GCC optimize ("O0")
-
-#endif
-
-/** @addtogroup USB_OTG_DRIVER
-* @{
-*/
-
-/** @defgroup USB_HCD_INT
-* @brief This file contains the interrupt subroutines for the Host mode.
-* @{
-*/
-
-
-/** @defgroup USB_HCD_INT_Private_Defines
-* @{
-*/
-/**
-* @}
-*/
-
-
-/** @defgroup USB_HCD_INT_Private_TypesDefinitions
-* @{
-*/
-/**
-* @}
-*/
-
-
-
-/** @defgroup USB_HCD_INT_Private_Macros
-* @{
-*/
-/**
-* @}
-*/
-
-
-/** @defgroup USB_HCD_INT_Private_Variables
-* @{
-*/
-/**
-* @}
-*/
-
-
-/** @defgroup USB_HCD_INT_Private_FunctionPrototypes
-* @{
-*/
-
-static uint32_t USB_OTG_USBH_handle_sof_ISR(USB_OTG_CORE_HANDLE *pdev);
-static uint32_t USB_OTG_USBH_handle_port_ISR(USB_OTG_CORE_HANDLE *pdev);
-static uint32_t USB_OTG_USBH_handle_hc_ISR (USB_OTG_CORE_HANDLE *pdev);
-static uint32_t USB_OTG_USBH_handle_hc_n_In_ISR (USB_OTG_CORE_HANDLE *pdev ,
- uint32_t num);
-static uint32_t USB_OTG_USBH_handle_hc_n_Out_ISR (USB_OTG_CORE_HANDLE *pdev ,
- uint32_t num);
-static uint32_t USB_OTG_USBH_handle_rx_qlvl_ISR (USB_OTG_CORE_HANDLE *pdev);
-static uint32_t USB_OTG_USBH_handle_nptxfempty_ISR (USB_OTG_CORE_HANDLE *pdev);
-static uint32_t USB_OTG_USBH_handle_ptxfempty_ISR (USB_OTG_CORE_HANDLE *pdev);
-static uint32_t USB_OTG_USBH_handle_Disconnect_ISR (USB_OTG_CORE_HANDLE *pdev);
-static uint32_t USB_OTG_USBH_handle_IncompletePeriodicXfer_ISR (USB_OTG_CORE_HANDLE *pdev);
-
-/**
-* @}
-*/
-
-
-/** @defgroup USB_HCD_INT_Private_Functions
-* @{
-*/
-
-/**
-* @brief HOST_Handle_ISR
-* This function handles all USB Host Interrupts
-* @param pdev: Selected device
-* @retval status
-*/
-
-uint32_t USBH_OTG_ISR_Handler (USB_OTG_CORE_HANDLE *pdev)
-{
- USB_OTG_GINTSTS_TypeDef gintsts;
- uint32_t retval = 0;
-
- gintsts.d32 = 0;
-
- /* Check if HOST Mode */
- if (USB_OTG_IsHostMode(pdev))
- {
- gintsts.d32 = USB_OTG_ReadCoreItr(pdev);
- if (!gintsts.d32)
- {
- return 0;
- }
-
- if (gintsts.b.sofintr)
- {
- retval |= USB_OTG_USBH_handle_sof_ISR (pdev);
- }
-
- if (gintsts.b.rxstsqlvl)
- {
- retval |= USB_OTG_USBH_handle_rx_qlvl_ISR (pdev);
- }
-
- if (gintsts.b.nptxfempty)
- {
- retval |= USB_OTG_USBH_handle_nptxfempty_ISR (pdev);
- }
-
- if (gintsts.b.ptxfempty)
- {
- retval |= USB_OTG_USBH_handle_ptxfempty_ISR (pdev);
- }
-
- if (gintsts.b.hcintr)
- {
- retval |= USB_OTG_USBH_handle_hc_ISR (pdev);
- }
-
- if (gintsts.b.portintr)
- {
- retval |= USB_OTG_USBH_handle_port_ISR (pdev);
- }
-
- if (gintsts.b.disconnect)
- {
- retval |= USB_OTG_USBH_handle_Disconnect_ISR (pdev);
-
- }
-
- if (gintsts.b.incomplisoout)
- {
- retval |= USB_OTG_USBH_handle_IncompletePeriodicXfer_ISR (pdev);
- }
-
-
- }
- return retval;
-}
-
-/**
-* @brief USB_OTG_USBH_handle_hc_ISR
-* This function indicates that one or more host channels has a pending
-* @param pdev: Selected device
-* @retval status
-*/
-static uint32_t USB_OTG_USBH_handle_hc_ISR (USB_OTG_CORE_HANDLE *pdev)
-{
- USB_OTG_HAINT_TypeDef haint;
- USB_OTG_HCCHAR_TypeDef hcchar;
- uint32_t i = 0;
- uint32_t retval = 0;
-
- /* Clear appropriate bits in HCINTn to clear the interrupt bit in
- * GINTSTS */
-
- haint.d32 = USB_OTG_ReadHostAllChannels_intr(pdev);
-
- for (i = 0; i < pdev->cfg.host_channels ; i++)
- {
- if (haint.b.chint & (1 << i))
- {
- hcchar.d32 = USB_OTG_READ_REG32(&pdev->regs.HC_REGS[i]->HCCHAR);
-
- if (hcchar.b.epdir)
- {
- retval |= USB_OTG_USBH_handle_hc_n_In_ISR (pdev, i);
- }
- else
- {
- retval |= USB_OTG_USBH_handle_hc_n_Out_ISR (pdev, i);
- }
- }
- }
-
- return retval;
-}
-
-/**
-* @brief USB_OTG_otg_hcd_handle_sof_intr
-* Handles the start-of-frame interrupt in host mode.
-* @param pdev: Selected device
-* @retval status
-*/
-static uint32_t USB_OTG_USBH_handle_sof_ISR (USB_OTG_CORE_HANDLE *pdev)
-{
- USB_OTG_GINTSTS_TypeDef gintsts;
- gintsts.d32 = 0;
-
- USBH_HCD_INT_fops->SOF(pdev);
-
- /* Clear interrupt */
- gintsts.b.sofintr = 1;
- USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GINTSTS, gintsts.d32);
-
- return 1;
-}
-
-/**
-* @brief USB_OTG_USBH_handle_Disconnect_ISR
-* Handles disconnect event.
-* @param pdev: Selected device
-* @retval status
-*/
-static uint32_t USB_OTG_USBH_handle_Disconnect_ISR (USB_OTG_CORE_HANDLE *pdev)
-{
- USB_OTG_GINTSTS_TypeDef gintsts;
-
- gintsts.d32 = 0;
-
- USBH_HCD_INT_fops->DevDisconnected(pdev);
-
- /* Clear interrupt */
- gintsts.b.disconnect = 1;
- USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GINTSTS, gintsts.d32);
-
- return 1;
-}
-
-/**
-* @brief USB_OTG_USBH_handle_nptxfempty_ISR
-* Handles non periodic tx fifo empty.
-* @param pdev: Selected device
-* @retval status
-*/
-static uint32_t USB_OTG_USBH_handle_nptxfempty_ISR (USB_OTG_CORE_HANDLE *pdev)
-{
- USB_OTG_GINTMSK_TypeDef intmsk;
- USB_OTG_HNPTXSTS_TypeDef hnptxsts;
- uint16_t len_words , len;
-
- hnptxsts.b.nptxqtop.chnum = 0U;
-
- hnptxsts.d32 = USB_OTG_READ_REG32(&pdev->regs.GREGS->HNPTXSTS);
-
- len_words = (pdev->host.hc[hnptxsts.b.nptxqtop.chnum].XferLen + 3) / 4;
-
- while ((hnptxsts.b.nptxfspcavail > len_words)&&
- (pdev->host.hc[hnptxsts.b.nptxqtop.chnum].XferLen != 0))
- {
-
- len = hnptxsts.b.nptxfspcavail * 4;
-
- if (len > pdev->host.hc[hnptxsts.b.nptxqtop.chnum].XferLen)
- {
- /* Last packet */
- len = pdev->host.hc[hnptxsts.b.nptxqtop.chnum].XferLen;
-
- intmsk.d32 = 0;
- intmsk.b.nptxfempty = 1;
- USB_OTG_MODIFY_REG32( &pdev->regs.GREGS->GINTMSK, intmsk.d32, 0);
- }
-
- len_words = (pdev->host.hc[hnptxsts.b.nptxqtop.chnum].XferLen + 3) / 4;
-
- USB_OTG_WritePacket (pdev , pdev->host.hc[hnptxsts.b.nptxqtop.chnum].xfer_buff, hnptxsts.b.nptxqtop.chnum, len);
-
- pdev->host.hc[hnptxsts.b.nptxqtop.chnum].xfer_buff += len;
- pdev->host.hc[hnptxsts.b.nptxqtop.chnum].XferLen -= len;
- pdev->host.hc[hnptxsts.b.nptxqtop.chnum].xfer_count += len;
-
- hnptxsts.d32 = USB_OTG_READ_REG32(&pdev->regs.GREGS->HNPTXSTS);
- }
-
- return 1;
-}
-
-/**
-* @brief USB_OTG_USBH_handle_ptxfempty_ISR
-* Handles periodic tx fifo empty
-* @param pdev: Selected device
-* @retval status
-*/
-static uint32_t USB_OTG_USBH_handle_ptxfempty_ISR (USB_OTG_CORE_HANDLE *pdev)
-{
- USB_OTG_GINTMSK_TypeDef intmsk;
- USB_OTG_HPTXSTS_TypeDef hptxsts;
- uint16_t len_words , len;
-
- hptxsts.b.ptxqtop.chnum = 0U;
-
- hptxsts.d32 = USB_OTG_READ_REG32(&pdev->regs.HREGS->HPTXSTS);
-
- len_words = (pdev->host.hc[hptxsts.b.ptxqtop.chnum].XferLen + 3) / 4;
-
- while ((hptxsts.b.ptxfspcavail > len_words)&&
- (pdev->host.hc[hptxsts.b.ptxqtop.chnum].XferLen != 0))
- {
-
- len = hptxsts.b.ptxfspcavail * 4;
-
- if (len > pdev->host.hc[hptxsts.b.ptxqtop.chnum].XferLen)
- {
- len = pdev->host.hc[hptxsts.b.ptxqtop.chnum].XferLen;
- /* Last packet */
- intmsk.d32 = 0;
- intmsk.b.ptxfempty = 1;
- USB_OTG_MODIFY_REG32( &pdev->regs.GREGS->GINTMSK, intmsk.d32, 0);
- }
-
- len_words = (pdev->host.hc[hptxsts.b.ptxqtop.chnum].XferLen + 3) / 4;
-
- USB_OTG_WritePacket (pdev , pdev->host.hc[hptxsts.b.ptxqtop.chnum].xfer_buff, hptxsts.b.ptxqtop.chnum, len);
-
- pdev->host.hc[hptxsts.b.ptxqtop.chnum].xfer_buff += len;
- pdev->host.hc[hptxsts.b.ptxqtop.chnum].XferLen -= len;
- pdev->host.hc[hptxsts.b.ptxqtop.chnum].xfer_count += len;
-
- hptxsts.d32 = USB_OTG_READ_REG32(&pdev->regs.HREGS->HPTXSTS);
- }
-
- return 1;
-}
-
-/**
-* @brief USB_OTG_USBH_handle_port_ISR
-* This function determines which interrupt conditions have occurred
-* @param pdev: Selected device
-* @retval status
-*/
-
-static uint32_t USB_OTG_USBH_handle_port_ISR (USB_OTG_CORE_HANDLE *pdev)
-{
- USB_OTG_HPRT0_TypeDef hprt0;
- USB_OTG_HPRT0_TypeDef hprt0_dup;
- USB_OTG_HCFG_TypeDef hcfg;
- uint32_t retval = 0;
- USB_OTG_GINTMSK_TypeDef intmsk;
-
- intmsk.d32 = 0;
- hcfg.d32 = 0;
- hprt0.d32 = 0;
- hprt0_dup.d32 = 0;
-
- hprt0.d32 = USB_OTG_READ_REG32(pdev->regs.HPRT0);
- hprt0_dup.d32 = USB_OTG_READ_REG32(pdev->regs.HPRT0);
-
- /* Clear the interrupt bits in GINTSTS */
-
- hprt0_dup.b.prtena = 0;
- hprt0_dup.b.prtconndet = 0;
- hprt0_dup.b.prtenchng = 0;
- hprt0_dup.b.prtovrcurrchng = 0;
-
- /* Port Connect Detected */
- if (hprt0.b.prtconndet)
- {
- hprt0_dup.b.prtconndet = 1;
- USBH_HCD_INT_fops->DevConnected(pdev);
- retval |= 1;
- }
-
- /* Port Enable Changed */
- if (hprt0.b.prtenchng)
- {
- hprt0_dup.b.prtenchng = 1;
-
- if (hprt0.b.prtena == 1)
- {
- if ((hprt0.b.prtspd == HPRT0_PRTSPD_LOW_SPEED) ||
- (hprt0.b.prtspd == HPRT0_PRTSPD_FULL_SPEED))
- {
- hcfg.d32 = USB_OTG_READ_REG32(&pdev->regs.HREGS->HCFG);
-
- if (hprt0.b.prtspd == HPRT0_PRTSPD_LOW_SPEED)
- {
- USB_OTG_WRITE_REG32(&pdev->regs.HREGS->HFIR, 6000 );
- if (hcfg.b.fslspclksel != HCFG_6_MHZ)
- {
- if(pdev->cfg.phy_itface == USB_OTG_EMBEDDED_PHY)
- {
- USB_OTG_InitFSLSPClkSel(pdev , HCFG_6_MHZ);
- }
-
- else
- {
- USB_OTG_WRITE_REG32(&pdev->regs.HREGS->HFIR, 48000 );
- if (hcfg.b.fslspclksel != HCFG_48_MHZ)
- {
- USB_OTG_InitFSLSPClkSel(pdev ,HCFG_48_MHZ );
- }
- }
- }
- }
- }
-
- USBH_HCD_INT_fops->DevPortEnabled(pdev);
-
- /*unmask disconnect interrupt */
- intmsk.d32 = 0;
- intmsk.b.disconnect = 1;
- USB_OTG_MODIFY_REG32(&pdev->regs.GREGS->GINTMSK, intmsk.d32, intmsk.d32);
- }
- else
- {
- USBH_HCD_INT_fops->DevPortDisabled(pdev);
-
- }
- }
-
- /* Overcurrent Change Interrupt */
- if (hprt0.b.prtovrcurrchng)
- {
- hprt0_dup.b.prtovrcurrchng = 1;
- retval |= 1;
- }
-
- /* Clear Port Interrupts */
- USB_OTG_WRITE_REG32(pdev->regs.HPRT0, hprt0_dup.d32);
-
- return retval;
-}
-
-/**
-* @brief USB_OTG_USBH_handle_hc_n_Out_ISR
-* Handles interrupt for a specific Host Channel
-* @param pdev: Selected device
-* @param hc_num: Channel number
-* @retval status
-*/
-uint32_t USB_OTG_USBH_handle_hc_n_Out_ISR (USB_OTG_CORE_HANDLE *pdev , uint32_t num)
-{
-
- USB_OTG_HCINTn_TypeDef hcint;
- USB_OTG_HCINTMSK_TypeDef hcintmsk;
- USB_OTG_HC_REGS *hcreg;
- USB_OTG_HCCHAR_TypeDef hcchar;
-
- hcreg = pdev->regs.HC_REGS[num];
- hcint.d32 = USB_OTG_READ_REG32(&hcreg->HCINT);
- hcintmsk.d32 = USB_OTG_READ_REG32(&hcreg->HCINTMSK);
- hcint.d32 = hcint.d32 & hcintmsk.d32;
-
- hcchar.d32 = USB_OTG_READ_REG32(&pdev->regs.HC_REGS[num]->HCCHAR);
-
- if (hcint.b.ahberr)
- {
- CLEAR_HC_INT(hcreg ,ahberr);
- UNMASK_HOST_INT_CHH (num);
- }
- else if (hcint.b.ack)
- {
- CLEAR_HC_INT(hcreg , ack);
- }
- else if (hcint.b.frmovrun)
- {
- UNMASK_HOST_INT_CHH (num);
- USB_OTG_HC_Halt(pdev, num);
- CLEAR_HC_INT(hcreg ,frmovrun);
- }
- else if (hcint.b.xfercompl)
- {
- pdev->host.ErrCnt[num] = 0;
- UNMASK_HOST_INT_CHH (num);
- USB_OTG_HC_Halt(pdev, num);
- CLEAR_HC_INT(hcreg , xfercompl);
- pdev->host.HC_Status[num] = HC_XFRC;
- }
-
- else if (hcint.b.stall)
- {
- CLEAR_HC_INT(hcreg , stall);
- UNMASK_HOST_INT_CHH (num);
- USB_OTG_HC_Halt(pdev, num);
- pdev->host.HC_Status[num] = HC_STALL;
- }
-
- else if (hcint.b.nak)
- {
- pdev->host.ErrCnt[num] = 0;
- UNMASK_HOST_INT_CHH (num);
- if (pdev->cfg.dma_enable == 0)
- {
- USB_OTG_HC_Halt(pdev, num);
- }
- CLEAR_HC_INT(hcreg , nak);
- pdev->host.HC_Status[num] = HC_NAK;
- }
-
- else if (hcint.b.xacterr)
- {
- UNMASK_HOST_INT_CHH (num);
- USB_OTG_HC_Halt(pdev, num);
- pdev->host.HC_Status[num] = HC_XACTERR;
- CLEAR_HC_INT(hcreg , xacterr);
- }
- else if (hcint.b.nyet)
- {
- pdev->host.ErrCnt[num] = 0;
- UNMASK_HOST_INT_CHH (num);
- if (pdev->cfg.dma_enable == 0)
- {
- USB_OTG_HC_Halt(pdev, num);
- }
- CLEAR_HC_INT(hcreg , nyet);
- pdev->host.HC_Status[num] = HC_NYET;
- }
- else if (hcint.b.datatglerr)
- {
- UNMASK_HOST_INT_CHH (num);
- USB_OTG_HC_Halt(pdev, num);
- CLEAR_HC_INT(hcreg , nak);
- pdev->host.HC_Status[num] = HC_DATATGLERR;
-
- CLEAR_HC_INT(hcreg , datatglerr);
- }
- else if (hcint.b.chhltd)
- {
- MASK_HOST_INT_CHH (num);
-
- if(pdev->host.HC_Status[num] == HC_XFRC)
- {
- pdev->host.URB_State[num] = URB_DONE;
-
- if (hcchar.b.eptype == EP_TYPE_BULK)
- {
- pdev->host.hc[num].toggle_out ^= 1;
- }
- }
- else if(pdev->host.HC_Status[num] == HC_NAK)
- {
- pdev->host.URB_State[num] = URB_NOTREADY;
- }
- else if(pdev->host.HC_Status[num] == HC_NYET)
- {
- if(pdev->host.hc[num].do_ping == 1)
- {
- USB_OTG_HC_DoPing(pdev, num);
- }
- pdev->host.URB_State[num] = URB_NOTREADY;
- }
- else if(pdev->host.HC_Status[num] == HC_STALL)
- {
- pdev->host.URB_State[num] = URB_STALL;
- }
- else if(pdev->host.HC_Status[num] == HC_XACTERR)
- {
- {
- pdev->host.URB_State[num] = URB_ERROR;
- }
- }
- CLEAR_HC_INT(hcreg , chhltd);
- USBH_HCD_INT_fops->URBChangeNotify(pdev);
- }
-
-
- return 1;
-}
-
-/**
-* @brief USB_OTG_USBH_handle_hc_n_In_ISR
-* Handles interrupt for a specific Host Channel
-* @param pdev: Selected device
-* @param hc_num: Channel number
-* @retval status
-*/
-uint32_t USB_OTG_USBH_handle_hc_n_In_ISR (USB_OTG_CORE_HANDLE *pdev , uint32_t num)
-{
- USB_OTG_HCINTn_TypeDef hcint;
- USB_OTG_HCINTMSK_TypeDef hcintmsk;
- USB_OTG_HCCHAR_TypeDef hcchar;
- USB_OTG_HCTSIZn_TypeDef hctsiz;
- USB_OTG_HC_REGS *hcreg;
-
- hcreg = pdev->regs.HC_REGS[num];
- hcint.d32 = USB_OTG_READ_REG32(&hcreg->HCINT);
- hcintmsk.d32 = USB_OTG_READ_REG32(&hcreg->HCINTMSK);
- hcint.d32 = hcint.d32 & hcintmsk.d32;
- hcchar.d32 = USB_OTG_READ_REG32(&pdev->regs.HC_REGS[num]->HCCHAR);
- hcintmsk.d32 = 0;
-
- if (hcint.b.ahberr)
- {
- CLEAR_HC_INT(hcreg ,ahberr);
- UNMASK_HOST_INT_CHH (num);
- }
- else if (hcint.b.ack)
- {
- CLEAR_HC_INT(hcreg ,ack);
- }
-
- else if (hcint.b.stall)
- {
- UNMASK_HOST_INT_CHH (num);
- pdev->host.HC_Status[num] = HC_STALL;
- CLEAR_HC_INT(hcreg , nak); /* Clear the NAK Condition */
- CLEAR_HC_INT(hcreg , stall); /* Clear the STALL Condition */
- hcint.b.nak = 0; /* NOTE: When there is a 'stall', reset also nak,
- else, the pdev->host.HC_Status = HC_STALL
- will be overwritten by 'nak' in code below */
- USB_OTG_HC_Halt(pdev, num);
- }
- else if (hcint.b.datatglerr)
- {
- UNMASK_HOST_INT_CHH (num);
- USB_OTG_HC_Halt(pdev, num);
- CLEAR_HC_INT(hcreg , nak);
- pdev->host.HC_Status[num] = HC_DATATGLERR;
- CLEAR_HC_INT(hcreg , datatglerr);
- }
-
- if (hcint.b.frmovrun)
- {
- UNMASK_HOST_INT_CHH (num);
- USB_OTG_HC_Halt(pdev, num);
- CLEAR_HC_INT(hcreg ,frmovrun);
- }
-
- else if (hcint.b.xfercompl)
- {
- if (pdev->cfg.dma_enable == 1)
- {
- hctsiz.d32 = USB_OTG_READ_REG32(&pdev->regs.HC_REGS[num]->HCTSIZ);
- pdev->host.XferCnt[num] = pdev->host.hc[num].XferLen - hctsiz.b.xfersize;
- }
-
- pdev->host.HC_Status[num] = HC_XFRC;
- pdev->host.ErrCnt [num]= 0;
- CLEAR_HC_INT(hcreg , xfercompl);
-
- if ((hcchar.b.eptype == EP_TYPE_CTRL)||
- (hcchar.b.eptype == EP_TYPE_BULK))
- {
- UNMASK_HOST_INT_CHH (num);
- USB_OTG_HC_Halt(pdev, num);
- CLEAR_HC_INT(hcreg , nak);
- pdev->host.hc[num].toggle_in ^= 1;
-
- }
- else if(hcchar.b.eptype == EP_TYPE_INTR)
- {
- hcchar.b.oddfrm = 1;
- USB_OTG_WRITE_REG32(&pdev->regs.HC_REGS[num]->HCCHAR, hcchar.d32);
- pdev->host.URB_State[num] = URB_DONE;
- USBH_HCD_INT_fops->URBChangeNotify(pdev);
- }
- }
- else if (hcint.b.chhltd)
- {
- MASK_HOST_INT_CHH (num);
-
- if(pdev->host.HC_Status[num] == HC_XFRC)
- {
- pdev->host.URB_State[num] = URB_DONE;
- }
-
- else if (pdev->host.HC_Status[num] == HC_STALL)
- {
- pdev->host.URB_State[num] = URB_STALL;
- }
-
- else if((pdev->host.HC_Status[num] == HC_XACTERR) ||
- (pdev->host.HC_Status[num] == HC_DATATGLERR))
- {
- pdev->host.ErrCnt[num] = 0;
- pdev->host.URB_State[num] = URB_ERROR;
-
- }
- else if(hcchar.b.eptype == EP_TYPE_INTR)
- {
- pdev->host.hc[num].toggle_in ^= 1;
- }
-
- CLEAR_HC_INT(hcreg , chhltd);
- USBH_HCD_INT_fops->URBChangeNotify(pdev);
- }
- else if (hcint.b.xacterr)
- {
- UNMASK_HOST_INT_CHH (num);
- pdev->host.HC_Status[num] = HC_XACTERR;
- USB_OTG_HC_Halt(pdev, num);
- CLEAR_HC_INT(hcreg , xacterr);
- }
- else if (hcint.b.nak)
- {
- if(hcchar.b.eptype == EP_TYPE_INTR)
- {
- UNMASK_HOST_INT_CHH (num);
- if (pdev->cfg.dma_enable == 0)
- {
- USB_OTG_HC_Halt(pdev, num);
- }
- }
-
- pdev->host.HC_Status[num] = HC_NAK;
- CLEAR_HC_INT(hcreg , nak);
-
- if ((hcchar.b.eptype == EP_TYPE_CTRL)||
- (hcchar.b.eptype == EP_TYPE_BULK))
- {
- /* re-activate the channel */
- hcchar.b.chen = 1;
- hcchar.b.chdis = 0;
- USB_OTG_WRITE_REG32(&pdev->regs.HC_REGS[num]->HCCHAR, hcchar.d32);
- }
- }
-
-
- return 1;
-
-}
-
-/**
-* @brief USB_OTG_USBH_handle_rx_qlvl_ISR
-* Handles the Rx Status Queue Level Interrupt
-* @param pdev: Selected device
-* @retval status
-*/
-
-static uint32_t USB_OTG_USBH_handle_rx_qlvl_ISR (USB_OTG_CORE_HANDLE *pdev)
-{
- USB_OTG_GRXFSTS_TypeDef grxsts;
- USB_OTG_GINTMSK_TypeDef intmsk;
- USB_OTG_HCTSIZn_TypeDef hctsiz;
- USB_OTG_HCCHAR_TypeDef hcchar;
- __IO uint8_t channelnum =0;
- uint32_t count;
-
- /* Disable the Rx Status Queue Level interrupt */
- intmsk.d32 = 0;
- intmsk.b.rxstsqlvl = 1;
- USB_OTG_MODIFY_REG32( &pdev->regs.GREGS->GINTMSK, intmsk.d32, 0);
-
- grxsts.d32 = USB_OTG_READ_REG32(&pdev->regs.GREGS->GRXSTSP);
- channelnum = grxsts.b.chnum;
- hcchar.d32 = USB_OTG_READ_REG32(&pdev->regs.HC_REGS[channelnum]->HCCHAR);
-
- switch (grxsts.b.pktsts)
- {
- case GRXSTS_PKTSTS_IN:
- /* Read the data into the host buffer. */
- if ((grxsts.b.bcnt > 0) && (pdev->host.hc[channelnum].xfer_buff != (void *)0))
- {
-
- USB_OTG_ReadPacket(pdev, pdev->host.hc[channelnum].xfer_buff, grxsts.b.bcnt);
- /*manage multiple Xfer */
- pdev->host.hc[grxsts.b.chnum].xfer_buff += grxsts.b.bcnt;
- pdev->host.hc[grxsts.b.chnum].xfer_count += grxsts.b.bcnt;
-
-
- count = pdev->host.hc[channelnum].xfer_count;
- pdev->host.XferCnt[channelnum] = count;
-
- hctsiz.d32 = USB_OTG_READ_REG32(&pdev->regs.HC_REGS[channelnum]->HCTSIZ);
- if(hctsiz.b.pktcnt > 0)
- {
- /* re-activate the channel when more packets are expected */
- hcchar.b.chen = 1;
- hcchar.b.chdis = 0;
- USB_OTG_WRITE_REG32(&pdev->regs.HC_REGS[channelnum]->HCCHAR, hcchar.d32);
- }
- }
- break;
-
- case GRXSTS_PKTSTS_IN_XFER_COMP:
-
- case GRXSTS_PKTSTS_DATA_TOGGLE_ERR:
- case GRXSTS_PKTSTS_CH_HALTED:
- default:
- break;
- }
-
- /* Enable the Rx Status Queue Level interrupt */
- intmsk.b.rxstsqlvl = 1;
- USB_OTG_MODIFY_REG32(&pdev->regs.GREGS->GINTMSK, 0, intmsk.d32);
- return 1;
-}
-
-/**
-* @brief USB_OTG_USBH_handle_IncompletePeriodicXfer_ISR
-* Handles the incomplete Periodic transfer Interrupt
-* @param pdev: Selected device
-* @retval status
-*/
-
-static uint32_t USB_OTG_USBH_handle_IncompletePeriodicXfer_ISR (USB_OTG_CORE_HANDLE *pdev)
-{
-
- USB_OTG_GINTSTS_TypeDef gintsts;
- USB_OTG_HCCHAR_TypeDef hcchar;
-
-
-
-
- hcchar.d32 = USB_OTG_READ_REG32(&pdev->regs.HC_REGS[0]->HCCHAR);
- hcchar.b.chen = 1;
- hcchar.b.chdis = 1;
- USB_OTG_WRITE_REG32(&pdev->regs.HC_REGS[0]->HCCHAR, hcchar.d32);
-
- gintsts.d32 = 0;
- /* Clear interrupt */
- gintsts.b.incomplisoout = 1;
- USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GINTSTS, gintsts.d32);
-
- return 1;
-}
-
-/**
-* @}
-*/
-
-/**
-* @}
-*/
-
-/**
-* @}
-*/
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
-
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/src/usb_otg.c b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/src/usb_otg.c
deleted file mode 100644
index fb718f740..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/STM32_USB_OTG_Driver/src/usb_otg.c
+++ /dev/null
@@ -1,418 +0,0 @@
-/**
- ******************************************************************************
- * @file usb_otg.c
- * @author xiuos Team
- * @version V1.0.0
- * @date 2020-9-3
- * @brief This file is based on usb_otg.c
- * OTG Core Layer
- ******************************************************************************
- * @file usb_otg.c
- * @author MCD Application Team
- * @version V1.0.0
- * @date 30-September-2011
- * ********************************************************************************
- * @attention
- *
- * © Copyright (c) 2015 STMicroelectronics.
- * All rights reserved.
- *
- * This software component is licensed by ST under Ultimate Liberty license
- * SLA0044, the "License"; You may not use this file except in compliance with
- * the License. You may obtain a copy of the License at:
- *
- *
- ******************************************************************************
- */
-
-/* Includes ------------------------------------------------------------------*/
-#include "usb_defines.h"
-#include "usb_regs.h"
-#include "usb_core.h"
-#include "usb_otg.h"
-
-/** @addtogroup USB_OTG_DRIVER
- * @{
- */
-
-/** @defgroup USB_OTG
- * @brief This file is the interface between EFSL ans Host mass-storage class
- * @{
- */
-
-
-/** @defgroup USB_OTG_Private_Defines
- * @{
- */
-/**
- * @}
- */
-
-
-/** @defgroup USB_OTG_Private_TypesDefinitions
- * @{
- */
-/**
- * @}
- */
-
-
-
-/** @defgroup USB_OTG_Private_Macros
- * @{
- */
-/**
- * @}
- */
-
-
-/** @defgroup USB_OTG_Private_Variables
- * @{
- */
-/**
- * @}
- */
-
-
-/** @defgroup USB_OTG_Private_FunctionPrototypes
- * @{
- */
-
-uint32_t USB_OTG_HandleOTG_ISR(USB_OTG_CORE_HANDLE *pdev);
-
-static uint32_t USB_OTG_HandleConnectorIDStatusChange_ISR(USB_OTG_CORE_HANDLE *pdev);
-static uint32_t USB_OTG_HandleSessionRequest_ISR(USB_OTG_CORE_HANDLE *pdev);
-static uint32_t USB_OTG_Read_itr(USB_OTG_CORE_HANDLE *pdev);
-
-/**
- * @}
- */
-
-
-/** @defgroup USB_OTG_Private_Functions
- * @{
- */
-
-
-/* OTG Interrupt Handler */
-
-
-/**
- * @brief STM32_USBO_OTG_ISR_Handler
- *
- * @param None
- * @retval : None
- */
-uint32_t STM32_USBO_OTG_ISR_Handler(USB_OTG_CORE_HANDLE *pdev)
-{
- uint32_t retval = 0;
- USB_OTG_GINTSTS_TypeDef gintsts ;
- gintsts.d32 = 0;
-
- gintsts.d32 = USB_OTG_Read_itr(pdev);
- if (gintsts.d32 == 0)
- {
- return 0;
- }
- if (gintsts.b.otgintr)
- {
- retval |= USB_OTG_HandleOTG_ISR(pdev);
- }
- if (gintsts.b.conidstschng)
- {
- retval |= USB_OTG_HandleConnectorIDStatusChange_ISR(pdev);
- }
- if (gintsts.b.sessreqintr)
- {
- retval |= USB_OTG_HandleSessionRequest_ISR(pdev);
- }
- return retval;
-}
-
-
-/**
- * @brief USB_OTG_Read_itr
- * returns the Core Interrupt register
- * @param None
- * @retval : status
- */
-static uint32_t USB_OTG_Read_itr(USB_OTG_CORE_HANDLE *pdev)
-{
- USB_OTG_GINTSTS_TypeDef gintsts;
- USB_OTG_GINTMSK_TypeDef gintmsk;
- USB_OTG_GINTMSK_TypeDef gintmsk_common;
-
-
- gintsts.d32 = 0;
- gintmsk.d32 = 0;
- gintmsk_common.d32 = 0;
-
- /* OTG interrupts */
- gintmsk_common.b.sessreqintr = 1;
- gintmsk_common.b.conidstschng = 1;
- gintmsk_common.b.otgintr = 1;
-
- gintsts.d32 = USB_OTG_READ_REG32(&pdev->regs.GREGS->GINTSTS);
- gintmsk.d32 = USB_OTG_READ_REG32(&pdev->regs.GREGS->GINTMSK);
- return ((gintsts.d32 & gintmsk.d32 ) & gintmsk_common.d32);
-}
-
-
-/**
- * @brief USB_OTG_HandleOTG_ISR
- * handles the OTG Interrupts
- * @param None
- * @retval : status
- */
-uint32_t USB_OTG_HandleOTG_ISR(USB_OTG_CORE_HANDLE *pdev)
-{
- USB_OTG_GOTGINT_TypeDef gotgint;
- USB_OTG_GOTGCTL_TypeDef gotgctl;
-
-
- gotgint.d32 = 0;
- gotgctl.d32 = 0;
-
- gotgint.d32 = USB_OTG_READ_REG32(&pdev->regs.GREGS->GOTGINT);
- gotgctl.d32 = USB_OTG_READ_REG32(&pdev->regs.GREGS->GOTGCTL);
-
- if (gotgint.b.sesenddet)
- {
- gotgctl.d32 = USB_OTG_READ_REG32(&pdev->regs.GREGS->GOTGCTL);
-
-
- if (USB_OTG_IsDeviceMode(pdev))
- {
-
- }
- else if (USB_OTG_IsHostMode(pdev))
- {
-
- }
- }
-
- /* ----> SRP SUCCESS or FAILURE INTERRUPT <---- */
- if (gotgint.b.sesreqsucstschng)
- {
- gotgctl.d32 = USB_OTG_READ_REG32(&pdev->regs.GREGS->GOTGCTL);
- if (gotgctl.b.sesreqscs) /* Session request success */
- {
- if (USB_OTG_IsDeviceMode(pdev))
- {
-
- }
- /* Clear Session Request */
- gotgctl.d32 = 0;
- gotgctl.b.sesreq = 1;
- USB_OTG_MODIFY_REG32(&pdev->regs.GREGS->GOTGCTL, gotgctl.d32, 0);
- }
- else /* Session request failure */
- {
- if (USB_OTG_IsDeviceMode(pdev))
- {
-
- }
- }
- }
- /* ----> HNP SUCCESS or FAILURE INTERRUPT <---- */
- if (gotgint.b.hstnegsucstschng)
- {
- gotgctl.d32 = USB_OTG_READ_REG32(&pdev->regs.GREGS->GOTGCTL);
-
- if (gotgctl.b.hstnegscs) /* Host negotiation success */
- {
- if (USB_OTG_IsHostMode(pdev)) /* The core AUTOMATICALLY sets the Host mode */
- {
-
- }
- }
- else /* Host negotiation failure */
- {
-
- }
- gotgint.b.hstnegsucstschng = 1; /* Ack "Host Negotiation Success Status Change" interrupt. */
- }
- /* ----> HOST NEGOTIATION DETECTED INTERRUPT <---- */
- if (gotgint.b.hstnegdet)
- {
- if (USB_OTG_IsDeviceMode(pdev)) /* The core AUTOMATICALLY sets the Host mode */
- {
-
- }
- else
- {
-
- }
- }
- if (gotgint.b.adevtoutchng)
- {}
- if (gotgint.b.debdone)
- {
- USB_OTG_ResetPort(pdev);
- }
- /* Clear OTG INT */
- USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GOTGINT, gotgint.d32);
- return 1;
-}
-
-
-/**
- * @brief USB_OTG_HandleConnectorIDStatusChange_ISR
- * handles the Connector ID Status Change Interrupt
- * @param None
- * @retval : status
- */
-static uint32_t USB_OTG_HandleConnectorIDStatusChange_ISR(USB_OTG_CORE_HANDLE *pdev)
-{
- USB_OTG_GINTMSK_TypeDef gintmsk;
- USB_OTG_GOTGCTL_TypeDef gotgctl;
- USB_OTG_GINTSTS_TypeDef gintsts;
-
- gintsts.d32 = 0 ;
- gintmsk.d32 = 0 ;
- gotgctl.d32 = 0 ;
- gintmsk.b.sofintr = 1;
-
- USB_OTG_MODIFY_REG32(&pdev->regs.GREGS->GINTMSK, gintmsk.d32, 0);
- gotgctl.d32 = USB_OTG_READ_REG32(&pdev->regs.GREGS->GOTGCTL);
-
- /* B-Device connector (Device Mode) */
- if (gotgctl.b.conidsts)
- {
- USB_OTG_DisableGlobalInt(pdev);
- USB_OTG_CoreInitDev(pdev);
- USB_OTG_EnableGlobalInt(pdev);
- pdev->otg.OTG_State = B_PERIPHERAL;
- }
- else
- {
- USB_OTG_DisableGlobalInt(pdev);
- USB_OTG_CoreInitHost(pdev);
- USB_OTG_EnableGlobalInt(pdev);
- pdev->otg.OTG_State = A_HOST;
- }
- /* Set flag and clear interrupt */
- gintsts.b.conidstschng = 1;
- USB_OTG_WRITE_REG32 (&pdev->regs.GREGS->GINTSTS, gintsts.d32);
- return 1;
-}
-
-
-/**
- * @brief USB_OTG_HandleSessionRequest_ISR
- * Initiating the Session Request Protocol
- * @param None
- * @retval : status
- */
-static uint32_t USB_OTG_HandleSessionRequest_ISR(USB_OTG_CORE_HANDLE *pdev)
-{
- USB_OTG_GINTSTS_TypeDef gintsts;
- USB_OTG_GOTGCTL_TypeDef gotgctl;
-
-
- gotgctl.d32 = 0;
- gintsts.d32 = 0;
-
- gotgctl.d32 = USB_OTG_READ_REG32( &pdev->regs.GREGS->GOTGCTL );
- if (USB_OTG_IsDeviceMode(pdev) && (gotgctl.b.bsesvld))
- {
-
- }
- else if (gotgctl.b.asesvld)
- {
- }
- /* Clear interrupt */
- gintsts.d32 = 0;
- gintsts.b.sessreqintr = 1;
- USB_OTG_WRITE_REG32 (&pdev->regs.GREGS->GINTSTS, gintsts.d32);
- return 1;
-}
-
-
-/**
- * @brief USB_OTG_InitiateSRP
- * Initiate an srp session
- * @param None
- * @retval : None
- */
-void USB_OTG_InitiateSRP(USB_OTG_CORE_HANDLE *pdev)
-{
- USB_OTG_GOTGCTL_TypeDef otgctl;
-
- otgctl.d32 = 0;
-
- otgctl.d32 = USB_OTG_READ_REG32( &pdev->regs.GREGS->GOTGCTL );
- if (otgctl.b.sesreq)
- {
- return; /* SRP in progress */
- }
- otgctl.b.sesreq = 1;
- USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GOTGCTL, otgctl.d32);
-}
-
-
-/**
- * @brief USB_OTG_InitiateHNP
- * Initiate HNP
- * @param None
- * @retval : None
- */
-void USB_OTG_InitiateHNP(USB_OTG_CORE_HANDLE *pdev , uint8_t state, uint8_t mode)
-{
- USB_OTG_GOTGCTL_TypeDef otgctl;
- USB_OTG_HPRT0_TypeDef hprt0;
-
- otgctl.d32 = 0;
- hprt0.d32 = 0;
-
- otgctl.d32 = USB_OTG_READ_REG32( &pdev->regs.GREGS->GOTGCTL );
- if (mode)
- { /* Device mode */
- if (state)
- {
-
- otgctl.b.devhnpen = 1; /* B-Dev has been enabled to perform HNP */
- otgctl.b.hnpreq = 1; /* Initiate an HNP req. to the connected USB host*/
- USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GOTGCTL, otgctl.d32);
- }
- }
- else
- { /* Host mode */
- if (state)
- {
- otgctl.b.hstsethnpen = 1; /* A-Dev has enabled B-device for HNP */
- USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GOTGCTL, otgctl.d32);
- /* Suspend the bus so that B-dev will disconnect indicating the initial condition for HNP to DWC_Core */
- hprt0.d32 = USB_OTG_ReadHPRT0(pdev);
- hprt0.b.prtsusp = 1; /* The core clear this bit when disconnect interrupt generated (GINTSTS.DisconnInt = '1') */
- USB_OTG_WRITE_REG32(pdev->regs.HPRT0, hprt0.d32);
- }
- }
-}
-
-
-/**
- * @brief USB_OTG_GetCurrentState
- * Return current OTG State
- * @param None
- * @retval : None
- */
-uint32_t USB_OTG_GetCurrentState (USB_OTG_CORE_HANDLE *pdev)
-{
- return pdev->otg.OTG_State;
-}
-
-
-/**
-* @}
-*/
-
-/**
-* @}
-*/
-
-/**
-* @}
-*/
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/connect_usb.c b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/connect_usb.c
deleted file mode 100644
index eb10628cf..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/connect_usb.c
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
-* Copyright (c) 2020 AIIT XUOS Lab
-* XiUOS is licensed under Mulan PSL v2.
-* You can use this software according to the terms and conditions of the Mulan PSL v2.
-* You may obtain a copy of Mulan PSL v2 at:
-* http://license.coscl.org.cn/MulanPSL2
-* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
-* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
-* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
-* See the Mulan PSL v2 for more details.
-*/
-
-/**
-* @file connect_usb.c
-* @brief support stm32f407-st-discovery-board usb function and register to bus framework
-* @version 1.0
-* @author AIIT XUOS Lab
-* @date 2021-04-25
-*/
-
-#include
-#include "core_cm4.h"
-#include "connect_usb.h"
-#include "bus_usb.h"
-#include "dev_usb.h"
-
-uint32 UdiskRead_new_api(void *dev, struct BusBlockReadParam *read_param);
-uint32 UdiskWirte_new_api(void *dev, struct BusBlockWriteParam *write_param);
-
-static uint32 UdiskOpenNewApi(void *dev)
-{
- return EOK;
-}
-
-static uint32 UdiskCloseNewApi(void *dev)
-{
- return EOK;
-}
-
-/*manage the usb device operations*/
-static const struct UsbDevDone dev_done =
-{
- .open = UdiskOpenNewApi,
- .close = UdiskCloseNewApi,
- .write = UdiskWirte_new_api,
- .read = UdiskRead_new_api,
-};
-
-/*Init usb bus*/
-static int BoardUsbBusInit(struct UsbBus *usb_bus, struct UsbDriver *usb_driver)
-{
- x_err_t ret = EOK;
-
- /*Init the usb bus */
- ret = UsbBusInit(usb_bus, USB_BUS_NAME);
- if (EOK != ret) {
- KPrintf("board_usb_init UsbBusInit error %d\n", ret);
- return ERROR;
- }
-
- /*Init the usb driver*/
- ret = UsbDriverInit(usb_driver, USB_DRIVER_NAME);
- if (EOK != ret) {
- KPrintf("board_usb_init UsbDriverInit error %d\n", ret);
- return ERROR;
- }
-
- /*Attach the usb driver to the usb bus*/
- ret = UsbDriverAttachToBus(USB_DRIVER_NAME, USB_BUS_NAME);
- if (EOK != ret) {
- KPrintf("board_usb_init USEDriverAttachToBus error %d\n", ret);
- return ERROR;
- }
-
- return ret;
-}
-
-/*Attach the usb device to the usb bus*/
-static int BoardUsbDevBend(void)
-{
- x_err_t ret = EOK;
- static struct UsbHardwareDevice usb_device1;
- memset(&usb_device1, 0, sizeof(struct UsbHardwareDevice));
-
- usb_device1.dev_done = &dev_done;
-
- ret = USBDeviceRegister(&usb_device1, NONE, USB_DEVICE_NAME);
- if (EOK != ret) {
- KPrintf("board_usb_init USBDeviceInit device %s error %d\n", USB_DEVICE_NAME, ret);
- return ERROR;
- }
-
- ret = USBDeviceAttachToBus(USB_DEVICE_NAME, USB_BUS_NAME);
- if (EOK != ret) {
- KPrintf("board_usb_init USBDeviceAttachToBus device %s error %d\n", USB_DEVICE_NAME, ret);
- return ERROR;
- }
-
- return ret;
-}
-
-/*ARM-32 BOARD USB INIT*/
-int Stm32HwUsbInit(void)
-{
- x_err_t ret = EOK;
- static struct UsbBus usb_bus;
- memset(&usb_bus, 0, sizeof(struct UsbBus));
-
- static struct UsbDriver usb_driver;
- memset(&usb_driver, 0, sizeof(struct UsbDriver));
-
- ret = BoardUsbBusInit(&usb_bus, &usb_driver);
- if (EOK != ret) {
- KPrintf("board_usb_Init error ret %u\n", ret);
- return ERROR;
- }
-
- ret = BoardUsbDevBend();
- if (EOK != ret) {
- KPrintf("board_usb_Init error ret %u\n", ret);
- return ERROR;
- }
-
- return ret;
-}
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/usb_bsp.c b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/usb_bsp.c
deleted file mode 100644
index 23d932c4f..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/usb_bsp.c
+++ /dev/null
@@ -1,236 +0,0 @@
-/**
- ******************************************************************************
- * @file usb_bsp.c
- * @author xiuos Team
- * @version V1.0.0
- * @date 2020-9-3
- * @brief This file is based on usb_bsp.c
- * This file is responsible to offer board support package and is
- * configurable by user.
- ******************************************************************************
- * @file usb_bsp.c
- * @author MCD Application Team
- * @version V1.0.0
- * @date 30-September-2011
- * ********************************************************************************
- * @attention
- *
- * © Copyright (c) 2015 STMicroelectronics.
- * All rights reserved.
- *
- * This software component is licensed by ST under Ultimate Liberty license
- * SLA0044, the "License"; You may not use this file except in compliance with
- * the License. You may obtain a copy of the License at:
- *
- *
- ******************************************************************************
- */
-
-/* Includes ------------------------------------------------------------------*/
-#include "usb_bsp.h"
-
-#include
-#include
-#include
-#include
-#include
-
-/** @addtogroup USB_OTG_DRIVER
-* @{
-*/
-
-/** @defgroup USB_BSP
- * @brief This file is responsible to offer board support package
- * @{
- */
-
-/** @defgroup USB_BSP_Private_Defines
- * @{
- */
-/**
- * @}
- */
-
-
-/** @defgroup USB_BSP_Private_TypesDefinitions
- * @{
- */
-/**
- * @}
- */
-
-
-
-
-
-/** @defgroup USB_BSP_Private_Macros
- * @{
- */
-/**
- * @}
- */
-
-/** @defgroup USBH_BSP_Private_Variables
- * @{
- */
-
-/**
- * @}
- */
-
-/** @defgroup USBH_BSP_Private_FunctionPrototypes
- * @{
- */
-/**
- * @}
- */
-
-/** @defgroup USB_BSP_Private_Functions
- * @{
- */
-
-
-/**
- * @brief USB_OTG_BSP_Init
- * Initializes BSP configurations
- * @param None
- * @retval None
- */
-
-int USB_OTG_BSP_Init_count = 0;
-
-void USB_OTG_BSP_Init(USB_OTG_CORE_HANDLE *pdev)
-{
- GPIO_InitTypeDef gpio_initstructure;
-
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
- RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_OTG_FS, ENABLE);
-
- gpio_initstructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12;
- gpio_initstructure.GPIO_Mode = GPIO_Mode_AF;
- gpio_initstructure.GPIO_OType = GPIO_OType_PP;
- gpio_initstructure.GPIO_Speed = GPIO_Speed_100MHz;
- gpio_initstructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
- GPIO_Init(GPIOA, &gpio_initstructure);
-
- GPIO_PinAFConfig(GPIOA,GPIO_PinSource11, GPIO_AF_OTG_FS);
- GPIO_PinAFConfig(GPIOA,GPIO_PinSource12, GPIO_AF_OTG_FS);
-
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
-
- gpio_initstructure.GPIO_Pin = GPIO_Pin_0;
- gpio_initstructure.GPIO_Mode = GPIO_Mode_OUT;
- gpio_initstructure.GPIO_OType = GPIO_OType_PP;
- gpio_initstructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
- GPIO_Init(GPIOC, &gpio_initstructure);
-}
-/**
- * @brief USB_OTG_BSP_ENABLE_INTERRUPT
- * Enable USB Global interrupt
- * @param None
- * @retval None
- */
-void USB_OTG_BSP_ENABLE_INTERRUPT(USB_OTG_CORE_HANDLE *pdev)
-{
- isrManager.done->enableIrq(OTG_FS_IRQn);
-}
-
-/**
- * @brief BSP_Drive_VBUS
- * Drives the Vbus signal through IO
- * @param speed : Full, Low
- * @param state : VBUS states
- * @retval None
- */
-
-void USB_OTG_BSP_DriveVBUS(USB_OTG_CORE_HANDLE *pdev,uint8_t state)
-{
- if (state == 1)
- GPIO_ResetBits(GPIOC, GPIO_Pin_0);
- else
- GPIO_SetBits(GPIOC, GPIO_Pin_0);
-}
-
-/**
- * @brief USB_OTG_BSP_ConfigVBUS
- * Configures the IO for the Vbus and OverCurrent
- * @param Speed : Full, Low
- * @retval None
- */
-
-void USB_OTG_BSP_ConfigVBUS(USB_OTG_CORE_HANDLE *pdev)
-{
-
-}
-
-/**
- * @brief USB_OTG_BSP_TimeInit
- * Initialises delay unit Systick timer /Timer2
- * @param None
- * @retval None
- */
-void USB_OTG_BSP_TimeInit ( void )
-{
-
-}
-
-/**
- * @brief USB_OTG_BSP_uDelay
- * This function provides delay time in micro sec
- * @param usec : Value of delay required in micro sec
- * @retval None
- */
-void USB_OTG_BSP_uDelay (const uint32_t usec)
-{
-
- uint32_t count = 0;
- const uint32_t utime = (120 * usec / 7);
- do {
- if ( ++count > utime ) {
- return ;
- }
- }
- while (1);
-
-}
-
-
-/**
- * @brief USB_OTG_BSP_mDelay
- * This function provides delay time in milli sec
- * @param msec : Value of delay required in milli sec
- * @retval None
- */
-void USB_OTG_BSP_mDelay (const uint32_t msec)
-{
-
- DelayKTask(msec * TICK_PER_SECOND / 1000);
-
-}
-
-
-/**
- * @brief USB_OTG_BSP_TimerIRQ
- * Time base IRQ
- * @param None
- * @retval None
- */
-
-void USB_OTG_BSP_TimerIRQ (void)
-{
-
-}
-
-/**
-* @}
-*/
-
-/**
-* @}
-*/
-
-/**
-* @}
-*/
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/usbh.c b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/usbh.c
deleted file mode 100644
index 6363fd221..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/usb/usbh.c
+++ /dev/null
@@ -1,409 +0,0 @@
-/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2017-10-30 ZYH the first version
- * 2019-12-19 tyustli port to stm32 series
- */
-
-/**
-* @file usbh.c
-* @brief support stm32f407-st-discovery-board usb function
-* @version 1.0
-* @author AIIT XUOS Lab
-* @date 2021-04-25
-*/
-
-/*************************************************
-File name: usbh.c
-Description: support stm32f407-st-discovery-board usb configure
-Others: take RT-Thread v4.0.2/bsp/stm32/libraries/HAL_Drivers/drv_usbh.c for references
- https://github.com/RT-Thread/rt-thread/tree/v4.0.2
-History:
-1. Date: 2021-04-25
-Author: AIIT XUOS Lab
-Modification:
-1. support stm32f407-st-discovery-board usb irq configure
-2. support stm32f407-st-discovery-board usb host register
-*************************************************/
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include "usb_bsp.h"
-#include "usb_hcd.h"
-#include "usb_hcd_int.h"
-
-static USB_OTG_CORE_HANDLE USB_OTG_Core;
-static int UrbCompletionSem;
-
-void OTG_FS_IRQHandler(int irq_num, void *arg)
-{
- USBH_OTG_ISR_Handler(&USB_OTG_Core);
-}
-DECLARE_HW_IRQ(OTG_FS_IRQn, OTG_FS_IRQHandler, NONE);
-
-static uint8_t SOF_cb(USB_OTG_CORE_HANDLE *pdev)
-{
- return 0;
-}
-
-static uint8_t DevConnected_cb(USB_OTG_CORE_HANDLE *pdev)
-{
- UhcdPointer hcd = pdev->data;
-
- if (!pdev->host.ConnSts) {
- pdev->host.ConnSts = 1;
- UsbhRootHubConnectHandler(hcd, 1, RET_FALSE);
- }
-
- return 0;
-}
-
-static uint8_t DevDisconnected_cb(USB_OTG_CORE_HANDLE *pdev)
-{
- UhcdPointer hcd = pdev->data;
-
- if (pdev->host.ConnSts) {
- pdev->host.ConnSts = 0;
- UsbhRootHubDisconnectHandler(hcd, 1);
- }
-
- return 0;
-}
-
-static uint8_t URBChangeNotify_cb(USB_OTG_CORE_HANDLE *pdev)
-{
- KSemaphoreAbandon(UrbCompletionSem);
-
- return 0;
-}
-
-static uint8_t DevPortEnabled_cb(USB_OTG_CORE_HANDLE *pdev)
-{
- pdev->host.PortEnabled = 1;
-
- return 0;
-}
-
-static uint8_t DevPortDisabled_cb(USB_OTG_CORE_HANDLE *pdev)
-{
- pdev->host.PortEnabled = 0;
-
- return 0;
-}
-
-static USBH_HCD_INT_cb_TypeDef USBH_HCD_INT_cb = {
- .SOF = SOF_cb,
- .DevConnected = DevConnected_cb,
- .DevDisconnected = DevDisconnected_cb,
- .DevPortEnabled = DevPortEnabled_cb,
- .DevPortDisabled = DevPortDisabled_cb,
- .URBChangeNotify = URBChangeNotify_cb,
-};
-USBH_HCD_INT_cb_TypeDef *USBH_HCD_INT_fops = &USBH_HCD_INT_cb;
-
-static void STM32USBHostChannelOpen(USB_OTG_CORE_HANDLE *pdev, uint8_t hc_num, uint8_t epnum,
- uint8_t dev_address, uint8_t speed, uint8_t ep_type, uint16_t mps)
-{
- pdev->host.hc[hc_num].ep_num = epnum & 0x7F;
- pdev->host.hc[hc_num].ep_is_in = (epnum & 0x80 ) == 0x80;
- pdev->host.hc[hc_num].DevAddr = dev_address;
- pdev->host.hc[hc_num].ep_type = ep_type;
- pdev->host.hc[hc_num].max_packet = mps;
- pdev->host.hc[hc_num].speed = speed;
- pdev->host.hc[hc_num].toggle_in = 0;
- pdev->host.hc[hc_num].toggle_out = 0;
- if(speed == HPRT0_PRTSPD_HIGH_SPEED) {
- pdev->host.hc[hc_num].do_ping = 1;
- }
-
- USB_OTG_HC_Init(pdev, hc_num) ;
-}
-
-static x_err_t STM32USBHostResetPort(uint8 port)
-{
- SYS_KDEBUG_LOG(SYS_DEBUG_USB, ("reset port\n"));
- HCD_ResetPort(&USB_OTG_Core);
-
- return EOK;
-}
-
-x_err_t STM32USBHostChannelSubmitRequest(USB_OTG_CORE_HANDLE *hhcd,
- uint8_t ch_num,
- uint8_t direction,
- uint8_t ep_type,
- uint8_t token,
- uint8_t *pbuff,
- uint16_t length,
- uint8_t do_ping)
-{
- SYS_KDEBUG_LOG(SYS_DEBUG_USB,
- ("%s: ch_num: %d, direction: %d, ", __func__, ch_num, direction));
- hhcd->host.hc[ch_num].ep_is_in = direction;
- hhcd->host.hc[ch_num].ep_type = ep_type;
-
- if (token == 0U)
- hhcd->host.hc[ch_num].data_pid = HC_PID_SETUP;
- else
- hhcd->host.hc[ch_num].data_pid = HC_PID_DATA1;
-
- /* Manage Data Toggle */
- switch (ep_type) {
- case EP_TYPE_CTRL:
- SYS_KDEBUG_LOG(SYS_DEBUG_USB, ("EP_TYPE_CTRL\n"));
- if ((token == 1U) && (direction == 0U)) {
- if (length == 0U)
- hhcd->host.hc[ch_num].toggle_out = 1U;
-
- if (hhcd->host.hc[ch_num].toggle_out == 0U)
- hhcd->host.hc[ch_num].data_pid = HC_PID_DATA0;
- else
- hhcd->host.hc[ch_num].data_pid = HC_PID_DATA1;
- }
- break;
-
- case EP_TYPE_BULK:
- SYS_KDEBUG_LOG(SYS_DEBUG_USB, ("EP_TYPE_BULK\n"));
- if (direction == 0U) {
- if (hhcd->host.hc[ch_num].toggle_out == 0U)
- hhcd->host.hc[ch_num].data_pid = HC_PID_DATA0;
- else
- hhcd->host.hc[ch_num].data_pid = HC_PID_DATA1;
- } else {
- if (hhcd->host.hc[ch_num].toggle_in == 0U)
- hhcd->host.hc[ch_num].data_pid = HC_PID_DATA0;
- else
- hhcd->host.hc[ch_num].data_pid = HC_PID_DATA1;
- }
- break;
-
- case EP_TYPE_INTR:
- SYS_KDEBUG_LOG(SYS_DEBUG_USB, ("EP_TYPE_INTR\n"));
- if (direction == 0U) {
- if (hhcd->host.hc[ch_num].toggle_out == 0U)
- hhcd->host.hc[ch_num].data_pid = HC_PID_DATA0;
- else
- hhcd->host.hc[ch_num].data_pid = HC_PID_DATA1;
- } else {
- if (hhcd->host.hc[ch_num].toggle_in == 0U)
- hhcd->host.hc[ch_num].data_pid = HC_PID_DATA0;
- else
- hhcd->host.hc[ch_num].data_pid = HC_PID_DATA1;
- }
- break;
-
- case EP_TYPE_ISOC:
- SYS_KDEBUG_LOG(SYS_DEBUG_USB, ("EP_TYPE_ISOC\n"));
- hhcd->host.hc[ch_num].data_pid = HC_PID_DATA0;
- break;
-
- default:
- break;
- }
-
- hhcd->host.hc[ch_num].xfer_buff = pbuff;
- hhcd->host.hc[ch_num].XferLen = length;
- hhcd->host.HC_Status[ch_num] = HC_IDLE;
-
- return HCD_SubmitRequest(hhcd, ch_num);
-}
-
-static int STM32USBHostPipeXfer(upipe_t pipe, uint8 token, void *buffer, int nbytes, int timeouts)
-{
- int timeout = timeouts;
- int interval = 1;
- int retry = 0;
-
- while (1) {
- if (!USB_OTG_Core.host.ConnSts)
- return -1;
-
- // UrbCompletionSem = KSemaphoreCreate( 0);
- KSemaphoreSetValue(UrbCompletionSem, 0);
- STM32USBHostChannelSubmitRequest(
- &USB_OTG_Core,
- pipe->pipe_index,
- (pipe->ep.bEndpointAddress & 0x80) >> 7,
- pipe->ep.bmAttributes,
- token,
- buffer,
- nbytes,
- 0
- );
-
- MdelayKTask(interval);
- KSemaphoreObtain(UrbCompletionSem, timeout);
-
- if (HCD_GetHCState(&USB_OTG_Core, pipe->pipe_index) == HC_NAK) {
- SYS_KDEBUG_LOG(SYS_DEBUG_USB, ("nak\n"));
- if (pipe->ep.bmAttributes == USB_EP_ATTR_INT)
- DelayKTask((pipe->ep.bInterval * TICK_PER_SECOND / 1000) > 0 ? (pipe->ep.bInterval * TICK_PER_SECOND / 1000) : 1);
- if (interval < 10) {
- interval += 1;
- continue;
- }
- USB_OTG_HC_Halt(&USB_OTG_Core, pipe->pipe_index);
- STM32USBHostChannelOpen(
- &USB_OTG_Core,
- pipe->pipe_index,
- pipe->ep.bEndpointAddress,
- pipe->inst->address,
- USB_OTG_SPEED_FULL,
- pipe->ep.bmAttributes,
- pipe->ep.wMaxPacketSize
- );
- if (++retry >= 10) {
- SYS_KDEBUG_LOG(SYS_DEBUG_USB, ("NAK retry limit exceeded\n"));
- return -1;
- }
- continue;
- } else if (HCD_GetHCState(&USB_OTG_Core, pipe->pipe_index) == HC_STALL) {
- SYS_KDEBUG_LOG(SYS_DEBUG_USB, ("stall\n"));
- pipe->status = UPIPE_STATUS_STALL;
- if (pipe->callback != NONE)
- pipe->callback(pipe);
- return -1;
- } else if (HCD_GetHCState(&USB_OTG_Core, pipe->pipe_index) == URB_ERROR) {
- SYS_KDEBUG_LOG(SYS_DEBUG_USB, ("error\n"));
- pipe->status = UPIPE_STATUS_ERROR;
- if (pipe->callback != NONE)
- pipe->callback(pipe);
- return -1;
- } else if (URB_DONE == HCD_GetHCState(&USB_OTG_Core, pipe->pipe_index)) {
- SYS_KDEBUG_LOG(SYS_DEBUG_USB, ("ok\n"));
- pipe->status = UPIPE_STATUS_OK;
- if (pipe->callback != NONE)
- pipe->callback(pipe);
- // size_t size = HAL_HCD_HC_GetXferCount(&USB_OTG_Core, pipe->pipe_index);
- size_t size = USB_OTG_Core.host.XferCnt[pipe->pipe_index];
- if (pipe->ep.bEndpointAddress & 0x80)
- return size;
- else if (pipe->ep.bEndpointAddress & 0x00)
- return size;
- return nbytes;
- }
-
- continue;
- }
-}
-
-static uint16 pipe_bitmap;
-
-static uint8 STM32USBHostAllocPipe()
-{
- for (int i = 1; i < 16; i++)
- if ((pipe_bitmap & (1 << i)) == 0) {
- pipe_bitmap |= (1 << i);
- return i;
- }
-
- return 0xff;
-}
-
-static void STM32USBHostFreePipe(int i)
-{
- pipe_bitmap &= ~(1 << i);
-}
-
-static x_err_t STM32USBHostOpenPipe(upipe_t pipe)
-{
- pipe->pipe_index = STM32USBHostAllocPipe();
-
- STM32USBHostChannelOpen(&USB_OTG_Core, pipe->pipe_index, pipe->ep.bEndpointAddress,
- pipe->inst->address, USB_OTG_SPEED_FULL, pipe->ep.bmAttributes,
- pipe->ep.wMaxPacketSize);
-
- if (USB_OTG_Core.host.hc[pipe->pipe_index].ep_is_in)
- USB_OTG_Core.host.hc[pipe->pipe_index].toggle_in = 0;
- else
- USB_OTG_Core.host.hc[pipe->pipe_index].toggle_out = 0;
-
- return EOK;
-}
-
-static x_err_t STM32USBHostClosePipe(upipe_t pipe)
-{
- USB_OTG_HC_Halt(&USB_OTG_Core, pipe->pipe_index);
-
- STM32USBHostFreePipe(pipe->pipe_index);
-
- return EOK;
-}
-
-/* implement these */
-static struct uhcd_ops USBHostOps = {
- .reset_port = STM32USBHostResetPort,
- .pipe_xfer = STM32USBHostPipeXfer,
- .open_pipe = STM32USBHostOpenPipe,
- .close_pipe = STM32USBHostClosePipe
-};
-
-static x_err_t STM32USBHostInit()
-{
- KPrintf("\nINITIALIZING HOST......\n");
-
- USB_OTG_BSP_Init(&USB_OTG_Core);
-
- HCD_Init(&USB_OTG_Core, USB_OTG_FS_CORE_ID);
-
- // RegisterHwIrq(OTG_FS_IRQn, OTG_FS_IRQHandler, NONE);
- USB_OTG_BSP_ENABLE_INTERRUPT(&USB_OTG_Core);
-
- UrbCompletionSem = KSemaphoreCreate( 0);
-
- return EOK;
-}
-
-int STM32USBHostRegister()
-{
- UhcdPointer uhcd = (UhcdPointer)x_malloc(sizeof(struct uhcd));
-
- memset(uhcd, 0, sizeof(struct uhcd));
-
- uhcd->ops = &USBHostOps;
- uhcd->NumPorts = 1;
-
- USB_OTG_Core.data = uhcd;
-
- UsbHostInit(uhcd);
- STM32USBHostInit();
-
- return EOK;
-}
-
-long dump_usb_regs()
-{
- volatile uint32_t *p = (volatile uint32_t *)0x50000000;
-
- while ((uint32_t)p < 0x50000000 + 80 * 4) {
- KPrintf("0x%03X: 0x%08X\n", (uint32_t)p - 0x50000000, *p);
- p++;
- }
-
- return 0;
-}
-SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0),dump_usb_regs, dump_usb_regs, dump USB registers );
-
-long dump_hc_regs()
-{
- for (int i = 0; i < USB_OTG_MAX_TX_FIFOS; i++) {
- USB_OTG_HC_REGS *regs = USB_OTG_Core.regs.HC_REGS[i];
- KPrintf("EP No.%d:\n", i);
- KPrintf(" HCCHAR: 0x%08X\n", regs->HCCHAR);
- KPrintf(" HCSPLT: 0x%08X\n", regs->HCSPLT);
- KPrintf(" HCINT: 0x%08X\n", regs->HCINT);
- KPrintf(" HCINTMSK: 0x%08X\n", regs->HCINTMSK);
- KPrintf(" HCTSIZ: 0x%08X\n", regs->HCTSIZ);
- KPrintf(" HCDMA: 0x%08X\n", regs->HCDMA);
- }
-
- return 0;
-}
-SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0),dump_hc_regs, dump_hc_regs, dump_hc_regs );
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/watchdog/Kconfig b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/watchdog/Kconfig
deleted file mode 100644
index 59a44436a..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/watchdog/Kconfig
+++ /dev/null
@@ -1,14 +0,0 @@
-
-if BSP_USING_WDT
-config WDT_BUS_NAME
- string "watchdog bus name"
- default "wdt"
-
-config WDT_DRIVER_NAME
- string "watchdog driver name"
- default "wdt_drv"
-
-config WDT_DEVICE_NAME
- string "watchdog device name"
- default "wdt_dev"
-endif
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/watchdog/Makefile b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/watchdog/Makefile
deleted file mode 100644
index e141d6994..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/watchdog/Makefile
+++ /dev/null
@@ -1,5 +0,0 @@
-SRC_FILES := hardware_wdg.c connect_wdg.c
-
-
-
-include $(KERNEL_ROOT)/compiler.mk
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/watchdog/connect_wdg.c b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/watchdog/connect_wdg.c
deleted file mode 100644
index bbbad0fd5..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/watchdog/connect_wdg.c
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
-* Copyright (c) 2020 AIIT XUOS Lab
-* XiUOS is licensed under Mulan PSL v2.
-* You can use this software according to the terms and conditions of the Mulan PSL v2.
-* You may obtain a copy of Mulan PSL v2 at:
-* http://license.coscl.org.cn/MulanPSL2
-* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
-* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
-* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
-* See the Mulan PSL v2 for more details.
-*/
-
-/**
-* @file connect_wdt.c
-* @brief support stm32f407-st-discovery-board watchdog function and register to bus framework
-* @version 1.0
-* @author AIIT XUOS Lab
-* @date 2021-04-25
-*/
-
-#include
-#include "hardware_iwdg.h"
-#include "connect_wdg.h"
-
-/**
- * This function Watchdog configuration function
- *
- * @param arg Watchdog device Parameters
- *
- * @return EOK
- */
-static int WdgSet(uint16_t arg)
-{
- IWDG_Enable();
- IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);
- IWDG_SetPrescaler(IWDG_Prescaler_16);
- IWDG_SetReload(arg);
- while(IWDG_GetFlagStatus(IWDG_FLAG_RVU) != RESET);
- IWDG_ReloadCounter();
- return 0;
-}
-/**
- * This function Watchdog initialization
- *
- * @param dev Watchdog driver structure handle
- *
- * @return EOK
- */
-static uint32 WdtOpen(void *dev)
-{
- WdgSet(4000);
- return EOK;
-}
-/**
- * This function Watchdog control function
- *
- * @param drv Watchdog driver structure handle
- *
- * @param args Watchdog driver Parameters
- *
- * @return EOK
- */
-static uint32 WdtConfigure(void *drv, struct BusConfigureInfo *args)
-{
- switch (args->configure_cmd)
- {
- case OPER_WDT_SET_TIMEOUT:
- if (WdgSet((uint16_t)*(int *)args->private_data) != 0) {
- return ERROR;
- }
- break;
- case OPER_WDT_KEEPALIVE:
- IWDG_ReloadCounter();
- break;
- default:
- return ERROR;
- }
- return EOK;
-}
-
-static const struct WdtDevDone dev_done =
-{
- WdtOpen,
- NONE,
- NONE,
- NONE,
-};
-
-/**
- * This function Watchdog initialization
- *
- * @return EOK
- */
-int HwWdtInit(void)
-{
- x_err_t ret = EOK;
-
- static struct WdtBus wdt;
- static struct WdtDriver drv;
- static struct WdtHardwareDevice dev;
-
- ret = WdtBusInit(&wdt, WDT_BUS_NAME);
- if(ret != EOK){
- KPrintf("Watchdog bus init error %d\n", ret);
- return ERROR;
- }
-
- drv.configure = WdtConfigure;
- ret = WdtDriverInit(&drv, WDT_DRIVER_NAME);
- if (ret != EOK) {
- KPrintf("Watchdog driver init error %d\n", ret);
- return ERROR;
- }
- ret = WdtDriverAttachToBus(WDT_DRIVER_NAME, WDT_BUS_NAME);
- if (ret != EOK) {
- KPrintf("Watchdog driver attach error %d\n", ret);
- return ERROR;
- }
-
- dev.dev_done = &dev_done;
-
- ret = WdtDeviceRegister(&dev, WDT_DEVICE_NAME);
- if (ret != EOK) {
- KPrintf("Watchdog device register error %d\n", ret);
- return ERROR;
- }
- ret = WdtDeviceAttachToBus(WDT_DEVICE_NAME, WDT_BUS_NAME);
- if (ret != EOK) {
- KPrintf("Watchdog device register error %d\n", ret);
- return ERROR;
- }
-}
diff --git a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/watchdog/hardware_wdg.c b/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/watchdog/hardware_wdg.c
deleted file mode 100644
index f78ffb5b1..000000000
--- a/Ubiquitous/XiUOS/board/cortex-m4-emulator/third_party_driver/watchdog/hardware_wdg.c
+++ /dev/null
@@ -1,283 +0,0 @@
-/**
- ******************************************************************************
- * @file stm32f4xx_iwdg.c
- * @author MCD Application Team
- * @version V1.0.0
- * @date 30-September-2011
- * @brief This file provides firmware functions to manage the following
- * functionalities of the Independent watchdog (IWDG) peripheral:
- * - Prescaler and Counter configuration
- * - IWDG activation
- * - Flag management
- *
- * @verbatim
- *
- * ===================================================================
- * IWDG features
- * ===================================================================
- *
- * The IWDG can be started by either software or hardware (configurable
- * through option byte).
- *
- * The IWDG is clocked by its own dedicated low-speed clock (LSI) and
- * thus stays active even if the main clock fails.
- * Once the IWDG is started, the LSI is forced ON and cannot be disabled
- * (LSI cannot be disabled too), and the counter starts counting down from
- * the reset value of 0xFFF. When it reaches the end of count value (0x000)
- * a system reset is generated.
- * The IWDG counter should be reloaded at regular intervals to prevent
- * an MCU reset.
- *
- * The IWDG is implemented in the VDD voltage domain that is still functional
- * in STOP and STANDBY mode (IWDG reset can wake-up from STANDBY).
- *
- * IWDGRST flag in RCC_CSR register can be used to inform when a IWDG
- * reset occurs.
- *
- * Min-max timeout value @32KHz (LSI): ~125us / ~32.7s
- * The IWDG timeout may vary due to LSI frequency dispersion. STM32F4xx
- * devices provide the capability to measure the LSI frequency (LSI clock
- * connected internally to TIM5 CH4 input capture). The measured value
- * can be used to have an IWDG timeout with an acceptable accuracy.
- * For more information, please refer to the STM32F4xx Reference manual
- *
- *
- * ===================================================================
- * How to use this driver
- * ===================================================================
- * 1. Enable write access to IWDG_PR and IWDG_RLR registers using
- * IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable) function
- *
- * 2. Configure the IWDG prescaler using IWDG_SetPrescaler() function
- *
- * 3. Configure the IWDG counter value using IWDG_SetReload() function.
- * This value will be loaded in the IWDG counter each time the counter
- * is reloaded, then the IWDG will start counting down from this value.
- *
- * 4. Start the IWDG using IWDG_Enable() function, when the IWDG is used
- * in software mode (no need to enable the LSI, it will be enabled
- * by hardware)
- *
- * 5. Then the application program must reload the IWDG counter at regular
- * intervals during normal operation to prevent an MCU reset, using
- * IWDG_ReloadCounter() function.
- *
- * @endverbatim
- *
- ******************************************************************************
- * @attention
- *
- * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
- * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
- * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
- * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
- * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
- * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
- *
- * © COPYRIGHT 2011 STMicroelectronics
- ******************************************************************************
- */
-
-/**
-* @file: hardware_wdg.c
-* @brief: support hardware wdg function
-* @version: 1.0
-* @author: AIIT XUOS Lab
-* @date: 2021/4/25
-*/
-
-/*************************************************
-File name: hardware_wdg.c
-Description: support hardware wdg function
-Others:
-History:
-1. Date: 2021-04-25
-Author: AIIT XUOS Lab
-Modification:
-1. rename stm32f4xx_iwdg.c for XiUOS
-*************************************************/
-
-/* Includes ------------------------------------------------------------------*/
-#include
-#include
-
-/** @addtogroup STM32F4xx_StdPeriph_Driver
- * @{
- */
-
-/** @defgroup IWDG
- * @brief IWDG driver modules
- * @{
- */
-
-/* Private typedef -----------------------------------------------------------*/
-/* Private define ------------------------------------------------------------*/
-
-/* KR register bit mask */
-#define KR_KEY_RELOAD ((uint16_t)0xAAAA)
-#define KR_KEY_ENABLE ((uint16_t)0xCCCC)
-
-/* Private macro -------------------------------------------------------------*/
-/* Private variables ---------------------------------------------------------*/
-/* Private function prototypes -----------------------------------------------*/
-/* Private functions ---------------------------------------------------------*/
-
-/** @defgroup IWDG_Private_Functions
- * @{
- */
-
-/** @defgroup IWDG_Group1 Prescaler and Counter configuration functions
- * @brief Prescaler and Counter configuration functions
- *
-@verbatim
- ===============================================================================
- Prescaler and Counter configuration functions
- ===============================================================================
-
-@endverbatim
- * @{
- */
-
-/**
- * @brief Enables or disables write access to IWDG_PR and IWDG_RLR registers.
- * @param IWDG_WriteAccess: new state of write access to IWDG_PR and IWDG_RLR registers.
- * This parameter can be one of the following values:
- * @arg IWDG_WriteAccess_Enable: Enable write access to IWDG_PR and IWDG_RLR registers
- * @arg IWDG_WriteAccess_Disable: Disable write access to IWDG_PR and IWDG_RLR registers
- * @retval None
- */
-void IWDG_WriteAccessCmd(uint16_t IWDG_WriteAccess)
-{
- /* Check the parameters */
- assert_param(IS_IWDG_WRITE_ACCESS(IWDG_WriteAccess));
- IWDG->KR = IWDG_WriteAccess;
-}
-
-/**
- * @brief Sets IWDG Prescaler value.
- * @param IWDG_Prescaler: specifies the IWDG Prescaler value.
- * This parameter can be one of the following values:
- * @arg IWDG_Prescaler_4: IWDG prescaler set to 4
- * @arg IWDG_Prescaler_8: IWDG prescaler set to 8
- * @arg IWDG_Prescaler_16: IWDG prescaler set to 16
- * @arg IWDG_Prescaler_32: IWDG prescaler set to 32
- * @arg IWDG_Prescaler_64: IWDG prescaler set to 64
- * @arg IWDG_Prescaler_128: IWDG prescaler set to 128
- * @arg IWDG_Prescaler_256: IWDG prescaler set to 256
- * @retval None
- */
-void IWDG_SetPrescaler(uint8_t IWDG_Prescaler)
-{
- /* Check the parameters */
- assert_param(IS_IWDG_PRESCALER(IWDG_Prescaler));
- IWDG->PR = IWDG_Prescaler;
-}
-
-/**
- * @brief Sets IWDG Reload value.
- * @param Reload: specifies the IWDG Reload value.
- * This parameter must be a number between 0 and 0x0FFF.
- * @retval None
- */
-void IWDG_SetReload(uint16_t Reload)
-{
- /* Check the parameters */
- assert_param(IS_IWDG_RELOAD(Reload));
- IWDG->RLR = Reload;
-}
-
-/**
- * @brief Reloads IWDG counter with value defined in the reload register
- * (write access to IWDG_PR and IWDG_RLR registers disabled).
- * @param None
- * @retval None
- */
-void IWDG_ReloadCounter(void)
-{
- IWDG->KR = KR_KEY_RELOAD;
-}
-
-/**
- * @}
- */
-
-/** @defgroup IWDG_Group2 IWDG activation function
- * @brief IWDG activation function
- *
-@verbatim
- ===============================================================================
- IWDG activation function
- ===============================================================================
-
-@endverbatim
- * @{
- */
-
-/**
- * @brief Enables IWDG (write access to IWDG_PR and IWDG_RLR registers disabled).
- * @param None
- * @retval None
- */
-void IWDG_Enable(void)
-{
- IWDG->KR = KR_KEY_ENABLE;
-}
-
-/**
- * @}
- */
-
-/** @defgroup IWDG_Group3 Flag management function
- * @brief Flag management function
- *
-@verbatim
- ===============================================================================
- Flag management function
- ===============================================================================
-
-@endverbatim
- * @{
- */
-
-/**
- * @brief Checks whether the specified IWDG flag is set or not.
- * @param IWDG_FLAG: specifies the flag to check.
- * This parameter can be one of the following values:
- * @arg IWDG_FLAG_PVU: Prescaler Value Update on going
- * @arg IWDG_FLAG_RVU: Reload Value Update on going
- * @retval The new state of IWDG_FLAG (SET or RESET).
- */
-FlagStatus IWDG_GetFlagStatus(uint16_t IWDG_FLAG)
-{
- FlagStatus bitstatus = RESET;
- /* Check the parameters */
- assert_param(IS_IWDG_FLAG(IWDG_FLAG));
- if ((IWDG->SR & IWDG_FLAG) != (uint32_t)RESET)
- {
- bitstatus = SET;
- }
- else
- {
- bitstatus = RESET;
- }
- /* Return the flag status */
- return bitstatus;
-}
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-
-/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/