Skip to content

Commit 2f448ea

Browse files
committed
Fixed USB pad calibration values for L21 in bootloader and USB host mode
1 parent 15e26fa commit 2f448ea

File tree

2 files changed

+27
-21
lines changed

2 files changed

+27
-21
lines changed

bootloaders/zero/board_driver_usb.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
#define NVM_USB_PAD_TRANSN_POS (32)
2828
#define NVM_USB_PAD_TRANSP_POS (37)
2929
#define NVM_USB_PAD_TRIM_POS (42)
30+
#elif (SAML21)
31+
#define NVM_CALIBRATION_ADDRESS NVMCTRL_OTP5
32+
#define NVM_USB_PAD_TRANSN_POS (13)
33+
#define NVM_USB_PAD_TRANSP_POS (18)
34+
#define NVM_USB_PAD_TRIM_POS (23)
3035
#else
3136
#define NVM_CALIBRATION_ADDRESS NVMCTRL_OTP4
3237
#define NVM_USB_PAD_TRANSN_POS (45)

cores/arduino/USB/samd21_host.c

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,23 @@ __attribute__((__aligned__(4))) volatile UsbHostDescriptor usb_pipe_table[USB_EP
4444

4545
extern void (*gpf_isr)(void);
4646

47-
48-
// NVM Software Calibration Area Mapping
49-
// USB TRANSN calibration value. Should be written to the USB PADCAL register.
50-
#define NVM_USB_PAD_TRANSN_POS 45
51-
#define NVM_USB_PAD_TRANSN_SIZE 5
52-
// USB TRANSP calibration value. Should be written to the USB PADCAL register.
53-
#define NVM_USB_PAD_TRANSP_POS 50
54-
#define NVM_USB_PAD_TRANSP_SIZE 5
55-
// USB TRIM calibration value. Should be written to the USB PADCAL register.
56-
#define NVM_USB_PAD_TRIM_POS 55
57-
#define NVM_USB_PAD_TRIM_SIZE 3
47+
#if (SAML21)
48+
#define NVM_CALIBRATION_ADDRESS NVMCTRL_OTP5
49+
#define NVM_USB_PAD_TRANSN_POS (13)
50+
#define NVM_USB_PAD_TRANSP_POS (18)
51+
#define NVM_USB_PAD_TRIM_POS (23)
52+
#else
53+
#define NVM_CALIBRATION_ADDRESS NVMCTRL_OTP4
54+
#define NVM_USB_PAD_TRANSN_POS (45)
55+
#define NVM_USB_PAD_TRANSP_POS (50)
56+
#define NVM_USB_PAD_TRIM_POS (55)
57+
#endif
58+
#define USB_PAD_TRANSN_REG_POS (6)
59+
#define NVM_USB_PAD_TRANSN_SIZE (5)
60+
#define USB_PAD_TRANSP_REG_POS (0)
61+
#define NVM_USB_PAD_TRANSP_SIZE (5)
62+
#define USB_PAD_TRIM_REG_POS (12)
63+
#define NVM_USB_PAD_TRIM_SIZE (3)
5864

5965
/**
6066
* \brief Initialize the SAMD21 host driver.
@@ -112,7 +118,7 @@ void UHD_Init(void)
112118
while (USB->HOST.SYNCBUSY.reg == USB_SYNCBUSY_ENABLE);
113119

114120
/* Load Pad Calibration */
115-
pad_transn = (*((uint32_t *)(NVMCTRL_OTP4) // Non-Volatile Memory Controller
121+
pad_transn = (*((uint32_t *)(NVM_CALIBRATION_ADDRESS) // Non-Volatile Memory Controller
116122
+ (NVM_USB_PAD_TRANSN_POS / 32))
117123
>> (NVM_USB_PAD_TRANSN_POS % 32))
118124
& ((1 << NVM_USB_PAD_TRANSN_SIZE) - 1);
@@ -122,9 +128,7 @@ void UHD_Init(void)
122128
pad_transn = 5;
123129
}
124130

125-
USB->HOST.PADCAL.bit.TRANSN = pad_transn;
126-
127-
pad_transp = (*((uint32_t *)(NVMCTRL_OTP4)
131+
pad_transp = (*((uint32_t *)(NVM_CALIBRATION_ADDRESS)
128132
+ (NVM_USB_PAD_TRANSP_POS / 32))
129133
>> (NVM_USB_PAD_TRANSP_POS % 32))
130134
& ((1 << NVM_USB_PAD_TRANSP_SIZE) - 1);
@@ -134,20 +138,17 @@ void UHD_Init(void)
134138
pad_transp = 29;
135139
}
136140

137-
USB->HOST.PADCAL.bit.TRANSP = pad_transp;
138-
139-
pad_trim = (*((uint32_t *)(NVMCTRL_OTP4)
141+
pad_trim = (*((uint32_t *)(NVM_CALIBRATION_ADDRESS)
140142
+ (NVM_USB_PAD_TRIM_POS / 32))
141143
>> (NVM_USB_PAD_TRIM_POS % 32))
142144
& ((1 << NVM_USB_PAD_TRIM_SIZE) - 1);
143145

144146
if (pad_trim == 0x7) // maximum value (7)
145147
{
146148
pad_trim = 3;
147-
}
148-
149-
USB->HOST.PADCAL.bit.TRIM = pad_trim;
149+
}
150150

151+
USB->HOST.PADCAL.reg = (uint16_t)((pad_trim << USB_PAD_TRIM_REG_POS) | (pad_transn << USB_PAD_TRANSN_REG_POS) | (pad_transp << USB_PAD_TRANSP_REG_POS));
151152

152153
/* Set the configuration */
153154
uhd_run_in_standby();

0 commit comments

Comments
 (0)