From 852ec90e6b1c69d77ccbc5efa49fa44923d14f66 Mon Sep 17 00:00:00 2001 From: retr0 <42kdesigners@gmail.com> Date: Thu, 16 Apr 2026 19:10:31 +0200 Subject: [PATCH] ShineLAN-X: Initiale Firmware + Hardware-Diagnose MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - STM32F103RBT6 Firmware für Growatt ShineLAN-X - Bitbang-SPI (EthernetENC) auf Port C (PC6/PC7/PC8/PC9) - UART-Debug auf USART1 (PA9/PA10), Modbus temporär deaktiviert - SO-Aktivitätstest und ESTAT-Register-Scan bestätigen: ENC28J60 läuft (SO aktiv), SI/MOSI-Verbindung unterbrochen - Nächster Schritt: Pin 5 ENC28J60 nachlöten oder Bodge-Draht Co-Authored-By: Claude Sonnet 4.6 --- Growatt ShineLAN-X/README.md | 117 + Growatt ShineLAN-X/STM32F103.log | 9379 +++++++++++++++++ Growatt ShineLAN-X/firmware/.gitignore | 5 + Growatt ShineLAN-X/firmware/include/config.h | 57 + .../firmware/include/enc28j60_bitbang.h | 29 + .../firmware/lib/EthernetENC/.piopm | 1 + .../firmware/lib/EthernetENC/README.md | 158 + .../lib/EthernetENC/library.properties | 11 + .../firmware/lib/EthernetENC/src/Dhcp.cpp | 491 + .../firmware/lib/EthernetENC/src/Dhcp.h | 189 + .../firmware/lib/EthernetENC/src/Dns.cpp | 416 + .../firmware/lib/EthernetENC/src/Dns.h | 41 + .../firmware/lib/EthernetENC/src/Ethernet.cpp | 559 + .../firmware/lib/EthernetENC/src/Ethernet.h | 161 + .../lib/EthernetENC/src/EthernetClient.cpp | 663 ++ .../lib/EthernetENC/src/EthernetClient.h | 110 + .../lib/EthernetENC/src/EthernetENC.h | 1 + .../lib/EthernetENC/src/EthernetServer.cpp | 112 + .../lib/EthernetENC/src/EthernetServer.h | 55 + .../lib/EthernetENC/src/EthernetUdp.cpp | 424 + .../lib/EthernetENC/src/EthernetUdp.h | 139 + .../firmware/lib/EthernetENC/src/tcp_states.h | 21 + .../src/utility/Enc28J60Network.cpp | 391 + .../EthernetENC/src/utility/Enc28J60Network.h | 94 + .../lib/EthernetENC/src/utility/enc28j60.h | 257 + .../lib/EthernetENC/src/utility/mempool.cpp | 168 + .../lib/EthernetENC/src/utility/mempool.h | 54 + .../EthernetENC/src/utility/mempool_conf.h | 34 + .../lib/EthernetENC/src/utility/uip-conf.h | 185 + .../lib/EthernetENC/src/utility/uip.c | 1897 ++++ .../lib/EthernetENC/src/utility/uip.h | 1601 +++ .../lib/EthernetENC/src/utility/uip_arch.h | 138 + .../lib/EthernetENC/src/utility/uip_arp.c | 422 + .../lib/EthernetENC/src/utility/uip_arp.h | 144 + .../src/utility/uipethernet-conf.h | 48 + .../lib/EthernetENC/src/utility/uipopt.h | 555 + .../lib/EthernetENC/src/utility/util.h | 10 + Growatt ShineLAN-X/firmware/platformio.ini | 16 + Growatt ShineLAN-X/firmware/src/main.cpp | 292 + 39 files changed, 19445 insertions(+) create mode 100644 Growatt ShineLAN-X/README.md create mode 100644 Growatt ShineLAN-X/STM32F103.log create mode 100644 Growatt ShineLAN-X/firmware/.gitignore create mode 100644 Growatt ShineLAN-X/firmware/include/config.h create mode 100644 Growatt ShineLAN-X/firmware/include/enc28j60_bitbang.h create mode 100644 Growatt ShineLAN-X/firmware/lib/EthernetENC/.piopm create mode 100644 Growatt ShineLAN-X/firmware/lib/EthernetENC/README.md create mode 100644 Growatt ShineLAN-X/firmware/lib/EthernetENC/library.properties create mode 100644 Growatt ShineLAN-X/firmware/lib/EthernetENC/src/Dhcp.cpp create mode 100644 Growatt ShineLAN-X/firmware/lib/EthernetENC/src/Dhcp.h create mode 100644 Growatt ShineLAN-X/firmware/lib/EthernetENC/src/Dns.cpp create mode 100644 Growatt ShineLAN-X/firmware/lib/EthernetENC/src/Dns.h create mode 100644 Growatt ShineLAN-X/firmware/lib/EthernetENC/src/Ethernet.cpp create mode 100644 Growatt ShineLAN-X/firmware/lib/EthernetENC/src/Ethernet.h create mode 100644 Growatt ShineLAN-X/firmware/lib/EthernetENC/src/EthernetClient.cpp create mode 100644 Growatt ShineLAN-X/firmware/lib/EthernetENC/src/EthernetClient.h create mode 100644 Growatt ShineLAN-X/firmware/lib/EthernetENC/src/EthernetENC.h create mode 100644 Growatt ShineLAN-X/firmware/lib/EthernetENC/src/EthernetServer.cpp create mode 100644 Growatt ShineLAN-X/firmware/lib/EthernetENC/src/EthernetServer.h create mode 100644 Growatt ShineLAN-X/firmware/lib/EthernetENC/src/EthernetUdp.cpp create mode 100644 Growatt ShineLAN-X/firmware/lib/EthernetENC/src/EthernetUdp.h create mode 100644 Growatt ShineLAN-X/firmware/lib/EthernetENC/src/tcp_states.h create mode 100644 Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/Enc28J60Network.cpp create mode 100644 Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/Enc28J60Network.h create mode 100644 Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/enc28j60.h create mode 100644 Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/mempool.cpp create mode 100644 Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/mempool.h create mode 100644 Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/mempool_conf.h create mode 100644 Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/uip-conf.h create mode 100644 Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/uip.c create mode 100644 Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/uip.h create mode 100644 Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/uip_arch.h create mode 100644 Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/uip_arp.c create mode 100644 Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/uip_arp.h create mode 100644 Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/uipethernet-conf.h create mode 100644 Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/uipopt.h create mode 100644 Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/util.h create mode 100644 Growatt ShineLAN-X/firmware/platformio.ini create mode 100644 Growatt ShineLAN-X/firmware/src/main.cpp diff --git a/Growatt ShineLAN-X/README.md b/Growatt ShineLAN-X/README.md new file mode 100644 index 0000000..53283a0 --- /dev/null +++ b/Growatt ShineLAN-X/README.md @@ -0,0 +1,117 @@ +# Growatt ShineLAN-X — Custom Firmware + +Custom-Firmware für den **Growatt ShineLAN-X** LAN-Stick. Liest Modbus RTU vom Wechselrichter und publiziert alle Werte per **MQTT** in Home Assistant — vollständig lokal, ohne Growatt-Cloud. + +--- + +## Hardware + +| Komponente | Details | +|---|---| +| MCU | STM32F103 (LQFP48) | +| Ethernet | Unbekannt — vermutlich W5500 (SPI) — **TODO: PCB prüfen** | +| RS485 | Transceiver auf Platine — **TODO: Chip-Bezeichnung prüfen** | +| Programmier-Interface | SWD (SWDIO, SWDCLK, GND, 3.3V) | +| Anschluss | RJ45 (Ethernet) + RS485-Port am Wechselrichter | + +### Pin-Belegung (TODO — muss durch PCB-Analyse bestätigt werden) + +| Funktion | STM32 Pin | Hinweis | +|---|---|---| +| SPI SCK | PA5 | SPI1, fest | +| SPI MISO | PA6 | SPI1, fest | +| SPI MOSI | PA7 | SPI1, fest | +| ETH CS | PA4 | TODO: nachmessen | +| ETH RST | PB1 | TODO: nachmessen | +| RS485 DE/RE | PB0 | TODO: nachmessen | +| Modbus TX | PA9 | USART1, fest | +| Modbus RX | PA10 | USART1, fest | +| Debug TX | PA2 | USART2 (optional) | + +> **Wichtig:** Die mit TODO markierten Pins müssen durch Nachmessen mit einem Multimeter auf der PCB bestätigt werden, bevor die Firmware geflasht wird. Falsche Pins beschädigen nichts, aber die Firmware funktioniert nicht. + +--- + +## Voraussetzungen + +- [PlatformIO](https://platformio.org/) (VS Code Extension oder CLI) +- ST-Link V2 Adapter (zum Flashen via SWD) +- ShineLAN-X geöffnet und SWD-Pins angelötet oder angeklemmt + +### SWD-Verkabelung + +| ShineLAN-X | ST-Link V2 | +|---|---| +| SWDIO | SWDIO | +| SWDCLK | SWCLK | +| GND | GND | +| 3.3V | 3.3V (nur wenn nicht extern versorgt) | + +--- + +## Konfiguration + +Alle Einstellungen in `firmware/include/config.h` anpassen: + +```cpp +// MQTT-Broker IP +#define MQTT_BROKER "192.168.1.x" + +// DHCP (1) oder statische IP (0) +#define USE_DHCP 1 + +// Modbus Slave-Adresse des Wechselrichters (Standard: 1) +#define MODBUS_ADDR 1 +``` + +--- + +## Flashen + +```bash +cd firmware +pio run --target upload +``` + +Nach dem ersten Flash sind weitere Updates ebenfalls per ST-Link möglich, solange die SWD-Pins zugänglich sind. + +--- + +## MQTT Topics + +Nach dem Start sendet die Firmware automatisch **MQTT Discovery** Pakete — Home Assistant erkennt das Gerät sofort ohne manuelle Konfiguration. + +| Topic | Inhalt | +|---|---| +| `homeassistant/sensor/growatt_shinelan_*/config` | Discovery (retained) | +| `growatt/shinelan/pv1_power` | PV1 Leistung in W | +| `growatt/shinelan/energy_total` | PV Gesamtenergie in kWh | +| `growatt/shinelan/bat_soc` | Batterie Ladestand in % | +| `growatt/shinelan/energy_import_total` | Netzbezug gesamt in kWh | +| … | alle weiteren Sensoren analog | + +--- + +## Unterstützte Sensoren + +Alle Sensoren entsprechen den Modbus-Registern des **Growatt SPH 5000 TL3-BH-UP**. +Für andere Modelle (z.B. MIC 1500 ohne Batterie) können nicht vorhandene Sensoren in `main.cpp` auskommentiert werden — fehlerhafte Modbus-Reads werden automatisch übersprungen. + +| Sensor | Register | Einheit | state_class | +|---|---|---|---| +| PV1/PV2 Voltage | 3, 7 | V | measurement | +| PV1/PV2 Current | 4, 8 | A | measurement | +| PV1/PV2 Power | 5, 9 | W | measurement | +| AC Output Power Total | 35 | W | measurement | +| Grid Frequency | 37 | Hz | measurement | +| Grid Voltage L1/L2/L3 | 38, 42, 46 | V | measurement | +| Grid Current L1/L2/L3 | 39, 43, 47 | A | measurement | +| Energy Today | 53 | kWh | total_increasing | +| Energy Total | 55 | kWh | total_increasing | +| Inverter Temperature | 93 | °C | measurement | +| Battery Discharge/Charge Power | 1009, 1011 | W | measurement | +| Battery Voltage | 1013 | V | measurement | +| Battery State of Charge | 1014 | % | measurement | +| Battery Temperature | 1040 | °C | measurement | +| Energy Import/Export Total | 1046, 1050 | kWh | total_increasing | +| Battery Discharge/Charge Total | 1054, 1058 | kWh | total_increasing | diff --git a/Growatt ShineLAN-X/STM32F103.log b/Growatt ShineLAN-X/STM32F103.log new file mode 100644 index 0000000..71a3576 --- /dev/null +++ b/Growatt ShineLAN-X/STM32F103.log @@ -0,0 +1,9379 @@ +Peripheral :Control +Name Value Access Address +ACTLR 0x00000000 read-write @ 0xE000E008 + DISFOLD 0 + DISDEFWBUF 0 + DISMCYCINT 0 + +ICSR 0x00000000 read-write @ 0xE000ED04 + NMIPENDSET 0 + PENDSVSET 0 + PENDSVCLR 0 + PENDSTSET 0 + PENDSTCLR 0 + ISRPREEMPT 0 + ISRPENDING 0 + VECTPENDING 0x0 + RETTOBASE 0 + VECTACTIVE 0x0 + +VTOR 0x00000000 read-write @ 0xE000ED08 + TBLOFF 0x0 + TBLBASE 0 + +DEMCR 0x00000000 read-only @ 0xE000EDFC + MON_EN 0 + MON_PEND 0 + +AIRCR 0xFA050000 read-write @ 0xE000ED0C + VECTKEY 0xFA05 + VECTKEYSTAT 0xFA05 + ENDIANNESS 0 + PRIGROUP 0x0 + SYSRESETREQ 0 + VECTCLRACTIVE 0 + +SCR 0x00000000 read-write @ 0xE000ED10 + SEVONPEND 0 + SLEEPDEEP 0 + SLEEPONEXIT 0 + +CCR 0x00000000 read-write @ 0xE000ED14 + STKALIGN 0 + BFHFNMIGN 0 + DIV_0_TRP 0 + UNALIGN_TRP 0 + USERSETMPEND 0 + NONBASETHRDENA 0 + +SHPR1 0x00000000 read-write @ 0xE000ED18 + PRI_7 0x0 + PRI_6 0x0 + PRI_5 0x0 + PRI_4 0x0 + +SHPR2 0x00000000 read-write @ 0xE000ED1C + PRI_11 0x0 + PRI_10 0x0 + PRI_9 0x0 + PRI_8 0x0 + +SHPR3 0x00000000 read-write @ 0xE000ED20 + PRI_15 0x0 + PRI_14 0x0 + PRI_13 0x0 + PRI_12 0x0 + +SHCSR 0x00000000 read-write @ 0xE000ED24 + USGFAULTENA 0 + BUSFAULTENA 0 + MEMFAULTENA 0 + SVCALLPENDED 0 + BUSFAULTPENDED 0 + MEMFAULTPENDED 0 + USGFAULTPENDED 0 + SYSTICKACT 0 + PENDSVACT 0 + MONITORACT 0 + SVCALLACT 0 + USGFAULTACT 0 + BUSFAULTACT 0 + MEMFAULTACT 0 + +CFSR 0x00000000 read-write @ 0xE000ED28 + DIVBYZERO 0 + UNALIGNED 0 + NOCP 0 + INVPC 0 + INVSTATE 0 + UNDEFINSTR 0 + BFARVALID 0 + LSPERR 0 + STKERR 0 + UNSTKERR 0 + IMPRECISERR 0 + PRECISERR 0 + IBUSERR 0 + MMARVALID 0 + MLSPERR 0 + MSTKERR 0 + MUNSTKERR 0 + DACCVIOL 0 + IACCVIOL 0 + +HFSR 0x00000000 read-write @ 0xE000ED2C + DEBUGEVT 0 + FORCED 0 + VECTTBL 0 + +DFSR 0x00000008 read-write @ 0xE000ED30 + EXTERNAL 0 + VCATCH 1 + DWTTRAP 0 + BKPT 0 + HALTED 0 + +MMFAR 0xE000EDF8 read-write @ 0xE000ED34 + +BFAR 0xE000EDF8 read-write @ 0xE000ED38 + +AFSR 0x00000000 read-write @ 0xE000ED3C + +CPACR 0x00000000 read-write @ 0xE000ED88 + CP11 0x0 + CP10 0x0 + CP7 0x0 + CP6 0x0 + CP5 0x0 + CP4 0x0 + CP3 0x0 + CP2 0x0 + CP1 0x0 + CP0 0x0 + +STIR write-only write-only @ 0xE000EF00 + INTID W + +Peripheral :ID +Name Value Access Address +CPUID 0x411FC231 read-only @ 0xE000ED00 + Implementer 0x41 + Variant 0x1 + Constant 0xF + Partno 0xC23 + Revision 0x1 + +ID_PFR0 0x00000030 read-only @ 0xE000ED40 + State1 0x3 + +ID_PFR1 0x00000200 read-only @ 0xE000ED44 + M_Profile 0x2 + +ID_DFR0 0x00100000 read-only @ 0xE000ED48 + M_Profile 0x1 + +ID_AFR0 0x00000000 read-only @ 0xE000ED4C + +ID_MMFR0 0x00000030 read-only @ 0xE000ED50 + Auxiliary_registers 0x0 + Shareability_levels 0x0 + Outermost_shareability 0x0 + PMSA 0x3 + +ID_MMFR1 0x00000000 read-only @ 0xE000ED54 + +ID_MMFR2 0x00000000 read-only @ 0xE000ED58 + WFI 0x0 + +ID_MMFR3 0x00000000 read-only @ 0xE000ED5C + +ID_ISAR0 0x01141110 read-only @ 0xE000ED60 + Divide_instrs 0x1 + Debug_instrs 0x1 + Coproc_instrs 0x4 + CmpBranch_instrs 0x1 + Bitfield_instrs 0x1 + BitCount_instrs 0x1 + +ID_ISAR1 0x02111000 read-only @ 0xE000ED64 + Interwork_instrs 0x2 + Immediate_instrs 0x1 + IfThen_instrs 0x1 + Extend_instrs 0x1 + +ID_ISAR2 0x21112231 read-only @ 0xE000ED68 + Reversal_instrs 0x2 + MultU_instrs 0x1 + MultS_instrs 0x1 + Mult_instrs 0x2 + MultiAccessInt_instrs 0x2 + MultiAccessInt_instrs 0x3 + LoadStore_instrs 0x1 + +ID_ISAR3 0x01111110 read-only @ 0xE000ED6C + TrueNOP_instrs 0x1 + ThumbCopy_instrs 0x1 + TabBranch_instrs 0x1 + SynchPrim_instrs 0x1 + SVC_instrs 0x1 + SIMD_instrs 0x1 + Saturate_instrs 0x0 + +ID_ISAR4 0x01310102 read-only @ 0xE000ED70 + PSR_M_instrs 0x1 + SynchPrim_instrs_frac 0x3 + Barrier_instrs 0x1 + Writeback_instrs 0x1 + WithShifts_instrs 0x0 + Unpriv_instrs 0x2 + +Peripheral :MPU +Name Value Access Address +MPU_TYPE 0x00000000 read-only @ 0xE000ED90 + SEPARATE 0 + DREGION 0x0 + IREGION 0x0 + +MPU_CTRL 0x00000000 read-write @ 0xE000ED94 + ENABLE 0 + HFNMIENA 0 + PRIVDEFENA 0 + +MPU_RNR 0x00000000 read-write @ 0xE000ED98 + REGION 0x0 + +MPU_RBAR 0x00000000 read-write @ 0xE000ED9C + REGION 0x0 + VALID 0 + ADDR 0x0 + +MPU_RASR 0x00000000 read-write @ 0xE000EDA0 + ENABLE 0 + SIZE 0x0 + SRD 0x0 + B 0 + C 0 + S 0 + TEX 0x0 + AP 0x0 + XN 0 + +MPU_RBAR_A1 0x00000000 read-write @ 0xE000EDA4 + REGION 0x0 + VALID 0 + ADDR 0x0 + +MPU_RASR_A1 0x00000000 read-write @ 0xE000EDA8 + ENABLE 0 + SIZE 0x0 + SRD 0x0 + B 0 + C 0 + S 0 + TEX 0x0 + AP 0x0 + XN 0 + +MPU_RBAR_A2 0x00000000 read-write @ 0xE000EDAC + REGION 0x0 + VALID 0 + ADDR 0x0 + +MPU_RASR_A2 0x00000000 read-write @ 0xE000EDB0 + ENABLE 0 + SIZE 0x0 + SRD 0x0 + B 0 + C 0 + S 0 + TEX 0x0 + AP 0x0 + XN 0 + +MPU_RBAR_A3 0x00000000 read-write @ 0xE000EDB4 + REGION 0x0 + VALID 0 + ADDR 0x0 + +MPU_RASR_A3 0x00000000 read-write @ 0xE000EDB8 + ENABLE 0 + SIZE 0x0 + SRD 0x0 + B 0 + C 0 + S 0 + TEX 0x0 + AP 0x0 + XN 0 + +Peripheral :NVIC +Name Value Access Address +NVIC_ISER0 0x00000000 read-write @ 0xE000E100 + SETENA 0x0 + +NVIC_ISER1 0x00000000 read-write @ 0xE000E104 + SETENA 0x0 + +NVIC_ISER2 0x00000000 read-write @ 0xE000E108 + SETENA 0x0 + +NVIC_ISER3 0x00000000 read-write @ 0xE000E10C + SETENA 0x0 + +NVIC_ISER4 0x00000000 read-write @ 0xE000E110 + SETENA 0x0 + +NVIC_ISER5 0x00000000 read-write @ 0xE000E114 + SETENA 0x0 + +NVIC_ISER6 0x00000000 read-write @ 0xE000E118 + SETENA 0x0 + +NVIC_ISER7 0x00000000 read-write @ 0xE000E11C + SETENA 0x0 + +NVIC_ICER0 0x00000000 read-write @ 0xE000E180 + CLRENA 0x0 + +NVIC_ICER1 0x00000000 read-write @ 0xE000E184 + CLRENA 0x0 + +NVIC_ICER2 0x00000000 read-write @ 0xE000E188 + CLRENA 0x0 + +NVIC_ICER3 0x00000000 read-write @ 0xE000E18C + CLRENA 0x0 + +NVIC_ICER4 0x00000000 read-write @ 0xE000E190 + CLRENA 0x0 + +NVIC_ICER5 0x00000000 read-write @ 0xE000E194 + CLRENA 0x0 + +NVIC_ICER6 0x00000000 read-write @ 0xE000E198 + CLRENA 0x0 + +NVIC_ICER7 0x00000000 read-write @ 0xE000E19C + CLRENA 0x0 + +NVIC_ISPR0 0x00000000 read-write @ 0xE000E200 + SETPEND 0x0 + +NVIC_ISPR1 0x00000000 read-write @ 0xE000E204 + SETPEND 0x0 + +NVIC_ISPR2 0x00000000 read-write @ 0xE000E208 + SETPEND 0x0 + +NVIC_ISPR3 0x00000000 read-write @ 0xE000E20C + SETPEND 0x0 + +NVIC_ISPR4 0x00000000 read-write @ 0xE000E210 + SETPEND 0x0 + +NVIC_ISPR5 0x00000000 read-write @ 0xE000E214 + SETPEND 0x0 + +NVIC_ISPR6 0x00000000 read-write @ 0xE000E218 + SETPEND 0x0 + +NVIC_ISPR7 0x00000000 read-write @ 0xE000E21C + SETPEND 0x0 + +NVIC_ICPR0 0x00000000 read-write @ 0xE000E280 + CLRPEND 0x0 + +NVIC_ICPR1 0x00000000 read-write @ 0xE000E284 + CLRPEND 0x0 + +NVIC_ICPR2 0x00000000 read-write @ 0xE000E288 + CLRPEND 0x0 + +NVIC_ICPR3 0x00000000 read-write @ 0xE000E28C + CLRPEND 0x0 + +NVIC_ICPR4 0x00000000 read-write @ 0xE000E290 + CLRPEND 0x0 + +NVIC_ICPR5 0x00000000 read-write @ 0xE000E294 + CLRPEND 0x0 + +NVIC_ICPR6 0x00000000 read-write @ 0xE000E298 + CLRPEND 0x0 + +NVIC_ICPR7 0x00000000 read-write @ 0xE000E29C + CLRPEND 0x0 + +NVIC_IABR0 0x00000000 read-write @ 0xE000E300 + ACTIVE 0x0 + +NVIC_IABR1 0x00000000 read-write @ 0xE000E304 + ACTIVE 0x0 + +NVIC_IABR2 0x00000000 read-write @ 0xE000E308 + ACTIVE 0x0 + +NVIC_IABR3 0x00000000 read-write @ 0xE000E30C + ACTIVE 0x0 + +NVIC_IABR4 0x00000000 read-write @ 0xE000E310 + ACTIVE 0x0 + +NVIC_IABR5 0x00000000 read-write @ 0xE000E314 + ACTIVE 0x0 + +NVIC_IABR6 0x00000000 read-write @ 0xE000E318 + ACTIVE 0x0 + +NVIC_IABR7 0x00000000 read-write @ 0xE000E31C + ACTIVE 0x0 + +NVIC_IPR0 0x00000000 read-write @ 0xE000E400 + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR1 0x00000000 read-write @ 0xE000E404 + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR2 0x00000000 read-write @ 0xE000E408 + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR3 0x00000000 read-write @ 0xE000E40C + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR4 0x00000000 read-write @ 0xE000E410 + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR5 0x00000000 read-write @ 0xE000E414 + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR6 0x00000000 read-write @ 0xE000E418 + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR7 0x00000000 read-write @ 0xE000E41C + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR8 0x00000000 read-write @ 0xE000E420 + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR9 0x00000000 read-write @ 0xE000E424 + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR10 0x00000000 read-write @ 0xE000E428 + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR11 0x00000000 read-write @ 0xE000E42C + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR12 0x00000000 read-write @ 0xE000E430 + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR13 0x00000000 read-write @ 0xE000E434 + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR14 0x00000000 read-write @ 0xE000E438 + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR15 0x00000000 read-write @ 0xE000E43C + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR16 0x00000000 read-write @ 0xE000E440 + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR17 0x00000000 read-write @ 0xE000E444 + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR18 0x00000000 read-write @ 0xE000E448 + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR19 0x00000000 read-write @ 0xE000E44C + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR20 0x00000000 read-write @ 0xE000E450 + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR21 0x00000000 read-write @ 0xE000E454 + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR22 0x00000000 read-write @ 0xE000E458 + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR23 0x00000000 read-write @ 0xE000E45C + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR24 0x00000000 read-write @ 0xE000E460 + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR25 0x00000000 read-write @ 0xE000E464 + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR26 0x00000000 read-write @ 0xE000E468 + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR27 0x00000000 read-write @ 0xE000E46C + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR28 0x00000000 read-write @ 0xE000E470 + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR29 0x00000000 read-write @ 0xE000E474 + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR30 0x00000000 read-write @ 0xE000E478 + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR31 0x00000000 read-write @ 0xE000E47C + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR32 0x00000000 read-write @ 0xE000E480 + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR33 0x00000000 read-write @ 0xE000E484 + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR34 0x00000000 read-write @ 0xE000E488 + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR35 0x00000000 read-write @ 0xE000E48C + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR36 0x00000000 read-write @ 0xE000E490 + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR37 0x00000000 read-write @ 0xE000E494 + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR38 0x00000000 read-write @ 0xE000E498 + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR39 0x00000000 read-write @ 0xE000E49C + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR40 0x00000000 read-write @ 0xE000E4A0 + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR41 0x00000000 read-write @ 0xE000E4A4 + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR42 0x00000000 read-write @ 0xE000E4A8 + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR43 0x00000000 read-write @ 0xE000E4AC + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR44 0x00000000 read-write @ 0xE000E4B0 + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR45 0x00000000 read-write @ 0xE000E4B4 + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR46 0x00000000 read-write @ 0xE000E4B8 + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR47 0x00000000 read-write @ 0xE000E4BC + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR48 0x00000000 read-write @ 0xE000E4C0 + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR49 0x00000000 read-write @ 0xE000E4C4 + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR50 0x00000000 read-write @ 0xE000E4C8 + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR51 0x00000000 read-write @ 0xE000E4CC + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR52 0x00000000 read-write @ 0xE000E4D0 + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR53 0x00000000 read-write @ 0xE000E4D4 + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR54 0x00000000 read-write @ 0xE000E4D8 + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR55 0x00000000 read-write @ 0xE000E4DC + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR56 0x00000000 read-write @ 0xE000E4E0 + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR57 0x00000000 read-write @ 0xE000E4E4 + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR58 0x00000000 read-write @ 0xE000E4E8 + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +NVIC_IPR59 0x00000000 read-write @ 0xE000E4EC + PRI_N3 0x0 + PRI_N2 0x0 + PRI_N1 0x0 + PRI_N0 0x0 + +Peripheral :NVIC_STIR +Name Value Access Address +STIR write-only write-only @ 0xE000EF00 + INTID W + +Peripheral :SysTick +Name Value Access Address +STCSR 0x00000000 read-write @ 0xE000E010 + COUNTFLAG 0 + CLKSOURCE 0 + TICKINT 0 + ENABLE 0 + +STRVR 0x00000000 read-write @ 0xE000E014 + RELOAD 0x0 + +STCVR 0x00000000 read-write @ 0xE000E018 + CURRENT 0x0 + +STCR 0x40002328 read-only @ 0xE000E01C + NOREF 0 + SKEW 1 + TENMS 0x2328 + +Peripheral :FSMC +Name Value Access Address +BCR1 0x00000000 read-write @ 0xA0000000 + CBURSTRW 0 + ASYNCWAIT 0 + EXTMOD 0 + WAITEN 0 + WREN 0 + WAITCFG 0 + WAITPOL 0 + BURSTEN 0 + FACCEN 0 + MWID 0x0 + MTYP 0x0 + MUXEN 0 + MBKEN 0 + +BTR1 0x00000000 read-write @ 0xA0000004 + ACCMOD 0x0 + DATLAT 0x0 + CLKDIV 0x0 + BUSTURN 0x0 + DATAST 0x0 + ADDHLD 0x0 + ADDSET 0x0 + +BCR2 0x00000000 read-write @ 0xA0000008 + CBURSTRW 0 + ASYNCWAIT 0 + EXTMOD 0 + WAITEN 0 + WREN 0 + WAITCFG 0 + WRAPMOD 0 + WAITPOL 0 + BURSTEN 0 + FACCEN 0 + MWID 0x0 + MTYP 0x0 + MUXEN 0 + MBKEN 0 + +BTR2 0x00000000 read-write @ 0xA000000C + ACCMOD 0x0 + DATLAT 0x0 + CLKDIV 0x0 + BUSTURN 0x0 + DATAST 0x0 + ADDHLD 0x0 + ADDSET 0x0 + +BCR3 0x00000000 read-write @ 0xA0000010 + CBURSTRW 0 + ASYNCWAIT 0 + EXTMOD 0 + WAITEN 0 + WREN 0 + WAITCFG 0 + WRAPMOD 0 + WAITPOL 0 + BURSTEN 0 + FACCEN 0 + MWID 0x0 + MTYP 0x0 + MUXEN 0 + MBKEN 0 + +BTR3 0x00000000 read-write @ 0xA0000014 + ACCMOD 0x0 + DATLAT 0x0 + CLKDIV 0x0 + BUSTURN 0x0 + DATAST 0x0 + ADDHLD 0x0 + ADDSET 0x0 + +BCR4 0x00000000 read-write @ 0xA0000018 + CBURSTRW 0 + ASYNCWAIT 0 + EXTMOD 0 + WAITEN 0 + WREN 0 + WAITCFG 0 + WRAPMOD 0 + WAITPOL 0 + BURSTEN 0 + FACCEN 0 + MWID 0x0 + MTYP 0x0 + MUXEN 0 + MBKEN 0 + +BTR4 0x00000000 read-write @ 0xA000001C + ACCMOD 0x0 + DATLAT 0x0 + CLKDIV 0x0 + BUSTURN 0x0 + DATAST 0x0 + ADDHLD 0x0 + ADDSET 0x0 + +PCR2 0x00000000 read-write @ 0xA0000060 + ECCPS 0x0 + TAR 0x0 + TCLR 0x0 + ECCEN 0 + PWID 0x0 + PTYP 0 + PBKEN 0 + PWAITEN 0 + +SR2 0x00000000 undefined @ 0xA0000064 + FEMPT 0 + IFEN 0 + ILEN 0 + IREN 0 + IFS 0 + ILS 0 + IRS 0 + +PMEM2 0x00000000 read-write @ 0xA0000068 + MEMHIZx 0x0 + MEMHOLDx 0x0 + MEMWAITx 0x0 + MEMSETx 0x0 + +PATT2 0x00000000 read-write @ 0xA000006C + ATTHIZx 0x0 + ATTHOLDx 0x0 + ATTWAITx 0x0 + ATTSETx 0x0 + +ECCR2 0x00000000 read-only @ 0xA0000074 + ECCx 0x0 + +PCR3 0x00000000 read-write @ 0xA0000080 + ECCPS 0x0 + TAR 0x0 + TCLR 0x0 + ECCEN 0 + PWID 0x0 + PTYP 0 + PBKEN 0 + PWAITEN 0 + +SR3 0x00000000 undefined @ 0xA0000084 + FEMPT 0 + IFEN 0 + ILEN 0 + IREN 0 + IFS 0 + ILS 0 + IRS 0 + +PMEM3 0x00000000 read-write @ 0xA0000088 + MEMHIZx 0x0 + MEMHOLDx 0x0 + MEMWAITx 0x0 + MEMSETx 0x0 + +PATT3 0x00000000 read-write @ 0xA000008C + ATTHIZx 0x0 + ATTHOLDx 0x0 + ATTWAITx 0x0 + ATTSETx 0x0 + +ECCR3 0x00000000 read-only @ 0xA0000094 + ECCx 0x0 + +PCR4 0x00000000 read-write @ 0xA00000A0 + ECCPS 0x0 + TAR 0x0 + TCLR 0x0 + ECCEN 0 + PWID 0x0 + PTYP 0 + PBKEN 0 + PWAITEN 0 + +SR4 0x00000000 undefined @ 0xA00000A4 + FEMPT 0 + IFEN 0 + ILEN 0 + IREN 0 + IFS 0 + ILS 0 + IRS 0 + +PMEM4 0x00000000 read-write @ 0xA00000A8 + MEMHIZx 0x0 + MEMHOLDx 0x0 + MEMWAITx 0x0 + MEMSETx 0x0 + +PATT4 0x00000000 read-write @ 0xA00000AC + ATTHIZx 0x0 + ATTHOLDx 0x0 + ATTWAITx 0x0 + ATTSETx 0x0 + +PIO4 0x00000000 read-write @ 0xA00000B0 + IOHIZx 0x0 + IOHOLDx 0x0 + IOWAITx 0x0 + IOSETx 0x0 + +BWTR1 0x00000000 read-write @ 0xA0000104 + ACCMOD 0x0 + DATLAT 0x0 + CLKDIV 0x0 + DATAST 0x0 + ADDHLD 0x0 + ADDSET 0x0 + +BWTR2 0x00000000 read-write @ 0xA000010C + ACCMOD 0x0 + DATLAT 0x0 + CLKDIV 0x0 + DATAST 0x0 + ADDHLD 0x0 + ADDSET 0x0 + +BWTR3 0x00000000 read-write @ 0xA0000114 + ACCMOD 0x0 + DATLAT 0x0 + CLKDIV 0x0 + DATAST 0x0 + ADDHLD 0x0 + ADDSET 0x0 + +BWTR4 0x00000000 read-write @ 0xA000011C + ACCMOD 0x0 + DATLAT 0x0 + CLKDIV 0x0 + DATAST 0x0 + ADDHLD 0x0 + ADDSET 0x0 + +Peripheral :PWR +Name Value Access Address +CR 0x00000000 read-write @ 0x40007000 + LPDS 0 + PDDS 0 + CWUF 0 + CSBF 0 + PVDE 0 + PLS 0x0 + DBP 0 + +CSR 0x00000000 undefined @ 0x40007004 + WUF 0 + SBF 0 + PVDO 0 + EWUP 0 + +Peripheral :RCC +Name Value Access Address +CR 0x00000000 undefined @ 0x40021000 + HSION 0 + HSIRDY 0 + HSITRIM 0x0 + HSICAL 0x0 + HSEON 0 + HSERDY 0 + HSEBYP 0 + CSSON 0 + PLLON 0 + PLLRDY 0 + +CFGR 0x00000000 undefined @ 0x40021004 + SW 0x0 + SWS 0x0 + HPRE 0x0 + PPRE1 0x0 + PPRE2 0x0 + ADCPRE 0x0 + PLLSRC 0 + PLLXTPRE 0 + PLLMUL 0x0 + OTGFSPRE 0 + MCO 0x0 + +CIR 0x00000000 undefined @ 0x40021008 + LSIRDYF 0 + LSERDYF 0 + HSIRDYF 0 + HSERDYF 0 + PLLRDYF 0 + CSSF 0 + LSIRDYIE 0 + LSERDYIE 0 + HSIRDYIE 0 + HSERDYIE 0 + PLLRDYIE 0 + LSIRDYC 0 + LSERDYC 0 + HSIRDYC 0 + HSERDYC 0 + PLLRDYC 0 + CSSC 0 + +APB2RSTR 0x00000000 read-write @ 0x4002100C + AFIORST 0 + IOPARST 0 + IOPBRST 0 + IOPCRST 0 + IOPDRST 0 + IOPERST 0 + IOPFRST 0 + IOPGRST 0 + ADC1RST 0 + ADC2RST 0 + TIM1RST 0 + SPI1RST 0 + TIM8RST 0 + USART1RST 0 + ADC3RST 0 + TIM9RST 0 + TIM10RST 0 + TIM11RST 0 + +APB1RSTR 0x00000000 read-write @ 0x40021010 + TIM2RST 0 + TIM3RST 0 + TIM4RST 0 + TIM5RST 0 + TIM6RST 0 + TIM7RST 0 + TIM12RST 0 + TIM13RST 0 + TIM14RST 0 + WWDGRST 0 + SPI2RST 0 + SPI3RST 0 + USART2RST 0 + USART3RST 0 + UART4RST 0 + UART5RST 0 + I2C1RST 0 + I2C2RST 0 + USBRST 0 + CANRST 0 + BKPRST 0 + PWRRST 0 + DACRST 0 + +AHBENR 0x00000014 read-write @ 0x40021014 + DMA1EN 0 + DMA2EN 0 + SRAMEN 1 + FLITFEN 1 + CRCEN 0 + FSMCEN 0 + SDIOEN 0 + +APB2ENR 0x00000000 read-write @ 0x40021018 + AFIOEN 0 + IOPAEN 0 + IOPBEN 0 + IOPCEN 0 + IOPDEN 0 + IOPEEN 0 + IOPFEN 0 + IOPGEN 0 + ADC1EN 0 + ADC2EN 0 + TIM1EN 0 + SPI1EN 0 + TIM8EN 0 + USART1EN 0 + ADC3EN 0 + TIM9EN 0 + TIM10EN 0 + TIM11EN 0 + +APB1ENR 0x00000000 read-write @ 0x4002101C + TIM2EN 0 + TIM3EN 0 + TIM4EN 0 + TIM5EN 0 + TIM6EN 0 + TIM7EN 0 + TIM12EN 0 + TIM13EN 0 + TIM14EN 0 + WWDGEN 0 + SPI2EN 0 + SPI3EN 0 + USART2EN 0 + USART3EN 0 + UART4EN 0 + UART5EN 0 + I2C1EN 0 + I2C2EN 0 + USBEN 0 + CANEN 0 + BKPEN 0 + PWREN 0 + DACEN 0 + +BDCR 0x00000000 undefined @ 0x40021020 + LSEON 0 + LSERDY 0 + LSEBYP 0 + RTCSEL 0x0 + RTCEN 0 + BDRST 0 + +CSR 0x00000000 undefined @ 0x40021024 + LSION 0 + LSIRDY 0 + RMVF 0 + PINRSTF 0 + PORRSTF 0 + SFTRSTF 0 + IWDGRSTF 0 + WWDGRSTF 0 + LPWRRSTF 0 + +Peripheral :GPIOA +Name Value Access Address +CRL 0x44444444 read-write @ 0x40010800 + MODE0 0x0 + CNF0 0x1 + MODE1 0x0 + CNF1 0x1 + MODE2 0x0 + CNF2 0x1 + MODE3 0x0 + CNF3 0x1 + MODE4 0x0 + CNF4 0x1 + MODE5 0x0 + CNF5 0x1 + MODE6 0x0 + CNF6 0x1 + MODE7 0x0 + CNF7 0x1 + +CRH 0x88844444 read-write @ 0x40010804 + MODE8 0x0 + CNF8 0x1 + MODE9 0x0 + CNF9 0x1 + MODE10 0x0 + CNF10 0x1 + MODE11 0x0 + CNF11 0x1 + MODE12 0x0 + CNF12 0x1 + MODE13 0x0 + CNF13 0x2 + MODE14 0x0 + CNF14 0x2 + MODE15 0x0 + CNF15 0x2 + +IDR 0x00000000 read-only @ 0x40010808 + IDR0 0 + IDR1 0 + IDR2 0 + IDR3 0 + IDR4 0 + IDR5 0 + IDR6 0 + IDR7 0 + IDR8 0 + IDR9 0 + IDR10 0 + IDR11 0 + IDR12 0 + IDR13 0 + IDR14 0 + IDR15 0 + +ODR 0x0000A000 read-write @ 0x4001080C + ODR0 0 + ODR1 0 + ODR2 0 + ODR3 0 + ODR4 0 + ODR5 0 + ODR6 0 + ODR7 0 + ODR8 0 + ODR9 0 + ODR10 0 + ODR11 0 + ODR12 0 + ODR13 1 + ODR14 0 + ODR15 1 + +BSRR write-only write-only @ 0x40010810 + BS0 W + BS1 W + BS2 W + BS3 W + BS4 W + BS5 W + BS6 W + BS7 W + BS8 W + BS9 W + BS10 W + BS11 W + BS12 W + BS13 W + BS14 W + BS15 W + BR0 W + BR1 W + BR2 W + BR3 W + BR4 W + BR5 W + BR6 W + BR7 W + BR8 W + BR9 W + BR10 W + BR11 W + BR12 W + BR13 W + BR14 W + BR15 W + +BRR write-only write-only @ 0x40010814 + BR0 W + BR1 W + BR2 W + BR3 W + BR4 W + BR5 W + BR6 W + BR7 W + BR8 W + BR9 W + BR10 W + BR11 W + BR12 W + BR13 W + BR14 W + BR15 W + +LCKR 0x00000000 read-write @ 0x40010818 + LCK0 0 + LCK1 0 + LCK2 0 + LCK3 0 + LCK4 0 + LCK5 0 + LCK6 0 + LCK7 0 + LCK8 0 + LCK9 0 + LCK10 0 + LCK11 0 + LCK12 0 + LCK13 0 + LCK14 0 + LCK15 0 + LCKK 0 + +Peripheral :GPIOB +Name Value Access Address +CRL 0x44484444 read-write @ 0x40010C00 + MODE0 0x0 + CNF0 0x1 + MODE1 0x0 + CNF1 0x1 + MODE2 0x0 + CNF2 0x1 + MODE3 0x0 + CNF3 0x1 + MODE4 0x0 + CNF4 0x2 + MODE5 0x0 + CNF5 0x1 + MODE6 0x0 + CNF6 0x1 + MODE7 0x0 + CNF7 0x1 + +CRH 0x44444444 read-write @ 0x40010C04 + MODE8 0x0 + CNF8 0x1 + MODE9 0x0 + CNF9 0x1 + MODE10 0x0 + CNF10 0x1 + MODE11 0x0 + CNF11 0x1 + MODE12 0x0 + CNF12 0x1 + MODE13 0x0 + CNF13 0x1 + MODE14 0x0 + CNF14 0x1 + MODE15 0x0 + CNF15 0x1 + +IDR 0x00000000 read-only @ 0x40010C08 + IDR0 0 + IDR1 0 + IDR2 0 + IDR3 0 + IDR4 0 + IDR5 0 + IDR6 0 + IDR7 0 + IDR8 0 + IDR9 0 + IDR10 0 + IDR11 0 + IDR12 0 + IDR13 0 + IDR14 0 + IDR15 0 + +ODR 0x00000010 read-write @ 0x40010C0C + ODR0 0 + ODR1 0 + ODR2 0 + ODR3 0 + ODR4 1 + ODR5 0 + ODR6 0 + ODR7 0 + ODR8 0 + ODR9 0 + ODR10 0 + ODR11 0 + ODR12 0 + ODR13 0 + ODR14 0 + ODR15 0 + +BSRR write-only write-only @ 0x40010C10 + BS0 W + BS1 W + BS2 W + BS3 W + BS4 W + BS5 W + BS6 W + BS7 W + BS8 W + BS9 W + BS10 W + BS11 W + BS12 W + BS13 W + BS14 W + BS15 W + BR0 W + BR1 W + BR2 W + BR3 W + BR4 W + BR5 W + BR6 W + BR7 W + BR8 W + BR9 W + BR10 W + BR11 W + BR12 W + BR13 W + BR14 W + BR15 W + +BRR write-only write-only @ 0x40010C14 + BR0 W + BR1 W + BR2 W + BR3 W + BR4 W + BR5 W + BR6 W + BR7 W + BR8 W + BR9 W + BR10 W + BR11 W + BR12 W + BR13 W + BR14 W + BR15 W + +LCKR 0x00000000 read-write @ 0x40010C18 + LCK0 0 + LCK1 0 + LCK2 0 + LCK3 0 + LCK4 0 + LCK5 0 + LCK6 0 + LCK7 0 + LCK8 0 + LCK9 0 + LCK10 0 + LCK11 0 + LCK12 0 + LCK13 0 + LCK14 0 + LCK15 0 + LCKK 0 + +Peripheral :GPIOC +Name Value Access Address +CRL 0x44444444 read-write @ 0x40011000 + MODE0 0x0 + CNF0 0x1 + MODE1 0x0 + CNF1 0x1 + MODE2 0x0 + CNF2 0x1 + MODE3 0x0 + CNF3 0x1 + MODE4 0x0 + CNF4 0x1 + MODE5 0x0 + CNF5 0x1 + MODE6 0x0 + CNF6 0x1 + MODE7 0x0 + CNF7 0x1 + +CRH 0x44444444 read-write @ 0x40011004 + MODE8 0x0 + CNF8 0x1 + MODE9 0x0 + CNF9 0x1 + MODE10 0x0 + CNF10 0x1 + MODE11 0x0 + CNF11 0x1 + MODE12 0x0 + CNF12 0x1 + MODE13 0x0 + CNF13 0x1 + MODE14 0x0 + CNF14 0x1 + MODE15 0x0 + CNF15 0x1 + +IDR 0x00000000 read-only @ 0x40011008 + IDR0 0 + IDR1 0 + IDR2 0 + IDR3 0 + IDR4 0 + IDR5 0 + IDR6 0 + IDR7 0 + IDR8 0 + IDR9 0 + IDR10 0 + IDR11 0 + IDR12 0 + IDR13 0 + IDR14 0 + IDR15 0 + +ODR 0x00000000 read-write @ 0x4001100C + ODR0 0 + ODR1 0 + ODR2 0 + ODR3 0 + ODR4 0 + ODR5 0 + ODR6 0 + ODR7 0 + ODR8 0 + ODR9 0 + ODR10 0 + ODR11 0 + ODR12 0 + ODR13 0 + ODR14 0 + ODR15 0 + +BSRR write-only write-only @ 0x40011010 + BS0 W + BS1 W + BS2 W + BS3 W + BS4 W + BS5 W + BS6 W + BS7 W + BS8 W + BS9 W + BS10 W + BS11 W + BS12 W + BS13 W + BS14 W + BS15 W + BR0 W + BR1 W + BR2 W + BR3 W + BR4 W + BR5 W + BR6 W + BR7 W + BR8 W + BR9 W + BR10 W + BR11 W + BR12 W + BR13 W + BR14 W + BR15 W + +BRR write-only write-only @ 0x40011014 + BR0 W + BR1 W + BR2 W + BR3 W + BR4 W + BR5 W + BR6 W + BR7 W + BR8 W + BR9 W + BR10 W + BR11 W + BR12 W + BR13 W + BR14 W + BR15 W + +LCKR 0x00000000 read-write @ 0x40011018 + LCK0 0 + LCK1 0 + LCK2 0 + LCK3 0 + LCK4 0 + LCK5 0 + LCK6 0 + LCK7 0 + LCK8 0 + LCK9 0 + LCK10 0 + LCK11 0 + LCK12 0 + LCK13 0 + LCK14 0 + LCK15 0 + LCKK 0 + +Peripheral :GPIOD +Name Value Access Address +CRL 0x44444444 read-write @ 0x40011400 + MODE0 0x0 + CNF0 0x1 + MODE1 0x0 + CNF1 0x1 + MODE2 0x0 + CNF2 0x1 + MODE3 0x0 + CNF3 0x1 + MODE4 0x0 + CNF4 0x1 + MODE5 0x0 + CNF5 0x1 + MODE6 0x0 + CNF6 0x1 + MODE7 0x0 + CNF7 0x1 + +CRH 0x44444444 read-write @ 0x40011404 + MODE8 0x0 + CNF8 0x1 + MODE9 0x0 + CNF9 0x1 + MODE10 0x0 + CNF10 0x1 + MODE11 0x0 + CNF11 0x1 + MODE12 0x0 + CNF12 0x1 + MODE13 0x0 + CNF13 0x1 + MODE14 0x0 + CNF14 0x1 + MODE15 0x0 + CNF15 0x1 + +IDR 0x00000000 read-only @ 0x40011408 + IDR0 0 + IDR1 0 + IDR2 0 + IDR3 0 + IDR4 0 + IDR5 0 + IDR6 0 + IDR7 0 + IDR8 0 + IDR9 0 + IDR10 0 + IDR11 0 + IDR12 0 + IDR13 0 + IDR14 0 + IDR15 0 + +ODR 0x00000000 read-write @ 0x4001140C + ODR0 0 + ODR1 0 + ODR2 0 + ODR3 0 + ODR4 0 + ODR5 0 + ODR6 0 + ODR7 0 + ODR8 0 + ODR9 0 + ODR10 0 + ODR11 0 + ODR12 0 + ODR13 0 + ODR14 0 + ODR15 0 + +BSRR write-only write-only @ 0x40011410 + BS0 W + BS1 W + BS2 W + BS3 W + BS4 W + BS5 W + BS6 W + BS7 W + BS8 W + BS9 W + BS10 W + BS11 W + BS12 W + BS13 W + BS14 W + BS15 W + BR0 W + BR1 W + BR2 W + BR3 W + BR4 W + BR5 W + BR6 W + BR7 W + BR8 W + BR9 W + BR10 W + BR11 W + BR12 W + BR13 W + BR14 W + BR15 W + +BRR write-only write-only @ 0x40011414 + BR0 W + BR1 W + BR2 W + BR3 W + BR4 W + BR5 W + BR6 W + BR7 W + BR8 W + BR9 W + BR10 W + BR11 W + BR12 W + BR13 W + BR14 W + BR15 W + +LCKR 0x00000000 read-write @ 0x40011418 + LCK0 0 + LCK1 0 + LCK2 0 + LCK3 0 + LCK4 0 + LCK5 0 + LCK6 0 + LCK7 0 + LCK8 0 + LCK9 0 + LCK10 0 + LCK11 0 + LCK12 0 + LCK13 0 + LCK14 0 + LCK15 0 + LCKK 0 + +Peripheral :GPIOE +Name Value Access Address +CRL 0x44444444 read-write @ 0x40011800 + MODE0 0x0 + CNF0 0x1 + MODE1 0x0 + CNF1 0x1 + MODE2 0x0 + CNF2 0x1 + MODE3 0x0 + CNF3 0x1 + MODE4 0x0 + CNF4 0x1 + MODE5 0x0 + CNF5 0x1 + MODE6 0x0 + CNF6 0x1 + MODE7 0x0 + CNF7 0x1 + +CRH 0x44444444 read-write @ 0x40011804 + MODE8 0x0 + CNF8 0x1 + MODE9 0x0 + CNF9 0x1 + MODE10 0x0 + CNF10 0x1 + MODE11 0x0 + CNF11 0x1 + MODE12 0x0 + CNF12 0x1 + MODE13 0x0 + CNF13 0x1 + MODE14 0x0 + CNF14 0x1 + MODE15 0x0 + CNF15 0x1 + +IDR 0x00000000 read-only @ 0x40011808 + IDR0 0 + IDR1 0 + IDR2 0 + IDR3 0 + IDR4 0 + IDR5 0 + IDR6 0 + IDR7 0 + IDR8 0 + IDR9 0 + IDR10 0 + IDR11 0 + IDR12 0 + IDR13 0 + IDR14 0 + IDR15 0 + +ODR 0x00000000 read-write @ 0x4001180C + ODR0 0 + ODR1 0 + ODR2 0 + ODR3 0 + ODR4 0 + ODR5 0 + ODR6 0 + ODR7 0 + ODR8 0 + ODR9 0 + ODR10 0 + ODR11 0 + ODR12 0 + ODR13 0 + ODR14 0 + ODR15 0 + +BSRR write-only write-only @ 0x40011810 + BS0 W + BS1 W + BS2 W + BS3 W + BS4 W + BS5 W + BS6 W + BS7 W + BS8 W + BS9 W + BS10 W + BS11 W + BS12 W + BS13 W + BS14 W + BS15 W + BR0 W + BR1 W + BR2 W + BR3 W + BR4 W + BR5 W + BR6 W + BR7 W + BR8 W + BR9 W + BR10 W + BR11 W + BR12 W + BR13 W + BR14 W + BR15 W + +BRR write-only write-only @ 0x40011814 + BR0 W + BR1 W + BR2 W + BR3 W + BR4 W + BR5 W + BR6 W + BR7 W + BR8 W + BR9 W + BR10 W + BR11 W + BR12 W + BR13 W + BR14 W + BR15 W + +LCKR 0x00000000 read-write @ 0x40011818 + LCK0 0 + LCK1 0 + LCK2 0 + LCK3 0 + LCK4 0 + LCK5 0 + LCK6 0 + LCK7 0 + LCK8 0 + LCK9 0 + LCK10 0 + LCK11 0 + LCK12 0 + LCK13 0 + LCK14 0 + LCK15 0 + LCKK 0 + +Peripheral :GPIOF +Name Value Access Address +CRL 0x44444444 read-write @ 0x40011C00 + MODE0 0x0 + CNF0 0x1 + MODE1 0x0 + CNF1 0x1 + MODE2 0x0 + CNF2 0x1 + MODE3 0x0 + CNF3 0x1 + MODE4 0x0 + CNF4 0x1 + MODE5 0x0 + CNF5 0x1 + MODE6 0x0 + CNF6 0x1 + MODE7 0x0 + CNF7 0x1 + +CRH 0x44444444 read-write @ 0x40011C04 + MODE8 0x0 + CNF8 0x1 + MODE9 0x0 + CNF9 0x1 + MODE10 0x0 + CNF10 0x1 + MODE11 0x0 + CNF11 0x1 + MODE12 0x0 + CNF12 0x1 + MODE13 0x0 + CNF13 0x1 + MODE14 0x0 + CNF14 0x1 + MODE15 0x0 + CNF15 0x1 + +IDR 0x00000000 read-only @ 0x40011C08 + IDR0 0 + IDR1 0 + IDR2 0 + IDR3 0 + IDR4 0 + IDR5 0 + IDR6 0 + IDR7 0 + IDR8 0 + IDR9 0 + IDR10 0 + IDR11 0 + IDR12 0 + IDR13 0 + IDR14 0 + IDR15 0 + +ODR 0x00000000 read-write @ 0x40011C0C + ODR0 0 + ODR1 0 + ODR2 0 + ODR3 0 + ODR4 0 + ODR5 0 + ODR6 0 + ODR7 0 + ODR8 0 + ODR9 0 + ODR10 0 + ODR11 0 + ODR12 0 + ODR13 0 + ODR14 0 + ODR15 0 + +BSRR write-only write-only @ 0x40011C10 + BS0 W + BS1 W + BS2 W + BS3 W + BS4 W + BS5 W + BS6 W + BS7 W + BS8 W + BS9 W + BS10 W + BS11 W + BS12 W + BS13 W + BS14 W + BS15 W + BR0 W + BR1 W + BR2 W + BR3 W + BR4 W + BR5 W + BR6 W + BR7 W + BR8 W + BR9 W + BR10 W + BR11 W + BR12 W + BR13 W + BR14 W + BR15 W + +BRR write-only write-only @ 0x40011C14 + BR0 W + BR1 W + BR2 W + BR3 W + BR4 W + BR5 W + BR6 W + BR7 W + BR8 W + BR9 W + BR10 W + BR11 W + BR12 W + BR13 W + BR14 W + BR15 W + +LCKR 0x00000000 read-write @ 0x40011C18 + LCK0 0 + LCK1 0 + LCK2 0 + LCK3 0 + LCK4 0 + LCK5 0 + LCK6 0 + LCK7 0 + LCK8 0 + LCK9 0 + LCK10 0 + LCK11 0 + LCK12 0 + LCK13 0 + LCK14 0 + LCK15 0 + LCKK 0 + +Peripheral :GPIOG +Name Value Access Address +CRL 0x44444444 read-write @ 0x40012000 + MODE0 0x0 + CNF0 0x1 + MODE1 0x0 + CNF1 0x1 + MODE2 0x0 + CNF2 0x1 + MODE3 0x0 + CNF3 0x1 + MODE4 0x0 + CNF4 0x1 + MODE5 0x0 + CNF5 0x1 + MODE6 0x0 + CNF6 0x1 + MODE7 0x0 + CNF7 0x1 + +CRH 0x44444444 read-write @ 0x40012004 + MODE8 0x0 + CNF8 0x1 + MODE9 0x0 + CNF9 0x1 + MODE10 0x0 + CNF10 0x1 + MODE11 0x0 + CNF11 0x1 + MODE12 0x0 + CNF12 0x1 + MODE13 0x0 + CNF13 0x1 + MODE14 0x0 + CNF14 0x1 + MODE15 0x0 + CNF15 0x1 + +IDR 0x00000000 read-only @ 0x40012008 + IDR0 0 + IDR1 0 + IDR2 0 + IDR3 0 + IDR4 0 + IDR5 0 + IDR6 0 + IDR7 0 + IDR8 0 + IDR9 0 + IDR10 0 + IDR11 0 + IDR12 0 + IDR13 0 + IDR14 0 + IDR15 0 + +ODR 0x00000000 read-write @ 0x4001200C + ODR0 0 + ODR1 0 + ODR2 0 + ODR3 0 + ODR4 0 + ODR5 0 + ODR6 0 + ODR7 0 + ODR8 0 + ODR9 0 + ODR10 0 + ODR11 0 + ODR12 0 + ODR13 0 + ODR14 0 + ODR15 0 + +BSRR write-only write-only @ 0x40012010 + BS0 W + BS1 W + BS2 W + BS3 W + BS4 W + BS5 W + BS6 W + BS7 W + BS8 W + BS9 W + BS10 W + BS11 W + BS12 W + BS13 W + BS14 W + BS15 W + BR0 W + BR1 W + BR2 W + BR3 W + BR4 W + BR5 W + BR6 W + BR7 W + BR8 W + BR9 W + BR10 W + BR11 W + BR12 W + BR13 W + BR14 W + BR15 W + +BRR write-only write-only @ 0x40012014 + BR0 W + BR1 W + BR2 W + BR3 W + BR4 W + BR5 W + BR6 W + BR7 W + BR8 W + BR9 W + BR10 W + BR11 W + BR12 W + BR13 W + BR14 W + BR15 W + +LCKR 0x00000000 read-write @ 0x40012018 + LCK0 0 + LCK1 0 + LCK2 0 + LCK3 0 + LCK4 0 + LCK5 0 + LCK6 0 + LCK7 0 + LCK8 0 + LCK9 0 + LCK10 0 + LCK11 0 + LCK12 0 + LCK13 0 + LCK14 0 + LCK15 0 + LCKK 0 + +Peripheral :AFIO +Name Value Access Address +EVCR 0x00000000 read-write @ 0x40010000 + PIN 0x0 + PORT 0x0 + EVOE 0 + +MAPR 0x00000000 undefined @ 0x40010004 + SPI1_REMAP 0 + I2C1_REMAP 0 + USART1_REMAP 0 + USART2_REMAP 0 + USART3_REMAP 0x0 + TIM1_REMAP 0x0 + TIM2_REMAP 0x0 + TIM3_REMAP 0x0 + TIM4_REMAP 0 + CAN_REMAP 0x0 + PD01_REMAP 0 + TIM5CH4_IREMAP 0 + ADC1_ETRGINJ_REMAP 0 + ADC1_ETRGREG_REMAP 0 + ADC2_ETRGINJ_REMAP 0 + ADC2_ETRGREG_REMAP 0 + SWJ_CFG 0x0 + +EXTICR1 0x00000000 read-write @ 0x40010008 + EXTI0 0x0 + EXTI1 0x0 + EXTI2 0x0 + EXTI3 0x0 + +EXTICR2 0x00000000 read-write @ 0x4001000C + EXTI4 0x0 + EXTI5 0x0 + EXTI6 0x0 + EXTI7 0x0 + +EXTICR3 0x00000000 read-write @ 0x40010010 + EXTI8 0x0 + EXTI9 0x0 + EXTI10 0x0 + EXTI11 0x0 + +EXTICR4 0x00000000 read-write @ 0x40010014 + EXTI12 0x0 + EXTI13 0x0 + EXTI14 0x0 + EXTI15 0x0 + +MAPR2 0x00000000 read-write @ 0x4001001C + TIM9_REMAP 0 + TIM10_REMAP 0 + TIM11_REMAP 0 + TIM13_REMAP 0 + TIM14_REMAP 0 + FSMC_NADV 0 + +Peripheral :EXTI +Name Value Access Address +IMR 0x00000000 read-write @ 0x40010400 + MR0 0 + MR1 0 + MR2 0 + MR3 0 + MR4 0 + MR5 0 + MR6 0 + MR7 0 + MR8 0 + MR9 0 + MR10 0 + MR11 0 + MR12 0 + MR13 0 + MR14 0 + MR15 0 + MR16 0 + MR17 0 + MR18 0 + +EMR 0x00000000 read-write @ 0x40010404 + MR0 0 + MR1 0 + MR2 0 + MR3 0 + MR4 0 + MR5 0 + MR6 0 + MR7 0 + MR8 0 + MR9 0 + MR10 0 + MR11 0 + MR12 0 + MR13 0 + MR14 0 + MR15 0 + MR16 0 + MR17 0 + MR18 0 + +RTSR 0x00000000 read-write @ 0x40010408 + TR0 0 + TR1 0 + TR2 0 + TR3 0 + TR4 0 + TR5 0 + TR6 0 + TR7 0 + TR8 0 + TR9 0 + TR10 0 + TR11 0 + TR12 0 + TR13 0 + TR14 0 + TR15 0 + TR16 0 + TR17 0 + TR18 0 + +FTSR 0x00000000 read-write @ 0x4001040C + TR0 0 + TR1 0 + TR2 0 + TR3 0 + TR4 0 + TR5 0 + TR6 0 + TR7 0 + TR8 0 + TR9 0 + TR10 0 + TR11 0 + TR12 0 + TR13 0 + TR14 0 + TR15 0 + TR16 0 + TR17 0 + TR18 0 + +SWIER 0x00000000 read-write @ 0x40010410 + SWIER0 0 + SWIER1 0 + SWIER2 0 + SWIER3 0 + SWIER4 0 + SWIER5 0 + SWIER6 0 + SWIER7 0 + SWIER8 0 + SWIER9 0 + SWIER10 0 + SWIER11 0 + SWIER12 0 + SWIER13 0 + SWIER14 0 + SWIER15 0 + SWIER16 0 + SWIER17 0 + SWIER18 0 + +PR 0x00000000 read-write @ 0x40010414 + PR0 0 + PR1 0 + PR2 0 + PR3 0 + PR4 0 + PR5 0 + PR6 0 + PR7 0 + PR8 0 + PR9 0 + PR10 0 + PR11 0 + PR12 0 + PR13 0 + PR14 0 + PR15 0 + PR16 0 + PR17 0 + PR18 0 + +Peripheral :DMA1 +Name Value Access Address +ISR 0x00000000 read-only @ 0x40020000 + GIF1 0 + TCIF1 0 + HTIF1 0 + TEIF1 0 + GIF2 0 + TCIF2 0 + HTIF2 0 + TEIF2 0 + GIF3 0 + TCIF3 0 + HTIF3 0 + TEIF3 0 + GIF4 0 + TCIF4 0 + HTIF4 0 + TEIF4 0 + GIF5 0 + TCIF5 0 + HTIF5 0 + TEIF5 0 + GIF6 0 + TCIF6 0 + HTIF6 0 + TEIF6 0 + GIF7 0 + TCIF7 0 + HTIF7 0 + TEIF7 0 + +IFCR write-only write-only @ 0x40020004 + CGIF1 W + CGIF2 W + CGIF3 W + CGIF4 W + CGIF5 W + CGIF6 W + CGIF7 W + CTCIF1 W + CTCIF2 W + CTCIF3 W + CTCIF4 W + CTCIF5 W + CTCIF6 W + CTCIF7 W + CHTIF1 W + CHTIF2 W + CHTIF3 W + CHTIF4 W + CHTIF5 W + CHTIF6 W + CHTIF7 W + CTEIF1 W + CTEIF2 W + CTEIF3 W + CTEIF4 W + CTEIF5 W + CTEIF6 W + CTEIF7 W + +CCR1 0x00000000 read-write @ 0x40020008 + EN 0 + TCIE 0 + HTIE 0 + TEIE 0 + DIR 0 + CIRC 0 + PINC 0 + MINC 0 + PSIZE 0x0 + MSIZE 0x0 + PL 0x0 + MEM2MEM 0 + +CNDTR1 0x00000000 read-write @ 0x4002000C + NDT 0x0 + +CPAR1 0x00000000 read-write @ 0x40020010 + PA 0x0 + +CMAR1 0x00000000 read-write @ 0x40020014 + MA 0x0 + +CCR2 0x00000000 read-write @ 0x4002001C + EN 0 + TCIE 0 + HTIE 0 + TEIE 0 + DIR 0 + CIRC 0 + PINC 0 + MINC 0 + PSIZE 0x0 + MSIZE 0x0 + PL 0x0 + MEM2MEM 0 + +CNDTR2 0x00000000 read-write @ 0x40020020 + NDT 0x0 + +CPAR2 0x00000000 read-write @ 0x40020024 + PA 0x0 + +CMAR2 0x00000000 read-write @ 0x40020028 + MA 0x0 + +CCR3 0x00000000 read-write @ 0x40020030 + EN 0 + TCIE 0 + HTIE 0 + TEIE 0 + DIR 0 + CIRC 0 + PINC 0 + MINC 0 + PSIZE 0x0 + MSIZE 0x0 + PL 0x0 + MEM2MEM 0 + +CNDTR3 0x00000000 read-write @ 0x40020034 + NDT 0x0 + +CPAR3 0x00000000 read-write @ 0x40020038 + PA 0x0 + +CMAR3 0x00000000 read-write @ 0x4002003C + MA 0x0 + +CCR4 0x00000000 read-write @ 0x40020044 + EN 0 + TCIE 0 + HTIE 0 + TEIE 0 + DIR 0 + CIRC 0 + PINC 0 + MINC 0 + PSIZE 0x0 + MSIZE 0x0 + PL 0x0 + MEM2MEM 0 + +CNDTR4 0x00000000 read-write @ 0x40020048 + NDT 0x0 + +CPAR4 0x00000000 read-write @ 0x4002004C + PA 0x0 + +CMAR4 0x00000000 read-write @ 0x40020050 + MA 0x0 + +CCR5 0x00000000 read-write @ 0x40020058 + EN 0 + TCIE 0 + HTIE 0 + TEIE 0 + DIR 0 + CIRC 0 + PINC 0 + MINC 0 + PSIZE 0x0 + MSIZE 0x0 + PL 0x0 + MEM2MEM 0 + +CNDTR5 0x00000000 read-write @ 0x4002005C + NDT 0x0 + +CPAR5 0x00000000 read-write @ 0x40020060 + PA 0x0 + +CMAR5 0x00000000 read-write @ 0x40020064 + MA 0x0 + +CCR6 0x00000000 read-write @ 0x4002006C + EN 0 + TCIE 0 + HTIE 0 + TEIE 0 + DIR 0 + CIRC 0 + PINC 0 + MINC 0 + PSIZE 0x0 + MSIZE 0x0 + PL 0x0 + MEM2MEM 0 + +CNDTR6 0x00000000 read-write @ 0x40020070 + NDT 0x0 + +CPAR6 0x00000000 read-write @ 0x40020074 + PA 0x0 + +CMAR6 0x00000000 read-write @ 0x40020078 + MA 0x0 + +CCR7 0x00000000 read-write @ 0x40020080 + EN 0 + TCIE 0 + HTIE 0 + TEIE 0 + DIR 0 + CIRC 0 + PINC 0 + MINC 0 + PSIZE 0x0 + MSIZE 0x0 + PL 0x0 + MEM2MEM 0 + +CNDTR7 0x00000000 read-write @ 0x40020084 + NDT 0x0 + +CPAR7 0x00000000 read-write @ 0x40020088 + PA 0x0 + +CMAR7 0x00000000 read-write @ 0x4002008C + MA 0x0 + +Peripheral :DMA2 +Name Value Access Address +ISR 0x00000000 read-only @ 0x40020400 + GIF1 0 + TCIF1 0 + HTIF1 0 + TEIF1 0 + GIF2 0 + TCIF2 0 + HTIF2 0 + TEIF2 0 + GIF3 0 + TCIF3 0 + HTIF3 0 + TEIF3 0 + GIF4 0 + TCIF4 0 + HTIF4 0 + TEIF4 0 + GIF5 0 + TCIF5 0 + HTIF5 0 + TEIF5 0 + GIF6 0 + TCIF6 0 + HTIF6 0 + TEIF6 0 + GIF7 0 + TCIF7 0 + HTIF7 0 + TEIF7 0 + +IFCR write-only write-only @ 0x40020404 + CGIF1 W + CGIF2 W + CGIF3 W + CGIF4 W + CGIF5 W + CGIF6 W + CGIF7 W + CTCIF1 W + CTCIF2 W + CTCIF3 W + CTCIF4 W + CTCIF5 W + CTCIF6 W + CTCIF7 W + CHTIF1 W + CHTIF2 W + CHTIF3 W + CHTIF4 W + CHTIF5 W + CHTIF6 W + CHTIF7 W + CTEIF1 W + CTEIF2 W + CTEIF3 W + CTEIF4 W + CTEIF5 W + CTEIF6 W + CTEIF7 W + +CCR1 0x00000000 read-write @ 0x40020408 + EN 0 + TCIE 0 + HTIE 0 + TEIE 0 + DIR 0 + CIRC 0 + PINC 0 + MINC 0 + PSIZE 0x0 + MSIZE 0x0 + PL 0x0 + MEM2MEM 0 + +CNDTR1 0x00000000 read-write @ 0x4002040C + NDT 0x0 + +CPAR1 0x00000000 read-write @ 0x40020410 + PA 0x0 + +CMAR1 0x00000000 read-write @ 0x40020414 + MA 0x0 + +CCR2 0x00000000 read-write @ 0x4002041C + EN 0 + TCIE 0 + HTIE 0 + TEIE 0 + DIR 0 + CIRC 0 + PINC 0 + MINC 0 + PSIZE 0x0 + MSIZE 0x0 + PL 0x0 + MEM2MEM 0 + +CNDTR2 0x00000000 read-write @ 0x40020420 + NDT 0x0 + +CPAR2 0x00000000 read-write @ 0x40020424 + PA 0x0 + +CMAR2 0x00000000 read-write @ 0x40020428 + MA 0x0 + +CCR3 0x00000000 read-write @ 0x40020430 + EN 0 + TCIE 0 + HTIE 0 + TEIE 0 + DIR 0 + CIRC 0 + PINC 0 + MINC 0 + PSIZE 0x0 + MSIZE 0x0 + PL 0x0 + MEM2MEM 0 + +CNDTR3 0x00000000 read-write @ 0x40020434 + NDT 0x0 + +CPAR3 0x00000000 read-write @ 0x40020438 + PA 0x0 + +CMAR3 0x00000000 read-write @ 0x4002043C + MA 0x0 + +CCR4 0x00000000 read-write @ 0x40020444 + EN 0 + TCIE 0 + HTIE 0 + TEIE 0 + DIR 0 + CIRC 0 + PINC 0 + MINC 0 + PSIZE 0x0 + MSIZE 0x0 + PL 0x0 + MEM2MEM 0 + +CNDTR4 0x00000000 read-write @ 0x40020448 + NDT 0x0 + +CPAR4 0x00000000 read-write @ 0x4002044C + PA 0x0 + +CMAR4 0x00000000 read-write @ 0x40020450 + MA 0x0 + +CCR5 0x00000000 read-write @ 0x40020458 + EN 0 + TCIE 0 + HTIE 0 + TEIE 0 + DIR 0 + CIRC 0 + PINC 0 + MINC 0 + PSIZE 0x0 + MSIZE 0x0 + PL 0x0 + MEM2MEM 0 + +CNDTR5 0x00000000 read-write @ 0x4002045C + NDT 0x0 + +CPAR5 0x00000000 read-write @ 0x40020460 + PA 0x0 + +CMAR5 0x00000000 read-write @ 0x40020464 + MA 0x0 + +CCR6 0x00000000 read-write @ 0x4002046C + EN 0 + TCIE 0 + HTIE 0 + TEIE 0 + DIR 0 + CIRC 0 + PINC 0 + MINC 0 + PSIZE 0x0 + MSIZE 0x0 + PL 0x0 + MEM2MEM 0 + +CNDTR6 0x00000000 read-write @ 0x40020470 + NDT 0x0 + +CPAR6 0x00000000 read-write @ 0x40020474 + PA 0x0 + +CMAR6 0x00000000 read-write @ 0x40020478 + MA 0x0 + +CCR7 0x00000000 read-write @ 0x40020480 + EN 0 + TCIE 0 + HTIE 0 + TEIE 0 + DIR 0 + CIRC 0 + PINC 0 + MINC 0 + PSIZE 0x0 + MSIZE 0x0 + PL 0x0 + MEM2MEM 0 + +CNDTR7 0x00000000 read-write @ 0x40020484 + NDT 0x0 + +CPAR7 0x00000000 read-write @ 0x40020488 + PA 0x0 + +CMAR7 0x00000000 read-write @ 0x4002048C + MA 0x0 + +Peripheral :SDIO +Name Value Access Address +POWER 0x00000000 read-write @ 0x40018000 + PWRCTRL 0x0 + +CLKCR 0x00000000 read-write @ 0x40018004 + CLKDIV 0x0 + CLKEN 0 + PWRSAV 0 + BYPASS 0 + WIDBUS 0x0 + NEGEDGE 0 + HWFC_EN 0 + +ARG 0x00000000 read-write @ 0x40018008 + CMDARG 0x0 + +CMD 0x00000000 read-write @ 0x4001800C + CMDINDEX 0x0 + WAITRESP 0x0 + WAITINT 0 + WAITPEND 0 + CPSMEN 0 + SDIOSuspend 0 + ENCMDcompl 0 + nIEN 0 + CE_ATACMD 0 + +RESPCMD 0x00000000 read-only @ 0x40018010 + RESPCMD 0x0 + +RESPI1 0x00000000 read-only @ 0x40018014 + CARDSTATUS1 0x0 + +RESP2 0x00000000 read-only @ 0x40018018 + CARDSTATUS2 0x0 + +RESP3 0x00000000 read-only @ 0x4001801C + CARDSTATUS3 0x0 + +RESP4 0x00000000 read-only @ 0x40018020 + CARDSTATUS4 0x0 + +DTIMER 0x00000000 read-write @ 0x40018024 + DATATIME 0x0 + +DLEN 0x00000000 read-write @ 0x40018028 + DATALENGTH 0x0 + +DCTRL 0x00000000 read-write @ 0x4001802C + DTEN 0 + DTDIR 0 + DTMODE 0 + DMAEN 0 + DBLOCKSIZE 0x0 + PWSTART 0 + PWSTOP 0 + RWMOD 0 + SDIOEN 0 + +DCOUNT 0x00000000 read-only @ 0x40018030 + DATACOUNT 0x0 + +STA 0x00000000 read-only @ 0x40018034 + CCRCFAIL 0 + DCRCFAIL 0 + CTIMEOUT 0 + DTIMEOUT 0 + TXUNDERR 0 + RXOVERR 0 + CMDREND 0 + CMDSENT 0 + DATAEND 0 + STBITERR 0 + DBCKEND 0 + CMDACT 0 + TXACT 0 + RXACT 0 + TXFIFOHE 0 + RXFIFOHF 0 + TXFIFOF 0 + RXFIFOF 0 + TXFIFOE 0 + RXFIFOE 0 + TXDAVL 0 + RXDAVL 0 + SDIOIT 0 + CEATAEND 0 + +ICR 0x00000000 read-write @ 0x40018038 + CCRCFAILC 0 + DCRCFAILC 0 + CTIMEOUTC 0 + DTIMEOUTC 0 + TXUNDERRC 0 + RXOVERRC 0 + CMDRENDC 0 + CMDSENTC 0 + DATAENDC 0 + STBITERRC 0 + DBCKENDC 0 + SDIOITC 0 + CEATAENDC 0 + +MASK 0x00000000 read-write @ 0x4001803C + CCRCFAILIE 0 + DCRCFAILIE 0 + CTIMEOUTIE 0 + DTIMEOUTIE 0 + TXUNDERRIE 0 + RXOVERRIE 0 + CMDRENDIE 0 + CMDSENTIE 0 + DATAENDIE 0 + STBITERRIE 0 + DBACKENDIE 0 + CMDACTIE 0 + TXACTIE 0 + RXACTIE 0 + TXFIFOHEIE 0 + RXFIFOHFIE 0 + TXFIFOFIE 0 + RXFIFOFIE 0 + TXFIFOEIE 0 + RXFIFOEIE 0 + TXDAVLIE 0 + RXDAVLIE 0 + SDIOITIE 0 + CEATENDIE 0 + +FIFOCNT 0x00000000 read-only @ 0x40018048 + FIF0COUNT 0x0 + +FIFO 0x00000000 read-write @ 0x40018080 + FIFOData 0x0 + +Peripheral :RTC +Name Value Access Address +CRH 0x00000000 read-write @ 0x40002800 + SECIE 0 + ALRIE 0 + OWIE 0 + +CRL 0x00000000 undefined @ 0x40002804 + SECF 0 + ALRF 0 + OWF 0 + RSF 0 + CNF 0 + RTOFF 0 + +PRLH write-only write-only @ 0x40002808 + PRLH W + +PRLL write-only write-only @ 0x4000280C + PRLL W + +DIVH 0x00000000 read-only @ 0x40002810 + DIVH 0x0 + +DIVL 0x00008000 read-only @ 0x40002814 + DIVL 0x8000 + +CNTH 0x00000000 read-write @ 0x40002818 + CNTH 0x0 + +CNTL 0x00000000 read-write @ 0x4000281C + CNTL 0x0 + +ALRH write-only write-only @ 0x40002820 + ALRH W + +ALRL write-only write-only @ 0x40002824 + ALRL W + +Peripheral :BKP +Name Value Access Address +DR1 0x00000000 read-write @ 0x40006C04 + D1 0x0 + +DR2 0x00000000 read-write @ 0x40006C08 + D2 0x0 + +DR3 0x00000000 read-write @ 0x40006C0C + D3 0x0 + +DR4 0x00000000 read-write @ 0x40006C10 + D4 0x0 + +DR5 0x00000000 read-write @ 0x40006C14 + D5 0x0 + +DR6 0x00000000 read-write @ 0x40006C18 + D6 0x0 + +DR7 0x00000000 read-write @ 0x40006C1C + D7 0x0 + +DR8 0x00000000 read-write @ 0x40006C20 + D8 0x0 + +DR9 0x00000000 read-write @ 0x40006C24 + D9 0x0 + +DR10 0x00000000 read-write @ 0x40006C28 + D10 0x0 + +RTCCR 0x00000000 read-write @ 0x40006C2C + CAL 0x0 + CCO 0 + ASOE 0 + ASOS 0 + +CR 0x00000000 read-write @ 0x40006C30 + TPE 0 + TPAL 0 + +CSR 0x00000000 undefined @ 0x40006C34 + CTE 0 + CTI 0 + TPIE 0 + TEF 0 + TIF 0 + +DR11 0x00000000 read-write @ 0x40006C40 + DR11 0x0 + +DR12 0x00000000 read-write @ 0x40006C44 + DR12 0x0 + +DR13 0x00000000 read-write @ 0x40006C48 + DR13 0x0 + +DR14 0x00000000 read-write @ 0x40006C4C + D14 0x0 + +DR15 0x00000000 read-write @ 0x40006C50 + D15 0x0 + +DR16 0x00000000 read-write @ 0x40006C54 + D16 0x0 + +DR17 0x00000000 read-write @ 0x40006C58 + D17 0x0 + +DR18 0x00000000 read-write @ 0x40006C5C + D18 0x0 + +DR19 0x00000000 read-write @ 0x40006C60 + D19 0x0 + +DR20 0x00000000 read-write @ 0x40006C64 + D20 0x0 + +DR21 0x00000000 read-write @ 0x40006C68 + D21 0x0 + +DR22 0x00000000 read-write @ 0x40006C6C + D22 0x0 + +DR23 0x00000000 read-write @ 0x40006C70 + D23 0x0 + +DR24 0x00000000 read-write @ 0x40006C74 + D24 0x0 + +DR25 0x00000000 read-write @ 0x40006C78 + D25 0x0 + +DR26 0x00000000 read-write @ 0x40006C7C + D26 0x0 + +DR27 0x00000000 read-write @ 0x40006C80 + D27 0x0 + +DR28 0x00000000 read-write @ 0x40006C84 + D28 0x0 + +DR29 0x00000000 read-write @ 0x40006C88 + D29 0x0 + +DR30 0x00000000 read-write @ 0x40006C8C + D30 0x0 + +DR31 0x00000000 read-write @ 0x40006C90 + D31 0x0 + +DR32 0x00000000 read-write @ 0x40006C94 + D32 0x0 + +DR33 0x00000000 read-write @ 0x40006C98 + D33 0x0 + +DR34 0x00000000 read-write @ 0x40006C9C + D34 0x0 + +DR35 0x00000000 read-write @ 0x40006CA0 + D35 0x0 + +DR36 0x00000000 read-write @ 0x40006CA4 + D36 0x0 + +DR37 0x00000000 read-write @ 0x40006CA8 + D37 0x0 + +DR38 0x00000000 read-write @ 0x40006CAC + D38 0x0 + +DR39 0x00000000 read-write @ 0x40006CB0 + D39 0x0 + +DR40 0x00000000 read-write @ 0x40006CB4 + D40 0x0 + +DR41 0x00000000 read-write @ 0x40006CB8 + D41 0x0 + +DR42 0x00000000 read-write @ 0x40006CBC + D42 0x0 + +Peripheral :IWDG +Name Value Access Address +KR write-only write-only @ 0x40003000 + KEY W + +PR 0x00000000 read-write @ 0x40003004 + PR 0x0 + +RLR 0x00000FFF read-write @ 0x40003008 + RL 0xFFF + +SR 0x00000000 read-only @ 0x4000300C + PVU 0 + RVU 0 + +Peripheral :WWDG +Name Value Access Address +CR 0x0000007F read-write @ 0x40002C00 + T 0x7F + WDGA 0 + +CFR 0x0000007F read-write @ 0x40002C04 + W 0x7F + WDGTB 0x0 + EWI 0 + +SR 0x00000000 read-write @ 0x40002C08 + EWI 0 + +Peripheral :TIM1 +Name Value Access Address +CR1 0x00000000 read-write @ 0x40012C00 + CKD 0x0 + ARPE 0 + CMS 0x0 + DIR 0 + OPM 0 + URS 0 + UDIS 0 + CEN 0 + +CR2 0x00000000 read-write @ 0x40012C04 + OIS4 0 + OIS3N 0 + OIS3 0 + OIS2N 0 + OIS2 0 + OIS1N 0 + OIS1 0 + TI1S 0 + MMS 0x0 + CCDS 0 + CCUS 0 + CCPC 0 + +SMCR 0x00000000 read-write @ 0x40012C08 + ETP 0 + ECE 0 + ETPS 0x0 + ETF 0x0 + MSM 0 + TS 0x0 + SMS 0x0 + +DIER 0x00000000 read-write @ 0x40012C0C + TDE 0 + COMDE 0 + CC4DE 0 + CC3DE 0 + CC2DE 0 + CC1DE 0 + UDE 0 + TIE 0 + CC4IE 0 + CC3IE 0 + CC2IE 0 + CC1IE 0 + UIE 0 + BIE 0 + COMIE 0 + +SR 0x00000000 read-write @ 0x40012C10 + CC4OF 0 + CC3OF 0 + CC2OF 0 + CC1OF 0 + BIF 0 + TIF 0 + COMIF 0 + CC4IF 0 + CC3IF 0 + CC2IF 0 + CC1IF 0 + UIF 0 + +EGR write-only write-only @ 0x40012C14 + BG W + TG W + COMG W + CC4G W + CC3G W + CC2G W + CC1G W + UG W + +CCMR1_Output 0x00000000 read-write @ 0x40012C18 + OC2CE 0 + OC2M 0x0 + OC2PE 0 + OC2FE 0 + CC2S 0x0 + OC1CE 0 + OC1M 0x0 + OC1PE 0 + OC1FE 0 + CC1S 0x0 + +CCMR1_Input 0x00000000 read-write @ 0x40012C18 + IC2F 0x0 + IC2PSC 0x0 + CC2S 0x0 + IC1F 0x0 + IC1PSC 0x0 + CC1S 0x0 + +CCMR2_Output 0x00000000 read-write @ 0x40012C1C + OC4CE 0 + OC4M 0x0 + OC4PE 0 + OC4FE 0 + CC4S 0x0 + OC3CE 0 + OC3M 0x0 + OC3PE 0 + OC3FE 0 + CC3S 0x0 + +CCMR2_Input 0x00000000 read-write @ 0x40012C1C + IC4F 0x0 + IC4PSC 0x0 + CC4S 0x0 + IC3F 0x0 + IC3PSC 0x0 + CC3S 0x0 + +CCER 0x00000000 read-write @ 0x40012C20 + CC4P 0 + CC4E 0 + CC3NP 0 + CC3NE 0 + CC3P 0 + CC3E 0 + CC2NP 0 + CC2NE 0 + CC2P 0 + CC2E 0 + CC1NP 0 + CC1NE 0 + CC1P 0 + CC1E 0 + +CNT 0x00000000 read-write @ 0x40012C24 + CNT 0x0 + +PSC 0x00000000 read-write @ 0x40012C28 + PSC 0x0 + +ARR 0x00000000 read-write @ 0x40012C2C + ARR 0x0 + +CCR1 0x00000000 read-write @ 0x40012C34 + CCR1 0x0 + +CCR2 0x00000000 read-write @ 0x40012C38 + CCR2 0x0 + +CCR3 0x00000000 read-write @ 0x40012C3C + CCR3 0x0 + +CCR4 0x00000000 read-write @ 0x40012C40 + CCR4 0x0 + +DCR 0x00000000 read-write @ 0x40012C48 + DBL 0x0 + DBA 0x0 + +DMAR 0x00000000 read-write @ 0x40012C4C + DMAB 0x0 + +RCR 0x00000000 read-write @ 0x40012C30 + REP 0x0 + +BDTR 0x00000000 read-write @ 0x40012C44 + MOE 0 + AOE 0 + BKP 0 + BKE 0 + OSSR 0 + OSSI 0 + LOCK 0x0 + DTG 0x0 + +Peripheral :TIM8 +Name Value Access Address +CR1 0x00000000 read-write @ 0x40013400 + CKD 0x0 + ARPE 0 + CMS 0x0 + DIR 0 + OPM 0 + URS 0 + UDIS 0 + CEN 0 + +CR2 0x00000000 read-write @ 0x40013404 + OIS4 0 + OIS3N 0 + OIS3 0 + OIS2N 0 + OIS2 0 + OIS1N 0 + OIS1 0 + TI1S 0 + MMS 0x0 + CCDS 0 + CCUS 0 + CCPC 0 + +SMCR 0x00000000 read-write @ 0x40013408 + ETP 0 + ECE 0 + ETPS 0x0 + ETF 0x0 + MSM 0 + TS 0x0 + SMS 0x0 + +DIER 0x00000000 read-write @ 0x4001340C + TDE 0 + COMDE 0 + CC4DE 0 + CC3DE 0 + CC2DE 0 + CC1DE 0 + UDE 0 + TIE 0 + CC4IE 0 + CC3IE 0 + CC2IE 0 + CC1IE 0 + UIE 0 + BIE 0 + COMIE 0 + +SR 0x00000000 read-write @ 0x40013410 + CC4OF 0 + CC3OF 0 + CC2OF 0 + CC1OF 0 + BIF 0 + TIF 0 + COMIF 0 + CC4IF 0 + CC3IF 0 + CC2IF 0 + CC1IF 0 + UIF 0 + +EGR write-only write-only @ 0x40013414 + BG W + TG W + COMG W + CC4G W + CC3G W + CC2G W + CC1G W + UG W + +CCMR1_Output 0x00000000 read-write @ 0x40013418 + OC2CE 0 + OC2M 0x0 + OC2PE 0 + OC2FE 0 + CC2S 0x0 + OC1CE 0 + OC1M 0x0 + OC1PE 0 + OC1FE 0 + CC1S 0x0 + +CCMR1_Input 0x00000000 read-write @ 0x40013418 + IC2F 0x0 + IC2PSC 0x0 + CC2S 0x0 + IC1F 0x0 + IC1PSC 0x0 + CC1S 0x0 + +CCMR2_Output 0x00000000 read-write @ 0x4001341C + OC4CE 0 + OC4M 0x0 + OC4PE 0 + OC4FE 0 + CC4S 0x0 + OC3CE 0 + OC3M 0x0 + OC3PE 0 + OC3FE 0 + CC3S 0x0 + +CCMR2_Input 0x00000000 read-write @ 0x4001341C + IC4F 0x0 + IC4PSC 0x0 + CC4S 0x0 + IC3F 0x0 + IC3PSC 0x0 + CC3S 0x0 + +CCER 0x00000000 read-write @ 0x40013420 + CC4P 0 + CC4E 0 + CC3NP 0 + CC3NE 0 + CC3P 0 + CC3E 0 + CC2NP 0 + CC2NE 0 + CC2P 0 + CC2E 0 + CC1NP 0 + CC1NE 0 + CC1P 0 + CC1E 0 + +CNT 0x00000000 read-write @ 0x40013424 + CNT 0x0 + +PSC 0x00000000 read-write @ 0x40013428 + PSC 0x0 + +ARR 0x00000000 read-write @ 0x4001342C + ARR 0x0 + +CCR1 0x00000000 read-write @ 0x40013434 + CCR1 0x0 + +CCR2 0x00000000 read-write @ 0x40013438 + CCR2 0x0 + +CCR3 0x00000000 read-write @ 0x4001343C + CCR3 0x0 + +CCR4 0x00000000 read-write @ 0x40013440 + CCR4 0x0 + +DCR 0x00000000 read-write @ 0x40013448 + DBL 0x0 + DBA 0x0 + +DMAR 0x00000000 read-write @ 0x4001344C + DMAB 0x0 + +RCR 0x00000000 read-write @ 0x40013430 + REP 0x0 + +BDTR 0x00000000 read-write @ 0x40013444 + MOE 0 + AOE 0 + BKP 0 + BKE 0 + OSSR 0 + OSSI 0 + LOCK 0x0 + DTG 0x0 + +Peripheral :TIM2 +Name Value Access Address +CR1 0x00000000 read-write @ 0x40000000 + CKD 0x0 + ARPE 0 + CMS 0x0 + DIR 0 + OPM 0 + URS 0 + UDIS 0 + CEN 0 + +CR2 0x00000000 read-write @ 0x40000004 + TI1S 0 + MMS 0x0 + CCDS 0 + +SMCR 0x00000000 read-write @ 0x40000008 + ETP 0 + ECE 0 + ETPS 0x0 + ETF 0x0 + MSM 0 + TS 0x0 + SMS 0x0 + +DIER 0x00000000 read-write @ 0x4000000C + TDE 0 + CC4DE 0 + CC3DE 0 + CC2DE 0 + CC1DE 0 + UDE 0 + TIE 0 + CC4IE 0 + CC3IE 0 + CC2IE 0 + CC1IE 0 + UIE 0 + +SR 0x00000000 read-write @ 0x40000010 + CC4OF 0 + CC3OF 0 + CC2OF 0 + CC1OF 0 + TIF 0 + CC4IF 0 + CC3IF 0 + CC2IF 0 + CC1IF 0 + UIF 0 + +EGR write-only write-only @ 0x40000014 + TG W + CC4G W + CC3G W + CC2G W + CC1G W + UG W + +CCMR1_Output 0x00000000 read-write @ 0x40000018 + OC2CE 0 + OC2M 0x0 + OC2PE 0 + OC2FE 0 + CC2S 0x0 + OC1CE 0 + OC1M 0x0 + OC1PE 0 + OC1FE 0 + CC1S 0x0 + +CCMR1_Input 0x00000000 read-write @ 0x40000018 + IC2F 0x0 + IC2PSC 0x0 + CC2S 0x0 + IC1F 0x0 + IC1PSC 0x0 + CC1S 0x0 + +CCMR2_Output 0x00000000 read-write @ 0x4000001C + O24CE 0 + OC4M 0x0 + OC4PE 0 + OC4FE 0 + CC4S 0x0 + OC3CE 0 + OC3M 0x0 + OC3PE 0 + OC3FE 0 + CC3S 0x0 + +CCMR2_Input 0x00000000 read-write @ 0x4000001C + IC4F 0x0 + IC4PSC 0x0 + CC4S 0x0 + IC3F 0x0 + IC3PSC 0x0 + CC3S 0x0 + +CCER 0x00000000 read-write @ 0x40000020 + CC4P 0 + CC4E 0 + CC3P 0 + CC3E 0 + CC2P 0 + CC2E 0 + CC1P 0 + CC1E 0 + +CNT 0x00000000 read-write @ 0x40000024 + CNT 0x0 + +PSC 0x00000000 read-write @ 0x40000028 + PSC 0x0 + +ARR 0x00000000 read-write @ 0x4000002C + ARR 0x0 + +CCR1 0x00000000 read-write @ 0x40000034 + CCR1 0x0 + +CCR2 0x00000000 read-write @ 0x40000038 + CCR2 0x0 + +CCR3 0x00000000 read-write @ 0x4000003C + CCR3 0x0 + +CCR4 0x00000000 read-write @ 0x40000040 + CCR4 0x0 + +DCR 0x00000000 read-write @ 0x40000048 + DBL 0x0 + DBA 0x0 + +DMAR 0x00000000 read-write @ 0x4000004C + DMAB 0x0 + +Peripheral :TIM3 +Name Value Access Address +CR1 0x00000000 read-write @ 0x40000400 + CKD 0x0 + ARPE 0 + CMS 0x0 + DIR 0 + OPM 0 + URS 0 + UDIS 0 + CEN 0 + +CR2 0x00000000 read-write @ 0x40000404 + TI1S 0 + MMS 0x0 + CCDS 0 + +SMCR 0x00000000 read-write @ 0x40000408 + ETP 0 + ECE 0 + ETPS 0x0 + ETF 0x0 + MSM 0 + TS 0x0 + SMS 0x0 + +DIER 0x00000000 read-write @ 0x4000040C + TDE 0 + CC4DE 0 + CC3DE 0 + CC2DE 0 + CC1DE 0 + UDE 0 + TIE 0 + CC4IE 0 + CC3IE 0 + CC2IE 0 + CC1IE 0 + UIE 0 + +SR 0x00000000 read-write @ 0x40000410 + CC4OF 0 + CC3OF 0 + CC2OF 0 + CC1OF 0 + TIF 0 + CC4IF 0 + CC3IF 0 + CC2IF 0 + CC1IF 0 + UIF 0 + +EGR write-only write-only @ 0x40000414 + TG W + CC4G W + CC3G W + CC2G W + CC1G W + UG W + +CCMR1_Output 0x00000000 read-write @ 0x40000418 + OC2CE 0 + OC2M 0x0 + OC2PE 0 + OC2FE 0 + CC2S 0x0 + OC1CE 0 + OC1M 0x0 + OC1PE 0 + OC1FE 0 + CC1S 0x0 + +CCMR1_Input 0x00000000 read-write @ 0x40000418 + IC2F 0x0 + IC2PSC 0x0 + CC2S 0x0 + IC1F 0x0 + IC1PSC 0x0 + CC1S 0x0 + +CCMR2_Output 0x00000000 read-write @ 0x4000041C + O24CE 0 + OC4M 0x0 + OC4PE 0 + OC4FE 0 + CC4S 0x0 + OC3CE 0 + OC3M 0x0 + OC3PE 0 + OC3FE 0 + CC3S 0x0 + +CCMR2_Input 0x00000000 read-write @ 0x4000041C + IC4F 0x0 + IC4PSC 0x0 + CC4S 0x0 + IC3F 0x0 + IC3PSC 0x0 + CC3S 0x0 + +CCER 0x00000000 read-write @ 0x40000420 + CC4P 0 + CC4E 0 + CC3P 0 + CC3E 0 + CC2P 0 + CC2E 0 + CC1P 0 + CC1E 0 + +CNT 0x00000000 read-write @ 0x40000424 + CNT 0x0 + +PSC 0x00000000 read-write @ 0x40000428 + PSC 0x0 + +ARR 0x00000000 read-write @ 0x4000042C + ARR 0x0 + +CCR1 0x00000000 read-write @ 0x40000434 + CCR1 0x0 + +CCR2 0x00000000 read-write @ 0x40000438 + CCR2 0x0 + +CCR3 0x00000000 read-write @ 0x4000043C + CCR3 0x0 + +CCR4 0x00000000 read-write @ 0x40000440 + CCR4 0x0 + +DCR 0x00000000 read-write @ 0x40000448 + DBL 0x0 + DBA 0x0 + +DMAR 0x00000000 read-write @ 0x4000044C + DMAB 0x0 + +Peripheral :TIM4 +Name Value Access Address +CR1 0x00000000 read-write @ 0x40000800 + CKD 0x0 + ARPE 0 + CMS 0x0 + DIR 0 + OPM 0 + URS 0 + UDIS 0 + CEN 0 + +CR2 0x00000000 read-write @ 0x40000804 + TI1S 0 + MMS 0x0 + CCDS 0 + +SMCR 0x00000000 read-write @ 0x40000808 + ETP 0 + ECE 0 + ETPS 0x0 + ETF 0x0 + MSM 0 + TS 0x0 + SMS 0x0 + +DIER 0x00000000 read-write @ 0x4000080C + TDE 0 + CC4DE 0 + CC3DE 0 + CC2DE 0 + CC1DE 0 + UDE 0 + TIE 0 + CC4IE 0 + CC3IE 0 + CC2IE 0 + CC1IE 0 + UIE 0 + +SR 0x00000000 read-write @ 0x40000810 + CC4OF 0 + CC3OF 0 + CC2OF 0 + CC1OF 0 + TIF 0 + CC4IF 0 + CC3IF 0 + CC2IF 0 + CC1IF 0 + UIF 0 + +EGR write-only write-only @ 0x40000814 + TG W + CC4G W + CC3G W + CC2G W + CC1G W + UG W + +CCMR1_Output 0x00000000 read-write @ 0x40000818 + OC2CE 0 + OC2M 0x0 + OC2PE 0 + OC2FE 0 + CC2S 0x0 + OC1CE 0 + OC1M 0x0 + OC1PE 0 + OC1FE 0 + CC1S 0x0 + +CCMR1_Input 0x00000000 read-write @ 0x40000818 + IC2F 0x0 + IC2PSC 0x0 + CC2S 0x0 + IC1F 0x0 + IC1PSC 0x0 + CC1S 0x0 + +CCMR2_Output 0x00000000 read-write @ 0x4000081C + O24CE 0 + OC4M 0x0 + OC4PE 0 + OC4FE 0 + CC4S 0x0 + OC3CE 0 + OC3M 0x0 + OC3PE 0 + OC3FE 0 + CC3S 0x0 + +CCMR2_Input 0x00000000 read-write @ 0x4000081C + IC4F 0x0 + IC4PSC 0x0 + CC4S 0x0 + IC3F 0x0 + IC3PSC 0x0 + CC3S 0x0 + +CCER 0x00000000 read-write @ 0x40000820 + CC4P 0 + CC4E 0 + CC3P 0 + CC3E 0 + CC2P 0 + CC2E 0 + CC1P 0 + CC1E 0 + +CNT 0x00000000 read-write @ 0x40000824 + CNT 0x0 + +PSC 0x00000000 read-write @ 0x40000828 + PSC 0x0 + +ARR 0x00000000 read-write @ 0x4000082C + ARR 0x0 + +CCR1 0x00000000 read-write @ 0x40000834 + CCR1 0x0 + +CCR2 0x00000000 read-write @ 0x40000838 + CCR2 0x0 + +CCR3 0x00000000 read-write @ 0x4000083C + CCR3 0x0 + +CCR4 0x00000000 read-write @ 0x40000840 + CCR4 0x0 + +DCR 0x00000000 read-write @ 0x40000848 + DBL 0x0 + DBA 0x0 + +DMAR 0x00000000 read-write @ 0x4000084C + DMAB 0x0 + +Peripheral :TIM5 +Name Value Access Address +CR1 0x00000000 read-write @ 0x40000C00 + CKD 0x0 + ARPE 0 + CMS 0x0 + DIR 0 + OPM 0 + URS 0 + UDIS 0 + CEN 0 + +CR2 0x00000000 read-write @ 0x40000C04 + TI1S 0 + MMS 0x0 + CCDS 0 + +SMCR 0x00000000 read-write @ 0x40000C08 + ETP 0 + ECE 0 + ETPS 0x0 + ETF 0x0 + MSM 0 + TS 0x0 + SMS 0x0 + +DIER 0x00000000 read-write @ 0x40000C0C + TDE 0 + CC4DE 0 + CC3DE 0 + CC2DE 0 + CC1DE 0 + UDE 0 + TIE 0 + CC4IE 0 + CC3IE 0 + CC2IE 0 + CC1IE 0 + UIE 0 + +SR 0x00000000 read-write @ 0x40000C10 + CC4OF 0 + CC3OF 0 + CC2OF 0 + CC1OF 0 + TIF 0 + CC4IF 0 + CC3IF 0 + CC2IF 0 + CC1IF 0 + UIF 0 + +EGR write-only write-only @ 0x40000C14 + TG W + CC4G W + CC3G W + CC2G W + CC1G W + UG W + +CCMR1_Output 0x00000000 read-write @ 0x40000C18 + OC2CE 0 + OC2M 0x0 + OC2PE 0 + OC2FE 0 + CC2S 0x0 + OC1CE 0 + OC1M 0x0 + OC1PE 0 + OC1FE 0 + CC1S 0x0 + +CCMR1_Input 0x00000000 read-write @ 0x40000C18 + IC2F 0x0 + IC2PSC 0x0 + CC2S 0x0 + IC1F 0x0 + IC1PSC 0x0 + CC1S 0x0 + +CCMR2_Output 0x00000000 read-write @ 0x40000C1C + O24CE 0 + OC4M 0x0 + OC4PE 0 + OC4FE 0 + CC4S 0x0 + OC3CE 0 + OC3M 0x0 + OC3PE 0 + OC3FE 0 + CC3S 0x0 + +CCMR2_Input 0x00000000 read-write @ 0x40000C1C + IC4F 0x0 + IC4PSC 0x0 + CC4S 0x0 + IC3F 0x0 + IC3PSC 0x0 + CC3S 0x0 + +CCER 0x00000000 read-write @ 0x40000C20 + CC4P 0 + CC4E 0 + CC3P 0 + CC3E 0 + CC2P 0 + CC2E 0 + CC1P 0 + CC1E 0 + +CNT 0x00000000 read-write @ 0x40000C24 + CNT 0x0 + +PSC 0x00000000 read-write @ 0x40000C28 + PSC 0x0 + +ARR 0x00000000 read-write @ 0x40000C2C + ARR 0x0 + +CCR1 0x00000000 read-write @ 0x40000C34 + CCR1 0x0 + +CCR2 0x00000000 read-write @ 0x40000C38 + CCR2 0x0 + +CCR3 0x00000000 read-write @ 0x40000C3C + CCR3 0x0 + +CCR4 0x00000000 read-write @ 0x40000C40 + CCR4 0x0 + +DCR 0x00000000 read-write @ 0x40000C48 + DBL 0x0 + DBA 0x0 + +DMAR 0x00000000 read-write @ 0x40000C4C + DMAB 0x0 + +Peripheral :TIM9 +Name Value Access Address +CR1 -- read-write @ 0x40014C00 + CKD -- + ARPE -- + OPM -- + URS -- + UDIS -- + CEN -- + +CR2 -- read-write @ 0x40014C04 + MMS -- + +SMCR -- read-write @ 0x40014C08 + MSM -- + TS -- + SMS -- + +DIER -- read-write @ 0x40014C0C + TIE -- + CC2IE -- + CC1IE -- + UIE -- + +SR -- read-write @ 0x40014C10 + CC2OF -- + CC1OF -- + TIF -- + CC2IF -- + CC1IF -- + UIF -- + +EGR write-only write-only @ 0x40014C14 + TG W + CC2G W + CC1G W + UG W + +CCMR1_Output -- read-write @ 0x40014C18 + OC2M -- + OC2PE -- + OC2FE -- + CC2S -- + OC1M -- + OC1PE -- + OC1FE -- + CC1S -- + +CCMR1_Input -- read-write @ 0x40014C18 + IC2F -- + IC2PSC -- + CC2S -- + IC1F -- + IC1PSC -- + CC1S -- + +CCER -- read-write @ 0x40014C20 + CC2NP -- + CC2P -- + CC2E -- + CC1NP -- + CC1P -- + CC1E -- + +CNT -- read-write @ 0x40014C24 + CNT -- + +PSC -- read-write @ 0x40014C28 + PSC -- + +ARR -- read-write @ 0x40014C2C + ARR -- + +CCR1 -- read-write @ 0x40014C34 + CCR1 -- + +CCR2 -- read-write @ 0x40014C38 + CCR2 -- + +Peripheral :TIM12 +Name Value Access Address +CR1 0x00000000 read-write @ 0x40001800 + CKD 0x0 + ARPE 0 + OPM 0 + URS 0 + UDIS 0 + CEN 0 + +CR2 0x00000000 read-write @ 0x40001804 + MMS 0x0 + +SMCR 0x00000000 read-write @ 0x40001808 + MSM 0 + TS 0x0 + SMS 0x0 + +DIER 0x00000000 read-write @ 0x4000180C + TIE 0 + CC2IE 0 + CC1IE 0 + UIE 0 + +SR 0x00000000 read-write @ 0x40001810 + CC2OF 0 + CC1OF 0 + TIF 0 + CC2IF 0 + CC1IF 0 + UIF 0 + +EGR write-only write-only @ 0x40001814 + TG W + CC2G W + CC1G W + UG W + +CCMR1_Output 0x00000000 read-write @ 0x40001818 + OC2M 0x0 + OC2PE 0 + OC2FE 0 + CC2S 0x0 + OC1M 0x0 + OC1PE 0 + OC1FE 0 + CC1S 0x0 + +CCMR1_Input 0x00000000 read-write @ 0x40001818 + IC2F 0x0 + IC2PSC 0x0 + CC2S 0x0 + IC1F 0x0 + IC1PSC 0x0 + CC1S 0x0 + +CCER 0x00000000 read-write @ 0x40001820 + CC2NP 0 + CC2P 0 + CC2E 0 + CC1NP 0 + CC1P 0 + CC1E 0 + +CNT 0x00000000 read-write @ 0x40001824 + CNT 0x0 + +PSC 0x00000000 read-write @ 0x40001828 + PSC 0x0 + +ARR 0x00000000 read-write @ 0x4000182C + ARR 0x0 + +CCR1 0x00000000 read-write @ 0x40001834 + CCR1 0x0 + +CCR2 0x00000000 read-write @ 0x40001838 + CCR2 0x0 + +Peripheral :TIM10 +Name Value Access Address +CR1 -- read-write @ 0x40015000 + CKD -- + ARPE -- + URS -- + UDIS -- + CEN -- + +CR2 -- read-write @ 0x40015004 + MMS -- + +DIER -- read-write @ 0x4001500C + CC1IE -- + UIE -- + +SR -- read-write @ 0x40015010 + CC1OF -- + CC1IF -- + UIF -- + +EGR write-only write-only @ 0x40015014 + CC1G W + UG W + +CCMR1_Output -- read-write @ 0x40015018 + OC1M -- + OC1PE -- + CC1S -- + +CCMR1_Input -- read-write @ 0x40015018 + IC1F -- + IC1PSC -- + CC1S -- + +CCER -- read-write @ 0x40015020 + CC1NP -- + CC1P -- + CC1E -- + +CNT -- read-write @ 0x40015024 + CNT -- + +PSC -- read-write @ 0x40015028 + PSC -- + +ARR -- read-write @ 0x4001502C + ARR -- + +CCR1 -- read-write @ 0x40015034 + CCR1 -- + +Peripheral :TIM11 +Name Value Access Address +CR1 -- read-write @ 0x40015400 + CKD -- + ARPE -- + URS -- + UDIS -- + CEN -- + +CR2 -- read-write @ 0x40015404 + MMS -- + +DIER -- read-write @ 0x4001540C + CC1IE -- + UIE -- + +SR -- read-write @ 0x40015410 + CC1OF -- + CC1IF -- + UIF -- + +EGR write-only write-only @ 0x40015414 + CC1G W + UG W + +CCMR1_Output -- read-write @ 0x40015418 + OC1M -- + OC1PE -- + CC1S -- + +CCMR1_Input -- read-write @ 0x40015418 + IC1F -- + IC1PSC -- + CC1S -- + +CCER -- read-write @ 0x40015420 + CC1NP -- + CC1P -- + CC1E -- + +CNT -- read-write @ 0x40015424 + CNT -- + +PSC -- read-write @ 0x40015428 + PSC -- + +ARR -- read-write @ 0x4001542C + ARR -- + +CCR1 -- read-write @ 0x40015434 + CCR1 -- + +Peripheral :TIM13 +Name Value Access Address +CR1 0x00000000 read-write @ 0x40001C00 + CKD 0x0 + ARPE 0 + URS 0 + UDIS 0 + CEN 0 + +CR2 0x00000000 read-write @ 0x40001C04 + MMS 0x0 + +DIER 0x00000000 read-write @ 0x40001C0C + CC1IE 0 + UIE 0 + +SR 0x00000000 read-write @ 0x40001C10 + CC1OF 0 + CC1IF 0 + UIF 0 + +EGR write-only write-only @ 0x40001C14 + CC1G W + UG W + +CCMR1_Output 0x00000000 read-write @ 0x40001C18 + OC1M 0x0 + OC1PE 0 + CC1S 0x0 + +CCMR1_Input 0x00000000 read-write @ 0x40001C18 + IC1F 0x0 + IC1PSC 0x0 + CC1S 0x0 + +CCER 0x00000000 read-write @ 0x40001C20 + CC1NP 0 + CC1P 0 + CC1E 0 + +CNT 0x00000000 read-write @ 0x40001C24 + CNT 0x0 + +PSC 0x00000000 read-write @ 0x40001C28 + PSC 0x0 + +ARR 0x00000000 read-write @ 0x40001C2C + ARR 0x0 + +CCR1 0x00000000 read-write @ 0x40001C34 + CCR1 0x0 + +Peripheral :TIM14 +Name Value Access Address +CR1 0x00000000 read-write @ 0x40002000 + CKD 0x0 + ARPE 0 + URS 0 + UDIS 0 + CEN 0 + +CR2 0x00000000 read-write @ 0x40002004 + MMS 0x0 + +DIER 0x00000000 read-write @ 0x4000200C + CC1IE 0 + UIE 0 + +SR 0x00000000 read-write @ 0x40002010 + CC1OF 0 + CC1IF 0 + UIF 0 + +EGR write-only write-only @ 0x40002014 + CC1G W + UG W + +CCMR1_Output 0x00000000 read-write @ 0x40002018 + OC1M 0x0 + OC1PE 0 + CC1S 0x0 + +CCMR1_Input 0x00000000 read-write @ 0x40002018 + IC1F 0x0 + IC1PSC 0x0 + CC1S 0x0 + +CCER 0x00000000 read-write @ 0x40002020 + CC1NP 0 + CC1P 0 + CC1E 0 + +CNT 0x00000000 read-write @ 0x40002024 + CNT 0x0 + +PSC 0x00000000 read-write @ 0x40002028 + PSC 0x0 + +ARR 0x00000000 read-write @ 0x4000202C + ARR 0x0 + +CCR1 0x00000000 read-write @ 0x40002034 + CCR1 0x0 + +Peripheral :TIM6 +Name Value Access Address +CR1 0x00000000 read-write @ 0x40001000 + ARPE 0 + OPM 0 + URS 0 + UDIS 0 + CEN 0 + +CR2 0x00000000 read-write @ 0x40001004 + MMS 0x0 + +DIER 0x00000000 read-write @ 0x4000100C + UDE 0 + UIE 0 + +SR 0x00000000 read-write @ 0x40001010 + UIF 0 + +EGR write-only write-only @ 0x40001014 + UG W + +CNT 0x00000000 read-write @ 0x40001024 + CNT 0x0 + +PSC 0x00000000 read-write @ 0x40001028 + PSC 0x0 + +ARR 0x00000000 read-write @ 0x4000102C + ARR 0x0 + +Peripheral :TIM7 +Name Value Access Address +CR1 0x00000000 read-write @ 0x40001400 + ARPE 0 + OPM 0 + URS 0 + UDIS 0 + CEN 0 + +CR2 0x00000000 read-write @ 0x40001404 + MMS 0x0 + +DIER 0x00000000 read-write @ 0x4000140C + UDE 0 + UIE 0 + +SR 0x00000000 read-write @ 0x40001410 + UIF 0 + +EGR write-only write-only @ 0x40001414 + UG W + +CNT 0x00000000 read-write @ 0x40001424 + CNT 0x0 + +PSC 0x00000000 read-write @ 0x40001428 + PSC 0x0 + +ARR 0x00000000 read-write @ 0x4000142C + ARR 0x0 + +Peripheral :I2C1 +Name Value Access Address +CR1 0x00000000 read-write @ 0x40005400 + SWRST 0 + ALERT 0 + PEC 0 + POS 0 + ACK 0 + STOP 0 + START 0 + NOSTRETCH 0 + ENGC 0 + ENPEC 0 + ENARP 0 + SMBTYPE 0 + SMBUS 0 + PE 0 + +CR2 0x00000000 read-write @ 0x40005404 + LAST 0 + DMAEN 0 + ITBUFEN 0 + ITEVTEN 0 + ITERREN 0 + FREQ 0x0 + +OAR1 0x00000000 read-write @ 0x40005408 + ADDMODE 0 + ADD10 0x0 + ADD7 0x0 + ADD0 0 + +OAR2 0x00000000 read-write @ 0x4000540C + ADD2 0x0 + ENDUAL 0 + +DR 0x00000000 read-write @ 0x40005410 + DR 0x0 + +SR1 0x00000000 undefined @ 0x40005414 + SMBALERT 0 + TIMEOUT 0 + PECERR 0 + OVR 0 + AF 0 + ARLO 0 + BERR 0 + TxE 0 + RxNE 0 + STOPF 0 + ADD10 0 + BTF 0 + ADDR 0 + SB 0 + +SR2 0x00000000 read-only @ 0x40005418 + PEC 0x0 + DUALF 0 + SMBHOST 0 + SMBDEFAULT 0 + GENCALL 0 + TRA 0 + BUSY 0 + MSL 0 + +CCR 0x00000000 read-write @ 0x4000541C + F_S 0 + DUTY 0 + CCR 0x0 + +TRISE 0x00000000 read-write @ 0x40005420 + TRISE 0x0 + +Peripheral :I2C2 +Name Value Access Address +CR1 0x00000000 read-write @ 0x40005800 + SWRST 0 + ALERT 0 + PEC 0 + POS 0 + ACK 0 + STOP 0 + START 0 + NOSTRETCH 0 + ENGC 0 + ENPEC 0 + ENARP 0 + SMBTYPE 0 + SMBUS 0 + PE 0 + +CR2 0x00000000 read-write @ 0x40005804 + LAST 0 + DMAEN 0 + ITBUFEN 0 + ITEVTEN 0 + ITERREN 0 + FREQ 0x0 + +OAR1 0x00000000 read-write @ 0x40005808 + ADDMODE 0 + ADD10 0x0 + ADD7 0x0 + ADD0 0 + +OAR2 0x00000000 read-write @ 0x4000580C + ADD2 0x0 + ENDUAL 0 + +DR 0x00000000 read-write @ 0x40005810 + DR 0x0 + +SR1 0x00000000 undefined @ 0x40005814 + SMBALERT 0 + TIMEOUT 0 + PECERR 0 + OVR 0 + AF 0 + ARLO 0 + BERR 0 + TxE 0 + RxNE 0 + STOPF 0 + ADD10 0 + BTF 0 + ADDR 0 + SB 0 + +SR2 0x00000000 read-only @ 0x40005818 + PEC 0x0 + DUALF 0 + SMBHOST 0 + SMBDEFAULT 0 + GENCALL 0 + TRA 0 + BUSY 0 + MSL 0 + +CCR 0x00000000 read-write @ 0x4000581C + F_S 0 + DUTY 0 + CCR 0x0 + +TRISE 0x00000000 read-write @ 0x40005820 + TRISE 0x0 + +Peripheral :SPI1 +Name Value Access Address +CR1 0x00000000 read-write @ 0x40013000 + BIDIMODE 0 + BIDIOE 0 + CRCEN 0 + CRCNEXT 0 + DFF 0 + RXONLY 0 + SSM 0 + SSI 0 + LSBFIRST 0 + SPE 0 + BR 0x0 + MSTR 0 + CPOL 0 + CPHA 0 + +CR2 0x00000000 read-write @ 0x40013004 + TXEIE 0 + RXNEIE 0 + ERRIE 0 + SSOE 0 + TXDMAEN 0 + RXDMAEN 0 + +SR 0x00000000 undefined @ 0x40013008 + BSY 0 + OVR 0 + MODF 0 + CRCERR 0 + UDR 0 + CHSIDE 0 + TXE 0 + RXNE 0 + +DR 0x00000000 read-write @ 0x4001300C + DR 0x0 + +CRCPR 0x00000000 read-write @ 0x40013010 + CRCPOLY 0x0 + +RXCRCR 0x00000000 read-only @ 0x40013014 + RxCRC 0x0 + +TXCRCR 0x00000000 read-only @ 0x40013018 + TxCRC 0x0 + +I2SCFGR 0x00000000 read-write @ 0x4001301C + I2SMOD 0 + I2SE 0 + I2SCFG 0x0 + PCMSYNC 0 + I2SSTD 0x0 + CKPOL 0 + DATLEN 0x0 + CHLEN 0 + +I2SPR 0x00000000 read-write @ 0x40013020 + MCKOE 0 + ODD 0 + I2SDIV 0x0 + +Peripheral :SPI2 +Name Value Access Address +CR1 0x00000000 read-write @ 0x40003800 + BIDIMODE 0 + BIDIOE 0 + CRCEN 0 + CRCNEXT 0 + DFF 0 + RXONLY 0 + SSM 0 + SSI 0 + LSBFIRST 0 + SPE 0 + BR 0x0 + MSTR 0 + CPOL 0 + CPHA 0 + +CR2 0x00000000 read-write @ 0x40003804 + TXEIE 0 + RXNEIE 0 + ERRIE 0 + SSOE 0 + TXDMAEN 0 + RXDMAEN 0 + +SR 0x00000000 undefined @ 0x40003808 + BSY 0 + OVR 0 + MODF 0 + CRCERR 0 + UDR 0 + CHSIDE 0 + TXE 0 + RXNE 0 + +DR 0x00000000 read-write @ 0x4000380C + DR 0x0 + +CRCPR 0x00000000 read-write @ 0x40003810 + CRCPOLY 0x0 + +RXCRCR 0x00000000 read-only @ 0x40003814 + RxCRC 0x0 + +TXCRCR 0x00000000 read-only @ 0x40003818 + TxCRC 0x0 + +I2SCFGR 0x00000000 read-write @ 0x4000381C + I2SMOD 0 + I2SE 0 + I2SCFG 0x0 + PCMSYNC 0 + I2SSTD 0x0 + CKPOL 0 + DATLEN 0x0 + CHLEN 0 + +I2SPR 0x00000000 read-write @ 0x40003820 + MCKOE 0 + ODD 0 + I2SDIV 0x0 + +Peripheral :SPI3 +Name Value Access Address +CR1 0x00000000 read-write @ 0x40003C00 + BIDIMODE 0 + BIDIOE 0 + CRCEN 0 + CRCNEXT 0 + DFF 0 + RXONLY 0 + SSM 0 + SSI 0 + LSBFIRST 0 + SPE 0 + BR 0x0 + MSTR 0 + CPOL 0 + CPHA 0 + +CR2 0x00000000 read-write @ 0x40003C04 + TXEIE 0 + RXNEIE 0 + ERRIE 0 + SSOE 0 + TXDMAEN 0 + RXDMAEN 0 + +SR 0x00000000 undefined @ 0x40003C08 + BSY 0 + OVR 0 + MODF 0 + CRCERR 0 + UDR 0 + CHSIDE 0 + TXE 0 + RXNE 0 + +DR 0x00000000 read-write @ 0x40003C0C + DR 0x0 + +CRCPR 0x00000000 read-write @ 0x40003C10 + CRCPOLY 0x0 + +RXCRCR 0x00000000 read-only @ 0x40003C14 + RxCRC 0x0 + +TXCRCR 0x00000000 read-only @ 0x40003C18 + TxCRC 0x0 + +I2SCFGR 0x00000000 read-write @ 0x40003C1C + I2SMOD 0 + I2SE 0 + I2SCFG 0x0 + PCMSYNC 0 + I2SSTD 0x0 + CKPOL 0 + DATLEN 0x0 + CHLEN 0 + +I2SPR 0x00000000 read-write @ 0x40003C20 + MCKOE 0 + ODD 0 + I2SDIV 0x0 + +Peripheral :USART1 +Name Value Access Address +SR 0x00000000 undefined @ 0x40013800 + CTS 0 + LBD 0 + TXE 0 + TC 0 + RXNE 0 + IDLE 0 + ORE 0 + NE 0 + FE 0 + PE 0 + +DR 0x00000000 read-write @ 0x40013804 + DR 0x0 + +BRR 0x00000000 read-write @ 0x40013808 + DIV_Mantissa 0x0 + DIV_Fraction 0x0 + +CR1 0x00000000 read-write @ 0x4001380C + UE 0 + M 0 + WAKE 0 + PCE 0 + PS 0 + PEIE 0 + TXEIE 0 + TCIE 0 + RXNEIE 0 + IDLEIE 0 + TE 0 + RE 0 + RWU 0 + SBK 0 + +CR2 0x00000000 read-write @ 0x40013810 + LINEN 0 + STOP 0x0 + CLKEN 0 + CPOL 0 + CPHA 0 + LBCL 0 + LBDIE 0 + LBDL 0 + ADD 0x0 + +CR3 0x00000000 read-write @ 0x40013814 + CTSIE 0 + CTSE 0 + RTSE 0 + DMAT 0 + DMAR 0 + SCEN 0 + NACK 0 + HDSEL 0 + IRLP 0 + IREN 0 + EIE 0 + +GTPR 0x00000000 read-write @ 0x40013818 + GT 0x0 + PSC 0x0 + +Peripheral :USART2 +Name Value Access Address +SR 0x00000000 undefined @ 0x40004400 + CTS 0 + LBD 0 + TXE 0 + TC 0 + RXNE 0 + IDLE 0 + ORE 0 + NE 0 + FE 0 + PE 0 + +DR 0x00000000 read-write @ 0x40004404 + DR 0x0 + +BRR 0x00000000 read-write @ 0x40004408 + DIV_Mantissa 0x0 + DIV_Fraction 0x0 + +CR1 0x00000000 read-write @ 0x4000440C + UE 0 + M 0 + WAKE 0 + PCE 0 + PS 0 + PEIE 0 + TXEIE 0 + TCIE 0 + RXNEIE 0 + IDLEIE 0 + TE 0 + RE 0 + RWU 0 + SBK 0 + +CR2 0x00000000 read-write @ 0x40004410 + LINEN 0 + STOP 0x0 + CLKEN 0 + CPOL 0 + CPHA 0 + LBCL 0 + LBDIE 0 + LBDL 0 + ADD 0x0 + +CR3 0x00000000 read-write @ 0x40004414 + CTSIE 0 + CTSE 0 + RTSE 0 + DMAT 0 + DMAR 0 + SCEN 0 + NACK 0 + HDSEL 0 + IRLP 0 + IREN 0 + EIE 0 + +GTPR 0x00000000 read-write @ 0x40004418 + GT 0x0 + PSC 0x0 + +Peripheral :USART3 +Name Value Access Address +SR 0x00000000 undefined @ 0x40004800 + CTS 0 + LBD 0 + TXE 0 + TC 0 + RXNE 0 + IDLE 0 + ORE 0 + NE 0 + FE 0 + PE 0 + +DR 0x00000000 read-write @ 0x40004804 + DR 0x0 + +BRR 0x00000000 read-write @ 0x40004808 + DIV_Mantissa 0x0 + DIV_Fraction 0x0 + +CR1 0x00000000 read-write @ 0x4000480C + UE 0 + M 0 + WAKE 0 + PCE 0 + PS 0 + PEIE 0 + TXEIE 0 + TCIE 0 + RXNEIE 0 + IDLEIE 0 + TE 0 + RE 0 + RWU 0 + SBK 0 + +CR2 0x00000000 read-write @ 0x40004810 + LINEN 0 + STOP 0x0 + CLKEN 0 + CPOL 0 + CPHA 0 + LBCL 0 + LBDIE 0 + LBDL 0 + ADD 0x0 + +CR3 0x00000000 read-write @ 0x40004814 + CTSIE 0 + CTSE 0 + RTSE 0 + DMAT 0 + DMAR 0 + SCEN 0 + NACK 0 + HDSEL 0 + IRLP 0 + IREN 0 + EIE 0 + +GTPR 0x00000000 read-write @ 0x40004818 + GT 0x0 + PSC 0x0 + +Peripheral :ADC1 +Name Value Access Address +SR 0x00000000 read-write @ 0x40012400 + STRT 0 + JSTRT 0 + JEOC 0 + EOC 0 + AWD 0 + +CR1 0x00000000 read-write @ 0x40012404 + AWDEN 0 + JAWDEN 0 + DUALMOD 0x0 + DISCNUM 0x0 + JDISCEN 0 + DISCEN 0 + JAUTO 0 + AWDSGL 0 + SCAN 0 + JEOCIE 0 + AWDIE 0 + EOCIE 0 + AWDCH 0x0 + +CR2 0x00000000 read-write @ 0x40012408 + TSVREFE 0 + SWSTART 0 + JSWSTART 0 + EXTTRIG 0 + EXTSEL 0x0 + JEXTTRIG 0 + JEXTSEL 0x0 + ALIGN 0 + DMA 0 + RSTCAL 0 + CAL 0 + CONT 0 + ADON 0 + +SMPR1 0x00000000 read-write @ 0x4001240C + SMP10 0x0 + SMP11 0x0 + SMP12 0x0 + SMP13 0x0 + SMP14 0x0 + SMP15 0x0 + SMP16 0x0 + SMP17 0x0 + +SMPR2 0x00000000 read-write @ 0x40012410 + SMP0 0x0 + SMP1 0x0 + SMP2 0x0 + SMP3 0x0 + SMP4 0x0 + SMP5 0x0 + SMP6 0x0 + SMP7 0x0 + SMP8 0x0 + SMP9 0x0 + +JOFR1 0x00000000 read-write @ 0x40012414 + JOFFSET1 0x0 + +JOFR2 0x00000000 read-write @ 0x40012418 + JOFFSET2 0x0 + +JOFR3 0x00000000 read-write @ 0x4001241C + JOFFSET3 0x0 + +JOFR4 0x00000000 read-write @ 0x40012420 + JOFFSET4 0x0 + +HTR 0x00000FFF read-write @ 0x40012424 + HT 0xFFF + +LTR 0x00000000 read-write @ 0x40012428 + LT 0x0 + +SQR1 0x00000000 read-write @ 0x4001242C + L 0x0 + SQ16 0x0 + SQ15 0x0 + SQ14 0x0 + SQ13 0x0 + +SQR2 0x00000000 read-write @ 0x40012430 + SQ12 0x0 + SQ11 0x0 + SQ10 0x0 + SQ9 0x0 + SQ8 0x0 + SQ7 0x0 + +SQR3 0x00000000 read-write @ 0x40012434 + SQ6 0x0 + SQ5 0x0 + SQ4 0x0 + SQ3 0x0 + SQ2 0x0 + SQ1 0x0 + +JSQR 0x00000000 read-write @ 0x40012438 + JL 0x0 + JSQ4 0x0 + JSQ3 0x0 + JSQ2 0x0 + JSQ1 0x0 + +JDR1 0x00000000 read-only @ 0x4001243C + JDATA 0x0 + +JDR2 0x00000000 read-only @ 0x40012440 + JDATA 0x0 + +JDR3 0x00000000 read-only @ 0x40012444 + JDATA 0x0 + +JDR4 0x00000000 read-only @ 0x40012448 + JDATA 0x0 + +DR 0x00000000 read-only @ 0x4001244C + DATA 0x0 + ADC2DATA 0x0 + +Peripheral :ADC2 +Name Value Access Address +SR 0x00000000 read-write @ 0x40012800 + STRT 0 + JSTRT 0 + JEOC 0 + EOC 0 + AWD 0 + +CR1 0x00000000 read-write @ 0x40012804 + AWDEN 0 + JAWDEN 0 + DISCNUM 0x0 + JDISCEN 0 + DISCEN 0 + JAUTO 0 + AWDSGL 0 + SCAN 0 + JEOCIE 0 + AWDIE 0 + EOCIE 0 + AWDCH 0x0 + +CR2 0x00000000 read-write @ 0x40012808 + TSVREFE 0 + SWSTART 0 + JSWSTART 0 + EXTTRIG 0 + EXTSEL 0x0 + JEXTTRIG 0 + JEXTSEL 0x0 + ALIGN 0 + DMA 0 + RSTCAL 0 + CAL 0 + CONT 0 + ADON 0 + +SMPR1 0x00000000 read-write @ 0x4001280C + SMP10 0x0 + SMP11 0x0 + SMP12 0x0 + SMP13 0x0 + SMP14 0x0 + SMP15 0x0 + SMP16 0x0 + SMP17 0x0 + +SMPR2 0x00000000 read-write @ 0x40012810 + SMP0 0x0 + SMP1 0x0 + SMP2 0x0 + SMP3 0x0 + SMP4 0x0 + SMP5 0x0 + SMP6 0x0 + SMP7 0x0 + SMP8 0x0 + SMP9 0x0 + +JOFR1 0x00000000 read-write @ 0x40012814 + JOFFSET1 0x0 + +JOFR2 0x00000000 read-write @ 0x40012818 + JOFFSET2 0x0 + +JOFR3 0x00000000 read-write @ 0x4001281C + JOFFSET3 0x0 + +JOFR4 0x00000000 read-write @ 0x40012820 + JOFFSET4 0x0 + +HTR 0x00000FFF read-write @ 0x40012824 + HT 0xFFF + +LTR 0x00000000 read-write @ 0x40012828 + LT 0x0 + +SQR1 0x00000000 read-write @ 0x4001282C + L 0x0 + SQ16 0x0 + SQ15 0x0 + SQ14 0x0 + SQ13 0x0 + +SQR2 0x00000000 read-write @ 0x40012830 + SQ12 0x0 + SQ11 0x0 + SQ10 0x0 + SQ9 0x0 + SQ8 0x0 + SQ7 0x0 + +SQR3 0x00000000 read-write @ 0x40012834 + SQ6 0x0 + SQ5 0x0 + SQ4 0x0 + SQ3 0x0 + SQ2 0x0 + SQ1 0x0 + +JSQR 0x00000000 read-write @ 0x40012838 + JL 0x0 + JSQ4 0x0 + JSQ3 0x0 + JSQ2 0x0 + JSQ1 0x0 + +JDR1 0x00000000 read-only @ 0x4001283C + JDATA 0x0 + +JDR2 0x00000000 read-only @ 0x40012840 + JDATA 0x0 + +JDR3 0x00000000 read-only @ 0x40012844 + JDATA 0x0 + +JDR4 0x00000000 read-only @ 0x40012848 + JDATA 0x0 + +DR 0x00000000 read-only @ 0x4001284C + DATA 0x0 + +Peripheral :ADC3 +Name Value Access Address +SR 0x00000000 read-write @ 0x40013C00 + STRT 0 + JSTRT 0 + JEOC 0 + EOC 0 + AWD 0 + +CR1 0x00000000 read-write @ 0x40013C04 + AWDEN 0 + JAWDEN 0 + DISCNUM 0x0 + JDISCEN 0 + DISCEN 0 + JAUTO 0 + AWDSGL 0 + SCAN 0 + JEOCIE 0 + AWDIE 0 + EOCIE 0 + AWDCH 0x0 + +CR2 0x00000000 read-write @ 0x40013C08 + TSVREFE 0 + SWSTART 0 + JSWSTART 0 + EXTTRIG 0 + EXTSEL 0x0 + JEXTTRIG 0 + JEXTSEL 0x0 + ALIGN 0 + DMA 0 + RSTCAL 0 + CAL 0 + CONT 0 + ADON 0 + +SMPR1 0x00000000 read-write @ 0x40013C0C + SMP10 0x0 + SMP11 0x0 + SMP12 0x0 + SMP13 0x0 + SMP14 0x0 + SMP15 0x0 + SMP16 0x0 + SMP17 0x0 + +SMPR2 0x00000000 read-write @ 0x40013C10 + SMP0 0x0 + SMP1 0x0 + SMP2 0x0 + SMP3 0x0 + SMP4 0x0 + SMP5 0x0 + SMP6 0x0 + SMP7 0x0 + SMP8 0x0 + SMP9 0x0 + +JOFR1 0x00000000 read-write @ 0x40013C14 + JOFFSET1 0x0 + +JOFR2 0x00000000 read-write @ 0x40013C18 + JOFFSET2 0x0 + +JOFR3 0x00000000 read-write @ 0x40013C1C + JOFFSET3 0x0 + +JOFR4 0x00000000 read-write @ 0x40013C20 + JOFFSET4 0x0 + +HTR 0x00000FFF read-write @ 0x40013C24 + HT 0xFFF + +LTR 0x00000000 read-write @ 0x40013C28 + LT 0x0 + +SQR1 0x00000000 read-write @ 0x40013C2C + L 0x0 + SQ16 0x0 + SQ15 0x0 + SQ14 0x0 + SQ13 0x0 + +SQR2 0x00000000 read-write @ 0x40013C30 + SQ12 0x0 + SQ11 0x0 + SQ10 0x0 + SQ9 0x0 + SQ8 0x0 + SQ7 0x0 + +SQR3 0x00000000 read-write @ 0x40013C34 + SQ6 0x0 + SQ5 0x0 + SQ4 0x0 + SQ3 0x0 + SQ2 0x0 + SQ1 0x0 + +JSQR 0x00000000 read-write @ 0x40013C38 + JL 0x0 + JSQ4 0x0 + JSQ3 0x0 + JSQ2 0x0 + JSQ1 0x0 + +JDR1 0x00000000 read-only @ 0x40013C3C + JDATA 0x0 + +JDR2 0x00000000 read-only @ 0x40013C40 + JDATA 0x0 + +JDR3 0x00000000 read-only @ 0x40013C44 + JDATA 0x0 + +JDR4 0x00000000 read-only @ 0x40013C48 + JDATA 0x0 + +DR 0x00000000 read-only @ 0x40013C4C + DATA 0x0 + +Peripheral :CAN1 +Name Value Access Address +CAN_MCR 0x00010002 read-write @ 0x40006400 + DBF 1 + RESET 0 + TTCM 0 + ABOM 0 + AWUM 0 + NART 0 + RFLM 0 + TXFP 0 + SLEEP 1 + INRQ 0 + +CAN_MSR 0x00000000 undefined @ 0x40006404 + RX 0 + SAMP 0 + RXM 0 + TXM 0 + SLAKI 0 + WKUI 0 + ERRI 0 + SLAK 0 + INAK 0 + +CAN_TSR 0x00000000 undefined @ 0x40006408 + LOW2 0 + LOW1 0 + LOW0 0 + TME2 0 + TME1 0 + TME0 0 + CODE 0x0 + ABRQ2 0 + TERR2 0 + ALST2 0 + TXOK2 0 + RQCP2 0 + ABRQ1 0 + TERR1 0 + ALST1 0 + TXOK1 0 + RQCP1 0 + ABRQ0 0 + TERR0 0 + ALST0 0 + TXOK0 0 + RQCP0 0 + +CAN_RF0R 0x00000000 undefined @ 0x4000640C + RFOM0 0 + FOVR0 0 + FULL0 0 + FMP0 0x0 + +CAN_RF1R 0x00000000 undefined @ 0x40006410 + RFOM1 0 + FOVR1 0 + FULL1 0 + FMP1 0x0 + +CAN_IER 0x00000000 read-write @ 0x40006414 + SLKIE 0 + WKUIE 0 + ERRIE 0 + LECIE 0 + BOFIE 0 + EPVIE 0 + EWGIE 0 + FOVIE1 0 + FFIE1 0 + FMPIE1 0 + FOVIE0 0 + FFIE0 0 + FMPIE0 0 + TMEIE 0 + +CAN_ESR 0x00000000 undefined @ 0x40006418 + REC 0x0 + TEC 0x0 + LEC 0x0 + BOFF 0 + EPVF 0 + EWGF 0 + +CAN_BTR 0x01230000 read-write @ 0x4000641C + SILM 0 + LBKM 0 + SJW 0x1 + TS2 0x2 + TS1 0x3 + BRP 0x0 + +CAN_TI0R 0xA3FCFBEE read-write @ 0x40006580 + STID 0x51F + EXID 0x39F7D + IDE 1 + RTR 1 + TXRQ 0 + +CAN_TDT0R 0x276774FD read-write @ 0x40006584 + TIME 0x2767 + TGT 0 + DLC 0xD + +CAN_TDL0R 0x655F1B25 read-write @ 0x40006588 + DATA3 0x65 + DATA2 0x5F + DATA1 0x1B + DATA0 0x25 + +CAN_TDH0R 0x3B66AF46 read-write @ 0x4000658C + DATA7 0x3B + DATA6 0x66 + DATA5 0xAF + DATA4 0x46 + +CAN_TI1R 0x7D55C640 read-write @ 0x40006590 + STID 0x3EA + EXID 0x2B8C8 + IDE 0 + RTR 0 + TXRQ 0 + +CAN_TDT1R 0xF1B504A4 read-write @ 0x40006594 + TIME 0xF1B5 + TGT 0 + DLC 0x4 + +CAN_TDL1R 0x5816BF8A read-write @ 0x40006598 + DATA3 0x58 + DATA2 0x16 + DATA1 0xBF + DATA0 0x8A + +CAN_TDH1R 0x7213171D read-write @ 0x4000659C + DATA7 0x72 + DATA6 0x13 + DATA5 0x17 + DATA4 0x1D + +CAN_TI2R 0x9AE2F5AA read-write @ 0x400065A0 + STID 0x4D7 + EXID 0x5EB5 + IDE 0 + RTR 1 + TXRQ 0 + +CAN_TDT2R 0x3E7F63F5 read-write @ 0x400065A4 + TIME 0x3E7F + TGT 1 + DLC 0x5 + +CAN_TDL2R 0x70255D53 read-write @ 0x400065A8 + DATA3 0x70 + DATA2 0x25 + DATA1 0x5D + DATA0 0x53 + +CAN_TDH2R 0x7A3C22C0 read-write @ 0x400065AC + DATA7 0x7A + DATA6 0x3C + DATA5 0x22 + DATA4 0xC0 + +CAN_RI0R 0x18D5B5D2 read-only @ 0x400065B0 + STID 0xC6 + EXID 0x2B6BA + IDE 0 + RTR 1 + +CAN_RDT0R 0x1CFB8063 read-only @ 0x400065B4 + TIME 0x1CFB + FMI 0x80 + DLC 0x3 + +CAN_RDL0R 0x8D527038 read-only @ 0x400065B8 + DATA3 0x8D + DATA2 0x52 + DATA1 0x70 + DATA0 0x38 + +CAN_RDH0R 0x34701170 read-only @ 0x400065BC + DATA7 0x34 + DATA6 0x70 + DATA5 0x11 + DATA4 0x70 + +CAN_RI1R 0x61540DCC read-only @ 0x400065C0 + STID 0x30A + EXID 0x281B9 + IDE 1 + RTR 0 + +CAN_RDT1R 0x8AF970FE read-only @ 0x400065C4 + TIME 0x8AF9 + FMI 0x70 + DLC 0xE + +CAN_RDL1R 0xB0BD2AC9 read-only @ 0x400065C8 + DATA3 0xB0 + DATA2 0xBD + DATA1 0x2A + DATA0 0xC9 + +CAN_RDH1R 0x9EF57E5D read-only @ 0x400065CC + DATA7 0x9E + DATA6 0xF5 + DATA5 0x7E + DATA4 0x5D + +CAN_FMR 0x2A1C0E01 read-write @ 0x40006600 + FINIT 1 + +CAN_FM1R 0x00000000 read-write @ 0x40006604 + FBM0 0 + FBM1 0 + FBM2 0 + FBM3 0 + FBM4 0 + FBM5 0 + FBM6 0 + FBM7 0 + FBM8 0 + FBM9 0 + FBM10 0 + FBM11 0 + FBM12 0 + FBM13 0 + +CAN_FS1R 0x00000000 read-write @ 0x4000660C + FSC0 0 + FSC1 0 + FSC2 0 + FSC3 0 + FSC4 0 + FSC5 0 + FSC6 0 + FSC7 0 + FSC8 0 + FSC9 0 + FSC10 0 + FSC11 0 + FSC12 0 + FSC13 0 + +CAN_FFA1R 0x00000000 read-write @ 0x40006614 + FFA0 0 + FFA1 0 + FFA2 0 + FFA3 0 + FFA4 0 + FFA5 0 + FFA6 0 + FFA7 0 + FFA8 0 + FFA9 0 + FFA10 0 + FFA11 0 + FFA12 0 + FFA13 0 + +CAN_FA1R 0x00000000 read-write @ 0x4000661C + FACT0 0 + FACT1 0 + FACT2 0 + FACT3 0 + FACT4 0 + FACT5 0 + FACT6 0 + FACT7 0 + FACT8 0 + FACT9 0 + FACT10 0 + FACT11 0 + FACT12 0 + FACT13 0 + +F0R1 0xAAFEF6B3 read-write @ 0x40006640 + FB0 1 + FB1 1 + FB2 0 + FB3 0 + FB4 1 + FB5 1 + FB6 0 + FB7 1 + FB8 0 + FB9 1 + FB10 1 + FB11 0 + FB12 1 + FB13 1 + FB14 1 + FB15 1 + FB16 0 + FB17 1 + FB18 1 + FB19 1 + FB20 1 + FB21 1 + FB22 1 + FB23 1 + FB24 0 + FB25 1 + FB26 0 + FB27 1 + FB28 0 + FB29 1 + FB30 0 + FB31 1 + +F0R2 0x685E5771 read-write @ 0x40006644 + FB0 1 + FB1 0 + FB2 0 + FB3 0 + FB4 1 + FB5 1 + FB6 1 + FB7 0 + FB8 1 + FB9 1 + FB10 1 + FB11 0 + FB12 1 + FB13 0 + FB14 1 + FB15 0 + FB16 0 + FB17 1 + FB18 1 + FB19 1 + FB20 1 + FB21 0 + FB22 1 + FB23 0 + FB24 0 + FB25 0 + FB26 0 + FB27 1 + FB28 0 + FB29 1 + FB30 1 + FB31 0 + +F1R1 0x5D479700 read-write @ 0x40006648 + FB0 0 + FB1 0 + FB2 0 + FB3 0 + FB4 0 + FB5 0 + FB6 0 + FB7 0 + FB8 1 + FB9 1 + FB10 1 + FB11 0 + FB12 1 + FB13 0 + FB14 0 + FB15 1 + FB16 1 + FB17 1 + FB18 1 + FB19 0 + FB20 0 + FB21 0 + FB22 1 + FB23 0 + FB24 1 + FB25 0 + FB26 1 + FB27 1 + FB28 1 + FB29 0 + FB30 1 + FB31 0 + +F1R2 0x3B9CDED3 read-write @ 0x4000664C + FB0 1 + FB1 1 + FB2 0 + FB3 0 + FB4 1 + FB5 0 + FB6 1 + FB7 1 + FB8 0 + FB9 1 + FB10 1 + FB11 1 + FB12 1 + FB13 0 + FB14 1 + FB15 1 + FB16 0 + FB17 0 + FB18 1 + FB19 1 + FB20 1 + FB21 0 + FB22 0 + FB23 1 + FB24 1 + FB25 1 + FB26 0 + FB27 1 + FB28 1 + FB29 1 + FB30 0 + FB31 0 + +F2R1 0x6D946647 read-write @ 0x40006650 + FB0 1 + FB1 1 + FB2 1 + FB3 0 + FB4 0 + FB5 0 + FB6 1 + FB7 0 + FB8 0 + FB9 1 + FB10 1 + FB11 0 + FB12 0 + FB13 1 + FB14 1 + FB15 0 + FB16 0 + FB17 0 + FB18 1 + FB19 0 + FB20 1 + FB21 0 + FB22 0 + FB23 1 + FB24 1 + FB25 0 + FB26 1 + FB27 1 + FB28 0 + FB29 1 + FB30 1 + FB31 0 + +F2R2 0xAADDFEB7 read-write @ 0x40006654 + FB0 1 + FB1 1 + FB2 1 + FB3 0 + FB4 1 + FB5 1 + FB6 0 + FB7 1 + FB8 0 + FB9 1 + FB10 1 + FB11 1 + FB12 1 + FB13 1 + FB14 1 + FB15 1 + FB16 1 + FB17 0 + FB18 1 + FB19 1 + FB20 1 + FB21 0 + FB22 1 + FB23 1 + FB24 0 + FB25 1 + FB26 0 + FB27 1 + FB28 0 + FB29 1 + FB30 0 + FB31 1 + +F3R1 0xA75AD983 read-write @ 0x40006658 + FB0 1 + FB1 1 + FB2 0 + FB3 0 + FB4 0 + FB5 0 + FB6 0 + FB7 1 + FB8 1 + FB9 0 + FB10 0 + FB11 1 + FB12 1 + FB13 0 + FB14 1 + FB15 1 + FB16 0 + FB17 1 + FB18 0 + FB19 1 + FB20 1 + FB21 0 + FB22 1 + FB23 0 + FB24 1 + FB25 1 + FB26 1 + FB27 0 + FB28 0 + FB29 1 + FB30 0 + FB31 1 + +F3R2 0x3345F2B7 read-write @ 0x4000665C + FB0 1 + FB1 1 + FB2 1 + FB3 0 + FB4 1 + FB5 1 + FB6 0 + FB7 1 + FB8 0 + FB9 1 + FB10 0 + FB11 0 + FB12 1 + FB13 1 + FB14 1 + FB15 1 + FB16 1 + FB17 0 + FB18 1 + FB19 0 + FB20 0 + FB21 0 + FB22 1 + FB23 0 + FB24 1 + FB25 1 + FB26 0 + FB27 0 + FB28 1 + FB29 1 + FB30 0 + FB31 0 + +F4R1 0xEA28B3CE read-write @ 0x40006660 + FB0 0 + FB1 1 + FB2 1 + FB3 1 + FB4 0 + FB5 0 + FB6 1 + FB7 1 + FB8 1 + FB9 1 + FB10 0 + FB11 0 + FB12 1 + FB13 1 + FB14 0 + FB15 1 + FB16 0 + FB17 0 + FB18 0 + FB19 1 + FB20 0 + FB21 1 + FB22 0 + FB23 0 + FB24 0 + FB25 1 + FB26 0 + FB27 1 + FB28 0 + FB29 1 + FB30 1 + FB31 1 + +F4R2 0x7B5D70D4 read-write @ 0x40006664 + FB0 0 + FB1 0 + FB2 1 + FB3 0 + FB4 1 + FB5 0 + FB6 1 + FB7 1 + FB8 0 + FB9 0 + FB10 0 + FB11 0 + FB12 1 + FB13 1 + FB14 1 + FB15 0 + FB16 1 + FB17 0 + FB18 1 + FB19 1 + FB20 1 + FB21 0 + FB22 1 + FB23 0 + FB24 1 + FB25 1 + FB26 0 + FB27 1 + FB28 1 + FB29 1 + FB30 1 + FB31 0 + +F5R1 0x6F5D51C1 read-write @ 0x40006668 + FB0 1 + FB1 0 + FB2 0 + FB3 0 + FB4 0 + FB5 0 + FB6 1 + FB7 1 + FB8 1 + FB9 0 + FB10 0 + FB11 0 + FB12 1 + FB13 0 + FB14 1 + FB15 0 + FB16 1 + FB17 0 + FB18 1 + FB19 1 + FB20 1 + FB21 0 + FB22 1 + FB23 0 + FB24 1 + FB25 1 + FB26 1 + FB27 1 + FB28 0 + FB29 1 + FB30 1 + FB31 0 + +F5R2 0x6B8FBACC read-write @ 0x4000666C + FB0 0 + FB1 0 + FB2 1 + FB3 1 + FB4 0 + FB5 0 + FB6 1 + FB7 1 + FB8 0 + FB9 1 + FB10 0 + FB11 1 + FB12 1 + FB13 1 + FB14 0 + FB15 1 + FB16 1 + FB17 1 + FB18 1 + FB19 1 + FB20 0 + FB21 0 + FB22 0 + FB23 1 + FB24 1 + FB25 1 + FB26 0 + FB27 1 + FB28 0 + FB29 1 + FB30 1 + FB31 0 + +F6R1 0xD115C550 read-write @ 0x40006670 + FB0 0 + FB1 0 + FB2 0 + FB3 0 + FB4 1 + FB5 0 + FB6 1 + FB7 0 + FB8 1 + FB9 0 + FB10 1 + FB11 0 + FB12 0 + FB13 0 + FB14 1 + FB15 1 + FB16 1 + FB17 0 + FB18 1 + FB19 0 + FB20 1 + FB21 0 + FB22 0 + FB23 0 + FB24 1 + FB25 0 + FB26 0 + FB27 0 + FB28 1 + FB29 0 + FB30 1 + FB31 1 + +F6R2 0xD229AFE3 read-write @ 0x40006674 + FB0 1 + FB1 1 + FB2 0 + FB3 0 + FB4 0 + FB5 1 + FB6 1 + FB7 1 + FB8 1 + FB9 1 + FB10 1 + FB11 1 + FB12 0 + FB13 1 + FB14 0 + FB15 1 + FB16 1 + FB17 0 + FB18 0 + FB19 1 + FB20 0 + FB21 1 + FB22 0 + FB23 0 + FB24 0 + FB25 1 + FB26 0 + FB27 0 + FB28 1 + FB29 0 + FB30 1 + FB31 1 + +F7R1 0x4989C6CB read-write @ 0x40006678 + FB0 1 + FB1 1 + FB2 0 + FB3 1 + FB4 0 + FB5 0 + FB6 1 + FB7 1 + FB8 0 + FB9 1 + FB10 1 + FB11 0 + FB12 0 + FB13 0 + FB14 1 + FB15 1 + FB16 1 + FB17 0 + FB18 0 + FB19 1 + FB20 0 + FB21 0 + FB22 0 + FB23 1 + FB24 1 + FB25 0 + FB26 0 + FB27 1 + FB28 0 + FB29 0 + FB30 1 + FB31 0 + +F7R2 0x58B95BC1 read-write @ 0x4000667C + FB0 1 + FB1 0 + FB2 0 + FB3 0 + FB4 0 + FB5 0 + FB6 1 + FB7 1 + FB8 1 + FB9 1 + FB10 0 + FB11 1 + FB12 1 + FB13 0 + FB14 1 + FB15 0 + FB16 1 + FB17 0 + FB18 0 + FB19 1 + FB20 1 + FB21 1 + FB22 0 + FB23 1 + FB24 0 + FB25 0 + FB26 0 + FB27 1 + FB28 1 + FB29 0 + FB30 1 + FB31 0 + +F8R1 0x8ABC12BA read-write @ 0x40006680 + FB0 0 + FB1 1 + FB2 0 + FB3 1 + FB4 1 + FB5 1 + FB6 0 + FB7 1 + FB8 0 + FB9 1 + FB10 0 + FB11 0 + FB12 1 + FB13 0 + FB14 0 + FB15 0 + FB16 0 + FB17 0 + FB18 1 + FB19 1 + FB20 1 + FB21 1 + FB22 0 + FB23 1 + FB24 0 + FB25 1 + FB26 0 + FB27 1 + FB28 0 + FB29 0 + FB30 0 + FB31 1 + +F8R2 0x67D1C6DF read-write @ 0x40006684 + FB0 1 + FB1 1 + FB2 1 + FB3 1 + FB4 1 + FB5 0 + FB6 1 + FB7 1 + FB8 0 + FB9 1 + FB10 1 + FB11 0 + FB12 0 + FB13 0 + FB14 1 + FB15 1 + FB16 1 + FB17 0 + FB18 0 + FB19 0 + FB20 1 + FB21 0 + FB22 1 + FB23 1 + FB24 1 + FB25 1 + FB26 1 + FB27 0 + FB28 0 + FB29 1 + FB30 1 + FB31 0 + +F9R1 0x776911D4 read-write @ 0x40006688 + FB0 0 + FB1 0 + FB2 1 + FB3 0 + FB4 1 + FB5 0 + FB6 1 + FB7 1 + FB8 1 + FB9 0 + FB10 0 + FB11 0 + FB12 1 + FB13 0 + FB14 0 + FB15 0 + FB16 1 + FB17 0 + FB18 0 + FB19 1 + FB20 0 + FB21 1 + FB22 1 + FB23 0 + FB24 1 + FB25 1 + FB26 1 + FB27 0 + FB28 1 + FB29 1 + FB30 1 + FB31 0 + +F9R2 0x2CB99ACE read-write @ 0x4000668C + FB0 0 + FB1 1 + FB2 1 + FB3 1 + FB4 0 + FB5 0 + FB6 1 + FB7 1 + FB8 0 + FB9 1 + FB10 0 + FB11 1 + FB12 1 + FB13 0 + FB14 0 + FB15 1 + FB16 1 + FB17 0 + FB18 0 + FB19 1 + FB20 1 + FB21 1 + FB22 0 + FB23 1 + FB24 0 + FB25 0 + FB26 1 + FB27 1 + FB28 0 + FB29 1 + FB30 0 + FB31 0 + +F10R1 0x714D5D43 read-write @ 0x40006690 + FB0 1 + FB1 1 + FB2 0 + FB3 0 + FB4 0 + FB5 0 + FB6 1 + FB7 0 + FB8 1 + FB9 0 + FB10 1 + FB11 1 + FB12 1 + FB13 0 + FB14 1 + FB15 0 + FB16 1 + FB17 0 + FB18 1 + FB19 1 + FB20 0 + FB21 0 + FB22 1 + FB23 0 + FB24 1 + FB25 0 + FB26 0 + FB27 0 + FB28 1 + FB29 1 + FB30 1 + FB31 0 + +F10R2 0x03C8A083 read-write @ 0x40006694 + FB0 1 + FB1 1 + FB2 0 + FB3 0 + FB4 0 + FB5 0 + FB6 0 + FB7 1 + FB8 0 + FB9 0 + FB10 0 + FB11 0 + FB12 0 + FB13 1 + FB14 0 + FB15 1 + FB16 0 + FB17 0 + FB18 0 + FB19 1 + FB20 0 + FB21 0 + FB22 1 + FB23 1 + FB24 1 + FB25 1 + FB26 0 + FB27 0 + FB28 0 + FB29 0 + FB30 0 + FB31 0 + +F11R1 0xB880B067 read-write @ 0x40006698 + FB0 1 + FB1 1 + FB2 1 + FB3 0 + FB4 0 + FB5 1 + FB6 1 + FB7 0 + FB8 0 + FB9 0 + FB10 0 + FB11 0 + FB12 1 + FB13 1 + FB14 0 + FB15 1 + FB16 0 + FB17 0 + FB18 0 + FB19 0 + FB20 0 + FB21 0 + FB22 0 + FB23 1 + FB24 0 + FB25 0 + FB26 0 + FB27 1 + FB28 1 + FB29 1 + FB30 0 + FB31 1 + +F11R2 0x19BDA145 read-write @ 0x4000669C + FB0 1 + FB1 0 + FB2 1 + FB3 0 + FB4 0 + FB5 0 + FB6 1 + FB7 0 + FB8 1 + FB9 0 + FB10 0 + FB11 0 + FB12 0 + FB13 1 + FB14 0 + FB15 1 + FB16 1 + FB17 0 + FB18 1 + FB19 1 + FB20 1 + FB21 1 + FB22 0 + FB23 1 + FB24 1 + FB25 0 + FB26 0 + FB27 1 + FB28 1 + FB29 0 + FB30 0 + FB31 0 + +F12R1 0x3A78CABE read-write @ 0x400066A0 + FB0 0 + FB1 1 + FB2 1 + FB3 1 + FB4 1 + FB5 1 + FB6 0 + FB7 1 + FB8 0 + FB9 1 + FB10 0 + FB11 1 + FB12 0 + FB13 0 + FB14 1 + FB15 1 + FB16 0 + FB17 0 + FB18 0 + FB19 1 + FB20 1 + FB21 1 + FB22 1 + FB23 0 + FB24 0 + FB25 1 + FB26 0 + FB27 1 + FB28 1 + FB29 1 + FB30 0 + FB31 0 + +F12R2 0x825D54E0 read-write @ 0x400066A4 + FB0 0 + FB1 0 + FB2 0 + FB3 0 + FB4 0 + FB5 1 + FB6 1 + FB7 1 + FB8 0 + FB9 0 + FB10 1 + FB11 0 + FB12 1 + FB13 0 + FB14 1 + FB15 0 + FB16 1 + FB17 0 + FB18 1 + FB19 1 + FB20 1 + FB21 0 + FB22 1 + FB23 0 + FB24 0 + FB25 1 + FB26 0 + FB27 0 + FB28 0 + FB29 0 + FB30 0 + FB31 1 + +F13R1 0x176C8145 read-write @ 0x400066A8 + FB0 1 + FB1 0 + FB2 1 + FB3 0 + FB4 0 + FB5 0 + FB6 1 + FB7 0 + FB8 1 + FB9 0 + FB10 0 + FB11 0 + FB12 0 + FB13 0 + FB14 0 + FB15 1 + FB16 0 + FB17 0 + FB18 1 + FB19 1 + FB20 0 + FB21 1 + FB22 1 + FB23 0 + FB24 1 + FB25 1 + FB26 1 + FB27 0 + FB28 1 + FB29 0 + FB30 0 + FB31 0 + +F13R2 0x842C6362 read-write @ 0x400066AC + FB0 0 + FB1 1 + FB2 0 + FB3 0 + FB4 0 + FB5 1 + FB6 1 + FB7 0 + FB8 1 + FB9 1 + FB10 0 + FB11 0 + FB12 0 + FB13 1 + FB14 1 + FB15 0 + FB16 0 + FB17 0 + FB18 1 + FB19 1 + FB20 0 + FB21 1 + FB22 0 + FB23 0 + FB24 0 + FB25 0 + FB26 1 + FB27 0 + FB28 0 + FB29 0 + FB30 0 + FB31 1 + +Peripheral :CAN2 +Name Value Access Address +CAN_MCR 0x00000000 read-write @ 0x40006800 + DBF 0 + RESET 0 + TTCM 0 + ABOM 0 + AWUM 0 + NART 0 + RFLM 0 + TXFP 0 + SLEEP 0 + INRQ 0 + +CAN_MSR 0x00000000 undefined @ 0x40006804 + RX 0 + SAMP 0 + RXM 0 + TXM 0 + SLAKI 0 + WKUI 0 + ERRI 0 + SLAK 0 + INAK 0 + +CAN_TSR 0x00000000 undefined @ 0x40006808 + LOW2 0 + LOW1 0 + LOW0 0 + TME2 0 + TME1 0 + TME0 0 + CODE 0x0 + ABRQ2 0 + TERR2 0 + ALST2 0 + TXOK2 0 + RQCP2 0 + ABRQ1 0 + TERR1 0 + ALST1 0 + TXOK1 0 + RQCP1 0 + ABRQ0 0 + TERR0 0 + ALST0 0 + TXOK0 0 + RQCP0 0 + +CAN_RF0R 0x00000000 undefined @ 0x4000680C + RFOM0 0 + FOVR0 0 + FULL0 0 + FMP0 0x0 + +CAN_RF1R 0x00000000 undefined @ 0x40006810 + RFOM1 0 + FOVR1 0 + FULL1 0 + FMP1 0x0 + +CAN_IER 0x00000000 read-write @ 0x40006814 + SLKIE 0 + WKUIE 0 + ERRIE 0 + LECIE 0 + BOFIE 0 + EPVIE 0 + EWGIE 0 + FOVIE1 0 + FFIE1 0 + FMPIE1 0 + FOVIE0 0 + FFIE0 0 + FMPIE0 0 + TMEIE 0 + +CAN_ESR 0x00000000 undefined @ 0x40006818 + REC 0x0 + TEC 0x0 + LEC 0x0 + BOFF 0 + EPVF 0 + EWGF 0 + +CAN_BTR 0x00000000 read-write @ 0x4000681C + SILM 0 + LBKM 0 + SJW 0x0 + TS2 0x0 + TS1 0x0 + BRP 0x0 + +CAN_TI0R 0x00000000 read-write @ 0x40006980 + STID 0x0 + EXID 0x0 + IDE 0 + RTR 0 + TXRQ 0 + +CAN_TDT0R 0x00000000 read-write @ 0x40006984 + TIME 0x0 + TGT 0 + DLC 0x0 + +CAN_TDL0R 0x00000000 read-write @ 0x40006988 + DATA3 0x0 + DATA2 0x0 + DATA1 0x0 + DATA0 0x0 + +CAN_TDH0R 0x00000000 read-write @ 0x4000698C + DATA7 0x0 + DATA6 0x0 + DATA5 0x0 + DATA4 0x0 + +CAN_TI1R 0x00000000 read-write @ 0x40006990 + STID 0x0 + EXID 0x0 + IDE 0 + RTR 0 + TXRQ 0 + +CAN_TDT1R 0x00000000 read-write @ 0x40006994 + TIME 0x0 + TGT 0 + DLC 0x0 + +CAN_TDL1R 0x00000000 read-write @ 0x40006998 + DATA3 0x0 + DATA2 0x0 + DATA1 0x0 + DATA0 0x0 + +CAN_TDH1R 0x00000000 read-write @ 0x4000699C + DATA7 0x0 + DATA6 0x0 + DATA5 0x0 + DATA4 0x0 + +CAN_TI2R 0x00000000 read-write @ 0x400069A0 + STID 0x0 + EXID 0x0 + IDE 0 + RTR 0 + TXRQ 0 + +CAN_TDT2R 0x00000000 read-write @ 0x400069A4 + TIME 0x0 + TGT 0 + DLC 0x0 + +CAN_TDL2R 0x00000000 read-write @ 0x400069A8 + DATA3 0x0 + DATA2 0x0 + DATA1 0x0 + DATA0 0x0 + +CAN_TDH2R 0x00000000 read-write @ 0x400069AC + DATA7 0x0 + DATA6 0x0 + DATA5 0x0 + DATA4 0x0 + +CAN_RI0R 0x00000000 read-only @ 0x400069B0 + STID 0x0 + EXID 0x0 + IDE 0 + RTR 0 + +CAN_RDT0R 0x00000000 read-only @ 0x400069B4 + TIME 0x0 + FMI 0x0 + DLC 0x0 + +CAN_RDL0R 0x00000000 read-only @ 0x400069B8 + DATA3 0x0 + DATA2 0x0 + DATA1 0x0 + DATA0 0x0 + +CAN_RDH0R 0x00000000 read-only @ 0x400069BC + DATA7 0x0 + DATA6 0x0 + DATA5 0x0 + DATA4 0x0 + +CAN_RI1R 0x00000000 read-only @ 0x400069C0 + STID 0x0 + EXID 0x0 + IDE 0 + RTR 0 + +CAN_RDT1R 0x00000000 read-only @ 0x400069C4 + TIME 0x0 + FMI 0x0 + DLC 0x0 + +CAN_RDL1R 0x00000000 read-only @ 0x400069C8 + DATA3 0x0 + DATA2 0x0 + DATA1 0x0 + DATA0 0x0 + +CAN_RDH1R 0x00000000 read-only @ 0x400069CC + DATA7 0x0 + DATA6 0x0 + DATA5 0x0 + DATA4 0x0 + +CAN_FMR 0x00000000 read-write @ 0x40006A00 + FINIT 0 + +CAN_FM1R 0x00000000 read-write @ 0x40006A04 + FBM0 0 + FBM1 0 + FBM2 0 + FBM3 0 + FBM4 0 + FBM5 0 + FBM6 0 + FBM7 0 + FBM8 0 + FBM9 0 + FBM10 0 + FBM11 0 + FBM12 0 + FBM13 0 + +CAN_FS1R 0x00000000 read-write @ 0x40006A0C + FSC0 0 + FSC1 0 + FSC2 0 + FSC3 0 + FSC4 0 + FSC5 0 + FSC6 0 + FSC7 0 + FSC8 0 + FSC9 0 + FSC10 0 + FSC11 0 + FSC12 0 + FSC13 0 + +CAN_FFA1R 0x00000000 read-write @ 0x40006A14 + FFA0 0 + FFA1 0 + FFA2 0 + FFA3 0 + FFA4 0 + FFA5 0 + FFA6 0 + FFA7 0 + FFA8 0 + FFA9 0 + FFA10 0 + FFA11 0 + FFA12 0 + FFA13 0 + +CAN_FA1R 0x00000000 read-write @ 0x40006A1C + FACT0 0 + FACT1 0 + FACT2 0 + FACT3 0 + FACT4 0 + FACT5 0 + FACT6 0 + FACT7 0 + FACT8 0 + FACT9 0 + FACT10 0 + FACT11 0 + FACT12 0 + FACT13 0 + +F0R1 0x00000000 read-write @ 0x40006A40 + FB0 0 + FB1 0 + FB2 0 + FB3 0 + FB4 0 + FB5 0 + FB6 0 + FB7 0 + FB8 0 + FB9 0 + FB10 0 + FB11 0 + FB12 0 + FB13 0 + FB14 0 + FB15 0 + FB16 0 + FB17 0 + FB18 0 + FB19 0 + FB20 0 + FB21 0 + FB22 0 + FB23 0 + FB24 0 + FB25 0 + FB26 0 + FB27 0 + FB28 0 + FB29 0 + FB30 0 + FB31 0 + +F0R2 0x00000000 read-write @ 0x40006A44 + FB0 0 + FB1 0 + FB2 0 + FB3 0 + FB4 0 + FB5 0 + FB6 0 + FB7 0 + FB8 0 + FB9 0 + FB10 0 + FB11 0 + FB12 0 + FB13 0 + FB14 0 + FB15 0 + FB16 0 + FB17 0 + FB18 0 + FB19 0 + FB20 0 + FB21 0 + FB22 0 + FB23 0 + FB24 0 + FB25 0 + FB26 0 + FB27 0 + FB28 0 + FB29 0 + FB30 0 + FB31 0 + +F1R1 0x00000000 read-write @ 0x40006A48 + FB0 0 + FB1 0 + FB2 0 + FB3 0 + FB4 0 + FB5 0 + FB6 0 + FB7 0 + FB8 0 + FB9 0 + FB10 0 + FB11 0 + FB12 0 + FB13 0 + FB14 0 + FB15 0 + FB16 0 + FB17 0 + FB18 0 + FB19 0 + FB20 0 + FB21 0 + FB22 0 + FB23 0 + FB24 0 + FB25 0 + FB26 0 + FB27 0 + FB28 0 + FB29 0 + FB30 0 + FB31 0 + +F1R2 0x00000000 read-write @ 0x40006A4C + FB0 0 + FB1 0 + FB2 0 + FB3 0 + FB4 0 + FB5 0 + FB6 0 + FB7 0 + FB8 0 + FB9 0 + FB10 0 + FB11 0 + FB12 0 + FB13 0 + FB14 0 + FB15 0 + FB16 0 + FB17 0 + FB18 0 + FB19 0 + FB20 0 + FB21 0 + FB22 0 + FB23 0 + FB24 0 + FB25 0 + FB26 0 + FB27 0 + FB28 0 + FB29 0 + FB30 0 + FB31 0 + +F2R1 0x00000000 read-write @ 0x40006A50 + FB0 0 + FB1 0 + FB2 0 + FB3 0 + FB4 0 + FB5 0 + FB6 0 + FB7 0 + FB8 0 + FB9 0 + FB10 0 + FB11 0 + FB12 0 + FB13 0 + FB14 0 + FB15 0 + FB16 0 + FB17 0 + FB18 0 + FB19 0 + FB20 0 + FB21 0 + FB22 0 + FB23 0 + FB24 0 + FB25 0 + FB26 0 + FB27 0 + FB28 0 + FB29 0 + FB30 0 + FB31 0 + +F2R2 0x00000000 read-write @ 0x40006A54 + FB0 0 + FB1 0 + FB2 0 + FB3 0 + FB4 0 + FB5 0 + FB6 0 + FB7 0 + FB8 0 + FB9 0 + FB10 0 + FB11 0 + FB12 0 + FB13 0 + FB14 0 + FB15 0 + FB16 0 + FB17 0 + FB18 0 + FB19 0 + FB20 0 + FB21 0 + FB22 0 + FB23 0 + FB24 0 + FB25 0 + FB26 0 + FB27 0 + FB28 0 + FB29 0 + FB30 0 + FB31 0 + +F3R1 0x00000000 read-write @ 0x40006A58 + FB0 0 + FB1 0 + FB2 0 + FB3 0 + FB4 0 + FB5 0 + FB6 0 + FB7 0 + FB8 0 + FB9 0 + FB10 0 + FB11 0 + FB12 0 + FB13 0 + FB14 0 + FB15 0 + FB16 0 + FB17 0 + FB18 0 + FB19 0 + FB20 0 + FB21 0 + FB22 0 + FB23 0 + FB24 0 + FB25 0 + FB26 0 + FB27 0 + FB28 0 + FB29 0 + FB30 0 + FB31 0 + +F3R2 0x00000000 read-write @ 0x40006A5C + FB0 0 + FB1 0 + FB2 0 + FB3 0 + FB4 0 + FB5 0 + FB6 0 + FB7 0 + FB8 0 + FB9 0 + FB10 0 + FB11 0 + FB12 0 + FB13 0 + FB14 0 + FB15 0 + FB16 0 + FB17 0 + FB18 0 + FB19 0 + FB20 0 + FB21 0 + FB22 0 + FB23 0 + FB24 0 + FB25 0 + FB26 0 + FB27 0 + FB28 0 + FB29 0 + FB30 0 + FB31 0 + +F4R1 0x00000000 read-write @ 0x40006A60 + FB0 0 + FB1 0 + FB2 0 + FB3 0 + FB4 0 + FB5 0 + FB6 0 + FB7 0 + FB8 0 + FB9 0 + FB10 0 + FB11 0 + FB12 0 + FB13 0 + FB14 0 + FB15 0 + FB16 0 + FB17 0 + FB18 0 + FB19 0 + FB20 0 + FB21 0 + FB22 0 + FB23 0 + FB24 0 + FB25 0 + FB26 0 + FB27 0 + FB28 0 + FB29 0 + FB30 0 + FB31 0 + +F4R2 0x00000000 read-write @ 0x40006A64 + FB0 0 + FB1 0 + FB2 0 + FB3 0 + FB4 0 + FB5 0 + FB6 0 + FB7 0 + FB8 0 + FB9 0 + FB10 0 + FB11 0 + FB12 0 + FB13 0 + FB14 0 + FB15 0 + FB16 0 + FB17 0 + FB18 0 + FB19 0 + FB20 0 + FB21 0 + FB22 0 + FB23 0 + FB24 0 + FB25 0 + FB26 0 + FB27 0 + FB28 0 + FB29 0 + FB30 0 + FB31 0 + +F5R1 0x00000000 read-write @ 0x40006A68 + FB0 0 + FB1 0 + FB2 0 + FB3 0 + FB4 0 + FB5 0 + FB6 0 + FB7 0 + FB8 0 + FB9 0 + FB10 0 + FB11 0 + FB12 0 + FB13 0 + FB14 0 + FB15 0 + FB16 0 + FB17 0 + FB18 0 + FB19 0 + FB20 0 + FB21 0 + FB22 0 + FB23 0 + FB24 0 + FB25 0 + FB26 0 + FB27 0 + FB28 0 + FB29 0 + FB30 0 + FB31 0 + +F5R2 0x00000000 read-write @ 0x40006A6C + FB0 0 + FB1 0 + FB2 0 + FB3 0 + FB4 0 + FB5 0 + FB6 0 + FB7 0 + FB8 0 + FB9 0 + FB10 0 + FB11 0 + FB12 0 + FB13 0 + FB14 0 + FB15 0 + FB16 0 + FB17 0 + FB18 0 + FB19 0 + FB20 0 + FB21 0 + FB22 0 + FB23 0 + FB24 0 + FB25 0 + FB26 0 + FB27 0 + FB28 0 + FB29 0 + FB30 0 + FB31 0 + +F6R1 0x00000000 read-write @ 0x40006A70 + FB0 0 + FB1 0 + FB2 0 + FB3 0 + FB4 0 + FB5 0 + FB6 0 + FB7 0 + FB8 0 + FB9 0 + FB10 0 + FB11 0 + FB12 0 + FB13 0 + FB14 0 + FB15 0 + FB16 0 + FB17 0 + FB18 0 + FB19 0 + FB20 0 + FB21 0 + FB22 0 + FB23 0 + FB24 0 + FB25 0 + FB26 0 + FB27 0 + FB28 0 + FB29 0 + FB30 0 + FB31 0 + +F6R2 0x00000000 read-write @ 0x40006A74 + FB0 0 + FB1 0 + FB2 0 + FB3 0 + FB4 0 + FB5 0 + FB6 0 + FB7 0 + FB8 0 + FB9 0 + FB10 0 + FB11 0 + FB12 0 + FB13 0 + FB14 0 + FB15 0 + FB16 0 + FB17 0 + FB18 0 + FB19 0 + FB20 0 + FB21 0 + FB22 0 + FB23 0 + FB24 0 + FB25 0 + FB26 0 + FB27 0 + FB28 0 + FB29 0 + FB30 0 + FB31 0 + +F7R1 0x00000000 read-write @ 0x40006A78 + FB0 0 + FB1 0 + FB2 0 + FB3 0 + FB4 0 + FB5 0 + FB6 0 + FB7 0 + FB8 0 + FB9 0 + FB10 0 + FB11 0 + FB12 0 + FB13 0 + FB14 0 + FB15 0 + FB16 0 + FB17 0 + FB18 0 + FB19 0 + FB20 0 + FB21 0 + FB22 0 + FB23 0 + FB24 0 + FB25 0 + FB26 0 + FB27 0 + FB28 0 + FB29 0 + FB30 0 + FB31 0 + +F7R2 0x00000000 read-write @ 0x40006A7C + FB0 0 + FB1 0 + FB2 0 + FB3 0 + FB4 0 + FB5 0 + FB6 0 + FB7 0 + FB8 0 + FB9 0 + FB10 0 + FB11 0 + FB12 0 + FB13 0 + FB14 0 + FB15 0 + FB16 0 + FB17 0 + FB18 0 + FB19 0 + FB20 0 + FB21 0 + FB22 0 + FB23 0 + FB24 0 + FB25 0 + FB26 0 + FB27 0 + FB28 0 + FB29 0 + FB30 0 + FB31 0 + +F8R1 0x00000000 read-write @ 0x40006A80 + FB0 0 + FB1 0 + FB2 0 + FB3 0 + FB4 0 + FB5 0 + FB6 0 + FB7 0 + FB8 0 + FB9 0 + FB10 0 + FB11 0 + FB12 0 + FB13 0 + FB14 0 + FB15 0 + FB16 0 + FB17 0 + FB18 0 + FB19 0 + FB20 0 + FB21 0 + FB22 0 + FB23 0 + FB24 0 + FB25 0 + FB26 0 + FB27 0 + FB28 0 + FB29 0 + FB30 0 + FB31 0 + +F8R2 0x00000000 read-write @ 0x40006A84 + FB0 0 + FB1 0 + FB2 0 + FB3 0 + FB4 0 + FB5 0 + FB6 0 + FB7 0 + FB8 0 + FB9 0 + FB10 0 + FB11 0 + FB12 0 + FB13 0 + FB14 0 + FB15 0 + FB16 0 + FB17 0 + FB18 0 + FB19 0 + FB20 0 + FB21 0 + FB22 0 + FB23 0 + FB24 0 + FB25 0 + FB26 0 + FB27 0 + FB28 0 + FB29 0 + FB30 0 + FB31 0 + +F9R1 0x00000000 read-write @ 0x40006A88 + FB0 0 + FB1 0 + FB2 0 + FB3 0 + FB4 0 + FB5 0 + FB6 0 + FB7 0 + FB8 0 + FB9 0 + FB10 0 + FB11 0 + FB12 0 + FB13 0 + FB14 0 + FB15 0 + FB16 0 + FB17 0 + FB18 0 + FB19 0 + FB20 0 + FB21 0 + FB22 0 + FB23 0 + FB24 0 + FB25 0 + FB26 0 + FB27 0 + FB28 0 + FB29 0 + FB30 0 + FB31 0 + +F9R2 0x00000000 read-write @ 0x40006A8C + FB0 0 + FB1 0 + FB2 0 + FB3 0 + FB4 0 + FB5 0 + FB6 0 + FB7 0 + FB8 0 + FB9 0 + FB10 0 + FB11 0 + FB12 0 + FB13 0 + FB14 0 + FB15 0 + FB16 0 + FB17 0 + FB18 0 + FB19 0 + FB20 0 + FB21 0 + FB22 0 + FB23 0 + FB24 0 + FB25 0 + FB26 0 + FB27 0 + FB28 0 + FB29 0 + FB30 0 + FB31 0 + +F10R1 0x00000000 read-write @ 0x40006A90 + FB0 0 + FB1 0 + FB2 0 + FB3 0 + FB4 0 + FB5 0 + FB6 0 + FB7 0 + FB8 0 + FB9 0 + FB10 0 + FB11 0 + FB12 0 + FB13 0 + FB14 0 + FB15 0 + FB16 0 + FB17 0 + FB18 0 + FB19 0 + FB20 0 + FB21 0 + FB22 0 + FB23 0 + FB24 0 + FB25 0 + FB26 0 + FB27 0 + FB28 0 + FB29 0 + FB30 0 + FB31 0 + +F10R2 0x00000000 read-write @ 0x40006A94 + FB0 0 + FB1 0 + FB2 0 + FB3 0 + FB4 0 + FB5 0 + FB6 0 + FB7 0 + FB8 0 + FB9 0 + FB10 0 + FB11 0 + FB12 0 + FB13 0 + FB14 0 + FB15 0 + FB16 0 + FB17 0 + FB18 0 + FB19 0 + FB20 0 + FB21 0 + FB22 0 + FB23 0 + FB24 0 + FB25 0 + FB26 0 + FB27 0 + FB28 0 + FB29 0 + FB30 0 + FB31 0 + +F11R1 0x00000000 read-write @ 0x40006A98 + FB0 0 + FB1 0 + FB2 0 + FB3 0 + FB4 0 + FB5 0 + FB6 0 + FB7 0 + FB8 0 + FB9 0 + FB10 0 + FB11 0 + FB12 0 + FB13 0 + FB14 0 + FB15 0 + FB16 0 + FB17 0 + FB18 0 + FB19 0 + FB20 0 + FB21 0 + FB22 0 + FB23 0 + FB24 0 + FB25 0 + FB26 0 + FB27 0 + FB28 0 + FB29 0 + FB30 0 + FB31 0 + +F11R2 0x00000000 read-write @ 0x40006A9C + FB0 0 + FB1 0 + FB2 0 + FB3 0 + FB4 0 + FB5 0 + FB6 0 + FB7 0 + FB8 0 + FB9 0 + FB10 0 + FB11 0 + FB12 0 + FB13 0 + FB14 0 + FB15 0 + FB16 0 + FB17 0 + FB18 0 + FB19 0 + FB20 0 + FB21 0 + FB22 0 + FB23 0 + FB24 0 + FB25 0 + FB26 0 + FB27 0 + FB28 0 + FB29 0 + FB30 0 + FB31 0 + +F12R1 0x00000000 read-write @ 0x40006AA0 + FB0 0 + FB1 0 + FB2 0 + FB3 0 + FB4 0 + FB5 0 + FB6 0 + FB7 0 + FB8 0 + FB9 0 + FB10 0 + FB11 0 + FB12 0 + FB13 0 + FB14 0 + FB15 0 + FB16 0 + FB17 0 + FB18 0 + FB19 0 + FB20 0 + FB21 0 + FB22 0 + FB23 0 + FB24 0 + FB25 0 + FB26 0 + FB27 0 + FB28 0 + FB29 0 + FB30 0 + FB31 0 + +F12R2 0x00000000 read-write @ 0x40006AA4 + FB0 0 + FB1 0 + FB2 0 + FB3 0 + FB4 0 + FB5 0 + FB6 0 + FB7 0 + FB8 0 + FB9 0 + FB10 0 + FB11 0 + FB12 0 + FB13 0 + FB14 0 + FB15 0 + FB16 0 + FB17 0 + FB18 0 + FB19 0 + FB20 0 + FB21 0 + FB22 0 + FB23 0 + FB24 0 + FB25 0 + FB26 0 + FB27 0 + FB28 0 + FB29 0 + FB30 0 + FB31 0 + +F13R1 0x00000000 read-write @ 0x40006AA8 + FB0 0 + FB1 0 + FB2 0 + FB3 0 + FB4 0 + FB5 0 + FB6 0 + FB7 0 + FB8 0 + FB9 0 + FB10 0 + FB11 0 + FB12 0 + FB13 0 + FB14 0 + FB15 0 + FB16 0 + FB17 0 + FB18 0 + FB19 0 + FB20 0 + FB21 0 + FB22 0 + FB23 0 + FB24 0 + FB25 0 + FB26 0 + FB27 0 + FB28 0 + FB29 0 + FB30 0 + FB31 0 + +F13R2 0x00000000 read-write @ 0x40006AAC + FB0 0 + FB1 0 + FB2 0 + FB3 0 + FB4 0 + FB5 0 + FB6 0 + FB7 0 + FB8 0 + FB9 0 + FB10 0 + FB11 0 + FB12 0 + FB13 0 + FB14 0 + FB15 0 + FB16 0 + FB17 0 + FB18 0 + FB19 0 + FB20 0 + FB21 0 + FB22 0 + FB23 0 + FB24 0 + FB25 0 + FB26 0 + FB27 0 + FB28 0 + FB29 0 + FB30 0 + FB31 0 + +Peripheral :DAC +Name Value Access Address +CR 0x00000000 read-write @ 0x40007400 + EN1 0 + BOFF1 0 + TEN1 0 + TSEL1 0x0 + WAVE1 0x0 + MAMP1 0x0 + DMAEN1 0 + EN2 0 + BOFF2 0 + TEN2 0 + TSEL2 0x0 + WAVE2 0x0 + MAMP2 0x0 + DMAEN2 0 + +SWTRIGR write-only write-only @ 0x40007404 + SWTRIG1 W + SWTRIG2 W + +DHR12R1 0x00000000 read-write @ 0x40007408 + DACC1DHR 0x0 + +DHR12L1 0x00000000 read-write @ 0x4000740C + DACC1DHR 0x0 + +DHR8R1 0x00000000 read-write @ 0x40007410 + DACC1DHR 0x0 + +DHR12R2 0x00000000 read-write @ 0x40007414 + DACC2DHR 0x0 + +DHR12L2 0x00000000 read-write @ 0x40007418 + DACC2DHR 0x0 + +DHR8R2 0x00000000 read-write @ 0x4000741C + DACC2DHR 0x0 + +DHR12RD 0x00000000 read-write @ 0x40007420 + DACC1DHR 0x0 + DACC2DHR 0x0 + +DHR12LD 0x00000000 read-write @ 0x40007424 + DACC1DHR 0x0 + DACC2DHR 0x0 + +DHR8RD 0x00000000 read-write @ 0x40007428 + DACC1DHR 0x0 + DACC2DHR 0x0 + +DOR1 0x00000000 read-only @ 0x4000742C + DACC1DOR 0x0 + +DOR2 0x00000000 read-only @ 0x40007430 + DACC2DOR 0x0 + +Peripheral :DBG +Name Value Access Address +IDCODE 0x10036414 read-only @ 0xE0042000 + DEV_ID 0x414 + REV_ID 0x1003 + +CR 0x00000000 read-write @ 0xE0042004 + DBG_SLEEP 0 + DBG_STOP 0 + DBG_STANDBY 0 + TRACE_IOEN 0 + TRACE_MODE 0x0 + DBG_IWDG_STOP 0 + DBG_WWDG_STOP 0 + DBG_TIM1_STOP 0 + DBG_TIM2_STOP 0 + DBG_TIM3_STOP 0 + DBG_TIM4_STOP 0 + DBG_CAN1_STOP 0 + DBG_I2C1_SMBUS_TIMEOUT 0 + DBG_I2C2_SMBUS_TIMEOUT 0 + DBG_TIM8_STOP 0 + DBG_TIM5_STOP 0 + DBG_TIM6_STOP 0 + DBG_TIM7_STOP 0 + DBG_CAN2_STOP 0 + +Peripheral :UART4 +Name Value Access Address +SR 0x00000000 undefined @ 0x40004C00 + PE 0 + FE 0 + NE 0 + ORE 0 + IDLE 0 + RXNE 0 + TC 0 + TXE 0 + LBD 0 + +DR 0x00000000 read-write @ 0x40004C04 + DR 0x0 + +BRR 0x00000000 read-write @ 0x40004C08 + DIV_Fraction 0x0 + DIV_Mantissa 0x0 + +CR1 0x00000000 read-write @ 0x40004C0C + SBK 0 + RWU 0 + RE 0 + TE 0 + IDLEIE 0 + RXNEIE 0 + TCIE 0 + TXEIE 0 + PEIE 0 + PS 0 + PCE 0 + WAKE 0 + M 0 + UE 0 + +CR2 0x00000000 read-write @ 0x40004C10 + ADD 0x0 + LBDL 0 + LBDIE 0 + STOP 0x0 + LINEN 0 + +CR3 0x00000000 read-write @ 0x40004C14 + EIE 0 + IREN 0 + IRLP 0 + HDSEL 0 + DMAR 0 + DMAT 0 + +Peripheral :UART5 +Name Value Access Address +SR 0x00000000 undefined @ 0x40005000 + PE 0 + FE 0 + NE 0 + ORE 0 + IDLE 0 + RXNE 0 + TC 0 + TXE 0 + LBD 0 + +DR 0x00000000 read-write @ 0x40005004 + DR 0x0 + +BRR 0x00000000 read-write @ 0x40005008 + DIV_Fraction 0x0 + DIV_Mantissa 0x0 + +CR1 0x00000000 read-write @ 0x4000500C + SBK 0 + RWU 0 + RE 0 + TE 0 + IDLEIE 0 + RXNEIE 0 + TCIE 0 + TXEIE 0 + PEIE 0 + PS 0 + PCE 0 + WAKE 0 + M 0 + UE 0 + +CR2 0x00000000 read-write @ 0x40005010 + ADD 0x0 + LBDL 0 + LBDIE 0 + STOP 0x0 + LINEN 0 + +CR3 0x00000000 read-write @ 0x40005014 + EIE 0 + IREN 0 + IRLP 0 + HDSEL 0 + DMAT 0 + +Peripheral :CRC +Name Value Access Address +DR 0x00000000 read-write @ 0x40023000 + DR 0x0 + +IDR 0x00000000 read-write @ 0x40023004 + IDR 0x0 + +CR write-only write-only @ 0x40023008 + RESET W + +Peripheral :FLASH +Name Value Access Address +ACR 0x00000000 undefined @ 0x40022000 + LATENCY 0x0 + HLFCYA 0 + PRFTBE 0 + PRFTBS 0 + +KEYR write-only write-only @ 0x40022004 + KEY W + +OPTKEYR write-only write-only @ 0x40022008 + OPTKEY W + +SR 0x00000000 undefined @ 0x4002200C + EOP 0 + WRPRTERR 0 + PGERR 0 + BSY 0 + +CR 0x00000080 read-write @ 0x40022010 + PG 0 + PER 0 + MER 0 + OPTPG 0 + OPTER 0 + STRT 0 + LOCK 1 + OPTWRE 0 + ERRIE 0 + EOPIE 0 + +AR write-only write-only @ 0x40022014 + FAR W + +OBR 0x03FFFFFE read-only @ 0x4002201C + OPTERR 0 + RDPRT 1 + WDG_SW 1 + nRST_STOP 1 + nRST_STDBY 1 + Data0 0xFF + Data1 0xFF + +WRPR 0xFFFFFFFF read-only @ 0x40022020 + WRP 0xFFFFFFFF + +Peripheral :USB +Name Value Access Address +EP0R 0x00000000 read-write @ 0x40005C00 + EA 0x0 + STAT_TX 0x0 + DTOG_TX 0 + CTR_TX 0 + EP_KIND 0 + EP_TYPE 0x0 + SETUP 0 + STAT_RX 0x0 + DTOG_RX 0 + CTR_RX 0 + +EP1R 0x00000000 read-write @ 0x40005C04 + EA 0x0 + STAT_TX 0x0 + DTOG_TX 0 + CTR_TX 0 + EP_KIND 0 + EP_TYPE 0x0 + SETUP 0 + STAT_RX 0x0 + DTOG_RX 0 + CTR_RX 0 + +EP2R 0x00000000 read-write @ 0x40005C08 + EA 0x0 + STAT_TX 0x0 + DTOG_TX 0 + CTR_TX 0 + EP_KIND 0 + EP_TYPE 0x0 + SETUP 0 + STAT_RX 0x0 + DTOG_RX 0 + CTR_RX 0 + +EP3R 0x00000000 read-write @ 0x40005C0C + EA 0x0 + STAT_TX 0x0 + DTOG_TX 0 + CTR_TX 0 + EP_KIND 0 + EP_TYPE 0x0 + SETUP 0 + STAT_RX 0x0 + DTOG_RX 0 + CTR_RX 0 + +EP4R 0x00000000 read-write @ 0x40005C10 + EA 0x0 + STAT_TX 0x0 + DTOG_TX 0 + CTR_TX 0 + EP_KIND 0 + EP_TYPE 0x0 + SETUP 0 + STAT_RX 0x0 + DTOG_RX 0 + CTR_RX 0 + +EP5R 0x00000000 read-write @ 0x40005C14 + EA 0x0 + STAT_TX 0x0 + DTOG_TX 0 + CTR_TX 0 + EP_KIND 0 + EP_TYPE 0x0 + SETUP 0 + STAT_RX 0x0 + DTOG_RX 0 + CTR_RX 0 + +EP6R 0x00000000 read-write @ 0x40005C18 + EA 0x0 + STAT_TX 0x0 + DTOG_TX 0 + CTR_TX 0 + EP_KIND 0 + EP_TYPE 0x0 + SETUP 0 + STAT_RX 0x0 + DTOG_RX 0 + CTR_RX 0 + +EP7R 0x00000000 read-write @ 0x40005C1C + EA 0x0 + STAT_TX 0x0 + DTOG_TX 0 + CTR_TX 0 + EP_KIND 0 + EP_TYPE 0x0 + SETUP 0 + STAT_RX 0x0 + DTOG_RX 0 + CTR_RX 0 + +CNTR 0x00000000 read-write @ 0x40005C40 + FRES 0 + PDWN 0 + LPMODE 0 + FSUSP 0 + RESUME 0 + ESOFM 0 + SOFM 0 + RESETM 0 + SUSPM 0 + WKUPM 0 + ERRM 0 + PMAOVRM 0 + CTRM 0 + +ISTR 0x00000000 read-write @ 0x40005C44 + EP_ID 0x0 + DIR 0 + ESOF 0 + SOF 0 + RESET 0 + SUSP 0 + WKUP 0 + ERR 0 + PMAOVR 0 + CTR 0 + +FNR 0x00000000 read-only @ 0x40005C48 + FN 0x0 + LSOF 0x0 + LCK 0 + RXDM 0 + RXDP 0 + +DADDR 0x00000000 read-write @ 0x40005C4C + ADD 0x0 + EF 0 + +BTABLE 0x00000000 read-write @ 0x40005C50 + BTABLE 0x0 + +Peripheral :OTG_FS_DEVICE +Name Value Access Address +FS_DCFG -- read-write @ 0x50000800 + DSPD -- + NZLSOHSK -- + DAD -- + PFIVL -- + +FS_DCTL 0x00000000 undefined @ 0x50000804 + RWUSIG 0 + SDIS 0 + GINSTS 0 + GONSTS 0 + TCTL 0x0 + SGINAK 0 + CGINAK 0 + SGONAK 0 + CGONAK 0 + POPRGDNE 0 + +FS_DSTS -- read-only @ 0x50000808 + SUSPSTS -- + ENUMSPD -- + EERR -- + FNSOF -- + +FS_DIEPMSK -- read-write @ 0x50000810 + XFRCM -- + EPDM -- + TOM -- + ITTXFEMSK -- + INEPNMM -- + INEPNEM -- + +FS_DOEPMSK -- read-write @ 0x50000814 + XFRCM -- + EPDM -- + STUPM -- + OTEPDM -- + +FS_DAINT -- read-only @ 0x50000818 + IEPINT -- + OEPINT -- + +FS_DAINTMSK -- read-write @ 0x5000081C + IEPM -- + OEPINT -- + +DVBUSDIS -- read-write @ 0x50000828 + VBUSDT -- + +DVBUSPULSE -- read-write @ 0x5000082C + DVBUSP -- + +DIEPEMPMSK -- read-write @ 0x50000834 + INEPTXFEM -- + +FS_DIEPCTL0 0x00000000 undefined @ 0x50000900 + MPSIZ 0x0 + USBAEP 0 + NAKSTS 0 + EPTYP 0x0 + STALL 0 + TXFNUM 0x0 + CNAK 0 + SNAK 0 + EPDIS 0 + EPENA 0 + +DIEPCTL1 0x00000000 undefined @ 0x50000920 + EPENA 0 + EPDIS 0 + SODDFRM_SD1PID 0 + SD0PID_SEVNFRM 0 + SNAK 0 + CNAK 0 + TXFNUM 0x0 + Stall 0 + EPTYP 0x0 + NAKSTS 0 + EONUM_DPID 0 + USBAEP 0 + MPSIZ 0x0 + +DIEPCTL2 0x00000000 undefined @ 0x50000940 + EPENA 0 + EPDIS 0 + SODDFRM 0 + SD0PID_SEVNFRM 0 + SNAK 0 + CNAK 0 + TXFNUM 0x0 + Stall 0 + EPTYP 0x0 + NAKSTS 0 + EONUM_DPID 0 + USBAEP 0 + MPSIZ 0x0 + +DIEPCTL3 0x00000000 undefined @ 0x50000960 + EPENA 0 + EPDIS 0 + SODDFRM 0 + SD0PID_SEVNFRM 0 + SNAK 0 + CNAK 0 + TXFNUM 0x0 + Stall 0 + EPTYP 0x0 + NAKSTS 0 + EONUM_DPID 0 + USBAEP 0 + MPSIZ 0x0 + +DOEPCTL0 0x00000000 undefined @ 0x50000B00 + EPENA 0 + EPDIS 0 + SNAK 0 + CNAK 0 + Stall 0 + SNPM 0 + EPTYP 0x0 + NAKSTS 0 + USBAEP 0 + MPSIZ 0x0 + +DOEPCTL1 0x00000000 undefined @ 0x50000B20 + EPENA 0 + EPDIS 0 + SODDFRM 0 + SD0PID_SEVNFRM 0 + SNAK 0 + CNAK 0 + Stall 0 + SNPM 0 + EPTYP 0x0 + NAKSTS 0 + EONUM_DPID 0 + USBAEP 0 + MPSIZ 0x0 + +DOEPCTL2 0x00000000 undefined @ 0x50000B40 + EPENA 0 + EPDIS 0 + SODDFRM 0 + SD0PID_SEVNFRM 0 + SNAK 0 + CNAK 0 + Stall 0 + SNPM 0 + EPTYP 0x0 + NAKSTS 0 + EONUM_DPID 0 + USBAEP 0 + MPSIZ 0x0 + +DOEPCTL3 0x00000000 undefined @ 0x50000B60 + EPENA 0 + EPDIS 0 + SODDFRM 0 + SD0PID_SEVNFRM 0 + SNAK 0 + CNAK 0 + Stall 0 + SNPM 0 + EPTYP 0x0 + NAKSTS 0 + EONUM_DPID 0 + USBAEP 0 + MPSIZ 0x0 + +DIEPINT0 0x00000000 undefined @ 0x50000908 + TXFE 0 + INEPNE 0 + ITTXFE 0 + TOC 0 + EPDISD 0 + XFRC 0 + +DIEPINT1 0x00000000 undefined @ 0x50000928 + TXFE 0 + INEPNE 0 + ITTXFE 0 + TOC 0 + EPDISD 0 + XFRC 0 + +DIEPINT2 0x00000000 undefined @ 0x50000948 + TXFE 0 + INEPNE 0 + ITTXFE 0 + TOC 0 + EPDISD 0 + XFRC 0 + +DIEPINT3 0x00000000 undefined @ 0x50000968 + TXFE 0 + INEPNE 0 + ITTXFE 0 + TOC 0 + EPDISD 0 + XFRC 0 + +DOEPINT0 -- read-write @ 0x50000B08 + B2BSTUP -- + OTEPDIS -- + STUP -- + EPDISD -- + XFRC -- + +DOEPINT1 -- read-write @ 0x50000B28 + B2BSTUP -- + OTEPDIS -- + STUP -- + EPDISD -- + XFRC -- + +DOEPINT2 -- read-write @ 0x50000B48 + B2BSTUP -- + OTEPDIS -- + STUP -- + EPDISD -- + XFRC -- + +DOEPINT3 -- read-write @ 0x50000B68 + B2BSTUP -- + OTEPDIS -- + STUP -- + EPDISD -- + XFRC -- + +DIEPTSIZ0 -- read-write @ 0x50000910 + PKTCNT -- + XFRSIZ -- + +DOEPTSIZ0 -- read-write @ 0x50000B10 + STUPCNT -- + PKTCNT -- + XFRSIZ -- + +DIEPTSIZ1 -- read-write @ 0x50000930 + MCNT -- + PKTCNT -- + XFRSIZ -- + +DIEPTSIZ2 -- read-write @ 0x50000950 + MCNT -- + PKTCNT -- + XFRSIZ -- + +DIEPTSIZ3 -- read-write @ 0x50000970 + MCNT -- + PKTCNT -- + XFRSIZ -- + +DTXFSTS0 -- read-only @ 0x50000918 + INEPTFSAV -- + +DTXFSTS1 -- read-only @ 0x50000938 + INEPTFSAV -- + +DTXFSTS2 -- read-only @ 0x50000958 + INEPTFSAV -- + +DTXFSTS3 -- read-only @ 0x50000978 + INEPTFSAV -- + +DOEPTSIZ1 -- read-write @ 0x50000B30 + RXDPID_STUPCNT -- + PKTCNT -- + XFRSIZ -- + +DOEPTSIZ2 -- read-write @ 0x50000B50 + RXDPID_STUPCNT -- + PKTCNT -- + XFRSIZ -- + +DOEPTSIZ3 -- read-write @ 0x50000B70 + RXDPID_STUPCNT -- + PKTCNT -- + XFRSIZ -- + +Peripheral :OTG_FS_GLOBAL +Name Value Access Address +FS_GOTGCTL 0x00000000 undefined @ 0x50000000 + SRQSCS 0 + SRQ 0 + HNGSCS 0 + HNPRQ 0 + HSHNPEN 0 + DHNPEN 0 + CIDSTS 0 + DBCT 0 + ASVLD 0 + BSVLD 0 + +FS_GOTGINT -- read-write @ 0x50000004 + SEDET -- + SRSSCHG -- + HNSSCHG -- + HNGDET -- + ADTOCHG -- + DBCDNE -- + +FS_GAHBCFG -- read-write @ 0x50000008 + GINT -- + TXFELVL -- + PTXFELVL -- + +FS_GUSBCFG 0x00000000 undefined @ 0x5000000C + TOCAL 0x0 + PHYSEL 0 + SRPCAP 0 + HNPCAP 0 + TRDT 0x0 + FHMOD 0 + FDMOD 0 + CTXPKT 0 + +FS_GRSTCTL 0x00000000 undefined @ 0x50000010 + CSRST 0 + HSRST 0 + FCRST 0 + RXFFLSH 0 + TXFFLSH 0 + TXFNUM 0x0 + AHBIDL 0 + +FS_GINTSTS 0x00000000 undefined @ 0x50000014 + CMOD 0 + MMIS 0 + OTGINT 0 + SOF 0 + RXFLVL 0 + NPTXFE 0 + GINAKEFF 0 + GOUTNAKEFF 0 + ESUSP 0 + USBSUSP 0 + USBRST 0 + ENUMDNE 0 + ISOODRP 0 + EOPF 0 + IEPINT 0 + OEPINT 0 + IISOIXFR 0 + IPXFR_INCOMPISOOUT 0 + HPRTINT 0 + HCINT 0 + PTXFE 0 + CIDSCHG 0 + DISCINT 0 + SRQINT 0 + WKUPINT 0 + +FS_GINTMSK 0x00000000 undefined @ 0x50000018 + MMISM 0 + OTGINT 0 + SOFM 0 + RXFLVLM 0 + NPTXFEM 0 + GINAKEFFM 0 + GONAKEFFM 0 + ESUSPM 0 + USBSUSPM 0 + USBRST 0 + ENUMDNEM 0 + ISOODRPM 0 + EOPFM 0 + EPMISM 0 + IEPINT 0 + OEPINT 0 + IISOIXFRM 0 + IPXFRM_IISOOXFRM 0 + PRTIM 0 + HCIM 0 + PTXFEM 0 + CIDSCHGM 0 + DISCINT 0 + SRQIM 0 + WUIM 0 + +FS_GRXSTSR_Device -- read-only @ 0x5000001C + EPNUM -- + BCNT -- + DPID -- + PKTSTS -- + FRMNUM -- + +FS_GRXSTSR_Host -- read-only @ 0x5000001C + EPNUM -- + BCNT -- + DPID -- + PKTSTS -- + FRMNUM -- + +FS_GRXFSIZ -- read-write @ 0x50000024 + RXFD -- + +FS_GNPTXFSIZ_Device -- read-write @ 0x50000028 + TX0FSA -- + TX0FD -- + +FS_GNPTXFSIZ_Host -- read-write @ 0x50000028 + NPTXFSA -- + NPTXFD -- + +FS_GNPTXSTS -- read-only @ 0x5000002C + NPTXFSAV -- + NPTQXSAV -- + NPTXQTOP -- + +FS_GCCFG -- read-write @ 0x50000038 + PWRDWN -- + VBUSASEN -- + VBUSBSEN -- + SOFOUTEN -- + +FS_CID -- read-write @ 0x5000003C + PRODUCT_ID -- + +FS_HPTXFSIZ -- read-write @ 0x50000100 + PTXSA -- + PTXFSIZ -- + +FS_DIEPTXF1 -- read-write @ 0x50000104 + INEPTXSA -- + INEPTXFD -- + +FS_DIEPTXF2 -- read-write @ 0x50000108 + INEPTXSA -- + INEPTXFD -- + +FS_DIEPTXF3 -- read-write @ 0x5000010C + INEPTXSA -- + INEPTXFD -- + +Peripheral :OTG_FS_HOST +Name Value Access Address +FS_HCFG 0x00000000 undefined @ 0x50000400 + FSLSPCS 0x0 + FSLSS 0 + +HFIR -- read-write @ 0x50000404 + FRIVL -- + +FS_HFNUM -- read-only @ 0x50000408 + FRNUM -- + FTREM -- + +FS_HPTXSTS 0x00000000 undefined @ 0x50000410 + PTXFSAVL 0x0 + PTXQSAV 0x0 + PTXQTOP 0x0 + +HAINT -- read-only @ 0x50000414 + HAINT -- + +HAINTMSK -- read-write @ 0x50000418 + HAINTM -- + +FS_HPRT 0x00000000 undefined @ 0x50000440 + PCSTS 0 + PCDET 0 + PENA 0 + PENCHNG 0 + POCA 0 + POCCHNG 0 + PRES 0 + PSUSP 0 + PRST 0 + PLSTS 0x0 + PPWR 0 + PTCTL 0x0 + PSPD 0x0 + +FS_HCCHAR0 -- read-write @ 0x50000500 + MPSIZ -- + EPNUM -- + EPDIR -- + LSDEV -- + EPTYP -- + MCNT -- + DAD -- + ODDFRM -- + CHDIS -- + CHENA -- + +FS_HCCHAR1 -- read-write @ 0x50000520 + MPSIZ -- + EPNUM -- + EPDIR -- + LSDEV -- + EPTYP -- + MCNT -- + DAD -- + ODDFRM -- + CHDIS -- + CHENA -- + +FS_HCCHAR2 -- read-write @ 0x50000540 + MPSIZ -- + EPNUM -- + EPDIR -- + LSDEV -- + EPTYP -- + MCNT -- + DAD -- + ODDFRM -- + CHDIS -- + CHENA -- + +FS_HCCHAR3 -- read-write @ 0x50000560 + MPSIZ -- + EPNUM -- + EPDIR -- + LSDEV -- + EPTYP -- + MCNT -- + DAD -- + ODDFRM -- + CHDIS -- + CHENA -- + +FS_HCCHAR4 -- read-write @ 0x50000580 + MPSIZ -- + EPNUM -- + EPDIR -- + LSDEV -- + EPTYP -- + MCNT -- + DAD -- + ODDFRM -- + CHDIS -- + CHENA -- + +FS_HCCHAR5 -- read-write @ 0x500005A0 + MPSIZ -- + EPNUM -- + EPDIR -- + LSDEV -- + EPTYP -- + MCNT -- + DAD -- + ODDFRM -- + CHDIS -- + CHENA -- + +FS_HCCHAR6 -- read-write @ 0x500005C0 + MPSIZ -- + EPNUM -- + EPDIR -- + LSDEV -- + EPTYP -- + MCNT -- + DAD -- + ODDFRM -- + CHDIS -- + CHENA -- + +FS_HCCHAR7 -- read-write @ 0x500005E0 + MPSIZ -- + EPNUM -- + EPDIR -- + LSDEV -- + EPTYP -- + MCNT -- + DAD -- + ODDFRM -- + CHDIS -- + CHENA -- + +FS_HCINT0 -- read-write @ 0x50000508 + XFRC -- + CHH -- + STALL -- + NAK -- + ACK -- + TXERR -- + BBERR -- + FRMOR -- + DTERR -- + +FS_HCINT1 -- read-write @ 0x50000528 + XFRC -- + CHH -- + STALL -- + NAK -- + ACK -- + TXERR -- + BBERR -- + FRMOR -- + DTERR -- + +FS_HCINT2 -- read-write @ 0x50000548 + XFRC -- + CHH -- + STALL -- + NAK -- + ACK -- + TXERR -- + BBERR -- + FRMOR -- + DTERR -- + +FS_HCINT3 -- read-write @ 0x50000568 + XFRC -- + CHH -- + STALL -- + NAK -- + ACK -- + TXERR -- + BBERR -- + FRMOR -- + DTERR -- + +FS_HCINT4 -- read-write @ 0x50000588 + XFRC -- + CHH -- + STALL -- + NAK -- + ACK -- + TXERR -- + BBERR -- + FRMOR -- + DTERR -- + +FS_HCINT5 -- read-write @ 0x500005A8 + XFRC -- + CHH -- + STALL -- + NAK -- + ACK -- + TXERR -- + BBERR -- + FRMOR -- + DTERR -- + +FS_HCINT6 -- read-write @ 0x500005C8 + XFRC -- + CHH -- + STALL -- + NAK -- + ACK -- + TXERR -- + BBERR -- + FRMOR -- + DTERR -- + +FS_HCINT7 -- read-write @ 0x500005E8 + XFRC -- + CHH -- + STALL -- + NAK -- + ACK -- + TXERR -- + BBERR -- + FRMOR -- + DTERR -- + +FS_HCINTMSK0 -- read-write @ 0x5000050C + XFRCM -- + CHHM -- + STALLM -- + NAKM -- + ACKM -- + NYET -- + TXERRM -- + BBERRM -- + FRMORM -- + DTERRM -- + +FS_HCINTMSK1 -- read-write @ 0x5000052C + XFRCM -- + CHHM -- + STALLM -- + NAKM -- + ACKM -- + NYET -- + TXERRM -- + BBERRM -- + FRMORM -- + DTERRM -- + +FS_HCINTMSK2 -- read-write @ 0x5000054C + XFRCM -- + CHHM -- + STALLM -- + NAKM -- + ACKM -- + NYET -- + TXERRM -- + BBERRM -- + FRMORM -- + DTERRM -- + +FS_HCINTMSK3 -- read-write @ 0x5000056C + XFRCM -- + CHHM -- + STALLM -- + NAKM -- + ACKM -- + NYET -- + TXERRM -- + BBERRM -- + FRMORM -- + DTERRM -- + +FS_HCINTMSK4 -- read-write @ 0x5000058C + XFRCM -- + CHHM -- + STALLM -- + NAKM -- + ACKM -- + NYET -- + TXERRM -- + BBERRM -- + FRMORM -- + DTERRM -- + +FS_HCINTMSK5 -- read-write @ 0x500005AC + XFRCM -- + CHHM -- + STALLM -- + NAKM -- + ACKM -- + NYET -- + TXERRM -- + BBERRM -- + FRMORM -- + DTERRM -- + +FS_HCINTMSK6 -- read-write @ 0x500005CC + XFRCM -- + CHHM -- + STALLM -- + NAKM -- + ACKM -- + NYET -- + TXERRM -- + BBERRM -- + FRMORM -- + DTERRM -- + +FS_HCINTMSK7 -- read-write @ 0x500005EC + XFRCM -- + CHHM -- + STALLM -- + NAKM -- + ACKM -- + NYET -- + TXERRM -- + BBERRM -- + FRMORM -- + DTERRM -- + +FS_HCTSIZ0 -- read-write @ 0x50000510 + XFRSIZ -- + PKTCNT -- + DPID -- + +FS_HCTSIZ1 -- read-write @ 0x50000530 + XFRSIZ -- + PKTCNT -- + DPID -- + +FS_HCTSIZ2 -- read-write @ 0x50000550 + XFRSIZ -- + PKTCNT -- + DPID -- + +FS_HCTSIZ3 -- read-write @ 0x50000570 + XFRSIZ -- + PKTCNT -- + DPID -- + +FS_HCTSIZ4 -- read-write @ 0x50000590 + XFRSIZ -- + PKTCNT -- + DPID -- + +FS_HCTSIZ5 -- read-write @ 0x500005B0 + XFRSIZ -- + PKTCNT -- + DPID -- + +FS_HCTSIZ6 -- read-write @ 0x500005D0 + XFRSIZ -- + PKTCNT -- + DPID -- + +FS_HCTSIZ7 -- read-write @ 0x500005F0 + XFRSIZ -- + PKTCNT -- + DPID -- + +Peripheral :OTG_FS_PWRCLK +Name Value Access Address +FS_PCGCCTL -- read-write @ 0x50000E00 + STPPCLK -- + GATEHCLK -- + PHYSUSP -- + +Peripheral :ETHERNET_MMC +Name Value Access Address +MMCCR -- read-write @ 0x40028100 + CR -- + CSR -- + ROR -- + MCF -- + +MMCRIR -- read-write @ 0x40028104 + RFCES -- + RFAES -- + RGUFS -- + +MMCTIR -- read-write @ 0x40028108 + TGFSCS -- + TGFMSCS -- + TGFS -- + +MMCRIMR -- read-write @ 0x4002810C + RFCEM -- + RFAEM -- + RGUFM -- + +MMCTIMR -- read-write @ 0x40028110 + TGFSCM -- + TGFMSCM -- + TGFM -- + +MMCTGFSCCR -- read-only @ 0x4002814C + TGFSCC -- + +MMCTGFMSCCR -- read-only @ 0x40028150 + TGFMSCC -- + +MMCTGFCR -- read-only @ 0x40028168 + TGFC -- + +MMCRFCECR -- read-only @ 0x40028194 + RFCFC -- + +MMCRFAECR -- read-only @ 0x40028198 + RFAEC -- + +MMCRGUFCR -- read-only @ 0x400281C4 + RGUFC -- + +Peripheral :ETHERNET_MAC +Name Value Access Address +MACCR -- read-write @ 0x40028000 + RE -- + TE -- + DC -- + BL -- + APCS -- + RD -- + IPCO -- + DM -- + LM -- + ROD -- + FES -- + CSD -- + IFG -- + JD -- + WD -- + +MACFFR -- read-write @ 0x40028004 + PM -- + HU -- + HM -- + DAIF -- + PAM -- + BFD -- + PCF -- + SAIF -- + SAF -- + HPF -- + RA -- + +MACHTHR -- read-write @ 0x40028008 + HTH -- + +MACHTLR -- read-write @ 0x4002800C + HTL -- + +MACMIIAR -- read-write @ 0x40028010 + MB -- + MW -- + CR -- + MR -- + PA -- + +MACMIIDR -- read-write @ 0x40028014 + MD -- + +MACFCR -- read-write @ 0x40028018 + FCB_BPA -- + TFCE -- + RFCE -- + UPFD -- + PLT -- + ZQPD -- + PT -- + +MACVLANTR -- read-write @ 0x4002801C + VLANTI -- + VLANTC -- + +MACRWUFFR -- read-write @ 0x40028028 + +MACPMTCSR -- read-write @ 0x4002802C + PD -- + MPE -- + WFE -- + MPR -- + WFR -- + GU -- + WFFRPR -- + +MACSR -- read-write @ 0x40028038 + PMTS -- + MMCS -- + MMCRS -- + MMCTS -- + TSTS -- + +MACIMR -- read-write @ 0x4002803C + PMTIM -- + TSTIM -- + +MACA0HR 0x00000000 undefined @ 0x40028040 + MACA0H 0x0 + MO 0 + +MACA0LR -- read-write @ 0x40028044 + MACA0L -- + +MACA1HR -- read-write @ 0x40028048 + MACA1H -- + MBC -- + SA -- + AE -- + +MACA1LR -- read-write @ 0x4002804C + MACA1L -- + +MACA2HR -- read-write @ 0x40028050 + ETH_MACA2HR -- + MBC -- + SA -- + AE -- + +MACA2LR -- read-write @ 0x40028054 + MACA2L -- + +MACA3HR -- read-write @ 0x40028058 + MACA3H -- + MBC -- + SA -- + AE -- + +MACA3LR -- read-write @ 0x4002805C + MBCA3L -- + +Peripheral :ETHERNET_PTP +Name Value Access Address +PTPTSCR -- read-write @ 0x40028700 + TSE -- + TSFCU -- + TSSTI -- + TSSTU -- + TSITE -- + TSARU -- + +PTPSSIR -- read-write @ 0x40028704 + STSSI -- + +PTPTSHR -- read-only @ 0x40028708 + STS -- + +PTPTSLR -- read-only @ 0x4002870C + STSS -- + STPNS -- + +PTPTSHUR -- read-write @ 0x40028710 + TSUS -- + +PTPTSLUR -- read-write @ 0x40028714 + TSUSS -- + TSUPNS -- + +PTPTSAR -- read-write @ 0x40028718 + TSA -- + +PTPTTHR -- read-write @ 0x4002871C + TTSH -- + +PTPTTLR -- read-write @ 0x40028720 + TTSL -- + +Peripheral :ETHERNET_DMA +Name Value Access Address +DMABMR -- read-write @ 0x40029000 + SR -- + DA -- + DSL -- + PBL -- + RTPR -- + FB -- + RDP -- + USP -- + FPM -- + AAB -- + +DMATPDR -- read-write @ 0x40029004 + TPD -- + +DMARPDR -- read-write @ 0x40029008 + RPD -- + +DMARDLAR -- read-write @ 0x4002900C + SRL -- + +DMATDLAR -- read-write @ 0x40029010 + STL -- + +DMASR 0x00000000 undefined @ 0x40029014 + TS 0 + TPSS 0 + TBUS 0 + TJTS 0 + ROS 0 + TUS 0 + RS 0 + RBUS 0 + RPSS 0 + PWTS 0 + ETS 0 + FBES 0 + ERS 0 + AIS 0 + NIS 0 + RPS 0x0 + TPS 0x0 + EBS 0x0 + MMCS 0 + PMTS 0 + TSTS 0 + +DMAOMR -- read-write @ 0x40029018 + SR -- + OSF -- + RTC -- + FUGF -- + FEF -- + ST -- + TTC -- + FTF -- + TSF -- + DFRF -- + RSF -- + DTCEFD -- + +DMAIER -- read-write @ 0x4002901C + TIE -- + TPSIE -- + TBUIE -- + TJTIE -- + ROIE -- + TUIE -- + RIE -- + RBUIE -- + RPSIE -- + RWTIE -- + ETIE -- + FBEIE -- + ERIE -- + AISE -- + NISE -- + +DMAMFBOCR -- read-only @ 0x40029020 + MFC -- + OMFC -- + MFA -- + OFOC -- + +DMACHTDR -- read-only @ 0x40029048 + HTDAP -- + +DMACHRDR -- read-only @ 0x4002904C + HRDAP -- + +DMACHTBAR -- read-only @ 0x40029050 + HTBAP -- + +DMACHRBAR -- read-only @ 0x40029054 + HRBAP -- + diff --git a/Growatt ShineLAN-X/firmware/.gitignore b/Growatt ShineLAN-X/firmware/.gitignore new file mode 100644 index 0000000..89cc49c --- /dev/null +++ b/Growatt ShineLAN-X/firmware/.gitignore @@ -0,0 +1,5 @@ +.pio +.vscode/.browse.c_cpp.db* +.vscode/c_cpp_properties.json +.vscode/launch.json +.vscode/ipch diff --git a/Growatt ShineLAN-X/firmware/include/config.h b/Growatt ShineLAN-X/firmware/include/config.h new file mode 100644 index 0000000..a4e0dc5 --- /dev/null +++ b/Growatt ShineLAN-X/firmware/include/config.h @@ -0,0 +1,57 @@ +#pragma once + +// ============================================================ +// NETZWERK — ENC28J60 Ethernet (Bitbang-SPI auf Port C) +// STM32F103RBT6, LQFP-64 +// Hardware-SPI nicht nutzbar — alle SPI-Pins liegen auf Port C +// ============================================================ + +// Bitbang-SPI Pins (alle gemessen) +#define ETH_CS_PIN PC7 // ENC28J60 Pin 7 /CS → STM32 Pin 36 (gemessen) +#define ETH_SCK_PIN PC6 // ENC28J60 Pin 6 SCK → STM32 Pin 35 (gemessen) +#define ETH_MISO_PIN PC8 // ENC28J60 Pin 4 SO → STM32 Pin 37 (gemessen) +#define ETH_MOSI_PIN PC9 // ENC28J60 Pin 5 SI → STM32 Pin ?? (noch unbekannt, Scan läuft) + +// ENC28J60 Reset +#define ETH_RST_PIN PB13 // ENC28J60 Pin 18 /RESET → STM32 Pin 32, 500Ω + +// 0 = DHCP, 1 = Statische IP +#define USE_DHCP 0 + +// Nur relevant wenn USE_DHCP = 0 +#define STATIC_IP 192,168,2,15 +#define STATIC_GW 192,168,2,1 +#define STATIC_SUBNET 255,255,255,0 +#define STATIC_DNS 192,168,2,1 + +// MAC-Adresse — muss im Netzwerk eindeutig sein +#define MAC_ADDRESS 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED + +// ============================================================ +// MQTT +// ============================================================ +#define MQTT_BROKER "192.168.2.84" +#define MQTT_PORT 1883 +#define MQTT_USER "" // Leer lassen wenn kein Auth +#define MQTT_PASSWORD "" +#define MQTT_CLIENT "growatt-shinelan" + +// ============================================================ +// RS485 / MODBUS +// RS485 DE/RE → STM32 Pin 25 = PB1 (LQFP-64 neu gemessen) +// USART1: TX=PA9 (Pin 40), RX=PA10 (Pin 41) +// ============================================================ +#define RS485_DE_PIN PB1 // RE/DE Steuerpin → STM32 Pin 25 +#define MODBUS_BAUD 9600 // Growatt Standard-Baudrate +#define MODBUS_ADDR 1 // Modbus Slave-Adresse des Wechselrichters + +// ============================================================ +// GERÄT +// ============================================================ +#define DEVICE_ID "growatt_shinelan" +#define DEVICE_NAME "Growatt ShineLAN-X" +#define DEVICE_MODEL "ShineLAN-X" +#define DEVICE_MFR "Growatt" + +// Abfrageintervall in Millisekunden +#define UPDATE_INTERVAL 10000UL diff --git a/Growatt ShineLAN-X/firmware/include/enc28j60_bitbang.h b/Growatt ShineLAN-X/firmware/include/enc28j60_bitbang.h new file mode 100644 index 0000000..b0c6924 --- /dev/null +++ b/Growatt ShineLAN-X/firmware/include/enc28j60_bitbang.h @@ -0,0 +1,29 @@ +#pragma once +#include +#include "config.h" + +// ============================================================ +// Bitbang-SPI für ENC28J60 auf PC6/PC7/PC8/PC9 +// ENC28J60 verwendet SPI Mode 0 (CPOL=0, CPHA=0) +// ============================================================ + +static inline void eth_spi_init() { + pinMode(ETH_SCK_PIN, OUTPUT); digitalWrite(ETH_SCK_PIN, LOW); + pinMode(ETH_MOSI_PIN, OUTPUT); digitalWrite(ETH_MOSI_PIN, LOW); + pinMode(ETH_MISO_PIN, INPUT); + pinMode(ETH_CS_PIN, OUTPUT); digitalWrite(ETH_CS_PIN, HIGH); +} + +static inline void eth_cs_low() { digitalWrite(ETH_CS_PIN, LOW); } +static inline void eth_cs_high() { digitalWrite(ETH_CS_PIN, HIGH); } + +static inline uint8_t eth_spi_transfer(uint8_t out) { + uint8_t in = 0; + for (int8_t i = 7; i >= 0; i--) { + digitalWrite(ETH_MOSI_PIN, (out >> i) & 1); + digitalWrite(ETH_SCK_PIN, HIGH); + in = (in << 1) | digitalRead(ETH_MISO_PIN); + digitalWrite(ETH_SCK_PIN, LOW); + } + return in; +} diff --git a/Growatt ShineLAN-X/firmware/lib/EthernetENC/.piopm b/Growatt ShineLAN-X/firmware/lib/EthernetENC/.piopm new file mode 100644 index 0000000..01c20e6 --- /dev/null +++ b/Growatt ShineLAN-X/firmware/lib/EthernetENC/.piopm @@ -0,0 +1 @@ +{"type": "library", "name": "EthernetENC", "version": "2.0.5", "spec": {"owner": "jandrassy", "id": 11203, "name": "EthernetENC", "requirements": null, "uri": null}} \ No newline at end of file diff --git a/Growatt ShineLAN-X/firmware/lib/EthernetENC/README.md b/Growatt ShineLAN-X/firmware/lib/EthernetENC/README.md new file mode 100644 index 0000000..c7d7411 --- /dev/null +++ b/Growatt ShineLAN-X/firmware/lib/EthernetENC/README.md @@ -0,0 +1,158 @@ +First an important note: There are more suitable libraries for ENC28J60 with ESP8266, RP2040, ESP32 and Mbed Arduino platforms: + +* With ESP8266 and RP2040 platform you can use the EthernetCompat.h from the lwIP_enc28j60 bundled library. +* With ESP32 platform version 3 you can use the [EthernetESP32](https://github.com/Networking-for-Arduino/EthernetESP32) library which integrates with networking on the ESP32 platform. +* With Arduino Mbed Core boards you can use the [ENC28J60-EMAC](https://github.com/Networking-for-Arduino/ENC28J60-EMAC) library with the platforms Ethernet library + +--- + +# EthernetENC + +EthernetENC is the Ethernet library for ENC28J60. It is a modern version of [the UIPEthernet library](https://github.com/jandrassy/EthernetENC/wiki/UIPEthernet). + +The modernization includes: +* Ethernet 2.0.0 Arduino library functions +* compatible include file names EthernetClient.h, EthernetServer.h and EthernetUdp.h +* support of many Arduino architectures by using the SPI library +* SPI transactions to share the SPI bus with devices with different communication settings +* SPI communication at 20 MHz if the MCU supports it, else on the maximum supported by the MCU +* client.flush() to send the packet immediately +* calls yield() in blocking functions +* has UDP backlog to receive more than one message at time +* Arduino 1.5 library format built with dot_a_linkage option for optimal build result + +[The documentation of Arduino Ethernet library](https://www.arduino.cc/en/Reference/Ethernet) applies for classes and functions descriptions. + +Limitations: +* UDP.beginMulticast is not supported, because the uIP stack doesn't support multicast +* UDP broadcasts receiving is turned off on ENC to lower the processing load on the library + +This library doesn't have examples, because examples of the Arduino Ethernet library apply. You can find them in the Arduino IDE Examples menu Ethernet section. Only change `#include ` to `#include `. Some examples require [a little change](https://github.com/jandrassy/EthernetENC/wiki/Examples). + +This library is based on the Norbert Truchsess's arduino-uip original source code repository and uses experience from the development of the multi-architecture support by Cassy. Applicable fixes and enhancements from development of EthernetENC were transfered to Cassy's UIPEthernet. + +**You can find more information in project's [Wiki](https://github.com/jandrassy/EthernetENC/wiki).** + +## Original notes by Norbert Truchsess + +UIPEthernet is written as a wrapper around the mature uIP Stack by Adam Dunkels, which provides the low-level implementation for all supported protocols. To overcome the memory-constrains (a 'regular' uIP-application does all processing in RAM) the ENC28J60 internal memory is used for all stream buffers (in and out). Only 400-600 Bytes of Arduinos RAM are used (depending on the number of concurrently open connections). As of Flash-memory a ATmega368-based Arduino is the minimum requirenment. + +uIP was written by Adam Dunkels of the Networked Embedded Systems group at the Swedish Institute of Computer Science. + +This library was inspired by the SerialIP implementation by Adam Nielsen , actually I took this code as a starting point, but in the latest versions there are very few lines left. + + +## Licenses +``` +UIPEthernet.h +UIPEthernet.cpp +UIPServer.h +UIPServer.cpp +UIPClient.h +UIPClient.cpp +UIPUdp.h +UIPUdp.cpp +utility/mempool.h +utility/mempool.cpp + +Copyright (c) 2013 Norbert Truchsess +All rights reserved. + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +-------------- + +utility/enc28j60.h + +Author : Pascal Stang (c)2005 +Modified by Norbert Truchsess +Copyright: GPL V2 + +-------------- + +utility/Enc28J60Network.h +utility/Enc28J60Network.cpp + +Copyright (c) 2013 Norbert Truchsess +All rights reserved. + +inspired and based on enc28j60.c file from the AVRlib library by Pascal Stang. + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +-------------- + +utility/uip.c +utility/uip_arp.h +utility/uip_arp.c +utility/uip_arch.h +utility/uip.h +utility/uipopt.h + +Copyright (c) 2001-2003, Adam Dunkels , . +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. +3. Neither the name of the Institute nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +SUCH DAMAGE. + +-------------- + +Dhcp.h +Dhcp.cpp + +DHCP Library v0.3 - April 25, 2009 +Author: Jordan Terrell - blog.jordanterrell.com +- as included in Arduinos stock Ethernet-library, no special licence mentioned here + +-------------- + +Dns.h +Dns.cpp + +(c) Copyright 2009-2010 MCQN Ltd. +Released under Apache License, version 2.0 + +``` \ No newline at end of file diff --git a/Growatt ShineLAN-X/firmware/lib/EthernetENC/library.properties b/Growatt ShineLAN-X/firmware/lib/EthernetENC/library.properties new file mode 100644 index 0000000..eecd621 --- /dev/null +++ b/Growatt ShineLAN-X/firmware/lib/EthernetENC/library.properties @@ -0,0 +1,11 @@ +name=EthernetENC +author=Norbert Truchsess, Juraj Andrassy +maintainer=Juraj Andrassy +sentence=Ethernet library for ENC28J60. Only include EthernetENC.h instead of Ethernet.h +paragraph=This is a modern version of the UIPEthernet library. EthernetENC library is compatible with all Arduino architectures with Arduino SPI library with transactions support. +url=https://github.com/Networking-for-Arduino/EthernetENC/wiki +architectures=* +version=2.0.5 +category=Communication +includes=EthernetENC.h +dot_a_linkage=true diff --git a/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/Dhcp.cpp b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/Dhcp.cpp new file mode 100644 index 0000000..cfcd2f6 --- /dev/null +++ b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/Dhcp.cpp @@ -0,0 +1,491 @@ +// DHCP Library v0.3 - April 25, 2009 +// Author: Jordan Terrell - blog.jordanterrell.com + +#include "Dhcp.h" +#include +#include "utility/util.h" + +int DhcpClass::beginWithDHCP(uint8_t *mac, unsigned long timeout, unsigned long responseTimeout) +{ + _dhcpLeaseTime=0; + _dhcpT1=0; + _dhcpT2=0; + _lastCheck=0; + _timeout = timeout; + _responseTimeout = responseTimeout; + + // zero out _dhcpMacAddr + memset(_dhcpMacAddr, 0, 6); + reset_DHCP_lease(); + + memcpy((void*)_dhcpMacAddr, (void*)mac, 6); + _dhcp_state = STATE_DHCP_START; + return request_DHCP_lease(); +} + +void DhcpClass::reset_DHCP_lease(){ + memset(_dhcpLocalIp, 0, 4); + memset(_dhcpSubnetMask, 0, 4); + memset(_dhcpGatewayIp, 0, 4); + memset(_dhcpDhcpServerIp, 0, 4); + memset(_dhcpDnsServerIp, 0, 4); +} + +//return:0 on error, 1 if request is sent and response is received +int DhcpClass::request_DHCP_lease(){ + + uint8_t messageType = 0; + + + + // Pick an initial transaction ID + _dhcpTransactionId = random(1UL, 2000UL); + _dhcpInitialTransactionId = _dhcpTransactionId; + + _dhcpUdpSocket.stop(); + if (_dhcpUdpSocket.begin(DHCP_CLIENT_PORT) == 0) + { + // Couldn't get a socket + return 0; + } + + presend_DHCP(); + + int result = 0; + + unsigned long startTime = millis(); + + while(_dhcp_state != STATE_DHCP_LEASED) + { + if(_dhcp_state == STATE_DHCP_START) + { + _dhcpTransactionId++; + + send_DHCP_MESSAGE(DHCP_DISCOVER, ((millis() - startTime) / 1000)); + _dhcp_state = STATE_DHCP_DISCOVER; + } + else if(_dhcp_state == STATE_DHCP_REREQUEST){ + _dhcpTransactionId++; + send_DHCP_MESSAGE(DHCP_REQUEST, ((millis() - startTime)/1000)); + _dhcp_state = STATE_DHCP_REQUEST; + } + else if(_dhcp_state == STATE_DHCP_DISCOVER) + { + uint32_t respId; + messageType = parseDHCPResponse(_responseTimeout, respId); + if(messageType == DHCP_OFFER) + { + // We'll use the transaction ID that the offer came with, + // rather than the one we were up to + _dhcpTransactionId = respId; + send_DHCP_MESSAGE(DHCP_REQUEST, ((millis() - startTime) / 1000)); + _dhcp_state = STATE_DHCP_REQUEST; + } + } + else if(_dhcp_state == STATE_DHCP_REQUEST) + { + uint32_t respId; + messageType = parseDHCPResponse(_responseTimeout, respId); + if(messageType == DHCP_ACK) + { + _dhcp_state = STATE_DHCP_LEASED; + result = 1; + //use default lease time if we didn't get it + if(_dhcpLeaseTime == 0){ + _dhcpLeaseTime = DEFAULT_LEASE; + } + //calculate T1 & T2 if we didn't get it + if(_dhcpT1 == 0){ + //T1 should be 50% of _dhcpLeaseTime + _dhcpT1 = _dhcpLeaseTime >> 1; + } + if(_dhcpT2 == 0){ + //T2 should be 87.5% (7/8ths) of _dhcpLeaseTime + _dhcpT2 = _dhcpT1 << 1; + } + _renewInSec = _dhcpT1; + _rebindInSec = _dhcpT2; + } + else if(messageType == DHCP_NAK) + _dhcp_state = STATE_DHCP_START; + } + + if(messageType == 255) + { + messageType = 0; + _dhcp_state = STATE_DHCP_START; + } + + if(result != 1 && ((millis() - startTime) > _timeout)) + break; + } + + // We're done with the socket now + _dhcpUdpSocket.stop(); + _dhcpTransactionId++; + + return result; +} + +void DhcpClass::presend_DHCP() +{ +} + +void DhcpClass::send_DHCP_MESSAGE(uint8_t messageType, uint16_t secondsElapsed) +{ + uint8_t buffer[32]; + memset(buffer, 0, 32); + IPAddress dest_addr( 255, 255, 255, 255 ); // Broadcast address + + if (-1 == _dhcpUdpSocket.beginPacket(dest_addr, DHCP_SERVER_PORT)) + { + // FIXME Need to return errors + return; + } + + buffer[0] = DHCP_BOOTREQUEST; // op + buffer[1] = DHCP_HTYPE10MB; // htype + buffer[2] = DHCP_HLENETHERNET; // hlen + buffer[3] = DHCP_HOPS; // hops + + // xid + unsigned long xid = htonl(_dhcpTransactionId); + memcpy(buffer + 4, &(xid), 4); + + // 8, 9 - seconds elapsed + buffer[8] = ((secondsElapsed & 0xff00) >> 8); + buffer[9] = (secondsElapsed & 0x00ff); + + // flags - the only one flag DHCP uses is + // to request the server response as broadcast, not unicast +// unsigned short flags = htons(DHCP_FLAGSBROADCAST); +// memcpy(buffer + 10, &(flags), 2); + + // ciaddr: already zeroed + // yiaddr: already zeroed + // siaddr: already zeroed + // giaddr: already zeroed + + //put data in W5100 transmit buffer + _dhcpUdpSocket.write(buffer, 28); + + memset(buffer, 0, 32); // clear local buffer + + memcpy(buffer, _dhcpMacAddr, 6); // chaddr + + //put data in W5100 transmit buffer + _dhcpUdpSocket.write(buffer, 16); + + memset(buffer, 0, 32); // clear local buffer + + // leave zeroed out for sname && file + // put in W5100 transmit buffer x 6 (192 bytes) + + for(int i = 0; i < 6; i++) { + _dhcpUdpSocket.write(buffer, 32); + } + + // OPT - Magic Cookie + buffer[0] = (uint8_t)((MAGIC_COOKIE >> 24)& 0xFF); + buffer[1] = (uint8_t)((MAGIC_COOKIE >> 16)& 0xFF); + buffer[2] = (uint8_t)((MAGIC_COOKIE >> 8)& 0xFF); + buffer[3] = (uint8_t)(MAGIC_COOKIE& 0xFF); + + // OPT - message type + buffer[4] = dhcpMessageType; + buffer[5] = 0x01; + buffer[6] = messageType; //DHCP_REQUEST; + + // OPT - client identifier + buffer[7] = dhcpClientIdentifier; + buffer[8] = 0x07; + buffer[9] = 0x01; + memcpy(buffer + 10, _dhcpMacAddr, 6); + + // OPT - host name + buffer[16] = hostName; + if (_hostname == nullptr) { + buffer[17] = strlen(HOST_NAME) + 6; // length of hostname + last 3 bytes of mac address + strcpy((char*)&(buffer[18]), HOST_NAME); + + printByte((char*)&(buffer[24]), _dhcpMacAddr[3]); + printByte((char*)&(buffer[26]), _dhcpMacAddr[4]); + printByte((char*)&(buffer[28]), _dhcpMacAddr[5]); + + //put data in W5100 transmit buffer + _dhcpUdpSocket.write(buffer, 30); + } else { + uint8_t len = strlen(_hostname); + buffer[17] = len; + _dhcpUdpSocket.write(buffer, 18); + _dhcpUdpSocket.write(_hostname, len); + } + + if(messageType == DHCP_REQUEST) + { + buffer[0] = dhcpRequestedIPaddr; + buffer[1] = 0x04; + buffer[2] = _dhcpLocalIp[0]; + buffer[3] = _dhcpLocalIp[1]; + buffer[4] = _dhcpLocalIp[2]; + buffer[5] = _dhcpLocalIp[3]; + + buffer[6] = dhcpServerIdentifier; + buffer[7] = 0x04; + buffer[8] = _dhcpDhcpServerIp[0]; + buffer[9] = _dhcpDhcpServerIp[1]; + buffer[10] = _dhcpDhcpServerIp[2]; + buffer[11] = _dhcpDhcpServerIp[3]; + + //put data in W5100 transmit buffer + _dhcpUdpSocket.write(buffer, 12); + } + + buffer[0] = dhcpParamRequest; + buffer[1] = 0x06; + buffer[2] = subnetMask; + buffer[3] = routersOnSubnet; + buffer[4] = dns; + buffer[5] = domainName; + buffer[6] = dhcpT1value; + buffer[7] = dhcpT2value; + buffer[8] = endOption; + + //put data in W5100 transmit buffer + _dhcpUdpSocket.write(buffer, 9); + + _dhcpUdpSocket.endPacket(); +} + +uint8_t DhcpClass::parseDHCPResponse(unsigned long responseTimeout, uint32_t& transactionId) +{ + uint8_t type = 0; + uint8_t opt_len = 0; + + unsigned long startTime = millis(); + + while(_dhcpUdpSocket.parsePacket() <= 0) + { + if((millis() - startTime) > responseTimeout) + { + return 255; + } + delay(50); + } + // start reading in the packet + RIP_MSG_FIXED fixedMsg; + _dhcpUdpSocket.read((uint8_t*)&fixedMsg, sizeof(RIP_MSG_FIXED)); + + if(fixedMsg.op == DHCP_BOOTREPLY && _dhcpUdpSocket.remotePort() == DHCP_SERVER_PORT) + { + transactionId = ntohl(fixedMsg.xid); + if(memcmp(fixedMsg.chaddr, _dhcpMacAddr, 6) != 0 || (transactionId < _dhcpInitialTransactionId) || (transactionId > _dhcpTransactionId)) + { + // Need to read the rest of the packet here regardless + _dhcpUdpSocket.discardReceived(); + return 0; + } + + memcpy(_dhcpLocalIp, fixedMsg.yiaddr, 4); + + // Skip to the option part + // Doing this a byte at a time so we don't have to put a big buffer + // on the stack (as we don't have lots of memory lying around) + for (int i =0; i < (240 - (int)sizeof(RIP_MSG_FIXED)); i++) + { + _dhcpUdpSocket.read(); // we don't care about the returned byte + } + + while (_dhcpUdpSocket.available() > 0) + { + switch (_dhcpUdpSocket.read()) + { + case endOption : + break; + + case padOption : + break; + + case dhcpMessageType : + opt_len = _dhcpUdpSocket.read(); + type = _dhcpUdpSocket.read(); + break; + + case subnetMask : + opt_len = _dhcpUdpSocket.read(); + _dhcpUdpSocket.read(_dhcpSubnetMask, 4); + break; + + case routersOnSubnet : + opt_len = _dhcpUdpSocket.read(); + _dhcpUdpSocket.read(_dhcpGatewayIp, 4); + for (int i = 0; i < opt_len-4; i++) + { + _dhcpUdpSocket.read(); + } + break; + + case dns : + opt_len = _dhcpUdpSocket.read(); + _dhcpUdpSocket.read(_dhcpDnsServerIp, 4); + for (int i = 0; i < opt_len-4; i++) + { + _dhcpUdpSocket.read(); + } + break; + + case dhcpServerIdentifier : + opt_len = _dhcpUdpSocket.read(); + if( _dhcpDhcpServerIp[0] == 0 || + IPAddress(_dhcpDhcpServerIp) == _dhcpUdpSocket.remoteIP() ) + { + _dhcpUdpSocket.read(_dhcpDhcpServerIp, sizeof(_dhcpDhcpServerIp)); + } + else + { + // Skip over the rest of this option + while (opt_len--) + { + _dhcpUdpSocket.read(); + } + } + break; + + case dhcpT1value : + opt_len = _dhcpUdpSocket.read(); + _dhcpUdpSocket.read((uint8_t*)&_dhcpT1, sizeof(_dhcpT1)); + _dhcpT1 = ntohl(_dhcpT1); + break; + + case dhcpT2value : + opt_len = _dhcpUdpSocket.read(); + _dhcpUdpSocket.read((uint8_t*)&_dhcpT2, sizeof(_dhcpT2)); + _dhcpT2 = ntohl(_dhcpT2); + break; + + case dhcpIPaddrLeaseTime : + opt_len = _dhcpUdpSocket.read(); + _dhcpUdpSocket.read((uint8_t*)&_dhcpLeaseTime, sizeof(_dhcpLeaseTime)); + _dhcpLeaseTime = ntohl(_dhcpLeaseTime); + _renewInSec = _dhcpLeaseTime; + break; + + default : + opt_len = _dhcpUdpSocket.read(); + // Skip over the rest of this option + while (opt_len--) + { + _dhcpUdpSocket.read(); + } + break; + } + } + } + + // Need to skip to end of the packet regardless here + _dhcpUdpSocket.discardReceived(); + + return type; +} + + +/* + returns: + 0/DHCP_CHECK_NONE: nothing happened + 1/DHCP_CHECK_RENEW_FAIL: renew failed + 2/DHCP_CHECK_RENEW_OK: renew success + 3/DHCP_CHECK_REBIND_FAIL: rebind fail + 4/DHCP_CHECK_REBIND_OK: rebind success +*/ +int DhcpClass::checkLease(){ + //this uses a signed / unsigned trick to deal with millis overflow + unsigned long now = millis(); + signed long snow = (long)now; + int rc=DHCP_CHECK_NONE; + if (_lastCheck != 0){ + signed long factor; + //calc how many ms past the timeout we are + factor = snow - (long)_secTimeout; + //if on or passed the timeout, reduce the counters + if ( factor >= 0 ){ + //next timeout should be now plus 1000 ms minus parts of second in factor + _secTimeout = snow + 1000 - factor % 1000; + //how many seconds late are we, minimum 1 + factor = factor / 1000 +1; + + //reduce the counters by that mouch + //if we can assume that the cycle time (factor) is fairly constant + //and if the remainder is less than cycle time * 2 + //do it early instead of late + if(_renewInSec < factor*2 ) + _renewInSec = 0; + else + _renewInSec -= factor; + + if(_rebindInSec < factor*2 ) + _rebindInSec = 0; + else + _rebindInSec -= factor; + } + + //if we have a lease but should renew, do it + if (_dhcp_state == STATE_DHCP_LEASED && _renewInSec <=0){ + _dhcp_state = STATE_DHCP_REREQUEST; + rc = 1 + request_DHCP_lease(); + } + + //if we have a lease or is renewing but should bind, do it + if( (_dhcp_state == STATE_DHCP_LEASED || _dhcp_state == STATE_DHCP_START) && _rebindInSec <=0){ + //this should basically restart completely + _dhcp_state = STATE_DHCP_START; + reset_DHCP_lease(); + rc = 3 + request_DHCP_lease(); + } + } + else{ + _secTimeout = snow + 1000; + } + + _lastCheck = now; + return rc; +} + +IPAddress DhcpClass::getLocalIp() +{ + return IPAddress(_dhcpLocalIp); +} + +IPAddress DhcpClass::getSubnetMask() +{ + return IPAddress(_dhcpSubnetMask); +} + +IPAddress DhcpClass::getGatewayIp() +{ + return IPAddress(_dhcpGatewayIp); +} + +IPAddress DhcpClass::getDhcpServerIp() +{ + return IPAddress(_dhcpDhcpServerIp); +} + +IPAddress DhcpClass::getDnsServerIp() +{ + return IPAddress(_dhcpDnsServerIp); +} + +void DhcpClass::setHostname(const char* hostname) { + _hostname = hostname; +} + +void DhcpClass::printByte(char * buf, uint8_t n ) { + char *str = &buf[1]; + buf[0]='0'; + do { + unsigned long m = n; + n /= 16; + char c = m - 16 * n; + *str-- = c < 10 ? c + '0' : c + 'A' - 10; + } while(n); +} diff --git a/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/Dhcp.h b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/Dhcp.h new file mode 100644 index 0000000..ec99072 --- /dev/null +++ b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/Dhcp.h @@ -0,0 +1,189 @@ +// DHCP Library v0.3 - April 25, 2009 +// Author: Jordan Terrell - blog.jordanterrell.com + +#ifndef Dhcp_h +#define Dhcp_h + +#include "EthernetUdp.h" + +/* DHCP state machine. */ +#define STATE_DHCP_START 0 +#define STATE_DHCP_DISCOVER 1 +#define STATE_DHCP_REQUEST 2 +#define STATE_DHCP_LEASED 3 +#define STATE_DHCP_REREQUEST 4 +#define STATE_DHCP_RELEASE 5 + +#define DHCP_FLAGSBROADCAST 0x8000 + +/* UDP port numbers for DHCP */ +#define DHCP_SERVER_PORT 67 /* from server to client */ +#define DHCP_CLIENT_PORT 68 /* from client to server */ + +/* DHCP message OP code */ +#define DHCP_BOOTREQUEST 1 +#define DHCP_BOOTREPLY 2 + +/* DHCP message type */ +#define DHCP_DISCOVER 1 +#define DHCP_OFFER 2 +#define DHCP_REQUEST 3 +#define DHCP_DECLINE 4 +#define DHCP_ACK 5 +#define DHCP_NAK 6 +#define DHCP_RELEASE 7 +#define DHCP_INFORM 8 + +#define DHCP_HTYPE10MB 1 +#define DHCP_HTYPE100MB 2 + +#define DHCP_HLENETHERNET 6 +#define DHCP_HOPS 0 +#define DHCP_SECS 0 + +#define MAGIC_COOKIE 0x63825363 +#define MAX_DHCP_OPT 16 + +#define HOST_NAME "ENC28J" +#define DEFAULT_LEASE (900) //default lease time in seconds + +#define DHCP_CHECK_NONE (0) +#define DHCP_CHECK_RENEW_FAIL (1) +#define DHCP_CHECK_RENEW_OK (2) +#define DHCP_CHECK_REBIND_FAIL (3) +#define DHCP_CHECK_REBIND_OK (4) + +enum +{ + padOption = 0, + subnetMask = 1, + timerOffset = 2, + routersOnSubnet = 3, + /* timeServer = 4, + nameServer = 5,*/ + dns = 6, + /*logServer = 7, + cookieServer = 8, + lprServer = 9, + impressServer = 10, + resourceLocationServer = 11,*/ + hostName = 12, + /*bootFileSize = 13, + meritDumpFile = 14,*/ + domainName = 15, + /*swapServer = 16, + rootPath = 17, + extentionsPath = 18, + IPforwarding = 19, + nonLocalSourceRouting = 20, + policyFilter = 21, + maxDgramReasmSize = 22, + defaultIPTTL = 23, + pathMTUagingTimeout = 24, + pathMTUplateauTable = 25, + ifMTU = 26, + allSubnetsLocal = 27, + broadcastAddr = 28, + performMaskDiscovery = 29, + maskSupplier = 30, + performRouterDiscovery = 31, + routerSolicitationAddr = 32, + staticRoute = 33, + trailerEncapsulation = 34, + arpCacheTimeout = 35, + ethernetEncapsulation = 36, + tcpDefaultTTL = 37, + tcpKeepaliveInterval = 38, + tcpKeepaliveGarbage = 39, + nisDomainName = 40, + nisServers = 41, + ntpServers = 42, + vendorSpecificInfo = 43, + netBIOSnameServer = 44, + netBIOSdgramDistServer = 45, + netBIOSnodeType = 46, + netBIOSscope = 47, + xFontServer = 48, + xDisplayManager = 49,*/ + dhcpRequestedIPaddr = 50, + dhcpIPaddrLeaseTime = 51, + /*dhcpOptionOverload = 52,*/ + dhcpMessageType = 53, + dhcpServerIdentifier = 54, + dhcpParamRequest = 55, + /*dhcpMsg = 56, + dhcpMaxMsgSize = 57,*/ + dhcpT1value = 58, + dhcpT2value = 59, + /*dhcpClassIdentifier = 60,*/ + dhcpClientIdentifier = 61, + endOption = 255 +}; + +typedef struct _RIP_MSG_FIXED +{ + uint8_t op; + uint8_t htype; + uint8_t hlen; + uint8_t hops; + uint32_t xid; + uint16_t secs; + uint16_t flags; + uint8_t ciaddr[4]; + uint8_t yiaddr[4]; + uint8_t siaddr[4]; + uint8_t giaddr[4]; + uint8_t chaddr[6]; +}RIP_MSG_FIXED; + +class DhcpClass { +private: + uint32_t _dhcpInitialTransactionId; + uint32_t _dhcpTransactionId; + uint8_t _dhcpMacAddr[6]; + const char* _hostname = nullptr; +#ifdef __arm__ + uint8_t _dhcpLocalIp[4] __attribute__((aligned(4))); + uint8_t _dhcpSubnetMask[4] __attribute__((aligned(4))); + uint8_t _dhcpGatewayIp[4] __attribute__((aligned(4))); + uint8_t _dhcpDhcpServerIp[4] __attribute__((aligned(4))); + uint8_t _dhcpDnsServerIp[4] __attribute__((aligned(4))); +#else + uint8_t _dhcpLocalIp[4]; + uint8_t _dhcpSubnetMask[4]; + uint8_t _dhcpGatewayIp[4]; + uint8_t _dhcpDhcpServerIp[4]; + uint8_t _dhcpDnsServerIp[4]; +#endif + uint32_t _dhcpLeaseTime; + uint32_t _dhcpT1, _dhcpT2; + signed long _renewInSec; + signed long _rebindInSec; + signed long _lastCheck; + unsigned long _timeout; + unsigned long _responseTimeout; + unsigned long _secTimeout; + uint8_t _dhcp_state; + EthernetUDP _dhcpUdpSocket; + + int request_DHCP_lease(); + void reset_DHCP_lease(); + void presend_DHCP(); + void send_DHCP_MESSAGE(uint8_t, uint16_t); + void printByte(char *, uint8_t); + + uint8_t parseDHCPResponse(unsigned long responseTimeout, uint32_t& transactionId); +public: + IPAddress getLocalIp(); + IPAddress getSubnetMask(); + IPAddress getGatewayIp(); + IPAddress getDhcpServerIp(); + IPAddress getDnsServerIp(); + + int beginWithDHCP(uint8_t *, unsigned long timeout = 60000, unsigned long responseTimeout = 4000); + int checkLease(); + + void setHostname(const char* hostname); +}; + +#endif diff --git a/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/Dns.cpp b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/Dns.cpp new file mode 100644 index 0000000..4d82236 --- /dev/null +++ b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/Dns.cpp @@ -0,0 +1,416 @@ +// Arduino DNS client for Enc28J60-based Ethernet shield +// (c) Copyright 2009-2010 MCQN Ltd. +// Released under Apache License, version 2.0 + +#include "Dns.h" +#include + +#define SOCKET_NONE 255 +// Various flags and header field values for a DNS message +#define UDP_HEADER_SIZE 8 +#define DNS_HEADER_SIZE 12 +#define TTL_SIZE 4 +#define QUERY_FLAG (0) +#define RESPONSE_FLAG (1<<15) +#define QUERY_RESPONSE_MASK (1<<15) +#define OPCODE_STANDARD_QUERY (0) +#define OPCODE_INVERSE_QUERY (1<<11) +#define OPCODE_STATUS_REQUEST (2<<11) +#define OPCODE_MASK (15<<11) +#define AUTHORITATIVE_FLAG (1<<10) +#define TRUNCATION_FLAG (1<<9) +#define RECURSION_DESIRED_FLAG (1<<8) +#define RECURSION_AVAILABLE_FLAG (1<<7) +#define RESP_NO_ERROR (0) +#define RESP_FORMAT_ERROR (1) +#define RESP_SERVER_FAILURE (2) +#define RESP_NAME_ERROR (3) +#define RESP_NOT_IMPLEMENTED (4) +#define RESP_REFUSED (5) +#define RESP_MASK (15) +#define TYPE_A (0x0001) +#define CLASS_IN (0x0001) +#define LABEL_COMPRESSION_MASK (0xC0) +// Port number that DNS servers listen on +#define DNS_PORT 53 + +// Possible return codes from ProcessResponse +#define SUCCESS 1 +#define TIMED_OUT -1 +#define INVALID_SERVER -2 +#define TRUNCATED -3 +#define INVALID_RESPONSE -4 + +void DNSClient::begin(const IPAddress& aDNSServer) +{ + iDNSServer = aDNSServer; + iRequestId = 0; +} + + +int DNSClient::inet_aton(const char* aIPAddrString, IPAddress& aResult) +{ + // See if we've been given a valid IP address + const char* p =aIPAddrString; + while (*p && + ( (*p == '.') || ((*p >= '0') && (*p <= '9')) )) + { + p++; + } + + if (*p == '\0') + { + // It's looking promising, we haven't found any invalid characters + p = aIPAddrString; + int segment =0; + int segmentValue =0; + while (*p && (segment < 4)) + { + if (*p == '.') + { + // We've reached the end of a segment + if (segmentValue > 255) + { + // You can't have IP address segments that don't fit in a byte + return 0; + } + else + { + aResult[segment] = (byte)segmentValue; + segment++; + segmentValue = 0; + } + } + else + { + // Next digit + segmentValue = (segmentValue*10)+(*p - '0'); + } + p++; + } + // We've reached the end of address, but there'll still be the last + // segment to deal with + if ((segmentValue > 255) || (segment > 3)) + { + // You can't have IP address segments that don't fit in a byte, + // or more than four segments + return 0; + } + else + { + aResult[segment] = (byte)segmentValue; + return 1; + } + } + else + { + return 0; + } +} + +int DNSClient::getHostByName(const char* aHostname, IPAddress& aResult) +{ + int ret =0; + + // See if it's a numeric IP address + if (inet_aton(aHostname, aResult)) + { + // It is, our work here is done + return 1; + } + + // Check we've got a valid DNS server to use + if (iDNSServer == INADDR_NONE) + { + return INVALID_SERVER; + } + + // Find a socket to use + if (iUdp.begin(1024+(millis() & 0xF)) == 1) + { + // Try up to three times + int retries = 0; +// while ((retries < 3) && (ret <= 0)) + { + // Send DNS request + ret = iUdp.beginPacket(iDNSServer, DNS_PORT); + if (ret != 0) + { + // Now output the request data + ret = BuildRequest(aHostname); + if (ret != 0) + { + // And finally send the request + ret = iUdp.endPacket(); + if (ret != 0) + { + // Now wait for a response + int wait_retries = 0; + ret = TIMED_OUT; + while ((wait_retries < 3) && (ret == TIMED_OUT)) + { + ret = ProcessResponse(5000, aResult); + wait_retries++; + } + } + } + } + retries++; + } + + // We're done with the socket now + iUdp.stop(); + } + + return ret; +} + +uint16_t DNSClient::BuildRequest(const char* aName) +{ + // Build header + // 1 1 1 1 1 1 + // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 + // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + // | ID | + // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + // |QR| Opcode |AA|TC|RD|RA| Z | RCODE | + // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + // | QDCOUNT | + // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + // | ANCOUNT | + // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + // | NSCOUNT | + // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + // | ARCOUNT | + // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + // As we only support one request at a time at present, we can simplify + // some of this header + iRequestId = millis(); // generate a random ID + uint16_t twoByteBuffer; + + // FIXME We should also check that there's enough space available to write to, rather + // FIXME than assume there's enough space (as the code does at present) + iUdp.write((uint8_t*)&iRequestId, sizeof(iRequestId)); + + twoByteBuffer = htons(QUERY_FLAG | OPCODE_STANDARD_QUERY | RECURSION_DESIRED_FLAG); + iUdp.write((uint8_t*)&twoByteBuffer, sizeof(twoByteBuffer)); + + twoByteBuffer = htons(1); // One question record + iUdp.write((uint8_t*)&twoByteBuffer, sizeof(twoByteBuffer)); + + twoByteBuffer = 0; // Zero answer records + iUdp.write((uint8_t*)&twoByteBuffer, sizeof(twoByteBuffer)); + + iUdp.write((uint8_t*)&twoByteBuffer, sizeof(twoByteBuffer)); + // and zero additional records + iUdp.write((uint8_t*)&twoByteBuffer, sizeof(twoByteBuffer)); + + // Build question + const char* start =aName; + const char* end =start; + uint8_t len; + // Run through the name being requested + while (*end) + { + // Find out how long this section of the name is + end = start; + while (*end && (*end != '.') ) + { + end++; + } + + if (end-start > 0) + { + // Write out the size of this section + len = end-start; + iUdp.write(&len, sizeof(len)); + // And then write out the section + iUdp.write((uint8_t*)start, end-start); + } + start = end+1; + } + + // We've got to the end of the question name, so + // terminate it with a zero-length section + len = 0; + iUdp.write(&len, sizeof(len)); + // Finally the type and class of question + twoByteBuffer = htons(TYPE_A); + iUdp.write((uint8_t*)&twoByteBuffer, sizeof(twoByteBuffer)); + + twoByteBuffer = htons(CLASS_IN); // Internet class of question + iUdp.write((uint8_t*)&twoByteBuffer, sizeof(twoByteBuffer)); + // Success! Everything buffered okay + return 1; +} + + +uint16_t DNSClient::ProcessResponse(uint16_t aTimeout, IPAddress& aAddress) +{ + uint32_t startTime = millis(); + + // Wait for a response packet + while(iUdp.parsePacket() <= 0) + { + if((millis() - startTime) > aTimeout) + return TIMED_OUT; + delay(50); + } + + // We've had a reply! + // Read the UDP header + uint8_t header[DNS_HEADER_SIZE]; // Enough space to reuse for the DNS header + // Check that it's a response from the right server and the right port + if ( (iDNSServer != iUdp.remoteIP()) || + (iUdp.remotePort() != DNS_PORT) ) + { + // It's not from who we expected + return INVALID_SERVER; + } + + // Read through the rest of the response + if (iUdp.available() < DNS_HEADER_SIZE) + { + return TRUNCATED; + } + iUdp.read(header, DNS_HEADER_SIZE); + + uint16_t header_flags = htons(*((uint16_t*)&header[2])); + // Check that it's a response to this request + if ( ( iRequestId != (*((uint16_t*)&header[0])) ) || + ((header_flags & QUERY_RESPONSE_MASK) != (uint16_t)RESPONSE_FLAG) ) + { + // Mark the entire packet as read + iUdp.discardReceived(); + return INVALID_RESPONSE; + } + // Check for any errors in the response (or in our request) + // although we don't do anything to get round these + if ( (header_flags & TRUNCATION_FLAG) || (header_flags & RESP_MASK) ) + { + // Mark the entire packet as read + iUdp.discardReceived(); + return -5; //INVALID_RESPONSE; + } + + // And make sure we've got (at least) one answer + uint16_t answerCount = htons(*((uint16_t*)&header[6])); + if (answerCount == 0 ) + { + // Mark the entire packet as read + iUdp.discardReceived(); + return -6; //INVALID_RESPONSE; + } + + // Skip over any questions + for (uint16_t i =0; i < htons(*((uint16_t*)&header[4])); i++) + { + // Skip over the name + uint8_t len; + do + { + iUdp.read(&len, sizeof(len)); + if (len > 0) + { + // Don't need to actually read the data out for the string, just + // advance ptr to beyond it + while(len--) + { + iUdp.read(); // we don't care about the returned byte + } + } + } while (len != 0); + + // Now jump over the type and class + for (int i =0; i < 4; i++) + { + iUdp.read(); // we don't care about the returned byte + } + } + + // Now we're up to the bit we're interested in, the answer + // There might be more than one answer (although we'll just use the first + // type A answer) and some authority and additional resource records but + // we're going to ignore all of them. + + for (uint16_t i =0; i < answerCount; i++) + { + // Skip the name + uint8_t len; + do + { + iUdp.read(&len, sizeof(len)); + if ((len & LABEL_COMPRESSION_MASK) == 0) + { + // It's just a normal label + if (len > 0) + { + // And it's got a length + // Don't need to actually read the data out for the string, + // just advance ptr to beyond it + while(len--) + { + iUdp.read(); // we don't care about the returned byte + } + } + } + else + { + // This is a pointer to a somewhere else in the message for the + // rest of the name. We don't care about the name, and RFC1035 + // says that a name is either a sequence of labels ended with a + // 0 length octet or a pointer or a sequence of labels ending in + // a pointer. Either way, when we get here we're at the end of + // the name + // Skip over the pointer + iUdp.read(); // we don't care about the returned byte + // And set len so that we drop out of the name loop + len = 0; + } + } while (len != 0); + + // Check the type and class + uint16_t answerType; + uint16_t answerClass; + iUdp.read((uint8_t*)&answerType, sizeof(answerType)); + iUdp.read((uint8_t*)&answerClass, sizeof(answerClass)); + + // Ignore the Time-To-Live as we don't do any caching + for (int i =0; i < TTL_SIZE; i++) + { + iUdp.read(); // we don't care about the returned byte + } + + // And read out the length of this answer + // Don't need header_flags anymore, so we can reuse it here + iUdp.read((uint8_t*)&header_flags, sizeof(header_flags)); + + if ( (htons(answerType) == TYPE_A) && (htons(answerClass) == CLASS_IN) ) + { + if (htons(header_flags) != 4) + { + // It's a weird size + // Mark the entire packet as read + iUdp.discardReceived(); + return -9;//INVALID_RESPONSE; + } + iUdp.read(aAddress.raw_address(), 4); + return SUCCESS; + } + else + { + // This isn't an answer type we're after, move onto the next one + for (uint16_t i =0; i < htons(header_flags); i++) + { + iUdp.read(); // we don't care about the returned byte + } + } + } + + // Mark the entire packet as read + iUdp.discardReceived(); + + // If we get here then we haven't found an answer + return -10;//INVALID_RESPONSE; +} + diff --git a/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/Dns.h b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/Dns.h new file mode 100644 index 0000000..81abc17 --- /dev/null +++ b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/Dns.h @@ -0,0 +1,41 @@ +// Arduino DNS client for Enc28J60-based Ethernet shield +// (c) Copyright 2009-2010 MCQN Ltd. +// Released under Apache License, version 2.0 + +#ifndef DNSClient_h +#define DNSClient_h + +#include "EthernetUdp.h" + +class DNSClient +{ +public: + // ctor + void begin(const IPAddress& aDNSServer); + + /** Convert a numeric IP address string into a four-byte IP address. + @param aIPAddrString IP address to convert + @param aResult IPAddress structure to store the returned IP address + @result 1 if aIPAddrString was successfully converted to an IP address, + else error code + */ + int inet_aton(const char *aIPAddrString, IPAddress& aResult); + + /** Resolve the given hostname to an IP address. + @param aHostname Name to be resolved + @param aResult IPAddress structure to store the returned IP address + @result 1 if aIPAddrString was successfully converted to an IP address, + else error code + */ + int getHostByName(const char* aHostname, IPAddress& aResult); + +protected: + uint16_t BuildRequest(const char* aName); + uint16_t ProcessResponse(uint16_t aTimeout, IPAddress& aAddress); + + IPAddress iDNSServer; + uint16_t iRequestId; + EthernetUDP iUdp; +}; + +#endif diff --git a/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/Ethernet.cpp b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/Ethernet.cpp new file mode 100644 index 0000000..df1c77f --- /dev/null +++ b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/Ethernet.cpp @@ -0,0 +1,559 @@ +/* + UIPEthernet.cpp - Arduino implementation of a uIP wrapper class. + Copyright (c) 2013 Norbert Truchsess + All rights reserved. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +#include +#include "Ethernet.h" +#include "Dns.h" +#include "utility/Enc28J60Network.h" + +extern "C" +{ +#include "utility/uip-conf.h" +#include "utility/uip.h" +#include "utility/uip_arp.h" +} + +#define ETH_HDR ((struct uip_eth_hdr *)&uip_buf[0]) + +bool UIPEthernetClass::initialized = false; +memhandle UIPEthernetClass::in_packet(NOBLOCK); +memhandle UIPEthernetClass::uip_packet(NOBLOCK); +uint8_t UIPEthernetClass::uip_hdrlen(0); +uint8_t UIPEthernetClass::packetstate(0); + +IPAddress UIPEthernetClass::_dnsServerAddress; +DhcpClass* UIPEthernetClass::_dhcp(NULL); + +unsigned long UIPEthernetClass::periodic_timer; +unsigned long UIPEthernetClass::arp_timer; + +// Because uIP isn't encapsulated within a class we have to use global +// variables, so we can only have one TCP/IP stack per program. + +UIPEthernetClass::UIPEthernetClass() +{ +} + +void UIPEthernetClass::init(uint8_t csPin) +{ + Enc28J60Network::setCsPin(csPin); +} + +#if UIP_UDP +void +UIPEthernetClass::setHostname(const char* hostname) +{ + if (_dhcp == NULL) { + _dhcp = new DhcpClass(); + } + _dhcp->setHostname(hostname); +} + +int +UIPEthernetClass::begin(const uint8_t* mac, unsigned long timeout, unsigned long responseTimeout) +{ + if (_dhcp == NULL) { + _dhcp = new DhcpClass(); + } + + // Initialise the basic info + init(mac); + + // Now try to get our config info from a DHCP server + int ret = _dhcp->beginWithDHCP((uint8_t*)mac, timeout, responseTimeout); + if(ret == 1) + { + // We've successfully found a DHCP server and got our configuration info, so set things + // accordingly + configure(_dhcp->getLocalIp(),_dhcp->getDnsServerIp(),_dhcp->getGatewayIp(),_dhcp->getSubnetMask()); + } + return ret; +} +#endif + +void +UIPEthernetClass::begin(const uint8_t* mac, IPAddress ip) +{ + IPAddress dns = ip; + dns[3] = 1; + begin(mac, ip, dns); +} + +void +UIPEthernetClass::begin(const uint8_t* mac, IPAddress ip, IPAddress dns) +{ + IPAddress gateway = ip; + gateway[3] = 1; + begin(mac, ip, dns, gateway); +} + +void +UIPEthernetClass::begin(const uint8_t* mac, IPAddress ip, IPAddress dns, IPAddress gateway) +{ + IPAddress subnet(255, 255, 255, 0); + begin(mac, ip, dns, gateway, subnet); +} + +void +UIPEthernetClass::begin(const uint8_t* mac, IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress subnet) +{ + init(mac); + configure(ip,dns,gateway,subnet); +} + +void UIPEthernetClass::end() +{ + //close all clients + for (int i = 0; i < UIP_CONNS; i++) + { + if (EthernetClient::all_data[i].state) { + EthernetClient client(&EthernetClient::all_data[i]); + client.stop(); + } + } + // handle clients closings + uint32_t st = millis(); + while (millis() - st < 3000) + { + tick(); + } + initialized = false; + configure(INADDR_NONE, INADDR_NONE, INADDR_NONE, INADDR_NONE); +} + +int UIPEthernetClass::maintain(){ + if (!initialized) + return 0; + tick(); + int rc = DHCP_CHECK_NONE; +#if UIP_UDP + if(_dhcp != NULL){ + //we have a pointer to dhcp, use it + rc = _dhcp->checkLease(); + switch ( rc ){ + case DHCP_CHECK_NONE: + //nothing done + break; + case DHCP_CHECK_RENEW_OK: + case DHCP_CHECK_REBIND_OK: + //we might have got a new IP. + configure(_dhcp->getLocalIp(),_dhcp->getDnsServerIp(),_dhcp->getGatewayIp(),_dhcp->getSubnetMask()); + break; + default: + //this is actually a error, it will retry though + break; + } + } +#endif + return rc; +} + +EthernetLinkStatus UIPEthernetClass::linkStatus() +{ + if (!Enc28J60Network::getrev()) + return Unknown; + return Enc28J60Network::linkStatus() ? LinkON : LinkOFF; +} + +EthernetHardwareStatus UIPEthernetClass::hardwareStatus() +{ + if (!Enc28J60Network::getrev()) + return EthernetNoHardware; + return EthernetENC28J60; +} + +uint8_t* UIPEthernetClass::macAddress(uint8_t* mac) +{ + memcpy(mac, uip_ethaddr.addr, 6); + return mac; +} + +IPAddress UIPEthernetClass::localIP() +{ + IPAddress ret; + uip_ipaddr_t a; + uip_gethostaddr(a); + return ip_addr_uip(a); +} + +IPAddress UIPEthernetClass::subnetMask() +{ + IPAddress ret; + uip_ipaddr_t a; + uip_getnetmask(a); + return ip_addr_uip(a); +} + +IPAddress UIPEthernetClass::gatewayIP() +{ + IPAddress ret; + uip_ipaddr_t a; + uip_getdraddr(a); + return ip_addr_uip(a); +} + +IPAddress UIPEthernetClass::dnsServerIP() +{ + return _dnsServerAddress; +} + +IPAddress UIPEthernetClass::dnsIP(int n) { + return (n == 0) ? _dnsServerAddress : IPAddress(); +} + +int UIPEthernetClass::hostByName(const char* hostname, IPAddress& result) +{ + // Look up the host first + int ret = 0; +#if UIP_UDP + DNSClient dns; + dns.begin(_dnsServerAddress); + ret = dns.getHostByName(hostname, result); +#endif + return ret; +} + +void +UIPEthernetClass::tick() +{ + if (!initialized) + return; + + // run ARP table cleanup every 10 seconds as required by a comment in uip_arp.h + if (millis() - arp_timer > 10000) { + arp_timer = millis(); + uip_arp_timer(); + } + + if (in_packet == NOBLOCK) + { + in_packet = Enc28J60Network::receivePacket(); +#ifdef UIPETHERNET_DEBUG + if (in_packet != NOBLOCK) + { + Serial.println(F("--------------\npacket received")); + } +#endif + } + if (in_packet != NOBLOCK) + { + packetstate = UIPETHERNET_FREEPACKET; + uip_len = Enc28J60Network::blockSize(in_packet); + if (uip_len > 0) + { + Enc28J60Network::readPacket(in_packet,0,(uint8_t*)uip_buf,UIP_BUFSIZE); + if (ETH_HDR ->type == HTONS(UIP_ETHTYPE_IP)) + { + uip_packet = in_packet; //required for upper_layer_checksum of in_packet! +#ifdef UIPETHERNET_DEBUG + Serial.print(F("readPacket type IP, uip_len: ")); + Serial.print(uip_len); + Serial.print(F(", bits: ")); + Serial.println(BUF->flags, BIN); +#endif + uip_arp_ipin(); + uip_input(); + if (uip_len > 0) + { + uip_arp_out(); + network_send(); + } + } + else if (ETH_HDR ->type == HTONS(UIP_ETHTYPE_ARP)) + { +#ifdef UIPETHERNET_DEBUG + Serial.print(F("readPacket type ARP, uip_len: ")); + Serial.println(uip_len); +#endif + uip_arp_arpin(); + if (uip_len > 0) + { + network_send(); + } + } + } + if (in_packet != NOBLOCK && (packetstate & UIPETHERNET_FREEPACKET)) + { +#ifdef UIPETHERNET_DEBUG + Serial.println(F("freeing received packet")); +#endif + Enc28J60Network::freePacket(); + in_packet = NOBLOCK; + } + } + + unsigned long now = millis(); + + if ((long)( now - periodic_timer ) >= 0) + { + periodic_timer = now + UIP_PERIODIC_TIMER; + + for (int i = 0; i < UIP_CONNS; i++) + { + uip_periodic(i); + // If the above function invocation resulted in data that + // should be sent out on the Enc28J60Network, the global variable + // uip_len is set to a value > 0. + if (uip_len > 0) + { + uip_arp_out(); + network_send(); + } + } +#if UIP_UDP + for (int i = 0; i < UIP_UDP_CONNS; i++) + { + uip_udp_periodic(i); + // If the above function invocation resulted in data that + // should be sent out on the Enc28J60Network, the global variable + // uip_len is set to a value > 0. */ + if (uip_len > 0) + { + EthernetUDP::_send(&uip_udp_conns[i]); + } + } +#endif /* UIP_UDP */ + } +} + +boolean UIPEthernetClass::network_send() +{ + if (packetstate & UIPETHERNET_SENDPACKET) + { +#ifdef UIPETHERNET_DEBUG + Serial.print(F("Enc28J60Network_send uip_packet: ")); + Serial.print(uip_packet); + Serial.print(F(", hdrlen: ")); + Serial.println(uip_hdrlen); +#endif + Enc28J60Network::writePacket(uip_packet, UIP_SENDBUFFER_OFFSET,uip_buf,uip_hdrlen); + packetstate &= ~ UIPETHERNET_SENDPACKET; + goto sendandfree; + } + uip_packet = Enc28J60Network::allocBlock(uip_len + UIP_SENDBUFFER_OFFSET + UIP_SENDBUFFER_PADDING); + if (uip_packet != NOBLOCK) + { +#ifdef UIPETHERNET_DEBUG + Serial.print(F("Enc28J60Network_send uip_buf (uip_len): ")); + Serial.print(uip_len); + Serial.print(F(", packet: ")); + Serial.print(uip_packet); + Serial.print(F(", bits: ")); + Serial.println(BUF->flags, BIN); +#endif + Enc28J60Network::writePacket(uip_packet, UIP_SENDBUFFER_OFFSET,uip_buf,uip_len); + goto sendandfree; + } + return false; +sendandfree: + bool success = Enc28J60Network::sendPacket(uip_packet); + Enc28J60Network::freeBlock(uip_packet); + uip_packet = NOBLOCK; + return success; +} + +void UIPEthernetClass::init(const uint8_t* mac) { + periodic_timer = millis() + UIP_PERIODIC_TIMER; + + initialized = Enc28J60Network::init((uint8_t*)mac); + uip_seteth_addr(mac); + + uip_init(); + uip_arp_init(); +} + +void UIPEthernetClass::configure(IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress subnet) { + uip_ipaddr_t ipaddr; + + uip_ip_addr(ipaddr, ip); + uip_sethostaddr(ipaddr); + + uip_ip_addr(ipaddr, gateway); + uip_setdraddr(ipaddr); + + uip_ip_addr(ipaddr, subnet); + uip_setnetmask(ipaddr); + + _dnsServerAddress = dns; +} + +void +UIPEthernetClass::call_yield() +{ + static bool in_yield; + static uint32_t last_call_millis; + if (!in_yield && millis() - last_call_millis > 0) + { + last_call_millis = millis(); + in_yield = true; + yield(); + in_yield = false; + } +} + +/*---------------------------------------------------------------------------*/ +uint16_t +UIPEthernetClass::chksum(uint16_t sum, const uint8_t *data, uint16_t len) +{ + uint16_t t; + const uint8_t *dataptr; + const uint8_t *last_byte; + + dataptr = data; + last_byte = data + len - 1; + + while(dataptr < last_byte) { /* At least two more bytes */ + t = (dataptr[0] << 8) + dataptr[1]; + sum += t; + if(sum < t) { + sum++; /* carry */ + } + dataptr += 2; + } + + if(dataptr == last_byte) { + t = (dataptr[0] << 8) + 0; + sum += t; + if(sum < t) { + sum++; /* carry */ + } + } + + /* Return sum in host byte order. */ + return sum; +} + +/*---------------------------------------------------------------------------*/ + +uint16_t +UIPEthernetClass::ipchksum(void) +{ + uint16_t sum; + + sum = chksum(0, &uip_buf[UIP_LLH_LEN], UIP_IPH_LEN); + return (sum == 0) ? 0xffff : htons(sum); +} + +/*---------------------------------------------------------------------------*/ +uint16_t +#if UIP_UDP +UIPEthernetClass::upper_layer_chksum(uint8_t proto) +#else +uip_tcpchksum(void) +#endif +{ + uint16_t upper_layer_len; + uint16_t sum; + +#if UIP_CONF_IPV6 + upper_layer_len = (((u16_t)(BUF->len[0]) << 8) + BUF->len[1]); +#else /* UIP_CONF_IPV6 */ + upper_layer_len = (((u16_t)(BUF->len[0]) << 8) + BUF->len[1]) - UIP_IPH_LEN; +#endif /* UIP_CONF_IPV6 */ + + /* First sum pseudoheader. */ + + /* IP protocol and length fields. This addition cannot carry. */ +#if UIP_UDP + sum = upper_layer_len + proto; +#else + sum = upper_layer_len + UIP_PROTO_TCP; +#endif + /* Sum IP source and destination addresses. */ + sum = UIPEthernetClass::chksum(sum, (u8_t *)&BUF->srcipaddr[0], 2 * sizeof(uip_ipaddr_t)); + + uint8_t upper_layer_memlen; +#if UIP_UDP + switch(proto) + { +// case UIP_PROTO_ICMP: +// case UIP_PROTO_ICMP6: +// upper_layer_memlen = upper_layer_len; +// break; + case UIP_PROTO_UDP: + upper_layer_memlen = UIP_UDPH_LEN; + break; + default: +// case UIP_PROTO_TCP: +#endif + upper_layer_memlen = (BUF->tcpoffset >> 4) << 2; +#if UIP_UDP + break; + } +#endif + sum = UIPEthernetClass::chksum(sum, &uip_buf[UIP_IPH_LEN + UIP_LLH_LEN], upper_layer_memlen); +#ifdef UIPETHERNET_DEBUG_CHKSUM + Serial.print(F("chksum uip_buf[")); + Serial.print(UIP_IPH_LEN + UIP_LLH_LEN); + Serial.print(F("-")); + Serial.print(UIP_IPH_LEN + UIP_LLH_LEN + upper_layer_memlen); + Serial.print(F("]: ")); + Serial.println(htons(sum),HEX); +#endif + if (upper_layer_memlen < upper_layer_len) + { + sum = Enc28J60Network::chksum( + sum, + UIPEthernetClass::uip_packet, + (UIPEthernetClass::packetstate & UIPETHERNET_SENDPACKET ? UIP_IPH_LEN + UIP_LLH_LEN + UIP_SENDBUFFER_OFFSET : UIP_IPH_LEN + UIP_LLH_LEN) + upper_layer_memlen, + upper_layer_len - upper_layer_memlen + ); +#ifdef UIPETHERNET_DEBUG_CHKSUM + Serial.print(F("chksum uip_packet(")); + Serial.print(uip_packet); + Serial.print(F(")[")); + Serial.print(UIP_IPH_LEN + UIP_LLH_LEN + upper_layer_memlen); + Serial.print(F("-")); + Serial.print(UIP_IPH_LEN + UIP_LLH_LEN + upper_layer_len); + Serial.print(F("]: ")); + Serial.println(htons(sum),HEX); +#endif + } + return (sum == 0) ? 0xffff : htons(sum); +} + +uint16_t +uip_ipchksum(void) +{ + return UIPEthernetClass::ipchksum(); +} + +#if UIP_UDP +uint16_t +uip_tcpchksum(void) +{ + uint16_t sum = UIPEthernetClass::upper_layer_chksum(UIP_PROTO_TCP); + return sum; +} + +uint16_t +uip_udpchksum(void) +{ + uint16_t sum = UIPEthernetClass::upper_layer_chksum(UIP_PROTO_UDP); + return sum; +} +#endif + +UIPEthernetClass Ethernet; + +extern "C" void serialPrint(int i); +void serialPrint(int i) { + Serial.println(i); + Serial.flush(); +} diff --git a/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/Ethernet.h b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/Ethernet.h new file mode 100644 index 0000000..3f9ddbf --- /dev/null +++ b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/Ethernet.h @@ -0,0 +1,161 @@ +/* + UIPEthernet.h - Arduino implementation of a uIP wrapper class. + Copyright (c) 2013 Norbert Truchsess + All rights reserved. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +#ifndef UIPETHERNET_H +#define UIPETHERNET_H + +//#define UIPETHERNET_DEBUG +//#define UIPETHERNET_DEBUG_CHKSUM +//#define UIPETHERNET_DEBUG_UDP +//#define UIPETHERNET_DEBUG_CLIENT + +#include +#include "Dhcp.h" +#include +#include "utility/Enc28J60Network.h" +#include "EthernetClient.h" +#include "EthernetServer.h" +#include "EthernetUdp.h" + +extern "C" +{ +#include "utility/uip.h" +} + +#define UIPETHERNET_FREEPACKET 1 +#define UIPETHERNET_SENDPACKET 2 +#define UIPETHERNET_BUFFERREAD 4 + +#define uip_ip_addr(addr, ip) do { \ + ((u16_t *)(addr))[0] = HTONS(((ip[0]) << 8) | (ip[1])); \ + ((u16_t *)(addr))[1] = HTONS(((ip[2]) << 8) | (ip[3])); \ + } while(0) + +#define ip_addr_uip(a) IPAddress(a[0] & 0xFF, a[0] >> 8 , a[1] & 0xFF, a[1] >> 8) //TODO this is not IPV6 capable + +#define uip_seteth_addr(eaddr) do {uip_ethaddr.addr[0] = eaddr[0]; \ + uip_ethaddr.addr[1] = eaddr[1];\ + uip_ethaddr.addr[2] = eaddr[2];\ + uip_ethaddr.addr[3] = eaddr[3];\ + uip_ethaddr.addr[4] = eaddr[4];\ + uip_ethaddr.addr[5] = eaddr[5];} while(0) + +#define BUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN]) + +enum EthernetLinkStatus { + Unknown, + LinkON, + LinkOFF +}; + +enum EthernetHardwareStatus { + EthernetNoHardware, + EthernetW5100, + EthernetW5200, + EthernetW5500, + EthernetENC28J60 = 10 +}; + +class UIPEthernetClass +{ +public: + UIPEthernetClass(); + + void init(uint8_t csPin); + + int begin(const uint8_t* mac, unsigned long timeout = 60000, unsigned long responseTimeout = 4000); + void begin(const uint8_t* mac, IPAddress ip); + void begin(const uint8_t* mac, IPAddress ip, IPAddress dns); + void begin(const uint8_t* mac, IPAddress ip, IPAddress dns, IPAddress gateway); + void begin(const uint8_t* mac, IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress subnet); + + void end(); + + // maintain() must be called at regular intervals to process the incoming serial + // data and issue IP events to the sketch. It does not return until all IP + // events have been processed. Renews dhcp-lease if required. + int maintain(); + + EthernetLinkStatus linkStatus(); + EthernetHardwareStatus hardwareStatus(); + + uint8_t* macAddress(uint8_t* mac); + void MACAddress(uint8_t *mac_address) { macAddress(mac_address); } + + IPAddress localIP(); + IPAddress subnetMask(); + IPAddress gatewayIP(); + IPAddress dnsServerIP(); + IPAddress dnsIP(int n = 0); + + void setDnsServerIP(const IPAddress dns_server) { _dnsServerAddress = dns_server; } + void setDNS(IPAddress dns_server) { _dnsServerAddress = dns_server; } + + void setHostname(const char* hostname); // only the pointer is stored! + + int hostByName(const char* hostname, IPAddress& result); + +private: + static bool initialized; + static memhandle in_packet; + static memhandle uip_packet; + static uint8_t uip_hdrlen; + static uint8_t packetstate; + + static IPAddress _dnsServerAddress; + static DhcpClass* _dhcp; + + static unsigned long periodic_timer; + static unsigned long arp_timer; + + static void init(const uint8_t* mac); + static void configure(IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress subnet); + + static void tick(); + + static boolean network_send(); + + static void call_yield(); + + friend class EthernetServer; + + friend class EthernetClient; + + friend class EthernetUDP; + + static uint16_t chksum(uint16_t sum, const uint8_t* data, uint16_t len); + static uint16_t ipchksum(void); +#if UIP_UDP + static uint16_t upper_layer_chksum(uint8_t proto); +#endif + friend uint16_t uip_ipchksum(void); + friend uint16_t uip_tcpchksum(void); + friend uint16_t uip_udpchksum(void); + + friend void uipclient_appcall(void); + friend void uipudp_appcall(void); + +#if UIP_CONF_IPV6 + uint16_t uip_icmp6chksum(void); +#endif /* UIP_CONF_IPV6 */ +}; + +extern UIPEthernetClass Ethernet; + +#endif diff --git a/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/EthernetClient.cpp b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/EthernetClient.cpp new file mode 100644 index 0000000..636bc1d --- /dev/null +++ b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/EthernetClient.cpp @@ -0,0 +1,663 @@ +/* + UIPClient.cpp - Arduino implementation of a uIP wrapper class. + Copyright (c) 2013 Norbert Truchsess + All rights reserved. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +extern "C" +{ +#include "utility/uip-conf.h" +#include "utility/uip.h" +#include "utility/uip_arp.h" +} +#include "Ethernet.h" +#include "EthernetClient.h" + +#define UIP_TCP_PHYH_LEN UIP_LLH_LEN+UIP_IPTCPH_LEN + +#define UIPClient EthernetClient // to not pollute source code history with the rename + +uip_userdata_t UIPClient::all_data[UIP_CONNS]; + +UIPClient::UIPClient() : + data(NULL) +{ +} + +UIPClient::UIPClient(uip_userdata_t* conn_data) : + data(conn_data) +{ +} + +int +UIPClient::connect(IPAddress ip, uint16_t port) +{ + stop(); + uip_ipaddr_t ipaddr; + uip_ip_addr(ipaddr, ip); + struct uip_conn* conn = uip_connect(&ipaddr, htons(port)); + if (conn) + { +#if UIP_CONNECT_TIMEOUT > 0 + uint32_t timeout = millis() + connectTimeout; +#endif + while((conn->tcpstateflags & UIP_TS_MASK) != UIP_CLOSED) + { + UIPEthernetClass::tick(); + if ((conn->tcpstateflags & UIP_TS_MASK) == UIP_ESTABLISHED) + { + data = (uip_userdata_t*) conn->appstate; +#ifdef UIPETHERNET_DEBUG_CLIENT + Serial.print(F("connected, state: ")); + Serial.print(data->state); + Serial.print(F(", first packet in: ")); + Serial.println(data->packets_in[0]); +#endif + return 1; + } +#if UIP_CONNECT_TIMEOUT > 0 + if (((int32_t)(millis() - timeout)) > 0) + { + conn->tcpstateflags = UIP_CLOSED; + break; + } +#endif + } + } + return 0; +} + +int +UIPClient::connect(const char *host, uint16_t port) +{ + // Look up the host first + int ret = 0; +#if UIP_UDP + IPAddress remote_addr; + ret = Ethernet.hostByName(host, remote_addr); + if (ret == 1) { + return connect(remote_addr, port); + } +#endif + return ret; +} + +void +UIPClient::stop() +{ + if (data && data->state) + { +#ifdef UIPETHERNET_DEBUG_CLIENT + Serial.println(F("before stop(), with data")); + _dumpAllData(); +#endif + if (data->state & UIP_CLIENT_REMOTECLOSED) + { + data->state = 0; + } + else + { + flush(); + data->state |= UIP_CLIENT_CLOSE; + } + _flushBlocks(data->packets_in); +#ifdef UIPETHERNET_DEBUG_CLIENT + Serial.println(F("after stop()")); + _dumpAllData(); +#endif + } +#ifdef UIPETHERNET_DEBUG_CLIENT + else + { + Serial.println(F("stop(), data: NULL")); + } +#endif + data = NULL; + UIPEthernetClass::tick(); +} + +uint8_t +UIPClient::connected() +{ + return (data && (data->packets_in[0] != NOBLOCK || (data->state & UIP_CLIENT_CONNECTED))) ? 1 : 0; +} + +bool +UIPClient::operator==(const UIPClient& rhs) +{ + return data && rhs.data && (data == rhs.data); +} + +UIPClient::operator bool() +{ + UIPEthernetClass::tick(); + return data && (!(data->state & UIP_CLIENT_REMOTECLOSED) || data->packets_in[0] != NOBLOCK); +} + +size_t +UIPClient::write(uint8_t c) +{ + return write(&c, 1); +} + +size_t +UIPClient::write(const uint8_t *buf, size_t size) +{ + uip_userdata_t* u = data; + int remain = size; + uint16_t written; +#if UIP_WRITE_TIMEOUT > 0 + uint32_t timeout_start = millis(); +#endif + repeat: + UIPEthernetClass::tick(); + if (u && u->state && !(u->state & (UIP_CLIENT_CLOSE | UIP_CLIENT_REMOTECLOSED))) + { + uint8_t p = _currentBlock(u->packets_out); + if (u->packets_out[p] == NOBLOCK) + { +newpacket: + u->packets_out[p] = Enc28J60Network::allocBlock(UIP_SOCKET_DATALEN); + if (u->packets_out[p] == NOBLOCK) + { +#if UIP_WRITE_TIMEOUT > 0 + if (millis() - timeout_start > UIP_WRITE_TIMEOUT) + { + setWriteError(); + goto ready; + } +#endif + Ethernet.call_yield(); + goto repeat; + } + u->out_pos = 0; + } +#ifdef UIPETHERNET_DEBUG_CLIENT + Serial.print(F("UIPClient.write: writePacket(")); + Serial.print(u->packets_out[p]); + Serial.print(F(") pos: ")); + Serial.print(u->out_pos); + Serial.print(F(", buf[")); + Serial.print(size-remain); + Serial.print(F("-")); + Serial.print(remain); + Serial.print(F("]: '")); + Serial.write((uint8_t*)buf+size-remain,remain); + Serial.println(F("'")); +#endif + written = Enc28J60Network::writePacket(u->packets_out[p],u->out_pos,(uint8_t*)buf+size-remain,remain); + remain -= written; + u->out_pos+=written; + if (remain > 0) + { + if (p == 0) // block 0 just filled, start sending immediately + { + flush(); + goto repeat; + } + if (p == UIP_SOCKET_NUMPACKETS-1) + { +#if UIP_WRITE_TIMEOUT > 0 + if (millis() - timeout_start > UIP_WRITE_TIMEOUT) + { + setWriteError(); + goto ready; + } +#endif + Ethernet.call_yield(); + goto repeat; + } + p++; + goto newpacket; + } +ready: + return size-remain; + } + return 0; +} + +int +UIPClient::availableForWrite() +{ + const int MAX_AVAILABLE = UIP_SOCKET_DATALEN * UIP_SOCKET_NUMPACKETS; + UIPEthernetClass::tick(); + if (data->packets_out[0] == NOBLOCK) + return MAX_AVAILABLE; + uint8_t p = _currentBlock(data->packets_out); + int used = UIP_SOCKET_DATALEN * p + data->out_pos; + return MAX_AVAILABLE - used; +} + +void +UIPClient::flush() +{ + UIPEthernetClass::tick(); + + if (data && data->packets_out[0] != NOBLOCK) + { + struct uip_conn* conn = &uip_conns[data->conn_index]; + if (!uip_outstanding(conn)) + { + uip_poll_conn(conn); + if (uip_len > 0) + { + uip_arp_out(); + UIPEthernetClass::network_send(); + } + } + } +} + +int +UIPClient::available() +{ + if (!(*this)) + return 0; + + int len = 0; + for (uint8_t i = 0; i < UIP_SOCKET_NUMPACKETS; i++) + { + len += Enc28J60Network::blockSize(data->packets_in[i]); + } + + // if sketch checks for incoming data and there are unsent data, flush the transmit buffer + if (!len) + flush(); + return len; +} + +int +UIPClient::read(uint8_t *buf, size_t size) +{ + if (*this) + { + uint16_t remain = size; + if (data->packets_in[0] == NOBLOCK) + { + flush(); // if sketch checks for incoming data and there are unsent data, flush the transmit buffer + return 0; + } + uint16_t read; + do + { + read = Enc28J60Network::readPacket(data->packets_in[0],0,buf+size-remain,remain); + if (read == Enc28J60Network::blockSize(data->packets_in[0])) + { + remain -= read; + _eatBlock(data->packets_in); + if (uip_stopped(&uip_conns[data->conn_index]) && !(data->state & (UIP_CLIENT_CLOSE | UIP_CLIENT_REMOTECLOSED))) + data->state |= UIP_CLIENT_RESTART; + if (data->packets_in[0] == NOBLOCK) + { + if (data->state & UIP_CLIENT_REMOTECLOSED) + { + data->state = 0; + data = NULL; + } + return size-remain; + } + } + else + { + Enc28J60Network::resizeBlock(data->packets_in[0],read); + break; + } + } + while(remain > 0); + return size; + } + return -1; +} + +int +UIPClient::read() +{ + uint8_t c; + if (read(&c,1) <= 0) + return -1; + return c; +} + +int +UIPClient::peek() +{ + if (*this) + { + if (data->packets_in[0] != NOBLOCK) + { + uint8_t c; + Enc28J60Network::readPacket(data->packets_in[0],0,&c,1); + return c; + } + } + return -1; +} + +void +UIPClient::discardReceived() +{ + if (*this) + { + _flushBlocks(data->packets_in); + } +} + +IPAddress +UIPClient::remoteIP(void) +{ + return data ? ip_addr_uip(uip_conns[data->conn_index].ripaddr) : IPAddress(); +} + +uint16_t +UIPClient::remotePort(void) +{ + return data ? ntohs(uip_conns[data->conn_index].rport) : 0; +} + +uint8_t +UIPClient::status() +{ + return !data ? UIP_CLOSED : uip_conns[data->conn_index].tcpstateflags & UIP_TS_MASK; +} + +void +uipclient_appcall(void) +{ + uint16_t send_len = 0; + uip_userdata_t *u = (uip_userdata_t*)uip_conn->appstate; + if (!u && uip_connected()) + { +#ifdef UIPETHERNET_DEBUG_CLIENT + Serial.println(F("UIPClient uip_connected")); + UIPClient::_dumpAllData(); +#endif + u = (uip_userdata_t*) UIPClient::_allocateData(); + if (u) + { + uip_conn->appstate = u; +#ifdef UIPETHERNET_DEBUG_CLIENT + Serial.print(F("UIPClient allocated state: ")); + Serial.println(u->state,BIN); +#endif + } +#ifdef UIPETHERNET_DEBUG_CLIENT + else + Serial.println(F("UIPClient allocation failed")); +#endif + } + if (u) + { + if (uip_newdata()) + { +#ifdef UIPETHERNET_DEBUG_CLIENT + Serial.print(F("UIPClient uip_newdata, uip_len:")); + Serial.println(uip_len); +#endif + if (uip_len && u->state && !(u->state & UIP_CLIENT_CLOSE)) + { + for (uint8_t i=0; i < UIP_SOCKET_NUMPACKETS; i++) + { + if (u->packets_in[i] == NOBLOCK) + { + u->packets_in[i] = Enc28J60Network::allocBlock(uip_len); + if (u->packets_in[i] != NOBLOCK) + { + Enc28J60Network::copyPacket(u->packets_in[i],0,UIPEthernetClass::in_packet,((uint8_t*)uip_appdata)-uip_buf,uip_len); + if (i == UIP_SOCKET_NUMPACKETS-1) + uip_stop(); + goto finish_newdata; + } + } + } + UIPEthernetClass::packetstate &= ~UIPETHERNET_FREEPACKET; + uip_stop(); + } + } +finish_newdata: + if (u->state & UIP_CLIENT_RESTART) + { + u->state &= ~UIP_CLIENT_RESTART; + uip_restart(); + } + // If the connection has been closed, save received but unread data. + if (uip_closed() || uip_timedout() || uip_aborted()) + { +#ifdef UIPETHERNET_DEBUG_CLIENT + Serial.println(F("UIPClient uip_closed")); + UIPClient::_dumpAllData(); +#endif + // drop outgoing packets not sent yet: + UIPClient::_flushBlocks(u->packets_out); + if (u->packets_in[0] != NOBLOCK) + { + ((uip_userdata_closed_t *)u)->lport = uip_conn->lport; + u->state |= UIP_CLIENT_REMOTECLOSED; + } + else + u->state = 0; + // disassociate appdata. +#ifdef UIPETHERNET_DEBUG_CLIENT + Serial.println(F("after UIPClient uip_closed")); + UIPClient::_dumpAllData(); +#endif + uip_conn->appstate = NULL; + goto finish; + } + if (uip_acked()) + { +#ifdef UIPETHERNET_DEBUG_CLIENT + Serial.println(F("UIPClient uip_acked")); +#endif + UIPClient::_eatBlock(u->packets_out); + goto send; + } + if (uip_poll() || uip_rexmit()) + { +#ifdef UIPETHERNET_DEBUG_CLIENT + //Serial.println(F("UIPClient uip_poll")); +#endif +send: + if (u->packets_out[0] != NOBLOCK) + { + if (u->packets_out[1] == NOBLOCK) + { + send_len = u->out_pos; + if (send_len > 0) + { + Enc28J60Network::resizeBlock(u->packets_out[0],0,send_len); + } + } + else + send_len = Enc28J60Network::blockSize(u->packets_out[0]); + if (send_len > 0) + { + UIPEthernetClass::uip_hdrlen = ((uint8_t*)uip_appdata)-uip_buf; + UIPEthernetClass::uip_packet = Enc28J60Network::allocBlock(UIPEthernetClass::uip_hdrlen+send_len + UIP_SENDBUFFER_OFFSET + UIP_SENDBUFFER_PADDING); + if (UIPEthernetClass::uip_packet != NOBLOCK) + { + Enc28J60Network::copyPacket(UIPEthernetClass::uip_packet,UIPEthernetClass::uip_hdrlen + UIP_SENDBUFFER_OFFSET,u->packets_out[0],0,send_len); + UIPEthernetClass::packetstate |= UIPETHERNET_SENDPACKET; + } + } + goto finish; + } + } + // don't close connection unless all outgoing packets are sent + if (u->state & UIP_CLIENT_CLOSE) + { +#ifdef UIPETHERNET_DEBUG_CLIENT + Serial.println(F("UIPClient state UIP_CLIENT_CLOSE")); + UIPClient::_dumpAllData(); +#endif + if (u->packets_out[0] == NOBLOCK) + { + u->state = 0; + uip_conn->appstate = NULL; + uip_close(); +#ifdef UIPETHERNET_DEBUG_CLIENT + Serial.println(F("no blocks out -> free userdata")); + UIPClient::_dumpAllData(); +#endif + } + else + { + uip_stop(); +#ifdef UIPETHERNET_DEBUG_CLIENT + Serial.println(F("blocks outstanding transfer -> uip_stop()")); +#endif + } + } + } + finish: + uip_send(uip_appdata,send_len); + uip_len = send_len; +} + +uip_userdata_t * +UIPClient::_allocateData() +{ + for ( uint8_t sock = 0; sock < UIP_CONNS; sock++ ) + { + uip_userdata_t* data = &UIPClient::all_data[sock]; + if (!data->state) + { + *data = uip_userdata_t(); + data->conn_index = uip_conn - uip_conns; // pointer arithmetics + data->state = UIP_CLIENT_CONNECTED; + return data; + } + } + return NULL; +} + +uint8_t +UIPClient::_currentBlock(memhandle* block) +{ + for (uint8_t i = 1; i < UIP_SOCKET_NUMPACKETS; i++) + { + if (block[i] == NOBLOCK) + return i-1; + } + return UIP_SOCKET_NUMPACKETS-1; +} + +void +UIPClient::_eatBlock(memhandle* block) +{ +#ifdef UIPETHERNET_DEBUG_CLIENT + memhandle* start = block; + Serial.print(F("eatblock(")); + Serial.print(*block); + Serial.print(F("): ")); + for (uint8_t i = 0; i < UIP_SOCKET_NUMPACKETS; i++) + { + Serial.print(start[i]); + Serial.print(F(" ")); + } + Serial.print(F("-> ")); +#endif + Enc28J60Network::freeBlock(block[0]); + for (uint8_t i = 0; i < UIP_SOCKET_NUMPACKETS-1; i++) + { + block[i] = block[i+1]; + } + block[UIP_SOCKET_NUMPACKETS-1] = NOBLOCK; +#ifdef UIPETHERNET_DEBUG_CLIENT + for (uint8_t i = 0; i < UIP_SOCKET_NUMPACKETS; i++) + { + Serial.print(start[i]); + Serial.print(F(" ")); + } + Serial.println(); +#endif +} + +void +UIPClient::_flushBlocks(memhandle* block) +{ + for (uint8_t i = 0; i < UIP_SOCKET_NUMPACKETS; i++) + { + Enc28J60Network::freeBlock(block[i]); + block[i] = NOBLOCK; + } +} + +#ifdef UIPETHERNET_DEBUG_CLIENT +void +UIPClient::_dumpAllData() { + for (uint8_t i=0; i < UIP_CONNS; i++) + { + if (!all_data[i].state) + continue; + Serial.print(F("UIPClient::all_data[")); + Serial.print(i); + Serial.print(F("], state:")); + Serial.println(all_data[i].state, BIN); + struct uip_conn& conn = uip_conns[all_data[i].conn_index]; + Serial.println(ip_addr_uip(conn.ripaddr)); + Serial.print(F("ix: ")); + Serial.print(all_data[i].conn_index); + Serial.print(F(" tcp flags: 0x")); + Serial.print(conn.tcpstateflags, HEX); + Serial.print(F(" retransmission: timer ")); + Serial.print(conn.timer); + Serial.print(F(" nrtx ")); + Serial.println(conn.nrtx); + Serial.print(F("packets_in: ")); + for (uint8_t j=0; j < UIP_SOCKET_NUMPACKETS; j++) + { + Serial.print(all_data[i].packets_in[j]); + Serial.print(F(" ")); + } + Serial.println(); + if (all_data[i].state & UIP_CLIENT_REMOTECLOSED) + { + Serial.print(F("state remote closed, local port: ")); + Serial.println(htons(((uip_userdata_closed_t *)(&all_data[i]))->lport)); + } + else + { + Serial.print(F("packets_out: ")); + for (uint8_t j=0; j < UIP_SOCKET_NUMPACKETS; j++) + { + Serial.print(all_data[i].packets_out[j]); + Serial.print(F(" ")); + } + Serial.println(); + Serial.print(F("out_pos: ")); + Serial.println(all_data[i].out_pos); + } + Serial.println(); + } + for (uint8_t i=0; i < UIP_CONNS; i++) + { + struct uip_conn& conn = uip_conns[i]; + Serial.print(i); + Serial.print(' '); + Serial.print(ip_addr_uip(conn.ripaddr)); + Serial.print(':'); + Serial.print(ntohs(conn.rport)); + Serial.print(' '); + Serial.print(ntohs(conn.lport)); + Serial.print(F(" tcp flags: 0x")); + Serial.print(conn.tcpstateflags, HEX); + Serial.print(F(" retransmission: timer ")); + Serial.print(conn.timer); + Serial.print(F(" nrtx ")); + Serial.println(conn.nrtx); + } +} +#endif diff --git a/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/EthernetClient.h b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/EthernetClient.h new file mode 100644 index 0000000..8807ece --- /dev/null +++ b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/EthernetClient.h @@ -0,0 +1,110 @@ +/* + UIPClient.h - Arduino implementation of a uIP wrapper class. + Copyright (c) 2013 Norbert Truchsess + All rights reserved. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +#ifndef UIPCLIENT_H +#define UIPCLIENT_H + +#include +#include "utility/mempool.h" + +extern "C" { + #include "utility/uip.h" +} + +#define UIP_SOCKET_DATALEN UIP_TCP_MSS + +#define UIP_CLIENT_CONNECTED 0x01 +#define UIP_CLIENT_CLOSE 0x02 +#define UIP_CLIENT_REMOTECLOSED 0x04 +#define UIP_CLIENT_RESTART 0x08 +#define UIP_CLIENT_ACCEPTED 0x10 + +typedef struct { + uint8_t conn_index; + uint8_t state; + memhandle packets_in[UIP_SOCKET_NUMPACKETS]; + uint16_t lport; /**< The local TCP port, in network byte order. */ +} uip_userdata_closed_t; + +typedef struct { + uint8_t conn_index; + uint8_t state; + memhandle packets_in[UIP_SOCKET_NUMPACKETS] = {NOBLOCK}; + memhandle packets_out[UIP_SOCKET_NUMPACKETS] = {NOBLOCK}; + memaddress out_pos; +} uip_userdata_t; + +class EthernetClient : public Client { + +public: + EthernetClient(); + int connect(IPAddress ip, uint16_t port); + int connect(const char *host, uint16_t port); + int read(uint8_t *buf, size_t size); + void stop(); + uint8_t connected(); + operator bool(); + virtual bool operator==(const EthernetClient&); + virtual bool operator!=(const EthernetClient& rhs) { return !this->operator==(rhs); }; + + size_t write(uint8_t); + size_t write(const uint8_t *buf, size_t size); + int availableForWrite(); + void flush(); // flush sends the buffered data + + int available(); + int read(); + int peek(); + void discardReceived(); + + using Print::write; + + IPAddress remoteIP(); + uint16_t remotePort(); + + uint8_t status(); + + void setConnectionTimeout(uint16_t millis) {connectTimeout = millis;} + +private: + EthernetClient(struct uip_conn *_conn); + EthernetClient(uip_userdata_t* conn_data); + + uip_userdata_t* data; + uint16_t connectTimeout = 1000 * UIP_CONNECT_TIMEOUT; + + static uip_userdata_t all_data[UIP_CONNS]; + static uip_userdata_t* _allocateData(); + + static uint8_t _currentBlock(memhandle* blocks); + static void _eatBlock(memhandle* blocks); + static void _flushBlocks(memhandle* blocks); + +#ifdef UIPETHERNET_DEBUG_CLIENT + static void _dumpAllData(); +#endif + + friend class UIPEthernetClass; + friend class EthernetServer; + + friend void uipclient_appcall(void); + +}; + +#endif diff --git a/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/EthernetENC.h b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/EthernetENC.h new file mode 100644 index 0000000..01e5d5b --- /dev/null +++ b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/EthernetENC.h @@ -0,0 +1 @@ +#include "Ethernet.h" diff --git a/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/EthernetServer.cpp b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/EthernetServer.cpp new file mode 100644 index 0000000..9237ad9 --- /dev/null +++ b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/EthernetServer.cpp @@ -0,0 +1,112 @@ +/* + UIPServer.cpp - Arduino implementation of a uIP wrapper class. + Copyright (c) 2013 Norbert Truchsess + All rights reserved. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +#include "Ethernet.h" +#include "EthernetServer.h" +extern "C" { + #include "utility/uip-conf.h" +} + +#define UIPServer EthernetServer // to not pollute source code history with the rename +#define UIPClient EthernetClient + +UIPServer::UIPServer(uint16_t port) : _port(htons(port)) +{ +} + +UIPClient UIPServer::available() +{ + UIPEthernetClass::tick(); + for ( uip_userdata_t* data = &UIPClient::all_data[0]; data < &UIPClient::all_data[UIP_CONNS]; data++ ) + { + if (data->packets_in[0] != NOBLOCK + && (((data->state & UIP_CLIENT_CONNECTED) && uip_conns[data->conn_index].lport ==_port) + || ((data->state & UIP_CLIENT_REMOTECLOSED) && ((uip_userdata_closed_t *)data)->lport == _port))) + return UIPClient(data); + } + return UIPClient(); +} + +UIPClient UIPServer::accept() +{ + UIPEthernetClass::tick(); + for ( uip_userdata_t* data = &UIPClient::all_data[0]; data < &UIPClient::all_data[UIP_CONNS]; data++ ) + { + if (!(data->state & UIP_CLIENT_ACCEPTED) + && (((data->state & UIP_CLIENT_CONNECTED) && uip_conns[data->conn_index].lport ==_port) + || ((data->state & UIP_CLIENT_REMOTECLOSED) && ((uip_userdata_closed_t *)data)->lport == _port))) { + data->state |= UIP_CLIENT_ACCEPTED; + return UIPClient(data); + } + } + return UIPClient(); +} + +void UIPServer::begin() +{ + uip_listen(_port); + UIPEthernetClass::tick(); + listening = true; +} + +void UIPServer::begin(uint16_t port) +{ + _port = port; + begin(); +} + +void UIPServer::end() { + uip_unlisten(_port); + listening = false; + for ( uip_userdata_t* data = &UIPClient::all_data[0]; data < &UIPClient::all_data[UIP_CONNS]; data++ ) + { + if ((data->state & UIP_CLIENT_CONNECTED) && uip_conns[data->conn_index].lport ==_port) + { + UIPClient client(data); + client.stop(); + } + } +} + +UIPServer::operator bool() { + return listening; +} + +size_t UIPServer::writeToAllClients(const uint8_t *buf, size_t size) +{ + size_t ret = 0; + for ( uip_userdata_t* data = &UIPClient::all_data[0]; data < &UIPClient::all_data[UIP_CONNS]; data++ ) + { + if ((data->state & UIP_CLIENT_CONNECTED) && uip_conns[data->conn_index].lport ==_port) + { + EthernetClient client(data); + ret = client.write(buf, size); + } + } + return ret; +} + +size_t EthernetServerPrint::write(uint8_t c) +{ + return write(&c,1); +} + +size_t EthernetServerPrint::write(const uint8_t *buf, size_t size) +{ + return EthernetServer::writeToAllClients(buf, size); +} diff --git a/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/EthernetServer.h b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/EthernetServer.h new file mode 100644 index 0000000..fec7006 --- /dev/null +++ b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/EthernetServer.h @@ -0,0 +1,55 @@ +/* + UIPServer.h - Arduino implementation of a uIP wrapper class. + Copyright (c) 2013 Norbert Truchsess + All rights reserved. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +#ifndef UIPSERVER_H +#define UIPSERVER_H + +#include "EthernetClient.h" + +class EthernetServer { + +public: + EthernetServer(uint16_t port = 80); + EthernetClient available(); + EthernetClient accept(); + void begin(); + void begin(uint16_t port); + void end(); + operator bool(); + +protected: + size_t writeToAllClients(const uint8_t *buf, size_t size); + +private: + uint16_t _port; + bool listening = false; +}; + +class EthernetServerPrint : public EthernetServer, public Print { + +public: + EthernetServerPrint(uint16_t port = 80) : EthernetServer(port) {} + + virtual size_t write(uint8_t); + virtual size_t write(const uint8_t *buf, size_t size); + + using Print::write; + +}; + +#endif diff --git a/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/EthernetUdp.cpp b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/EthernetUdp.cpp new file mode 100644 index 0000000..979037b --- /dev/null +++ b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/EthernetUdp.cpp @@ -0,0 +1,424 @@ +/* + UIPUdp.cpp - Arduino implementation of a uIP wrapper class. + Copyright (c) 2013 Norbert Truchsess + All rights reserved. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +#include "Ethernet.h" +#include "EthernetUdp.h" + +extern "C" { +#include "utility/uip-conf.h" +#include "utility/uip.h" +#include "utility/uip_arp.h" +} + +#if UIP_UDP +#define UIP_ARPHDRSIZE 42 +#define UDPBUF ((struct uip_udpip_hdr *)&uip_buf[UIP_LLH_LEN]) + +#define UIPUDP EthernetUDP // to not pollute source code history with the rename + +// Constructor +UIPUDP::UIPUDP() : + _uip_udp_conn(NULL), + appdata() +{ +} + +// initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use +uint8_t +UIPUDP::begin(uint16_t port) +{ + if (!_uip_udp_conn) + { + _uip_udp_conn = uip_udp_new(NULL, 0); + } + if (_uip_udp_conn) + { + uip_udp_bind(_uip_udp_conn,htons(port)); + _uip_udp_conn->appstate = &appdata; + return 1; + } + return 0; +} + +// Finish with the UDP socket +void +UIPUDP::stop() +{ + if (_uip_udp_conn) + { + uip_udp_remove(_uip_udp_conn); + _uip_udp_conn->appstate = NULL; + _uip_udp_conn=NULL; + Enc28J60Network::freeBlock(appdata.packet_in); + _flushBlocks(appdata.packet_next); + Enc28J60Network::freeBlock(appdata.packet_out); + appdata = uip_udp_userdata_t(); + } +} + +// Sending UDP packets + +// Start building up a packet to send to the remote host specific in ip and port +// Returns 1 if successful, 0 if there was a problem with the supplied IP address or port +int +UIPUDP::beginPacket(IPAddress ip, uint16_t port) +{ + UIPEthernetClass::tick(); + if ((ip[0] || ip[1] || ip[2] || ip[3]) && port) + { + uip_ipaddr_t ripaddr; + uip_ip_addr(&ripaddr, ip); +#ifdef UIPETHERNET_DEBUG_UDP + Serial.print(F("udp beginPacket, ")); +#endif + if (_uip_udp_conn) + { + // [J.A]: for UDP server, setting ripaddr and rport causes in uIP filtering + // of incoming messages. it would be better to store the IP and port in fields + // and set them only in endPacket(). + _uip_udp_conn->rport = htons(port); + uip_ipaddr_copy(_uip_udp_conn->ripaddr, &ripaddr); + } + else + { + _uip_udp_conn = uip_udp_new(&ripaddr,htons(port)); + if (_uip_udp_conn) + { +#ifdef UIPETHERNET_DEBUG_UDP + Serial.print(F("new connection, ")); +#endif + _uip_udp_conn->appstate = &appdata; + } + else + { +#ifdef UIPETHERNET_DEBUG_UDP + Serial.println(F("failed to allocate new connection")); +#endif + return 0; + } + } +#ifdef UIPETHERNET_DEBUG_UDP + Serial.print(F("rip: ")); + Serial.print(ip); + Serial.print(F(", port: ")); + Serial.println(port); +#endif + } + if (_uip_udp_conn) + { + if (appdata.packet_out == NOBLOCK) + { + appdata.packet_out = Enc28J60Network::allocBlock(UIP_UDP_MAXPACKETSIZE + UIP_SENDBUFFER_OFFSET + UIP_SENDBUFFER_PADDING); + appdata.out_pos = UIP_UDP_PHYH_LEN + UIP_SENDBUFFER_OFFSET; + if (appdata.packet_out != NOBLOCK) + return 1; +#ifdef UIPETHERNET_DEBUG_UDP + else + Serial.println(F("failed to allocate memory for packet")); +#endif + } +#ifdef UIPETHERNET_DEBUG_UDP + else + Serial.println(F("previous packet on that connection not sent yet")); +#endif + } + return 0; +} + +// Start building up a packet to send to the remote host specific in host and port +// Returns 1 if successful, 0 if there was a problem resolving the hostname or port +int +UIPUDP::beginPacket(const char *host, uint16_t port) +{ + // Look up the host first + int ret = 0; + IPAddress remote_addr; + ret = Ethernet.hostByName(host, remote_addr); + if (ret == 1) { + return beginPacket(remote_addr, port); + } else { + return ret; + } +} + +// Finish off this packet and send it +// Returns 1 if the packet was sent successfully, 0 if there was an error +int +UIPUDP::endPacket() +{ + if (_uip_udp_conn && appdata.packet_out != NOBLOCK) + { + appdata.send = true; + Enc28J60Network::resizeBlock(appdata.packet_out,0,appdata.out_pos + UIP_SENDBUFFER_PADDING); + uip_udp_periodic_conn(_uip_udp_conn); + if (uip_len > 0) + { + _send(_uip_udp_conn); + return 1; + } + } + return 0; +} + +// Write a single byte into the packet +size_t +UIPUDP::write(uint8_t c) +{ + return write(&c,1); +} + +// Write size bytes from buffer into the packet +size_t +UIPUDP::write(const uint8_t *buffer, size_t size) +{ + if (appdata.packet_out != NOBLOCK) + { + size_t ret = Enc28J60Network::writePacket(appdata.packet_out,appdata.out_pos,(uint8_t*)buffer,size); + appdata.out_pos += ret; + return ret; + } + return 0; +} + +// Start processing the next available incoming packet +// Returns the size of the packet in bytes, or 0 if no packets are available +int +UIPUDP::parsePacket() +{ + UIPEthernetClass::tick(); +#ifdef UIPETHERNET_DEBUG_UDP + if (appdata.packet_in != NOBLOCK) + { + Serial.print(F("udp parsePacket freeing previous packet: ")); + Serial.println(appdata.packet_in); + } +#endif + Enc28J60Network::freeBlock(appdata.packet_in); + + appdata.packet_in = appdata.packet_next[0].packet; + uip_ipaddr_copy(appdata.remote_ip, appdata.packet_next[0].remote_ip); + appdata.remote_port = appdata.packet_next[0].remote_port; + _moveBlocks(appdata.packet_next); + +#ifdef UIPETHERNET_DEBUG_UDP + if (appdata.packet_in != NOBLOCK) + { + Serial.print(F("udp parsePacket received packet: ")); + Serial.print(appdata.packet_in); + } +#endif + int size = Enc28J60Network::blockSize(appdata.packet_in); +#ifdef UIPETHERNET_DEBUG_UDP + if (appdata.packet_in != NOBLOCK) + { + Serial.print(F(", size: ")); + Serial.println(size); + } +#endif + return size; +} + +// Number of bytes remaining in the current packet +int +UIPUDP::available() +{ + UIPEthernetClass::tick(); + return Enc28J60Network::blockSize(appdata.packet_in); +} + +// Read a single byte from the current packet +int +UIPUDP::read() +{ + unsigned char c; + if (read(&c,1) > 0) + { + return c; + } + return -1; +} + +// Read up to len bytes from the current packet and place them into buffer +// Returns the number of bytes read, or 0 if none are available +int +UIPUDP::read(unsigned char* buffer, size_t len) +{ + UIPEthernetClass::tick(); + if (appdata.packet_in != NOBLOCK) + { + memaddress read = Enc28J60Network::readPacket(appdata.packet_in,0,buffer,len); + if (read == Enc28J60Network::blockSize(appdata.packet_in)) + { + Enc28J60Network::freeBlock(appdata.packet_in); + appdata.packet_in = NOBLOCK; + } + else + Enc28J60Network::resizeBlock(appdata.packet_in,read); + return read; + } + return 0; +} + +// Return the next byte from the current packet without moving on to the next byte +int +UIPUDP::peek() +{ + UIPEthernetClass::tick(); + if (appdata.packet_in != NOBLOCK) + { + unsigned char c; + if (Enc28J60Network::readPacket(appdata.packet_in,0,&c,1) == 1) + return c; + } + return -1; +} + +// Finish reading the current packet +void +UIPUDP::discardReceived() +{ + UIPEthernetClass::tick(); + Enc28J60Network::freeBlock(appdata.packet_in); + appdata.packet_in = NOBLOCK; +} + +// Return the IP address of the host who sent the current incoming packet +IPAddress +UIPUDP::remoteIP() +{ + return ip_addr_uip(appdata.remote_ip); +} + +// Return the port of the host who sent the current incoming packet +uint16_t +UIPUDP::remotePort() +{ + return ntohs(appdata.remote_port); +} + +// uIP callback function + +void +uipudp_appcall(void) { + if (uip_udp_userdata_t *data = (uip_udp_userdata_t *)(uip_udp_conn->appstate)) + { + if (uip_newdata()) + { + uint8_t p = UIPUDP::_newBlock(data->packet_next); + if (data->packet_next[p].packet == NOBLOCK) + { + data->packet_next[p].remote_port = UDPBUF->srcport; + uip_ipaddr_copy( data->packet_next[p].remote_ip,UDPBUF->srcipaddr); + data->packet_next[p].packet = Enc28J60Network::allocBlock(ntohs(UDPBUF->udplen)-UIP_UDPH_LEN); + //if we are unable to allocate memory the packet is dropped. udp doesn't guarantee packet delivery + if (data->packet_next[p].packet != NOBLOCK) + { + //discard Linklevel and IP and udp-header and any trailing bytes: + Enc28J60Network::copyPacket(data->packet_next[p].packet,0,UIPEthernetClass::in_packet,UIP_UDP_PHYH_LEN,Enc28J60Network::blockSize(data->packet_next[p].packet)); + #ifdef UIPETHERNET_DEBUG_UDP + Serial.print(F("udp, uip_newdata received packet: ")); + Serial.print(data->packet_next[p].packet); + Serial.print(F(", size: ")); + Serial.println(Enc28J60Network::blockSize(data->packet_next[p].packet)); + #endif + } + } + } + if (uip_poll() && data->send) + { + //set uip_slen (uip private) by calling uip_udp_send +#ifdef UIPETHERNET_DEBUG_UDP + Serial.print(F("udp, uip_poll preparing packet to send: ")); + Serial.print(data->packet_out); + Serial.print(F(", size: ")); + Serial.println(Enc28J60Network::blockSize(data->packet_out)); +#endif + UIPEthernetClass::uip_packet = data->packet_out; + UIPEthernetClass::packetstate |= UIPETHERNET_SENDPACKET; + UIPEthernetClass::uip_hdrlen = UIP_UDP_PHYH_LEN; + uip_udp_send(data->out_pos - (UIP_UDP_PHYH_LEN + UIP_SENDBUFFER_OFFSET)); + } + } +} + +void +UIPUDP::_send(struct uip_udp_conn *uip_udp_conn) { + + uip_arp_out(); //add arp + if (uip_len == UIP_ARPHDRSIZE) + { + UIPEthernetClass::uip_packet = NOBLOCK; + UIPEthernetClass::packetstate &= ~UIPETHERNET_SENDPACKET; +#ifdef UIPETHERNET_DEBUG_UDP + Serial.println(F("udp, uip_poll results in ARP-packet")); +#endif + UIPEthernetClass::network_send(); + } + else + //arp found ethaddr for ip (otherwise packet is replaced by arp-request) + { + uip_udp_userdata_t* data = (uip_udp_userdata_t *)(uip_udp_conn->appstate); + UIPEthernetClass::network_send(); + data->send = false; + data->packet_out = NOBLOCK; + + // [J.A] a listening UDP port in uIP filters received messages + // if rport and ripaddr are set. so we better clear them + uip_udp_conn->rport = 0; + uip_udp_conn->ripaddr[0] = 0; + uip_udp_conn->ripaddr[1] = 0; + +#ifdef UIPETHERNET_DEBUG_UDP + Serial.print(F("udp, uip_packet to send: ")); + Serial.println(UIPEthernetClass::uip_packet); +#endif + } +} + +uint8_t +UIPUDP::_newBlock(uip_udp_msg_rec_t* block) +{ + for (uint8_t i = 0; i < UIP_UDP_BACKLOG; i++) + { + if (block[i].packet == NOBLOCK) + return i; + } + return UIP_UDP_BACKLOG-1; +} + +void +UIPUDP::_moveBlocks(uip_udp_msg_rec_t* block) +{ + for (uint8_t i = 0; i < UIP_UDP_BACKLOG-1; i++) + { + block[i] = block[i+1]; + } + block[UIP_UDP_BACKLOG-1].packet = NOBLOCK; +} + +void +UIPUDP::_flushBlocks(uip_udp_msg_rec_t* block) +{ + for (uint8_t i = 0; i < UIP_UDP_BACKLOG; i++) + { + Enc28J60Network::freeBlock(block[i].packet); + block[i].packet = NOBLOCK; + } +} +#endif diff --git a/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/EthernetUdp.h b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/EthernetUdp.h new file mode 100644 index 0000000..43d27ca --- /dev/null +++ b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/EthernetUdp.h @@ -0,0 +1,139 @@ +/* + UIPUdp.h - Arduino implementation of a uIP wrapper class. + Copyright (c) 2013 Norbert Truchsess + All rights reserved. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +#ifndef UIPUDP_H +#define UIPUDP_H + +#include +#include +#include "utility/mempool.h" +extern "C" { + #include "utility/uip.h" +} + +#define UIP_UDP_MAXDATALEN 1500 +#define UIP_UDP_PHYH_LEN UIP_LLH_LEN+UIP_IPUDPH_LEN +#define UIP_UDP_MAXPACKETSIZE UIP_UDP_MAXDATALEN+UIP_UDP_PHYH_LEN + +typedef struct { + memhandle packet = NOBLOCK; + uip_ipaddr_t remote_ip; + uint16_t remote_port = 0; +} uip_udp_msg_rec_t; + +typedef struct { + memaddress out_pos; + uip_udp_msg_rec_t packet_next[UIP_UDP_BACKLOG]; + memhandle packet_in = NOBLOCK; + memhandle packet_out = NOBLOCK; + boolean send; + uip_ipaddr_t remote_ip; + uint16_t remote_port = 0; +} uip_udp_userdata_t; + +class EthernetUDP : public UDP +{ + +private: + struct uip_udp_conn *_uip_udp_conn; + + uip_udp_userdata_t appdata; + +public: + EthernetUDP(); // Constructor + uint8_t + begin(uint16_t);// initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use + void + stop(); // Finish with the UDP socket + + // Sending UDP packets + + // Start building up a packet to send to the remote host specific in ip and port + // Returns 1 if successful, 0 if there was a problem with the supplied IP address or port + int + beginPacket(IPAddress ip, uint16_t port); + // Start building up a packet to send to the remote host specific in host and port + // Returns 1 if successful, 0 if there was a problem resolving the hostname or port + int + beginPacket(const char *host, uint16_t port); + // Finish off this packet and send it + // Returns 1 if the packet was sent successfully, 0 if there was an error + int + endPacket(); + // Write a single byte into the packet + size_t + write(uint8_t); + // Write size bytes from buffer into the packet + size_t + write(const uint8_t *buffer, size_t size); + // flush() should send the data, but here endPacket does it + void + flush() {}; // in Print it is empty, UDP makes it pure virtual + + using Print::write; + + // Start processing the next available incoming packet + // Returns the size of the packet in bytes, or 0 if no packets are available + int + parsePacket(); + // Number of bytes remaining in the current packet + int + available(); + // Read a single byte from the current packet + int + read(); + // Read up to len bytes from the current packet and place them into buffer + // Returns the number of bytes read, or 0 if none are available + int + read(unsigned char* buffer, size_t len); + // Read up to len characters from the current packet and place them into buffer + // Returns the number of characters read, or 0 if none are available + int + read(char* buffer, size_t len) + { + return read((unsigned char*) buffer, len); + } + ; + // Return the next byte from the current packet without moving on to the next byte + int + peek(); + void + discardReceived(); // former flush + + // Return the IP address of the host who sent the current incoming packet + IPAddress + remoteIP(); + + // Return the port of the host who sent the current incoming packet + uint16_t + remotePort(); + +private: + + friend void uipudp_appcall(void); + + friend class UIPEthernetClass; + static void _send(struct uip_udp_conn *uip_udp_conn); + + static uint8_t _newBlock(uip_udp_msg_rec_t* blocks); + static void _moveBlocks(uip_udp_msg_rec_t* blocks); + static void _flushBlocks(uip_udp_msg_rec_t* blocks); +}; + +#endif diff --git a/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/tcp_states.h b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/tcp_states.h new file mode 100644 index 0000000..02864da --- /dev/null +++ b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/tcp_states.h @@ -0,0 +1,21 @@ + +#ifndef UIP_TCP_STATES_H +#define UIP_TCP_STATES_H + +#include + +// common constants for client.state() return values +enum uip_tcp_state { + CLOSED = UIP_CLOSED, + SYN_SENT = UIP_SYN_SENT, + SYN_RCVD = UIP_SYN_RCVD, + ESTABLISHED = UIP_ESTABLISHED, + FIN_WAIT_1 = UIP_FIN_WAIT_1, + FIN_WAIT_2 = UIP_FIN_WAIT_2, + CLOSE_WAIT = 10, // not used + CLOSING = UIP_CLOSING, + LAST_ACK = UIP_LAST_ACK, + TIME_WAIT = UIP_TIME_WAIT +}; + +#endif diff --git a/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/Enc28J60Network.cpp b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/Enc28J60Network.cpp new file mode 100644 index 0000000..6649b48 --- /dev/null +++ b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/Enc28J60Network.cpp @@ -0,0 +1,391 @@ +/* + Enc28J60NetworkClass.cpp — Bitbang-SPI version for non-hardware-SPI pins + Based on UIPEthernet by Norbert Truchsess, GPL V2 + + Modification: Hardware SPI replaced with bitbang SPI. + Target: STM32F103RBT6 with ENC28J60 on PC6(SCK)/PC7(MISO)/PC8(CS)/PC9(MOSI) + */ + +#include "Enc28J60Network.h" +#include +#include "config.h" // ETH_SCK_PIN / ETH_MOSI_PIN / ETH_MISO_PIN +// Note: intentionally NOT included — this version uses bitbang SPI + +extern "C" { +#include "enc28j60.h" +#include "uip.h" +} + +// ============================================================ +// Bitbang SPI — SPI Mode 0 (CPOL=0, CPHA=0) +// Pin definitions come from project include/config.h via build system +// ============================================================ +#ifndef ETH_SCK_PIN + #error "ETH_SCK_PIN not defined — check include/config.h" +#endif + +static bool _spi_ready = false; + +static void bitbang_init() { + if (_spi_ready) return; + pinMode(ETH_SCK_PIN, OUTPUT); digitalWrite(ETH_SCK_PIN, LOW); + pinMode(ETH_MOSI_PIN, OUTPUT); digitalWrite(ETH_MOSI_PIN, LOW); + pinMode(ETH_MISO_PIN, INPUT); + _spi_ready = true; +} + +static inline uint8_t bitbang_transfer(uint8_t out) { + uint8_t in = 0; + for (int8_t i = 7; i >= 0; i--) { + digitalWrite(ETH_MOSI_PIN, (out >> i) & 1); + digitalWrite(ETH_SCK_PIN, HIGH); + in = (in << 1) | digitalRead(ETH_MISO_PIN); + digitalWrite(ETH_SCK_PIN, LOW); + } + return in; +} +// ============================================================ + +// set CS to 0 = active +#define CSACTIVE digitalWrite(csPin, LOW) +// set CS to 1 = passive +#define CSPASSIVE digitalWrite(csPin, HIGH) + +bool Enc28J60Network::spiInitialized = false; +uint8_t Enc28J60Network::csPin = SS; +uint16_t Enc28J60Network::nextPacketPtr; +uint8_t Enc28J60Network::bank = 0xff; + +struct memblock Enc28J60Network::receivePkt; + +void Enc28J60Network::initSPI() +{ + if (spiInitialized) + return; + bitbang_init(); + pinMode(csPin, OUTPUT); + CSPASSIVE; + spiInitialized = true; +} + +bool Enc28J60Network::init(uint8_t* macaddr) +{ + MemoryPool::init(); + initSPI(); + + // perform system reset + writeOp(ENC28J60_SOFT_RESET, 0, ENC28J60_SOFT_RESET); + delay(50); + nextPacketPtr = RXSTART_INIT; + writeRegPair(ERXSTL, RXSTART_INIT); + writeRegPair(ERXRDPTL, RXSTART_INIT); + writeRegPair(ERXNDL, RXSTOP_INIT); + writeReg(ERXFCON, ERXFCON_UCEN|ERXFCON_CRCEN|ERXFCON_PMEN); + writeRegPair(EPMM0, 0x303f); + writeRegPair(EPMCSL, 0xf7f9); + writeRegPair(MACON1, MACON1_MARXEN|MACON1_TXPAUS|MACON1_RXPAUS); + writeOp(ENC28J60_BIT_FIELD_SET, MACON3, MACON3_PADCFG0|MACON3_TXCRCEN|MACON3_FRMLNEN); + writeRegPair(MAIPGL, 0x0C12); + writeReg(MABBIPG, 0x12); + writeRegPair(MAMXFLL, MAX_FRAMELEN); + writeReg(MAADR5, macaddr[0]); + writeReg(MAADR4, macaddr[1]); + writeReg(MAADR3, macaddr[2]); + writeReg(MAADR2, macaddr[3]); + writeReg(MAADR1, macaddr[4]); + writeReg(MAADR0, macaddr[5]); + phyWrite(PHCON2, PHCON2_HDLDIS); + setBank(ECON1); + writeOp(ENC28J60_BIT_FIELD_SET, EIE, EIE_INTIE|EIE_PKTIE); + writeOp(ENC28J60_BIT_FIELD_SET, ECON1, ECON1_RXEN); + phyWrite(PHLCON, 0x476); + + return getrev(); +} + +memhandle Enc28J60Network::receivePacket() +{ + uint8_t rxstat; + uint16_t len; + + if (readReg(EPKTCNT) != 0) + { + uint16_t readPtr = nextPacketPtr+6 > RXSTOP_INIT ? + nextPacketPtr+6-((RXSTOP_INIT + 1)-RXSTART_INIT) : nextPacketPtr+6; + writeRegPair(ERDPTL, nextPacketPtr); + nextPacketPtr = readOp(ENC28J60_READ_BUF_MEM, 0); + nextPacketPtr |= readOp(ENC28J60_READ_BUF_MEM, 0) << 8; + len = readOp(ENC28J60_READ_BUF_MEM, 0); + len |= readOp(ENC28J60_READ_BUF_MEM, 0) << 8; + len -= 4; + rxstat = readOp(ENC28J60_READ_BUF_MEM, 0); + writeOp(ENC28J60_BIT_FIELD_SET, ECON2, ECON2_PKTDEC); + if ((rxstat & 0x80) != 0) + { + receivePkt.begin = readPtr; + receivePkt.size = len; + return UIP_RECEIVEBUFFERHANDLE; + } + setERXRDPT(); + } + return (NOBLOCK); +} + +void Enc28J60Network::setERXRDPT() +{ + writeRegPair(ERXRDPTL, nextPacketPtr == RXSTART_INIT ? RXSTOP_INIT : nextPacketPtr-1); +} + +memaddress Enc28J60Network::blockSize(memhandle handle) +{ + return handle == NOBLOCK ? 0 : + handle == UIP_RECEIVEBUFFERHANDLE ? receivePkt.size : blocks[handle].size; +} + +bool Enc28J60Network::sendPacket(memhandle handle) +{ + memblock *packet = &blocks[handle]; + uint16_t start = packet->begin; + uint16_t end = start + packet->size - 1 - UIP_SENDBUFFER_PADDING; + + writeByte(start, 0); + + writeRegPair(ETXSTL, start); + writeRegPair(ETXNDL, end); + + bool success = false; + for (uint8_t retry = 0; retry < TX_COLLISION_RETRY_COUNT; retry++) + { + writeOp(ENC28J60_BIT_FIELD_SET, ECON1, ECON1_TXRST); + writeOp(ENC28J60_BIT_FIELD_CLR, ECON1, ECON1_TXRST); + writeOp(ENC28J60_BIT_FIELD_CLR, EIR, EIR_TXERIF | EIR_TXIF); + writeOp(ENC28J60_BIT_FIELD_SET, ECON1, ECON1_TXRTS); + uint8_t eir; + while (((eir = readReg(EIR)) & (EIR_TXIF | EIR_TXERIF)) == 0); + writeOp(ENC28J60_BIT_FIELD_CLR, ECON1, ECON1_TXRTS); + success = ((eir & EIR_TXERIF) == 0); + if (success) break; + uint8_t tsv4 = readByte(end + 4); + if (!(tsv4 & 0b00100000)) break; + } + return success; +} + +uint16_t Enc28J60Network::setReadPtr(memhandle handle, memaddress position, uint16_t len) +{ + memblock *packet = handle == UIP_RECEIVEBUFFERHANDLE ? &receivePkt : &blocks[handle]; + memaddress start = handle == UIP_RECEIVEBUFFERHANDLE && + packet->begin + position > RXSTOP_INIT ? + packet->begin + position-((RXSTOP_INIT + 1)-RXSTART_INIT) : + packet->begin + position; + writeRegPair(ERDPTL, start); + if (len > packet->size - position) len = packet->size - position; + return len; +} + +uint16_t Enc28J60Network::readPacket(memhandle handle, memaddress position, uint8_t* buffer, uint16_t len) +{ + len = setReadPtr(handle, position, len); + readBuffer(len, buffer); + return len; +} + +uint16_t Enc28J60Network::writePacket(memhandle handle, memaddress position, uint8_t* buffer, uint16_t len) +{ + memblock *packet = &blocks[handle]; + uint16_t start = packet->begin + position; + if (len > packet->size - position) len = packet->size - position; + if (len == 0) return 0; + writeRegPair(EWRPTL, start); + writeBuffer(len, buffer); + return len; +} + +uint8_t Enc28J60Network::readByte(uint16_t addr) +{ + writeRegPair(ERDPTL, addr); + CSACTIVE; + bitbang_transfer(ENC28J60_READ_BUF_MEM); + uint8_t c = bitbang_transfer(0x00); + CSPASSIVE; + return c; +} + +void Enc28J60Network::writeByte(uint16_t addr, uint8_t data) +{ + writeRegPair(EWRPTL, addr); + CSACTIVE; + bitbang_transfer(ENC28J60_WRITE_BUF_MEM); + bitbang_transfer(data); + CSPASSIVE; +} + +void Enc28J60Network::copyPacket(memhandle dest_pkt, memaddress dest_pos, memhandle src_pkt, memaddress src_pos, uint16_t len) +{ + memblock *dest = &blocks[dest_pkt]; + memblock *src = src_pkt == UIP_RECEIVEBUFFERHANDLE ? &receivePkt : &blocks[src_pkt]; + memaddress start = src_pkt == UIP_RECEIVEBUFFERHANDLE && src->begin + src_pos > RXSTOP_INIT ? + src->begin + src_pos - ((RXSTOP_INIT + 1) - RXSTART_INIT) : src->begin + src_pos; + enc28J60_mempool_block_move_callback(dest->begin + dest_pos, start, len); +} + +void enc28J60_mempool_block_move_callback(memaddress dest, memaddress src, memaddress len) +{ + if (len == 1) + { + Enc28J60Network::writeByte(dest, Enc28J60Network::readByte(src)); + } + else + { + len += src - 1; + Enc28J60Network::writeRegPair(EDMASTL, src); + Enc28J60Network::writeRegPair(EDMADSTL, dest); + if ((src <= RXSTOP_INIT) && (len > RXSTOP_INIT)) + len -= ((RXSTOP_INIT + 1)-RXSTART_INIT); + Enc28J60Network::writeRegPair(EDMANDL, len); + Enc28J60Network::writeOp(ENC28J60_BIT_FIELD_CLR, ECON1, ECON1_CSUMEN); + Enc28J60Network::writeOp(ENC28J60_BIT_FIELD_SET, ECON1, ECON1_DMAST); + while (Enc28J60Network::readOp(ENC28J60_READ_CTRL_REG, ECON1) & ECON1_DMAST); + } +} + +void Enc28J60Network::freePacket() +{ + setERXRDPT(); +} + +uint8_t Enc28J60Network::readOp(uint8_t op, uint8_t address) +{ + CSACTIVE; + bitbang_transfer(op | (address & ADDR_MASK)); + if (address & 0x80) bitbang_transfer(0x00); // dummy read for MAC/MII + uint8_t c = bitbang_transfer(0x00); + CSPASSIVE; + return c; +} + +void Enc28J60Network::writeOp(uint8_t op, uint8_t address, uint8_t data) +{ + CSACTIVE; + bitbang_transfer(op | (address & ADDR_MASK)); + bitbang_transfer(data); + CSPASSIVE; +} + +void Enc28J60Network::readBuffer(uint16_t len, uint8_t* data) +{ + CSACTIVE; + bitbang_transfer(ENC28J60_READ_BUF_MEM); + while (len--) *data++ = bitbang_transfer(0x00); + CSPASSIVE; +} + +void Enc28J60Network::writeBuffer(uint16_t len, uint8_t* data) +{ + CSACTIVE; + bitbang_transfer(ENC28J60_WRITE_BUF_MEM); + while (len--) bitbang_transfer(*data++); + CSPASSIVE; +} + +void Enc28J60Network::setBank(uint8_t address) +{ + if ((address & BANK_MASK) != bank) + { + writeOp(ENC28J60_BIT_FIELD_CLR, ECON1, (ECON1_BSEL1|ECON1_BSEL0)); + writeOp(ENC28J60_BIT_FIELD_SET, ECON1, (address & BANK_MASK)>>5); + bank = (address & BANK_MASK); + } +} + +uint8_t Enc28J60Network::readReg(uint8_t address) +{ + setBank(address); + return readOp(ENC28J60_READ_CTRL_REG, address); +} + +void Enc28J60Network::writeReg(uint8_t address, uint8_t data) +{ + setBank(address); + writeOp(ENC28J60_WRITE_CTRL_REG, address, data); +} + +void Enc28J60Network::writeRegPair(uint8_t address, uint16_t data) +{ + setBank(address); + writeOp(ENC28J60_WRITE_CTRL_REG, address, (data & 0xFF)); + writeOp(ENC28J60_WRITE_CTRL_REG, address+1, (data >> 8)); +} + +void Enc28J60Network::phyWrite(uint8_t address, uint16_t data) +{ + writeReg(MIREGADR, address); + writeRegPair(MIWRL, data); + while (readReg(MISTAT) & MISTAT_BUSY) delayMicroseconds(15); +} + +uint16_t Enc28J60Network::phyRead(uint8_t address) +{ + writeReg(MIREGADR, address); + writeReg(MICMD, MICMD_MIIRD); + while (readReg(MISTAT) & MISTAT_BUSY) delayMicroseconds(15); + writeReg(MICMD, 0); + return (readReg(MIRDL) | readReg(MIRDH) << 8); +} + +void Enc28J60Network::clkout(uint8_t clk) +{ + writeReg(ECOCON, clk & 0x7); +} + +uint8_t Enc28J60Network::getrev(void) +{ + initSPI(); + return readReg(EREVID); +} + +uint16_t Enc28J60Network::chksum(uint16_t sum, memhandle handle, memaddress pos, uint16_t len) +{ + uint16_t t; + len = setReadPtr(handle, pos, len) - 1; + CSACTIVE; + bitbang_transfer(ENC28J60_READ_BUF_MEM); + uint16_t i; + for (i = 0; i < len; i += 2) + { + t = bitbang_transfer(0x00) << 8; + t += bitbang_transfer(0x00); + sum += t; + if (sum < t) sum++; + } + if (i == len) + { + t = (bitbang_transfer(0x00) << 8) + 0; + sum += t; + if (sum < t) sum++; + } + CSPASSIVE; + return sum; +} + +void Enc28J60Network::powerOff() +{ + writeOp(ENC28J60_BIT_FIELD_CLR, ECON1, ECON1_RXEN); + delay(50); + writeOp(ENC28J60_BIT_FIELD_SET, ECON2, ECON2_VRPS); + delay(50); + writeOp(ENC28J60_BIT_FIELD_SET, ECON2, ECON2_PWRSV); +} + +void Enc28J60Network::powerOn() +{ + writeOp(ENC28J60_BIT_FIELD_CLR, ECON2, ECON2_PWRSV); + delay(50); + writeOp(ENC28J60_BIT_FIELD_SET, ECON1, ECON1_RXEN); + delay(50); +} + +bool Enc28J60Network::linkStatus() +{ + return (phyRead(PHSTAT2) & 0x0400) > 0; +} diff --git a/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/Enc28J60Network.h b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/Enc28J60Network.h new file mode 100644 index 0000000..f35801b --- /dev/null +++ b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/Enc28J60Network.h @@ -0,0 +1,94 @@ +/* + Enc28J60NetworkClass.h + UIPEthernet network driver for Microchip ENC28J60 Ethernet Interface. + + Copyright (c) 2013 Norbert Truchsess + All rights reserved. + + inspired by enc28j60.c file from the AVRlib library by Pascal Stang. + For AVRlib See http://www.procyonengineering.com/ + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +#ifndef Enc28J60Network_H_ +#define Enc28J60Network_H_ + +#include "mempool.h" + +#define UIP_RECEIVEBUFFERHANDLE 0xff + +#define UIP_SENDBUFFER_PADDING 7 +#define UIP_SENDBUFFER_OFFSET 1 + +#define TX_COLLISION_RETRY_COUNT 3 + +//#define ENC28J60DEBUG + +/* + * Empfangen von ip-header, arp etc... + * wenn tcp/udp -> tcp/udp-callback -> assign new packet to connection + */ + +class Enc28J60Network : public MemoryPool +{ + +private: + static uint8_t csPin; + static bool spiInitialized; + + static uint16_t nextPacketPtr; + static uint8_t bank; + + static struct memblock receivePkt; + + static uint8_t readOp(uint8_t op, uint8_t address); + static void writeOp(uint8_t op, uint8_t address, uint8_t data); + static uint16_t setReadPtr(memhandle handle, memaddress position, uint16_t len); + static void setERXRDPT(); + static void readBuffer(uint16_t len, uint8_t* data); + static void writeBuffer(uint16_t len, uint8_t* data); + static uint8_t readByte(uint16_t addr); + static void writeByte(uint16_t addr, uint8_t data); + static void setBank(uint8_t address); + static uint8_t readReg(uint8_t address); + static void writeReg(uint8_t address, uint8_t data); + static void writeRegPair(uint8_t address, uint16_t data); + static void phyWrite(uint8_t address, uint16_t data); + static uint16_t phyRead(uint8_t address); + static void clkout(uint8_t clk); + + friend void enc28J60_mempool_block_move_callback(memaddress,memaddress,memaddress); + +public: + + static uint8_t getrev(void); + static void powerOn(); + static void powerOff(); + static bool linkStatus(); + + static void setCsPin(uint8_t _csPin) {csPin = _csPin;} + static void initSPI(); + static bool init(uint8_t* macaddr); + static memhandle receivePacket(); + static void freePacket(); + static memaddress blockSize(memhandle handle); + static bool sendPacket(memhandle handle); + static uint16_t readPacket(memhandle handle, memaddress position, uint8_t* buffer, uint16_t len); + static uint16_t writePacket(memhandle handle, memaddress position, uint8_t* buffer, uint16_t len); + static void copyPacket(memhandle dest, memaddress dest_pos, memhandle src, memaddress src_pos, uint16_t len); + static uint16_t chksum(uint16_t sum, memhandle handle, memaddress pos, uint16_t len); +}; + +#endif /* Enc28J60NetworkClass_H_ */ diff --git a/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/enc28j60.h b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/enc28j60.h new file mode 100644 index 0000000..3a45c59 --- /dev/null +++ b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/enc28j60.h @@ -0,0 +1,257 @@ +/***************************************************************************** +* +* Title : Microchip ENC28J60 Ethernet Interface Driver +* Author : Pascal Stang (c)2005 +* Modified by Norbert Truchsess +* Copyright: GPL V2 +* +*This driver provides initialization and transmit/receive +*functions for the Microchip ENC28J60 10Mb Ethernet Controller and PHY. +*This chip is novel in that it is a full MAC+PHY interface all in a 28-pin +*chip, using an SPI interface to the host processor. +* +* +*****************************************************************************/ + +#ifndef ENC28J60_H +#define ENC28J60_H +#include + +// ENC28J60 Control Registers +// Control register definitions are a combination of address, +// bank number, and Ethernet/MAC/PHY indicator bits. +// - Register address (bits 0-4) +// - Bank number (bits 5-6) +// - MAC/PHY indicator (bit 7) +#define ADDR_MASK 0x1F +#define BANK_MASK 0x60 +#define SPRD_MASK 0x80 +// All-bank registers +#define EIE 0x1B +#define EIR 0x1C +#define ESTAT 0x1D +#define ECON2 0x1E +#define ECON1 0x1F +// Bank 0 registers +#define ERDPTL (0x00|0x00) +#define ERDPTH (0x01|0x00) +#define EWRPTL (0x02|0x00) +#define EWRPTH (0x03|0x00) +#define ETXSTL (0x04|0x00) +#define ETXSTH (0x05|0x00) +#define ETXNDL (0x06|0x00) +#define ETXNDH (0x07|0x00) +#define ERXSTL (0x08|0x00) +#define ERXSTH (0x09|0x00) +#define ERXNDL (0x0A|0x00) +#define ERXNDH (0x0B|0x00) +#define ERXRDPTL (0x0C|0x00) +#define ERXRDPTH (0x0D|0x00) +#define ERXWRPTL (0x0E|0x00) +#define ERXWRPTH (0x0F|0x00) +#define EDMASTL (0x10|0x00) +#define EDMASTH (0x11|0x00) +#define EDMANDL (0x12|0x00) +#define EDMANDH (0x13|0x00) +#define EDMADSTL (0x14|0x00) +#define EDMADSTH (0x15|0x00) +#define EDMACSL (0x16|0x00) +#define EDMACSH (0x17|0x00) +// Bank 1 registers +#define EHT0 (0x00|0x20) +#define EHT1 (0x01|0x20) +#define EHT2 (0x02|0x20) +#define EHT3 (0x03|0x20) +#define EHT4 (0x04|0x20) +#define EHT5 (0x05|0x20) +#define EHT6 (0x06|0x20) +#define EHT7 (0x07|0x20) +#define EPMM0 (0x08|0x20) +#define EPMM1 (0x09|0x20) +#define EPMM2 (0x0A|0x20) +#define EPMM3 (0x0B|0x20) +#define EPMM4 (0x0C|0x20) +#define EPMM5 (0x0D|0x20) +#define EPMM6 (0x0E|0x20) +#define EPMM7 (0x0F|0x20) +#define EPMCSL (0x10|0x20) +#define EPMCSH (0x11|0x20) +#define EPMOL (0x14|0x20) +#define EPMOH (0x15|0x20) +#define EWOLIE (0x16|0x20) +#define EWOLIR (0x17|0x20) +#define ERXFCON (0x18|0x20) +#define EPKTCNT (0x19|0x20) +// Bank 2 registers +#define MACON1 (0x00|0x40|0x80) +#define MACON2 (0x01|0x40|0x80) +#define MACON3 (0x02|0x40|0x80) +#define MACON4 (0x03|0x40|0x80) +#define MABBIPG (0x04|0x40|0x80) +#define MAIPGL (0x06|0x40|0x80) +#define MAIPGH (0x07|0x40|0x80) +#define MACLCON1 (0x08|0x40|0x80) +#define MACLCON2 (0x09|0x40|0x80) +#define MAMXFLL (0x0A|0x40|0x80) +#define MAMXFLH (0x0B|0x40|0x80) +#define MAPHSUP (0x0D|0x40|0x80) +#define MICON (0x11|0x40|0x80) +#define MICMD (0x12|0x40|0x80) +#define MIREGADR (0x14|0x40|0x80) +#define MIWRL (0x16|0x40|0x80) +#define MIWRH (0x17|0x40|0x80) +#define MIRDL (0x18|0x40|0x80) +#define MIRDH (0x19|0x40|0x80) +// Bank 3 registers +#define MAADR1 (0x00|0x60|0x80) +#define MAADR0 (0x01|0x60|0x80) +#define MAADR3 (0x02|0x60|0x80) +#define MAADR2 (0x03|0x60|0x80) +#define MAADR5 (0x04|0x60|0x80) +#define MAADR4 (0x05|0x60|0x80) +#define EBSTSD (0x06|0x60) +#define EBSTCON (0x07|0x60) +#define EBSTCSL (0x08|0x60) +#define EBSTCSH (0x09|0x60) +#define MISTAT (0x0A|0x60|0x80) +#define EREVID (0x12|0x60) +#define ECOCON (0x15|0x60) +#define EFLOCON (0x17|0x60) +#define EPAUSL (0x18|0x60) +#define EPAUSH (0x19|0x60) +// PHY registers +#define PHCON1 0x00 +#define PHSTAT1 0x01 +#define PHHID1 0x02 +#define PHHID2 0x03 +#define PHCON2 0x10 +#define PHSTAT2 0x11 +#define PHIE 0x12 +#define PHIR 0x13 +#define PHLCON 0x14 + +// ENC28J60 ERXFCON Register Bit Definitions +#define ERXFCON_UCEN 0x80 +#define ERXFCON_ANDOR 0x40 +#define ERXFCON_CRCEN 0x20 +#define ERXFCON_PMEN 0x10 +#define ERXFCON_MPEN 0x08 +#define ERXFCON_HTEN 0x04 +#define ERXFCON_MCEN 0x02 +#define ERXFCON_BCEN 0x01 +// ENC28J60 EIE Register Bit Definitions +#define EIE_INTIE 0x80 +#define EIE_PKTIE 0x40 +#define EIE_DMAIE 0x20 +#define EIE_LINKIE 0x10 +#define EIE_TXIE 0x08 +#define EIE_WOLIE 0x04 +#define EIE_TXERIE 0x02 +#define EIE_RXERIE 0x01 +// ENC28J60 EIR Register Bit Definitions +#define EIR_PKTIF 0x40 +#define EIR_DMAIF 0x20 +#define EIR_LINKIF 0x10 +#define EIR_TXIF 0x08 +#define EIR_WOLIF 0x04 +#define EIR_TXERIF 0x02 +#define EIR_RXERIF 0x01 +// ENC28J60 ESTAT Register Bit Definitions +#define ESTAT_INT 0x80 +#define ESTAT_LATECOL 0x10 +#define ESTAT_RXBUSY 0x04 +#define ESTAT_TXABRT 0x02 +#define ESTAT_CLKRDY 0x01 +// ENC28J60 ECON2 Register Bit Definitions +#define ECON2_AUTOINC 0x80 +#define ECON2_PKTDEC 0x40 +#define ECON2_PWRSV 0x20 +#define ECON2_VRPS 0x08 +// ENC28J60 ECON1 Register Bit Definitions +#define ECON1_TXRST 0x80 +#define ECON1_RXRST 0x40 +#define ECON1_DMAST 0x20 +#define ECON1_CSUMEN 0x10 +#define ECON1_TXRTS 0x08 +#define ECON1_RXEN 0x04 +#define ECON1_BSEL1 0x02 +#define ECON1_BSEL0 0x01 +// ENC28J60 MACON1 Register Bit Definitions +#define MACON1_LOOPBK 0x10 +#define MACON1_TXPAUS 0x08 +#define MACON1_RXPAUS 0x04 +#define MACON1_PASSALL 0x02 +#define MACON1_MARXEN 0x01 +// ENC28J60 MACON2 Register Bit Definitions +#define MACON2_MARST 0x80 +#define MACON2_RNDRST 0x40 +#define MACON2_MARXRST 0x08 +#define MACON2_RFUNRST 0x04 +#define MACON2_MATXRST 0x02 +#define MACON2_TFUNRST 0x01 +// ENC28J60 MACON3 Register Bit Definitions +#define MACON3_PADCFG2 0x80 +#define MACON3_PADCFG1 0x40 +#define MACON3_PADCFG0 0x20 +#define MACON3_TXCRCEN 0x10 +#define MACON3_PHDRLEN 0x08 +#define MACON3_HFRMLEN 0x04 +#define MACON3_FRMLNEN 0x02 +#define MACON3_FULDPX 0x01 +// ENC28J60 MICMD Register Bit Definitions +#define MICMD_MIISCAN 0x02 +#define MICMD_MIIRD 0x01 +// ENC28J60 MISTAT Register Bit Definitions +#define MISTAT_NVALID 0x04 +#define MISTAT_SCAN 0x02 +#define MISTAT_BUSY 0x01 +// ENC28J60 PHY PHCON1 Register Bit Definitions +#define PHCON1_PRST 0x8000 +#define PHCON1_PLOOPBK 0x4000 +#define PHCON1_PPWRSV 0x0800 +#define PHCON1_PDPXMD 0x0100 +// ENC28J60 PHY PHSTAT1 Register Bit Definitions +#define PHSTAT1_PFDPX 0x1000 +#define PHSTAT1_PHDPX 0x0800 +#define PHSTAT1_LLSTAT 0x0004 +#define PHSTAT1_JBSTAT 0x0002 +// ENC28J60 PHY PHCON2 Register Bit Definitions +#define PHCON2_FRCLINK 0x4000 +#define PHCON2_TXDIS 0x2000 +#define PHCON2_JABBER 0x0400 +#define PHCON2_HDLDIS 0x0100 + +// ENC28J60 Packet Control Byte Bit Definitions +#define PKTCTRL_PHUGEEN 0x08 +#define PKTCTRL_PPADEN 0x04 +#define PKTCTRL_PCRCEN 0x02 +#define PKTCTRL_POVERRIDE 0x01 + +// SPI operation codes +#define ENC28J60_READ_CTRL_REG 0x00 +#define ENC28J60_READ_BUF_MEM 0x3A +#define ENC28J60_WRITE_CTRL_REG 0x40 +#define ENC28J60_WRITE_BUF_MEM 0x7A +#define ENC28J60_BIT_FIELD_SET 0x80 +#define ENC28J60_BIT_FIELD_CLR 0xA0 +#define ENC28J60_SOFT_RESET 0xFF + + +// The RXSTART_INIT should be zero. See Rev. B4 Silicon Errata +// buffer boundaries applied to internal 8K ram +// the entire available packet buffer space is allocated +// +// start with recbuf at 0/ +#define RXSTART_INIT 0x0 +// receive buffer end. make sure this is an odd value ( See Rev. B1,B4,B5,B7 Silicon Errata 'Memory (Ethernet Buffer)') +#define RXSTOP_INIT (0x1FFF-0x1800) +// start TX buffer RXSTOP_INIT+1 +#define TXSTART_INIT (RXSTOP_INIT+1) +// stp TX buffer at end of mem +#define TXSTOP_INIT 0x1FFF +// +// max frame length which the conroller will accept: +#define MAX_FRAMELEN 1500 // (note: maximum ethernet frame length would be 1518) +//#define MAX_FRAMELEN 600 + +#endif diff --git a/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/mempool.cpp b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/mempool.cpp new file mode 100644 index 0000000..c2f7abf --- /dev/null +++ b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/mempool.cpp @@ -0,0 +1,168 @@ +/* + mempool.cpp - sleek implementation of a memory pool + Copyright (c) 2013 Norbert Truchsess + All rights reserved. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +#include "mempool.h" +#include + +#define POOLOFFSET 1 + +struct memblock MemoryPool::blocks[MEMPOOL_NUM_MEMBLOCKS+1]; + +void +MemoryPool::init() +{ + memset(&blocks[0], 0, sizeof(blocks)); + blocks[POOLSTART].begin = MEMPOOL_STARTADDRESS; + blocks[POOLSTART].size = 0; + blocks[POOLSTART].nextblock = NOBLOCK; +} + +memhandle +MemoryPool::allocBlock(memaddress size) +{ + memblock* best = NULL; + memhandle cur = POOLSTART; + memblock* block = &blocks[POOLSTART]; + memaddress bestsize = MEMPOOL_SIZE + 1; + + do + { + memhandle next = block->nextblock; + memaddress freesize = ( next == NOBLOCK ? blocks[POOLSTART].begin + MEMPOOL_SIZE : blocks[next].begin) - block->begin - block->size; + if (freesize == size) + { + best = &blocks[cur]; + goto found; + } + if (freesize > size && freesize < bestsize) + { + bestsize = freesize; + best = &blocks[cur]; + } + if (next == NOBLOCK) + { + if (best) + goto found; + else + goto collect; + } + block = &blocks[next]; + cur = next; + } + while (true); + + collect: + { + cur = POOLSTART; + block = &blocks[POOLSTART]; + memhandle next; + while ((next = block->nextblock) != NOBLOCK) + { + memaddress dest = block->begin + block->size; + memblock* nextblock = &blocks[next]; + memaddress* src = &nextblock->begin; + if (dest != *src) + { +#ifdef MEMPOOL_MEMBLOCK_MV + MEMPOOL_MEMBLOCK_MV(dest,*src,nextblock->size); +#endif + *src = dest; + } + block = nextblock; + } + if (blocks[POOLSTART].begin + MEMPOOL_SIZE - block->begin - block->size >= size) + best = block; + else + goto notfound; + } + + found: + { + block = &blocks[POOLOFFSET]; + for (cur = POOLOFFSET; cur < MEMPOOL_NUM_MEMBLOCKS + POOLOFFSET; cur++) + { + if (block->size) + { + block++; + continue; + } + memaddress address = best->begin + best->size; +#ifdef MEMBLOCK_ALLOC + MEMBLOCK_ALLOC(address,size); +#endif + block->begin = address; + block->size = size; + block->nextblock = best->nextblock; + best->nextblock = cur; + return cur; + } + } + + notfound: return NOBLOCK; +} + +void +MemoryPool::freeBlock(memhandle handle) +{ + if (handle == NOBLOCK) + return; + memblock *b = &blocks[POOLSTART]; + + do + { + memhandle next = b->nextblock; + if (next == handle) + { + memblock *f = &blocks[next]; +#ifdef MEMBLOCK_FREE + MEMBLOCK_FREE(f->begin,f->size); +#endif + b->nextblock = f->nextblock; + f->size = 0; + f->nextblock = NOBLOCK; + return; + } + if (next == NOBLOCK) + return; + b = &blocks[next]; + } + while (true); +} + +void +MemoryPool::resizeBlock(memhandle handle, memaddress position) +{ + memblock * block = &blocks[handle]; + block->begin += position; + block->size -= position; +} + +void +MemoryPool::resizeBlock(memhandle handle, memaddress position, memaddress size) +{ + memblock * block = &blocks[handle]; + block->begin += position; + block->size = size; +} + +memaddress +MemoryPool::blockSize(memhandle handle) +{ + return blocks[handle].size; +} diff --git a/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/mempool.h b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/mempool.h new file mode 100644 index 0000000..2a1db21 --- /dev/null +++ b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/mempool.h @@ -0,0 +1,54 @@ +/* + mempool.h - sleek implementation of a memory pool + Copyright (c) 2013 Norbert Truchsess + All rights reserved. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +#ifndef MEMPOOL_H +#define MEMPOOL_H + +#include + +#define POOLSTART 0 +#define NOBLOCK 0 + +#include "mempool_conf.h" + +struct memblock +{ + memaddress begin; + memaddress size; + memhandle nextblock; +}; + +class MemoryPool +{ +#ifdef MEMPOOLTEST_H + friend class MemoryPoolTest; +#endif + +protected: + static struct memblock blocks[MEMPOOL_NUM_MEMBLOCKS+1]; + +public: + static void init(); + static memhandle allocBlock(memaddress); + static void freeBlock(memhandle); + static void resizeBlock(memhandle handle, memaddress position); + static void resizeBlock(memhandle handle, memaddress position, memaddress size); + static memaddress blockSize(memhandle); +}; +#endif diff --git a/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/mempool_conf.h b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/mempool_conf.h new file mode 100644 index 0000000..5f953dd --- /dev/null +++ b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/mempool_conf.h @@ -0,0 +1,34 @@ +#ifndef MEMPOOLCONF_H +#define MEMPOOLCONF_H +#include "uipethernet-conf.h" +extern "C" { + #include "uipopt.h" + #include "enc28j60.h" +} +#include + +typedef uint16_t memaddress; +typedef uint8_t memhandle; + +#if UIP_SOCKET_NUMPACKETS and UIP_CONNS +#define NUM_TCP_MEMBLOCKS (UIP_SOCKET_NUMPACKETS*2)*UIP_CONNS +#else +#define NUM_TCP_MEMBLOCKS 0 +#endif + +#if UIP_UDP and UIP_UDP_CONNS +#define NUM_UDP_MEMBLOCKS ((2+UIP_UDP_BACKLOG)*UIP_UDP_CONNS) +#else +#define NUM_UDP_MEMBLOCKS 0 +#endif + +#define MEMPOOL_NUM_MEMBLOCKS (NUM_TCP_MEMBLOCKS+NUM_UDP_MEMBLOCKS) + +#define MEMPOOL_STARTADDRESS TXSTART_INIT+1 +#define MEMPOOL_SIZE TXSTOP_INIT-TXSTART_INIT + +void enc28J60_mempool_block_move_callback(memaddress,memaddress,memaddress); + +#define MEMPOOL_MEMBLOCK_MV(dest,src,size) enc28J60_mempool_block_move_callback(dest,src,size) + +#endif diff --git a/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/uip-conf.h b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/uip-conf.h new file mode 100644 index 0000000..a6242c4 --- /dev/null +++ b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/uip-conf.h @@ -0,0 +1,185 @@ +/** + * UIPEthernet Project-specific configuration options + * Copyright (c) 2013 Norbert Truchsess + * @{ + * + * uIP has a number of configuration options that can be overridden + * for each project. These are kept in a project-specific uip-conf.h + * file and all configuration names have the prefix UIP_CONF. + */ + +/* + * Copyright (c) 2006, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the uIP TCP/IP stack + * + */ + +#ifndef __UIP_CONF_H__ +#define __UIP_CONF_H__ + +#include +#include "uipethernet-conf.h" + +/** + * 8 bit datatype + * + * This typedef defines the 8-bit type used throughout uIP. + * + * \hideinitializer + */ +typedef uint8_t u8_t; + +/** + * 16 bit datatype + * + * This typedef defines the 16-bit type used throughout uIP. + * + * \hideinitializer + */ +typedef uint16_t u16_t; + +/** + * Statistics datatype + * + * This typedef defines the dataype used for keeping statistics in + * uIP. + * + * \hideinitializer + */ +typedef unsigned short uip_stats_t; + +/** + * Maximum number of TCP connections. + * (see uipethernet-conf.h) + * \hideinitializer + * + * #define UIP_CONF_MAX_CONNECTIONS 4 + */ + +/** + * Maximum number of listening TCP ports. + * + * \hideinitializer + */ +#define UIP_CONF_MAX_LISTENPORTS 4 + +/** + * uIP buffer size. + * + * \hideinitializer + */ +#define UIP_CONF_BUFFER_SIZE 98 +//#define UIP_CONF_BUFFER_SIZE 118 + +/** + * The TCP maximum segment size. + * + * This is should not be to set to more than + * UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN. + */ + +#define UIP_CONF_TCP_MSS 512 + +/** + * The size of the advertised receiver's window. + * + * Should be set low (i.e., to the size of the uip_buf buffer) is the + * application is slow to process incoming data, or high (32768 bytes) + * if the application processes data quickly. + * + * \hideinitializer + */ +#define UIP_CONF_RECEIVE_WINDOW 512 + +/** + * CPU byte order. + * + * \hideinitializer + */ +#define UIP_CONF_BYTE_ORDER __BYTE_ORDER__ + +/** + * Logging on or off + * + * \hideinitializer + */ +#define UIP_CONF_LOGGING 0 + +/** + * UDP support on or off + * (see uipethernet-conf.h) + * \hideinitializer + * + * #define UIP_CONF_UDP 1 + * + * #define UIP_CONF_UDP_CONNS 4 + */ + +/** + * UDP checksums on or off + * + * \hideinitializer + */ +#define UIP_CONF_UDP_CHECKSUMS 1 + +/** + * UDP Broadcast (receive) on or off + * (see uipethernet-conf.h) + * \hideinitializer + */ +#define UIP_CONF_BROADCAST 1 + + +/** + * uIP statistics on or off + * + * \hideinitializer + */ +#define UIP_CONF_STATISTICS 0 + +// SLIP +//#define UIP_CONF_LLH_LEN 0 + +typedef void* uip_tcp_appstate_t; + +void uipclient_appcall(void); + +#define UIP_APPCALL uipclient_appcall + +typedef void* uip_udp_appstate_t; + +void uipudp_appcall(void); + +#define UIP_UDP_APPCALL uipudp_appcall + +#define CC_REGISTER_ARG register + +#define UIP_ARCH_CHKSUM 1 + +#endif /* __UIP_CONF_H__ */ diff --git a/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/uip.c b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/uip.c new file mode 100644 index 0000000..84ea8c3 --- /dev/null +++ b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/uip.c @@ -0,0 +1,1897 @@ +#define DEBUG_PRINTF(...) /*printf(__VA_ARGS__)*/ + +/** + * \defgroup uip The uIP TCP/IP stack + * @{ + * + * uIP is an implementation of the TCP/IP protocol stack intended for + * small 8-bit and 16-bit microcontrollers. + * + * uIP provides the necessary protocols for Internet communication, + * with a very small code footprint and RAM requirements - the uIP + * code size is on the order of a few kilobytes and RAM usage is on + * the order of a few hundred bytes. + */ + +/** + * \file + * The uIP TCP/IP stack code. + * \author Adam Dunkels + */ + +/* + * Copyright (c) 2001-2003, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This file is part of the uIP TCP/IP stack. + * + * $Id: uip.c,v 1.65 2006/06/11 21:46:39 adam Exp $ + * + */ + +/* + * uIP is a small implementation of the IP, UDP and TCP protocols (as + * well as some basic ICMP stuff). The implementation couples the IP, + * UDP, TCP and the application layers very tightly. To keep the size + * of the compiled code down, this code frequently uses the goto + * statement. While it would be possible to break the uip_process() + * function into many smaller functions, this would increase the code + * size because of the overhead of parameter passing and the fact that + * the optimier would not be as efficient. + * + * The principle is that we have a small buffer, called the uip_buf, + * in which the device driver puts an incoming packet. The TCP/IP + * stack parses the headers in the packet, and calls the + * application. If the remote host has sent data to the application, + * this data is present in the uip_buf and the application read the + * data from there. It is up to the application to put this data into + * a byte stream if needed. The application will not be fed with data + * that is out of sequence. + * + * If the application whishes to send data to the peer, it should put + * its data into the uip_buf. The uip_appdata pointer points to the + * first available byte. The TCP/IP stack will calculate the + * checksums, and fill in the necessary header fields and finally send + * the packet back to the peer. +*/ + +#include "uip.h" +#include "uipopt.h" +#include "uip_arch.h" + +#if UIP_CONF_IPV6 +#include "uip-neighbor.h" +#endif /* UIP_CONF_IPV6 */ + +#include + +/*---------------------------------------------------------------------------*/ +/* Variable definitions. */ + + +/* The IP address of this host. If it is defined to be fixed (by + setting UIP_FIXEDADDR to 1 in uipopt.h), the address is set + here. Otherwise, the address */ +#if UIP_FIXEDADDR > 0 +const uip_ipaddr_t uip_hostaddr = + {HTONS((UIP_IPADDR0 << 8) | UIP_IPADDR1), + HTONS((UIP_IPADDR2 << 8) | UIP_IPADDR3)}; +const uip_ipaddr_t uip_draddr = + {HTONS((UIP_DRIPADDR0 << 8) | UIP_DRIPADDR1), + HTONS((UIP_DRIPADDR2 << 8) | UIP_DRIPADDR3)}; +const uip_ipaddr_t uip_netmask = + {HTONS((UIP_NETMASK0 << 8) | UIP_NETMASK1), + HTONS((UIP_NETMASK2 << 8) | UIP_NETMASK3)}; +#else +uip_ipaddr_t uip_hostaddr, uip_draddr, uip_netmask; +#endif /* UIP_FIXEDADDR */ + +static const uip_ipaddr_t all_ones_addr = +#if UIP_CONF_IPV6 + {0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff}; +#else /* UIP_CONF_IPV6 */ + {0xffff,0xffff}; +#endif /* UIP_CONF_IPV6 */ +static const uip_ipaddr_t all_zeroes_addr = +#if UIP_CONF_IPV6 + {0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000}; +#else /* UIP_CONF_IPV6 */ + {0x0000,0x0000}; +#endif /* UIP_CONF_IPV6 */ + + +#if UIP_FIXEDETHADDR +const struct uip_eth_addr uip_ethaddr = {{UIP_ETHADDR0, + UIP_ETHADDR1, + UIP_ETHADDR2, + UIP_ETHADDR3, + UIP_ETHADDR4, + UIP_ETHADDR5}}; +#else +struct uip_eth_addr uip_ethaddr = {{0,0,0,0,0,0}}; +#endif + +#ifndef UIP_CONF_EXTERNAL_BUFFER +u8_t uip_buf[UIP_BUFSIZE + 2]; /* The packet buffer that contains + incoming packets. */ +#endif /* UIP_CONF_EXTERNAL_BUFFER */ + +void *uip_appdata; /* The uip_appdata pointer points to + application data. */ +void *uip_sappdata; /* The uip_appdata pointer points to + the application data which is to + be sent. */ +#if UIP_URGDATA > 0 +void *uip_urgdata; /* The uip_urgdata pointer points to + urgent data (out-of-band data), if + present. */ +u16_t uip_urglen, uip_surglen; +#endif /* UIP_URGDATA > 0 */ + +u16_t uip_len, uip_slen; + /* The uip_len is either 8 or 16 bits, + depending on the maximum packet + size. */ + +u8_t uip_flags; /* The uip_flags variable is used for + communication between the TCP/IP stack + and the application program. */ +struct uip_conn *uip_conn; /* uip_conn always points to the current + connection. */ + +struct uip_conn uip_conns[UIP_CONNS]; + /* The uip_conns array holds all TCP + connections. */ +u16_t uip_listenports[UIP_LISTENPORTS]; + /* The uip_listenports list all currently + listning ports. */ +#if UIP_UDP +struct uip_udp_conn *uip_udp_conn; +struct uip_udp_conn uip_udp_conns[UIP_UDP_CONNS]; +#endif /* UIP_UDP */ + +static u16_t ipid; /* Ths ipid variable is an increasing + number that is used for the IP ID + field. */ + +void uip_setipid(u16_t id) { ipid = id; } + +static u8_t iss[4]; /* The iss variable is used for the TCP + initial sequence number. */ + +#if UIP_ACTIVE_OPEN +static u16_t lastport; /* Keeps track of the last port used for + a new connection. */ +#endif /* UIP_ACTIVE_OPEN */ + +/* Temporary variables. */ +u8_t uip_acc32[4]; +static u8_t c, opt; +static u16_t tmp16; + +/* Structures and definitions. */ +#define TCP_FIN 0x01 +#define TCP_SYN 0x02 +#define TCP_RST 0x04 +#define TCP_PSH 0x08 +#define TCP_ACK 0x10 +#define TCP_URG 0x20 +#define TCP_CTL 0x3f + +#define TCP_OPT_END 0 /* End of TCP options list */ +#define TCP_OPT_NOOP 1 /* "No-operation" TCP option */ +#define TCP_OPT_MSS 2 /* Maximum segment size TCP option */ + +#define TCP_OPT_MSS_LEN 4 /* Length of TCP MSS option. */ + +#define ICMP_ECHO_REPLY 0 +#define ICMP_ECHO 8 + +#define ICMP6_ECHO_REPLY 129 +#define ICMP6_ECHO 128 +#define ICMP6_NEIGHBOR_SOLICITATION 135 +#define ICMP6_NEIGHBOR_ADVERTISEMENT 136 + +#define ICMP6_FLAG_S (1 << 6) + +#define ICMP6_OPTION_SOURCE_LINK_ADDRESS 1 +#define ICMP6_OPTION_TARGET_LINK_ADDRESS 2 + + +/* Macros. */ +#define BUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN]) +#define FBUF ((struct uip_tcpip_hdr *)&uip_reassbuf[0]) +#define ICMPBUF ((struct uip_icmpip_hdr *)&uip_buf[UIP_LLH_LEN]) +#define UDPBUF ((struct uip_udpip_hdr *)&uip_buf[UIP_LLH_LEN]) + + +#if UIP_STATISTICS == 1 +struct uip_stats uip_stat; +#define UIP_STAT(s) s +#else +#define UIP_STAT(s) +#endif /* UIP_STATISTICS == 1 */ + +#if UIP_LOGGING == 1 +#include +void uip_log(char *msg); +#define UIP_LOG(m) uip_log(m) +#else +#define UIP_LOG(m) +#endif /* UIP_LOGGING == 1 */ + +#if ! UIP_ARCH_ADD32 +void +uip_add32(u8_t *op32, u16_t op16) +{ + uip_acc32[3] = op32[3] + (op16 & 0xff); + uip_acc32[2] = op32[2] + (op16 >> 8); + uip_acc32[1] = op32[1]; + uip_acc32[0] = op32[0]; + + if(uip_acc32[2] < (op16 >> 8)) { + ++uip_acc32[1]; + if(uip_acc32[1] == 0) { + ++uip_acc32[0]; + } + } + + + if(uip_acc32[3] < (op16 & 0xff)) { + ++uip_acc32[2]; + if(uip_acc32[2] == 0) { + ++uip_acc32[1]; + if(uip_acc32[1] == 0) { + ++uip_acc32[0]; + } + } + } +} + +#endif /* UIP_ARCH_ADD32 */ + +#if ! UIP_ARCH_CHKSUM +/*---------------------------------------------------------------------------*/ +static u16_t +chksum(u16_t sum, const u8_t *data, u16_t len) +{ + u16_t t; + const u8_t *dataptr; + const u8_t *last_byte; + + dataptr = data; + last_byte = data + len - 1; + + while(dataptr < last_byte) { /* At least two more bytes */ + t = (dataptr[0] << 8) + dataptr[1]; + sum += t; + if(sum < t) { + sum++; /* carry */ + } + dataptr += 2; + } + + if(dataptr == last_byte) { + t = (dataptr[0] << 8) + 0; + sum += t; + if(sum < t) { + sum++; /* carry */ + } + } + + /* Return sum in host byte order. */ + return sum; +} +/*---------------------------------------------------------------------------*/ +u16_t +uip_chksum(u16_t *data, u16_t len) +{ + return htons(chksum(0, (u8_t *)data, len)); +} +/*---------------------------------------------------------------------------*/ +#ifndef UIP_ARCH_IPCHKSUM +u16_t +uip_ipchksum(void) +{ + u16_t sum; + + sum = chksum(0, &uip_buf[UIP_LLH_LEN], UIP_IPH_LEN); + DEBUG_PRINTF("uip_ipchksum: sum 0x%04x\n", sum); + return (sum == 0) ? 0xffff : htons(sum); +} +#endif +/*---------------------------------------------------------------------------*/ +static u16_t +upper_layer_chksum(u8_t proto) +{ + u16_t upper_layer_len; + u16_t sum; + +#if UIP_CONF_IPV6 + upper_layer_len = (((u16_t)(BUF->len[0]) << 8) + BUF->len[1]); +#else /* UIP_CONF_IPV6 */ + upper_layer_len = (((u16_t)(BUF->len[0]) << 8) + BUF->len[1]) - UIP_IPH_LEN; +#endif /* UIP_CONF_IPV6 */ + + /* First sum pseudoheader. */ + + /* IP protocol and length fields. This addition cannot carry. */ + sum = upper_layer_len + proto; + /* Sum IP source and destination addresses. */ + sum = chksum(sum, (u8_t *)&BUF->srcipaddr[0], 2 * sizeof(uip_ipaddr_t)); + + /* Sum TCP header and data. */ + sum = chksum(sum, &uip_buf[UIP_IPH_LEN + UIP_LLH_LEN], + upper_layer_len); + + return (sum == 0) ? 0xffff : htons(sum); +} +/*---------------------------------------------------------------------------*/ +#if UIP_CONF_IPV6 +u16_t +uip_icmp6chksum(void) +{ + return upper_layer_chksum(UIP_PROTO_ICMP6); + +} +#endif /* UIP_CONF_IPV6 */ +/*---------------------------------------------------------------------------*/ +u16_t +uip_tcpchksum(void) +{ + return upper_layer_chksum(UIP_PROTO_TCP); +} +/*---------------------------------------------------------------------------*/ +#if UIP_UDP_CHECKSUMS +u16_t +uip_udpchksum(void) +{ + return upper_layer_chksum(UIP_PROTO_UDP); +} +#endif /* UIP_UDP_CHECKSUMS */ +#endif /* UIP_ARCH_CHKSUM */ +/*---------------------------------------------------------------------------*/ +void +uip_init(void) +{ + for(c = 0; c < UIP_LISTENPORTS; ++c) { + uip_listenports[c] = 0; + } + for(c = 0; c < UIP_CONNS; ++c) { + uip_conns[c].tcpstateflags = UIP_CLOSED; + } +#if UIP_ACTIVE_OPEN + lastport = 1024; +#endif /* UIP_ACTIVE_OPEN */ + +#if UIP_UDP + for(c = 0; c < UIP_UDP_CONNS; ++c) { + uip_udp_conns[c].lport = 0; + } +#endif /* UIP_UDP */ + + + /* IPv4 initialization. */ +#if UIP_FIXEDADDR == 0 + /* uip_hostaddr[0] = uip_hostaddr[1] = 0;*/ +#endif /* UIP_FIXEDADDR */ + +} +/*---------------------------------------------------------------------------*/ +#if UIP_ACTIVE_OPEN +struct uip_conn * +uip_connect(uip_ipaddr_t *ripaddr, u16_t rport) +{ + register struct uip_conn *conn, *cconn; + + /* Find an unused local port. */ + again: + ++lastport; + + if(lastport >= 32000) { + lastport = 4096; + } + + /* Check if this port is already in use, and if so try to find + another one. */ + for(c = 0; c < UIP_CONNS; ++c) { + conn = &uip_conns[c]; + if(conn->tcpstateflags != UIP_CLOSED && + conn->lport == htons(lastport)) { + goto again; + } + } + + conn = 0; + for(c = 0; c < UIP_CONNS; ++c) { + cconn = &uip_conns[c]; + if(cconn->tcpstateflags == UIP_CLOSED) { + conn = cconn; + break; + } + if(cconn->tcpstateflags == UIP_TIME_WAIT) { + if(conn == 0 || + cconn->timer > conn->timer) { + conn = cconn; + } + } + } + + if(conn == 0) { + return 0; + } + + conn->tcpstateflags = UIP_SYN_SENT; + + conn->snd_nxt[0] = iss[0]; + conn->snd_nxt[1] = iss[1]; + conn->snd_nxt[2] = iss[2]; + conn->snd_nxt[3] = iss[3]; + + conn->initialmss = conn->mss = UIP_TCP_MSS; + + conn->len = 1; /* TCP length of the SYN is one. */ + conn->nrtx = 0; + conn->timer = 1; /* Send the SYN next time around. */ + conn->rto = UIP_RTO; + conn->sa = 0; + conn->sv = 16; /* Initial value of the RTT variance. */ + conn->lport = htons(lastport); + conn->rport = rport; + uip_ipaddr_copy(&conn->ripaddr, ripaddr); + + return conn; +} +#endif /* UIP_ACTIVE_OPEN */ +/*---------------------------------------------------------------------------*/ +#if UIP_UDP +struct uip_udp_conn * +uip_udp_new(uip_ipaddr_t *ripaddr, u16_t rport) +{ + register struct uip_udp_conn *conn; + + /* Find an unused local port. */ + again: + ++lastport; + + if(lastport >= 32000) { + lastport = 4096; + } + + for(c = 0; c < UIP_UDP_CONNS; ++c) { + if(uip_udp_conns[c].lport == htons(lastport)) { + goto again; + } + } + + + conn = 0; + for(c = 0; c < UIP_UDP_CONNS; ++c) { + if(uip_udp_conns[c].lport == 0) { + conn = &uip_udp_conns[c]; + break; + } + } + + if(conn == 0) { + return 0; + } + + conn->lport = HTONS(lastport); + conn->rport = rport; + if(ripaddr == NULL) { + memset(conn->ripaddr, 0, sizeof(uip_ipaddr_t)); + } else { + uip_ipaddr_copy(&conn->ripaddr, ripaddr); + } + conn->ttl = UIP_TTL; + + return conn; +} +#endif /* UIP_UDP */ +/*---------------------------------------------------------------------------*/ +void +uip_unlisten(u16_t port) +{ + for(c = 0; c < UIP_LISTENPORTS; ++c) { + if(uip_listenports[c] == port) { + uip_listenports[c] = 0; + return; + } + } +} +/*---------------------------------------------------------------------------*/ +void +uip_listen(u16_t port) +{ + for(c = 0; c < UIP_LISTENPORTS; ++c) { + if(uip_listenports[c] == 0) { + uip_listenports[c] = port; + return; + } + } +} +/*---------------------------------------------------------------------------*/ +/* XXX: IP fragment reassembly: not well-tested. */ + +#if UIP_REASSEMBLY && !UIP_CONF_IPV6 +#define UIP_REASS_BUFSIZE (UIP_BUFSIZE - UIP_LLH_LEN) +static u8_t uip_reassbuf[UIP_REASS_BUFSIZE]; +static u8_t uip_reassbitmap[UIP_REASS_BUFSIZE / (8 * 8)]; +static const u8_t bitmap_bits[8] = {0xff, 0x7f, 0x3f, 0x1f, + 0x0f, 0x07, 0x03, 0x01}; +static u16_t uip_reasslen; +static u8_t uip_reassflags; +#define UIP_REASS_FLAG_LASTFRAG 0x01 +static u8_t uip_reasstmr; + +#define IP_MF 0x20 + +static u8_t +uip_reass(void) +{ + u16_t offset, len; + u16_t i; + + /* If ip_reasstmr is zero, no packet is present in the buffer, so we + write the IP header of the fragment into the reassembly + buffer. The timer is updated with the maximum age. */ + if(uip_reasstmr == 0) { + memcpy(uip_reassbuf, &BUF->vhl, UIP_IPH_LEN); + uip_reasstmr = UIP_REASS_MAXAGE; + uip_reassflags = 0; + /* Clear the bitmap. */ + memset(uip_reassbitmap, 0, sizeof(uip_reassbitmap)); + } + + /* Check if the incoming fragment matches the one currently present + in the reasembly buffer. If so, we proceed with copying the + fragment into the buffer. */ + if(BUF->srcipaddr[0] == FBUF->srcipaddr[0] && + BUF->srcipaddr[1] == FBUF->srcipaddr[1] && + BUF->destipaddr[0] == FBUF->destipaddr[0] && + BUF->destipaddr[1] == FBUF->destipaddr[1] && + BUF->ipid[0] == FBUF->ipid[0] && + BUF->ipid[1] == FBUF->ipid[1]) { + + len = (BUF->len[0] << 8) + BUF->len[1] - (BUF->vhl & 0x0f) * 4; + offset = (((BUF->ipoffset[0] & 0x3f) << 8) + BUF->ipoffset[1]) * 8; + + /* If the offset or the offset + fragment length overflows the + reassembly buffer, we discard the entire packet. */ + if(offset > UIP_REASS_BUFSIZE || + offset + len > UIP_REASS_BUFSIZE) { + uip_reasstmr = 0; + goto nullreturn; + } + + /* Copy the fragment into the reassembly buffer, at the right + offset. */ + memcpy(&uip_reassbuf[UIP_IPH_LEN + offset], + (char *)BUF + (int)((BUF->vhl & 0x0f) * 4), + len); + + /* Update the bitmap. */ + if(offset / (8 * 8) == (offset + len) / (8 * 8)) { + /* If the two endpoints are in the same byte, we only update + that byte. */ + + uip_reassbitmap[offset / (8 * 8)] |= + bitmap_bits[(offset / 8 ) & 7] & + ~bitmap_bits[((offset + len) / 8 ) & 7]; + } else { + /* If the two endpoints are in different bytes, we update the + bytes in the endpoints and fill the stuff inbetween with + 0xff. */ + uip_reassbitmap[offset / (8 * 8)] |= + bitmap_bits[(offset / 8 ) & 7]; + for(i = 1 + offset / (8 * 8); i < (offset + len) / (8 * 8); ++i) { + uip_reassbitmap[i] = 0xff; + } + uip_reassbitmap[(offset + len) / (8 * 8)] |= + ~bitmap_bits[((offset + len) / 8 ) & 7]; + } + + /* If this fragment has the More Fragments flag set to zero, we + know that this is the last fragment, so we can calculate the + size of the entire packet. We also set the + IP_REASS_FLAG_LASTFRAG flag to indicate that we have received + the final fragment. */ + + if((BUF->ipoffset[0] & IP_MF) == 0) { + uip_reassflags |= UIP_REASS_FLAG_LASTFRAG; + uip_reasslen = offset + len; + } + + /* Finally, we check if we have a full packet in the buffer. We do + this by checking if we have the last fragment and if all bits + in the bitmap are set. */ + if(uip_reassflags & UIP_REASS_FLAG_LASTFRAG) { + /* Check all bytes up to and including all but the last byte in + the bitmap. */ + for(i = 0; i < uip_reasslen / (8 * 8) - 1; ++i) { + if(uip_reassbitmap[i] != 0xff) { + goto nullreturn; + } + } + /* Check the last byte in the bitmap. It should contain just the + right amount of bits. */ + if(uip_reassbitmap[uip_reasslen / (8 * 8)] != + (u8_t)~bitmap_bits[uip_reasslen / 8 & 7]) { + goto nullreturn; + } + + /* If we have come this far, we have a full packet in the + buffer, so we allocate a pbuf and copy the packet into it. We + also reset the timer. */ + uip_reasstmr = 0; + memcpy(BUF, FBUF, uip_reasslen); + + /* Pretend to be a "normal" (i.e., not fragmented) IP packet + from now on. */ + BUF->ipoffset[0] = BUF->ipoffset[1] = 0; + BUF->len[0] = uip_reasslen >> 8; + BUF->len[1] = uip_reasslen & 0xff; + BUF->ipchksum = 0; + BUF->ipchksum = ~(uip_ipchksum()); + + return uip_reasslen; + } + } + + nullreturn: + return 0; +} +#endif /* UIP_REASSEMBLY */ +/*---------------------------------------------------------------------------*/ +static void +uip_add_rcv_nxt(u16_t n) +{ + uip_add32(uip_conn->rcv_nxt, n); + uip_conn->rcv_nxt[0] = uip_acc32[0]; + uip_conn->rcv_nxt[1] = uip_acc32[1]; + uip_conn->rcv_nxt[2] = uip_acc32[2]; + uip_conn->rcv_nxt[3] = uip_acc32[3]; +} +/*---------------------------------------------------------------------------*/ +void +uip_process(u8_t flag) +{ + register struct uip_conn *uip_connr = uip_conn; + +#if UIP_UDP + if(flag == UIP_UDP_SEND_CONN) { + goto udp_send; + } +#endif /* UIP_UDP */ + + uip_sappdata = uip_appdata = &uip_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN]; + + /* Check if we were invoked because of a poll request for a + particular connection. */ + if(flag == UIP_POLL_REQUEST) { + if((uip_connr->tcpstateflags & UIP_TS_MASK) == UIP_ESTABLISHED && + !uip_outstanding(uip_connr)) { + uip_flags = UIP_POLL; + UIP_APPCALL(); + goto appsend; + } + goto drop; + + /* Check if we were invoked because of the perodic timer fireing. */ + } else if(flag == UIP_TIMER) { +#if UIP_REASSEMBLY + if(uip_reasstmr != 0) { + --uip_reasstmr; + } +#endif /* UIP_REASSEMBLY */ + /* Increase the initial sequence number. */ + if(++iss[3] == 0) { + if(++iss[2] == 0) { + if(++iss[1] == 0) { + ++iss[0]; + } + } + } + + /* Reset the length variables. */ + uip_len = 0; + uip_slen = 0; + + /* Check if the connection is in a state in which we simply wait + for the connection to time out. If so, we increase the + connection's timer and remove the connection if it times + out. */ + if(uip_connr->tcpstateflags == UIP_TIME_WAIT || + uip_connr->tcpstateflags == UIP_FIN_WAIT_2) { + ++(uip_connr->timer); + if(uip_connr->timer == UIP_TIME_WAIT_TIMEOUT) { + uip_connr->tcpstateflags = UIP_CLOSED; + } + } else if(uip_connr->tcpstateflags != UIP_CLOSED) { + /* If the connection has outstanding data, we increase the + connection's timer and see if it has reached the RTO value + in which case we retransmit. */ + if(uip_outstanding(uip_connr)) { + if(uip_connr->timer-- == 0) { + if(uip_connr->nrtx == UIP_MAXRTX || + ((uip_connr->tcpstateflags == UIP_SYN_SENT || + uip_connr->tcpstateflags == UIP_SYN_RCVD) && + uip_connr->nrtx == UIP_MAXSYNRTX)) { + uip_connr->tcpstateflags = UIP_CLOSED; + + /* We call UIP_APPCALL() with uip_flags set to + UIP_TIMEDOUT to inform the application that the + connection has timed out. */ + uip_flags = UIP_TIMEDOUT; + UIP_APPCALL(); + + /* We also send a reset packet to the remote host. */ + BUF->flags = TCP_RST | TCP_ACK; + goto tcp_send_nodata; + } + + /* Exponential backoff. */ + uip_connr->timer = UIP_RTO << (uip_connr->nrtx > 4? + 4: + uip_connr->nrtx); + ++(uip_connr->nrtx); + + /* Ok, so we need to retransmit. We do this differently + depending on which state we are in. In ESTABLISHED, we + call upon the application so that it may prepare the + data for the retransmit. In SYN_RCVD, we resend the + SYNACK that we sent earlier and in LAST_ACK we have to + retransmit our FINACK. */ + UIP_STAT(++uip_stat.tcp.rexmit); + switch(uip_connr->tcpstateflags & UIP_TS_MASK) { + case UIP_SYN_RCVD: + /* In the SYN_RCVD state, we should retransmit our + SYNACK. */ + goto tcp_send_synack; + +#if UIP_ACTIVE_OPEN + case UIP_SYN_SENT: + /* In the SYN_SENT state, we retransmit out SYN. */ + BUF->flags = 0; + goto tcp_send_syn; +#endif /* UIP_ACTIVE_OPEN */ + + case UIP_ESTABLISHED: + /* In the ESTABLISHED state, we call upon the application + to do the actual retransmit after which we jump into + the code for sending out the packet (the apprexmit + label). */ + uip_flags = UIP_REXMIT; + UIP_APPCALL(); + goto apprexmit; + + case UIP_FIN_WAIT_1: + case UIP_CLOSING: + case UIP_LAST_ACK: + /* In all these states we should retransmit a FINACK. */ + goto tcp_send_finack; + + } + } + } else if((uip_connr->tcpstateflags & UIP_TS_MASK) == UIP_ESTABLISHED) { + /* If there was no need for a retransmission, we poll the + application for new data. */ + uip_flags = UIP_POLL; + UIP_APPCALL(); + goto appsend; + } + } + goto drop; + } +#if UIP_UDP + if(flag == UIP_UDP_TIMER) { + if(uip_udp_conn->lport != 0) { + uip_conn = NULL; + uip_sappdata = uip_appdata = &uip_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN]; + uip_len = uip_slen = 0; + uip_flags = UIP_POLL; + UIP_UDP_APPCALL(); + goto udp_send; + } else { + goto drop; + } + } +#endif + + /* This is where the input processing starts. */ + UIP_STAT(++uip_stat.ip.recv); + + /* Start of IP input header processing code. */ + +#if UIP_CONF_IPV6 + /* Check validity of the IP header. */ + if((BUF->vtc & 0xf0) != 0x60) { /* IP version and header length. */ + UIP_STAT(++uip_stat.ip.drop); + UIP_STAT(++uip_stat.ip.vhlerr); + UIP_LOG("ipv6: invalid version."); + goto drop; + } +#else /* UIP_CONF_IPV6 */ + /* Check validity of the IP header. */ + if(BUF->vhl != 0x45) { /* IP version and header length. */ + UIP_STAT(++uip_stat.ip.drop); + UIP_STAT(++uip_stat.ip.vhlerr); + UIP_LOG("ip: invalid version or header length."); + goto drop; + } +#endif /* UIP_CONF_IPV6 */ + + /* Check the size of the packet. If the size reported to us in + uip_len is smaller the size reported in the IP header, we assume + that the packet has been corrupted in transit. If the size of + uip_len is larger than the size reported in the IP packet header, + the packet has been padded and we set uip_len to the correct + value.. */ + + if((BUF->len[0] << 8) + BUF->len[1] <= uip_len) { + uip_len = (BUF->len[0] << 8) + BUF->len[1]; +#if UIP_CONF_IPV6 + uip_len += 40; /* The length reported in the IPv6 header is the + length of the payload that follows the + header. However, uIP uses the uip_len variable + for holding the size of the entire packet, + including the IP header. For IPv4 this is not a + problem as the length field in the IPv4 header + contains the length of the entire packet. But + for IPv6 we need to add the size of the IPv6 + header (40 bytes). */ +#endif /* UIP_CONF_IPV6 */ + } else { + UIP_LOG("ip: packet shorter than reported in IP header."); + goto drop; + } + +#if !UIP_CONF_IPV6 + /* Check the fragment flag. */ + if((BUF->ipoffset[0] & 0x3f) != 0 || + BUF->ipoffset[1] != 0) { +#if UIP_REASSEMBLY + uip_len = uip_reass(); + if(uip_len == 0) { + goto drop; + } +#else /* UIP_REASSEMBLY */ + UIP_STAT(++uip_stat.ip.drop); + UIP_STAT(++uip_stat.ip.fragerr); + UIP_LOG("ip: fragment dropped."); + goto drop; +#endif /* UIP_REASSEMBLY */ + } +#endif /* UIP_CONF_IPV6 */ + + if(uip_ipaddr_cmp(uip_hostaddr, all_zeroes_addr)) { + /* If we are configured to use ping IP address configuration and + hasn't been assigned an IP address yet, we accept all ICMP + packets. */ +#if UIP_PINGADDRCONF && !UIP_CONF_IPV6 + if(BUF->proto == UIP_PROTO_ICMP) { + UIP_LOG("ip: possible ping config packet received."); + goto icmp_input; + } else { + UIP_LOG("ip: packet dropped since no address assigned."); + goto drop; + } +#endif /* UIP_PINGADDRCONF */ + + } else { + /* If IP broadcast support is configured, we check for a broadcast + UDP packet, which may be destined to us. */ +#if UIP_BROADCAST + DEBUG_PRINTF("UDP IP checksum 0x%04x\n", uip_ipchksum()); + if(BUF->proto == UIP_PROTO_UDP && + uip_ipaddr_cmp(BUF->destipaddr, all_ones_addr) + /*&& + uip_ipchksum() == 0xffff*/) { + goto udp_input; + } +#endif /* UIP_BROADCAST */ + + /* Check if the packet is destined for our IP address. */ +#if !UIP_CONF_IPV6 + if(!uip_ipaddr_cmp(BUF->destipaddr, uip_hostaddr)) { + UIP_STAT(++uip_stat.ip.drop); + goto drop; + } +#else /* UIP_CONF_IPV6 */ + /* For IPv6, packet reception is a little trickier as we need to + make sure that we listen to certain multicast addresses (all + hosts multicast address, and the solicited-node multicast + address) as well. However, we will cheat here and accept all + multicast packets that are sent to the ff02::/16 addresses. */ + if(!uip_ipaddr_cmp(BUF->destipaddr, uip_hostaddr) && + BUF->destipaddr[0] != HTONS(0xff02)) { + UIP_STAT(++uip_stat.ip.drop); + goto drop; + } +#endif /* UIP_CONF_IPV6 */ + } + +#if !UIP_CONF_IPV6 + if(uip_ipchksum() != 0xffff) { /* Compute and check the IP header + checksum. */ + UIP_STAT(++uip_stat.ip.drop); + UIP_STAT(++uip_stat.ip.chkerr); + UIP_LOG("ip: bad checksum."); + goto drop; + } +#endif /* UIP_CONF_IPV6 */ + + if(BUF->proto == UIP_PROTO_TCP) { /* Check for TCP packet. If so, + proceed with TCP input + processing. */ + goto tcp_input; + } + +#if UIP_UDP + if(BUF->proto == UIP_PROTO_UDP) { + goto udp_input; + } +#endif /* UIP_UDP */ + +#if !UIP_CONF_IPV6 + /* ICMPv4 processing code follows. */ + if(BUF->proto != UIP_PROTO_ICMP) { /* We only allow ICMP packets from + here. */ + UIP_STAT(++uip_stat.ip.drop); + UIP_STAT(++uip_stat.ip.protoerr); + UIP_LOG("ip: neither tcp nor icmp."); + goto drop; + } + +#if UIP_PINGADDRCONF + icmp_input: +#endif /* UIP_PINGADDRCONF */ + UIP_STAT(++uip_stat.icmp.recv); + + /* ICMP echo (i.e., ping) processing. This is simple, we only change + the ICMP type from ECHO to ECHO_REPLY and adjust the ICMP + checksum before we return the packet. */ + if(ICMPBUF->type != ICMP_ECHO) { + UIP_STAT(++uip_stat.icmp.drop); + UIP_STAT(++uip_stat.icmp.typeerr); + UIP_LOG("icmp: not icmp echo."); + goto drop; + } + + /* If we are configured to use ping IP address assignment, we use + the destination IP address of this ping packet and assign it to + ourself. */ +#if UIP_PINGADDRCONF + if((uip_hostaddr[0] | uip_hostaddr[1]) == 0) { + uip_hostaddr[0] = BUF->destipaddr[0]; + uip_hostaddr[1] = BUF->destipaddr[1]; + } +#endif /* UIP_PINGADDRCONF */ + + ICMPBUF->type = ICMP_ECHO_REPLY; + + if(ICMPBUF->icmpchksum >= HTONS(0xffff - (ICMP_ECHO << 8))) { + ICMPBUF->icmpchksum += HTONS(ICMP_ECHO << 8) + 1; + } else { + ICMPBUF->icmpchksum += HTONS(ICMP_ECHO << 8); + } + + /* Swap IP addresses. */ + uip_ipaddr_copy(BUF->destipaddr, BUF->srcipaddr); + uip_ipaddr_copy(BUF->srcipaddr, uip_hostaddr); + + UIP_STAT(++uip_stat.icmp.sent); + goto send; + + /* End of IPv4 input header processing code. */ +#else /* !UIP_CONF_IPV6 */ + + /* This is IPv6 ICMPv6 processing code. */ + DEBUG_PRINTF("icmp6_input: length %d\n", uip_len); + + if(BUF->proto != UIP_PROTO_ICMP6) { /* We only allow ICMPv6 packets from + here. */ + UIP_STAT(++uip_stat.ip.drop); + UIP_STAT(++uip_stat.ip.protoerr); + UIP_LOG("ip: neither tcp nor icmp6."); + goto drop; + } + + UIP_STAT(++uip_stat.icmp.recv); + + /* If we get a neighbor solicitation for our address we should send + a neighbor advertisement message back. */ + if(ICMPBUF->type == ICMP6_NEIGHBOR_SOLICITATION) { + if(uip_ipaddr_cmp(ICMPBUF->icmp6data, uip_hostaddr)) { + + if(ICMPBUF->options[0] == ICMP6_OPTION_SOURCE_LINK_ADDRESS) { + /* Save the sender's address in our neighbor list. */ + uip_neighbor_add(ICMPBUF->srcipaddr, &(ICMPBUF->options[2])); + } + + /* We should now send a neighbor advertisement back to where the + neighbor solicication came from. */ + ICMPBUF->type = ICMP6_NEIGHBOR_ADVERTISEMENT; + ICMPBUF->flags = ICMP6_FLAG_S; /* Solicited flag. */ + + ICMPBUF->reserved1 = ICMPBUF->reserved2 = ICMPBUF->reserved3 = 0; + + uip_ipaddr_copy(ICMPBUF->destipaddr, ICMPBUF->srcipaddr); + uip_ipaddr_copy(ICMPBUF->srcipaddr, uip_hostaddr); + ICMPBUF->options[0] = ICMP6_OPTION_TARGET_LINK_ADDRESS; + ICMPBUF->options[1] = 1; /* Options length, 1 = 8 bytes. */ + memcpy(&(ICMPBUF->options[2]), &uip_ethaddr, sizeof(uip_ethaddr)); + ICMPBUF->icmpchksum = 0; + ICMPBUF->icmpchksum = ~uip_icmp6chksum(); + goto send; + + } + goto drop; + } else if(ICMPBUF->type == ICMP6_ECHO) { + /* ICMP echo (i.e., ping) processing. This is simple, we only + change the ICMP type from ECHO to ECHO_REPLY and update the + ICMP checksum before we return the packet. */ + + ICMPBUF->type = ICMP6_ECHO_REPLY; + + uip_ipaddr_copy(BUF->destipaddr, BUF->srcipaddr); + uip_ipaddr_copy(BUF->srcipaddr, uip_hostaddr); + ICMPBUF->icmpchksum = 0; + ICMPBUF->icmpchksum = ~uip_icmp6chksum(); + + UIP_STAT(++uip_stat.icmp.sent); + goto send; + } else { + DEBUG_PRINTF("Unknown icmp6 message type %d\n", ICMPBUF->type); + UIP_STAT(++uip_stat.icmp.drop); + UIP_STAT(++uip_stat.icmp.typeerr); + UIP_LOG("icmp: unknown ICMP message."); + goto drop; + } + + /* End of IPv6 ICMP processing. */ + +#endif /* !UIP_CONF_IPV6 */ + +#if UIP_UDP + /* UDP input processing. */ + udp_input: + /* UDP processing is really just a hack. We don't do anything to the + UDP/IP headers, but let the UDP application do all the hard + work. If the application sets uip_slen, it has a packet to + send. */ +#if UIP_UDP_CHECKSUMS + uip_len = uip_len - UIP_IPUDPH_LEN; + uip_appdata = &uip_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN]; + if(UDPBUF->udpchksum != 0 && uip_udpchksum() != 0xffff) { + UIP_STAT(++uip_stat.udp.drop); + UIP_STAT(++uip_stat.udp.chkerr); + UIP_LOG("udp: bad checksum."); + goto drop; + } +#else /* UIP_UDP_CHECKSUMS */ + uip_len = uip_len - UIP_IPUDPH_LEN; +#endif /* UIP_UDP_CHECKSUMS */ + + /* Demultiplex this UDP packet between the UDP "connections". */ + for(uip_udp_conn = &uip_udp_conns[0]; + uip_udp_conn < &uip_udp_conns[UIP_UDP_CONNS]; + ++uip_udp_conn) { + /* If the local UDP port is non-zero, the connection is considered + to be used. If so, the local port number is checked against the + destination port number in the received packet. If the two port + numbers match, the remote port number is checked if the + connection is bound to a remote port. Finally, if the + connection is bound to a remote IP address, the source IP + address of the packet is checked. */ + if(uip_udp_conn->lport != 0 && + UDPBUF->destport == uip_udp_conn->lport && + (uip_udp_conn->rport == 0 || + UDPBUF->srcport == uip_udp_conn->rport) && + (uip_ipaddr_cmp(uip_udp_conn->ripaddr, all_zeroes_addr) || + uip_ipaddr_cmp(uip_udp_conn->ripaddr, all_ones_addr) || + uip_ipaddr_cmp(BUF->srcipaddr, uip_udp_conn->ripaddr))) { + goto udp_found; + } + } + UIP_LOG("udp: no matching connection found"); + goto drop; + + udp_found: + uip_conn = NULL; + uip_flags = UIP_NEWDATA; + uip_sappdata = uip_appdata = &uip_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN]; + uip_slen = 0; + UIP_UDP_APPCALL(); + udp_send: + if(uip_slen == 0) { + goto drop; + } + uip_len = uip_slen + UIP_IPUDPH_LEN; + +#if UIP_CONF_IPV6 + /* For IPv6, the IP length field does not include the IPv6 IP header + length. */ + BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8); + BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff); +#else /* UIP_CONF_IPV6 */ + BUF->len[0] = (uip_len >> 8); + BUF->len[1] = (uip_len & 0xff); +#endif /* UIP_CONF_IPV6 */ + + BUF->ttl = uip_udp_conn->ttl; + BUF->proto = UIP_PROTO_UDP; + + UDPBUF->udplen = HTONS(uip_slen + UIP_UDPH_LEN); + UDPBUF->udpchksum = 0; + + BUF->srcport = uip_udp_conn->lport; + BUF->destport = uip_udp_conn->rport; + + uip_ipaddr_copy(BUF->srcipaddr, uip_hostaddr); + uip_ipaddr_copy(BUF->destipaddr, uip_udp_conn->ripaddr); + + uip_appdata = &uip_buf[UIP_LLH_LEN + UIP_IPTCPH_LEN]; + +#if UIP_UDP_CHECKSUMS + /* Calculate UDP checksum. */ + UDPBUF->udpchksum = ~(uip_udpchksum()); + if(UDPBUF->udpchksum == 0) { + UDPBUF->udpchksum = 0xffff; + } +#endif /* UIP_UDP_CHECKSUMS */ + + goto ip_send_nolen; +#endif /* UIP_UDP */ + + /* TCP input processing. */ + tcp_input: + UIP_STAT(++uip_stat.tcp.recv); + + /* Start of TCP input header processing code. */ + + if(uip_tcpchksum() != 0xffff) { /* Compute and check the TCP + checksum. */ + UIP_STAT(++uip_stat.tcp.drop); + UIP_STAT(++uip_stat.tcp.chkerr); + UIP_LOG("tcp: bad checksum."); + goto drop; + } + + + /* Demultiplex this segment. */ + /* First check any active connections. */ + for(uip_connr = &uip_conns[0]; uip_connr <= &uip_conns[UIP_CONNS - 1]; + ++uip_connr) { + if(uip_connr->tcpstateflags != UIP_CLOSED && + BUF->destport == uip_connr->lport && + BUF->srcport == uip_connr->rport && + uip_ipaddr_cmp(BUF->srcipaddr, uip_connr->ripaddr)) { + goto found; + } + } + + /* If we didn't find and active connection that expected the packet, + either this packet is an old duplicate, or this is a SYN packet + destined for a connection in LISTEN. If the SYN flag isn't set, + it is an old packet and we send a RST. */ + if((BUF->flags & TCP_CTL) != TCP_SYN) { + goto reset; + } + + tmp16 = BUF->destport; + /* Next, check listening connections. */ + for(c = 0; c < UIP_LISTENPORTS; ++c) { + if(tmp16 == uip_listenports[c]) + goto found_listen; + } + + /* No matching connection found, so we send a RST packet. */ + UIP_STAT(++uip_stat.tcp.synrst); + reset: + + /* We do not send resets in response to resets. */ + if(BUF->flags & TCP_RST) { + goto drop; + } + + UIP_STAT(++uip_stat.tcp.rst); + + BUF->flags = TCP_RST | TCP_ACK; + uip_len = UIP_IPTCPH_LEN; + BUF->tcpoffset = 5 << 4; + + /* Flip the seqno and ackno fields in the TCP header. */ + c = BUF->seqno[3]; + BUF->seqno[3] = BUF->ackno[3]; + BUF->ackno[3] = c; + + c = BUF->seqno[2]; + BUF->seqno[2] = BUF->ackno[2]; + BUF->ackno[2] = c; + + c = BUF->seqno[1]; + BUF->seqno[1] = BUF->ackno[1]; + BUF->ackno[1] = c; + + c = BUF->seqno[0]; + BUF->seqno[0] = BUF->ackno[0]; + BUF->ackno[0] = c; + + /* We also have to increase the sequence number we are + acknowledging. If the least significant byte overflowed, we need + to propagate the carry to the other bytes as well. */ + if(++BUF->ackno[3] == 0) { + if(++BUF->ackno[2] == 0) { + if(++BUF->ackno[1] == 0) { + ++BUF->ackno[0]; + } + } + } + + /* Swap port numbers. */ + tmp16 = BUF->srcport; + BUF->srcport = BUF->destport; + BUF->destport = tmp16; + + /* Swap IP addresses. */ + uip_ipaddr_copy(BUF->destipaddr, BUF->srcipaddr); + uip_ipaddr_copy(BUF->srcipaddr, uip_hostaddr); + + /* And send out the RST packet! */ + goto tcp_send_noconn; + + /* This label will be jumped to if we matched the incoming packet + with a connection in LISTEN. In that case, we should create a new + connection and send a SYNACK in return. */ + found_listen: + /* First we check if there are any connections avaliable. Unused + connections are kept in the same table as used connections, but + unused ones have the tcpstate set to CLOSED. Also, connections in + TIME_WAIT are kept track of and we'll use the oldest one if no + CLOSED connections are found. Thanks to Eddie C. Dost for a very + nice algorithm for the TIME_WAIT search. */ + uip_connr = 0; + for(c = 0; c < UIP_CONNS; ++c) { + if(uip_conns[c].tcpstateflags == UIP_CLOSED) { + uip_connr = &uip_conns[c]; + break; + } + if(uip_conns[c].tcpstateflags == UIP_TIME_WAIT) { + if(uip_connr == 0 || + uip_conns[c].timer > uip_connr->timer) { + uip_connr = &uip_conns[c]; + } + } + } + + if(uip_connr == 0) { + /* All connections are used already, we drop packet and hope that + the remote end will retransmit the packet at a time when we + have more spare connections. */ + UIP_STAT(++uip_stat.tcp.syndrop); + UIP_LOG("tcp: found no unused connections."); + goto drop; + } + uip_conn = uip_connr; + + /* Fill in the necessary fields for the new connection. */ + uip_connr->rto = uip_connr->timer = UIP_RTO; + uip_connr->sa = 0; + uip_connr->sv = 4; + uip_connr->nrtx = 0; + uip_connr->lport = BUF->destport; + uip_connr->rport = BUF->srcport; + uip_ipaddr_copy(uip_connr->ripaddr, BUF->srcipaddr); + uip_connr->tcpstateflags = UIP_SYN_RCVD; + + uip_connr->snd_nxt[0] = iss[0]; + uip_connr->snd_nxt[1] = iss[1]; + uip_connr->snd_nxt[2] = iss[2]; + uip_connr->snd_nxt[3] = iss[3]; + uip_connr->len = 1; + + /* rcv_nxt should be the seqno from the incoming packet + 1. */ + uip_connr->rcv_nxt[3] = BUF->seqno[3]; + uip_connr->rcv_nxt[2] = BUF->seqno[2]; + uip_connr->rcv_nxt[1] = BUF->seqno[1]; + uip_connr->rcv_nxt[0] = BUF->seqno[0]; + uip_add_rcv_nxt(1); + + /* Parse the TCP MSS option, if present. */ + if((BUF->tcpoffset & 0xf0) > 0x50) { + for(c = 0; c < ((BUF->tcpoffset >> 4) - 5) << 2 ;) { + opt = uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + c]; + if(opt == TCP_OPT_END) { + /* End of options. */ + break; + } else if(opt == TCP_OPT_NOOP) { + ++c; + /* NOP option. */ + } else if(opt == TCP_OPT_MSS && + uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == TCP_OPT_MSS_LEN) { + /* An MSS option with the right option length. */ + tmp16 = ((u16_t)uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 2 + c] << 8) | + (u16_t)uip_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN + 3 + c]; + uip_connr->initialmss = uip_connr->mss = + tmp16 > UIP_TCP_MSS? UIP_TCP_MSS: tmp16; + + /* And we are done processing options. */ + break; + } else { + /* All other options have a length field, so that we easily + can skip past them. */ + if(uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == 0) { + /* If the length field is zero, the options are malformed + and we don't process them further. */ + break; + } + c += uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c]; + } + } + } + + /* Our response will be a SYNACK. */ +#if UIP_ACTIVE_OPEN + tcp_send_synack: + BUF->flags = TCP_ACK; + + tcp_send_syn: + BUF->flags |= TCP_SYN; +#else /* UIP_ACTIVE_OPEN */ + tcp_send_synack: + BUF->flags = TCP_SYN | TCP_ACK; +#endif /* UIP_ACTIVE_OPEN */ + + /* We send out the TCP Maximum Segment Size option with our + SYNACK. */ + BUF->optdata[0] = TCP_OPT_MSS; + BUF->optdata[1] = TCP_OPT_MSS_LEN; + BUF->optdata[2] = (UIP_TCP_MSS) / 256; + BUF->optdata[3] = (UIP_TCP_MSS) & 255; + uip_len = UIP_IPTCPH_LEN + TCP_OPT_MSS_LEN; + BUF->tcpoffset = ((UIP_TCPH_LEN + TCP_OPT_MSS_LEN) / 4) << 4; + goto tcp_send; + + /* This label will be jumped to if we found an active connection. */ + found: + uip_conn = uip_connr; + uip_flags = 0; + /* We do a very naive form of TCP reset processing; we just accept + any RST and kill our connection. We should in fact check if the + sequence number of this reset is wihtin our advertised window + before we accept the reset. */ + if(BUF->flags & TCP_RST) { + uip_connr->tcpstateflags = UIP_CLOSED; + UIP_LOG("tcp: got reset, aborting connection."); + uip_flags = UIP_ABORT; + UIP_APPCALL(); + goto drop; + } + /* Calculated the length of the data, if the application has sent + any data to us. */ + c = (BUF->tcpoffset >> 4) << 2; + /* uip_len will contain the length of the actual TCP data. This is + calculated by subtracing the length of the TCP header (in + c) and the length of the IP header (20 bytes). */ + uip_len = uip_len - c - UIP_IPH_LEN; + + /* First, check if the sequence number of the incoming packet is + what we're expecting next. If not, we send out an ACK with the + correct numbers in. */ + if(!(((uip_connr->tcpstateflags & UIP_TS_MASK) == UIP_SYN_SENT) && + ((BUF->flags & TCP_CTL) == (TCP_SYN | TCP_ACK)))) { + if((uip_len > 0 || ((BUF->flags & (TCP_SYN | TCP_FIN)) != 0)) && + (BUF->seqno[0] != uip_connr->rcv_nxt[0] || + BUF->seqno[1] != uip_connr->rcv_nxt[1] || + BUF->seqno[2] != uip_connr->rcv_nxt[2] || + BUF->seqno[3] != uip_connr->rcv_nxt[3])) { + goto tcp_send_ack; + } + } + + /* Next, check if the incoming segment acknowledges any outstanding + data. If so, we update the sequence number, reset the length of + the outstanding data, calculate RTT estimations, and reset the + retransmission timer. */ + if((BUF->flags & TCP_ACK) && uip_outstanding(uip_connr)) { + uip_add32(uip_connr->snd_nxt, uip_connr->len); + + if(BUF->ackno[0] == uip_acc32[0] && + BUF->ackno[1] == uip_acc32[1] && + BUF->ackno[2] == uip_acc32[2] && + BUF->ackno[3] == uip_acc32[3]) { + /* Update sequence number. */ + uip_connr->snd_nxt[0] = uip_acc32[0]; + uip_connr->snd_nxt[1] = uip_acc32[1]; + uip_connr->snd_nxt[2] = uip_acc32[2]; + uip_connr->snd_nxt[3] = uip_acc32[3]; + + + /* Do RTT estimation, unless we have done retransmissions. */ + if(uip_connr->nrtx == 0) { + signed char m; + m = uip_connr->rto - uip_connr->timer; + /* This is taken directly from VJs original code in his paper */ + m = m - (uip_connr->sa >> 3); + uip_connr->sa += m; + if(m < 0) { + m = -m; + } + m = m - (uip_connr->sv >> 2); + uip_connr->sv += m; + uip_connr->rto = (uip_connr->sa >> 3) + uip_connr->sv; + + } + /* Set the acknowledged flag. */ + uip_flags = UIP_ACKDATA; + /* Reset the retransmission timer. */ + uip_connr->timer = uip_connr->rto; + + /* Reset length of outstanding data. */ + uip_connr->len = 0; + } + + } + + /* Do different things depending on in what state the connection is. */ + switch(uip_connr->tcpstateflags & UIP_TS_MASK) { + /* CLOSED and LISTEN are not handled here. CLOSE_WAIT is not + implemented, since we force the application to close when the + peer sends a FIN (hence the application goes directly from + ESTABLISHED to LAST_ACK). */ + case UIP_SYN_RCVD: + /* In SYN_RCVD we have sent out a SYNACK in response to a SYN, and + we are waiting for an ACK that acknowledges the data we sent + out the last time. Therefore, we want to have the UIP_ACKDATA + flag set. If so, we enter the ESTABLISHED state. */ + if(uip_flags & UIP_ACKDATA) { + uip_connr->tcpstateflags = UIP_ESTABLISHED; + uip_flags = UIP_CONNECTED; + uip_connr->len = 0; + if(uip_len > 0) { + uip_flags |= UIP_NEWDATA; + uip_add_rcv_nxt(uip_len); + } + uip_slen = 0; + UIP_APPCALL(); + goto appsend; + } + goto drop; +#if UIP_ACTIVE_OPEN + case UIP_SYN_SENT: + /* In SYN_SENT, we wait for a SYNACK that is sent in response to + our SYN. The rcv_nxt is set to sequence number in the SYNACK + plus one, and we send an ACK. We move into the ESTABLISHED + state. */ + if((uip_flags & UIP_ACKDATA) && + (BUF->flags & TCP_CTL) == (TCP_SYN | TCP_ACK)) { + + /* Parse the TCP MSS option, if present. */ + if((BUF->tcpoffset & 0xf0) > 0x50) { + for(c = 0; c < ((BUF->tcpoffset >> 4) - 5) << 2 ;) { + opt = uip_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN + c]; + if(opt == TCP_OPT_END) { + /* End of options. */ + break; + } else if(opt == TCP_OPT_NOOP) { + ++c; + /* NOP option. */ + } else if(opt == TCP_OPT_MSS && + uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == TCP_OPT_MSS_LEN) { + /* An MSS option with the right option length. */ + tmp16 = (uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 2 + c] << 8) | + uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 3 + c]; + uip_connr->initialmss = + uip_connr->mss = tmp16 > UIP_TCP_MSS? UIP_TCP_MSS: tmp16; + + /* And we are done processing options. */ + break; + } else { + /* All other options have a length field, so that we easily + can skip past them. */ + if(uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == 0) { + /* If the length field is zero, the options are malformed + and we don't process them further. */ + break; + } + c += uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c]; + } + } + } + uip_connr->tcpstateflags = UIP_ESTABLISHED; + uip_connr->rcv_nxt[0] = BUF->seqno[0]; + uip_connr->rcv_nxt[1] = BUF->seqno[1]; + uip_connr->rcv_nxt[2] = BUF->seqno[2]; + uip_connr->rcv_nxt[3] = BUF->seqno[3]; + uip_add_rcv_nxt(1); + uip_flags = UIP_CONNECTED | UIP_NEWDATA; + uip_connr->len = 0; + uip_len = 0; + uip_slen = 0; + UIP_APPCALL(); + goto appsend; + } + /* Inform the application that the connection failed */ + uip_flags = UIP_ABORT; + UIP_APPCALL(); + /* The connection is closed after we send the RST */ + uip_conn->tcpstateflags = UIP_CLOSED; + goto reset; +#endif /* UIP_ACTIVE_OPEN */ + + case UIP_ESTABLISHED: + /* In the ESTABLISHED state, we call upon the application to feed + data into the uip_buf. If the UIP_ACKDATA flag is set, the + application should put new data into the buffer, otherwise we are + retransmitting an old segment, and the application should put that + data into the buffer. + + If the incoming packet is a FIN, we should close the connection on + this side as well, and we send out a FIN and enter the LAST_ACK + state. We require that there is no outstanding data; otherwise the + sequence numbers will be screwed up. */ + + if(BUF->flags & TCP_FIN && !(uip_connr->tcpstateflags & UIP_STOPPED)) { + if(uip_outstanding(uip_connr)) { + goto drop; + } + uip_add_rcv_nxt(1 + uip_len); + uip_flags |= UIP_CLOSE; + if(uip_len > 0) { + uip_flags |= UIP_NEWDATA; + } + UIP_APPCALL(); + uip_connr->len = 1; + uip_connr->tcpstateflags = UIP_LAST_ACK; + uip_connr->nrtx = 0; + tcp_send_finack: + BUF->flags = TCP_FIN | TCP_ACK; + goto tcp_send_nodata; + } + + /* Check the URG flag. If this is set, the segment carries urgent + data that we must pass to the application. */ + if((BUF->flags & TCP_URG) != 0) { +#if UIP_URGDATA > 0 + uip_urglen = (BUF->urgp[0] << 8) | BUF->urgp[1]; + if(uip_urglen > uip_len) { + /* There is more urgent data in the next segment to come. */ + uip_urglen = uip_len; + } + uip_add_rcv_nxt(uip_urglen); + uip_len -= uip_urglen; + uip_urgdata = uip_appdata; + uip_appdata += uip_urglen; + } else { + uip_urglen = 0; +#else /* UIP_URGDATA > 0 */ + uip_appdata = ((char *)uip_appdata) + ((BUF->urgp[0] << 8) | BUF->urgp[1]); + uip_len -= (BUF->urgp[0] << 8) | BUF->urgp[1]; +#endif /* UIP_URGDATA > 0 */ + } + + /* If uip_len > 0 we have TCP data in the packet, and we flag this + by setting the UIP_NEWDATA flag and update the sequence number + we acknowledge. If the application has stopped the dataflow + using uip_stop(), we must not accept any data packets from the + remote host. */ + if(uip_len > 0 && !(uip_connr->tcpstateflags & UIP_STOPPED)) { + uip_flags |= UIP_NEWDATA; + uip_add_rcv_nxt(uip_len); + } + + /* Check if the available buffer space advertised by the other end + is smaller than the initial MSS for this connection. If so, we + set the current MSS to the window size to ensure that the + application does not send more data than the other end can + handle. + + If the remote host advertises a zero window, we set the MSS to + the initial MSS so that the application will send an entire MSS + of data. This data will not be acknowledged by the receiver, + and the application will retransmit it. This is called the + "persistent timer" and uses the retransmission mechanim. + */ + tmp16 = ((u16_t)BUF->wnd[0] << 8) + (u16_t)BUF->wnd[1]; + if(tmp16 > uip_connr->initialmss || + tmp16 == 0) { + tmp16 = uip_connr->initialmss; + } + uip_connr->mss = tmp16; + + /* If this packet constitutes an ACK for outstanding data (flagged + by the UIP_ACKDATA flag, we should call the application since it + might want to send more data. If the incoming packet had data + from the peer (as flagged by the UIP_NEWDATA flag), the + application must also be notified. + + When the application is called, the global variable uip_len + contains the length of the incoming data. The application can + access the incoming data through the global pointer + uip_appdata, which usually points UIP_IPTCPH_LEN + UIP_LLH_LEN + bytes into the uip_buf array. + + If the application wishes to send any data, this data should be + put into the uip_appdata and the length of the data should be + put into uip_len. If the application don't have any data to + send, uip_len must be set to 0. */ + if(uip_flags & (UIP_NEWDATA | UIP_ACKDATA)) { + uip_slen = 0; + UIP_APPCALL(); + + appsend: + + if(uip_flags & UIP_ABORT) { + uip_slen = 0; + uip_connr->tcpstateflags = UIP_CLOSED; + BUF->flags = TCP_RST | TCP_ACK; + goto tcp_send_nodata; + } + + if(uip_flags & UIP_CLOSE) { + uip_slen = 0; + uip_connr->len = 1; + uip_connr->tcpstateflags = UIP_FIN_WAIT_1; + uip_connr->nrtx = 0; + BUF->flags = TCP_FIN | TCP_ACK; + goto tcp_send_nodata; + } + + /* If uip_slen > 0, the application has data to be sent. */ + if(uip_slen > 0) { + + /* If the connection has acknowledged data, the contents of + the ->len variable should be discarded. */ + if((uip_flags & UIP_ACKDATA) != 0) { + uip_connr->len = 0; + } + + /* If the ->len variable is non-zero the connection has + already data in transit and cannot send anymore right + now. */ + if(uip_connr->len == 0) { + + /* The application cannot send more than what is allowed by + the mss (the minumum of the MSS and the available + window). */ + if(uip_slen > uip_connr->mss) { + uip_slen = uip_connr->mss; + } + + /* Remember how much data we send out now so that we know + when everything has been acknowledged. */ + uip_connr->len = uip_slen; + } else { + + /* If the application already had unacknowledged data, we + make sure that the application does not send (i.e., + retransmit) out more than it previously sent out. */ + uip_slen = uip_connr->len; + } + } + uip_connr->nrtx = 0; + apprexmit: + uip_appdata = uip_sappdata; + + /* If the application has data to be sent, or if the incoming + packet had new data in it, we must send out a packet. */ + if(uip_slen > 0 && uip_connr->len > 0) { + /* Add the length of the IP and TCP headers. */ + uip_len = uip_connr->len + UIP_TCPIP_HLEN; + /* We always set the ACK flag in response packets. */ + BUF->flags = TCP_ACK | TCP_PSH; + /* Send the packet. */ + goto tcp_send_noopts; + } + /* If there is no data to send, just send out a pure ACK if + there is newdata. */ + if(uip_flags & UIP_NEWDATA) { + uip_len = UIP_TCPIP_HLEN; + BUF->flags = TCP_ACK; + goto tcp_send_noopts; + } + } + goto drop; + case UIP_LAST_ACK: + /* We can close this connection if the peer has acknowledged our + FIN. This is indicated by the UIP_ACKDATA flag. */ + if(uip_flags & UIP_ACKDATA) { + uip_connr->tcpstateflags = UIP_CLOSED; + uip_flags = UIP_CLOSE; + UIP_APPCALL(); + } + break; + + case UIP_FIN_WAIT_1: + /* The application has closed the connection, but the remote host + hasn't closed its end yet. Thus we do nothing but wait for a + FIN from the other side. */ + if(uip_len > 0) { + uip_add_rcv_nxt(uip_len); + } + if(BUF->flags & TCP_FIN) { + if(uip_flags & UIP_ACKDATA) { + uip_connr->tcpstateflags = UIP_TIME_WAIT; + uip_connr->timer = 0; + uip_connr->len = 0; + } else { + uip_connr->tcpstateflags = UIP_CLOSING; + } + uip_add_rcv_nxt(1); + uip_flags = UIP_CLOSE; + UIP_APPCALL(); + goto tcp_send_ack; + } else if(uip_flags & UIP_ACKDATA) { + uip_connr->tcpstateflags = UIP_FIN_WAIT_2; + uip_connr->len = 0; + goto drop; + } + if(uip_len > 0) { + goto tcp_send_ack; + } + goto drop; + + case UIP_FIN_WAIT_2: + if(uip_len > 0) { + uip_add_rcv_nxt(uip_len); + } + if(BUF->flags & TCP_FIN) { + uip_connr->tcpstateflags = UIP_TIME_WAIT; + uip_connr->timer = 0; + uip_add_rcv_nxt(1); + uip_flags = UIP_CLOSE; + UIP_APPCALL(); + goto tcp_send_ack; + } + if(uip_len > 0) { + goto tcp_send_ack; + } + goto drop; + + case UIP_TIME_WAIT: + goto tcp_send_ack; + + case UIP_CLOSING: + if(uip_flags & UIP_ACKDATA) { + uip_connr->tcpstateflags = UIP_TIME_WAIT; + uip_connr->timer = 0; + } + } + goto drop; + + + /* We jump here when we are ready to send the packet, and just want + to set the appropriate TCP sequence numbers in the TCP header. */ + tcp_send_ack: + BUF->flags = TCP_ACK; + tcp_send_nodata: + uip_len = UIP_IPTCPH_LEN; + tcp_send_noopts: + BUF->tcpoffset = (UIP_TCPH_LEN / 4) << 4; + tcp_send: + /* We're done with the input processing. We are now ready to send a + reply. Our job is to fill in all the fields of the TCP and IP + headers before calculating the checksum and finally send the + packet. */ + BUF->ackno[0] = uip_connr->rcv_nxt[0]; + BUF->ackno[1] = uip_connr->rcv_nxt[1]; + BUF->ackno[2] = uip_connr->rcv_nxt[2]; + BUF->ackno[3] = uip_connr->rcv_nxt[3]; + + BUF->seqno[0] = uip_connr->snd_nxt[0]; + BUF->seqno[1] = uip_connr->snd_nxt[1]; + BUF->seqno[2] = uip_connr->snd_nxt[2]; + BUF->seqno[3] = uip_connr->snd_nxt[3]; + + BUF->proto = UIP_PROTO_TCP; + + BUF->srcport = uip_connr->lport; + BUF->destport = uip_connr->rport; + + uip_ipaddr_copy(BUF->srcipaddr, uip_hostaddr); + uip_ipaddr_copy(BUF->destipaddr, uip_connr->ripaddr); + + if(uip_connr->tcpstateflags & UIP_STOPPED) { + /* If the connection has issued uip_stop(), we advertise a zero + window so that the remote host will stop sending data. */ + BUF->wnd[0] = BUF->wnd[1] = 0; + } else { + BUF->wnd[0] = ((UIP_RECEIVE_WINDOW) >> 8); + BUF->wnd[1] = ((UIP_RECEIVE_WINDOW) & 0xff); + } + + tcp_send_noconn: + BUF->ttl = UIP_TTL; +#if UIP_CONF_IPV6 + /* For IPv6, the IP length field does not include the IPv6 IP header + length. */ + BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8); + BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff); +#else /* UIP_CONF_IPV6 */ + BUF->len[0] = (uip_len >> 8); + BUF->len[1] = (uip_len & 0xff); +#endif /* UIP_CONF_IPV6 */ + + BUF->urgp[0] = BUF->urgp[1] = 0; + + /* Calculate TCP checksum. */ + BUF->tcpchksum = 0; + BUF->tcpchksum = ~(uip_tcpchksum()); + + ip_send_nolen: + +#if UIP_CONF_IPV6 + BUF->vtc = 0x60; + BUF->tcflow = 0x00; + BUF->flow = 0x00; +#else /* UIP_CONF_IPV6 */ + BUF->vhl = 0x45; + BUF->tos = 0; + BUF->ipoffset[0] = BUF->ipoffset[1] = 0; + ++ipid; + BUF->ipid[0] = ipid >> 8; + BUF->ipid[1] = ipid & 0xff; + /* Calculate IP checksum. */ + BUF->ipchksum = 0; + BUF->ipchksum = ~(uip_ipchksum()); + DEBUG_PRINTF("uip ip_send_nolen: chkecum 0x%04x\n", uip_ipchksum()); +#endif /* UIP_CONF_IPV6 */ + + UIP_STAT(++uip_stat.tcp.sent); + send: + DEBUG_PRINTF("Sending packet with length %d (%d)\n", uip_len, + (BUF->len[0] << 8) | BUF->len[1]); + + UIP_STAT(++uip_stat.ip.sent); + /* Return and let the caller do the actual transmission. */ + uip_flags = 0; + return; + drop: + uip_len = 0; + uip_flags = 0; + return; +} +/*---------------------------------------------------------------------------*/ +u16_t +htons(u16_t val) +{ + return HTONS(val); +} +/*---------------------------------------------------------------------------*/ +void +uip_send(const void *data, int len) +{ + uip_slen = len; + if(len > 0) { + if(data != uip_sappdata) { + memcpy(uip_sappdata, (data), uip_slen); + } + } +} +/** @} */ diff --git a/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/uip.h b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/uip.h new file mode 100644 index 0000000..4fc0452 --- /dev/null +++ b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/uip.h @@ -0,0 +1,1601 @@ + +/** + * \addtogroup uip + * @{ + */ + +/** + * \file + * Header file for the uIP TCP/IP stack. + * \author Adam Dunkels + * + * The uIP TCP/IP stack header file contains definitions for a number + * of C macros that are used by uIP programs as well as internal uIP + * structures, TCP/IP header structures and function declarations. + * + */ + + +/* + * Copyright (c) 2001-2003, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This file is part of the uIP TCP/IP stack. + * + * $Id: uip.h,v 1.40 2006/06/08 07:12:07 adam Exp $ + * + */ + +#ifndef __UIP_H__ +#define __UIP_H__ + +#include "uipopt.h" + +/** + * Repressentation of an IP address. + * + */ +typedef u16_t uip_ip4addr_t[2]; +typedef u16_t uip_ip6addr_t[8]; +#if UIP_CONF_IPV6 +typedef uip_ip6addr_t uip_ipaddr_t; +#else /* UIP_CONF_IPV6 */ +typedef uip_ip4addr_t uip_ipaddr_t; +#endif /* UIP_CONF_IPV6 */ + +/*---------------------------------------------------------------------------*/ +/* First, the functions that should be called from the + * system. Initialization, the periodic timer and incoming packets are + * handled by the following three functions. + */ + +/** + * \defgroup uipconffunc uIP configuration functions + * @{ + * + * The uIP configuration functions are used for setting run-time + * parameters in uIP such as IP addresses. + */ + +/** + * Set the IP address of this host. + * + * The IP address is represented as a 4-byte array where the first + * octet of the IP address is put in the first member of the 4-byte + * array. + * + * Example: + \code + + uip_ipaddr_t addr; + + uip_ipaddr(&addr, 192,168,1,2); + uip_sethostaddr(&addr); + + \endcode + * \param addr A pointer to an IP address of type uip_ipaddr_t; + * + * \sa uip_ipaddr() + * + * \hideinitializer + */ +#define uip_sethostaddr(addr) uip_ipaddr_copy(uip_hostaddr, (addr)) + +/** + * Get the IP address of this host. + * + * The IP address is represented as a 4-byte array where the first + * octet of the IP address is put in the first member of the 4-byte + * array. + * + * Example: + \code + uip_ipaddr_t hostaddr; + + uip_gethostaddr(&hostaddr); + \endcode + * \param addr A pointer to a uip_ipaddr_t variable that will be + * filled in with the currently configured IP address. + * + * \hideinitializer + */ +#define uip_gethostaddr(addr) uip_ipaddr_copy((addr), uip_hostaddr) + +/** + * Set the default router's IP address. + * + * \param addr A pointer to a uip_ipaddr_t variable containing the IP + * address of the default router. + * + * \sa uip_ipaddr() + * + * \hideinitializer + */ +#define uip_setdraddr(addr) uip_ipaddr_copy(uip_draddr, (addr)) + +/** + * Set the netmask. + * + * \param addr A pointer to a uip_ipaddr_t variable containing the IP + * address of the netmask. + * + * \sa uip_ipaddr() + * + * \hideinitializer + */ +#define uip_setnetmask(addr) uip_ipaddr_copy(uip_netmask, (addr)) + + +/** + * Get the default router's IP address. + * + * \param addr A pointer to a uip_ipaddr_t variable that will be + * filled in with the IP address of the default router. + * + * \hideinitializer + */ +#define uip_getdraddr(addr) uip_ipaddr_copy((addr), uip_draddr) + +/** + * Get the netmask. + * + * \param addr A pointer to a uip_ipaddr_t variable that will be + * filled in with the value of the netmask. + * + * \hideinitializer + */ +#define uip_getnetmask(addr) uip_ipaddr_copy((addr), uip_netmask) + +/** @} */ + +/** + * \defgroup uipinit uIP initialization functions + * @{ + * + * The uIP initialization functions are used for booting uIP. + */ + +/** + * uIP initialization function. + * + * This function should be called at boot up to initilize the uIP + * TCP/IP stack. + */ +void uip_init(void); + +/** + * uIP initialization function. + * + * This function may be used at boot time to set the initial ip_id. + */ +void uip_setipid(u16_t id); + +/** @} */ + +/** + * \defgroup uipdevfunc uIP device driver functions + * @{ + * + * These functions are used by a network device driver for interacting + * with uIP. + */ + +/** + * Process an incoming packet. + * + * This function should be called when the device driver has received + * a packet from the network. The packet from the device driver must + * be present in the uip_buf buffer, and the length of the packet + * should be placed in the uip_len variable. + * + * When the function returns, there may be an outbound packet placed + * in the uip_buf packet buffer. If so, the uip_len variable is set to + * the length of the packet. If no packet is to be sent out, the + * uip_len variable is set to 0. + * + * The usual way of calling the function is presented by the source + * code below. + \code + uip_len = devicedriver_poll(); + if(uip_len > 0) { + uip_input(); + if(uip_len > 0) { + devicedriver_send(); + } + } + \endcode + * + * \note If you are writing a uIP device driver that needs ARP + * (Address Resolution Protocol), e.g., when running uIP over + * Ethernet, you will need to call the uIP ARP code before calling + * this function: + \code + #define BUF ((struct uip_eth_hdr *)&uip_buf[0]) + uip_len = ethernet_devicedrver_poll(); + if(uip_len > 0) { + if(BUF->type == HTONS(UIP_ETHTYPE_IP)) { + uip_arp_ipin(); + uip_input(); + if(uip_len > 0) { + uip_arp_out(); + ethernet_devicedriver_send(); + } + } else if(BUF->type == HTONS(UIP_ETHTYPE_ARP)) { + uip_arp_arpin(); + if(uip_len > 0) { + ethernet_devicedriver_send(); + } + } + \endcode + * + * \hideinitializer + */ +#define uip_input() uip_process(UIP_DATA) + +/** + * Periodic processing for a connection identified by its number. + * + * This function does the necessary periodic processing (timers, + * polling) for a uIP TCP conneciton, and should be called when the + * periodic uIP timer goes off. It should be called for every + * connection, regardless of whether they are open of closed. + * + * When the function returns, it may have an outbound packet waiting + * for service in the uIP packet buffer, and if so the uip_len + * variable is set to a value larger than zero. The device driver + * should be called to send out the packet. + * + * The ususal way of calling the function is through a for() loop like + * this: + \code + for(i = 0; i < UIP_CONNS; ++i) { + uip_periodic(i); + if(uip_len > 0) { + devicedriver_send(); + } + } + \endcode + * + * \note If you are writing a uIP device driver that needs ARP + * (Address Resolution Protocol), e.g., when running uIP over + * Ethernet, you will need to call the uip_arp_out() function before + * calling the device driver: + \code + for(i = 0; i < UIP_CONNS; ++i) { + uip_periodic(i); + if(uip_len > 0) { + uip_arp_out(); + ethernet_devicedriver_send(); + } + } + \endcode + * + * \param conn The number of the connection which is to be periodically polled. + * + * \hideinitializer + */ +#define uip_periodic(conn) do { uip_conn = &uip_conns[conn]; \ + uip_process(UIP_TIMER); } while (0) + +/** + * + * + */ +#define uip_conn_active(conn) (uip_conns[conn].tcpstateflags != UIP_CLOSED) + +/** + * Perform periodic processing for a connection identified by a pointer + * to its structure. + * + * Same as uip_periodic() but takes a pointer to the actual uip_conn + * struct instead of an integer as its argument. This function can be + * used to force periodic processing of a specific connection. + * + * \param conn A pointer to the uip_conn struct for the connection to + * be processed. + * + * \hideinitializer + */ +#define uip_periodic_conn(conn) do { uip_conn = conn; \ + uip_process(UIP_TIMER); } while (0) + +/** + * Reuqest that a particular connection should be polled. + * + * Similar to uip_periodic_conn() but does not perform any timer + * processing. The application is polled for new data. + * + * \param conn A pointer to the uip_conn struct for the connection to + * be processed. + * + * \hideinitializer + */ +#define uip_poll_conn(conn) do { uip_conn = conn; \ + uip_process(UIP_POLL_REQUEST); } while (0) + + +#if UIP_UDP +/** + * Periodic processing for a UDP connection identified by its number. + * + * This function is essentially the same as uip_periodic(), but for + * UDP connections. It is called in a similar fashion as the + * uip_periodic() function: + \code + for(i = 0; i < UIP_UDP_CONNS; i++) { + uip_udp_periodic(i); + if(uip_len > 0) { + devicedriver_send(); + } + } + \endcode + * + * \note As for the uip_periodic() function, special care has to be + * taken when using uIP together with ARP and Ethernet: + \code + for(i = 0; i < UIP_UDP_CONNS; i++) { + uip_udp_periodic(i); + if(uip_len > 0) { + uip_arp_out(); + ethernet_devicedriver_send(); + } + } + \endcode + * + * \param conn The number of the UDP connection to be processed. + * + * \hideinitializer + */ +#define uip_udp_periodic(conn) do { uip_udp_conn = &uip_udp_conns[conn]; \ + uip_process(UIP_UDP_TIMER); } while (0) + +/** + * Periodic processing for a UDP connection identified by a pointer to + * its structure. + * + * Same as uip_udp_periodic() but takes a pointer to the actual + * uip_conn struct instead of an integer as its argument. This + * function can be used to force periodic processing of a specific + * connection. + * + * \param conn A pointer to the uip_udp_conn struct for the connection + * to be processed. + * + * \hideinitializer + */ +#define uip_udp_periodic_conn(conn) do { uip_udp_conn = conn; \ + uip_process(UIP_UDP_TIMER); } while (0) + + +#endif /* UIP_UDP */ + +/** + * The uIP packet buffer. + * + * The uip_buf array is used to hold incoming and outgoing + * packets. The device driver should place incoming data into this + * buffer. When sending data, the device driver should read the link + * level headers and the TCP/IP headers from this buffer. The size of + * the link level headers is configured by the UIP_LLH_LEN define. + * + * \note The application data need not be placed in this buffer, so + * the device driver must read it from the place pointed to by the + * uip_appdata pointer as illustrated by the following example: + \code + void + devicedriver_send(void) + { + hwsend(&uip_buf[0], UIP_LLH_LEN); + if(uip_len <= UIP_LLH_LEN + UIP_TCPIP_HLEN) { + hwsend(&uip_buf[UIP_LLH_LEN], uip_len - UIP_LLH_LEN); + } else { + hwsend(&uip_buf[UIP_LLH_LEN], UIP_TCPIP_HLEN); + hwsend(uip_appdata, uip_len - UIP_TCPIP_HLEN - UIP_LLH_LEN); + } + } + \endcode + */ +extern u8_t uip_buf[UIP_BUFSIZE+2]; + +/** @} */ + +/*---------------------------------------------------------------------------*/ +/* Functions that are used by the uIP application program. Opening and + * closing connections, sending and receiving data, etc. is all + * handled by the functions below. +*/ +/** + * \defgroup uipappfunc uIP application functions + * @{ + * + * Functions used by an application running of top of uIP. + */ + +/** + * Start listening to the specified port. + * + * \note Since this function expects the port number in network byte + * order, a conversion using HTONS() or htons() is necessary. + * + \code + uip_listen(HTONS(80)); + \endcode + * + * \param port A 16-bit port number in network byte order. + */ +void uip_listen(u16_t port); + +/** + * Stop listening to the specified port. + * + * \note Since this function expects the port number in network byte + * order, a conversion using HTONS() or htons() is necessary. + * + \code + uip_unlisten(HTONS(80)); + \endcode + * + * \param port A 16-bit port number in network byte order. + */ +void uip_unlisten(u16_t port); + +/** + * Connect to a remote host using TCP. + * + * This function is used to start a new connection to the specified + * port on the specied host. It allocates a new connection identifier, + * sets the connection to the SYN_SENT state and sets the + * retransmission timer to 0. This will cause a TCP SYN segment to be + * sent out the next time this connection is periodically processed, + * which usually is done within 0.5 seconds after the call to + * uip_connect(). + * + * \note This function is avaliable only if support for active open + * has been configured by defining UIP_ACTIVE_OPEN to 1 in uipopt.h. + * + * \note Since this function requires the port number to be in network + * byte order, a conversion using HTONS() or htons() is necessary. + * + \code + uip_ipaddr_t ipaddr; + + uip_ipaddr(&ipaddr, 192,168,1,2); + uip_connect(&ipaddr, HTONS(80)); + \endcode + * + * \param ripaddr The IP address of the remote hot. + * + * \param port A 16-bit port number in network byte order. + * + * \return A pointer to the uIP connection identifier for the new connection, + * or NULL if no connection could be allocated. + * + */ +struct uip_conn *uip_connect(uip_ipaddr_t *ripaddr, u16_t port); + + + +/** + * \internal + * + * Check if a connection has outstanding (i.e., unacknowledged) data. + * + * \param conn A pointer to the uip_conn structure for the connection. + * + * \hideinitializer + */ +#define uip_outstanding(conn) ((conn)->len) + +/** + * Send data on the current connection. + * + * This function is used to send out a single segment of TCP + * data. Only applications that have been invoked by uIP for event + * processing can send data. + * + * The amount of data that actually is sent out after a call to this + * funcion is determined by the maximum amount of data TCP allows. uIP + * will automatically crop the data so that only the appropriate + * amount of data is sent. The function uip_mss() can be used to query + * uIP for the amount of data that actually will be sent. + * + * \note This function does not guarantee that the sent data will + * arrive at the destination. If the data is lost in the network, the + * application will be invoked with the uip_rexmit() event being + * set. The application will then have to resend the data using this + * function. + * + * \param data A pointer to the data which is to be sent. + * + * \param len The maximum amount of data bytes to be sent. + * + * \hideinitializer + */ +void uip_send(const void *data, int len); + +/** + * The length of any incoming data that is currently avaliable (if avaliable) + * in the uip_appdata buffer. + * + * The test function uip_data() must first be used to check if there + * is any data available at all. + * + * \hideinitializer + */ +/*void uip_datalen(void);*/ +#define uip_datalen() uip_len + +/** + * The length of any out-of-band data (urgent data) that has arrived + * on the connection. + * + * \note The configuration parameter UIP_URGDATA must be set for this + * function to be enabled. + * + * \hideinitializer + */ +#define uip_urgdatalen() uip_urglen + +/** + * Close the current connection. + * + * This function will close the current connection in a nice way. + * + * \hideinitializer + */ +#define uip_close() (uip_flags = UIP_CLOSE) + +/** + * Abort the current connection. + * + * This function will abort (reset) the current connection, and is + * usually used when an error has occured that prevents using the + * uip_close() function. + * + * \hideinitializer + */ +#define uip_abort() (uip_flags = UIP_ABORT) + +/** + * Tell the sending host to stop sending data. + * + * This function will close our receiver's window so that we stop + * receiving data for the current connection. + * + * \hideinitializer + */ +#define uip_stop() (uip_conn->tcpstateflags |= UIP_STOPPED) + +/** + * Find out if the current connection has been previously stopped with + * uip_stop(). + * + * \hideinitializer + */ +#define uip_stopped(conn) ((conn)->tcpstateflags & UIP_STOPPED) + +/** + * Restart the current connection, if is has previously been stopped + * with uip_stop(). + * + * This function will open the receiver's window again so that we + * start receiving data for the current connection. + * + * \hideinitializer + */ +#define uip_restart() do { uip_flags |= UIP_NEWDATA; \ + uip_conn->tcpstateflags &= ~UIP_STOPPED; \ + } while(0) + + +/* uIP tests that can be made to determine in what state the current + connection is, and what the application function should do. */ + +/** + * Is the current connection a UDP connection? + * + * This function checks whether the current connection is a UDP connection. + * + * \hideinitializer + * + */ +#define uip_udpconnection() (uip_conn == NULL) + +/** + * Is new incoming data available? + * + * Will reduce to non-zero if there is new data for the application + * present at the uip_appdata pointer. The size of the data is + * avaliable through the uip_len variable. + * + * \hideinitializer + */ +#define uip_newdata() (uip_flags & UIP_NEWDATA) + +/** + * Has previously sent data been acknowledged? + * + * Will reduce to non-zero if the previously sent data has been + * acknowledged by the remote host. This means that the application + * can send new data. + * + * \hideinitializer + */ +#define uip_acked() (uip_flags & UIP_ACKDATA) + +/** + * Has the connection just been connected? + * + * Reduces to non-zero if the current connection has been connected to + * a remote host. This will happen both if the connection has been + * actively opened (with uip_connect()) or passively opened (with + * uip_listen()). + * + * \hideinitializer + */ +#define uip_connected() (uip_flags & UIP_CONNECTED) + +/** + * Has the connection been closed by the other end? + * + * Is non-zero if the connection has been closed by the remote + * host. The application may then do the necessary clean-ups. + * + * \hideinitializer + */ +#define uip_closed() (uip_flags & UIP_CLOSE) + +/** + * Has the connection been aborted by the other end? + * + * Non-zero if the current connection has been aborted (reset) by the + * remote host. + * + * \hideinitializer + */ +#define uip_aborted() (uip_flags & UIP_ABORT) + +/** + * Has the connection timed out? + * + * Non-zero if the current connection has been aborted due to too many + * retransmissions. + * + * \hideinitializer + */ +#define uip_timedout() (uip_flags & UIP_TIMEDOUT) + +/** + * Do we need to retransmit previously data? + * + * Reduces to non-zero if the previously sent data has been lost in + * the network, and the application should retransmit it. The + * application should send the exact same data as it did the last + * time, using the uip_send() function. + * + * \hideinitializer + */ +#define uip_rexmit() (uip_flags & UIP_REXMIT) + +/** + * Is the connection being polled by uIP? + * + * Is non-zero if the reason the application is invoked is that the + * current connection has been idle for a while and should be + * polled. + * + * The polling event can be used for sending data without having to + * wait for the remote host to send data. + * + * \hideinitializer + */ +#define uip_poll() (uip_flags & UIP_POLL) + +/** + * Get the initial maxium segment size (MSS) of the current + * connection. + * + * \hideinitializer + */ +#define uip_initialmss() (uip_conn->initialmss) + +/** + * Get the current maxium segment size that can be sent on the current + * connection. + * + * The current maxiumum segment size that can be sent on the + * connection is computed from the receiver's window and the MSS of + * the connection (which also is available by calling + * uip_initialmss()). + * + * \hideinitializer + */ +#define uip_mss() (uip_conn->mss) + +/** + * Set up a new UDP connection. + * + * This function sets up a new UDP connection. The function will + * automatically allocate an unused local port for the new + * connection. However, another port can be chosen by using the + * uip_udp_bind() call, after the uip_udp_new() function has been + * called. + * + * Example: + \code + uip_ipaddr_t addr; + struct uip_udp_conn *c; + + uip_ipaddr(&addr, 192,168,2,1); + c = uip_udp_new(&addr, HTONS(12345)); + if(c != NULL) { + uip_udp_bind(c, HTONS(12344)); + } + \endcode + * \param ripaddr The IP address of the remote host. + * + * \param rport The remote port number in network byte order. + * + * \return The uip_udp_conn structure for the new connection or NULL + * if no connection could be allocated. + */ +struct uip_udp_conn *uip_udp_new(uip_ipaddr_t *ripaddr, u16_t rport); + +/** + * Removed a UDP connection. + * + * \param conn A pointer to the uip_udp_conn structure for the connection. + * + * \hideinitializer + */ +#define uip_udp_remove(conn) (conn)->lport = 0 + +/** + * Bind a UDP connection to a local port. + * + * \param conn A pointer to the uip_udp_conn structure for the + * connection. + * + * \param port The local port number, in network byte order. + * + * \hideinitializer + */ +#define uip_udp_bind(conn, port) (conn)->lport = port + +/** + * Send a UDP datagram of length len on the current connection. + * + * This function can only be called in response to a UDP event (poll + * or newdata). The data must be present in the uip_buf buffer, at the + * place pointed to by the uip_appdata pointer. + * + * \param len The length of the data in the uip_buf buffer. + * + * \hideinitializer + */ +#define uip_udp_send(len) uip_send((char *)uip_appdata, len) + +/** @} */ + +/* uIP convenience and converting functions. */ + +/** + * \defgroup uipconvfunc uIP conversion functions + * @{ + * + * These functions can be used for converting between different data + * formats used by uIP. + */ + +/** + * Construct an IP address from four bytes. + * + * This function constructs an IP address of the type that uIP handles + * internally from four bytes. The function is handy for specifying IP + * addresses to use with e.g. the uip_connect() function. + * + * Example: + \code + uip_ipaddr_t ipaddr; + struct uip_conn *c; + + uip_ipaddr(&ipaddr, 192,168,1,2); + c = uip_connect(&ipaddr, HTONS(80)); + \endcode + * + * \param addr A pointer to a uip_ipaddr_t variable that will be + * filled in with the IP address. + * + * \param addr0 The first octet of the IP address. + * \param addr1 The second octet of the IP address. + * \param addr2 The third octet of the IP address. + * \param addr3 The forth octet of the IP address. + * + * \hideinitializer + */ +#define uip_ipaddr(addr, addr0,addr1,addr2,addr3) do { \ + ((u16_t *)(addr))[0] = HTONS(((addr0) << 8) | (addr1)); \ + ((u16_t *)(addr))[1] = HTONS(((addr2) << 8) | (addr3)); \ + } while(0) + +/** + * Construct an IPv6 address from eight 16-bit words. + * + * This function constructs an IPv6 address. + * + * \hideinitializer + */ +#define uip_ip6addr(addr, addr0,addr1,addr2,addr3,addr4,addr5,addr6,addr7) do { \ + ((u16_t *)(addr))[0] = HTONS((addr0)); \ + ((u16_t *)(addr))[1] = HTONS((addr1)); \ + ((u16_t *)(addr))[2] = HTONS((addr2)); \ + ((u16_t *)(addr))[3] = HTONS((addr3)); \ + ((u16_t *)(addr))[4] = HTONS((addr4)); \ + ((u16_t *)(addr))[5] = HTONS((addr5)); \ + ((u16_t *)(addr))[6] = HTONS((addr6)); \ + ((u16_t *)(addr))[7] = HTONS((addr7)); \ + } while(0) + +/** + * Copy an IP address to another IP address. + * + * Copies an IP address from one place to another. + * + * Example: + \code + uip_ipaddr_t ipaddr1, ipaddr2; + + uip_ipaddr(&ipaddr1, 192,16,1,2); + uip_ipaddr_copy(&ipaddr2, &ipaddr1); + \endcode + * + * \param dest The destination for the copy. + * \param src The source from where to copy. + * + * \hideinitializer + */ +#if !UIP_CONF_IPV6 +#define uip_ipaddr_copy(dest, src) do { \ + ((u16_t *)dest)[0] = ((u16_t *)src)[0]; \ + ((u16_t *)dest)[1] = ((u16_t *)src)[1]; \ + } while(0) +#else /* !UIP_CONF_IPV6 */ +#define uip_ipaddr_copy(dest, src) memcpy(dest, src, sizeof(uip_ip6addr_t)) +#endif /* !UIP_CONF_IPV6 */ + +/** + * Compare two IP addresses + * + * Compares two IP addresses. + * + * Example: + \code + uip_ipaddr_t ipaddr1, ipaddr2; + + uip_ipaddr(&ipaddr1, 192,16,1,2); + if(uip_ipaddr_cmp(&ipaddr2, &ipaddr1)) { + printf("They are the same"); + } + \endcode + * + * \param addr1 The first IP address. + * \param addr2 The second IP address. + * + * \hideinitializer + */ +#if !UIP_CONF_IPV6 +#define uip_ipaddr_cmp(addr1, addr2) (((u16_t *)addr1)[0] == ((u16_t *)addr2)[0] && \ + ((u16_t *)addr1)[1] == ((u16_t *)addr2)[1]) +#else /* !UIP_CONF_IPV6 */ +#define uip_ipaddr_cmp(addr1, addr2) (memcmp(addr1, addr2, sizeof(uip_ip6addr_t)) == 0) +#endif /* !UIP_CONF_IPV6 */ + +/** + * Compare two IP addresses with netmasks + * + * Compares two IP addresses with netmasks. The masks are used to mask + * out the bits that are to be compared. + * + * Example: + \code + uip_ipaddr_t ipaddr1, ipaddr2, mask; + + uip_ipaddr(&mask, 255,255,255,0); + uip_ipaddr(&ipaddr1, 192,16,1,2); + uip_ipaddr(&ipaddr2, 192,16,1,3); + if(uip_ipaddr_maskcmp(&ipaddr1, &ipaddr2, &mask)) { + printf("They are the same"); + } + \endcode + * + * \param addr1 The first IP address. + * \param addr2 The second IP address. + * \param mask The netmask. + * + * \hideinitializer + */ +#define uip_ipaddr_maskcmp(addr1, addr2, mask) \ + (((((u16_t *)addr1)[0] & ((u16_t *)mask)[0]) == \ + (((u16_t *)addr2)[0] & ((u16_t *)mask)[0])) && \ + ((((u16_t *)addr1)[1] & ((u16_t *)mask)[1]) == \ + (((u16_t *)addr2)[1] & ((u16_t *)mask)[1]))) + + +/** + * Mask out the network part of an IP address. + * + * Masks out the network part of an IP address, given the address and + * the netmask. + * + * Example: + \code + uip_ipaddr_t ipaddr1, ipaddr2, netmask; + + uip_ipaddr(&ipaddr1, 192,16,1,2); + uip_ipaddr(&netmask, 255,255,255,0); + uip_ipaddr_mask(&ipaddr2, &ipaddr1, &netmask); + \endcode + * + * In the example above, the variable "ipaddr2" will contain the IP + * address 192.168.1.0. + * + * \param dest Where the result is to be placed. + * \param src The IP address. + * \param mask The netmask. + * + * \hideinitializer + */ +#define uip_ipaddr_mask(dest, src, mask) do { \ + ((u16_t *)dest)[0] = ((u16_t *)src)[0] & ((u16_t *)mask)[0]; \ + ((u16_t *)dest)[1] = ((u16_t *)src)[1] & ((u16_t *)mask)[1]; \ + } while(0) + +/** + * Pick the first octet of an IP address. + * + * Picks out the first octet of an IP address. + * + * Example: + \code + uip_ipaddr_t ipaddr; + u8_t octet; + + uip_ipaddr(&ipaddr, 1,2,3,4); + octet = uip_ipaddr1(&ipaddr); + \endcode + * + * In the example above, the variable "octet" will contain the value 1. + * + * \hideinitializer + */ +#define uip_ipaddr1(addr) (htons(((u16_t *)(addr))[0]) >> 8) + +/** + * Pick the second octet of an IP address. + * + * Picks out the second octet of an IP address. + * + * Example: + \code + uip_ipaddr_t ipaddr; + u8_t octet; + + uip_ipaddr(&ipaddr, 1,2,3,4); + octet = uip_ipaddr2(&ipaddr); + \endcode + * + * In the example above, the variable "octet" will contain the value 2. + * + * \hideinitializer + */ +#define uip_ipaddr2(addr) (htons(((u16_t *)(addr))[0]) & 0xff) + +/** + * Pick the third octet of an IP address. + * + * Picks out the third octet of an IP address. + * + * Example: + \code + uip_ipaddr_t ipaddr; + u8_t octet; + + uip_ipaddr(&ipaddr, 1,2,3,4); + octet = uip_ipaddr3(&ipaddr); + \endcode + * + * In the example above, the variable "octet" will contain the value 3. + * + * \hideinitializer + */ +#define uip_ipaddr3(addr) (htons(((u16_t *)(addr))[1]) >> 8) + +/** + * Pick the fourth octet of an IP address. + * + * Picks out the fourth octet of an IP address. + * + * Example: + \code + uip_ipaddr_t ipaddr; + u8_t octet; + + uip_ipaddr(&ipaddr, 1,2,3,4); + octet = uip_ipaddr4(&ipaddr); + \endcode + * + * In the example above, the variable "octet" will contain the value 4. + * + * \hideinitializer + */ +#define uip_ipaddr4(addr) (htons(((u16_t *)(addr))[1]) & 0xff) + +/** + * Convert 16-bit quantity from host byte order to network byte order. + * + * This macro is primarily used for converting constants from host + * byte order to network byte order. For converting variables to + * network byte order, use the htons() function instead. + * + * \hideinitializer + */ +#ifndef HTONS +# if UIP_BYTE_ORDER == UIP_BIG_ENDIAN +# define HTONS(n) (n) +# else /* UIP_BYTE_ORDER == UIP_BIG_ENDIAN */ +# define HTONS(n) (u16_t)((((u16_t) (n)) << 8) | (((u16_t) (n)) >> 8)) +# endif /* UIP_BYTE_ORDER == UIP_BIG_ENDIAN */ +#else +#error "HTONS already defined!" +#endif /* HTONS */ + +/** + * Convert 16-bit quantity from host byte order to network byte order. + * + * This function is primarily used for converting variables from host + * byte order to network byte order. For converting constants to + * network byte order, use the HTONS() macro instead. + */ +#ifndef htons +u16_t htons(u16_t val); +#endif /* htons */ +#ifndef ntohs +#define ntohs htons +#endif + +/** @} */ + +/** + * Pointer to the application data in the packet buffer. + * + * This pointer points to the application data when the application is + * called. If the application wishes to send data, the application may + * use this space to write the data into before calling uip_send(). + */ +extern void *uip_appdata; + +#if UIP_URGDATA > 0 +/* u8_t *uip_urgdata: + * + * This pointer points to any urgent data that has been received. Only + * present if compiled with support for urgent data (UIP_URGDATA). + */ +extern void *uip_urgdata; +#endif /* UIP_URGDATA > 0 */ + + +/** + * \defgroup uipdrivervars Variables used in uIP device drivers + * @{ + * + * uIP has a few global variables that are used in device drivers for + * uIP. + */ + +/** + * The length of the packet in the uip_buf buffer. + * + * The global variable uip_len holds the length of the packet in the + * uip_buf buffer. + * + * When the network device driver calls the uIP input function, + * uip_len should be set to the length of the packet in the uip_buf + * buffer. + * + * When sending packets, the device driver should use the contents of + * the uip_len variable to determine the length of the outgoing + * packet. + * + */ +extern u16_t uip_len; + +/** @} */ + +#if UIP_URGDATA > 0 +extern u16_t uip_urglen, uip_surglen; +#endif /* UIP_URGDATA > 0 */ + + +/** + * Representation of a uIP TCP connection. + * + * The uip_conn structure is used for identifying a connection. All + * but one field in the structure are to be considered read-only by an + * application. The only exception is the appstate field whos purpose + * is to let the application store application-specific state (e.g., + * file pointers) for the connection. The type of this field is + * configured in the "uipopt.h" header file. + */ +struct uip_conn { + uip_ipaddr_t ripaddr; /**< The IP address of the remote host. */ + + u16_t lport; /**< The local TCP port, in network byte order. */ + u16_t rport; /**< The local remote TCP port, in network byte + order. */ + + u8_t rcv_nxt[4]; /**< The sequence number that we expect to + receive next. */ + u8_t snd_nxt[4]; /**< The sequence number that was last sent by + us. */ + u16_t len; /**< Length of the data that was previously sent. */ + u16_t mss; /**< Current maximum segment size for the + connection. */ + u16_t initialmss; /**< Initial maximum segment size for the + connection. */ + u8_t sa; /**< Retransmission time-out calculation state + variable. */ + u8_t sv; /**< Retransmission time-out calculation state + variable. */ + u8_t rto; /**< Retransmission time-out. */ + u8_t tcpstateflags; /**< TCP state and flags. */ + u8_t timer; /**< The retransmission timer. */ + u8_t nrtx; /**< The number of retransmissions for the last + segment sent. */ + + /** The application state. */ + uip_tcp_appstate_t appstate; +}; + + +/** + * Pointer to the current TCP connection. + * + * The uip_conn pointer can be used to access the current TCP + * connection. + */ +extern struct uip_conn *uip_conn; +/* The array containing all uIP connections. */ +extern struct uip_conn uip_conns[UIP_CONNS]; +/** + * \addtogroup uiparch + * @{ + */ + +/** + * 4-byte array used for the 32-bit sequence number calculations. + */ +extern u8_t uip_acc32[4]; + +/** @} */ + + +#if UIP_UDP +/** + * Representation of a uIP UDP connection. + */ +struct uip_udp_conn { + uip_ipaddr_t ripaddr; /**< The IP address of the remote peer. */ + u16_t lport; /**< The local port number in network byte order. */ + u16_t rport; /**< The remote port number in network byte order. */ + u8_t ttl; /**< Default time-to-live. */ + + /** The application state. */ + uip_udp_appstate_t appstate; +}; + +/** + * The current UDP connection. + */ +extern struct uip_udp_conn *uip_udp_conn; +extern struct uip_udp_conn uip_udp_conns[UIP_UDP_CONNS]; +#endif /* UIP_UDP */ + +/** + * The structure holding the TCP/IP statistics that are gathered if + * UIP_STATISTICS is set to 1. + * + */ +struct uip_stats { + struct { + uip_stats_t drop; /**< Number of dropped packets at the IP + layer. */ + uip_stats_t recv; /**< Number of received packets at the IP + layer. */ + uip_stats_t sent; /**< Number of sent packets at the IP + layer. */ + uip_stats_t vhlerr; /**< Number of packets dropped due to wrong + IP version or header length. */ + uip_stats_t hblenerr; /**< Number of packets dropped due to wrong + IP length, high byte. */ + uip_stats_t lblenerr; /**< Number of packets dropped due to wrong + IP length, low byte. */ + uip_stats_t fragerr; /**< Number of packets dropped since they + were IP fragments. */ + uip_stats_t chkerr; /**< Number of packets dropped due to IP + checksum errors. */ + uip_stats_t protoerr; /**< Number of packets dropped since they + were neither ICMP, UDP nor TCP. */ + } ip; /**< IP statistics. */ + struct { + uip_stats_t drop; /**< Number of dropped ICMP packets. */ + uip_stats_t recv; /**< Number of received ICMP packets. */ + uip_stats_t sent; /**< Number of sent ICMP packets. */ + uip_stats_t typeerr; /**< Number of ICMP packets with a wrong + type. */ + } icmp; /**< ICMP statistics. */ + struct { + uip_stats_t drop; /**< Number of dropped TCP segments. */ + uip_stats_t recv; /**< Number of recived TCP segments. */ + uip_stats_t sent; /**< Number of sent TCP segments. */ + uip_stats_t chkerr; /**< Number of TCP segments with a bad + checksum. */ + uip_stats_t ackerr; /**< Number of TCP segments with a bad ACK + number. */ + uip_stats_t rst; /**< Number of recevied TCP RST (reset) segments. */ + uip_stats_t rexmit; /**< Number of retransmitted TCP segments. */ + uip_stats_t syndrop; /**< Number of dropped SYNs due to too few + connections was avaliable. */ + uip_stats_t synrst; /**< Number of SYNs for closed ports, + triggering a RST. */ + } tcp; /**< TCP statistics. */ +#if UIP_UDP + struct { + uip_stats_t drop; /**< Number of dropped UDP segments. */ + uip_stats_t recv; /**< Number of recived UDP segments. */ + uip_stats_t sent; /**< Number of sent UDP segments. */ + uip_stats_t chkerr; /**< Number of UDP segments with a bad + checksum. */ + } udp; /**< UDP statistics. */ +#endif /* UIP_UDP */ +}; + +/** + * The uIP TCP/IP statistics. + * + * This is the variable in which the uIP TCP/IP statistics are gathered. + */ +extern struct uip_stats uip_stat; + + +/*---------------------------------------------------------------------------*/ +/* All the stuff below this point is internal to uIP and should not be + * used directly by an application or by a device driver. + */ +/*---------------------------------------------------------------------------*/ +/* u8_t uip_flags: + * + * When the application is called, uip_flags will contain the flags + * that are defined in this file. Please read below for more + * infomation. + */ +extern u8_t uip_flags; + +/* The following flags may be set in the global variable uip_flags + before calling the application callback. The UIP_ACKDATA, + UIP_NEWDATA, and UIP_CLOSE flags may both be set at the same time, + whereas the others are mutualy exclusive. Note that these flags + should *NOT* be accessed directly, but only through the uIP + functions/macros. */ + +#define UIP_ACKDATA 1 /* Signifies that the outstanding data was + acked and the application should send + out new data instead of retransmitting + the last data. */ +#define UIP_NEWDATA 2 /* Flags the fact that the peer has sent + us new data. */ +#define UIP_REXMIT 4 /* Tells the application to retransmit the + data that was last sent. */ +#define UIP_POLL 8 /* Used for polling the application, to + check if the application has data that + it wants to send. */ +#define UIP_CLOSE 16 /* The remote host has closed the + connection, thus the connection has + gone away. Or the application signals + that it wants to close the + connection. */ +#define UIP_ABORT 32 /* The remote host has aborted the + connection, thus the connection has + gone away. Or the application signals + that it wants to abort the + connection. */ +#define UIP_CONNECTED 64 /* We have got a connection from a remote + host and have set up a new connection + for it, or an active connection has + been successfully established. */ + +#define UIP_TIMEDOUT 128 /* The connection has been aborted due to + too many retransmissions. */ + +/* uip_process(flag): + * + * The actual uIP function which does all the work. + */ +void uip_process(u8_t flag); + +/* The following flags are passed as an argument to the uip_process() + function. They are used to distinguish between the two cases where + uip_process() is called. It can be called either because we have + incoming data that should be processed, or because the periodic + timer has fired. These values are never used directly, but only in + the macrose defined in this file. */ + +#define UIP_DATA 1 /* Tells uIP that there is incoming + data in the uip_buf buffer. The + length of the data is stored in the + global variable uip_len. */ +#define UIP_TIMER 2 /* Tells uIP that the periodic timer + has fired. */ +#define UIP_POLL_REQUEST 3 /* Tells uIP that a connection should + be polled. */ +#define UIP_UDP_SEND_CONN 4 /* Tells uIP that a UDP datagram + should be constructed in the + uip_buf buffer. */ +#if UIP_UDP +#define UIP_UDP_TIMER 5 +#endif /* UIP_UDP */ + +/* The TCP states used in the uip_conn->tcpstateflags. */ +#define UIP_CLOSED 0 +#define UIP_SYN_RCVD 1 +#define UIP_SYN_SENT 2 +#define UIP_ESTABLISHED 3 +#define UIP_FIN_WAIT_1 4 +#define UIP_FIN_WAIT_2 5 +#define UIP_CLOSING 6 +#define UIP_TIME_WAIT 7 +#define UIP_LAST_ACK 8 +#define UIP_TS_MASK 15 + +#define UIP_STOPPED 16 + +/* The TCP and IP headers. */ +struct uip_tcpip_hdr { +#if UIP_CONF_IPV6 + /* IPv6 header. */ + u8_t vtc, + tcflow; + u16_t flow; + u8_t len[2]; + u8_t proto, ttl; + uip_ip6addr_t srcipaddr, destipaddr; +#else /* UIP_CONF_IPV6 */ + /* IPv4 header. */ + u8_t vhl, + tos, + len[2], + ipid[2], + ipoffset[2], + ttl, + proto; + u16_t ipchksum; + u16_t srcipaddr[2], + destipaddr[2]; +#endif /* UIP_CONF_IPV6 */ + + /* TCP header. */ + u16_t srcport, + destport; + u8_t seqno[4], + ackno[4], + tcpoffset, + flags, + wnd[2]; + u16_t tcpchksum; + u8_t urgp[2]; + u8_t optdata[4]; +}; + +/* The ICMP and IP headers. */ +struct uip_icmpip_hdr { +#if UIP_CONF_IPV6 + /* IPv6 header. */ + u8_t vtc, + tcf; + u16_t flow; + u8_t len[2]; + u8_t proto, ttl; + uip_ip6addr_t srcipaddr, destipaddr; +#else /* UIP_CONF_IPV6 */ + /* IPv4 header. */ + u8_t vhl, + tos, + len[2], + ipid[2], + ipoffset[2], + ttl, + proto; + u16_t ipchksum; + u16_t srcipaddr[2], + destipaddr[2]; +#endif /* UIP_CONF_IPV6 */ + + /* ICMP (echo) header. */ + u8_t type, icode; + u16_t icmpchksum; +#if !UIP_CONF_IPV6 + u16_t id, seqno; +#else /* !UIP_CONF_IPV6 */ + u8_t flags, reserved1, reserved2, reserved3; + u8_t icmp6data[16]; + u8_t options[1]; +#endif /* !UIP_CONF_IPV6 */ +}; + + +/* The UDP and IP headers. */ +struct uip_udpip_hdr { +#if UIP_CONF_IPV6 + /* IPv6 header. */ + u8_t vtc, + tcf; + u16_t flow; + u8_t len[2]; + u8_t proto, ttl; + uip_ip6addr_t srcipaddr, destipaddr; +#else /* UIP_CONF_IPV6 */ + /* IP header. */ + u8_t vhl, + tos, + len[2], + ipid[2], + ipoffset[2], + ttl, + proto; + u16_t ipchksum; + u16_t srcipaddr[2], + destipaddr[2]; +#endif /* UIP_CONF_IPV6 */ + + /* UDP header. */ + u16_t srcport, + destport; + u16_t udplen; + u16_t udpchksum; +}; + + + +/** + * The buffer size available for user data in the \ref uip_buf buffer. + * + * This macro holds the available size for user data in the \ref + * uip_buf buffer. The macro is intended to be used for checking + * bounds of available user data. + * + * Example: + \code + snprintf(uip_appdata, UIP_APPDATA_SIZE, "%u\n", i); + \endcode + * + * \hideinitializer + */ +#define UIP_APPDATA_SIZE (UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN) + + +#define UIP_PROTO_ICMP 1 +#define UIP_PROTO_TCP 6 +#define UIP_PROTO_UDP 17 +#define UIP_PROTO_ICMP6 58 + +/* Header sizes. */ +#if UIP_CONF_IPV6 +#define UIP_IPH_LEN 40 +#else /* UIP_CONF_IPV6 */ +#define UIP_IPH_LEN 20 /* Size of IP header */ +#endif /* UIP_CONF_IPV6 */ +#define UIP_UDPH_LEN 8 /* Size of UDP header */ +#define UIP_TCPH_LEN 20 /* Size of TCP header */ +#define UIP_IPUDPH_LEN (UIP_UDPH_LEN + UIP_IPH_LEN) /* Size of IP + + UDP + header */ +#define UIP_IPTCPH_LEN (UIP_TCPH_LEN + UIP_IPH_LEN) /* Size of IP + + TCP + header */ +#define UIP_TCPIP_HLEN UIP_IPTCPH_LEN + + +#if UIP_FIXEDADDR +extern const uip_ipaddr_t uip_hostaddr, uip_netmask, uip_draddr; +#else /* UIP_FIXEDADDR */ +extern uip_ipaddr_t uip_hostaddr, uip_netmask, uip_draddr; +#endif /* UIP_FIXEDADDR */ + + + +/** + * Representation of a 48-bit Ethernet address. + */ +struct uip_eth_addr { + u8_t addr[6]; +}; + +/** + * Calculate the Internet checksum over a buffer. + * + * The Internet checksum is the one's complement of the one's + * complement sum of all 16-bit words in the buffer. + * + * See RFC1071. + * + * \param buf A pointer to the buffer over which the checksum is to be + * computed. + * + * \param len The length of the buffer over which the checksum is to + * be computed. + * + * \return The Internet checksum of the buffer. + */ +u16_t uip_chksum(u16_t *buf, u16_t len); + +/** + * Calculate the IP header checksum of the packet header in uip_buf. + * + * The IP header checksum is the Internet checksum of the 20 bytes of + * the IP header. + * + * \return The IP header checksum of the IP header in the uip_buf + * buffer. + */ +u16_t uip_ipchksum(void); + +/** + * Calculate the TCP checksum of the packet in uip_buf and uip_appdata. + * + * The TCP checksum is the Internet checksum of data contents of the + * TCP segment, and a pseudo-header as defined in RFC793. + * + * \return The TCP checksum of the TCP segment in uip_buf and pointed + * to by uip_appdata. + */ +u16_t uip_tcpchksum(void); + +/** + * Calculate the UDP checksum of the packet in uip_buf and uip_appdata. + * + * The UDP checksum is the Internet checksum of data contents of the + * UDP segment, and a pseudo-header as defined in RFC768. + * + * \return The UDP checksum of the UDP segment in uip_buf and pointed + * to by uip_appdata. + */ +u16_t uip_udpchksum(void); + + +#endif /* __UIP_H__ */ + + +/** @} */ diff --git a/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/uip_arch.h b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/uip_arch.h new file mode 100644 index 0000000..71fd84b --- /dev/null +++ b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/uip_arch.h @@ -0,0 +1,138 @@ +/** + * \addtogroup uip + * {@ + */ + +/** + * \defgroup uiparch Architecture specific uIP functions + * @{ + * + * The functions in the architecture specific module implement the IP + * check sum and 32-bit additions. + * + * The IP checksum calculation is the most computationally expensive + * operation in the TCP/IP stack and it therefore pays off to + * implement this in efficient assembler. The purpose of the uip-arch + * module is to let the checksum functions to be implemented in + * architecture specific assembler. + * + */ + +/** + * \file + * Declarations of architecture specific functions. + * \author Adam Dunkels + */ + +/* + * Copyright (c) 2001, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This file is part of the uIP TCP/IP stack. + * + * $Id: uip_arch.h,v 1.2 2006/06/07 09:15:19 adam Exp $ + * + */ + +#ifndef __UIP_ARCH_H__ +#define __UIP_ARCH_H__ + +#include "uip.h" + +/** + * Carry out a 32-bit addition. + * + * Because not all architectures for which uIP is intended has native + * 32-bit arithmetic, uIP uses an external C function for doing the + * required 32-bit additions in the TCP protocol processing. This + * function should add the two arguments and place the result in the + * global variable uip_acc32. + * + * \note The 32-bit integer pointed to by the op32 parameter and the + * result in the uip_acc32 variable are in network byte order (big + * endian). + * + * \param op32 A pointer to a 4-byte array representing a 32-bit + * integer in network byte order (big endian). + * + * \param op16 A 16-bit integer in host byte order. + */ +void uip_add32(u8_t *op32, u16_t op16); + +/** + * Calculate the Internet checksum over a buffer. + * + * The Internet checksum is the one's complement of the one's + * complement sum of all 16-bit words in the buffer. + * + * See RFC1071. + * + * \note This function is not called in the current version of uIP, + * but future versions might make use of it. + * + * \param buf A pointer to the buffer over which the checksum is to be + * computed. + * + * \param len The length of the buffer over which the checksum is to + * be computed. + * + * \return The Internet checksum of the buffer. + */ +u16_t uip_chksum(u16_t *buf, u16_t len); + +/** + * Calculate the IP header checksum of the packet header in uip_buf. + * + * The IP header checksum is the Internet checksum of the 20 bytes of + * the IP header. + * + * \return The IP header checksum of the IP header in the uip_buf + * buffer. + */ +u16_t uip_ipchksum(void); + +/** + * Calculate the TCP checksum of the packet in uip_buf and uip_appdata. + * + * The TCP checksum is the Internet checksum of data contents of the + * TCP segment, and a pseudo-header as defined in RFC793. + * + * \note The uip_appdata pointer that points to the packet data may + * point anywhere in memory, so it is not possible to simply calculate + * the Internet checksum of the contents of the uip_buf buffer. + * + * \return The TCP checksum of the TCP segment in uip_buf and pointed + * to by uip_appdata. + */ +u16_t uip_tcpchksum(void); + +u16_t uip_udpchksum(void); + +/** @} */ +/** @} */ + +#endif /* __UIP_ARCH_H__ */ diff --git a/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/uip_arp.c b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/uip_arp.c new file mode 100644 index 0000000..86b4df8 --- /dev/null +++ b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/uip_arp.c @@ -0,0 +1,422 @@ +/** + * \addtogroup uip + * @{ + */ + +/** + * \defgroup uiparp uIP Address Resolution Protocol + * @{ + * + * The Address Resolution Protocol ARP is used for mapping between IP + * addresses and link level addresses such as the Ethernet MAC + * addresses. ARP uses broadcast queries to ask for the link level + * address of a known IP address and the host which is configured with + * the IP address for which the query was meant, will respond with its + * link level address. + * + * \note This ARP implementation only supports Ethernet. + */ + +/** + * \file + * Implementation of the ARP Address Resolution Protocol. + * \author Adam Dunkels + * + */ + +/* + * Copyright (c) 2001-2003, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This file is part of the uIP TCP/IP stack. + * + * $Id: uip_arp.c,v 1.8 2006/06/02 23:36:21 adam Exp $ + * + */ + + +#include "uip_arp.h" + +#include + +struct arp_hdr { + struct uip_eth_hdr ethhdr; + u16_t hwtype; + u16_t protocol; + u8_t hwlen; + u8_t protolen; + u16_t opcode; + struct uip_eth_addr shwaddr; + u16_t sipaddr[2]; + struct uip_eth_addr dhwaddr; + u16_t dipaddr[2]; +}; + +struct ethip_hdr { + struct uip_eth_hdr ethhdr; + /* IP header. */ + u8_t vhl, + tos, + len[2], + ipid[2], + ipoffset[2], + ttl, + proto; + u16_t ipchksum; + u16_t srcipaddr[2], + destipaddr[2]; +}; + +#define ARP_REQUEST 1 +#define ARP_REPLY 2 + +#define ARP_HWTYPE_ETH 1 + +struct arp_entry { + u16_t ipaddr[2]; + struct uip_eth_addr ethaddr; + u8_t time; +}; + +static const struct uip_eth_addr broadcast_ethaddr = + {{0xff,0xff,0xff,0xff,0xff,0xff}}; +static const u16_t broadcast_ipaddr[2] = {0xffff,0xffff}; + +static struct arp_entry arp_table[UIP_ARPTAB_SIZE]; +static u16_t ipaddr[2]; +static u8_t i, c; + +static u8_t arptime; +static u8_t tmpage; + +#define BUF ((struct arp_hdr *)&uip_buf[0]) +#define IPBUF ((struct ethip_hdr *)&uip_buf[0]) +/*-----------------------------------------------------------------------------------*/ +/** + * Initialize the ARP module. + * + */ +/*-----------------------------------------------------------------------------------*/ +void +uip_arp_init(void) +{ + for(i = 0; i < UIP_ARPTAB_SIZE; ++i) { + memset(arp_table[i].ipaddr, 0, 4); + } +} +/*-----------------------------------------------------------------------------------*/ +/** + * Periodic ARP processing function. + * + * This function performs periodic timer processing in the ARP module + * and should be called at regular intervals. The recommended interval + * is 10 seconds between the calls. + * + */ +/*-----------------------------------------------------------------------------------*/ +void +uip_arp_timer(void) +{ + struct arp_entry *tabptr; + + ++arptime; + for(i = 0; i < UIP_ARPTAB_SIZE; ++i) { + tabptr = &arp_table[i]; + if((tabptr->ipaddr[0] | tabptr->ipaddr[1]) != 0 && + arptime - tabptr->time >= UIP_ARP_MAXAGE) { + memset(tabptr->ipaddr, 0, 4); + } + } + +} +/*-----------------------------------------------------------------------------------*/ +static void +uip_arp_update(u16_t *ipaddr, struct uip_eth_addr *ethaddr) +{ + register struct arp_entry *tabptr; + /* Walk through the ARP mapping table and try to find an entry to + update. If none is found, the IP -> MAC address mapping is + inserted in the ARP table. */ + for(i = 0; i < UIP_ARPTAB_SIZE; ++i) { + + tabptr = &arp_table[i]; + /* Only check those entries that are actually in use. */ + if(tabptr->ipaddr[0] != 0 && + tabptr->ipaddr[1] != 0) { + + /* Check if the source IP address of the incoming packet matches + the IP address in this ARP table entry. */ + if(memcmp(ipaddr, tabptr->ipaddr, 4) == 0) { + + /* An old entry found, update this and return. */ + memcpy(tabptr->ethaddr.addr, ethaddr->addr, 6); + tabptr->time = arptime; + + return; + } + } + } + + /* If we get here, no existing ARP table entry was found, so we + create one. */ + + /* First, we try to find an unused entry in the ARP table. */ + for(i = 0; i < UIP_ARPTAB_SIZE; ++i) { + tabptr = &arp_table[i]; + if(tabptr->ipaddr[0] == 0 && + tabptr->ipaddr[1] == 0) { + break; + } + } + + /* If no unused entry is found, we try to find the oldest entry and + throw it away. */ + if(i == UIP_ARPTAB_SIZE) { + tmpage = 0; + c = 0; + for(i = 0; i < UIP_ARPTAB_SIZE; ++i) { + tabptr = &arp_table[i]; + if(arptime - tabptr->time > tmpage) { + tmpage = arptime - tabptr->time; + c = i; + } + } + i = c; + tabptr = &arp_table[i]; + } + + /* Now, i is the ARP table entry which we will fill with the new + information. */ + memcpy(tabptr->ipaddr, ipaddr, 4); + memcpy(tabptr->ethaddr.addr, ethaddr->addr, 6); + tabptr->time = arptime; +} +/*-----------------------------------------------------------------------------------*/ +/** + * ARP processing for incoming IP packets + * + * This function should be called by the device driver when an IP + * packet has been received. The function will check if the address is + * in the ARP cache, and if so the ARP cache entry will be + * refreshed. If no ARP cache entry was found, a new one is created. + * + * This function expects an IP packet with a prepended Ethernet header + * in the uip_buf[] buffer, and the length of the packet in the global + * variable uip_len. + */ +/*-----------------------------------------------------------------------------------*/ +//#if 0 +void +uip_arp_ipin(void) +{ + uip_len -= sizeof(struct uip_eth_hdr); + + /* Only insert/update an entry if the source IP address of the + incoming IP packet comes from a host on the local network. */ + if((IPBUF->srcipaddr[0] & uip_netmask[0]) != + (uip_hostaddr[0] & uip_netmask[0])) { + return; + } + if((IPBUF->srcipaddr[1] & uip_netmask[1]) != + (uip_hostaddr[1] & uip_netmask[1])) { + return; + } + uip_arp_update(IPBUF->srcipaddr, &(IPBUF->ethhdr.src)); + + return; +} +//#endif /* 0 */ +/*-----------------------------------------------------------------------------------*/ +/** + * ARP processing for incoming ARP packets. + * + * This function should be called by the device driver when an ARP + * packet has been received. The function will act differently + * depending on the ARP packet type: if it is a reply for a request + * that we previously sent out, the ARP cache will be filled in with + * the values from the ARP reply. If the incoming ARP packet is an ARP + * request for our IP address, an ARP reply packet is created and put + * into the uip_buf[] buffer. + * + * When the function returns, the value of the global variable uip_len + * indicates whether the device driver should send out a packet or + * not. If uip_len is zero, no packet should be sent. If uip_len is + * non-zero, it contains the length of the outbound packet that is + * present in the uip_buf[] buffer. + * + * This function expects an ARP packet with a prepended Ethernet + * header in the uip_buf[] buffer, and the length of the packet in the + * global variable uip_len. + */ +/*-----------------------------------------------------------------------------------*/ +void +uip_arp_arpin(void) +{ + + if(uip_len < sizeof(struct arp_hdr)) { + uip_len = 0; + return; + } + uip_len = 0; + + switch(BUF->opcode) { + case HTONS(ARP_REQUEST): + /* ARP request. If it asked for our address, we send out a + reply. */ + if(uip_ipaddr_cmp(BUF->dipaddr, uip_hostaddr)) { + /* First, we register the one who made the request in our ARP + table, since it is likely that we will do more communication + with this host in the future. */ + uip_arp_update(BUF->sipaddr, &BUF->shwaddr); + + /* The reply opcode is 2. */ + BUF->opcode = HTONS(2); + + memcpy(BUF->dhwaddr.addr, BUF->shwaddr.addr, 6); + memcpy(BUF->shwaddr.addr, uip_ethaddr.addr, 6); + memcpy(BUF->ethhdr.src.addr, uip_ethaddr.addr, 6); + memcpy(BUF->ethhdr.dest.addr, BUF->dhwaddr.addr, 6); + + BUF->dipaddr[0] = BUF->sipaddr[0]; + BUF->dipaddr[1] = BUF->sipaddr[1]; + BUF->sipaddr[0] = uip_hostaddr[0]; + BUF->sipaddr[1] = uip_hostaddr[1]; + + BUF->ethhdr.type = HTONS(UIP_ETHTYPE_ARP); + uip_len = sizeof(struct arp_hdr); + } + break; + case HTONS(ARP_REPLY): + /* ARP reply. We insert or update the ARP table if it was meant + for us. */ + if(uip_ipaddr_cmp(BUF->dipaddr, uip_hostaddr)) { + uip_arp_update(BUF->sipaddr, &BUF->shwaddr); + } + break; + } + + return; +} +/*-----------------------------------------------------------------------------------*/ +/** + * Prepend Ethernet header to an outbound IP packet and see if we need + * to send out an ARP request. + * + * This function should be called before sending out an IP packet. The + * function checks the destination IP address of the IP packet to see + * what Ethernet MAC address that should be used as a destination MAC + * address on the Ethernet. + * + * If the destination IP address is in the local network (determined + * by logical ANDing of netmask and our IP address), the function + * checks the ARP cache to see if an entry for the destination IP + * address is found. If so, an Ethernet header is prepended and the + * function returns. If no ARP cache entry is found for the + * destination IP address, the packet in the uip_buf[] is replaced by + * an ARP request packet for the IP address. The IP packet is dropped + * and it is assumed that they higher level protocols (e.g., TCP) + * eventually will retransmit the dropped packet. + * + * If the destination IP address is not on the local network, the IP + * address of the default router is used instead. + * + * When the function returns, a packet is present in the uip_buf[] + * buffer, and the length of the packet is in the global variable + * uip_len. + */ +/*-----------------------------------------------------------------------------------*/ +void +uip_arp_out(void) +{ + struct arp_entry *tabptr; + + /* Find the destination IP address in the ARP table and construct + the Ethernet header. If the destination IP addres isn't on the + local network, we use the default router's IP address instead. + + If not ARP table entry is found, we overwrite the original IP + packet with an ARP request for the IP address. */ + + /* First check if destination is a local broadcast. */ + if(uip_ipaddr_cmp(IPBUF->destipaddr, broadcast_ipaddr)) { + memcpy(IPBUF->ethhdr.dest.addr, broadcast_ethaddr.addr, 6); + } else { + /* Check if the destination address is on the local network. */ + if(!uip_ipaddr_maskcmp(IPBUF->destipaddr, uip_hostaddr, uip_netmask)) { + /* Destination address was not on the local network, so we need to + use the default router's IP address instead of the destination + address when determining the MAC address. */ + uip_ipaddr_copy(ipaddr, uip_draddr); + } else { + /* Else, we use the destination IP address. */ + uip_ipaddr_copy(ipaddr, IPBUF->destipaddr); + } + + for(i = 0; i < UIP_ARPTAB_SIZE; ++i) { + tabptr = &arp_table[i]; + if(uip_ipaddr_cmp(ipaddr, tabptr->ipaddr)) { + break; + } + } + + if(i == UIP_ARPTAB_SIZE) { + /* The destination address was not in our ARP table, so we + overwrite the IP packet with an ARP request. */ + + memset(BUF->ethhdr.dest.addr, 0xff, 6); + memset(BUF->dhwaddr.addr, 0x00, 6); + memcpy(BUF->ethhdr.src.addr, uip_ethaddr.addr, 6); + memcpy(BUF->shwaddr.addr, uip_ethaddr.addr, 6); + + uip_ipaddr_copy(BUF->dipaddr, ipaddr); + uip_ipaddr_copy(BUF->sipaddr, uip_hostaddr); + BUF->opcode = HTONS(ARP_REQUEST); /* ARP request. */ + BUF->hwtype = HTONS(ARP_HWTYPE_ETH); + BUF->protocol = HTONS(UIP_ETHTYPE_IP); + BUF->hwlen = 6; + BUF->protolen = 4; + BUF->ethhdr.type = HTONS(UIP_ETHTYPE_ARP); + + uip_appdata = &uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN]; + + uip_len = sizeof(struct arp_hdr); + return; + } + + /* Build an ethernet header. */ + memcpy(IPBUF->ethhdr.dest.addr, tabptr->ethaddr.addr, 6); + } + memcpy(IPBUF->ethhdr.src.addr, uip_ethaddr.addr, 6); + + IPBUF->ethhdr.type = HTONS(UIP_ETHTYPE_IP); + + uip_len += sizeof(struct uip_eth_hdr); +} +/*-----------------------------------------------------------------------------------*/ + +/** @} */ +/** @} */ diff --git a/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/uip_arp.h b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/uip_arp.h new file mode 100644 index 0000000..ef93054 --- /dev/null +++ b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/uip_arp.h @@ -0,0 +1,144 @@ +/** + * \addtogroup uip + * @{ + */ + +/** + * \addtogroup uiparp + * @{ + */ + +/** + * \file + * Macros and definitions for the ARP module. + * \author Adam Dunkels + */ + + +/* + * Copyright (c) 2001-2003, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This file is part of the uIP TCP/IP stack. + * + * $Id: uip_arp.h,v 1.5 2006/06/11 21:46:39 adam Exp $ + * + */ + +#ifndef __UIP_ARP_H__ +#define __UIP_ARP_H__ + +#include "uip.h" + + +extern struct uip_eth_addr uip_ethaddr; + +/** + * The Ethernet header. + */ +struct uip_eth_hdr { + struct uip_eth_addr dest; + struct uip_eth_addr src; + u16_t type; +}; + +#define UIP_ETHTYPE_ARP 0x0806 +#define UIP_ETHTYPE_IP 0x0800 +#define UIP_ETHTYPE_IP6 0x86dd + + +/* The uip_arp_init() function must be called before any of the other + ARP functions. */ +void uip_arp_init(void); + +/* The uip_arp_ipin() function should be called whenever an IP packet + arrives from the Ethernet. This function refreshes the ARP table or + inserts a new mapping if none exists. The function assumes that an + IP packet with an Ethernet header is present in the uip_buf buffer + and that the length of the packet is in the uip_len variable. */ +void uip_arp_ipin(void); +//#define uip_arp_ipin() + +/* The uip_arp_arpin() should be called when an ARP packet is received + by the Ethernet driver. This function also assumes that the + Ethernet frame is present in the uip_buf buffer. When the + uip_arp_arpin() function returns, the contents of the uip_buf + buffer should be sent out on the Ethernet if the uip_len variable + is > 0. */ +void uip_arp_arpin(void); + +/* The uip_arp_out() function should be called when an IP packet + should be sent out on the Ethernet. This function creates an + Ethernet header before the IP header in the uip_buf buffer. The + Ethernet header will have the correct Ethernet MAC destination + address filled in if an ARP table entry for the destination IP + address (or the IP address of the default router) is present. If no + such table entry is found, the IP packet is overwritten with an ARP + request and we rely on TCP to retransmit the packet that was + overwritten. In any case, the uip_len variable holds the length of + the Ethernet frame that should be transmitted. */ +void uip_arp_out(void); + +/* The uip_arp_timer() function should be called every ten seconds. It + is responsible for flushing old entries in the ARP table. */ +void uip_arp_timer(void); + +/** @} */ + +/** + * \addtogroup uipconffunc + * @{ + */ + + +/** + * Specifiy the Ethernet MAC address. + * + * The ARP code needs to know the MAC address of the Ethernet card in + * order to be able to respond to ARP queries and to generate working + * Ethernet headers. + * + * \note This macro only specifies the Ethernet MAC address to the ARP + * code. It cannot be used to change the MAC address of the Ethernet + * card. + * + * \param eaddr A pointer to a struct uip_eth_addr containing the + * Ethernet MAC address of the Ethernet card. + * + * \hideinitializer + */ +#define uip_setethaddr(eaddr) do {uip_ethaddr.addr[0] = eaddr.addr[0]; \ + uip_ethaddr.addr[1] = eaddr.addr[1];\ + uip_ethaddr.addr[2] = eaddr.addr[2];\ + uip_ethaddr.addr[3] = eaddr.addr[3];\ + uip_ethaddr.addr[4] = eaddr.addr[4];\ + uip_ethaddr.addr[5] = eaddr.addr[5];} while(0) + +/** @} */ +/** @} */ + +#endif /* __UIP_ARP_H__ */ diff --git a/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/uipethernet-conf.h b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/uipethernet-conf.h new file mode 100644 index 0000000..6387091 --- /dev/null +++ b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/uipethernet-conf.h @@ -0,0 +1,48 @@ +#ifndef UIPETHERNET_CONF_H +#define UIPETHERNET_CONF_H + +// https://github.com/jandrassy/EthernetENC/wiki/Settings + +/* for TCP */ +#ifndef UIP_SOCKET_NUMPACKETS +#define UIP_SOCKET_NUMPACKETS 3 +#endif +#ifndef UIP_CONF_MAX_CONNECTIONS +#define UIP_CONF_MAX_CONNECTIONS 4 +#endif + +/* for UDP + * set UIP_CONF_UDP to 0 to disable UDP (saves aprox. 4kB flash) */ +#ifndef UIP_CONF_UDP +#define UIP_CONF_UDP 1 +#endif +#ifndef UIP_CONF_UDP_CONNS +#define UIP_CONF_UDP_CONNS 2 +#endif + +/** + * size of received UDP messages backlog. it must be at least 1 + */ +#ifndef UIP_UDP_BACKLOG +#define UIP_UDP_BACKLOG 2 +#endif + +/* timeout in ms for attempts to get a free memory block to write + * before returning number of bytes sent so far + * set to 0 to block until connection is closed by timeout */ +#ifndef UIP_WRITE_TIMEOUT +#define UIP_WRITE_TIMEOUT 2000 +#endif + +/* timeout after which UIPClient::connect gives up. The timeout is specified in seconds. + * if set to a number <= 0 connect will timeout when uIP does (which might be longer than you expect...) */ +#ifndef UIP_CONNECT_TIMEOUT +#define UIP_CONNECT_TIMEOUT 5 +#endif + +/* periodic timer for uip (in ms) */ +#ifndef UIP_PERIODIC_TIMER +#define UIP_PERIODIC_TIMER 100 +#endif + +#endif diff --git a/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/uipopt.h b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/uipopt.h new file mode 100644 index 0000000..945decd --- /dev/null +++ b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/uipopt.h @@ -0,0 +1,555 @@ +/** + * \defgroup uipopt Configuration options for uIP + * @{ + * + * uIP is configured using the per-project configuration file + * uipopt.h. This file contains all compile-time options for uIP and + * should be tweaked to match each specific project. The uIP + * distribution contains a documented example "uipopt.h" that can be + * copied and modified for each project. + * + * \note Most of the configuration options in the uipopt.h should not + * be changed, but rather the per-project uip-conf.h file. + */ + +/** + * \file + * Configuration options for uIP. + * \author Adam Dunkels + * + * This file is used for tweaking various configuration options for + * uIP. You should make a copy of this file into one of your project's + * directories instead of editing this example "uipopt.h" file that + * comes with the uIP distribution. + */ + +/* + * Copyright (c) 2001-2003, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This file is part of the uIP TCP/IP stack. + * + * $Id: uipopt.h,v 1.4 2006/06/12 08:00:31 adam Exp $ + * + */ + +#ifndef __UIPOPT_H__ +#define __UIPOPT_H__ + +#ifndef UIP_LITTLE_ENDIAN + #if defined(LITTLE_ENDIAN) + #define UIP_LITTLE_ENDIAN LITTLE_ENDIAN + #elif defined(__ORDER_LITTLE_ENDIAN__) + #define UIP_LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__ + #else + #define UIP_LITTLE_ENDIAN 1234 + #endif +#endif /* UIP_LITTLE_ENDIAN */ +#ifndef UIP_BIG_ENDIAN + #if defined(BIG_ENDIAN) + #define UIP_BIG_ENDIAN BIG_ENDIAN + #elif defined(__ORDER_BIG_ENDIAN__) + #define UIP_BIG_ENDIAN __ORDER_BIG_ENDIAN__ + #else + #define UIP_BIG_ENDIAN 4321 + #endif +#endif /* UIP_BIG_ENDIAN */ + +#include "uip-conf.h" + +/*------------------------------------------------------------------------------*/ + +/** + * \name Static configuration options + * @{ + * + * These configuration options can be used for setting the IP address + * settings statically, but only if UIP_FIXEDADDR is set to 1. The + * configuration options for a specific node includes IP address, + * netmask and default router as well as the Ethernet address. The + * netmask, default router and Ethernet address are appliciable only + * if uIP should be run over Ethernet. + * + * All of these should be changed to suit your project. +*/ + +/** + * Determines if uIP should use a fixed IP address or not. + * + * If uIP should use a fixed IP address, the settings are set in the + * uipopt.h file. If not, the macros uip_sethostaddr(), + * uip_setdraddr() and uip_setnetmask() should be used instead. + * + * \hideinitializer + */ +#define UIP_FIXEDADDR 0 + +/** + * Ping IP address asignment. + * + * uIP uses a "ping" packets for setting its own IP address if this + * option is set. If so, uIP will start with an empty IP address and + * the destination IP address of the first incoming "ping" (ICMP echo) + * packet will be used for setting the hosts IP address. + * + * \note This works only if UIP_FIXEDADDR is 0. + * + * \hideinitializer + */ +#ifdef UIP_CONF_PINGADDRCONF +#define UIP_PINGADDRCONF UIP_CONF_PINGADDRCONF +#else /* UIP_CONF_PINGADDRCONF */ +#define UIP_PINGADDRCONF 0 +#endif /* UIP_CONF_PINGADDRCONF */ + + +/** + * Specifies if the uIP ARP module should be compiled with a fixed + * Ethernet MAC address or not. + * + * If this configuration option is 0, the macro uip_setethaddr() can + * be used to specify the Ethernet address at run-time. + * + * \hideinitializer + */ +#define UIP_FIXEDETHADDR 0 + +/** @} */ +/*------------------------------------------------------------------------------*/ +/** + * \name IP configuration options + * @{ + * + */ +/** + * The IP TTL (time to live) of IP packets sent by uIP. + * + * This should normally not be changed. + */ +#define UIP_TTL 64 + +/** + * Turn on support for IP packet reassembly. + * + * uIP supports reassembly of fragmented IP packets. This features + * requires an additonal amount of RAM to hold the reassembly buffer + * and the reassembly code size is approximately 700 bytes. The + * reassembly buffer is of the same size as the uip_buf buffer + * (configured by UIP_BUFSIZE). + * + * \note IP packet reassembly is not heavily tested. + * + * \hideinitializer + */ +#define UIP_REASSEMBLY 0 + +/** + * The maximum time an IP fragment should wait in the reassembly + * buffer before it is dropped. + * + */ +#define UIP_REASS_MAXAGE 40 + +/** @} */ + +/*------------------------------------------------------------------------------*/ +/** + * \name UDP configuration options + * @{ + */ + +/** + * Toggles wether UDP support should be compiled in or not. + * + * \hideinitializer + */ +#ifdef UIP_CONF_UDP +#define UIP_UDP UIP_CONF_UDP +#else /* UIP_CONF_UDP */ +#define UIP_UDP 0 +#endif /* UIP_CONF_UDP */ + +/** + * Toggles if UDP checksums should be used or not. + * + * \note Support for UDP checksums is currently not included in uIP, + * so this option has no function. + * + * \hideinitializer + */ +#ifdef UIP_CONF_UDP_CHECKSUMS +#define UIP_UDP_CHECKSUMS UIP_CONF_UDP_CHECKSUMS +#else +#define UIP_UDP_CHECKSUMS 0 +#endif + +/** + * The maximum amount of concurrent UDP connections. + * + * \hideinitializer + */ +#ifdef UIP_CONF_UDP_CONNS +#define UIP_UDP_CONNS UIP_CONF_UDP_CONNS +#else /* UIP_CONF_UDP_CONNS */ +#define UIP_UDP_CONNS 10 +#endif /* UIP_CONF_UDP_CONNS */ + +/** + * The name of the function that should be called when UDP datagrams arrive. + * + * \hideinitializer + */ + + +/** @} */ +/*------------------------------------------------------------------------------*/ +/** + * \name TCP configuration options + * @{ + */ + +/** + * Determines if support for opening connections from uIP should be + * compiled in. + * + * If the applications that are running on top of uIP for this project + * do not need to open outgoing TCP connections, this configration + * option can be turned off to reduce the code size of uIP. + * + * \hideinitializer + */ +#define UIP_ACTIVE_OPEN 1 + +/** + * The maximum number of simultaneously open TCP connections. + * + * Since the TCP connections are statically allocated, turning this + * configuration knob down results in less RAM used. Each TCP + * connection requires approximatly 30 bytes of memory. + * + * \hideinitializer + */ +#ifndef UIP_CONF_MAX_CONNECTIONS +#define UIP_CONNS 10 +#else /* UIP_CONF_MAX_CONNECTIONS */ +#define UIP_CONNS UIP_CONF_MAX_CONNECTIONS +#endif /* UIP_CONF_MAX_CONNECTIONS */ + + +/** + * The maximum number of simultaneously listening TCP ports. + * + * Each listening TCP port requires 2 bytes of memory. + * + * \hideinitializer + */ +#ifndef UIP_CONF_MAX_LISTENPORTS +#define UIP_LISTENPORTS 20 +#else /* UIP_CONF_MAX_LISTENPORTS */ +#define UIP_LISTENPORTS UIP_CONF_MAX_LISTENPORTS +#endif /* UIP_CONF_MAX_LISTENPORTS */ + +/** + * Determines if support for TCP urgent data notification should be + * compiled in. + * + * Urgent data (out-of-band data) is a rarely used TCP feature that + * very seldom would be required. + * + * \hideinitializer + */ +#define UIP_URGDATA 0 + +/** + * The initial retransmission timeout counted in timer pulses. + * + * This should not be changed. + */ +#define UIP_RTO 3 + +/** + * The maximum number of times a segment should be retransmitted + * before the connection should be aborted. + * + * This should not be changed. + */ +#define UIP_MAXRTX 8 + +/** + * The maximum number of times a SYN segment should be retransmitted + * before a connection request should be deemed to have been + * unsuccessful. + * + * This should not need to be changed. + */ +#define UIP_MAXSYNRTX 5 + +/** + * The TCP maximum segment size. + * + * This is should not be to set to more than + * UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN. + */ +#ifndef UIP_CONF_TCP_MSS +#define UIP_TCP_MSS (UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN) +#else +#define UIP_TCP_MSS UIP_CONF_TCP_MSS +#endif + +/** + * The size of the advertised receiver's window. + * + * Should be set low (i.e., to the size of the uip_buf buffer) is the + * application is slow to process incoming data, or high (32768 bytes) + * if the application processes data quickly. + * + * \hideinitializer + */ +#ifndef UIP_CONF_RECEIVE_WINDOW +#define UIP_RECEIVE_WINDOW UIP_TCP_MSS +#else +#define UIP_RECEIVE_WINDOW UIP_CONF_RECEIVE_WINDOW +#endif + +/** + * How long a connection should stay in the TIME_WAIT state. + * + * This configiration option has no real implication, and it should be + * left untouched. + */ +#define UIP_TIME_WAIT_TIMEOUT 120 + + +/** @} */ +/*------------------------------------------------------------------------------*/ +/** + * \name ARP configuration options + * @{ + */ + +/** + * The size of the ARP table. + * + * This option should be set to a larger value if this uIP node will + * have many connections from the local network. + * + * \hideinitializer + */ +#ifdef UIP_CONF_ARPTAB_SIZE +#define UIP_ARPTAB_SIZE UIP_CONF_ARPTAB_SIZE +#else +#define UIP_ARPTAB_SIZE 8 +#endif + +/** + * The maxium age of ARP table entries measured in 10ths of seconds. + * + * An UIP_ARP_MAXAGE of 120 corresponds to 20 minutes (BSD + * default). + */ +#define UIP_ARP_MAXAGE 120 + +/** @} */ + +/*------------------------------------------------------------------------------*/ + +/** + * \name General configuration options + * @{ + */ + +/** + * The size of the uIP packet buffer. + * + * The uIP packet buffer should not be smaller than 60 bytes, and does + * not need to be larger than 1500 bytes. Lower size results in lower + * TCP throughput, larger size results in higher TCP throughput. + * + * \hideinitializer + */ +#ifndef UIP_CONF_BUFFER_SIZE +#define UIP_BUFSIZE 400 +#else /* UIP_CONF_BUFFER_SIZE */ +#define UIP_BUFSIZE UIP_CONF_BUFFER_SIZE +#endif /* UIP_CONF_BUFFER_SIZE */ + + +/** + * Determines if statistics support should be compiled in. + * + * The statistics is useful for debugging and to show the user. + * + * \hideinitializer + */ +#ifndef UIP_CONF_STATISTICS +#define UIP_STATISTICS 0 +#else /* UIP_CONF_STATISTICS */ +#define UIP_STATISTICS UIP_CONF_STATISTICS +#endif /* UIP_CONF_STATISTICS */ + +/** + * Determines if logging of certain events should be compiled in. + * + * This is useful mostly for debugging. The function uip_log() + * must be implemented to suit the architecture of the project, if + * logging is turned on. + * + * \hideinitializer + */ +#ifndef UIP_CONF_LOGGING +#define UIP_LOGGING 0 +#else /* UIP_CONF_LOGGING */ +#define UIP_LOGGING UIP_CONF_LOGGING +#endif /* UIP_CONF_LOGGING */ + +/** + * Broadcast support. + * + * This flag configures IP broadcast support. This is useful only + * together with UDP. + * + * \hideinitializer + * + */ +#if UIP_UDP && UIP_CONF_BROADCAST +#define UIP_BROADCAST UIP_CONF_BROADCAST +#else /* UIP_CONF_BROADCAST */ +#define UIP_BROADCAST 0 +#endif /* UIP_CONF_BROADCAST */ + +/** + * Print out a uIP log message. + * + * This function must be implemented by the module that uses uIP, and + * is called by uIP whenever a log message is generated. + */ +void uip_log(char *msg); + +/** + * The link level header length. + * + * This is the offset into the uip_buf where the IP header can be + * found. For Ethernet, this should be set to 14. For SLIP, this + * should be set to 0. + * + * \hideinitializer + */ +#ifdef UIP_CONF_LLH_LEN +#define UIP_LLH_LEN UIP_CONF_LLH_LEN +#else /* UIP_CONF_LLH_LEN */ +#define UIP_LLH_LEN 14 +#endif /* UIP_CONF_LLH_LEN */ + +/** @} */ +/*------------------------------------------------------------------------------*/ +/** + * \name CPU architecture configuration + * @{ + * + * The CPU architecture configuration is where the endianess of the + * CPU on which uIP is to be run is specified. Most CPUs today are + * little endian, and the most notable exception are the Motorolas + * which are big endian. The BYTE_ORDER macro should be changed to + * reflect the CPU architecture on which uIP is to be run. + */ + +/** + * The byte order of the CPU architecture on which uIP is to be run. + * + * This option can be either BIG_ENDIAN (Motorola byte order) or + * LITTLE_ENDIAN (Intel byte order). + * + * \hideinitializer + */ +#ifdef UIP_CONF_BYTE_ORDER +#define UIP_BYTE_ORDER UIP_CONF_BYTE_ORDER +#else /* UIP_CONF_BYTE_ORDER */ +#define UIP_BYTE_ORDER UIP_LITTLE_ENDIAN +#endif /* UIP_CONF_BYTE_ORDER */ + +/** @} */ +/*------------------------------------------------------------------------------*/ + +/** + * \name Appication specific configurations + * @{ + * + * An uIP application is implemented using a single application + * function that is called by uIP whenever a TCP/IP event occurs. The + * name of this function must be registered with uIP at compile time + * using the UIP_APPCALL definition. + * + * uIP applications can store the application state within the + * uip_conn structure by specifying the type of the application + * structure by typedef:ing the type uip_tcp_appstate_t and uip_udp_appstate_t. + * + * The file containing the definitions must be included in the + * uipopt.h file. + * + * The following example illustrates how this can look. + \code + +void httpd_appcall(void); +#define UIP_APPCALL httpd_appcall + +struct httpd_state { + u8_t state; + u16_t count; + char *dataptr; + char *script; +}; +typedef struct httpd_state uip_tcp_appstate_t + \endcode + */ + +/** + * \var #define UIP_APPCALL + * + * The name of the application function that uIP should call in + * response to TCP/IP events. + * + */ + +/** + * \var typedef uip_tcp_appstate_t + * + * The type of the application state that is to be stored in the + * uip_conn structure. This usually is typedef:ed to a struct holding + * application state information. + */ + +/** + * \var typedef uip_udp_appstate_t + * + * The type of the application state that is to be stored in the + * uip_conn structure. This usually is typedef:ed to a struct holding + * application state information. + */ +/** @} */ +/** @} */ + +#endif /* __UIPOPT_H__ */ diff --git a/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/util.h b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/util.h new file mode 100644 index 0000000..11e4242 --- /dev/null +++ b/Growatt ShineLAN-X/firmware/lib/EthernetENC/src/utility/util.h @@ -0,0 +1,10 @@ +#ifndef UTIL_H +#define UTIL_H + +#define htonl(x) ( ((x)<<24 & 0xFF000000UL) | \ + ((x)<< 8 & 0x00FF0000UL) | \ + ((x)>> 8 & 0x0000FF00UL) | \ + ((x)>>24 & 0x000000FFUL) ) +#define ntohl(x) htonl(x) + +#endif diff --git a/Growatt ShineLAN-X/firmware/platformio.ini b/Growatt ShineLAN-X/firmware/platformio.ini new file mode 100644 index 0000000..65669d2 --- /dev/null +++ b/Growatt ShineLAN-X/firmware/platformio.ini @@ -0,0 +1,16 @@ +[env:growatt-shinelan] +platform = ststm32 +board = genericSTM32F103RB +framework = arduino +upload_protocol = stlink +debug_tool = stlink +monitor_speed = 115200 + +lib_deps = + 4-20ma/ModbusMaster@^2.0.1 + knolleary/PubSubClient@^2.8 + # EthernetENC ist lokal in lib/EthernetENC/ (Bitbang-SPI Modifikation) + +build_flags = + -DPIO_FRAMEWORK_ARDUINO_NOERRNO + -I include diff --git a/Growatt ShineLAN-X/firmware/src/main.cpp b/Growatt ShineLAN-X/firmware/src/main.cpp new file mode 100644 index 0000000..433a2fb --- /dev/null +++ b/Growatt ShineLAN-X/firmware/src/main.cpp @@ -0,0 +1,292 @@ +#include +#include +#include +#include +#include +#include "config.h" + +// Debug-UART: USART1, TX=PA9, RX=PA10 (Testpunkt auf Platine) +// HINWEIS: Modbus ist temporär deaktiviert — erst Ethernet/MQTT bestätigen, +// dann Debug entfernen und Modbus wieder aktivieren. +HardwareSerial DebugSerial(PA10, PA9); + +// ============================================================ +// Sensor-Definition +// ============================================================ +struct Sensor { + const char* id; + const char* name; + uint16_t address; + bool isDword; // true = 2 Register (32 bit), false = 1 Register (16 bit) + float scale; + const char* unit; + const char* deviceClass; + const char* stateClass; + const char* icon; +}; + +// Sensor-Liste — entspricht den Modbus-Registern des SPH 5000 TL3-BH-UP +// Für andere Modelle nicht zutreffende Sensoren auskommentieren. +const Sensor SENSORS[] = { + // --- PV Eingang --- + {"pv1_voltage", "PV1 Voltage", 3, false, 0.1f, "V", "voltage", "measurement", "mdi:solar-panel"}, + {"pv1_current", "PV1 Current", 4, false, 0.1f, "A", "current", "measurement", "mdi:solar-panel"}, + {"pv1_power", "PV1 Power", 5, true, 0.1f, "W", "power", "measurement", "mdi:solar-panel"}, + {"pv2_voltage", "PV2 Voltage", 7, false, 0.1f, "V", "voltage", "measurement", "mdi:solar-panel"}, + {"pv2_current", "PV2 Current", 8, false, 0.1f, "A", "current", "measurement", "mdi:solar-panel"}, + {"pv2_power", "PV2 Power", 9, true, 0.1f, "W", "power", "measurement", "mdi:solar-panel"}, + // --- AC Ausgang / Netz --- + {"ac_power_total", "AC Output Power Total", 35, true, 0.1f, "W", "power", "measurement", "mdi:flash"}, + {"grid_frequency", "Grid Frequency", 37, false, 0.01f, "Hz", "frequency", "measurement", "mdi:sine-wave"}, + {"grid_voltage_l1", "Grid Voltage L1", 38, false, 0.1f, "V", "voltage", "measurement", "mdi:flash"}, + {"grid_current_l1", "Grid Current L1", 39, false, 0.1f, "A", "current", "measurement", "mdi:flash"}, + {"grid_voltage_l2", "Grid Voltage L2", 42, false, 0.1f, "V", "voltage", "measurement", "mdi:flash"}, + {"grid_current_l2", "Grid Current L2", 43, false, 0.1f, "A", "current", "measurement", "mdi:flash"}, + {"grid_voltage_l3", "Grid Voltage L3", 46, false, 0.1f, "V", "voltage", "measurement", "mdi:flash"}, + {"grid_current_l3", "Grid Current L3", 47, false, 0.1f, "A", "current", "measurement", "mdi:flash"}, + // --- Energie PV --- + {"energy_today", "Energy Today", 53, true, 0.1f, "kWh", "energy", "total_increasing", "mdi:solar-power"}, + {"energy_total", "Energy Total", 55, true, 0.1f, "kWh", "energy", "total_increasing", "mdi:solar-power"}, + // --- Temperatur --- + {"inverter_temp", "Inverter Temperature", 93, false, 0.1f, "°C", "temperature", "measurement", "mdi:thermometer"}, + // --- Batterie --- + {"bat_discharge_power", "Battery Discharge Power", 1009, true, 0.1f, "W", "power", "measurement", "mdi:battery-minus"}, + {"bat_charge_power", "Battery Charge Power", 1011, true, 0.1f, "W", "power", "measurement", "mdi:battery-plus"}, + {"bat_voltage", "Battery Voltage", 1013, false, 0.1f, "V", "voltage", "measurement", "mdi:battery"}, + {"bat_soc", "Battery State of Charge", 1014, false, 1.0f, "%", "battery", "measurement", "mdi:battery"}, + {"bat_temperature", "Battery Temperature", 1040, false, 0.1f, "°C", "temperature", "measurement", "mdi:thermometer"}, + // --- Netz- und Batterie-Energiezähler (für Energie-Dashboard) --- + {"energy_import_total", "Energy Import Total", 1046, true, 0.1f, "kWh", "energy", "total_increasing", "mdi:transmission-tower-import"}, + {"energy_export_total", "Energy Export Total", 1050, true, 0.1f, "kWh", "energy", "total_increasing", "mdi:transmission-tower-export"}, + {"bat_discharge_total", "Battery Discharge Total", 1054, true, 0.1f, "kWh", "energy", "total_increasing", "mdi:battery-minus"}, + {"bat_charge_total", "Battery Charge Total", 1058, true, 0.1f, "kWh", "energy", "total_increasing", "mdi:battery-plus"}, +}; +const uint8_t SENSOR_COUNT = sizeof(SENSORS) / sizeof(SENSORS[0]); + +// ============================================================ +// Globale Objekte +// ============================================================ +// HardwareSerial modbusSerial(PA10, PA9); // USART1 — temporär deaktiviert (teilt sich UART mit DebugSerial) + +byte mac[] = {MAC_ADDRESS}; +EthernetClient ethClient; +PubSubClient mqtt(ethClient); +// ModbusMaster modbus; // temporär deaktiviert + +// ============================================================ +// RS485 Richtungssteuerung (Callbacks für ModbusMaster) +// ============================================================ +void preTransmission() { digitalWrite(RS485_DE_PIN, HIGH); } +void postTransmission() { digitalWrite(RS485_DE_PIN, LOW); } + +// ============================================================ +// MQTT Hilfsfunktionen +// ============================================================ + +// Veröffentlicht alle Sensor-Discovery-Pakete für Home Assistant +void publishDiscovery() { + char topic[128]; + char payload[640]; + + for (uint8_t i = 0; i < SENSOR_COUNT; i++) { + const Sensor& s = SENSORS[i]; + + snprintf(topic, sizeof(topic), + "homeassistant/sensor/%s_%s/config", + DEVICE_ID, s.id); + + snprintf(payload, sizeof(payload), + "{" + "\"name\":\"%s\"," + "\"unique_id\":\"%s_%s\"," + "\"state_topic\":\"growatt/shinelan/%s\"," + "\"unit_of_measurement\":\"%s\"," + "\"device_class\":\"%s\"," + "\"state_class\":\"%s\"," + "\"icon\":\"%s\"," + "\"device\":{" + "\"identifiers\":[\"%s\"]," + "\"name\":\"%s\"," + "\"model\":\"%s\"," + "\"manufacturer\":\"%s\"" + "}}", + s.name, + DEVICE_ID, s.id, + s.id, + s.unit, + s.deviceClass, + s.stateClass, + s.icon, + DEVICE_ID, DEVICE_NAME, DEVICE_MODEL, DEVICE_MFR); + + mqtt.publish(topic, payload, true); // retained = true + } + +} + +bool mqttReconnect() { + DebugSerial.print("MQTT connecting... "); + bool ok; + if (strlen(MQTT_USER) > 0) { + ok = mqtt.connect(MQTT_CLIENT, MQTT_USER, MQTT_PASSWORD); + } else { + ok = mqtt.connect(MQTT_CLIENT); + } + if (ok) { + DebugSerial.println("OK"); + publishDiscovery(); + } else { + DebugSerial.print("FAIL rc="); + DebugSerial.println(mqtt.state()); + } + return ok; +} + +// ============================================================ +// Setup +// ============================================================ +void setup() { + // Debug-UART zuerst starten (USART1: TX=PA9 = Testpunkt auf Platine) + DebugSerial.begin(115200); + delay(10); + DebugSerial.println("\r\n=== Growatt ShineLAN-X ==="); + DebugSerial.println("Build: " __DATE__ " " __TIME__); + + // RS485 DE/RE Pin + pinMode(RS485_DE_PIN, OUTPUT); + digitalWrite(RS485_DE_PIN, LOW); // Empfangsmodus + + // ENC28J60 Reset (Hardware-Reset vor init) + DebugSerial.println("ETH: reset..."); + pinMode(ETH_RST_PIN, OUTPUT); + digitalWrite(ETH_RST_PIN, LOW); + delay(50); + digitalWrite(ETH_RST_PIN, HIGH); + delay(200); + + // SO-Aktivitätstest: Ist der ENC28J60 überhaupt am Leben? + // PC8 mit Pull-Down → wenn ENC28J60 SO aktiv HIGH treibt = Chip antwortet + // Wenn PC8 bleibt LOW = SO ist High-Z = Chip tot/kein Takt/keine Power + pinMode(ETH_CS_PIN, OUTPUT); digitalWrite(ETH_CS_PIN, HIGH); + pinMode(ETH_SCK_PIN, OUTPUT); digitalWrite(ETH_SCK_PIN, LOW); + pinMode(PC8, INPUT_PULLDOWN); + + DebugSerial.println("SO-Aktivitaetstest (PC8 = INPUT_PULLDOWN):"); + + // Test 1: CS hoch (SO sollte High-Z sein → LOW erwartet) + uint8_t so_cs_high = digitalRead(PC8); + DebugSerial.print(" CS=H SO="); DebugSerial.print(so_cs_high); + DebugSerial.println(so_cs_high == 0 ? " (High-Z, erwartet)" : " (getrieben! unerwartet)"); + + // Test 2: CS runter (ENC28J60 soll SO aktivieren) + digitalWrite(ETH_CS_PIN, LOW); + delayMicroseconds(50); + uint8_t so_cs_low = digitalRead(PC8); + digitalWrite(ETH_CS_PIN, HIGH); + DebugSerial.print(" CS=L SO="); DebugSerial.print(so_cs_low); + if (so_cs_low == 1) DebugSerial.println(" --> Chip treibt SO! Chip ist am Leben."); + else DebugSerial.println(" --> SO bleibt LOW = Chip antwortet nicht (kein Takt? kein Strom?)"); + + // Test 3: Reset-Zyklus, dann CS low + digitalWrite(ETH_RST_PIN, LOW); delay(10); + digitalWrite(ETH_RST_PIN, HIGH); delay(100); + digitalWrite(ETH_CS_PIN, LOW); + delayMicroseconds(50); + uint8_t so_after_reset = digitalRead(PC8); + digitalWrite(ETH_CS_PIN, HIGH); + DebugSerial.print(" nach Reset, CS=L SO="); DebugSerial.print(so_after_reset); + if (so_after_reset == 1) DebugSerial.println(" --> Chip lebt!"); + else DebugSerial.println(" --> immer noch kein Leben"); + + // ============================================================ + // Roher SPI-Test: ESTAT-Register lesen (kein EthernetENC) + // ENC28J60 ESTAT = Bank0, Addr 0x1D + // Read Control Register: opcode 000 | addr 11101 = 0x1D + // Erwarteter Wert nach Reset: 0x01 (CLKRDY-Bit gesetzt) + // ============================================================ + + // Langer Reset-Zyklus und Wartezeit für CLKRDY + pinMode(ETH_RST_PIN, OUTPUT); + digitalWrite(ETH_RST_PIN, LOW); delay(20); + digitalWrite(ETH_RST_PIN, HIGH); delay(800); // 25 MHz Quarz braucht <1 ms + + pinMode(ETH_CS_PIN, OUTPUT); digitalWrite(ETH_CS_PIN, HIGH); + pinMode(ETH_SCK_PIN, OUTPUT); digitalWrite(ETH_SCK_PIN, LOW); + pinMode(ETH_MISO_PIN, INPUT); // kein Pull — Chip treibt SO direkt + + // Inline-Hilfsfunktion: 1 Byte über SPI senden und empfangen + // MOSI-Pin wird als Parameter übergeben (Kandidaten-Scan) + auto spiXfer = [](uint8_t mosiPin, uint8_t out) -> uint8_t { + uint8_t in = 0; + for (int8_t i = 7; i >= 0; i--) { + digitalWrite(mosiPin, (out >> i) & 1); + digitalWrite(ETH_SCK_PIN, HIGH); + in = (in << 1) | digitalRead(ETH_MISO_PIN); + digitalWrite(ETH_SCK_PIN, LOW); + } + return in; + }; + + auto readESTAT = [&](uint8_t mosiPin) -> uint8_t { + digitalWrite(ETH_CS_PIN, LOW); + spiXfer(mosiPin, 0x1D); // RCR ESTAT + uint8_t val = spiXfer(mosiPin, 0x00); + digitalWrite(ETH_CS_PIN, HIGH); + return val; + }; + + // MOSI-Kandidaten + const uint8_t MOSI_CANDIDATES[] = { PC9, PB14, PB15, PB10, PB11, PA5, PA7 }; + const char* MOSI_NAMES[] = {"PC9","PB14","PB15","PB10","PB11","PA5","PA7"}; + const uint8_t NUM_CAND = sizeof(MOSI_CANDIDATES) / sizeof(MOSI_CANDIDATES[0]); + + DebugSerial.println("SPI ESTAT-Scan (Erwartung: 0x01):"); + for (uint8_t c = 0; c < NUM_CAND; c++) { + uint8_t pin = MOSI_CANDIDATES[c]; + pinMode(pin, OUTPUT); digitalWrite(pin, LOW); + + // Chip-Reset zwischen Kandidaten + digitalWrite(ETH_RST_PIN, LOW); delay(5); + digitalWrite(ETH_RST_PIN, HIGH); delay(50); + + uint8_t estat = readESTAT(pin); + + DebugSerial.print(" MOSI="); DebugSerial.print(MOSI_NAMES[c]); + DebugSerial.print(" -> ESTAT=0x"); DebugSerial.print(estat, HEX); + if (estat == 0x01) DebugSerial.println(" <-- TREFFER! SPI OK"); + else if (estat == 0xFF) DebugSerial.println(" (kein Kontakt)"); + else DebugSerial.println(" (unbekannt)"); + + pinMode(pin, INPUT); // danach wieder floating lassen + } + + DebugSerial.println("Scan fertig."); + DebugSerial.println("Setup done (Ethernet deaktiviert bis MOSI gefunden)."); +} + +// ============================================================ +// Loop +// ============================================================ +unsigned long lastUpdate = 0; + +void loop() { + // MQTT Verbindung halten + if (!mqtt.connected()) { + if (!mqttReconnect()) { + delay(5000); + return; + } + } + mqtt.loop(); + + if (millis() - lastUpdate < UPDATE_INTERVAL) return; + lastUpdate = millis(); + + char stateTopic[64]; + char valueStr[16]; + + // Modbus temporär deaktiviert — Sensor-Loop übersprungen + DebugSerial.println("loop: MQTT ok, Modbus disabled"); + (void)stateTopic; + (void)valueStr; +}