#!/usr/bin/env python ''' extra DMA mapping tables from a stm32 datasheet This assumes a csv file extracted from the datasheet using tablula: https://github.com/tabulapdf/tabula ''' import sys, csv, os def parse_dma_table(fname, table): dma_num = 1 csvt = csv.reader(open(fname,'rb')) i = 0 last_channel = -1 for row in csvt: if len(row) > 1 and row[1].startswith('Channel '): row = row[1:] if not row[0].startswith('Channel '): continue channel = int(row[0].split(' ')[1]) if channel < last_channel: dma_num += 1 last_channel = channel for stream in range(8): s = row[stream+1] s = s.replace('_\r', '_') s = s.replace('\r_', '_') if s == '-': continue keys = s.split() for k in keys: brace = k.find('(') if brace != -1: k = k[:brace] if k not in table: table[k] = [] table[k] += [(dma_num, stream, channel)] def error(str): '''show an error and exit''' print("Error: " + str) sys.exit(1) def check_full_table(table): '''check the table is not missing rows or columns we should have at least one entry in every row and one entry in every colum of each dma table ''' stream_mask = [0,0] channel_mask = [0,0] for k in table: for v in table[k]: (engine,stream,channel) = v if engine > 2 or engine < 1: error("Bad entry for %s: %s" % (k, v)) stream_mask[engine-1] |= 1<