Skip to content

Commit 678c6f2

Browse files
committed
working on SAMD51
1 parent 32a164b commit 678c6f2

File tree

5 files changed

+163
-15
lines changed

5 files changed

+163
-15
lines changed

src/drivers/hardware_specific/generic_mcu.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
#elif defined(_SAMD21_) // samd21 for the moment, samd51 in progress...
1616

17+
#elif defined(_SAMD51_) // samd21 for the moment, samd51 in progress...
18+
1719
#else
1820

1921
// function setting the high pwm frequency to the supplied pins

src/drivers/hardware_specific/samd21_mcu.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
11

22

3-
#if defined(ARDUINO_ARCH_SAMD)
4-
//#if defined(_SAMD21_)
53

6-
7-
#include "../hardware_api.h"
8-
#include "wiring_private.h"
9-
10-
#include "./samd21_wo_associations.h"
4+
#define SIMPLEFOC_SAMD_DEBUG
115

126

13-
#define SIMPLEFOC_SAMD_DEBUG
147

8+
#include "../hardware_api.h"
9+
#include "wiring_private.h"
1510

11+
#if defined(SAMD_SERIES)
1612

17-
#ifndef SIMPLEFOC_SAMD_ALLOW_DIFFERENT_TCCS
18-
#define SIMPLEFOC_SAMD_ALLOW_DIFFERENT_TCCS false
13+
#if defined(_SAMD21_)
14+
#include "./samd21_wo_associations.h"
15+
#elif defined(_SAMD51_)
16+
#include "./samd21_wo_associations.h"
1917
#endif
2018

19+
2120
#ifndef SIMPLEFOC_SAMD_PWM_RESOLUTION
2221
#define SIMPLEFOC_SAMD_PWM_RESOLUTION 1000
2322
#define SIMPLEFOC_SAMD_PWM_TC_RESOLUTION 250
2423
#endif
2524

2625
#ifndef SIMPLEFOC_SAMD_MAX_TCC_PINCONFIGURATIONS
27-
#define SIMPLEFOC_SAMD_MAX_TCC_PINCONFIGURATIONS 12
26+
#define SIMPLEFOC_SAMD_MAX_TCC_PINCONFIGURATIONS 24
2827
#endif
2928

3029

src/drivers/hardware_specific/samd21_wo_associations.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11

2+
#include "variant.h"
3+
4+
#ifdef _SAMD21_
5+
6+
27

38
struct wo_association {
49
EPortType port;
@@ -11,8 +16,6 @@ struct wo_association {
1116

1217

1318

14-
#ifdef _SAMD21_
15-
1619

1720

1821
#ifndef TCC3_CH0
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
2+
3+
4+
// TCC# Channels WO_NUM Counter size Fault Dithering Output matrix DTI SWAP Pattern generation
5+
// 0 6 8 24-bit Yes Yes Yes Yes Yes Yes
6+
// 1 4 8 24-bit Yes Yes Yes Yes Yes Yes
7+
// 2 3 3 16-bit Yes - Yes - - -
8+
// 3 2 2 16-bit Yes - - - - -
9+
// 4 2 2 16-bit Yes - - - - -
10+
11+
12+
#include "variant.h"
13+
14+
15+
#ifdef _SAMD51_
16+
17+
18+
19+
struct wo_association {
20+
EPortType port;
21+
uint32_t pin;
22+
ETCChannel tccE;
23+
uint8_t woE;
24+
ETCChannel tccF;
25+
uint8_t woF;
26+
ETCChannel tccG;
27+
uint8_t woG;
28+
};
29+
30+
31+
struct wo_association WO_associations[] = {
32+
33+
{ PORTB, 9, TC4_CH1, 1, NOT_ON_TIMER, 0, NOT_ON_TIMER, 0},
34+
{ PORTA, 4, TC0_CH0, 0, NOT_ON_TIMER, 0, NOT_ON_TIMER, 0},
35+
{ PORTA, 5, TC0_CH1, 1, NOT_ON_TIMER, 0, NOT_ON_TIMER, 0},
36+
{ PORTA, 6, TC1_CH0, 0, NOT_ON_TIMER, 0, NOT_ON_TIMER, 0},
37+
{ PORTA, 7, TC1_CH1, 1, NOT_ON_TIMER, 0, NOT_ON_TIMER, 0},
38+
{ PORTC, 4, NOT_ON_TIMER, 0, TCC0_CH0, 0, NOT_ON_TIMER, 0},
39+
// PC05, PC06, PC07 -> no timers
40+
{ PORTA, 8, TC0_CH0, 0, TCC0_CH0, 0, TCC1_CH0, 4},
41+
{ PORTA, 9, TC0_CH1, 1, TCC0_CH1, 1, TCC1_CH1, 5},
42+
{ PORTA, 10, TC1_CH0, 0, TCC0_CH2, 2, TCC1_CH2, 6},
43+
{ PORTA, 11, TC1_CH1, 1, TCC0_CH3, 3, TCC1_CH3, 7},
44+
{ PORTB, 10, TC5_CH0, 0, TCC0_CH0, 4, TCC1_CH0, 0}, //?
45+
{ PORTB, 11, TC5_CH1, 1, TCC0_CH1, 5, TCC1_CH1, 1}, //?
46+
{ PORTB, 12, TC4_CH0, 0, TCC3_CH0, 0, TCC0_CH0, 0},
47+
{ PORTB, 13, TC4_CH1, 1, TCC3_CH1, 1, TCC0_CH1, 1},
48+
{ PORTB, 14, TC5_CH0, 0, TCC4_CH0, 0, TCC0_CH2, 2},
49+
{ PORTB, 15, TC5_CH1, 1, TCC4_CH1, 1, TCC0_CH3, 3},
50+
{ PORTD, 8, NOT_ON_TIMER, 0, TCC0_CH1, 1, NOT_ON_TIMER, 0},
51+
{ PORTD, 9, NOT_ON_TIMER, 0, TCC0_CH2, 2, NOT_ON_TIMER, 0},
52+
{ PORTD, 10, NOT_ON_TIMER, 0, TCC0_CH3, 3, NOT_ON_TIMER, 0},
53+
{ PORTD, 11, NOT_ON_TIMER, 0, TCC0_CH0, 4, NOT_ON_TIMER, 0}, //?
54+
{ PORTD, 12, NOT_ON_TIMER, 0, TCC0_CH1, 5, NOT_ON_TIMER, 0}, //?
55+
{ PORTC, 10, NOT_ON_TIMER, 0, TCC0_CH0, 0, TCC1_CH0, 4},
56+
{ PORTC, 11, NOT_ON_TIMER, 0, TCC0_CH1, 1, TCC1_CH1, 5},
57+
{ PORTC, 12, NOT_ON_TIMER, 0, TCC0_CH2, 2, TCC1_CH2, 6},
58+
{ PORTC, 13, NOT_ON_TIMER, 0, TCC0_CH3, 3, TCC1_CH3, 7},
59+
{ PORTC, 14, NOT_ON_TIMER, 0, TCC0_CH0, 4, TCC1_CH0, 0}, //?
60+
{ PORTC, 15, NOT_ON_TIMER, 0, TCC0_CH1, 5, TCC1_CH1, 1}, //?
61+
{ PORTA, 12, TC2_CH0, 0, TCC0_CH2, 6, TCC1_CH2, 2},
62+
{ PORTA, 13, TC2_CH1, 1, TCC0_CH3, 7, TCC1_CH3, 3},
63+
{ PORTA, 14, TC3_CH0, 0, TCC2_CH0, 0, TCC1_CH2, 2}, //?
64+
{ PORTA, 15, TC3_CH1, 1, TCC1_CH1, 1, TCC1_CH3, 3}, //?
65+
{ PORTA, 16, TC2_CH0, 0, TCC1_CH0, 0, TCC0_CH0, 4},
66+
{ PORTA, 17, TC2_CH1, 1, TCC1_CH1, 1, TCC0_CH1, 5},
67+
{ PORTA, 18, TC3_CH0, 0, TCC1_CH2, 2, TCC0_CH2, 6},
68+
{ PORTA, 19, TC3_CH1, 1, TCC1_CH3, 3, TCC0_CH3, 7},
69+
{ PORTC, 16, NOT_ON_TIMER, 0, TCC0_CH0, 0, NOT_ON_TIMER, 0}, // PDEC0
70+
{ PORTC, 17, NOT_ON_TIMER, 0, TCC0_CH1, 1, NOT_ON_TIMER, 0}, // PDEC1
71+
{ PORTC, 18, NOT_ON_TIMER, 0, TCC0_CH2, 2, NOT_ON_TIMER, 0}, // PDEC2
72+
{ PORTC, 19, NOT_ON_TIMER, 0, TCC0_CH3, 3, NOT_ON_TIMER, 0},
73+
{ PORTC, 20, NOT_ON_TIMER, 0, TCC0_CH0, 4, NOT_ON_TIMER, 0},
74+
{ PORTC, 21, NOT_ON_TIMER, 0, TCC0_CH1, 5, NOT_ON_TIMER, 0},
75+
{ PORTC, 22, NOT_ON_TIMER, 0, TCC0_CH2, 6, NOT_ON_TIMER, 0},
76+
{ PORTC, 23, NOT_ON_TIMER, 0, TCC0_CH3, 7, NOT_ON_TIMER, 0},
77+
{ PORTD, 20, NOT_ON_TIMER, 0, TCC1_CH0, 0, NOT_ON_TIMER, 0},
78+
{ PORTD, 21, NOT_ON_TIMER, 0, TCC1_CH1, 1, NOT_ON_TIMER, 0},
79+
{ PORTB, 16, TC6_CH0, 0, TCC3_CH0, 0, TCC0_CH0, 4},
80+
{ PORTB, 17, TC6_CH1, 1, TCC3_CH1, 1, TCC0_CH1, 5},
81+
{ PORTB, 18, NOT_ON_TIMER, 0, TCC1_CH0, 0, NOT_ON_TIMER, 0}, // PDEC0
82+
{ PORTB, 19, NOT_ON_TIMER, 0, TCC1_CH1, 1, NOT_ON_TIMER, 0}, // PDEC1
83+
{ PORTB, 20, NOT_ON_TIMER, 0, TCC1_CH2, 2, NOT_ON_TIMER, 0}, // PDEC2
84+
{ PORTB, 21, NOT_ON_TIMER, 0, TCC1_CH3, 3, NOT_ON_TIMER, 0},
85+
{ PORTA, 20, TC7_CH0, 0, TCC1_CH0, 4, TCC0_CH0, 0},
86+
{ PORTA, 21, TC7_CH1, 1, TCC1_CH1, 5, TCC0_CH1, 1},
87+
{ PORTA, 22, TC4_CH0, 0, TCC1_CH2, 6, TCC0_CH2, 2},
88+
{ PORTA, 23, TC4_CH1, 1, TCC1_CH3, 7, TCC0_CH3, 3},
89+
{ PORTA, 24, TC5_CH0, 0, TCC2_CH2, 2, NOT_ON_TIMER, 0}, // PDEC0
90+
{ PORTA, 25, TC5_CH1, 1, NOT_ON_TIMER, 0, NOT_ON_TIMER, 0}, // PDEC1
91+
{ PORTB, 22, TC7_CH0, 0, NOT_ON_TIMER, 0, NOT_ON_TIMER, 0}, // PDEC2
92+
{ PORTB, 23, TC7_CH1, 1, NOT_ON_TIMER, 0, NOT_ON_TIMER, 0}, // PDEC0
93+
{ PORTB, 24, NOT_ON_TIMER, 0, NOT_ON_TIMER, 0, NOT_ON_TIMER, 0}, // PDEC1
94+
{ PORTB, 25, NOT_ON_TIMER, 0, NOT_ON_TIMER, 0, NOT_ON_TIMER, 0}, // PDEC2
95+
{ PORTB, 26, NOT_ON_TIMER, 0, TCC1_CH2, 2, NOT_ON_TIMER, 0},
96+
{ PORTB, 27, NOT_ON_TIMER, 0, TCC1_CH3, 3, NOT_ON_TIMER, 0},
97+
{ PORTB, 28, NOT_ON_TIMER, 0, TCC1_CH0, 4, NOT_ON_TIMER, 0},
98+
{ PORTB, 29, NOT_ON_TIMER, 1, TCC1_CH1, 5, NOT_ON_TIMER, 0},
99+
// PC24-PC28, PA27, RESET -> no TC/TCC peripherals
100+
{ PORTA, 30, TC6_CH0, 0, TCC2_CH0, 0, NOT_ON_TIMER, 0},
101+
{ PORTA, 31, TC6_CH1, 1, TCC2_CH1, 1, NOT_ON_TIMER, 0},
102+
{ PORTB, 30, TC0_CH0, 0, TCC4_CH0, 0, TCC0_CH2, 6},
103+
{ PORTB, 31, TC0_CH1, 1, TCC4_CH1, 1, TCC0_CH3, 7},
104+
// PC30, PC31 -> no TC/TCC peripherals
105+
{ PORTB, 0, TC7_CH0, 0, NOT_ON_TIMER, 0, NOT_ON_TIMER, 0},
106+
{ PORTB, 1, TC7_CH1, 1, NOT_ON_TIMER, 0, NOT_ON_TIMER, 0},
107+
{ PORTB, 2, TC6_CH0, 0, TCC2_CH2, 2, NOT_ON_TIMER, 0},
108+
109+
};
110+
#define NUM_WO_ASSOCIATIONS 72
111+
112+
wo_association ASSOCIATION_NOT_FOUND = { NOT_A_PORT, 0, NOT_ON_TIMER, 0, NOT_ON_TIMER, 0};
113+
114+
115+
struct wo_association& getWOAssociation(EPortType port, uint32_t pin) {
116+
for (int i=0;i<NUM_WO_ASSOCIATIONS;i++) {
117+
if (WO_associations[i].port==port && WO_associations[i].pin==pin)
118+
return WO_associations[i];
119+
}
120+
return ASSOCIATION_NOT_FOUND;
121+
};
122+
123+
124+
#endif

src/drivers/hardware_specific/samd_debug.h

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44
#include "../hardware_api.h"
55
#include "wiring_private.h"
66

7-
// Read count
8-
//TCC0->CTRLBSET.reg = TCC_CTRLBSET_CMD_READSYNC;
7+
#if defined(_SAMD21_)
8+
#include "./samd21_wo_associations.h"
9+
#elif defined(_SAMD51_)
10+
#include "./samd51_wo_associations.h"
11+
#endif
12+
913
//while (TCC0->SYNCBUSY.bit.CTRLB); // or while (TCC0->SYNCBUSY.reg);
1014
//int count = TCC0->COUNT.reg;
1115

@@ -66,6 +70,22 @@ void printAllPinInfos() {
6670
else
6771
Serial.println(" None ");
6872

73+
#ifdef _SAMD51_
74+
Serial.print(" G=");
75+
if (association.tccG>=0) {
76+
int tcn = GetTCNumber(association.tccG);
77+
Serial.print(" TCC");
78+
Serial.print(tcn);
79+
Serial.print("-");
80+
Serial.print(GetTCChannelNumber(association.tccG));
81+
Serial.print("[");
82+
Serial.print(GetTCChannelNumber(association.woG));
83+
Serial.println("]");
84+
}
85+
else
86+
Serial.println(" None ");
87+
#endif
88+
6989
}
7090
Serial.println();
7191

0 commit comments

Comments
 (0)