Skip to content

Commit c43f1e3

Browse files
committed
fix samd51 pwm glitch and enable same51 support
1 parent 62534c2 commit c43f1e3

File tree

4 files changed

+26
-16
lines changed

4 files changed

+26
-16
lines changed

src/drivers/hardware_specific/generic_mcu.cpp

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

1313
#elif defined(_STM32_DEF_) // or stm32
1414

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

17-
#elif defined(_SAMD51_) // samd21 for the moment, samd51 in progress...
17+
#elif defined(_SAMD51_) // samd51
18+
19+
#elif defined(__SAME51J19A__) || defined(__ATSAME51J19A__) // samd51
1820

1921
#else
2022

src/drivers/hardware_specific/samd51_mcu.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "./samd_mcu.h"
44

55

6-
#ifdef _SAMD51_
6+
#if defined(_SAMD51_)||defined(_SAME51_)
77

88

99

@@ -129,12 +129,13 @@ void writeSAMDDutyCycle(int chaninfo, float dc) {
129129
uint8_t chan = GetTCChannelNumber(chaninfo);
130130
if (tccn<TCC_INST_NUM) {
131131
Tcc* tcc = (Tcc*)GetTC(chaninfo);
132-
// set via CCBUF]
132+
// set via CCBUF
133+
while ( (tcc->SYNCBUSY.vec.CC & (0x1<<chan)) > 0 );
133134
tcc->CCBUF[chan].reg = (uint32_t)((SIMPLEFOC_SAMD_PWM_RESOLUTION-1) * dc); // TODO pwm frequency!
134-
tcc->STATUS.vec.CCBUFV |= (0x1<<chan);
135-
while ( tcc->SYNCBUSY.bit.STATUS > 0 );
136-
tcc->CTRLBSET.reg |= TCC_CTRLBSET_CMD(TCC_CTRLBSET_CMD_UPDATE_Val);
137-
while ( tcc->SYNCBUSY.bit.CTRLB > 0 );
135+
// tcc->STATUS.vec.CCBUFV |= (0x1<<chan);
136+
// while ( tcc->SYNCBUSY.bit.STATUS > 0 );
137+
// tcc->CTRLBSET.reg |= TCC_CTRLBSET_CMD(TCC_CTRLBSET_CMD_UPDATE_Val);
138+
// while ( tcc->SYNCBUSY.bit.CTRLB > 0 );
138139
}
139140
else {
140141
// Tc* tc = (Tc*)GetTC(chaninfo);

src/drivers/hardware_specific/samd_mcu.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include "./samd_mcu.h"
55

6-
#if defined(_SAMD21_)||defined(_SAMD51_)
6+
#if defined(_SAMD21_)||defined(_SAMD51_)||defined(_SAME51_)
77

88

99

@@ -90,7 +90,7 @@ tccConfiguration getTCCChannelNr(int pin, EPioType peripheral) {
9090
result.tcc.chaninfo = association.tccF;
9191
result.wo = association.woF;
9292
}
93-
#ifdef _SAMD51_
93+
#if defined(_SAMD51_)||defined(_SAME51_)
9494
else if (peripheral==PIO_TCC_PDEC) {
9595
result.tcc.chaninfo = association.tccG;
9696
result.wo = association.woG;
@@ -758,7 +758,7 @@ void printAllPinInfos() {
758758
case PORTA: Serial.print(" PA"); break;
759759
case PORTB: Serial.print(" PB"); break;
760760
case PORTC: Serial.print(" PC"); break;
761-
#ifdef _SAMD51_
761+
#if defined(_SAMD51_)||defined(_SAME51_)
762762
case PORTD: Serial.print(" PD"); break;
763763
#endif
764764
}
@@ -803,7 +803,7 @@ void printAllPinInfos() {
803803
else
804804
Serial.print(" None ");
805805

806-
#ifdef _SAMD51_
806+
#if defined(_SAMD51_)||defined(_SAME51_)
807807
Serial.print(" G=");
808808
if (association.tccG>=0) {
809809
int tcn = GetTCNumber(association.tccG);
@@ -842,7 +842,7 @@ void printTCCConfiguration(tccConfiguration& info) {
842842
Serial.print(" E "); break;
843843
case PIO_TIMER_ALT:
844844
Serial.print(" F "); break;
845-
#ifdef _SAMD51_
845+
#if defined(_SAMD51_)||defined(_SAME51_)
846846
case PIO_TCC_PDEC:
847847
Serial.print(" G "); break;
848848
#endif

src/drivers/hardware_specific/samd_mcu.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@
99
#include "../hardware_api.h"
1010

1111

12-
#if defined(_SAMD21_)||defined(_SAMD51_)
12+
#if defined(__SAME51J19A__) || defined(__ATSAME51J19A__)
13+
#ifndef _SAME51_
14+
#define _SAME51_
15+
#endif
16+
#endif
17+
18+
19+
#if defined(_SAMD21_)||defined(_SAMD51_)||defined(_SAME51_)
1320

1421

1522
#include "Arduino.h"
@@ -53,7 +60,7 @@ struct wo_association {
5360
uint8_t woE;
5461
ETCChannel tccF;
5562
uint8_t woF;
56-
#if defined(_SAMD51_)
63+
#if defined(_SAMD51_)||defined(_SAME51_)
5764
ETCChannel tccG;
5865
uint8_t woG;
5966
#endif
@@ -63,7 +70,7 @@ struct wo_association {
6370

6471
#if defined(_SAMD21_)
6572
#define NUM_PIO_TIMER_PERIPHERALS 2
66-
#elif defined(_SAMD51_)
73+
#elif defined(_SAMD51_)||defined(_SAME51_)
6774
#define NUM_PIO_TIMER_PERIPHERALS 3
6875
#endif
6976

0 commit comments

Comments
 (0)