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

XH-M188 locking up after power-up #44

Closed
hexagon5un opened this issue Aug 3, 2017 · 5 comments
Closed

XH-M188 locking up after power-up #44

hexagon5un opened this issue Aug 3, 2017 · 5 comments
Assignees

Comments

@hexagon5un
Copy link
Collaborator

After a power cycle my test XH-M188s don't respond with the stm8eForth prompt, or apparently work at all. Sometimes a reset either with a pushbutton or the st-link programmer will bring the console back, but even then the PWM doesn't work. They work just fine when freshly programmed, but a subsequent power cycle kills 'em.

I wrote some frankly dodgy code in the init section for this board, and I'm not surprised if it's related to that. To set the hardware PWM channel for the board, there is some fooling around with option bytes in flash, and it could be the bug lies there.

I tested the same boards out with the MINDEV version, and they work just fine on power-up every time, so I'm pretty sure that it's the firmware. I'll look into it fairly soon.

hexagon5un pushed a commit to hexagon5un/stm8ef that referenced this issue Aug 3, 2017
Old version mistakenly unlocked option bytes, not necessary from user
space code
Old version didn't wait for EOP (end of programming) bit to be set

New version does both, and doesn't hang.  Woot.
@hexagon5un
Copy link
Collaborator Author

Fix was easy. Partly reading the three (!) datasheets correctly, partly buckling down and writing a one-liner busy-wait in assembly. Sent pull request.

hexagon5un added a commit that referenced this issue Aug 3, 2017
Fixes #44: XH-M188 lockup after power cycle
@TG9541
Copy link
Owner

TG9541 commented Aug 5, 2017

I wonder whether a standard method for defining option bits in a project should look like. It would be possible to define option bits in a file in the board folder but especially for breakout boards that misses the point. Checking and setting the option bits should be done at the start of the application software. Problem is that options bits can be wrong even if the application is completely happy with the default.

What do you think about the following:

  • always reset option bits to the default in the make flash target
  • always check the option bits if a non-default value (i.e. not 0x00) is needed
  • change the option bit value automatically if needed

@hexagon5un
Copy link
Collaborator Author

I didn't know there was option-byte code in lib/ ... or maybe there wasn't when I wrote the first versioin of the XH-M188 code.

The OPT! word in lib/ doesn't a) wait for EEPROM write to finish, or b) reset the option-protect bit (in FLASH_CR2) when it's done. It could probably do both.

An option-bytes config shouild definitely default to a per-board setting. On the XH-M188, for instance, it's absolutely necessary to set the option bit to enable PWM on the voltage-control channel.

And you'll definitely want to enable user access to the option bits for the general-purpose boards as well, as your servo example illustrates. OPT! is a great addition to the lib/.

The check-default, modify-if-needed plan you outlined seems fine to me.

hexagon5un pushed a commit to hexagon5un/stm8ef that referenced this issue Aug 8, 2017
* upstream/master: (25 commits)
  reference to Wiki updated
  library additions
  library mcu according to e4thcom convention
  Update README.md
  some bytes saved
  some editing
  Fixes TG9541#44: XH-M188 lockup after power cycle
  fixes TG9541#43 Provide a Forth library infrastructure
  fixes TG9541#42 Improve W1209 ease of use
  fixes TG9541#42 Improve W1209 ease of use
  fixes TG9541#41: improved full duplex simulated serial
  edit
  Fix for UART simulation with 2 GPIOs
  HAS_ALIAS default on (IMMEDIATE words in RAM possible)
  SWIMCOM fix for HEADER macro, option WORDS_HWREG off
  issue TG9541#32 Build framework feature #include
  fixes TG9541#39 : underflow error message doesn't match normal pattern
  fixes TG9541#39 : underflow error message doesn't match normal pattern
  issue TG9541#32 Build framework feature: Forth application binary with uCsim
  issue TG9541#32: use telnet library
  ...
@TG9541
Copy link
Owner

TG9541 commented Aug 12, 2017

The library is quite new, and when you published the OPT-setting code the library didn't even exist :-)
You're right: the OPT! should reset the write protection bit. Please correct me if I'm wrong but in my understanding EEPROM and Flash write access stalls the CPU until the next write is possible. Since I don't know if it's safe to reset the option-protect bit before the write is complete it's probably best to wait until the EEPROM write has finished.
I'll change the OPT! library code (using an in-line STM8 spin-lock).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants