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

W1209 "mutants" (was: NVM appears to be broken) #153

Closed
VK6TT opened this issue Jan 25, 2018 · 31 comments

Comments

@VK6TT
Copy link
Collaborator

commented Jan 25, 2018

When I load my forth definitions via the console on the W1209-FD they are not being saved in the flash.

eg after a clean flash of W1209-FD binary

STM8eForth 2.2.21 ok
words
IRET SAVEC RESET RAM NVM LOCK ULOCK ADC@ ADC! ?KEYB P7S E7S WORDS .S DUMP IMMEDIATE ALLOT VARIABLE CONSTANT CREATE DOES> ] : ; OVERT ." $" ABORT" AFT REPEAT WHILE AHEAD ELSE THEN IF AGAIN UNTIL BEGIN +LOOP LOOP DO NEXT FOR COMPILE [COMPILE] LITERAL CALL, C, , ' hi CR [ NAME> \ ( .( ? . U. TYPE U.R .R SPACES SPACE KEY DECIMAL HEX <# SIGN HOLD #S # #> ERASE FILL CMOVE HERE COUNT +! DEPTH PICK 0= ABS NEGATE NOT 1+ 1- 2+ 2- 2* 2/ EXG / /MOD M * UM / MOD /MOD M/MOD UM/MOD WITHIN MIN MAX < U< = DNEGATE 2DUP ROT ?DUP BG TIM BL OUT last '?KEY 'EMIT BASE - 0< OR AND XOR + UM+ I OVER SWAP DUP 2DROP DROP NIP >R R@ R> C! C@ ! @ B! 2C@ 2C! 2@ 2! EXIT EXECUTE LEAVE EMIT ?KEY TX! ?RX 'BOOT BKEY OUT! COLD ok
ok

\ now I define "a"
NVM ok
: a ." test" cr ; ok
atest
ok
words
a IRET SAVEC RESET RAM NVM LOCK ULOCK ADC@ ADC! ?KEYB P7S E7S WORDS .S DUMP IMMEDIATE ALLOT VARIABLE CONSTANT CREATE DOES> ] : ; OVERT ." $" ABORT" AFT REPEAT WHILE AHEAD ELSE THEN IF AGAIN UNTIL BEGIN +LOOP LOOP DO NEXT FOR COMPILE [COMPILE] LITERAL CALL, C, , ' hi CR [ NAME> \ ( .( ? . U. TYPE U.R .R SPACES SPACE KEY DECIMAL HEX <# SIGN HOLD #S # #> ERASE FILL CMOVE HERE COUNT +! DEPTH PICK 0= ABS NEGATE NOT 1+ 1- 2+ 2- 2* 2/ EXG / /MOD M * UM / MOD /MOD M/MOD UM/MOD WITHIN MIN MAX < U< = DNEGATE 2DUP ROT ?DUP BG TIM BL OUT last '?KEY 'EMIT BASE - 0< OR AND XOR + UM+ I OVER SWAP DUP 2DROP DROP NIP >R R@ R> C! C@ ! @ B! 2C@ 2C! 2@ 2! EXIT EXECUTE LEAVE EMIT ?KEY TX! ?RX 'BOOT BKEY OUT! COLD ok

\ now I power off and back on
STM8eForth 2.2.21 ok
words
IRET SAVEC RESET RAM NVM LOCK ULOCK ADC@ ADC! ?KEYB P7S E7S WORDS .S DUMP IMMEDIATE ALLOT VARIABLE CONSTANT CREATE DOES> ] : ; OVERT ." $" ABORT" AFT REPEAT WHILE AHEAD ELSE THEN IF AGAIN UNTIL BEGIN +LOOP LOOP DO NEXT FOR COMPILE [COMPILE] LITERAL CALL, C, , ' hi CR [ NAME> \ ( .( ? . U. TYPE U.R .R SPACES SPACE KEY DECIMAL HEX <# SIGN HOLD #S # #> ERASE FILL CMOVE HERE COUNT +! DEPTH PICK 0= ABS NEGATE NOT 1+ 1- 2+ 2- 2* 2/ EXG / /MOD M * UM / MOD /MOD M/MOD UM/MOD WITHIN MIN MAX < U< = DNEGATE 2DUP ROT ?DUP BG TIM BL OUT last '?KEY 'EMIT BASE - 0< OR AND XOR + UM+ I OVER SWAP DUP 2DROP DROP NIP >R R@ R> C! C@ ! @ B! 2C@ 2C! 2@ 2! EXIT EXECUTE LEAVE EMIT ?KEY TX! ?RX 'BOOT BKEY OUT! COLD ok

\ and a is missing.

@VK6TT VK6TT closed this Jan 25, 2018
@VK6TT

This comment has been minimized.

Copy link
Collaborator Author

commented Jan 25, 2018

Definitely something amiss. With a new board and 2.2.21 flashed I can confirm the flash has been written to by using :
' iret 2000 dump
And my new word vectored into boot works as expected.

However, all my words are there but they are not shown when I type "words" at the prompt. Since I can only use those words from the terminal are those shown by the command "words" I have no way of manipulating the search order or vocabularies.

These words are, to void repeating them here, what was shown in my earlier message.

@TG9541

This comment has been minimized.

Copy link
Owner

commented Jan 25, 2018

@TG9541 TG9541 self-assigned this Jan 25, 2018
@TG9541

This comment has been minimized.

Copy link
Owner

commented Jan 26, 2018

Hi Richard,
just to be totally sure:

\ now I define "a"
NVM ok
: a ." test" cr ; ok
atest
ok
words
a IRET SAVEC RESET RAM NVM LOCK ULOCK ADC@ ADC! ?KEYB P7S E7S WORDS .S DUMP IMMEDIATE ALLOT VARIABLE CONSTANT CREATE DOES> ] : ; OVERT ." $" ABORT" AFT REPEAT WHILE AHEAD ELSE THEN IF AGAIN UNTIL BEGIN +LOOP LOOP DO NEXT FOR COMPILE [COMPILE] LITERAL CALL, C, , ' hi CR [ NAME> \ ( .( ? . U. TYPE U.R .R SPACES SPACE KEY DECIMAL HEX <# SIGN HOLD #S # #> ERASE FILL CMOVE HERE COUNT +! DEPTH PICK 0= ABS NEGATE NOT 1+ 1- 2+ 2- 2* 2/ EXG / /MOD M * UM / MOD /MOD M/MOD UM/MOD WITHIN MIN MAX < U< = DNEGATE 2DUP ROT ?DUP BG TIM BL OUT last '?KEY 'EMIT BASE - 0< OR AND XOR + UM+ I OVER SWAP DUP 2DROP DROP NIP >R R@ R> C! C@ ! @ B! 2C@ 2C! 2@ 2! EXIT EXECUTE LEAVE EMIT ?KEY TX! ?RX 'BOOT BKEY OUT! COLD ok

Now, here I would have expected RAM before the restart. However, you do a reset without it:

\ now I power off and back on
STM8eForth 2.2.21 ok
words
IRET SAVEC RESET RAM NVM LOCK ULOCK ADC@ ADC! ?KEYB P7S E7S WORDS .S DUMP I

The result is that the new words won't be linked. They remain in the flash memory, and they can be used of the address is known (e.g. by writing the address of a word to 'BOOT) , but they will be overwritten by new word definitions!

Could you please run the following:

RESET
NVM
: a ;
RAM
COLD   \ or do a power cycle
WORDS  \ a should be there

/Thomas

@VK6TT

This comment has been minimized.

Copy link
Collaborator Author

commented Jan 27, 2018

@TG9541

This comment has been minimized.

Copy link
Owner

commented Jan 27, 2018

Hi Richard,

the behavior of NVM and RAM is there by design. It's been done that way in order not to "wear out" the Flash memory cells used for initializing memory pointers like CONTEXT and LAST (the code is here). Sometimes RAM is hidden in constructs like the #include STARTTEMP ... TARGET ... ENDTEMP.

Maybe one of the following solutions would be more user friendly (because more obvious):

  • introduce a word KEEP (similar to PERSIST, which, by the way, copies the initialization values to a second list that's used by RESET)
  • the initialization values now updated by RAM could also be stored in EEPROM when completing a column definition in NVM mode

Your input is, as always, highly appreciated!
/Thomas

PS: please also have a look at issue #152 :-)

@VK6TT

This comment has been minimized.

Copy link
Collaborator Author

commented Jan 27, 2018

@TG9541

This comment has been minimized.

Copy link
Owner

commented Jan 27, 2018

Hi Richard,

thanks for the encouragement, and for the suggestion!

I added the line you proposed to readme.md, and I'm now thinking of adding a FAQ to the Wiki (some questions were indeed recurrent).

Regarding the number of write cycles: I never experienced the consequences of exceeding the STM8S00x limit of 100 cycles. Some of my STM8S003F3 boards were re-flashed much more often than that, but I never tried to operate those at "55°C for 20 years". My recommendation is therefore to use some µC boards for development, and others for deployment. It's likely that the low spec is a tool for lowering the quality assurance costs in batches of low-cost devices, and maybe ST even package STM8S103 production batches that may be slightly out of spec (and may thus not qualify for "55°C for 20 years after 10000 write cycles" ) as the low cost variant.

Kind regards,
Thomas

@TG9541 TG9541 closed this Jan 27, 2018
@VK6TT

This comment has been minimized.

Copy link
Collaborator Author

commented Jan 30, 2018

@TG9541

This comment has been minimized.

Copy link
Owner

commented Jan 30, 2018

Hi Richard,

I knew that Nuveton offers 8051-like µCs which are pin compatible with STM8S003F3P6, but I certainly didn't see that coming.

Lately, someone got a STM8S003 based W1209 with a 5k reference resistor (instead of 20k). The W1209 platform is now getting unstable, and people should know that. STM8 eForth has a basis as long as (less popular) devices like W1219, or W1401, are cheap enough.

Thermostat boards are rarely advertised as based on a specific µC, and most people won't care. However, I don't think that breakout boards are going to have "fake" chips (except maybe STM8S003F3 chips labeled as STM8S103F3).

By the way, when did you purchase the boards? Did you buy from a specific vendor?

Edit: The W1209 here from TENSTAR ROBOT aren't based on STM8S003F3 (there is no Vcap capacitor).

Edit2: here is another one, also from TENSTAR ROBOT. It's safe to say that these guys made their very own W1209.

@zcsahok

This comment has been minimized.

Copy link
Contributor

commented Feb 4, 2018

FYI I have a W1209 similar to the one in Edit2. It can be flashed, but it has a common anode LED display (p.n. TUSO-02803-U) as opposed to the common cathode display on the original board. Pin assignment is also a bit different and the result is garbled display. Did not test the serial IF, though.

@TG9541

This comment has been minimized.

Copy link
Owner

commented Feb 5, 2018

Zoltan, thanks, that's really interesting!

Now we have 4 variants (in the order of appearance):

  • the garden variety W1209 as described in the Wiki
  • one with improved sensor sensitivity in the 40°C range (5k reference resistor)
  • and one with a Nuveton 8051-style µC
  • one with a common anode LED display (yours)

Is your common-anode variant branded in any way (e.g. TENSTAR)?
Do you know of a way to identify it before buying?

I guess I'll have to think for a solution to this problem. If you like you can flash the W1209-FD binary, and try to connect through the PC4/PC5 key pins. If that works, we'll have to test the hypothesis that the PCB is the same. In that case patching the binary through the Forth console might be sufficient.

@TG9541 TG9541 changed the title NVM appears to be broken W1209 "mutants" (was: NVM appears to be broken) Feb 5, 2018
@TG9541 TG9541 added the help wanted label Feb 5, 2018
@TG9541 TG9541 reopened this Feb 5, 2018
@TG9541

This comment has been minimized.

Copy link
Owner

commented Feb 5, 2018

@zcsahok , you already described the hardware changes, thanks! Of course the PCB had to be changed to accommodate common-anode LED displays (the details are here: mister-grumbler/w1209-firmware#19 ).

Here is a version for CA displays: W1209-FD-CA.zip. If it works, it should also work with the W1209 data logging thermostat code.

@zcsahok

This comment has been minimized.

Copy link
Contributor

commented Feb 5, 2018

It's definitely better: now it shows

| |      |      |
---    ---    ---
  |    |      | |
       ---

Swapping B and F would give the expected 4th.
I does not react on key presses, but maybe that's intentional.

I'll upload HW details tomorrow.

@TG9541

This comment has been minimized.

Copy link
Owner

commented Feb 5, 2018

Oops, of course!

Here is the new file: W1209-FD-CA.zip

Yes, not reacting on keys is intentional as this was the "naked" Forth binary (you need to connect a terminal to program it - the compiler actually runs on the board).

I made a thermostat file for you - that one should work just fine: W1209-CA.zip

@zcsahok

This comment has been minimized.

Copy link
Contributor

commented Feb 5, 2018

Wow! W1209-CA.ihx works as expected.

@TG9541

This comment has been minimized.

Copy link
Owner

commented Feb 5, 2018

Great :-) You'll find that it isn't functionally equivalent to the orignal firmware. If you connect a terminal you can give the logger a try!

@zcsahok

This comment has been minimized.

Copy link
Contributor

commented Feb 6, 2018

I can confirm that serial console works also fine. No issues so far.

Here is the board I have: Link. Its "brand name" is diymore and on the back of the board it shows "XH-W1209". It has a uC marked as 8S003F3P6.

img_8279
(programming connector was populated by me)

The two marked vias are placed differently to the "normal" board.
img_8280b

Here's a normal board for reference (pic from net):
brd1_a

@TG9541

This comment has been minimized.

Copy link
Owner

commented Feb 6, 2018

Thanks for the feedback, and for the pictures!
The traces and vias you highlighted is a way to tell boards apart. The air gap isolation slots are also different. The pictures on the vendor's page show these details, too.
The µC markings are standard for STM8S003F3P6.

The board appears to be fully usable, but of course, introducing yet another variant for the base system isn't fun. Maybe it's an option to provide a patch for the binary. What do you think?

@zcsahok

This comment has been minimized.

Copy link
Contributor

commented Feb 7, 2018

Patch is fine as long it's easy to apply. I mean it shall be somehow automatized.

As far I could see in this case the only affected place is the LED_MPX routine (same pins are used, no change in BOARDINIT). Can one ensure that it's always compiled to the same address? Could it be linked from of library? I don't know the possibilities of the tooling.

(btw looking at the code I had the impression that at the fourth phase of multiplexing the display stays blank. Did I miss something?)

@TG9541

This comment has been minimized.

Copy link
Owner

commented Feb 8, 2018

Right, only LED_MPX is affected.

Any address can be published as a symbol, and it would be possible to run the patch from the Forth console, which has the advantage that it can be distributed as source code, yes, from the library.

Another option is to add a small hex file as a patch. This file, however, has absolute addresses, and the easiest way for building it, would be creating a full board folder. I've had plans for adding a board variant feature which help in a case like this.

Well observed, the fourth phase stays blank. It could be refactored to increase the repetition rate and luminosity by 1/4. However, to conserve space, the LED activity counter is the 2LSB of the "mod 2^n" background counter. There is no trade of when using boards with a 4 digits LED display.

Of course, you can change that if you like :-)

@TG9541

This comment has been minimized.

Copy link
Owner

commented Feb 9, 2018

Out of the cheapest offers, only this one with a green LED display looks like it were of the original kind!

The W1209 here, here, here and here look like they were of the "common anode" type. These will be supported in the future.

The ones here, here, and here are also (likely) non-standard. I ordered one for inspection.

@VK6TT

This comment has been minimized.

Copy link
Collaborator Author

commented Feb 11, 2018

@TG9541

This comment has been minimized.

Copy link
Owner

commented Feb 11, 2018

Hi Richard,
thanks for the info!

The vendor's picture looks like one of the 3rd kind in my last comment (one of those that I ordered for inspection).

It's a very good idea to provide an identification aid in the Wiki. There is no need to install git for uploading pictures: these can be dragged & dropped into comments in this issue, or in the "wiki photo non-issue" #40.

Edit: if the vendor's picture is accurate then the keys (SET, +, -), and communication through the key pins, will work. The working of the LED display has already been conformed. The remaining points to test are relay and sensor input.

@TG9541

This comment has been minimized.

Copy link
Owner

commented Feb 11, 2018

One open question is whether the "communication through the sensor input" variant should be removed. The "W1209-FD" variant allows using mini clamps while the first "W1209" requires removing the capacitor from the sensor input which is a rather "invasive" procedure.

@VK6TT

This comment has been minimized.

Copy link
Collaborator Author

commented Feb 11, 2018

@TG9541

This comment has been minimized.

Copy link
Owner

commented Feb 11, 2018

OK, that simplifies things when variants are to be supported.

We now have knowledge of the following variants:

  1. µC variants (STM8S003F3P6, and 8051).
  2. reference resistor variants (20k and 5k), and
  3. LED variants (CC, CA),

For obvious reasons STM8 eForth won't support the 805, and it will be up to the users to avoid them. The resistor variants can must be handled in the application software (or fixed by replacing resistors). The variants that matter are CC and CA LED displays.

@zcsahok

This comment has been minimized.

Copy link
Contributor

commented Feb 11, 2018

How about this approach for the variants

  • board name would be <baseboard>-<var1>-...-<varN>
  • includes come from <baseboard> dir, as now
  • tooling dynamically creates variant.h in <baseboard> dir that contains just defines for var1..N that control the included features,
    e.g.
.define var1
...
.define varN
  • board output files go to the corresponding dir in out, as now.

This would give quite a flexibility, even to define different baud rate. (say 1200 for the sensor pin so that cap can stay in circuit)
And it would of course allow a W1209-CA board.

@TG9541

This comment has been minimized.

Copy link
Owner

commented Feb 11, 2018

Zoltan, I also had ideas along these lines but creating variants is a messy business ;-)

The following things need to be considered:

  • variant points in multiple source files (e.g. boardcore.inc)
  • variant files and subdirectories in the out folder(.ihx, forth.rst, target/)

What do you think of a two level configuration folder structure? Generating files would be possible but it makes the debugging process even more complicated (I had to work around limitations of the outdated and heavily patched version of sdasstm8 that comes with SDCC).

It's Forth though. Some things can be patched easily on-line (e.g. the baud rate). As think about it... the baud rate timer reload value should have been exposed long ago ;-)

@TG9541

This comment has been minimized.

Copy link
Owner

commented Feb 17, 2018

Thanks a lot @VK6TT for providing great docs in the Wiki and to @zcsahok for providing code for the W1209-CA (Common Anode) variant!

@TG9541 TG9541 closed this Feb 17, 2018
@VK6TT

This comment has been minimized.

Copy link
Collaborator Author

commented Feb 18, 2018

@TG9541

This comment has been minimized.

Copy link
Owner

commented Mar 5, 2018

I've now got a W1209 with a Nuveton chip on it of my own. It has the original PCB layout. However, I opened a dispute on the basis of misleading pictures, e.g. components on the board, 30cm instead of 50cm sensor cable, and "wrong material" (which it clearly is). I've got a refund, but I couldn't test the 3rd W1209 PCB layout variant as planned.

This, of course, also refers to #156.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.