-
Notifications
You must be signed in to change notification settings - Fork 3k
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
STM32_gen_PeripheralPins.py script v1.12 #13036
Conversation
@jeromecoutant, thank you for your changes. |
BUTTON_list.append(EachPin) | ||
elif "BTN" in PinLabel[EachPin].upper(): | ||
BUTTON_list.append(EachPin) | ||
except: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't really use a bare except
here. I wouldn't expect we want to pass
on KeyboardInterrupt
, SystemExit
or another low level error. A slightly more pleasant version of this would be to catch all errors which derive from Exception
, but ideally we'd catch the specific exceptions we're expecting here (which I suspect is probably at least a KeyError
given all the dictionary look-ups).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be addressed.
@@ -1203,20 +1327,22 @@ def parse_BoardFile(fileName): | |||
print("Please set your configuration in '%s' file" % config_filename) | |||
config_file = open(config_filename, "w") | |||
if sys.platform.startswith("win32"): | |||
print("Platform is Windows") | |||
cubemxdir = "C:\\Program Files (x86)\\STMicroelectronics\\STM32Cube\\STM32CubeMX" | |||
# print("Platform is Windows") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shall we just remove this dead code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
l.sort(key=natural_sortkey) | ||
previous_pin = "" | ||
for p in l: | ||
# print("DEBUG pin %s => %s" % (p, p[0])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
either use logging or remove this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
- license header update - TIM_MST default value - PinNames.h is now complete
6821bee
to
dbe8e93
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thx for comments
l.sort(key=natural_sortkey) | ||
previous_pin = "" | ||
for p in l: | ||
# print("DEBUG pin %s => %s" % (p, p[0])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -1203,20 +1327,22 @@ def parse_BoardFile(fileName): | |||
print("Please set your configuration in '%s' file" % config_filename) | |||
config_file = open(config_filename, "w") | |||
if sys.platform.startswith("win32"): | |||
print("Platform is Windows") | |||
cubemxdir = "C:\\Program Files (x86)\\STMicroelectronics\\STM32Cube\\STM32CubeMX" | |||
# print("Platform is Windows") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
CI started |
Test run: SUCCESSSummary: 6 of 6 test jobs passed |
All green but the incorrect status reported from mergify makes it red. I'll merge as it can't be overwritten. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, after taking a closer look at this, I have some more comments. I know some of these issues already existed in the code, but we should try and improve any new code we add.
} | ||
|
||
def print_debug(console_line): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use the logging
module here. It will give us more informative output and allows the log level to be set.
s += "// TIM<x> cannot be used because already used by the us_ticker\n" | ||
s += "// You have to comment all PWM using TIM_MST defined in hal_tick.h file\n" | ||
s += "// or update python script (check TIM_MST_LIST) and re-run it\n" | ||
DefaultTimerCore1 = "TIM5" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason we use camel case here? The preferred style for python code is lowercase_with_underscores
for variable names, CamelCase
for class names. https://www.python.org/dev/peps/pep-0008/#function-and-variable-names
continue | ||
else: | ||
prev_p = p[0] | ||
p[0] += '_ALT%d' % alt_index |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer we didn't use single letter variable names. Can we come up with something more descriptive?
if p[1] in PinLabel.keys(): | ||
s2 += ' // Connected to ' + PinLabel[p[1]] | ||
s2 += '\n' | ||
out_c_file.write(s2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where do we open
this out_c_file
? Looks like we have the potential to leak a file descriptor, as this seems to be used throughout the script. We should use the with
statement to ensure the resources are released if an exception is raised. Same comment for out_h_file
.
@@ -979,6 +937,141 @@ def print_usb(lst): | |||
out_c_file.write( "#endif\n" ) | |||
|
|||
|
|||
def print_PinList(l): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have a more descriptive parameter name than l
?
NameCounter += 1 | ||
|
||
NameCounter = 1 | ||
if len(BUTTON_list) == 0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if len(BUTTON_list) == 0: | |
if not BUTTON_list: |
@@ -1148,42 +1241,63 @@ def parse_BoardFile(fileName): | |||
board_file.close() | |||
|
|||
for EachPin in PinData: | |||
try: | |||
PinLabel[EachPin] = "" | |||
if "Signal" in PinData[EachPin].keys(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to call keys
- the in
operator will just check dictionary keys by default.
cubemxdir = "<Set CubeMX install directory>" | ||
config_file.write(json.dumps({"CUBEMX_DIRECTORY":cubemxdir})) | ||
config_file.close() | ||
exit(1) | ||
print("Default path set: %s\n" % cubemxdir) | ||
config_file = open(config_filename, "r") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use the with
statement to ensure this file object is cleaned up when an exception occurs.
"DISCO_H747XIH": "DISCO_H747I" | ||
} | ||
|
||
if TargetName in target_rename.keys(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't need to call keys
epilog=textwrap.dedent('''\ | ||
Once generated, you have to check and comment pins that can not be used (specific HW, internal ADC channels, remove PWM using us ticker timer, ...) | ||
'''), | ||
formatter_class=RawTextHelpFormatter) | ||
group = parser.add_mutually_exclusive_group() | ||
|
||
group = parser.add_mutually_exclusive_group(required = True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
group = parser.add_mutually_exclusive_group(required = True) | |
group = parser.add_mutually_exclusive_group(required=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to go ahead and approve this as-is. This is a small script that doesn't form part of the core tools so I'm not as concerned about the quality. We can schedule in some improvement work into our backlog at a later date.
@rwalton-arm as it is fresh in your mind, I suggest you to propose a PR with all your good ideas just after merge ? |
Hi Jerome. Unfortunately I'm not going to have time for that this sprint. I will schedule the work for next sprint. I can refer back to this PR when I get time to make the changes so things won't be forgotten. Thanks for your hard work on this contribution! |
I have a good idea: please document how to use the script! ;-) It is mentioned at a Mbed STM page but without any usage instructions. I like the idea of the script very much but I was not able to try it. Using google I found some information snippets but unfortunatly that was not enough. |
Should be on #13053 ! |
@jeromecoutant isn't this just modifying ST target code and thus should be patch type ? |
Let's start CI ? |
CI restarted |
Test run: SUCCESSSummary: 6 of 6 test jobs passed |
Summary of changes
Goal is to help every one to make his own custom boards.
I remind script goal is to generate PeripheralPins.c and PinNames.h for ST MCU
Few addition in this PR:
@ARMmbed/team-st-mcd
Impact of changes
Migration actions required
Documentation
Pull request type
Test results
Reviewers