Skip to content

Instantly share code, notes, and snippets.

@stan754
Created December 7, 2023 09:34
Show Gist options
  • Save stan754/bc2805a27e79fafc674e9a254ba0fa92 to your computer and use it in GitHub Desktop.
Save stan754/bc2805a27e79fafc674e9a254ba0fa92 to your computer and use it in GitHub Desktop.
Calculate IWDG Reload value
import argparse
from tabulate import tabulate
parser = argparse.ArgumentParser(description='Calculate IWDG RLR')
parser.add_argument("-ms", help="Reload time in ms", default=20 , type=int)
parser.add_argument("-pr", help="PR value as decimal", default=1, type=int)
parser.add_argument("-lsi", help="LSI Clock in Hz", default=40000, type=int)
args = parser.parse_args()
ms = args.ms
PR = args.pr
LSI = args.lsi
RL = int(((ms*LSI)/(4*(2**PR)*1000))-1)
table = [
["Var", "Value", "HEX", "BIN"],
["MS", f'{ms} ms'],
["LSI", f'{LSI} Hz'],
["PR", PR, hex(PR), bin(PR)],
["RL", RL, hex(RL), bin(RL)]
]
print(tabulate(table, headers='firstrow', tablefmt='grid'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment