Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flashing and compiling issues #5

Closed
brandondb1 opened this issue Jan 15, 2023 · 13 comments
Closed

Flashing and compiling issues #5

brandondb1 opened this issue Jan 15, 2023 · 13 comments
Assignees
Labels
bug Something isn't working

Comments

@brandondb1
Copy link

Hello, thanks for your work on this - I have been using this sensor for a while so I am excited to try a new firmware on it...but...

When I try to flash the prebuilt binary the flash tool (STCGAL) stalls at waiting for MCU.

When I try to compile the binary and flash using make, the compile crashes out with a problem with a problem with patsubst in 1-mcu-settings.mk (line 114), after I updated the paths in the makefile so it could find things (before that it couldn't find anything). I can't see any obvious problems with the syntax.

I've tried on a linux machine and a windows machine with same result for the prebuilt flash. I've checked and I have the 104 variant chip on the sensor with the tamper detection, so it is the same as you have mentioned (same board rev based on the photos as well).

SDCC won't work on the linux machine for some reason, so my data point is only the windows machine for compiling. That could be a windows issue if you built the makefile etc. for linux, so perhaps not surprising. When I get a minute I'll try it on another linux box.

I've flashed lots of chips in my day, so Tx goes to Rx etc...equally, I have compiled a variety of things before.

Before I beat my head against the wall for a while longer, do you have any advice? Is there a library I might be missing or something?

Thanks in advance!

@mightymos
Copy link
Owner

I use MSYS2 on Windows so I do not know if make will work with just windows command line or powershell.
That could be the issue as far as manually compiling.

I'm going to try to work on a firmware solution that makes flashing more reliable.
However this won't help with a first flash.
You basically just have to cycle power to the sensor by disconnecting/reconnecting 3.3V when stcgal says Waiting on MCU.

Otherwise a piece of hardware with diodes is likely required for more consistent flashing.
I may have to detail this as well to help.

But you can see an example that would hopefully work in sec 1.2.6.1 Application Circuit Diagram for ISP:
http://www.stcmcudata.com/datasheet/stc/STC-AD-PDF/STC15-English.pdf

@mightymos
Copy link
Owner

Sorry it's actually:
sec 1.2.6.2 Application Circuit Diagram for ISP using USB Chip PL-2303SA to convert Serial Port

@brandondb1
Copy link
Author

Hey, thanks for the feedback. I wired a microswitch inline to the ground side so I can click the power on and off and that made it much easier to cycle the power without disrupting the serial lines.

I never did get STCGAL to program anything - it only got as far as erasing the flash...which did work as the device was then dead. After that I get serial port error: read timeout

I had a lot more success with the STC ISP flasher (v6.91J). It detects the MCU every time (when I cycle the power with the microswitch), and claims to have programmed the device with the .ihx file (the activity log says all the right things and there us a little blue bar that progresses from zero to 100%). It did resurrect the one I killed with the STCGAL, so it is programming something...the light on the device again flashes as normal with a reed trip or tamper event. However, it doesn't seem to be transmitting anything. My Sonoff RF Bridges don't receive anything during these events. I don't have Portisch installed, so if the firmware is using another protocol, that would explain it, unless there is something else at play...do I need portisch to receive signals from this firmware?

Thanks again, and sorry to take up so much time!

@mightymos
Copy link
Owner

mightymos commented Jan 16, 2023

That's progress at least.
You need to select or input 24 MHz under Trim IRC -> Input IRC frequency.
I don't think Portisch is required.

Does setting clock frequency fix it?

EDIT: Stock timings and "protocol 1" timing from rc-switch/Portisch are now supported.
Main thing now is to test with various receivers and see if packets are reliably received or not.

@brandondb1
Copy link
Author

Hi, no unfortunately setting the freq to 24 didn't seem to make a difference. There are lots of settings in the STC program, so perhaps there is something else that needs to be set. I tried to copy the settings listed in STCGAL, but some don't have the same names or aren't specific enough to copy into the official STC program.

I tried STCGAL a bunch more times, and occasionally I get the incorrect frame start error but mostly the read timeout error.

It could be a current leak from the serial pins, but it is odd that the official STC program seems to work every time (even if it does not transmit, it connects and flashes, and consistently resurrects the device after STCGAL has erased it). You'd think it would have the same issues.

here is the STC official log from the last programming run:

Checking target MCU ...
MCU type: STC15W104
F/W version: 7.2.5T

Current H/W Option:
. Current system clock source is internal IRC oscillator
. Current frequency: 23.999MHz
. Wakeup Timer frequency: 36.850KHz
. Do not detect the level of P3.2 and P3.3 next download
. Power-on reset, use the extra power-on delay
. RESET pin behaves as IO pin
. Interrupt while detect a Low-Voltage
. Thresh voltage level of the built-in LVD : 2.66 V
. Inhibit EEPROM operation under Low-Voltage
. CPU-Core supply level : 3.02 V
. Hardware enable Watch-Dog-Timer when power-on reset
. Watch-Dog-Timer pre-scalar : 256
. Watch-Dog-Timer stop count in idle mode
. Program can modify the Watch-Dog-Timer scalar
. Do not erase user EEPROM area at next download
. Do not control 485 at next download
. Do not check user password next download
. TXD is independent IO
. TXD pin as quasi-bidirectional mode after reset
. P3.3 output HIGH level after reset
. Reference voltage: 1253 mV (Range: 1150~1320mV)
. Testing time: 2021-1-10

MCU type: STC15W104
F/W version: 7.2.5T

Adjusting frequency ... [0.765"]
Adjusted frequency: 24.011MHz (0.045%)

Re-handshaking ... Successful [0.125"]
Current Baudrate: 38400
Erasing MCU flash ... OK ! [0.407"]
Programming user code ... OK ! [1.625"]
Programming OPTIONS ... OK ! [0.063"]

H/W Option upgrade to:
. Current system clock source is internal IRC oscillator
. Current frequency: 24.011MHz
. Do not detect the level of P3.2 and P3.3 next download
. Power-on reset, use the general power-on delay
. RESET pin behaves as IO pin
. Interrupt while detect a Low-Voltage
. Thresh voltage level of the built-in LVD : 2.66 V
. Permit EEPROM operation under Low-Voltag
. CPU-Core supply level : 3.02 V
. Hardware enable Watch-Dog-Timer when power-on reset
. Watch-Dog-Timer pre-scalar : 256
. Watch-Dog-Timer stop count in idle mode
. Program can modify the Watch-Dog-Timer scalar
. Do not erase user EEPROM area at next download
. Do not control 485 at next download
. Do not check user password next download
. TXD is independent IO
. TXD pin as quasi-bidirectional mode after reset
. P3.3 output HIGH level after reset
. Reference voltage: 1253 mV (Range: 1150~1320mV)
. Testing time: 2021-1-10
MCU ID : F2A4C3A2000A02

MCU type: STC15W104
F/W version: 7.2.5T

. Set frequency: 24.000MHz
. Adjusted frequency: 24.011MHz
. Trim error: 0.045%

Complete !(2023-01-16 14:33:43)

@mightymos
Copy link
Owner

OK it's a little confusing because I am not sure how to reset to default settings in stc isp.
However we do not want watch dog timer enabled.
So setting should be:

Hardware do not enable Watch-Dog-Timer

@mightymos
Copy link
Owner

My output:

Checking target MCU ...
MCU type: STC15W104
F/W version: 7.2.5T

Current H/W Option:
. Current system clock source is internal IRC oscillator
. Current frequency: 24.134MHz
. Wakeup Timer frequency: 36.125KHz
. Do not detect the level of P3.2 and P3.3 next download
. Power-on reset, use the extra power-on delay
. RESET pin behaves as IO pin
. Reset while detect a Low-Voltage
. Thresh voltage level of the built-in LVD : 2.66 V
. Inhibit EEPROM operation under Low-Voltage
. CPU-Core supply level : 2.73 V
. Hardware do not enable Watch-Dog-Timer
. Watch-Dog-Timer pre-scalar : 256
. Watch-Dog-Timer stop count in idle mode
. Program can modify the Watch-Dog-Timer scalar
. Do not erase user EEPROM area at next download
. Do not control 485 at next download
. Do not check user password next download
. TXD is independent IO
. TXD pin as quasi-bidirectional mode after reset
. P3.3 output HIGH level after reset
. Reference voltage: 1256 mV (Range: 1150~1320mV)
. Testing time: 2022-5-24

MCU type: STC15W104
F/W version: 7.2.5T

Adjusting frequency ... [0.750"]
Adjusted frequency: 23.993MHz (-0.030%)

Re-handshaking ... Successful [0.172"]
Current Baudrate: 38400
Erasing MCU flash ... OK ! [0.344"]
Programming user code ... OK ! [0.750"]
Programming OPTIONS ... OK ! [0.062"]

H/W Option upgrade to:
. Current system clock source is internal IRC oscillator
. Current frequency: 23.993MHz
. Do not detect the level of P3.2 and P3.3 next download
. Power-on reset, use the extra power-on delay
. RESET pin behaves as IO pin
. Reset while detect a Low-Voltage
. Thresh voltage level of the built-in LVD : 2.66 V
. Inhibit EEPROM operation under Low-Voltage
. CPU-Core supply level : 2.27 V
. Hardware do not enable Watch-Dog-Timer
. Watch-Dog-Timer pre-scalar : 256
. Watch-Dog-Timer stop count in idle mode
. Program can modify the Watch-Dog-Timer scalar
. Do not erase user EEPROM area at next download
. Do not control 485 at next download
. Do not check user password next download
. TXD is independent IO
. TXD pin as quasi-bidirectional mode after reset
. P3.3 output HIGH level after reset
. Reference voltage: 1256 mV (Range: 1150~1320mV)
. Testing time: 2022-5-24
MCU ID : F2A4C4B41E16E0

MCU type: STC15W104
F/W version: 7.2.5T

. Set frequency: 24.000MHz
. Adjusted frequency: 23.993MHz
. Trim error: -0.030%

Complete !(2023-01-16 14:13:41)

@mightymos
Copy link
Owner

Also do you know if you have the Sonoff hardware version v1 or v2?

@mmotley999
Copy link

Wanted to share that I have one of the newer Sonoff RF bridges (v2.2) and am using the hack you mentioned in your README. I'm running ESPHome, not Tasmota.

I can confirm that I'm seeing RCswitch protocol 1 codes on my Sonoff bridge with your firmware. I did have to increase the transmission count to 8 to increase the chance of a good code. I think 433mhz is busy/noisy in my area (or the hack causes some noise) as both the stock firmware and your firmware often send truncated codes along with good ones, and rare cases none would match (the hearbeat, which I enabled, will help keep things in sync but hopefully doesn't kill batteries).

@brandondb1
Copy link
Author

Ah, ok. I have the r2v1 hardware, but I don't run Portisch. I tried it once but the raw format was more trouble than it was worth to try and decode for door and motion sensors in home assistant. I don't use it for anything else so there wasn't much to be gained (and the RF noise is constant with raw signals).

I was hoping with new firmware that the heartbeat could help indicate when a battery has died. I capture the battery low signals but in the stock firmware they are only sent once until the device is rebooted and the battery voltage crosses the threshold again (it's the crossing that triggers, not <).

Thanks again for the time you've spent on this - it's really great that you've figured it out and it will potentially be useful in other 433 devices that I'm sure use the same chip.

@mightymos mightymos self-assigned this Jan 31, 2023
@mightymos mightymos added the bug Something isn't working label Jan 31, 2023
@mightymos
Copy link
Owner

Wanted to share that I have one of the newer Sonoff RF bridges (v2.2) and am using the hack you mentioned in your README. I'm running ESPHome, not Tasmota.

I can confirm that I'm seeing RCswitch protocol 1 codes on my Sonoff bridge with your firmware. I did have to increase the transmission count to 8 to increase the chance of a good code. I think 433mhz is busy/noisy in my area (or the hack causes some noise) as both the stock firmware and your firmware often send truncated codes along with good ones, and rare cases none would match (the hearbeat, which I enabled, will help keep things in sync but hopefully doesn't kill batteries).

@mmotley999 Would you be willing to test the "...StockTimings.ihx" release file with your bypassed receiver?
If it works (or does not) please let me know so I can update the readme table of seemingly compatible receivers?

@horga83
Copy link

horga83 commented Feb 28, 2023

I had to add "-P st15" as shown below for the flashing to work.

~/stcgal-patched/stcgal.py -p /dev/ttyUSB0 -P stc15 -l 1200 -b 1200 -t 24000 ReedTripRadio.ihx

Cheers

@mightymos
Copy link
Owner

README has been updated to explain flashing via make and manually.
Stock and rc-switch "protocol 1" are supported and testing results with various receivers is also listed in readme when available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants