-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEK_TM4C123GXL.c
801 lines (698 loc) · 23.7 KB
/
EK_TM4C123GXL.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
/*
* Copyright (c) 2015, Texas Instruments Incorporated
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* ======== EK_TM4C123GXL.c ========
* This file is responsible for setting up the board specific items for the
* EK_TM4C123GXL board.
*/
#include <stdint.h>
#include <stdbool.h>
#include <xdc/std.h>
#include <xdc/runtime/Error.h>
#include <xdc/runtime/System.h>
#include <ti/sysbios/family/arm/m3/Hwi.h>
#include <inc/hw_ints.h>
#include <inc/hw_memmap.h>
#include <inc/hw_types.h>
#include <inc/hw_gpio.h>
#include <driverlib/gpio.h>
#include <driverlib/i2c.h>
#include <driverlib/pin_map.h>
#include <driverlib/pwm.h>
#include <driverlib/ssi.h>
#include <driverlib/sysctl.h>
#include <driverlib/uart.h>
#include <driverlib/udma.h>
#include "EK_TM4C123GXL.h"
#ifndef TI_DRIVERS_UART_DMA
#define TI_DRIVERS_UART_DMA 0
#endif
/*
* =============================== DMA ===============================
*/
#if defined(__TI_COMPILER_VERSION__)
#pragma DATA_ALIGN(dmaControlTable, 1024)
#elif defined(__IAR_SYSTEMS_ICC__)
#pragma data_alignment=1024
#elif defined(__GNUC__)
__attribute__ ((aligned (1024)))
#endif
static tDMAControlTable dmaControlTable[32];
static bool dmaInitialized = false;
/* Hwi_Struct used in the initDMA Hwi_construct call */
static Hwi_Struct dmaHwiStruct;
/*
* ======== dmaErrorHwi ========
*/
static Void dmaErrorHwi(UArg arg)
{
System_printf("DMA error code: %d\n", uDMAErrorStatusGet());
uDMAErrorStatusClear();
System_abort("DMA error!!");
}
/*
* ======== EK_TM4C123GXL_initDMA ========
*/
void EK_TM4C123GXL_initDMA(void)
{
Error_Block eb;
Hwi_Params hwiParams;
if (!dmaInitialized) {
Error_init(&eb);
Hwi_Params_init(&hwiParams);
Hwi_construct(&(dmaHwiStruct), INT_UDMAERR, dmaErrorHwi,
&hwiParams, &eb);
if (Error_check(&eb)) {
System_abort("Couldn't construct DMA error hwi");
}
SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA);
uDMAEnable();
uDMAControlBaseSet(dmaControlTable);
dmaInitialized = true;
}
}
/*
* =============================== General ===============================
*/
/*
* ======== EK_TM4C123GXL_initGeneral ========
*/
void EK_TM4C123GXL_initGeneral(void)
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
}
/*
* =============================== GPIO ===============================
*/
/* Place into subsections to allow the TI linker to remove items properly */
#if defined(__TI_COMPILER_VERSION__)
#pragma DATA_SECTION(GPIOTiva_config, ".const:GPIOTiva_config")
#endif
#include <ti/drivers/GPIO.h>
#include <ti/drivers/gpio/GPIOTiva.h>
/*
* Array of Pin configurations
* NOTE: The order of the pin configurations must coincide with what was
* defined in EK_TM4C123GXL.h
* NOTE: Pins not used for interrupts should be placed at the end of the
* array. Callback entries can be omitted from callbacks array to
* reduce memory usage.
*/
GPIO_PinConfig gpioPinConfigs[] = {
/* Input pins */
/* EK_TM4C123GXL_GPIO_SW1 */
GPIOTiva_PF_4 | GPIO_CFG_IN_PU | GPIO_CFG_IN_INT_RISING,
/* EK_TM4C123GXL_GPIO_SW2 */
GPIOTiva_PF_0 | GPIO_CFG_IN_PU | GPIO_CFG_IN_INT_RISING,
/* Output pins */
/* EK_TM4C123GXL_LED_RED */
GPIOTiva_PF_1 | GPIO_CFG_OUT_STD | GPIO_CFG_OUT_STR_HIGH | GPIO_CFG_OUT_LOW,
/* EK_TM4C123GXL_LED_BLUE */
GPIOTiva_PF_2 | GPIO_CFG_OUT_STD | GPIO_CFG_OUT_STR_HIGH | GPIO_CFG_OUT_LOW,
/* EK_TM4C123GXL_LED_GREEN */
GPIOTiva_PF_3 | GPIO_CFG_OUT_STD | GPIO_CFG_OUT_STR_HIGH | GPIO_CFG_OUT_LOW,
/* EK_TM4C123GXL_SDCARD_VCC */
GPIOTiva_PA_2 | GPIO_CFG_OUT_STD | GPIO_CFG_OUT_STR_HIGH | GPIO_CFG_OUT_LOW,
/* EK_TM4C123GXL_WRITE_ACTIVITY_LED */
GPIOTiva_PF_4 | GPIO_CFG_OUT_STD | GPIO_CFG_OUT_STR_HIGH | GPIO_CFG_OUT_LOW
};
/*
* Array of callback function pointers
* NOTE: The order of the pin configurations must coincide with what was
* defined in EK_TM4C123GXL.h
* NOTE: Pins not used for interrupts can be omitted from callbacks array to
* reduce memory usage (if placed at end of gpioPinConfigs array).
*/
GPIO_CallbackFxn gpioCallbackFunctions[] = {
NULL, /* EK_TM4C123GXL_GPIO_SW1 */
NULL /* EK_TM4C123GXL_GPIO_SW2 */
};
/* The device-specific GPIO_config structure */
const GPIOTiva_Config GPIOTiva_config = {
.pinConfigs = (GPIO_PinConfig *)gpioPinConfigs,
.callbacks = (GPIO_CallbackFxn *)gpioCallbackFunctions,
.numberOfPinConfigs = sizeof(gpioPinConfigs)/sizeof(GPIO_PinConfig),
.numberOfCallbacks = sizeof(gpioCallbackFunctions)/sizeof(GPIO_CallbackFxn),
.intPriority = (~0)
};
/*
* ======== EK_TM4C123GXL_initGPIO ========
*/
void EK_TM4C123GXL_initGPIO(void)
{
/* EK_TM4C123GXL_GPIO_SW2 - PF0 requires unlocking before configuration */
HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
HWREG(GPIO_PORTF_BASE + GPIO_O_CR) |= GPIO_PIN_0;
GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_0);
/* Initialize peripheral and pins */
GPIO_init();
}
/*
* =============================== I2C ===============================
*/
/* Place into subsections to allow the TI linker to remove items properly */
#if defined(__TI_COMPILER_VERSION__)
#pragma DATA_SECTION(I2C_config, ".const:I2C_config")
#pragma DATA_SECTION(i2cTivaHWAttrs, ".const:i2cTivaHWAttrs")
#endif
#include <ti/drivers/I2C.h>
#include <ti/drivers/i2c/I2CTiva.h>
I2CTiva_Object i2cTivaObjects[EK_TM4C123GXL_I2CCOUNT];
const I2CTiva_HWAttrs i2cTivaHWAttrs[EK_TM4C123GXL_I2CCOUNT] = {
{
.baseAddr = I2C1_BASE,
.intNum = INT_I2C1,
.intPriority = (~0)
},
{
.baseAddr = I2C3_BASE,
.intNum = INT_I2C3,
.intPriority = (~0)
},
};
const I2C_Config I2C_config[] = {
{
.fxnTablePtr = &I2CTiva_fxnTable,
.object = &i2cTivaObjects[0],
.hwAttrs = &i2cTivaHWAttrs[0]
},
{
.fxnTablePtr = &I2CTiva_fxnTable,
.object = &i2cTivaObjects[1],
.hwAttrs = &i2cTivaHWAttrs[1]
},
{NULL, NULL, NULL}
};
/*
* ======== EK_TM4C123GXL_initI2C ========
*/
void EK_TM4C123GXL_initI2C(void)
{
/* I2C1 Init */
/* Enable the peripheral */
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C1);
/* Configure the appropriate pins to be I2C instead of GPIO. */
GPIOPinConfigure(GPIO_PA6_I2C1SCL);
GPIOPinConfigure(GPIO_PA7_I2C1SDA);
GPIOPinTypeI2CSCL(GPIO_PORTA_BASE, GPIO_PIN_6);
GPIOPinTypeI2C(GPIO_PORTA_BASE, GPIO_PIN_7);
/* I2C3 Init */
/*
* NOTE: TI-RTOS examples configure pins PD0 & PD1 for SSI3 or I2C3. Thus,
* a conflict occurs when the I2C & SPI drivers are used simultaneously in
* an application. Modify the pin mux settings in this file and resolve the
* conflict before running your the application.
*/
/* Enable the peripheral */
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C3);
/* Configure the appropriate pins to be I2C instead of GPIO. */
GPIOPinConfigure(GPIO_PD0_I2C3SCL);
GPIOPinConfigure(GPIO_PD1_I2C3SDA);
GPIOPinTypeI2CSCL(GPIO_PORTD_BASE, GPIO_PIN_0);
GPIOPinTypeI2C(GPIO_PORTD_BASE, GPIO_PIN_1);
/*
* These GPIOs are connected to PD0 and PD1 and need to be brought into a
* GPIO input state so they don't interfere with I2C communications.
*/
GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_6);
GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_7);
I2C_init();
}
/*
* =============================== PWM ===============================
*/
/* Place into subsections to allow the TI linker to remove items properly */
#if defined(__TI_COMPILER_VERSION__)
#pragma DATA_SECTION(PWM_config, ".const:PWM_config")
#pragma DATA_SECTION(pwmTivaHWAttrs, ".const:pwmTivaHWAttrs")
#endif
#include <ti/drivers/PWM.h>
#include <ti/drivers/pwm/PWMTiva.h>
PWMTiva_Object pwmTivaObjects[EK_TM4C123GXL_PWMCOUNT];
const PWMTiva_HWAttrs pwmTivaHWAttrs[EK_TM4C123GXL_PWMCOUNT] = {
{
.baseAddr = PWM1_BASE,
.pwmOutput = PWM_OUT_6,
.pwmGenOpts = PWM_GEN_MODE_DOWN | PWM_GEN_MODE_DBG_RUN
},
{
.baseAddr = PWM1_BASE,
.pwmOutput = PWM_OUT_7,
.pwmGenOpts = PWM_GEN_MODE_DOWN | PWM_GEN_MODE_DBG_RUN
}
};
const PWM_Config PWM_config[] = {
{
.fxnTablePtr = &PWMTiva_fxnTable,
.object = &pwmTivaObjects[0],
.hwAttrs = &pwmTivaHWAttrs[0]
},
{
.fxnTablePtr = &PWMTiva_fxnTable,
.object = &pwmTivaObjects[1],
.hwAttrs = &pwmTivaHWAttrs[1]
},
{NULL, NULL, NULL}
};
/*
* ======== EK_TM4C123GXL_initPWM ========
*/
void EK_TM4C123GXL_initPWM(void)
{
/* Enable PWM peripherals */
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);
/*
* Enable PWM output on GPIO pins. Board_LED1 and Board_LED2 are now
* controlled by PWM peripheral - Do not use GPIO APIs.
*/
GPIOPinConfigure(GPIO_PF2_M1PWM6);
GPIOPinConfigure(GPIO_PF3_M1PWM7);
GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_2 |GPIO_PIN_3);
PWM_init();
}
/*
* =============================== SDSPI ===============================
*/
/* Place into subsections to allow the TI linker to remove items properly */
#if defined(__TI_COMPILER_VERSION__)
#pragma DATA_SECTION(SDSPI_config, ".const:SDSPI_config")
#pragma DATA_SECTION(sdspiTivaHWattrs, ".const:sdspiTivaHWattrs")
#endif
#include <ti/drivers/SDSPI.h>
#include <ti/drivers/sdspi/SDSPITiva.h>
SDSPITiva_Object sdspiTivaObjects[EK_TM4C123GXL_SDSPICOUNT];
const SDSPITiva_HWAttrs sdspiTivaHWattrs[EK_TM4C123GXL_SDSPICOUNT] = {
{
.baseAddr = SSI2_BASE,
.portSCK = GPIO_PORTB_BASE,
.pinSCK = GPIO_PIN_4,
.portMISO = GPIO_PORTB_BASE,
.pinMISO = GPIO_PIN_6,
.portMOSI = GPIO_PORTB_BASE,
.pinMOSI = GPIO_PIN_7,
.portCS = GPIO_PORTA_BASE,
.pinCS = GPIO_PIN_5,
}
};
const SDSPI_Config SDSPI_config[] = {
{
.fxnTablePtr = &SDSPITiva_fxnTable,
.object = &sdspiTivaObjects[0],
.hwAttrs = &sdspiTivaHWattrs[0]
},
{NULL, NULL, NULL}
};
/*
* ======== EK_TM4C123GXL_initSDSPI ========
*/
void EK_TM4C123GXL_initSDSPI(void)
{
/* Enable the peripherals used by the SD Card */
SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI2);
/* Configure pad settings */
GPIOPadConfigSet(GPIO_PORTB_BASE,
GPIO_PIN_4 | GPIO_PIN_7,
GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD);
GPIOPadConfigSet(GPIO_PORTB_BASE,
GPIO_PIN_6,
GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD_WPU);
GPIOPadConfigSet(GPIO_PORTA_BASE,
GPIO_PIN_5,
GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD);
GPIOPinConfigure(GPIO_PB4_SSI2CLK);
GPIOPinConfigure(GPIO_PB6_SSI2RX);
GPIOPinConfigure(GPIO_PB7_SSI2TX);
/*
* These GPIOs are connected to PB6 and PB7 and need to be brought into a
* GPIO input state so they don't interfere with SPI communications.
*/
GPIOPinTypeGPIOInput(GPIO_PORTD_BASE, GPIO_PIN_0);
GPIOPinTypeGPIOInput(GPIO_PORTD_BASE, GPIO_PIN_1);
SDSPI_init();
}
/*
* =============================== SPI ===============================
*/
/* Place into subsections to allow the TI linker to remove items properly */
#if defined(__TI_COMPILER_VERSION__)
#pragma DATA_SECTION(SPI_config, ".const:SPI_config")
#pragma DATA_SECTION(spiTivaDMAHWAttrs, ".const:spiTivaDMAHWAttrs")
#endif
#include <ti/drivers/SPI.h>
#include <ti/drivers/spi/SPITivaDMA.h>
SPITivaDMA_Object spiTivaDMAObjects[EK_TM4C123GXL_SPICOUNT];
#if defined(__TI_COMPILER_VERSION__)
#pragma DATA_ALIGN(spiTivaDMAscratchBuf, 32)
#elif defined(__IAR_SYSTEMS_ICC__)
#pragma data_alignment=32
#elif defined(__GNUC__)
__attribute__ ((aligned (32)))
#endif
uint32_t spiTivaDMAscratchBuf[EK_TM4C123GXL_SPICOUNT];
const SPITivaDMA_HWAttrs spiTivaDMAHWAttrs[EK_TM4C123GXL_SPICOUNT] = {
{
.baseAddr = SSI0_BASE,
.intNum = INT_SSI0,
.intPriority = (~0),
.scratchBufPtr = &spiTivaDMAscratchBuf[0],
.defaultTxBufValue = 0,
.rxChannelIndex = UDMA_CHANNEL_SSI0RX,
.txChannelIndex = UDMA_CHANNEL_SSI0TX,
.channelMappingFxn = uDMAChannelAssign,
.rxChannelMappingFxnArg = UDMA_CH10_SSI0RX,
.txChannelMappingFxnArg = UDMA_CH11_SSI0TX
},
{
.baseAddr = SSI2_BASE,
.intNum = INT_SSI2,
.intPriority = (~0),
.scratchBufPtr = &spiTivaDMAscratchBuf[1],
.defaultTxBufValue = 0,
.rxChannelIndex = UDMA_SEC_CHANNEL_UART2RX_12,
.txChannelIndex = UDMA_SEC_CHANNEL_UART2TX_13,
.channelMappingFxn = uDMAChannelAssign,
.rxChannelMappingFxnArg = UDMA_CH12_SSI2RX,
.txChannelMappingFxnArg = UDMA_CH13_SSI2TX
},
{
.baseAddr = SSI3_BASE,
.intNum = INT_SSI3,
.intPriority = (~0),
.scratchBufPtr = &spiTivaDMAscratchBuf[2],
.defaultTxBufValue = 0,
.rxChannelIndex = UDMA_SEC_CHANNEL_TMR2A_14,
.txChannelIndex = UDMA_SEC_CHANNEL_TMR2B_15,
.channelMappingFxn = uDMAChannelAssign,
.rxChannelMappingFxnArg = UDMA_CH14_SSI3RX,
.txChannelMappingFxnArg = UDMA_CH15_SSI3TX
}
};
const SPI_Config SPI_config[] = {
{
.fxnTablePtr = &SPITivaDMA_fxnTable,
.object = &spiTivaDMAObjects[0],
.hwAttrs = &spiTivaDMAHWAttrs[0]
},
{
.fxnTablePtr = &SPITivaDMA_fxnTable,
.object = &spiTivaDMAObjects[1],
.hwAttrs = &spiTivaDMAHWAttrs[1]
},
{
.fxnTablePtr = &SPITivaDMA_fxnTable,
.object = &spiTivaDMAObjects[2],
.hwAttrs = &spiTivaDMAHWAttrs[2]
},
{NULL, NULL, NULL},
};
/*
* ======== EK_TM4C123GXL_initSPI ========
*/
void EK_TM4C123GXL_initSPI(void)
{
/* SPI0 */
SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0);
/* Need to unlock PF0 */
GPIOPinConfigure(GPIO_PA2_SSI0CLK);
GPIOPinConfigure(GPIO_PA3_SSI0FSS);
GPIOPinConfigure(GPIO_PA4_SSI0RX);
GPIOPinConfigure(GPIO_PA5_SSI0TX);
GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_2 | GPIO_PIN_3 |
GPIO_PIN_4 | GPIO_PIN_5);
/* SSI2 */
SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI2);
GPIOPinConfigure(GPIO_PB4_SSI2CLK);
GPIOPinConfigure(GPIO_PB5_SSI2FSS);
GPIOPinConfigure(GPIO_PB6_SSI2RX);
GPIOPinConfigure(GPIO_PB7_SSI2TX);
GPIOPinTypeSSI(GPIO_PORTB_BASE, GPIO_PIN_4 | GPIO_PIN_5 |
GPIO_PIN_6 | GPIO_PIN_7);
/* SSI3 */
/*
* NOTE: TI-RTOS examples configure pins PD0 & PD1 for SSI3 or I2C3. Thus,
* a conflict occurs when the I2C & SPI drivers are used simultaneously in
* an application. Modify the pin mux settings in this file and resolve the
* conflict before running your the application.
*/
SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI3);
GPIOPinConfigure(GPIO_PD0_SSI3CLK);
GPIOPinConfigure(GPIO_PD1_SSI3FSS);
GPIOPinConfigure(GPIO_PD2_SSI3RX);
GPIOPinConfigure(GPIO_PD3_SSI3TX);
GPIOPinTypeSSI(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1 |
GPIO_PIN_2 | GPIO_PIN_3);
EK_TM4C123GXL_initDMA();
SPI_init();
}
/*
* =============================== UART ===============================
*/
/* Place into subsections to allow the TI linker to remove items properly */
#if defined(__TI_COMPILER_VERSION__)
#pragma DATA_SECTION(UART_config, ".const:UART_config")
#pragma DATA_SECTION(uartTivaHWAttrs, ".const:uartTivaHWAttrs")
#endif
#include <ti/drivers/UART.h>
#if TI_DRIVERS_UART_DMA
#include <ti/drivers/uart/UARTTivaDMA.h>
UARTTivaDMA_Object uartTivaObjects[EK_TM4C123GXL_UARTCOUNT];
const UARTTivaDMA_HWAttrs uartTivaHWAttrs[EK_TM4C123GXL_UARTCOUNT] = {
{
.baseAddr = UART0_BASE,
.intNum = INT_UART0,
.intPriority = (~0),
.rxChannelIndex = UDMA_CH8_UART0RX,
.txChannelIndex = UDMA_CH9_UART0TX,
},
{
.baseAddr = UART2_BASE,
.intNum = INT_UART2,
.intPriority = (~0),
.rxChannelIndex = UDMA_CH8_UART0RX,
.txChannelIndex = UDMA_CH9_UART0TX,
}
};
const UART_Config UART_config[] = {
{
.fxnTablePtr = &UARTTivaDMA_fxnTable,
.object = &uartTivaObjects[0],
.hwAttrs = &uartTivaHWAttrs[0]
},
{
.fxnTablePtr = &UARTTivaDMA_fxnTable,
.object = &uartTivaObjects[1],
.hwAttrs = &uartTivaHWAttrs[1]
},
{NULL, NULL, NULL}
};
#else
#include <ti/drivers/uart/UARTTiva.h>
UARTTiva_Object uartTivaObjects[EK_TM4C123GXL_UARTCOUNT];
unsigned char uartTivaRingBuffer[EK_TM4C123GXL_UARTCOUNT][32];
/* UART configuration structure */
const UARTTiva_HWAttrs uartTivaHWAttrs[EK_TM4C123GXL_UARTCOUNT] = {
{
.baseAddr = UART0_BASE,
.intNum = INT_UART0,
.intPriority = (~0),
.flowControl = UART_FLOWCONTROL_NONE,
.ringBufPtr = uartTivaRingBuffer[0],
.ringBufSize = sizeof(uartTivaRingBuffer[0])
},
{
.baseAddr = UART3_BASE,
.intNum = INT_UART3,
.intPriority = (~0),
.flowControl = UART_FLOWCONTROL_NONE,
.ringBufPtr = uartTivaRingBuffer[1],
.ringBufSize = sizeof(uartTivaRingBuffer[1])
}
};
const UART_Config UART_config[] = {
{
.fxnTablePtr = &UARTTiva_fxnTable,
.object = &uartTivaObjects[0],
.hwAttrs = &uartTivaHWAttrs[0]
},
{
.fxnTablePtr = &UARTTiva_fxnTable,
.object = &uartTivaObjects[1],
.hwAttrs = &uartTivaHWAttrs[1]
},
{NULL, NULL, NULL}
};
#endif /* TI_DRIVERS_UART_DMA */
/*
* ======== EK_TM4C123GXL_initUART ========
*/
void EK_TM4C123GXL_initUART(void)
{
/* Enable and configure the peripherals used by the uart. */
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
GPIOPinConfigure(GPIO_PA0_U0RX);
GPIOPinConfigure(GPIO_PA1_U0TX);
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
/* Enable UART 2 as well */
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART3);
GPIOPinConfigure(GPIO_PC6_U3RX);
GPIOPinConfigure(GPIO_PC7_U3TX);
GPIOPinTypeUART(GPIO_PORTC_BASE, GPIO_PIN_6 | GPIO_PIN_7);
/* Initialize the UART driver */
#if TI_DRIVERS_UART_DMA
EK_TM4C123GXL_initDMA();
#endif
UART_init();
}
/*
* =============================== USB ===============================
*/
/*
* ======== EK_TM4C123GXL_initUSB ========
* This function just turns on the USB
*/
void EK_TM4C123GXL_initUSB(EK_TM4C123GXL_USBMode usbMode)
{
/* Enable the USB peripheral and PLL */
SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0);
SysCtlUSBPLLEnable();
/* Setup pins for USB operation */
GPIOPinTypeUSBAnalog(GPIO_PORTD_BASE, GPIO_PIN_4 | GPIO_PIN_5);
if (usbMode == EK_TM4C123GXL_USBHOST) {
System_abort("USB host not supported\n");
}
}
/*
* =============================== Watchdog ===============================
*/
/* Place into subsections to allow the TI linker to remove items properly */
#if defined(__TI_COMPILER_VERSION__)
#pragma DATA_SECTION(Watchdog_config, ".const:Watchdog_config")
#pragma DATA_SECTION(watchdogTivaHWAttrs, ".const:watchdogTivaHWAttrs")
#endif
#include <ti/drivers/Watchdog.h>
#include <ti/drivers/watchdog/WatchdogTiva.h>
WatchdogTiva_Object watchdogTivaObjects[EK_TM4C123GXL_WATCHDOGCOUNT];
const WatchdogTiva_HWAttrs watchdogTivaHWAttrs[EK_TM4C123GXL_WATCHDOGCOUNT] = {
{
.baseAddr = WATCHDOG0_BASE,
.intNum = INT_WATCHDOG,
.intPriority = (~0),
.reloadValue = 80000000 // 1 second period at default CPU clock freq
},
};
const Watchdog_Config Watchdog_config[] = {
{
.fxnTablePtr = &WatchdogTiva_fxnTable,
.object = &watchdogTivaObjects[0],
.hwAttrs = &watchdogTivaHWAttrs[0]
},
{NULL, NULL, NULL},
};
/*
* ======== EK_TM4C123GXL_initWatchdog ========
*
* NOTE: To use the other watchdog timer with base address WATCHDOG1_BASE,
* an additional function call may need be made to enable PIOSC. Enabling
* WDOG1 does not do this. Enabling another peripheral that uses PIOSC
* such as ADC0 or SSI0, however, will do so. Example:
*
* SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
* SysCtlPeripheralEnable(SYSCTL_PERIPH_WDOG1);
*
* See the following forum post for more information:
* http://e2e.ti.com/support/microcontrollers/stellaris_arm_cortex-m3_microcontroller/f/471/p/176487/654390.aspx#654390
*/
void EK_TM4C123GXL_initWatchdog(void)
{
/* Enable peripherals used by Watchdog */
SysCtlPeripheralEnable(SYSCTL_PERIPH_WDOG0);
Watchdog_init();
}
/*
* =============================== WiFi ===============================
*/
/* Place into subsections to allow the TI linker to remove items properly */
#if defined(__TI_COMPILER_VERSION__)
#pragma DATA_SECTION(WiFi_config, ".const:WiFi_config")
#pragma DATA_SECTION(wiFiCC3100HWAttrs, ".const:wiFiCC3100HWAttrs")
#endif
#include <ti/drivers/WiFi.h>
#include <ti/drivers/wifi/WiFiCC3100.h>
WiFiCC3100_Object wiFiCC3100Objects[EK_TM4C123GXL_WIFICOUNT];
const WiFiCC3100_HWAttrs wiFiCC3100HWAttrs[EK_TM4C123GXL_WIFICOUNT] = {
{
.irqPort = GPIO_PORTB_BASE,
.irqPin = GPIO_PIN_2,
.irqIntNum = INT_GPIOB,
.csPort = GPIO_PORTE_BASE,
.csPin = GPIO_PIN_0,
.enPort = GPIO_PORTE_BASE,
.enPin = GPIO_PIN_4
}
};
const WiFi_Config WiFi_config[] = {
{
.fxnTablePtr = &WiFiCC3100_fxnTable,
.object = &wiFiCC3100Objects[0],
.hwAttrs = &wiFiCC3100HWAttrs[0]
},
{NULL,NULL, NULL},
};
/*
* ======== EK_TM4C123GXL_initWiFi ========
*/
void EK_TM4C123GXL_initWiFi(void)
{
/* Configure EN & CS pins to disable CC3100 */
GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_4);
GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_0, GPIO_PIN_0);
GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_4, 0);
/* Configure SSI2 for CC3100 */
SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI2);
GPIOPinConfigure(GPIO_PB4_SSI2CLK);
GPIOPinConfigure(GPIO_PB6_SSI2RX);
GPIOPinConfigure(GPIO_PB7_SSI2TX);
GPIOPinTypeSSI(GPIO_PORTB_BASE, GPIO_PIN_4 | GPIO_PIN_6 | GPIO_PIN_7);
/* Configure IRQ pin */
GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_2);
GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_2, GPIO_STRENGTH_2MA,
GPIO_PIN_TYPE_STD_WPD);
GPIOIntTypeSet(GPIO_PORTB_BASE, GPIO_PIN_2, GPIO_RISING_EDGE);
SPI_init();
EK_TM4C123GXL_initDMA();
WiFi_init();
}