Created
October 31, 2021 13:13
-
-
Save chris-durand/69741d902a44424b080f58888ae57fce to your computer and use it in GitHub Desktop.
Test script to extract dmamux request mappings from CubeHal headers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
_dmamux_pattern = re.compile("^\s*#define\s+(?P<name>(LL_DMAMUX_REQ_\w+))\s+(?P<id>(0x[0-9A-Fa-f]+))U") | |
_request_pattern = re.compile("^\s*#define\s+(?P<name>(DMA_REQUEST_\w+))\s+(?P<id>([0-9]+))U") | |
def _read_map(filename, pattern): | |
out_map = {} | |
with open(filename, "r") as header_file: | |
for line in header_file.readlines(): | |
m = pattern.match(line) | |
if m: | |
name = m.group("name") | |
if name in out_map: | |
raise RuntimeError("Duplicate entry {}".format(name)) | |
out_map[name] = m.group("id") | |
return out_map | |
def read_requests_map_l4(read_for_p5_q5): | |
out_map = {} | |
p5_q5_if = "#if defined (STM32L4P5xx) || defined (STM32L4Q5xx)" | |
if_pattern = re.compile(r"^\s*#\s*if\s+") | |
else_pattern = re.compile(r"^\s*#\s*else") | |
endif_pattern = re.compile(r"^\s*#\s*endif") | |
in_p5_q5_section = False | |
ignore = False | |
with open("stm32l4xx_hal_dma.h", "r") as header_file: | |
if_counter = 0 | |
for line in header_file.readlines(): | |
if p5_q5_if in line: | |
in_p5_q5_section = True | |
ignore = not read_for_p5_q5 | |
elif in_p5_q5_section: | |
if if_pattern.match(line): | |
if_counter += 1 | |
elif endif_pattern.match(line): | |
if_counter -= 1 | |
elif else_pattern.match(line) and if_counter == 0: | |
p5_q5_section = False | |
ignore = read_for_p5_q5 | |
if not ignore: | |
m = _request_pattern.match(line) | |
if m: | |
name = m.group("name") | |
if name in out_map: | |
raise RuntimeError("Duplicate entry {}".format(name)) | |
out_map[name] = int(m.group("id")) | |
return out_map | |
# For G0 and WB | |
def read_requests_map_from_ll_dmamux(ll_dmamux_file, hal_dma_file): | |
dmamux_map = _read_map(ll_dmamux_file, _dmamux_pattern) | |
request_pattern = re.compile("^\s*#define\s+(?P<name>(DMA_REQUEST_\w+))\s+(?P<id>(LL_DMAMUX?_REQ_\w+))\s*") | |
requests_map = _read_map(hal_dma_file, request_pattern) | |
id_map = {} | |
for r in requests_map.keys(): | |
id_map[r] = int(dmamux_map[requests_map[r]], 16) | |
return id_map | |
# For H7 | |
def read_requests_map(hal_dma_file): | |
requests_map = _read_map(hal_dma_file, _request_pattern) | |
for r in requests_map.keys(): | |
requests_map[r] = int(requests_map[r]) | |
return requests_map | |
print("STM32WB:") | |
print(read_requests_map_from_ll_dmamux("stm32wbxx_ll_dmamux.h", "stm32wbxx_hal_dma.h"), "\n") | |
print("STM32G0:") | |
print(read_requests_map_from_ll_dmamux("stm32g0xx_ll_dmamux.h", "stm32g0xx_hal_dma.h"), "\n") | |
print("STM32L4 without L4P5xx, L4Q5xx:") | |
print(read_requests_map_l4(False), "\n") | |
print("STM32L4P5xx, STML4Q5xx:") | |
print(read_requests_map_l4(True), "\n") | |
print("STM32H7:") | |
print(read_requests_map("stm32h7xx_hal_dma.h")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment