summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2017-08-24 22:43:36 +1000
committerDamien George <damien.p.george@gmail.com>2017-08-24 22:43:36 +1000
commit7e6881cf7dad69f753ad3e16e5c3e9270f2ab527 (patch)
tree152c1ff41ae27cbfd841dbb1bd99d269c9829b77
parent3e1412a1fb1a9c57858f67f01173ec8e966fdfe1 (diff)
stmhal/boards/pllvalues.py: Make script work with both Python 2 and 3.
-rw-r--r--stmhal/boards/pllvalues.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/stmhal/boards/pllvalues.py b/stmhal/boards/pllvalues.py
index e930ae87d..befd6cfa0 100644
--- a/stmhal/boards/pllvalues.py
+++ b/stmhal/boards/pllvalues.py
@@ -4,6 +4,8 @@ the CPU frequency to a given value. The algorithm here appears as C code
for the machine.freq() function.
"""
+from __future__ import print_function
+
def close_int(x):
return abs(x - round(x)) < 0.01
@@ -38,7 +40,10 @@ def compute_pll(hse, sys):
# improved version that doesn't require N/M to be an integer
def compute_pll2(hse, sys):
- for P in (2, 4, 6, 8): # allowed values of P
+ # Loop over the allowed values of P, looking for a valid PLL configuration
+ # that gives the desired "sys" frequency. We use floats for P to force
+ # floating point arithmetic on Python 2.
+ for P in (2.0, 4.0, 6.0, 8.0):
Q = sys * P / 48
# Q must be an integer in a set range
if not (close_int(Q) and 2 <= Q <= 15):