1
1
#!/usr/bin/env python
2
- """Creates the pin file for the STM32F4xx."""
2
+
3
+ """
4
+ Generates pin source files based on an MCU alternate-function definition (eg
5
+ stm32f405_af.csv) and a board-specific pin definition file, pins.csv.
6
+
7
+ The pins.csv file must contain lines of the form:
8
+
9
+ board,cpu
10
+
11
+ Where "board" is the user-facing name of the pin as specified by the particular
12
+ board layout and markings, and "cpu" is the corresponding name of the CPU/MCU
13
+ pin.
14
+
15
+ The "board" entry may be absent if the CPU pin has no additional name, and both
16
+ entries may start with "-" to hide them from the corresponding Python dict of
17
+ pins, and hence hide them from the user (but they are still accessible in C).
18
+
19
+ For example, take the following pins.csv file:
20
+
21
+ X1,PA0
22
+ -X2,PA1
23
+ X3,-PA2
24
+ -X4,-PA3
25
+ ,PA4
26
+ ,-PA5
27
+
28
+ The first row here configures:
29
+ - The CPU pin PA0 is labelled X1.
30
+ - The Python user can access both by the names Pin("X1") and Pin("A0").
31
+ - The Python user can access both by the members Pin.board.X1 and Pin.cpu.A0.
32
+ - In C code they are available as pyb_pin_X1 and pin_A0.
33
+
34
+ Prefixing the names with "-" hides them from the user. The following table
35
+ summarises the various possibilities:
36
+
37
+ pins.csv entry | board name | cpu name | C board name | C cpu name
38
+ ---------------+------------+----------+--------------+-----------
39
+ X1,PA0 "X1" "A0" pyb_pin_X1 pin_A0
40
+ -X2,PA1 - "A1" pyb_pin_X2 pin_A1
41
+ X3,-PA2 "X3" - pyb_pin_X3 pin_A2
42
+ -X4,-PA3 - - pyb_pin_X4 pin_A3
43
+ ,PA4 - "A4" - pin_A4
44
+ ,-PA5 - - - pin_A5
45
+
46
+ """
3
47
4
48
from __future__ import print_function
5
49
@@ -273,6 +317,9 @@ def __init__(self, name, pin):
273
317
self ._name = name
274
318
self ._pin = pin
275
319
320
+ def set_hidden (self , value ):
321
+ self ._is_hidden = value
322
+
276
323
def is_hidden (self ):
277
324
return self ._is_hidden
278
325
@@ -293,7 +340,7 @@ def find_pin(self, port_num, pin_num):
293
340
for named_pin in self .cpu_pins :
294
341
pin = named_pin .pin ()
295
342
if pin .port == port_num and pin .pin == pin_num :
296
- return pin
343
+ return named_pin
297
344
298
345
def parse_af_file (self , filename , pinname_col , af_col ):
299
346
with open (filename , "r" ) as csvfile :
@@ -315,12 +362,19 @@ def parse_board_file(self, filename):
315
362
with open (filename , "r" ) as csvfile :
316
363
rows = csv .reader (csvfile )
317
364
for row in rows :
365
+ cpu_pin_name = row [1 ]
366
+ cpu_pin_hidden = False
367
+ if cpu_pin_name .startswith ("-" ):
368
+ cpu_pin_name = cpu_pin_name [1 :]
369
+ cpu_pin_hidden = True
318
370
try :
319
- (port_num , pin_num ) = parse_port_pin (row [ 1 ] )
371
+ (port_num , pin_num ) = parse_port_pin (cpu_pin_name )
320
372
except :
321
373
continue
322
- pin = self .find_pin (port_num , pin_num )
323
- if pin :
374
+ named_pin = self .find_pin (port_num , pin_num )
375
+ if named_pin :
376
+ named_pin .set_hidden (cpu_pin_hidden )
377
+ pin = named_pin .pin ()
324
378
pin .set_is_board_pin ()
325
379
if row [0 ]: # Only add board pins that have a name
326
380
self .board_pins .append (NamedPin (row [0 ], pin ))
0 commit comments