Skip to content

Various fixes and improvement#5

Closed
thbtcllt wants to merge 16 commits intovjardin:mainfrom
thbtcllt:dev
Closed

Various fixes and improvement#5
thbtcllt wants to merge 16 commits intovjardin:mainfrom
thbtcllt:dev

Conversation

@thbtcllt
Copy link
Collaborator

Fixes issue on read command
Change a fault command for consistency between get and set
Move store (now call save) and restore command to a specific command and not in user_data one
Fix issue to save and restore command for BMR456
Add generic command to access any byte and word register

tcollet and others added 16 commits November 10, 2025 17:28
block sequence for the restart is incorrect.
Regarding
https://datasheet.lcsc.com/lcsc/2412091105_Flex-Power-Modules-BMR4802112-032_C6132194.pdf
it is "ERIC" and not "00000000".
With this value restart is successfull for BMR456
Call to reset optind is done too early and the whole arguments are
provided to the subcommands that fails due to the unexpected value.
Just move the reset of optind after settings arg/argv for the
subcommand.
Add a substantial set of PMBus feature commands, aligned with Flex BMR
(BMR685/BMR456/BMR480) docs.
Include some long helps and some notes (see TODO).

1) capability
   - capability get
   - capability check --need-pec on|off --min-speed 100|400 --need-alert on|off [--strict]
   Decodes: PEC support, max bus speed (100/400 kHz), SMBALERT# presence,
   and reserved low bits.

2) interleave
   - interleave get
   - interleave set [--set 0xNN] [--phases 1..16 --index 0..15]`
   Upper nibble = phases-1, lower nibble = phase index.

3) hrr
   - hrr get
   - hrr set [--pec on|off] [--hrr on|off] [--dls linear|nonlinear] [--artdlc on|off] [--dbv on|off]`
   - hrr set --raw 0xNN
   Bits: bit7=PEC require, bit6=HRR, bit5=DLS slope, bit3=ART/DLC, bit2=DBV.
   Includes hrr help with detailed descriptions and examples.
   TODO: apply the same for other commands.

4) vin
   - vin get [--exp5 N] [--raw]
   - vin set [--on V] [--off V] [--exp5 N] | [--on-raw 0xNNNN] [--off-raw 0xNNNN]

5) pgood
   - pgood get [--exp5 N] [--raw]
   - pgood set [--on V] [--off V] [--exp5 N] | [--on-raw 0xNNNN] [--off-raw 0xNNNN]

6) freq
   - freq get
   - freq set --raw 0xNNNN

7) salert
   - salert get
   - salert set --raw 0xNN

8) addr-offset
   - addr-offset get
   - addr-offset set --raw 0xNN

9) ramp-data
   Returns a hex blob (TODO: no vendor decode).

10) status-data
    Returns a hex blob (concise status history snapshot).

11) write-protect
    - write-protect get
    - write-protect set [--none|--ctrl|--nvm|--all] | --raw 0xNN
    Typical values: 0x00, 0x40, 0x80, 0xFF.

- No behavior changes for the existing commands.
- PEC: Enabling via hrr will require the host stack to send SMBus PEC or
  communication will fail; see comments from hrr help.
The scaling logic can be incorrect. When exp5 >= 0, the condition (1 << (-exp5))
attempts a left shift with a negative value, which is undefined behavior.
The logic should be inverted: when exp5 is negative, use (1 << (-exp5)),
and when positive, use division.

The simplest option is to use math.h's ldexp(). It seems it does not
require libm.
Since it is not an obvious value to be set and it'll be very likely
available from most devices from VOUT_MODE, let's read first the needed
value instead of using the arguments.

Let's keep the --exp5 argument if we to do not trust the read values.
Factorize the code to util_json.c
Centralize the lin16 code. It should be used to better apply the
specifications based on PMBus-Specification-Rev-1-3-1-Part-II-20150313.pdf
from https://pmbus.org/specification-archives/
Some BMR do not support an automatic restart. The workaround can be
to generate a fault that leads to a shutdown until the fault is cleared.

For instance, we can set the fault on the temperature.
Based on the PMBus specifiations, add few cases that were not clearly
described by the Flex/BMR documentation.
Purpose of this command is to:
- be able to configure any BMR where commands behavior is different from
  456 or 685
- access non documented commands (if any)
Use the same order of the get that is more logical
Fault configuration for voltage or intensity will be added later.
Useless call:
json_object_set_new(o, key + (sizeof("") - 1), json_object_get(o, key))
break the json object and then call to json_print_or_pretty do a
segfault as json_dumps return NULL and this case is not checked before
calling put(s)

A check is added in function json_print_or_pretty to avoid the segfault
(an error message is displayed) and useless call is removed.
Save and restore are required for any commands and not only for the
USER_DATA.
Two new commands are created for that and README is changed accordingly.
For these new commands BMT456 does not exepct call to sendbyte but a
write byte on the command with a dummy value.
A test is done on the BMR version to know how to execute the command.

Moreover for the restore two options are provided to reload the default
configuration or the last saved configuration.
No automatic save is done after a restore.
@thbtcllt thbtcllt closed this by deleting the head repository Nov 20, 2025
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

Successfully merging this pull request may close these issues.

2 participants