├── .gitignore ├── README.md ├── boards.txt ├── cores └── arduino │ ├── Arduino.h │ ├── Client.h │ ├── HardwareSerial.cpp │ ├── HardwareSerial.h │ ├── IPAddress.cpp │ ├── IPAddress.h │ ├── Print.cpp │ ├── Print.h │ ├── Printable.h │ ├── SPI.cpp │ ├── SPI.h │ ├── Server.h │ ├── SoftwareSerial.cpp │ ├── SoftwareSerial.h │ ├── Stream.cpp │ ├── Stream.h │ ├── Tone.cpp │ ├── Tone.h │ ├── Udp.h │ ├── WCharacter.h │ ├── WMath.cpp │ ├── WMath.h │ ├── WProgram.h │ ├── WString.cpp │ ├── WString.h │ ├── Wire.cpp │ ├── Wire.h │ ├── WireBase.cpp │ ├── WireBase.h │ ├── avr │ ├── interrupt.h │ └── pgmspace.h │ ├── binary.h │ ├── dtostrf.c │ ├── dtostrf.h │ ├── itoa.c │ ├── itoa.h │ ├── libcore │ ├── Arduino.c │ ├── adc.c │ ├── adc.h │ ├── at32f403a_407_clock.c │ ├── at32f403a_407_clock.h │ ├── config │ │ └── mcu_config.h │ ├── delay.c │ ├── delay.h │ ├── extend_SRAM.c │ ├── extend_SRAM.h │ ├── exti.c │ ├── exti.h │ ├── gpio.c │ ├── gpio.h │ ├── i2c.c │ ├── i2c.h │ ├── mcu_core.c │ ├── mcu_core.h │ ├── mcu_type.h │ ├── pwm.c │ ├── pwm.h │ ├── rtc.c │ ├── rtc.h │ ├── syscalls.c │ ├── timer.c │ ├── timer.h │ ├── wdg.c │ └── wdg.h │ └── main.cpp ├── libraries └── Generic_Examples │ ├── empty.h │ └── examples │ └── 01.Basics │ └── Blink │ ├── Blink.ino │ └── Blink.txt ├── package_at32_index.json ├── platform.txt ├── system ├── AT32F403A │ └── syscall.c └── Drivers │ ├── CMSIS │ └── Include │ │ ├── at32f403a_407.h │ │ ├── cmsis_compiler.h │ │ ├── cmsis_gcc.h │ │ ├── cmsis_version.h │ │ ├── core_cm4.h │ │ ├── mpu_armv7.h │ │ └── system_at32f403a_407.h │ └── Firmware │ ├── inc │ ├── at32f403a_407_acc.h │ ├── at32f403a_407_adc.h │ ├── at32f403a_407_bpr.h │ ├── at32f403a_407_can.h │ ├── at32f403a_407_crc.h │ ├── at32f403a_407_crm.h │ ├── at32f403a_407_dac.h │ ├── at32f403a_407_debug.h │ ├── at32f403a_407_def.h │ ├── at32f403a_407_dma.h │ ├── at32f403a_407_emac.h │ ├── at32f403a_407_exint.h │ ├── at32f403a_407_flash.h │ ├── at32f403a_407_gpio.h │ ├── at32f403a_407_i2c.h │ ├── at32f403a_407_misc.h │ ├── at32f403a_407_pwc.h │ ├── at32f403a_407_rtc.h │ ├── at32f403a_407_sdio.h │ ├── at32f403a_407_spi.h │ ├── at32f403a_407_tmr.h │ ├── at32f403a_407_usart.h │ ├── at32f403a_407_usb.h │ ├── at32f403a_407_wdt.h │ ├── at32f403a_407_wwdt.h │ └── at32f403a_407_xmc.h │ └── src │ ├── at32f403a_407_acc.c │ ├── at32f403a_407_adc.c │ ├── at32f403a_407_bpr.c │ ├── at32f403a_407_can.c │ ├── at32f403a_407_crc.c │ ├── at32f403a_407_crm.c │ ├── at32f403a_407_dac.c │ ├── at32f403a_407_debug.c │ ├── at32f403a_407_dma.c │ ├── at32f403a_407_emac.c │ ├── at32f403a_407_exint.c │ ├── at32f403a_407_flash.c │ ├── at32f403a_407_gpio.c │ ├── at32f403a_407_i2c.c │ ├── at32f403a_407_misc.c │ ├── at32f403a_407_pwc.c │ ├── at32f403a_407_rtc.c │ ├── at32f403a_407_sdio.c │ ├── at32f403a_407_spi.c │ ├── at32f403a_407_tmr.c │ ├── at32f403a_407_usart.c │ ├── at32f403a_407_usb.c │ ├── at32f403a_407_wdt.c │ ├── at32f403a_407_wwdt.c │ └── at32f403a_407_xmc.c └── variants └── AT32F403ACGU7 ├── FrameLib.a ├── at32f403a_407_conf.h ├── at32f403a_407_conf_template.h ├── linker_scripts └── AT32F403AxG_FLASH.ld ├── startup_at32f403a_407.S └── system_at32f403a_407.c /.gitignore: -------------------------------------------------------------------------------- 1 | # Specific 2 | astyle.out 3 | boards.local.txt 4 | platform.local.txt 5 | path_config.json 6 | update_config.json 7 | variant_config.json 8 | 9 | # Backup 10 | *.bak 11 | *.gho 12 | *.ori 13 | *.swp 14 | *.tmp 15 | 16 | # macOS 17 | # General 18 | .DS_Store 19 | .AppleDouble 20 | .LSOverride 21 | 22 | # Patch 23 | *.orig 24 | *.rej 25 | 26 | # Python 27 | # Byte-compiled / optimized / DLL files 28 | __pycache__/ 29 | *.py[cod] 30 | *$py.class 31 | 32 | # VisualStudioCode 33 | .vscode/* 34 | *.code-workspace 35 | 36 | Unsupport/* 37 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ArduinoCore-AT32F4 2 | ## Using this core with the Arduino IDE 3 | 4 | To compile for this core with the Arduino IDE, add the following URL to the boards manager. 5 | 6 | `https://raw.githubusercontent.com/WeActStudio/ArduinoCore-AT32F4/main/package_at32_index.json` 7 | ![image](https://user-images.githubusercontent.com/57818792/180649925-ed366423-5f76-42d5-b801-dd5ed2923825.png) 8 | -------------------------------------------------------------------------------- /cores/arduino/Arduino.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * Copyright (c) 2017 - 2022 _VIFEXTech 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | #ifndef __ARDUINO_H 24 | #define __ARDUINO_H 25 | 26 | #include 27 | #include 28 | #include "libcore/mcu_core.h" 29 | #include "binary.h" 30 | #include "avr/pgmspace.h" 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | #define KEILDUINO_VERSION 100 37 | 38 | #define PI 3.1415926535897932384626433832795f 39 | #define HALF_PI 1.5707963267948966192313216916398f 40 | #define TWO_PI 6.283185307179586476925286766559f 41 | #define DEG_TO_RAD 0.017453292519943295769236907684886f 42 | #define RAD_TO_DEG 57.295779513082320876798154814105f 43 | #define EULER 2.718281828459045235360287471352f 44 | 45 | #define SERIAL 0x0 46 | #define DISPLAY 0x1 47 | 48 | #define LSBFIRST 0x0 49 | #define MSBFIRST 0x1 50 | 51 | #define LOW 0x0 52 | #define HIGH 0x1 53 | 54 | #define min(a,b) ((a)<(b)?(a):(b)) 55 | #define max(a,b) ((a)>(b)?(a):(b)) 56 | #define ABS(x) (((x)>0)?(x):-(x)) //abs(x) is define in stdlib.h 57 | #define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt))) 58 | //#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) 59 | #define radians(deg) ((deg)*DEG_TO_RAD) 60 | #define degrees(rad) ((rad)*RAD_TO_DEG) 61 | #define sq(x) ((x)*(x)) 62 | 63 | #define lowByte(w) ((uint8_t) ((w) & 0xff)) 64 | #define highByte(w) ((uint8_t) ((w) >> 8)) 65 | 66 | #define bitRead(value, bit) (((value) >> (bit)) & 0x01) 67 | #define bitSet(value, bit) ((value) |= (1UL << (bit))) 68 | #define bitClear(value, bit) ((value) &= ~(1UL << (bit))) 69 | #define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit)) 70 | 71 | #ifndef _BV 72 | # define _BV(bit) (1 << (bit)) 73 | #endif 74 | 75 | #define clockCyclesPerMicrosecond() (F_CPU / 1000000L) 76 | #define clockCyclesToMicroseconds(a) (((a) * 1000L) / (F_CPU / 1000L)) 77 | #define microsecondsToClockCycles(a) ((a) * (F_CPU / 1000000L)) 78 | 79 | #define delay(ms) delay_ms(ms) 80 | #define delayMicroseconds(us) delay_us(us) 81 | 82 | #define interrupts() sei() 83 | #define noInterrupts() cli() 84 | 85 | #define NOT_A_PIN 0xFF 86 | #define NOT_A_PORT 0xFF 87 | #define NOT_AN_INTERRUPT -1 88 | 89 | #define boolean bool 90 | typedef unsigned char byte; 91 | 92 | void pinMode(uint8_t pin, PinMode_TypeDef mode); 93 | void digitalWrite(uint8_t pin, uint8_t value); 94 | uint8_t digitalRead(uint8_t pin); 95 | void analogWrite(uint8_t pin, uint16_t value); 96 | uint16_t analogRead(uint8_t pin); 97 | uint16_t analogRead_DMA(uint8_t pin); 98 | void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t value); 99 | uint32_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint32_t bitOrder); 100 | uint32_t pulseIn(uint32_t pin, uint32_t state, uint32_t timeout); 101 | 102 | long map(long x, long in_min, long in_max, long out_min, long out_max); 103 | float fmap(float x, float in_min, float in_max, float out_min, float out_max); 104 | void yield(void); 105 | 106 | #ifdef __cplusplus 107 | }// extern "C" 108 | #endif 109 | 110 | #ifdef __cplusplus 111 | # include "WCharacter.h" 112 | # include "WString.h" 113 | # include "WMath.h" 114 | # include 115 | # include 116 | #endif 117 | 118 | #endif 119 | -------------------------------------------------------------------------------- /cores/arduino/Client.h: -------------------------------------------------------------------------------- 1 | /* 2 | Client.h - Base class that provides Client 3 | Copyright (c) 2011 Adrian McEwen. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef client_h 21 | #define client_h 22 | #include "Print.h" 23 | #include "Stream.h" 24 | #include "IPAddress.h" 25 | 26 | class Client: public Stream 27 | { 28 | public: 29 | virtual int connect(IPAddress ip, uint16_t port) =0; 30 | virtual int connect(const char *host, uint16_t port) =0; 31 | virtual size_t write(uint8_t) =0; 32 | virtual size_t write(const uint8_t *buf, size_t size) =0; 33 | virtual int available() = 0; 34 | virtual int read() = 0; 35 | virtual int read(uint8_t *buf, size_t size) = 0; 36 | virtual int peek() = 0; 37 | virtual void flush() = 0; 38 | virtual void stop() = 0; 39 | virtual uint8_t connected() = 0; 40 | virtual operator bool() = 0; 41 | protected: 42 | uint8_t* rawIPAddress(IPAddress& addr) 43 | { 44 | return addr.raw_address(); 45 | } 46 | }; 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /cores/arduino/HardwareSerial.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * Copyright (c) 2019 _VIFEXTech 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | #ifndef __HardwareSerial_h 24 | #define __HardwareSerial_h 25 | 26 | #include "Arduino.h" 27 | #include "Print.h" 28 | #include "Stream.h" 29 | 30 | typedef enum 31 | { 32 | SERIAL_7E1, 33 | SERIAL_7E2, 34 | SERIAL_7O1, 35 | SERIAL_7O2, 36 | SERIAL_7E0_5, 37 | SERIAL_7E1_5, 38 | SERIAL_7O0_5, 39 | SERIAL_7O1_5, 40 | 41 | SERIAL_8N1, 42 | SERIAL_8N2, 43 | SERIAL_8E1, 44 | SERIAL_8E2, 45 | SERIAL_8O1, 46 | SERIAL_8O2, 47 | SERIAL_8N0_5, 48 | SERIAL_8N1_5, 49 | SERIAL_8E0_5, 50 | SERIAL_8E1_5, 51 | SERIAL_8O0_5, 52 | SERIAL_8O1_5, 53 | 54 | SERIAL_9N1, 55 | SERIAL_9N2, 56 | SERIAL_9N0_5, 57 | SERIAL_9N1_5, 58 | } SERIAL_Config_t; 59 | 60 | class HardwareSerial : public Stream 61 | { 62 | typedef void(*CallbackFunction_t)(HardwareSerial* serial); 63 | 64 | public: 65 | HardwareSerial(usart_type* usart); 66 | 67 | usart_type* getUSART() 68 | { 69 | return _USARTx; 70 | } 71 | 72 | void begin( 73 | uint32_t baudRate, 74 | SERIAL_Config_t config = SERIAL_CONFIG_DEFAULT, 75 | uint8_t preemptionPriority = SERIAL_PREEMPTIONPRIORITY_DEFAULT, 76 | uint8_t subPriority = SERIAL_SUBPRIORITY_DEFAULT 77 | ); 78 | void end(void); 79 | void attachInterrupt(CallbackFunction_t func); 80 | virtual int available(void); 81 | virtual int peek(void); 82 | virtual int read(void); 83 | virtual void flush(void); 84 | 85 | virtual size_t write(uint8_t n); 86 | inline size_t write(unsigned long n) 87 | { 88 | return write((uint8_t)n); 89 | } 90 | inline size_t write(long n) 91 | { 92 | return write((uint8_t)n); 93 | } 94 | inline size_t write(unsigned int n) 95 | { 96 | return write((uint8_t)n); 97 | } 98 | inline size_t write(int n) 99 | { 100 | return write((uint8_t)n); 101 | } 102 | using Print::write; // pull in write(str) and write(buf, size) from Print 103 | operator bool() 104 | { 105 | return true; 106 | } 107 | 108 | void IRQHandler(); 109 | 110 | private: 111 | usart_type* _USARTx; 112 | CallbackFunction_t _callbackFunction; 113 | volatile uint16_t _rxBufferHead; 114 | volatile uint16_t _rxBufferTail; 115 | uint8_t _rxBuffer[SERIAL_RX_BUFFER_SIZE]; 116 | }; 117 | 118 | #if SERIAL_1_ENABLE 119 | extern HardwareSerial Serial; 120 | #endif 121 | 122 | #if SERIAL_2_ENABLE 123 | extern HardwareSerial Serial2; 124 | #endif 125 | 126 | #if SERIAL_3_ENABLE 127 | extern HardwareSerial Serial3; 128 | #endif 129 | 130 | #if SERIAL_4_ENABLE 131 | extern HardwareSerial Serial4; 132 | #endif 133 | 134 | #if SERIAL_5_ENABLE 135 | extern HardwareSerial Serial5; 136 | #endif 137 | 138 | #if SERIAL_6_ENABLE 139 | extern HardwareSerial Serial6; 140 | #endif 141 | 142 | #if SERIAL_7_ENABLE 143 | extern HardwareSerial Serial7; 144 | #endif 145 | 146 | #if SERIAL_8_ENABLE 147 | extern HardwareSerial Serial8; 148 | #endif 149 | 150 | #endif 151 | -------------------------------------------------------------------------------- /cores/arduino/IPAddress.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | IPAddress.cpp - Base class that provides IPAddress 3 | Copyright (c) 2011 Adrian McEwen. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | IPAddress::IPAddress() 25 | { 26 | _address.dword = 0; 27 | } 28 | 29 | IPAddress::IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet) 30 | { 31 | _address.bytes[0] = first_octet; 32 | _address.bytes[1] = second_octet; 33 | _address.bytes[2] = third_octet; 34 | _address.bytes[3] = fourth_octet; 35 | } 36 | 37 | IPAddress::IPAddress(uint32_t address) 38 | { 39 | _address.dword = address; 40 | } 41 | 42 | IPAddress::IPAddress(const uint8_t *address) 43 | { 44 | memcpy(_address.bytes, address, sizeof(_address.bytes)); 45 | } 46 | 47 | IPAddress& IPAddress::operator=(const uint8_t *address) 48 | { 49 | memcpy(_address.bytes, address, sizeof(_address.bytes)); 50 | return *this; 51 | } 52 | 53 | IPAddress& IPAddress::operator=(uint32_t address) 54 | { 55 | _address.dword = address; 56 | return *this; 57 | } 58 | 59 | bool IPAddress::operator==(const uint8_t* addr) const 60 | { 61 | return memcmp(addr, _address.bytes, sizeof(_address.bytes)) == 0; 62 | } 63 | 64 | size_t IPAddress::printTo(Print& p) const 65 | { 66 | size_t n = 0; 67 | for(int i = 0; i < 3; i++) { 68 | n += p.print(_address.bytes[i], DEC); 69 | n += p.print('.'); 70 | } 71 | n += p.print(_address.bytes[3], DEC); 72 | return n; 73 | } 74 | 75 | String IPAddress::toString() const 76 | { 77 | char szRet[16]; 78 | sprintf(szRet,"%u.%u.%u.%u", _address.bytes[0], _address.bytes[1], _address.bytes[2], _address.bytes[3]); 79 | return String(szRet); 80 | } 81 | 82 | bool IPAddress::fromString(const char *address) 83 | { 84 | // TODO: add support for "a", "a.b", "a.b.c" formats 85 | 86 | uint16_t acc = 0; // Accumulator 87 | uint8_t dots = 0; 88 | 89 | while (*address) 90 | { 91 | char c = *address++; 92 | if (c >= '0' && c <= '9') 93 | { 94 | acc = acc * 10 + (c - '0'); 95 | if (acc > 255) { 96 | // Value out of [0..255] range 97 | return false; 98 | } 99 | } 100 | else if (c == '.') 101 | { 102 | if (dots == 3) { 103 | // Too much dots (there must be 3 dots) 104 | return false; 105 | } 106 | _address.bytes[dots++] = acc; 107 | acc = 0; 108 | } 109 | else 110 | { 111 | // Invalid char 112 | return false; 113 | } 114 | } 115 | 116 | if (dots != 3) { 117 | // Too few dots (there must be 3 dots) 118 | return false; 119 | } 120 | _address.bytes[3] = acc; 121 | return true; 122 | } 123 | 124 | // declared one time - as external in IPAddress.h 125 | IPAddress INADDR_NONE(0, 0, 0, 0); 126 | -------------------------------------------------------------------------------- /cores/arduino/IPAddress.h: -------------------------------------------------------------------------------- 1 | /* 2 | IPAddress.h - Base class that provides IPAddress 3 | Copyright (c) 2011 Adrian McEwen. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef IPAddress_h 21 | #define IPAddress_h 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | // A class to make it easier to handle and pass around IP addresses 28 | 29 | class IPAddress: public Printable 30 | { 31 | private: 32 | union { 33 | uint8_t bytes[4]; // IPv4 address 34 | uint32_t dword; 35 | } _address; 36 | 37 | // Access the raw byte array containing the address. Because this returns a pointer 38 | // to the internal structure rather than a copy of the address this function should only 39 | // be used when you know that the usage of the returned uint8_t* will be transient and not 40 | // stored. 41 | uint8_t* raw_address() 42 | { 43 | return _address.bytes; 44 | } 45 | 46 | public: 47 | // Constructors 48 | IPAddress(); 49 | IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet); 50 | IPAddress(uint32_t address); 51 | IPAddress(const uint8_t *address); 52 | virtual ~IPAddress() {} 53 | 54 | bool fromString(const char *address); 55 | bool fromString(const String &address) { return fromString(address.c_str()); } 56 | 57 | // Overloaded cast operator to allow IPAddress objects to be used where a pointer 58 | // to a four-byte uint8_t array is expected 59 | operator uint32_t() const 60 | { 61 | return _address.dword; 62 | } 63 | bool operator==(const IPAddress& addr) const 64 | { 65 | return _address.dword == addr._address.dword; 66 | } 67 | bool operator==(const uint8_t* addr) const; 68 | 69 | // Overloaded index operator to allow getting and setting individual octets of the address 70 | uint8_t operator[](int index) const 71 | { 72 | return _address.bytes[index]; 73 | } 74 | uint8_t& operator[](int index) 75 | { 76 | return _address.bytes[index]; 77 | } 78 | 79 | // Overloaded copy operators to allow initialisation of IPAddress objects from other types 80 | IPAddress& operator=(const uint8_t *address); 81 | IPAddress& operator=(uint32_t address); 82 | 83 | virtual size_t printTo(Print& p) const; 84 | String toString() const; 85 | 86 | friend class EthernetClass; 87 | friend class UDP; 88 | friend class Client; 89 | friend class Server; 90 | friend class DhcpClass; 91 | friend class DNSClient; 92 | }; 93 | 94 | // changed to extern because const declaration creates copies in BSS of INADDR_NONE for each CPP unit that includes it 95 | extern IPAddress INADDR_NONE; 96 | #endif 97 | -------------------------------------------------------------------------------- /cores/arduino/Print.h: -------------------------------------------------------------------------------- 1 | /* 2 | Print.h - Base class that provides print() and println() 3 | Copyright (c) 2008 David A. Mellis. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef Print_h 21 | #define Print_h 22 | 23 | #include 24 | #include // for size_t 25 | 26 | #include "WString.h" 27 | #include "Printable.h" 28 | 29 | #define DEC 10 30 | #define HEX 16 31 | #define OCT 8 32 | #ifdef BIN // Prevent warnings if BIN is previously defined in "iotnx4.h" or similar 33 | #undef BIN 34 | #endif 35 | #define BIN 2 36 | 37 | class Print 38 | { 39 | private: 40 | int write_error; 41 | size_t printNumber(unsigned long, uint8_t); 42 | size_t printFloat(double, uint8_t); 43 | protected: 44 | void setWriteError(int err = 1) 45 | { 46 | write_error = err; 47 | } 48 | public: 49 | Print() : write_error(0) {} 50 | 51 | int getWriteError() 52 | { 53 | return write_error; 54 | } 55 | void clearWriteError() 56 | { 57 | setWriteError(0); 58 | } 59 | 60 | virtual size_t write(uint8_t) = 0; 61 | size_t write(const char *str) 62 | { 63 | if (str == NULL) return 0; 64 | return write((const uint8_t *)str, strlen(str)); 65 | } 66 | virtual size_t write(const uint8_t *buffer, size_t size); 67 | size_t write(const char *buffer, size_t size) 68 | { 69 | return write((const uint8_t *)buffer, size); 70 | } 71 | 72 | // default to zero, meaning "a single write may block" 73 | // should be overridden by subclasses with buffering 74 | virtual int availableForWrite() 75 | { 76 | return 0; 77 | } 78 | 79 | size_t print(const __FlashStringHelper *); 80 | size_t print(const String &); 81 | size_t print(const char[]); 82 | size_t print(char); 83 | size_t print(unsigned char, int = DEC); 84 | size_t print(int, int = DEC); 85 | size_t print(unsigned int, int = DEC); 86 | size_t print(long, int = DEC); 87 | size_t print(unsigned long, int = DEC); 88 | size_t print(double, int = 2); 89 | size_t print(const Printable&); 90 | 91 | size_t println(const __FlashStringHelper *); 92 | size_t println(const String &s); 93 | size_t println(const char[]); 94 | size_t println(char); 95 | size_t println(unsigned char, int = DEC); 96 | size_t println(int, int = DEC); 97 | size_t println(unsigned int, int = DEC); 98 | size_t println(long, int = DEC); 99 | size_t println(unsigned long, int = DEC); 100 | size_t println(double, int = 2); 101 | size_t println(const Printable&); 102 | size_t println(void); 103 | #ifdef SUPPORTS_PRINTF 104 | int printf(const char * format, ...); 105 | #endif 106 | virtual void flush() { /* Empty implementation for backward compatibility */ } 107 | }; 108 | 109 | #endif 110 | -------------------------------------------------------------------------------- /cores/arduino/Printable.h: -------------------------------------------------------------------------------- 1 | /* 2 | Printable.h - Interface class that allows printing of complex types 3 | Copyright (c) 2011 Adrian McEwen. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef Printable_h 21 | #define Printable_h 22 | 23 | #include 24 | 25 | class Print; 26 | 27 | /** The Printable class provides a way for new classes to allow themselves to be printed. 28 | By deriving from Printable and implementing the printTo method, it will then be possible 29 | for users to print out instances of this class by passing them into the usual 30 | Print::print and Print::println methods. 31 | */ 32 | 33 | class Printable 34 | { 35 | public: 36 | virtual size_t printTo(Print& p) const = 0; 37 | }; 38 | 39 | #endif 40 | 41 | -------------------------------------------------------------------------------- /cores/arduino/SPI.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * Copyright (c) 2017 - 2022 _VIFEXTech 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | #ifndef __SPI_H 24 | #define __SPI_H 25 | 26 | #include "Arduino.h" 27 | 28 | #ifndef LSBFIRST 29 | # define LSBFIRST 0 30 | #endif 31 | #ifndef MSBFIRST 32 | # define MSBFIRST 1 33 | #endif 34 | 35 | #if SPI_CLASS_PIN_DEFINE_ENABLE 36 | # define SS PA4 37 | # define SCK PA5 38 | # define MISO PA6 39 | # define MOSI PA7 40 | #endif 41 | 42 | #define DATA_SIZE_8BIT SPI_FRAME_8BIT 43 | #define DATA_SIZE_16BIT SPI_FRAME_16BIT 44 | 45 | #define SPI_I2S_GET_FLAG(spix, SPI_I2S_FLAG) (spix->sts & SPI_I2S_FLAG) 46 | #define SPI_I2S_RXDATA(spix) (spix->dt) 47 | #define SPI_I2S_RXDATA_VOLATILE(spix) do{ volatile uint16_t vn = SPI_I2S_RXDATA(spix); vn = vn; } while(0) 48 | #define SPI_I2S_TXDATA(spix, data) (spix->dt = (data)) 49 | #define SPI_I2S_WAIT_RX(spix) do{ while (!SPI_I2S_GET_FLAG(spix, SPI_I2S_RDBF_FLAG)); } while(0) 50 | #define SPI_I2S_WAIT_TX(spix) do{ while (!SPI_I2S_GET_FLAG(spix, SPI_I2S_TDBE_FLAG)); } while(0) 51 | #define SPI_I2S_WAIT_BUSY(spix) do{ while (SPI_I2S_GET_FLAG(spix, SPI_I2S_BF_FLAG)); } while(0) 52 | 53 | typedef enum 54 | { 55 | SPI_MODE0, 56 | SPI_MODE1, 57 | SPI_MODE2, 58 | SPI_MODE3 59 | } SPI_MODE_TypeDef; 60 | 61 | typedef enum 62 | { 63 | SPI_STATE_IDLE, 64 | SPI_STATE_READY, 65 | SPI_STATE_RECEIVE, 66 | SPI_STATE_TRANSMIT, 67 | SPI_STATE_TRANSFER 68 | } spi_mode_t; 69 | 70 | class SPISettings 71 | { 72 | public: 73 | SPISettings(uint32_t clock, uint16_t bitOrder, uint8_t dataMode) 74 | { 75 | init_AlwaysInline(clock, bitOrder, dataMode, DATA_SIZE_8BIT); 76 | } 77 | SPISettings(uint32_t clock, uint16_t bitOrder, uint8_t dataMode, uint32_t dataSize) 78 | { 79 | init_AlwaysInline(clock, bitOrder, dataMode, dataSize); 80 | } 81 | SPISettings(uint32_t clock) 82 | { 83 | init_AlwaysInline(clock, MSBFIRST, SPI_MODE0, DATA_SIZE_8BIT); 84 | } 85 | SPISettings() 86 | { 87 | init_AlwaysInline(4000000, MSBFIRST, SPI_MODE0, DATA_SIZE_8BIT); 88 | } 89 | private: 90 | void init_MightInline(uint32_t clock, uint16_t bitOrder, uint8_t dataMode, uint32_t dataSize) 91 | { 92 | init_AlwaysInline(clock, bitOrder, dataMode, dataSize); 93 | } 94 | void init_AlwaysInline(uint32_t clock, uint16_t bitOrder, uint8_t dataMode, uint32_t dataSize) __attribute__((__always_inline__)) 95 | { 96 | this->clock = clock; 97 | this->bitOrder = bitOrder; 98 | this->dataMode = dataMode; 99 | this->dataSize = dataSize; 100 | } 101 | uint32_t clock; 102 | uint16_t bitOrder; 103 | uint8_t dataMode; 104 | uint32_t dataSize; 105 | 106 | friend class SPIClass; 107 | }; 108 | 109 | class SPIClass 110 | { 111 | public: 112 | SPIClass(spi_type* spix); 113 | void SPI_Settings( 114 | spi_master_slave_mode_type master_slave_mode, 115 | spi_frame_bit_num_type frame_bit_num, 116 | uint16_t SPI_MODEx, 117 | spi_cs_mode_type cs_mode, 118 | spi_mclk_freq_div_type mclk_freq_div, 119 | spi_first_bit_type first_bit 120 | ); 121 | void begin(void); 122 | void begin(uint32_t clock, uint16_t dataOrder, uint16_t dataMode); 123 | void begin(SPISettings settings); 124 | void beginSlave(uint32_t bitOrder, uint32_t mode); 125 | void beginSlave(void); 126 | void beginTransactionSlave(void); 127 | void beginTransaction(SPISettings settings); 128 | 129 | void endTransaction(void); 130 | void end(void); 131 | 132 | void setClock(uint32_t clock); 133 | void setClockDivider(uint32_t Div); 134 | void setBitOrder(uint16_t bitOrder); 135 | void setDataMode(uint8_t dataMode); 136 | void setDataSize(uint32_t datasize); 137 | 138 | uint16_t read(void); 139 | void read(uint8_t *buffer, uint32_t length); 140 | void write(uint16_t data); 141 | void write(uint16_t data, uint32_t n); 142 | void write(const uint8_t *data, uint32_t length); 143 | void write(const uint16_t *data, uint32_t length); 144 | uint8_t transfer(uint8_t data) const; 145 | uint16_t transfer16(uint16_t data) const; 146 | uint8_t send(uint8_t data); 147 | uint8_t send(uint8_t *data, uint32_t length); 148 | uint8_t recv(void); 149 | 150 | spi_type* getSPI() 151 | { 152 | return SPIx; 153 | } 154 | 155 | private: 156 | spi_type* SPIx; 157 | spi_init_type spi_init_struct; 158 | uint32_t SPI_Clock; 159 | }; 160 | 161 | #if SPI_CLASS_1_ENABLE 162 | extern SPIClass SPI; 163 | #endif 164 | 165 | #if SPI_CLASS_2_ENABLE 166 | extern SPIClass SPI_2; 167 | #endif 168 | 169 | #if SPI_CLASS_3_ENABLE 170 | extern SPIClass SPI_3; 171 | #endif 172 | 173 | #endif 174 | -------------------------------------------------------------------------------- /cores/arduino/Server.h: -------------------------------------------------------------------------------- 1 | /* 2 | Server.h - Base class that provides Server 3 | Copyright (c) 2011 Adrian McEwen. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef server_h 21 | #define server_h 22 | 23 | #include "Print.h" 24 | 25 | class Server: public Print 26 | { 27 | public: 28 | virtual void begin(uint16_t port=0) =0; 29 | }; 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /cores/arduino/SoftwareSerial.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SoftwareSerial.h (formerly NewSoftSerial.h) 3 | * 4 | * Multi-instance software serial library for Arduino/Wiring 5 | * -- Interrupt-driven receive and other improvements by ladyada 6 | * (http://ladyada.net) 7 | * -- Tuning, circular buffer, derivation from class Print/Stream, 8 | * multi-instance support, porting to 8MHz processors, 9 | * various optimizations, PROGMEM delay tables, inverse logic and 10 | * direct port writing by Mikal Hart (http://www.arduiniana.org) 11 | * -- Pin change interrupt macros by Paul Stoffregen (http://www.pjrc.com) 12 | * -- 20MHz processor support by Garrett Mace (http://www.macetech.com) 13 | * -- ATmega1280/2560 support by Brett Hagman (http://www.roguerobotics.com/) 14 | * 15 | * This library is free software; you can redistribute it and/or 16 | * modify it under the terms of the GNU Lesser General Public 17 | * License as published by the Free Software Foundation; either 18 | * version 2.1 of the License, or (at your option) any later version. 19 | * 20 | * This library is distributed in the hope that it will be useful, 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23 | * Lesser General Public License for more details. 24 | * 25 | * You should have received a copy of the GNU Lesser General Public 26 | * License along with this library; if not, write to the Free Software 27 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 28 | * 29 | * The latest version of this library can always be found at 30 | * http://arduiniana.org. 31 | */ 32 | 33 | #ifndef SOFTWARESERIAL_H 34 | #define SOFTWARESERIAL_H 35 | 36 | #include 37 | 38 | /****************************************************************************** 39 | * Definitions 40 | ******************************************************************************/ 41 | 42 | #define _SS_MAX_RX_BUFF 64 // RX buffer size 43 | 44 | class SoftwareSerial : public Stream { 45 | private: 46 | // per object data 47 | uint16_t _receivePin; 48 | uint16_t _transmitPin; 49 | GPIO_TypeDef *_receivePinPort; 50 | uint32_t _receivePinNumber; 51 | GPIO_TypeDef *_transmitPinPort; 52 | uint32_t _transmitPinNumber; 53 | uint32_t _speed; 54 | 55 | uint16_t _buffer_overflow: 1; 56 | uint16_t _inverse_logic: 1; 57 | uint16_t _half_duplex: 1; 58 | uint16_t _output_pending: 1; 59 | 60 | unsigned char _receive_buffer[_SS_MAX_RX_BUFF]; 61 | volatile uint8_t _receive_buffer_tail; 62 | volatile uint8_t _receive_buffer_head; 63 | 64 | uint32_t delta_start = 0; 65 | 66 | // static data 67 | static bool initialised; 68 | static SoftwareSerial *active_listener; 69 | static SoftwareSerial *volatile active_out; 70 | static SoftwareSerial *volatile active_in; 71 | static int32_t tx_tick_cnt; 72 | static volatile int32_t rx_tick_cnt; 73 | static uint32_t tx_buffer; 74 | static int32_t tx_bit_cnt; 75 | static uint32_t rx_buffer; 76 | static int32_t rx_bit_cnt; 77 | static uint32_t cur_speed; 78 | 79 | // private methods 80 | void send(); 81 | void recv(); 82 | void setTX(); 83 | void setRX(); 84 | void setSpeed(uint32_t speed); 85 | void setRXTX(bool input); 86 | static void handleInterrupt(); 87 | 88 | public: 89 | // public methods 90 | 91 | SoftwareSerial(uint16_t receivePin, uint16_t transmitPin, bool inverse_logic = false); 92 | virtual ~SoftwareSerial(); 93 | void begin(long speed); 94 | bool listen(); 95 | void end(); 96 | bool isListening() 97 | { 98 | return active_listener == this; 99 | } 100 | bool stopListening(); 101 | bool overflow() 102 | { 103 | bool ret = _buffer_overflow; 104 | if (ret) { 105 | _buffer_overflow = false; 106 | } 107 | return ret; 108 | } 109 | int peek(); 110 | 111 | virtual size_t write(uint8_t byte); 112 | virtual int read(); 113 | virtual int available(); 114 | virtual void flush(); 115 | operator bool() 116 | { 117 | return true; 118 | } 119 | 120 | static void setInterruptPriority(uint32_t preemptPriority, uint32_t subPriority); 121 | 122 | using Print::write; 123 | }; 124 | 125 | #endif // SOFTWARESERIAL_H 126 | -------------------------------------------------------------------------------- /cores/arduino/Tone.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * Copyright (c) 2017 - 2022 _VIFEXTech 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | #include "Tone.h" 24 | #include "Arduino.h" 25 | 26 | #define TONE_FREQ_MAX 500000U 27 | 28 | static tmr_type* Tone_Timer = NULL; 29 | static bool Tone_IsContinuousModeEnable = false; 30 | static uint8_t Tone_Pin = NOT_A_PIN; 31 | static uint32_t Tone_ToggleCounter = 0; 32 | 33 | /** 34 | * @brief tone中断入口,被定时中断调用 35 | * @param 无 36 | * @retval 无 37 | */ 38 | static void Tone_TimerHandler() 39 | { 40 | if(!Tone_IsContinuousModeEnable) 41 | { 42 | if(Tone_ToggleCounter == 0) 43 | { 44 | noTone(Tone_Pin); 45 | return; 46 | } 47 | 48 | Tone_ToggleCounter--; 49 | } 50 | 51 | togglePin(Tone_Pin); 52 | } 53 | 54 | /** 55 | * @brief 改变tone所使用的定时器 56 | * @param TIMx: 定时器地址 57 | * @retval 无 58 | */ 59 | void toneSetTimer(tmr_type* TIMx) 60 | { 61 | Timer_SetInterruptBase( 62 | TIMx, 63 | 0xFF, 64 | 0xFF, 65 | Tone_TimerHandler, 66 | TONE_PREEMPTIONPRIORITY_DEFAULT, 67 | TONE_SUBPRIORITY_DEFAULT 68 | ); 69 | Tone_Timer = TIMx; 70 | } 71 | 72 | /** 73 | * @brief 在Pin上生成指定频率 (50%占空比的方波) 74 | * @param pin: 产生音调的 Pin 75 | * @param freq: 频率(Hz) 76 | * @param duration: 音调的持续时间 (以毫秒为单位) 77 | * @retval 无 78 | */ 79 | void tone(uint8_t pin, uint32_t freq, uint32_t duration) 80 | { 81 | noTone(pin); 82 | 83 | if(duration == 0 || freq == 0 || freq > TONE_FREQ_MAX) 84 | { 85 | return; 86 | } 87 | 88 | Tone_Pin = pin; 89 | Tone_IsContinuousModeEnable = (duration == TONE_DURATION_INFINITE) ? true : false; 90 | 91 | if(!Tone_IsContinuousModeEnable) 92 | { 93 | Tone_ToggleCounter = freq * duration / 1000 * 2; 94 | 95 | if(Tone_ToggleCounter == 0) 96 | { 97 | return; 98 | } 99 | 100 | Tone_ToggleCounter--; 101 | } 102 | 103 | if(Tone_Timer == NULL) 104 | { 105 | toneSetTimer(TONE_TIMER_DEFAULT); 106 | } 107 | 108 | Timer_SetInterruptTimeUpdate(Tone_Timer, TONE_FREQ_MAX / freq); 109 | Timer_SetEnable(Tone_Timer, true); 110 | } 111 | 112 | /** 113 | * @brief 关闭声音 114 | * @param Pin: 产生音调的引脚编号 115 | * @retval 无 116 | */ 117 | void noTone(uint8_t pin) 118 | { 119 | if(Tone_Timer) 120 | { 121 | Timer_SetEnable(Tone_Timer, false); 122 | } 123 | 124 | digitalWrite(pin, LOW); 125 | Tone_IsContinuousModeEnable = false; 126 | Tone_Pin = NOT_A_PIN; 127 | Tone_ToggleCounter = 0; 128 | } 129 | -------------------------------------------------------------------------------- /cores/arduino/Tone.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * Copyright (c) 2017 - 2022 _VIFEXTech 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | #ifndef __TONE_H 24 | #define __TONE_H 25 | 26 | #include "libcore/timer.h" 27 | 28 | #define TONE_DURATION_INFINITE 0xFFFFFFFFU 29 | 30 | void toneSetTimer(tmr_type* TIMx); 31 | void tone(uint8_t pin, uint32_t freq, uint32_t duration = TONE_DURATION_INFINITE); 32 | void noTone(uint8_t pin); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /cores/arduino/Udp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Udp.cpp: Library to send/receive UDP packets. 3 | * 4 | * NOTE: UDP is fast, but has some important limitations (thanks to Warren Gray for mentioning these) 5 | * 1) UDP does not guarantee the order in which assembled UDP packets are received. This 6 | * might not happen often in practice, but in larger network topologies, a UDP 7 | * packet can be received out of sequence. 8 | * 2) UDP does not guard against lost packets - so packets *can* disappear without the sender being 9 | * aware of it. Again, this may not be a concern in practice on small local networks. 10 | * For more information, see http://www.cafeaulait.org/course/week12/35.html 11 | * 12 | * MIT License: 13 | * Copyright (c) 2008 Bjoern Hartmann 14 | * Permission is hereby granted, free of charge, to any person obtaining a copy 15 | * of this software and associated documentation files (the "Software"), to deal 16 | * in the Software without restriction, including without limitation the rights 17 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 18 | * copies of the Software, and to permit persons to whom the Software is 19 | * furnished to do so, subject to the following conditions: 20 | * 21 | * The above copyright notice and this permission notice shall be included in 22 | * all copies or substantial portions of the Software. 23 | * 24 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 27 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 28 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 29 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 30 | * THE SOFTWARE. 31 | * 32 | * bjoern@cs.stanford.edu 12/30/2008 33 | */ 34 | 35 | #ifndef udp_h 36 | #define udp_h 37 | 38 | #include 39 | #include 40 | 41 | class UDP: public Stream 42 | { 43 | 44 | public: 45 | virtual uint8_t begin(uint16_t) =0; // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use 46 | virtual uint8_t beginMulticast(IPAddress, uint16_t) { return 0; } // initialize, start listening on specified multicast IP address and port. Returns 1 if successful, 0 on failure 47 | virtual void stop() =0; // Finish with the UDP socket 48 | 49 | // Sending UDP packets 50 | 51 | // Start building up a packet to send to the remote host specific in ip and port 52 | // Returns 1 if successful, 0 if there was a problem with the supplied IP address or port 53 | virtual int beginPacket(IPAddress ip, uint16_t port) =0; 54 | // Start building up a packet to send to the remote host specific in host and port 55 | // Returns 1 if successful, 0 if there was a problem resolving the hostname or port 56 | virtual int beginPacket(const char *host, uint16_t port) =0; 57 | // Finish off this packet and send it 58 | // Returns 1 if the packet was sent successfully, 0 if there was an error 59 | virtual int endPacket() =0; 60 | // Write a single byte into the packet 61 | virtual size_t write(uint8_t) =0; 62 | // Write size bytes from buffer into the packet 63 | virtual size_t write(const uint8_t *buffer, size_t size) =0; 64 | 65 | // Start processing the next available incoming packet 66 | // Returns the size of the packet in bytes, or 0 if no packets are available 67 | virtual int parsePacket() =0; 68 | // Number of bytes remaining in the current packet 69 | virtual int available() =0; 70 | // Read a single byte from the current packet 71 | virtual int read() =0; 72 | // Read up to len bytes from the current packet and place them into buffer 73 | // Returns the number of bytes read, or 0 if none are available 74 | virtual int read(unsigned char* buffer, size_t len) =0; 75 | // Read up to len characters from the current packet and place them into buffer 76 | // Returns the number of characters read, or 0 if none are available 77 | virtual int read(char* buffer, size_t len) =0; 78 | // Return the next byte from the current packet without moving on to the next byte 79 | virtual int peek() =0; 80 | virtual void flush() =0; // Finish reading the current packet 81 | 82 | // Return the IP address of the host who sent the current incoming packet 83 | virtual IPAddress remoteIP() =0; 84 | // Return the port of the host who sent the current incoming packet 85 | virtual uint16_t remotePort() =0; 86 | protected: 87 | uint8_t* rawIPAddress(IPAddress& addr) 88 | { 89 | return addr.raw_address(); 90 | } 91 | }; 92 | 93 | #endif 94 | -------------------------------------------------------------------------------- /cores/arduino/WCharacter.h: -------------------------------------------------------------------------------- 1 | /* 2 | WCharacter.h - Character utility functions for Wiring & Arduino 3 | Copyright (c) 2010 Hernando Barragan. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef Character_h 21 | #define Character_h 22 | 23 | #include 24 | 25 | // #define isascii(c) ((unsigned int)c < 0x7F) 26 | // #define toascii(c) ((unsigned char)c) 27 | 28 | // WCharacter.h prototypes 29 | inline bool isAlphaNumeric(int c) __attribute__((always_inline)); 30 | inline bool isAlpha(int c) __attribute__((always_inline)); 31 | inline bool isAscii(int c) __attribute__((always_inline)); 32 | inline bool isWhitespace(int c) __attribute__((always_inline)); 33 | inline bool isControl(int c) __attribute__((always_inline)); 34 | inline bool isDigit(int c) __attribute__((always_inline)); 35 | inline bool isGraph(int c) __attribute__((always_inline)); 36 | inline bool isLowerCase(int c) __attribute__((always_inline)); 37 | inline bool isPrintable(int c) __attribute__((always_inline)); 38 | inline bool isPunct(int c) __attribute__((always_inline)); 39 | inline bool isSpace(int c) __attribute__((always_inline)); 40 | inline bool isUpperCase(int c) __attribute__((always_inline)); 41 | inline bool isHexadecimalDigit(int c) __attribute__((always_inline)); 42 | inline int toAscii(int c) __attribute__((always_inline)); 43 | inline int toLowerCase(int c) __attribute__((always_inline)); 44 | inline int toUpperCase(int c)__attribute__((always_inline)); 45 | 46 | 47 | // Checks for an alphanumeric character. 48 | // It is equivalent to (isalpha(c) || isdigit(c)). 49 | inline bool isAlphaNumeric(int c) 50 | { 51 | return ( isalnum(c) == 0 ? false : true); 52 | } 53 | 54 | 55 | // Checks for an alphabetic character. 56 | // It is equivalent to (isupper(c) || islower(c)). 57 | inline bool isAlpha(int c) 58 | { 59 | return ( isalpha(c) == 0 ? false : true); 60 | } 61 | 62 | 63 | // Checks whether c is a 7-bit unsigned char value 64 | // that fits into the ASCII character set. 65 | inline bool isAscii(int c) 66 | { 67 | return ( isascii (c) == 0 ? false : true); 68 | } 69 | 70 | 71 | // Checks for a blank character, that is, a space or a tab. 72 | inline bool isWhitespace(int c) 73 | { 74 | return ( isblank (c) == 0 ? false : true); 75 | } 76 | 77 | 78 | // Checks for a control character. 79 | inline bool isControl(int c) 80 | { 81 | return ( iscntrl (c) == 0 ? false : true); 82 | } 83 | 84 | 85 | // Checks for a digit (0 through 9). 86 | inline bool isDigit(int c) 87 | { 88 | return ( isdigit (c) == 0 ? false : true); 89 | } 90 | 91 | 92 | // Checks for any printable character except space. 93 | inline bool isGraph(int c) 94 | { 95 | return ( isgraph (c) == 0 ? false : true); 96 | } 97 | 98 | 99 | // Checks for a lower-case character. 100 | inline bool isLowerCase(int c) 101 | { 102 | return (islower (c) == 0 ? false : true); 103 | } 104 | 105 | 106 | // Checks for any printable character including space. 107 | inline bool isPrintable(int c) 108 | { 109 | return ( isprint (c) == 0 ? false : true); 110 | } 111 | 112 | 113 | // Checks for any printable character which is not a space 114 | // or an alphanumeric character. 115 | inline bool isPunct(int c) 116 | { 117 | return ( ispunct (c) == 0 ? false : true); 118 | } 119 | 120 | 121 | // Checks for white-space characters. For the avr-libc library, 122 | // these are: space, formfeed ('\f'), newline ('\n'), carriage 123 | // return ('\r'), horizontal tab ('\t'), and vertical tab ('\v'). 124 | inline bool isSpace(int c) 125 | { 126 | return ( isspace (c) == 0 ? false : true); 127 | } 128 | 129 | 130 | // Checks for an uppercase letter. 131 | inline bool isUpperCase(int c) 132 | { 133 | return ( isupper (c) == 0 ? false : true); 134 | } 135 | 136 | 137 | // Checks for a hexadecimal digits, i.e. one of 0 1 2 3 4 5 6 7 138 | // 8 9 a b c d e f A B C D E F. 139 | inline bool isHexadecimalDigit(int c) 140 | { 141 | return ( isxdigit (c) == 0 ? false : true); 142 | } 143 | 144 | 145 | // Converts c to a 7-bit unsigned char value that fits into the 146 | // ASCII character set, by clearing the high-order bits. 147 | inline int toAscii(int c) 148 | { 149 | return toascii (c); 150 | } 151 | 152 | 153 | // Warning: 154 | // Many people will be unhappy if you use this function. 155 | // This function will convert accented letters into random 156 | // characters. 157 | 158 | // Converts the letter c to lower case, if possible. 159 | inline int toLowerCase(int c) 160 | { 161 | return tolower (c); 162 | } 163 | 164 | 165 | // Converts the letter c to upper case, if possible. 166 | inline int toUpperCase(int c) 167 | { 168 | return toupper (c); 169 | } 170 | 171 | #endif 172 | -------------------------------------------------------------------------------- /cores/arduino/WMath.cpp: -------------------------------------------------------------------------------- 1 | /* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2 | 3 | /* 4 | Part of the Wiring project - http://wiring.org.co 5 | Copyright (c) 2004-06 Hernando Barragan 6 | Modified 13 August 2006, David A. Mellis for Arduino - http://www.arduino.cc/ 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 2.1 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General 19 | Public License along with this library; if not, write to the 20 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 21 | Boston, MA 02111-1307 USA 22 | */ 23 | #include "WMath.h" 24 | 25 | void randomSeed(unsigned long seed) 26 | { 27 | if (seed != 0) 28 | { 29 | srand(seed); 30 | } 31 | } 32 | 33 | long random(long howbig) 34 | { 35 | if (howbig == 0) 36 | { 37 | return 0; 38 | } 39 | return rand() % howbig; 40 | } 41 | 42 | long random(long howsmall, long howbig) 43 | { 44 | if (howsmall >= howbig) 45 | { 46 | return howsmall; 47 | } 48 | long diff = howbig - howsmall; 49 | return random(diff) + howsmall; 50 | } 51 | 52 | unsigned int makeWord(unsigned int w) 53 | { 54 | return w; 55 | } 56 | 57 | unsigned int makeWord(unsigned char h, unsigned char l) 58 | { 59 | return (h << 8) | l; 60 | } 61 | -------------------------------------------------------------------------------- /cores/arduino/WMath.h: -------------------------------------------------------------------------------- 1 | #ifndef __WMATH_H 2 | #define __WMATH_H 3 | 4 | extern "C" { 5 | #include "stdlib.h" 6 | } 7 | 8 | void randomSeed(unsigned long seed); 9 | long random(long howbig); 10 | long random(long howsmall, long howbig); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /cores/arduino/WProgram.h: -------------------------------------------------------------------------------- 1 | #ifndef __WPROGRAM_H 2 | #define __WPROGRAM_H 3 | 4 | #include "Arduino.h" 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /cores/arduino/Wire.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * The MIT License 3 | * 4 | * Copyright (c) 2010 LeafLabs LLC. 5 | * 6 | * Permission is hereby granted, free of charge, to any person 7 | * obtaining a copy of this software and associated documentation 8 | * files (the "Software"), to deal in the Software without 9 | * restriction, including without limitation the rights to use, copy, 10 | * modify, merge, publish, distribute, sublicense, and/or sell copies 11 | * of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 21 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 22 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | *****************************************************************************/ 26 | 27 | /** 28 | * @file Wire.h 29 | * @author Trystan Jones 30 | * @brief Wire library, uses the WireBase to create the primary interface 31 | * while keeping low level interactions invisible to the user. 32 | */ 33 | 34 | /* 35 | * Library updated by crenn to follow new Wire system. 36 | * Code was derived from the original Wire for maple code by leaflabs and the 37 | * modifications by gke and ala42. 38 | */ 39 | 40 | #ifndef _WIRE_H_ 41 | #define _WIRE_H_ 42 | 43 | #include "WireBase.h" 44 | 45 | /* 46 | * On the Maple, let the default pins be in the same location as the Arduino 47 | * pins 48 | */ 49 | 50 | class TwoWire : public WireBase 51 | { 52 | public: 53 | /* 54 | * Accept pin numbers for SCL and SDA lines. Set the delay needed 55 | * to create the timing for I2C's Standard Mode and Fast Mode. 56 | */ 57 | TwoWire(uint8_t scl, uint8_t sda, uint8_t delay); 58 | 59 | /* 60 | * If object is destroyed, set pin numbers to 0. 61 | */ 62 | virtual ~TwoWire(); 63 | 64 | /* 65 | * Sets pins SDA and SCL to OUPTUT_OPEN_DRAIN, joining I2C bus as 66 | * master. This function overwrites the default behaviour of 67 | * .begin(uint8_t) in WireBase 68 | */ 69 | bool begin(uint8_t self_addr = 0x00); 70 | public: 71 | uint8_t i2c_delay; 72 | uint8_t scl_pin; 73 | uint8_t sda_pin; 74 | 75 | /* 76 | * Sets the SCL line to HIGH/LOW and allow for clock stretching by slave 77 | * devices 78 | */ 79 | void set_scl(bool state); 80 | bool set_scl(bool state, uint32_t timeout); 81 | 82 | /* 83 | * Sets the SDA line to HIGH/LOW 84 | */ 85 | void set_sda(bool state); 86 | 87 | /* 88 | * Creates a Start condition on the bus 89 | */ 90 | void i2c_start(); 91 | 92 | /* 93 | * Creates a Stop condition on the bus 94 | */ 95 | void i2c_stop(); 96 | 97 | /* 98 | * Gets an ACK condition from a slave device on the bus 99 | */ 100 | bool i2c_get_ack(); 101 | 102 | /* 103 | * Creates a ACK condition on the bus 104 | */ 105 | void i2c_send_ack(); 106 | 107 | /* 108 | * Creates a NACK condition on the bus 109 | */ 110 | void i2c_send_nack(); 111 | 112 | /* 113 | * Shifts in the data through SDA and clocks SCL for the slave device 114 | */ 115 | uint8_t i2c_shift_in(); 116 | 117 | /* 118 | * Shifts out the data through SDA and clocks SCL for the slave device 119 | */ 120 | void i2c_shift_out(uint8_t val); 121 | protected: 122 | /* 123 | * Processes the incoming I2C message defined by WireBase 124 | */ 125 | 126 | virtual uint8_t process(); 127 | }; 128 | 129 | extern TwoWire Wire; 130 | 131 | #endif // _WIRE_H_ 132 | -------------------------------------------------------------------------------- /cores/arduino/WireBase.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * The MIT License 3 | * 4 | * Copyright (c) 2010 LeafLabs LLC. 5 | * 6 | * Permission is hereby granted, free of charge, to any person 7 | * obtaining a copy of this software and associated documentation 8 | * files (the "Software"), to deal in the Software without 9 | * restriction, including without limitation the rights to use, copy, 10 | * modify, merge, publish, distribute, sublicense, and/or sell copies 11 | * of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 21 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 22 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | *****************************************************************************/ 26 | 27 | /** 28 | * @file WireBase.cpp 29 | * @author Trystan Jones 30 | * @brief Wire library, following the majority of the interface from Arduino. 31 | * Provides a 'standard' interface to I2C (two-wire) communication for 32 | * derived classes. 33 | */ 34 | 35 | /* 36 | * Library created by crenn to allow a system which would provide users the 37 | * 'standardised' Arduino method for interfacing with I2C devices regardless of 38 | * whether it is I2C hardware or emulating software. 39 | */ 40 | 41 | #include "WireBase.h" 42 | 43 | void WireBase::begin(uint8_t self_addr) 44 | { 45 | tx_buf_idx = 0; 46 | tx_buf_overflow = false; 47 | rx_buf_idx = 0; 48 | rx_buf_len = 0; 49 | } 50 | 51 | void WireBase::setClock(uint32_t clock) 52 | { 53 | 54 | } 55 | 56 | void WireBase::beginTransmission(uint8_t slave_address) 57 | { 58 | itc_msg.addr = slave_address; 59 | itc_msg.data = &tx_buf[tx_buf_idx]; 60 | itc_msg.length = 0; 61 | itc_msg.flags = 0; 62 | } 63 | 64 | void WireBase::beginTransmission(int slave_address) 65 | { 66 | beginTransmission((uint8_t)slave_address); 67 | } 68 | 69 | uint8_t WireBase::endTransmission(void) 70 | { 71 | uint8_t retVal; 72 | if (tx_buf_overflow) 73 | { 74 | return EDATA; 75 | } 76 | retVal = process();// Changed so that the return value from process is returned by this function see also the return line below 77 | tx_buf_idx = 0; 78 | tx_buf_overflow = false; 79 | return retVal;//SUCCESS; 80 | } 81 | 82 | //TODO: Add the ability to queue messages (adding a boolean to end of function 83 | // call, allows for the Arduino style to stay while also giving the flexibility 84 | // to bulk send 85 | uint8_t WireBase::requestFrom(uint8_t address, int num_bytes) 86 | { 87 | if (num_bytes > WIRE_BUFF_SIZE) 88 | { 89 | num_bytes = WIRE_BUFF_SIZE; 90 | } 91 | itc_msg.addr = address; 92 | itc_msg.flags = I2C_MSG_READ; 93 | itc_msg.length = num_bytes; 94 | itc_msg.data = &rx_buf[rx_buf_idx]; 95 | process(); 96 | rx_buf_len += itc_msg.xferred; 97 | itc_msg.flags = 0; 98 | return rx_buf_len; 99 | } 100 | 101 | uint8_t WireBase::requestFrom(int address, int numBytes) 102 | { 103 | return WireBase::requestFrom((uint8_t)address, numBytes); 104 | } 105 | 106 | void WireBase::write(uint8_t value) 107 | { 108 | if (tx_buf_idx == WIRE_BUFF_SIZE) 109 | { 110 | tx_buf_overflow = true; 111 | return; 112 | } 113 | tx_buf[tx_buf_idx++] = value; 114 | itc_msg.length++; 115 | } 116 | 117 | void WireBase::write(uint8_t* buf, int len) 118 | { 119 | for (int i = 0; i < len; i++) 120 | { 121 | write(buf[i]); 122 | } 123 | } 124 | 125 | void WireBase::write(int value) 126 | { 127 | write((uint8_t)value); 128 | } 129 | 130 | void WireBase::write(int* buf, int len) 131 | { 132 | write((uint8_t*)buf, (uint8_t)len); 133 | } 134 | 135 | void WireBase::write(char* buf) 136 | { 137 | uint8_t *ptr = (uint8_t*)buf; 138 | while (*ptr) 139 | { 140 | write(*ptr); 141 | ptr++; 142 | } 143 | } 144 | 145 | uint8_t WireBase::available() 146 | { 147 | return rx_buf_len - rx_buf_idx; 148 | } 149 | 150 | uint8_t WireBase::read() 151 | { 152 | if (rx_buf_idx == rx_buf_len) 153 | { 154 | rx_buf_idx = 0; 155 | rx_buf_len = 0; 156 | return 0; 157 | } 158 | else if (rx_buf_idx == (rx_buf_len - 1)) 159 | { 160 | uint8_t temp = rx_buf[rx_buf_idx]; 161 | rx_buf_idx = 0; 162 | rx_buf_len = 0; 163 | return temp; 164 | } 165 | return rx_buf[rx_buf_idx++]; 166 | } 167 | -------------------------------------------------------------------------------- /cores/arduino/WireBase.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * The MIT License 3 | * 4 | * Copyright (c) 2010 LeafLabs LLC. 5 | * 6 | * Permission is hereby granted, free of charge, to any person 7 | * obtaining a copy of this software and associated documentation 8 | * files (the "Software"), to deal in the Software without 9 | * restriction, including without limitation the rights to use, copy, 10 | * modify, merge, publish, distribute, sublicense, and/or sell copies 11 | * of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 21 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 22 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | *****************************************************************************/ 26 | 27 | /** 28 | * @file WireBase.h 29 | * @author Trystan Jones 30 | * @brief Wire library, following the majority of the interface from Arduino. 31 | * Provides a 'standard' interface to I2C (two-wire) communication for 32 | * derived classes. 33 | */ 34 | 35 | /* 36 | * Library created by crenn to allow a system which would provide users the 37 | * 'standardised' Arduino method for interfacing with I2C devices regardless of 38 | * whether it is I2C hardware or emulating software. 39 | */ 40 | 41 | #ifndef _WIREBASE_H_ 42 | #define _WIREBASE_H_ 43 | 44 | 45 | #include "Arduino.h" 46 | 47 | #ifndef WIRE_BUFF_SIZE 48 | # define WIRE_BUFF_SIZE 32 49 | #endif 50 | 51 | /* return codes from endTransmission() */ 52 | #define SUCCESS 0 /* transmission was successful */ 53 | #define EDATA 1 /* too much data */ 54 | #define ENACKADDR 2 /* received nack on transmit of address */ 55 | #define ENACKTRNS 3 /* received nack on transmit of data */ 56 | #define EOTHER 4 /* other error */ 57 | 58 | struct i2c_msg; 59 | 60 | typedef struct i2c_msg 61 | { 62 | uint16_t addr; /**< Address */ 63 | 64 | #define I2C_MSG_READ 0x1 65 | #define I2C_MSG_10BIT_ADDR 0x2 66 | /** 67 | * Bitwise OR of: 68 | * - I2C_MSG_READ (write is default) 69 | * - I2C_MSG_10BIT_ADDR (7-bit is default) */ 70 | uint16_t flags; 71 | 72 | uint16_t length; /**< Message length */ 73 | uint16_t xferred; /**< Messages transferred */ 74 | uint8_t *data; /**< Data */ 75 | } i2c_msg; 76 | 77 | class WireBase // Abstraction is awesome! 78 | { 79 | protected: 80 | i2c_msg itc_msg; 81 | uint8_t rx_buf[WIRE_BUFF_SIZE]; /* receive buffer */ 82 | uint8_t rx_buf_idx; /* first unread idx in rx_buf */ 83 | uint8_t rx_buf_len; /* number of bytes read */ 84 | 85 | uint8_t tx_buf[WIRE_BUFF_SIZE]; /* transmit buffer */ 86 | uint8_t tx_buf_idx; // next idx available in tx_buf, -1 overflow 87 | boolean tx_buf_overflow; 88 | 89 | // Force derived classes to define process function 90 | virtual uint8_t process() = 0; 91 | public: 92 | WireBase() {} 93 | virtual ~WireBase() {} 94 | 95 | /* 96 | * Initialises the class interface 97 | */ 98 | // Allow derived classes to overwrite begin function 99 | void begin(uint8_t = 0x00); 100 | 101 | void setClock(uint32_t); 102 | 103 | /* 104 | * Sets up the transmission message to be processed 105 | */ 106 | void beginTransmission(uint8_t); 107 | 108 | /* 109 | * Allow only 8 bit addresses to be used 110 | */ 111 | void beginTransmission(int); 112 | 113 | /* 114 | * Call the process function to process the message if the TX 115 | * buffer has not overflowed. 116 | */ 117 | uint8_t endTransmission(void); 118 | 119 | inline uint8_t endTransmission(uint8_t) 120 | { 121 | return endTransmission(); 122 | } 123 | 124 | /* 125 | * Request bytes from a slave device and process the request, 126 | * storing into the receiving buffer. 127 | */ 128 | uint8_t requestFrom(uint8_t, int); 129 | 130 | /* 131 | * Allow only 8 bit addresses to be used when requesting bytes 132 | */ 133 | uint8_t requestFrom(int, int); 134 | 135 | /* 136 | * Stack up bytes to be sent when transmitting 137 | */ 138 | void write(uint8_t); 139 | 140 | /* 141 | * Stack up bytes from the array to be sent when transmitting 142 | */ 143 | void write(uint8_t*, int); 144 | 145 | /* 146 | * Ensure that a sending data will only be 8-bit bytes 147 | */ 148 | void write(int); 149 | 150 | /* 151 | * Ensure that an array sending data will only be 8-bit bytes 152 | */ 153 | void write(int*, int); 154 | 155 | /* 156 | * Stack up bytes from a string to be sent when transmitting 157 | */ 158 | void write(char*); 159 | 160 | /* 161 | * Return the amount of bytes that is currently in the receiving buffer 162 | */ 163 | uint8_t available(); 164 | 165 | /* 166 | * Return the value of byte in the receiving buffer that is currently being 167 | * pointed to 168 | */ 169 | uint8_t read(); 170 | }; 171 | 172 | #endif // _WIREBASE_H_ 173 | -------------------------------------------------------------------------------- /cores/arduino/avr/interrupt.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WeActStudio/ArduinoCore-AT32F4/e4686b837df3ae8b905f2466c456c21d2ea05f95/cores/arduino/avr/interrupt.h -------------------------------------------------------------------------------- /cores/arduino/avr/pgmspace.h: -------------------------------------------------------------------------------- 1 | #ifndef __PGMSPACE_H_ 2 | #define __PGMSPACE_H_ 1 3 | 4 | #include 5 | 6 | #define PROGMEM 7 | #define PGM_P const char * 8 | #define PSTR(str) (str) 9 | 10 | #define _SFR_BYTE(n) (n) 11 | 12 | typedef void prog_void; 13 | typedef char prog_char; 14 | typedef unsigned char prog_uchar; 15 | typedef int8_t prog_int8_t; 16 | typedef uint8_t prog_uint8_t; 17 | typedef int16_t prog_int16_t; 18 | typedef uint16_t prog_uint16_t; 19 | typedef int32_t prog_int32_t; 20 | typedef uint32_t prog_uint32_t; 21 | 22 | #define memcpy_P(dest, src, num) memcpy((dest), (src), (num)) 23 | #define strcpy_P(dest, src) strcpy((dest), (src)) 24 | #define strcat_P(dest, src) strcat((dest), (src)) 25 | #define strcmp_P(a, b) strcmp((a), (b)) 26 | #define strstr_P(a, b) strstr((a), (b)) 27 | #define strlen_P(a) strlen((a)) 28 | #define sprintf_P(s, f, ...) sprintf((s), (f), __VA_ARGS__) 29 | 30 | #define pgm_read_byte(addr) (*(const unsigned char *)(addr)) 31 | #define pgm_read_word(addr) (*(const unsigned short *)(addr)) 32 | #define pgm_read_dword(addr) (*(const unsigned long *)(addr)) 33 | #define pgm_read_float(addr) (*(const float *)(addr)) 34 | 35 | #define pgm_read_byte_near(addr) pgm_read_byte(addr) 36 | #define pgm_read_word_near(addr) pgm_read_word(addr) 37 | #define pgm_read_dword_near(addr) pgm_read_dword(addr) 38 | #define pgm_read_float_near(addr) pgm_read_float(addr) 39 | #define pgm_read_byte_far(addr) pgm_read_byte(addr) 40 | #define pgm_read_word_far(addr) pgm_read_word(addr) 41 | #define pgm_read_dword_far(addr) pgm_read_dword(addr) 42 | #define pgm_read_float_far(addr) pgm_read_float(addr) 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /cores/arduino/dtostrf.c: -------------------------------------------------------------------------------- 1 | /* 2 | dtostrf - Emulation for dtostrf function from avr-libc 3 | Copyright (c) 2013 Arduino. All rights reserved. 4 | Written by Cristian Maglie 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "dtostrf.h" 22 | 23 | char *dtostrf(double val, signed char width, unsigned char prec, char *sout) 24 | { 25 | char fmt[20]; 26 | snprintf(fmt, sizeof(fmt), "%%%d.%df", width, prec); 27 | sprintf(sout, fmt, val); 28 | return sout; 29 | } 30 | 31 | char *dtostrnf(double val, signed char width, unsigned char prec, char *sout, size_t sout_size) 32 | { 33 | char fmt[20]; 34 | snprintf(fmt, sizeof(fmt), "%%%d.%df", width, prec); 35 | snprintf(sout, sout_size, fmt, val); 36 | return sout; 37 | } 38 | -------------------------------------------------------------------------------- /cores/arduino/dtostrf.h: -------------------------------------------------------------------------------- 1 | /* 2 | dtostrf - Emulation for dtostrf function from avr-libc 3 | Copyright (c) 2013 Arduino. All rights reserved. 4 | Written by Cristian Maglie 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef __DTOSTRF_H 22 | #define __DTOSTRF_H 23 | 24 | #include "stdio.h" 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | char *dtostrf(double val, signed char width, unsigned char prec, char *sout); 31 | char *dtostrnf(double val, signed char width, unsigned char prec, char *sout, size_t sout_size); 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /cores/arduino/itoa.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Arduino. All right reserved. 3 | This library is free software; you can redistribute it and/or 4 | modify it under the terms of the GNU Lesser General Public 5 | License as published by the Free Software Foundation; either 6 | version 2.1 of the License, or (at your option) any later version. 7 | This library is distributed in the hope that it will be useful, 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 10 | See the GNU Lesser General Public License for more details. 11 | You should have received a copy of the GNU Lesser General Public 12 | License along with this library; if not, write to the Free Software 13 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 14 | */ 15 | 16 | #include "itoa.h" 17 | #include 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif // __cplusplus 22 | 23 | #if 0 24 | /* reverse: reverse string s in place */ 25 | static void reverse(char s[]) 26 | { 27 | int i, j ; 28 | char c ; 29 | 30 | for (i = 0, j = strlen(s) - 1 ; i < j ; i++, j--) { 31 | c = s[i] ; 32 | s[i] = s[j] ; 33 | s[j] = c ; 34 | } 35 | } 36 | 37 | /* itoa: convert n to characters in s */ 38 | extern void itoa(int n, char s[]) 39 | { 40 | int i, sign ; 41 | 42 | if ((sign = n) < 0) { /* record sign */ 43 | n = -n; /* make n positive */ 44 | } 45 | 46 | i = 0; 47 | do { 48 | /* generate digits in reverse order */ 49 | s[i++] = n % 10 + '0'; /* get next digit */ 50 | } while ((n /= 10) > 0) ; /* delete it */ 51 | 52 | if (sign < 0) { 53 | s[i++] = '-'; 54 | } 55 | 56 | s[i] = '\0'; 57 | 58 | reverse(s) ; 59 | } 60 | 61 | #else 62 | 63 | extern char *itoa(int value, char *string, int radix) 64 | { 65 | return ltoa(value, string, radix) ; 66 | } 67 | 68 | extern char *ltoa(long value, char *string, int radix) 69 | { 70 | char tmp[33]; 71 | char *tp = tmp; 72 | long i; 73 | unsigned long v; 74 | int sign; 75 | char *sp; 76 | 77 | if (string == NULL) { 78 | return 0 ; 79 | } 80 | 81 | if (radix > 36 || radix <= 1) { 82 | return 0 ; 83 | } 84 | 85 | sign = (radix == 10 && value < 0); 86 | if (sign) { 87 | v = -value; 88 | } else { 89 | v = (unsigned long)value; 90 | } 91 | 92 | while (v || tp == tmp) { 93 | i = v % radix; 94 | v = v / radix; 95 | if (i < 10) { 96 | *tp++ = i + '0'; 97 | } else { 98 | *tp++ = i + 'a' - 10; 99 | } 100 | } 101 | 102 | sp = string; 103 | 104 | if (sign) { 105 | *sp++ = '-'; 106 | } 107 | while (tp > tmp) { 108 | *sp++ = *--tp; 109 | } 110 | *sp = 0; 111 | 112 | return string; 113 | } 114 | #if __GNUC__ > 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ > 9 || \ 115 | (__GNUC_MINOR__ == 9 && __GNUC_PATCHLEVEL__ > 2))) 116 | extern char *utoa(unsigned value, char *string, int radix) 117 | #else 118 | extern char *utoa(unsigned long value, char *string, int radix) 119 | #endif 120 | { 121 | return ultoa(value, string, radix) ; 122 | } 123 | 124 | extern char *ultoa(unsigned long value, char *string, int radix) 125 | { 126 | char tmp[33]; 127 | char *tp = tmp; 128 | long i; 129 | unsigned long v = value; 130 | char *sp; 131 | 132 | if (string == NULL) { 133 | return 0; 134 | } 135 | 136 | if (radix > 36 || radix <= 1) { 137 | return 0; 138 | } 139 | 140 | while (v || tp == tmp) { 141 | i = v % radix; 142 | v = v / radix; 143 | if (i < 10) { 144 | *tp++ = i + '0'; 145 | } else { 146 | *tp++ = i + 'a' - 10; 147 | } 148 | } 149 | 150 | sp = string; 151 | 152 | 153 | while (tp > tmp) { 154 | *sp++ = *--tp; 155 | } 156 | *sp = 0; 157 | 158 | return string; 159 | } 160 | #endif /* 0 */ 161 | 162 | #ifdef __cplusplus 163 | } // extern "C" 164 | #endif // __cplusplus -------------------------------------------------------------------------------- /cores/arduino/itoa.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Arduino. All right reserved. 3 | This library is free software; you can redistribute it and/or 4 | modify it under the terms of the GNU Lesser General Public 5 | License as published by the Free Software Foundation; either 6 | version 2.1 of the License, or (at your option) any later version. 7 | This library is distributed in the hope that it will be useful, 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 10 | See the GNU Lesser General Public License for more details. 11 | You should have received a copy of the GNU Lesser General Public 12 | License along with this library; if not, write to the Free Software 13 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 14 | */ 15 | 16 | #ifndef _ITOA_ 17 | #define _ITOA_ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif // __cplusplus 22 | 23 | #if 0 24 | 25 | extern void itoa(int n, char s[]) ; 26 | 27 | #else 28 | 29 | extern char *itoa(int value, char *string, int radix) ; 30 | extern char *ltoa(long value, char *string, int radix) ; 31 | #if __GNUC__ > 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ > 9 || \ 32 | (__GNUC_MINOR__ == 9 && __GNUC_PATCHLEVEL__ > 2))) 33 | extern char *utoa(unsigned value, char *string, int radix) ; 34 | #else 35 | extern char *utoa(unsigned long value, char *string, int radix) ; 36 | #endif 37 | extern char *ultoa(unsigned long value, char *string, int radix) ; 38 | #endif /* 0 */ 39 | 40 | #ifdef __cplusplus 41 | } // extern "C" 42 | #endif // __cplusplus 43 | 44 | #endif // _ITOA_ -------------------------------------------------------------------------------- /cores/arduino/libcore/adc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * Copyright (c) 2017 - 2022 _VIFEXTech 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | #ifndef __ADC_H 24 | #define __ADC_H 25 | 26 | #include "mcu_type.h" 27 | 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif 31 | 32 | typedef enum 33 | { 34 | ADC_DMA_RES_OK = 0, 35 | ADC_DMA_RES_NOT_ADC_CHANNEL = -1, 36 | ADC_DMA_RES_DUPLICATE_REGISTRATION = -2, 37 | ADC_DMA_RES_MAX_NUM_OF_REGISTRATIONS_EXCEEDED = -3, 38 | } ADC_DMA_Res_Type; 39 | 40 | void ADCx_Init(adc_type* ADCx); 41 | uint16_t ADCx_GetValue(adc_type* ADCx, uint16_t ADC_Channel); 42 | void ADC_DMA_Init(void); 43 | ADC_DMA_Res_Type ADC_DMA_Register(uint8_t ADC_Channel); 44 | uint16_t ADC_DMA_GetValue(uint8_t ADC_Channel); 45 | uint8_t ADC_DMA_GetRegisterCount(void); 46 | 47 | #ifdef __cplusplus 48 | } 49 | #endif 50 | 51 | #endif /* __ADC_H */ 52 | -------------------------------------------------------------------------------- /cores/arduino/libcore/at32f403a_407_clock.c: -------------------------------------------------------------------------------- 1 | /** 2 | ************************************************************************** 3 | * @file at32f403a_407_clock.c 4 | * @version v2.0.9 5 | * @date 2022-04-25 6 | * @brief system clock config program 7 | ************************************************************************** 8 | * Copyright notice & Disclaimer 9 | * 10 | * The software Board Support Package (BSP) that is made available to 11 | * download from Artery official website is the copyrighted work of Artery. 12 | * Artery authorizes customers to use, copy, and distribute the BSP 13 | * software and its related documentation for the purpose of design and 14 | * development in conjunction with Artery microcontrollers. Use of the 15 | * software is governed by this copyright notice and the following disclaimer. 16 | * 17 | * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, 18 | * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, 19 | * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR 20 | * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, 21 | * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. 23 | * 24 | ************************************************************************** 25 | */ 26 | 27 | /* includes ------------------------------------------------------------------*/ 28 | #include "at32f403a_407_clock.h" 29 | 30 | /** 31 | * @brief system clock config program 32 | * @note the system clock is configured as follow: 33 | * - system clock = hext / 2 * pll_mult 34 | * - system clock source = pll (hext) 35 | * - hext = 8000000 36 | * - sclk = 240000000 37 | * - ahbdiv = 1 38 | * - ahbclk = 240000000 39 | * - apb2div = 2 40 | * - apb2clk = 120000000 41 | * - apb1div = 2 42 | * - apb1clk = 120000000 43 | * - pll_mult = 60 44 | * - pll_range = GT72MHZ (greater than 72 mhz) 45 | * @param none 46 | * @retval none 47 | */ 48 | void system_clock_config(void) 49 | { 50 | /* reset crm */ 51 | crm_reset(); 52 | 53 | #if F_PLL_CLOCK_SOURCE != 0 54 | crm_clock_source_enable(CRM_CLOCK_SOURCE_HEXT, TRUE); 55 | 56 | /* wait till hext is ready */ 57 | while(crm_hext_stable_wait() == ERROR) 58 | { 59 | } 60 | #endif 61 | 62 | /* config pll clock resource */ 63 | crm_pll_config(F_PLL_CLOCK_SOURCE, F_PLL_MULT, F_PLL_OUTPUT_RANGE); 64 | 65 | #if F_PLL_CLOCK_SOURCE == 2 66 | /* config hext division */ 67 | crm_hext_clock_div_set(F_HEXT_DIV); 68 | #elif F_PLL_CLOCK_SOURCE == 1 69 | crm_hick_divider_select(F_HSI_DIV); 70 | #endif 71 | 72 | /* enable pll */ 73 | crm_clock_source_enable(CRM_CLOCK_SOURCE_PLL, TRUE); 74 | 75 | /* wait till pll is ready */ 76 | while(crm_flag_get(CRM_PLL_STABLE_FLAG) != SET) 77 | { 78 | } 79 | 80 | /* config ahbclk */ 81 | crm_ahb_div_set(CRM_AHB_DIV_1); 82 | 83 | /* config apb2clk */ 84 | crm_apb2_div_set(CRM_APB2_DIV_2); 85 | 86 | /* config apb1clk */ 87 | crm_apb1_div_set(CRM_APB1_DIV_2); 88 | 89 | /* enable auto step mode */ 90 | crm_auto_step_mode_enable(TRUE); 91 | 92 | /* select pll as system clock source */ 93 | crm_sysclk_switch(CRM_SCLK_PLL); 94 | 95 | /* wait till pll is used as system clock source */ 96 | while(crm_sysclk_switch_status_get() != CRM_SCLK_PLL) 97 | { 98 | } 99 | 100 | /* disable auto step mode */ 101 | crm_auto_step_mode_enable(FALSE); 102 | 103 | /* update system_core_clock global variable */ 104 | system_core_clock_update(); 105 | } 106 | -------------------------------------------------------------------------------- /cores/arduino/libcore/at32f403a_407_clock.h: -------------------------------------------------------------------------------- 1 | /** 2 | ************************************************************************** 3 | * @file at32f403a_407_clock.h 4 | * @version v2.0.9 5 | * @date 2022-04-25 6 | * @brief header file of clock program 7 | ************************************************************************** 8 | * Copyright notice & Disclaimer 9 | * 10 | * The software Board Support Package (BSP) that is made available to 11 | * download from Artery official website is the copyrighted work of Artery. 12 | * Artery authorizes customers to use, copy, and distribute the BSP 13 | * software and its related documentation for the purpose of design and 14 | * development in conjunction with Artery microcontrollers. Use of the 15 | * software is governed by this copyright notice and the following disclaimer. 16 | * 17 | * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, 18 | * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, 19 | * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR 20 | * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, 21 | * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. 23 | * 24 | ************************************************************************** 25 | */ 26 | 27 | /* define to prevent recursive inclusion -------------------------------------*/ 28 | #ifndef __AT32F403A_407_CLOCK_H 29 | #define __AT32F403A_407_CLOCK_H 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | /* includes ------------------------------------------------------------------*/ 36 | #include "at32f403a_407.h" 37 | 38 | /* exported functions ------------------------------------------------------- */ 39 | void system_clock_config(void); 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | #endif /* __AT32F403A_407_CLOCK_H */ 46 | 47 | -------------------------------------------------------------------------------- /cores/arduino/libcore/config/mcu_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * Copyright (c) 2017 - 2022 _VIFEXTech 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | #ifndef __MCU_CONFIG_H 24 | #define __MCU_CONFIG_H 25 | 26 | /*========================= 27 | MCU configuration 28 | *=========================*/ 29 | /* System tick */ 30 | #define SYSTICK_TICK_FREQ 1000 // Hz 31 | #define SYSTICK_PRIORITY 0 32 | 33 | /* Hardware Serial */ 34 | #define SERIAL_RX_BUFFER_SIZE 128 35 | #define SERIAL_PREEMPTIONPRIORITY_DEFAULT 1 36 | #define SERIAL_SUBPRIORITY_DEFAULT 3 37 | #define SERIAL_CONFIG_DEFAULT SERIAL_8N1 38 | 39 | #define SERIAL_1_ENABLE 1 40 | #if SERIAL_1_ENABLE 41 | # define SERIAL_1_USART USART1 42 | # define SERIAL_1_IRQ_HANDLER_DEF() void USART1_IRQHandler(void) 43 | #endif 44 | 45 | #define SERIAL_2_ENABLE 1 46 | #if SERIAL_2_ENABLE 47 | # define SERIAL_2_USART USART2 48 | # define SERIAL_2_IRQ_HANDLER_DEF() void USART2_IRQHandler(void) 49 | #endif 50 | 51 | #define SERIAL_3_ENABLE 1 52 | #if SERIAL_3_ENABLE 53 | # define SERIAL_3_USART USART3 54 | # define SERIAL_3_IRQ_HANDLER_DEF() void USART3_IRQHandler(void) 55 | #endif 56 | 57 | #define SERIAL_4_ENABLE 1 58 | #if SERIAL_4_ENABLE 59 | # define SERIAL_4_UART UART4 60 | # define SERIAL_4_IRQ_HANDLER_DEF() void UART4_IRQHandler(void) 61 | #endif 62 | 63 | #define SERIAL_5_ENABLE 1 64 | #if SERIAL_5_ENABLE 65 | # define SERIAL_5_UART UART5 66 | # define SERIAL_5_IRQ_HANDLER_DEF() void UART5_IRQHandler(void) 67 | #endif 68 | 69 | #define SERIAL_6_ENABLE 1 70 | #if SERIAL_6_ENABLE 71 | # define SERIAL_6_USART USART6 72 | # define SERIAL_6_IRQ_HANDLER_DEF() void USART6_IRQHandler(void) 73 | #endif 74 | 75 | #define SERIAL_7_ENABLE 1 76 | #if SERIAL_7_ENABLE 77 | # define SERIAL_7_UART UART7 78 | # define SERIAL_7_IRQ_HANDLER_DEF() void UART7_IRQHandler(void) 79 | #endif 80 | 81 | #define SERIAL_8_ENABLE 1 82 | #if SERIAL_8_ENABLE 83 | # define SERIAL_8_UART UART8 84 | # define SERIAL_8_IRQ_HANDLER_DEF() void UART8_IRQHandler(void) 85 | #endif 86 | 87 | /* Wire (Software I2C) */ 88 | #define WIRE_USE_FULL_SPEED_I2C 0 89 | #define WIRE_SDA_PIN PB7 90 | #define WIRE_SCL_PIN PB6 91 | #define WIRE_DELAY 0 92 | #define WIRE_BEGIN_TIMEOUT 100 // ms 93 | #define WIRE_BUFF_SIZE 32 94 | 95 | /* SPI Class */ 96 | #define SPI_CLASS_AVR_COMPATIBILITY_MODE 1 97 | #define SPI_CLASS_PIN_DEFINE_ENABLE 1 98 | 99 | #define SPI_CLASS_1_ENABLE 1 100 | #if SPI_CLASS_1_ENABLE 101 | # define SPI_CLASS_1_SPI SPI1 102 | #endif 103 | 104 | #define SPI_CLASS_2_ENABLE 1 105 | #if SPI_CLASS_2_ENABLE 106 | # define SPI_CLASS_2_SPI SPI2 107 | #endif 108 | 109 | #define SPI_CLASS_3_ENABLE 1 110 | #if SPI_CLASS_3_ENABLE 111 | # define SPI_CLASS_3_SPI SPI3 112 | #endif 113 | 114 | /* WString */ 115 | #define WSTRING_MEM_INCLUDE 116 | #define WSTRING_MEM_REALLOC realloc 117 | #define WSTRING_MEM_FREE free 118 | 119 | /* Print */ 120 | #define PRINT_PRINTF_BUFFER_LENGTH 128 121 | 122 | /* GPIO */ 123 | #define GPIO_DRIVE_DEFAULT GPIO_DRIVE_STRENGTH_STRONGER 124 | 125 | /* External Interrupt */ 126 | #define EXTI_PREEMPTIONPRIORITY_DEFAULT 2 127 | #define EXTI_SUBPRIORITY_DEFAULT 1 128 | 129 | /* Timer Interrupt */ 130 | #define TIMER_PREEMPTIONPRIORITY_DEFAULT 0 131 | #define TIMER_SUBPRIORITY_DEFAULT 3 132 | 133 | /* Tone */ 134 | #define TONE_TIMER_DEFAULT TIM1 135 | #define TONE_PREEMPTIONPRIORITY_DEFAULT 0 136 | #define TONE_SUBPRIORITY_DEFAULT 1 137 | 138 | /* PWM */ 139 | #define PWM_RESOLUTION_DEFAULT 1000 140 | #define PWM_FREQUENCY_DEFAULT 10000 141 | 142 | #endif 143 | -------------------------------------------------------------------------------- /cores/arduino/libcore/delay.c: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * Copyright (c) 2017 - 2022 _VIFEXTech 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | #include "delay.h" 24 | 25 | #ifndef SYSTICK_TICK_FREQ 26 | # define SYSTICK_TICK_FREQ 1000 // Hz 27 | #endif 28 | 29 | #define SYSTICK_TICK_INTERVAL (1000 / SYSTICK_TICK_FREQ) 30 | #define SYSTICK_LOAD_VALUE (system_core_clock / SYSTICK_TICK_FREQ) 31 | #define SYSTICK_MILLIS (SystemTickCount * SYSTICK_TICK_INTERVAL) 32 | 33 | static volatile uint32_t SystemTickCount = 0; 34 | 35 | /** 36 | * @brief 系统滴答定时器初始化,定时1ms 37 | * @param 无 38 | * @retval 无 39 | */ 40 | void Delay_Init(void) 41 | { 42 | system_core_clock_update(); 43 | SysTick_Config(SYSTICK_LOAD_VALUE); 44 | NVIC_SetPriority(SysTick_IRQn, SYSTICK_PRIORITY); 45 | } 46 | 47 | /** 48 | * @brief 系统滴答定时器中断入口 49 | * @param 无 50 | * @retval 无 51 | */ 52 | void SysTick_Handler(void) 53 | { 54 | SystemTickCount++; 55 | } 56 | 57 | /** 58 | * @brief 获取单片机自上电以来经过的毫秒数 59 | * @param 无 60 | * @retval 当前系统时钟毫秒数 61 | */ 62 | uint32_t millis(void) 63 | { 64 | return SYSTICK_MILLIS; 65 | } 66 | 67 | /** 68 | * @brief 获取单片机自上电以来经过的微秒数 69 | * @param 无 70 | * @retval 当前系统时钟微秒数 71 | */ 72 | uint32_t micros(void) 73 | { 74 | return (SYSTICK_MILLIS * 1000 + (SYSTICK_LOAD_VALUE - SysTick->VAL) / CYCLES_PER_MICROSECOND); 75 | } 76 | 77 | /** 78 | * @brief 毫秒级延时 79 | * @param ms: 要延时的毫秒数 80 | * @retval 无 81 | */ 82 | void delay_ms(uint32_t ms) 83 | { 84 | uint32_t tickstart = SystemTickCount; 85 | uint32_t wait = ms / SYSTICK_TICK_INTERVAL; 86 | 87 | while((SystemTickCount - tickstart) < wait) 88 | { 89 | } 90 | } 91 | 92 | /** 93 | * @brief 微秒级延时 94 | * @param us: 要延时的微秒数 95 | * @retval 无 96 | */ 97 | void delay_us(uint32_t us) 98 | { 99 | uint32_t total = 0; 100 | uint32_t target = CYCLES_PER_MICROSECOND * us; 101 | int last = SysTick->VAL; 102 | int now = last; 103 | int diff = 0; 104 | start: 105 | now = SysTick->VAL; 106 | diff = last - now; 107 | if(diff > 0) 108 | { 109 | total += diff; 110 | } 111 | else 112 | { 113 | total += diff + SYSTICK_LOAD_VALUE; 114 | } 115 | if(total > target) 116 | { 117 | return; 118 | } 119 | last = now; 120 | goto start; 121 | } 122 | -------------------------------------------------------------------------------- /cores/arduino/libcore/delay.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * Copyright (c) 2017 - 2022 _VIFEXTech 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | #ifndef __DELAY_H 24 | #define __DELAY_H 25 | 26 | #include "mcu_type.h" 27 | 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif 31 | 32 | void Delay_Init(void); 33 | uint32_t millis(void); 34 | uint32_t micros(void); 35 | void delay_ms(uint32_t ms); 36 | void delay_us(uint32_t us); 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | 42 | #endif /* __DELAY_H */ 43 | -------------------------------------------------------------------------------- /cores/arduino/libcore/extend_SRAM.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * File : SRAM/extend_SRAM/EXTEND_SRAM/extend_SRAM.c 4 | * Version: V1.2.7 5 | * Date : 2020-11-10 6 | * Brief : This file contains the function extend_SRAM_test used to extend SRAM size 7 | ****************************************************************************** 8 | */ 9 | 10 | /* Includes ------------------------------------------------------------------*/ 11 | #include "extend_SRAM.h" 12 | #include "at32f403a_407.h" 13 | 14 | #define EXTEND_SRAM_224K 15 | 16 | /* Copy to Startup file */ 17 | #if 0 18 | ; Reset handler 19 | Reset_Handler PROC 20 | EXPORT Reset_Handler [WEAK] 21 | IMPORT __main 22 | IMPORT SystemInit 23 | IMPORT extend_SRAM 24 | 25 | MOV32 R0, #0x20001000 26 | MOV SP, R0 27 | LDR R0, =extend_SRAM 28 | BLX R0 29 | MOV32 R0, #0x08000000 30 | LDR SP, [R0] 31 | 32 | LDR R0, =SystemInit 33 | BLX R0 34 | LDR R0, =__main 35 | BX R0 36 | ENDP 37 | #endif 38 | 39 | /** @addtogroup AT32F403A_StdPeriph_Examples 40 | * @{ 41 | */ 42 | 43 | /** @addtogroup SRAM_Extended_SRAM 44 | * @{ 45 | */ 46 | 47 | /* Private typedef -----------------------------------------------------------*/ 48 | 49 | #define TEST_RAM_SIZE 0x800 50 | 51 | /* Private variables ---------------------------------------------------------*/ 52 | 53 | 54 | 55 | /* Private functions ---------------------------------------------------------*/ 56 | /** 57 | * @brief To extend SRAM size 58 | * @param None 59 | * @retval None 60 | */ 61 | void extend_sram(void) 62 | { 63 | /* Target set_SRAM_96K is selected */ 64 | #ifdef EXTEND_SRAM_96K 65 | /* check if RAM has been set to 96K, if not, change EOPB0 */ 66 | if(((UOPTB->EOPB0)&0xFF)!=0xFF) 67 | { 68 | /* Unlock Option Bytes Program Erase controller */ 69 | FLASH_Unlock(); 70 | /* Erase Option Bytes */ 71 | FLASH_EraseUserOptionBytes(); 72 | /* Change SRAM size to 96KB */ 73 | FLASH_ProgramUserOptionByteData((uint32_t)&UOPTB->EOPB0,0xFF); 74 | NVIC_SystemReset(); 75 | } 76 | #endif 77 | 78 | /* Target set_SRAM_224K is selected */ 79 | #ifdef EXTEND_SRAM_224K 80 | /* check if ram has been set to expectant size, if not, change eopb0 */ 81 | if(((USD->eopb0) & 0xFF) != 0xFE) 82 | { 83 | flash_unlock(); 84 | /* erase user system data bytes */ 85 | flash_user_system_data_erase(); 86 | 87 | /* change sram size */ 88 | flash_user_system_data_program((uint32_t)&USD->eopb0, 0xFE); 89 | 90 | /* system reset */ 91 | nvic_system_reset(); 92 | } 93 | #endif 94 | } 95 | 96 | /** 97 | * @} 98 | */ 99 | 100 | /** 101 | * @} 102 | */ 103 | 104 | -------------------------------------------------------------------------------- /cores/arduino/libcore/extend_SRAM.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * File : SRAM/extend_SRAM/EXTEND_SRAM/extend_SRAM.h 4 | * Version: V1.2.7 5 | * Date : 2020-11-10 6 | * Brief : This file contains all the macros used in extend_SRAM.c 7 | ****************************************************************************** 8 | */ 9 | 10 | /* Define to prevent recursive inclusion -------------------------------------*/ 11 | #ifndef __EXTEND_SRAM_H 12 | #define __EXTEND_SRAM_H 13 | 14 | /* Exported functions ------------------------------------------------------- */ 15 | void extend_sram(void); 16 | 17 | #endif /* __EXTEND_SRAM_H */ 18 | 19 | -------------------------------------------------------------------------------- /cores/arduino/libcore/exti.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * Copyright (c) 2017 - 2022 _VIFEXTech 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | #ifndef __EXTI_H 24 | #define __EXTI_H 25 | 26 | #include "mcu_type.h" 27 | 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif 31 | 32 | #define CHANGE EXINT_TRIGGER_BOTH_EDGE 33 | #define FALLING EXINT_TRIGGER_FALLING_EDGE 34 | #define RISING EXINT_TRIGGER_RISING_EDGE 35 | 36 | typedef void(*EXTI_CallbackFunction_t)(void); 37 | 38 | void EXTIx_Init( 39 | uint8_t Pin, 40 | EXTI_CallbackFunction_t Function, 41 | exint_polarity_config_type line_polarity, 42 | uint8_t PreemptionPriority, 43 | uint8_t SubPriority 44 | ); 45 | void attachInterrupt( 46 | uint8_t Pin, 47 | EXTI_CallbackFunction_t Function, 48 | exint_polarity_config_type polarity_config 49 | ); 50 | void detachInterrupt(uint8_t Pin); 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /cores/arduino/libcore/gpio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * Copyright (c) 2017 - 2022 _VIFEXTech 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | #ifndef __GPIO_H 24 | #define __GPIO_H 25 | 26 | #include "mcu_type.h" 27 | 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif 31 | 32 | #ifndef NULL 33 | # define NULL ((void*)0) 34 | #endif 35 | 36 | #define ADC_CHANNEL_X ((uint8_t)0xFF) 37 | 38 | #define IS_PIN(Pin) (Pin < PIN_MAX) 39 | #define IS_ADC_PIN(Pin) (IS_PIN(Pin) && PIN_MAP[Pin].ADCx != NULL && PIN_MAP[Pin].ADC_Channel != ADC_CHANNEL_X) 40 | #define IS_PWM_PIN(Pin) (IS_PIN(Pin) && PIN_MAP[Pin].TIMx != NULL && PIN_MAP[Pin].TimerChannel != 0) 41 | 42 | #define GPIO_HIGH(GPIOX,GPIO_PIN_X) ((GPIOX)->scr = (GPIO_PIN_X)) 43 | #define GPIO_LOW(GPIOX,GPIO_PIN_X) ((GPIOX)->clr = (GPIO_PIN_X)) 44 | #define GPIO_READ(GPIOX,GPIO_PIN_X) (((GPIOX)->idt & (GPIO_PIN_X))!=0) 45 | #define GPIO_TOGGLE(GPIOX,GPIO_PIN_X) ((GPIOX)->odt ^= (GPIO_PIN_X)) 46 | 47 | #define portInputRegister(Port) (&(Port->idt)) 48 | #define portOutputRegister(Port) (&(Port->odt)) 49 | 50 | #define analogInPinToBit(Pin) (Pin) 51 | #define digitalPinToInterrupt(Pin) (Pin) 52 | #define digitalPinToPort(Pin) (PIN_MAP[Pin].GPIOx) 53 | #define digitalPinToBitMask(Pin) (PIN_MAP[Pin].GPIO_Pin_x) 54 | 55 | #define digitalWrite_HIGH(Pin) GPIO_HIGH (PIN_MAP[Pin].GPIOx, PIN_MAP[Pin].GPIO_Pin_x) 56 | #define digitalWrite_LOW(Pin) GPIO_LOW (PIN_MAP[Pin].GPIOx, PIN_MAP[Pin].GPIO_Pin_x) 57 | #define digitalRead_FAST(Pin) GPIO_READ (PIN_MAP[Pin].GPIOx, PIN_MAP[Pin].GPIO_Pin_x) 58 | #define togglePin(Pin) GPIO_TOGGLE(PIN_MAP[Pin].GPIOx, PIN_MAP[Pin].GPIO_Pin_x) 59 | 60 | #define LED_BUILTIN PC13 61 | 62 | typedef enum 63 | { 64 | PA0, PA1, PA2, PA3, PA4, PA5, PA6, PA7, PA8, PA9, PA10, PA11, PA12, PA13, PA14, PA15, 65 | PB0, PB1, PB2, PB3, PB4, PB5, PB6, PB7, PB8, PB9, PB10, PB11, PB12, PB13, PB14, PB15, 66 | PC0, PC1, PC2, PC3, PC4, PC5, PC6, PC7, PC8, PC9, PC10, PC11, PC12, PC13, PC14, PC15, 67 | PD0, PD1, PD2, PD3, PD4, PD5, PD6, PD7, PD8, PD9, PD10, PD11, PD12, PD13, PD14, PD15, 68 | #ifdef GPIOE 69 | PE0, PE1, PE2, PE3, PE4, PE5, PE6, PE7, PE8, PE9, PE10, PE11, PE12, PE13, PE14, PE15, 70 | #endif 71 | #ifdef GPIOF 72 | PF0, PF1, PF2, PF3, PF4, PF5, PF6, PF7, PF8, PF9, PF10, PF11, PF12, PF13, PF14, PF15, 73 | #endif 74 | #ifdef GPIOG 75 | PG0, PG1, PG2, PG3, PG4, PG5, PG6, PG7, PG8, PG9, PG10, PG11, PG12, PG13, PG14, PG15, 76 | #endif 77 | PIN_MAX 78 | } Pin_TypeDef; 79 | 80 | typedef struct 81 | { 82 | gpio_type* GPIOx; 83 | tmr_type* TIMx; 84 | adc_type* ADCx; 85 | uint16_t GPIO_Pin_x; 86 | uint8_t TimerChannel; 87 | uint8_t ADC_Channel; 88 | } PinInfo_TypeDef; 89 | 90 | typedef enum 91 | { 92 | INPUT, 93 | INPUT_PULLUP, 94 | INPUT_PULLDOWN, 95 | INPUT_ANALOG, 96 | INPUT_ANALOG_DMA, 97 | OUTPUT, 98 | OUTPUT_OPEN_DRAIN, 99 | OUTPUT_AF_OD, 100 | OUTPUT_AF_PP, 101 | PWM 102 | } PinMode_TypeDef; 103 | 104 | extern const PinInfo_TypeDef PIN_MAP[PIN_MAX]; 105 | 106 | void GPIOx_Init( 107 | gpio_type* GPIOx, 108 | uint16_t GPIO_Pin_x, 109 | PinMode_TypeDef Mode, 110 | gpio_drive_type GPIO_Drive_x 111 | ); 112 | void GPIO_JTAG_Disable(void); 113 | uint8_t GPIO_GetPortNum(uint8_t Pin); 114 | uint8_t GPIO_GetPinNum(uint8_t Pin); 115 | uint8_t GPIO_GetPinSource(uint16_t GPIO_Pin_x); 116 | 117 | #ifdef __cplusplus 118 | }// extern "C" 119 | #endif 120 | 121 | #endif 122 | -------------------------------------------------------------------------------- /cores/arduino/libcore/i2c.c: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * Copyright (c) 2019 _VIFEXTech 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | #include "Arduino.h" 24 | #include "i2c.h" 25 | 26 | void I2Cx_Init(i2c_type *I2Cx, uint32_t baudRate) 27 | { 28 | if(I2Cx == I2C1) 29 | { 30 | crm_periph_clock_enable(CRM_I2C1_PERIPH_CLOCK, TRUE); 31 | pinMode(PB6, OUTPUT_AF_OD); 32 | pinMode(PB7, OUTPUT_AF_OD); 33 | } 34 | #ifdef CRM_I2C2_PERIPH_CLOCK 35 | else if(I2Cx == I2C2) 36 | { 37 | crm_periph_clock_enable(CRM_I2C2_PERIPH_CLOCK, TRUE); 38 | pinMode(PB10, OUTPUT_AF_OD); 39 | pinMode(PB11, OUTPUT_AF_OD); 40 | } 41 | #endif 42 | #ifdef CRM_I2C3_PERIPH_CLOCK 43 | else if(I2Cx == I2C3) 44 | { 45 | crm_periph_clock_enable(CRM_I2C3_PERIPH_CLOCK, TRUE); 46 | pinMode(PA8, OUTPUT_AF_OD); 47 | pinMode(PC9, OUTPUT_AF_OD); 48 | } 49 | #endif 50 | else 51 | { 52 | return; 53 | } 54 | /* reset i2c peripheral */ 55 | i2c_reset(I2Cx); 56 | /* i2c peripheral initialization */ 57 | i2c_init(I2Cx, I2C_FSMODE_DUTY_2_1, baudRate); 58 | 59 | i2c_own_address1_set(I2Cx, I2C_ADDRESS_MODE_7BIT, 0); 60 | i2c_ack_enable(I2Cx, TRUE); 61 | i2c_master_receive_ack_set(I2Cx, I2C_MASTER_ACK_CURRENT); 62 | /* i2c peripheral enable */ 63 | i2c_enable(I2Cx, TRUE); 64 | } 65 | 66 | void I2Cx_ClearADDRFlag(i2c_type* I2Cx) 67 | { 68 | __attribute__((unused)) __IO uint32_t tmpreg; 69 | 70 | tmpreg = I2Cx->sts1; 71 | 72 | tmpreg = I2Cx->sts2; 73 | } 74 | 75 | void I2Cx_Read(i2c_type *I2Cx, uint8_t slaveAddr, uint8_t regAddr, void *buf, uint32_t length) 76 | { 77 | uint8_t *dat = (uint8_t *)buf; 78 | 79 | /* enable ack */ 80 | i2c_ack_enable(I2Cx, TRUE); 81 | 82 | /* generate start condtion */ 83 | i2c_start_generate(I2Cx); 84 | 85 | while(!i2c_flag_get(I2Cx, I2C_STARTF_FLAG)); 86 | while(I2Cx->ctrl1 & I2C_CTRL1_STARTGEN); 87 | i2c_7bit_address_send(I2Cx, (slaveAddr << 1), I2C_DIRECTION_TRANSMIT); 88 | while(!i2c_flag_get(I2Cx, I2C_ADDR7F_FLAG)); 89 | I2Cx_ClearADDRFlag(I2Cx); 90 | 91 | i2c_data_send(I2Cx, regAddr); 92 | while(!i2c_flag_get(I2Cx, I2C_TDC_FLAG)); 93 | i2c_flag_clear(I2Cx, I2C_TDC_FLAG); 94 | 95 | i2c_start_generate(I2Cx); 96 | while(!i2c_flag_get(I2Cx, I2C_STARTF_FLAG)); 97 | 98 | i2c_7bit_address_send(I2Cx, (slaveAddr << 1), I2C_DIRECTION_RECEIVE); 99 | while(!i2c_flag_get(I2Cx, I2C_ADDR7F_FLAG)); 100 | I2Cx_ClearADDRFlag(I2Cx); 101 | 102 | while(length --) 103 | { 104 | if(!length) 105 | { 106 | i2c_ack_enable(I2Cx, FALSE); 107 | i2c_stop_generate(I2Cx); 108 | } 109 | while(!i2c_flag_get(I2Cx, I2C_RDBF_FLAG)); 110 | *dat++ = i2c_data_receive(I2Cx); 111 | } 112 | while(I2Cx->ctrl1 & I2C_CTRL1_STOPGEN); 113 | } 114 | 115 | void I2Cx_Write(i2c_type *I2Cx, uint8_t slaveAddr, uint8_t regAddr, void *buf, uint32_t length) 116 | { 117 | uint8_t *dat = (uint8_t *)buf; 118 | 119 | i2c_start_generate(I2Cx); 120 | while(!i2c_flag_get(I2Cx, I2C_STARTF_FLAG)); 121 | 122 | i2c_7bit_address_send(I2Cx, (slaveAddr << 1), I2C_DIRECTION_TRANSMIT); 123 | while(!i2c_flag_get(I2Cx, I2C_ADDR7F_FLAG)); 124 | I2Cx_ClearADDRFlag(I2Cx); 125 | 126 | i2c_data_send(I2Cx, regAddr); 127 | while(!i2c_flag_get(I2Cx, I2C_TDC_FLAG)); 128 | i2c_flag_clear(I2Cx, I2C_TDC_FLAG); 129 | 130 | while(length --) 131 | { 132 | i2c_data_send(I2Cx, *dat++); 133 | while(!i2c_flag_get(I2Cx, I2C_TDC_FLAG)); 134 | i2c_flag_clear(I2Cx, I2C_TDC_FLAG); 135 | } 136 | 137 | i2c_stop_generate(I2Cx); 138 | 139 | while(I2Cx->ctrl1 & I2C_CTRL1_STOPGEN); 140 | // while(!I2C_GetFlagStatus(I2Cx, I2C_FLAG_TDE)); 141 | // while(!I2C_GetFlagStatus(I2Cx, I2C_FLAG_BTFF)); 142 | } 143 | 144 | uint8_t I2Cx_ReadReg(i2c_type *I2Cx, uint8_t slaveAddr, uint8_t regAddr) 145 | { 146 | uint8_t retval = 0; 147 | I2Cx_Read(I2Cx, slaveAddr, regAddr, &retval, sizeof(uint8_t)); 148 | return retval; 149 | } 150 | 151 | void I2Cx_WriteReg(i2c_type *I2Cx, uint8_t slaveAddr, uint8_t regAddr, uint8_t value) 152 | { 153 | I2Cx_Write(I2Cx, slaveAddr, regAddr, &value, sizeof(uint8_t)); 154 | } 155 | 156 | 157 | 158 | 159 | -------------------------------------------------------------------------------- /cores/arduino/libcore/i2c.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * Copyright (c) 2019 _VIFEXTech 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | #ifndef __HARDWAREI2C_H 24 | #define __HARDWAREI2C_H 25 | 26 | #include 27 | #include "mcu_type.h" 28 | /* I2C START mask */ 29 | #define I2C_CTRL1_STARTGEN ((uint16_t)0x0100) 30 | /* I2C STOP mask */ 31 | #define I2C_CTRL1_STOPGEN ((uint16_t)0x0200) 32 | void I2Cx_Init(i2c_type *I2Cx, uint32_t baudRate); 33 | void I2Cx_Read(i2c_type *I2Cx, uint8_t slaveAddr, uint8_t regAddr, void *buf, uint32_t length); 34 | void I2Cx_Write(i2c_type *I2Cx, uint8_t slaveAddr, uint8_t regAddr, void *buf, uint32_t length); 35 | uint8_t I2Cx_ReadReg(i2c_type *I2Cx, uint8_t slaveAddr, uint8_t regAddr); 36 | void I2Cx_WriteReg(i2c_type *I2Cx, uint8_t slaveAddr, uint8_t regAddr, uint8_t value); 37 | 38 | #endif 39 | 40 | -------------------------------------------------------------------------------- /cores/arduino/libcore/mcu_core.c: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * Copyright (c) 2017 - 2022 _VIFEXTech 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #include "mcu_core.h" 25 | 26 | void Core_Init(void) 27 | { 28 | system_clock_config(); 29 | nvic_priority_group_config(NVIC_PRIORITY_GROUP_2); 30 | GPIO_JTAG_Disable(); 31 | Delay_Init(); 32 | ADCx_Init(ADC1); 33 | } 34 | -------------------------------------------------------------------------------- /cores/arduino/libcore/mcu_core.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * Copyright (c) 2017 - 2022 _VIFEXTech 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | #ifndef __MCU_CORE_H 24 | #define __MCU_CORE_H 25 | 26 | #include "at32f403a_407_clock.h" 27 | 28 | #define sei() __set_PRIMASK(0) 29 | #define cli() __set_PRIMASK(1) 30 | 31 | #include "adc.h" 32 | #include "delay.h" 33 | #include "exti.h" 34 | #include "gpio.h" 35 | #include "pwm.h" 36 | #include "timer.h" 37 | #include "wdg.h" 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | void Core_Init(void); 44 | 45 | #ifdef __cplusplus 46 | } 47 | #endif 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /cores/arduino/libcore/mcu_type.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * Copyright (c) 2017 - 2022 _VIFEXTech 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | #ifndef __MCU_TYPE_H 24 | #define __MCU_TYPE_H 25 | 26 | #include "at32f403a_407.h" 27 | #include "at32f403a_407_conf.h" 28 | #include "config/mcu_config.h" 29 | 30 | #define __AT32__ 31 | #define __AT32F4__ 32 | // #define F_CPU system_core_clock 33 | // #define F_CPU 80000000L 34 | #define CYCLES_PER_MICROSECOND (F_CPU / 1000000U) 35 | 36 | typedef gpio_type GPIO_TypeDef; 37 | typedef spi_type SPI_TypeDef; 38 | typedef tmr_type TIM_TypeDef; 39 | 40 | #define GPIO_Pin_0 GPIO_PINS_0 41 | #define GPIO_Pin_1 GPIO_PINS_1 42 | #define GPIO_Pin_2 GPIO_PINS_2 43 | #define GPIO_Pin_3 GPIO_PINS_3 44 | #define GPIO_Pin_4 GPIO_PINS_4 45 | #define GPIO_Pin_5 GPIO_PINS_5 46 | #define GPIO_Pin_6 GPIO_PINS_6 47 | #define GPIO_Pin_7 GPIO_PINS_7 48 | #define GPIO_Pin_8 GPIO_PINS_8 49 | #define GPIO_Pin_9 GPIO_PINS_9 50 | #define GPIO_Pin_10 GPIO_PINS_10 51 | #define GPIO_Pin_11 GPIO_PINS_11 52 | #define GPIO_Pin_12 GPIO_PINS_12 53 | #define GPIO_Pin_13 GPIO_PINS_13 54 | #define GPIO_Pin_14 GPIO_PINS_14 55 | #define GPIO_Pin_15 GPIO_PINS_15 56 | #define GPIO_Pin_All GPIO_PINS_All 57 | 58 | #define TIM1 TMR1 59 | #define TIM2 TMR2 60 | #define TIM3 TMR3 61 | #define TIM4 TMR4 62 | #define TIM5 TMR5 63 | #define TIM6 TMR6 64 | #define TIM7 TMR7 65 | #define TIM8 TMR8 66 | #define TIM9 TMR9 67 | #define TIM10 TMR10 68 | #define TIM11 TMR11 69 | #define TIM12 TMR12 70 | #define TIM13 TMR13 71 | #define TIM14 TMR14 72 | #define TIM15 TMR15 73 | 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /cores/arduino/libcore/pwm.c: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * Copyright (c) 2017 - 2022 _VIFEXTech 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | #include "pwm.h" 24 | #include "timer.h" 25 | #include "Arduino.h" 26 | 27 | /** 28 | * @brief 定时器输出捕获初始化 29 | * @param TIMx: 定时器地址 30 | * @param arr: 自动重装值 31 | * @param psc: 时钟预分频数 32 | * @param TimerChannel: 定时器通道 33 | * @retval 无 34 | */ 35 | static void TIMx_OCxInit(tmr_type* TIMx, uint32_t arr, uint16_t psc, uint8_t TimerChannel) 36 | { 37 | tmr_output_config_type tmr_output_struct; 38 | 39 | Timer_ClockCmd(TIMx, true); 40 | 41 | tmr_base_init(TIMx, arr, psc); 42 | tmr_cnt_dir_set(TIMx, TMR_COUNT_UP); 43 | 44 | tmr_output_default_para_init(&tmr_output_struct); 45 | tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_PWM_MODE_B; 46 | tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_LOW; 47 | tmr_output_struct.oc_idle_state = TRUE; 48 | tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH; 49 | tmr_output_struct.occ_idle_state = FALSE; 50 | tmr_output_struct.oc_output_state = TRUE; 51 | tmr_output_struct.occ_output_state = TRUE; 52 | 53 | switch(TimerChannel) 54 | { 55 | case 1: 56 | tmr_output_channel_config(TIMx, TMR_SELECT_CHANNEL_1, &tmr_output_struct); 57 | break; 58 | case 2: 59 | tmr_output_channel_config(TIMx, TMR_SELECT_CHANNEL_2, &tmr_output_struct); 60 | break; 61 | case 3: 62 | tmr_output_channel_config(TIMx, TMR_SELECT_CHANNEL_3, &tmr_output_struct); 63 | break; 64 | case 4: 65 | tmr_output_channel_config(TIMx, TMR_SELECT_CHANNEL_4, &tmr_output_struct); 66 | break; 67 | default: 68 | return; 69 | } 70 | 71 | tmr_output_enable(TIMx, TRUE); 72 | tmr_counter_enable(TIMx, TRUE); 73 | } 74 | 75 | /** 76 | * @brief PWM输出初始化 77 | * @param Pin:引脚编号 78 | * @param Resolution: PWM分辨率 79 | * @param Frequency: PWM频率 80 | * @retval 引脚对应的定时器通道 81 | */ 82 | uint8_t PWM_Init(uint8_t Pin, uint32_t Resolution, uint32_t Frequency) 83 | { 84 | uint32_t arr, psc; 85 | 86 | if(!IS_PWM_PIN(Pin)) 87 | { 88 | return 0; 89 | } 90 | 91 | if(Resolution == 0 || Frequency == 0 || (Resolution * Frequency) > F_CPU) 92 | { 93 | return 0; 94 | } 95 | 96 | pinMode(Pin, OUTPUT_AF_PP); 97 | 98 | arr = Resolution; 99 | psc = Timer_GetClockMax(PIN_MAP[Pin].TIMx) / Resolution / Frequency; 100 | 101 | Timer_SetEnable(PIN_MAP[Pin].TIMx, false); 102 | TIMx_OCxInit(PIN_MAP[Pin].TIMx, arr - 1, psc - 1, PIN_MAP[Pin].TimerChannel); 103 | return PIN_MAP[Pin].TimerChannel; 104 | } 105 | 106 | /** 107 | * @brief 输出PWM信号 108 | * @param Pin: 引脚编号 109 | * @param Value: PWM输出值 110 | * @retval PWM占空比值 111 | */ 112 | void PWM_Write(uint8_t Pin, uint32_t Value) 113 | { 114 | Timer_SetCompare(PIN_MAP[Pin].TIMx, PIN_MAP[Pin].TimerChannel, Value); 115 | } 116 | -------------------------------------------------------------------------------- /cores/arduino/libcore/pwm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * Copyright (c) 2017 - 2022 _VIFEXTech 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | #ifndef __PWM_H 24 | #define __PWM_H 25 | 26 | #include "mcu_type.h" 27 | 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif 31 | 32 | #define pwmWrite(pin, value) PWM_Write(pin, value) 33 | 34 | uint8_t PWM_Init(uint8_t Pin, uint32_t Resolution, uint32_t Frequency); 35 | void PWM_Write(uint8_t Pin, uint32_t Value); 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /cores/arduino/libcore/rtc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * Copyright (c) 2017 - 2022 _VIFEXTech 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | #ifndef __RTC_H 24 | #define __RTC_H 25 | 26 | #include "mcu_type.h" 27 | 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif 31 | 32 | typedef struct 33 | { 34 | uint8_t hour; 35 | uint8_t min; 36 | uint8_t sec; 37 | uint16_t year; 38 | uint8_t month; 39 | uint8_t day; 40 | uint8_t week; 41 | } RTC_Calendar_TypeDef; 42 | 43 | void RTC_Init(void); 44 | void RTC_GetCalendar(RTC_Calendar_TypeDef* calendar); 45 | uint8_t RTC_SetAlarm(uint16_t syear, uint8_t smon, uint8_t sday, uint8_t hour, uint8_t min, uint8_t sec); 46 | uint8_t RTC_GetWeek(uint16_t year, uint8_t month, uint8_t day); 47 | uint8_t RTC_SetTime(uint16_t syear, uint8_t smon, uint8_t sday, uint8_t hour, uint8_t min, uint8_t sec); 48 | 49 | #ifdef __cplusplus 50 | } 51 | #endif 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /cores/arduino/libcore/syscalls.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file syscalls_at32.c 3 | * 4 | * Implementation of newlib syscall. 5 | * 6 | */ 7 | #include "at32f403a_407.h" 8 | #include "at32f403a_407_conf.h" 9 | #if defined ( __GNUC__ ) /* GCC CS3 */ 10 | #include 11 | #endif 12 | #include 13 | #undef errno 14 | extern int errno; 15 | 16 | 17 | // Helper macro to mark unused parameters and prevent compiler warnings. 18 | // Appends _UNUSED to the variable name to prevent accidentally using them. 19 | #ifdef UNUSED 20 | #undef UNUSED 21 | #endif 22 | #ifdef __GNUC__ 23 | #define UNUSED(x) x ## _UNUSED __attribute__((__unused__)) 24 | #else 25 | #define UNUSED(x) x ## _UNUSED 26 | #endif 27 | 28 | __attribute__((weak)) 29 | caddr_t _sbrk(int incr) 30 | { 31 | extern char _estack; /* Defined in the linker script */ 32 | extern char _Min_Stack_Size; /* Defined in the linker script */ 33 | extern char _end; /* Defined by the linker */ 34 | static char *heap_end = &_end ; 35 | char *prev_heap_end = heap_end; 36 | 37 | if (heap_end + incr > (char *)__get_MSP()) { 38 | /* Heap and stack collision */ 39 | errno = ENOMEM; 40 | return (caddr_t) -1; 41 | } 42 | /* Ensure to keep minimum stack size defined in the linker script */ 43 | if (heap_end + incr >= (char *)(&_estack - &_Min_Stack_Size)) { 44 | errno = ENOMEM; 45 | return (caddr_t) -1; 46 | } 47 | 48 | heap_end += incr ; 49 | return (caddr_t) prev_heap_end ; 50 | } 51 | 52 | __attribute__((weak)) 53 | int _close(UNUSED(int file)) 54 | { 55 | return -1; 56 | } 57 | 58 | __attribute__((weak)) 59 | int _fstat(UNUSED(int file), struct stat *st) 60 | { 61 | st->st_mode = S_IFCHR ; 62 | return 0; 63 | } 64 | 65 | __attribute__((weak)) 66 | int _isatty(UNUSED(int file)) 67 | { 68 | return 1; 69 | } 70 | 71 | __attribute__((weak)) 72 | int _lseek(UNUSED(int file), UNUSED(int ptr), UNUSED(int dir)) 73 | { 74 | return 0; 75 | } 76 | 77 | __attribute__((weak)) 78 | int _read(UNUSED(int file), UNUSED(char *ptr), UNUSED(int len)) 79 | { 80 | return 0; 81 | } 82 | 83 | /* Moved to Print.cpp to support Print::printf() 84 | __attribute__((weak)) 85 | int _write(UNUSED(int file), char *ptr, int len) 86 | { 87 | } 88 | */ 89 | 90 | __attribute__((weak)) 91 | void _exit(UNUSED(int status)) 92 | { 93 | for (; ;) ; 94 | } 95 | 96 | __attribute__((weak)) 97 | int _kill(UNUSED(int pid), UNUSED(int sig)) 98 | { 99 | errno = EINVAL; 100 | return -1; 101 | } 102 | 103 | __attribute__((weak)) 104 | int _getpid(void) 105 | { 106 | return 1; 107 | } -------------------------------------------------------------------------------- /cores/arduino/libcore/timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * Copyright (c) 2017 - 2022 _VIFEXTech 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | #ifndef __TIMER_H 24 | #define __TIMER_H 25 | 26 | #include 27 | #include "mcu_type.h" 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | typedef void(*Timer_CallbackFunction_t)(void); 34 | 35 | void Timer_SetEnable(tmr_type* TIMx, bool Enable); 36 | void Timer_SetInterrupt(tmr_type* TIMx, uint32_t time, Timer_CallbackFunction_t Function); 37 | void Timer_SetInterruptTimeUpdate(tmr_type* TIMx, uint32_t Time); 38 | bool Timer_SetInterruptFreqUpdate(tmr_type* TIMx, uint32_t Freq); 39 | void Timer_SetInterruptBase( 40 | tmr_type* TIMx, 41 | uint16_t Period, uint16_t Prescaler, 42 | Timer_CallbackFunction_t Function, 43 | uint8_t PreemptionPriority, uint8_t SubPriority 44 | ); 45 | void Timer_SetCompare(tmr_type* TIMx, uint8_t TimerChannel, uint32_t Compare); 46 | void Timer_SetPrescaler(tmr_type* TIMx, uint16_t Prescaler); 47 | void Timer_SetReload(tmr_type* TIMx, uint16_t Reload); 48 | void Timer_SetCounter(tmr_type* TIMx, uint32_t Counter); 49 | void Timer_ClockCmd(tmr_type* TIMx, bool Enable); 50 | uint32_t Timer_GetClockMax(tmr_type* TIMx); 51 | uint32_t Timer_GetClockOut(tmr_type* TIMx); 52 | uint16_t Timer_GetCompare(tmr_type* TIMx, uint8_t TimerChannel); 53 | void Timer_GenerateUpdate(tmr_type* TIMx); 54 | void Timer_Pause(tmr_type* TIMx); 55 | void Timer_Resume(tmr_type* TIMx); 56 | #ifdef __cplusplus 57 | } 58 | #endif 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /cores/arduino/libcore/wdg.c: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * Copyright (c) 2017 - 2022 _VIFEXTech 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | #include "wdg.h" 24 | 25 | uint32_t WDG_Init(uint32_t timeout) 26 | { 27 | uint32_t reload_value; 28 | uint32_t real_timeout = 0; 29 | 30 | uint16_t division; 31 | 32 | static const uint8_t div_map[] = 33 | { 34 | WDT_CLK_DIV_4, /*!< wdt clock divider value is 4 */ 35 | WDT_CLK_DIV_8, /*!< wdt clock divider value is 8 */ 36 | WDT_CLK_DIV_16, /*!< wdt clock divider value is 16 */ 37 | WDT_CLK_DIV_32, /*!< wdt clock divider value is 32 */ 38 | WDT_CLK_DIV_64, /*!< wdt clock divider value is 64 */ 39 | WDT_CLK_DIV_128, /*!< wdt clock divider value is 128 */ 40 | WDT_CLK_DIV_256 /*!< wdt clock divider value is 256 */ 41 | }; 42 | 43 | /* set reload value 44 | * lick_freq = 40000 45 | * timeout = reload_value * divider / lick_freq * 1000 (ms) 46 | * timeout / divider * lick_freq / 1000 = reload_value 47 | */ 48 | const uint32_t lick_freq = 40000; 49 | 50 | for(int i = 0; i < sizeof(div_map) / sizeof(uint8_t); i++) 51 | { 52 | int div = 4 << i; 53 | reload_value = (uint64_t)timeout * lick_freq / div / 1000; 54 | 55 | if(reload_value <= 0xFFF) 56 | { 57 | real_timeout = (uint64_t)reload_value * div * 1000 / lick_freq; 58 | division = div_map[i]; 59 | break; 60 | } 61 | } 62 | 63 | if(reload_value > 0xFFF) 64 | { 65 | return 0; 66 | } 67 | 68 | if(crm_flag_get(CRM_WDT_RESET_FLAG) != RESET) 69 | { 70 | /* reset from wdt */ 71 | crm_flag_clear(CRM_WDT_RESET_FLAG); 72 | } 73 | 74 | /* disable register write protection */ 75 | wdt_register_write_enable(TRUE); 76 | 77 | /* set the wdt divider value */ 78 | wdt_divider_set(division); 79 | 80 | 81 | /* Set counter reload value */ 82 | wdt_reload_value_set(3000 - 1); 83 | 84 | /* Reload IWDG counter */ 85 | wdt_counter_reload(); 86 | 87 | /* Enable IWDG (the LSI oscillator will be enabled by hardware) */ 88 | wdt_enable(); 89 | 90 | return real_timeout; 91 | } 92 | 93 | void WDG_ReloadCounter(void) 94 | { 95 | wdt_counter_reload(); 96 | } 97 | -------------------------------------------------------------------------------- /cores/arduino/libcore/wdg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * Copyright (c) 2017 - 2022 _VIFEXTech 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | #ifndef __WDT_H 24 | #define __WDT_H 25 | 26 | #include "mcu_type.h" 27 | 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif 31 | 32 | uint32_t WDG_Init(uint32_t timeout); 33 | void WDG_ReloadCounter(void); 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /cores/arduino/main.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * The MIT License 3 | * 4 | * Copyright (c) 2010 LeafLabs LLC. 5 | * 6 | * Permission is hereby granted, free of charge, to any person 7 | * obtaining a copy of this software and associated documentation 8 | * files (the "Software"), to deal in the Software without 9 | * restriction, including without limitation the rights to use, copy, 10 | * modify, merge, publish, distribute, sublicense, and/or sell copies 11 | * of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 21 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 22 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | *****************************************************************************/ 26 | #include 27 | #include "libcore/mcu_core.h" 28 | extern void setup(void); 29 | extern void loop(void); 30 | 31 | // Force init to be called *first*, i.e. before static object allocation. 32 | // Otherwise, statically allocated objects that need libmaple may fail. 33 | __attribute__(( constructor (101))) void premain() { 34 | 35 | } 36 | 37 | int main(void) { 38 | Core_Init(); 39 | setup(); 40 | 41 | while (1) { 42 | loop(); 43 | } 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /libraries/Generic_Examples/empty.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WeActStudio/ArduinoCore-AT32F4/e4686b837df3ae8b905f2466c456c21d2ea05f95/libraries/Generic_Examples/empty.h -------------------------------------------------------------------------------- /libraries/Generic_Examples/examples/01.Basics/Blink/Blink.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Blink 3 | 4 | Turns an LED on for one second, then off for one second, repeatedly. 5 | 6 | Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO 7 | it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to 8 | the correct LED pin independent of which board is used. 9 | If you want to know what pin the on-board LED is connected to on your Arduino 10 | model, check the Technical Specs of your board at: 11 | https://www.arduino.cc/en/Main/Products 12 | 13 | modified 8 May 2014 14 | by Scott Fitzgerald 15 | modified 2 Sep 2016 16 | by Arturo Guadalupi 17 | modified 8 Sep 2016 18 | by Colby Newman 19 | 20 | This example code is in the public domain. 21 | 22 | https://www.arduino.cc/en/Tutorial/BuiltInExamples/Blink 23 | */ 24 | 25 | // the setup function runs once when you press reset or power the board 26 | void setup() { 27 | // initialize digital pin LED_BUILTIN as an output. 28 | pinMode(PC13, OUTPUT); 29 | } 30 | 31 | // the loop function runs over and over again forever 32 | void loop() { 33 | digitalWrite(PC13, HIGH); // turn the LED on (HIGH is the voltage level) 34 | delay(1000); // wait for a second 35 | digitalWrite(PC13, LOW); // turn the LED off by making the voltage LOW 36 | delay(1000); // wait for a second 37 | } 38 | -------------------------------------------------------------------------------- /libraries/Generic_Examples/examples/01.Basics/Blink/Blink.txt: -------------------------------------------------------------------------------- 1 | Turn an LED on and off. -------------------------------------------------------------------------------- /package_at32_index.json: -------------------------------------------------------------------------------- 1 | { 2 | "packages": [ 3 | { 4 | "name": "WeActStudio", 5 | "maintainer": "WeActStudio", 6 | "email": "", 7 | "websiteURL": "https://github.com/WeActStudio/ArduinoCore-AT32F4/", 8 | "help": { 9 | "online": "https://github.com/WeActStudio/ArduinoCore-AT32F4/" 10 | }, 11 | "platforms": [ 12 | { 13 | "name": "AT32F403ACGU7 Core Board", 14 | "architecture": "at32f403a", 15 | "version": "0.0.9", 16 | "category": "Contributed", 17 | "url": "https://github.com/WeActStudio/ArduinoCore-AT32F4/archive/refs/heads/main.zip", 18 | "archiveFileName": "ArduinoCore-AT32F4-main.zip", 19 | "help": { 20 | "online": "" 21 | }, 22 | "boards": [ 23 | { 24 | "name": "BlackPill AT32F403ACGU7" 25 | } 26 | ], 27 | "toolsDependencies": [ 28 | { 29 | "packager": "WeActStudio", 30 | "name": "xpack-arm-none-eabi-gcc", 31 | "version": "11.2.1-1.2" 32 | }, 33 | { 34 | "packager": "WeActStudio", 35 | "name": "Artery_ISP_Console", 36 | "version": "0.0.1" 37 | } 38 | ] 39 | } 40 | ], 41 | "tools": [ 42 | { 43 | "name": "xpack-arm-none-eabi-gcc", 44 | "version": "11.2.1-1.2", 45 | "systems": [ 46 | { 47 | "host": "i686-mingw32", 48 | "url": "https://github.com/xpack-dev-tools/arm-none-eabi-gcc-xpack/releases/download/v11.2.1-1.2/xpack-arm-none-eabi-gcc-11.2.1-1.2-win32-x64.zip", 49 | "archiveFileName": "xpack-arm-none-eabi-gcc-11.2.1-1.2-win32-x64.zip", 50 | "checksum": "SHA-256:4a45e1df1c621f0a97a2bcb63977a3745ffcff7afc0e31ad2f3d5cc1272acf4b", 51 | "size": "247612940" 52 | }, 53 | { 54 | "host": "x86_64-pc-linux-gnu", 55 | "url": "https://github.com/xpack-dev-tools/arm-none-eabi-gcc-xpack/releases/download/v11.2.1-1.2/xpack-arm-none-eabi-gcc-11.2.1-1.2-linux-x64.tar.gz", 56 | "archiveFileName": "xpack-arm-none-eabi-gcc-11.2.1-1.2-linux-x64.tar.gz", 57 | "checksum": "SHA-256:7479becc1ea98fbceecadf1f036ddaba8dc39c9cce5cb45f0a7a36e923d33c9a", 58 | "size": "235243515" 59 | } 60 | 61 | ] 62 | }, 63 | { 64 | "name": "Artery_ISP_Console", 65 | "version": "0.0.1", 66 | "systems": [ 67 | { 68 | "host": "i686-mingw32", 69 | "url": "https://github.com/WeActStudio/ArduinoCore-AT32F4/releases/download/0.0.1/Artery_ISP_Console_Win_V3.0.01.zip", 70 | "archiveFileName": "Artery_ISP_Console_Win_V3.0.01.zip", 71 | "size": "3890476", 72 | "checksum": "SHA-256:785979348d5c6b9451650d2ba22233825f362d46adfdfb1e4794e3866b4d034f" 73 | }, 74 | { 75 | "host": "x86_64-pc-linux-gnu", 76 | "url": "https://github.com/WeActStudio/ArduinoCore-AT32F4/releases/download/0.0.1/Artery_ISP_Console_Linux_V3.0.01.tar.bz2", 77 | "archiveFileName": "Artery_ISP_Console_Linux_V3.0.01.tar.bz2", 78 | "size": "14810873", 79 | "checksum": "SHA-256:f84a0a2156a6b4bb8e8ccbc6d9b297517a526dfc857c4789176a906c91c26f77" 80 | } 81 | ] 82 | } 83 | ] 84 | } 85 | ] 86 | } 87 | -------------------------------------------------------------------------------- /platform.txt: -------------------------------------------------------------------------------- 1 | ##==============================================## 2 | name=WeActStudio AT32F403A Boards 3 | version=0.0.9 4 | ##==============================================## 5 | 6 | ####AT32 compile variables 7 | 8 | ## compiler variables 9 | compiler.path={runtime.tools.xpack-arm-none-eabi-gcc.path}/bin/ 10 | 11 | ##All the command 12 | compiler.asm.cmd=arm-none-eabi-gcc 13 | compiler.c.cmd=arm-none-eabi-gcc 14 | compiler.cpp.cmd=arm-none-eabi-g++ 15 | compiler.ar.cmd=arm-none-eabi-ar 16 | compiler.elf.cmd=arm-none-eabi-g++ 17 | compiler.hex.cmd=arm-none-eabi-objcopy 18 | compiler.bin.cmd=arm-none-eabi-objcopy 19 | compiler.size.cmd=arm-none-eabi-size 20 | 21 | ##Set the compiler flags 22 | compiler.ar.flags=rcs 23 | compiler.asm.flags=-mthumb -Wall -g -Os 24 | compiler.c.flags=-mthumb -Wall -MMD -std=gnu11 -ffunction-sections -g -Os -fno-exceptions 25 | compiler.cpp.flags=-mthumb -Wall -MMD -std=gnu++11 -ffunction-sections -g -Os -fno-exceptions -fno-rtti 26 | compiler.elf.flags=-mthumb -g -Wl,--gc-sections -Wall -lstdc++ -lm 27 | compiler.hex.flags=-Oihex 28 | compiler.bin.flags=-Obinary 29 | compiler.combine.flags=-u _sbrk -u link -u _close -u _fstat -u _isatty -u _lseek -u _read -u _write -u _exit -u kill -u _getpid 30 | compiler.c.elf.extra_flags=-specs=nosys.specs -specs=nano.specs {compiler.combine.flags} 31 | build.common_flags=-mthumb 32 | 33 | ##===============================================## 34 | ## In there,set the include path,for FrameLib use 35 | 36 | compiler.FrameLib.c.flags="-I{build.system.path}/Drivers/CMSIS/Include" "-I{build.system.path}/AT32F403A" "-I{build.system.path}/Drivers/Firmware/inc" "-I{build.system.path}/libcore" "-I{build.system.path}/libcore/config" 37 | 38 | ##===============================================## 39 | 40 | recipe.S.o.pattern="{compiler.path}{compiler.asm.cmd}" {compiler.asm.flags} -mcpu={build.mcu} -c "{source_file}" -o "{object_file}" 41 | 42 | recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.c.flags} -mcpu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DF_PLL_CLOCK_SOURCE={build.f_pll_clock_source} -DF_PLL_MULT={build.f_pll_mult} -DF_PLL_OUTPUT_RANGE={build.f_pll_output_range} -DF_HEXT_DIV={build.f_hext_div} -DF_HSI_DIV={build.f_hsi_div} {build.extra_flags} {compiler.FrameLib.c.flags} {includes} -c "{source_file}" -o "{object_file}" 43 | 44 | recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} -mcpu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DF_PLL_CLOCK_SOURCE={build.f_pll_clock_source} -DF_PLL_MULT={build.f_pll_mult} -DF_PLL_OUTPUT_RANGE={build.f_pll_output_range} -DF_HEXT_DIV={build.f_hext_div} -DF_HSI_DIV={build.f_hsi_div} {build.extra_flags} {compiler.FrameLib.c.flags} {includes} -c "{source_file}" -o "{object_file}" 45 | 46 | recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} "{archive_file_path}" "{object_file}" 47 | 48 | recipe.c.combine.pattern="{compiler.path}{compiler.elf.cmd}" {compiler.elf.flags} -mcpu={build.mcu} "-L{build.variant.path}" "-T{build.variant.path}/{build.ldscript}" {object_files} "{archive_file_path}" "{build.variant.path}/{build.variant_system_lib}" {compiler.c.elf.extra_flags} -o "{build.path}/{build.project_name}.elf" 49 | ##recipe.c.combine.pattern="{compiler.path}{compiler.elf.cmd}" {compiler.elf.flags} -mcpu={build.mcu} "-T{build.variant.path}/{build.ldscript}" "-Wl,-Map,{build.path}/{build.project_name}.map" -o "{build.path}/{build.project_name}.elf" "-L{build.path}" -lm -lgcc -mthumb -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -Wl,--warn-unresolved-symbols -Wl,--start-group {object_files} -Wl,--whole-archive "{archive_file_path}" -Wl,--no-whole-archive -Wl,--end-group 50 | 51 | recipe.objcopy.eep.pattern= 52 | 53 | recipe.objcopy.hex.pattern="{compiler.path}{compiler.hex.cmd}" {compiler.hex.flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.hex" 54 | 55 | ## Compute size 56 | recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.elf" 57 | recipe.size.regex=^(?:\.text|\.data|\.rodata|\.text.align|\.ARM.exidx)\s+([0-9]+).* 58 | recipe.size.regex.data=^(?:\.data|\.bss|\.noinit)\s+([0-9]+).* 59 | 60 | 61 | # Uploader tools 62 | # ------------------- 63 | 64 | tools.Artery_ISP_Console.cmd=DFU_download.sh 65 | tools.Artery_ISP_Console.cmd.windows=WeAct Studio Download Tool.bat 66 | tools.Artery_ISP_Console.path={runtime.tools.Artery_ISP_Console.path} 67 | 68 | tools.Artery_ISP_Console.upload.params.verbose=-d 69 | tools.Artery_ISP_Console.upload.params.quiet= 70 | tools.Artery_ISP_Console.upload.pattern="{path}/{cmd}" "{build.path}/{build.project_name}.hex" 71 | -------------------------------------------------------------------------------- /system/AT32F403A/syscall.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file syscalls_at32.c 3 | * 4 | * Implementation of newlib syscall. 5 | * 6 | */ 7 | #include "at32f403a_407.h" 8 | #include "at32f403a_407_conf.h" 9 | // #if defined ( __GNUC__ ) /* GCC CS3 */ 10 | #include 11 | // #endif 12 | #include 13 | #undef errno 14 | extern int errno; 15 | 16 | extern size_t uart_debug_write(uint8_t *data, uint32_t size); 17 | 18 | // Helper macro to mark unused parameters and prevent compiler warnings. 19 | // Appends _UNUSED to the variable name to prevent accidentally using them. 20 | #ifdef UNUSED 21 | #undef UNUSED 22 | #endif 23 | #ifdef __GNUC__ 24 | #define UNUSED(x) x ## _UNUSED __attribute__((__unused__)) 25 | #else 26 | #define UNUSED(x) x ## _UNUSED 27 | #endif 28 | 29 | __attribute__((weak)) 30 | caddr_t _sbrk(int incr) 31 | { 32 | extern char _estack; /* Defined in the linker script */ 33 | extern char _Min_Stack_Size; /* Defined in the linker script */ 34 | extern char _end; /* Defined by the linker */ 35 | static char *heap_end = &_end ; 36 | char *prev_heap_end = heap_end; 37 | 38 | if (heap_end + incr > (char *)__get_MSP()) { 39 | /* Heap and stack collision */ 40 | errno = ENOMEM; 41 | return (caddr_t) -1; 42 | } 43 | /* Ensure to keep minimum stack size defined in the linker script */ 44 | if (heap_end + incr >= (char *)(&_estack - &_Min_Stack_Size)) { 45 | errno = ENOMEM; 46 | return (caddr_t) -1; 47 | } 48 | 49 | heap_end += incr ; 50 | return (caddr_t) prev_heap_end ; 51 | } 52 | 53 | __attribute__((weak)) 54 | int _close(UNUSED(int file)) 55 | { 56 | return -1; 57 | } 58 | 59 | __attribute__((weak)) 60 | int _fstat(UNUSED(int file), struct stat *st) 61 | { 62 | st->st_mode = S_IFCHR ; 63 | return 0; 64 | } 65 | 66 | __attribute__((weak)) 67 | int _isatty(UNUSED(int file)) 68 | { 69 | return 1; 70 | } 71 | 72 | __attribute__((weak)) 73 | int _lseek(UNUSED(int file), UNUSED(int ptr), UNUSED(int dir)) 74 | { 75 | return 0; 76 | } 77 | 78 | __attribute__((weak)) 79 | int _read(UNUSED(int file), UNUSED(char *ptr), UNUSED(int len)) 80 | { 81 | return 0; 82 | } 83 | 84 | /* Moved to Print.cpp to support Print::printf() 85 | __attribute__((weak)) 86 | int _write(UNUSED(int file), char *ptr, int len) 87 | { 88 | } 89 | */ 90 | 91 | __attribute__((weak)) 92 | void _exit(UNUSED(int status)) 93 | { 94 | for (; ;) ; 95 | } 96 | 97 | __attribute__((weak)) 98 | int _kill(UNUSED(int pid), UNUSED(int sig)) 99 | { 100 | errno = EINVAL; 101 | return -1; 102 | } 103 | 104 | __attribute__((weak)) 105 | int _getpid(void) 106 | { 107 | return 1; 108 | } -------------------------------------------------------------------------------- /system/Drivers/CMSIS/Include/cmsis_version.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file cmsis_version.h 3 | * @brief CMSIS Core(M) Version definitions 4 | * @version V5.0.5 5 | * @date 02. February 2022 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2009-2022 ARM Limited. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #if defined ( __ICCARM__ ) 26 | #pragma system_include /* treat file as system include file for MISRA check */ 27 | #elif defined (__clang__) 28 | #pragma clang system_header /* treat file as system include file */ 29 | #endif 30 | 31 | #ifndef __CMSIS_VERSION_H 32 | #define __CMSIS_VERSION_H 33 | 34 | /* CMSIS Version definitions */ 35 | #define __CM_CMSIS_VERSION_MAIN ( 5U) /*!< [31:16] CMSIS Core(M) main version */ 36 | #define __CM_CMSIS_VERSION_SUB ( 6U) /*!< [15:0] CMSIS Core(M) sub version */ 37 | #define __CM_CMSIS_VERSION ((__CM_CMSIS_VERSION_MAIN << 16U) | \ 38 | __CM_CMSIS_VERSION_SUB ) /*!< CMSIS Core(M) version number */ 39 | #endif 40 | -------------------------------------------------------------------------------- /system/Drivers/CMSIS/Include/system_at32f403a_407.h: -------------------------------------------------------------------------------- 1 | /** 2 | ************************************************************************** 3 | * @file system_at32f403a_407.h 4 | * @version v2.0.9 5 | * @date 2022-04-25 6 | * @brief cmsis cortex-m4 system header file. 7 | ************************************************************************** 8 | * Copyright notice & Disclaimer 9 | * 10 | * The software Board Support Package (BSP) that is made available to 11 | * download from Artery official website is the copyrighted work of Artery. 12 | * Artery authorizes customers to use, copy, and distribute the BSP 13 | * software and its related documentation for the purpose of design and 14 | * development in conjunction with Artery microcontrollers. Use of the 15 | * software is governed by this copyright notice and the following disclaimer. 16 | * 17 | * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, 18 | * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, 19 | * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR 20 | * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, 21 | * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. 23 | * 24 | ************************************************************************** 25 | */ 26 | 27 | #ifndef __SYSTEM_AT32F403A_407_H 28 | #define __SYSTEM_AT32F403A_407_H 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | /** @addtogroup CMSIS 35 | * @{ 36 | */ 37 | 38 | /** @addtogroup AT32F403A_407_system 39 | * @{ 40 | */ 41 | 42 | /** @defgroup AT32F403A_407_system_clock_stable_definition 43 | * @{ 44 | */ 45 | 46 | #define HEXT_STABLE_DELAY (5000u) 47 | #define PLL_STABLE_DELAY (500u) 48 | 49 | /** 50 | * @} 51 | */ 52 | 53 | /** @defgroup AT32F403A_407_system_exported_variables 54 | * @{ 55 | */ 56 | 57 | extern unsigned int system_core_clock; /*!< system clock frequency (core clock) */ 58 | 59 | /** 60 | * @} 61 | */ 62 | 63 | /** @defgroup AT32F403A_407_system_exported_functions 64 | * @{ 65 | */ 66 | 67 | extern void SystemInit(void); 68 | extern void system_core_clock_update(void); 69 | 70 | /** 71 | * @} 72 | */ 73 | 74 | /** 75 | * @} 76 | */ 77 | 78 | /** 79 | * @} 80 | */ 81 | 82 | #ifdef __cplusplus 83 | } 84 | #endif 85 | 86 | #endif 87 | -------------------------------------------------------------------------------- /system/Drivers/Firmware/inc/at32f403a_407_crc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ************************************************************************** 3 | * @file at32f403a_407_crc.h 4 | * @version v2.0.9 5 | * @date 2022-04-25 6 | * @brief at32f403a_407 crc header file 7 | ************************************************************************** 8 | * Copyright notice & Disclaimer 9 | * 10 | * The software Board Support Package (BSP) that is made available to 11 | * download from Artery official website is the copyrighted work of Artery. 12 | * Artery authorizes customers to use, copy, and distribute the BSP 13 | * software and its related documentation for the purpose of design and 14 | * development in conjunction with Artery microcontrollers. Use of the 15 | * software is governed by this copyright notice and the following disclaimer. 16 | * 17 | * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, 18 | * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, 19 | * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR 20 | * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, 21 | * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. 23 | * 24 | ************************************************************************** 25 | */ 26 | 27 | /* define to prevent recursive inclusion -------------------------------------*/ 28 | #ifndef __AT32F403A_407_CRC_H 29 | #define __AT32F403A_407_CRC_H 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | 36 | /* includes ------------------------------------------------------------------*/ 37 | #include "at32f403a_407.h" 38 | 39 | /** @addtogroup AT32F403A_407_periph_driver 40 | * @{ 41 | */ 42 | 43 | /** @addtogroup CRC 44 | * @{ 45 | */ 46 | 47 | /** @defgroup CRC_exported_types 48 | * @{ 49 | */ 50 | 51 | /** 52 | * @brief crc reverse input data 53 | */ 54 | typedef enum 55 | { 56 | CRC_REVERSE_INPUT_NO_AFFECTE = 0x00, /*!< input data no reverse */ 57 | CRC_REVERSE_INPUT_BY_BYTE = 0x01, /*!< input data reverse by byte */ 58 | CRC_REVERSE_INPUT_BY_HALFWORD = 0x02, /*!< input data reverse by half word */ 59 | CRC_REVERSE_INPUT_BY_WORD = 0x03 /*!< input data reverse by word */ 60 | } crc_reverse_input_type; 61 | 62 | /** 63 | * @brief crc reverse output data 64 | */ 65 | typedef enum 66 | { 67 | CRC_REVERSE_OUTPUT_NO_AFFECTE = 0x00, /*!< output data no reverse */ 68 | CRC_REVERSE_OUTPUT_DATA = 0x01 /*!< output data reverse by word */ 69 | } crc_reverse_output_type; 70 | 71 | /** 72 | * @brief type define crc register all 73 | */ 74 | typedef struct 75 | { 76 | /** 77 | * @brief crc dt register, offset:0x00 78 | */ 79 | union 80 | { 81 | __IO uint32_t dt; 82 | struct 83 | { 84 | __IO uint32_t dt : 32; /* [31:0] */ 85 | } dt_bit; 86 | }; 87 | 88 | /** 89 | * @brief crc cdt register, offset:0x04 90 | */ 91 | union 92 | { 93 | __IO uint32_t cdt; 94 | struct 95 | { 96 | __IO uint32_t cdt : 8 ; /* [7:0] */ 97 | __IO uint32_t reserved1 : 24 ;/* [31:8] */ 98 | } cdt_bit; 99 | }; 100 | 101 | /** 102 | * @brief crc ctrl register, offset:0x08 103 | */ 104 | union 105 | { 106 | __IO uint32_t ctrl; 107 | struct 108 | { 109 | __IO uint32_t rst : 1 ; /* [0] */ 110 | __IO uint32_t reserved1 : 4 ; /* [4:1] */ 111 | __IO uint32_t revid : 2 ; /* [6:5] */ 112 | __IO uint32_t revod : 1 ; /* [7] */ 113 | __IO uint32_t reserved2 : 24 ;/* [31:8] */ 114 | } ctrl_bit; 115 | }; 116 | 117 | /** 118 | * @brief crm reserved1 register, offset:0x0C 119 | */ 120 | __IO uint32_t reserved1; 121 | 122 | /** 123 | * @brief crc idt register, offset:0x10 124 | */ 125 | union 126 | { 127 | __IO uint32_t idt; 128 | struct 129 | { 130 | __IO uint32_t idt : 32; /* [31:0] */ 131 | } idt_bit; 132 | }; 133 | 134 | } crc_type; 135 | 136 | /** 137 | * @} 138 | */ 139 | 140 | #define CRC ((crc_type *) CRC_BASE) 141 | 142 | /** @defgroup CRC_exported_functions 143 | * @{ 144 | */ 145 | 146 | void crc_data_reset(void); 147 | uint32_t crc_one_word_calculate(uint32_t data); 148 | uint32_t crc_block_calculate(uint32_t *pbuffer, uint32_t length); 149 | uint32_t crc_data_get(void); 150 | void crc_common_data_set(uint8_t cdt_value); 151 | uint8_t crc_common_date_get(void); 152 | void crc_init_data_set(uint32_t value); 153 | void crc_reverse_input_data_set(crc_reverse_input_type value); 154 | void crc_reverse_output_data_set(crc_reverse_output_type value); 155 | 156 | /** 157 | * @} 158 | */ 159 | 160 | /** 161 | * @} 162 | */ 163 | 164 | /** 165 | * @} 166 | */ 167 | 168 | #ifdef __cplusplus 169 | } 170 | #endif 171 | 172 | #endif 173 | -------------------------------------------------------------------------------- /system/Drivers/Firmware/inc/at32f403a_407_def.h: -------------------------------------------------------------------------------- 1 | /** 2 | ************************************************************************** 3 | * @file at32f403a_407_def.h 4 | * @version v2.0.9 5 | * @date 2022-04-25 6 | * @brief at32f403a_407 macros header file 7 | ************************************************************************** 8 | * Copyright notice & Disclaimer 9 | * 10 | * The software Board Support Package (BSP) that is made available to 11 | * download from Artery official website is the copyrighted work of Artery. 12 | * Artery authorizes customers to use, copy, and distribute the BSP 13 | * software and its related documentation for the purpose of design and 14 | * development in conjunction with Artery microcontrollers. Use of the 15 | * software is governed by this copyright notice and the following disclaimer. 16 | * 17 | * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, 18 | * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, 19 | * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR 20 | * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, 21 | * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. 23 | * 24 | ************************************************************************** 25 | */ 26 | 27 | /* Define to prevent recursive inclusion -------------------------------------*/ 28 | #ifndef __AT32F403A_407_DEF_H 29 | #define __AT32F403A_407_DEF_H 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | /* gnu compiler */ 36 | #if defined (__GNUC__) 37 | #ifndef ALIGNED_HEAD 38 | #define ALIGNED_HEAD 39 | #endif 40 | #ifndef ALIGNED_TAIL 41 | #define ALIGNED_TAIL __attribute__ ((aligned (4))) 42 | #endif 43 | #endif 44 | 45 | /* arm compiler */ 46 | #if defined (__CC_ARM) 47 | #ifndef ALIGNED_HEAD 48 | #define ALIGNED_HEAD __align(4) 49 | #endif 50 | #ifndef ALIGNED_TAIL 51 | #define ALIGNED_TAIL 52 | #endif 53 | #endif 54 | 55 | /* iar compiler */ 56 | #if defined (__ICCARM__) 57 | #ifndef ALIGNED_HEAD 58 | #define ALIGNED_HEAD 59 | #endif 60 | #ifndef ALIGNED_TAIL 61 | #define ALIGNED_TAIL 62 | #endif 63 | #endif 64 | 65 | #ifdef __cplusplus 66 | } 67 | #endif 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /system/Drivers/Firmware/inc/at32f403a_407_misc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ************************************************************************** 3 | * @file at32f403a_407_misc.h 4 | * @version v2.0.9 5 | * @date 2022-04-25 6 | * @brief at32f403a_407 misc header file 7 | ************************************************************************** 8 | * Copyright notice & Disclaimer 9 | * 10 | * The software Board Support Package (BSP) that is made available to 11 | * download from Artery official website is the copyrighted work of Artery. 12 | * Artery authorizes customers to use, copy, and distribute the BSP 13 | * software and its related documentation for the purpose of design and 14 | * development in conjunction with Artery microcontrollers. Use of the 15 | * software is governed by this copyright notice and the following disclaimer. 16 | * 17 | * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, 18 | * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, 19 | * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR 20 | * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, 21 | * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. 23 | * 24 | ************************************************************************** 25 | */ 26 | 27 | /* define to prevent recursive inclusion -------------------------------------*/ 28 | #ifndef __AT32F403A_407_MISC_H 29 | #define __AT32F403A_407_MISC_H 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | 36 | /* includes ------------------------------------------------------------------*/ 37 | #include "at32f403a_407.h" 38 | 39 | /** @addtogroup AT32F403A_407_periph_driver 40 | * @{ 41 | */ 42 | 43 | /** @addtogroup MISC 44 | * @{ 45 | */ 46 | 47 | /** @defgroup MISC_vector_table_base_address 48 | * @{ 49 | */ 50 | 51 | #define NVIC_VECTTAB_RAM ((uint32_t)0x20000000) /*!< nvic vector table based ram address */ 52 | #define NVIC_VECTTAB_FLASH ((uint32_t)0x08000000) /*!< nvic vector table based flash address */ 53 | 54 | /** 55 | * @} 56 | */ 57 | 58 | /** @defgroup MISC_exported_types 59 | * @{ 60 | */ 61 | 62 | /** 63 | * @brief nvic interrupt priority group 64 | */ 65 | typedef enum 66 | { 67 | NVIC_PRIORITY_GROUP_0 = ((uint32_t)0x7), /*!< 0 bits for preemption priority, 4 bits for subpriority */ 68 | NVIC_PRIORITY_GROUP_1 = ((uint32_t)0x6), /*!< 1 bits for preemption priority, 3 bits for subpriority */ 69 | NVIC_PRIORITY_GROUP_2 = ((uint32_t)0x5), /*!< 2 bits for preemption priority, 2 bits for subpriority */ 70 | NVIC_PRIORITY_GROUP_3 = ((uint32_t)0x4), /*!< 3 bits for preemption priority, 1 bits for subpriority */ 71 | NVIC_PRIORITY_GROUP_4 = ((uint32_t)0x3) /*!< 4 bits for preemption priority, 0 bits for subpriority */ 72 | } nvic_priority_group_type; 73 | 74 | /** 75 | * @brief nvic low power mode 76 | */ 77 | typedef enum 78 | { 79 | NVIC_LP_SLEEPONEXIT = 0x02, /*!< send event on pending */ 80 | NVIC_LP_SLEEPDEEP = 0x04, /*!< enable sleep-deep output signal when entering sleep mode */ 81 | NVIC_LP_SEVONPEND = 0x10 /*!< enable sleep-on-exit feature */ 82 | } nvic_lowpower_mode_type; 83 | 84 | /** 85 | * @brief systick clock source 86 | */ 87 | typedef enum 88 | { 89 | SYSTICK_CLOCK_SOURCE_AHBCLK_DIV8 = ((uint32_t)0x00000000), /*!< systick clock source from core clock div8 */ 90 | SYSTICK_CLOCK_SOURCE_AHBCLK_NODIV = ((uint32_t)0x00000004) /*!< systick clock source from core clock */ 91 | } systick_clock_source_type; 92 | 93 | /** 94 | * @} 95 | */ 96 | 97 | /** @defgroup MISC_exported_functions 98 | * @{ 99 | */ 100 | 101 | void nvic_system_reset(void); 102 | void nvic_irq_enable(IRQn_Type irqn, uint32_t preempt_priority, uint32_t sub_priority); 103 | void nvic_irq_disable(IRQn_Type irqn); 104 | void nvic_priority_group_config(nvic_priority_group_type priority_group); 105 | void nvic_vector_table_set(uint32_t base, uint32_t offset); 106 | void nvic_lowpower_mode_config(nvic_lowpower_mode_type lp_mode, confirm_state new_state); 107 | void systick_clock_source_config(systick_clock_source_type source); 108 | 109 | /** 110 | * @} 111 | */ 112 | 113 | /** 114 | * @} 115 | */ 116 | 117 | /** 118 | * @} 119 | */ 120 | 121 | #ifdef __cplusplus 122 | } 123 | #endif 124 | 125 | #endif 126 | -------------------------------------------------------------------------------- /system/Drivers/Firmware/inc/at32f403a_407_wdt.h: -------------------------------------------------------------------------------- 1 | /** 2 | ************************************************************************** 3 | * @file at32f403a_407_wdt.h 4 | * @version v2.0.9 5 | * @date 2022-04-25 6 | * @brief at32f403a_407 wdt header file 7 | ************************************************************************** 8 | * Copyright notice & Disclaimer 9 | * 10 | * The software Board Support Package (BSP) that is made available to 11 | * download from Artery official website is the copyrighted work of Artery. 12 | * Artery authorizes customers to use, copy, and distribute the BSP 13 | * software and its related documentation for the purpose of design and 14 | * development in conjunction with Artery microcontrollers. Use of the 15 | * software is governed by this copyright notice and the following disclaimer. 16 | * 17 | * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, 18 | * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, 19 | * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR 20 | * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, 21 | * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. 23 | * 24 | ************************************************************************** 25 | */ 26 | 27 | /* Define to prevent recursive inclusion -------------------------------------*/ 28 | #ifndef __AT32F403A_407_WDT_H 29 | #define __AT32F403A_407_WDT_H 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | 36 | /* Includes ------------------------------------------------------------------*/ 37 | #include "at32f403a_407.h" 38 | 39 | /** @addtogroup AT32F403A_407_periph_driver 40 | * @{ 41 | */ 42 | 43 | /** @addtogroup WDT 44 | * @{ 45 | */ 46 | 47 | 48 | /** @defgroup WDT_flags_definition 49 | * @brief wdt flag 50 | * @{ 51 | */ 52 | 53 | #define WDT_DIVF_UPDATE_FLAG ((uint16_t)0x0001) /*!< wdt division value update complete flag */ 54 | #define WDT_RLDF_UPDATE_FLAG ((uint16_t)0x0002) /*!< wdt reload value update complete flag */ 55 | 56 | /** 57 | * @} 58 | */ 59 | 60 | /** @defgroup WDT_exported_types 61 | * @{ 62 | */ 63 | 64 | /** 65 | * @brief wdt division value type 66 | */ 67 | typedef enum 68 | { 69 | WDT_CLK_DIV_4 = 0x00, /*!< wdt clock divider value is 4 */ 70 | WDT_CLK_DIV_8 = 0x01, /*!< wdt clock divider value is 8 */ 71 | WDT_CLK_DIV_16 = 0x02, /*!< wdt clock divider value is 16 */ 72 | WDT_CLK_DIV_32 = 0x03, /*!< wdt clock divider value is 32 */ 73 | WDT_CLK_DIV_64 = 0x04, /*!< wdt clock divider value is 64 */ 74 | WDT_CLK_DIV_128 = 0x05, /*!< wdt clock divider value is 128 */ 75 | WDT_CLK_DIV_256 = 0x06 /*!< wdt clock divider value is 256 */ 76 | } wdt_division_type; 77 | 78 | /** 79 | * @brief wdt cmd value type 80 | */ 81 | typedef enum 82 | { 83 | WDT_CMD_LOCK = 0x0000, /*!< disable write protection command */ 84 | WDT_CMD_UNLOCK = 0x5555, /*!< enable write protection command */ 85 | WDT_CMD_ENABLE = 0xCCCC, /*!< enable wdt command */ 86 | WDT_CMD_RELOAD = 0xAAAA /*!< reload command */ 87 | } wdt_cmd_value_type; 88 | 89 | /** 90 | * @brief type define wdt register all 91 | */ 92 | typedef struct 93 | { 94 | 95 | /** 96 | * @brief wdt cmd register, offset:0x00 97 | */ 98 | union 99 | { 100 | __IO uint32_t cmd; 101 | struct 102 | { 103 | __IO uint32_t cmd : 16;/* [15:0] */ 104 | __IO uint32_t reserved1 : 16;/* [31:16] */ 105 | } cmd_bit; 106 | }; 107 | 108 | /** 109 | * @brief wdt div register, offset:0x04 110 | */ 111 | union 112 | { 113 | __IO uint32_t div; 114 | struct 115 | { 116 | __IO uint32_t div : 3; /* [2:0] */ 117 | __IO uint32_t reserved1 : 29;/* [31:3] */ 118 | } div_bit; 119 | }; 120 | 121 | /** 122 | * @brief wdt rld register, offset:0x08 123 | */ 124 | union 125 | { 126 | __IO uint32_t rld; 127 | struct 128 | { 129 | __IO uint32_t rld : 12;/* [11:0] */ 130 | __IO uint32_t reserved1 : 20;/* [31:12] */ 131 | } rld_bit; 132 | }; 133 | 134 | /** 135 | * @brief wdt sts register, offset:0x0C 136 | */ 137 | union 138 | { 139 | __IO uint32_t sts; 140 | struct 141 | { 142 | __IO uint32_t divf : 1; /* [0] */ 143 | __IO uint32_t rldf : 1; /* [1] */ 144 | __IO uint32_t reserved1 : 30;/* [31:2] */ 145 | } sts_bit; 146 | }; 147 | 148 | } wdt_type; 149 | 150 | /** 151 | * @} 152 | */ 153 | 154 | #define WDT ((wdt_type *) WDT_BASE) 155 | 156 | /** @defgroup WDT_exported_functions 157 | * @{ 158 | */ 159 | 160 | void wdt_enable(void); 161 | void wdt_counter_reload(void); 162 | void wdt_reload_value_set(uint16_t reload_value); 163 | void wdt_divider_set(wdt_division_type division); 164 | void wdt_register_write_enable( confirm_state new_state); 165 | flag_status wdt_flag_get(uint16_t wdt_flag); 166 | 167 | /** 168 | * @} 169 | */ 170 | 171 | /** 172 | * @} 173 | */ 174 | 175 | /** 176 | * @} 177 | */ 178 | 179 | #ifdef __cplusplus 180 | } 181 | #endif 182 | 183 | #endif 184 | -------------------------------------------------------------------------------- /system/Drivers/Firmware/inc/at32f403a_407_wwdt.h: -------------------------------------------------------------------------------- 1 | /** 2 | ************************************************************************** 3 | * @file at32f403a_407_wwdt.h 4 | * @version v2.0.9 5 | * @date 2022-04-25 6 | * @brief at32f403a_407 wwdt header file 7 | ************************************************************************** 8 | * Copyright notice & Disclaimer 9 | * 10 | * The software Board Support Package (BSP) that is made available to 11 | * download from Artery official website is the copyrighted work of Artery. 12 | * Artery authorizes customers to use, copy, and distribute the BSP 13 | * software and its related documentation for the purpose of design and 14 | * development in conjunction with Artery microcontrollers. Use of the 15 | * software is governed by this copyright notice and the following disclaimer. 16 | * 17 | * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, 18 | * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, 19 | * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR 20 | * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, 21 | * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. 23 | * 24 | ************************************************************************** 25 | */ 26 | 27 | /* Define to prevent recursive inclusion -------------------------------------*/ 28 | #ifndef __AT32F403A_407_WWDT_H 29 | #define __AT32F403A_407_WWDT_H 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | 36 | /* Includes ------------------------------------------------------------------*/ 37 | #include "at32f403a_407.h" 38 | 39 | /** @addtogroup AT32F403A_407_periph_driver 40 | * @{ 41 | */ 42 | 43 | /** @addtogroup WWDT 44 | * @{ 45 | */ 46 | 47 | /** @defgroup WWDT_enable_bit_definition 48 | * @brief wwdt enable bit 49 | * @{ 50 | */ 51 | 52 | #define WWDT_EN_BIT ((uint32_t)0x00000080) /*!< wwdt enable bit */ 53 | 54 | /** 55 | * @} 56 | */ 57 | 58 | /** @defgroup WWDT_exported_types 59 | * @{ 60 | */ 61 | 62 | /** 63 | * @brief wwdt division type 64 | */ 65 | typedef enum 66 | { 67 | WWDT_PCLK1_DIV_4096 = 0x00, /*!< wwdt counter clock = (pclk1/4096)/1) */ 68 | WWDT_PCLK1_DIV_8192 = 0x01, /*!< wwdt counter clock = (pclk1/4096)/2) */ 69 | WWDT_PCLK1_DIV_16384 = 0x02, /*!< wwdt counter clock = (pclk1/4096)/4) */ 70 | WWDT_PCLK1_DIV_32768 = 0x03 /*!< wwdt counter clock = (pclk1/4096)/8) */ 71 | } wwdt_division_type; 72 | 73 | /** 74 | * @brief type define wwdt register all 75 | */ 76 | typedef struct 77 | { 78 | 79 | /** 80 | * @brief wwdt ctrl register, offset:0x00 81 | */ 82 | union 83 | { 84 | __IO uint32_t ctrl; 85 | struct 86 | { 87 | __IO uint32_t cnt : 7; /* [6:0] */ 88 | __IO uint32_t wwdten : 1; /* [7] */ 89 | __IO uint32_t reserved1 : 24;/* [31:8] */ 90 | } ctrl_bit; 91 | }; 92 | 93 | /** 94 | * @brief wwdt cfg register, offset:0x04 95 | */ 96 | union 97 | { 98 | __IO uint32_t cfg; 99 | struct 100 | { 101 | __IO uint32_t win : 7; /* [6:0] */ 102 | __IO uint32_t div : 2; /* [8:7] */ 103 | __IO uint32_t rldien : 1; /* [9] */ 104 | __IO uint32_t reserved1 : 22;/* [31:10] */ 105 | } cfg_bit; 106 | }; 107 | 108 | /** 109 | * @brief wwdt cfg register, offset:0x08 110 | */ 111 | union 112 | { 113 | __IO uint32_t sts; 114 | struct 115 | { 116 | __IO uint32_t rldf : 1; /* [0] */ 117 | __IO uint32_t reserved1 : 31;/* [31:1] */ 118 | } sts_bit; 119 | }; 120 | 121 | } wwdt_type; 122 | 123 | /** 124 | * @} 125 | */ 126 | 127 | #define WWDT ((wwdt_type *) WWDT_BASE) 128 | 129 | /** @defgroup WWDT_exported_functions 130 | * @{ 131 | */ 132 | 133 | void wwdt_reset(void); 134 | void wwdt_divider_set(wwdt_division_type division); 135 | void wwdt_flag_clear(void); 136 | void wwdt_enable(uint8_t wwdt_cnt); 137 | void wwdt_interrupt_enable(void); 138 | flag_status wwdt_flag_get(void); 139 | void wwdt_counter_set(uint8_t wwdt_cnt); 140 | void wwdt_window_counter_set(uint8_t window_cnt); 141 | 142 | /** 143 | * @} 144 | */ 145 | 146 | /** 147 | * @} 148 | */ 149 | 150 | /** 151 | * @} 152 | */ 153 | 154 | #ifdef __cplusplus 155 | } 156 | #endif 157 | 158 | #endif 159 | -------------------------------------------------------------------------------- /system/Drivers/Firmware/src/at32f403a_407_crc.c: -------------------------------------------------------------------------------- 1 | /** 2 | ************************************************************************** 3 | * @file at32f403a_407_crc.c 4 | * @version v2.0.9 5 | * @date 2022-04-25 6 | * @brief contains all the functions for the crc firmware library 7 | ************************************************************************** 8 | * Copyright notice & Disclaimer 9 | * 10 | * The software Board Support Package (BSP) that is made available to 11 | * download from Artery official website is the copyrighted work of Artery. 12 | * Artery authorizes customers to use, copy, and distribute the BSP 13 | * software and its related documentation for the purpose of design and 14 | * development in conjunction with Artery microcontrollers. Use of the 15 | * software is governed by this copyright notice and the following disclaimer. 16 | * 17 | * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, 18 | * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, 19 | * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR 20 | * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, 21 | * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. 23 | * 24 | ************************************************************************** 25 | */ 26 | 27 | #include "at32f403a_407_conf.h" 28 | 29 | /** @addtogroup AT32F403A_407_periph_driver 30 | * @{ 31 | */ 32 | 33 | /** @defgroup CRC 34 | * @brief CRC driver modules 35 | * @{ 36 | */ 37 | 38 | #ifdef CRC_MODULE_ENABLED 39 | 40 | /** @defgroup CRC_private_functions 41 | * @{ 42 | */ 43 | 44 | /** 45 | * @brief reset the crc data register. 46 | * @param none 47 | * @retval none 48 | */ 49 | void crc_data_reset(void) 50 | { 51 | /* reset crc generator */ 52 | CRC->ctrl_bit.rst = 0x1; 53 | } 54 | 55 | /** 56 | * @brief compute the 32-bit crc of a given data word(32-bit). 57 | * @param data: data word(32-bit) to compute its crc 58 | * @retval 32-bit crc 59 | */ 60 | uint32_t crc_one_word_calculate(uint32_t data) 61 | { 62 | CRC->dt = data; 63 | return (CRC->dt); 64 | } 65 | 66 | /** 67 | * @brief compute the 32-bit crc of a given buffer of data word(32-bit). 68 | * @param pbuffer: pointer to the buffer containing the data to be computed 69 | * @param length: length of the buffer to be computed 70 | * @retval 32-bit crc 71 | */ 72 | uint32_t crc_block_calculate(uint32_t *pbuffer, uint32_t length) 73 | { 74 | uint32_t index = 0; 75 | 76 | for(index = 0; index < length; index++) 77 | { 78 | CRC->dt = pbuffer[index]; 79 | } 80 | 81 | return (CRC->dt); 82 | } 83 | 84 | /** 85 | * @brief return the current crc value. 86 | * @param none 87 | * @retval 32-bit crc 88 | */ 89 | uint32_t crc_data_get(void) 90 | { 91 | return (CRC->dt); 92 | } 93 | 94 | /** 95 | * @brief store a 8-bit data in the common data register. 96 | * @param cdt_value: 8-bit value to be stored in the common data register 97 | * @retval none 98 | */ 99 | void crc_common_data_set(uint8_t cdt_value) 100 | { 101 | CRC->cdt_bit.cdt = cdt_value; 102 | } 103 | 104 | /** 105 | * @brief return the 8-bit data stored in the common data register 106 | * @param none 107 | * @retval 8-bit value of the common data register 108 | */ 109 | uint8_t crc_common_date_get(void) 110 | { 111 | return (CRC->cdt_bit.cdt); 112 | } 113 | 114 | /** 115 | * @brief set the 32-bit initial data of crc 116 | * @param value: initial data 117 | * @retval none 118 | */ 119 | void crc_init_data_set(uint32_t value) 120 | { 121 | CRC->idt = value; 122 | } 123 | 124 | /** 125 | * @brief control the reversal of the bit order in the input data 126 | * @param value 127 | * this parameter can be one of the following values: 128 | * - CRC_REVERSE_INPUT_NO_AFFECTE 129 | * - CRC_REVERSE_INPUT_BY_BYTE 130 | * - CRC_REVERSE_INPUT_BY_HALFWORD 131 | * - CRC_REVERSE_INPUT_BY_WORD 132 | * @retval none. 133 | */ 134 | void crc_reverse_input_data_set(crc_reverse_input_type value) 135 | { 136 | CRC->ctrl_bit.revid = value; 137 | } 138 | 139 | /** 140 | * @brief control the reversal of the bit order in the output data 141 | * @param value 142 | * this parameter can be one of the following values: 143 | * - CRC_REVERSE_OUTPUT_NO_AFFECTE 144 | * - CRC_REVERSE_OUTPUT_DATA 145 | * @retval none. 146 | */ 147 | void crc_reverse_output_data_set(crc_reverse_output_type value) 148 | { 149 | CRC->ctrl_bit.revod = value; 150 | } 151 | 152 | /** 153 | * @} 154 | */ 155 | 156 | #endif 157 | 158 | /** 159 | * @} 160 | */ 161 | 162 | /** 163 | * @} 164 | */ 165 | -------------------------------------------------------------------------------- /system/Drivers/Firmware/src/at32f403a_407_debug.c: -------------------------------------------------------------------------------- 1 | /** 2 | ************************************************************************** 3 | * @file at32f403a_407_debug.c 4 | * @version v2.0.9 5 | * @date 2022-04-25 6 | * @brief contains all the functions for the debug firmware library 7 | ************************************************************************** 8 | * Copyright notice & Disclaimer 9 | * 10 | * The software Board Support Package (BSP) that is made available to 11 | * download from Artery official website is the copyrighted work of Artery. 12 | * Artery authorizes customers to use, copy, and distribute the BSP 13 | * software and its related documentation for the purpose of design and 14 | * development in conjunction with Artery microcontrollers. Use of the 15 | * software is governed by this copyright notice and the following disclaimer. 16 | * 17 | * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, 18 | * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, 19 | * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR 20 | * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, 21 | * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. 23 | * 24 | ************************************************************************** 25 | */ 26 | 27 | #include "at32f403a_407_conf.h" 28 | 29 | /** @addtogroup AT32F403A_407_periph_driver 30 | * @{ 31 | */ 32 | 33 | /** @defgroup DEBUG 34 | * @brief DEBUG driver modules 35 | * @{ 36 | */ 37 | 38 | #ifdef DEBUG_MODULE_ENABLED 39 | 40 | /** @defgroup DEBUG_private_functions 41 | * @{ 42 | */ 43 | 44 | /** 45 | * @brief get debug device id 46 | * @param none 47 | * @retval the debug device id 48 | */ 49 | uint32_t debug_device_id_get(void) 50 | { 51 | return DEBUGMCU->pid; 52 | } 53 | 54 | /** 55 | * @brief set periph debug mode 56 | * @param periph_debug_mode 57 | * this parameter can be any combination of the following values: 58 | * - DEBUG_SLEEP - DEBUG_DEEPSLEEP 59 | * - DEBUG_STANDBY - DEBUG_WDT_PAUSE 60 | * - DEBUG_WWDT_PAUSE - DEBUG_TMR1_PAUSE 61 | * - DEBUG_TMR3_PAUSE - DEBUG_I2C1_SMBUS_TIMEOUT 62 | * - DEBUG_I2C2_SMBUS_TIMEOUT - DEBUG_I2C3_SMBUS_TIMEOUT 63 | * - DEBUG_TMR2_PAUSE - DEBUG_TMR4_PAUSE 64 | * - DEBUG_CAN1_PAUSE - DEBUG_TMR8_PAUSE 65 | * - DEBUG_TMR5_PAUSE - DEBUG_TMR6_PAUSE 66 | * - DEBUG_TMR7_PAUSE - DEBUG_CAN2_PAUSE 67 | * - DEBUG_TMR12_PAUSE - DEBUG_TMR13_PAUSE 68 | * - DEBUG_TMR14_PAUSE - DEBUG_TMR9_PAUSE 69 | * - DEBUG_TMR10_PAUSE - DEBUG_TMR11_PAUSE 70 | * @param new_state (TRUE or FALSE) 71 | * @retval none 72 | */ 73 | void debug_periph_mode_set(uint32_t periph_debug_mode, confirm_state new_state) 74 | { 75 | if(new_state != FALSE) 76 | { 77 | DEBUGMCU->ctrl |= periph_debug_mode; 78 | } 79 | else 80 | { 81 | DEBUGMCU->ctrl &= ~periph_debug_mode; 82 | } 83 | } 84 | 85 | /** 86 | * @} 87 | */ 88 | 89 | #endif 90 | 91 | /** 92 | * @} 93 | */ 94 | 95 | /** 96 | * @} 97 | */ 98 | -------------------------------------------------------------------------------- /system/Drivers/Firmware/src/at32f403a_407_misc.c: -------------------------------------------------------------------------------- 1 | /** 2 | ************************************************************************** 3 | * @file at32f403a_407_misc.c 4 | * @version v2.0.9 5 | * @date 2022-04-25 6 | * @brief contains all the functions for the misc firmware library 7 | ************************************************************************** 8 | * Copyright notice & Disclaimer 9 | * 10 | * The software Board Support Package (BSP) that is made available to 11 | * download from Artery official website is the copyrighted work of Artery. 12 | * Artery authorizes customers to use, copy, and distribute the BSP 13 | * software and its related documentation for the purpose of design and 14 | * development in conjunction with Artery microcontrollers. Use of the 15 | * software is governed by this copyright notice and the following disclaimer. 16 | * 17 | * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, 18 | * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, 19 | * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR 20 | * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, 21 | * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. 23 | * 24 | ************************************************************************** 25 | */ 26 | 27 | /* includes ------------------------------------------------------------------*/ 28 | #include "at32f403a_407_conf.h" 29 | 30 | /** @addtogroup AT32F403A_407_periph_driver 31 | * @{ 32 | */ 33 | 34 | /** @defgroup MISC 35 | * @brief MISC driver modules 36 | * @{ 37 | */ 38 | 39 | #ifdef MISC_MODULE_ENABLED 40 | 41 | /** @defgroup MISC_private_functions 42 | * @{ 43 | */ 44 | 45 | #define AIRCR_VECTKEY_MASK ((uint32_t)0x05FA0000) 46 | 47 | /** 48 | * @brief system reset 49 | * @param none 50 | * @retval none 51 | */ 52 | void nvic_system_reset(void) 53 | { 54 | NVIC_SystemReset(); 55 | } 56 | 57 | /** 58 | * @brief enable nvic irq 59 | * @param irqn (IRQn_Type number) 60 | * @param preempt_priority: preemptive priority value (starting from 0) 61 | * @param sub_priority: subpriority value (starting from 0) 62 | * @retval none 63 | */ 64 | void nvic_irq_enable(IRQn_Type irqn, uint32_t preempt_priority, uint32_t sub_priority) 65 | { 66 | uint32_t temp_priority = 0; 67 | 68 | /* encode priority */ 69 | temp_priority = NVIC_EncodePriority(NVIC_GetPriorityGrouping(), preempt_priority, sub_priority); 70 | /* set priority */ 71 | NVIC_SetPriority(irqn, temp_priority); 72 | /* enable irqn */ 73 | NVIC_EnableIRQ(irqn); 74 | } 75 | 76 | /** 77 | * @brief disable nvic irq number 78 | * @param irqn (IRQn_Type number) 79 | * @retval none 80 | */ 81 | void nvic_irq_disable(IRQn_Type irqn) 82 | { 83 | NVIC_DisableIRQ(irqn); 84 | } 85 | 86 | /** 87 | * @brief config nvic priority group 88 | * @param priority_group 89 | * this parameter can be one of the following values: 90 | * - NVIC_PRIORITY_GROUP_0 91 | * - NVIC_PRIORITY_GROUP_1 92 | * - NVIC_PRIORITY_GROUP_2 93 | * - NVIC_PRIORITY_GROUP_3 94 | * - NVIC_PRIORITY_GROUP_4 95 | * @retval none 96 | */ 97 | void nvic_priority_group_config(nvic_priority_group_type priority_group) 98 | { 99 | /* set the prigroup[10:8] bits according to nvic_prioritygroup value */ 100 | NVIC_SetPriorityGrouping(priority_group); 101 | } 102 | 103 | /** 104 | * @brief set the vector table location and offset. 105 | * @param base 106 | * this parameter can be one of the following values: 107 | * - NVIC_VECTTAB_RAM 108 | * - NVIC_VECTTAB_FLASH 109 | * @param offset (vector table base offset field. this value must be a multiple of 0x200) 110 | * @retval none 111 | */ 112 | void nvic_vector_table_set(uint32_t base, uint32_t offset) 113 | { 114 | SCB->VTOR = base | (offset & (uint32_t)0x1FFFFF80); 115 | } 116 | 117 | /** 118 | * @brief config nvic lowpower mode 119 | * @param lp_mode 120 | * this parameter can be one of the following values: 121 | * - NVIC_LP_SEVONPEND 122 | * - NVIC_LP_SLEEPDEEP 123 | * - NVIC_LP_SLEEPONEXIT 124 | * @param new_state (new state of lp condition. ENABLE or DISABLE) 125 | * @retval none 126 | */ 127 | void nvic_lowpower_mode_config(nvic_lowpower_mode_type lp_mode, confirm_state new_state) 128 | { 129 | if(new_state != FALSE) 130 | { 131 | SCB->SCR |= lp_mode; 132 | } 133 | else 134 | { 135 | SCB->SCR &= (uint32_t)(~(uint32_t)lp_mode); 136 | } 137 | } 138 | 139 | /** 140 | * @brief config systick clock source 141 | * @param source 142 | * this parameter can be one of the following values: 143 | * - SYSTICK_CLOCK_SOURCE_AHBCLK_DIV8 144 | * - SYSTICK_CLOCK_SOURCE_AHBCLK_NODIV 145 | * @retval none 146 | */ 147 | void systick_clock_source_config(systick_clock_source_type source) 148 | { 149 | if(source == SYSTICK_CLOCK_SOURCE_AHBCLK_NODIV) 150 | { 151 | SysTick->CTRL |= SYSTICK_CLOCK_SOURCE_AHBCLK_NODIV; 152 | } 153 | else 154 | { 155 | SysTick->CTRL &= ~(uint32_t)SYSTICK_CLOCK_SOURCE_AHBCLK_NODIV; 156 | } 157 | } 158 | 159 | /** 160 | * @} 161 | */ 162 | 163 | #endif 164 | 165 | /** 166 | * @} 167 | */ 168 | 169 | /** 170 | * @} 171 | */ 172 | 173 | 174 | -------------------------------------------------------------------------------- /system/Drivers/Firmware/src/at32f403a_407_rtc.c: -------------------------------------------------------------------------------- 1 | /** 2 | ************************************************************************** 3 | * @file at32f403a_407_rtc.c 4 | * @version v2.0.9 5 | * @date 2022-04-25 6 | * @brief contains all the functions for the rtc firmware library 7 | ************************************************************************** 8 | * Copyright notice & Disclaimer 9 | * 10 | * The software Board Support Package (BSP) that is made available to 11 | * download from Artery official website is the copyrighted work of Artery. 12 | * Artery authorizes customers to use, copy, and distribute the BSP 13 | * software and its related documentation for the purpose of design and 14 | * development in conjunction with Artery microcontrollers. Use of the 15 | * software is governed by this copyright notice and the following disclaimer. 16 | * 17 | * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, 18 | * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, 19 | * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR 20 | * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, 21 | * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. 23 | * 24 | ************************************************************************** 25 | */ 26 | 27 | #include "at32f403a_407_conf.h" 28 | 29 | /** @addtogroup AT32F403A_407_periph_driver 30 | * @{ 31 | */ 32 | 33 | /** @defgroup RTC 34 | * @brief RTC driver modules 35 | * @{ 36 | */ 37 | 38 | #ifdef RTC_MODULE_ENABLED 39 | 40 | /** @defgroup RTC_private_functions 41 | * @{ 42 | */ 43 | 44 | /** 45 | * @brief rtc counter set 46 | * @param counter_value (0x0000_0000 ~ 0xFFFF_FFFF) 47 | * @retval none 48 | */ 49 | void rtc_counter_set(uint32_t counter_value) 50 | { 51 | /* enter rtc config mode */ 52 | RTC->ctrll = 0x003F; 53 | 54 | /* set rtc counter */ 55 | RTC->cnth_bit.cnt = (uint16_t)(counter_value >> 16); 56 | RTC->cntl_bit.cnt = (uint16_t)(counter_value & 0x0000FFFF); 57 | 58 | /* exit rtc config mode */ 59 | RTC->ctrll = 0x000F; 60 | } 61 | 62 | /** 63 | * @brief rtc counter get 64 | * @param none 65 | * @retval rtc counter 66 | */ 67 | uint32_t rtc_counter_get(void) 68 | { 69 | uint32_t cnt = 0; 70 | 71 | cnt = RTC->cnth; 72 | cnt = (cnt << 16) | RTC->cntl; 73 | 74 | return cnt; 75 | } 76 | 77 | /** 78 | * @brief rtc divider set 79 | * @param div_value (0x0000_0000 ~ 0xFFFF_FFFF) 80 | * @retval none 81 | */ 82 | void rtc_divider_set(uint32_t div_value) 83 | { 84 | /* enter rtc config mode */ 85 | RTC->ctrll = 0x003F; 86 | 87 | /* set rtc divider */ 88 | RTC->divh_bit.div = (uint16_t)(div_value >> 16); 89 | RTC->divl_bit.div = (uint16_t)(div_value & 0x0000FFFF); 90 | 91 | /* exit rtc config mode */ 92 | RTC->ctrll = 0x000F; 93 | } 94 | 95 | /** 96 | * @brief rtc divider get 97 | * @param none 98 | * @retval rtc counter 99 | */ 100 | uint32_t rtc_divider_get(void) 101 | { 102 | uint32_t div = 0; 103 | 104 | div = RTC->divcnth; 105 | div = (div << 16) | RTC->divcntl; 106 | 107 | return div; 108 | } 109 | 110 | /** 111 | * @brief rtc alarm value set 112 | * @param alarm_value (0x0000_0000 ~ 0xFFFF_FFFF) 113 | * @retval none 114 | */ 115 | void rtc_alarm_set(uint32_t alarm_value) 116 | { 117 | /* enter rtc config mode */ 118 | RTC->ctrll = 0x003F; 119 | 120 | /* set rtc alarm value */ 121 | RTC->tah_bit.ta = (uint16_t)(alarm_value >> 16); 122 | RTC->tal_bit.ta = (uint16_t)(alarm_value & 0x0000FFFF); 123 | 124 | /* exit rtc config mode */ 125 | RTC->ctrll = 0x000F; 126 | } 127 | 128 | /** 129 | * @brief rtc interrupt enable 130 | * @param source 131 | * this parameter can be any combination of the following values: 132 | * - RTC_TS_INT: time second interrupt. 133 | * - RTC_TA_INT: time alarm interrupt. 134 | * - RTC_OVF_INT: overflow interrupt. 135 | * @param new_state (TRUE or FALSE) 136 | * @retval none 137 | */ 138 | void rtc_interrupt_enable(uint16_t source, confirm_state new_state) 139 | { 140 | if(new_state == FALSE) 141 | { 142 | RTC->ctrlh &= ~source; 143 | } 144 | else 145 | { 146 | RTC->ctrlh |= source; 147 | } 148 | } 149 | 150 | /** 151 | * @brief rtc flag get 152 | * @param flag 153 | * this parameter can be one of the following values: 154 | * - RTC_TS_FLAG: time second flag. 155 | * - RTC_TA_FLAG: time alarm flag. 156 | * - RTC_OVF_FLAG: overflow flag. 157 | * - RTC_UPDF_FLAG: rtc update finish flag. 158 | * - RTC_CFGF_FLAG: rtc configuration finish flag. 159 | * @retval state of rtc flag 160 | */ 161 | flag_status rtc_flag_get(uint16_t flag) 162 | { 163 | flag_status status = RESET; 164 | 165 | if ((RTC->ctrll & flag) != (uint16_t)RESET) 166 | { 167 | status = SET; 168 | } 169 | else 170 | { 171 | status = RESET; 172 | } 173 | 174 | return status; 175 | } 176 | 177 | /** 178 | * @brief rtc flag clear 179 | * @param interrupt_flag 180 | * this parameter can be any combination of the following values: 181 | * - RTC_TS_FLAG: time second flag. 182 | * - RTC_TA_FLAG: time alarm flag. 183 | * - RTC_OVF_FLAG: overflow flag. 184 | * - RTC_CFGF_FLAG: rtc configuration finish flag. 185 | * @retval none 186 | */ 187 | void rtc_flag_clear(uint16_t flag) 188 | { 189 | RTC->ctrll = ~(flag | 0x10) | (RTC->ctrll_bit.cfgen << 4); 190 | } 191 | 192 | /** 193 | * @brief rtc wait configuration finish 194 | * @param none 195 | * @retval none 196 | */ 197 | void rtc_wait_config_finish(void) 198 | { 199 | while (RTC->ctrll_bit.cfgf == 0); 200 | } 201 | 202 | /** 203 | * @brief rtc wait update finish 204 | * @param none 205 | * @retval none 206 | */ 207 | void rtc_wait_update_finish(void) 208 | { 209 | while (RTC->ctrll_bit.updf == 0); 210 | } 211 | 212 | /** 213 | * @} 214 | */ 215 | 216 | #endif 217 | 218 | /** 219 | * @} 220 | */ 221 | 222 | /** 223 | * @} 224 | */ 225 | -------------------------------------------------------------------------------- /system/Drivers/Firmware/src/at32f403a_407_wdt.c: -------------------------------------------------------------------------------- 1 | /** 2 | ************************************************************************** 3 | * @file at32f403a_407_wdt.c 4 | * @version v2.0.9 5 | * @date 2022-04-25 6 | * @brief contains all the functions for the wdt firmware library 7 | ************************************************************************** 8 | * Copyright notice & Disclaimer 9 | * 10 | * The software Board Support Package (BSP) that is made available to 11 | * download from Artery official website is the copyrighted work of Artery. 12 | * Artery authorizes customers to use, copy, and distribute the BSP 13 | * software and its related documentation for the purpose of design and 14 | * development in conjunction with Artery microcontrollers. Use of the 15 | * software is governed by this copyright notice and the following disclaimer. 16 | * 17 | * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, 18 | * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, 19 | * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR 20 | * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, 21 | * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. 23 | * 24 | ************************************************************************** 25 | */ 26 | 27 | #include "at32f403a_407_conf.h" 28 | 29 | /** @addtogroup AT32F403A_407_periph_driver 30 | * @{ 31 | */ 32 | 33 | /** @defgroup WDT 34 | * @brief WDT driver modules 35 | * @{ 36 | */ 37 | 38 | #ifdef WDT_MODULE_ENABLED 39 | 40 | /** @defgroup WDT_private_functions 41 | * @{ 42 | */ 43 | 44 | /** 45 | * @brief wdt enable ,the reload value will be sent to the counter 46 | * @param none 47 | * @retval none 48 | */ 49 | void wdt_enable(void) 50 | { 51 | WDT->cmd = WDT_CMD_ENABLE; 52 | } 53 | 54 | /** 55 | * @brief reload wdt counter 56 | * @param none 57 | * @retval none 58 | */ 59 | void wdt_counter_reload(void) 60 | { 61 | WDT->cmd = WDT_CMD_RELOAD; 62 | } 63 | 64 | /** 65 | * @brief set wdt counter reload value 66 | * @param reload_value (0x0000~0x0FFF) 67 | * @retval none 68 | */ 69 | void wdt_reload_value_set(uint16_t reload_value) 70 | { 71 | WDT->rld = reload_value; 72 | } 73 | 74 | /** 75 | * @brief set wdt division divider 76 | * @param division 77 | * this parameter can be one of the following values: 78 | * - WDT_CLK_DIV_4 79 | * - WDT_CLK_DIV_8 80 | * - WDT_CLK_DIV_16 81 | * - WDT_CLK_DIV_32 82 | * - WDT_CLK_DIV_64 83 | * - WDT_CLK_DIV_128 84 | * - WDT_CLK_DIV_256 85 | * @retval none 86 | */ 87 | void wdt_divider_set(wdt_division_type division) 88 | { 89 | WDT->div_bit.div = division; 90 | } 91 | 92 | /** 93 | * @brief enable or disable wdt cmd register write 94 | * @param new_state (TRUE or FALSE) 95 | * @retval none 96 | */ 97 | void wdt_register_write_enable( confirm_state new_state) 98 | { 99 | if(new_state == FALSE) 100 | { 101 | WDT->cmd = WDT_CMD_LOCK; 102 | } 103 | else 104 | { 105 | WDT->cmd = WDT_CMD_UNLOCK; 106 | } 107 | } 108 | 109 | /** 110 | * @brief get wdt flag 111 | * @param wdt_flag 112 | * this parameter can be one of the following values: 113 | * - WDT_DIVF_UPDATE_FLAG: division value update complete flag. 114 | * - WDT_RLDF_UPDATE_FLAG: reload value update complete flag. 115 | * @retval state of wdt flag 116 | */ 117 | flag_status wdt_flag_get(uint16_t wdt_flag) 118 | { 119 | flag_status status = RESET; 120 | 121 | if ((WDT->sts & wdt_flag) != (uint16_t)RESET) 122 | { 123 | status = SET; 124 | } 125 | else 126 | { 127 | status = RESET; 128 | } 129 | 130 | return status; 131 | } 132 | 133 | /** 134 | * @} 135 | */ 136 | 137 | #endif 138 | 139 | /** 140 | * @} 141 | */ 142 | 143 | /** 144 | * @} 145 | */ 146 | -------------------------------------------------------------------------------- /system/Drivers/Firmware/src/at32f403a_407_wwdt.c: -------------------------------------------------------------------------------- 1 | /** 2 | ************************************************************************** 3 | * @file at32f403a_407_wwdt.c 4 | * @version v2.0.9 5 | * @date 2022-04-25 6 | * @brief contains all the functions for the wwdt firmware library 7 | ************************************************************************** 8 | * Copyright notice & Disclaimer 9 | * 10 | * The software Board Support Package (BSP) that is made available to 11 | * download from Artery official website is the copyrighted work of Artery. 12 | * Artery authorizes customers to use, copy, and distribute the BSP 13 | * software and its related documentation for the purpose of design and 14 | * development in conjunction with Artery microcontrollers. Use of the 15 | * software is governed by this copyright notice and the following disclaimer. 16 | * 17 | * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, 18 | * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, 19 | * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR 20 | * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, 21 | * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. 23 | * 24 | ************************************************************************** 25 | */ 26 | 27 | #include "at32f403a_407_conf.h" 28 | 29 | /** @addtogroup AT32F403A_407_periph_driver 30 | * @{ 31 | */ 32 | 33 | /** @defgroup WWDT 34 | * @brief WWDT driver modules 35 | * @{ 36 | */ 37 | 38 | #ifdef WWDT_MODULE_ENABLED 39 | 40 | /** @defgroup WWDT_private_functions 41 | * @{ 42 | */ 43 | 44 | /** 45 | * @brief wwdt reset by crm reset register 46 | * @retval none 47 | */ 48 | void wwdt_reset(void) 49 | { 50 | crm_periph_reset(CRM_WWDT_PERIPH_RESET, TRUE); 51 | crm_periph_reset(CRM_WWDT_PERIPH_RESET, FALSE); 52 | } 53 | 54 | /** 55 | * @brief wwdt division set 56 | * @param division 57 | * this parameter can be one of the following values: 58 | * - WWDT_PCLK1_DIV_4096 (wwdt counter clock = (pclk1/4096)/1) 59 | * - WWDT_PCLK1_DIV_8192 (wwdt counter clock = (pclk1/4096)/2) 60 | * - WWDT_PCLK1_DIV_16384 (wwdt counter clock = (pclk1/4096)/4) 61 | * - WWDT_PCLK1_DIV_32768 (wwdt counter clock = (pclk1/4096)/8) 62 | * @retval none 63 | */ 64 | void wwdt_divider_set(wwdt_division_type division) 65 | { 66 | WWDT->cfg_bit.div = division; 67 | } 68 | 69 | /** 70 | * @brief wwdt reload counter interrupt flag clear 71 | * @param none 72 | * @retval none 73 | */ 74 | void wwdt_flag_clear(void) 75 | { 76 | WWDT->sts = 0; 77 | } 78 | 79 | /** 80 | * @brief wwdt enable and the counter value load 81 | * @param wwdt_cnt (0x40~0x7f) 82 | * @retval none 83 | */ 84 | void wwdt_enable(uint8_t wwdt_cnt) 85 | { 86 | WWDT->ctrl = wwdt_cnt | WWDT_EN_BIT; 87 | } 88 | 89 | /** 90 | * @brief wwdt reload counter interrupt enable 91 | * @param none 92 | * @retval none 93 | */ 94 | void wwdt_interrupt_enable(void) 95 | { 96 | WWDT->cfg_bit.rldien = TRUE; 97 | } 98 | 99 | /** 100 | * @brief wwdt reload counter interrupt flag get 101 | * @param none 102 | * @retval state of reload counter interrupt flag 103 | */ 104 | flag_status wwdt_flag_get(void) 105 | { 106 | return (flag_status)WWDT->sts_bit.rldf; 107 | } 108 | 109 | /** 110 | * @brief wwdt counter value set 111 | * @param wwdt_cnt (0x40~0x7f) 112 | * @retval none 113 | */ 114 | void wwdt_counter_set(uint8_t wwdt_cnt) 115 | { 116 | WWDT->ctrl_bit.cnt = wwdt_cnt; 117 | } 118 | 119 | /** 120 | * @brief wwdt window counter value set 121 | * @param window_cnt (0x40~0x7f) 122 | * @retval none 123 | */ 124 | void wwdt_window_counter_set(uint8_t window_cnt) 125 | { 126 | WWDT->cfg_bit.win = window_cnt; 127 | } 128 | 129 | /** 130 | * @} 131 | */ 132 | 133 | #endif 134 | 135 | /** 136 | * @} 137 | */ 138 | 139 | /** 140 | * @} 141 | */ 142 | -------------------------------------------------------------------------------- /variants/AT32F403ACGU7/FrameLib.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WeActStudio/ArduinoCore-AT32F4/e4686b837df3ae8b905f2466c456c21d2ea05f95/variants/AT32F403ACGU7/FrameLib.a -------------------------------------------------------------------------------- /variants/AT32F403ACGU7/at32f403a_407_conf.h: -------------------------------------------------------------------------------- 1 | /** 2 | ************************************************************************** 3 | * @file at32f403a_407_conf.h 4 | * @version v2.0.9 5 | * @date 2022-04-25 6 | * @brief at32f403a_407 config header file 7 | ************************************************************************** 8 | * Copyright notice & Disclaimer 9 | * 10 | * The software Board Support Package (BSP) that is made available to 11 | * download from Artery official website is the copyrighted work of Artery. 12 | * Artery authorizes customers to use, copy, and distribute the BSP 13 | * software and its related documentation for the purpose of design and 14 | * development in conjunction with Artery microcontrollers. Use of the 15 | * software is governed by this copyright notice and the following disclaimer. 16 | * 17 | * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, 18 | * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, 19 | * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR 20 | * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, 21 | * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. 23 | * 24 | ************************************************************************** 25 | */ 26 | 27 | /* define to prevent recursive inclusion -------------------------------------*/ 28 | #ifndef __AT32F403A_407_CONF_H 29 | #define __AT32F403A_407_CONF_H 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | 36 | /** 37 | * @brief in the following line adjust the value of high speed exernal crystal (hext) 38 | * used in your application 39 | * tip: to avoid modifying this file each time you need to use different hext, you 40 | * can define the hext value in your toolchain compiler preprocessor. 41 | */ 42 | #if !defined HEXT_VALUE 43 | #define HEXT_VALUE ((uint32_t)8000000) /*!< value of the high speed exernal crystal in hz */ 44 | #endif 45 | 46 | /** 47 | * @brief in the following line adjust the high speed exernal crystal (hext) startup 48 | * timeout value 49 | */ 50 | #define HEXT_STARTUP_TIMEOUT ((uint16_t)0x3000) /*!< time out for hext start up */ 51 | #define HICK_VALUE ((uint32_t)8000000) /*!< value of the high speed internal clock in hz */ 52 | 53 | /* module define -------------------------------------------------------------*/ 54 | #define CRM_MODULE_ENABLED 55 | #define TMR_MODULE_ENABLED 56 | #define RTC_MODULE_ENABLED 57 | #define BPR_MODULE_ENABLED 58 | #define GPIO_MODULE_ENABLED 59 | #define I2C_MODULE_ENABLED 60 | #define USART_MODULE_ENABLED 61 | #define PWC_MODULE_ENABLED 62 | #define CAN_MODULE_ENABLED 63 | #define ADC_MODULE_ENABLED 64 | #define DAC_MODULE_ENABLED 65 | #define SPI_MODULE_ENABLED 66 | #define DMA_MODULE_ENABLED 67 | #define DEBUG_MODULE_ENABLED 68 | #define FLASH_MODULE_ENABLED 69 | #define CRC_MODULE_ENABLED 70 | #define WWDT_MODULE_ENABLED 71 | #define WDT_MODULE_ENABLED 72 | #define EXINT_MODULE_ENABLED 73 | #define SDIO_MODULE_ENABLED 74 | #define XMC_MODULE_ENABLED 75 | #define USB_MODULE_ENABLED 76 | #define ACC_MODULE_ENABLED 77 | #define MISC_MODULE_ENABLED 78 | #define EMAC_MODULE_ENABLED 79 | 80 | /* includes ------------------------------------------------------------------*/ 81 | #ifdef CRM_MODULE_ENABLED 82 | #include "at32f403a_407_crm.h" 83 | #endif 84 | #ifdef TMR_MODULE_ENABLED 85 | #include "at32f403a_407_tmr.h" 86 | #endif 87 | #ifdef RTC_MODULE_ENABLED 88 | #include "at32f403a_407_rtc.h" 89 | #endif 90 | #ifdef BPR_MODULE_ENABLED 91 | #include "at32f403a_407_bpr.h" 92 | #endif 93 | #ifdef GPIO_MODULE_ENABLED 94 | #include "at32f403a_407_gpio.h" 95 | #endif 96 | #ifdef I2C_MODULE_ENABLED 97 | #include "at32f403a_407_i2c.h" 98 | #endif 99 | #ifdef USART_MODULE_ENABLED 100 | #include "at32f403a_407_usart.h" 101 | #endif 102 | #ifdef PWC_MODULE_ENABLED 103 | #include "at32f403a_407_pwc.h" 104 | #endif 105 | #ifdef CAN_MODULE_ENABLED 106 | #include "at32f403a_407_can.h" 107 | #endif 108 | #ifdef ADC_MODULE_ENABLED 109 | #include "at32f403a_407_adc.h" 110 | #endif 111 | #ifdef DAC_MODULE_ENABLED 112 | #include "at32f403a_407_dac.h" 113 | #endif 114 | #ifdef SPI_MODULE_ENABLED 115 | #include "at32f403a_407_spi.h" 116 | #endif 117 | #ifdef DMA_MODULE_ENABLED 118 | #include "at32f403a_407_dma.h" 119 | #endif 120 | #ifdef DEBUG_MODULE_ENABLED 121 | #include "at32f403a_407_debug.h" 122 | #endif 123 | #ifdef FLASH_MODULE_ENABLED 124 | #include "at32f403a_407_flash.h" 125 | #endif 126 | #ifdef CRC_MODULE_ENABLED 127 | #include "at32f403a_407_crc.h" 128 | #endif 129 | #ifdef WWDT_MODULE_ENABLED 130 | #include "at32f403a_407_wwdt.h" 131 | #endif 132 | #ifdef WDT_MODULE_ENABLED 133 | #include "at32f403a_407_wdt.h" 134 | #endif 135 | #ifdef EXINT_MODULE_ENABLED 136 | #include "at32f403a_407_exint.h" 137 | #endif 138 | #ifdef SDIO_MODULE_ENABLED 139 | #include "at32f403a_407_sdio.h" 140 | #endif 141 | #ifdef XMC_MODULE_ENABLED 142 | #include "at32f403a_407_xmc.h" 143 | #endif 144 | #ifdef ACC_MODULE_ENABLED 145 | #include "at32f403a_407_acc.h" 146 | #endif 147 | #ifdef MISC_MODULE_ENABLED 148 | #include "at32f403a_407_misc.h" 149 | #endif 150 | #ifdef USB_MODULE_ENABLED 151 | #include "at32f403a_407_usb.h" 152 | #endif 153 | #ifdef EMAC_MODULE_ENABLED 154 | #include "at32f403a_407_emac.h" 155 | #endif 156 | 157 | #ifdef __cplusplus 158 | } 159 | #endif 160 | 161 | #endif /* __AT32F403A_407_CONF_H */ 162 | 163 | 164 | -------------------------------------------------------------------------------- /variants/AT32F403ACGU7/at32f403a_407_conf_template.h: -------------------------------------------------------------------------------- 1 | /** 2 | ************************************************************************** 3 | * @file at32f403a_407_conf.h 4 | * @version v2.0.9 5 | * @date 2022-04-25 6 | * @brief at32f403a_407 config header file 7 | ************************************************************************** 8 | * Copyright notice & Disclaimer 9 | * 10 | * The software Board Support Package (BSP) that is made available to 11 | * download from Artery official website is the copyrighted work of Artery. 12 | * Artery authorizes customers to use, copy, and distribute the BSP 13 | * software and its related documentation for the purpose of design and 14 | * development in conjunction with Artery microcontrollers. Use of the 15 | * software is governed by this copyright notice and the following disclaimer. 16 | * 17 | * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, 18 | * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, 19 | * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR 20 | * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, 21 | * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. 23 | * 24 | ************************************************************************** 25 | */ 26 | 27 | /* define to prevent recursive inclusion -------------------------------------*/ 28 | #ifndef __AT32F403A_407_CONF_H 29 | #define __AT32F403A_407_CONF_H 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | 36 | /** 37 | * @brief in the following line adjust the value of high speed exernal crystal (hext) 38 | * used in your application 39 | * tip: to avoid modifying this file each time you need to use different hext, you 40 | * can define the hext value in your toolchain compiler preprocessor. 41 | */ 42 | #if !defined HEXT_VALUE 43 | #define HEXT_VALUE ((uint32_t)8000000) /*!< value of the high speed exernal crystal in hz */ 44 | #endif 45 | 46 | /** 47 | * @brief in the following line adjust the high speed exernal crystal (hext) startup 48 | * timeout value 49 | */ 50 | #define HEXT_STARTUP_TIMEOUT ((uint16_t)0x3000) /*!< time out for hext start up */ 51 | #define HICK_VALUE ((uint32_t)8000000) /*!< value of the high speed internal clock in hz */ 52 | 53 | /* module define -------------------------------------------------------------*/ 54 | #define CRM_MODULE_ENABLED 55 | #define TMR_MODULE_ENABLED 56 | #define RTC_MODULE_ENABLED 57 | #define BPR_MODULE_ENABLED 58 | #define GPIO_MODULE_ENABLED 59 | #define I2C_MODULE_ENABLED 60 | #define USART_MODULE_ENABLED 61 | #define PWC_MODULE_ENABLED 62 | #define CAN_MODULE_ENABLED 63 | #define ADC_MODULE_ENABLED 64 | #define DAC_MODULE_ENABLED 65 | #define SPI_MODULE_ENABLED 66 | #define DMA_MODULE_ENABLED 67 | #define DEBUG_MODULE_ENABLED 68 | #define FLASH_MODULE_ENABLED 69 | #define CRC_MODULE_ENABLED 70 | #define WWDT_MODULE_ENABLED 71 | #define WDT_MODULE_ENABLED 72 | #define EXINT_MODULE_ENABLED 73 | #define SDIO_MODULE_ENABLED 74 | #define XMC_MODULE_ENABLED 75 | #define USB_MODULE_ENABLED 76 | #define ACC_MODULE_ENABLED 77 | #define MISC_MODULE_ENABLED 78 | #define EMAC_MODULE_ENABLED 79 | 80 | /* includes ------------------------------------------------------------------*/ 81 | #ifdef CRM_MODULE_ENABLED 82 | #include "at32f403a_407_crm.h" 83 | #endif 84 | #ifdef TMR_MODULE_ENABLED 85 | #include "at32f403a_407_tmr.h" 86 | #endif 87 | #ifdef RTC_MODULE_ENABLED 88 | #include "at32f403a_407_rtc.h" 89 | #endif 90 | #ifdef BPR_MODULE_ENABLED 91 | #include "at32f403a_407_bpr.h" 92 | #endif 93 | #ifdef GPIO_MODULE_ENABLED 94 | #include "at32f403a_407_gpio.h" 95 | #endif 96 | #ifdef I2C_MODULE_ENABLED 97 | #include "at32f403a_407_i2c.h" 98 | #endif 99 | #ifdef USART_MODULE_ENABLED 100 | #include "at32f403a_407_usart.h" 101 | #endif 102 | #ifdef PWC_MODULE_ENABLED 103 | #include "at32f403a_407_pwc.h" 104 | #endif 105 | #ifdef CAN_MODULE_ENABLED 106 | #include "at32f403a_407_can.h" 107 | #endif 108 | #ifdef ADC_MODULE_ENABLED 109 | #include "at32f403a_407_adc.h" 110 | #endif 111 | #ifdef DAC_MODULE_ENABLED 112 | #include "at32f403a_407_dac.h" 113 | #endif 114 | #ifdef SPI_MODULE_ENABLED 115 | #include "at32f403a_407_spi.h" 116 | #endif 117 | #ifdef DMA_MODULE_ENABLED 118 | #include "at32f403a_407_dma.h" 119 | #endif 120 | #ifdef DEBUG_MODULE_ENABLED 121 | #include "at32f403a_407_debug.h" 122 | #endif 123 | #ifdef FLASH_MODULE_ENABLED 124 | #include "at32f403a_407_flash.h" 125 | #endif 126 | #ifdef CRC_MODULE_ENABLED 127 | #include "at32f403a_407_crc.h" 128 | #endif 129 | #ifdef WWDT_MODULE_ENABLED 130 | #include "at32f403a_407_wwdt.h" 131 | #endif 132 | #ifdef WDT_MODULE_ENABLED 133 | #include "at32f403a_407_wdt.h" 134 | #endif 135 | #ifdef EXINT_MODULE_ENABLED 136 | #include "at32f403a_407_exint.h" 137 | #endif 138 | #ifdef SDIO_MODULE_ENABLED 139 | #include "at32f403a_407_sdio.h" 140 | #endif 141 | #ifdef XMC_MODULE_ENABLED 142 | #include "at32f403a_407_xmc.h" 143 | #endif 144 | #ifdef ACC_MODULE_ENABLED 145 | #include "at32f403a_407_acc.h" 146 | #endif 147 | #ifdef MISC_MODULE_ENABLED 148 | #include "at32f403a_407_misc.h" 149 | #endif 150 | #ifdef USB_MODULE_ENABLED 151 | #include "at32f403a_407_usb.h" 152 | #endif 153 | #ifdef EMAC_MODULE_ENABLED 154 | #include "at32f403a_407_emac.h" 155 | #endif 156 | 157 | #ifdef __cplusplus 158 | } 159 | #endif 160 | 161 | #endif /* __AT32F403A_407_CONF_H */ 162 | 163 | 164 | -------------------------------------------------------------------------------- /variants/AT32F403ACGU7/linker_scripts/AT32F403AxG_FLASH.ld: -------------------------------------------------------------------------------- 1 | /* 2 | ***************************************************************************** 3 | ** 4 | ** File : AT32F403AxG_FLASH.ld 5 | ** 6 | ** Abstract : Linker script for AT32F403AxG Device with 7 | ** 1000KByte FLASH, 96KByte RAM 8 | ** 9 | ** Set heap size, stack size and stack location according 10 | ** to application requirements. 11 | ** 12 | ** Set memory bank area and size if external memory is used. 13 | ** 14 | ** Target : Artery Tek AT32 15 | ** 16 | ** Environment : Arm gcc toolchain 17 | ** 18 | ***************************************************************************** 19 | */ 20 | 21 | /* Entry Point */ 22 | ENTRY(Reset_Handler) 23 | 24 | /* Highest address of the user mode stack */ 25 | _estack = 0x20018000; /* end of RAM */ 26 | 27 | /* Generate a link error if heap and stack don't fit into RAM */ 28 | _Min_Heap_Size = 0x200; /* required amount of heap */ 29 | _Min_Stack_Size = 0x400; /* required amount of stack */ 30 | 31 | /* Specify the memory areas */ 32 | MEMORY 33 | { 34 | FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 1000K 35 | RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 96K 36 | } 37 | 38 | /* Define output sections */ 39 | SECTIONS 40 | { 41 | /* The startup code goes first into FLASH */ 42 | .isr_vector : 43 | { 44 | . = ALIGN(4); 45 | KEEP(*(.isr_vector)) /* Startup code */ 46 | . = ALIGN(4); 47 | } >FLASH 48 | 49 | /* The program code and other data goes into FLASH */ 50 | .text : 51 | { 52 | . = ALIGN(4); 53 | *(.text) /* .text sections (code) */ 54 | *(.text*) /* .text* sections (code) */ 55 | *(.glue_7) /* glue arm to thumb code */ 56 | *(.glue_7t) /* glue thumb to arm code */ 57 | *(.eh_frame) 58 | 59 | KEEP (*(.init)) 60 | KEEP (*(.fini)) 61 | 62 | . = ALIGN(4); 63 | _etext = .; /* define a global symbols at end of code */ 64 | } >FLASH 65 | 66 | /* Constant data goes into FLASH */ 67 | .rodata : 68 | { 69 | . = ALIGN(4); 70 | *(.rodata) /* .rodata sections (constants, strings, etc.) */ 71 | *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ 72 | . = ALIGN(4); 73 | } >FLASH 74 | 75 | .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH 76 | .ARM : { 77 | __exidx_start = .; 78 | *(.ARM.exidx*) 79 | __exidx_end = .; 80 | } >FLASH 81 | 82 | .preinit_array : 83 | { 84 | PROVIDE_HIDDEN (__preinit_array_start = .); 85 | KEEP (*(.preinit_array*)) 86 | PROVIDE_HIDDEN (__preinit_array_end = .); 87 | } >FLASH 88 | .init_array : 89 | { 90 | PROVIDE_HIDDEN (__init_array_start = .); 91 | KEEP (*(SORT(.init_array.*))) 92 | KEEP (*(.init_array*)) 93 | PROVIDE_HIDDEN (__init_array_end = .); 94 | } >FLASH 95 | .fini_array : 96 | { 97 | PROVIDE_HIDDEN (__fini_array_start = .); 98 | KEEP (*(SORT(.fini_array.*))) 99 | KEEP (*(.fini_array*)) 100 | PROVIDE_HIDDEN (__fini_array_end = .); 101 | } >FLASH 102 | 103 | /* used by the startup to initialize data */ 104 | _sidata = LOADADDR(.data); 105 | 106 | /* Initialized data sections goes into RAM, load LMA copy after code */ 107 | .data : 108 | { 109 | . = ALIGN(4); 110 | _sdata = .; /* create a global symbol at data start */ 111 | *(.data) /* .data sections */ 112 | *(.data*) /* .data* sections */ 113 | 114 | . = ALIGN(4); 115 | _edata = .; /* define a global symbol at data end */ 116 | } >RAM AT> FLASH 117 | 118 | /* Uninitialized data section */ 119 | . = ALIGN(4); 120 | .bss : 121 | { 122 | /* This is used by the startup in order to initialize the .bss secion */ 123 | _sbss = .; /* define a global symbol at bss start */ 124 | __bss_start__ = _sbss; 125 | *(.bss) 126 | *(.bss*) 127 | *(COMMON) 128 | 129 | . = ALIGN(4); 130 | _ebss = .; /* define a global symbol at bss end */ 131 | __bss_end__ = _ebss; 132 | } >RAM 133 | 134 | /* User_heap_stack section, used to check that there is enough RAM left */ 135 | ._user_heap_stack : 136 | { 137 | . = ALIGN(8); 138 | PROVIDE ( end = . ); 139 | PROVIDE ( _end = . ); 140 | . = . + _Min_Heap_Size; 141 | . = . + _Min_Stack_Size; 142 | . = ALIGN(8); 143 | } >RAM 144 | 145 | /* Remove information from the standard libraries */ 146 | /DISCARD/ : 147 | { 148 | libc.a ( * ) 149 | libm.a ( * ) 150 | libgcc.a ( * ) 151 | } 152 | 153 | .ARM.attributes 0 : { *(.ARM.attributes) } 154 | } 155 | --------------------------------------------------------------------------------