From 22e538df162c8c8ecdaf2f223c24c0e8a67c9db5 Mon Sep 17 00:00:00 2001 From: Jakub Kaderka Date: Fri, 28 Sep 2018 12:10:01 +0200 Subject: Generate PAL_LINE for named pins --- tools/mx2board.py | 2 ++ 1 file changed, 2 insertions(+) mode change 100644 => 100755 tools/mx2board.py (limited to 'tools/mx2board.py') diff --git a/tools/mx2board.py b/tools/mx2board.py old mode 100644 new mode 100755 index 642a934..132689e --- a/tools/mx2board.py +++ b/tools/mx2board.py @@ -267,6 +267,8 @@ def gen_defines(project): defines['PORT_'+label] = 'GPIO' + port_key defines['PAD_'+label] = pad_key + defines['LINE_'+label] = 'PAL_LINE(GPIO' + port_key + defines['LINE_'+label] += ', ' + str(pad_key) + 'U)' if re.search(r"TIM\d+_CH\d$", signal, re.M): timer = signal.replace('S_TIM', '').replace('_CH', '')[:-1] -- cgit v1.2.3 From 92b21d872d5edcac773843986a645c2e1e572b03 Mon Sep 17 00:00:00 2001 From: Jakub Kaderka Date: Mon, 10 Dec 2018 22:34:43 +0100 Subject: Fixed board generation for pins with note in name --- tools/mx2board.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'tools/mx2board.py') diff --git a/tools/mx2board.py b/tools/mx2board.py index 132689e..99b54a3 100755 --- a/tools/mx2board.py +++ b/tools/mx2board.py @@ -171,7 +171,11 @@ def read_gpio(filename): for pin in root.findall('GPIO_Pin'): try: port = pin.attrib['Name'][1] - num = int(pin.attrib['Name'][2:]) + num = pin.attrib['Name'][2:] + # remove notes from pin name (e.g. PH0 - OSC_IN) + num = num.split('-')[0].strip() + num = int(num) + if port not in gpio['ports']: gpio['ports'][port] = {} if num not in gpio['ports'][port]: -- cgit v1.2.3 From bfa560413c8052e7ef2be656546b2868e5a993a2 Mon Sep 17 00:00:00 2001 From: Jakub Kaderka Date: Fri, 21 Dec 2018 17:25:22 +0100 Subject: Fixed Timer number generation --- tools/mx2board.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/mx2board.py') diff --git a/tools/mx2board.py b/tools/mx2board.py index 99b54a3..5bec83c 100755 --- a/tools/mx2board.py +++ b/tools/mx2board.py @@ -275,7 +275,7 @@ def gen_defines(project): defines['LINE_'+label] += ', ' + str(pad_key) + 'U)' if re.search(r"TIM\d+_CH\d$", signal, re.M): - timer = signal.replace('S_TIM', '').replace('_CH', '')[:-1] + timer = signal.replace('TIM', '').replace('_CH', '')[:-1] ch_num = int(signal[-1:]) defines['TIM_' + label] = timer -- cgit v1.2.3 From ceff99507d96795f5040d6a0b493867ceaf35d34 Mon Sep 17 00:00:00 2001 From: Jakub Kaderka Date: Fri, 21 Dec 2018 23:52:26 +0100 Subject: Generate peripherals and channels from signal name --- tools/mx2board.py | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) (limited to 'tools/mx2board.py') diff --git a/tools/mx2board.py b/tools/mx2board.py index 5bec83c..14b367c 100755 --- a/tools/mx2board.py +++ b/tools/mx2board.py @@ -230,6 +230,7 @@ def read_project(gpio, filename): or 'DAC' in prop_value \ or 'OSC' in prop_value: pads[pad_port][pad_num]["MODER"] = PIN_MODE_ANALOG + pads[pad_port][pad_num]["SIGNAL"] = prop_value elif 'GPIO_Output' == prop_value: pads[pad_port][pad_num]["MODER"] = PIN_MODE_OUTPUT elif 'GPIO_Input' == prop_value: @@ -274,15 +275,48 @@ def gen_defines(project): defines['LINE_'+label] = 'PAL_LINE(GPIO' + port_key defines['LINE_'+label] += ', ' + str(pad_key) + 'U)' - if re.search(r"TIM\d+_CH\d$", signal, re.M): - timer = signal.replace('TIM', '').replace('_CH', '')[:-1] - ch_num = int(signal[-1:]) - + match = re.search(r"TIM(\d+)_CH(\d)$", signal) + if match: + timer = match.group(1) + ch_num = int(match.group(2)) defines['TIM_' + label] = timer defines['CCR_' + label] = 'CCR' + timer[-1] defines['PWMD_' + label] = 'PWMD' + timer[-1] defines['ICUD_' + label] = 'ICUD' + timer[-1] defines['CHN_' + label] = ch_num - 1 + continue + + match = re.search(r"ADC(\d*)_IN(\d+)$", signal) + if match: + adc = match.group(1) + if len(adc) == 0: + adc = 1 + defines['ADC_' + label] = adc + defines['CHN_' + label] = match.group(2) + continue + + match = re.search(r"USART(\d+)_[RT]X$", signal) + if match: + defines['USART_' + label] = match.group(1) + continue + + match = re.search(r"COMP_DAC(\d+)_group", signal) + if match: + defines['DAC_' + label] = match.group(1) + continue + + match = re.search(r"I2C(\d)_S(CL|DA)", signal) + if match: + defines['I2C_' + label] = match.group(1) + continue + + match = re.search(r"CAN(\d)_[RT]X", signal) + if match: + can = match.group(1) + if len(can) == 0: + can = 1 + defines['CAN_' + label] = can + continue return defines -- cgit v1.2.3 From 4ce121fdb0039a11f9617ca0e8a53bdac57a64c8 Mon Sep 17 00:00:00 2001 From: Jakub Kaderka Date: Sat, 22 Dec 2018 09:12:33 +0100 Subject: Fixed single can generation --- tools/mx2board.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/mx2board.py') diff --git a/tools/mx2board.py b/tools/mx2board.py index 14b367c..20dcfb3 100755 --- a/tools/mx2board.py +++ b/tools/mx2board.py @@ -310,7 +310,7 @@ def gen_defines(project): defines['I2C_' + label] = match.group(1) continue - match = re.search(r"CAN(\d)_[RT]X", signal) + match = re.search(r"CAN(\d*)_[RT]X", signal) if match: can = match.group(1) if len(can) == 0: -- cgit v1.2.3 From 7b88a716bdb83a06e68e6ac8ab4a3648796a0df6 Mon Sep 17 00:00:00 2001 From: Jakub Kaderka Date: Mon, 28 Jan 2019 20:14:57 +0100 Subject: Added ODR setting to mx2board.py --- tools/mx2board.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'tools/mx2board.py') diff --git a/tools/mx2board.py b/tools/mx2board.py index 20dcfb3..1727b12 100755 --- a/tools/mx2board.py +++ b/tools/mx2board.py @@ -48,7 +48,7 @@ DEFAULT_PAD = {"SIGNAL": "UNUSED", "OTYPER": PIN_OTYPE_PUSHPULL, "OSPEEDR": PIN_OSPEED_VERYLOW, "PUPDR": PIN_PUPDR_FLOATING, - "ODR": PIN_ODR_HIGH} + "ODR": PIN_ODR_LOW} PIN_MODE_TRANSLATE = {"GPIO_MODE_AF_PP": PIN_MODE_ALTERNATE, "GPIO_MODE_ANALOG": PIN_MODE_ANALOG, @@ -70,6 +70,9 @@ PIN_PUPDR_TRANSLATE = {"GPIO_NOPULL": PIN_PUPDR_FLOATING, "GPIO_PULLUP": PIN_PUPDR_PULLUP, "GPIO_PULLDOWN": PIN_PUPDR_PULLDOWN} +PIN_ODR_TRANSLATE = {"GPIO_PIN_SET": PIN_ODR_HIGH, + "GPIO_PIN_CLEAR": PIN_ODR_LOW} + parser = ArgumentParser(description='Generate ChibiOS GPIO header file from STM32CubeMX project files.') group = parser.add_mutually_exclusive_group(required=False) group.add_argument('-m', '--mx', default='', type=str, help='STM32CubeMX path. Invalid if -g is used.') @@ -222,6 +225,7 @@ def read_project(gpio, filename): pad_prop = split[0].split(".")[-1] prop_value = split[-1].rstrip('\r\n') + if pad_prop == "Signal": if 'S_TIM' in prop_value: prop_value = prop_value[2:] @@ -250,6 +254,8 @@ def read_project(gpio, filename): pads[pad_port][pad_num]["MODER"] = PIN_MODE_OUTPUT elif pad_prop == "GPIO_Speed": pads[pad_port][pad_num]["OSPEEDR"] = PIN_OSPEED_TRANSLATE[prop_value] + elif pad_prop == "PinState": + pads[pad_port][pad_num]["ODR"] = PIN_ODR_TRANSLATE[prop_value] return pads -- cgit v1.2.3 From e0e7b4270bcbc53e591df8b456f920e404d4158a Mon Sep 17 00:00:00 2001 From: Jakub Kaderka Date: Sun, 10 Feb 2019 21:26:18 +0100 Subject: Added spi and fixed FSMC alternate setup --- tools/mx2board.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tools/mx2board.py') diff --git a/tools/mx2board.py b/tools/mx2board.py index 1727b12..6e09d39 100755 --- a/tools/mx2board.py +++ b/tools/mx2board.py @@ -240,6 +240,11 @@ def read_project(gpio, filename): elif 'GPIO_Input' == prop_value: pads[pad_port][pad_num]["MODER"] = PIN_MODE_INPUT else: + # workaround for different names in project and gpio defs + if "FSMC" in prop_value: + prop_value = re.sub(r"FSMC_D([0-9]+)_DA[0-9]+", + r"FSMC_D\1", prop_value) + pads[pad_port][pad_num]["SIGNAL"] = prop_value pads[pad_port][pad_num]["MODER"] = PIN_MODE_ALTERNATE pads[pad_port][pad_num]["OSPEEDR"] = PIN_OSPEED_MEDIUM @@ -316,6 +321,11 @@ def gen_defines(project): defines['I2C_' + label] = match.group(1) continue + match = re.search(r"SPI(\d)_(MOSI|MISO|SCK|NSS)", signal) + if match: + defines['SPI_' + label] = match.group(1) + continue + match = re.search(r"CAN(\d*)_[RT]X", signal) if match: can = match.group(1) -- cgit v1.2.3 From 1698a158b3ba91bccc1887733e31b19703caf61b Mon Sep 17 00:00:00 2001 From: Jakub Kaderka Date: Wed, 6 Mar 2019 19:54:44 +0100 Subject: Fixed gpio pin reset --- tools/mx2board.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tools/mx2board.py') diff --git a/tools/mx2board.py b/tools/mx2board.py index 6e09d39..4ad3e97 100755 --- a/tools/mx2board.py +++ b/tools/mx2board.py @@ -71,7 +71,8 @@ PIN_PUPDR_TRANSLATE = {"GPIO_NOPULL": PIN_PUPDR_FLOATING, "GPIO_PULLDOWN": PIN_PUPDR_PULLDOWN} PIN_ODR_TRANSLATE = {"GPIO_PIN_SET": PIN_ODR_HIGH, - "GPIO_PIN_CLEAR": PIN_ODR_LOW} + "GPIO_PIN_CLEAR": PIN_ODR_LOW, + "GPIO_PIN_RESET": PIN_ODR_LOW } parser = ArgumentParser(description='Generate ChibiOS GPIO header file from STM32CubeMX project files.') group = parser.add_mutually_exclusive_group(required=False) -- cgit v1.2.3 From 814a79bfaf907508578320c1e9e55fa7c77cd773 Mon Sep 17 00:00:00 2001 From: Jakub Kaderka Date: Wed, 13 Mar 2019 21:09:24 +0100 Subject: I2C not set as opendrain, fixed --- tools/mx2board.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tools/mx2board.py') diff --git a/tools/mx2board.py b/tools/mx2board.py index 4ad3e97..8ab155d 100755 --- a/tools/mx2board.py +++ b/tools/mx2board.py @@ -262,6 +262,10 @@ def read_project(gpio, filename): pads[pad_port][pad_num]["OSPEEDR"] = PIN_OSPEED_TRANSLATE[prop_value] elif pad_prop == "PinState": pads[pad_port][pad_num]["ODR"] = PIN_ODR_TRANSLATE[prop_value] + elif pad_prop == "Mode": + if "I2C" in prop_value: + pads[pad_port][pad_num]["OTYPER"] = PIN_OTYPE_OPENDRAIN + return pads -- cgit v1.2.3