Skip to content

Commit

Permalink
Add further separation between the two families of devices.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmlambo committed Aug 28, 2023
1 parent 35a7b99 commit 32e40a2
Show file tree
Hide file tree
Showing 9 changed files with 163 additions and 32 deletions.
6 changes: 4 additions & 2 deletions misc/scripts/gd32_genpinmap/datasheet_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ def process_add_funcs_dataframe(dfs: DataFrame, datasheet_info: DatasheetParsing
last_column = the_overwrite_quirk.pin_description
add_funcs_arr = GD32DatasheetParser.analyze_additional_funcs_string(last_column)
print("Pin %s Add. Funcs: %s" % (pin_name, str(add_funcs_arr)))
additional_funcs[pin_name] = GD32Pin(pin_name, [GD32PinFunction(sig, None, None, None, pages_info.subseries, pages_info.package) for sig in add_funcs_arr])
additional_funcs[pin_name] = GD32Pin(pin_name, [GD32PinFunction(sig, None, None, None, datasheet_info.family_type, pages_info.subseries, pages_info.package) for sig in add_funcs_arr])
print(additional_funcs)
return additional_funcs

Expand Down Expand Up @@ -389,12 +389,14 @@ def process_alts_and_remaps(dfs: DataFrame, datasheet_info: DatasheetParsingInfo
None,
GD32DatasheetParser.analyze_footnote(sig)[1],
pages_info.footnotes_device_availability,
datasheet_info.family_type,
pages_info.subseries, pages_info.package, False) for sig in alternate_arr
] + [
GD32PinFunction(GD32DatasheetParser.analyze_footnote(sig)[0],
None,
GD32DatasheetParser.analyze_footnote(sig)[1],
pages_info.footnotes_device_availability,
datasheet_info.family_type,
pages_info.subseries, pages_info.package, True) for sig in remap_arr
])
print(parsed_pins)
Expand Down Expand Up @@ -457,7 +459,7 @@ def process_af_dataframe(dfs: DataFrame, datasheet_info: DatasheetParsingInfo, p
for f in funcs:
# check if we need to extra footnotes
sig_name, footnote = GD32DatasheetParser.analyze_footnote(f)
af_list.append(GD32PinFunction(sig_name, get_trailing_number(af_name), footnote, pages_info.footnotes_device_availability))
af_list.append(GD32PinFunction(sig_name, get_trailing_number(af_name), footnote, pages_info.footnotes_device_availability, datasheet_info.family_type))
print(af_list)
parser_result_pins[pin_name] = GD32Pin(pin_name, af_list)
print("Parsed all %d pins." % len(parser_result_pins))
Expand Down
2 changes: 1 addition & 1 deletion misc/scripts/gd32_genpinmap/func_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typing import Tuple
from pin_definitions import GD32Pin, GD32PinFunction

def get_trailing_number(s):
def get_trailing_number(s:str):
m = re.search(r'\d+$', s)
return int(m.group()) if m else None

Expand Down
9 changes: 5 additions & 4 deletions misc/scripts/gd32_genpinmap/gd32_genpinmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,14 @@ def main_func():
#"C:\\Users\\Max\\Desktop\\gd32_dev\\gigadevice-firmware-and-docs\\GD32F30x\\GD32F303xx_Datasheet_Rev1.9.pdf"
#"C:\\Users\\Max\\Desktop\\gd32_dev\\gigadevice-firmware-and-docs\\GD32E23x\\GD32E230xx_Datasheet_Rev1.4.pdf",
#"C:\\Users\\Max\\Desktop\\gd32_dev\\gigadevice-firmware-and-docs\\GD32F1x0\\GD32F190xx_Datasheet_Rev2.1.pdf",
"C:\\Users\\Max\\Desktop\\gd32_dev\\gigadevice-firmware-and-docs\\GD32F1x0\\GD32F170xx_Datasheet_Rev2.1.pdf",
"C:\\Users\\Max\\Desktop\\gd32_dev\\gigadevice-firmware-and-docs\\GD32F1x0\\GD32F150xx_Datasheet_Rev3.2.pdf",
"C:\\Users\\Max\\Desktop\\gd32_dev\\gigadevice-firmware-and-docs\\GD32F1x0\\GD32F130xx_Datasheet_Rev3.4.pdf",
# "C:\\Users\\Max\\Desktop\\gd32_dev\\gigadevice-firmware-and-docs\\GD32F1x0\\GD32F170xx_Datasheet_Rev2.1.pdf",
# "C:\\Users\\Max\\Desktop\\gd32_dev\\gigadevice-firmware-and-docs\\GD32F1x0\\GD32F150xx_Datasheet_Rev3.2.pdf",
# "C:\\Users\\Max\\Desktop\\gd32_dev\\gigadevice-firmware-and-docs\\GD32F1x0\\GD32F130xx_Datasheet_Rev3.4.pdf",
"~/gd32-pdf/GD32F103xx-Datasheet-Rev-2.7.pdf"
]
for datasheet_pdf_path in datasheet_pdf_paths:
device_pinmap = load_pinmap(datasheet_pdf_path)
if device_pinmap is None or "--no-load-preparsed" in sys.argv or True:
if device_pinmap is None or "--no-load-preparsed" in sys.argv:
device_pinmap = GD32DatasheetParser.get_pinmap_for_pdf(datasheet_pdf_path)
save_pinmap(device_pinmap)
device_pinmap.solve_remapper_pins()
Expand Down
72 changes: 68 additions & 4 deletions misc/scripts/gd32_genpinmap/known_datasheets.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,54 @@
"GD32F103xx-Datasheet-Rev-2.7.pdf": DatasheetParsingInfo(
alternate_funcs = [],
pin_defs = [
# GD32F103Zx
DatasheetPinDefPageParsingInfo([21], "GD32F103Zx", "LQFP144", [
ParseUsingAreaQuirk((180,123,769,527)),
OverwritePinDescriptionQuirk("PF6", "Default: PF6\rAlternate: ADC2_IN4, EXMC_NIORD\nRemap: TIMER9_CH0(3)"),
]),
DatasheetPinDefPageParsingInfo([22], "GD32F103Zx", "LQFP144", [
ParseUsingAreaQuirk((88,123,769,527)),
]),
DatasheetPinDefPageParsingInfo([23], "GD32F103Zx", "LQFP144", [
ParseUsingAreaQuirk((88,123,769,527)),
OverwritePinDescriptionQuirk("PG1", "Default: PG1\rAlternate: EXMC_A11"),
]),
DatasheetPinDefPageParsingInfo([24], "GD32F103Zx", "LQFP144", [
ParseUsingAreaQuirk((88,123,769,527)),
OverwritePinDescriptionQuirk("PB13", "Default: PB13\rAlternate: SPI1_SCK, USART2_CTS, TIMER0_CH0_ON, I2S1_CK"),
]),
DatasheetPinDefPageParsingInfo([25], "GD32F103Zx", "LQFP144", [
ParseUsingAreaQuirk((88,123,769,527)),
]),
DatasheetPinDefPageParsingInfo([26], "GD32F103Zx", "LQFP144", [
ParseUsingAreaQuirk((88,123,769,527)),
OverwritePinDescriptionQuirk("PC10", "Default: PC10\nAlternate: UART3_TX, SDIO_D2\nRemap: USART2_TX, SPI2_SCK, I2S2_CK"),
]),
DatasheetPinDefPageParsingInfo([27], "GD32F103Zx", "LQFP144", [
ParseUsingAreaQuirk((88,123,769,527)),
]),
DatasheetPinDefPageParsingInfo([28], "GD32F103Zx", "LQFP144", [
ParseUsingAreaQuirk((88,123,650,527)),
]),
# GD32F103Vx
DatasheetPinDefPageParsingInfo([29], "GD32F103Vx", "LQFP100", [
ParseUsingAreaQuirk((133,123,769,527)),
]),
DatasheetPinDefPageParsingInfo([30], "GD32F103Vx", "LQFP100", [
ParseUsingAreaQuirk((88,123,769,527)),
]),
DatasheetPinDefPageParsingInfo([31], "GD32F103Vx", "LQFP100", [
ParseUsingAreaQuirk((88,123,769,527)),
OverwritePinDescriptionQuirk("PB13", "Default: PB13\nAlternate: SPI1_SCK, USART2_CTS, TIMER0_CH0_ON, I2S1_CK(4)"),
]),
DatasheetPinDefPageParsingInfo([32], "GD32F103Vx", "LQFP100", [
ParseUsingAreaQuirk((88,123,769,527)),
OverwritePinDescriptionQuirk("PC9", "Default: PB13\nAlternate: TIMER7_CH3(4), SDIO_D1(4)\nRemap: TIMER2_CH3"),
]),
DatasheetPinDefPageParsingInfo([33], "GD32F103Vx", "LQFP100", [
ParseUsingAreaQuirk((88,123,769,527)),
OverwritePinDescriptionQuirk("PD3", "Default: PD3\nAlternate: EXMC_CLK\nRemap: USART1_CTS"),
]),
# GD32F103Rx
DatasheetPinDefPageParsingInfo([36], "GD32F103Rx", "LQFP64", [
ParseUsingAreaQuirk((135,123,769,527)),
Expand All @@ -461,15 +509,31 @@
]),
DatasheetPinDefPageParsingInfo([38], "GD32F103Rx", "LQFP64", [
ParseUsingAreaQuirk((88,123,769,527)),
OverwritePinDescriptionQuirk("PC12", "Default: PC12\rAlternate: UART4_TX (4), SDIO_CK (4)\nRemap: USART2_CK (6), SPI2_MOSI (4), I2S2_SD (4)"),
OverwritePinDescriptionQuirk("PC12", "Default: PC12\rAlternate: UART4_TX(4), SDIO_CK(4)\nRemap: USART2_CK (6), SPI2_MOSI(4), I2S2_SD(4)"),
]),
DatasheetPinDefPageParsingInfo([39], "GD32F103Rx", "LQFP64", [
ParseUsingAreaQuirk((135,123,576,527)),
]),
]),
# GD32F103Cx
DatasheetPinDefPageParsingInfo([40], "GD32F103Cx", "LQFP48", [
ParseUsingAreaQuirk((135,123,769,527)),
OverwritePinDescriptionQuirk("PB1", "Default: PB1\rAlternate: ADC01_IN9, TIMER2_CH3\nRemap: TIMER0_CH2_ON"),
]),
DatasheetPinDefPageParsingInfo([41], "GD32F103Cx", "LQFP48", [
ParseUsingAreaQuirk((88,123,769,527)),
OverwritePinDescriptionQuirk("PB3", "Default: JTDO\rRemap: PB3, TRACESWO, TIMER1_CH1, SPI0_SCK"),
]),
DatasheetPinDefPageParsingInfo([42], "GD32F103Cx", "LQFP48", [
ParseUsingAreaQuirk((88,123,476,527)),
]),
],
series = "GD32F10x", # series
series = "GD32F10x",
family_name = "GD32F103xx",
family_type = "A" # family type
family_type = "A",
internal_adc = {
"ADC_TEMP": ("0", "16"), # (adc, channel)
"ADC_VREF": ("0", "17"),
}
),
}

Expand Down
5 changes: 3 additions & 2 deletions misc/scripts/gd32_genpinmap/parsing_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ def __init__(self, page_range: List[int], subseries:str, package:str, quirks:Lis
self.footnotes_device_availability = footnotes_device_availablity

class DatasheetParsingInfo:
def __init__(self, alternate_funcs: List[DatasheetAFPageParsingInfo], pin_defs: List[DatasheetPinDefPageParsingInfo], series:str, family_type:str, family_name:str=None) -> None:
def __init__(self, alternate_funcs: List[DatasheetAFPageParsingInfo], pin_defs: List[DatasheetPinDefPageParsingInfo], series:str, family_type:str, family_name:str=None, internal_adc:str=None) -> None:
self.alternate_funcs = alternate_funcs
self.pin_defs = pin_defs
self.series = series
self.family_type = family_type
self.family_name = family_name
self.family_name = family_name
self.internal_adc = internal_adc
3 changes: 2 additions & 1 deletion misc/scripts/gd32_genpinmap/pin_definitions.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from typing import Dict, List, Optional

class GD32PinFunction:
def __init__(self, signal_name: str, af_number: int, footnote: str, footnote_device_availability: Dict[str, List[str]], subseries: str = None, package: str = None, needs_remap: bool = False) -> None:
def __init__(self, signal_name: str, af_number: int, footnote: str, footnote_device_availability: Dict[str, List[str]], family_type: str, subseries: str = None, package: str = None, needs_remap: bool = False) -> None:
self.signal_name = signal_name
self.family_type = family_type
self.footnote = footnote
self.footnote_device_availability = footnote_device_availability
self.footnote_resolved = None
Expand Down
51 changes: 37 additions & 14 deletions misc/scripts/gd32_genpinmap/pinmap_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,22 @@ def add_dac_pin(pin: GD32Pin, func: GD32PinFunction) -> str:

@staticmethod
def add_i2c_pin(pin: GD32Pin, func: GD32PinFunction) -> str:
af_num = func.af_number or 0
return GD32PinMapGenerator.add_pin(
pin, func, "GD_PIN_FUNCTION4(PIN_MODE_AF, PIN_OTYPE_OD, PIN_PUPD_PULLUP, IND_GPIO_AF_%d)" % af_num, False)
if func.family_type is "B":
if func.has_af_number():
return GD32PinMapGenerator.add_pin(
pin, func, "GD_PIN_FUNCTION4(PIN_MODE_AF, PIN_OTYPE_OD, PIN_PUPD_PULLUP, IND_GPIO_AF_%d)" % func.af_number, False)
else:
raise Exception("Alternate function number must be provided to enable i2c AF on B family devices")
elif func.family_type is "A":
# There is no AF config beyond setting GPIOx_CFGn and enabling the peripheral
return GD32PinMapGenerator.add_pin(
pin, func, "GD_PIN_FUNCTION4(PIN_MODE_AF, PIN_OTYPE_OD, PIN_PUPD_PULLUP, 0)", False)
else:
raise Exception("Unknown family_type: %s" % func.family_type)

@staticmethod
def add_uart_pin(pin: GD32Pin, func: GD32PinFunction) -> str:
af_num = func.af_number or 0
af_num = func.af_number
if func.has_af_number():
return GD32PinMapGenerator.add_pin(
pin, func, "GD_PIN_FUNCTION4(PIN_MODE_AF, GPIO_OTYPE_PP, PIN_PUPD_PULLUP, IND_GPIO_AF_%d)" % af_num, False)
Expand Down Expand Up @@ -211,13 +220,19 @@ def add_pwm_pin(pin: GD32Pin, func: GD32PinFunction) -> str:
#print(sig_split)
#print(chan_num)
#print(af_num)
if func.has_af_number():
if func.family_type == "B":
if func.has_af_number():
return GD32PinMapGenerator.add_pin(
pin, func, "GD_PIN_FUNC_PWM(%d, IND_GPIO_AF_%d)" % (chan_num, af_num), False)
else:
raise Exception("Alternate function number must be provided to enable PWM AF on B family devices")
elif func.family_type == "A":
# Just use the same, but with no alternate function
return GD32PinMapGenerator.add_pin(
pin, func, "GD_PIN_FUNC_PWM(%d, IND_GPIO_AF_%d)" % (chan_num, af_num), False)
pin, func, "GD_PIN_FUNC_PWM(%d, 0)" % (chan_num), False)
else:
return GD32PinMapGenerator.add_pin(
pin, func, "GD_PIN_FUNC_PWM_2(%d)" % (chan_num), False)

raise Exception("Unknown family_type: %s" % func.family_type)

@staticmethod
def add_gpio_ports(pinmap:GD32PinMap, device_name:str) -> str:
temp = "const uint32_t gpio_port[] = {\n"
Expand Down Expand Up @@ -250,7 +265,10 @@ def add_all_gpio_pins() -> str:
@staticmethod
def generate_arduino_peripheralpins_c(pinmap:GD32PinMap, device_name:str) -> str:
output = gigadevice_header
output += spl_family_b_peripheral_pins_c_header
if pinmap.datasheet_info.family_type == "B":
output += spl_family_b_peripheral_pins_c_header
elif pinmap.datasheet_info.family_type == "A":
output += spl_family_a_peripheral_pins_c_header
# small correction for header: remove AF above 6
if device_name.lower().startswith("gd32e23"):
output = output.replace(" GPIO_AF_7, /* 7 */\n", "")
Expand All @@ -265,10 +283,15 @@ def generate_arduino_peripheralpins_c(pinmap:GD32PinMap, device_name:str) -> str
output += GD32PinMapGenerator.add_adc_pin(p, f)
# ToDo: The "ADC" might actaully be "ADC0" ("ADC1"?) for some chips.
# Channel 16 and 17 should be correct.
output += GD32PinMapGenerator.add_pin_text(
"ADC_TEMP", "ADC", "GD_PIN_FUNC_ANALOG_CH(16)", "ADC_IN16")
output += GD32PinMapGenerator.add_pin_text(
"ADC_VREF", "ADC", "GD_PIN_FUNC_ANALOG_CH(17)", "ADC_IN17")
if pinmap.datasheet_info.internal_adc != None:
for (adc_name, (adc, channel)) in pinmap.datasheet_info.internal_adc.items():
output += GD32PinMapGenerator.add_pin_text(
adc_name, "ADC%s" %(adc or ""), "GD_PIN_FUNC_ANALOG_CH(%s)" % channel, "ADC%s_IN%s" %(adc or "", channel))
else:
output += GD32PinMapGenerator.add_pin_text(
"ADC_TEMP", "ADC", "GD_PIN_FUNC_ANALOG_CH(16)", "ADC_IN16")
output += GD32PinMapGenerator.add_pin_text(
"ADC_VREF", "ADC", "GD_PIN_FUNC_ANALOG_CH(17)", "ADC_IN17")
output += GD32PinMapGenerator.end_pinmap()
# DAC
output += GD32PinMapGenerator.begin_pinmap("DAC")
Expand Down
Binary file not shown.
47 changes: 43 additions & 4 deletions misc/scripts/gd32_genpinmap/static_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
OF SUCH DAMAGE.
*/
"""

spl_family_b_peripheral_pins_c_header = """#include "PeripheralPins.h"
#include "gd32xxyy.h"
#include "PeripheralPins.h"
/* void pin_function(PinName pin, int function);
"""

spl_family_b_peripheral_pins_c_header = """/* void pin_function(PinName pin, int function);
configure the speed, mode,and remap function of pins
the parameter function contains the configuration information,show as below
bit 0:2 gpio mode
Expand Down Expand Up @@ -100,6 +100,45 @@
"""

# Reference wiring_digital.c to see which of the GD32PinMode enums are used
spl_family_a_peripheral_pins_c_header = """/* void pin_function(PinName pin, int function);
configure the speed, mode,and remap function of pins
the parameter function contains the configuration information,show as below
bit 0:2 gpio mode
bit 3:8 remap
bit 9:10 gpio speed
bit 11:15 adc /timer channel
*/
/* pin descriptions only reference the index in the array, so
* to get e.g. AF11 one must give it index = 9. provide
* convenience macros here.
* for all other arrays, the value is also equivalent to the index,
* so there doesn't need to be anything done more.
*/
/* GPIO MODE */
const int GD_GPIO_MODE[] = {
GPIO_MODE_AIN, /* 0 INPUT_ANALOG */
GPIO_MODE_IN_FLOATING, /* 1 INPUT */
GPIO_MODE_IPD, /* 2 INPUT_PULLDOWN */
GPIO_MODE_IPU, /* 3 INPUT_PULLUP */
GPIO_MODE_OUT_OD, /* 4 OUTPUT_OPEN_DRAIN */
GPIO_MODE_OUT_PP, /* 5 OUTPUT */
0, /* 6 (unused) */
0, /* 7 (unused) */
};
/* GPIO SPEED */
const int GD_GPIO_SPEED[] = {
GPIO_OSPEED_2MHZ, /* 0 */
GPIO_OSPEED_10MHZ, /* 1 */
0, /* 2 (unused) */
GPIO_OSPEED_50MHZ, /* 3 */
};
"""

community_copyright_header = """/*
Copyright (c) 2021, CommunityGD32Cores
Expand Down

0 comments on commit 32e40a2

Please sign in to comment.