aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-09-02 00:05:13 +0100
committerDamien George <damien.p.george@gmail.com>2014-09-02 00:05:13 +0100
commita2ee194612fee8b6c0924f999acf8c41f4207e8d (patch)
tree160750dafb972d62775c2cc17e77b6e3e4fe2c56
parent6f70542d82c529173161275b0a21f090fecfddb2 (diff)
cc3k: Change configurability of the CC3000 module.iabdalkader-cc3k-update
Optional compiling of the CC3K module is moved from mpconfigboard.h. To enable compiling of the module, set the MICROPY_PY_CC3K variable, either on the command line (make MICROPY_PY_CC3K=1) on in the mpconfigport.mk file. It is enabled by default. Setting of the SPI and pins for the CC3K module is now done dynamically by the arguments to wlan.init().
-rw-r--r--stmhal/Makefile41
-rw-r--r--stmhal/boards/HYDRABUS/mpconfigboard.h1
-rw-r--r--stmhal/boards/NETDUINO_PLUS_2/mpconfigboard.h1
-rw-r--r--stmhal/boards/PYBV10/mpconfigboard.h8
-rw-r--r--stmhal/boards/PYBV3/mpconfigboard.h1
-rw-r--r--stmhal/boards/PYBV4/mpconfigboard.h1
-rw-r--r--stmhal/boards/STM32F4DISC/mpconfigboard.h8
-rw-r--r--stmhal/cc3k/inc/ccspi.h4
-rw-r--r--stmhal/cc3k/src/cc3000_common.c3
-rw-r--r--stmhal/cc3k/src/ccspi.c88
-rw-r--r--stmhal/cc3k/src/evnt_handler.c3
-rw-r--r--stmhal/cc3k/src/hci.c3
-rw-r--r--stmhal/cc3k/src/inet_ntop.c4
-rw-r--r--stmhal/cc3k/src/inet_pton.c3
-rw-r--r--stmhal/cc3k/src/netapp.c3
-rw-r--r--stmhal/cc3k/src/nvmem.c3
-rw-r--r--stmhal/cc3k/src/patch_prog.c4
-rw-r--r--stmhal/cc3k/src/security.c3
-rw-r--r--stmhal/cc3k/src/socket.c3
-rw-r--r--stmhal/cc3k/src/wlan.c3
-rw-r--r--stmhal/modselect.c9
-rw-r--r--stmhal/modsocket.c10
-rw-r--r--stmhal/modwlan.c27
-rw-r--r--stmhal/mpconfigport.h25
-rw-r--r--stmhal/mpconfigport.mk3
-rw-r--r--stmhal/spi.c8
-rw-r--r--stmhal/spi.h1
27 files changed, 119 insertions, 152 deletions
diff --git a/stmhal/Makefile b/stmhal/Makefile
index 8089abb96..1943277d0 100644
--- a/stmhal/Makefile
+++ b/stmhal/Makefile
@@ -22,7 +22,6 @@ HAL_DIR=hal
USBDEV_DIR=usbdev
#USBHOST_DIR=usbhost
FATFS_DIR=fatfs
-CC3K_DIR=cc3k
DFU=../tools/dfu.py
# may need to prefix dfu-util with sudo
DFU_UTIL ?= dfu-util
@@ -39,7 +38,6 @@ INC += -I$(HAL_DIR)/inc
INC += -I$(USBDEV_DIR)/core/inc -I$(USBDEV_DIR)/class/cdc_msc_hid/inc
#INC += -I$(USBHOST_DIR)
INC += -I$(FATFS_DIR)/src
-INC += -I$(CC3K_DIR)/inc
CFLAGS_CORTEX_M4 = -mthumb -mtune=cortex-m4 -mabi=aapcs-linux -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -fsingle-precision-constant -Wdouble-promotion
CFLAGS = $(INC) -Wall -Werror -ansi -std=gnu99 -nostdlib $(CFLAGS_MOD) $(CFLAGS_CORTEX_M4) $(COPT)
@@ -119,9 +117,6 @@ SRC_C = \
servo.c \
dac.c \
adc.c \
- modwlan.c \
- modsocket.c \
- modselect.c \
SRC_S = \
startup_stm32f40xx.s \
@@ -186,7 +181,28 @@ SRC_FATFS = $(addprefix $(FATFS_DIR)/src/,\
option/ccsbcs.c \
)
-SRC_CC3K = $(addprefix $(CC3K_DIR)/src/,\
+ifeq ($(MICROPY_PY_WIZNET5K),1)
+WIZNET5K_DIR=drivers/wiznet5k
+INC += -I$(TOP)/$(WIZNET5K_DIR)
+CFLAGS_MOD += -DMICROPY_PY_WIZNET5K=1
+SRC_MOD += modwiznet5k.c
+SRC_MOD += $(addprefix $(WIZNET5K_DIR)/,\
+ ethernet/w5200/w5200.c \
+ ethernet/wizchip_conf.c \
+ ethernet/socket.c \
+ internet/dns/dns.c \
+ )
+endif
+
+ifeq ($(MICROPY_PY_CC3K),1)
+CC3K_DIR=cc3k
+INC += -I$(CC3K_DIR)/inc
+CFLAGS_MOD += -DMICROPY_PY_CC3K=1
+SRC_MOD += \
+ modwlan.c \
+ modsocket.c \
+ modselect.c
+SRC_MOD += $(addprefix $(CC3K_DIR)/src/,\
cc3000_common.c \
evnt_handler.c \
hci.c \
@@ -202,18 +218,6 @@ SRC_CC3K = $(addprefix $(CC3K_DIR)/src/,\
# patch.c \
# patch_prog.c \
)
-
-ifeq ($(MICROPY_PY_WIZNET5K),1)
-WIZNET5K_DIR=drivers/wiznet5k
-INC += -I$(TOP)/$(WIZNET5K_DIR)
-CFLAGS_MOD += -DMICROPY_PY_WIZNET5K=1
-SRC_MOD += modwiznet5k.c
-SRC_MOD += $(addprefix $(WIZNET5K_DIR)/,\
- ethernet/w5200/w5200.c \
- ethernet/wizchip_conf.c \
- ethernet/socket.c \
- internet/dns/dns.c \
- )
endif
OBJ =
@@ -224,7 +228,6 @@ OBJ += $(addprefix $(BUILD)/, $(SRC_S:.s=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_HAL:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_USBDEV:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_FATFS:.c=.o))
-OBJ += $(addprefix $(BUILD)/, $(SRC_CC3K:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_MOD:.c=.o))
OBJ += $(BUILD)/pins_$(BOARD).o
diff --git a/stmhal/boards/HYDRABUS/mpconfigboard.h b/stmhal/boards/HYDRABUS/mpconfigboard.h
index db49434b5..18d1df19d 100644
--- a/stmhal/boards/HYDRABUS/mpconfigboard.h
+++ b/stmhal/boards/HYDRABUS/mpconfigboard.h
@@ -16,7 +16,6 @@
#define MICROPY_HW_ENABLE_I2C1 (1)
#define MICROPY_HW_ENABLE_SPI1 (1)
#define MICROPY_HW_ENABLE_SPI3 (1)
-#define MICROPY_HW_ENABLE_CC3K (0)
// USRSW/UBTN (Needs Jumper UBTN) is pulled low. Pressing the button makes the input go high.
#define MICROPY_HW_USRSW_PIN (pin_A0)
diff --git a/stmhal/boards/NETDUINO_PLUS_2/mpconfigboard.h b/stmhal/boards/NETDUINO_PLUS_2/mpconfigboard.h
index 2679aee57..c32e0d29e 100644
--- a/stmhal/boards/NETDUINO_PLUS_2/mpconfigboard.h
+++ b/stmhal/boards/NETDUINO_PLUS_2/mpconfigboard.h
@@ -20,7 +20,6 @@
#define MICROPY_HW_ENABLE_I2C1 (0)
#define MICROPY_HW_ENABLE_SPI1 (0)
#define MICROPY_HW_ENABLE_SPI3 (0)
-#define MICROPY_HW_ENABLE_CC3K (0)
// USRSW is pulled low. Pressing the button makes the input go high.
#define MICROPY_HW_USRSW_PIN (pin_B11)
diff --git a/stmhal/boards/PYBV10/mpconfigboard.h b/stmhal/boards/PYBV10/mpconfigboard.h
index fb522b5cb..977fabe40 100644
--- a/stmhal/boards/PYBV10/mpconfigboard.h
+++ b/stmhal/boards/PYBV10/mpconfigboard.h
@@ -17,7 +17,6 @@
#define MICROPY_HW_ENABLE_I2C1 (1)
#define MICROPY_HW_ENABLE_SPI1 (1)
#define MICROPY_HW_ENABLE_SPI3 (0)
-#define MICROPY_HW_ENABLE_CC3K (1)
// USRSW has no pullup or pulldown, and pressing the switch makes the input go low
#define MICROPY_HW_USRSW_PIN (pin_B3)
@@ -38,10 +37,3 @@
#define MICROPY_HW_SDCARD_DETECT_PIN (pin_A8)
#define MICROPY_HW_SDCARD_DETECT_PULL (GPIO_PULLUP)
#define MICROPY_HW_SDCARD_DETECT_PRESENT (GPIO_PIN_RESET)
-
-// CC3K WLAN
-#define MICROPY_HW_WLAN_PIN_CS (pin_B12) // Y5
-#define MICROPY_HW_WLAN_PIN_EN (pin_B9) // Y4
-#define MICROPY_HW_WLAN_PIN_IRQ (pin_B8) // Y3
-#define MICROPY_HW_WLAN_SPI_HANDLE (SPIHandle2) // SPI on Y position (Y6=B13=SCK, Y7=B14=MISO, Y8=B15=MOSI)
-#define MICROPY_HW_WLAN_IRQ_LINE (8) // B8 on line 8
diff --git a/stmhal/boards/PYBV3/mpconfigboard.h b/stmhal/boards/PYBV3/mpconfigboard.h
index 43d860a0c..048812748 100644
--- a/stmhal/boards/PYBV3/mpconfigboard.h
+++ b/stmhal/boards/PYBV3/mpconfigboard.h
@@ -16,7 +16,6 @@
#define MICROPY_HW_ENABLE_I2C1 (1)
#define MICROPY_HW_ENABLE_SPI1 (1)
#define MICROPY_HW_ENABLE_SPI3 (0)
-#define MICROPY_HW_ENABLE_CC3K (0)
// USRSW has no pullup or pulldown, and pressing the switch makes the input go low
#define MICROPY_HW_USRSW_PIN (pin_A13)
diff --git a/stmhal/boards/PYBV4/mpconfigboard.h b/stmhal/boards/PYBV4/mpconfigboard.h
index a278dea9f..5bb7f03b2 100644
--- a/stmhal/boards/PYBV4/mpconfigboard.h
+++ b/stmhal/boards/PYBV4/mpconfigboard.h
@@ -16,7 +16,6 @@
#define MICROPY_HW_ENABLE_I2C1 (1)
#define MICROPY_HW_ENABLE_SPI1 (1)
#define MICROPY_HW_ENABLE_SPI3 (0)
-#define MICROPY_HW_ENABLE_CC3K (0)
// USRSW has no pullup or pulldown, and pressing the switch makes the input go low
#define MICROPY_HW_USRSW_PIN (pin_B3)
diff --git a/stmhal/boards/STM32F4DISC/mpconfigboard.h b/stmhal/boards/STM32F4DISC/mpconfigboard.h
index 2f8a8b8fa..2e2769477 100644
--- a/stmhal/boards/STM32F4DISC/mpconfigboard.h
+++ b/stmhal/boards/STM32F4DISC/mpconfigboard.h
@@ -16,7 +16,6 @@
#define MICROPY_HW_ENABLE_I2C1 (1)
#define MICROPY_HW_ENABLE_SPI1 (1)
#define MICROPY_HW_ENABLE_SPI3 (0)
-#define MICROPY_HW_ENABLE_CC3K (0)
// USRSW is pulled low. Pressing the button makes the input go high.
#define MICROPY_HW_USRSW_PIN (pin_A0)
@@ -32,10 +31,3 @@
#define MICROPY_HW_LED_OTYPE (GPIO_MODE_OUTPUT_PP)
#define MICROPY_HW_LED_ON(pin) (pin->gpio->BSRRL = pin->pin_mask)
#define MICROPY_HW_LED_OFF(pin) (pin->gpio->BSRRH = pin->pin_mask)
-
-// CC3K WLAN
-#define MICROPY_HW_WLAN_PIN_CS (pin_A15)
-#define MICROPY_HW_WLAN_PIN_EN (pin_B10)
-#define MICROPY_HW_WLAN_PIN_IRQ (pin_B11)
-#define MICROPY_HW_WLAN_SPI_HANDLE (SPIHandle2)
-#define MICROPY_HW_WLAN_IRQ_LINE (11)
diff --git a/stmhal/cc3k/inc/ccspi.h b/stmhal/cc3k/inc/ccspi.h
index eb0e5d385..4f5e2a2bb 100644
--- a/stmhal/cc3k/inc/ccspi.h
+++ b/stmhal/cc3k/inc/ccspi.h
@@ -56,6 +56,10 @@ extern unsigned char wlan_tx_buffer[];
// Prototypes for the APIs.
//
//*****************************************************************************
+
+// the arguments must be of type pin_obj_t* and SPI_HandleTypeDef*
+extern void SpiInit(void *spi, const void *pin_cs, const void *pin_en, const void *pin_irq);
+
extern void SpiOpen(gcSpiHandleRx pfRxHandler);
extern void SpiClose(void);
extern void SpiPauseSpi(void);
diff --git a/stmhal/cc3k/src/cc3000_common.c b/stmhal/cc3k/src/cc3000_common.c
index 7759cb20f..b4c87848c 100644
--- a/stmhal/cc3k/src/cc3000_common.c
+++ b/stmhal/cc3k/src/cc3000_common.c
@@ -43,8 +43,6 @@
* Include files
*
*****************************************************************************/
-#include "mpconfigport.h"
-#if MICROPY_HW_ENABLE_CC3K
#include "cc3000_common.h"
#include "socket.h"
@@ -164,4 +162,3 @@ UINT32 STREAM_TO_UINT32_f(CHAR* p, UINT16 offset)
//! @}
//
//*****************************************************************************
-#endif // MICROPY_HW_ENABLE_CC3K
diff --git a/stmhal/cc3k/src/ccspi.c b/stmhal/cc3k/src/ccspi.c
index 0352c6e40..2abc637fe 100644
--- a/stmhal/cc3k/src/ccspi.c
+++ b/stmhal/cc3k/src/ccspi.c
@@ -31,8 +31,6 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*****************************************************************************/
-#include "mpconfigport.h"
-#if MICROPY_HW_ENABLE_CC3K
#include <string.h>
@@ -44,7 +42,6 @@
#include "obj.h"
#include "runtime.h"
#include "pin.h"
-#include "genhdr/pins.h"
#include "led.h"
#include "extint.h"
#include "spi.h"
@@ -58,14 +55,14 @@
#define DEBUG_printf(args...) (void)0
#endif
-#define PIN_CS MICROPY_HW_WLAN_PIN_CS
-#define PIN_EN MICROPY_HW_WLAN_PIN_EN
-#define PIN_IRQ MICROPY_HW_WLAN_PIN_IRQ
-#define SPI_HANDLE MICROPY_HW_WLAN_SPI_HANDLE
-#define IRQ_LINE MICROPY_HW_WLAN_IRQ_LINE
+// these need to be set to valid values before anything in this file will work
+STATIC SPI_HandleTypeDef *SPI_HANDLE = NULL;
+STATIC const pin_obj_t *PIN_CS = NULL;
+STATIC const pin_obj_t *PIN_EN = NULL;
+STATIC const pin_obj_t *PIN_IRQ = NULL;
-#define CS_LOW() HAL_GPIO_WritePin(PIN_CS.gpio, PIN_CS.pin_mask, GPIO_PIN_RESET)
-#define CS_HIGH() HAL_GPIO_WritePin(PIN_CS.gpio, PIN_CS.pin_mask, GPIO_PIN_SET)
+#define CS_LOW() HAL_GPIO_WritePin(PIN_CS->gpio, PIN_CS->pin_mask, GPIO_PIN_RESET)
+#define CS_HIGH() HAL_GPIO_WritePin(PIN_CS->gpio, PIN_CS->pin_mask, GPIO_PIN_SET)
#define READ 3
#define WRITE 1
@@ -106,10 +103,19 @@ tSpiInformation sSpiInformation;
char spi_buffer[CC3000_RX_BUFFER_SIZE];
unsigned char wlan_tx_buffer[CC3000_TX_BUFFER_SIZE];
-static const mp_obj_fun_native_t irq_callback_obj;
+STATIC const mp_obj_fun_builtin_t irq_callback_obj;
void SpiWriteDataSynchronous(unsigned char *data, unsigned short size);
void SpiReadDataSynchronous(unsigned char *data, unsigned short size);
+// set the pins to use to communicate with the CC3000
+// the arguments must be of type pin_obj_t* and SPI_HandleTypeDef*
+void SpiInit(void *spi, const void *pin_cs, const void *pin_en, const void *pin_irq) {
+ SPI_HANDLE = spi;
+ PIN_CS = pin_cs;
+ PIN_EN = pin_en;
+ PIN_IRQ = pin_irq;
+}
+
void SpiClose(void)
{
if (sSpiInformation.pRxPacket) {
@@ -118,7 +124,7 @@ void SpiClose(void)
tSLInformation.WlanInterruptDisable();
- //HAL_SPI_DeInit(&SPI_HANDLE);
+ //HAL_SPI_DeInit(SPI_HANDLE);
}
void SpiOpen(gcSpiHandleRx pfRxHandler)
@@ -136,18 +142,18 @@ void SpiOpen(gcSpiHandleRx pfRxHandler)
wlan_tx_buffer[CC3000_TX_BUFFER_SIZE - 1] = CC3000_BUFFER_MAGIC_NUMBER;
/* SPI configuration */
- SPI_HANDLE.Init.Mode = SPI_MODE_MASTER;
- SPI_HANDLE.Init.Direction = SPI_DIRECTION_2LINES;
- SPI_HANDLE.Init.DataSize = SPI_DATASIZE_8BIT;
- SPI_HANDLE.Init.CLKPolarity = SPI_POLARITY_LOW;
- SPI_HANDLE.Init.CLKPhase = SPI_PHASE_2EDGE;
- SPI_HANDLE.Init.NSS = SPI_NSS_SOFT;
- SPI_HANDLE.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8;
- SPI_HANDLE.Init.FirstBit = SPI_FIRSTBIT_MSB;
- SPI_HANDLE.Init.TIMode = SPI_TIMODE_DISABLED;
- SPI_HANDLE.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;
- SPI_HANDLE.Init.CRCPolynomial = 7;
- spi_init(&SPI_HANDLE);
+ SPI_HANDLE->Init.Mode = SPI_MODE_MASTER;
+ SPI_HANDLE->Init.Direction = SPI_DIRECTION_2LINES;
+ SPI_HANDLE->Init.DataSize = SPI_DATASIZE_8BIT;
+ SPI_HANDLE->Init.CLKPolarity = SPI_POLARITY_LOW;
+ SPI_HANDLE->Init.CLKPhase = SPI_PHASE_2EDGE;
+ SPI_HANDLE->Init.NSS = SPI_NSS_SOFT;
+ SPI_HANDLE->Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8;
+ SPI_HANDLE->Init.FirstBit = SPI_FIRSTBIT_MSB;
+ SPI_HANDLE->Init.TIMode = SPI_TIMODE_DISABLED;
+ SPI_HANDLE->Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;
+ SPI_HANDLE->Init.CRCPolynomial = 7;
+ spi_init(SPI_HANDLE);
// configure wlan CS and EN pins
GPIO_InitTypeDef GPIO_InitStructure;
@@ -156,48 +162,48 @@ void SpiOpen(gcSpiHandleRx pfRxHandler)
GPIO_InitStructure.Pull = GPIO_NOPULL;
GPIO_InitStructure.Alternate = 0;
- GPIO_InitStructure.Pin = PIN_CS.pin_mask;
- HAL_GPIO_Init(PIN_CS.gpio, &GPIO_InitStructure);
+ GPIO_InitStructure.Pin = PIN_CS->pin_mask;
+ HAL_GPIO_Init(PIN_CS->gpio, &GPIO_InitStructure);
- GPIO_InitStructure.Pin = PIN_EN.pin_mask;
- HAL_GPIO_Init(PIN_EN.gpio, &GPIO_InitStructure);
+ GPIO_InitStructure.Pin = PIN_EN->pin_mask;
+ HAL_GPIO_Init(PIN_EN->gpio, &GPIO_InitStructure);
- HAL_GPIO_WritePin(PIN_CS.gpio, PIN_CS.pin_mask, GPIO_PIN_SET);
- HAL_GPIO_WritePin(PIN_EN.gpio, PIN_EN.pin_mask, GPIO_PIN_RESET);
+ HAL_GPIO_WritePin(PIN_CS->gpio, PIN_CS->pin_mask, GPIO_PIN_SET);
+ HAL_GPIO_WritePin(PIN_EN->gpio, PIN_EN->pin_mask, GPIO_PIN_RESET);
/* do a dummy read, this ensures SCLK is low before
actual communications start, it might be required */
CS_LOW();
uint8_t buf[1];
- HAL_SPI_Receive(&SPI_HANDLE, buf, sizeof(buf), SPI_TIMEOUT);
+ HAL_SPI_Receive(SPI_HANDLE, buf, sizeof(buf), SPI_TIMEOUT);
CS_HIGH();
// register EXTI
- extint_register((mp_obj_t)&PIN_IRQ, GPIO_MODE_IT_FALLING, GPIO_PULLUP, (mp_obj_t)&irq_callback_obj, true, NULL);
- extint_enable(IRQ_LINE);
+ extint_register((mp_obj_t)PIN_IRQ, GPIO_MODE_IT_FALLING, GPIO_PULLUP, (mp_obj_t)&irq_callback_obj, true, NULL);
+ extint_enable(PIN_IRQ->pin);
- DEBUG_printf("SpiOpen finished; IRQ.pin=%d IRQ_LINE=%d\n", PIN_IRQ.pin, IRQ_LINE);
+ DEBUG_printf("SpiOpen finished; IRQ.pin=%d IRQ_LINE=%d\n", PIN_IRQ->pin, PIN_IRQ->pin);
}
void SpiPauseSpi(void)
{
- extint_disable(IRQ_LINE);
+ extint_disable(PIN_IRQ->pin);
}
void SpiResumeSpi(void)
{
- extint_enable(IRQ_LINE);
+ extint_enable(PIN_IRQ->pin);
}
long ReadWlanInterruptPin(void)
{
- return HAL_GPIO_ReadPin(PIN_IRQ.gpio, PIN_IRQ.pin_mask);
+ return HAL_GPIO_ReadPin(PIN_IRQ->gpio, PIN_IRQ->pin_mask);
}
void WriteWlanPin(unsigned char val)
{
- HAL_GPIO_WritePin(PIN_EN.gpio, PIN_EN.pin_mask,
+ HAL_GPIO_WritePin(PIN_EN->gpio, PIN_EN->pin_mask,
(WLAN_ENABLE)? GPIO_PIN_SET:GPIO_PIN_RESET);
}
@@ -306,7 +312,7 @@ void SpiWriteDataSynchronous(unsigned char *data, unsigned short size)
{
DEBUG_printf("SpiWriteDataSynchronous(data=%p [%x %x %x %x], size=%u)\n", data, data[0], data[1], data[2], data[3], size);
__disable_irq();
- if (HAL_SPI_TransmitReceive(&SPI_HANDLE, data, data, size, SPI_TIMEOUT) != HAL_OK) {
+ if (HAL_SPI_TransmitReceive(SPI_HANDLE, data, data, size, SPI_TIMEOUT) != HAL_OK) {
//BREAK();
}
__enable_irq();
@@ -317,7 +323,7 @@ void SpiReadDataSynchronous(unsigned char *data, unsigned short size)
{
memset(data, READ, size);
__disable_irq();
- if (HAL_SPI_TransmitReceive(&SPI_HANDLE, data, data, size, SPI_TIMEOUT) != HAL_OK) {
+ if (HAL_SPI_TransmitReceive(SPI_HANDLE, data, data, size, SPI_TIMEOUT) != HAL_OK) {
//BREAK();
}
__enable_irq();
@@ -453,5 +459,3 @@ STATIC mp_obj_t irq_callback(mp_obj_t line)
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(irq_callback_obj, irq_callback);
-
-#endif // MICROPY_HW_ENABLE_CC3K
diff --git a/stmhal/cc3k/src/evnt_handler.c b/stmhal/cc3k/src/evnt_handler.c
index 2733408b7..80f34e469 100644
--- a/stmhal/cc3k/src/evnt_handler.c
+++ b/stmhal/cc3k/src/evnt_handler.c
@@ -42,8 +42,6 @@
//******************************************************************************
// INCLUDE FILES
//******************************************************************************
-#include "mpconfigport.h"
-#if MICROPY_HW_ENABLE_CC3K
#include "cc3000_common.h"
#include "string.h"
@@ -849,4 +847,3 @@ void SimpleLinkWaitData(UINT8 *pBuf, UINT8 *from, UINT8 *fromlen)
//! @}
//
//*****************************************************************************
-#endif // MICROPY_HW_ENABLE_CC3K
diff --git a/stmhal/cc3k/src/hci.c b/stmhal/cc3k/src/hci.c
index d476b3b33..4391692b8 100644
--- a/stmhal/cc3k/src/hci.c
+++ b/stmhal/cc3k/src/hci.c
@@ -39,8 +39,6 @@
//! @{
//
//*****************************************************************************
-#include "mpconfigport.h"
-#if MICROPY_HW_ENABLE_CC3K
#include <string.h>
#include "cc3000_common.h"
@@ -225,4 +223,3 @@ void hci_patch_send(UINT8 ucOpcode, UINT8 *pucBuff, CHAR *patch, UINT16 usDataLe
//
//
//*****************************************************************************
-#endif // MICROPY_HW_ENABLE_CC3K
diff --git a/stmhal/cc3k/src/inet_ntop.c b/stmhal/cc3k/src/inet_ntop.c
index 1d03c82b0..1b7e01a23 100644
--- a/stmhal/cc3k/src/inet_ntop.c
+++ b/stmhal/cc3k/src/inet_ntop.c
@@ -15,9 +15,6 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#include "mpconfigport.h"
-#if MICROPY_HW_ENABLE_CC3K
-
#include <std.h>
#include <string.h>
#include "cc3000_common.h"
@@ -197,4 +194,3 @@ char *inet_ntop(int af, const void *src, char *buf, size_t size)
return NULL;
}
}
-#endif // MICROPY_HW_ENABLE_CC3K
diff --git a/stmhal/cc3k/src/inet_pton.c b/stmhal/cc3k/src/inet_pton.c
index 8193d173a..88c785866 100644
--- a/stmhal/cc3k/src/inet_pton.c
+++ b/stmhal/cc3k/src/inet_pton.c
@@ -15,8 +15,6 @@
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
-#include "mpconfigport.h"
-#if MICROPY_HW_ENABLE_CC3K
#include <string.h>
#include "cc3000_common.h"
@@ -216,4 +214,3 @@ static int inet_pton6(const char *src, unsigned char *dst)
return (1);
}
#endif /* ENABLE_IPV6 */
-#endif // MICROPY_HW_ENABLE_CC3K
diff --git a/stmhal/cc3k/src/netapp.c b/stmhal/cc3k/src/netapp.c
index a0f75894d..a6f60feda 100644
--- a/stmhal/cc3k/src/netapp.c
+++ b/stmhal/cc3k/src/netapp.c
@@ -32,8 +32,6 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*****************************************************************************/
-#include "mpconfigport.h"
-#if MICROPY_HW_ENABLE_CC3K
#include <string.h>
#include "netapp.h"
@@ -459,4 +457,3 @@ INT32 netapp_set_debug_level(UINT32 ulLevel)
}
#endif
-#endif // MICROPY_HW_ENABLE_CC3K
diff --git a/stmhal/cc3k/src/nvmem.c b/stmhal/cc3k/src/nvmem.c
index 4897ab3a6..c6e170a74 100644
--- a/stmhal/cc3k/src/nvmem.c
+++ b/stmhal/cc3k/src/nvmem.c
@@ -39,8 +39,6 @@
//! @{
//
//*****************************************************************************
-#include "mpconfigport.h"
-#if MICROPY_HW_ENABLE_CC3K
#include <string.h>
#include "nvmem.h"
@@ -334,4 +332,3 @@ INT32 nvmem_create_entry(UINT32 ulFileId, UINT32 ulNewLen)
//! @}
//
//*****************************************************************************
-#endif // MICROPY_HW_ENABLE_CC3K
diff --git a/stmhal/cc3k/src/patch_prog.c b/stmhal/cc3k/src/patch_prog.c
index cda312036..fd128928f 100644
--- a/stmhal/cc3k/src/patch_prog.c
+++ b/stmhal/cc3k/src/patch_prog.c
@@ -1,6 +1,3 @@
-#include "mpconfigport.h"
-#if MICROPY_HW_ENABLE_CC3K
-
#include <stdio.h>
#include <string.h>
#include "cc3000_common.h"
@@ -415,4 +412,3 @@ void patch_prog_start()
// Patch update done
printf("All done, call wlan.patch_version()\n");
}
-#endif // MICROPY_HW_ENABLE_CC3K
diff --git a/stmhal/cc3k/src/security.c b/stmhal/cc3k/src/security.c
index e2ddb32da..62b4f8813 100644
--- a/stmhal/cc3k/src/security.c
+++ b/stmhal/cc3k/src/security.c
@@ -39,8 +39,6 @@
//! @{
//
//*****************************************************************************
-#include "mpconfigport.h"
-#if MICROPY_HW_ENABLE_CC3K
#include "security.h"
@@ -530,4 +528,3 @@ INT32 aes_write_key(UINT8 *key)
//! @}
//
//*****************************************************************************
-#endif // MICROPY_HW_ENABLE_CC3K
diff --git a/stmhal/cc3k/src/socket.c b/stmhal/cc3k/src/socket.c
index ea7e59799..bcc608e5f 100644
--- a/stmhal/cc3k/src/socket.c
+++ b/stmhal/cc3k/src/socket.c
@@ -39,8 +39,6 @@
//! @{
//
//*****************************************************************************
-#include "mpconfigport.h"
-#if MICROPY_HW_ENABLE_CC3K
#include <string.h>
#include <stdlib.h>
@@ -1182,4 +1180,3 @@ UINT16 getmssvalue (INT32 sd)
return ret;
}
-#endif // MICROPY_HW_ENABLE_CC3K
diff --git a/stmhal/cc3k/src/wlan.c b/stmhal/cc3k/src/wlan.c
index ff010519f..0514d1150 100644
--- a/stmhal/cc3k/src/wlan.c
+++ b/stmhal/cc3k/src/wlan.c
@@ -39,8 +39,6 @@
//! @{
//
//*****************************************************************************
-#include "mpconfigport.h"
-#if MICROPY_HW_ENABLE_CC3K
#include <string.h>
#include "wlan.h"
@@ -1252,4 +1250,3 @@ INT32 wlan_smart_config_process()
//! @}
//
//*****************************************************************************
-#endif // MICROPY_HW_ENABLE_CC3K
diff --git a/stmhal/modselect.c b/stmhal/modselect.c
index 6213b4b2d..1c4ae0845 100644
--- a/stmhal/modselect.c
+++ b/stmhal/modselect.c
@@ -10,15 +10,8 @@
#include "portmodules.h"
#include "hci.h"
-#include "ccspi.h"
-#include "wlan.h"
#include "socket.h"
-#include "nvmem.h"
#include "netapp.h"
-#include "evnt_handler.h"
-#include "patch_prog.h"
-
-#if MICROPY_HW_ENABLE_CC3K
#define MP_ASSERT_TYPE(obj, type) \
do { \
@@ -147,5 +140,3 @@ const mp_obj_module_t select_module = {
.name = MP_QSTR_select,
.globals = (mp_obj_dict_t*)&select_module_globals,
};
-
-#endif // MICROPY_HW_ENABLE_CC3K
diff --git a/stmhal/modsocket.c b/stmhal/modsocket.c
index 1b7f0d28f..893d0393f 100644
--- a/stmhal/modsocket.c
+++ b/stmhal/modsocket.c
@@ -16,18 +16,10 @@
#include "portmodules.h"
#include "hci.h"
-#include "ccspi.h"
-#include "wlan.h"
#include "socket.h"
-#include "nvmem.h"
-#include "netapp.h"
-#include "evnt_handler.h"
-#include "patch_prog.h"
#include "inet_ntop.h"
#include "inet_pton.h"
-#if MICROPY_HW_ENABLE_CC3K
-
#define EPIPE (32)
#define MAX_FD (8)
#define MAX_ADDRSTRLEN (128)
@@ -360,5 +352,3 @@ const mp_obj_module_t socket_module = {
.name = MP_QSTR_socket,
.globals = (mp_obj_dict_t*)&socket_module_globals,
};
-
-#endif // MICROPY_HW_ENABLE_CC3K
diff --git a/stmhal/modwlan.c b/stmhal/modwlan.c
index 6dedfc90e..ca3e539aa 100644
--- a/stmhal/modwlan.c
+++ b/stmhal/modwlan.c
@@ -10,6 +10,9 @@
#include "objtuple.h"
#include "runtime.h"
#include "portmodules.h"
+#include "pin.h"
+#include "genhdr/pins.h"
+#include "spi.h"
#include "hci.h"
#include "ccspi.h"
@@ -18,8 +21,6 @@
#include "netapp.h"
#include "patch_prog.h"
-#if MICROPY_HW_ENABLE_CC3K
-
#define IS_WLAN_SEC(sec) \
(sec>WLAN_SEC_UNSEC && sec<=WLAN_SEC_WPA2)
#define MAX_PACKET_LENGTH (1024)
@@ -56,7 +57,23 @@ STATIC void sWlanCallback(long lEventType, char * data, unsigned char length) {
}
}
-STATIC mp_obj_t modwlan_init(void) {
+/// \function init(spi, pin_cs, pin_en, pin_irq)
+/// Initialise the CC3000 using the given SPI bus and pins.
+// Note: pins were originally hard-coded to:
+// PYBv1.0: init(pyb.SPI(2), pyb.Pin.board.Y5, pyb.Pin.board.Y4, pyb.Pin.board.Y3)
+// [SPI on Y position; Y6=B13=SCK, Y7=B14=MISO, Y8=B15=MOSI]
+//
+// STM32F4DISC: init(pyb.SPI(2), pyb.Pin.cpu.A15, pyb.Pin.cpu.B10, pyb.Pin.cpu.B11)
+STATIC mp_obj_t modwlan_init(mp_uint_t n_args, const mp_obj_t *args) {
+ // set the pins to use
+ SpiInit(
+ spi_get_handle(args[0]),
+ pin_find(args[1]),
+ pin_find(args[2]),
+ pin_find(args[3])
+
+ );
+
// initialize and start the module
wlan_init(sWlanCallback, NULL, NULL, NULL,
ReadWlanInterruptPin, SpiResumeSpi, SpiPauseSpi, WriteWlanPin);
@@ -180,7 +197,7 @@ STATIC mp_obj_t modwlan_patch_program(void) {
return mp_const_none;
}
-STATIC MP_DEFINE_CONST_FUN_OBJ_0 (modwlan_init_obj, modwlan_init);
+STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(modwlan_init_obj, 4, 4, modwlan_init);
STATIC MP_DEFINE_CONST_FUN_OBJ_0 (modwlan_ifconfig_obj, modwlan_ifconfig);
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(modwlan_connect_obj, 1, modwlan_connect);
STATIC MP_DEFINE_CONST_FUN_OBJ_0 (modwlan_disconnect_obj, modwlan_disconnect);
@@ -220,5 +237,3 @@ const mp_obj_module_t wlan_module = {
.name = MP_QSTR_wlan,
.globals = (mp_obj_dict_t*)&wlan_module_globals,
};
-
-#endif //MICROPY_HW_ENABLE_CC3K
diff --git a/stmhal/mpconfigport.h b/stmhal/mpconfigport.h
index 94308a2fa..010ed2085 100644
--- a/stmhal/mpconfigport.h
+++ b/stmhal/mpconfigport.h
@@ -76,23 +76,23 @@ extern const struct _mp_obj_module_t pyb_module;
extern const struct _mp_obj_module_t stm_module;
extern const struct _mp_obj_module_t time_module;
-#if MICROPY_HW_ENABLE_CC3K
+#if MICROPY_PY_WIZNET5K
+extern const struct _mp_obj_module_t mp_module_wiznet5k;
+#define MICROPY_PY_WIZNET5K_DEF { MP_OBJ_NEW_QSTR(MP_QSTR_wiznet5k), (mp_obj_t)&mp_module_wiznet5k },
+#else
+#define MICROPY_PY_WIZNET5K_DEF
+#endif
+
+#if MICROPY_PY_CC3K
extern const struct _mp_obj_module_t wlan_module;
extern const struct _mp_obj_module_t socket_module;
extern const struct _mp_obj_module_t select_module;
-#define MICROPY_PORT_BUILTIN_MODULES_CC3K \
+#define MICROPY_PY_CC3K_DEF \
{ MP_OBJ_NEW_QSTR(MP_QSTR_wlan), (mp_obj_t)&wlan_module }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_socket), (mp_obj_t)&socket_module }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_select), (mp_obj_t)&select_module },
#else
-#define MICROPY_PORT_BUILTIN_MODULES_CC3K
-#endif
-
-#if MICROPY_PY_WIZNET5K
-extern const struct _mp_obj_module_t mp_module_wiznet5k;
-#define MICROPY_PY_WIZNET5K_DEF { MP_OBJ_NEW_QSTR(MP_QSTR_wiznet5k), (mp_obj_t)&mp_module_wiznet5k },
-#else
-#define MICROPY_PY_WIZNET5K_DEF
+#define MICROPY_PY_CC3K_DEF
#endif
#define MICROPY_PORT_BUILTIN_MODULES \
@@ -100,8 +100,8 @@ extern const struct _mp_obj_module_t mp_module_wiznet5k;
{ MP_OBJ_NEW_QSTR(MP_QSTR_pyb), (mp_obj_t)&pyb_module }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_stm), (mp_obj_t)&stm_module }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_time), (mp_obj_t)&time_module }, \
- MICROPY_PORT_BUILTIN_MODULES_CC3K \
MICROPY_PY_WIZNET5K_DEF \
+ MICROPY_PY_CC3K_DEF \
// extra constants
#define MICROPY_PORT_CONSTANTS \
@@ -156,6 +156,9 @@ static inline mp_uint_t disable_irq(void) {
#define USE_DEVICE_MODE
//#define USE_HOST_MODE
+// board specific definitions
+#include "mpconfigboard.h"
+
// We need to provide a declaration/definition of alloca()
#include <alloca.h>
diff --git a/stmhal/mpconfigport.mk b/stmhal/mpconfigport.mk
index b5ff3af58..44deace31 100644
--- a/stmhal/mpconfigport.mk
+++ b/stmhal/mpconfigport.mk
@@ -2,3 +2,6 @@
# wiznet5k module for ethernet support
MICROPY_PY_WIZNET5K ?= 0
+
+# cc3k module for wifi support
+MICROPY_PY_CC3K ?= 1
diff --git a/stmhal/spi.c b/stmhal/spi.c
index e08c07b0e..0b825ce1d 100644
--- a/stmhal/spi.c
+++ b/stmhal/spi.c
@@ -190,6 +190,14 @@ STATIC const pyb_spi_obj_t pyb_spi_obj[] = {
};
#define PYB_NUM_SPI MP_ARRAY_SIZE(pyb_spi_obj)
+SPI_HandleTypeDef *spi_get_handle(mp_obj_t o) {
+ if (!MP_OBJ_IS_TYPE(o, &pyb_spi_type)) {
+ nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "expecting an SPI object"));
+ }
+ pyb_spi_obj_t *self = o;
+ return self->spi;
+}
+
STATIC void pyb_spi_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) {
pyb_spi_obj_t *self = self_in;
diff --git a/stmhal/spi.h b/stmhal/spi.h
index 3b5e0f5e5..1f6e7e7b2 100644
--- a/stmhal/spi.h
+++ b/stmhal/spi.h
@@ -31,3 +31,4 @@ extern const mp_obj_type_t pyb_spi_type;
void spi_init0(void);
void spi_init(SPI_HandleTypeDef *spi);
+SPI_HandleTypeDef *spi_get_handle(mp_obj_t o);