11"""
22Generate STM32 microcontroller symbols, components and devices.
33
4- Data source: https://github.com/LibrePCB/stm-pinout
4+ Data source: https://github.com/LibrePCB/stm-db
55
66In order to reduce the number of symbols, the following items are reused:
77
@@ -212,7 +212,10 @@ def __init__(self, ref: str, info: Dict[str, Any], pins: Iterable[Pin]):
212212 self .family = info ['names' ]['family' ]
213213 self .package = info ['package' ]
214214 self .pins = list (pins )
215- self .flash = '{} KiB' .format (info ['info' ]['flash' ])
215+ if 'flash' in info ['info' ]:
216+ self .flash = '{} KiB' .format (info ['info' ]['flash' ])
217+ else :
218+ self .flash = None
216219 self .ram = '{} KiB' .format (info ['info' ]['ram' ])
217220 self .io_count : int = info ['info' ]['io' ]
218221 self .gpio_version = info ['gpio_version' ] if len (info ['gpio_version' ]) else None
@@ -252,6 +255,22 @@ def _cleanup_pin_name(pin_name: str) -> str:
252255 val = re .sub (r'\s*-\s*OSC' , r'-OSC' , val )
253256 val = re .sub (r'\s*/\s*OSC' , r'-OSC' , val )
254257 val = re .sub (r'([0-9])OSC' , r'\1-OSC' , val )
258+ val = re .sub (r'-(OSC(X|32)?_(IN|OUT))\([A-Z0-9_]+\)' , r'-\1' , val )
259+
260+ if 'NRST' in pin_name :
261+ val = re .sub (r'NRST\((P[A-Z][0-9]+)\)' , r'NRST/\1' , val )
262+
263+ # Ad-hoc cleanup
264+ if '(JTMS/SWDIO)' in pin_name :
265+ val = val .replace ('(JTMS/SWDIO)' , '' )
266+ if '(JTCK/SWCLK)' in pin_name :
267+ val = val .replace ('(JTCK/SWCLK)' , '' )
268+ if '(JTDI)' in pin_name :
269+ val = val .replace ('(JTDI)' , '' )
270+ if '(JTDO/TRACESWO)' in pin_name :
271+ val = val .replace ('(JTDO/TRACESWO)' , '' )
272+ if '(NJTRST)' in pin_name :
273+ val = val .replace ('(NJTRST)' , '' )
255274
256275 # Remove everything after the first space
257276 val = val .split (' ' )[0 ]
@@ -286,9 +305,10 @@ def from_json(cls, ref: str, info: Dict[str, Any]) -> 'MCU':
286305 # Ensure that all merged signals have the same pin type
287306 types = {pin .pin_type for pin in group }
288307 if 'MonoIO' in types and 'IO' in types :
289- # Merge MonoIO into IO
308+ # Merge ' MonoIO' into 'IO'
290309 types .remove ('MonoIO' )
291- types .add ('IO' )
310+ if 'Reset' in types and 'IO' in types :
311+ types .remove ('IO' )
292312 assert len (types ) == 1 , (types , info )
293313
294314 # Update the first pin
@@ -341,6 +361,8 @@ def flash_size_offset(ref: str) -> Optional[int]:
341361 # finding the flash size in the ref name, so don't handle them for now.
342362 if ref .startswith ('STM32MP' ):
343363 return None # No flash
364+ elif ref .startswith ('STM32WBA' ):
365+ return 11
344366 elif ref .startswith ('STM32' ):
345367 return 10
346368 else :
@@ -366,6 +388,7 @@ def ref_without_flash(self) -> str:
366388 # Sanity check for the flash size
367389 size = self .ref [offset ]
368390 flash_sizes = {
391+ '0' : 1 ,
369392 '2' : 4 ,
370393 '3' : 8 ,
371394 '4' : 16 ,
@@ -381,6 +404,9 @@ def ref_without_flash(self) -> str:
381404 'G' : 1024 ,
382405 'H' : 1536 ,
383406 'I' : 2048 ,
407+ 'J' : 4096 ,
408+ 'K' : 3072 ,
409+ 'Y' : 640 ,
384410 }
385411 assert size in flash_sizes , "{}: Flash size {} doesn't look valid" .format (self .ref , size )
386412
@@ -477,13 +503,12 @@ def component_description(self) -> str:
477503 @property
478504 def description (self ) -> str :
479505 description = 'A {} MCU by ST Microelectronics.\n \n ' .format (self .name )
480- description += 'Package: {}\n Flash: {}\n RAM: {}\n I/Os: {}\n Frequency: {}\n ' .format (
481- self .package ,
482- self .flash ,
483- self .ram ,
484- self .io_count ,
485- self .frequency ,
486- )
506+ description += 'Package: {}\n ' .format (self .package )
507+ if self .flash :
508+ description += 'Flash: {}\n ' .format (self .flash )
509+ description += 'RAM: {}\n ' .format (self .ram )
510+ description += 'I/Os: {}\n ' .format (self .io_count )
511+ description += 'Frequency: {}\n ' .format (self .frequency )
487512 if self .voltage :
488513 description += 'Voltage: {}\n ' .format (self .voltage )
489514 if self .temperature :
0 commit comments