Skip to content

Commit 52096ae

Browse files
Theoxiaoxiang781216
authored andcommitted
Add activation of SPI0 on arduino due
1 parent b53af56 commit 52096ae

File tree

4 files changed

+74
-0
lines changed

4 files changed

+74
-0
lines changed

boards/arm/sam34/arduino-due/include/board.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@
131131

132132
#define BOARD_FWS 4
133133

134+
/* Serial Peripheral Interface (SPI) */
135+
136+
#define GPIO_SPI0_SPCK GPIO_SPI0_SPCK_1
137+
#define GPIO_SPI0_CS (GPIO_OUTPUT | GPIO_CFG_DEFAULT | GPIO_OUTPUT_SET | GPIO_PORT_PIOC | GPIO_PIN21)
138+
134139
/* LED definitions **********************************************************/
135140

136141
/* There are three user-controllable LEDs on board the Arduino Due board:

boards/arm/sam34/arduino-due/src/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,8 @@ ifeq ($(CONFIG_BOARDCTL),y)
4949
CSRCS += sam_appinit.c
5050
endif
5151

52+
ifeq ($(CONFIG_SAM34_SPI0),y)
53+
CSRCS += sam_spidev.c
54+
endif
55+
5256
include $(TOPDIR)/boards/Board.mk

boards/arm/sam34/arduino-due/src/sam_bringup.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@
3030
#include <nuttx/board.h>
3131
#include <nuttx/fs/fs.h>
3232
#include <nuttx/leds/userled.h>
33+
#include <nuttx/spi/spi_transfer.h>
3334

3435
#include "arduino-due.h"
3536

3637
#include <arch/board/board.h>
38+
#include "sam_spi.h"
3739

3840
/****************************************************************************
3941
* Pre-processor Definitions
@@ -138,6 +140,23 @@ int sam_bringup(void)
138140
}
139141
#endif
140142

143+
#ifdef CONFIG_SAM34_SPI0
144+
sam_configgpio(GPIO_SPI0_CS);
145+
146+
struct spi_dev_s *spi;
147+
spi = sam_spibus_initialize(0);
148+
149+
if (!spi)
150+
{
151+
syslog(LOG_ERR, "ERROR: Failed to initialize SPI port 0\n");
152+
return -1;
153+
}
154+
else
155+
{
156+
spi_register(spi, 0);
157+
}
158+
#endif
159+
141160
UNUSED(ret);
142161
return OK;
143162
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/****************************************************************************
2+
* boards/arm/sam34/arduino-due/src/sam_spidev.c
3+
*
4+
* Licensed to the Apache Software Foundation (ASF) under one or more
5+
* contributor license agreements. See the NOTICE file distributed with
6+
* this work for additional information regarding copyright ownership. The
7+
* ASF licenses this file to you under the Apache License, Version 2.0 (the
8+
* "License"); you may not use this file except in compliance with the
9+
* License. You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16+
* License for the specific language governing permissions and limitations
17+
* under the License.
18+
*
19+
****************************************************************************/
20+
21+
/****************************************************************************
22+
* Included Files
23+
****************************************************************************/
24+
25+
#include <debug.h>
26+
#include <arch/board/board.h>
27+
28+
#include "sam_spi.h"
29+
#include "hardware/sam3x_pinmap.h"
30+
31+
/****************************************************************************
32+
* Public Functions
33+
****************************************************************************/
34+
35+
void sam_spi0select(uint32_t devid, bool selected)
36+
{
37+
spiinfo("devid: %08x CS: %s\n",
38+
(unsigned int)devid, selected ? "assert" : "de-assert");
39+
sam_gpiowrite(GPIO_SPI0_CS, !selected);
40+
}
41+
42+
uint8_t sam_spi0status(struct spi_dev_s *dev, uint32_t devid)
43+
{
44+
spiinfo("Returning nothing\n");
45+
return 0;
46+
}

0 commit comments

Comments
 (0)