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

STM32_gen_PeripheralPins.py script v1.12 #13036

Merged
merged 1 commit into from
Jun 17, 2020

Conversation

jeromecoutant
Copy link
Collaborator

@jeromecoutant jeromecoutant commented May 29, 2020

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:

  • alignment with ST internal version
  • license header update
  • PinNames.h is now complete

@ARMmbed/team-st-mcd

Impact of changes

Migration actions required

Documentation


Pull request type

[x] Patch update (Bug fix / Target update / Docs update / Test update / Refactor)
[] Feature update (New feature / Functionality change / New API)
[] Major update (Breaking change E.g. Return code change / API behaviour change)

Test results

[x] No Tests required for this change (E.g docs only update)
[] Covered by existing mbed-os tests (Greentea or Unittest)
[] Tests / results supplied as part of this PR

Reviewers


@ciarmcom
Copy link
Member

@jeromecoutant, thank you for your changes.
@ARMmbed/mbed-os-tools @ARMmbed/mbed-os-maintainers please review.

@ciarmcom ciarmcom requested review from a team May 29, 2020 15:00
BUTTON_list.append(EachPin)
elif "BTN" in PinLabel[EachPin].upper():
BUTTON_list.append(EachPin)
except:
Copy link
Contributor

@rwalton-arm rwalton-arm Jun 2, 2020

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).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be addressed.

0xc0170
0xc0170 previously requested changes Jun 3, 2020
@@ -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")
Copy link
Contributor

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?

Copy link
Collaborator Author

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]))
Copy link
Contributor

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

Copy link
Collaborator Author

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
Copy link
Collaborator Author

@jeromecoutant jeromecoutant left a 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]))
Copy link
Collaborator Author

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")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

tools/targets/STM32_gen_PeripheralPins.py Outdated Show resolved Hide resolved
tools/targets/STM32_gen_PeripheralPins.py Outdated Show resolved Hide resolved
tools/targets/STM32_gen_PeripheralPins.py Outdated Show resolved Hide resolved
@mergify mergify bot dismissed 0xc0170’s stale review June 8, 2020 09:11

Pull request has been modified.

@mergify mergify bot added needs: CI and removed needs: review labels Jun 8, 2020
@0xc0170
Copy link
Contributor

0xc0170 commented Jun 9, 2020

CI started

@mbed-ci
Copy link

mbed-ci commented Jun 9, 2020

Test run: SUCCESS

Summary: 6 of 6 test jobs passed
Build number : 1
Build artifacts

@0xc0170
Copy link
Contributor

0xc0170 commented Jun 10, 2020

All green but the incorrect status reported from mergify makes it red. I'll merge as it can't be overwritten.

Copy link
Contributor

@rwalton-arm rwalton-arm left a 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):
Copy link
Contributor

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"
Copy link
Contributor

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
Copy link
Contributor

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)
Copy link
Contributor

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):
Copy link
Contributor

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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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():
Copy link
Contributor

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")
Copy link
Contributor

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():
Copy link
Contributor

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
group = parser.add_mutually_exclusive_group(required = True)
group = parser.add_mutually_exclusive_group(required=True)

Copy link
Contributor

@rwalton-arm rwalton-arm left a 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.

@jeromecoutant
Copy link
Collaborator Author

jeromecoutant commented Jun 11, 2020

@rwalton-arm as it is fresh in your mind, I suggest you to propose a PR with all your good ideas just after merge ?

@rwalton-arm
Copy link
Contributor

@rwalton-arm as it is fresh in your mind, I suggest 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!

@ATM-HSW
Copy link

ATM-HSW commented Jun 11, 2020

@rwalton-arm as it is fresh in your mind, I suggest you to propose a PR with all your good ideas just after merge ?

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.

@jeromecoutant
Copy link
Collaborator Author

I have a good idea: please document how to use the script! ;-)

Should be on #13053 !

@adbridge
Copy link
Contributor

@jeromecoutant isn't this just modifying ST target code and thus should be patch type ?

@jeromecoutant
Copy link
Collaborator Author

Let's start CI ?

@adbridge adbridge added needs: CI release-type: patch Indentifies a PR as containing just a patch and removed needs: work labels Jun 17, 2020
@adbridge
Copy link
Contributor

CI restarted

@mbed-ci
Copy link

mbed-ci commented Jun 17, 2020

Test run: SUCCESS

Summary: 6 of 6 test jobs passed
Build number : 2
Build artifacts

@0xc0170 0xc0170 merged commit 31748ed into ARMmbed:master Jun 17, 2020
@mergify mergify bot removed the ready for merge label Jun 17, 2020
@jeromecoutant jeromecoutant deleted the PR_GENPERIPH_V12 branch June 17, 2020 11:42
@adbridge adbridge added release-version: 6.1.0 Release-pending and removed release-type: patch Indentifies a PR as containing just a patch Release-pending labels Jun 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants