KiCad PCB EDA Suite
Loading...
Searching...
No Matches
drc_test_provider_via_stack.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#include <cstdlib>
21#include <map>
22#include <set>
23#include <vector>
24
25#include <board.h>
27#include <footprint.h>
28#include <layer_range.h>
29#include <pad.h>
30#include <padstack.h>
31#include <pcb_generator.h>
32#include <pcb_track.h>
34#include <drc/drc_engine.h>
35#include <drc/drc_item.h>
39
40/*
41 Microvia stack topology tests.
42
43 Errors generated:
44 - DRCE_MALFORMED_MICROVIA_STACK_SPAN
45 - DRCE_MICROVIA_STACK_NOT_FILLED
46 - DRCE_MICROVIA_STACK_DEPTH
47 - DRCE_HOLE_ASPECT_RATIO
48 - DRCE_MICROVIA_CROSSES_CORE
49 - DRCE_MICROVIA_SPANS_DIELECTRICS
50
51 The span test asks whether a generator's hops still tile the span it declares. Nothing
52 rebuilds a stack on load, so a file can carry one that does not. The others ask whether
53 the copper can be built. The aspect ratio test applies to every plated hole, the rest
54 to every microvia however it was placed.
55
56 Where these rules come from:
57
58 IPC-2226 defines a microvia as a hole of aspect ratio 1:1 or better, no deeper than 0.25 mm.
59 That is why a hop spans one dielectric and why deeper structures are built by stacking.
60
61 IPC-4761 names the via protection types. A filled via is Type V and a filled and capped via is
62 Type VII, which is the via in pad treatment used for BGA fanout.
63
64 IPC-6012 carries the reliability requirements for microvias, including the thermal cycling a
65 stacked structure has to survive. Unfilled stacked microvias separate at the target pad.
66
67 Maximum stack depth is deliberately not standardised. It is a fabricator capability, so it is a
68 board setting rather than a fixed number here.
69*/
70
72{
73public:
75
76 virtual ~DRC_TEST_PROVIDER_VIA_STACK() = default;
77
78 virtual bool Run() override;
79
80 virtual const wxString GetName() const override { return wxT( "microvia_stack" ); };
81
82private:
83 void checkSpan( PCB_VIA_STACK* aStack, int aCopperLayers );
84 void checkColumn( const std::vector<PCB_VIA*>& aColumn );
85 void checkLooseMicrovias( BOARD* aBoard );
86 void checkConstructability( BOARD* aBoard );
87};
88
89
90void DRC_TEST_PROVIDER_VIA_STACK::checkSpan( PCB_VIA_STACK* aStack, int aCopperLayers )
91{
92 std::vector<PCB_VIA*> vias;
93
94 for( BOARD_ITEM* item : aStack->GetBoardItems() )
95 {
96 if( item->Type() == PCB_VIA_T )
97 {
98 PCB_VIA* via = static_cast<PCB_VIA*>( item );
99
100 if( via->GetViaType() == VIATYPE::MICROVIA )
101 vias.push_back( via );
102 }
103 }
104
105 if( vias.empty() )
106 return;
107
108 // IPC-2226 confines a microvia to one dielectric, so the hops must tile the declared span
109 // with single layer steps and no gap. A span naming layers absent from the board is broken
110 // by definition, and iterating it would never terminate.
111 if( !m_drcEngine->IsErrorLimitExceeded( DRCE_MALFORMED_MICROVIA_STACK_SPAN ) )
112 {
113 if( !PCB_VIA_STACK::IsSpanValid( m_drcEngine->GetBoard(), aStack->GetStartLayer(), aStack->GetEndLayer() ) )
114 {
115 std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_MALFORMED_MICROVIA_STACK_SPAN );
116 drcItem->SetItems( aStack );
117 reportViolation( drcItem, aStack->GetPosition(), aStack->GetLayer() );
118 return;
119 }
120
121 std::map<int, int> layerToIndex;
122 int spanLen = 0;
123
124 for( PCB_LAYER_ID layer : LAYER_RANGE( aStack->GetStartLayer(), aStack->GetEndLayer(), aCopperLayers ) )
125 layerToIndex[layer] = spanLen++;
126
127 std::set<int> covered;
128 bool broken = false;
129
130 for( PCB_VIA* via : vias )
131 {
132 auto top = layerToIndex.find( via->TopLayer() );
133 auto bot = layerToIndex.find( via->BottomLayer() );
134
135 if( top == layerToIndex.end() || bot == layerToIndex.end() || std::abs( top->second - bot->second ) != 1 )
136 {
137 broken = true;
138 break;
139 }
140
141 if( !covered.insert( std::min( top->second, bot->second ) ).second )
142 {
143 broken = true;
144 break;
145 }
146 }
147
148 if( broken || (int) covered.size() != spanLen - 1 )
149 {
150 std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_MALFORMED_MICROVIA_STACK_SPAN );
151 drcItem->SetItems( aStack );
152 reportViolation( drcItem, aStack->GetPosition(), aStack->GetLayer() );
153 }
154 }
155}
156
157
158// Depth and fill are properties of the copper, not of the object that placed it.
159void DRC_TEST_PROVIDER_VIA_STACK::checkColumn( const std::vector<PCB_VIA*>& aColumn )
160{
161 // Not standardised. A fabricator quotes its own limit, and a designer may accept a deeper
162 // stack in one area than another, so the limit is resolved per via rather than read once.
163 PCB_VIA* top = aColumn.front();
164 DRC_CONSTRAINT depthConstraint =
165 m_drcEngine->EvalRules( MICROVIA_STACK_DEPTH_CONSTRAINT, top, nullptr, top->GetLayer() );
166
167 if( depthConstraint.GetSeverity() != RPT_SEVERITY_IGNORE && depthConstraint.GetValue().HasMax()
168 && (int) aColumn.size() > depthConstraint.GetValue().Max()
169 && !m_drcEngine->IsErrorLimitExceeded( DRCE_MICROVIA_STACK_DEPTH ) )
170 {
171 std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_MICROVIA_STACK_DEPTH );
172 drcItem->SetErrorMessage( wxString::Format( _( "Stack is %d hops deep, limit is %d" ), (int) aColumn.size(),
173 depthConstraint.GetValue().Max() ) );
174 drcItem->SetItems( top );
175 drcItem->SetViolatingRule( depthConstraint.GetParentRule() );
176 reportViolation( drcItem, top->GetPosition(), top->GetLayer() );
177 }
178
179 if( m_drcEngine->IsErrorLimitExceeded( DRCE_MICROVIA_STACK_NOT_FILLED ) )
180 return;
181
182 // IPC-6012 requires the hops of a stacked microvia to be filled. An unfilled hop is a dimple,
183 // and the joint separates under thermal cycling.
184 // An unset fill takes the board default.
185 bool boardFillsVias = m_drcEngine->GetBoard()->GetDesignSettings().m_FillVias;
186
187 for( PCB_VIA* via : aColumn )
188 {
189 if( !via->Padstack().Drill().is_filled.value_or( boardFillsVias ) )
190 {
191 std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_MICROVIA_STACK_NOT_FILLED );
192 drcItem->SetItems( via );
193 reportViolation( drcItem, via->GetPosition(), via->GetLayer() );
194 }
195 }
196}
197
198
200{
201 std::vector<std::vector<PCB_VIA*>> columns = PCB_VIA::CollectMicroviaColumns( aBoard );
202
203 const int progressDelta = 250;
204 int ii = 0;
205
206 for( const std::vector<PCB_VIA*>& column : columns )
207 {
208 if( !reportProgress( ii++, columns.size(), progressDelta ) )
209 return;
210
211 checkColumn( column );
212 }
213}
214
215
216// Copper and dielectric only, so soldermask does not count.
217static int stackThickness( const std::vector<BOARD_STACKUP_ITEM*>& aStack, int aFirst, int aLast )
218{
219 int thickness = 0;
220
221 for( int i = aFirst; i < aLast; ++i )
222 {
223 const BOARD_STACKUP_ITEM* item = aStack[i];
224
225 if( !item->IsEnabled() )
226 continue;
227
228 if( item->GetType() == BS_ITEM_TYPE_DIELECTRIC )
229 {
230 for( int sub = 0; sub < item->GetSublayersCount(); ++sub )
231 thickness += item->GetThickness( sub );
232 }
233 else if( item->GetType() == BS_ITEM_TYPE_COPPER )
234 {
235 thickness += item->GetThickness();
236 }
237 }
238
239 return thickness;
240}
241
242
244{
245 bool checkRatio = !m_drcEngine->IsErrorLimitExceeded( DRCE_HOLE_ASPECT_RATIO )
246 && m_drcEngine->HasRulesForConstraintType( HOLE_ASPECT_RATIO_CONSTRAINT );
247 bool checkCore = !m_drcEngine->IsErrorLimitExceeded( DRCE_MICROVIA_CROSSES_CORE );
248 bool checkDielectrics = !m_drcEngine->IsErrorLimitExceeded( DRCE_MICROVIA_SPANS_DIELECTRICS );
249
250 if( !checkRatio && !checkCore && !checkDielectrics )
251 return;
252
253 BOARD_STACKUP stackup = aBoard->GetStackupOrDefault();
254 const std::vector<BOARD_STACKUP_ITEM*>& stack = stackup.GetList();
255
256 const int progressDelta = 500;
257 int ii = 0;
258
259 for( PCB_TRACK* track : aBoard->Tracks() )
260 {
261 if( !reportProgress( ii++, aBoard->Tracks().size(), progressDelta ) )
262 return;
263
264 if( track->Type() != PCB_VIA_T )
265 continue;
266
267 PCB_VIA* via = static_cast<PCB_VIA*>( track );
268
269 int first = -1;
270 int last = -1;
271
272 for( int i = 0; i < (int) stack.size(); ++i )
273 {
274 if( stack[i]->GetType() != BS_ITEM_TYPE_COPPER )
275 continue;
276
277 PCB_LAYER_ID layer = stack[i]->GetBrdLayerId();
278
279 if( layer == via->TopLayer() || layer == via->BottomLayer() )
280 {
281 if( first < 0 )
282 first = i;
283 else
284 last = i;
285 }
286 }
287
288 if( first < 0 || last < 0 )
289 continue;
290
291 // IPC-2226 builds microvias in the layers laminated onto the core, not through it.
292 // Laser drilling relies on the resin ablating, and core is glass reinforced.
293 if( via->GetViaType() == VIATYPE::MICROVIA && checkCore )
294 {
295 for( int i = first + 1; i < last; ++i )
296 {
297 if( stack[i]->IsEnabled() && stack[i]->GetType() == BS_ITEM_TYPE_DIELECTRIC
298 && stack[i]->GetTypeName() == KEY_CORE )
299 {
300 std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_MICROVIA_CROSSES_CORE );
301
302 drcItem->SetErrorMessage(
303 wxString::Format( _( "The stackup gives the dielectric between %s and %s as core" ),
304 LSET::Name( via->TopLayer() ), LSET::Name( via->BottomLayer() ) ) );
305 drcItem->SetItems( via );
306 reportViolation( drcItem, via->GetPosition(), via->GetLayer() );
307 break;
308 }
309 }
310 }
311
312 // A hop spans one dielectric, the laser stops at the copper it lands on. Sublayers are
313 // one lamination, so they count once.
314 if( via->GetViaType() == VIATYPE::MICROVIA && checkDielectrics )
315 {
316 int dielectrics = 0;
317
318 for( int i = first + 1; i < last; ++i )
319 {
320 if( stack[i]->IsEnabled() && stack[i]->GetType() == BS_ITEM_TYPE_DIELECTRIC )
321 dielectrics++;
322 }
323
324 if( dielectrics > 1 )
325 {
326 std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_MICROVIA_SPANS_DIELECTRICS );
327
328 drcItem->SetErrorMessage( wxString::Format( _( "The stackup gives %d dielectrics between %s and %s" ),
329 dielectrics, LSET::Name( via->TopLayer() ),
330 LSET::Name( via->BottomLayer() ) ) );
331 drcItem->SetItems( via );
332 reportViolation( drcItem, via->GetPosition(), via->GetLayer() );
333 }
334 }
335
336 if( !checkRatio || via->GetDrillValue() <= 0 )
337 continue;
338
339 DRC_CONSTRAINT ratioConstraint = m_drcEngine->EvalRules( HOLE_ASPECT_RATIO_CONSTRAINT, via, nullptr,
340 UNDEFINED_LAYER /* holes are not layer-specific */ );
341
342 if( ratioConstraint.GetSeverity() == RPT_SEVERITY_IGNORE || !ratioConstraint.GetValue().HasMax() )
343 continue;
344
345 // Ratios are parsed to three decimals, so the stored maximum is scaled by 1000.
346 double limit = ratioConstraint.GetValue().Max() / 1000.0;
347
348 if( limit <= 0.0 )
349 continue;
350
351 bool topExternal = IsExternalCopperLayer( stack[first]->GetBrdLayerId() );
352 bool botExternal = IsExternalCopperLayer( stack[last]->GetBrdLayerId() );
353 bool fromBack = botExternal && !topExternal;
354
355 int thickness = stackThickness( stack, first + 1, last ) + stack[fromBack ? last : first]->GetThickness();
356
357 // The laser stops on the foil it lands on, and so does a blind drill. Any other drill
358 // leaves through the far foil.
359 if( via->GetViaType() != VIATYPE::MICROVIA && topExternal == botExternal )
360 thickness += stack[fromBack ? first : last]->GetThickness();
361
362 double ratio = (double) thickness / (double) via->GetDrillValue();
363
364 if( ratio <= limit )
365 continue;
366
367 if( m_drcEngine->IsErrorLimitExceeded( DRCE_HOLE_ASPECT_RATIO ) )
368 {
369 if( !checkCore )
370 return;
371
372 checkRatio = false;
373 continue;
374 }
375
376 std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_HOLE_ASPECT_RATIO );
377
378 drcItem->SetErrorMessage( wxString::Format( _( "Aspect ratio %.2f exceeds the %.2f limit" ), ratio, limit ) );
379
380 drcItem->SetItems( via );
381 drcItem->SetViolatingRule( ratioConstraint.GetParentRule() );
382 reportViolation( drcItem, via->GetPosition(), via->GetLayer() );
383 }
384
385 if( !checkRatio || m_drcEngine->IsCancelled() )
386 return;
387
388 int boardDepth = stackThickness( stack, 0, (int) stack.size() );
389
390 ii = 0;
391
392 for( FOOTPRINT* footprint : aBoard->Footprints() )
393 {
394 if( !reportProgress( ii++, aBoard->Footprints().size(), progressDelta ) )
395 return;
396
397 for( PAD* pad : footprint->Pads() )
398 {
399 if( m_drcEngine->IsErrorLimitExceeded( DRCE_HOLE_ASPECT_RATIO ) )
400 return;
401
402 if( pad->GetAttribute() != PAD_ATTRIB::PTH )
403 continue;
404
405 // The chemistry sees the narrow dimension of a slot.
406 int drill = std::min( pad->GetDrillSize().x, pad->GetDrillSize().y );
407
408 if( drill <= 0 )
409 continue;
410
411 DRC_CONSTRAINT ratioConstraint = m_drcEngine->EvalRules(
412 HOLE_ASPECT_RATIO_CONSTRAINT, pad, nullptr, UNDEFINED_LAYER /* holes are not layer-specific */ );
413
414 if( ratioConstraint.GetSeverity() == RPT_SEVERITY_IGNORE || !ratioConstraint.GetValue().HasMax() )
415 continue;
416
417 double limit = ratioConstraint.GetValue().Max() / 1000.0;
418
419 if( limit <= 0.0 )
420 continue;
421
422 double ratio = (double) boardDepth / (double) drill;
423
424 if( ratio <= limit )
425 continue;
426
427 std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_HOLE_ASPECT_RATIO );
428
429 drcItem->SetErrorMessage(
430 wxString::Format( _( "Aspect ratio %.2f exceeds the %.2f limit" ), ratio, limit ) );
431
432 drcItem->SetItems( pad );
433 drcItem->SetViolatingRule( ratioConstraint.GetParentRule() );
434 reportViolation( drcItem, pad->GetPosition(), pad->GetLayer() );
435 }
436 }
437}
438
439
441{
442 if( m_drcEngine->IsErrorLimitExceeded( DRCE_MALFORMED_MICROVIA_STACK_SPAN )
443 && m_drcEngine->IsErrorLimitExceeded( DRCE_MICROVIA_STACK_NOT_FILLED )
444 && m_drcEngine->IsErrorLimitExceeded( DRCE_MICROVIA_STACK_DEPTH )
445 && m_drcEngine->IsErrorLimitExceeded( DRCE_HOLE_ASPECT_RATIO )
446 && m_drcEngine->IsErrorLimitExceeded( DRCE_MICROVIA_CROSSES_CORE )
447 && m_drcEngine->IsErrorLimitExceeded( DRCE_MICROVIA_SPANS_DIELECTRICS ) )
448 {
449 return true;
450 }
451
452 if( !reportPhase( _( "Checking hole aspect ratios and microvia stacks..." ) ) )
453 return false;
454
455 BOARD* board = m_drcEngine->GetBoard();
456 int copperLayers = board->GetCopperLayerCount();
457
458 if( !m_drcEngine->IsErrorLimitExceeded( DRCE_MALFORMED_MICROVIA_STACK_SPAN ) )
459 {
460 for( PCB_GENERATOR* gen : board->Generators() )
461 {
462 if( m_drcEngine->IsCancelled() )
463 break;
464
465 if( PCB_VIA_STACK* stack = dynamic_cast<PCB_VIA_STACK*>( gen ) )
466 checkSpan( stack, copperLayers );
467 }
468 }
469
470 if( !m_drcEngine->IsCancelled()
471 && !( m_drcEngine->IsErrorLimitExceeded( DRCE_MICROVIA_STACK_NOT_FILLED )
472 && m_drcEngine->IsErrorLimitExceeded( DRCE_MICROVIA_STACK_DEPTH ) ) )
473 {
474 checkLooseMicrovias( board );
475 }
476
477 if( !m_drcEngine->IsCancelled()
478 && !( m_drcEngine->IsErrorLimitExceeded( DRCE_HOLE_ASPECT_RATIO )
479 && m_drcEngine->IsErrorLimitExceeded( DRCE_MICROVIA_CROSSES_CORE )
480 && m_drcEngine->IsErrorLimitExceeded( DRCE_MICROVIA_SPANS_DIELECTRICS ) ) )
481 {
482 checkConstructability( board );
483 }
484
485 return !m_drcEngine->IsCancelled();
486}
487
488
489namespace detail
490{
492}
@ BS_ITEM_TYPE_COPPER
@ BS_ITEM_TYPE_DIELECTRIC
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:99
Manage one layer needed to make a physical board.
int GetSublayersCount() const
int GetThickness(int aDielectricSubLayer=0) const
bool IsEnabled() const
BOARD_STACKUP_ITEM_TYPE GetType() const
Manage layers needed to make a physical board.
const std::vector< BOARD_STACKUP_ITEM * > & GetList() const
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
BOARD_STACKUP GetStackupOrDefault() const
Definition board.cpp:3506
const GENERATORS & Generators() const
Definition board.h:485
int GetCopperLayerCount() const
Definition board.cpp:1155
const FOOTPRINTS & Footprints() const
Definition board.h:465
const TRACKS & Tracks() const
Definition board.h:463
SEVERITY GetSeverity() const
Definition drc_rule.h:181
const MINOPTMAX< int > & GetValue() const
Definition drc_rule.h:129
DRC_RULE * GetParentRule() const
Definition drc_rule.h:147
static std::shared_ptr< DRC_ITEM > Create(int aErrorCode)
Constructs a DRC_ITEM for the given error code.
Definition drc_item.cpp:505
virtual const wxString GetName() const override
virtual ~DRC_TEST_PROVIDER_VIA_STACK()=default
virtual bool Run() override
Run this provider against the given PCB with configured options (if any).
void checkColumn(const std::vector< PCB_VIA * > &aColumn)
void checkSpan(PCB_VIA_STACK *aStack, int aCopperLayers)
virtual bool reportPhase(const wxString &aStageName)
void reportViolation(std::shared_ptr< DRC_ITEM > &item, const VECTOR2I &aMarkerPos, int aMarkerLayer, const std::function< void(PCB_MARKER *)> &aPathGenerator=[](PCB_MARKER *){})
virtual bool reportProgress(size_t aCount, size_t aSize, size_t aDelta=1)
static wxString Name(PCB_LAYER_ID aLayerId)
Return the fixed name association with aLayerId.
Definition lset.cpp:184
bool HasMax() const
Definition minoptmax.h:38
T Max() const
Definition minoptmax.h:30
Definition pad.h:61
PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
VECTOR2I GetPosition() const override
std::unordered_set< BOARD_ITEM * > GetBoardItems() const
A microvia stack: several single hop microvias, plus connecting traces for staggered stacks,...
PCB_LAYER_ID GetStartLayer() const
PCB_LAYER_ID GetEndLayer() const
static bool IsSpanValid(BOARD *aBoard, PCB_LAYER_ID aStart, PCB_LAYER_ID aEnd)
True when both span ends are copper layers within the board's copper layer count.
static std::vector< std::vector< PCB_VIA * > > CollectMicroviaColumns(BOARD *aBoard)
Runs of microvias that land on one another, each ordered from its outermost hop down.
@ HOLE_ASPECT_RATIO_CONSTRAINT
@ MICROVIA_STACK_DEPTH_CONSTRAINT
@ DRCE_MICROVIA_STACK_DEPTH
Definition drc_item.h:76
@ DRCE_HOLE_ASPECT_RATIO
Definition drc_item.h:77
@ DRCE_MICROVIA_CROSSES_CORE
Definition drc_item.h:78
@ DRCE_MALFORMED_MICROVIA_STACK_SPAN
Definition drc_item.h:74
@ DRCE_MICROVIA_STACK_NOT_FILLED
Definition drc_item.h:75
@ DRCE_MICROVIA_SPANS_DIELECTRICS
Definition drc_item.h:79
static int stackThickness(const std::vector< BOARD_STACKUP_ITEM * > &aStack, int aFirst, int aLast)
#define _(s)
bool IsExternalCopperLayer(int aLayerId)
Test whether a layer is an external (F_Cu or B_Cu) copper layer.
Definition layer_ids.h:755
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ UNDEFINED_LAYER
Definition layer_ids.h:57
static DRC_REGISTER_TEST_PROVIDER< DRC_TEST_PROVIDER_ANNULAR_WIDTH > dummy
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition eda_angle.h:461
@ PTH
Plated through hole pad.
Definition padstack.h:99
@ RPT_SEVERITY_IGNORE
#define KEY_CORE
KIBIS top(path, &reporter)
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition typeinfo.h:89