libretiny-eu / libretiny

PlatformIO development platform for IoT modules
http://docs.libretiny.eu/
MIT License
382 stars 55 forks source link

rtl8710bn HLW8012 CHANGE interrupts not supported #155

Open alexxx113 opened 11 months ago

alexxx113 commented 11 months ago
libretiny:
  board: generic-rtl8710bn-2mb-788k
  framework:  
    version: dev 

not work

libretiny:
  board: generic-rtl8710bn-2mb-788k
  framework:  
    version: 1.1.0

work good

error log

System_Init1
OSC8M: 7fea9f 
boot reason: 1 
System_Init2
I [      0.000] LibreTiny v1.2.0+sha.e99c612 on generic-rtl8710bn-2mb-788k, compiled at Aug 12 2023 01:25:36, GCC 10.3.1 (-Os)
I [      0.000] Reset reason: Unknown
 I [      0.007] Preferences initialized
[I][logger:302]: Log initialized
[C][ota:477]: There have been 9 suspected unsuccessful boot attempts.
[D][lt.preferences:104]: Saving 1 preferences to flash...
[D][lt.preferences:132]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed
[I][app:029]: Running through setup()...
[C][switch.gpio:011]: Setting up GPIO Switch 'Relay'...
[D][switch:016]: 'Relay' Turning OFF.
[D][switch:055]: 'Relay': Sending state OFF
[D][switch:016]: 'Relay' Turning OFF.
[C][status_led:055]: Setting up Status LED...
[C][light:035]: Setting up light 'statusled'...
[D][status_led:038]: 'statusled': Setting initial state
[D][status_led:049]: 'statusled': Setting state OFF
[D][light:036]: 'statusled' Setting:
[D][light:041]:   Color mode: 
[C][hlw8012:014]: Setting up HLW8012...
W [      0.102] CHANGE interrupts not supported
alexxx113 commented 10 months ago

Can I help? logs? tests?

kuba2k2 commented 10 months ago

Not really. Seems like CHANGE interrupts were "supported" previously, only due to a bug that produced undefined behavior. Realtek doesn't support CHANGE interrupts properly and that's why it's failing now.

When you tried 1.1.0, did it actually report correct energy measurements? Or just produced no warning?

alexxx113 commented 10 months ago

version: 1.1.0 work no problem

sensor:

log

01:12:01 | [D] | [sensor:093] | 'Voltage': Sending state 225.81564 V with 1 decimals of accuracy 01:12:01 | [D] | [sensor:093] | 'Power': Sending state 25.43914 W with 1 decimals of accuracy 01:12:01 | [D] | [sensor:093] | 'Energy': Sending state 541.63861 Wh with 1 decimals of accuracy 01:12:06 | [D] | [hlw8012:082] | Got power=22.6W, voltage=226.0V 01:12:06 | [D] | [sensor:093] | 'Voltage': Sending state 226.04918 V with 1 decimals of accuracy 01:12:06 | [D] | [sensor:093] | 'Power': Sending state 22.57724 W with 1 decimals of accuracy 01:12:06 | [D] | [sensor:093] | 'Energy': Sending state 541.66998 Wh with 1 decimals of accuracy

mihsu81 commented 10 months ago

I'm encountering the same issue on a generic-rtl8710bx-4mb-980k with the hlw8012 platform.

[1B][0;36m[D][binary_sensor:034]: 'Power Button': Sending initial state OFF[1B][0m
[1B][0;36m[D][text_sensor:064]: 'MAC Wifi Address': Sending state '64:F2:FB:3B:AF:1C'[1B][0m
[1B][0;36m[D][text_sensor:064]: 'ESPHome Version': Sending state '2023.9.0-dev Aug 21 2023, 23:18:40'[1B][0m
[1B][0;35m[C][hlw8012:014]: Setting up HLW8012...[1B][0m
[1B][1;33mW [      0.130] [1B][0mCHANGE interrupts not supported
[1B][1;33mW [      0.136] [1B][0mCHANGE interrupts not supported

But for me LT 1.1.0 causes a Hard Fault Error when opening the web browser.

RTL8195A[HAL]: Hard Fault Error!!!!

RTL8195A[HAL]: R0 = 0x1

RTL8195A[HAL]: R1 = 0x50

RTL8195A[HAL]: R2 = 0x0

RTL8195A[HAL]: R3 = 0x10005bbc

RTL8195A[HAL]: R12 = 0x80000000

RTL8195A[HAL]: LR = 0x80380c3

RTL8195A[HAL]: PC = 0x0

RTL8195A[HAL]: PSR = 0x20000000

RTL8195A[HAL]: BFAR = 0xe000ed38

RTL8195A[HAL]: CFSR = 0x20000

RTL8195A[HAL]: HFSR = 0x40000000

RTL8195A[HAL]: DFSR = 0x0

RTL8195A[HAL]: AFSR = 0x0

RTL8195A[HAL]: PriMask 0x0

RTL8195A[HAL]: BasePri 0x0

RTL8195A[HAL]: SVC priority: 0x00

RTL8195A[HAL]: PendSVC priority: 0xf0

RTL8195A[HAL]: Systick priority: 0xf0
mihsu81 commented 10 months ago

My guess is that it is related to the change introduced in 1.2.0 which adds preliminary support for RTL8720C.

https://github.com/kuba2k2/libretiny/blob/f3871388ce54bf277f2067370ee99c57b677e186/cores/realtek-amb/arduino/src/wiring_irq.c#L65

SuperXL2023 commented 7 months ago

I found a temporary solution. Slightly modified the code in the file: < config dir >/.esphome/platformio/platforms/libretiny/cores/realtek-amb/arduino/src/wiring_irq.c

file: wiring_irq.c

...<other code> 
62: #if LT_RTL8720C
63:                        event = IRQ_FALL_RISE; // <- BUG  [ IRQ_FALL_RISE ] not defined, the compiler stops at this point with an error
64: #elif LT_RTL8710B
65:                        event = IRQ_RISE;
66: #else
67:                        LT_W("CHANGE interrupts not supported !!!!!!");
68: #endif
...<other code>

First I tried to add to line 62: #if LT_RTL8720C || LT_RTL8710B, but the compiler stopped here with the error IRQ_FALL_RISE not defined after that, I added lines 64, 65 and everything compiled perfectly and worked.

I hope this bug will be fixed in the next version of the library, and I hope my temporary solution will help you.

appleimperio commented 5 months ago

Having the same issue on the WR3E using the RTL8710BN in ESPHome with a MOES iR and RF system. when use the PA12 pin which is the one for the ir receiver can't compile it this si the log.

OTAx SELE[fffffffc]
OTA1 USE
IMG2 DATA[0x80899c0:3844:0x10005000]
IMG2 SIGN[RTKWin(10005008)]
IMG2 ENTRY[0x10005000:0x803c7f9]
System_Init1
System_Init2
I [      0.000] LibreTiny v1.4.1 on wr3e, compiled at Jan 28 2024 13:04:19, GCC 10.3.1 (-Os)

W [      0.021] CHANGE interrupts not supported
<RTL8195A>ROM:[V0.1]
FLASHRATE:4
===== Enter Image 1 ====
Img2 Sign: RTKWin, InfaStart @ 0x0803c7f9 
System_Init1
System_Init2
I [      0.000] LibreTiny v1.4.1 on wr3e, compiled at Jan 28 2024 13:04:19, GCC 10.3.1 (-Os)
W [      0.045] CHANGE interrupts not supported
io driver parameters error! file_name: rtl8711b_gpio_rom.c, line: 61

Any update on this issue?

Thank You.

flohav commented 5 months ago

Hi,

I had the exact same issue, and the following solution by SuperXL2023 works perfectly. Thanks !

I found a temporary solution. Slightly modified the code in the file: < config dir >/.esphome/platformio/platforms/libretiny/cores/realtek-amb/arduino/src/wiring_irq.c

file: wiring_irq.c

...<other code> 
62: #if LT_RTL8720C
63:                        event = IRQ_FALL_RISE; // <- BUG  [ IRQ_FALL_RISE ] not defined, the compiler stops at this point with an error
64: #elif LT_RTL8710B
65:                        event = IRQ_RISE;
66: #else
67:                        LT_W("CHANGE interrupts not supported !!!!!!");
68: #endif
...<other code>

First I tried to add to line 62: #if LT_RTL8720C || LT_RTL8710B, but the compiler stopped here with the error IRQ_FALL_RISE not defined after that, I added lines 64, 65 and everything compiled perfectly and worked.

I hope this bug will be fixed in the next version of the library, and I hope my temporary solution will help you.

appleimperio commented 5 months ago

@flohav thank you it worked

RF197 commented 4 months ago

Thanks a lot, this worked for me as well (on a BX chip)!

raufaser commented 3 months ago

@SuperXL2023 Thanks a lot. It worked.

Jaco1990 commented 2 months ago

@SuperXL2023 the solution worked for me aswell

flohav commented 1 month ago

Do you know how to apply this fix to Home Assistant Esphome? I couldn't fine the correct file to modify...

Jaco1990 commented 1 month ago

Do you know how to apply this fix to Home Assistant Esphome? I couldn't fine the correct file to modify...

A temporary fix was included in release v1.6.0. At the moment the only way to use this fix in Home Assistant and ESPHome is to add the following lines to your board declaration.

rtl87xx:
  board: ${board}
  framework: 
    version: dev
kuba2k2 commented 1 month ago

Or you can probably use version: 1.6.0 Let me know if it works fine.

flohav commented 4 weeks ago

It works fine, I used version: dev, updated via Esphome on HA and no issue at all.

Another issue however, since a few months I can't get any value from my HLW8012 whereas it used to work. But that's another issue I guess.