Skip to content

Commit bc2c779

Browse files
committedAug 29, 2018
Make CDC/UART interface configurable from Makefile
1 parent 2267161 commit bc2c779

10 files changed

+71
-72
lines changed
 

‎bootloaders/zero/Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ NAME?=samd21_sam_ba
6262

6363
# -----------------------------------------------------------------------------
6464
# Compiler options
65-
CFLAGS_EXTRA=-D__SAMD21G18A__ -DBOARD_ID_$(BOARD_ID)
65+
SAM_BA_INTERFACES?=SAM_BA_BOTH_INTERFACES
66+
CFLAGS_EXTRA=-D__SAMD21G18A__ -DBOARD_ID_$(BOARD_ID) -D$(SAM_BA_INTERFACES)
6667
CFLAGS=-mthumb -mcpu=cortex-m0plus -Wall -c -std=gnu99 -ffunction-sections -fdata-sections -nostdlib -nostartfiles --param max-inline-insns-single=500
6768
ifdef DEBUG
6869
CFLAGS+=-g3 -O1 -DDEBUG=1

‎bootloaders/zero/board_definitions_arduino_mkrvidor4000.h

-11
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,6 @@
4444
//#define BOOT_LOAD_PIN PIN_PA21
4545
//#define BOOT_LOAD_PIN PIN_PA15
4646

47-
#define BOOT_USART_MODULE SERCOM5
48-
#define BOOT_USART_BUS_CLOCK_INDEX PM_APBCMASK_SERCOM5
49-
#define BOOT_USART_PER_CLOCK_INDEX GCLK_CLKCTRL_ID_SERCOM5_CORE_Val
50-
#define BOOT_USART_PAD_SETTINGS UART_RX_PAD3_TX_PAD2
51-
#define BOOT_USART_PAD3 PINMUX_PB23D_SERCOM5_PAD3
52-
#define BOOT_USART_PAD2 PINMUX_PB22D_SERCOM5_PAD2
53-
#define BOOT_USART_PAD1 PINMUX_UNUSED
54-
#define BOOT_USART_PAD0 PINMUX_UNUSED
55-
5647
/* Master clock frequency */
5748
#define CPU_FREQUENCY (48000000ul)
5849
#define VARIANT_MCK CPU_FREQUENCY
@@ -94,8 +85,6 @@ typedef struct __attribute__((packed)) {
9485
uint32_t force;
9586
} externalFlashSignatures;
9687

97-
#define SAM_BA_INTERFACE SAM_BA_USBCDC_ONLY
98-
9988
// No RX/TX led
10089
//#define BOARD_LEDRX_PORT
10190
//#define BOARD_LEDRX_PIN

‎bootloaders/zero/board_driver_jtag.c

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "board_driver_jtag.h"
2+
#include <string.h>
23

34
#ifdef ENABLE_JTAG_LOAD
45

‎bootloaders/zero/board_driver_serial.c

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
*/
1919

2020
#include "board_driver_serial.h"
21+
#include "board_definitions.h"
22+
23+
#if defined(SAM_BA_UART_ONLY) || defined(SAM_BA_BOTH_INTERFACES)
2124

2225
bool uart_drv_error_flag = false;
2326

@@ -102,3 +105,5 @@ void uart_read_buffer_polled(Sercom *sercom, uint8_t *ptr, uint16_t length)
102105
*ptr++ = (uint8_t)sercom->USART.DATA.reg;
103106
} while (length--);
104107
}
108+
109+
#endif

‎bootloaders/zero/board_driver_usb.c

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include "sam_ba_usb.h"
2323
#include "sam_ba_cdc.h"
2424

25+
#if defined(SAM_BA_USBCDC_ONLY) || defined(SAM_BA_BOTH_INTERFACES)
26+
2527
#define NVM_USB_PAD_TRANSN_POS (45)
2628
#define NVM_USB_PAD_TRANSN_SIZE (5)
2729
#define NVM_USB_PAD_TRANSP_POS (50)
@@ -359,3 +361,5 @@ void USB_Configure(Usb *pUsb)
359361
usb_endpoint_table[USB_EP_COMM].DeviceDescBank[1].PCKSIZE.bit.SIZE = 0;
360362
pUsb->DEVICE.DeviceEndpoint[USB_EP_COMM].EPSTATUSCLR.reg = USB_DEVICE_EPSTATUSCLR_BK1RDY;
361363
}
364+
365+
#endif

‎bootloaders/zero/build_all_bootloaders.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ mv -v samd21_sam_ba_arduino_mkrwan1300.* ../mkrwan1300/
2525
BOARD_ID=arduino_mkrwifi1010 NAME=samd21_sam_ba_arduino_mkrwifi1010 make clean all
2626
mv -v samd21_sam_ba_arduino_mkrwifi1010.* ../mkrwifi1010/
2727

28-
BOARD_ID=arduino_mkrvidor4000 NAME=samd21_sam_ba_arduino_mkrvidor make clean all
28+
BOARD_ID=arduino_mkrvidor4000 SAM_BA_INTERFACES=SAM_BA_USBCDC_ONLY NAME=samd21_sam_ba_arduino_mkrvidor make clean all
2929
mv -v samd21_sam_ba_arduino_mkrvidor.* ../mkrvidor4000/
3030

3131
echo Done building bootloaders!

‎bootloaders/zero/main.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ static void check_start_application(void)
165165
*/
166166
int main(void)
167167
{
168-
#if SAM_BA_INTERFACE == SAM_BA_USBCDC_ONLY || SAM_BA_INTERFACE == SAM_BA_BOTH_INTERFACES
168+
#if defined(SAM_BA_USBCDC_ONLY) || defined(SAM_BA_BOTH_INTERFACES)
169169
P_USB_CDC pCdc;
170170
#endif
171171
DEBUG_PIN_HIGH;
@@ -196,12 +196,12 @@ int main(void)
196196
clockout(0, 1);
197197
#endif
198198

199-
#if SAM_BA_INTERFACE == SAM_BA_UART_ONLY || SAM_BA_INTERFACE == SAM_BA_BOTH_INTERFACES
199+
#if defined(SAM_BA_UART_ONLY) || defined(SAM_BA_BOTH_INTERFACES)
200200
/* UART is enabled in all cases */
201201
serial_open();
202202
#endif
203203

204-
#if SAM_BA_INTERFACE == SAM_BA_USBCDC_ONLY || SAM_BA_INTERFACE == SAM_BA_BOTH_INTERFACES
204+
#if defined(SAM_BA_USBCDC_ONLY) || defined(SAM_BA_BOTH_INTERFACES)
205205
pCdc = usb_init();
206206
#endif
207207

@@ -220,7 +220,7 @@ int main(void)
220220
/* Wait for a complete enum on usb or a '#' char on serial line */
221221
while (1)
222222
{
223-
#if SAM_BA_INTERFACE == SAM_BA_USBCDC_ONLY || SAM_BA_INTERFACE == SAM_BA_BOTH_INTERFACES
223+
#if defined(SAM_BA_USBCDC_ONLY) || defined(SAM_BA_BOTH_INTERFACES)
224224
if (pCdc->IsConfigured(pCdc) != 0)
225225
{
226226
main_b_cdc_enable = true;
@@ -238,7 +238,7 @@ int main(void)
238238
}
239239
#endif
240240

241-
#if SAM_BA_INTERFACE == SAM_BA_UART_ONLY || SAM_BA_INTERFACE == SAM_BA_BOTH_INTERFACES
241+
#if defined(SAM_BA_UART_ONLY) || defined(SAM_BA_BOTH_INTERFACES)
242242
/* Check if a '#' has been received */
243243
if (!main_b_cdc_enable && serial_sharp_received())
244244
{

‎bootloaders/zero/sam_ba_monitor.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ typedef struct
5151
uint32_t (*getdata_xmd)(void* data, uint32_t length);
5252
} t_monitor_if;
5353

54-
#if SAM_BA_INTERFACE == SAM_BA_UART_ONLY || SAM_BA_INTERFACE == SAM_BA_BOTH_INTERFACES
54+
#if defined(SAM_BA_UART_ONLY) || defined(SAM_BA_BOTH_INTERFACES)
5555
/* Initialize structures with function pointers from supported interfaces */
5656
const t_monitor_if uart_if =
5757
{
@@ -65,7 +65,7 @@ const t_monitor_if uart_if =
6565
};
6666
#endif
6767

68-
#if SAM_BA_INTERFACE == SAM_BA_USBCDC_ONLY || SAM_BA_INTERFACE == SAM_BA_BOTH_INTERFACES
68+
#if defined(SAM_BA_USBCDC_ONLY) || defined(SAM_BA_BOTH_INTERFACES)
6969
//Please note that USB doesn't use Xmodem protocol, since USB already includes flow control and data verification
7070
//Data are simply forwarded without further coding.
7171
const t_monitor_if usbcdc_if =
@@ -94,15 +94,15 @@ volatile uint16_t rxLEDPulse = 0; // time remaining for Rx LED pulse
9494

9595
void sam_ba_monitor_init(uint8_t com_interface)
9696
{
97-
#if SAM_BA_INTERFACE == SAM_BA_UART_ONLY || SAM_BA_INTERFACE == SAM_BA_BOTH_INTERFACES
97+
#if defined(SAM_BA_UART_ONLY) || defined(SAM_BA_BOTH_INTERFACES)
9898
//Selects the requested interface for future actions
9999
if (com_interface == SAM_BA_INTERFACE_USART)
100100
{
101101
ptr_monitor_if = (t_monitor_if*) &uart_if;
102102
b_sam_ba_interface_usart = true;
103103
}
104104
#endif
105-
#if SAM_BA_INTERFACE == SAM_BA_USBCDC_ONLY || SAM_BA_INTERFACE == SAM_BA_BOTH_INTERFACES
105+
#if defined(SAM_BA_USBCDC_ONLY) || defined(SAM_BA_BOTH_INTERFACES)
106106
if (com_interface == SAM_BA_INTERFACE_USBCDC)
107107
{
108108
ptr_monitor_if = (t_monitor_if*) &usbcdc_if;

‎bootloaders/zero/sam_ba_monitor.h

+2-7
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,8 @@
2424

2525
#define SAM_BA_VERSION "2.0"
2626

27-
/* Enable the interfaces to save code size */
28-
#define SAM_BA_BOTH_INTERFACES 0
29-
#define SAM_BA_UART_ONLY 1
30-
#define SAM_BA_USBCDC_ONLY 2
31-
32-
#ifndef SAM_BA_INTERFACE
33-
#define SAM_BA_INTERFACE SAM_BA_BOTH_INTERFACES
27+
#if !defined(SAM_BA_BOTH_INTERFACES) && !defined(SAM_BA_UART_ONLY) && !defined(SAM_BA_USBCDC_ONLY)
28+
#define SAM_BA_BOTH_INTERFACES
3429
#endif
3530

3631
/* Selects USB as the communication interface of the monitor */

‎bootloaders/zero/sam_ba_serial.c

+47-43
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include "sam_ba_serial.h"
2323
#include "board_driver_serial.h"
2424

25+
#if defined(SAM_BA_UART_ONLY) || defined(SAM_BA_BOTH_INTERFACES)
26+
2527
/* Local reference to current Usart instance in use with this driver */
2628
//struct usart_module usart_sam_ba;
2729

@@ -200,49 +202,6 @@ uint32_t serial_getdata(void* data, uint32_t length)
200202
return (1);
201203
}
202204

203-
static const uint16_t crc16Table[256]=
204-
{
205-
0x0000,0x1021,0x2042,0x3063,0x4084,0x50a5,0x60c6,0x70e7,
206-
0x8108,0x9129,0xa14a,0xb16b,0xc18c,0xd1ad,0xe1ce,0xf1ef,
207-
0x1231,0x0210,0x3273,0x2252,0x52b5,0x4294,0x72f7,0x62d6,
208-
0x9339,0x8318,0xb37b,0xa35a,0xd3bd,0xc39c,0xf3ff,0xe3de,
209-
0x2462,0x3443,0x0420,0x1401,0x64e6,0x74c7,0x44a4,0x5485,
210-
0xa56a,0xb54b,0x8528,0x9509,0xe5ee,0xf5cf,0xc5ac,0xd58d,
211-
0x3653,0x2672,0x1611,0x0630,0x76d7,0x66f6,0x5695,0x46b4,
212-
0xb75b,0xa77a,0x9719,0x8738,0xf7df,0xe7fe,0xd79d,0xc7bc,
213-
0x48c4,0x58e5,0x6886,0x78a7,0x0840,0x1861,0x2802,0x3823,
214-
0xc9cc,0xd9ed,0xe98e,0xf9af,0x8948,0x9969,0xa90a,0xb92b,
215-
0x5af5,0x4ad4,0x7ab7,0x6a96,0x1a71,0x0a50,0x3a33,0x2a12,
216-
0xdbfd,0xcbdc,0xfbbf,0xeb9e,0x9b79,0x8b58,0xbb3b,0xab1a,
217-
0x6ca6,0x7c87,0x4ce4,0x5cc5,0x2c22,0x3c03,0x0c60,0x1c41,
218-
0xedae,0xfd8f,0xcdec,0xddcd,0xad2a,0xbd0b,0x8d68,0x9d49,
219-
0x7e97,0x6eb6,0x5ed5,0x4ef4,0x3e13,0x2e32,0x1e51,0x0e70,
220-
0xff9f,0xefbe,0xdfdd,0xcffc,0xbf1b,0xaf3a,0x9f59,0x8f78,
221-
0x9188,0x81a9,0xb1ca,0xa1eb,0xd10c,0xc12d,0xf14e,0xe16f,
222-
0x1080,0x00a1,0x30c2,0x20e3,0x5004,0x4025,0x7046,0x6067,
223-
0x83b9,0x9398,0xa3fb,0xb3da,0xc33d,0xd31c,0xe37f,0xf35e,
224-
0x02b1,0x1290,0x22f3,0x32d2,0x4235,0x5214,0x6277,0x7256,
225-
0xb5ea,0xa5cb,0x95a8,0x8589,0xf56e,0xe54f,0xd52c,0xc50d,
226-
0x34e2,0x24c3,0x14a0,0x0481,0x7466,0x6447,0x5424,0x4405,
227-
0xa7db,0xb7fa,0x8799,0x97b8,0xe75f,0xf77e,0xc71d,0xd73c,
228-
0x26d3,0x36f2,0x0691,0x16b0,0x6657,0x7676,0x4615,0x5634,
229-
0xd94c,0xc96d,0xf90e,0xe92f,0x99c8,0x89e9,0xb98a,0xa9ab,
230-
0x5844,0x4865,0x7806,0x6827,0x18c0,0x08e1,0x3882,0x28a3,
231-
0xcb7d,0xdb5c,0xeb3f,0xfb1e,0x8bf9,0x9bd8,0xabbb,0xbb9a,
232-
0x4a75,0x5a54,0x6a37,0x7a16,0x0af1,0x1ad0,0x2ab3,0x3a92,
233-
0xfd2e,0xed0f,0xdd6c,0xcd4d,0xbdaa,0xad8b,0x9de8,0x8dc9,
234-
0x7c26,0x6c07,0x5c64,0x4c45,0x3ca2,0x2c83,0x1ce0,0x0cc1,
235-
0xef1f,0xff3e,0xcf5d,0xdf7c,0xaf9b,0xbfba,0x8fd9,0x9ff8,
236-
0x6e17,0x7e36,0x4e55,0x5e74,0x2e93,0x3eb2,0x0ed1,0x1ef0
237-
};
238-
239-
//*----------------------------------------------------------------------------
240-
//* \brief Compute the CRC
241-
//*----------------------------------------------------------------------------
242-
unsigned short serial_add_crc(char ptr, unsigned short crc)
243-
{
244-
return (crc << 8) ^ crc16Table[((crc >> 8) ^ ptr) & 0xff];
245-
}
246205

247206
//*----------------------------------------------------------------------------
248207
//* \brief
@@ -532,3 +491,48 @@ uint32_t serial_getdata_xmd(void* data, uint32_t length)
532491
// return(b_run);
533492
}
534493

494+
#endif
495+
496+
static const uint16_t crc16Table[256]=
497+
{
498+
0x0000,0x1021,0x2042,0x3063,0x4084,0x50a5,0x60c6,0x70e7,
499+
0x8108,0x9129,0xa14a,0xb16b,0xc18c,0xd1ad,0xe1ce,0xf1ef,
500+
0x1231,0x0210,0x3273,0x2252,0x52b5,0x4294,0x72f7,0x62d6,
501+
0x9339,0x8318,0xb37b,0xa35a,0xd3bd,0xc39c,0xf3ff,0xe3de,
502+
0x2462,0x3443,0x0420,0x1401,0x64e6,0x74c7,0x44a4,0x5485,
503+
0xa56a,0xb54b,0x8528,0x9509,0xe5ee,0xf5cf,0xc5ac,0xd58d,
504+
0x3653,0x2672,0x1611,0x0630,0x76d7,0x66f6,0x5695,0x46b4,
505+
0xb75b,0xa77a,0x9719,0x8738,0xf7df,0xe7fe,0xd79d,0xc7bc,
506+
0x48c4,0x58e5,0x6886,0x78a7,0x0840,0x1861,0x2802,0x3823,
507+
0xc9cc,0xd9ed,0xe98e,0xf9af,0x8948,0x9969,0xa90a,0xb92b,
508+
0x5af5,0x4ad4,0x7ab7,0x6a96,0x1a71,0x0a50,0x3a33,0x2a12,
509+
0xdbfd,0xcbdc,0xfbbf,0xeb9e,0x9b79,0x8b58,0xbb3b,0xab1a,
510+
0x6ca6,0x7c87,0x4ce4,0x5cc5,0x2c22,0x3c03,0x0c60,0x1c41,
511+
0xedae,0xfd8f,0xcdec,0xddcd,0xad2a,0xbd0b,0x8d68,0x9d49,
512+
0x7e97,0x6eb6,0x5ed5,0x4ef4,0x3e13,0x2e32,0x1e51,0x0e70,
513+
0xff9f,0xefbe,0xdfdd,0xcffc,0xbf1b,0xaf3a,0x9f59,0x8f78,
514+
0x9188,0x81a9,0xb1ca,0xa1eb,0xd10c,0xc12d,0xf14e,0xe16f,
515+
0x1080,0x00a1,0x30c2,0x20e3,0x5004,0x4025,0x7046,0x6067,
516+
0x83b9,0x9398,0xa3fb,0xb3da,0xc33d,0xd31c,0xe37f,0xf35e,
517+
0x02b1,0x1290,0x22f3,0x32d2,0x4235,0x5214,0x6277,0x7256,
518+
0xb5ea,0xa5cb,0x95a8,0x8589,0xf56e,0xe54f,0xd52c,0xc50d,
519+
0x34e2,0x24c3,0x14a0,0x0481,0x7466,0x6447,0x5424,0x4405,
520+
0xa7db,0xb7fa,0x8799,0x97b8,0xe75f,0xf77e,0xc71d,0xd73c,
521+
0x26d3,0x36f2,0x0691,0x16b0,0x6657,0x7676,0x4615,0x5634,
522+
0xd94c,0xc96d,0xf90e,0xe92f,0x99c8,0x89e9,0xb98a,0xa9ab,
523+
0x5844,0x4865,0x7806,0x6827,0x18c0,0x08e1,0x3882,0x28a3,
524+
0xcb7d,0xdb5c,0xeb3f,0xfb1e,0x8bf9,0x9bd8,0xabbb,0xbb9a,
525+
0x4a75,0x5a54,0x6a37,0x7a16,0x0af1,0x1ad0,0x2ab3,0x3a92,
526+
0xfd2e,0xed0f,0xdd6c,0xcd4d,0xbdaa,0xad8b,0x9de8,0x8dc9,
527+
0x7c26,0x6c07,0x5c64,0x4c45,0x3ca2,0x2c83,0x1ce0,0x0cc1,
528+
0xef1f,0xff3e,0xcf5d,0xdf7c,0xaf9b,0xbfba,0x8fd9,0x9ff8,
529+
0x6e17,0x7e36,0x4e55,0x5e74,0x2e93,0x3eb2,0x0ed1,0x1ef0
530+
};
531+
532+
//*----------------------------------------------------------------------------
533+
//* \brief Compute the CRC
534+
//*----------------------------------------------------------------------------
535+
unsigned short serial_add_crc(char ptr, unsigned short crc)
536+
{
537+
return (crc << 8) ^ crc16Table[((crc >> 8) ^ ptr) & 0xff];
538+
}

0 commit comments

Comments
 (0)