add ch579m bsp (#5600)

* add ch579m bsp

Author:    Tuber <tuber@xyza.cn>
Date:      Wed Feb 16 07:20:23 2022 +0000

* fix uart reg value error and format code

* change file encode to utf-8
This commit is contained in:
Tuber 2022-02-18 13:41:59 +08:00 committed by GitHub
parent 89bf823f7d
commit 5a61304a09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
60 changed files with 13234 additions and 0 deletions

715
bsp/wch/arm/ch579m/.config Normal file
View File

@ -0,0 +1,715 @@
#
# Automatically generated file; DO NOT EDIT.
# RT-Thread Configuration
#
#
# RT-Thread Kernel
#
CONFIG_RT_NAME_MAX=8
# CONFIG_RT_USING_ARCH_DATA_TYPE is not set
# CONFIG_RT_USING_SMP is not set
CONFIG_RT_ALIGN_SIZE=4
# CONFIG_RT_THREAD_PRIORITY_8 is not set
CONFIG_RT_THREAD_PRIORITY_32=y
# CONFIG_RT_THREAD_PRIORITY_256 is not set
CONFIG_RT_THREAD_PRIORITY_MAX=32
CONFIG_RT_TICK_PER_SECOND=1000
# CONFIG_RT_USING_OVERFLOW_CHECK is not set
# CONFIG_RT_USING_HOOK is not set
# CONFIG_RT_USING_IDLE_HOOK is not set
CONFIG_IDLE_THREAD_STACK_SIZE=256
# CONFIG_RT_USING_TIMER_SOFT is not set
#
# kservice optimization
#
# CONFIG_RT_KSERVICE_USING_STDLIB is not set
# CONFIG_RT_KSERVICE_USING_TINY_SIZE is not set
# CONFIG_RT_USING_TINY_FFS is not set
# CONFIG_RT_PRINTF_LONGLONG is not set
# CONFIG_RT_DEBUG is not set
#
# Inter-Thread communication
#
CONFIG_RT_USING_SEMAPHORE=y
CONFIG_RT_USING_MUTEX=y
# CONFIG_RT_USING_EVENT is not set
CONFIG_RT_USING_MAILBOX=y
CONFIG_RT_USING_MESSAGEQUEUE=y
# CONFIG_RT_USING_SIGNALS is not set
#
# Memory Management
#
# CONFIG_RT_USING_MEMPOOL is not set
CONFIG_RT_USING_SMALL_MEM=y
# CONFIG_RT_USING_SLAB is not set
# CONFIG_RT_USING_MEMHEAP is not set
CONFIG_RT_USING_SMALL_MEM_AS_HEAP=y
# CONFIG_RT_USING_MEMHEAP_AS_HEAP is not set
# CONFIG_RT_USING_SLAB_AS_HEAP is not set
# CONFIG_RT_USING_USERHEAP is not set
# CONFIG_RT_USING_NOHEAP is not set
# CONFIG_RT_USING_MEMTRACE is not set
# CONFIG_RT_USING_HEAP_ISR is not set
CONFIG_RT_USING_HEAP=y
#
# Kernel Device Object
#
CONFIG_RT_USING_DEVICE=y
# CONFIG_RT_USING_DEVICE_OPS is not set
# CONFIG_RT_USING_INTERRUPT_INFO is not set
CONFIG_RT_USING_CONSOLE=y
CONFIG_RT_CONSOLEBUF_SIZE=128
CONFIG_RT_CONSOLE_DEVICE_NAME="uart1"
CONFIG_RT_VER_NUM=0x40100
# CONFIG_RT_USING_CPU_FFS is not set
# CONFIG_ARCH_CPU_STACK_GROWS_UPWARD is not set
#
# RT-Thread Components
#
CONFIG_RT_USING_COMPONENTS_INIT=y
CONFIG_RT_USING_USER_MAIN=y
CONFIG_RT_MAIN_THREAD_STACK_SIZE=1024
CONFIG_RT_MAIN_THREAD_PRIORITY=10
# CONFIG_RT_USING_LEGACY is not set
#
# C++ features
#
# CONFIG_RT_USING_CPLUSPLUS is not set
#
# Command shell
#
CONFIG_RT_USING_FINSH=y
CONFIG_RT_USING_MSH=y
CONFIG_FINSH_USING_MSH=y
CONFIG_FINSH_THREAD_NAME="tshell"
CONFIG_FINSH_THREAD_PRIORITY=20
CONFIG_FINSH_THREAD_STACK_SIZE=2048
CONFIG_FINSH_USING_HISTORY=y
CONFIG_FINSH_HISTORY_LINES=5
CONFIG_FINSH_USING_SYMTAB=y
CONFIG_FINSH_CMD_SIZE=80
CONFIG_MSH_USING_BUILT_IN_COMMANDS=y
CONFIG_FINSH_USING_DESCRIPTION=y
# CONFIG_FINSH_ECHO_DISABLE_DEFAULT is not set
# CONFIG_FINSH_USING_AUTH is not set
CONFIG_FINSH_ARG_MAX=10
#
# Device virtual file system
#
# CONFIG_RT_USING_DFS is not set
#
# Device Drivers
#
CONFIG_RT_USING_DEVICE_IPC=y
# CONFIG_RT_USING_SYSTEM_WORKQUEUE is not set
CONFIG_RT_USING_SERIAL=y
CONFIG_RT_USING_SERIAL_V1=y
# CONFIG_RT_USING_SERIAL_V2 is not set
# CONFIG_RT_SERIAL_USING_DMA is not set
CONFIG_RT_SERIAL_RB_BUFSZ=64
# CONFIG_RT_USING_CAN is not set
# CONFIG_RT_USING_HWTIMER is not set
# CONFIG_RT_USING_CPUTIME is not set
# CONFIG_RT_USING_I2C is not set
# CONFIG_RT_USING_PHY is not set
# CONFIG_RT_USING_PIN is not set
# CONFIG_RT_USING_ADC is not set
# CONFIG_RT_USING_DAC is not set
# CONFIG_RT_USING_PWM is not set
# CONFIG_RT_USING_MTD_NOR is not set
# CONFIG_RT_USING_MTD_NAND is not set
# CONFIG_RT_USING_PM is not set
# CONFIG_RT_USING_RTC is not set
# CONFIG_RT_USING_SDIO is not set
# CONFIG_RT_USING_SPI is not set
# CONFIG_RT_USING_WDT is not set
# CONFIG_RT_USING_AUDIO is not set
# CONFIG_RT_USING_SENSOR is not set
# CONFIG_RT_USING_TOUCH is not set
# CONFIG_RT_USING_HWCRYPTO is not set
# CONFIG_RT_USING_PULSE_ENCODER is not set
# CONFIG_RT_USING_INPUT_CAPTURE is not set
# CONFIG_RT_USING_WIFI is not set
#
# Using USB
#
CONFIG_RT_USING_USB=y
CONFIG_RT_USING_USB_HOST=y
# CONFIG_RT_USBH_MSTORAGE is not set
# CONFIG_RT_USBH_HID is not set
# CONFIG_RT_USING_USB_DEVICE is not set
CONFIG_RT_USBD_THREAD_STACK_SZ=512
#
# POSIX layer and C standard library
#
CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8
#
# POSIX (Portable Operating System Interface) layer
#
# CONFIG_RT_USING_POSIX_FS is not set
# CONFIG_RT_USING_POSIX_DELAY is not set
# CONFIG_RT_USING_POSIX_CLOCK is not set
# CONFIG_RT_USING_POSIX_TIMER is not set
# CONFIG_RT_USING_PTHREADS is not set
# CONFIG_RT_USING_MODULE is not set
#
# Interprocess Communication (IPC)
#
# CONFIG_RT_USING_POSIX_PIPE is not set
# CONFIG_RT_USING_POSIX_MESSAGE_QUEUE is not set
# CONFIG_RT_USING_POSIX_MESSAGE_SEMAPHORE is not set
#
# Socket is in the 'Network' category
#
#
# Network
#
#
# Socket abstraction layer
#
# CONFIG_RT_USING_SAL is not set
#
# Network interface device
#
CONFIG_RT_USING_NETDEV=y
CONFIG_NETDEV_USING_IFCONFIG=y
CONFIG_NETDEV_USING_PING=y
# CONFIG_NETDEV_USING_NETSTAT is not set
# CONFIG_NETDEV_USING_AUTO_DEFAULT is not set
# CONFIG_NETDEV_USING_IPV6 is not set
CONFIG_NETDEV_IPV4=1
CONFIG_NETDEV_IPV6=0
# CONFIG_NETDEV_IPV6_SCOPES is not set
#
# light weight TCP/IP stack
#
CONFIG_RT_USING_LWIP=y
# CONFIG_RT_USING_LWIP141 is not set
# CONFIG_RT_USING_LWIP203 is not set
CONFIG_RT_USING_LWIP212=y
# CONFIG_RT_USING_LWIP_IPV6 is not set
CONFIG_RT_LWIP_MEM_ALIGNMENT=4
# CONFIG_RT_LWIP_IGMP is not set
CONFIG_RT_LWIP_ICMP=y
# CONFIG_RT_LWIP_SNMP is not set
CONFIG_RT_LWIP_DNS=y
# CONFIG_RT_LWIP_DHCP is not set
#
# Static IPv4 Address
#
CONFIG_RT_LWIP_IPADDR="19.111.115.250"
CONFIG_RT_LWIP_GWADDR="19.111.115.254"
CONFIG_RT_LWIP_MSKADDR="255.255.255.0"
CONFIG_RT_LWIP_UDP=y
CONFIG_RT_LWIP_TCP=y
CONFIG_RT_LWIP_RAW=y
# CONFIG_RT_LWIP_PPP is not set
CONFIG_RT_MEMP_NUM_NETCONN=4
CONFIG_RT_LWIP_PBUF_NUM=4
CONFIG_RT_LWIP_RAW_PCB_NUM=4
CONFIG_RT_LWIP_UDP_PCB_NUM=4
CONFIG_RT_LWIP_TCP_PCB_NUM=4
CONFIG_RT_LWIP_TCP_SEG_NUM=8
CONFIG_RT_LWIP_TCP_SND_BUF=3072
CONFIG_RT_LWIP_TCP_WND=3072
CONFIG_RT_LWIP_TCPTHREAD_PRIORITY=10
CONFIG_RT_LWIP_TCPTHREAD_MBOX_SIZE=4
CONFIG_RT_LWIP_TCPTHREAD_STACKSIZE=1024
# CONFIG_LWIP_NO_RX_THREAD is not set
CONFIG_LWIP_NO_TX_THREAD=y
CONFIG_RT_LWIP_ETHTHREAD_PRIORITY=12
CONFIG_RT_LWIP_ETHTHREAD_STACKSIZE=512
CONFIG_RT_LWIP_ETHTHREAD_MBOX_SIZE=4
# CONFIG_RT_LWIP_REASSEMBLY_FRAG is not set
CONFIG_LWIP_NETIF_STATUS_CALLBACK=0
CONFIG_LWIP_NETIF_LINK_CALLBACK=0
CONFIG_SO_REUSE=1
CONFIG_LWIP_SO_RCVTIMEO=1
CONFIG_LWIP_SO_SNDTIMEO=1
CONFIG_LWIP_SO_RCVBUF=1
CONFIG_LWIP_SO_LINGER=0
# CONFIG_RT_LWIP_NETIF_LOOPBACK is not set
CONFIG_LWIP_NETIF_LOOPBACK=0
# CONFIG_RT_LWIP_STATS is not set
# CONFIG_RT_LWIP_USING_HW_CHECKSUM is not set
CONFIG_RT_LWIP_USING_PING=y
# CONFIG_RT_LWIP_DEBUG is not set
#
# AT commands
#
# CONFIG_RT_USING_AT is not set
# CONFIG_LWIP_USING_DHCPD is not set
#
# VBUS(Virtual Software BUS)
#
# CONFIG_RT_USING_VBUS is not set
#
# Utilities
#
# CONFIG_RT_USING_RYM is not set
# CONFIG_RT_USING_ULOG is not set
# CONFIG_RT_USING_UTEST is not set
# CONFIG_RT_USING_VAR_EXPORT is not set
# CONFIG_RT_USING_RT_LINK is not set
#
# RT-Thread Utestcases
#
# CONFIG_RT_USING_UTESTCASES is not set
#
# RT-Thread online packages
#
#
# IoT - internet of things
#
# CONFIG_PKG_USING_LORAWAN_DRIVER is not set
# CONFIG_PKG_USING_PAHOMQTT is not set
# CONFIG_PKG_USING_UMQTT is not set
# CONFIG_PKG_USING_WEBCLIENT is not set
# CONFIG_PKG_USING_WEBNET is not set
# CONFIG_PKG_USING_MONGOOSE is not set
# CONFIG_PKG_USING_MYMQTT is not set
# CONFIG_PKG_USING_KAWAII_MQTT is not set
# CONFIG_PKG_USING_BC28_MQTT is not set
# CONFIG_PKG_USING_WEBTERMINAL is not set
# CONFIG_PKG_USING_CJSON is not set
# CONFIG_PKG_USING_JSMN is not set
# CONFIG_PKG_USING_LIBMODBUS is not set
# CONFIG_PKG_USING_FREEMODBUS is not set
# CONFIG_PKG_USING_LJSON is not set
# CONFIG_PKG_USING_EZXML is not set
# CONFIG_PKG_USING_NANOPB is not set
#
# Wi-Fi
#
#
# Marvell WiFi
#
# CONFIG_PKG_USING_WLANMARVELL is not set
#
# Wiced WiFi
#
# CONFIG_PKG_USING_WLAN_WICED is not set
# CONFIG_PKG_USING_RW007 is not set
# CONFIG_PKG_USING_COAP is not set
# CONFIG_PKG_USING_NOPOLL is not set
# CONFIG_PKG_USING_NETUTILS is not set
# CONFIG_PKG_USING_CMUX is not set
# CONFIG_PKG_USING_PPP_DEVICE is not set
# CONFIG_PKG_USING_AT_DEVICE is not set
# CONFIG_PKG_USING_ATSRV_SOCKET is not set
# CONFIG_PKG_USING_WIZNET is not set
# CONFIG_PKG_USING_ZB_COORDINATOR is not set
#
# IoT Cloud
#
# CONFIG_PKG_USING_ONENET is not set
# CONFIG_PKG_USING_GAGENT_CLOUD is not set
# CONFIG_PKG_USING_ALI_IOTKIT is not set
# CONFIG_PKG_USING_AZURE is not set
# CONFIG_PKG_USING_TENCENT_IOT_EXPLORER is not set
# CONFIG_PKG_USING_JIOT-C-SDK is not set
# CONFIG_PKG_USING_UCLOUD_IOT_SDK is not set
# CONFIG_PKG_USING_JOYLINK is not set
# CONFIG_PKG_USING_EZ_IOT_OS is not set
# CONFIG_PKG_USING_NIMBLE is not set
# CONFIG_PKG_USING_LLSYNC_SDK_ADAPTER is not set
# CONFIG_PKG_USING_OTA_DOWNLOADER is not set
# CONFIG_PKG_USING_IPMSG is not set
# CONFIG_PKG_USING_LSSDP is not set
# CONFIG_PKG_USING_AIRKISS_OPEN is not set
# CONFIG_PKG_USING_LIBRWS is not set
# CONFIG_PKG_USING_TCPSERVER is not set
# CONFIG_PKG_USING_PROTOBUF_C is not set
# CONFIG_PKG_USING_DLT645 is not set
# CONFIG_PKG_USING_QXWZ is not set
# CONFIG_PKG_USING_SMTP_CLIENT is not set
# CONFIG_PKG_USING_ABUP_FOTA is not set
# CONFIG_PKG_USING_LIBCURL2RTT is not set
# CONFIG_PKG_USING_CAPNP is not set
# CONFIG_PKG_USING_RT_CJSON_TOOLS is not set
# CONFIG_PKG_USING_AGILE_TELNET is not set
# CONFIG_PKG_USING_NMEALIB is not set
# CONFIG_PKG_USING_AGILE_JSMN is not set
# CONFIG_PKG_USING_PDULIB is not set
# CONFIG_PKG_USING_BTSTACK is not set
# CONFIG_PKG_USING_LORAWAN_ED_STACK is not set
# CONFIG_PKG_USING_WAYZ_IOTKIT is not set
# CONFIG_PKG_USING_MAVLINK is not set
# CONFIG_PKG_USING_RAPIDJSON is not set
# CONFIG_PKG_USING_BSAL is not set
# CONFIG_PKG_USING_AGILE_MODBUS is not set
# CONFIG_PKG_USING_AGILE_FTP is not set
# CONFIG_PKG_USING_EMBEDDEDPROTO is not set
# CONFIG_PKG_USING_RT_LINK_HW is not set
# CONFIG_PKG_USING_LORA_PKT_FWD is not set
# CONFIG_PKG_USING_LORA_GW_DRIVER_LIB is not set
# CONFIG_PKG_USING_LORA_PKT_SNIFFER is not set
# CONFIG_PKG_USING_HM is not set
# CONFIG_PKG_USING_SMALL_MODBUS is not set
# CONFIG_PKG_USING_NET_SERVER is not set
#
# security packages
#
# CONFIG_PKG_USING_MBEDTLS is not set
# CONFIG_PKG_USING_LIBSODIUM is not set
# CONFIG_PKG_USING_TINYCRYPT is not set
# CONFIG_PKG_USING_TFM is not set
# CONFIG_PKG_USING_YD_CRYPTO is not set
#
# language packages
#
# CONFIG_PKG_USING_LUATOS_SOC is not set
# CONFIG_PKG_USING_LUA is not set
# CONFIG_PKG_USING_JERRYSCRIPT is not set
# CONFIG_PKG_USING_MICROPYTHON is not set
# CONFIG_PKG_USING_PIKASCRIPT is not set
#
# multimedia packages
#
#
# LVGL: powerful and easy-to-use embedded GUI library
#
# CONFIG_PKG_USING_LVGL is not set
# CONFIG_PKG_USING_LITTLEVGL2RTT is not set
# CONFIG_PKG_USING_LV_MUSIC_DEMO is not set
#
# u8g2: a monochrome graphic library
#
# CONFIG_PKG_USING_U8G2_OFFICIAL is not set
# CONFIG_PKG_USING_U8G2 is not set
# CONFIG_PKG_USING_OPENMV is not set
# CONFIG_PKG_USING_MUPDF is not set
# CONFIG_PKG_USING_STEMWIN is not set
# CONFIG_PKG_USING_WAVPLAYER is not set
# CONFIG_PKG_USING_TJPGD is not set
# CONFIG_PKG_USING_PDFGEN is not set
# CONFIG_PKG_USING_HELIX is not set
# CONFIG_PKG_USING_AZUREGUIX is not set
# CONFIG_PKG_USING_TOUCHGFX2RTT is not set
# CONFIG_PKG_USING_NUEMWIN is not set
# CONFIG_PKG_USING_MP3PLAYER is not set
# CONFIG_PKG_USING_TINYJPEG is not set
# CONFIG_PKG_USING_UGUI is not set
#
# PainterEngine: A cross-platform graphics application framework written in C language
#
# CONFIG_PKG_USING_PAINTERENGINE is not set
# CONFIG_PKG_USING_PAINTERENGINE_AUX is not set
# CONFIG_PKG_USING_MCURSES is not set
# CONFIG_PKG_USING_TERMBOX is not set
# CONFIG_PKG_USING_VT100 is not set
# CONFIG_PKG_USING_QRCODE is not set
#
# tools packages
#
# CONFIG_PKG_USING_CMBACKTRACE is not set
# CONFIG_PKG_USING_EASYFLASH is not set
# CONFIG_PKG_USING_EASYLOGGER is not set
# CONFIG_PKG_USING_SYSTEMVIEW is not set
# CONFIG_PKG_USING_SEGGER_RTT is not set
# CONFIG_PKG_USING_RDB is not set
# CONFIG_PKG_USING_ULOG_EASYFLASH is not set
# CONFIG_PKG_USING_ULOG_FILE is not set
# CONFIG_PKG_USING_LOGMGR is not set
# CONFIG_PKG_USING_ADBD is not set
# CONFIG_PKG_USING_COREMARK is not set
# CONFIG_PKG_USING_DHRYSTONE is not set
# CONFIG_PKG_USING_MEMORYPERF is not set
# CONFIG_PKG_USING_NR_MICRO_SHELL is not set
# CONFIG_PKG_USING_CHINESE_FONT_LIBRARY is not set
# CONFIG_PKG_USING_LUNAR_CALENDAR is not set
# CONFIG_PKG_USING_BS8116A is not set
# CONFIG_PKG_USING_GPS_RMC is not set
# CONFIG_PKG_USING_URLENCODE is not set
# CONFIG_PKG_USING_UMCN is not set
# CONFIG_PKG_USING_LWRB2RTT is not set
# CONFIG_PKG_USING_CPU_USAGE is not set
# CONFIG_PKG_USING_GBK2UTF8 is not set
# CONFIG_PKG_USING_VCONSOLE is not set
# CONFIG_PKG_USING_KDB is not set
# CONFIG_PKG_USING_WAMR is not set
# CONFIG_PKG_USING_MICRO_XRCE_DDS_CLIENT is not set
# CONFIG_PKG_USING_LWLOG is not set
# CONFIG_PKG_USING_ANV_TRACE is not set
# CONFIG_PKG_USING_ANV_MEMLEAK is not set
# CONFIG_PKG_USING_ANV_TESTSUIT is not set
# CONFIG_PKG_USING_ANV_BENCH is not set
# CONFIG_PKG_USING_DEVMEM is not set
# CONFIG_PKG_USING_REGEX is not set
# CONFIG_PKG_USING_MEM_SANDBOX is not set
# CONFIG_PKG_USING_SOLAR_TERMS is not set
# CONFIG_PKG_USING_GAN_ZHI is not set
# CONFIG_PKG_USING_FDT is not set
#
# system packages
#
#
# enhanced kernel services
#
# CONFIG_PKG_USING_RT_MEMCPY_CM is not set
# CONFIG_PKG_USING_RT_KPRINTF_THREADSAFE is not set
# CONFIG_PKG_USING_RT_VSNPRINTF_FULL is not set
#
# POSIX extension functions
#
# CONFIG_PKG_USING_POSIX_GETLINE is not set
# CONFIG_PKG_USING_POSIX_WCWIDTH is not set
# CONFIG_PKG_USING_POSIX_ITOA is not set
# CONFIG_PKG_USING_POSIX_STRINGS is not set
#
# acceleration: Assembly language or algorithmic acceleration packages
#
# CONFIG_PKG_USING_QFPLIB_M0_FULL is not set
# CONFIG_PKG_USING_QFPLIB_M0_TINY is not set
# CONFIG_PKG_USING_QFPLIB_M3 is not set
#
# CMSIS: ARM Cortex-M Microcontroller Software Interface Standard
#
# CONFIG_PKG_USING_CMSIS_5 is not set
# CONFIG_PKG_USING_CMSIS_RTOS2 is not set
#
# Micrium: Micrium software products porting for RT-Thread
#
# CONFIG_PKG_USING_UCOSIII_WRAPPER is not set
# CONFIG_PKG_USING_UCOSII_WRAPPER is not set
# CONFIG_PKG_USING_UC_CRC is not set
# CONFIG_PKG_USING_UC_CLK is not set
# CONFIG_PKG_USING_UC_COMMON is not set
# CONFIG_PKG_USING_UC_MODBUS is not set
# CONFIG_RT_USING_ARDUINO is not set
# CONFIG_PKG_USING_GUIENGINE is not set
# CONFIG_PKG_USING_CAIRO is not set
# CONFIG_PKG_USING_PIXMAN is not set
# CONFIG_PKG_USING_PARTITION is not set
# CONFIG_PKG_USING_FAL is not set
# CONFIG_PKG_USING_FLASHDB is not set
# CONFIG_PKG_USING_SQLITE is not set
# CONFIG_PKG_USING_RTI is not set
# CONFIG_PKG_USING_DFS_YAFFS is not set
# CONFIG_PKG_USING_LITTLEFS is not set
# CONFIG_PKG_USING_DFS_JFFS2 is not set
# CONFIG_PKG_USING_DFS_UFFS is not set
# CONFIG_PKG_USING_LWEXT4 is not set
# CONFIG_PKG_USING_THREAD_POOL is not set
# CONFIG_PKG_USING_ROBOTS is not set
# CONFIG_PKG_USING_EV is not set
# CONFIG_PKG_USING_SYSWATCH is not set
# CONFIG_PKG_USING_SYS_LOAD_MONITOR is not set
# CONFIG_PKG_USING_PLCCORE is not set
# CONFIG_PKG_USING_RAMDISK is not set
# CONFIG_PKG_USING_MININI is not set
# CONFIG_PKG_USING_QBOOT is not set
# CONFIG_PKG_USING_PPOOL is not set
# CONFIG_PKG_USING_OPENAMP is not set
# CONFIG_PKG_USING_LPM is not set
# CONFIG_PKG_USING_TLSF is not set
# CONFIG_PKG_USING_EVENT_RECORDER is not set
# CONFIG_PKG_USING_ARM_2D is not set
# CONFIG_PKG_USING_MCUBOOT is not set
# CONFIG_PKG_USING_TINYUSB is not set
# CONFIG_PKG_USING_CHERRYUSB is not set
#
# peripheral libraries and drivers
#
# CONFIG_PKG_USING_SENSORS_DRIVERS is not set
# CONFIG_PKG_USING_REALTEK_AMEBA is not set
# CONFIG_PKG_USING_SHT2X is not set
# CONFIG_PKG_USING_SHT3X is not set
# CONFIG_PKG_USING_AS7341 is not set
# CONFIG_PKG_USING_STM32_SDIO is not set
# CONFIG_PKG_USING_ICM20608 is not set
# CONFIG_PKG_USING_BUTTON is not set
# CONFIG_PKG_USING_PCF8574 is not set
# CONFIG_PKG_USING_SX12XX is not set
# CONFIG_PKG_USING_SIGNAL_LED is not set
# CONFIG_PKG_USING_LEDBLINK is not set
# CONFIG_PKG_USING_LITTLED is not set
# CONFIG_PKG_USING_LKDGUI is not set
# CONFIG_PKG_USING_NRF5X_SDK is not set
# CONFIG_PKG_USING_NRFX is not set
# CONFIG_PKG_USING_WM_LIBRARIES is not set
# CONFIG_PKG_USING_KENDRYTE_SDK is not set
# CONFIG_PKG_USING_INFRARED is not set
# CONFIG_PKG_USING_AGILE_BUTTON is not set
# CONFIG_PKG_USING_AGILE_LED is not set
# CONFIG_PKG_USING_AT24CXX is not set
# CONFIG_PKG_USING_MOTIONDRIVER2RTT is not set
# CONFIG_PKG_USING_AD7746 is not set
# CONFIG_PKG_USING_PCA9685 is not set
# CONFIG_PKG_USING_I2C_TOOLS is not set
# CONFIG_PKG_USING_NRF24L01 is not set
# CONFIG_PKG_USING_TOUCH_DRIVERS is not set
# CONFIG_PKG_USING_MAX17048 is not set
# CONFIG_PKG_USING_RPLIDAR is not set
# CONFIG_PKG_USING_AS608 is not set
# CONFIG_PKG_USING_RC522 is not set
# CONFIG_PKG_USING_WS2812B is not set
# CONFIG_PKG_USING_EMBARC_BSP is not set
# CONFIG_PKG_USING_EXTERN_RTC_DRIVERS is not set
# CONFIG_PKG_USING_MULTI_RTIMER is not set
# CONFIG_PKG_USING_MAX7219 is not set
# CONFIG_PKG_USING_BEEP is not set
# CONFIG_PKG_USING_EASYBLINK is not set
# CONFIG_PKG_USING_PMS_SERIES is not set
# CONFIG_PKG_USING_CAN_YMODEM is not set
# CONFIG_PKG_USING_LORA_RADIO_DRIVER is not set
# CONFIG_PKG_USING_QLED is not set
# CONFIG_PKG_USING_PAJ7620 is not set
# CONFIG_PKG_USING_AGILE_CONSOLE is not set
# CONFIG_PKG_USING_LD3320 is not set
# CONFIG_PKG_USING_WK2124 is not set
# CONFIG_PKG_USING_LY68L6400 is not set
# CONFIG_PKG_USING_DM9051 is not set
# CONFIG_PKG_USING_SSD1306 is not set
# CONFIG_PKG_USING_QKEY is not set
# CONFIG_PKG_USING_RS485 is not set
# CONFIG_PKG_USING_RS232 is not set
# CONFIG_PKG_USING_NES is not set
# CONFIG_PKG_USING_VIRTUAL_SENSOR is not set
# CONFIG_PKG_USING_VDEVICE is not set
# CONFIG_PKG_USING_SGM706 is not set
# CONFIG_PKG_USING_STM32WB55_SDK is not set
# CONFIG_PKG_USING_RDA58XX is not set
# CONFIG_PKG_USING_LIBNFC is not set
# CONFIG_PKG_USING_MFOC is not set
# CONFIG_PKG_USING_TMC51XX is not set
# CONFIG_PKG_USING_TCA9534 is not set
# CONFIG_PKG_USING_KOBUKI is not set
# CONFIG_PKG_USING_ROSSERIAL is not set
# CONFIG_PKG_USING_MICRO_ROS is not set
# CONFIG_PKG_USING_MCP23008 is not set
# CONFIG_PKG_USING_BLUETRUM_SDK is not set
# CONFIG_PKG_USING_MISAKA_AT24CXX is not set
# CONFIG_PKG_USING_MISAKA_RGB_BLING is not set
# CONFIG_PKG_USING_LORA_MODEM_DRIVER is not set
# CONFIG_PKG_USING_BL_MCU_SDK is not set
# CONFIG_PKG_USING_SOFT_SERIAL is not set
# CONFIG_PKG_USING_MB85RS16 is not set
# CONFIG_PKG_USING_CW2015 is not set
#
# AI packages
#
# CONFIG_PKG_USING_LIBANN is not set
# CONFIG_PKG_USING_NNOM is not set
# CONFIG_PKG_USING_ONNX_BACKEND is not set
# CONFIG_PKG_USING_ONNX_PARSER is not set
# CONFIG_PKG_USING_TENSORFLOWLITEMICRO is not set
# CONFIG_PKG_USING_ELAPACK is not set
# CONFIG_PKG_USING_ULAPACK is not set
# CONFIG_PKG_USING_QUEST is not set
# CONFIG_PKG_USING_NAXOS is not set
#
# miscellaneous packages
#
#
# samples: kernel and components samples
#
# CONFIG_PKG_USING_KERNEL_SAMPLES is not set
# CONFIG_PKG_USING_FILESYSTEM_SAMPLES is not set
# CONFIG_PKG_USING_NETWORK_SAMPLES is not set
# CONFIG_PKG_USING_PERIPHERAL_SAMPLES is not set
#
# entertainment: terminal games and other interesting software packages
#
# CONFIG_PKG_USING_CMATRIX is not set
# CONFIG_PKG_USING_SL is not set
# CONFIG_PKG_USING_CAL is not set
# CONFIG_PKG_USING_ACLOCK is not set
# CONFIG_PKG_USING_THREES is not set
# CONFIG_PKG_USING_2048 is not set
# CONFIG_PKG_USING_SNAKE is not set
# CONFIG_PKG_USING_TETRIS is not set
# CONFIG_PKG_USING_DONUT is not set
# CONFIG_PKG_USING_COWSAY is not set
# CONFIG_PKG_USING_LIBCSV is not set
# CONFIG_PKG_USING_OPTPARSE is not set
# CONFIG_PKG_USING_FASTLZ is not set
# CONFIG_PKG_USING_MINILZO is not set
# CONFIG_PKG_USING_QUICKLZ is not set
# CONFIG_PKG_USING_LZMA is not set
# CONFIG_PKG_USING_MULTIBUTTON is not set
# CONFIG_PKG_USING_FLEXIBLE_BUTTON is not set
# CONFIG_PKG_USING_CANFESTIVAL is not set
# CONFIG_PKG_USING_ZLIB is not set
# CONFIG_PKG_USING_MINIZIP is not set
# CONFIG_PKG_USING_DSTR is not set
# CONFIG_PKG_USING_TINYFRAME is not set
# CONFIG_PKG_USING_KENDRYTE_DEMO is not set
# CONFIG_PKG_USING_DIGITALCTRL is not set
# CONFIG_PKG_USING_UPACKER is not set
# CONFIG_PKG_USING_UPARAM is not set
# CONFIG_PKG_USING_HELLO is not set
# CONFIG_PKG_USING_VI is not set
# CONFIG_PKG_USING_KI is not set
# CONFIG_PKG_USING_ARMv7M_DWT is not set
# CONFIG_PKG_USING_UKAL is not set
# CONFIG_PKG_USING_CRCLIB is not set
# CONFIG_PKG_USING_LWGPS is not set
# CONFIG_PKG_USING_STATE_MACHINE is not set
# CONFIG_PKG_USING_DESIGN_PATTERN is not set
# CONFIG_PKG_USING_CONTROLLER is not set
# CONFIG_PKG_USING_PHASE_LOCKED_LOOP is not set
#
# Hardware Drivers Config
#
CONFIG_SOC_CH579M=y
#
# On-chip Peripheral Drivers
#
CONFIG_BSP_USING_UART=y
# CONFIG_BSP_USING_UART0 is not set
CONFIG_BSP_USING_UART1=y
# CONFIG_BSP_USING_UART2 is not set
# CONFIG_BSP_USING_UART3 is not set
CONFIG_BSP_USING_USBH=y
CONFIG_BSP_USING_ETH=y

View File

@ -0,0 +1,20 @@
mainmenu "RT-Thread Configuration"
config BSP_DIR
string
option env="BSP_ROOT"
default "."
config RTT_DIR
string
option env="RTT_ROOT"
default "../../../.."
config PKGS_DIR
string
option env="PKGS_ROOT"
default "packages"
source "$RTT_DIR/Kconfig"
source "$PKGS_DIR/Kconfig"
source "board/Kconfig"

View File

@ -0,0 +1,15 @@
# for module compiling
import os
Import('RTT_ROOT')
from building import *
cwd = GetCurrentDir()
objs = []
list = os.listdir(cwd)
for d in list:
path = os.path.join(cwd, d)
if os.path.isfile(os.path.join(path, 'SConscript')):
objs = objs + SConscript(os.path.join(d, 'SConscript'))
Return('objs')

View File

@ -0,0 +1,41 @@
import os
import sys
import rtconfig
if os.getenv('RTT_ROOT'):
RTT_ROOT = os.getenv('RTT_ROOT')
else:
RTT_ROOT = os.path.normpath(os.getcwd() + '/../../../..')
sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
try:
from building import *
except:
print('Cannot found RT-Thread root directory, please check RTT_ROOT')
print(RTT_ROOT)
exit(-1)
TARGET = 'rtthread.' + rtconfig.TARGET_EXT
DefaultEnvironment(tools=[])
env = Environment(tools = ['mingw'],
AS = rtconfig.AS, ASFLAGS = rtconfig.AFLAGS,
CC = rtconfig.CC, CCFLAGS = rtconfig.CFLAGS,
AR = rtconfig.AR, ARFLAGS = '-rc',
LINK = rtconfig.LINK, LINKFLAGS = rtconfig.LFLAGS)
env.PrependENVPath('PATH', rtconfig.EXEC_PATH)
if rtconfig.PLATFORM == 'iar':
env.Replace(CCCOM = ['$CC $CCFLAGS $CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS -o $TARGET $SOURCES'])
env.Replace(ARFLAGS = [''])
env.Replace(LINKCOM = env["LINKCOM"] + ' --map project.map')
Export('RTT_ROOT')
Export('rtconfig')
# prepare building environment
objs = PrepareBuilding(env, RTT_ROOT, has_libcpu=False)
# make a building
DoBuilding(TARGET, objs)

View File

@ -0,0 +1,17 @@
# RT-Thread building script for component
Import('RTT_ROOT')
Import('rtconfig')
from building import *
cwd = GetCurrentDir()
# add the general drivers.
src = Split("""
main.c
""")
CPPPATH = [cwd, str(Dir('#'))]
group = DefineGroup('Applications', src, depend = [''], CPPPATH = CPPPATH)
Return('group')

View File

@ -0,0 +1,18 @@
/*
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2018-11-06 SummerGift change to new framework
*/
#include <rtthread.h>
#include <rtdevice.h>
#include <board.h>
int main(void)
{
return RT_EOK;
}

View File

@ -0,0 +1,45 @@
menu "Hardware Drivers Config"
config SOC_CH579M
bool
select RT_USING_USER_MAIN
select RT_USING_COMPONENTS_INIT
default y
menu "On-chip Peripheral Drivers"
menuconfig BSP_USING_UART
bool "Enable UART"
default y
select RT_USING_SERIAL
if BSP_USING_UART
config BSP_USING_UART0
bool "Enable UART0"
default n
config BSP_USING_UART1
bool "Enable UART1"
default y
config BSP_USING_UART2
bool "Enable UART2"
default n
config BSP_USING_UART3
bool "Enable UART3"
default n
endif
config BSP_USING_USBH
bool "Enable USBH"
default n
select RT_USING_USB_HOST
config BSP_USING_ETH
bool "Enable ETH"
default n
select RT_USING_LWIP
endmenu
endmenu

View File

@ -0,0 +1,11 @@
Import('RTT_ROOT')
Import('rtconfig')
from building import *
cwd = GetCurrentDir()
src = Glob('*.c')
CPPPATH = [cwd]
group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH)
Return('group')

View File

@ -0,0 +1,67 @@
/*
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2022-02-16 Tuber first version
*/
#include <rtthread.h>
#include <rtdevice.h>
#include <rthw.h>
#include "board.h"
#ifdef RT_USING_SERIAL
#include "drv_uart.h"
#endif
#ifdef RT_USING_FINSH
#include <finsh.h>
static void reboot(uint8_t argc, char **argv)
{
rt_hw_cpu_reset();
}
MSH_CMD_EXPORT(reboot, Reboot System)
#endif /* RT_USING_FINSH */
void SysTick_Handler(void)
{
/* enter interrupt */
rt_interrupt_enter();
rt_tick_increase();
/* leave interrupt */
rt_interrupt_leave();
}
void rt_hw_board_init()
{
// 打开PLL
PWR_UnitModCfg(ENABLE, UNIT_SYS_PLL);
// 设置外部40M做主频
SetSysClock(CLK_SOURCE_PLL_40MHz);
SysTick_Config(GetSysClock() / RT_TICK_PER_SECOND);
//开启中断
NVIC_SetPriority(SysTick_IRQn, 0);
NVIC_EnableIRQ(SysTick_IRQn);
#if defined(RT_USING_HEAP)
rt_system_heap_init((void *)HEAP_BEGIN, (void *)HEAP_END);
#endif
#ifdef RT_USING_SERIAL
rt_hw_uart_init();
#endif
#ifdef RT_USING_CONSOLE
rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
#endif
#ifdef RT_USING_COMPONENTS_INIT
rt_components_board_init();
#endif
}

View File

@ -0,0 +1,37 @@
/*
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2022-02-16 Tuber first version
*/
#ifndef __BOARD_H__
#define __BOARD_H__
#include "CH57x_common.h"
#define CH579M_FLASH_START_ADRESS ((uint32_t)0x00000000)
#define FLASH_PAGE_SIZE (64)
#define CH579M_FLASH_SIZE (512 * 1024)
#define CH579M_FLASH_END_ADDRESS ((uint32_t)(CH579M_FLASH_START_ADRESS + CH579M_FLASH_SIZE))
#define CH579M_SRAM_SIZE 32
#define CH579M_SRAM_END (0x20000000 + CH579M_SRAM_SIZE * 1024)
#if defined(__CC_ARM) || defined(__CLANG_ARM)
extern int Image$$RW_IRAM1$$ZI$$Limit;
#define HEAP_BEGIN ((void *)&Image$$RW_IRAM1$$ZI$$Limit)
#elif __ICCARM__
#pragma section="CSTACK"
#define HEAP_BEGIN (__segment_end("CSTACK"))
#else
extern int __bss_end;
#define HEAP_BEGIN ((void *)&__bss_end)
#endif
#define HEAP_END CH579M_SRAM_END
#endif /* __BOARD_H__ */

View File

@ -0,0 +1,261 @@
/*
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2022-02-16 Tuber first version
*/
#include <rtthread.h>
#include <rtdevice.h>
#include "board.h"
#include <netif/ethernetif.h>
#include "drv_eth.h"
#ifdef BSP_USING_ETH
static struct eth_device eth_device;
//DMA接收内存区必须4字节对齐
__align(4) UINT8 eth_dma_tx_buf[ETH_BUF_SIZE];
__align(4) UINT8 eth_dma_rx_buf[ETH_BUF_SIZE];
UINT16 eth_rx_len = 0; //接收状态和长度
UINT8 eth_rx_buf[ETH_BUF_SIZE]; //中间缓冲区
UINT8 eth_mac_addr[] = { 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF };
static rt_err_t eth_init(rt_device_t dev)
{
return RT_EOK;
}
static rt_err_t eth_open(rt_device_t dev, rt_uint16_t oflag)
{
return RT_EOK;
}
static rt_err_t eth_close(rt_device_t dev)
{
return RT_EOK;
}
static rt_size_t eth_read(rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size)
{
rt_set_errno(-RT_ENOSYS);
return 0;
}
static rt_size_t eth_write(rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size)
{
rt_set_errno(-RT_ENOSYS);
return 0;
}
static rt_err_t eth_control(rt_device_t dev, int cmd, void *args)
{
switch (cmd)
{
case NIOCTL_GADDR:
/* get mac address */
if (args) rt_memcpy(args, eth_mac_addr, 6);
else return -RT_ERROR;
break;
default :
break;
}
return RT_EOK;
}
rt_err_t eth_tx(rt_device_t dev, struct pbuf *p)
{
//判断eth是否处于发送状态
if ((R8_ETH_ECON1 & RB_ETH_ECON1_TXRTS) != 0x00)
{
return ERR_INPROGRESS;
}
//确定缓冲区是否足够
if (p->tot_len > sizeof(eth_dma_tx_buf))
{
return ERR_MEM;
}
//拷贝数据到dma缓冲区
rt_memcpy(eth_dma_tx_buf, p->payload, p->tot_len);
//设置数据长度
R16_ETH_ETXLN = p->tot_len;
//开始发送
R8_ETH_ECON1 |= RB_ETH_ECON1_TXRTS;
return ERR_OK;
}
struct pbuf *eth_rx(rt_device_t dev)
{
struct pbuf *p = NULL;
//检查是否有数据
if (eth_rx_len == 0)
{
return NULL;
}
p = pbuf_alloc(PBUF_RAW, eth_rx_len, PBUF_POOL);
if (p == NULL)
{
rt_kprintf("eth_rx: pbuf_alloc failed\n");
eth_rx_len = 0;
return NULL;
}
//拷贝数据到pbuf
rt_memcpy((uint8_t *)((uint8_t *)p->payload), (uint8_t *)((uint8_t *)eth_rx_buf), eth_rx_len);
//恢复状态
eth_rx_len = 0;
return p;
}
int read_eth_link_status()
{
R8_ETH_MIREGADR = 0x01;//状态寄存器
R8_ETH_MISTAT |= 0x00; //读MII寄存器
//获取link状态
if ((R16_ETH_MIRD & 0x04) != 0)
{
return 1; //已插入
}
return 0;
}
void ETH_IRQHandler(void) /* 以太网中断 */
{
rt_interrupt_enter();
//接收到数据包
if ((R8_ETH_EIR & RB_ETH_EIR_RXIF) != 0)
{
//判断缓存区是否有数据
if (eth_rx_len == 0)
{
rt_memcpy(eth_rx_buf, eth_dma_rx_buf, R16_ETH_ERXLN);
eth_rx_len = R16_ETH_ERXLN;
//通知拿数据
eth_device_ready(&eth_device);
}
R8_ETH_EIR |= RB_ETH_EIR_RXIF; //清除中断
}
//接收错误
if ((R8_ETH_EIR & RB_ETH_EIE_RXERIE) != 0)
{
R8_ETH_EIR |= RB_ETH_EIE_RXERIE; //清除中断
}
//发送完成
if ((R8_ETH_EIR & RB_ETH_EIR_TXIF) != 0)
{
R8_ETH_EIR |= RB_ETH_EIR_TXIF; //清除中断
}
//发送错误
if ((R8_ETH_EIR & RB_ETH_EIE_TXERIE) != 0)
{
R8_ETH_EIR |= RB_ETH_EIE_TXERIE; //清除中断
}
//Link 变化标志
if ((R8_ETH_EIR & RB_ETH_EIR_LINKIF) != 0)
{
//获取连接状态
if (read_eth_link_status())
{
eth_device_linkchange(&eth_device, RT_TRUE);
rt_kprintf("eth1: link is up\n");
}
else
{
eth_device_linkchange(&eth_device, RT_FALSE);
rt_kprintf("eth1: link is down\n");
}
R8_ETH_EIR |= RB_ETH_EIR_LINKIF; //清除中断
}
rt_interrupt_leave();
}
int rt_hw_eth_init(void)
{
//使能ETH引脚
R16_PIN_ANALOG_IE |= RB_PIN_ETH_IE;
//进入安全访问模式
R8_SAFE_ACCESS_SIG = 0x57;
R8_SAFE_ACCESS_SIG = 0xA8;
//打开以太网时钟
R8_SLP_CLK_OFF1 &= (~RB_SLP_CLK_ETH);
//打开以太网电源
R8_SLP_POWER_CTRL &= (~RB_SLP_ETH_PWR_DN);
//退出安全访问模式
R8_SAFE_ACCESS_SIG = 0x00;
//开启以太网中断
R8_ETH_EIE |= RB_ETH_EIE_INTIE;
//启用以太网接收中断
R8_ETH_EIE |= RB_ETH_EIE_RXIE;
//R8_ETH_EIE |= RB_ETH_EIE_RXERIE;
//启用以太网发送中断
R8_ETH_EIE |= RB_ETH_EIR_TXIF;
R8_ETH_EIE |= RB_ETH_EIR_TXERIF;
//启用Link变化中断
R8_ETH_EIE |= RB_ETH_EIE_LINKIE;
//启用内置的50欧姆阻抗匹配电阻
R8_ETH_EIE |= RB_ETH_EIE_R_EN50;
//配置接收过滤模式
R8_ETH_ERXFCON = RB_ETH_ERXFCON_ANDOR | RB_ETH_ERXFCON_CRCEN;
//设置发送dma
R16_ETH_ETXST = (uint32_t)eth_dma_tx_buf;
//设置接收dma
R16_ETH_ERXST = (uint32_t)eth_dma_rx_buf;
//设置最大接收长度
R16_ETH_MAMXFL = sizeof(eth_dma_rx_buf);
//使能MAC层接收
R8_ETH_MACON1 |= RB_ETH_MACON1_MARXEN;
//开启硬件CRC
R8_ETH_MACON2 |= RB_ETH_MACON2_TXCRCEN;
//所有短包填充0至60字节再4字节 CRC
R8_ETH_MACON2 |= 0x20;
//使能接收
R8_ETH_ECON1 |= RB_ETH_ECON1_RXEN;
//开启中断
NVIC_EnableIRQ(ETH_IRQn);
//设置回调函数
eth_device.parent.init = eth_init;
eth_device.parent.open = eth_open;
eth_device.parent.close = eth_close;
eth_device.parent.read = eth_read;
eth_device.parent.write = eth_write;
eth_device.parent.control = eth_control;
eth_device.parent.user_data = RT_NULL;
eth_device.eth_rx = eth_rx;
eth_device.eth_tx = eth_tx;
return eth_device_init(&(eth_device), "e0");
}
INIT_DEVICE_EXPORT(rt_hw_eth_init);
#endif /* BSP_USING_ETH */

View File

@ -0,0 +1,19 @@
/*
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2022-02-16 Tuber first version
*/
#ifndef __DRV_ETH_H__
#define __DRV_ETH_H__
#include <rtthread.h>
#define ETH_BUF_SIZE 1536
int rt_hw_eth_init(void);
#endif

View File

@ -0,0 +1,421 @@
/*
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2022-02-16 Tuber first version
*/
#include <rtthread.h>
#include <rtdevice.h>
#include "board.h"
#include "drv_uart.h"
#ifdef BSP_USING_UART
struct uart_device
{
struct rt_serial_device serial;
char *name;
};
#ifdef BSP_USING_UART0
static struct uart_device uart_device0 =
{
.name = "uart0",
};
#endif
#ifdef BSP_USING_UART1
static struct uart_device uart_device1 =
{
.name = "uart1",
};
#endif
#ifdef BSP_USING_UART2
static struct uart_device uart_device2 =
{
.name = "uart2",
};
#endif
#ifdef BSP_USING_UART3
static struct uart_device uart_device3 =
{
.name = "uart3",
};
#endif
static rt_err_t uart_configure(struct rt_serial_device *serial, struct serial_configure *cfg)
{
UINT32 x;
UINT8V R8_UARTx_FCR = 0, R8_UARTx_LCR = 0, R8_UARTx_IER = 0, R8_UARTx_DIV = 0;
UINT16V R16_UARTx_DL = 0;
struct uart_device *uart_device = serial->parent.user_data;
//设置波特率
x = 10 * GetSysClock() / 8 / cfg->baud_rate;
x = (x + 5) / 10;
R16_UARTx_DL = (UINT16)x;
//设置数据长度
switch (cfg->data_bits)
{
case DATA_BITS_5:
//R8_UARTx_LCR |= 0x00;
break;
case DATA_BITS_6:
R8_UARTx_LCR |= 0x01;
break;
case DATA_BITS_7:
R8_UARTx_LCR |= 0x02;
break;
case DATA_BITS_8:
default:
R8_UARTx_LCR |= 0x03;
break;
}
//设置停止位
switch (cfg->stop_bits)
{
case STOP_BITS_2:
R8_UARTx_LCR |= 0x04;
break;
case STOP_BITS_1:
default:
//R8_UARTx_LCR |= 0x00;
break;
}
//设置校验位
switch (cfg->parity)
{
case PARITY_ODD:
R8_UART1_LCR |= R8_LCR_PAR_EN;
//R8_UART1_LCR |= 0x00;
break;
case PARITY_EVEN:
R8_UART1_LCR |= R8_LCR_PAR_EN;
R8_UART1_LCR |= 0x10;
break;
case PARITY_NONE:
default:
//R8_UART1_LCR &= (~R8_UART1_LCR);
break;
}
#ifdef BSP_USING_UART0
if (uart_device == &uart_device0)
{
GPIOB_SetBits(GPIO_Pin_7);
GPIOB_ModeCfg(GPIO_Pin_4, GPIO_ModeIN_PU); // RXD-配置上拉输入
GPIOB_ModeCfg(GPIO_Pin_7, GPIO_ModeOut_PP_5mA); // TXD-配置推挽输出注意先让IO口输出高电平
R16_UART0_DL = R16_UARTx_DL;
R8_UART0_FCR = (2 << 6) | RB_FCR_TX_FIFO_CLR | RB_FCR_RX_FIFO_CLR | RB_FCR_FIFO_EN; // FIFO打开触发点4字节
R8_UART0_LCR = R8_UARTx_LCR;
R8_UART0_IER = RB_IER_TXD_EN;
R8_UART0_DIV = 1;
}
#endif
#ifdef BSP_USING_UART1
if (uart_device == &uart_device1)
{
GPIOA_SetBits(GPIO_Pin_9);
GPIOA_ModeCfg(GPIO_Pin_8, GPIO_ModeIN_PU); // RXD-配置上拉输入
GPIOA_ModeCfg(GPIO_Pin_9, GPIO_ModeOut_PP_5mA); // TXD-配置推挽输出注意先让IO口输出高电平
R16_UART1_DL = R16_UARTx_DL;
R8_UART1_FCR = (2 << 6) | RB_FCR_TX_FIFO_CLR | RB_FCR_RX_FIFO_CLR | RB_FCR_FIFO_EN; // FIFO打开触发点4字节
R8_UART1_LCR = R8_UARTx_LCR;
R8_UART1_IER = RB_IER_TXD_EN;
R8_UART1_DIV = 1;
}
#endif
#ifdef BSP_USING_UART2
if (uart_device == &uart_device2)
{
GPIOA_SetBits(GPIO_Pin_7);
GPIOA_ModeCfg(GPIO_Pin_6, GPIO_ModeIN_PU); // RXD-配置上拉输入
GPIOA_ModeCfg(GPIO_Pin_7, GPIO_ModeOut_PP_5mA); // TXD-配置推挽输出注意先让IO口输出高电平
R16_UART2_DL = R16_UARTx_DL;
R8_UART2_FCR = (2 << 6) | RB_FCR_TX_FIFO_CLR | RB_FCR_RX_FIFO_CLR | RB_FCR_FIFO_EN; // FIFO打开触发点4字节
R8_UART2_LCR = R8_UARTx_LCR;
R8_UART2_IER = RB_IER_TXD_EN;
R8_UART2_DIV = 1;
}
#endif
#ifdef BSP_USING_UART3
if (uart_device == &uart_device3)
{
GPIOA_SetBits(GPIO_Pin_5);
GPIOA_ModeCfg(GPIO_Pin_4, GPIO_ModeIN_PU); // RXD-配置上拉输入
GPIOA_ModeCfg(GPIO_Pin_5, GPIO_ModeOut_PP_5mA); // TXD-配置推挽输出注意先让IO口输出高电平
R16_UART3_DL = R16_UARTx_DL;
R8_UART3_FCR = (2 << 6) | RB_FCR_TX_FIFO_CLR | RB_FCR_RX_FIFO_CLR | RB_FCR_FIFO_EN; // FIFO打开触发点4字节
R8_UART3_LCR = R8_UARTx_LCR;
R8_UART3_IER = RB_IER_TXD_EN;
R8_UART3_DIV = 1;
}
#endif
return RT_EOK;
}
static rt_err_t uart_control(struct rt_serial_device *serial, int cmd, void *arg)
{
struct uart_device *uart_device = serial->parent.user_data;
switch (cmd)
{
case RT_DEVICE_CTRL_CLR_INT:
#ifdef BSP_USING_UART0
if (uart_device == &uart_device0)
{
UART0_INTCfg(DISABLE, RB_IER_RECV_RDY);
NVIC_EnableIRQ(UART0_IRQn);
}
#endif
#ifdef BSP_USING_UART1
if (uart_device == &uart_device1)
{
UART1_INTCfg(DISABLE, RB_IER_RECV_RDY);
NVIC_EnableIRQ(UART1_IRQn);
}
#endif
#ifdef BSP_USING_UART2
if (uart_device == &uart_device2)
{
UART2_INTCfg(DISABLE, RB_IER_RECV_RDY);
NVIC_EnableIRQ(UART2_IRQn);
}
#endif
#ifdef BSP_USING_UART3
if (uart_device == &uart_device3)
{
UART3_INTCfg(DISABLE, RB_IER_RECV_RDY);
NVIC_EnableIRQ(UART3_IRQn);
}
#endif
break;
case RT_DEVICE_CTRL_SET_INT:
#ifdef BSP_USING_UART0
if (uart_device == &uart_device0)
{
UART0_ByteTrigCfg(UART_1BYTE_TRIG);
UART0_INTCfg(ENABLE, RB_IER_RECV_RDY);
NVIC_EnableIRQ(UART0_IRQn);
}
#endif
#ifdef BSP_USING_UART1
if (uart_device == &uart_device1)
{
UART1_ByteTrigCfg(UART_1BYTE_TRIG);
UART1_INTCfg(ENABLE, RB_IER_RECV_RDY);
NVIC_EnableIRQ(UART1_IRQn);
}
#endif
#ifdef BSP_USING_UART2
if (uart_device == &uart_device2)
{
UART2_ByteTrigCfg(UART_1BYTE_TRIG);
UART2_INTCfg(ENABLE, RB_IER_RECV_RDY);
NVIC_EnableIRQ(UART2_IRQn);
}
#endif
#ifdef BSP_USING_UART3
if (uart_device == &uart_device3)
{
UART3_ByteTrigCfg(UART_1BYTE_TRIG);
UART3_INTCfg(ENABLE, RB_IER_RECV_RDY);
NVIC_EnableIRQ(UART3_IRQn);
}
#endif
break;
default:
break;
}
return RT_EOK;
}
static int uart_putc(struct rt_serial_device *serial, char ch)
{
struct uart_device *uart_device = serial->parent.user_data;
#ifdef BSP_USING_UART0
if (uart_device == &uart_device0)
{
while (R8_UART0_TFC >= UART_FIFO_SIZE);
R8_UART0_THR = ch;
}
#endif
#ifdef BSP_USING_UART1
if (uart_device == &uart_device1)
{
while (R8_UART1_TFC >= UART_FIFO_SIZE);
R8_UART1_THR = ch;
}
#endif
#ifdef BSP_USING_UART2
if (uart_device == &uart_device2)
{
while (R8_UART2_TFC >= UART_FIFO_SIZE);
R8_UART2_THR = ch;
}
#endif
#ifdef BSP_USING_UART3
if (uart_device == &uart_device3)
{
while (R8_UART3_TFC >= UART_FIFO_SIZE);
R8_UART3_THR = ch;
}
#endif
return 1;
}
static int uart_getc(struct rt_serial_device *serial)
{
struct uart_device *uart_device = serial->parent.user_data;
#ifdef BSP_USING_UART0
if (uart_device == &uart_device0)
{
if (R8_UART0_RFC > 0)
{
return R8_UART0_RBR;
}
}
#endif
#ifdef BSP_USING_UART1
if (uart_device == &uart_device1)
{
if (R8_UART1_RFC > 0)
{
return R8_UART1_RBR;
}
}
#endif
#ifdef BSP_USING_UART2
if (uart_device == &uart_device2)
{
if (R8_UART2_RFC > 0)
{
return R8_UART2_RBR;
}
}
#endif
#ifdef BSP_USING_UART3
if (uart_device == &uart_device3)
{
if (R8_UART3_RFC > 0)
{
return R8_UART3_RBR;
}
}
#endif
return -1;
}
static const struct rt_uart_ops uart_ops =
{
.configure = uart_configure,
.control = uart_control,
.putc = uart_putc,
.getc = uart_getc,
.dma_transmit = RT_NULL,
};
void uart_isr(struct rt_serial_device *serial, UINT8 flag)
{
switch (flag)
{
case UART_II_RECV_RDY: // 数据达到设置触发点
rt_hw_serial_isr(serial, RT_SERIAL_EVENT_RX_IND);
break;
case UART_II_RECV_TOUT: // 接收超时,暂时一帧数据接收完成
rt_hw_serial_isr(serial, RT_SERIAL_EVENT_RX_TIMEOUT);
break;
case UART_II_THR_EMPTY: // 发送缓存区空,可继续发送
rt_hw_serial_isr(serial, RT_SERIAL_EVENT_TX_DONE);
break;
default:
break;
}
}
#ifdef BSP_USING_UART0
void UART0_IRQHandler(void)
{
rt_interrupt_enter();
uart_isr(&uart_device0.serial, UART0_GetITFlag());
rt_interrupt_leave();
}
#endif
#ifdef BSP_USING_UART1
void UART1_IRQHandler(void)
{
rt_interrupt_enter();
uart_isr(&uart_device1.serial, UART1_GetITFlag());
rt_interrupt_leave();
}
#endif
#ifdef BSP_USING_UART2
void UART2_IRQHandler(void)
{
rt_interrupt_enter();
uart_isr(&uart_device2.serial, UART2_GetITFlag());
rt_interrupt_leave();
}
#endif
#ifdef BSP_USING_UART3
void UART3_IRQHandler(void)
{
rt_interrupt_enter();
uart_isr(&uart_device3.serial, UART3_GetITFlag());
rt_interrupt_leave();
}
#endif
int rt_hw_uart_init(void)
{
struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT;
#ifdef BSP_USING_UART0
uart_device0.serial.config = config;
uart_device0.serial.ops = &uart_ops;
rt_hw_serial_register(&uart_device0.serial, uart_device0.name,
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_INT_TX,
&uart_device0);
#endif
#ifdef BSP_USING_UART1
uart_device1.serial.config = config;
uart_device1.serial.ops = &uart_ops;
rt_hw_serial_register(&uart_device1.serial, uart_device1.name,
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_INT_TX,
&uart_device1);
#endif
#ifdef BSP_USING_UART2
uart_device2.serial.config = config;
uart_device2.serial.ops = &uart_ops;
rt_hw_serial_register(&uart_device2.serial, uart_device2.name,
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_INT_TX,
&uart_device2);
#endif
#ifdef BSP_USING_UART3
uart_device3.serial.config = config;
uart_device3.serial.ops = &uart_ops;
rt_hw_serial_register(&uart_device3.serial, uart_device3.name,
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_INT_TX,
&uart_device3);
#endif
return RT_EOK;
}
#endif /* BSP_USING_UART */

View File

@ -0,0 +1,16 @@
/*
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2022-02-16 Tuber first version
*/
#ifndef DRV_UART_H__
#define DRV_UART_H__
int rt_hw_uart_init(void);
#endif

View File

@ -0,0 +1,299 @@
/*
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2022-02-16 Tuber first version
*/
#include <rtthread.h>
#include <rtdevice.h>
#include "board.h"
#include "drv_usbh.h"
#ifdef BSP_USING_USBH
static struct rt_completion urb_completion;
//USB接收缓存区
__align(4) UINT8 usb_rx_buf[MAX_PACKET_SIZE]; // IN, must even address
__align(4) UINT8 usb_tx_buf[MAX_PACKET_SIZE]; // OUT, must even address
static struct uhcd uhcd;
static rt_err_t drv_reset_port(rt_uint8_t port)
{
//关闭中断
R8_USB_INT_EN = 0x00;
R8_USB_DEV_AD = (R8_USB_DEV_AD & RB_UDA_GP_BIT) | (0x00 & MASK_USB_ADDR); //设置地址
R8_UHOST_CTRL &= ~RB_UH_PORT_EN; // 关掉端口
//判断设备速度
if (R8_USB_MIS_ST & RB_UMS_DM_LEVEL)
{
//低速
R8_USB_CTRL |= RB_UC_LOW_SPEED; // 默认为低速
R8_UHOST_CTRL = (R8_UHOST_CTRL | RB_UH_LOW_SPEED) | RB_UH_BUS_RESET; // 默认为低速,开始复位
}
else
{
//全速
R8_USB_CTRL &= ~ RB_UC_LOW_SPEED; // 默认为全速
R8_UHOST_CTRL = (R8_UHOST_CTRL & ~RB_UH_LOW_SPEED) | RB_UH_BUS_RESET; // 默认为全速,开始复位
}
rt_thread_mdelay(15); // 复位时间10mS到20mS
R8_UHOST_CTRL = R8_UHOST_CTRL & ~ RB_UH_BUS_RESET; // 结束复位
rt_thread_mdelay(1);
R8_UHOST_CTRL |= RB_UH_PORT_EN; //打开端口
R8_USB_INT_FG = RB_UIF_DETECT; // 清中断标志
//打开中断
R8_USB_INT_EN = RB_UIF_TRANSFER | RB_UIE_DETECT;
return RT_EOK;
}
static int drv_pipe_xfer(upipe_t pipe, rt_uint8_t token, void *buffer, int nbytes, int timeouts)
{
rt_err_t res;
UINT16 i;
UINT16 retry_count = 3;
rt_uint8_t usb_pid, res_pid;
UINT8 *tog = (UINT8 *)pipe->user_data;
//设置目标usb地址
R8_USB_DEV_AD = (R8_USB_DEV_AD & RB_UDA_GP_BIT) | (pipe->inst->address & MASK_USB_ADDR);
//判断是in还是out操作
if (pipe->ep.bEndpointAddress & USB_DIR_IN)
{
usb_pid = USB_PID_IN; //in
R8_UH_TX_LEN = 0x00;
}
else
{
usb_pid = (token == USBH_PID_SETUP) ? USB_PID_SETUP : USB_PID_OUT; //setup/out
rt_memcpy(usb_tx_buf, buffer, nbytes);
R8_UH_TX_LEN = nbytes;
}
//设置数据TOG
switch (usb_pid)
{
case USB_PID_IN:
if (nbytes == 0) *tog = USB_PID_DATA1; //状态反馈
R8_UH_RX_CTRL = (*tog == USB_PID_DATA1) ? RB_UH_R_TOG : 0x00;
break;
case USB_PID_OUT:
if (nbytes == 0) *tog = USB_PID_DATA1; //状态反馈
R8_UH_TX_CTRL = (*tog == USB_PID_DATA1) ? RB_UH_T_TOG : 0x00;
break;
case USB_PID_SETUP:
*(UINT8 *)pipe->inst->pipe_ep0_out->user_data = USB_PID_DATA0;
*(UINT8 *)pipe->inst->pipe_ep0_in->user_data = USB_PID_DATA1;
R8_UH_TX_CTRL = (*tog == USB_PID_DATA1) ? RB_UH_T_TOG : 0x00;
break;
}
//usb枚举的时候加大重试次数提高usb设备枚举成功率
if ((pipe->ep.bmAttributes & USB_EP_ATTR_TYPE_MASK) == USB_EP_ATTR_CONTROL)
{
retry_count = 1000;
}
for (i = 0; i < retry_count; i++)
{
//传输
R8_UH_EP_PID = (usb_pid << 4) | (pipe->ep.bEndpointAddress & 0x0F);
res = rt_completion_wait(&urb_completion, timeouts);
if (res != RT_EOK)
{
return res;
}
//判断是否需要反转数据
if (R8_USB_INT_ST & RB_UIS_TOG_OK)
{
*tog = (*tog == USB_PID_DATA0) ? USB_PID_DATA1 : USB_PID_DATA0;//翻转
}
res_pid = R8_USB_INT_ST & MASK_UIS_H_RES;
switch (res_pid)
{
case USB_PID_ACK://发送成功
pipe->status = UPIPE_STATUS_OK;
if (pipe->callback != RT_NULL) pipe->callback(pipe);
return nbytes;
case USB_PID_DATA0: //收到数据
case USB_PID_DATA1: //收到数据
pipe->status = UPIPE_STATUS_OK;
if (pipe->callback != RT_NULL) pipe->callback(pipe);
//拷贝数据到buffer
if (usb_pid == USB_PID_IN)
{
rt_memcpy(buffer, usb_rx_buf, R8_USB_RX_LEN);
return R8_USB_RX_LEN;
}
return nbytes;
case USB_PID_NAK: //数据未就绪
if (pipe->ep.bmAttributes == USB_EP_ATTR_INT)
{
rt_thread_delay((pipe->ep.bInterval * RT_TICK_PER_SECOND / 1000) > 0 ? (pipe->ep.bInterval * RT_TICK_PER_SECOND / 1000) : 1);
}
rt_thread_mdelay(1);
continue;//重试
case USB_PID_STALL: //传输停止
pipe->status = UPIPE_STATUS_STALL;
if (pipe->callback != RT_NULL) pipe->callback(pipe);
return 0;
default:
break;
}
}
pipe->status = UPIPE_STATUS_ERROR;
if (pipe->callback != RT_NULL) pipe->callback(pipe);
return -RT_ERROR;
}
static rt_err_t drv_open_pipe(upipe_t pipe)
{
pipe->pipe_index = pipe->inst->address & MASK_USB_ADDR;
pipe->user_data = rt_malloc(sizeof(UINT8));
//默认发送DATA0
if (pipe->ep.bEndpointAddress & USB_DIR_IN)
{
*(UINT8 *)pipe->user_data = USB_PID_DATA0;
}
else
{
*(UINT8 *)pipe->user_data = USB_PID_DATA0;
}
return RT_EOK;
}
static rt_err_t drv_close_pipe(upipe_t pipe)
{
rt_free(pipe->user_data);
return RT_EOK;
}
static struct uhcd_ops uhcd_ops =
{
drv_reset_port,
drv_pipe_xfer,
drv_open_pipe,
drv_close_pipe,
};
static rt_err_t hcd_init(rt_device_t dev)
{
R16_PIN_ANALOG_IE |= RB_PIN_USB_IE;
R8_USB_CTRL = RB_UC_HOST_MODE;
R8_UHOST_CTRL = 0;
R8_USB_DEV_AD = 0x00;
R8_UH_EP_MOD = RB_UH_EP_TX_EN | RB_UH_EP_RX_EN;
R16_UH_RX_DMA = (UINT16)(UINT32)usb_rx_buf;
R16_UH_TX_DMA = (UINT16)(UINT32)usb_tx_buf;
R8_USB_CTRL = RB_UC_HOST_MODE | RB_UC_INT_BUSY | RB_UC_DMA_EN;
R8_UH_SETUP = RB_UH_SOF_EN;
R8_USB_INT_FG = 0xFF;
R8_USB_INT_EN = RB_UIF_TRANSFER | RB_UIE_DETECT;
//开启中断
NVIC_EnableIRQ(USB_IRQn);
rt_completion_init(&urb_completion);
return RT_EOK;
}
void USB_IRQHandler()
{
rt_interrupt_enter();
//USB连接断开中断
if (R8_USB_INT_FG & RB_UIF_DETECT)
{
R8_USB_INT_FG = RB_UIF_DETECT;//清除中断
//检查USB设备连接状态
if ((R8_USB_MIS_ST & RB_UMS_DEV_ATTACH) != 0)
{
rt_usbh_root_hub_connect_handler(&uhcd, 1, RT_FALSE);
rt_kprintf("usb: up\n");
}
else
{
rt_usbh_root_hub_disconnect_handler(&uhcd, 1);
rt_kprintf("usb: down\n");
}
}
if (R8_USB_INT_FG & RB_UIF_TRANSFER)
{
R8_UH_EP_PID = 0x00; //停止发送
R8_USB_INT_FG = RB_UIF_TRANSFER;//清除中断
rt_completion_done(&urb_completion);
}
if (R8_USB_INT_FG & RB_UIF_SUSPEND)
{
R8_USB_INT_FG = RB_UIF_SUSPEND;//清除中断
}
if (R8_USB_INT_FG & RB_UIF_HST_SOF)
{
R8_USB_INT_FG = RB_UIF_HST_SOF;//清除中断
}
if (R8_USB_INT_FG & RB_UIF_FIFO_OV)
{
R8_USB_INT_FG = RB_UIF_FIFO_OV;//清除中断
}
rt_interrupt_leave();
}
int rt_hw_usbh_init(void)
{
rt_err_t res = -RT_ERROR;
rt_memset((void *)&uhcd, 0, sizeof(struct uhcd));
uhcd.parent.type = RT_Device_Class_USBHost;
uhcd.parent.init = hcd_init;
uhcd.ops = &uhcd_ops;
uhcd.num_ports = 1;
res = rt_device_register(&uhcd.parent, "usbh", RT_DEVICE_FLAG_DEACTIVATE);
if (res != RT_EOK)
{
rt_kprintf("register usb host failed res = %d\r\n", res);
return -RT_ERROR;
}
rt_usb_host_init("usbh");
return RT_EOK;
}
INIT_DEVICE_EXPORT(rt_hw_usbh_init);
#endif /* BSP_USING_USBH */

View File

@ -0,0 +1,28 @@
/*
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2022-02-16 Tuber first version
*/
#ifndef __DRV_USBH_H__
#define __DRV_USBH_H__
#include <rtthread.h>
#define USB_PID_SETUP 0x0D
#define USB_PID_IN 0x09
#define USB_PID_OUT 0x01
#define USB_PID_SOF 0x05
#define USB_PID_ACK 0x02
#define USB_PID_NAK 0x0A
#define USB_PID_STALL 0x0E
#define USB_PID_DATA0 0x03
#define USB_PID_DATA1 0x0B
#define USB_PID_PRE 0x0C
int rt_hw_usbh_init(void);
#endif

View File

@ -0,0 +1,711 @@
/**************************************************************************//**
* @file core_cm0.h
* @brief CMSIS Cortex-M0 Core Peripheral Access Layer Header File
* @version V4.00
* @date 22. August 2014
*
* @note
*
******************************************************************************/
/* Copyright (c) 2009 - 2014 ARM LIMITED
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
- Neither the name of ARM nor the names of its contributors may be used
to endorse or promote products derived from this software without
specific prior written permission.
*
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------*/
#if defined ( __ICCARM__ )
#pragma system_include /* treat file as system include file for MISRA check */
#endif
#ifndef __CORE_CM0_H_GENERIC
#define __CORE_CM0_H_GENERIC
#ifdef __cplusplus
extern "C" {
#endif
/** \page CMSIS_MISRA_Exceptions MISRA-C:2004 Compliance Exceptions
CMSIS violates the following MISRA-C:2004 rules:
\li Required Rule 8.5, object/function definition in header file.<br>
Function definitions in header files are used to allow 'inlining'.
\li Required Rule 18.4, declaration of union type or object of union type: '{...}'.<br>
Unions are used for effective representation of core registers.
\li Advisory Rule 19.7, Function-like macro defined.<br>
Function-like macros are used to allow more efficient code.
*/
/*******************************************************************************
* CMSIS definitions
******************************************************************************/
/** \ingroup Cortex_M0
@{
*/
/* CMSIS CM0 definitions */
#define __CM0_CMSIS_VERSION_MAIN (0x04) /*!< [31:16] CMSIS HAL main version */
#define __CM0_CMSIS_VERSION_SUB (0x00) /*!< [15:0] CMSIS HAL sub version */
#define __CM0_CMSIS_VERSION ((__CM0_CMSIS_VERSION_MAIN << 16) | \
__CM0_CMSIS_VERSION_SUB ) /*!< CMSIS HAL version number */
#define __CORTEX_M (0x00) /*!< Cortex-M Core */
#if defined ( __CC_ARM )
#define __ASM __asm /*!< asm keyword for ARM Compiler */
#define __INLINE __inline /*!< inline keyword for ARM Compiler */
#define __STATIC_INLINE static __inline
#elif defined ( __GNUC__ )
#define __ASM __asm /*!< asm keyword for GNU Compiler */
#define __INLINE inline /*!< inline keyword for GNU Compiler */
#define __STATIC_INLINE static inline
#elif defined ( __ICCARM__ )
#define __ASM __asm /*!< asm keyword for IAR Compiler */
#define __INLINE inline /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */
#define __STATIC_INLINE static inline
#elif defined ( __TMS470__ )
#define __ASM __asm /*!< asm keyword for TI CCS Compiler */
#define __STATIC_INLINE static inline
#elif defined ( __TASKING__ )
#define __ASM __asm /*!< asm keyword for TASKING Compiler */
#define __INLINE inline /*!< inline keyword for TASKING Compiler */
#define __STATIC_INLINE static inline
#elif defined ( __CSMC__ )
#define __packed
#define __ASM _asm /*!< asm keyword for COSMIC Compiler */
#define __INLINE inline /*use -pc99 on compile line !< inline keyword for COSMIC Compiler */
#define __STATIC_INLINE static inline
#endif
/** __FPU_USED indicates whether an FPU is used or not.
This core does not support an FPU at all
*/
#define __FPU_USED 0
#if defined ( __CC_ARM )
#if defined __TARGET_FPU_VFP
#warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
#endif
#elif defined ( __GNUC__ )
#if defined (__VFP_FP__) && !defined(__SOFTFP__)
#warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
#endif
#elif defined ( __ICCARM__ )
#if defined __ARMVFP__
#warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
#endif
#elif defined ( __TMS470__ )
#if defined __TI__VFP_SUPPORT____
#warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
#endif
#elif defined ( __TASKING__ )
#if defined __FPU_VFP__
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
#endif
#elif defined ( __CSMC__ ) /* Cosmic */
#if ( __CSMC__ & 0x400) // FPU present for parser
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
#endif
#endif
#include <stdint.h> /* standard types definitions */
#include <core_cmInstr.h> /* Core Instruction Access */
#include <core_cmFunc.h> /* Core Function Access */
#ifdef __cplusplus
}
#endif
#endif /* __CORE_CM0_H_GENERIC */
#ifndef __CMSIS_GENERIC
#ifndef __CORE_CM0_H_DEPENDANT
#define __CORE_CM0_H_DEPENDANT
#ifdef __cplusplus
extern "C" {
#endif
/* check device defines and use defaults */
#if defined __CHECK_DEVICE_DEFINES
#ifndef __CM0_REV
#define __CM0_REV 0x0000
#warning "__CM0_REV not defined in device header file; using default!"
#endif
#ifndef __NVIC_PRIO_BITS
#define __NVIC_PRIO_BITS 2
#warning "__NVIC_PRIO_BITS not defined in device header file; using default!"
#endif
#ifndef __Vendor_SysTickConfig
#define __Vendor_SysTickConfig 0
#warning "__Vendor_SysTickConfig not defined in device header file; using default!"
#endif
#endif
/* IO definitions (access restrictions to peripheral registers) */
/**
\defgroup CMSIS_glob_defs CMSIS Global Defines
<strong>IO Type Qualifiers</strong> are used
\li to specify the access to peripheral variables.
\li for automatic generation of peripheral register debug information.
*/
#ifdef __cplusplus
#define __I volatile /*!< Defines 'read only' permissions */
#else
#define __I volatile const /*!< Defines 'read only' permissions */
#endif
#define __O volatile /*!< Defines 'write only' permissions */
#define __IO volatile /*!< Defines 'read / write' permissions */
/*@} end of group Cortex_M0 */
/*******************************************************************************
* Register Abstraction
Core Register contain:
- Core Register
- Core NVIC Register
- Core SCB Register
- Core SysTick Register
******************************************************************************/
/** \defgroup CMSIS_core_register Defines and Type Definitions
\brief Type definitions and defines for Cortex-M processor based devices.
*/
/** \ingroup CMSIS_core_register
\defgroup CMSIS_CORE Status and Control Registers
\brief Core Register type definitions.
@{
*/
/** \brief Union type to access the Application Program Status Register (APSR).
*/
typedef union
{
struct
{
#if (__CORTEX_M != 0x04)
uint32_t _reserved0:27; /*!< bit: 0..26 Reserved */
#else
uint32_t _reserved0:16; /*!< bit: 0..15 Reserved */
uint32_t GE:4; /*!< bit: 16..19 Greater than or Equal flags */
uint32_t _reserved1:7; /*!< bit: 20..26 Reserved */
#endif
uint32_t Q:1; /*!< bit: 27 Saturation condition flag */
uint32_t V:1; /*!< bit: 28 Overflow condition code flag */
uint32_t C:1; /*!< bit: 29 Carry condition code flag */
uint32_t Z:1; /*!< bit: 30 Zero condition code flag */
uint32_t N:1; /*!< bit: 31 Negative condition code flag */
} b; /*!< Structure used for bit access */
uint32_t w; /*!< Type used for word access */
} APSR_Type;
/** \brief Union type to access the Interrupt Program Status Register (IPSR).
*/
typedef union
{
struct
{
uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */
uint32_t _reserved0:23; /*!< bit: 9..31 Reserved */
} b; /*!< Structure used for bit access */
uint32_t w; /*!< Type used for word access */
} IPSR_Type;
/** \brief Union type to access the Special-Purpose Program Status Registers (xPSR).
*/
typedef union
{
struct
{
uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */
#if (__CORTEX_M != 0x04)
uint32_t _reserved0:15; /*!< bit: 9..23 Reserved */
#else
uint32_t _reserved0:7; /*!< bit: 9..15 Reserved */
uint32_t GE:4; /*!< bit: 16..19 Greater than or Equal flags */
uint32_t _reserved1:4; /*!< bit: 20..23 Reserved */
#endif
uint32_t T:1; /*!< bit: 24 Thumb bit (read 0) */
uint32_t IT:2; /*!< bit: 25..26 saved IT state (read 0) */
uint32_t Q:1; /*!< bit: 27 Saturation condition flag */
uint32_t V:1; /*!< bit: 28 Overflow condition code flag */
uint32_t C:1; /*!< bit: 29 Carry condition code flag */
uint32_t Z:1; /*!< bit: 30 Zero condition code flag */
uint32_t N:1; /*!< bit: 31 Negative condition code flag */
} b; /*!< Structure used for bit access */
uint32_t w; /*!< Type used for word access */
} xPSR_Type;
/** \brief Union type to access the Control Registers (CONTROL).
*/
typedef union
{
struct
{
uint32_t nPRIV:1; /*!< bit: 0 Execution privilege in Thread mode */
uint32_t SPSEL:1; /*!< bit: 1 Stack to be used */
uint32_t FPCA:1; /*!< bit: 2 FP extension active flag */
uint32_t _reserved0:29; /*!< bit: 3..31 Reserved */
} b; /*!< Structure used for bit access */
uint32_t w; /*!< Type used for word access */
} CONTROL_Type;
/*@} end of group CMSIS_CORE */
/** \ingroup CMSIS_core_register
\defgroup CMSIS_NVIC Nested Vectored Interrupt Controller (NVIC)
\brief Type definitions for the NVIC Registers
@{
*/
/** \brief Structure type to access the Nested Vectored Interrupt Controller (NVIC).
*/
typedef struct
{
__IO uint32_t ISER[1]; /*!< Offset: 0x000 (R/W) Interrupt Set Enable Register */
uint32_t RESERVED0[31];
__IO uint32_t ICER[1]; /*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register */
uint32_t RSERVED1[31];
__IO uint32_t ISPR[1]; /*!< Offset: 0x100 (R/W) Interrupt Set Pending Register */
uint32_t RESERVED2[31];
__IO uint32_t ICPR[1]; /*!< Offset: 0x180 (R/W) Interrupt Clear Pending Register */
uint32_t RESERVED3[31];
uint32_t RESERVED4[64];
__IO uint32_t IP[8]; /*!< Offset: 0x300 (R/W) Interrupt Priority Register */
} NVIC_Type;
/*@} end of group CMSIS_NVIC */
/** \ingroup CMSIS_core_register
\defgroup CMSIS_SCB System Control Block (SCB)
\brief Type definitions for the System Control Block Registers
@{
*/
/** \brief Structure type to access the System Control Block (SCB).
*/
typedef struct
{
__I uint32_t CPUID; /*!< Offset: 0x000 (R/ ) CPUID Base Register */
__IO uint32_t ICSR; /*!< Offset: 0x004 (R/W) Interrupt Control and State Register */
uint32_t RESERVED0;
__IO uint32_t AIRCR; /*!< Offset: 0x00C (R/W) Application Interrupt and Reset Control Register */
__IO uint32_t SCR; /*!< Offset: 0x010 (R/W) System Control Register */
__IO uint32_t CCR; /*!< Offset: 0x014 (R/W) Configuration Control Register */
uint32_t RESERVED1;
__IO uint32_t SHP[2]; /*!< Offset: 0x01C (R/W) System Handlers Priority Registers. [0] is RESERVED */
__IO uint32_t SHCSR; /*!< Offset: 0x024 (R/W) System Handler Control and State Register */
} SCB_Type;
/* SCB CPUID Register Definitions */
#define SCB_CPUID_IMPLEMENTER_Pos 24 /*!< SCB CPUID: IMPLEMENTER Position */
#define SCB_CPUID_IMPLEMENTER_Msk (0xFFUL << SCB_CPUID_IMPLEMENTER_Pos) /*!< SCB CPUID: IMPLEMENTER Mask */
#define SCB_CPUID_VARIANT_Pos 20 /*!< SCB CPUID: VARIANT Position */
#define SCB_CPUID_VARIANT_Msk (0xFUL << SCB_CPUID_VARIANT_Pos) /*!< SCB CPUID: VARIANT Mask */
#define SCB_CPUID_ARCHITECTURE_Pos 16 /*!< SCB CPUID: ARCHITECTURE Position */
#define SCB_CPUID_ARCHITECTURE_Msk (0xFUL << SCB_CPUID_ARCHITECTURE_Pos) /*!< SCB CPUID: ARCHITECTURE Mask */
#define SCB_CPUID_PARTNO_Pos 4 /*!< SCB CPUID: PARTNO Position */
#define SCB_CPUID_PARTNO_Msk (0xFFFUL << SCB_CPUID_PARTNO_Pos) /*!< SCB CPUID: PARTNO Mask */
#define SCB_CPUID_REVISION_Pos 0 /*!< SCB CPUID: REVISION Position */
#define SCB_CPUID_REVISION_Msk (0xFUL << SCB_CPUID_REVISION_Pos) /*!< SCB CPUID: REVISION Mask */
/* SCB Interrupt Control State Register Definitions */
#define SCB_ICSR_NMIPENDSET_Pos 31 /*!< SCB ICSR: NMIPENDSET Position */
#define SCB_ICSR_NMIPENDSET_Msk (1UL << SCB_ICSR_NMIPENDSET_Pos) /*!< SCB ICSR: NMIPENDSET Mask */
#define SCB_ICSR_PENDSVSET_Pos 28 /*!< SCB ICSR: PENDSVSET Position */
#define SCB_ICSR_PENDSVSET_Msk (1UL << SCB_ICSR_PENDSVSET_Pos) /*!< SCB ICSR: PENDSVSET Mask */
#define SCB_ICSR_PENDSVCLR_Pos 27 /*!< SCB ICSR: PENDSVCLR Position */
#define SCB_ICSR_PENDSVCLR_Msk (1UL << SCB_ICSR_PENDSVCLR_Pos) /*!< SCB ICSR: PENDSVCLR Mask */
#define SCB_ICSR_PENDSTSET_Pos 26 /*!< SCB ICSR: PENDSTSET Position */
#define SCB_ICSR_PENDSTSET_Msk (1UL << SCB_ICSR_PENDSTSET_Pos) /*!< SCB ICSR: PENDSTSET Mask */
#define SCB_ICSR_PENDSTCLR_Pos 25 /*!< SCB ICSR: PENDSTCLR Position */
#define SCB_ICSR_PENDSTCLR_Msk (1UL << SCB_ICSR_PENDSTCLR_Pos) /*!< SCB ICSR: PENDSTCLR Mask */
#define SCB_ICSR_ISRPREEMPT_Pos 23 /*!< SCB ICSR: ISRPREEMPT Position */
#define SCB_ICSR_ISRPREEMPT_Msk (1UL << SCB_ICSR_ISRPREEMPT_Pos) /*!< SCB ICSR: ISRPREEMPT Mask */
#define SCB_ICSR_ISRPENDING_Pos 22 /*!< SCB ICSR: ISRPENDING Position */
#define SCB_ICSR_ISRPENDING_Msk (1UL << SCB_ICSR_ISRPENDING_Pos) /*!< SCB ICSR: ISRPENDING Mask */
#define SCB_ICSR_VECTPENDING_Pos 12 /*!< SCB ICSR: VECTPENDING Position */
#define SCB_ICSR_VECTPENDING_Msk (0x1FFUL << SCB_ICSR_VECTPENDING_Pos) /*!< SCB ICSR: VECTPENDING Mask */
#define SCB_ICSR_VECTACTIVE_Pos 0 /*!< SCB ICSR: VECTACTIVE Position */
#define SCB_ICSR_VECTACTIVE_Msk (0x1FFUL << SCB_ICSR_VECTACTIVE_Pos) /*!< SCB ICSR: VECTACTIVE Mask */
/* SCB Application Interrupt and Reset Control Register Definitions */
#define SCB_AIRCR_VECTKEY_Pos 16 /*!< SCB AIRCR: VECTKEY Position */
#define SCB_AIRCR_VECTKEY_Msk (0xFFFFUL << SCB_AIRCR_VECTKEY_Pos) /*!< SCB AIRCR: VECTKEY Mask */
#define SCB_AIRCR_VECTKEYSTAT_Pos 16 /*!< SCB AIRCR: VECTKEYSTAT Position */
#define SCB_AIRCR_VECTKEYSTAT_Msk (0xFFFFUL << SCB_AIRCR_VECTKEYSTAT_Pos) /*!< SCB AIRCR: VECTKEYSTAT Mask */
#define SCB_AIRCR_ENDIANESS_Pos 15 /*!< SCB AIRCR: ENDIANESS Position */
#define SCB_AIRCR_ENDIANESS_Msk (1UL << SCB_AIRCR_ENDIANESS_Pos) /*!< SCB AIRCR: ENDIANESS Mask */
#define SCB_AIRCR_SYSRESETREQ_Pos 2 /*!< SCB AIRCR: SYSRESETREQ Position */
#define SCB_AIRCR_SYSRESETREQ_Msk (1UL << SCB_AIRCR_SYSRESETREQ_Pos) /*!< SCB AIRCR: SYSRESETREQ Mask */
#define SCB_AIRCR_VECTCLRACTIVE_Pos 1 /*!< SCB AIRCR: VECTCLRACTIVE Position */
#define SCB_AIRCR_VECTCLRACTIVE_Msk (1UL << SCB_AIRCR_VECTCLRACTIVE_Pos) /*!< SCB AIRCR: VECTCLRACTIVE Mask */
/* SCB System Control Register Definitions */
#define SCB_SCR_SEVONPEND_Pos 4 /*!< SCB SCR: SEVONPEND Position */
#define SCB_SCR_SEVONPEND_Msk (1UL << SCB_SCR_SEVONPEND_Pos) /*!< SCB SCR: SEVONPEND Mask */
#define SCB_SCR_SLEEPDEEP_Pos 2 /*!< SCB SCR: SLEEPDEEP Position */
#define SCB_SCR_SLEEPDEEP_Msk (1UL << SCB_SCR_SLEEPDEEP_Pos) /*!< SCB SCR: SLEEPDEEP Mask */
#define SCB_SCR_SLEEPONEXIT_Pos 1 /*!< SCB SCR: SLEEPONEXIT Position */
#define SCB_SCR_SLEEPONEXIT_Msk (1UL << SCB_SCR_SLEEPONEXIT_Pos) /*!< SCB SCR: SLEEPONEXIT Mask */
/* SCB Configuration Control Register Definitions */
#define SCB_CCR_STKALIGN_Pos 9 /*!< SCB CCR: STKALIGN Position */
#define SCB_CCR_STKALIGN_Msk (1UL << SCB_CCR_STKALIGN_Pos) /*!< SCB CCR: STKALIGN Mask */
#define SCB_CCR_UNALIGN_TRP_Pos 3 /*!< SCB CCR: UNALIGN_TRP Position */
#define SCB_CCR_UNALIGN_TRP_Msk (1UL << SCB_CCR_UNALIGN_TRP_Pos) /*!< SCB CCR: UNALIGN_TRP Mask */
/* SCB System Handler Control and State Register Definitions */
#define SCB_SHCSR_SVCALLPENDED_Pos 15 /*!< SCB SHCSR: SVCALLPENDED Position */
#define SCB_SHCSR_SVCALLPENDED_Msk (1UL << SCB_SHCSR_SVCALLPENDED_Pos) /*!< SCB SHCSR: SVCALLPENDED Mask */
/*@} end of group CMSIS_SCB */
/** \ingroup CMSIS_core_register
\defgroup CMSIS_SysTick System Tick Timer (SysTick)
\brief Type definitions for the System Timer Registers.
@{
*/
/** \brief Structure type to access the System Timer (SysTick).
*/
typedef struct
{
__IO uint32_t CTRL; /*!< Offset: 0x000 (R/W) SysTick Control and Status Register */
__IO uint32_t LOAD; /*!< Offset: 0x004 (R/W) SysTick Reload Value Register */
__IO uint32_t VAL; /*!< Offset: 0x008 (R/W) SysTick Current Value Register */
__I uint32_t CALIB; /*!< Offset: 0x00C (R/ ) SysTick Calibration Register */
} SysTick_Type;
/* SysTick Control / Status Register Definitions */
#define SysTick_CTRL_COUNTFLAG_Pos 16 /*!< SysTick CTRL: COUNTFLAG Position */
#define SysTick_CTRL_COUNTFLAG_Msk (1UL << SysTick_CTRL_COUNTFLAG_Pos) /*!< SysTick CTRL: COUNTFLAG Mask */
#define SysTick_CTRL_CLKSOURCE_Pos 2 /*!< SysTick CTRL: CLKSOURCE Position */
#define SysTick_CTRL_CLKSOURCE_Msk (1UL << SysTick_CTRL_CLKSOURCE_Pos) /*!< SysTick CTRL: CLKSOURCE Mask */
#define SysTick_CTRL_TICKINT_Pos 1 /*!< SysTick CTRL: TICKINT Position */
#define SysTick_CTRL_TICKINT_Msk (1UL << SysTick_CTRL_TICKINT_Pos) /*!< SysTick CTRL: TICKINT Mask */
#define SysTick_CTRL_ENABLE_Pos 0 /*!< SysTick CTRL: ENABLE Position */
#define SysTick_CTRL_ENABLE_Msk (1UL << SysTick_CTRL_ENABLE_Pos) /*!< SysTick CTRL: ENABLE Mask */
/* SysTick Reload Register Definitions */
#define SysTick_LOAD_RELOAD_Pos 0 /*!< SysTick LOAD: RELOAD Position */
#define SysTick_LOAD_RELOAD_Msk (0xFFFFFFUL << SysTick_LOAD_RELOAD_Pos) /*!< SysTick LOAD: RELOAD Mask */
/* SysTick Current Register Definitions */
#define SysTick_VAL_CURRENT_Pos 0 /*!< SysTick VAL: CURRENT Position */
#define SysTick_VAL_CURRENT_Msk (0xFFFFFFUL << SysTick_VAL_CURRENT_Pos) /*!< SysTick VAL: CURRENT Mask */
/* SysTick Calibration Register Definitions */
#define SysTick_CALIB_NOREF_Pos 31 /*!< SysTick CALIB: NOREF Position */
#define SysTick_CALIB_NOREF_Msk (1UL << SysTick_CALIB_NOREF_Pos) /*!< SysTick CALIB: NOREF Mask */
#define SysTick_CALIB_SKEW_Pos 30 /*!< SysTick CALIB: SKEW Position */
#define SysTick_CALIB_SKEW_Msk (1UL << SysTick_CALIB_SKEW_Pos) /*!< SysTick CALIB: SKEW Mask */
#define SysTick_CALIB_TENMS_Pos 0 /*!< SysTick CALIB: TENMS Position */
#define SysTick_CALIB_TENMS_Msk (0xFFFFFFUL << SysTick_CALIB_TENMS_Pos) /*!< SysTick CALIB: TENMS Mask */
/*@} end of group CMSIS_SysTick */
/** \ingroup CMSIS_core_register
\defgroup CMSIS_CoreDebug Core Debug Registers (CoreDebug)
\brief Cortex-M0 Core Debug Registers (DCB registers, SHCSR, and DFSR)
are only accessible over DAP and not via processor. Therefore
they are not covered by the Cortex-M0 header file.
@{
*/
/*@} end of group CMSIS_CoreDebug */
/** \ingroup CMSIS_core_register
\defgroup CMSIS_core_base Core Definitions
\brief Definitions for base addresses, unions, and structures.
@{
*/
/* Memory mapping of Cortex-M0 Hardware */
#define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */
#define SysTick_BASE (SCS_BASE + 0x0010UL) /*!< SysTick Base Address */
#define NVIC_BASE (SCS_BASE + 0x0100UL) /*!< NVIC Base Address */
#define SCB_BASE (SCS_BASE + 0x0D00UL) /*!< System Control Block Base Address */
#define SCB ((SCB_Type *) SCB_BASE ) /*!< SCB configuration struct */
#define SysTick ((SysTick_Type *) SysTick_BASE ) /*!< SysTick configuration struct */
#define NVIC ((NVIC_Type *) NVIC_BASE ) /*!< NVIC configuration struct */
/*@} */
/*******************************************************************************
* Hardware Abstraction Layer
Core Function Interface contains:
- Core NVIC Functions
- Core SysTick Functions
- Core Register Access Functions
******************************************************************************/
/** \defgroup CMSIS_Core_FunctionInterface Functions and Instructions Reference
*/
/* ########################## NVIC functions #################################### */
/** \ingroup CMSIS_Core_FunctionInterface
\defgroup CMSIS_Core_NVICFunctions NVIC Functions
\brief Functions that manage interrupts and exceptions via the NVIC.
@{
*/
/* Interrupt Priorities are WORD accessible only under ARMv6M */
/* The following MACROS handle generation of the register offset and byte masks */
#define _BIT_SHIFT(IRQn) ( (((uint32_t)(IRQn) ) & 0x03) * 8 )
#define _SHP_IDX(IRQn) ( ((((uint32_t)(IRQn) & 0x0F)-8) >> 2) )
#define _IP_IDX(IRQn) ( ((uint32_t)(IRQn) >> 2) )
/** \brief Enable External Interrupt
The function enables a device-specific interrupt in the NVIC interrupt controller.
\param [in] IRQn External interrupt number. Value cannot be negative.
*/
__STATIC_INLINE void NVIC_EnableIRQ(IRQn_Type IRQn)
{
NVIC->ISER[0] = (1 << ((uint32_t)(IRQn) & 0x1F));
}
/** \brief Disable External Interrupt
The function disables a device-specific interrupt in the NVIC interrupt controller.
\param [in] IRQn External interrupt number. Value cannot be negative.
*/
__STATIC_INLINE void NVIC_DisableIRQ(IRQn_Type IRQn)
{
NVIC->ICER[0] = (1 << ((uint32_t)(IRQn) & 0x1F));
}
/** \brief Get Pending Interrupt
The function reads the pending register in the NVIC and returns the pending bit
for the specified interrupt.
\param [in] IRQn Interrupt number.
\return 0 Interrupt status is not pending.
\return 1 Interrupt status is pending.
*/
__STATIC_INLINE uint32_t NVIC_GetPendingIRQ(IRQn_Type IRQn)
{
return((uint32_t) ((NVIC->ISPR[0] & (1 << ((uint32_t)(IRQn) & 0x1F)))?1:0));
}
/** \brief Set Pending Interrupt
The function sets the pending bit of an external interrupt.
\param [in] IRQn Interrupt number. Value cannot be negative.
*/
__STATIC_INLINE void NVIC_SetPendingIRQ(IRQn_Type IRQn)
{
NVIC->ISPR[0] = (1 << ((uint32_t)(IRQn) & 0x1F));
}
/** \brief Clear Pending Interrupt
The function clears the pending bit of an external interrupt.
\param [in] IRQn External interrupt number. Value cannot be negative.
*/
__STATIC_INLINE void NVIC_ClearPendingIRQ(IRQn_Type IRQn)
{
NVIC->ICPR[0] = (1 << ((uint32_t)(IRQn) & 0x1F)); /* Clear pending interrupt */
}
/** \brief Set Interrupt Priority
The function sets the priority of an interrupt.
\note The priority cannot be set for every core interrupt.
\param [in] IRQn Interrupt number.
\param [in] priority Priority to set.
*/
__STATIC_INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
{
if(IRQn < 0) {
SCB->SHP[_SHP_IDX(IRQn)] = (SCB->SHP[_SHP_IDX(IRQn)] & ~(0xFF << _BIT_SHIFT(IRQn))) |
(((priority << (8 - __NVIC_PRIO_BITS)) & 0xFF) << _BIT_SHIFT(IRQn)); }
else {
NVIC->IP[_IP_IDX(IRQn)] = (NVIC->IP[_IP_IDX(IRQn)] & ~(0xFF << _BIT_SHIFT(IRQn))) |
(((priority << (8 - __NVIC_PRIO_BITS)) & 0xFF) << _BIT_SHIFT(IRQn)); }
}
/** \brief Get Interrupt Priority
The function reads the priority of an interrupt. The interrupt
number can be positive to specify an external (device specific)
interrupt, or negative to specify an internal (core) interrupt.
\param [in] IRQn Interrupt number.
\return Interrupt Priority. Value is aligned automatically to the implemented
priority bits of the microcontroller.
*/
__STATIC_INLINE uint32_t NVIC_GetPriority(IRQn_Type IRQn)
{
if(IRQn < 0) {
return((uint32_t)(((SCB->SHP[_SHP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & 0xFF) >> (8 - __NVIC_PRIO_BITS))); } /* get priority for Cortex-M0 system interrupts */
else {
return((uint32_t)(((NVIC->IP[ _IP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & 0xFF) >> (8 - __NVIC_PRIO_BITS))); } /* get priority for device specific interrupts */
}
/** \brief System Reset
The function initiates a system reset request to reset the MCU.
*/
__STATIC_INLINE void NVIC_SystemReset(void)
{
__DSB(); /* Ensure all outstanding memory accesses included
buffered write are completed before reset */
SCB->AIRCR = ((0x5FA << SCB_AIRCR_VECTKEY_Pos) |
SCB_AIRCR_SYSRESETREQ_Msk);
__DSB(); /* Ensure completion of memory access */
while(1); /* wait until reset */
}
/*@} end of CMSIS_Core_NVICFunctions */
/* ################################## SysTick function ############################################ */
/** \ingroup CMSIS_Core_FunctionInterface
\defgroup CMSIS_Core_SysTickFunctions SysTick Functions
\brief Functions that configure the System.
@{
*/
#if (__Vendor_SysTickConfig == 0)
/** \brief System Tick Configuration
The function initializes the System Timer and its interrupt, and starts the System Tick Timer.
Counter is in free running mode to generate periodic interrupts.
\param [in] ticks Number of ticks between two interrupts.
\return 0 Function succeeded.
\return 1 Function failed.
\note When the variable <b>__Vendor_SysTickConfig</b> is set to 1, then the
function <b>SysTick_Config</b> is not included. In this case, the file <b><i>device</i>.h</b>
must contain a vendor-specific implementation of this function.
*/
__STATIC_INLINE uint32_t SysTick_Config(uint32_t ticks)
{
if ((ticks - 1) > SysTick_LOAD_RELOAD_Msk) return (1); /* Reload value impossible */
SysTick->LOAD = ticks - 1; /* set reload register */
NVIC_SetPriority (SysTick_IRQn, (1<<__NVIC_PRIO_BITS) - 1); /* set Priority for Systick Interrupt */
SysTick->VAL = 0; /* Load the SysTick Counter Value */
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
SysTick_CTRL_TICKINT_Msk |
SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
return (0); /* Function successful */
}
#endif
/*@} end of CMSIS_Core_SysTickFunctions */
#ifdef __cplusplus
}
#endif
#endif /* __CORE_CM0_H_DEPENDANT */
#endif /* __CMSIS_GENERIC */

View File

@ -0,0 +1,637 @@
/**************************************************************************//**
* @file core_cmFunc.h
* @brief CMSIS Cortex-M Core Function Access Header File
* @version V4.00
* @date 28. August 2014
*
* @note
*
******************************************************************************/
/* Copyright (c) 2009 - 2014 ARM LIMITED
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
- Neither the name of ARM nor the names of its contributors may be used
to endorse or promote products derived from this software without
specific prior written permission.
*
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------*/
#ifndef __CORE_CMFUNC_H
#define __CORE_CMFUNC_H
/* ########################### Core Function Access ########################### */
/** \ingroup CMSIS_Core_FunctionInterface
\defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions
@{
*/
#if defined ( __CC_ARM ) /*------------------RealView Compiler -----------------*/
/* ARM armcc specific functions */
#if (__ARMCC_VERSION < 400677)
#error "Please use ARM Compiler Toolchain V4.0.677 or later!"
#endif
/* intrinsic void __enable_irq(); */
/* intrinsic void __disable_irq(); */
/** \brief Get Control Register
This function returns the content of the Control Register.
\return Control Register value
*/
__STATIC_INLINE uint32_t __get_CONTROL(void)
{
register uint32_t __regControl __ASM("control");
return(__regControl);
}
/** \brief Set Control Register
This function writes the given value to the Control Register.
\param [in] control Control Register value to set
*/
__STATIC_INLINE void __set_CONTROL(uint32_t control)
{
register uint32_t __regControl __ASM("control");
__regControl = control;
}
/** \brief Get IPSR Register
This function returns the content of the IPSR Register.
\return IPSR Register value
*/
__STATIC_INLINE uint32_t __get_IPSR(void)
{
register uint32_t __regIPSR __ASM("ipsr");
return(__regIPSR);
}
/** \brief Get APSR Register
This function returns the content of the APSR Register.
\return APSR Register value
*/
__STATIC_INLINE uint32_t __get_APSR(void)
{
register uint32_t __regAPSR __ASM("apsr");
return(__regAPSR);
}
/** \brief Get xPSR Register
This function returns the content of the xPSR Register.
\return xPSR Register value
*/
__STATIC_INLINE uint32_t __get_xPSR(void)
{
register uint32_t __regXPSR __ASM("xpsr");
return(__regXPSR);
}
/** \brief Get Process Stack Pointer
This function returns the current value of the Process Stack Pointer (PSP).
\return PSP Register value
*/
__STATIC_INLINE uint32_t __get_PSP(void)
{
register uint32_t __regProcessStackPointer __ASM("psp");
return(__regProcessStackPointer);
}
/** \brief Set Process Stack Pointer
This function assigns the given value to the Process Stack Pointer (PSP).
\param [in] topOfProcStack Process Stack Pointer value to set
*/
__STATIC_INLINE void __set_PSP(uint32_t topOfProcStack)
{
register uint32_t __regProcessStackPointer __ASM("psp");
__regProcessStackPointer = topOfProcStack;
}
/** \brief Get Main Stack Pointer
This function returns the current value of the Main Stack Pointer (MSP).
\return MSP Register value
*/
__STATIC_INLINE uint32_t __get_MSP(void)
{
register uint32_t __regMainStackPointer __ASM("msp");
return(__regMainStackPointer);
}
/** \brief Set Main Stack Pointer
This function assigns the given value to the Main Stack Pointer (MSP).
\param [in] topOfMainStack Main Stack Pointer value to set
*/
__STATIC_INLINE void __set_MSP(uint32_t topOfMainStack)
{
register uint32_t __regMainStackPointer __ASM("msp");
__regMainStackPointer = topOfMainStack;
}
/** \brief Get Priority Mask
This function returns the current state of the priority mask bit from the Priority Mask Register.
\return Priority Mask value
*/
__STATIC_INLINE uint32_t __get_PRIMASK(void)
{
register uint32_t __regPriMask __ASM("primask");
return(__regPriMask);
}
/** \brief Set Priority Mask
This function assigns the given value to the Priority Mask Register.
\param [in] priMask Priority Mask
*/
__STATIC_INLINE void __set_PRIMASK(uint32_t priMask)
{
register uint32_t __regPriMask __ASM("primask");
__regPriMask = (priMask);
}
#if (__CORTEX_M >= 0x03) || (__CORTEX_SC >= 300)
/** \brief Enable FIQ
This function enables FIQ interrupts by clearing the F-bit in the CPSR.
Can only be executed in Privileged modes.
*/
#define __enable_fault_irq __enable_fiq
/** \brief Disable FIQ
This function disables FIQ interrupts by setting the F-bit in the CPSR.
Can only be executed in Privileged modes.
*/
#define __disable_fault_irq __disable_fiq
/** \brief Get Base Priority
This function returns the current value of the Base Priority register.
\return Base Priority register value
*/
__STATIC_INLINE uint32_t __get_BASEPRI(void)
{
register uint32_t __regBasePri __ASM("basepri");
return(__regBasePri);
}
/** \brief Set Base Priority
This function assigns the given value to the Base Priority register.
\param [in] basePri Base Priority value to set
*/
__STATIC_INLINE void __set_BASEPRI(uint32_t basePri)
{
register uint32_t __regBasePri __ASM("basepri");
__regBasePri = (basePri & 0xff);
}
/** \brief Get Fault Mask
This function returns the current value of the Fault Mask register.
\return Fault Mask register value
*/
__STATIC_INLINE uint32_t __get_FAULTMASK(void)
{
register uint32_t __regFaultMask __ASM("faultmask");
return(__regFaultMask);
}
/** \brief Set Fault Mask
This function assigns the given value to the Fault Mask register.
\param [in] faultMask Fault Mask value to set
*/
__STATIC_INLINE void __set_FAULTMASK(uint32_t faultMask)
{
register uint32_t __regFaultMask __ASM("faultmask");
__regFaultMask = (faultMask & (uint32_t)1);
}
#endif /* (__CORTEX_M >= 0x03) || (__CORTEX_SC >= 300) */
#if (__CORTEX_M == 0x04) || (__CORTEX_M == 0x07)
/** \brief Get FPSCR
This function returns the current value of the Floating Point Status/Control register.
\return Floating Point Status/Control register value
*/
__STATIC_INLINE uint32_t __get_FPSCR(void)
{
#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
register uint32_t __regfpscr __ASM("fpscr");
return(__regfpscr);
#else
return(0);
#endif
}
/** \brief Set FPSCR
This function assigns the given value to the Floating Point Status/Control register.
\param [in] fpscr Floating Point Status/Control value to set
*/
__STATIC_INLINE void __set_FPSCR(uint32_t fpscr)
{
#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
register uint32_t __regfpscr __ASM("fpscr");
__regfpscr = (fpscr);
#endif
}
#endif /* (__CORTEX_M == 0x04) || (__CORTEX_M == 0x07) */
#elif defined ( __GNUC__ ) /*------------------ GNU Compiler ---------------------*/
/* GNU gcc specific functions */
/** \brief Enable IRQ Interrupts
This function enables IRQ interrupts by clearing the I-bit in the CPSR.
Can only be executed in Privileged modes.
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __enable_irq(void)
{
__ASM volatile ("cpsie i" : : : "memory");
}
/** \brief Disable IRQ Interrupts
This function disables IRQ interrupts by setting the I-bit in the CPSR.
Can only be executed in Privileged modes.
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __disable_irq(void)
{
__ASM volatile ("cpsid i" : : : "memory");
}
/** \brief Get Control Register
This function returns the content of the Control Register.
\return Control Register value
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_CONTROL(void)
{
uint32_t result;
__ASM volatile ("MRS %0, control" : "=r" (result) );
return(result);
}
/** \brief Set Control Register
This function writes the given value to the Control Register.
\param [in] control Control Register value to set
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_CONTROL(uint32_t control)
{
__ASM volatile ("MSR control, %0" : : "r" (control) : "memory");
}
/** \brief Get IPSR Register
This function returns the content of the IPSR Register.
\return IPSR Register value
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_IPSR(void)
{
uint32_t result;
__ASM volatile ("MRS %0, ipsr" : "=r" (result) );
return(result);
}
/** \brief Get APSR Register
This function returns the content of the APSR Register.
\return APSR Register value
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_APSR(void)
{
uint32_t result;
__ASM volatile ("MRS %0, apsr" : "=r" (result) );
return(result);
}
/** \brief Get xPSR Register
This function returns the content of the xPSR Register.
\return xPSR Register value
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_xPSR(void)
{
uint32_t result;
__ASM volatile ("MRS %0, xpsr" : "=r" (result) );
return(result);
}
/** \brief Get Process Stack Pointer
This function returns the current value of the Process Stack Pointer (PSP).
\return PSP Register value
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_PSP(void)
{
register uint32_t result;
__ASM volatile ("MRS %0, psp\n" : "=r" (result) );
return(result);
}
/** \brief Set Process Stack Pointer
This function assigns the given value to the Process Stack Pointer (PSP).
\param [in] topOfProcStack Process Stack Pointer value to set
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_PSP(uint32_t topOfProcStack)
{
__ASM volatile ("MSR psp, %0\n" : : "r" (topOfProcStack) : "sp");
}
/** \brief Get Main Stack Pointer
This function returns the current value of the Main Stack Pointer (MSP).
\return MSP Register value
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_MSP(void)
{
register uint32_t result;
__ASM volatile ("MRS %0, msp\n" : "=r" (result) );
return(result);
}
/** \brief Set Main Stack Pointer
This function assigns the given value to the Main Stack Pointer (MSP).
\param [in] topOfMainStack Main Stack Pointer value to set
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_MSP(uint32_t topOfMainStack)
{
__ASM volatile ("MSR msp, %0\n" : : "r" (topOfMainStack) : "sp");
}
/** \brief Get Priority Mask
This function returns the current state of the priority mask bit from the Priority Mask Register.
\return Priority Mask value
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_PRIMASK(void)
{
uint32_t result;
__ASM volatile ("MRS %0, primask" : "=r" (result) );
return(result);
}
/** \brief Set Priority Mask
This function assigns the given value to the Priority Mask Register.
\param [in] priMask Priority Mask
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_PRIMASK(uint32_t priMask)
{
__ASM volatile ("MSR primask, %0" : : "r" (priMask) : "memory");
}
#if (__CORTEX_M >= 0x03)
/** \brief Enable FIQ
This function enables FIQ interrupts by clearing the F-bit in the CPSR.
Can only be executed in Privileged modes.
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __enable_fault_irq(void)
{
__ASM volatile ("cpsie f" : : : "memory");
}
/** \brief Disable FIQ
This function disables FIQ interrupts by setting the F-bit in the CPSR.
Can only be executed in Privileged modes.
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __disable_fault_irq(void)
{
__ASM volatile ("cpsid f" : : : "memory");
}
/** \brief Get Base Priority
This function returns the current value of the Base Priority register.
\return Base Priority register value
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_BASEPRI(void)
{
uint32_t result;
__ASM volatile ("MRS %0, basepri_max" : "=r" (result) );
return(result);
}
/** \brief Set Base Priority
This function assigns the given value to the Base Priority register.
\param [in] basePri Base Priority value to set
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_BASEPRI(uint32_t value)
{
__ASM volatile ("MSR basepri, %0" : : "r" (value) : "memory");
}
/** \brief Get Fault Mask
This function returns the current value of the Fault Mask register.
\return Fault Mask register value
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_FAULTMASK(void)
{
uint32_t result;
__ASM volatile ("MRS %0, faultmask" : "=r" (result) );
return(result);
}
/** \brief Set Fault Mask
This function assigns the given value to the Fault Mask register.
\param [in] faultMask Fault Mask value to set
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_FAULTMASK(uint32_t faultMask)
{
__ASM volatile ("MSR faultmask, %0" : : "r" (faultMask) : "memory");
}
#endif /* (__CORTEX_M >= 0x03) */
#if (__CORTEX_M == 0x04) || (__CORTEX_M == 0x07)
/** \brief Get FPSCR
This function returns the current value of the Floating Point Status/Control register.
\return Floating Point Status/Control register value
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_FPSCR(void)
{
#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
uint32_t result;
/* Empty asm statement works as a scheduling barrier */
__ASM volatile ("");
__ASM volatile ("VMRS %0, fpscr" : "=r" (result) );
__ASM volatile ("");
return(result);
#else
return(0);
#endif
}
/** \brief Set FPSCR
This function assigns the given value to the Floating Point Status/Control register.
\param [in] fpscr Floating Point Status/Control value to set
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_FPSCR(uint32_t fpscr)
{
#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
/* Empty asm statement works as a scheduling barrier */
__ASM volatile ("");
__ASM volatile ("VMSR fpscr, %0" : : "r" (fpscr) : "vfpcc");
__ASM volatile ("");
#endif
}
#endif /* (__CORTEX_M == 0x04) || (__CORTEX_M == 0x07) */
#elif defined ( __ICCARM__ ) /*------------------ ICC Compiler -------------------*/
/* IAR iccarm specific functions */
#include <cmsis_iar.h>
#elif defined ( __TMS470__ ) /*---------------- TI CCS Compiler ------------------*/
/* TI CCS specific functions */
#include <cmsis_ccs.h>
#elif defined ( __TASKING__ ) /*------------------ TASKING Compiler --------------*/
/* TASKING carm specific functions */
/*
* The CMSIS functions have been implemented as intrinsics in the compiler.
* Please use "carm -?i" to get an up to date list of all intrinsics,
* Including the CMSIS ones.
*/
#elif defined ( __CSMC__ ) /*------------------ COSMIC Compiler -------------------*/
/* Cosmic specific functions */
#include <cmsis_csm.h>
#endif
/*@} end of CMSIS_Core_RegAccFunctions */
#endif /* __CORE_CMFUNC_H */

View File

@ -0,0 +1,880 @@
/**************************************************************************//**
* @file core_cmInstr.h
* @brief CMSIS Cortex-M Core Instruction Access Header File
* @version V4.00
* @date 28. August 2014
*
* @note
*
******************************************************************************/
/* Copyright (c) 2009 - 2014 ARM LIMITED
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
- Neither the name of ARM nor the names of its contributors may be used
to endorse or promote products derived from this software without
specific prior written permission.
*
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------*/
#ifndef __CORE_CMINSTR_H
#define __CORE_CMINSTR_H
/* ########################## Core Instruction Access ######################### */
/** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface
Access to dedicated instructions
@{
*/
#if defined ( __CC_ARM ) /*------------------RealView Compiler -----------------*/
/* ARM armcc specific functions */
#if (__ARMCC_VERSION < 400677)
#error "Please use ARM Compiler Toolchain V4.0.677 or later!"
#endif
/** \brief No Operation
No Operation does nothing. This instruction can be used for code alignment purposes.
*/
#define __NOP __nop
/** \brief Wait For Interrupt
Wait For Interrupt is a hint instruction that suspends execution
until one of a number of events occurs.
*/
#define __WFI __wfi
/** \brief Wait For Event
Wait For Event is a hint instruction that permits the processor to enter
a low-power state until one of a number of events occurs.
*/
#define __WFE __wfe
/** \brief Send Event
Send Event is a hint instruction. It causes an event to be signaled to the CPU.
*/
#define __SEV __sev
/** \brief Instruction Synchronization Barrier
Instruction Synchronization Barrier flushes the pipeline in the processor,
so that all instructions following the ISB are fetched from cache or
memory, after the instruction has been completed.
*/
#define __ISB() __isb(0xF)
/** \brief Data Synchronization Barrier
This function acts as a special kind of Data Memory Barrier.
It completes when all explicit memory accesses before this instruction complete.
*/
#define __DSB() __dsb(0xF)
/** \brief Data Memory Barrier
This function ensures the apparent order of the explicit memory operations before
and after the instruction, without ensuring their completion.
*/
#define __DMB() __dmb(0xF)
/** \brief Reverse byte order (32 bit)
This function reverses the byte order in integer value.
\param [in] value Value to reverse
\return Reversed value
*/
#define __REV __rev
/** \brief Reverse byte order (16 bit)
This function reverses the byte order in two unsigned short values.
\param [in] value Value to reverse
\return Reversed value
*/
#ifndef __NO_EMBEDDED_ASM
__attribute__((section(".rev16_text"))) __STATIC_INLINE __ASM uint32_t __REV16(uint32_t value)
{
rev16 r0, r0
bx lr
}
#endif
/** \brief Reverse byte order in signed short value
This function reverses the byte order in a signed short value with sign extension to integer.
\param [in] value Value to reverse
\return Reversed value
*/
#ifndef __NO_EMBEDDED_ASM
__attribute__((section(".revsh_text"))) __STATIC_INLINE __ASM int32_t __REVSH(int32_t value)
{
revsh r0, r0
bx lr
}
#endif
/** \brief Rotate Right in unsigned value (32 bit)
This function Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits.
\param [in] value Value to rotate
\param [in] value Number of Bits to rotate
\return Rotated value
*/
#define __ROR __ror
/** \brief Breakpoint
This function causes the processor to enter Debug state.
Debug tools can use this to investigate system state when the instruction at a particular address is reached.
\param [in] value is ignored by the processor.
If required, a debugger can use it to store additional information about the breakpoint.
*/
#define __BKPT(value) __breakpoint(value)
#if (__CORTEX_M >= 0x03) || (__CORTEX_SC >= 300)
/** \brief Reverse bit order of value
This function reverses the bit order of the given value.
\param [in] value Value to reverse
\return Reversed value
*/
#define __RBIT __rbit
/** \brief LDR Exclusive (8 bit)
This function executes a exclusive LDR instruction for 8 bit value.
\param [in] ptr Pointer to data
\return value of type uint8_t at (*ptr)
*/
#define __LDREXB(ptr) ((uint8_t ) __ldrex(ptr))
/** \brief LDR Exclusive (16 bit)
This function executes a exclusive LDR instruction for 16 bit values.
\param [in] ptr Pointer to data
\return value of type uint16_t at (*ptr)
*/
#define __LDREXH(ptr) ((uint16_t) __ldrex(ptr))
/** \brief LDR Exclusive (32 bit)
This function executes a exclusive LDR instruction for 32 bit values.
\param [in] ptr Pointer to data
\return value of type uint32_t at (*ptr)
*/
#define __LDREXW(ptr) ((uint32_t ) __ldrex(ptr))
/** \brief STR Exclusive (8 bit)
This function executes a exclusive STR instruction for 8 bit values.
\param [in] value Value to store
\param [in] ptr Pointer to location
\return 0 Function succeeded
\return 1 Function failed
*/
#define __STREXB(value, ptr) __strex(value, ptr)
/** \brief STR Exclusive (16 bit)
This function executes a exclusive STR instruction for 16 bit values.
\param [in] value Value to store
\param [in] ptr Pointer to location
\return 0 Function succeeded
\return 1 Function failed
*/
#define __STREXH(value, ptr) __strex(value, ptr)
/** \brief STR Exclusive (32 bit)
This function executes a exclusive STR instruction for 32 bit values.
\param [in] value Value to store
\param [in] ptr Pointer to location
\return 0 Function succeeded
\return 1 Function failed
*/
#define __STREXW(value, ptr) __strex(value, ptr)
/** \brief Remove the exclusive lock
This function removes the exclusive lock which is created by LDREX.
*/
#define __CLREX __clrex
/** \brief Signed Saturate
This function saturates a signed value.
\param [in] value Value to be saturated
\param [in] sat Bit position to saturate to (1..32)
\return Saturated value
*/
#define __SSAT __ssat
/** \brief Unsigned Saturate
This function saturates an unsigned value.
\param [in] value Value to be saturated
\param [in] sat Bit position to saturate to (0..31)
\return Saturated value
*/
#define __USAT __usat
/** \brief Count leading zeros
This function counts the number of leading zeros of a data value.
\param [in] value Value to count the leading zeros
\return number of leading zeros in value
*/
#define __CLZ __clz
/** \brief Rotate Right with Extend (32 bit)
This function moves each bit of a bitstring right by one bit. The carry input is shifted in at the left end of the bitstring.
\param [in] value Value to rotate
\return Rotated value
*/
#ifndef __NO_EMBEDDED_ASM
__attribute__((section(".rrx_text"))) __STATIC_INLINE __ASM uint32_t __RRX(uint32_t value)
{
rrx r0, r0
bx lr
}
#endif
/** \brief LDRT Unprivileged (8 bit)
This function executes a Unprivileged LDRT instruction for 8 bit value.
\param [in] ptr Pointer to data
\return value of type uint8_t at (*ptr)
*/
#define __LDRBT(ptr) ((uint8_t ) __ldrt(ptr))
/** \brief LDRT Unprivileged (16 bit)
This function executes a Unprivileged LDRT instruction for 16 bit values.
\param [in] ptr Pointer to data
\return value of type uint16_t at (*ptr)
*/
#define __LDRHT(ptr) ((uint16_t) __ldrt(ptr))
/** \brief LDRT Unprivileged (32 bit)
This function executes a Unprivileged LDRT instruction for 32 bit values.
\param [in] ptr Pointer to data
\return value of type uint32_t at (*ptr)
*/
#define __LDRT(ptr) ((uint32_t ) __ldrt(ptr))
/** \brief STRT Unprivileged (8 bit)
This function executes a Unprivileged STRT instruction for 8 bit values.
\param [in] value Value to store
\param [in] ptr Pointer to location
*/
#define __STRBT(value, ptr) __strt(value, ptr)
/** \brief STRT Unprivileged (16 bit)
This function executes a Unprivileged STRT instruction for 16 bit values.
\param [in] value Value to store
\param [in] ptr Pointer to location
*/
#define __STRHT(value, ptr) __strt(value, ptr)
/** \brief STRT Unprivileged (32 bit)
This function executes a Unprivileged STRT instruction for 32 bit values.
\param [in] value Value to store
\param [in] ptr Pointer to location
*/
#define __STRT(value, ptr) __strt(value, ptr)
#endif /* (__CORTEX_M >= 0x03) || (__CORTEX_SC >= 300) */
#elif defined ( __GNUC__ ) /*------------------ GNU Compiler ---------------------*/
/* GNU gcc specific functions */
/* Define macros for porting to both thumb1 and thumb2.
* For thumb1, use low register (r0-r7), specified by constrant "l"
* Otherwise, use general registers, specified by constrant "r" */
#if defined (__thumb__) && !defined (__thumb2__)
#define __CMSIS_GCC_OUT_REG(r) "=l" (r)
#define __CMSIS_GCC_USE_REG(r) "l" (r)
#else
#define __CMSIS_GCC_OUT_REG(r) "=r" (r)
#define __CMSIS_GCC_USE_REG(r) "r" (r)
#endif
/** \brief No Operation
No Operation does nothing. This instruction can be used for code alignment purposes.
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __NOP(void)
{
__ASM volatile ("nop");
}
/** \brief Wait For Interrupt
Wait For Interrupt is a hint instruction that suspends execution
until one of a number of events occurs.
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __WFI(void)
{
__ASM volatile ("wfi");
}
/** \brief Wait For Event
Wait For Event is a hint instruction that permits the processor to enter
a low-power state until one of a number of events occurs.
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __WFE(void)
{
__ASM volatile ("wfe");
}
/** \brief Send Event
Send Event is a hint instruction. It causes an event to be signaled to the CPU.
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __SEV(void)
{
__ASM volatile ("sev");
}
/** \brief Instruction Synchronization Barrier
Instruction Synchronization Barrier flushes the pipeline in the processor,
so that all instructions following the ISB are fetched from cache or
memory, after the instruction has been completed.
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __ISB(void)
{
__ASM volatile ("isb");
}
/** \brief Data Synchronization Barrier
This function acts as a special kind of Data Memory Barrier.
It completes when all explicit memory accesses before this instruction complete.
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __DSB(void)
{
__ASM volatile ("dsb");
}
/** \brief Data Memory Barrier
This function ensures the apparent order of the explicit memory operations before
and after the instruction, without ensuring their completion.
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __DMB(void)
{
__ASM volatile ("dmb");
}
/** \brief Reverse byte order (32 bit)
This function reverses the byte order in integer value.
\param [in] value Value to reverse
\return Reversed value
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __REV(uint32_t value)
{
#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
return __builtin_bswap32(value);
#else
uint32_t result;
__ASM volatile ("rev %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
return(result);
#endif
}
/** \brief Reverse byte order (16 bit)
This function reverses the byte order in two unsigned short values.
\param [in] value Value to reverse
\return Reversed value
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __REV16(uint32_t value)
{
uint32_t result;
__ASM volatile ("rev16 %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
return(result);
}
/** \brief Reverse byte order in signed short value
This function reverses the byte order in a signed short value with sign extension to integer.
\param [in] value Value to reverse
\return Reversed value
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE int32_t __REVSH(int32_t value)
{
#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
return (short)__builtin_bswap16(value);
#else
uint32_t result;
__ASM volatile ("revsh %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
return(result);
#endif
}
/** \brief Rotate Right in unsigned value (32 bit)
This function Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits.
\param [in] value Value to rotate
\param [in] value Number of Bits to rotate
\return Rotated value
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __ROR(uint32_t op1, uint32_t op2)
{
return (op1 >> op2) | (op1 << (32 - op2));
}
/** \brief Breakpoint
This function causes the processor to enter Debug state.
Debug tools can use this to investigate system state when the instruction at a particular address is reached.
\param [in] value is ignored by the processor.
If required, a debugger can use it to store additional information about the breakpoint.
*/
#define __BKPT(value) __ASM volatile ("bkpt "#value)
#if (__CORTEX_M >= 0x03) || (__CORTEX_SC >= 300)
/** \brief Reverse bit order of value
This function reverses the bit order of the given value.
\param [in] value Value to reverse
\return Reversed value
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __RBIT(uint32_t value)
{
uint32_t result;
__ASM volatile ("rbit %0, %1" : "=r" (result) : "r" (value) );
return(result);
}
/** \brief LDR Exclusive (8 bit)
This function executes a exclusive LDR instruction for 8 bit value.
\param [in] ptr Pointer to data
\return value of type uint8_t at (*ptr)
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint8_t __LDREXB(volatile uint8_t *addr)
{
uint32_t result;
#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
__ASM volatile ("ldrexb %0, %1" : "=r" (result) : "Q" (*addr) );
#else
/* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
accepted by assembler. So has to use following less efficient pattern.
*/
__ASM volatile ("ldrexb %0, [%1]" : "=r" (result) : "r" (addr) : "memory" );
#endif
return ((uint8_t) result); /* Add explicit type cast here */
}
/** \brief LDR Exclusive (16 bit)
This function executes a exclusive LDR instruction for 16 bit values.
\param [in] ptr Pointer to data
\return value of type uint16_t at (*ptr)
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint16_t __LDREXH(volatile uint16_t *addr)
{
uint32_t result;
#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
__ASM volatile ("ldrexh %0, %1" : "=r" (result) : "Q" (*addr) );
#else
/* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
accepted by assembler. So has to use following less efficient pattern.
*/
__ASM volatile ("ldrexh %0, [%1]" : "=r" (result) : "r" (addr) : "memory" );
#endif
return ((uint16_t) result); /* Add explicit type cast here */
}
/** \brief LDR Exclusive (32 bit)
This function executes a exclusive LDR instruction for 32 bit values.
\param [in] ptr Pointer to data
\return value of type uint32_t at (*ptr)
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __LDREXW(volatile uint32_t *addr)
{
uint32_t result;
__ASM volatile ("ldrex %0, %1" : "=r" (result) : "Q" (*addr) );
return(result);
}
/** \brief STR Exclusive (8 bit)
This function executes a exclusive STR instruction for 8 bit values.
\param [in] value Value to store
\param [in] ptr Pointer to location
\return 0 Function succeeded
\return 1 Function failed
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __STREXB(uint8_t value, volatile uint8_t *addr)
{
uint32_t result;
__ASM volatile ("strexb %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" ((uint32_t)value) );
return(result);
}
/** \brief STR Exclusive (16 bit)
This function executes a exclusive STR instruction for 16 bit values.
\param [in] value Value to store
\param [in] ptr Pointer to location
\return 0 Function succeeded
\return 1 Function failed
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __STREXH(uint16_t value, volatile uint16_t *addr)
{
uint32_t result;
__ASM volatile ("strexh %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" ((uint32_t)value) );
return(result);
}
/** \brief STR Exclusive (32 bit)
This function executes a exclusive STR instruction for 32 bit values.
\param [in] value Value to store
\param [in] ptr Pointer to location
\return 0 Function succeeded
\return 1 Function failed
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __STREXW(uint32_t value, volatile uint32_t *addr)
{
uint32_t result;
__ASM volatile ("strex %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" (value) );
return(result);
}
/** \brief Remove the exclusive lock
This function removes the exclusive lock which is created by LDREX.
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __CLREX(void)
{
__ASM volatile ("clrex" ::: "memory");
}
/** \brief Signed Saturate
This function saturates a signed value.
\param [in] value Value to be saturated
\param [in] sat Bit position to saturate to (1..32)
\return Saturated value
*/
#define __SSAT(ARG1,ARG2) \
({ \
uint32_t __RES, __ARG1 = (ARG1); \
__ASM ("ssat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \
__RES; \
})
/** \brief Unsigned Saturate
This function saturates an unsigned value.
\param [in] value Value to be saturated
\param [in] sat Bit position to saturate to (0..31)
\return Saturated value
*/
#define __USAT(ARG1,ARG2) \
({ \
uint32_t __RES, __ARG1 = (ARG1); \
__ASM ("usat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \
__RES; \
})
/** \brief Count leading zeros
This function counts the number of leading zeros of a data value.
\param [in] value Value to count the leading zeros
\return number of leading zeros in value
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint8_t __CLZ(uint32_t value)
{
uint32_t result;
__ASM volatile ("clz %0, %1" : "=r" (result) : "r" (value) );
return ((uint8_t) result); /* Add explicit type cast here */
}
/** \brief Rotate Right with Extend (32 bit)
This function moves each bit of a bitstring right by one bit. The carry input is shifted in at the left end of the bitstring.
\param [in] value Value to rotate
\return Rotated value
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __RRX(uint32_t value)
{
uint32_t result;
__ASM volatile ("rrx %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
return(result);
}
/** \brief LDRT Unprivileged (8 bit)
This function executes a Unprivileged LDRT instruction for 8 bit value.
\param [in] ptr Pointer to data
\return value of type uint8_t at (*ptr)
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint8_t __LDRBT(volatile uint8_t *addr)
{
uint32_t result;
#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
__ASM volatile ("ldrbt %0, %1" : "=r" (result) : "Q" (*addr) );
#else
/* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
accepted by assembler. So has to use following less efficient pattern.
*/
__ASM volatile ("ldrbt %0, [%1]" : "=r" (result) : "r" (addr) : "memory" );
#endif
return ((uint8_t) result); /* Add explicit type cast here */
}
/** \brief LDRT Unprivileged (16 bit)
This function executes a Unprivileged LDRT instruction for 16 bit values.
\param [in] ptr Pointer to data
\return value of type uint16_t at (*ptr)
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint16_t __LDRHT(volatile uint16_t *addr)
{
uint32_t result;
#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
__ASM volatile ("ldrht %0, %1" : "=r" (result) : "Q" (*addr) );
#else
/* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
accepted by assembler. So has to use following less efficient pattern.
*/
__ASM volatile ("ldrht %0, [%1]" : "=r" (result) : "r" (addr) : "memory" );
#endif
return ((uint16_t) result); /* Add explicit type cast here */
}
/** \brief LDRT Unprivileged (32 bit)
This function executes a Unprivileged LDRT instruction for 32 bit values.
\param [in] ptr Pointer to data
\return value of type uint32_t at (*ptr)
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __LDRT(volatile uint32_t *addr)
{
uint32_t result;
__ASM volatile ("ldrt %0, %1" : "=r" (result) : "Q" (*addr) );
return(result);
}
/** \brief STRT Unprivileged (8 bit)
This function executes a Unprivileged STRT instruction for 8 bit values.
\param [in] value Value to store
\param [in] ptr Pointer to location
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __STRBT(uint8_t value, volatile uint8_t *addr)
{
__ASM volatile ("strbt %1, %0" : "=Q" (*addr) : "r" ((uint32_t)value) );
}
/** \brief STRT Unprivileged (16 bit)
This function executes a Unprivileged STRT instruction for 16 bit values.
\param [in] value Value to store
\param [in] ptr Pointer to location
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __STRHT(uint16_t value, volatile uint16_t *addr)
{
__ASM volatile ("strht %1, %0" : "=Q" (*addr) : "r" ((uint32_t)value) );
}
/** \brief STRT Unprivileged (32 bit)
This function executes a Unprivileged STRT instruction for 32 bit values.
\param [in] value Value to store
\param [in] ptr Pointer to location
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __STRT(uint32_t value, volatile uint32_t *addr)
{
__ASM volatile ("strt %1, %0" : "=Q" (*addr) : "r" (value) );
}
#endif /* (__CORTEX_M >= 0x03) || (__CORTEX_SC >= 300) */
#elif defined ( __ICCARM__ ) /*------------------ ICC Compiler -------------------*/
/* IAR iccarm specific functions */
#include <cmsis_iar.h>
#elif defined ( __TMS470__ ) /*---------------- TI CCS Compiler ------------------*/
/* TI CCS specific functions */
#include <cmsis_ccs.h>
#elif defined ( __TASKING__ ) /*------------------ TASKING Compiler --------------*/
/* TASKING carm specific functions */
/*
* The CMSIS functions have been implemented as intrinsics in the compiler.
* Please use "carm -?i" to get an up to date list of all intrinsics,
* Including the CMSIS ones.
*/
#elif defined ( __CSMC__ ) /*------------------ COSMIC Compiler -------------------*/
/* Cosmic specific functions */
#include <cmsis_csm.h>
#endif
/*@}*/ /* end of group CMSIS_Core_InstructionInterface */
#endif /* __CORE_CMINSTR_H */

View File

@ -0,0 +1,16 @@
Import('RTT_ROOT')
Import('rtconfig')
from building import *
cwd = GetCurrentDir()
# The set of source files associated with this SConscript file.
src = Split("""
""")
CPPPATH = [cwd + '/StdPeriphDriver/inc', cwd + '/CMSIS/Include']
src += ['Startup/startup_ARMCM0.s']
src += Glob('StdPeriphDriver/*.c')
group = DefineGroup('Libraries', src, depend = [''], CPPPATH = CPPPATH)
Return('group')

View File

@ -0,0 +1,237 @@
;/**************************************************************************//**
; * @file startup_ARMCM0.s
; * @brief CMSIS Core Device Startup File for
; * ARMCM0 Device Series
; * @version V1.08
; * @date 23. November 2012
; *
; * @note
; *
; ******************************************************************************/
;/* Copyright (c) 2011 - 2012 ARM LIMITED
;
; All rights reserved.
; Redistribution and use in source and binary forms, with or without
; modification, are permitted provided that the following conditions are met:
; - Redistributions of source code must retain the above copyright
; notice, this list of conditions and the following disclaimer.
; - Redistributions in binary form must reproduce the above copyright
; notice, this list of conditions and the following disclaimer in the
; documentation and/or other materials provided with the distribution.
; - Neither the name of ARM nor the names of its contributors may be used
; to endorse or promote products derived from this software without
; specific prior written permission.
; *
; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
; ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
; CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
; ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
; POSSIBILITY OF SUCH DAMAGE.
; ---------------------------------------------------------------------------*/
;/*
;//-------- <<< Use Configuration Wizard in Context Menu >>> ------------------
;*/
; <h> Stack Configuration
; <o> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>
Stack_Size EQU 0x00000400
AREA STACK, NOINIT, READWRITE, ALIGN=3
Stack_Mem SPACE Stack_Size
__initial_sp EQU 0x20008000
; <h> Heap Configuration
; <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>
Heap_Size EQU 0x00000400
AREA HEAP, NOINIT, READWRITE, ALIGN=3
__heap_base
Heap_Mem SPACE Heap_Size
__heap_limit
PRESERVE8
THUMB
; Vector Table Mapped to Address 0 at Reset
AREA RESET, DATA, READONLY
EXPORT __Vectors
EXPORT __Vectors_End
EXPORT __Vectors_Size
__Vectors DCD __initial_sp ; Top of Stack
DCD Reset_Handler ; Reset Handler
DCD NMI_Handler ; NMI Handler
DCD HardFault_Handler ; Hard Fault Handler
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD SVC_Handler ; SVCall Handler
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD PendSV_Handler ; PendSV Handler
DCD SysTick_Handler ; SysTick Handler
; External Interrupts
DCD TMR0_IRQHandler ; 0: TMR0
DCD GPIO_IRQHandler ; 1: GPIO
DCD SLAVE_IRQHandler ; 2: SLAVE
DCD SPI0_IRQHandler ; 3: SPI0
DCD BB_IRQHandler ; 4: BB
DCD LLE_IRQHandler ; 5: LLE
DCD USB_IRQHandler ; 6: USB
DCD ETH_IRQHandler ; 7: ETH
DCD TMR1_IRQHandler ; 8: TMR1
DCD TMR2_IRQHandler ; 9: TMR2
DCD UART0_IRQHandler ; 10: UART0
DCD UART1_IRQHandler ; 11: UART1
DCD RTC_IRQHandler ; 12: RTC
DCD ADC_IRQHandler ; 13: ADC
DCD SPI1_IRQHandler ; 14: SPI1
DCD LED_IRQHandler ; 15: LED
DCD TMR3_IRQHandler ; 16: TMR3
DCD UART2_IRQHandler ; 17: UART2
DCD UART3_IRQHandler ; 18: UART3
DCD WDT_IRQHandler ; 19: WDT
__Vectors_End
__Vectors_Size EQU __Vectors_End - __Vectors
AREA |.text|, CODE, READONLY
; Reset Handler
Reset_Handler PROC
EXPORT Reset_Handler [WEAK]
IMPORT SystemInit
IMPORT __main
;LDR R0, =0x1007058
;MOV SP, R0
LDR R0, =SystemInit
BLX R0
LDR R0, =__main
BX R0
ENDP
; Dummy Exception Handlers (infinite loops which can be modified)
NMI_Handler PROC
EXPORT NMI_Handler [WEAK]
B .
ENDP
HardFault_Handler\
PROC
EXPORT HardFault_Handler [WEAK]
; B .
ENDP
SVC_Handler PROC
EXPORT SVC_Handler [WEAK]
B .
ENDP
PendSV_Handler PROC
EXPORT PendSV_Handler [WEAK]
B .
ENDP
SysTick_Handler PROC
EXPORT SysTick_Handler [WEAK]
B .
ENDP
Default_Handler PROC
EXPORT TMR0_IRQHandler [WEAK]; 0: TMR0
EXPORT GPIO_IRQHandler [WEAK]; 1: GPIO
EXPORT SLAVE_IRQHandler [WEAK]; 2: SLAVE
EXPORT SPI0_IRQHandler [WEAK]; 3: SPI0
EXPORT BB_IRQHandler [WEAK]; 4: BB
EXPORT LLE_IRQHandler [WEAK]; 5: LLE
EXPORT USB_IRQHandler [WEAK]; 6: USB
EXPORT ETH_IRQHandler [WEAK]; 7: ETH
EXPORT TMR1_IRQHandler [WEAK]; 8: TMR1
EXPORT TMR2_IRQHandler [WEAK]; 9: TMR2
EXPORT UART0_IRQHandler [WEAK]; 10: UART0
EXPORT UART1_IRQHandler [WEAK]; 11: UART1
EXPORT RTC_IRQHandler [WEAK]; 12: RTC
EXPORT ADC_IRQHandler [WEAK]; 13: ADC
EXPORT SPI1_IRQHandler [WEAK]; 14: SPI1
EXPORT LED_IRQHandler [WEAK]; 15: LED
EXPORT TMR3_IRQHandler [WEAK]; 16: TMR3
EXPORT UART2_IRQHandler [WEAK]; 17: UART2
EXPORT UART3_IRQHandler [WEAK]; 18: UART3
EXPORT WDT_IRQHandler [WEAK]; 19: WDT
TMR0_IRQHandler ; 0: TMR0
GPIO_IRQHandler ; 1: GPIO
SLAVE_IRQHandler ; 2: SLAVE
SPI0_IRQHandler ; 3: SPI0
BB_IRQHandler ; 4: BB
LLE_IRQHandler ; 5: LLE
USB_IRQHandler ; 6: USB
ETH_IRQHandler ; 7: ETH
TMR1_IRQHandler ; 8: TMR1
TMR2_IRQHandler ; 9: TMR2
UART0_IRQHandler ; 10: UART0
UART1_IRQHandler ; 11: UART1
RTC_IRQHandler ; 12: RTC
ADC_IRQHandler ; 13: ADC
SPI1_IRQHandler ; 14: SPI1
LED_IRQHandler ; 15: LED
TMR3_IRQHandler ; 16: TMR3
UART2_IRQHandler ; 17: UART2
UART3_IRQHandler ; 18: UART3
WDT_IRQHandler ; 19: WDT
B .
ENDP
ALIGN
; User Initial Stack & Heap
IF :DEF:__MICROLIB
EXPORT __initial_sp
EXPORT __heap_base
EXPORT __heap_limit
ELSE
IMPORT __use_two_region_memory
EXPORT __user_initial_stackheap
__user_initial_stackheap PROC
LDR R0, = Heap_Mem
LDR R1, =(Stack_Mem + Stack_Size)
LDR R2, = (Heap_Mem + Heap_Size)
LDR R3, = Stack_Mem
BX LR
ENDP
ALIGN
ENDIF
END

View File

@ -0,0 +1,223 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : CH57x_adc.c
* Author : WCH
* Version : V1.1
* Date : 2020/04/01
* Description
*******************************************************************************/
#include "CH57x_common.h"
/*******************************************************************************
* Function Name : ADC_DataCalib_Rough
* Description : ,
* 使 PA5(AIN1)
* Input : None
* Return :
*******************************************************************************/
signed short ADC_DataCalib_Rough( void ) // 采样数据粗调,获取偏差值
{
UINT16 i;
UINT32 sum=0;
UINT8 ch=0; // 备份通道
UINT8 ctrl=0; // 备份控制寄存器
ch = R8_ADC_CHANNEL;
ctrl = R8_ADC_CFG;
ADC_ChannelCfg( 1 );
R8_ADC_CFG |= RB_ADC_OFS_TEST; // 进入测试模式
R8_ADC_CONVERT = RB_ADC_START;
while( R8_ADC_CONVERT & RB_ADC_START );
for(i=0; i<16; i++)
{
R8_ADC_CONVERT = RB_ADC_START;
while( R8_ADC_CONVERT & RB_ADC_START );
sum += (~R16_ADC_DATA)&RB_ADC_DATA;
}
sum = (sum+8)>>4;
R8_ADC_CFG &= ~RB_ADC_OFS_TEST; // 关闭测试模式
R8_ADC_CHANNEL = ch;
R8_ADC_CFG = ctrl;
return (2048 - sum);
}
void ADC_DataCalib_Fine( PUINT16 dat, ADC_SignalPGATypeDef ga ) // 采样数据细调
{
UINT32 d = (UINT32)*dat;
switch( ga )
{
case ADC_PGA_1_4: // y=0.973x+55.188
*dat = (996*d + 56513 + 512)>>10;
break;
case ADC_PGA_1_2: // y=0.974x+55.26
*dat = (997*d + 56586 + 512)>>10;
break;
case ADC_PGA_0: // y=0.975x+53.63
*dat = (998*d + 54917 + 512)>>10;
break;
case ADC_PGA_2: // y=0.975x+51.58
*dat = (998*d + 52818 + 512)>>10;
break;
}
}
/*******************************************************************************
* Function Name : ADC_ExtSingleChSampInit
* Description :
* Input : sp:
refer to ADC_SampClkTypeDef
ga:
refer to ADC_SignalPGATypeDef
* Return : None
*******************************************************************************/
void ADC_ExtSingleChSampInit( ADC_SampClkTypeDef sp, ADC_SignalPGATypeDef ga )
{
R8_ADC_CFG = RB_ADC_POWER_ON \
|RB_ADC_BUF_EN \
|( sp<<6 ) \
|( ga<<4 ) ;
}
/*******************************************************************************
* Function Name : ADC_ExtDiffChSampInit
* Description :
* Input : sp:
refer to ADC_SampClkTypeDef
ga:
refer to ADC_SignalPGATypeDef
* Return : None
*******************************************************************************/
void ADC_ExtDiffChSampInit( ADC_SampClkTypeDef sp, ADC_SignalPGATypeDef ga )
{
R8_ADC_CFG = RB_ADC_POWER_ON \
|RB_ADC_DIFF_EN \
|( sp<<6 ) \
|( ga<<4 ) ;
}
/*******************************************************************************
* Function Name : ADC_InterTSSampInit
* Description :
* Input : None
* Return : None
*******************************************************************************/
void ADC_InterTSSampInit( void )
{
R8_TEM_SENSOR |= RB_TEM_SEN_PWR_ON;
R8_ADC_CHANNEL = CH_INTE_VTEMP;
R8_ADC_CFG = RB_ADC_POWER_ON \
|( 2<<4 ) ;
}
/*******************************************************************************
* Function Name : ADC_InterBATSampInit
* Description :
* Input : None
* Return : None
*******************************************************************************/
void ADC_InterBATSampInit( void )
{
R8_ADC_CHANNEL = CH_INTE_VBAT;
R8_ADC_CFG = RB_ADC_POWER_ON \
|RB_ADC_BUF_EN \
|( 0<<4 ) ; // 使用-12dB模式
}
/*******************************************************************************
* Function Name : TouchKey_ChSampInit
* Description :
* Input : None
* Return : None
*******************************************************************************/
void TouchKey_ChSampInit( void )
{
R8_ADC_CFG = RB_ADC_POWER_ON | RB_ADC_BUF_EN | ( 2<<4 );
R8_TKEY_CTRL = RB_TKEY_PWR_ON;
}
/*******************************************************************************
* Function Name : ADC_ExcutSingleConver
* Description : ADC执行单次转换
* Input : None
* Return : ADC转换后的数据
*******************************************************************************/
UINT16 ADC_ExcutSingleConver( void )
{
R8_ADC_CONVERT = RB_ADC_START;
while( R8_ADC_CONVERT & RB_ADC_START );
return ( R16_ADC_DATA&RB_ADC_DATA );
}
/*******************************************************************************
* Function Name : TouchKey_ExcutSingleConver
* Description : TouchKey转换后数据
* Input : d: Touchkey充放电时间4bit-8bit-
* Return : TouchKey等效数据
*******************************************************************************/
UINT16 TouchKey_ExcutSingleConver( UINT8 d )
{
R8_TKEY_CTRL = RB_TKEY_PWR_ON;
R8_TKEY_CNT = d;
while( R8_TKEY_CTRL & RB_TKEY_ACTION );
return ( R16_ADC_DATA&RB_ADC_DATA );
}
/*******************************************************************************
* Function Name : ADC_GetCurrentTS
* Description :
* Input : ts_v
* Return :
*******************************************************************************/
int ADC_GetCurrentTS( UINT16 ts_v )
{
UINT16 vol_ts;
UINT16 D85_tem, D85_vol;
UINT16 D25_tem, D25_vol;
UINT16 temperK;
UINT32 temp;
UINT8 sum, sumck;
int cal;
temperK = 64; // mV/16^C
vol_ts = (ts_v*1060)>>11;
temp = (*((PUINT32)ROM_TMP_25C_ADDR));
D25_tem = temp;
D25_vol = (temp>>16);
if( D25_vol != 0 ){ // 默认系数换算
// T = T85 + (V-V85)*16/D25
cal = (D25_tem*temperK + vol_ts*16 + (temperK>>1) - D25_vol*16) / temperK ;
return ( cal );
}
else{ // 内置系数换算 D25_tem
temp = (*((PUINT32)ROM_TMP_85C_ADDR));
sum = (UINT8)(temp>>24); // 最高字节
sumck = (UINT8)(temp>>16);
sumck += (UINT8)(temp>>8);
sumck += (UINT8)temp;
if( sum != sumck ) return 0xff; // 校验和出错
temperK = D25_tem; // D25_tem = temperK
D85_tem = (UINT16)((temp>>16)&0x00ff);
D85_vol = (UINT16)temp;
// T = T85 + (V-V85)*16/D25
cal = (D85_tem*temperK + vol_ts*16 + (temperK>>1) - D85_vol*16) / temperK ;
return ( cal );
}
}

View File

@ -0,0 +1,595 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : CH57x_clk.c
* Author : WCH
* Version : V1.0
* Date : 2018/12/15
* Description
*******************************************************************************/
#include "CH57x_common.h"
/*******************************************************************************
* Function Name : SystemInit
* Description :
* Input : None
* Return : None
*******************************************************************************/
void SystemInit(void)
{
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R16_CLK_SYS_CFG = (2<<6)|0x08; // 32M -> Fsys
*((PUINT16V)0x40001048) |= 4;
R8_SAFE_ACCESS_SIG = 0;
mDelayuS(10);
/* 开启电压监控 */
PowerMonitor( ENABLE );
}
/*******************************************************************************
* Function Name : SetSysClock
* Description :
* Input : sc:
refer to SYS_CLKTypeDef
* Return : None
*******************************************************************************/
void SetSysClock( SYS_CLKTypeDef sc)
{
switch( sc )
{
case CLK_SOURCE_LSI:
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R8_CK32K_CONFIG &= ~RB_CLK_OSC32K_XT;
R16_CLK_SYS_CFG = (3<<6)|0x08;
break;
case CLK_SOURCE_LSE:
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R8_CK32K_CONFIG |= RB_CLK_OSC32K_XT;
R16_CLK_SYS_CFG = (3<<6)|0x08;
break;
case CLK_SOURCE_HSE_32MHz:
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R16_CLK_SYS_CFG = RB_CLK_OSC32M_XT|(2<<6)|0x08;
break;
case CLK_SOURCE_HSE_16MHz:
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R16_CLK_SYS_CFG = RB_CLK_OSC32M_XT|(0<<6)|0x02;
break;
case CLK_SOURCE_HSE_8MHz:
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R16_CLK_SYS_CFG = RB_CLK_OSC32M_XT|(0<<6)|0x04;
break;
case CLK_SOURCE_HSI_32MHz:
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R16_CLK_SYS_CFG = (2<<6)|0x08;
break;
case CLK_SOURCE_HSI_16MHz:
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R16_CLK_SYS_CFG = (0<<6)|0x02;
break;
case CLK_SOURCE_HSI_8MHz:
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R16_CLK_SYS_CFG = (0<<6)|0x04;
break;
case CLK_SOURCE_PLL_40MHz:
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R16_CLK_SYS_CFG = RB_CLK_OSC32M_XT|(1<<6)|12;
break;
case CLK_SOURCE_PLL_32MHz:
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R16_CLK_SYS_CFG = RB_CLK_OSC32M_XT|(1<<6)|15;
break;
case CLK_SOURCE_PLL_24MHz:
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R16_CLK_SYS_CFG = RB_CLK_OSC32M_XT|(1<<6)|20;
break;
case CLK_SOURCE_PLL_20MHz:
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R16_CLK_SYS_CFG = RB_CLK_OSC32M_XT|(1<<6)|24;
break;
case CLK_SOURCE_PLL_16MHz:
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R16_CLK_SYS_CFG = RB_CLK_OSC32M_XT|(1<<6)|30;
break;
default :
break;
}
R8_SAFE_ACCESS_SIG = 0;
}
/*******************************************************************************
* Function Name : GetSysClock
* Description :
* Input : None
* Return : Hz
*******************************************************************************/
UINT32 GetSysClock( void )
{
UINT16 rev;
rev = R16_CLK_SYS_CFG & 0xff;
if( (rev & RB_CLK_SYS_MOD) == (2<<6) ){ // 32M做主频
return (32000000);
}
else if( (rev & RB_CLK_SYS_MOD) == (1<<6) ){ // PLL进行分频
return (480000000/(rev&0x1f));
}
else if( (rev & RB_CLK_SYS_MOD) == (0<<6) ){ // 32M进行分频
return (32000000/(rev&0x1f));
}
else { // 32K做主频
return (32000);
}
}
/*******************************************************************************
* Function Name : HClk32M_Select
* Description : 32M
* Input : hc:
Clk32M_HSI - 32M
Clk32M_HSE - 32M
* Return : None
*******************************************************************************/
void HClk32M_Select( HClk32MTypeDef hc)
{
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
if( hc == Clk32M_HSI)
R16_CLK_SYS_CFG &= ~RB_CLK_OSC32M_XT;
else
R16_CLK_SYS_CFG |= RB_CLK_OSC32M_XT;
R8_SAFE_ACCESS_SIG = 0;
}
/*******************************************************************************
* Function Name : LClk32K_Select
* Description : 32K
* Input : hc:
Clk32K_LSI - 32K
Clk32K_LSE - 32K
* Return : None
*******************************************************************************/
void LClk32K_Select( LClk32KTypeDef hc)
{
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
if( hc == Clk32K_LSI)
R8_CK32K_CONFIG &= ~RB_CLK_OSC32K_XT;
else
R8_CK32K_CONFIG |= RB_CLK_OSC32K_XT;
R8_SAFE_ACCESS_SIG = 0;
}
/*******************************************************************************
* Function Name : HSECFG_Current
* Description : HSE晶体
* Input : c: 75%,100%,125%,150%
* Return : None
*******************************************************************************/
void HSECFG_Current( HSECurrentTypeDef c )
{
UINT8 x32M_c;
x32M_c = R8_XT32M_TUNE;
x32M_c = (x32M_c&0xfc)|(c&0x03);
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R8_XT32M_TUNE = x32M_c;
R8_SAFE_ACCESS_SIG = 0;
}
/*******************************************************************************
* Function Name : HSECFG_Capacitance
* Description : HSE晶体
* Input : c: refer to HSECapTypeDef
* Return : None
*******************************************************************************/
void HSECFG_Capacitance( HSECapTypeDef c )
{
UINT8 x32M_c;
x32M_c = R8_XT32M_TUNE;
x32M_c = (x32M_c&0x8f)|(c<<4);
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R8_XT32M_TUNE = x32M_c;
R8_SAFE_ACCESS_SIG = 0;
}
/*******************************************************************************
* Function Name : LSECFG_Current
* Description : LSE晶体
* Input : c: 70%,100%,140%,200%
* Return : None
*******************************************************************************/
void LSECFG_Current( LSECurrentTypeDef c )
{
UINT8 x32K_c;
x32K_c = R8_XT32K_TUNE;
x32K_c = (x32K_c&0xfc)|(c&0x03);
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R8_XT32K_TUNE = x32K_c;
R8_SAFE_ACCESS_SIG = 0;
}
/*******************************************************************************
* Function Name : LSECFG_Capacitance
* Description : LSE晶体
* Input : c: refer to LSECapTypeDef
* Return : None
*******************************************************************************/
void LSECFG_Capacitance( LSECapTypeDef c )
{
UINT8 x32K_c;
x32K_c = R8_XT32K_TUNE;
x32K_c = (x32K_c&0x0f)|(c<<4);
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R8_XT32K_TUNE = x32K_c;
R8_SAFE_ACCESS_SIG = 0;
}
/*******************************************************************************
* Function Name : Calibration_LSI
* Description : 32K时钟
* Input : None
* Return :
*******************************************************************************/
// 0-26030Hz 1023-44220Hz
UINT16 Calibration_LSI( void )
{
UINT16 rev, basev;
UINT32 calv;
UINT16 i;
UINT16 loc, loc_t;
signed short CNT_STEP_K;
signed short diff_1, diff_2, diffc;
UINT8 k=0;
/* 根据当前时钟获取标称值和斜率T-step */
rev = R16_CLK_SYS_CFG & 0xff;
// CNT_STEP_K=Fsys*5*(1/26030 - 1/44220)/1023;
if( (rev & RB_CLK_SYS_MOD) == (2<<6) ){ // 32M做主频
calv = ((5*32000000+(CAB_LSIFQ>>1))/CAB_LSIFQ);
CNT_STEP_K = -3;
}
else if( (rev & RB_CLK_SYS_MOD) == (1<<6) ){ // PLL进行分频
calv = (((UINT32)5*480000000/(rev&0x1f)+(CAB_LSIFQ>>1))/CAB_LSIFQ);
CNT_STEP_K =( -37-((rev&0x1f)-1))/(rev&0x1f);
}
else if( (rev & RB_CLK_SYS_MOD) == (0<<6) ){ // 32M进行分频
calv = ((5*32000000/(rev&0x1f)+(CAB_LSIFQ>>1))/CAB_LSIFQ);
CNT_STEP_K = ( -3-((rev&0x1f)-1))/(rev&0x1f);
}
else { // 32K做主频
calv = (5);
CNT_STEP_K = 0;
}
/* 校准 */
basev = ( calv &0xfff ); // 获取校准标称值
// loc = 1023*(f-26030)/f/((44220-26030)/44220) 经验曲线
loc = R16_INT32K_TUNE;
diff_2 = 0;
diffc = 0;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R8_OSC_CAL_CTRL = RB_OSC_CNT_EN;
do
{
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R16_INT32K_TUNE = loc;
R8_SAFE_ACCESS_SIG = 0;
/* 读取当前值 */
while(!(R8_OSC_CAL_CTRL&RB_OSC_CNT_HALT));
i = R16_OSC_CAL_CNT; // 用于丢弃
while(R8_OSC_CAL_CTRL&RB_OSC_CNT_HALT);
while(!(R8_OSC_CAL_CTRL&RB_OSC_CNT_HALT));
i = R16_OSC_CAL_CNT; // 实时校准后采样值
k++;
diff_1 = i-basev;
if( diff_1 == 0 ){
return 0; // 校准正好
}
else if((diff_1*diff_2)<0){ // 处于两点之间
if((diffc == 1) || (diffc == -1) || (diffc == 0))
{
// 都变成正数
if( diff_2<0 ) diff_2 = ~(diff_2-1);
else diff_1 = ~(diff_1-1);
if(diff_1>diff_2){
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R16_INT32K_TUNE = loc_t;
R8_SAFE_ACCESS_SIG = 0;
return (diff_2*1000/basev); // 返回误差值,千分之
}
else return(diff_1*1000/basev);
}
}
// 保存上一次值
diff_2 = diff_1;
loc_t = loc;
diffc = diff_1/CNT_STEP_K;
loc = loc - diffc;
if( loc == loc_t )
{
if( diff_1 > 0 ) loc = loc+1; // 当前频率偏小
else loc = loc-1; // 当前频率偏大
}
}while( k<20 );
return(0xff);
}
/*******************************************************************************
* Function Name : RTCInitTime
* Description : RTC时钟初始化当前时间
* Input : y: -
MAX_Y = BEGYEAR + 44
mon: -
MAX_MON = 12
d: -
MAX_D = 31
h: -
MAX_H = 23
m: -
MAX_M = 59
s: -
MAX_S = 59
* Return : None
*******************************************************************************/
void RTC_InitTime( UINT16 y, UINT16 mon, UINT16 d, UINT16 h, UINT16 m, UINT16 s )
{
UINT32 t;
UINT16 year, month, day, sec2, t32k;
UINT8V clk_pin;
year = y;
month = mon;
day = 0;
while ( year > BEGYEAR )
{
day += YearLength( year-1 );
year--;
}
while ( month > 1 )
{
day += monthLength( IsLeapYear( y ), month-2 );
month--;
}
day += d-1;
sec2 = (h%24)*1800+m*30+s/2;
t32k = (s&1)?(0x8000):(0);
t = sec2;
t = t<<16 | t32k;
do{
clk_pin = (R8_CK32K_CONFIG&RB_32K_CLK_PIN);
}while( (clk_pin != (R8_CK32K_CONFIG&RB_32K_CLK_PIN)) || (!clk_pin) );
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R32_RTC_TRIG = day;
R8_RTC_MODE_CTRL |= RB_RTC_LOAD_HI;
R32_RTC_TRIG = t;
R8_RTC_MODE_CTRL |= RB_RTC_LOAD_LO;
R8_SAFE_ACCESS_SIG = 0;
}
/*******************************************************************************
* Function Name : RTC_GetTime
* Description :
* Input : y: -
MAX_Y = BEGYEAR + 44
mon: -
MAX_MON = 12
d: -
MAX_D = 31
ph: -
MAX_H = 23
pm: -
MAX_M = 59
ps: -
MAX_S = 59
* Return : None
*******************************************************************************/
void RTC_GetTime( PUINT16 py, PUINT16 pmon, PUINT16 pd, PUINT16 ph, PUINT16 pm, PUINT16 ps )
{
UINT32 t;
UINT16 day, sec2, t32k;
day = R32_RTC_CNT_DAY & 0x3FFF;
sec2 = R16_RTC_CNT_2S;
t32k = R16_RTC_CNT_32K;
t = sec2*2 + ((t32k<0x8000)?0:1);
*py = BEGYEAR;
while ( day >= YearLength( *py ) )
{
day -= YearLength( *py );
(*py)++;
}
*pmon = 0;
while ( day >= monthLength( IsLeapYear( *py ), *pmon ) )
{
day -= monthLength( IsLeapYear( *py ), *pmon );
(*pmon)++;
}
(*pmon) ++;
*pd = day+1;
*ph = t/3600;
*pm = t%3600/60;
*ps = t%60;
}
/*******************************************************************************
* Function Name : RTC_SetCycle32k
* Description : LSE/LSI时钟RTC
* Input : cyc: - cycle
MAX_CYC = 0xA8BFFFFF = 2831155199
* Return : None
*******************************************************************************/
void RTC_SetCycle32k( UINT32 cyc )
{
UINT8V clk_pin;
do{
clk_pin = (R8_CK32K_CONFIG&RB_32K_CLK_PIN);
}while( (clk_pin != (R8_CK32K_CONFIG&RB_32K_CLK_PIN)) || (!clk_pin) );
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R32_RTC_TRIG = cyc;
R8_RTC_MODE_CTRL |= RB_RTC_LOAD_LO;
R8_SAFE_ACCESS_SIG = 0;
}
/*******************************************************************************
* Function Name : RTC_GetCycle32k
* Description : LSE/LSI时钟RTC
* Input : None
* Return : MAX_CYC = 0xA8BFFFFF = 2831155199
*******************************************************************************/
UINT32 RTC_GetCycle32k( void )
{
UINT32 i;
do{
i = R32_RTC_CNT_32K;
}while( i != R32_RTC_CNT_32K );
return (i);
}
/*******************************************************************************
* Function Name : RTC_TMRFunCfg
* Description : RTC定时模式配置
* Input : t:
refer to RTC_TMRCycTypeDef
* Return : None
*******************************************************************************/
void RTC_TMRFunCfg( RTC_TMRCycTypeDef t )
{
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R8_RTC_MODE_CTRL &= ~(RB_RTC_TMR_EN|RB_RTC_TMR_MODE);
R8_RTC_MODE_CTRL |= RB_RTC_TMR_EN | (t);
R8_SAFE_ACCESS_SIG = 0;
}
/*******************************************************************************
* Function Name : RTC_TRIGFunCfg
* Description : RTC时间触发模式配置
* Input : cyc: LSE/LSI时钟周期数
* Return : None
*******************************************************************************/
void RTC_TRIGFunCfg( UINT32 cyc )
{
UINT32 t;
t = RTC_GetCycle32k() + cyc;
if( t>0xA8C00000) t -= 0xA8C00000;
if( t&0xFFFF ) t = t+0x10000;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R32_RTC_TRIG = t;
R8_RTC_MODE_CTRL |= RB_RTC_TRIG_EN;
R8_SAFE_ACCESS_SIG = 0;
}
/*******************************************************************************
* Function Name : RTC_ModeFunDisable
* Description : RTC
* Input : m:
* Return : None
*******************************************************************************/
void RTC_ModeFunDisable( RTC_MODETypeDef m )
{
UINT8 i=0;
if( m == RTC_TRIG_MODE ) i |= RB_RTC_TRIG_EN;
else if( m == RTC_TMR_MODE ) i |= RB_RTC_TMR_EN;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R8_RTC_MODE_CTRL &= ~(i);
R8_SAFE_ACCESS_SIG = 0;
}
/*******************************************************************************
* Function Name : RTC_GetITFlag
* Description : RTC中断标志
* Input : f:
refer to RTC_EVENTTypeDef
* Return : :
0 -
(!0) -
*******************************************************************************/
UINT8 RTC_GetITFlag( RTC_EVENTTypeDef f )
{
if( f == RTC_TRIG_EVENT )
return ( R8_RTC_FLAG_CTRL & RB_RTC_TRIG_FLAG );
else
return ( R8_RTC_FLAG_CTRL & RB_RTC_TMR_FLAG );
}
/*******************************************************************************
* Function Name : RTC_ClearITFlag
* Description : RTC中断标志
* Input : f:
refer to RTC_EVENTTypeDef
* Return : None
*******************************************************************************/
void RTC_ClearITFlag( RTC_EVENTTypeDef f )
{
switch( f )
{
case RTC_TRIG_EVENT:
R8_RTC_FLAG_CTRL = RB_RTC_TRIG_CLR;
break;
case RTC_TMR_EVENT:
R8_RTC_FLAG_CTRL = RB_RTC_TMR_CLR;
break;
default :
break;
}
}

View File

@ -0,0 +1,283 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : CH57x_flash.c
* Author : WCH
* Version : V1.1
* Date : 2020/03/20
* Description :
*******************************************************************************/
/******************************************************************************/
/* 头文件包含 */
#include "CH57x_common.h"
/* 操作Flash的保护状态标志 */
#define CODEFLASH_SAFE_FLAG1 0x57
#define CODEFLASH_SAFE_FLAG2 0xA8
/* 操作Flash的保护状态变量 */
unsigned char codeflash_access_flag1 = 0x0;
unsigned char codeflash_access_flag2 = 0x0;
/*******************************************************************************
* Function Name : GetUniqueID
* Description : ID6B-ID 2B-CKS
* Input : buf: 86ID2
* Return : None
*******************************************************************************/
void GetUniqueID(PUINT8 buf)
{
PUINT8 pID;
UINT8 i;
pID = (PUINT8)ROM_UUID_ADDR;
for(i=0; i<8; i++) *buf++ = *pID++;
}
/*******************************************************************************
* Function Name : GetMACAddress
* Description : MAC6B-MAC
* Input : buf: 66 MAC
* Return : None
*******************************************************************************/
void GetMACAddress(PUINT8 buf)
{
PUINT8 pMAC;
UINT8 i;
pMAC = (PUINT8)ROM_MAC_ADDR;
for(i=0; i<6; i++) *buf++ = *pMAC++;
}
/*******************************************************************************
* Function Name : FlashBlockErase
* Description : Flash 512B
* Input : addr: 32512
* codeflash: startAddr - 0x00000000 size - 0x3E800
* dataflash: startAddr - 0x3E800(DATA_FLASH_ADDR) size - 0x0800(DATA_FLASH_SIZE)
* Return : 0 - -
*******************************************************************************/
UINT8 FlashBlockErase(UINT32 addr)
{
UINT8 status = 0;
volatile UINT8 op_step;
if( addr & (0x200-1) ) return 1; //地址不对齐
op_step = 0x11;
codeflash_access_flag1 = 0;
codeflash_access_flag2 = 0;
R8_FLASH_PROTECT = RB_ROM_WE_MUST_10;
//开启电压监控中断
op_step += 0x11;
if((R8_BAT_DET_CTRL & 0x0F) != 0x0D) PowerMonitor( ENABLE );
op_step += 0x11;
if((R8_BAT_STATUS & 0x03) != 0x00) return 2; //电源电压偏低Flash不允许操作
op_step += 0x11;
if(((R8_BAT_STATUS & 0x03) == 0x00)
&&(op_step == 0x44))
{
codeflash_access_flag1 = CODEFLASH_SAFE_FLAG1;
}
op_step += 0x11;
if(((R8_BAT_STATUS & 0x03) == 0x00)
&&(op_step == 0x55)
&&(codeflash_access_flag1 == CODEFLASH_SAFE_FLAG1))
{
codeflash_access_flag2 = CODEFLASH_SAFE_FLAG2;
}
op_step += 0x11;
if((codeflash_access_flag1 == CODEFLASH_SAFE_FLAG1)
&&(codeflash_access_flag2 == CODEFLASH_SAFE_FLAG2)
&&(op_step == 0x66))
{
R32_FLASH_ADDR = addr;
if( addr < DATA_FLASH_ADDR ) R8_FLASH_PROTECT = RB_ROM_WE_MUST_10|RB_ROM_CODE_WE; // Codefalsh区
else R8_FLASH_PROTECT = RB_ROM_WE_MUST_10|RB_ROM_DATA_WE; // datafalsh区
}
op_step += 0x11;
/* 判断操作Flash的保护状态标志 */
if((codeflash_access_flag1 == CODEFLASH_SAFE_FLAG1)
&&(codeflash_access_flag2 == CODEFLASH_SAFE_FLAG2)
&&(op_step == 0x77))
{
R8_FLASH_COMMAND = ROM_CMD_ERASE;
status = (unsigned char)(R16_FLASH_STATUS & 0xff);
}
op_step = 0x00;
codeflash_access_flag1 = 0x00;
codeflash_access_flag2 = 0x00;
R8_FLASH_PROTECT = RB_ROM_WE_MUST_10; // LOCK
if( status != RB_ROM_ADDR_OK ) return 3; //操作失败
return 0;
}
/*******************************************************************************
* Function Name : FlashWriteDW
* Description : Flash 4
* Input : addr: 324
* codeflash: startAddr - 0x00000000 size - 0x3E800
* dataflash: startAddr - 0x3E800(DATA_FLASH_ADDR) size - 0x0800(DATA_FLASH_SIZE)
dat: 32
* Return : FAILED -
SUCCESS -
*******************************************************************************/
UINT8 FlashWriteDW(UINT32 addr, UINT32 dat)
{
UINT32 add = addr;
UINT32 val = dat;
UINT8 status = 0;
volatile UINT8 op_step;
if( addr & (4-1) ) return 1; //地址不对齐
op_step = 0x11;
codeflash_access_flag1 = 0;
codeflash_access_flag2 = 0;
R8_FLASH_PROTECT = RB_ROM_WE_MUST_10;
//开启电压监控中断
op_step += 0x11;
if((R8_BAT_DET_CTRL & 0x0F) != 0x0D) PowerMonitor( ENABLE );
op_step += 0x11;
if((R8_BAT_STATUS & 0x03) != 0x00) return 2; //电源电压偏低Flash不允许操作
op_step += 0x11;
if(((R8_BAT_STATUS & 0x01) == 0x00)
&&(op_step == 0x44))
{
codeflash_access_flag1 = CODEFLASH_SAFE_FLAG1;
}
op_step += 0x11;
if(((R8_BAT_STATUS & 0x01) == 0x00)
&&(op_step == 0x55)
&&(codeflash_access_flag1 == CODEFLASH_SAFE_FLAG1))
{
codeflash_access_flag2 = CODEFLASH_SAFE_FLAG2;
}
op_step += 0x11;
if((codeflash_access_flag1 == CODEFLASH_SAFE_FLAG1)
&&(codeflash_access_flag2 == CODEFLASH_SAFE_FLAG2)
&&(op_step == 0x66))
{
if( addr < DATA_FLASH_ADDR ) R8_FLASH_PROTECT = RB_ROM_WE_MUST_10|RB_ROM_CODE_WE; // Codefalsh区
else R8_FLASH_PROTECT = RB_ROM_WE_MUST_10|RB_ROM_DATA_WE; // datafalsh区
}
op_step += 0x11;
/* 判断OTA操作Flash的保护状态标志 */
if((codeflash_access_flag1==CODEFLASH_SAFE_FLAG1)
&&(codeflash_access_flag2==CODEFLASH_SAFE_FLAG2)
&&(op_step == 0x77))
{
R32_FLASH_ADDR = add;
R32_FLASH_DATA = val;
R8_FLASH_COMMAND = ROM_CMD_PROG;
status = (unsigned char)(R16_FLASH_STATUS & 0xff);
}
op_step = 0x00;
codeflash_access_flag1 = 0x00;
codeflash_access_flag2 = 0x00;
R8_FLASH_PROTECT = RB_ROM_WE_MUST_10;
if( status != RB_ROM_ADDR_OK ) return 3; //操作失败
return 0;
}
/*******************************************************************************
* Function Name : FlashWriteBuf
* Description : Flash
* Input : addr: 324
* codeflash: startAddr - 0x00000000 size - 0x3E800
* dataflash: startAddr - 0x3E800(DATA_FLASH_ADDR) size - 0x0800(DATA_FLASH_SIZE)
* pdat:
* len:
* Return : 0 - -
*******************************************************************************/
UINT8 FlashWriteBuf(UINT32 addr, PUINT32 pdat, UINT16 len)
{
UINT32 add = addr;
PUINT32 p32 = pdat;
UINT8 status = 0;
UINT16 i;
volatile UINT8 op_step;
if( addr & (4-1) ) return 1; //地址不对齐
op_step = 0x11;
codeflash_access_flag1 = 0;
codeflash_access_flag2 = 0;
R8_FLASH_PROTECT = RB_ROM_WE_MUST_10;
//开启电压监控中断
op_step += 0x11;
if((R8_BAT_DET_CTRL & 0x0F) != 0x0D) PowerMonitor( ENABLE );
op_step += 0x11;
if((R8_BAT_STATUS & 0x03) != 0x00) return 2; //电源电压偏低Flash不允许操作
op_step += 0x11;
if(((R8_BAT_STATUS & 0x01) == 0x00)
&&(op_step == 0x44))
{
codeflash_access_flag1 = CODEFLASH_SAFE_FLAG1;
}
op_step += 0x11;
if(((R8_BAT_STATUS & 0x01) == 0x00)
&&(op_step == 0x55)
&&(codeflash_access_flag1 == CODEFLASH_SAFE_FLAG1))
{
codeflash_access_flag2 = CODEFLASH_SAFE_FLAG2;
}
op_step += 0x11;
if((codeflash_access_flag1 == CODEFLASH_SAFE_FLAG1)
&&(codeflash_access_flag2 == CODEFLASH_SAFE_FLAG2)
&&(op_step == 0x66))
{
if( addr < DATA_FLASH_ADDR ) R8_FLASH_PROTECT = RB_ROM_WE_MUST_10|RB_ROM_CODE_WE; // Codefalsh区
else R8_FLASH_PROTECT = RB_ROM_WE_MUST_10|RB_ROM_DATA_WE; // datafalsh区
}
op_step += 0x11;
/* 判断OTA操作Flash的保护状态标志 */
if((codeflash_access_flag1==CODEFLASH_SAFE_FLAG1)
&&(codeflash_access_flag2==CODEFLASH_SAFE_FLAG2)
&&(op_step == 0x77))
{
for(i=0; i<len; i+=4)
{
R32_FLASH_ADDR = add;
R32_FLASH_DATA = *p32++;
R8_FLASH_COMMAND = ROM_CMD_PROG;
add += 4;
//status = R8_FLASH_STATUS;
status = (unsigned char)(R16_FLASH_STATUS & 0xff);
if( status != RB_ROM_ADDR_OK ) break;
}
}
op_step = 0x00;
codeflash_access_flag1 = 0x00;
codeflash_access_flag2 = 0x00;
R8_FLASH_PROTECT = RB_ROM_WE_MUST_10;
if( status != RB_ROM_ADDR_OK ) return 3; //操作失败
return 0;
}

View File

@ -0,0 +1,252 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : CH57x_gpio.c
* Author : WCH
* Version : V1.0
* Date : 2018/12/15
* Description
*******************************************************************************/
#include "CH57x_common.h"
/*******************************************************************************
* Function Name : GPIOA_ModeCfg
* Description : GPIOA端口引脚模式配置
* Input : pin: PA0-PA15
GPIO_Pin_0 - GPIO_Pin_15
mode:
GPIO_ModeIN_Floating -
GPIO_ModeIN_PU -
GPIO_ModeIN_PD -
GPIO_ModeOut_PP_5mA - 5mA
GPIO_ModeOut_PP_20mA - 20mA
* Return : None
*******************************************************************************/
void GPIOA_ModeCfg( UINT32 pin, GPIOModeTypeDef mode )
{
switch(mode)
{
case GPIO_ModeIN_Floating:
R32_PA_PD_DRV &= ~pin;
R32_PA_PU &= ~pin;
R32_PA_DIR &= ~pin;
break;
case GPIO_ModeIN_PU:
R32_PA_PD_DRV &= ~pin;
R32_PA_PU |= pin;
R32_PA_DIR &= ~pin;
break;
case GPIO_ModeIN_PD:
R32_PA_PD_DRV |= pin;
R32_PA_PU &= ~pin;
R32_PA_DIR &= ~pin;
break;
case GPIO_ModeOut_PP_5mA:
R32_PA_PD_DRV &= ~pin;
R32_PA_DIR |= pin;
break;
case GPIO_ModeOut_PP_20mA:
R32_PA_PD_DRV |= pin;
R32_PA_DIR |= pin;
break;
default:
break;
}
}
/*******************************************************************************
* Function Name : GPIOB_ModeCfg
* Description : GPIOB端口引脚模式配置
* Input : pin: PB0-PB23
GPIO_Pin_0 - GPIO_Pin_23
mode:
GPIO_ModeIN_Floating -
GPIO_ModeIN_PU -
GPIO_ModeIN_PD -
GPIO_ModeOut_PP_5mA - 5mA
GPIO_ModeOut_PP_20mA - 20mA
* Return : None
*******************************************************************************/
void GPIOB_ModeCfg( UINT32 pin, GPIOModeTypeDef mode )
{
switch(mode)
{
case GPIO_ModeIN_Floating:
R32_PB_PD_DRV &= ~pin;
R32_PB_PU &= ~pin;
R32_PB_DIR &= ~pin;
break;
case GPIO_ModeIN_PU:
R32_PB_PD_DRV &= ~pin;
R32_PB_PU |= pin;
R32_PB_DIR &= ~pin;
break;
case GPIO_ModeIN_PD:
R32_PB_PD_DRV |= pin;
R32_PB_PU &= ~pin;
R32_PB_DIR &= ~pin;
break;
case GPIO_ModeOut_PP_5mA:
R32_PB_PD_DRV &= ~pin;
R32_PB_DIR |= pin;
break;
case GPIO_ModeOut_PP_20mA:
R32_PB_PD_DRV |= pin;
R32_PB_DIR |= pin;
break;
default:
break;
}
}
/*******************************************************************************
* Function Name : GPIOA_ITModeCfg
* Description : GPIOA引脚中断模式配置
* Input : pin: PA0-PA15
GPIO_Pin_0 - GPIO_Pin_15
mode:
GPIO_ITMode_LowLevel -
GPIO_ITMode_HighLevel -
GPIO_ITMode_FallEdge - 沿
GPIO_ITMode_RiseEdge - 沿
* Return : None
*******************************************************************************/
void GPIOA_ITModeCfg( UINT32 pin, GPIOITModeTpDef mode )
{
switch( mode )
{
case GPIO_ITMode_LowLevel: // 低电平触发
R16_PA_INT_MODE &= ~pin;
R32_PA_CLR |= pin;
break;
case GPIO_ITMode_HighLevel: // 高电平触发
R16_PA_INT_MODE &= ~pin;
R32_PA_OUT |= pin;
break;
case GPIO_ITMode_FallEdge: // 下降沿触发
R16_PA_INT_MODE |= pin;
R32_PA_CLR |= pin;
break;
case GPIO_ITMode_RiseEdge: // 上升沿触发
R16_PA_INT_MODE |= pin;
R32_PA_OUT |= pin;
break;
default :
break;
}
R16_PA_INT_IF = pin;
R16_PA_INT_EN |= pin;
}
/*******************************************************************************
* Function Name : GPIOB_ITModeCfg
* Description : GPIOB引脚中断模式配置
* Input : pin: PB0-PB15
GPIO_Pin_0 - GPIO_Pin_15
mode:
GPIO_ITMode_LowLevel -
GPIO_ITMode_HighLevel -
GPIO_ITMode_FallEdge - 沿
GPIO_ITMode_RiseEdge - 沿
* Return : None
*******************************************************************************/
void GPIOB_ITModeCfg( UINT32 pin, GPIOITModeTpDef mode )
{
switch( mode )
{
case GPIO_ITMode_LowLevel: // 低电平触发
R16_PB_INT_MODE &= ~pin;
R32_PB_CLR |= pin;
break;
case GPIO_ITMode_HighLevel: // 高电平触发
R16_PB_INT_MODE &= ~pin;
R32_PB_OUT |= pin;
break;
case GPIO_ITMode_FallEdge: // 下降沿触发
R16_PB_INT_MODE |= pin;
R32_PB_CLR |= pin;
break;
case GPIO_ITMode_RiseEdge: // 上升沿触发
R16_PB_INT_MODE |= pin;
R32_PB_OUT |= pin;
break;
default :
break;
}
R16_PB_INT_IF = pin;
R16_PB_INT_EN |= pin;
}
/*******************************************************************************
* Function Name : GPIOPinRemap
* Description :
* Input : s:
ENABLE -
DISABLE -
perph:
RB_PIN_SPI0 - SPI0: PA12/PA13/PA14/PA15 -> PB12/PB13/PB14/PB15
RB_PIN_UART3 - UART3: PA4/PA5 -> PB20/PB21
RB_PIN_UART2 - UART2: PA6/PA7 -> PB22/PB23
RB_PIN_UART1 - UART1: PA8/PA9 -> PB8/PB9
RB_PIN_UART0 - UART0: PB4/PB7 -> PA15/PA14
RB_PIN_TMR3 - TMR3: PA2 -> PB18
RB_PIN_TMR2 - TMR2: PA11 -> PB11
RB_PIN_TMR1 - TMR1: PA10 -> PB10
RB_PIN_TMR0 - TMR0: PA3 -> PB19
* Return : None
*******************************************************************************/
void GPIOPinRemap( UINT8 s, UINT16 perph )
{
if( s ) R16_PIN_ALTERNATE |= perph;
else R16_PIN_ALTERNATE &= ~perph;
}
/*******************************************************************************
* Function Name : GPIOAGPPCfg
* Description : GPIO引脚功能控制
* Input : s:
ENABLE -
DISABLE -
perph:
RB_PIN_ADC0_1_IE - ADC0-1
RB_PIN_ADC2_3_IE - ADC2-3
RB_PIN_ADC4_5_IE - ADC4-5
RB_PIN_ADC6_7_IE - ADC6-7
RB_PIN_ADC8_9_IE - ADC8-9
RB_PIN_ADC10_11_IE - ADC10-11
RB_PIN_ADC12_13_IE - ADC12-13
RB_PIN_XT32K_IE - 32K引脚
RB_PIN_USB_IE - USB功能信号引脚
RB_PIN_ETH_IE -
RB_PIN_SEG0_3_IE - LCD控制器SEG0-3
RB_PIN_SEG4_7_IE - LCD控制器SEG4-7
RB_PIN_SEG8_11_IE - LCD控制器SEG8-11
RB_PIN_SEG12_15_IE - LCD控制器SEG12-15
RB_PIN_SEG16_19_IE - LCD控制器SEG16-19
RB_PIN_SEG20_23_IE - LCD控制器SEG20-23
* Return : None
*******************************************************************************/
void GPIOAGPPCfg( UINT8 s, UINT16 perph )
{
if( s ) R16_PIN_ANALOG_IE |= perph;
else R16_PIN_ANALOG_IE &= ~perph;
}

View File

@ -0,0 +1,242 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : CH57x_int.c
* Author : WCH
* Version : V1.0
* Date : 2020/03/18
* Description
*******************************************************************************/
#include "CH57x_common.h"
/*******************************************************************************
* Function Name : NMI_Handler
* Description : NMI中断函数
* Input : None
* Return : None
*******************************************************************************/
//__attribute__((section("NMICode")))
void NMI_Handler( void )
{
UINT32 i=0;
if( (R8_HFCK_PWR_CTRL & RB_CLK_INT32M_PON) == 0 )
{
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R8_HFCK_PWR_CTRL |= RB_CLK_INT32M_PON; // 打开内部32M
}
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R16_CLK_SYS_CFG = 5; // 降频 HSI/5=6.4M
R16_POWER_PLAN &= ~(RB_PWR_DCDC_EN|RB_PWR_DCDC_PRE); // 旁路 DC/DC
R8_HFCK_PWR_CTRL |= RB_CLK_PLL_PON; // 打开PLL
R8_SAFE_ACCESS_SIG = 0;
while(1)
{
if(R8_BAT_STATUS & RB_BAT_STAT_LOWER) i = 0;
else i++;
if( i>2000 )
{
/* 执行系统复位 */
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R8_RST_WDOG_CTRL = RB_SOFTWARE_RESET;
R8_SAFE_ACCESS_SIG = 0;
}
}
}
/*******************************************************************************
* Function Name : LowPower_Halt_1
* Description : -Halt_1模式
HSI/5
* Input : None
* Return : None
*******************************************************************************/
//__attribute__((section("NMICode")))
void LowPower_Halt_1( void )
{
UINT8 x32Kpw, x32Mpw;
x32Kpw = R8_XT32K_TUNE;
x32Mpw = R8_XT32M_TUNE;
x32Mpw = (x32Mpw&0xfc)|0x03; // 150%额定电流
if(R16_RTC_CNT_32K>0x3fff){ // 超过500ms
x32Kpw = (x32Kpw&0xfc)|0x01; // LSE驱动电流降低到额定电流
}
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R8_SLP_POWER_CTRL &= ~RB_SLP_ROM_PWR_DN; // flash待机
R8_BAT_DET_CTRL = 0; // 关闭电压监控
R8_XT32K_TUNE = x32Kpw;
R8_XT32M_TUNE = x32Mpw;
R16_CLK_SYS_CFG = 5; // 降频 HSI/5=6.4M
R8_SAFE_ACCESS_SIG = 0;
SCB -> SCR |= SCB_SCR_SLEEPDEEP_Msk; //deep sleep
__WFI();
R8_SAFE_ACCESS_SIG = 0;
/* 开启电压监控 */
PowerMonitor( ENABLE );
}
/*******************************************************************************
* Function Name : LowPower_Halt_2
* Description : -Halt_2模式
HSI/5
* Input : None
* Return : None
*******************************************************************************/
//__attribute__((section("NMICode")))
void LowPower_Halt_2( void )
{
UINT8 x32Kpw, x32Mpw;
x32Kpw = R8_XT32K_TUNE;
x32Mpw = R8_XT32M_TUNE;
x32Mpw = (x32Mpw&0xfc)|0x03; // 150%额定电流
if(R16_RTC_CNT_32K>0x3fff){ // 超过500ms
x32Kpw = (x32Kpw&0xfc)|0x01; // LSE驱动电流降低到额定电流
}
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R8_SLP_POWER_CTRL |= RB_SLP_ROM_PWR_DN; // flash停机
R8_BAT_DET_CTRL = 0; // 关闭电压监控
R8_XT32K_TUNE = x32Kpw;
R8_XT32M_TUNE = x32Mpw;
R16_CLK_SYS_CFG = 5; // 降频 HSI/5=6.4M
R8_SAFE_ACCESS_SIG = 0;
SCB -> SCR |= SCB_SCR_SLEEPDEEP_Msk; //deep sleep
__WFI();
R8_SAFE_ACCESS_SIG = 0;
/* 开启电压监控 */
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R8_BAT_DET_CFG = 1; // 2.05V - 2.33V
R8_BAT_DET_CTRL = RB_BAT_DET_EN;
R8_SAFE_ACCESS_SIG = 0;
__nop(); __nop();
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R8_BAT_DET_CTRL = RB_BAT_LOW_IE|RB_BAT_LOWER_IE|RB_BAT_DET_EN;
R8_SAFE_ACCESS_SIG = 0;
}
/*******************************************************************************
* Function Name : LowPower_Sleep
* Description : -Sleep模式
HSI/5
DCDC功能强制关闭
* Input : rm:
RB_PWR_RAM2K - 2K SRAM
RB_PWR_RAM14K - 0x20004000 - 0x20007800 14K SRAM
RB_PWR_EXTEND - USB和RF
NULL -
* Return : None
*******************************************************************************/
//__attribute__((section("NMICode")))
void LowPower_Sleep( UINT8 rm )
{
UINT8 x32Kpw, x32Mpw;
x32Kpw = R8_XT32K_TUNE;
x32Mpw = R8_XT32M_TUNE;
x32Mpw = (x32Mpw&0xfc)|0x03; // 150%额定电流
if(R16_RTC_CNT_32K>0x3fff){ // 超过500ms
x32Kpw = (x32Kpw&0xfc)|0x01; // LSE驱动电流降低到额定电流
}
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R16_POWER_PLAN = RB_PWR_PLAN_EN \
|RB_PWR_MUST_0010 \
|RB_PWR_CORE \
|rm;
R8_SAFE_ACCESS_SIG = 0;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R8_BAT_DET_CTRL = 0; // 关闭电压监控
R8_XT32K_TUNE = x32Kpw;
R8_XT32M_TUNE = x32Mpw;
R16_CLK_SYS_CFG = 5; // 降频 HSI/5=6.4M
R8_SAFE_ACCESS_SIG = 0;
SCB -> SCR |= SCB_SCR_SLEEPDEEP_Msk; //deep sleep
__WFI();
R8_SAFE_ACCESS_SIG = 0;
/* 开启电压监控 */
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R8_BAT_DET_CFG = 1; // 2.05V - 2.33V
R8_BAT_DET_CTRL = RB_BAT_DET_EN;
R8_SAFE_ACCESS_SIG = 0;
__nop(); __nop();
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R8_BAT_DET_CTRL = RB_BAT_LOW_IE|RB_BAT_LOWER_IE|RB_BAT_DET_EN;
R8_SAFE_ACCESS_SIG = 0;
}
/*******************************************************************************
* Function Name : LowPower_Shutdown
* Description : -Shutdown模式
HSI/5
DCDC功能强制关闭
* Input : rm:
RB_PWR_RAM2K - 2K SRAM
NULL -
* Return : None
*******************************************************************************/
//__attribute__((section("NMICode")))
void LowPower_Shutdown( UINT8 rm )
{
UINT8 x32Kpw, x32Mpw;
x32Kpw = R8_XT32K_TUNE;
x32Mpw = R8_XT32M_TUNE;
x32Mpw = (x32Mpw&0xfc)|0x03; // 150%额定电流
if(R16_RTC_CNT_32K>0x3fff){ // 超过500ms
x32Kpw = (x32Kpw&0xfc)|0x01; // LSE驱动电流降低到额定电流
}
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R16_POWER_PLAN = RB_PWR_PLAN_EN \
|RB_PWR_MUST_0010 \
|rm;
R8_SAFE_ACCESS_SIG = 0;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R8_BAT_DET_CTRL = 0; // 关闭电压监控
R8_XT32K_TUNE = x32Kpw;
R8_XT32M_TUNE = x32Mpw;
R16_CLK_SYS_CFG = 5; // 降频 HSI/5=6.4M
R8_SAFE_ACCESS_SIG = 0;
SCB -> SCR |= SCB_SCR_SLEEPDEEP_Msk; //deep sleep
__WFI();
R8_SAFE_ACCESS_SIG = 0;
/* 开启电压监控 */
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R8_BAT_DET_CFG = 1; // 2.05V - 2.33V
R8_BAT_DET_CTRL = RB_BAT_DET_EN;
R8_SAFE_ACCESS_SIG = 0;
__nop(); __nop();
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R8_BAT_DET_CTRL = RB_BAT_LOW_IE|RB_BAT_LOWER_IE|RB_BAT_DET_EN;
R8_RST_WDOG_CTRL |= RB_SOFTWARE_RESET;
R8_SAFE_ACCESS_SIG = 0;
}

View File

@ -0,0 +1,27 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : CH57x_lcd.c
* Author : WCH
* Version : V1.0
* Date : 2018/12/15
* Description
*******************************************************************************/
#include "CH57x_common.h"
/*******************************************************************************
* Function Name : LCD_DefInit
* Description : LCD段式屏驱动默认初始化配置
* Input : None
* Return : None
*******************************************************************************/
void LCD_DefInit( void )
{
/* 3.3V 1KHZ COM0~COM3 1/3BISA */
R8_LCD_CTRL_MOD = RB_SYS_POWER_ON \
|RB_LCD_POWER_ON \
|(1<<2) \
|(2<<3) \
|(2<<5) \
|(0<<7) ;
}

View File

@ -0,0 +1,110 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : CH57x_pwm.c
* Author : WCH
* Version : V1.0
* Date : 2018/12/15
* Description
*******************************************************************************/
#include "CH57x_common.h"
/*******************************************************************************
* Function Name : PWMX_CycleCfg
* Description : PWM4-PWM11基准时钟配置
* Input : cyc:
refer to PWMX_CycleTypeDef
* Return : None
*******************************************************************************/
void PWMX_CycleCfg( PWMX_CycleTypeDef cyc )
{
switch( cyc )
{
case PWMX_Cycle_256:
R8_PWM_CONFIG = R8_PWM_CONFIG & 0xf0;
break;
case PWMX_Cycle_255:
R8_PWM_CONFIG = (R8_PWM_CONFIG & 0xf0) | 0x01;
break;
case PWMX_Cycle_128:
R8_PWM_CONFIG = (R8_PWM_CONFIG & 0xf0) | (1<<2);
break;
case PWMX_Cycle_127:
R8_PWM_CONFIG = (R8_PWM_CONFIG & 0xf0) | (1<<2) | 0x01;
break;
case PWMX_Cycle_64:
R8_PWM_CONFIG = (R8_PWM_CONFIG & 0xf0) | (2<<2);
break;
case PWMX_Cycle_63:
R8_PWM_CONFIG = (R8_PWM_CONFIG & 0xf0) | (2<<2) | 0x01;
break;
case PWMX_Cycle_32:
R8_PWM_CONFIG = (R8_PWM_CONFIG & 0xf0) | (3<<2);
break;
case PWMX_Cycle_31:
R8_PWM_CONFIG = (R8_PWM_CONFIG & 0xf0) | (3<<2) | 0x01;
break;
default :
break;
}
}
/*******************************************************************************
* Function Name : PWMX_ACTOUT
* Description : PWM4-PWM11通道输出波形配置
* Input : ch: select channel of pwm
refer to channel of PWM define
da: effective pulse width
pr: select wave polar
refer to PWMX_PolarTypeDef
s : control pwmx function
ENABLE - PWM
DISABLE - PWM
* Return : None
*******************************************************************************/
void PWMX_ACTOUT( UINT8 ch, UINT8 da, PWMX_PolarTypeDef pr, UINT8 s)
{
UINT8 i;
if(s == DISABLE) R8_PWM_OUT_EN &= ~(ch);
else
{
(pr)?(R8_PWM_POLAR|=(ch)):(R8_PWM_POLAR&=~(ch));
for(i=0; i<8; i++)
{
if((ch>>i)&1) *((PUINT8V)((&R8_PWM4_DATA)+i)) = da;
}
R8_PWM_OUT_EN |= (ch);
}
}
/*******************************************************************************
* Function Name : PWMX_AlterOutCfg
* Description : PWM
* Input : ch: select group of PWM alternate output
RB_PWM4_5_STAG_EN - PWM4 PWM5
RB_PWM6_7_STAG_EN - PWM6 PWM7
RB_PWM8_9_STAG_EN - PWM8 PWM9
RB_PWM10_11_STAG_EN - PWM10 PWM11
s : control pwmx function
ENABLE -
DISABLE -
* Return : None
*******************************************************************************/
void PWMX_AlterOutCfg( UINT8 ch, UINT8 s)
{
if(s == DISABLE) R8_PWM_CONFIG &= ~(ch);
else R8_PWM_CONFIG |= (ch);
}

View File

@ -0,0 +1,223 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : CH57x_pwr.c
* Author : WCH
* Version : V1.0
* Date : 2018/12/15
* Description
*******************************************************************************/
#include "CH57x_common.h"
/*******************************************************************************
* Function Name : PWR_DCDCCfg
* Description : DC/DC电源
* Input : s:
ENABLE - DCDC电源
DISABLE - DCDC电源
* Return : None
*******************************************************************************/
void PWR_DCDCCfg( UINT8 s )
{
if(s == DISABLE)
{
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R16_POWER_PLAN &= ~(RB_PWR_DCDC_EN|RB_PWR_DCDC_PRE); // 旁路 DC/DC
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG0;
}
else
{
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R16_POWER_PLAN |= RB_PWR_DCDC_PRE;
DelayUs(10);
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R16_POWER_PLAN |= RB_PWR_DCDC_EN;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG0;
}
}
/*******************************************************************************
* Function Name : PWR_UnitModCfg
* Description :
* Input : s:
ENABLE -
DISABLE -
unit:
please refer to unit of controllable power supply
* Return : None
*******************************************************************************/
void PWR_UnitModCfg( UINT8 s, UINT8 unit )
{
if(s == DISABLE) //关闭
{
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
if(unit&UNIT_ETH_PHY) R8_SLP_POWER_CTRL |= RB_SLP_ETH_PWR_DN;
R8_HFCK_PWR_CTRL &= ~(unit&0x1c);
R8_CK32K_CONFIG &= ~(unit&0x03);
}
else //打开
{
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
if(unit&UNIT_ETH_PHY) R8_SLP_POWER_CTRL &= ~RB_SLP_ETH_PWR_DN;
R8_HFCK_PWR_CTRL |= (unit&0x1c);
R8_CK32K_CONFIG |= (unit&0x03);
}
R8_SAFE_ACCESS_SIG = 0;
}
/*******************************************************************************
* Function Name : PWR_PeriphClkCfg
* Description :
* Input : s:
ENABLE -
DISABLE -
perph:
please refer to Peripher CLK control bit define
* Return : None
*******************************************************************************/
void PWR_PeriphClkCfg( UINT8 s, UINT16 perph )
{
if( s == DISABLE )
{
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R32_SLEEP_CONTROL |= perph;
}
else
{
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R32_SLEEP_CONTROL &= ~perph;
}
R8_SAFE_ACCESS_SIG = 0;
}
/*******************************************************************************
* Function Name : PWR_PeriphWakeUpCfg
* Description :
* Input : s:
ENABLE -
DISABLE -
perph:
RB_SLP_USB_WAKE - USB
RB_SLP_ETH_WAKE - ETH
RB_SLP_RTC_WAKE - RTC
RB_SLP_GPIO_WAKE - GPIO
RB_SLP_BAT_WAKE - BAT
ALL -
* Return : None
*******************************************************************************/
void PWR_PeriphWakeUpCfg( UINT8 s, UINT16 perph )
{
if( s == DISABLE )
{
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R8_SLP_WAKE_CTRL &= ~perph;
}
else
{
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R8_SLP_WAKE_CTRL |= perph;
}
R8_SAFE_ACCESS_SIG = 0;
}
/*******************************************************************************
* Function Name : PowerMonitor
* Description :
* Input : s:
ENABLE -
DISABLE -
* Return : None
*******************************************************************************/
void PowerMonitor( UINT8 s )
{
if( s == DISABLE )
{
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R8_BAT_DET_CTRL = 0;
R8_SAFE_ACCESS_SIG = 0;
}
else
{
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R8_BAT_DET_CFG = 1; // 2.05V - 2.33V
R8_BAT_DET_CTRL = RB_BAT_DET_EN;
R8_SAFE_ACCESS_SIG = 0;
mDelayuS(1);
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R8_BAT_DET_CTRL = RB_BAT_LOW_IE|RB_BAT_LOWER_IE|RB_BAT_DET_EN;
R8_SAFE_ACCESS_SIG = 0;
}
}
/*******************************************************************************
* Function Name : LowPower_Idle
* Description : -Idle模式
* Input : None
* Return : None
*******************************************************************************/
void LowPower_Idle( void )
{
SCB -> SCR &= ~SCB_SCR_SLEEPDEEP_Msk; // sleep
__WFI();
}
/*******************************************************************************
* Function Name : EnterCodeUpgrade
* Description : BOOT程序
* Input : None
* Return : None
*******************************************************************************/
void EnterCodeUpgrade( void )
{
/* RTC wakeup */
UINT32 t;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R8_SLP_WAKE_CTRL |= RB_SLP_RTC_WAKE;
R16_POWER_PLAN = RB_PWR_PLAN_EN \
|RB_PWR_MUST_0010;
R8_SAFE_ACCESS_SIG = 0;
do{
t = R32_RTC_CNT_32K;
}while( t != R32_RTC_CNT_32K );
t = t + 10;
if( t>0xA8C00000 ) t -= 0xA8C00000;
if( t&0xFFFF ) t = t+0x10000;
R8_RTC_FLAG_CTRL = RB_RTC_TRIG_CLR|RB_RTC_TMR_CLR;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R32_RTC_TRIG = t;
R8_RTC_MODE_CTRL = 0x2f; // 进入boot下载必要条件
R8_SAFE_ACCESS_SIG = 0;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R16_CLK_SYS_CFG = 5; // 降频 HSI/5=6.4M
R8_SAFE_ACCESS_SIG = 0;
/* ready to BOOT */
__SEV();
__WFE();
__WFE();
while(1);
}

View File

@ -0,0 +1,324 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : CH57x_SPI0.c
* Author : WCH
* Version : V1.0
* Date : 2018/12/15
* Description
*******************************************************************************/
#include "CH57x_common.h"
/*******************************************************************************
* Function Name : SPI0_MasterDefInit
* Description : 0+3线+8MHz
* Input : None
* Return : None
*******************************************************************************/
void SPI0_MasterDefInit( void )
{
R8_SPI0_CLOCK_DIV = 4; // 主频时钟4分频
R8_SPI0_CTRL_MOD = RB_SPI_ALL_CLEAR;
R8_SPI0_CTRL_MOD = RB_SPI_MOSI_OE | RB_SPI_SCK_OE ;
R8_SPI0_CTRL_CFG |= RB_SPI_AUTO_IF; // 访问BUFFER/FIFO自动清除IF_BYTE_END标志
R8_SPI0_CTRL_CFG &= ~RB_SPI_DMA_ENABLE; // 不启动DMA方式
}
/*******************************************************************************
* Function Name : SPI0_CLKCfg
* Description : SPI0 = d*Tsys
* Input : c:
* Return : None
*******************************************************************************/
void SPI0_CLKCfg( UINT8 c )
{
if(c==2)
R8_SPI0_CTRL_CFG |= RB_SPI_MST_DLY_EN;
else
R8_SPI0_CTRL_CFG &= ~RB_SPI_MST_DLY_EN;
R8_SPI0_CLOCK_DIV = c;
}
/*******************************************************************************
* Function Name : SPI0_DataMode
* Description :
* Input : m:
refer to ModeBitOrderTypeDef
* Return : None
*******************************************************************************/
void SPI0_DataMode( ModeBitOrderTypeDef m )
{
switch( m )
{
case Mode0_LowBitINFront:
R8_SPI0_CTRL_MOD &= ~RB_SPI_MST_SCK_MOD;
R8_SPI0_CTRL_CFG |= RB_SPI_BIT_ORDER;
break;
case Mode0_HighBitINFront:
R8_SPI0_CTRL_MOD &= ~RB_SPI_MST_SCK_MOD;
R8_SPI0_CTRL_CFG &= ~RB_SPI_BIT_ORDER;
break;
case Mode3_LowBitINFront:
R8_SPI0_CTRL_MOD |= RB_SPI_MST_SCK_MOD;
R8_SPI0_CTRL_CFG |= RB_SPI_BIT_ORDER;
break;
case Mode3_HighBitINFront:
R8_SPI0_CTRL_MOD |= RB_SPI_MST_SCK_MOD;
R8_SPI0_CTRL_CFG &= ~RB_SPI_BIT_ORDER;
break;
default:
break;
}
}
/*******************************************************************************
* Function Name : SPI0_MasterSendByte
* Description : (buffer)
* Input : d:
* Return : None
*******************************************************************************/
void SPI0_MasterSendByte( UINT8 d )
{
R8_SPI0_CTRL_MOD &= ~RB_SPI_FIFO_DIR;
R8_SPI0_BUFFER = d;
while( !(R8_SPI0_INT_FLAG & RB_SPI_FREE) );
}
/*******************************************************************************
* Function Name : SPI0_MasterRecvByte
* Description : (buffer)
* Input : None
* Return :
*******************************************************************************/
UINT8 SPI0_MasterRecvByte( void )
{
R8_SPI0_CTRL_MOD &= ~RB_SPI_FIFO_DIR;
R8_SPI0_BUFFER = 0xFF; // 启动传输
while( !(R8_SPI0_INT_FLAG & RB_SPI_FREE) );
return ( R8_SPI0_BUFFER );
}
/*******************************************************************************
* Function Name : SPI0_MasterTrans
* Description : 使FIFO连续发送多字节
* Input : pbuf:
len: 4095
* Return : None
*******************************************************************************/
void SPI0_MasterTrans( UINT8 *pbuf, UINT16 len )
{
UINT16 sendlen;
sendlen = len;
R8_SPI0_CTRL_MOD &= ~RB_SPI_FIFO_DIR; // 设置数据方向为输出
R16_SPI0_TOTAL_CNT = sendlen; // 设置要发送的数据长度
R8_SPI0_INT_FLAG = RB_SPI_IF_CNT_END;
while( sendlen )
{
if( R8_SPI0_FIFO_COUNT < SPI_FIFO_SIZE )
{
R8_SPI0_FIFO = *pbuf;
pbuf++;
sendlen--;
}
}
while( R8_SPI0_FIFO_COUNT != 0 ); // 等待FIFO中的数据全部发送完成
}
/*******************************************************************************
* Function Name : SPI0_MasterRecv
* Description : 使FIFO连续接收多字节
* Input : pbuf:
len: 4095
* Return : None
*******************************************************************************/
void SPI0_MasterRecv( UINT8 *pbuf, UINT16 len )
{
UINT16 readlen;
readlen = len;
R8_SPI0_CTRL_MOD |= RB_SPI_FIFO_DIR; // 设置数据方向为输入
R16_SPI0_TOTAL_CNT = len; // 设置需要接收的数据长度FIFO方向为输入长度不为0则会启动传输 */
R8_SPI0_INT_FLAG = RB_SPI_IF_CNT_END;
while( readlen )
{
if( R8_SPI0_FIFO_COUNT )
{
*pbuf = R8_SPI0_FIFO;
pbuf++;
readlen--;
}
}
}
/*******************************************************************************
* Function Name : SPI0_MasterDMATrans
* Description : DMA方式连续发送数据
* Input : pbuf:
* len :
* Return : None
*******************************************************************************/
void SPI0_MasterDMATrans( PUINT8 pbuf, UINT16 len)
{
R8_SPI0_CTRL_MOD &= ~RB_SPI_FIFO_DIR;
R16_SPI0_DMA_BEG = (UINT32)pbuf;
R16_SPI0_DMA_END = (UINT32)(pbuf + len);
R16_SPI0_TOTAL_CNT = len;
R8_SPI0_INT_FLAG = RB_SPI_IF_CNT_END|RB_SPI_IF_DMA_END;
R8_SPI0_CTRL_CFG |= RB_SPI_DMA_ENABLE;
while(!(R8_SPI0_INT_FLAG & RB_SPI_IF_CNT_END));
R8_SPI0_CTRL_CFG &= ~RB_SPI_DMA_ENABLE;
}
/*******************************************************************************
* Function Name : SPI0_MasterDMARecv
* Description : DMA方式连续接收数据
* Input : pbuf:
* len :
* Return : None
*******************************************************************************/
void SPI0_MasterDMARecv( PUINT8 pbuf, UINT16 len)
{
R8_SPI0_CTRL_MOD |= RB_SPI_FIFO_DIR;
R16_SPI0_DMA_BEG = (UINT32)pbuf;
R16_SPI0_DMA_END = (UINT32)(pbuf + len);
R16_SPI0_TOTAL_CNT = len;
R8_SPI0_INT_FLAG = RB_SPI_IF_CNT_END|RB_SPI_IF_DMA_END;
R8_SPI0_CTRL_CFG |= RB_SPI_DMA_ENABLE;
while(!(R8_SPI0_INT_FLAG & RB_SPI_IF_CNT_END));
R8_SPI0_CTRL_CFG &= ~RB_SPI_DMA_ENABLE;
}
/*******************************************************************************
* Function Name : SPI0_SlaveInit
* Description : MISO的GPIO对应为输入模式
* Input : None
* Return : None
*******************************************************************************/
void SPI0_SlaveInit( void )
{
R8_SPI0_CTRL_MOD = RB_SPI_ALL_CLEAR;
R8_SPI0_CTRL_MOD = RB_SPI_MISO_OE | RB_SPI_MODE_SLAVE;
R8_SPI0_CTRL_CFG |= RB_SPI_AUTO_IF;
}
/*******************************************************************************
* Function Name : SPI0_SlaveRecvByte
* Description :
* Input : None
* Return :
*******************************************************************************/
UINT8 SPI0_SlaveRecvByte( void )
{
R8_SPI0_CTRL_MOD |= RB_SPI_FIFO_DIR;
while( R8_SPI0_FIFO_COUNT == 0 );
return R8_SPI0_FIFO;
}
/*******************************************************************************
* Function Name : SPI0_SlaveSendByte
* Description :
* Input : d -
* Return : None
*******************************************************************************/
void SPI0_SlaveSendByte( UINT8 d )
{
R8_SPI0_CTRL_MOD &= ~RB_SPI_FIFO_DIR;
R8_SPI0_FIFO = d;
while( R8_SPI0_FIFO_COUNT != 0 ); // 等待发送完成
}
/*******************************************************************************
* Function Name : SPI0_SlaveRecv
* Description :
* Input : pbuf:
* len :
* Return : None
*******************************************************************************/
void SPI0_SlaveRecv( PUINT8 pbuf, UINT16 len )
{
UINT16 revlen;
revlen = len;
R8_SPI0_CTRL_MOD |= RB_SPI_FIFO_DIR;
R8_SPI0_INT_FLAG = RB_SPI_IF_CNT_END;
while( revlen )
{
if( R8_SPI0_FIFO_COUNT )
{
*pbuf = R8_SPI0_FIFO;
pbuf++;
revlen--;
}
}
}
/*******************************************************************************
* Function Name : SPI0_SlaveTrans
* Description :
* Input : pbuf:
len: 4095
* Return : None
*******************************************************************************/
void SPI0_SlaveTrans( UINT8 *pbuf, UINT16 len )
{
UINT16 sendlen;
sendlen = len;
R8_SPI0_CTRL_MOD &= ~RB_SPI_FIFO_DIR; // 设置数据方向为输出
R8_SPI0_INT_FLAG = RB_SPI_IF_CNT_END;
while( sendlen )
{
if( R8_SPI0_FIFO_COUNT < SPI_FIFO_SIZE )
{
R8_SPI0_FIFO = *pbuf;
pbuf++;
sendlen--;
}
}
while( R8_SPI0_FIFO_COUNT != 0 ); // 等待FIFO中的数据全部发送完成
}
/*******************************************************************************
* Function Name : SPI0_SlaveDMARecv
* Description : DMA方式连续接收数据
* Input : pbuf:
* len :
* Return : None
*******************************************************************************/
void SPI0_SlaveDMARecv( PUINT8 pbuf, UINT16 len)
{
R8_SPI0_CTRL_MOD |= RB_SPI_FIFO_DIR;
R16_SPI0_DMA_BEG = (UINT32)pbuf;
R16_SPI0_DMA_END = (UINT32)(pbuf + len);
R16_SPI0_TOTAL_CNT = len;
R8_SPI0_INT_FLAG = RB_SPI_IF_CNT_END|RB_SPI_IF_DMA_END;
R8_SPI0_CTRL_CFG |= RB_SPI_DMA_ENABLE;
while(!(R8_SPI0_INT_FLAG & RB_SPI_IF_CNT_END));
R8_SPI0_CTRL_CFG &= ~RB_SPI_DMA_ENABLE;
}
/*******************************************************************************
* Function Name : SPI0_SlaveDMATrans
* Description : DMA方式连续发送数据
* Input : pbuf:
* len :
* Return : None
*******************************************************************************/
void SPI0_SlaveDMATrans( PUINT8 pbuf, UINT16 len)
{
R8_SPI0_CTRL_MOD &= ~RB_SPI_FIFO_DIR;
R16_SPI0_DMA_BEG = (UINT32)pbuf;
R16_SPI0_DMA_END = (UINT32)(pbuf + len);
R16_SPI0_TOTAL_CNT = len;
R8_SPI0_INT_FLAG = RB_SPI_IF_CNT_END|RB_SPI_IF_DMA_END;
R8_SPI0_CTRL_CFG |= RB_SPI_DMA_ENABLE;
while(!(R8_SPI0_INT_FLAG & RB_SPI_IF_CNT_END));
R8_SPI0_CTRL_CFG &= ~RB_SPI_DMA_ENABLE;
}

View File

@ -0,0 +1,156 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : CH57x_SPI1.c
* Author : WCH
* Version : V1.0
* Date : 2019/4/29
* Description
*******************************************************************************/
#include "CH57x_common.h"
/*******************************************************************************
* Function Name : SPI1_MasterDefInit
* Description : 0+3线+8MHz
* Input : None
* Return : None
*******************************************************************************/
void SPI1_MasterDefInit( void )
{
R8_SPI1_CLOCK_DIV = 4; // 主频时钟4分频
R8_SPI1_CTRL_MOD = RB_SPI_ALL_CLEAR;
R8_SPI1_CTRL_MOD = RB_SPI_MOSI_OE | RB_SPI_SCK_OE ;
R8_SPI1_CTRL_CFG |= RB_SPI_AUTO_IF; // 访问BUFFER/FIFO自动清除IF_BYTE_END标志
R8_SPI1_CTRL_CFG &= ~RB_SPI_DMA_ENABLE; // 不启动DMA方式
}
/*******************************************************************************
* Function Name : SPI1_CLKCfg
* Description : SPI1 = d*Tsys
* Input : c:
* Return : None
*******************************************************************************/
void SPI1_CLKCfg( UINT8 c )
{
if(c==2)
R8_SPI1_CTRL_CFG |= RB_SPI_MST_DLY_EN;
else
R8_SPI1_CTRL_CFG &= ~RB_SPI_MST_DLY_EN;
R8_SPI1_CLOCK_DIV = c;
}
/*******************************************************************************
* Function Name : SPI1_DataMode
* Description :
* Input : m:
refer to ModeBitOrderTypeDef
* Return : None
*******************************************************************************/
void SPI1_DataMode( ModeBitOrderTypeDef m )
{
switch( m )
{
case Mode0_LowBitINFront:
R8_SPI1_CTRL_MOD &= ~RB_SPI_MST_SCK_MOD;
R8_SPI1_CTRL_CFG |= RB_SPI_BIT_ORDER;
break;
case Mode0_HighBitINFront:
R8_SPI1_CTRL_MOD &= ~RB_SPI_MST_SCK_MOD;
R8_SPI1_CTRL_CFG &= ~RB_SPI_BIT_ORDER;
break;
case Mode3_LowBitINFront:
R8_SPI1_CTRL_MOD |= RB_SPI_MST_SCK_MOD;
R8_SPI1_CTRL_CFG |= RB_SPI_BIT_ORDER;
break;
case Mode3_HighBitINFront:
R8_SPI1_CTRL_MOD |= RB_SPI_MST_SCK_MOD;
R8_SPI1_CTRL_CFG &= ~RB_SPI_BIT_ORDER;
break;
default:
break;
}
}
/*******************************************************************************
* Function Name : SPI1_MasterSendByte
* Description : (buffer)
* Input : d:
* Return : None
*******************************************************************************/
void SPI1_MasterSendByte( UINT8 d )
{
R8_SPI1_CTRL_MOD &= ~RB_SPI_FIFO_DIR;
R8_SPI1_BUFFER = d;
while( !(R8_SPI1_INT_FLAG & RB_SPI_FREE) );
}
/*******************************************************************************
* Function Name : SPI1_MasterRecvByte
* Description : (buffer)
* Input : None
* Return :
*******************************************************************************/
UINT8 SPI1_MasterRecvByte( void )
{
R8_SPI1_CTRL_MOD &= ~RB_SPI_FIFO_DIR;
R8_SPI1_BUFFER = 0xFF; // 启动传输
while( !(R8_SPI1_INT_FLAG & RB_SPI_FREE) );
return ( R8_SPI1_BUFFER );
}
/*******************************************************************************
* Function Name : SPI1_MasterTrans
* Description : 使FIFO连续发送多字节
* Input : pbuf:
len: 4095
* Return : None
*******************************************************************************/
void SPI1_MasterTrans( UINT8 *pbuf, UINT16 len )
{
UINT16 sendlen;
sendlen = len;
R8_SPI1_CTRL_MOD &= ~RB_SPI_FIFO_DIR; // 设置数据方向为输出
R16_SPI1_TOTAL_CNT = sendlen; // 设置要发送的数据长度
R8_SPI1_INT_FLAG = RB_SPI_IF_CNT_END;
while( sendlen )
{
if( R8_SPI1_FIFO_COUNT < SPI_FIFO_SIZE )
{
R8_SPI1_FIFO = *pbuf;
pbuf++;
sendlen--;
}
}
while( R8_SPI1_FIFO_COUNT != 0 ); // 等待FIFO中的数据全部发送完成
}
/*******************************************************************************
* Function Name : SPI1_MasterRecv
* Description : 使FIFO连续接收多字节
* Input : pbuf:
len: 4095
* Return : None
*******************************************************************************/
void SPI1_MasterRecv( UINT8 *pbuf, UINT16 len )
{
UINT16 readlen;
readlen = len;
R8_SPI1_CTRL_MOD |= RB_SPI_FIFO_DIR; // 设置数据方向为输入
R16_SPI1_TOTAL_CNT = len; // 设置需要接收的数据长度FIFO方向为输入长度不为0则会启动传输 */
R8_SPI1_INT_FLAG = RB_SPI_IF_CNT_END;
while( readlen )
{
if( R8_SPI1_FIFO_COUNT )
{
*pbuf = R8_SPI1_FIFO;
pbuf++;
readlen--;
}
}
}

View File

@ -0,0 +1,193 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : CH57x_SYS.c
* Author : WCH
* Version : V1.0
* Date : 2018/12/15
* Description
*******************************************************************************/
#include "CH57x_common.h"
/*******************************************************************************
* Function Name : SYS_GetInfoSta
* Description :
* Input : i:
refer to SYS_InfoStaTypeDef
* Return : DISABLE -
ENABLE -
*******************************************************************************/
UINT8 SYS_GetInfoSta( SYS_InfoStaTypeDef i )
{
if(i == STA_SAFEACC_ACT)
return (R8_SAFE_ACCESS_SIG & RB_SAFE_ACC_ACT);
else
return (R8_GLOB_CFG_INFO&(1<<i));
}
/*******************************************************************************
* Function Name : SYS_ResetExecute
* Description :
* Input : None
* Return : None
*******************************************************************************/
void SYS_ResetExecute( void )
{
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R8_RST_WDOG_CTRL |= RB_SOFTWARE_RESET;
R8_SAFE_ACCESS_SIG = 0;
}
/*******************************************************************************
* Function Name : SYS_DisableAllIrq
* Description :
* Input : pirqv
* Return : None
*******************************************************************************/
void SYS_DisableAllIrq( PUINT32 pirqv)
{
*pirqv = NVIC->ISER[0];
NVIC->ICER[0] = 0xffffffff;
}
/*******************************************************************************
* Function Name : SYS_RecoverIrq
* Description :
* Input : irq_status
* Return : None
*******************************************************************************/
void SYS_RecoverIrq( UINT32 irq_status )
{
NVIC->ISER[0] = irq_status;
}
/*******************************************************************************
* Function Name : SYS_GetSysTickCnt
* Description : (SYSTICK)
* Input : None
* Return :
*******************************************************************************/
UINT32 SYS_GetSysTickCnt( void )
{
return(SysTick->VAL );
}
/*******************************************************************************
* Function Name : WWDG_ITCfg
* Description : 使
* Input : DISABLE- ENABLE-
* Return : None
*******************************************************************************/
void WWDG_ITCfg( UINT8 s )
{
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
if(s == DISABLE) R8_RST_WDOG_CTRL&=~RB_WDOG_INT_EN;
else R8_RST_WDOG_CTRL|=RB_WDOG_INT_EN;
R8_SAFE_ACCESS_SIG = 0;
}
/*******************************************************************************
* Function Name : WWDG_ResetCfg
* Description :
* Input : DISABLE- ENABLE-
* Return : None
*******************************************************************************/
void WWDG_ResetCfg( UINT8 s )
{
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
if(s == DISABLE) R8_RST_WDOG_CTRL&=~RB_WDOG_RST_EN;
else R8_RST_WDOG_CTRL|=RB_WDOG_RST_EN;
R8_SAFE_ACCESS_SIG = 0;
}
/*******************************************************************************
* Function Name : WWDG_ClearFlag
* Description :
* Input : None
* Return : None
*******************************************************************************/
void WWDG_ClearFlag( void )
{
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
R8_RST_WDOG_CTRL |= RB_WDOG_INT_FLAG;
R8_SAFE_ACCESS_SIG = 0;
}
/*******************************************************************************
* Function Name : mDelayuS
* Description : uS
* Input : t:
* Return : None
*******************************************************************************/
void mDelayuS( UINT16 t )
{
UINT16 i, j;
for(j=0; j<t; j++)
{
#if (FREQ_SYS == 40000000)
for(i=0; i<4; i++) __nop();
#elif (FREQ_SYS == 32000000)
i = 2;
while(i--) { __nop(); __nop(); }
#elif (FREQ_SYS == 24000000)
i = 1;
while(i--) { __nop(); __nop(); }
#elif (FREQ_SYS == 20000000)
for(i=0; i<1; i++) __nop();
#elif (FREQ_SYS == 16000000)
__nop(); __nop(); __nop(); __nop();
__nop(); __nop(); __nop(); __nop(); __nop();
#elif (FREQ_SYS == 8000000)
__nop(); __nop();
#endif
}
}
/*******************************************************************************
* Function Name : mDelaymS
* Description : mS
* Input : t:
* Return : None
*******************************************************************************/
void mDelaymS( UINT16 t )
{
UINT16 i;
for(i=0; i<t; i++)
mDelayuS(1000);
}
#if( defined DEBUG)
int fputc( int c, FILE *f )
{
#if DEBUG == Debug_UART0
while( R8_UART0_TFC == UART_FIFO_SIZE ); /* 等待数据发送 */
R8_UART0_THR = c; /* 发送数据 */
#elif DEBUG == Debug_UART1
while( R8_UART1_TFC == UART_FIFO_SIZE ); /* 等待数据发送 */
R8_UART1_THR = c; /* 发送数据 */
#elif DEBUG == Debug_UART2
while( R8_UART2_TFC == UART_FIFO_SIZE ); /* 等待数据发送 */
R8_UART2_THR = c; /* 发送数据 */
#elif DEBUG == Debug_UART3
while( R8_UART3_TFC == UART_FIFO_SIZE ); /* 等待数据发送 */
R8_UART3_THR = c; /* 发送数据 */
#endif
return( c );
}
#endif

View File

@ -0,0 +1,96 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : CH57x_timer0.c
* Author : WCH
* Version : V1.0
* Date : 2018/12/15
* Description
*******************************************************************************/
#include "CH57x_common.h"
/*******************************************************************************
* Function Name : TMR0_TimerInit
* Description :
* Input : t: Tsys, 67108864
* Return : None
*******************************************************************************/
void TMR0_TimerInit( UINT32 t )
{
R32_TMR0_CNT_END = t;
R8_TMR0_CTRL_MOD = RB_TMR_ALL_CLEAR;
R8_TMR0_CTRL_MOD = RB_TMR_COUNT_EN;
}
/*******************************************************************************
* Function Name : TMR0_EXTSingleCounterInit
* Description :
* Input : c: , 67108864
* Return : None
*******************************************************************************/
void TMR0_EXTSingleCounterInit( UINT32 c )
{
R32_TMR0_CNT_END = c;
R8_TMR0_CTRL_MOD = RB_TMR_ALL_CLEAR;
R8_TMR0_CTRL_MOD = RB_TMR_CAP_COUNT|RB_TMR_MODE_IN|RB_TMR_COUNT_EN;
}
/*******************************************************************************
* Function Name : TMR0_CountInit
* Description : 沿
* Input : cap:
CAP_NULL -
Edge_To_Edge - 沿
FallEdge_To_FallEdge - 沿
RiseEdge_To_RiseEdge - 沿
* Return : None
*******************************************************************************/
void TMR0_CountInit( CapModeTypeDef cap )
{
R8_TMR0_CTRL_MOD = RB_TMR_ALL_CLEAR;
R8_TMR0_CTRL_MOD = RB_TMR_COUNT_EN \
|RB_TMR_CAP_COUNT \
|RB_TMR_MODE_IN \
|(cap<<6);
}
/*******************************************************************************
* Function Name : TMR0_PWMInit
* Description : PWM
* Input : pr: select wave polar
refer to PWMX_PolarTypeDef
ts: set pwm repeat times
refer to PWM_RepeatTsTypeDef
* Return : None
*******************************************************************************/
void TMR0_PWMInit( PWMX_PolarTypeDef pr, PWM_RepeatTsTypeDef ts )
{
// R8_TMR0_CTRL_MOD = RB_TMR_ALL_CLEAR;
R8_TMR0_CTRL_MOD = RB_TMR_COUNT_EN \
|RB_TMR_OUT_EN \
|(pr<<4) \
|(ts<<6);
}
/*******************************************************************************
* Function Name : TMR0_CapInit
* Description :
* Input : cap: select capture mode
refer to CapModeTypeDef
* Return : None
*******************************************************************************/
void TMR0_CapInit( CapModeTypeDef cap )
{
R8_TMR0_CTRL_MOD = RB_TMR_ALL_CLEAR;
R8_TMR0_CTRL_MOD = RB_TMR_COUNT_EN \
|RB_TMR_MODE_IN \
|(cap<<6);
}

View File

@ -0,0 +1,118 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : CH57x_timer1.c
* Author : WCH
* Version : V1.0
* Date : 2018/12/15
* Description
*******************************************************************************/
#include "CH57x_common.h"
/*******************************************************************************
* Function Name : TMR1_TimerInit
* Description :
* Input : t: Tsys, 67108864
* Return : None
*******************************************************************************/
void TMR1_TimerInit( UINT32 t )
{
R32_TMR1_CNT_END = t;
R8_TMR1_CTRL_MOD = RB_TMR_ALL_CLEAR;
R8_TMR1_CTRL_MOD = RB_TMR_COUNT_EN;
}
/*******************************************************************************
* Function Name : TMR1_EXTSingleCounterInit
* Description :
* Input : c: , 67108864
* Return : None
*******************************************************************************/
void TMR1_EXTSingleCounterInit( UINT32 c )
{
R32_TMR1_CNT_END = c;
R8_TMR1_CTRL_MOD = RB_TMR_ALL_CLEAR;
R8_TMR1_CTRL_MOD = RB_TMR_CAP_COUNT|RB_TMR_MODE_IN|RB_TMR_COUNT_EN;
}
/*******************************************************************************
* Function Name : TMR1_CountInit
* Description : 沿
* Input : cap:
CAP_NULL -
Edge_To_Edge - 沿
FallEdge_To_FallEdge - 沿
RiseEdge_To_RiseEdge - 沿
* Return : None
*******************************************************************************/
void TMR1_CountInit( CapModeTypeDef cap )
{
R8_TMR1_CTRL_MOD = RB_TMR_ALL_CLEAR;
R8_TMR1_CTRL_MOD = RB_TMR_COUNT_EN \
|RB_TMR_CAP_COUNT \
|RB_TMR_MODE_IN \
|(cap<<6);
}
/*******************************************************************************
* Function Name : TMR1_PWMInit
* Description : PWM
* Input : pr: select wave polar
refer to PWMX_PolarTypeDef
ts: set pwm repeat times
refer to PWM_RepeatTsTypeDef
* Return : None
*******************************************************************************/
void TMR1_PWMInit( PWMX_PolarTypeDef pr, PWM_RepeatTsTypeDef ts )
{
// R8_TMR1_CTRL_MOD = RB_TMR_ALL_CLEAR;
R8_TMR1_CTRL_MOD = RB_TMR_COUNT_EN \
|RB_TMR_OUT_EN \
|(pr<<4) \
|(ts<<6);
}
/*******************************************************************************
* Function Name : TMR1_CapInit
* Description :
* Input : cap: select capture mode
refer to CapModeTypeDef
* Return : None
*******************************************************************************/
void TMR1_CapInit( CapModeTypeDef cap )
{
R8_TMR1_CTRL_MOD = RB_TMR_ALL_CLEAR;
R8_TMR1_CTRL_MOD = RB_TMR_COUNT_EN \
|RB_TMR_MODE_IN \
|(cap<<6);
}
/*******************************************************************************
* Function Name : TMR1_DMACfg
* Description : DMA功能
* Input : s:
ENABLE -
DISABLE -
startAddr DMA
endAddr DMA结束地址
mDMA模式
* Return : None
*******************************************************************************/
void TMR1_DMACfg( UINT8 s, UINT16 startAddr, UINT16 endAddr, DMAModeTypeDef m )
{
if(s == DISABLE){
R8_TMR1_CTRL_DMA = 0;
}
else{
R16_TMR1_DMA_BEG = startAddr;
R16_TMR1_DMA_END = endAddr;
if(m) R8_TMR1_CTRL_DMA = RB_TMR_DMA_LOOP|RB_TMR_DMA_ENABLE;
else R8_TMR1_CTRL_DMA = RB_TMR_DMA_ENABLE;
}
}

View File

@ -0,0 +1,118 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : CH57x_timer2.c
* Author : WCH
* Version : V1.0
* Date : 2018/12/15
* Description
*******************************************************************************/
#include "CH57x_common.h"
/*******************************************************************************
* Function Name : TMR2_TimerInit
* Description :
* Input : t: Tsys, 67108864
* Return : None
*******************************************************************************/
void TMR2_TimerInit( UINT32 t )
{
R32_TMR2_CNT_END = t;
R8_TMR2_CTRL_MOD = RB_TMR_ALL_CLEAR;
R8_TMR2_CTRL_MOD = RB_TMR_COUNT_EN;
}
/*******************************************************************************
* Function Name : TMR2_EXTSingleCounterInit
* Description :
* Input : c: , 67108864
* Return : None
*******************************************************************************/
void TMR2_EXTSingleCounterInit( UINT32 c )
{
R32_TMR2_CNT_END = c;
R8_TMR2_CTRL_MOD = RB_TMR_ALL_CLEAR;
R8_TMR2_CTRL_MOD = RB_TMR_CAP_COUNT|RB_TMR_MODE_IN|RB_TMR_COUNT_EN;
}
/*******************************************************************************
* Function Name : TMR2_CountInit
* Description : 沿
* Input : cap:
CAP_NULL -
Edge_To_Edge - 沿
FallEdge_To_FallEdge - 沿
RiseEdge_To_RiseEdge - 沿
* Return : None
*******************************************************************************/
void TMR2_CountInit( CapModeTypeDef cap )
{
R8_TMR2_CTRL_MOD = RB_TMR_ALL_CLEAR;
R8_TMR2_CTRL_MOD = RB_TMR_COUNT_EN \
|RB_TMR_CAP_COUNT \
|RB_TMR_MODE_IN \
|(cap<<6);
}
/*******************************************************************************
* Function Name : TMR2_PWMInit
* Description : PWM
* Input : pr: select wave polar
refer to PWMX_PolarTypeDef
ts: set pwm repeat times
refer to PWM_RepeatTsTypeDef
* Return : None
*******************************************************************************/
void TMR2_PWMInit( PWMX_PolarTypeDef pr, PWM_RepeatTsTypeDef ts )
{
// R8_TMR2_CTRL_MOD = RB_TMR_ALL_CLEAR;
R8_TMR2_CTRL_MOD = RB_TMR_COUNT_EN \
|RB_TMR_OUT_EN \
|(pr<<4) \
|(ts<<6);
}
/*******************************************************************************
* Function Name : TMR2_CapInit
* Description :
* Input : cap: select capture mode
refer to CapModeTypeDef
* Return : None
*******************************************************************************/
void TMR2_CapInit( CapModeTypeDef cap )
{
R8_TMR2_CTRL_MOD = RB_TMR_ALL_CLEAR;
R8_TMR2_CTRL_MOD = RB_TMR_COUNT_EN \
|RB_TMR_MODE_IN \
|(cap<<6);
}
/*******************************************************************************
* Function Name : TMR2_DMACfg
* Description : DMA功能
* Input : s:
ENABLE -
DISABLE -
startAddr DMA
endAddr DMA结束地址
mDMA模式
* Return : None
*******************************************************************************/
void TMR2_DMACfg( UINT8 s, UINT16 startAddr, UINT16 endAddr, DMAModeTypeDef m )
{
if(s == DISABLE){
R8_TMR2_CTRL_DMA = 0;
}
else{
R16_TMR2_DMA_BEG = startAddr;
R16_TMR2_DMA_END = endAddr;
if(m) R8_TMR2_CTRL_DMA = RB_TMR_DMA_LOOP|RB_TMR_DMA_ENABLE;
else R8_TMR2_CTRL_DMA = RB_TMR_DMA_ENABLE;
}
}

View File

@ -0,0 +1,96 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : CH57x_timer3.c
* Author : WCH
* Version : V1.0
* Date : 2018/12/15
* Description
*******************************************************************************/
#include "CH57x_common.h"
/*******************************************************************************
* Function Name : TMR3_TimerInit
* Description :
* Input : t: Tsys, 67108864
* Return : None
*******************************************************************************/
void TMR3_TimerInit( UINT32 t )
{
R32_TMR3_CNT_END = t;
R8_TMR3_CTRL_MOD = RB_TMR_ALL_CLEAR;
R8_TMR3_CTRL_MOD = RB_TMR_COUNT_EN;
}
/*******************************************************************************
* Function Name : TMR3_EXTSingleCounterInit
* Description :
* Input : c: , 67108864
* Return : None
*******************************************************************************/
void TMR3_EXTSingleCounterInit( UINT32 c )
{
R32_TMR3_CNT_END = c;
R8_TMR3_CTRL_MOD = RB_TMR_ALL_CLEAR;
R8_TMR3_CTRL_MOD = RB_TMR_CAP_COUNT|RB_TMR_MODE_IN|RB_TMR_COUNT_EN;
}
/*******************************************************************************
* Function Name : TMR3_CountInit
* Description : 沿
* Input : cap:
CAP_NULL -
Edge_To_Edge - 沿
FallEdge_To_FallEdge - 沿
RiseEdge_To_RiseEdge - 沿
* Return : None
*******************************************************************************/
void TMR3_CountInit( CapModeTypeDef cap )
{
R8_TMR3_CTRL_MOD = RB_TMR_ALL_CLEAR;
R8_TMR3_CTRL_MOD = RB_TMR_COUNT_EN \
|RB_TMR_CAP_COUNT \
|RB_TMR_MODE_IN \
|(cap<<6);
}
/*******************************************************************************
* Function Name : TMR3_PWMInit
* Description : PWM
* Input : pr: select wave polar
refer to PWMX_PolarTypeDef
ts: set pwm repeat times
refer to PWM_RepeatTsTypeDef
* Return : None
*******************************************************************************/
void TMR3_PWMInit( PWMX_PolarTypeDef pr, PWM_RepeatTsTypeDef ts )
{
// R8_TMR3_CTRL_MOD = RB_TMR_ALL_CLEAR;
R8_TMR3_CTRL_MOD = RB_TMR_COUNT_EN \
|RB_TMR_OUT_EN \
|(pr<<4) \
|(ts<<6);
}
/*******************************************************************************
* Function Name : TMR3_CapInit
* Description :
* Input : cap: select capture mode
refer to CapModeTypeDef
* Return : None
*******************************************************************************/
void TMR3_CapInit( CapModeTypeDef cap )
{
R8_TMR3_CTRL_MOD = RB_TMR_ALL_CLEAR;
R8_TMR3_CTRL_MOD = RB_TMR_COUNT_EN \
|RB_TMR_MODE_IN \
|(cap<<6);
}

View File

@ -0,0 +1,130 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : CH57x_uart0.c
* Author : WCH
* Version : V1.0
* Date : 2018/12/15
* Description
*******************************************************************************/
#include "CH57x_common.h"
/*******************************************************************************
* Function Name : UART0_DefInit
* Description :
* Input : None
* Return : None
*******************************************************************************/
void UART0_DefInit( void )
{
UART0_BaudRateCfg( 115200 );
R8_UART0_FCR = (2<<6) | RB_FCR_TX_FIFO_CLR | RB_FCR_RX_FIFO_CLR | RB_FCR_FIFO_EN; // FIFO打开触发点4字节
R8_UART0_LCR = RB_LCR_WORD_SZ;
R8_UART0_IER = RB_IER_TXD_EN;
R8_UART0_DIV = 1;
}
/*******************************************************************************
* Function Name : UART0_BaudRateCfg
* Description :
* Input :
* Return :
*******************************************************************************/
void UART0_BaudRateCfg( UINT32 baudrate )
{
UINT32 x;
x = 10 * GetSysClock() / 8 / baudrate;
x = ( x + 5 ) / 10;
R16_UART0_DL = (UINT16)x;
}
/*******************************************************************************
* Function Name : UART0_ByteTrigCfg
* Description :
* Input : b:
refer to UARTByteTRIGTypeDef
* Return :
*******************************************************************************/
void UART0_ByteTrigCfg( UARTByteTRIGTypeDef b )
{
R8_UART0_FCR = (R8_UART0_FCR&~RB_FCR_FIFO_TRIG)|(b<<6);
}
/*******************************************************************************
* Function Name : UART0_INTCfg
* Description :
* Input : s:
ENABLE - 使
DISABLE -
i:
RB_IER_MODEM_CHG - 使 UART0
RB_IER_LINE_STAT - 线
RB_IER_THR_EMPTY -
RB_IER_RECV_RDY -
* Return : None
*******************************************************************************/
void UART0_INTCfg( UINT8 s, UINT8 i )
{
if( s )
{
R8_UART0_IER |= i;
R8_UART0_MCR |= RB_MCR_INT_OE;
}
else
{
R8_UART0_IER &= ~i;
}
}
/*******************************************************************************
* Function Name : UART0_Reset
* Description :
* Input : None
* Return : None
*******************************************************************************/
void UART0_Reset( void )
{
R8_UART0_IER = RB_IER_RESET;
}
/*******************************************************************************
* Function Name : UART0_SendString
* Description :
* Input : buf -
l -
* Return : None
*******************************************************************************/
void UART0_SendString( PUINT8 buf, UINT16 l )
{
UINT16 len = l;
while(len)
{
if(R8_UART0_TFC != UART_FIFO_SIZE)
{
R8_UART0_THR = *buf++;
len--;
}
}
}
/*******************************************************************************
* Function Name : UART0_RecvString
* Description :
* Input : buf -
* Return :
*******************************************************************************/
UINT16 UART0_RecvString( PUINT8 buf )
{
UINT16 len = 0;
while( R8_UART0_RFC )
{
*buf++ = R8_UART0_RBR;
len ++;
}
return (len);
}

View File

@ -0,0 +1,130 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : CH57x_uart1.c
* Author : WCH
* Version : V1.0
* Date : 2018/12/15
* Description
*******************************************************************************/
#include "CH57x_common.h"
/*******************************************************************************
* Function Name : UART1_DefInit
* Description :
* Input : None
* Return : None
*******************************************************************************/
void UART1_DefInit( void )
{
UART1_BaudRateCfg( 115200 );
R8_UART1_FCR = (2<<6) | RB_FCR_TX_FIFO_CLR | RB_FCR_RX_FIFO_CLR | RB_FCR_FIFO_EN; // FIFO打开触发点4字节
R8_UART1_LCR = RB_LCR_WORD_SZ;
R8_UART1_IER = RB_IER_TXD_EN;
R8_UART1_DIV = 1;
}
/*******************************************************************************
* Function Name : UART1_BaudRateCfg
* Description :
* Input :
* Return :
*******************************************************************************/
void UART1_BaudRateCfg( UINT32 baudrate )
{
UINT32 x;
x = 10 * GetSysClock() / 8 / baudrate;
x = ( x + 5 ) / 10;
R16_UART1_DL = (UINT16)x;
}
/*******************************************************************************
* Function Name : UART1_ByteTrigCfg
* Description :
* Input : b:
refer to UARTByteTRIGTypeDef
* Return :
*******************************************************************************/
void UART1_ByteTrigCfg( UARTByteTRIGTypeDef b )
{
R8_UART1_FCR = (R8_UART1_FCR&~RB_FCR_FIFO_TRIG)|(b<<6);
}
/*******************************************************************************
* Function Name : UART1_INTCfg
* Description :
* Input : s:
ENABLE - 使
DISABLE -
i:
RB_IER_MODEM_CHG - 使 UART0
RB_IER_LINE_STAT - 线
RB_IER_THR_EMPTY -
RB_IER_RECV_RDY -
* Return : None
*******************************************************************************/
void UART1_INTCfg( UINT8 s, UINT8 i )
{
if( s )
{
R8_UART1_IER |= i;
R8_UART1_MCR |= RB_MCR_INT_OE;
}
else
{
R8_UART1_IER &= ~i;
}
}
/*******************************************************************************
* Function Name : UART1_Reset
* Description :
* Input : None
* Return : None
*******************************************************************************/
void UART1_Reset( void )
{
R8_UART1_IER = RB_IER_RESET;
}
/*******************************************************************************
* Function Name : UART1_SendString
* Description :
* Input : buf -
l -
* Return : None
*******************************************************************************/
void UART1_SendString( PUINT8 buf, UINT16 l )
{
UINT16 len = l;
while(len)
{
if(R8_UART1_TFC != UART_FIFO_SIZE)
{
R8_UART1_THR = *buf++;
len--;
}
}
}
/*******************************************************************************
* Function Name : UART1_RecvString
* Description :
* Input : buf -
* Return :
*******************************************************************************/
UINT16 UART1_RecvString( PUINT8 buf )
{
UINT16 len = 0;
while( R8_UART1_RFC )
{
*buf++ = R8_UART1_RBR;
len ++;
}
return (len);
}

View File

@ -0,0 +1,130 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : CH57x_uart2.c
* Author : WCH
* Version : V1.0
* Date : 2018/12/15
* Description
*******************************************************************************/
#include "CH57x_common.h"
/*******************************************************************************
* Function Name : UART2_DefInit
* Description :
* Input : None
* Return : None
*******************************************************************************/
void UART2_DefInit( void )
{
UART2_BaudRateCfg( 115200 );
R8_UART2_FCR = (2<<6) | RB_FCR_TX_FIFO_CLR | RB_FCR_RX_FIFO_CLR | RB_FCR_FIFO_EN; // FIFO打开触发点4字节
R8_UART2_LCR = RB_LCR_WORD_SZ;
R8_UART2_IER = RB_IER_TXD_EN;
R8_UART2_DIV = 1;
}
/*******************************************************************************
* Function Name : UART2_BaudRateCfg
* Description :
* Input :
* Return :
*******************************************************************************/
void UART2_BaudRateCfg( UINT32 baudrate )
{
UINT32 x;
x = 10 * GetSysClock() / 8 / baudrate;
x = ( x + 5 ) / 10;
R16_UART2_DL = (UINT16)x;
}
/*******************************************************************************
* Function Name : UART2_ByteTrigCfg
* Description :
* Input : b:
refer to UARTByteTRIGTypeDef
* Return :
*******************************************************************************/
void UART2_ByteTrigCfg( UARTByteTRIGTypeDef b )
{
R8_UART2_FCR = (R8_UART2_FCR&~RB_FCR_FIFO_TRIG)|(b<<6);
}
/*******************************************************************************
* Function Name : UART2_INTCfg
* Description :
* Input : s:
ENABLE - 使
DISABLE -
i:
RB_IER_MODEM_CHG - 使 UART0
RB_IER_LINE_STAT - 线
RB_IER_THR_EMPTY -
RB_IER_RECV_RDY -
* Return : None
*******************************************************************************/
void UART2_INTCfg( UINT8 s, UINT8 i )
{
if( s )
{
R8_UART2_IER |= i;
R8_UART2_MCR |= RB_MCR_INT_OE;
}
else
{
R8_UART2_IER &= ~i;
}
}
/*******************************************************************************
* Function Name : UART2_Reset
* Description :
* Input : None
* Return : None
*******************************************************************************/
void UART2_Reset( void )
{
R8_UART2_IER = RB_IER_RESET;
}
/*******************************************************************************
* Function Name : UART2_SendString
* Description :
* Input : buf -
l -
* Return : None
*******************************************************************************/
void UART2_SendString( PUINT8 buf, UINT16 l )
{
UINT16 len = l;
while(len)
{
if(R8_UART2_TFC != UART_FIFO_SIZE)
{
R8_UART2_THR = *buf++;
len--;
}
}
}
/*******************************************************************************
* Function Name : UART2_RecvString
* Description :
* Input : buf -
* Return :
*******************************************************************************/
UINT16 UART2_RecvString( PUINT8 buf )
{
UINT16 len = 0;
while( R8_UART2_RFC )
{
*buf++ = R8_UART2_RBR;
len ++;
}
return (len);
}

View File

@ -0,0 +1,130 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : CH57x_uart3.c
* Author : WCH
* Version : V1.0
* Date : 2018/12/15
* Description
*******************************************************************************/
#include "CH57x_common.h"
/*******************************************************************************
* Function Name : UART3_DefInit
* Description :
* Input : None
* Return : None
*******************************************************************************/
void UART3_DefInit( void )
{
UART3_BaudRateCfg( 115200 );
R8_UART3_FCR = (2<<6) | RB_FCR_TX_FIFO_CLR | RB_FCR_RX_FIFO_CLR | RB_FCR_FIFO_EN; // FIFO打开触发点4字节
R8_UART3_LCR = RB_LCR_WORD_SZ;
R8_UART3_IER = RB_IER_TXD_EN;
R8_UART3_DIV = 1;
}
/*******************************************************************************
* Function Name : UART3_BaudRateCfg
* Description :
* Input :
* Return :
*******************************************************************************/
void UART3_BaudRateCfg( UINT32 baudrate )
{
UINT32 x;
x = 10 * GetSysClock() / 8 / baudrate;
x = ( x + 5 ) / 10;
R16_UART3_DL = (UINT16)x;
}
/*******************************************************************************
* Function Name : UART3_ByteTrigCfg
* Description :
* Input : b:
refer to UARTByteTRIGTypeDef
* Return :
*******************************************************************************/
void UART3_ByteTrigCfg( UARTByteTRIGTypeDef b )
{
R8_UART3_FCR = (R8_UART3_FCR&~RB_FCR_FIFO_TRIG)|(b<<6);
}
/*******************************************************************************
* Function Name : UART3_INTCfg
* Description :
* Input : s:
ENABLE - 使
DISABLE -
i:
RB_IER_MODEM_CHG - 使 UART0
RB_IER_LINE_STAT - 线
RB_IER_THR_EMPTY -
RB_IER_RECV_RDY -
* Return : None
*******************************************************************************/
void UART3_INTCfg( UINT8 s, UINT8 i )
{
if( s )
{
R8_UART3_IER |= i;
R8_UART3_MCR |= RB_MCR_INT_OE;
}
else
{
R8_UART3_IER &= ~i;
}
}
/*******************************************************************************
* Function Name : UART3_Reset
* Description :
* Input : None
* Return : None
*******************************************************************************/
void UART3_Reset( void )
{
R8_UART3_IER = RB_IER_RESET;
}
/*******************************************************************************
* Function Name : UART3_SendString
* Description :
* Input : buf -
l -
* Return : None
*******************************************************************************/
void UART3_SendString( PUINT8 buf, UINT16 l )
{
UINT16 len = l;
while(len)
{
if(R8_UART3_TFC != UART_FIFO_SIZE)
{
R8_UART3_THR = *buf++;
len--;
}
}
}
/*******************************************************************************
* Function Name : UART3_RecvString
* Description :
* Input : buf -
* Return :
*******************************************************************************/
UINT16 UART3_RecvString( PUINT8 buf )
{
UINT16 len = 0;
while( R8_UART3_RFC )
{
*buf++ = R8_UART3_RBR;
len ++;
}
return (len);
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,112 @@
#ifndef __CH57x_ADC_H__
#define __CH57x_ADC_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "CH579SFR.h"
#include "core_cm0.h"
#define ROM_TMP_85C_ADDR 0x40634
#define ROM_TMP_25C_ADDR 0x40638
/**
* @brief adc single channel define
*/
typedef enum
{
CH_EXTIN_0 = 0, // ADC 外部模拟通道 0
CH_EXTIN_1, // ADC 外部模拟通道 1
CH_EXTIN_2, // ADC 外部模拟通道 2
CH_EXTIN_3, // ADC 外部模拟通道 3
CH_EXTIN_4, // ADC 外部模拟通道 4
CH_EXTIN_5, // ADC 外部模拟通道 5
CH_EXTIN_6, // ADC 外部模拟通道 6
CH_EXTIN_7, // ADC 外部模拟通道 7
CH_EXTIN_8, // ADC 外部模拟通道 8
CH_EXTIN_9, // ADC 外部模拟通道 9
CH_EXTIN_10, // ADC 外部模拟通道 10
CH_EXTIN_11, // ADC 外部模拟通道 11
CH_EXTIN_12, // ADC 外部模拟通道 12
CH_EXTIN_13, // ADC 外部模拟通道 13
CH_INTE_VBAT, // ADC 内部电池检测通道
CH_INTE_VTEMP, // ADC 内部温度传感器检测通道
}ADC_SingleChannelTypeDef;
/**
* @brief adc differential channel define
*/
typedef enum
{
CH_DIFF_0_2 = 0, // ADC 差分通道 #0-#2
CH_DIFF_1_3, // ADC 差分通道 #1-#3
}ADC_DiffChannelTypeDef;
/**
* @brief adc sampling clock
*/
typedef enum
{
SampleFreq_3_2 = 0, // 3.2M 采样频率
SampleFreq_2_67, // 2.67M 采样频率
SampleFreq_5_33, // 5.33M 采样频率
SampleFreq_4, // 4M 采样频率
}ADC_SampClkTypeDef;
/**
* @brief adc signal PGA
*/
typedef enum
{
ADC_PGA_1_4 = 0, // -12dB, 1/4倍
ADC_PGA_1_2, // -6dB, 1/2倍
ADC_PGA_0, // 0dB, 1倍无增益
ADC_PGA_2, // 6dB, 2倍
}ADC_SignalPGATypeDef;
// refer to ADC_SingleChannelTypeDef
#define ADC_ChannelCfg( d ) (R8_ADC_CHANNEL = d) /* 设置 ADC 采样通道 */
// refer to ADC_SampClkTypeDef
#define ADC_SampClkCfg( d ) (R8_ADC_CFG=R8_ADC_CFG&(~RB_ADC_CLK_DIV)|(d<<6)) /* 设置 ADC 采样时钟 */
// refer to ADC_SignalPGATypeDef
#define ADC_PGACfg( d ) (R8_ADC_CFG=R8_ADC_CFG&(~RB_ADC_PGA_GAIN)|(d<<4)) /* 设置 ADC 信号增益 */
#define ADC_TempCalibCfg( d ) (R8_TEM_SENSOR=R8_TEM_SENSOR&(~RB_TEM_SEN_CALIB)|d) /* 设置内部温度传感器校准值 */
void ADC_ExtSingleChSampInit( ADC_SampClkTypeDef sp, ADC_SignalPGATypeDef ga ); /* 外部信号单通道采样初始化 */
void ADC_ExtDiffChSampInit( ADC_SampClkTypeDef sp, ADC_SignalPGATypeDef ga ); /* 外部信号差分通道采样初始化 */
void TouchKey_ChSampInit( void ); /* 触摸按键通道采样初始化 */
void ADC_InterTSSampInit( void ); /* 内置温度传感器采样初始化 */
void ADC_InterBATSampInit( void ); /* 内置电池电压采样初始化 */
UINT16 ADC_ExcutSingleConver( void ); /* ADC执行单次转换 */
signed short ADC_DataCalib_Rough( void );
void ADC_DataCalib_Fine( PUINT16 dat, ADC_SignalPGATypeDef ga );
UINT16 TouchKey_ExcutSingleConver( UINT8 d ); /* TouchKey转换后数据 */
int ADC_GetCurrentTS( UINT16 ts_v ); /* 获取当前采样的温度值(℃) */
#define ADC_ReadConverValue() (R16_ADC_DATA) /* 读取转换后的数值 */
#define ADC_StartUp() (R8_ADC_CONVERT = RB_ADC_START) /* ADC启动转换 */
#define ADC_GetITStatus() ( R8_ADC_INT_FLAG & RB_ADC_IF_EOC ) /* 获取ADC转换完成标志 */
#define ADC_ClearITFlag() (R8_ADC_CONVERT = 0) /* 清除ADC转换完成标志 */
#define TouchKey_GetITStatus() ( R8_ADC_INT_FLAG & RB_ADC_IF_EOC ) /* 获取TouchKey转换完成标志 */
#define TouchKey_ClearITFlag() (R8_TKEY_CTRL |= RB_TKEY_PWR_ON) /* 清除TouchKey转换完成标志 */
#ifdef __cplusplus
}
#endif
#endif // __CH57x_ADC_H__

View File

@ -0,0 +1,164 @@
#ifndef __CH57x_CLK_H__
#define __CH57x_CLK_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "CH579SFR.h"
#include "core_cm0.h"
typedef enum
{
CLK_SOURCE_LSI = 0,
CLK_SOURCE_LSE,
CLK_SOURCE_HSE_32MHz,
CLK_SOURCE_HSE_16MHz,
CLK_SOURCE_HSE_8MHz,
CLK_SOURCE_HSI_32MHz, //上电默认情况
CLK_SOURCE_HSI_16MHz,
CLK_SOURCE_HSI_8MHz,
CLK_SOURCE_PLL_40MHz,
CLK_SOURCE_PLL_32MHz,
CLK_SOURCE_PLL_24MHz,
CLK_SOURCE_PLL_20MHz,
CLK_SOURCE_PLL_16MHz,
}SYS_CLKTypeDef;
typedef enum
{
Clk32M_HSI = 0,
Clk32M_HSE,
}HClk32MTypeDef;
typedef enum
{
Clk32K_LSI = 0,
Clk32K_LSE,
}LClk32KTypeDef;
typedef enum
{
HSE_RCur_75 = 0,
HSE_RCur_100,
HSE_RCur_125,
HSE_RCur_150
}HSECurrentTypeDef;
typedef enum
{
HSECap_10p = 0,
HSECap_12p, HSECap_14p, HSECap_16p, HSECap_18p,
HSECap_20p, HSECap_22p, HSECap_24p
}HSECapTypeDef;
typedef enum
{
LSE_RCur_70 = 0,
LSE_RCur_100,
LSE_RCur_140,
LSE_RCur_200
}LSECurrentTypeDef;
typedef enum
{
LSECap_2p = 0,
LSECap_13p, LSECap_14p, LSECap_15p, LSECap_16p,
LSECap_17p, LSECap_18p, LSECap_19p, LSECap_20p,
LSECap_21p, LSECap_22p, LSECap_23p, LSECap_24p,
LSECap_25p, LSECap_26p, LSECap_27p
}LSECapTypeDef;
#define MAX_DAY 0x00004000
#define MAX_2_SEC 0x0000A8C0
//#define MAX_SEC 0x545FFFFF
#define BEGYEAR 2020
#define IsLeapYear(yr) (!((yr) % 400) || (((yr) % 100) && !((yr) % 4)))
#define YearLength(yr) (IsLeapYear(yr) ? 366 : 365)
#define monthLength(lpyr,mon) ((mon==1) ? (28+lpyr) : ((mon>6) ? ((mon&1)?31:30) : ((mon&1)?30:31)))
/**
* @brief rtc timer mode period define
*/
typedef enum
{
Period_0_125_S = 0, // 0.125s 周期
Period_0_25_S, // 0.25s 周期
Period_0_5_S, // 0.5s 周期
Period_1_S, // 1s 周期
Period_2_S, // 2s 周期
Period_4_S, // 4s 周期
Period_8_S, // 8s 周期
Period_16_S, // 16s 周期
}RTC_TMRCycTypeDef;
/**
* @brief rtc interrupt event define
*/
typedef enum
{
RTC_TRIG_EVENT = 0, // RTC 触发事件
RTC_TMR_EVENT, // RTC 周期定时事件
}RTC_EVENTTypeDef;
/**
* @brief rtc interrupt event define
*/
typedef enum
{
RTC_TRIG_MODE = 0, // RTC 触发模式
RTC_TMR_MODE, // RTC 周期定时模式
}RTC_MODETypeDef;
void SystemInit(void); /* 系统时钟初始化 */
void SetSysClock( SYS_CLKTypeDef sc); /* 重设系统运行时钟 */
UINT32 GetSysClock( void ); /* 获取当前系统时钟 */
void HClk32M_Select( HClk32MTypeDef hc); /* 32M 高频时钟来源 */
void LClk32K_Select( LClk32KTypeDef hc); /* 32K 低频时钟来源 */
void HSECFG_Current( HSECurrentTypeDef c ); /* HSE晶体 偏置电流配置 */
void HSECFG_Capacitance( HSECapTypeDef c ); /* HSE晶体 负载电容配置 */
void LSECFG_Current( LSECurrentTypeDef c ); /* LSE晶体 偏置电流配置 */
void LSECFG_Capacitance( LSECapTypeDef c ); /* LSE晶体 负载电容配置 */
UINT16 Calibration_LSI( void ); /* 外部32M时钟校准内部32K时钟 */
void RTC_InitTime( UINT16 y, UINT16 mon, UINT16 d, UINT16 h, UINT16 m, UINT16 s ); /* RTC时钟初始化当前时间 */
void RTC_GetTime( PUINT16 py, PUINT16 pmon, PUINT16 pd, PUINT16 ph, PUINT16 pm, PUINT16 ps ); /* 获取当前时间 */
void RTC_SetCycle32k( UINT32 cyc ); /* 基于LSE/LSI时钟配置当前RTC 周期数 */
UINT32 RTC_GetCycle32k( void ); /* 基于LSE/LSI时钟获取当前RTC 周期数 */
void RTC_TRIGFunCfg( UINT32 cyc ); /* RTC触发模式配置间隔时间,基于LSE/LSI时钟匹配周期数 */
void RTC_TMRFunCfg( RTC_TMRCycTypeDef t ); /* RTC定时模式配置 */
void RTC_ModeFunDisable( RTC_MODETypeDef m ); /* RTC 模式功能关闭 */
UINT8 RTC_GetITFlag( RTC_EVENTTypeDef f ); /* 获取RTC中断标志 */
void RTC_ClearITFlag( RTC_EVENTTypeDef f ); /* 清除RTC中断标志 */
#ifdef __cplusplus
}
#endif
#endif // __CH57x_CLK_H__

View File

@ -0,0 +1,71 @@
#ifndef __CH57x_COMM_H__
#define __CH57x_COMM_H__
#ifdef __cplusplus
extern "C" {
#endif
#define NULL 0
#define ALL 0xFFFF
#ifndef SUCCESS
#define SUCCESS 0
#define FAILED (!SUCCESS)
#endif
#ifndef ENABLE
#define DISABLE 0
#define ENABLE (!DISABLE)
#endif
#define Debug_UART0 0
#define Debug_UART1 1
#define Debug_UART2 2
#define Debug_UART3 3
#ifdef DEBUG
#include <stdio.h>
#endif
#ifndef FREQ_SYS
#define FREQ_SYS 32000000
#endif
#if ( CLK_OSC32K == 1 )
#define CAB_LSIFQ 32000
#else
#define CAB_LSIFQ 32768
#endif
#include <string.h>
#include "CH57x_clk.h"
#include "CH57x_uart.h"
#include "CH57x_gpio.h"
#include "CH57x_lcd.h"
#include "CH57x_flash.h"
#include "CH57x_pwr.h"
#include "CH57x_pwm.h"
#include "CH57x_adc.h"
#include "CH57x_sys.h"
#include "CH57x_timer.h"
#include "CH57x_spi.h"
#include "CH57x_usbdev.h"
#include "CH57x_usbhost.h"
#define DelayMs(x) mDelaymS(x)
#define DelayUs(x) mDelayuS(x)
#ifdef __cplusplus
}
#endif
#endif // __CH57x_COMM_H__

View File

@ -0,0 +1,35 @@
#ifndef __CH57x_FLASH_H__
#define __CH57x_FLASH_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "CH579SFR.h"
#include "core_cm0.h"
#define ROM_UUID_ADDR 0x40608 // chip UID address ( ID-48bit + CKS-16bit )
#define ROM_MAC_ADDR 0x40608 // NET MAC address 48bit
// 获取唯一ID
void GetUniqueID(PUINT8 buf); /* 获取芯片唯一ID小端模式6B-ID 2B-CKS */
// 获取网络MAC
void GetMACAddress(PUINT8 buf); /* 获取网络MAC小端模式6B-MAC */
UINT8 FlashBlockErase(UINT32 addr);
UINT8 FlashWriteDW(UINT32 addr, UINT32 dat);
UINT8 FlashWriteBuf(UINT32 addr, PUINT32 pdat, UINT16 len);
#ifdef __cplusplus
}
#endif
#endif // __CH57x_FLASH_H__

View File

@ -0,0 +1,102 @@
#ifndef __CH57x_GPIO_H__
#define __CH57x_GPIO_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "CH579SFR.h"
#include "core_cm0.h"
/**
* @brief GPIO_pins_define
*/
#define GPIO_Pin_0 (0x00000001) /*!< Pin 0 selected */
#define GPIO_Pin_1 (0x00000002) /*!< Pin 1 selected */
#define GPIO_Pin_2 (0x00000004) /*!< Pin 2 selected */
#define GPIO_Pin_3 (0x00000008) /*!< Pin 3 selected */
#define GPIO_Pin_4 (0x00000010) /*!< Pin 4 selected */
#define GPIO_Pin_5 (0x00000020) /*!< Pin 5 selected */
#define GPIO_Pin_6 (0x00000040) /*!< Pin 6 selected */
#define GPIO_Pin_7 (0x00000080) /*!< Pin 7 selected */
#define GPIO_Pin_8 (0x00000100) /*!< Pin 8 selected */
#define GPIO_Pin_9 (0x00000200) /*!< Pin 9 selected */
#define GPIO_Pin_10 (0x00000400) /*!< Pin 10 selected */
#define GPIO_Pin_11 (0x00000800) /*!< Pin 11 selected */
#define GPIO_Pin_12 (0x00001000) /*!< Pin 12 selected */
#define GPIO_Pin_13 (0x00002000) /*!< Pin 13 selected */
#define GPIO_Pin_14 (0x00004000) /*!< Pin 14 selected */
#define GPIO_Pin_15 (0x00008000) /*!< Pin 15 selected */
#define GPIO_Pin_16 (0x00010000) /*!< Pin 16 selected */
#define GPIO_Pin_17 (0x00020000) /*!< Pin 17 selected */
#define GPIO_Pin_18 (0x00040000) /*!< Pin 18 selected */
#define GPIO_Pin_19 (0x00080000) /*!< Pin 19 selected */
#define GPIO_Pin_20 (0x00100000) /*!< Pin 20 selected */
#define GPIO_Pin_21 (0x00200000) /*!< Pin 21 selected */
#define GPIO_Pin_22 (0x00400000) /*!< Pin 22 selected */
#define GPIO_Pin_23 (0x00800000) /*!< Pin 23 selected */
#define GPIO_Pin_All (0xFFFFFFFF) /*!< All pins selected */
/**
* @brief Configuration GPIO Mode
*/
typedef enum
{
GPIO_ModeIN_Floating, //浮空输入
GPIO_ModeIN_PU, //上拉输入
GPIO_ModeIN_PD, //下拉输入
GPIO_ModeOut_PP_5mA, //推挽输出最大5mA
GPIO_ModeOut_PP_20mA, //推挽输出最大20mA
}GPIOModeTypeDef;
/**
* @brief Configuration GPIO IT Mode
*/
typedef enum
{
GPIO_ITMode_LowLevel, //低电平触发
GPIO_ITMode_HighLevel, //高电平触发
GPIO_ITMode_FallEdge, //下降沿触发
GPIO_ITMode_RiseEdge, //上升沿触发
}GPIOITModeTpDef;
void GPIOA_ModeCfg( UINT32 pin, GPIOModeTypeDef mode ); /* GPIOA端口引脚模式配置 */
void GPIOB_ModeCfg( UINT32 pin, GPIOModeTypeDef mode ); /* GPIOB端口引脚模式配置 */
#define GPIOA_ResetBits( pin ) (R32_PA_CLR |= pin) /* GPIOA端口引脚输出置低 */
#define GPIOA_SetBits( pin ) (R32_PA_OUT |= pin) /* GPIOA端口引脚输出置高 */
#define GPIOB_ResetBits( pin ) (R32_PB_CLR |= pin) /* GPIOB端口引脚输出置低 */
#define GPIOB_SetBits( pin ) (R32_PB_OUT |= pin) /* GPIOB端口引脚输出置高 */
#define GPIOA_InverseBits( pin ) (R32_PA_OUT ^= pin) /* GPIOA端口引脚输出电平翻转 */
#define GPIOB_InverseBits( pin ) (R32_PB_OUT ^= pin) /* GPIOB端口引脚输出电平翻转 */
#define GPIOA_ReadPort() (R32_PA_PIN) /* GPIOA端口32位数据返回低16位有效 */
#define GPIOB_ReadPort() (R32_PB_PIN) /* GPIOB端口32位数据返回低24位有效 */
#define GPIOA_ReadPortPin( pin ) (R32_PA_PIN&pin) /* GPIOA端口引脚状态0-引脚低电平,(!0)-引脚高电平 */
#define GPIOB_ReadPortPin( pin ) (R32_PB_PIN&pin) /* GPIOB端口引脚状态0-引脚低电平,(!0)-引脚高电平 */
void GPIOA_ITModeCfg( UINT32 pin, GPIOITModeTpDef mode ); /* GPIOA引脚中断模式配置 */
void GPIOB_ITModeCfg( UINT32 pin, GPIOITModeTpDef mode ); /* GPIOB引脚中断模式配置 */
#define GPIOA_ReadITFlagPort() (R16_PA_INT_IF) /* 读取GPIOA端口中断标志状态 */
#define GPIOB_ReadITFlagPort() (R16_PB_INT_IF) /* 读取GPIOB端口中断标志状态 */
#define GPIOA_ReadITFlagBit( pin ) (R16_PA_INT_IF&pin) /* 读取GPIOA端口引脚中断标志状态 */
#define GPIOB_ReadITFlagBit( pin ) (R16_PB_INT_IF&pin) /* 读取GPIOB端口引脚中断标志状态 */
#define GPIOA_ClearITFlagBit( pin ) (R16_PA_INT_IF = pin) /* 清除GPIOA端口引脚中断标志状态 */
#define GPIOB_ClearITFlagBit( pin ) (R16_PB_INT_IF = pin) /* 清除GPIOB端口引脚中断标志状态 */
void GPIOPinRemap( UINT8 s, UINT16 perph ); /* 外设功能引脚映射 */
void GPIOAGPPCfg( UINT8 s, UINT16 perph ); /* 模拟外设GPIO引脚功能控制 */
#ifdef __cplusplus
}
#endif
#endif // __CH57x_GPIO_H__

View File

@ -0,0 +1,91 @@
#ifndef __CH57x_LCD_H__
#define __CH57x_LCD_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "CH579SFR.h"
#include "core_cm0.h"
/**
* @brief Configuration LCD driver power
*/
typedef enum
{
LCD_PS_3V3 = 0, // 3.3V 驱动
LCD_PS_2V5, // 2.5V 驱动
}LCDDrvPowerTypeDef;
/**
* @brief Configuration LCD bias
*/
typedef enum
{
LCD_1_2_Bias = 0, // 2级分压
LCD_1_3_Bias, // 3级分压
}LCDBiasTypeDef;
/**
* @brief Configuration LCD duty
*/
typedef enum
{
LCD_1_2_Duty = 0, // COM0-COM1
LCD_1_3_Duty, // COM0-COM2
LCD_1_4_Duty, // COM0-COM3
}LCDDutyTypeDef;
/**
* @brief Configuration LCD scan clk
*/
typedef enum
{
LCD_CLK_256 = 0, // 256Hz
LCD_CLK_512, // 512Hz
LCD_CLK_1000, // 1KHz
LCD_CLK_128 // 128Hz
}LCDSCANCLKTypeDef;
void LCD_DefInit( void ); /* LCD段式屏驱动默认初始化配置 */
#define LCD_PowerDown() (R8_LCD_CTRL_MOD &= ~(RB_LCD_POWER_ON|RB_SYS_POWER_ON)) /* LCD功能模块关闭 */
#define LCD_PowerOn() (R8_LCD_CTRL_MOD |= (RB_LCD_POWER_ON|RB_SYS_POWER_ON)) /* LCD功能模块开启 */
// 输入值参考 LCDDrvPowerTypeDef
#define LCD_PowerCfg( d ) (R8_LCD_CTRL_MOD=R8_LCD_CTRL_MOD&0x7F|(d<<7)) /* 配置LCD的 供电电压选择 */
// 输入值参考 LCDSCANCLKTypeDef
#define LCD_ScanCLKCfg( d ) (R8_LCD_CTRL_MOD=R8_LCD_CTRL_MOD&0x9F|(d<<5)) /* 配置LCD的 扫描时钟选择 */
// 输入值参考 LCDDutyTypeDef
#define LCD_DutyCfg( d ) (R8_LCD_CTRL_MOD=R8_LCD_CTRL_MOD&0xE7|(d<<3)) /* 配置LCD的 duty选择 */
// 输入值参考 LCDBiasTypeDef
#define LCD_BiasCfg( d ) (R8_LCD_CTRL_MOD=R8_LCD_CTRL_MOD&0xFB|(d<<2)) /* 配置LCD的 bias选择 */
#define LCD_WriteData0( d ) (R32_LCD_RAM0=R32_LCD_RAM0&0xffffff00|((UINT32)d)) /* 填充SEG0驱动数值 */
#define LCD_WriteData1( d ) (R32_LCD_RAM0=R32_LCD_RAM0&0xffff00ff|((UINT32)d<<8)) /* 填充SEG1驱动数值 */
#define LCD_WriteData2( d ) (R32_LCD_RAM0=R32_LCD_RAM0&0xff00ffff|((UINT32)d<<16)) /* 填充SEG2驱动数值 */
#define LCD_WriteData3( d ) (R32_LCD_RAM0=R32_LCD_RAM0&0x00ffffff|((UINT32)d<<24)) /* 填充SEG3驱动数值 */
#define LCD_WriteData4( d ) (R32_LCD_RAM1=R32_LCD_RAM1&0xffffff00|((UINT32)d)) /* 填充SEG4驱动数值 */
#define LCD_WriteData5( d ) (R32_LCD_RAM1=R32_LCD_RAM1&0xffff00ff|((UINT32)d<<8)) /* 填充SEG5驱动数值 */
#define LCD_WriteData6( d ) (R32_LCD_RAM1=R32_LCD_RAM1&0xff00ffff|((UINT32)d<<16)) /* 填充SEG6驱动数值 */
#define LCD_WriteData7( d ) (R32_LCD_RAM1=R32_LCD_RAM1&0x00ffffff|((UINT32)d<<24)) /* 填充SEG7驱动数值 */
#define LCD_WriteData8( d ) (R32_LCD_RAM2=R32_LCD_RAM2&0xffffff00|((UINT32)d)) /* 填充SEG8驱动数值 */
#define LCD_WriteData9( d ) (R32_LCD_RAM2=R32_LCD_RAM2&0xffff00ff|((UINT32)d<<8)) /* 填充SEG9驱动数值 */
#define LCD_WriteData10( d ) (R32_LCD_RAM2=R32_LCD_RAM2&0xff00ffff|((UINT32)d<<16)) /* 填充SEG10驱动数值 */
#define LCD_WriteData11( d ) (R32_LCD_RAM2=R32_LCD_RAM2&0x00ffffff|((UINT32)d<<24)) /* 填充SEG11驱动数值 */
#ifdef __cplusplus
}
#endif
#endif // __CH57x_LCD_H__

View File

@ -0,0 +1,80 @@
#ifndef __CH57x_PWM_H__
#define __CH57x_PWM_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "CH579SFR.h"
#include "core_cm0.h"
/**
* @brief channel of PWM define
*/
#define CH_PWM4 0x01 // PWM4 通道
#define CH_PWM5 0x02 // PWM5 通道
#define CH_PWM6 0x04 // PWM6 通道
#define CH_PWM7 0x08 // PWM7 通道
#define CH_PWM8 0x10 // PWM8 通道
#define CH_PWM9 0x20 // PWM9 通道
#define CH_PWM10 0x40 // PWM10 通道
#define CH_PWM11 0x80 // PWM11 通道
/**
* @brief channel of PWM define
*/
typedef enum
{
High_Level = 0, // 默认低电平,高电平有效
Low_Level, // 默认高电平,低电平有效
}PWMX_PolarTypeDef;
/**
* @brief Configuration PWM4_11 Cycle size
*/
typedef enum
{
PWMX_Cycle_256 = 0, // 256 个PWMX周期
PWMX_Cycle_255, // 255 个PWMX周期
PWMX_Cycle_128, // 128 个PWMX周期
PWMX_Cycle_127, // 127 个PWMX周期
PWMX_Cycle_64, // 64 个PWMX周期
PWMX_Cycle_63, // 63 个PWMX周期
PWMX_Cycle_32, // 32 个PWMX周期
PWMX_Cycle_31, // 31 个PWMX周期
}PWMX_CycleTypeDef;
#define PWMX_CLKCfg( d ) (R8_PWM_CLOCK_DIV=d) /* PWM4-PWM11 通道基准时钟配置,= d*Tsys */
void PWMX_CycleCfg( PWMX_CycleTypeDef cyc ); /* PWM4-PWM11 通道输出波形周期配置 */
#define PWM4_ActDataWidth( d ) (R8_PWM4_DATA = d) /* PWM4 有效数据脉宽 */
#define PWM5_ActDataWidth( d ) (R8_PWM5_DATA = d) /* PWM5 有效数据脉宽 */
#define PWM6_ActDataWidth( d ) (R8_PWM6_DATA = d) /* PWM6 有效数据脉宽 */
#define PWM7_ActDataWidth( d ) (R8_PWM7_DATA = d) /* PWM7 有效数据脉宽 */
#define PWM8_ActDataWidth( d ) (R8_PWM8_DATA = d) /* PWM8 有效数据脉宽 */
#define PWM9_ActDataWidth( d ) (R8_PWM9_DATA = d) /* PWM9 有效数据脉宽 */
#define PWM10_ActDataWidth( d ) (R8_PWM10_DATA = d) /* PWM10 有效数据脉宽 */
#define PWM11_ActDataWidth( d ) (R8_PWM11_DATA = d) /* PWM11 有效数据脉宽 */
// 占空比 = 数据有效脉宽/波形周期
void PWMX_ACTOUT( UINT8 ch, UINT8 da, PWMX_PolarTypeDef pr, UINT8 s); /* PWM4-PWM11通道输出波形配置 */
void PWMX_AlterOutCfg( UINT8 ch, UINT8 s); /* PWM 交替输出模式配置 */
#ifdef __cplusplus
}
#endif
#endif // __CH57x_PWM_H__

View File

@ -0,0 +1,69 @@
#ifndef __CH57x_PWR_H__
#define __CH57x_PWR_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "CH579SFR.h"
#include "core_cm0.h"
/**
* @brief Peripher CLK control bit define
*/
#define BIT_SLP_CLK_TMR0 (0x00000001) /*!< TMR0 peripher clk bit */
#define BIT_SLP_CLK_TMR1 (0x00000002) /*!< TMR1 peripher clk bit */
#define BIT_SLP_CLK_TMR2 (0x00000004) /*!< TMR2 peripher clk bit */
#define BIT_SLP_CLK_TMR3 (0x00000008) /*!< TMR3 peripher clk bit */
#define BIT_SLP_CLK_UART0 (0x00000010) /*!< UART0 peripher clk bit */
#define BIT_SLP_CLK_UART1 (0x00000020) /*!< UART1 peripher clk bit */
#define BIT_SLP_CLK_UART2 (0x00000040) /*!< UART2 peripher clk bit */
#define BIT_SLP_CLK_UART3 (0x00000080) /*!< UART3 peripher clk bit */
#define BIT_SLP_CLK_SPI0 (0x00000100) /*!< SPI0 peripher clk bit */
#define BIT_SLP_CLK_SPI1 (0x00000200) /*!< SPI1 peripher clk bit */
#define BIT_SLP_CLK_PWMX (0x00000400) /*!< PWMX peripher clk bit */
#define BIT_SLP_CLK_LCD (0x00000800) /*!< LCD peripher clk bit */
#define BIT_SLP_CLK_USB (0x00001000) /*!< USB peripher clk bit */
#define BIT_SLP_CLK_ETH (0x00002000) /*!< ETH peripher clk bit */
#define BIT_SLP_CLK_LED (0x00004000) /*!< LED peripher clk bit */
#define BIT_SLP_CLK_BLE (0x00008000) /*!< BLE peripher clk bit */
#define BIT_SLP_CLK_RAMX (0x10000000) /*!< RAM14K peripher clk bit */
#define BIT_SLP_CLK_RAM2K (0x20000000) /*!< RAM2K peripher clk bit */
#define BIT_SLP_CLK_ALL (0x3000FFFF) /*!< All peripher clk bit */
/**
* @brief unit of controllable power supply
*/
#define UNIT_SYS_LSE RB_CLK_XT32K_PON // 外部32K 时钟振荡
#define UNIT_SYS_LSI RB_CLK_INT32K_PON // 内部32K 时钟振荡
#define UNIT_SYS_HSE RB_CLK_XT32M_PON // 外部32M 时钟振荡
#define UNIT_SYS_HSI RB_CLK_INT32M_PON // 内部32M 时钟振荡
#define UNIT_SYS_PLL RB_CLK_PLL_PON // PLL 时钟振荡
#define UNIT_ETH_PHY (0x80) // 以太网收发器 ETH-PHY
void PWR_DCDCCfg( UINT8 s ); /* 内部DC/DC电源控制 */
void PWR_UnitModCfg( UINT8 s, UINT8 unit ); /* 可控单元模块的电源控制 */
void PWR_PeriphClkCfg( UINT8 s, UINT16 perph ); /* 外设时钟控制位 */
void PowerMonitor( UINT8 s ); /* 电源电压监控功能控制 */
void PWR_PeriphWakeUpCfg( UINT8 s, UINT16 perph ); /* 睡眠唤醒源配置 */
void LowPower_Idle( void ); /* 低功耗-IDLE模式 */
void LowPower_Halt_1( void ); /* 低功耗-Halt_1模式 */
void LowPower_Halt_2( void ); /* 低功耗-Halt_2模式 */
void LowPower_Sleep( UINT8 rm ); /* 低功耗-Sleep模式 */
void LowPower_Shutdown( UINT8 rm ); /* 低功耗-Shutdown模式 */
void EnterCodeUpgrade( void ); /* 跳入BOOT程序准备代码升级 */
#ifdef __cplusplus
}
#endif
#endif // __CH57x_PWR_H__

View File

@ -0,0 +1,108 @@
#ifndef __CH57x_SPI_H__
#define __CH57x_SPI_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "CH579SFR.h"
#include "core_cm0.h"
/**
* @brief SPI0 interrupt bit define
*/
#define SPI0_IT_FST_BYTE RB_SPI_IE_FST_BYTE // 从机模式的首字节命令模式下,接收到首字节中断
#define SPI0_IT_FIFO_OV RB_SPI_IE_FIFO_OV // FIFO 溢出
#define SPI0_IT_DMA_END RB_SPI_IE_DMA_END // DMA 传输结束
#define SPI0_IT_FIFO_HF RB_SPI_IE_FIFO_HF // FIFO 使用过半
#define SPI0_IT_BYTE_END RB_SPI_IE_BYTE_END // 单字节传输完成
#define SPI0_IT_CNT_END RB_SPI_IE_CNT_END // 全部字节传输完成
/**
* @brief Configuration data mode
*/
typedef enum
{
Mode0_LowBitINFront = 0, // 模式0低位在前
Mode0_HighBitINFront, // 模式0高位在前
Mode3_LowBitINFront, // 模式3低位在前
Mode3_HighBitINFront, // 模式3高位在前
}ModeBitOrderTypeDef;
/**
* @brief Configuration SPI0 slave mode
*/
typedef enum
{
Mode_DataStream = 0, // 数据流模式
Mose_FirstCmd, // 首字节命令模式
}Slave_ModeTypeDef;
/**************** SPI0 */
void SPI0_MasterDefInit( void ); /* 主机模式默认初始化模式0+3线全双工+8MHz */
void SPI0_CLKCfg( UINT8 c ); /* SPI0 基准时钟配置,= d*Tsys */
void SPI0_DataMode( ModeBitOrderTypeDef m ); /* 设置数据流模式 */
void SPI0_MasterSendByte( UINT8 d ); /* 发送单字节 (buffer) */
UINT8 SPI0_MasterRecvByte( void ); /* 接收单字节 (buffer) */
void SPI0_MasterTrans( UINT8 *pbuf, UINT16 len ); /* 使用FIFO连续发送多字节 */
void SPI0_MasterRecv( UINT8 *pbuf, UINT16 len ); /* 使用FIFO连续接收多字节 */
void SPI0_MasterDMATrans( PUINT8 pbuf, UINT16 len); /* DMA方式连续发送数据 */
void SPI0_MasterDMARecv( PUINT8 pbuf, UINT16 len); /* DMA方式连续接收数据 */
void SPI0_SlaveInit( void ); /* 设备模式默认初始化建议设置MISO的GPIO对应为输入模式 */
#define SetFirstData(d) (R8_SPI0_SLAVE_PRE = d) /* 加载首字节数据内容 */
void SPI0_SlaveSendByte( UINT8 d ); /* 从机模式,发送一字节数据 */
UINT8 SPI0_SlaveRecvByte( void ); /* 从机模式,接收一字节数据 */
void SPI0_SlaveTrans( UINT8 *pbuf, UINT16 len ); /* 从机模式,发送多字节数据 */
void SPI0_SlaveRecv( PUINT8 pbuf, UINT16 len ); /* 从机模式,接收多字节数据 */
void SPI0_SlaveDMATrans( PUINT8 pbuf, UINT16 len); /* 从机模式DMA方式发送多字节数据 */
void SPI0_SlaveDMARecv( PUINT8 pbuf, UINT16 len); /* 从机模式DMA方式接收多字节数据 */
// refer to SPI0 interrupt bit define
#define SPI0_ITCfg(s,f) ((s)?(R8_SPI0_INTER_EN|=f):(R8_SPI0_INTER_EN&=~f))
#define SPI0_GetITFlag(f) (R8_SPI0_INT_FLAG&f) /* 获取中断标志状态0-未置位,(!0)-触发 */
#define SPI0_ClearITFlag(f) (R8_SPI0_INT_FLAG = f) /* 清除当前中断标志 */
/**************** SPI1 */
void SPI1_MasterDefInit( void ); /* 主机模式默认初始化模式0+3线全双工+8MHz */
void SPI1_CLKCfg( UINT8 c ); /* SPI1 基准时钟配置,= d*Tsys */
void SPI1_DataMode( ModeBitOrderTypeDef m ); /* 设置数据流模式 */
void SPI1_MasterSendByte( UINT8 d ); /* 发送单字节 (buffer) */
UINT8 SPI1_MasterRecvByte( void ); /* 接收单字节 (buffer) */
void SPI1_MasterTrans( UINT8 *pbuf, UINT16 len ); /* 使用FIFO连续发送多字节 */
void SPI1_MasterRecv( UINT8 *pbuf, UINT16 len ); /* 使用FIFO连续接收多字节 */
// refer to SPI1 interrupt bit define
#define SPI1_ITCfg(s,f) ((s)?(R8_SPI1_INTER_EN|=f):(R8_SPI1_INTER_EN&=~f))
#define SPI1_GetITFlag(f) (R8_SPI1_INT_FLAG&f) /* 获取中断标志状态0-未置位,(!0)-触发 */
#define SPI1_ClearITFlag(f) (R8_SPI1_INT_FLAG = f) /* 清除当前中断标志 */
#ifdef __cplusplus
}
#endif
#endif // __CH57x_SPI_H__

View File

@ -0,0 +1,76 @@
#ifndef __CH57x_SYS_H__
#define __CH57x_SYS_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "CH579SFR.h"
#include "core_cm0.h"
/**
* @brief rtc interrupt event define
*/
typedef enum
{
RST_STATUS_SW = 0, // 软件复位
RST_STATUS_RPOR, // 上电复位
RST_STATUS_WTR, // 看门狗超时复位
RST_STATUS_MR, // 外部手动复位
RST_STATUS_LRM0, // 唤醒复位-软复位引起
RST_STATUS_GPWSM, // 下电模式唤醒复位
RST_STATUS_LRM1, // 唤醒复位-看门狗引起
RST_STATUS_LRM2, // 唤醒复位-手动复位引起
}SYS_ResetStaTypeDef;
/**
* @brief rtc interrupt event define
*/
typedef enum
{
INFO_ROM_READ = 0, // FlashROM 代码和数据区 是否可读
INFO_RESET_EN = 2, // RST#外部手动复位输入功能是否开启
INFO_BOOT_EN, // 系统引导程序 BootLoader 是否开启
INFO_DEBUG_EN, // 系统仿真调试接口是否开启
INFO_LOADER, // 当前系统是否处于Bootloader 区
STA_SAFEACC_ACT, // 当前系统是否处于安全访问状态否则RWA属性区域不可访问
}SYS_InfoStaTypeDef;
#define SYS_GetChipID() R8_CHIP_ID /* 获取芯片ID类一般为固定值 */
#define SYS_GetAccessID() R8_SAFE_ACCESS_ID /* 获取安全访问ID一般为固定值 */
UINT8 SYS_GetInfoSta( SYS_InfoStaTypeDef i ); /* 获取当前系统信息状态 */
// refer to SYS_ResetStaTypeDef
#define SYS_GetLastResetSta() (R8_RESET_STATUS&RB_RESET_FLAG) /* 获取系统上次复位状态 */
void SYS_ResetExecute( void ); /* 执行系统软件复位 */
#define SYS_ResetKeepBuf( d ) (R8_GLOB_RESET_KEEP = d) /* 不受手动复位、 软件复位、 看门狗复位或者普通唤醒复位的影响 */
void SYS_DisableAllIrq( PUINT32 pirqv); /* 关闭所有中断,并保留当前中断值 */
void SYS_RecoverIrq( UINT32 irq_status ); /* 恢复之前关闭的中断值 */
UINT32 SYS_GetSysTickCnt( void ); /* 获取当前系统(SYSTICK)计数值 */
#define WWDG_SetCounter( c ) (R8_WDOG_COUNT = c) /* 加载看门狗计数初值,递增型 */
void WWDG_ITCfg( UINT8 s ); /* 看门狗溢出中断使能 */
void WWDG_ResetCfg( UINT8 s ); /* 看门狗溢出复位使能 */
#define WWDG_GetFlowFlag() (R8_RST_WDOG_CTRL&RB_WDOG_INT_FLAG) /* 获取当前看门狗定时器溢出标志 */
void WWDG_ClearFlag(void); /* 清除看门狗中断标志,重新加载计数值也可清除 */
void mDelayuS( UINT16 t ); /* uS 延时 */
void mDelaymS( UINT16 t ); /* mS 延时 */
#ifdef __cplusplus
}
#endif
#endif // __CH57x_SYS_H__

View File

@ -0,0 +1,197 @@
#ifndef __CH57x_TIMER_H__
#define __CH57x_TIMER_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "CH579SFR.h"
#include "core_cm0.h"
#define DataBit_25 (1<<25)
/**
* @brief TMR0 interrupt bit define
*/
#define TMR0_3_IT_CYC_END 0x01 // 周期结束标志:捕捉-超时,定时-周期结束PWM-周期结束
#define TMR0_3_IT_DATA_ACT 0x02 // 数据有效标志:捕捉-新数据PWM-有效电平结束
#define TMR0_3_IT_FIFO_HF 0x04 // FIFO 使用过半:捕捉- FIFO>=4 PWM- FIFO<4
#define TMR1_2_IT_DMA_END 0x08 // DMA 结束支持TMR1和TMR2
#define TMR0_3_IT_FIFO_OV 0x10 // FIFO 溢出:捕捉- FIFO满 PWM- FIFO空
/**
* @brief Configuration PWM effective level repeat times
*/
typedef enum
{
PWM_Times_1 = 0, // PWM 有效输出重复1次数
PWM_Times_4, // PWM 有效输出重复4次数
PWM_Times_8, // PWM 有效输出重复8次数
PWM_Times_16, // PWM 有效输出重复16次数
}PWM_RepeatTsTypeDef;
/**
* @brief Configuration Cap mode
*/
typedef enum
{
CAP_NULL = 0, // 不捕捉 & 不计数
Edge_To_Edge, // 任意边沿之间 & 计数任意边沿
FallEdge_To_FallEdge, // 下降沿到下降沿 & 计数下降沿
RiseEdge_To_RiseEdge, // 上升沿到上升沿 & 计数上升沿
}CapModeTypeDef;
/**
* @brief Configuration DMA mode
*/
typedef enum
{
Mode_Single = 0, // 单次模式
Mode_LOOP, // 循环模式
}DMAModeTypeDef;
/****************** TMR0 */
// 定时功能
void TMR0_TimerInit( UINT32 t ); /* 定时功能初始化 */
void TMR0_EXTSingleCounterInit( UINT32 c ); /* 外部信号计数功能初始化 */
#define TMR0_GetCurrentTimer() R32_TMR0_COUNT /* 获取当前定时器值最大67108864 */
//计数功能
void TMR0_CountInit( CapModeTypeDef cap ); /* 外部信号边沿计数初始化 */
#define TMR0_CountOverflowCfg( cyc ) (R32_TMR0_CNT_END=(cyc+2)) /* 计数统计溢出大小最大67108862 */
#define TMR0_GetCurrentCount() R32_TMR0_COUNT /* 获取当前计数值最大67108862 */
// PWM功能
#define TMR0_PWMCycleCfg( cyc ) (R32_TMR0_CNT_END=cyc) /* PWM0 通道输出波形周期配置, 最大67108864 */
void TMR0_PWMInit( PWMX_PolarTypeDef pr, PWM_RepeatTsTypeDef ts ); /* PWM 输出初始化 */
#define TMR0_PWMActDataWidth( d ) (R32_TMR0_FIFO = d) /* PWM0 有效数据脉宽, 最大67108864 */
// 捕捉脉宽
#define TMR0_CAPTimeoutCfg( cyc ) (R32_TMR0_CNT_END=cyc) /* CAP0 捕捉电平超时配置, 最大33554432 */
void TMR0_CapInit( CapModeTypeDef cap ); /* 外部信号捕捉功能初始化 */
#define TMR0_CAPGetData() R32_TMR0_FIFO /* 获取脉冲数据 */
#define TMR0_CAPDataCounter() R8_TMR0_FIFO_COUNT /* 获取当前已捕获数据个数 */
#define TMR0_Disable() (R8_TMR0_CTRL_MOD &= ~RB_TMR_COUNT_EN) /* 关闭 TMR0 */
#define TMR0_Enable() (R8_TMR0_CTRL_MOD |= RB_TMR_COUNT_EN) /* 开启 TMR0 */
// refer to TMR0 interrupt bit define
#define TMR0_ITCfg(s,f) ((s)?(R8_TMR0_INTER_EN|=f):(R8_TMR0_INTER_EN&=~f)) /* TMR0 相应中断位开启与关闭 */
// refer to TMR0 interrupt bit define
#define TMR0_ClearITFlag(f) (R8_TMR0_INT_FLAG = f) /* 清除中断标志 */
#define TMR0_GetITFlag(f) (R8_TMR0_INT_FLAG&f) /* 查询中断标志状态 */
/****************** TMR1 */
// 定时和计数
void TMR1_TimerInit( UINT32 t ); /* 定时功能初始化 */
void TMR1_EXTSingleCounterInit( UINT32 c ); /* 外部信号计数功能初始化 */
#define TMR1_GetCurrentTimer() R32_TMR1_COUNT /* 获取当前定时器值最大67108864 */
//计数功能
void TMR1_CountInit( CapModeTypeDef cap ); /* 外部信号边沿计数初始化 */
#define TMR1_CountOverflowCfg( cyc ) (R32_TMR1_CNT_END=(cyc+2)) /* 计数统计溢出大小最大67108862 */
#define TMR1_GetCurrentCount() R32_TMR1_COUNT /* 获取当前计数值最大67108862 */
// PWM功能
#define TMR1_PWMCycleCfg( cyc ) (R32_TMR1_CNT_END=cyc) /* PWM1 通道输出波形周期配置, 最大67108864 */
void TMR1_PWMInit( PWMX_PolarTypeDef pr, PWM_RepeatTsTypeDef ts ); /* PWM1 输出初始化 */
#define TMR1_PWMActDataWidth( d ) (R32_TMR1_FIFO = d) /* PWM1 有效数据脉宽, 最大67108864 */
// 捕捉脉宽
#define TMR1_CAPTimeoutCfg( cyc ) (R32_TMR1_CNT_END=cyc) /* CAP1 捕捉电平超时配置, 最大33554432 */
void TMR1_CapInit( CapModeTypeDef cap ); /* 外部信号捕捉功能初始化 */
#define TMR1_CAPGetData() R32_TMR1_FIFO /* 获取脉冲数据 */
#define TMR1_CAPDataCounter() R8_TMR1_FIFO_COUNT /* 获取当前已捕获数据个数 */
void TMR1_DMACfg( UINT8 s, UINT16 startAddr, UINT16 endAddr, DMAModeTypeDef m ); /* DMA配置 */
#define TMR1_Disable() (R8_TMR1_CTRL_MOD &= ~RB_TMR_COUNT_EN) /* 关闭 TMR1 */
#define TMR1_Enable() (R8_TMR1_CTRL_MOD |= RB_TMR_COUNT_EN) /* 开启 TMR1 */
// refer to TMR1 interrupt bit define
#define TMR1_ITCfg(s,f) ((s)?(R8_TMR1_INTER_EN|=f):(R8_TMR1_INTER_EN&=~f)) /* TMR1 相应中断位开启与关闭 */
// refer to TMR1 interrupt bit define
#define TMR1_ClearITFlag(f) (R8_TMR1_INT_FLAG = f) /* 清除中断标志 */
#define TMR1_GetITFlag(f) (R8_TMR1_INT_FLAG&f) /* 查询中断标志状态 */
/****************** TMR2 */
// 定时和计数
void TMR2_TimerInit( UINT32 t ); /* 定时功能初始化 */
void TMR2_EXTSingleCounterInit( UINT32 c ); /* 外部信号计数功能初始化 */
#define TMR2_GetCurrentTimer() R32_TMR2_COUNT /* 获取当前定时器值最大67108864 */
//计数功能
void TMR2_CountInit( CapModeTypeDef cap ); /* 外部信号边沿计数初始化 */
#define TMR2_CountOverflowCfg( cyc ) (R32_TMR2_CNT_END=(cyc+2)) /* 计数统计溢出大小最大67108862 */
#define TMR2_GetCurrentCount() R32_TMR2_COUNT /* 获取当前计数值最大67108862 */
// PWM功能
#define TMR2_PWMCycleCfg( cyc ) (R32_TMR2_CNT_END=cyc) /* PWM2 通道输出波形周期配置, 最大67108864 */
void TMR2_PWMInit( PWMX_PolarTypeDef pr, PWM_RepeatTsTypeDef ts ); /* PWM2 输出初始化 */
#define TMR2_PWMActDataWidth( d ) (R32_TMR2_FIFO = d) /* PWM2 有效数据脉宽, 最大67108864 */
// 捕捉脉宽
#define TMR2_CAPTimeoutCfg( cyc ) (R32_TMR2_CNT_END=cyc) /* CAP2 捕捉电平超时配置, 最大33554432 */
void TMR2_CapInit( CapModeTypeDef cap ); /* 外部信号捕捉功能初始化 */
#define TMR2_CAPGetData() R32_TMR2_FIFO /* 获取脉冲数据 */
#define TMR2_CAPDataCounter() R8_TMR2_FIFO_COUNT /* 获取当前已捕获数据个数 */
void TMR2_DMACfg( UINT8 s, UINT16 startAddr, UINT16 endAddr, DMAModeTypeDef m ); /* DMA配置 */
#define TMR2_Disable() (R8_TMR2_CTRL_MOD &= ~RB_TMR_COUNT_EN) /* 关闭 TMR2 */
#define TMR2_Enable() (R8_TMR2_CTRL_MOD |= RB_TMR_COUNT_EN) /* 开启 TMR2 */
// refer to TMR2 interrupt bit define
#define TMR2_ITCfg(s,f) ((s)?(R8_TMR2_INTER_EN|=f):(R8_TMR2_INTER_EN&=~f)) /* TMR2 相应中断位开启与关闭 */
// refer to TMR2 interrupt bit define
#define TMR2_ClearITFlag(f) (R8_TMR2_INT_FLAG = f) /* 清除中断标志 */
#define TMR2_GetITFlag(f) (R8_TMR2_INT_FLAG&f) /* 查询中断标志状态 */
/****************** TMR3 */
// 定时和计数
void TMR3_TimerInit( UINT32 t ); /* 定时功能初始化 */
void TMR3_EXTSingleCounterInit( UINT32 c ); /* 外部信号计数功能初始化 */
#define TMR3_GetCurrentTimer() R32_TMR3_COUNT /* 获取当前定时器值最大67108864 */
//计数功能
void TMR3_CountInit( CapModeTypeDef cap ); /* 外部信号边沿计数初始化 */
#define TMR3_CountOverflowCfg( cyc ) (R32_TMR3_CNT_END=(cyc+2)) /* 计数统计溢出大小最大67108862 */
#define TMR3_GetCurrentCount() R32_TMR3_COUNT /* 获取当前计数值最大67108862 */
// PWM功能
#define TMR3_PWMCycleCfg( cyc ) (R32_TMR3_CNT_END=cyc) /* PWM3 通道输出波形周期配置, 最大67108864 */
void TMR3_PWMInit( PWMX_PolarTypeDef pr, PWM_RepeatTsTypeDef ts ); /* PWM3 输出初始化 */
#define TMR3_PWMActDataWidth( d ) (R32_TMR3_FIFO = d) /* PWM3 有效数据脉宽, 最大67108864 */
// 捕捉脉宽
#define TMR3_CAPTimeoutCfg( cyc ) (R32_TMR3_CNT_END=cyc) /* CAP3 捕捉电平超时配置, 最大33554432 */
void TMR3_CapInit( CapModeTypeDef cap ); /* 外部信号捕捉功能初始化 */
#define TMR3_CAPGetData() R32_TMR3_FIFO /* 获取脉冲数据 */
#define TMR3_CAPDataCounter() R8_TMR3_FIFO_COUNT /* 获取当前已捕获数据个数 */
#define TMR3_Disable() (R8_TMR3_CTRL_MOD &= ~RB_TMR_COUNT_EN) /* 关闭 TMR3 */
#define TMR3_Enable() (R8_TMR3_CTRL_MOD |= RB_TMR_COUNT_EN) /* 开启 TMR3 */
// refer to TMR3 interrupt bit define
#define TMR3_ITCfg(s,f) ((s)?(R8_TMR3_INTER_EN|=f):(R8_TMR3_INTER_EN&=~f)) /* TMR3 相应中断位开启与关闭 */
// refer to TMR3 interrupt bit define
#define TMR3_ClearITFlag(f) (R8_TMR3_INT_FLAG = f) /* 清除中断标志 */
#define TMR3_GetITFlag(f) (R8_TMR3_INT_FLAG&f) /* 查询中断标志状态 */
#ifdef __cplusplus
}
#endif
#endif // __CH57x_TIMER_H__

View File

@ -0,0 +1,131 @@
#ifndef __CH57x_UART_H__
#define __CH57x_UART_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "CH579SFR.h"
#include "core_cm0.h"
/**
* @brief LINE error and status define
*/
#define STA_ERR_BREAK RB_LSR_BREAK_ERR // 数据间隔错误
#define STA_ERR_FRAME RB_LSR_FRAME_ERR // 数据帧错误
#define STA_ERR_PAR RB_LSR_PAR_ERR // 奇偶校验位出错
#define STA_ERR_FIFOOV RB_LSR_OVER_ERR // 接收数据溢出
#define STA_TXFIFO_EMP RB_LSR_TX_FIFO_EMP // 当前发送FIFO空可以继续填充发送数据
#define STA_TXALL_EMP RB_LSR_TX_ALL_EMP // 当前所有发送数据都发送完成
#define STA_RECV_DATA RB_LSR_DATA_RDY // 当前有接收到数据
/**
* @brief Configuration UART TrigByte num
*/
typedef enum
{
UART_1BYTE_TRIG = 0, // 1字节触发
UART_2BYTE_TRIG, // 2字节触发
UART_4BYTE_TRIG, // 4字节触发
UART_7BYTE_TRIG, // 7字节触发
}UARTByteTRIGTypeDef;
/****************** UART0 */
void UART0_DefInit( void ); /* 串口默认初始化配置 */
void UART0_BaudRateCfg( UINT32 baudrate ); /* 串口波特率配置 */
void UART0_ByteTrigCfg( UARTByteTRIGTypeDef b ); /* 串口字节触发中断配置 */
void UART0_INTCfg( UINT8 s, UINT8 i ); /* 串口中断配置 */
void UART0_Reset( void ); /* 串口软件复位 */
#define UART0_CLR_RXFIFO() (R8_UART0_FCR |= RB_FCR_RX_FIFO_CLR) /* 清除当前接收FIFO */
#define UART0_CLR_TXFIFO() (R8_UART0_FCR |= RB_FCR_TX_FIFO_CLR) /* 清除当前发送FIFO */
#define UART0_GetITFlag() (R8_UART0_IIR&RB_IIR_INT_MASK) /* 获取当前中断标志 */
// please refer to LINE error and status define
#define UART0_GetLinSTA() (R8_UART0_LSR) /* 获取当前通讯状态 */
#define UART0_SendByte(b) (R8_UART0_THR = b) /* 串口单字节发送 */
void UART0_SendString( PUINT8 buf, UINT16 l ); /* 串口多字节发送 */
#define UART0_RecvByte() ( R8_UART0_RBR ) /* 串口读取单字节 */
UINT16 UART0_RecvString( PUINT8 buf ); /* 串口读取多字节 */
/****************** UART1 */
void UART1_DefInit( void ); /* 串口默认初始化配置 */
void UART1_BaudRateCfg( UINT32 baudrate ); /* 串口波特率配置 */
void UART1_ByteTrigCfg( UARTByteTRIGTypeDef b ); /* 串口字节触发中断配置 */
void UART1_INTCfg( UINT8 s, UINT8 i ); /* 串口中断配置 */
void UART1_Reset( void ); /* 串口软件复位 */
#define UART1_CLR_RXFIFO() (R8_UART1_FCR |= RB_FCR_RX_FIFO_CLR) /* 清除当前接收FIFO */
#define UART1_CLR_TXFIFO() (R8_UART1_FCR |= RB_FCR_TX_FIFO_CLR) /* 清除当前发送FIFO */
#define UART1_GetITFlag() (R8_UART1_IIR&RB_IIR_INT_MASK) /* 获取当前中断标志 */
// please refer to LINE error and status define
#define UART1_GetLinSTA() (R8_UART1_LSR) /* 获取当前通讯状态 */
#define UART1_SendByte(b) (R8_UART1_THR = b) /* 串口单字节发送 */
void UART1_SendString( PUINT8 buf, UINT16 l ); /* 串口多字节发送 */
#define UART1_RecvByte() ( R8_UART1_RBR ) /* 串口读取单字节 */
UINT16 UART1_RecvString( PUINT8 buf ); /* 串口读取多字节 */
/****************** UART2 */
void UART2_DefInit( void ); /* 串口默认初始化配置 */
void UART2_BaudRateCfg( UINT32 baudrate ); /* 串口波特率配置 */
void UART2_ByteTrigCfg( UARTByteTRIGTypeDef b ); /* 串口字节触发中断配置 */
void UART2_INTCfg( UINT8 s, UINT8 i ); /* 串口中断配置 */
void UART2_Reset( void ); /* 串口软件复位 */
#define UART2_CLR_RXFIFO() (R8_UART2_FCR |= RB_FCR_RX_FIFO_CLR) /* 清除当前接收FIFO */
#define UART2_CLR_TXFIFO() (R8_UART2_FCR |= RB_FCR_TX_FIFO_CLR) /* 清除当前发送FIFO */
#define UART2_GetITFlag() (R8_UART2_IIR&RB_IIR_INT_MASK) /* 获取当前中断标志 */
// please refer to LINE error and status define
#define UART2_GetLinSTA() (R8_UART2_LSR) /* 获取当前通讯状态 */
#define UART2_SendByte(b) (R8_UART2_THR = b) /* 串口单字节发送 */
void UART2_SendString( PUINT8 buf, UINT16 l ); /* 串口多字节发送 */
#define UART2_RecvByte() ( R8_UART2_RBR ) /* 串口读取单字节 */
UINT16 UART2_RecvString( PUINT8 buf ); /* 串口读取多字节 */
/****************** UART3 */
void UART3_DefInit( void ); /* 串口默认初始化配置 */
void UART3_BaudRateCfg( UINT32 baudrate ); /* 串口波特率配置 */
void UART3_ByteTrigCfg( UARTByteTRIGTypeDef b ); /* 串口字节触发中断配置 */
void UART3_INTCfg( UINT8 s, UINT8 i ); /* 串口中断配置 */
void UART3_Reset( void ); /* 串口软件复位 */
#define UART3_CLR_RXFIFO() (R8_UART3_FCR |= RB_FCR_RX_FIFO_CLR) /* 清除当前接收FIFO */
#define UART3_CLR_TXFIFO() (R8_UART3_FCR |= RB_FCR_TX_FIFO_CLR) /* 清除当前发送FIFO */
#define UART3_GetITFlag() (R8_UART3_IIR&RB_IIR_INT_MASK) /* 获取当前中断标志 */
// please refer to LINE error and status define
#define UART3_GetLinSTA() (R8_UART3_LSR) /* 获取当前通讯状态 */
#define UART3_SendByte(b) (R8_UART3_THR = b) /* 串口单字节发送 */
void UART3_SendString( PUINT8 buf, UINT16 l ); /* 串口多字节发送 */
#define UART3_RecvByte() ( R8_UART3_RBR ) /* 串口读取单字节 */
UINT16 UART3_RecvString( PUINT8 buf ); /* 串口读取多字节 */
#ifdef __cplusplus
}
#endif
#endif // __CH57x_UART_H__

View File

@ -0,0 +1,59 @@
#ifndef __CH57x_USBDEV_H__
#define __CH57x_USBDEV_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "CH579SFR.h"
#include "core_cm0.h"
/* 以下缓存区是USB模块收发使用的数据缓冲区总共9个通道9块缓存用户可根据实际使用的通道数定义相应缓存区 */
extern PUINT8 pEP0_RAM_Addr; //ep0(64)+ep4_out(64)+ep4_in(64)
extern PUINT8 pEP1_RAM_Addr; //ep1_out(64)+ep1_in(64)
extern PUINT8 pEP2_RAM_Addr; //ep2_out(64)+ep2_in(64)
extern PUINT8 pEP3_RAM_Addr; //ep3_out(64)+ep3_in(64)
#define pSetupReqPak ((PUSB_SETUP_REQ)pEP0_RAM_Addr)
#define pEP0_DataBuf (pEP0_RAM_Addr)
#define pEP1_OUT_DataBuf (pEP1_RAM_Addr)
#define pEP1_IN_DataBuf (pEP1_RAM_Addr+64)
#define pEP2_OUT_DataBuf (pEP2_RAM_Addr)
#define pEP2_IN_DataBuf (pEP2_RAM_Addr+64)
#define pEP3_OUT_DataBuf (pEP3_RAM_Addr)
#define pEP3_IN_DataBuf (pEP3_RAM_Addr+64)
#define pEP4_OUT_DataBuf (pEP0_RAM_Addr+64)
#define pEP4_IN_DataBuf (pEP0_RAM_Addr+128)
void USB_DeviceInit( void ); /* USB设备功能初始化4个端点8个通道 */
void USB_DevTransProcess( void ); /* USB设备应答传输处理 */
void DevEP1_OUT_Deal( UINT8 l ); /* 设备端点1下传通道处理 */
void DevEP2_OUT_Deal( UINT8 l ); /* 设备端点2下传通道处理 */
void DevEP3_OUT_Deal( UINT8 l ); /* 设备端点3下传通道处理 */
void DevEP4_OUT_Deal( UINT8 l ); /* 设备端点4下传通道处理 */
void DevEP1_IN_Deal( UINT8 l ); /* 设备端点1上传通道处理 */
void DevEP2_IN_Deal( UINT8 l ); /* 设备端点2上传通道处理 */
void DevEP3_IN_Deal( UINT8 l ); /* 设备端点3上传通道处理 */
void DevEP4_IN_Deal( UINT8 l ); /* 设备端点4上传通道处理 */
// 0-未完成 (!0)-已完成
#define EP1_GetINSta() (R8_UEP1_CTRL&UEP_T_RES_NAK) /* 查询端点1是否上传完成 */
#define EP2_GetINSta() (R8_UEP2_CTRL&UEP_T_RES_NAK) /* 查询端点2是否上传完成 */
#define EP3_GetINSta() (R8_UEP3_CTRL&UEP_T_RES_NAK) /* 查询端点3是否上传完成 */
#define EP4_GetINSta() (R8_UEP4_CTRL&UEP_T_RES_NAK) /* 查询端点4是否上传完成 */
#ifdef __cplusplus
}
#endif
#endif // __CH57x_USBDEV_H__

View File

@ -0,0 +1,130 @@
#ifndef __CH57x_USBHOST_H__
#define __CH57x_USBHOST_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "CH579SFR.h"
#include "core_cm0.h"
/***************************************** 不使用U盘文件系统库或者U盘挂载USBhub下面需要关闭下面定义 */
#define FOR_ROOT_UDISK_ONLY
/***************************************** 使用U盘文件系统库需要开启下面定义, 不使用请关闭 */
#define DISK_BASE_BUF_LEN 512 /* 默认的磁盘数据缓冲区大小为512字节,建议选择为2048甚至4096以支持某些大扇区的U盘,为0则禁止在.H文件中定义缓冲区并由应用程序在pDISK_BASE_BUF中指定 */
// 各子程序返回状态码
#define ERR_SUCCESS 0x00 // 操作成功
#define ERR_USB_CONNECT 0x15 /* 检测到USB设备连接事件,已经连接 */
#define ERR_USB_DISCON 0x16 /* 检测到USB设备断开事件,已经断开 */
#define ERR_USB_BUF_OVER 0x17 /* USB传输的数据有误或者数据太多缓冲区溢出 */
#define ERR_USB_DISK_ERR 0x1F /* USB存储器操作失败,在初始化时可能是USB存储器不支持,在读写操作中可能是磁盘损坏或者已经断开 */
#define ERR_USB_TRANSFER 0x20 /* NAK/STALL等更多错误码在0x20~0x2F */
#define ERR_USB_UNSUPPORT 0xFB /*不支持的USB设备*/
#define ERR_USB_UNKNOWN 0xFE /*设备操作出错*/
#define ERR_AOA_PROTOCOL 0x41 /*协议版本出错 */
/*USB设备相关信息表,最多支持1个设备*/
#define ROOT_DEV_DISCONNECT 0
#define ROOT_DEV_CONNECTED 1
#define ROOT_DEV_FAILED 2
#define ROOT_DEV_SUCCESS 3
#define DEV_TYPE_KEYBOARD ( USB_DEV_CLASS_HID | 0x20 )
#define DEV_TYPE_MOUSE ( USB_DEV_CLASS_HID | 0x30 )
#define DEF_AOA_DEVICE 0xF0
#define DEV_TYPE_UNKNOW 0xFF
/*
: USB设备地址分配规则(USB_DEVICE_ADDR)
0x02 Root-HUB下的USB设备或外部HUB
0x1x Root-HUB下的外部HUB的端口x下的USB设备,x为1~n
*/
#define HUB_MAX_PORTS 4
#define WAIT_USB_TOUT_200US 800 // 等待USB中断超时时间
typedef struct
{
UINT8 DeviceStatus; // 设备状态,0-无设备,1-有设备但尚未初始化,2-有设备但初始化枚举失败,3-有设备且初始化枚举成功
UINT8 DeviceAddress; // 设备被分配的USB地址
UINT8 DeviceSpeed; // 0为低速,非0为全速
UINT8 DeviceType; // 设备类型
UINT16 DeviceVID;
UINT16 DevicePID;
UINT8 GpVar[4]; // 通用变量,存放端点
UINT8 GpHUBPortNum; // 通用变量,如果是HUB表示HUB端口数
} _RootHubDev;
extern _RootHubDev ThisUsbDev;
extern UINT8 UsbDevEndp0Size; // USB设备的端点0的最大包尺寸 */
extern UINT8 FoundNewDev;
extern PUINT8 pHOST_RX_RAM_Addr;
extern PUINT8 pHOST_TX_RAM_Addr;
#define pSetupReq ((PUSB_SETUP_REQ)pHOST_TX_RAM_Addr)
extern UINT8 Com_Buffer[];
/* 以下为USB主机请求包 */
extern const UINT8 SetupGetDevDescr[]; //*获取设备描述符*/
extern const UINT8 SetupGetCfgDescr[]; //*获取配置描述符*/
extern const UINT8 SetupSetUsbAddr[]; //*设置USB地址*/
extern const UINT8 SetupSetUsbConfig[]; //*设置USB配置*/
extern const UINT8 SetupSetUsbInterface[];//*设置USB接口配置*/
extern const UINT8 SetupClrEndpStall[]; //*清除端点STALL*/
void DisableRootHubPort(void) ; // 关闭ROOT-HUB端口,实际上硬件已经自动关闭,此处只是清除一些结构状态
UINT8 AnalyzeRootHub( void ) ; // 分析ROOT-HUB状态,处理ROOT-HUB端口的设备插拔事件
// 返回ERR_SUCCESS为没有情况,返回ERR_USB_CONNECT为检测到新连接,返回ERR_USB_DISCON为检测到断开
void SetHostUsbAddr( UINT8 addr ); // 设置USB主机当前操作的USB设备地址
void SetUsbSpeed( UINT8 FullSpeed ); // 设置当前USB速度
void ResetRootHubPort(void); // 检测到设备后,复位相应端口的总线,为枚举设备准备,设置为默认为全速
UINT8 EnableRootHubPort(void); // 使能ROOT-HUB端口,相应的bUH_PORT_EN置1开启端口,设备断开可能导致返回失败
void SelectHubPort( UINT8 HubPortIndex );// HubPortIndex=0选择操作指定的ROOT-HUB端口,否则选择操作指定的ROOT-HUB端口的外部HUB的指定端口
UINT8 WaitUSB_Interrupt( void ); // 等待USB中断
// 传输事务,输入目的端点地址/PID令牌,同步标志,以20uS为单位的NAK重试总时间(0则不重试,0xFFFF无限重试),返回0成功,超时/出错重试
UINT8 USBHostTransact( UINT8 endp_pid, UINT8 tog, UINT32 timeout ); // endp_pid: 高4位是token_pid令牌, 低4位是端点地址
UINT8 HostCtrlTransfer( PUINT8 DataBuf, PUINT8 RetLen ); // 执行控制传输,8字节请求码在pSetupReq中,DataBuf为可选的收发缓冲区
// 如果需要接收和发送数据,那么DataBuf需指向有效缓冲区用于存放后续数据,实际成功收发的总长度返回保存在ReqLen指向的字节变量中
void CopySetupReqPkg( PCCHAR pReqPkt ); // 复制控制传输的请求包
UINT8 CtrlGetDeviceDescr( void ); // 获取设备描述符,返回在 pHOST_TX_RAM_Addr 中
UINT8 CtrlGetConfigDescr( void ); // 获取配置描述符,返回在 pHOST_TX_RAM_Addr 中
UINT8 CtrlSetUsbAddress( UINT8 addr ); // 设置USB设备地址
UINT8 CtrlSetUsbConfig( UINT8 cfg ); // 设置USB设备配置
UINT8 CtrlClearEndpStall( UINT8 endp ) ; // 清除端点STALL
UINT8 CtrlSetUsbIntercace( UINT8 cfg ); // 设置USB设备接口
void USB_HostInit( void ); // 初始化USB主机
/*************************************************************/
UINT8 InitRootDevice( void );
UINT8 CtrlGetHIDDeviceReport( UINT8 infc ); // HID类命令SET_IDLE和GET_REPORT
UINT8 CtrlGetHubDescr( void ); // 获取HUB描述符,返回在TxBuffer中
UINT8 HubGetPortStatus( UINT8 HubPortIndex ); // 查询HUB端口状态,返回在TxBuffer中
UINT8 HubSetPortFeature( UINT8 HubPortIndex, UINT8 FeatureSelt ); // 设置HUB端口特性
UINT8 HubClearPortFeature( UINT8 HubPortIndex, UINT8 FeatureSelt ); // 清除HUB端口特性
#ifdef __cplusplus
}
#endif
#endif // __CH57x_USBHOST_H__

View File

@ -0,0 +1,19 @@
; *************************************************************
; *** Scatter-Loading Description File generated by uVision ***
; *************************************************************
LR_IROM1 0x00000000 0x0003E800 { ; load region size_region
ER_IROM1 0x00000000 0x0003E800 { ; load address = execution address
*.o (RESET, +First)
*(InRoot$$Sections)
.ANY (+RO)
}
RW_IRAM1 0x20000000 0x00004000 { ; RW data
.ANY (+RW +ZI)
}
RW_IRAM2 0x20004000 0x00004000 {
*.o (NMICode)
.ANY (+RW +ZI)
}
}

View File

@ -0,0 +1,977 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="project_projx.xsd">
<SchemaVersion>2.1</SchemaVersion>
<Header>### uVision Project, (C) Keil Software</Header>
<Targets>
<Target>
<TargetName>rtthread-ch579m</TargetName>
<ToolsetNumber>0x4</ToolsetNumber>
<ToolsetName>ARM-ADS</ToolsetName>
<pCCUsed>5060960::V5.06 update 7 (build 960)::.\ARMCC</pCCUsed>
<uAC6>0</uAC6>
<TargetOption>
<TargetCommonOption>
<Device>CH579M</Device>
<Vendor>WCH</Vendor>
<PackID>Keil.WCH57x_DFP.1.1.0</PackID>
<PackURL>http://wch.cn/pack</PackURL>
<Cpu>IRAM(0x20000000,0x8000) IROM(0x00000000,0x3E800) CPUTYPE("Cortex-M0") CLOCK(12000000) ELITTLE</Cpu>
<FlashUtilSpec></FlashUtilSpec>
<StartupFile></StartupFile>
<FlashDriverDll>UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0CH57x -FS00 -FL03F000 -FP0($$Device:CH579M$CMSIS\Flash\CH57x.FLM))</FlashDriverDll>
<DeviceId>0</DeviceId>
<RegisterFile>$$Device:CH579M$Drivers\CMSIS\Device\WCH\CH57x\Include\CH579SFR.h</RegisterFile>
<MemoryEnv></MemoryEnv>
<Cmp></Cmp>
<Asm></Asm>
<Linker></Linker>
<OHString></OHString>
<InfinionOptionDll></InfinionOptionDll>
<SLE66CMisc></SLE66CMisc>
<SLE66AMisc></SLE66AMisc>
<SLE66LinkerMisc></SLE66LinkerMisc>
<SFDFile>$$Device:CH579M$CMSIS\SVD\CH579SFR.svd</SFDFile>
<bCustSvd>0</bCustSvd>
<UseEnv>0</UseEnv>
<BinPath></BinPath>
<IncludePath></IncludePath>
<LibPath></LibPath>
<RegisterFilePath></RegisterFilePath>
<DBRegisterFilePath></DBRegisterFilePath>
<TargetStatus>
<Error>0</Error>
<ExitCodeStop>0</ExitCodeStop>
<ButtonStop>0</ButtonStop>
<NotGenerated>0</NotGenerated>
<InvalidFlash>1</InvalidFlash>
</TargetStatus>
<OutputDirectory>.\build\keil\Obj\</OutputDirectory>
<OutputName>rt-thread</OutputName>
<CreateExecutable>1</CreateExecutable>
<CreateLib>0</CreateLib>
<CreateHexFile>1</CreateHexFile>
<DebugInformation>1</DebugInformation>
<BrowseInformation>1</BrowseInformation>
<ListingPath>.\build\keil\List\</ListingPath>
<HexFormatSelection>1</HexFormatSelection>
<Merge32K>0</Merge32K>
<CreateBatchFile>0</CreateBatchFile>
<BeforeCompile>
<RunUserProg1>0</RunUserProg1>
<RunUserProg2>0</RunUserProg2>
<UserProg1Name></UserProg1Name>
<UserProg2Name></UserProg2Name>
<UserProg1Dos16Mode>0</UserProg1Dos16Mode>
<UserProg2Dos16Mode>0</UserProg2Dos16Mode>
<nStopU1X>0</nStopU1X>
<nStopU2X>0</nStopU2X>
</BeforeCompile>
<BeforeMake>
<RunUserProg1>0</RunUserProg1>
<RunUserProg2>0</RunUserProg2>
<UserProg1Name></UserProg1Name>
<UserProg2Name></UserProg2Name>
<UserProg1Dos16Mode>0</UserProg1Dos16Mode>
<UserProg2Dos16Mode>0</UserProg2Dos16Mode>
<nStopB1X>0</nStopB1X>
<nStopB2X>0</nStopB2X>
</BeforeMake>
<AfterMake>
<RunUserProg1>1</RunUserProg1>
<RunUserProg2>0</RunUserProg2>
<UserProg1Name>fromelf --bin !L --output rtthread.bin</UserProg1Name>
<UserProg2Name></UserProg2Name>
<UserProg1Dos16Mode>0</UserProg1Dos16Mode>
<UserProg2Dos16Mode>0</UserProg2Dos16Mode>
<nStopA1X>0</nStopA1X>
<nStopA2X>0</nStopA2X>
</AfterMake>
<SelectedForBatchBuild>0</SelectedForBatchBuild>
<SVCSIdString></SVCSIdString>
</TargetCommonOption>
<CommonProperty>
<UseCPPCompiler>0</UseCPPCompiler>
<RVCTCodeConst>0</RVCTCodeConst>
<RVCTZI>0</RVCTZI>
<RVCTOtherData>0</RVCTOtherData>
<ModuleSelection>0</ModuleSelection>
<IncludeInBuild>1</IncludeInBuild>
<AlwaysBuild>0</AlwaysBuild>
<GenerateAssemblyFile>0</GenerateAssemblyFile>
<AssembleAssemblyFile>0</AssembleAssemblyFile>
<PublicsOnly>0</PublicsOnly>
<StopOnExitCode>3</StopOnExitCode>
<CustomArgument></CustomArgument>
<IncludeLibraryModules></IncludeLibraryModules>
<ComprImg>1</ComprImg>
</CommonProperty>
<DllOption>
<SimDllName>SARMCM3.DLL</SimDllName>
<SimDllArguments> </SimDllArguments>
<SimDlgDll>DARMCM1.DLL</SimDlgDll>
<SimDlgDllArguments>-pCM0</SimDlgDllArguments>
<TargetDllName>SARMCM3.DLL</TargetDllName>
<TargetDllArguments> </TargetDllArguments>
<TargetDlgDll>TARMCM1.DLL</TargetDlgDll>
<TargetDlgDllArguments>-pCM0</TargetDlgDllArguments>
</DllOption>
<DebugOption>
<OPTHX>
<HexSelection>1</HexSelection>
<HexRangeLowAddress>0</HexRangeLowAddress>
<HexRangeHighAddress>0</HexRangeHighAddress>
<HexOffset>0</HexOffset>
<Oh166RecLen>16</Oh166RecLen>
</OPTHX>
</DebugOption>
<Utilities>
<Flash1>
<UseTargetDll>1</UseTargetDll>
<UseExternalTool>0</UseExternalTool>
<RunIndependent>0</RunIndependent>
<UpdateFlashBeforeDebugging>1</UpdateFlashBeforeDebugging>
<Capability>1</Capability>
<DriverSelection>4096</DriverSelection>
</Flash1>
<bUseTDR>1</bUseTDR>
<Flash2>BIN\UL2CM3.DLL</Flash2>
<Flash3>"" ()</Flash3>
<Flash4></Flash4>
<pFcarmOut></pFcarmOut>
<pFcarmGrp></pFcarmGrp>
<pFcArmRoot></pFcArmRoot>
<FcArmLst>0</FcArmLst>
</Utilities>
<TargetArmAds>
<ArmAdsMisc>
<GenerateListings>0</GenerateListings>
<asHll>1</asHll>
<asAsm>1</asAsm>
<asMacX>1</asMacX>
<asSyms>1</asSyms>
<asFals>1</asFals>
<asDbgD>1</asDbgD>
<asForm>1</asForm>
<ldLst>0</ldLst>
<ldmm>1</ldmm>
<ldXref>1</ldXref>
<BigEnd>0</BigEnd>
<AdsALst>1</AdsALst>
<AdsACrf>1</AdsACrf>
<AdsANop>0</AdsANop>
<AdsANot>0</AdsANot>
<AdsLLst>1</AdsLLst>
<AdsLmap>1</AdsLmap>
<AdsLcgr>1</AdsLcgr>
<AdsLsym>1</AdsLsym>
<AdsLszi>1</AdsLszi>
<AdsLtoi>1</AdsLtoi>
<AdsLsun>1</AdsLsun>
<AdsLven>1</AdsLven>
<AdsLsxf>1</AdsLsxf>
<RvctClst>0</RvctClst>
<GenPPlst>0</GenPPlst>
<AdsCpuType>"Cortex-M0"</AdsCpuType>
<RvctDeviceName></RvctDeviceName>
<mOS>0</mOS>
<uocRom>0</uocRom>
<uocRam>0</uocRam>
<hadIROM>1</hadIROM>
<hadIRAM>1</hadIRAM>
<hadXRAM>0</hadXRAM>
<uocXRam>0</uocXRam>
<RvdsVP>0</RvdsVP>
<RvdsMve>0</RvdsMve>
<RvdsCdeCp>0</RvdsCdeCp>
<hadIRAM2>0</hadIRAM2>
<hadIROM2>0</hadIROM2>
<StupSel>8</StupSel>
<useUlib>1</useUlib>
<EndSel>0</EndSel>
<uLtcg>0</uLtcg>
<nSecure>0</nSecure>
<RoSelD>3</RoSelD>
<RwSelD>3</RwSelD>
<CodeSel>0</CodeSel>
<OptFeed>0</OptFeed>
<NoZi1>0</NoZi1>
<NoZi2>0</NoZi2>
<NoZi3>0</NoZi3>
<NoZi4>0</NoZi4>
<NoZi5>0</NoZi5>
<Ro1Chk>0</Ro1Chk>
<Ro2Chk>0</Ro2Chk>
<Ro3Chk>0</Ro3Chk>
<Ir1Chk>1</Ir1Chk>
<Ir2Chk>0</Ir2Chk>
<Ra1Chk>0</Ra1Chk>
<Ra2Chk>0</Ra2Chk>
<Ra3Chk>0</Ra3Chk>
<Im1Chk>1</Im1Chk>
<Im2Chk>0</Im2Chk>
<OnChipMemories>
<Ocm1>
<Type>0</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</Ocm1>
<Ocm2>
<Type>0</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</Ocm2>
<Ocm3>
<Type>0</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</Ocm3>
<Ocm4>
<Type>0</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</Ocm4>
<Ocm5>
<Type>0</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</Ocm5>
<Ocm6>
<Type>0</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</Ocm6>
<IRAM>
<Type>0</Type>
<StartAddress>0x20000000</StartAddress>
<Size>0x8000</Size>
</IRAM>
<IROM>
<Type>1</Type>
<StartAddress>0x0</StartAddress>
<Size>0x3e800</Size>
</IROM>
<XRAM>
<Type>0</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</XRAM>
<OCR_RVCT1>
<Type>1</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</OCR_RVCT1>
<OCR_RVCT2>
<Type>1</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</OCR_RVCT2>
<OCR_RVCT3>
<Type>1</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</OCR_RVCT3>
<OCR_RVCT4>
<Type>1</Type>
<StartAddress>0x0</StartAddress>
<Size>0x3e800</Size>
</OCR_RVCT4>
<OCR_RVCT5>
<Type>1</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</OCR_RVCT5>
<OCR_RVCT6>
<Type>0</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</OCR_RVCT6>
<OCR_RVCT7>
<Type>0</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</OCR_RVCT7>
<OCR_RVCT8>
<Type>0</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</OCR_RVCT8>
<OCR_RVCT9>
<Type>0</Type>
<StartAddress>0x20000000</StartAddress>
<Size>0x8000</Size>
</OCR_RVCT9>
<OCR_RVCT10>
<Type>0</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</OCR_RVCT10>
</OnChipMemories>
<RvctStartVector></RvctStartVector>
</ArmAdsMisc>
<Cads>
<interw>1</interw>
<Optim>4</Optim>
<oTime>0</oTime>
<SplitLS>0</SplitLS>
<OneElfS>1</OneElfS>
<Strict>0</Strict>
<EnumInt>0</EnumInt>
<PlainCh>0</PlainCh>
<Ropi>0</Ropi>
<Rwpi>0</Rwpi>
<wLevel>2</wLevel>
<uThumb>0</uThumb>
<uSurpInc>0</uSurpInc>
<uC99>1</uC99>
<uGnu>0</uGnu>
<useXO>0</useXO>
<v6Lang>3</v6Lang>
<v6LangP>3</v6LangP>
<vShortEn>1</vShortEn>
<vShortWch>1</vShortWch>
<v6Lto>0</v6Lto>
<v6WtE>0</v6WtE>
<v6Rtti>0</v6Rtti>
<VariousControls>
<MiscControls></MiscControls>
<Define>__RTTHREAD__, RT_USING_ARM_LIBC, __CLK_TCK=RT_TICK_PER_SECOND</Define>
<Undefine></Undefine>
<IncludePath>applications;.;..\..\..\..\components\libc\compilers\common;..\..\..\..\components\libc\compilers\common\extension;..\..\..\..\libcpu\arm\common;..\..\..\..\libcpu\arm\cortex-m0;..\..\..\..\components\drivers\include;..\..\..\..\components\drivers\include;board;..\..\..\..\components\finsh;.;..\..\..\..\include;libraries\StdPeriphDriver\inc;libraries\CMSIS\Include;..\..\..\..\components\net\lwip-2.1.2\src;..\..\..\..\components\net\lwip-2.1.2\src\include;..\..\..\..\components\net\lwip-2.1.2\src\arch\include;..\..\..\..\components\net\lwip-2.1.2\src\include\netif;..\..\..\..\components\net\lwip-2.1.2\src\include\compat\posix;..\..\..\..\components\libc\posix\io\poll;..\..\..\..\components\libc\posix\io\stdio;..\..\..\..\components\libc\posix\ipc;..\..\..\..\components\drivers\usb\usbhost;..\..\..\..\components\drivers\usb\usbhost\class;..\..\..\..\components\drivers\usb\usbhost\core;..\..\..\..\components\drivers\usb\usbhost\include;..\..\..\..\components\drivers\include;..\..\..\..\components\net\netdev\include</IncludePath>
</VariousControls>
</Cads>
<Aads>
<interw>1</interw>
<Ropi>0</Ropi>
<Rwpi>0</Rwpi>
<thumb>0</thumb>
<SplitLS>0</SplitLS>
<SwStkChk>0</SwStkChk>
<NoWarn>0</NoWarn>
<uSurpInc>0</uSurpInc>
<useXO>0</useXO>
<ClangAsOpt>1</ClangAsOpt>
<VariousControls>
<MiscControls></MiscControls>
<Define></Define>
<Undefine></Undefine>
<IncludePath></IncludePath>
</VariousControls>
</Aads>
<LDads>
<umfTarg>1</umfTarg>
<Ropi>0</Ropi>
<Rwpi>0</Rwpi>
<noStLib>0</noStLib>
<RepFail>1</RepFail>
<useFile>0</useFile>
<TextAddressRange>0x08000000</TextAddressRange>
<DataAddressRange>0x20000000</DataAddressRange>
<pXoBase></pXoBase>
<ScatterFile>.\board\linker_scripts\link.sct</ScatterFile>
<IncludeLibs></IncludeLibs>
<IncludeLibsPath></IncludeLibsPath>
<Misc></Misc>
<LinkerInputFile></LinkerInputFile>
<DisabledWarnings></DisabledWarnings>
</LDads>
</TargetArmAds>
</TargetOption>
<Groups>
<Group>
<GroupName>Applications</GroupName>
<Files>
<File>
<FileName>main.c</FileName>
<FileType>1</FileType>
<FilePath>applications\main.c</FilePath>
</File>
</Files>
</Group>
<Group>
<GroupName>Compiler</GroupName>
<Files>
<File>
<FileName>syscall_mem.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\libc\compilers\armlibc\syscall_mem.c</FilePath>
</File>
<File>
<FileName>syscalls.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\libc\compilers\armlibc\syscalls.c</FilePath>
</File>
<File>
<FileName>stdlib.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\libc\compilers\common\stdlib.c</FilePath>
</File>
<File>
<FileName>time.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\libc\compilers\common\time.c</FilePath>
</File>
</Files>
</Group>
<Group>
<GroupName>CPU</GroupName>
<Files>
<File>
<FileName>showmem.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\libcpu\arm\common\showmem.c</FilePath>
</File>
<File>
<FileName>div0.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\libcpu\arm\common\div0.c</FilePath>
</File>
<File>
<FileName>backtrace.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\libcpu\arm\common\backtrace.c</FilePath>
</File>
<File>
<FileName>cpuport.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\libcpu\arm\cortex-m0\cpuport.c</FilePath>
</File>
<File>
<FileName>context_rvds.S</FileName>
<FileType>2</FileType>
<FilePath>..\..\..\..\libcpu\arm\cortex-m0\context_rvds.S</FilePath>
</File>
</Files>
</Group>
<Group>
<GroupName>DeviceDrivers</GroupName>
<Files>
<File>
<FileName>ringblk_buf.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\drivers\ipc\ringblk_buf.c</FilePath>
</File>
<File>
<FileName>dataqueue.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\drivers\ipc\dataqueue.c</FilePath>
</File>
<File>
<FileName>workqueue.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\drivers\ipc\workqueue.c</FilePath>
</File>
<File>
<FileName>waitqueue.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\drivers\ipc\waitqueue.c</FilePath>
</File>
<File>
<FileName>ringbuffer.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\drivers\ipc\ringbuffer.c</FilePath>
</File>
<File>
<FileName>pipe.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\drivers\ipc\pipe.c</FilePath>
</File>
<File>
<FileName>completion.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\drivers\ipc\completion.c</FilePath>
</File>
<File>
<FileName>serial.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\drivers\serial\serial.c</FilePath>
</File>
</Files>
</Group>
<Group>
<GroupName>Drivers</GroupName>
<Files>
<File>
<FileName>board.c</FileName>
<FileType>1</FileType>
<FilePath>board\board.c</FilePath>
</File>
<File>
<FileName>drv_uart.c</FileName>
<FileType>1</FileType>
<FilePath>board\drv_uart.c</FilePath>
</File>
<File>
<FileName>drv_usbh.c</FileName>
<FileType>1</FileType>
<FilePath>board\drv_usbh.c</FilePath>
</File>
<File>
<FileName>drv_eth.c</FileName>
<FileType>1</FileType>
<FilePath>board\drv_eth.c</FilePath>
</File>
</Files>
</Group>
<Group>
<GroupName>Finsh</GroupName>
<Files>
<File>
<FileName>shell.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\finsh\shell.c</FilePath>
</File>
<File>
<FileName>msh.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\finsh\msh.c</FilePath>
</File>
<File>
<FileName>cmd.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\finsh\cmd.c</FilePath>
</File>
</Files>
</Group>
<Group>
<GroupName>Kernel</GroupName>
<Files>
<File>
<FileName>mem.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\src\mem.c</FilePath>
</File>
<File>
<FileName>kservice.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\src\kservice.c</FilePath>
</File>
<File>
<FileName>scheduler.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\src\scheduler.c</FilePath>
</File>
<File>
<FileName>components.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\src\components.c</FilePath>
</File>
<File>
<FileName>idle.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\src\idle.c</FilePath>
</File>
<File>
<FileName>ipc.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\src\ipc.c</FilePath>
</File>
<File>
<FileName>thread.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\src\thread.c</FilePath>
</File>
<File>
<FileName>device.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\src\device.c</FilePath>
</File>
<File>
<FileName>object.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\src\object.c</FilePath>
</File>
<File>
<FileName>timer.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\src\timer.c</FilePath>
</File>
<File>
<FileName>clock.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\src\clock.c</FilePath>
</File>
<File>
<FileName>irq.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\src\irq.c</FilePath>
</File>
</Files>
</Group>
<Group>
<GroupName>Libraries</GroupName>
<Files>
<File>
<FileName>CH57x_pwm.c</FileName>
<FileType>1</FileType>
<FilePath>libraries\StdPeriphDriver\CH57x_pwm.c</FilePath>
</File>
<File>
<FileName>startup_ARMCM0.s</FileName>
<FileType>2</FileType>
<FilePath>libraries\Startup\startup_ARMCM0.s</FilePath>
</File>
<File>
<FileName>CH57x_pwr.c</FileName>
<FileType>1</FileType>
<FilePath>libraries\StdPeriphDriver\CH57x_pwr.c</FilePath>
</File>
<File>
<FileName>CH57x_sys.c</FileName>
<FileType>1</FileType>
<FilePath>libraries\StdPeriphDriver\CH57x_sys.c</FilePath>
</File>
<File>
<FileName>CH57x_spi1.c</FileName>
<FileType>1</FileType>
<FilePath>libraries\StdPeriphDriver\CH57x_spi1.c</FilePath>
</File>
<File>
<FileName>CH57x_uart0.c</FileName>
<FileType>1</FileType>
<FilePath>libraries\StdPeriphDriver\CH57x_uart0.c</FilePath>
</File>
<File>
<FileName>CH57x_flash.c</FileName>
<FileType>1</FileType>
<FilePath>libraries\StdPeriphDriver\CH57x_flash.c</FilePath>
</File>
<File>
<FileName>CH57x_uart1.c</FileName>
<FileType>1</FileType>
<FilePath>libraries\StdPeriphDriver\CH57x_uart1.c</FilePath>
</File>
<File>
<FileName>CH57x_gpio.c</FileName>
<FileType>1</FileType>
<FilePath>libraries\StdPeriphDriver\CH57x_gpio.c</FilePath>
</File>
<File>
<FileName>CH57x_timer1.c</FileName>
<FileType>1</FileType>
<FilePath>libraries\StdPeriphDriver\CH57x_timer1.c</FilePath>
</File>
<File>
<FileName>CH57x_adc.c</FileName>
<FileType>1</FileType>
<FilePath>libraries\StdPeriphDriver\CH57x_adc.c</FilePath>
</File>
<File>
<FileName>CH57x_lcd.c</FileName>
<FileType>1</FileType>
<FilePath>libraries\StdPeriphDriver\CH57x_lcd.c</FilePath>
</File>
<File>
<FileName>CH57x_uart3.c</FileName>
<FileType>1</FileType>
<FilePath>libraries\StdPeriphDriver\CH57x_uart3.c</FilePath>
</File>
<File>
<FileName>CH57x_uart2.c</FileName>
<FileType>1</FileType>
<FilePath>libraries\StdPeriphDriver\CH57x_uart2.c</FilePath>
</File>
<File>
<FileName>CH57x_spi0.c</FileName>
<FileType>1</FileType>
<FilePath>libraries\StdPeriphDriver\CH57x_spi0.c</FilePath>
</File>
<File>
<FileName>CH57x_timer3.c</FileName>
<FileType>1</FileType>
<FilePath>libraries\StdPeriphDriver\CH57x_timer3.c</FilePath>
</File>
<File>
<FileName>CH57x_int.c</FileName>
<FileType>1</FileType>
<FilePath>libraries\StdPeriphDriver\CH57x_int.c</FilePath>
</File>
<File>
<FileName>CH57x_clk.c</FileName>
<FileType>1</FileType>
<FilePath>libraries\StdPeriphDriver\CH57x_clk.c</FilePath>
</File>
<File>
<FileName>CH57x_timer2.c</FileName>
<FileType>1</FileType>
<FilePath>libraries\StdPeriphDriver\CH57x_timer2.c</FilePath>
</File>
<File>
<FileName>CH57x_timer0.c</FileName>
<FileType>1</FileType>
<FilePath>libraries\StdPeriphDriver\CH57x_timer0.c</FilePath>
</File>
</Files>
</Group>
<Group>
<GroupName>lwIP</GroupName>
<Files>
<File>
<FileName>netdb.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\net\lwip-2.1.2\src\api\netdb.c</FilePath>
</File>
<File>
<FileName>ip.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\net\lwip-2.1.2\src\core\ip.c</FilePath>
</File>
<File>
<FileName>autoip.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\net\lwip-2.1.2\src\core\ipv4\autoip.c</FilePath>
</File>
<File>
<FileName>ethernet.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\net\lwip-2.1.2\src\netif\ethernet.c</FilePath>
</File>
<File>
<FileName>netif.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\net\lwip-2.1.2\src\core\netif.c</FilePath>
</File>
<File>
<FileName>sys.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\net\lwip-2.1.2\src\core\sys.c</FilePath>
</File>
<File>
<FileName>sockets.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\net\lwip-2.1.2\src\api\sockets.c</FilePath>
</File>
<File>
<FileName>altcp_alloc.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\net\lwip-2.1.2\src\core\altcp_alloc.c</FilePath>
</File>
<File>
<FileName>netifapi.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\net\lwip-2.1.2\src\api\netifapi.c</FilePath>
</File>
<File>
<FileName>tcpip.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\net\lwip-2.1.2\src\api\tcpip.c</FilePath>
</File>
<File>
<FileName>ip4_addr.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\net\lwip-2.1.2\src\core\ipv4\ip4_addr.c</FilePath>
</File>
<File>
<FileName>dhcp.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\net\lwip-2.1.2\src\core\ipv4\dhcp.c</FilePath>
</File>
<File>
<FileName>init.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\net\lwip-2.1.2\src\core\init.c</FilePath>
</File>
<File>
<FileName>ethernetif.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\net\lwip-2.1.2\src\netif\ethernetif.c</FilePath>
</File>
<File>
<FileName>etharp.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\net\lwip-2.1.2\src\core\ipv4\etharp.c</FilePath>
</File>
<File>
<FileName>memp.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\net\lwip-2.1.2\src\core\memp.c</FilePath>
</File>
<File>
<FileName>ip4.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\net\lwip-2.1.2\src\core\ipv4\ip4.c</FilePath>
</File>
<File>
<FileName>netbuf.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\net\lwip-2.1.2\src\api\netbuf.c</FilePath>
</File>
<File>
<FileName>raw.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\net\lwip-2.1.2\src\core\raw.c</FilePath>
</File>
<File>
<FileName>ip4_frag.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\net\lwip-2.1.2\src\core\ipv4\ip4_frag.c</FilePath>
</File>
<File>
<FileName>tcp_out.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\net\lwip-2.1.2\src\core\tcp_out.c</FilePath>
</File>
<File>
<FileName>lowpan6.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\net\lwip-2.1.2\src\netif\lowpan6.c</FilePath>
</File>
<File>
<FileName>icmp.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\net\lwip-2.1.2\src\core\ipv4\icmp.c</FilePath>
</File>
<File>
<FileName>api_lib.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\net\lwip-2.1.2\src\api\api_lib.c</FilePath>
</File>
<File>
<FileName>inet_chksum.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\net\lwip-2.1.2\src\core\inet_chksum.c</FilePath>
</File>
<File>
<FileName>stats.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\net\lwip-2.1.2\src\core\stats.c</FilePath>
</File>
<File>
<FileName>err.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\net\lwip-2.1.2\src\api\err.c</FilePath>
</File>
<File>
<FileName>altcp.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\net\lwip-2.1.2\src\core\altcp.c</FilePath>
</File>
<File>
<FileName>tcp_in.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\net\lwip-2.1.2\src\core\tcp_in.c</FilePath>
</File>
<File>
<FileName>dns.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\net\lwip-2.1.2\src\core\dns.c</FilePath>
</File>
<File>
<FileName>sys_arch.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\net\lwip-2.1.2\src\arch\sys_arch.c</FilePath>
</File>
<File>
<FileName>timeouts.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\net\lwip-2.1.2\src\core\timeouts.c</FilePath>
</File>
<File>
<FileName>igmp.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\net\lwip-2.1.2\src\core\ipv4\igmp.c</FilePath>
</File>
<File>
<FileName>udp.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\net\lwip-2.1.2\src\core\udp.c</FilePath>
</File>
<File>
<FileName>altcp_tcp.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\net\lwip-2.1.2\src\core\altcp_tcp.c</FilePath>
</File>
<File>
<FileName>pbuf.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\net\lwip-2.1.2\src\core\pbuf.c</FilePath>
</File>
<File>
<FileName>def.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\net\lwip-2.1.2\src\core\def.c</FilePath>
</File>
<File>
<FileName>api_msg.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\net\lwip-2.1.2\src\api\api_msg.c</FilePath>
</File>
<File>
<FileName>ping.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\net\lwip-2.1.2\src\apps\ping\ping.c</FilePath>
</File>
<File>
<FileName>if_api.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\net\lwip-2.1.2\src\api\if_api.c</FilePath>
</File>
<File>
<FileName>tcp.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\net\lwip-2.1.2\src\core\tcp.c</FilePath>
</File>
</Files>
</Group>
<Group>
<GroupName>rt_usbh</GroupName>
<Files>
<File>
<FileName>hub.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\drivers\usb\usbhost\core\hub.c</FilePath>
</File>
<File>
<FileName>usbhost.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\drivers\usb\usbhost\core\usbhost.c</FilePath>
</File>
<File>
<FileName>usbhost_core.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\drivers\usb\usbhost\core\usbhost_core.c</FilePath>
</File>
<File>
<FileName>driver.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\drivers\usb\usbhost\core\driver.c</FilePath>
</File>
</Files>
</Group>
<Group>
<GroupName>SAL</GroupName>
<Files>
<File>
<FileName>netdev.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\net\netdev\src\netdev.c</FilePath>
</File>
<File>
<FileName>netdev_ipaddr.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\..\..\components\net\netdev\src\netdev_ipaddr.c</FilePath>
</File>
</Files>
</Group>
</Groups>
</Target>
</Targets>
<RTE>
<apis/>
<components/>
<files/>
</RTE>
<LayerInfo>
<Layers>
<Layer>
<LayName>template</LayName>
<LayPrjMark>1</LayPrjMark>
</Layer>
</Layers>
</LayerInfo>
</Project>

View File

@ -0,0 +1,238 @@
#ifndef RT_CONFIG_H__
#define RT_CONFIG_H__
/* Automatically generated file; DO NOT EDIT. */
/* RT-Thread Configuration */
/* RT-Thread Kernel */
#define RT_NAME_MAX 8
#define RT_ALIGN_SIZE 4
#define RT_THREAD_PRIORITY_32
#define RT_THREAD_PRIORITY_MAX 32
#define RT_TICK_PER_SECOND 1000
#define IDLE_THREAD_STACK_SIZE 256
/* kservice optimization */
/* Inter-Thread communication */
#define RT_USING_SEMAPHORE
#define RT_USING_MUTEX
#define RT_USING_MAILBOX
#define RT_USING_MESSAGEQUEUE
/* Memory Management */
#define RT_USING_SMALL_MEM
#define RT_USING_SMALL_MEM_AS_HEAP
#define RT_USING_HEAP
/* Kernel Device Object */
#define RT_USING_DEVICE
#define RT_USING_CONSOLE
#define RT_CONSOLEBUF_SIZE 128
#define RT_CONSOLE_DEVICE_NAME "uart1"
#define RT_VER_NUM 0x40100
/* RT-Thread Components */
#define RT_USING_COMPONENTS_INIT
#define RT_USING_USER_MAIN
#define RT_MAIN_THREAD_STACK_SIZE 1024
#define RT_MAIN_THREAD_PRIORITY 10
/* C++ features */
/* Command shell */
#define RT_USING_FINSH
#define RT_USING_MSH
#define FINSH_USING_MSH
#define FINSH_THREAD_NAME "tshell"
#define FINSH_THREAD_PRIORITY 20
#define FINSH_THREAD_STACK_SIZE 2048
#define FINSH_USING_HISTORY
#define FINSH_HISTORY_LINES 5
#define FINSH_USING_SYMTAB
#define FINSH_CMD_SIZE 80
#define MSH_USING_BUILT_IN_COMMANDS
#define FINSH_USING_DESCRIPTION
#define FINSH_ARG_MAX 10
/* Device virtual file system */
/* Device Drivers */
#define RT_USING_DEVICE_IPC
#define RT_USING_SERIAL
#define RT_USING_SERIAL_V1
#define RT_SERIAL_RB_BUFSZ 64
/* Using USB */
#define RT_USING_USB
#define RT_USING_USB_HOST
#define RT_USBD_THREAD_STACK_SZ 512
/* POSIX layer and C standard library */
#define RT_LIBC_DEFAULT_TIMEZONE 8
/* POSIX (Portable Operating System Interface) layer */
/* Interprocess Communication (IPC) */
/* Socket is in the 'Network' category */
/* Network */
/* Socket abstraction layer */
/* Network interface device */
#define RT_USING_NETDEV
#define NETDEV_USING_IFCONFIG
#define NETDEV_USING_PING
#define NETDEV_IPV4 1
#define NETDEV_IPV6 0
/* light weight TCP/IP stack */
#define RT_USING_LWIP
#define RT_USING_LWIP212
#define RT_LWIP_MEM_ALIGNMENT 4
#define RT_LWIP_ICMP
#define RT_LWIP_DNS
/* Static IPv4 Address */
#define RT_LWIP_IPADDR "19.111.115.250"
#define RT_LWIP_GWADDR "19.111.115.254"
#define RT_LWIP_MSKADDR "255.255.255.0"
#define RT_LWIP_UDP
#define RT_LWIP_TCP
#define RT_LWIP_RAW
#define RT_MEMP_NUM_NETCONN 4
#define RT_LWIP_PBUF_NUM 4
#define RT_LWIP_RAW_PCB_NUM 4
#define RT_LWIP_UDP_PCB_NUM 4
#define RT_LWIP_TCP_PCB_NUM 4
#define RT_LWIP_TCP_SEG_NUM 8
#define RT_LWIP_TCP_SND_BUF 3072
#define RT_LWIP_TCP_WND 3072
#define RT_LWIP_TCPTHREAD_PRIORITY 10
#define RT_LWIP_TCPTHREAD_MBOX_SIZE 4
#define RT_LWIP_TCPTHREAD_STACKSIZE 1024
#define LWIP_NO_TX_THREAD
#define RT_LWIP_ETHTHREAD_PRIORITY 12
#define RT_LWIP_ETHTHREAD_STACKSIZE 512
#define RT_LWIP_ETHTHREAD_MBOX_SIZE 4
#define LWIP_NETIF_STATUS_CALLBACK 0
#define LWIP_NETIF_LINK_CALLBACK 0
#define SO_REUSE 1
#define LWIP_SO_RCVTIMEO 1
#define LWIP_SO_SNDTIMEO 1
#define LWIP_SO_RCVBUF 1
#define LWIP_SO_LINGER 0
#define LWIP_NETIF_LOOPBACK 0
#define RT_LWIP_USING_PING
/* AT commands */
/* VBUS(Virtual Software BUS) */
/* Utilities */
/* RT-Thread Utestcases */
/* RT-Thread online packages */
/* IoT - internet of things */
/* Wi-Fi */
/* Marvell WiFi */
/* Wiced WiFi */
/* IoT Cloud */
/* security packages */
/* language packages */
/* multimedia packages */
/* LVGL: powerful and easy-to-use embedded GUI library */
/* u8g2: a monochrome graphic library */
/* PainterEngine: A cross-platform graphics application framework written in C language */
/* tools packages */
/* system packages */
/* enhanced kernel services */
/* POSIX extension functions */
/* acceleration: Assembly language or algorithmic acceleration packages */
/* CMSIS: ARM Cortex-M Microcontroller Software Interface Standard */
/* Micrium: Micrium software products porting for RT-Thread */
/* peripheral libraries and drivers */
/* AI packages */
/* miscellaneous packages */
/* samples: kernel and components samples */
/* entertainment: terminal games and other interesting software packages */
/* Hardware Drivers Config */
#define SOC_CH579M
/* On-chip Peripheral Drivers */
#define BSP_USING_UART
#define BSP_USING_UART1
#define BSP_USING_USBH
#define BSP_USING_ETH
#endif

View File

@ -0,0 +1,150 @@
import os
# toolchains options
ARCH='arm'
CPU='cortex-m0'
CROSS_TOOL='keil'
# bsp lib config
BSP_LIBRARY_TYPE = None
if os.getenv('RTT_CC'):
CROSS_TOOL = os.getenv('RTT_CC')
if os.getenv('RTT_ROOT'):
RTT_ROOT = os.getenv('RTT_ROOT')
# cross_tool provides the cross compiler
# EXEC_PATH is the compiler execute path, for example, CodeSourcery, Keil MDK, IAR
if CROSS_TOOL == 'gcc':
PLATFORM = 'gcc'
EXEC_PATH = r'C:/GCC'
elif CROSS_TOOL == 'keil':
PLATFORM = 'armcc'
EXEC_PATH = r'C:/Keil_v5'
elif CROSS_TOOL == 'iar':
PLATFORM = 'iar'
EXEC_PATH = r'C:/IAR'
if os.getenv('RTT_EXEC_PATH'):
EXEC_PATH = os.getenv('RTT_EXEC_PATH')
BUILD = 'debug'
if PLATFORM == 'gcc':
# toolchains
PREFIX = 'arm-none-eabi-'
CC = PREFIX + 'gcc'
AS = PREFIX + 'gcc'
AR = PREFIX + 'ar'
CXX = PREFIX + 'g++'
LINK = PREFIX + 'gcc'
TARGET_EXT = 'elf'
SIZE = PREFIX + 'size'
OBJDUMP = PREFIX + 'objdump'
OBJCPY = PREFIX + 'objcopy'
DEVICE = ' -mcpu=cortex-m0 -mthumb -ffunction-sections -fdata-sections'
CFLAGS = DEVICE + ' -std=gnu9x'
AFLAGS = ' -c' + DEVICE + ' -x assembler-with-cpp'
LFLAGS = DEVICE + ' -Wl,--gc-sections,-Map=rt-thread.map,-cref,-u,Reset_Handler -T board/linker_scripts/link.lds'
CPATH = ''
LPATH = ''
if BUILD == 'debug':
CFLAGS += ' -O0 -gdwarf-2 -g'
AFLAGS += ' -gdwarf-2'
else:
CFLAGS += ' -O2'
CXXFLAGS = CFLAGS
POST_ACTION = OBJCPY + ' -O binary $TARGET rtthread.bin\n' + SIZE + ' $TARGET \n'
elif PLATFORM == 'armcc':
# toolchains
CC = 'armcc'
CXX = 'armcc'
AS = 'armasm'
AR = 'armar'
LINK = 'armlink'
TARGET_EXT = 'axf'
DEVICE = ' --cpu Cortex-M3 '
CFLAGS = '-c ' + DEVICE + ' --apcs=interwork --c99'
AFLAGS = DEVICE + ' --apcs=interwork '
LFLAGS = DEVICE + ' --info sizes --info totals --info unused --info veneers --list rt-thread.map'
LFLAGS += r' --strict --scatter "board\linker_scripts\link.sct" '
CFLAGS += ' -I' + EXEC_PATH + '/ARM/ARMCC/include'
LFLAGS += ' --libpath=' + EXEC_PATH + '/ARM/ARMCC/lib'
CFLAGS += ' -D__MICROLIB '
AFLAGS += ' --pd "__MICROLIB SETA 1" '
LFLAGS += ' --library_type=microlib '
EXEC_PATH += '/ARM/ARMCC/bin/'
if BUILD == 'debug':
CFLAGS += ' -g -O0'
AFLAGS += ' -g'
else:
CFLAGS += ' -O2'
CXXFLAGS = CFLAGS
POST_ACTION = 'fromelf --bin $TARGET --output rtthread.bin \nfromelf -z $TARGET'
elif PLATFORM == 'iar':
# toolchains
CC = 'iccarm'
CXX = 'iccarm'
AS = 'iasmarm'
AR = 'iarchive'
LINK = 'ilinkarm'
TARGET_EXT = 'out'
DEVICE = '-Dewarm'
CFLAGS = DEVICE
CFLAGS += ' --diag_suppress Pa050'
CFLAGS += ' --no_cse'
CFLAGS += ' --no_unroll'
CFLAGS += ' --no_inline'
CFLAGS += ' --no_code_motion'
CFLAGS += ' --no_tbaa'
CFLAGS += ' --no_clustering'
CFLAGS += ' --no_scheduling'
CFLAGS += ' --endian=little'
CFLAGS += ' --cpu=Cortex-M3'
CFLAGS += ' -e'
CFLAGS += ' --fpu=None'
CFLAGS += ' --dlib_config "' + EXEC_PATH + '/arm/INC/c/DLib_Config_Normal.h"'
CFLAGS += ' --silent'
AFLAGS = DEVICE
AFLAGS += ' -s+'
AFLAGS += ' -w+'
AFLAGS += ' -r'
AFLAGS += ' --cpu Cortex-M3'
AFLAGS += ' --fpu None'
AFLAGS += ' -S'
if BUILD == 'debug':
CFLAGS += ' --debug'
CFLAGS += ' -On'
else:
CFLAGS += ' -Oh'
LFLAGS = ' --config "board/linker_scripts/link.icf"'
LFLAGS += ' --entry __iar_program_start'
CXXFLAGS = CFLAGS
EXEC_PATH = EXEC_PATH + '/arm/bin/'
POST_ACTION = 'ielftool --bin $TARGET rtthread.bin'
def dist_handle(BSP_ROOT, dist_dir):
import sys
cwd_path = os.getcwd()
sys.path.append(os.path.join(os.path.dirname(BSP_ROOT), 'tools'))
from sdk_dist import dist_do_building
dist_do_building(BSP_ROOT, dist_dir)

View File

@ -0,0 +1,404 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="project_projx.xsd">
<SchemaVersion>2.1</SchemaVersion>
<Header>### uVision Project, (C) Keil Software</Header>
<Targets>
<Target>
<TargetName>rtthread-ch579m</TargetName>
<ToolsetNumber>0x4</ToolsetNumber>
<ToolsetName>ARM-ADS</ToolsetName>
<uAC6>0</uAC6>
<TargetOption>
<TargetCommonOption>
<Device>CH579M</Device>
<Vendor>WCH</Vendor>
<PackID>Keil.WCH57x_DFP.1.1.0</PackID>
<PackURL>http://wch.cn/pack</PackURL>
<Cpu>IRAM(0x20000000,0x8000) IROM(0x00000000,0x3E800) CPUTYPE("Cortex-M0") CLOCK(12000000) ELITTLE</Cpu>
<FlashUtilSpec></FlashUtilSpec>
<StartupFile></StartupFile>
<FlashDriverDll>UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0CH57x -FS00 -FL03F000 -FP0($$Device:CH579M$CMSIS\Flash\CH57x.FLM))</FlashDriverDll>
<DeviceId>0</DeviceId>
<RegisterFile>$$Device:CH579M$Drivers\CMSIS\Device\WCH\CH57x\Include\CH579SFR.h</RegisterFile>
<MemoryEnv></MemoryEnv>
<Cmp></Cmp>
<Asm></Asm>
<Linker></Linker>
<OHString></OHString>
<InfinionOptionDll></InfinionOptionDll>
<SLE66CMisc></SLE66CMisc>
<SLE66AMisc></SLE66AMisc>
<SLE66LinkerMisc></SLE66LinkerMisc>
<SFDFile>$$Device:CH579M$CMSIS\SVD\CH579SFR.svd</SFDFile>
<bCustSvd>0</bCustSvd>
<UseEnv>0</UseEnv>
<BinPath></BinPath>
<IncludePath></IncludePath>
<LibPath></LibPath>
<RegisterFilePath></RegisterFilePath>
<DBRegisterFilePath></DBRegisterFilePath>
<TargetStatus>
<Error>0</Error>
<ExitCodeStop>0</ExitCodeStop>
<ButtonStop>0</ButtonStop>
<NotGenerated>0</NotGenerated>
<InvalidFlash>1</InvalidFlash>
</TargetStatus>
<OutputDirectory>.\build\keil\Obj\</OutputDirectory>
<OutputName>rt-thread</OutputName>
<CreateExecutable>1</CreateExecutable>
<CreateLib>0</CreateLib>
<CreateHexFile>1</CreateHexFile>
<DebugInformation>1</DebugInformation>
<BrowseInformation>1</BrowseInformation>
<ListingPath>.\build\keil\List\</ListingPath>
<HexFormatSelection>1</HexFormatSelection>
<Merge32K>0</Merge32K>
<CreateBatchFile>0</CreateBatchFile>
<BeforeCompile>
<RunUserProg1>0</RunUserProg1>
<RunUserProg2>0</RunUserProg2>
<UserProg1Name></UserProg1Name>
<UserProg2Name></UserProg2Name>
<UserProg1Dos16Mode>0</UserProg1Dos16Mode>
<UserProg2Dos16Mode>0</UserProg2Dos16Mode>
<nStopU1X>0</nStopU1X>
<nStopU2X>0</nStopU2X>
</BeforeCompile>
<BeforeMake>
<RunUserProg1>0</RunUserProg1>
<RunUserProg2>0</RunUserProg2>
<UserProg1Name></UserProg1Name>
<UserProg2Name></UserProg2Name>
<UserProg1Dos16Mode>0</UserProg1Dos16Mode>
<UserProg2Dos16Mode>0</UserProg2Dos16Mode>
<nStopB1X>0</nStopB1X>
<nStopB2X>0</nStopB2X>
</BeforeMake>
<AfterMake>
<RunUserProg1>1</RunUserProg1>
<RunUserProg2>0</RunUserProg2>
<UserProg1Name>fromelf --bin !L --output rtthread.bin</UserProg1Name>
<UserProg2Name></UserProg2Name>
<UserProg1Dos16Mode>0</UserProg1Dos16Mode>
<UserProg2Dos16Mode>0</UserProg2Dos16Mode>
<nStopA1X>0</nStopA1X>
<nStopA2X>0</nStopA2X>
</AfterMake>
<SelectedForBatchBuild>0</SelectedForBatchBuild>
<SVCSIdString></SVCSIdString>
</TargetCommonOption>
<CommonProperty>
<UseCPPCompiler>0</UseCPPCompiler>
<RVCTCodeConst>0</RVCTCodeConst>
<RVCTZI>0</RVCTZI>
<RVCTOtherData>0</RVCTOtherData>
<ModuleSelection>0</ModuleSelection>
<IncludeInBuild>1</IncludeInBuild>
<AlwaysBuild>0</AlwaysBuild>
<GenerateAssemblyFile>0</GenerateAssemblyFile>
<AssembleAssemblyFile>0</AssembleAssemblyFile>
<PublicsOnly>0</PublicsOnly>
<StopOnExitCode>3</StopOnExitCode>
<CustomArgument></CustomArgument>
<IncludeLibraryModules></IncludeLibraryModules>
<ComprImg>1</ComprImg>
</CommonProperty>
<DllOption>
<SimDllName>SARMCM3.DLL</SimDllName>
<SimDllArguments> </SimDllArguments>
<SimDlgDll>DARMCM1.DLL</SimDlgDll>
<SimDlgDllArguments>-pCM0</SimDlgDllArguments>
<TargetDllName>SARMCM3.DLL</TargetDllName>
<TargetDllArguments> </TargetDllArguments>
<TargetDlgDll>TARMCM1.DLL</TargetDlgDll>
<TargetDlgDllArguments>-pCM0</TargetDlgDllArguments>
</DllOption>
<DebugOption>
<OPTHX>
<HexSelection>1</HexSelection>
<HexRangeLowAddress>0</HexRangeLowAddress>
<HexRangeHighAddress>0</HexRangeHighAddress>
<HexOffset>0</HexOffset>
<Oh166RecLen>16</Oh166RecLen>
</OPTHX>
</DebugOption>
<Utilities>
<Flash1>
<UseTargetDll>1</UseTargetDll>
<UseExternalTool>0</UseExternalTool>
<RunIndependent>0</RunIndependent>
<UpdateFlashBeforeDebugging>1</UpdateFlashBeforeDebugging>
<Capability>1</Capability>
<DriverSelection>4096</DriverSelection>
</Flash1>
<bUseTDR>1</bUseTDR>
<Flash2>BIN\UL2CM3.DLL</Flash2>
<Flash3>"" ()</Flash3>
<Flash4></Flash4>
<pFcarmOut></pFcarmOut>
<pFcarmGrp></pFcarmGrp>
<pFcArmRoot></pFcArmRoot>
<FcArmLst>0</FcArmLst>
</Utilities>
<TargetArmAds>
<ArmAdsMisc>
<GenerateListings>0</GenerateListings>
<asHll>1</asHll>
<asAsm>1</asAsm>
<asMacX>1</asMacX>
<asSyms>1</asSyms>
<asFals>1</asFals>
<asDbgD>1</asDbgD>
<asForm>1</asForm>
<ldLst>0</ldLst>
<ldmm>1</ldmm>
<ldXref>1</ldXref>
<BigEnd>0</BigEnd>
<AdsALst>1</AdsALst>
<AdsACrf>1</AdsACrf>
<AdsANop>0</AdsANop>
<AdsANot>0</AdsANot>
<AdsLLst>1</AdsLLst>
<AdsLmap>1</AdsLmap>
<AdsLcgr>1</AdsLcgr>
<AdsLsym>1</AdsLsym>
<AdsLszi>1</AdsLszi>
<AdsLtoi>1</AdsLtoi>
<AdsLsun>1</AdsLsun>
<AdsLven>1</AdsLven>
<AdsLsxf>1</AdsLsxf>
<RvctClst>0</RvctClst>
<GenPPlst>0</GenPPlst>
<AdsCpuType>"Cortex-M0"</AdsCpuType>
<RvctDeviceName></RvctDeviceName>
<mOS>0</mOS>
<uocRom>0</uocRom>
<uocRam>0</uocRam>
<hadIROM>1</hadIROM>
<hadIRAM>1</hadIRAM>
<hadXRAM>0</hadXRAM>
<uocXRam>0</uocXRam>
<RvdsVP>0</RvdsVP>
<RvdsMve>0</RvdsMve>
<RvdsCdeCp>0</RvdsCdeCp>
<hadIRAM2>0</hadIRAM2>
<hadIROM2>0</hadIROM2>
<StupSel>8</StupSel>
<useUlib>1</useUlib>
<EndSel>0</EndSel>
<uLtcg>0</uLtcg>
<nSecure>0</nSecure>
<RoSelD>3</RoSelD>
<RwSelD>3</RwSelD>
<CodeSel>0</CodeSel>
<OptFeed>0</OptFeed>
<NoZi1>0</NoZi1>
<NoZi2>0</NoZi2>
<NoZi3>0</NoZi3>
<NoZi4>0</NoZi4>
<NoZi5>0</NoZi5>
<Ro1Chk>0</Ro1Chk>
<Ro2Chk>0</Ro2Chk>
<Ro3Chk>0</Ro3Chk>
<Ir1Chk>1</Ir1Chk>
<Ir2Chk>0</Ir2Chk>
<Ra1Chk>0</Ra1Chk>
<Ra2Chk>0</Ra2Chk>
<Ra3Chk>0</Ra3Chk>
<Im1Chk>1</Im1Chk>
<Im2Chk>0</Im2Chk>
<OnChipMemories>
<Ocm1>
<Type>0</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</Ocm1>
<Ocm2>
<Type>0</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</Ocm2>
<Ocm3>
<Type>0</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</Ocm3>
<Ocm4>
<Type>0</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</Ocm4>
<Ocm5>
<Type>0</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</Ocm5>
<Ocm6>
<Type>0</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</Ocm6>
<IRAM>
<Type>0</Type>
<StartAddress>0x20000000</StartAddress>
<Size>0x8000</Size>
</IRAM>
<IROM>
<Type>1</Type>
<StartAddress>0x0</StartAddress>
<Size>0x3e800</Size>
</IROM>
<XRAM>
<Type>0</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</XRAM>
<OCR_RVCT1>
<Type>1</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</OCR_RVCT1>
<OCR_RVCT2>
<Type>1</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</OCR_RVCT2>
<OCR_RVCT3>
<Type>1</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</OCR_RVCT3>
<OCR_RVCT4>
<Type>1</Type>
<StartAddress>0x0</StartAddress>
<Size>0x3e800</Size>
</OCR_RVCT4>
<OCR_RVCT5>
<Type>1</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</OCR_RVCT5>
<OCR_RVCT6>
<Type>0</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</OCR_RVCT6>
<OCR_RVCT7>
<Type>0</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</OCR_RVCT7>
<OCR_RVCT8>
<Type>0</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</OCR_RVCT8>
<OCR_RVCT9>
<Type>0</Type>
<StartAddress>0x20000000</StartAddress>
<Size>0x8000</Size>
</OCR_RVCT9>
<OCR_RVCT10>
<Type>0</Type>
<StartAddress>0x0</StartAddress>
<Size>0x0</Size>
</OCR_RVCT10>
</OnChipMemories>
<RvctStartVector></RvctStartVector>
</ArmAdsMisc>
<Cads>
<interw>1</interw>
<Optim>4</Optim>
<oTime>0</oTime>
<SplitLS>0</SplitLS>
<OneElfS>1</OneElfS>
<Strict>0</Strict>
<EnumInt>0</EnumInt>
<PlainCh>0</PlainCh>
<Ropi>0</Ropi>
<Rwpi>0</Rwpi>
<wLevel>2</wLevel>
<uThumb>0</uThumb>
<uSurpInc>0</uSurpInc>
<uC99>1</uC99>
<uGnu>0</uGnu>
<useXO>0</useXO>
<v6Lang>3</v6Lang>
<v6LangP>3</v6LangP>
<vShortEn>1</vShortEn>
<vShortWch>1</vShortWch>
<v6Lto>0</v6Lto>
<v6WtE>0</v6WtE>
<v6Rtti>0</v6Rtti>
<VariousControls>
<MiscControls></MiscControls>
<Define></Define>
<Undefine></Undefine>
<IncludePath></IncludePath>
</VariousControls>
</Cads>
<Aads>
<interw>1</interw>
<Ropi>0</Ropi>
<Rwpi>0</Rwpi>
<thumb>0</thumb>
<SplitLS>0</SplitLS>
<SwStkChk>0</SwStkChk>
<NoWarn>0</NoWarn>
<uSurpInc>0</uSurpInc>
<useXO>0</useXO>
<ClangAsOpt>1</ClangAsOpt>
<VariousControls>
<MiscControls></MiscControls>
<Define></Define>
<Undefine></Undefine>
<IncludePath></IncludePath>
</VariousControls>
</Aads>
<LDads>
<umfTarg>1</umfTarg>
<Ropi>0</Ropi>
<Rwpi>0</Rwpi>
<noStLib>0</noStLib>
<RepFail>1</RepFail>
<useFile>0</useFile>
<TextAddressRange>0x08000000</TextAddressRange>
<DataAddressRange>0x20000000</DataAddressRange>
<pXoBase></pXoBase>
<ScatterFile>.\board\linker_scripts\link.sct</ScatterFile>
<IncludeLibs></IncludeLibs>
<IncludeLibsPath></IncludeLibsPath>
<Misc></Misc>
<LinkerInputFile></LinkerInputFile>
<DisabledWarnings></DisabledWarnings>
</LDads>
</TargetArmAds>
</TargetOption>
<Groups>
<Group>
<GroupName>main</GroupName>
</Group>
</Groups>
</Target>
</Targets>
<RTE>
<apis/>
<components/>
<files/>
</RTE>
<LayerInfo>
<Layers>
<Layer>
<LayName>template</LayName>
<LayPrjMark>1</LayPrjMark>
</Layer>
</Layers>
</LayerInfo>
</Project>