Skip to content

Commit a2ee194

Browse files
committed
cc3k: Change configurability of the CC3000 module.
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().
1 parent 6f70542 commit a2ee194

27 files changed

+119
-152
lines changed

stmhal/Makefile

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ HAL_DIR=hal
2222
USBDEV_DIR=usbdev
2323
#USBHOST_DIR=usbhost
2424
FATFS_DIR=fatfs
25-
CC3K_DIR=cc3k
2625
DFU=../tools/dfu.py
2726
# may need to prefix dfu-util with sudo
2827
DFU_UTIL ?= dfu-util
@@ -39,7 +38,6 @@ INC += -I$(HAL_DIR)/inc
3938
INC += -I$(USBDEV_DIR)/core/inc -I$(USBDEV_DIR)/class/cdc_msc_hid/inc
4039
#INC += -I$(USBHOST_DIR)
4140
INC += -I$(FATFS_DIR)/src
42-
INC += -I$(CC3K_DIR)/inc
4341

4442
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
4543
CFLAGS = $(INC) -Wall -Werror -ansi -std=gnu99 -nostdlib $(CFLAGS_MOD) $(CFLAGS_CORTEX_M4) $(COPT)
@@ -119,9 +117,6 @@ SRC_C = \
119117
servo.c \
120118
dac.c \
121119
adc.c \
122-
modwlan.c \
123-
modsocket.c \
124-
modselect.c \
125120

126121
SRC_S = \
127122
startup_stm32f40xx.s \
@@ -186,7 +181,28 @@ SRC_FATFS = $(addprefix $(FATFS_DIR)/src/,\
186181
option/ccsbcs.c \
187182
)
188183

189-
SRC_CC3K = $(addprefix $(CC3K_DIR)/src/,\
184+
ifeq ($(MICROPY_PY_WIZNET5K),1)
185+
WIZNET5K_DIR=drivers/wiznet5k
186+
INC += -I$(TOP)/$(WIZNET5K_DIR)
187+
CFLAGS_MOD += -DMICROPY_PY_WIZNET5K=1
188+
SRC_MOD += modwiznet5k.c
189+
SRC_MOD += $(addprefix $(WIZNET5K_DIR)/,\
190+
ethernet/w5200/w5200.c \
191+
ethernet/wizchip_conf.c \
192+
ethernet/socket.c \
193+
internet/dns/dns.c \
194+
)
195+
endif
196+
197+
ifeq ($(MICROPY_PY_CC3K),1)
198+
CC3K_DIR=cc3k
199+
INC += -I$(CC3K_DIR)/inc
200+
CFLAGS_MOD += -DMICROPY_PY_CC3K=1
201+
SRC_MOD += \
202+
modwlan.c \
203+
modsocket.c \
204+
modselect.c
205+
SRC_MOD += $(addprefix $(CC3K_DIR)/src/,\
190206
cc3000_common.c \
191207
evnt_handler.c \
192208
hci.c \
@@ -202,18 +218,6 @@ SRC_CC3K = $(addprefix $(CC3K_DIR)/src/,\
202218
# patch.c \
203219
# patch_prog.c \
204220
)
205-
206-
ifeq ($(MICROPY_PY_WIZNET5K),1)
207-
WIZNET5K_DIR=drivers/wiznet5k
208-
INC += -I$(TOP)/$(WIZNET5K_DIR)
209-
CFLAGS_MOD += -DMICROPY_PY_WIZNET5K=1
210-
SRC_MOD += modwiznet5k.c
211-
SRC_MOD += $(addprefix $(WIZNET5K_DIR)/,\
212-
ethernet/w5200/w5200.c \
213-
ethernet/wizchip_conf.c \
214-
ethernet/socket.c \
215-
internet/dns/dns.c \
216-
)
217221
endif
218222

219223
OBJ =
@@ -224,7 +228,6 @@ OBJ += $(addprefix $(BUILD)/, $(SRC_S:.s=.o))
224228
OBJ += $(addprefix $(BUILD)/, $(SRC_HAL:.c=.o))
225229
OBJ += $(addprefix $(BUILD)/, $(SRC_USBDEV:.c=.o))
226230
OBJ += $(addprefix $(BUILD)/, $(SRC_FATFS:.c=.o))
227-
OBJ += $(addprefix $(BUILD)/, $(SRC_CC3K:.c=.o))
228231
OBJ += $(addprefix $(BUILD)/, $(SRC_MOD:.c=.o))
229232
OBJ += $(BUILD)/pins_$(BOARD).o
230233

stmhal/boards/HYDRABUS/mpconfigboard.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#define MICROPY_HW_ENABLE_I2C1 (1)
1717
#define MICROPY_HW_ENABLE_SPI1 (1)
1818
#define MICROPY_HW_ENABLE_SPI3 (1)
19-
#define MICROPY_HW_ENABLE_CC3K (0)
2019

2120
// USRSW/UBTN (Needs Jumper UBTN) is pulled low. Pressing the button makes the input go high.
2221
#define MICROPY_HW_USRSW_PIN (pin_A0)

stmhal/boards/NETDUINO_PLUS_2/mpconfigboard.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#define MICROPY_HW_ENABLE_I2C1 (0)
2121
#define MICROPY_HW_ENABLE_SPI1 (0)
2222
#define MICROPY_HW_ENABLE_SPI3 (0)
23-
#define MICROPY_HW_ENABLE_CC3K (0)
2423

2524
// USRSW is pulled low. Pressing the button makes the input go high.
2625
#define MICROPY_HW_USRSW_PIN (pin_B11)

stmhal/boards/PYBV10/mpconfigboard.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#define MICROPY_HW_ENABLE_I2C1 (1)
1818
#define MICROPY_HW_ENABLE_SPI1 (1)
1919
#define MICROPY_HW_ENABLE_SPI3 (0)
20-
#define MICROPY_HW_ENABLE_CC3K (1)
2120

2221
// USRSW has no pullup or pulldown, and pressing the switch makes the input go low
2322
#define MICROPY_HW_USRSW_PIN (pin_B3)
@@ -38,10 +37,3 @@
3837
#define MICROPY_HW_SDCARD_DETECT_PIN (pin_A8)
3938
#define MICROPY_HW_SDCARD_DETECT_PULL (GPIO_PULLUP)
4039
#define MICROPY_HW_SDCARD_DETECT_PRESENT (GPIO_PIN_RESET)
41-
42-
// CC3K WLAN
43-
#define MICROPY_HW_WLAN_PIN_CS (pin_B12) // Y5
44-
#define MICROPY_HW_WLAN_PIN_EN (pin_B9) // Y4
45-
#define MICROPY_HW_WLAN_PIN_IRQ (pin_B8) // Y3
46-
#define MICROPY_HW_WLAN_SPI_HANDLE (SPIHandle2) // SPI on Y position (Y6=B13=SCK, Y7=B14=MISO, Y8=B15=MOSI)
47-
#define MICROPY_HW_WLAN_IRQ_LINE (8) // B8 on line 8

stmhal/boards/PYBV3/mpconfigboard.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#define MICROPY_HW_ENABLE_I2C1 (1)
1717
#define MICROPY_HW_ENABLE_SPI1 (1)
1818
#define MICROPY_HW_ENABLE_SPI3 (0)
19-
#define MICROPY_HW_ENABLE_CC3K (0)
2019

2120
// USRSW has no pullup or pulldown, and pressing the switch makes the input go low
2221
#define MICROPY_HW_USRSW_PIN (pin_A13)

stmhal/boards/PYBV4/mpconfigboard.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#define MICROPY_HW_ENABLE_I2C1 (1)
1717
#define MICROPY_HW_ENABLE_SPI1 (1)
1818
#define MICROPY_HW_ENABLE_SPI3 (0)
19-
#define MICROPY_HW_ENABLE_CC3K (0)
2019

2120
// USRSW has no pullup or pulldown, and pressing the switch makes the input go low
2221
#define MICROPY_HW_USRSW_PIN (pin_B3)

stmhal/boards/STM32F4DISC/mpconfigboard.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#define MICROPY_HW_ENABLE_I2C1 (1)
1717
#define MICROPY_HW_ENABLE_SPI1 (1)
1818
#define MICROPY_HW_ENABLE_SPI3 (0)
19-
#define MICROPY_HW_ENABLE_CC3K (0)
2019

2120
// USRSW is pulled low. Pressing the button makes the input go high.
2221
#define MICROPY_HW_USRSW_PIN (pin_A0)
@@ -32,10 +31,3 @@
3231
#define MICROPY_HW_LED_OTYPE (GPIO_MODE_OUTPUT_PP)
3332
#define MICROPY_HW_LED_ON(pin) (pin->gpio->BSRRL = pin->pin_mask)
3433
#define MICROPY_HW_LED_OFF(pin) (pin->gpio->BSRRH = pin->pin_mask)
35-
36-
// CC3K WLAN
37-
#define MICROPY_HW_WLAN_PIN_CS (pin_A15)
38-
#define MICROPY_HW_WLAN_PIN_EN (pin_B10)
39-
#define MICROPY_HW_WLAN_PIN_IRQ (pin_B11)
40-
#define MICROPY_HW_WLAN_SPI_HANDLE (SPIHandle2)
41-
#define MICROPY_HW_WLAN_IRQ_LINE (11)

stmhal/cc3k/inc/ccspi.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ extern unsigned char wlan_tx_buffer[];
5656
// Prototypes for the APIs.
5757
//
5858
//*****************************************************************************
59+
60+
// the arguments must be of type pin_obj_t* and SPI_HandleTypeDef*
61+
extern void SpiInit(void *spi, const void *pin_cs, const void *pin_en, const void *pin_irq);
62+
5963
extern void SpiOpen(gcSpiHandleRx pfRxHandler);
6064
extern void SpiClose(void);
6165
extern void SpiPauseSpi(void);

stmhal/cc3k/src/cc3000_common.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@
4343
* Include files
4444
*
4545
*****************************************************************************/
46-
#include "mpconfigport.h"
47-
#if MICROPY_HW_ENABLE_CC3K
4846

4947
#include "cc3000_common.h"
5048
#include "socket.h"
@@ -164,4 +162,3 @@ UINT32 STREAM_TO_UINT32_f(CHAR* p, UINT16 offset)
164162
//! @}
165163
//
166164
//*****************************************************************************
167-
#endif // MICROPY_HW_ENABLE_CC3K

stmhal/cc3k/src/ccspi.c

Lines changed: 46 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3232
*
3333
*****************************************************************************/
34-
#include "mpconfigport.h"
35-
#if MICROPY_HW_ENABLE_CC3K
3634

3735
#include <string.h>
3836

@@ -44,7 +42,6 @@
4442
#include "obj.h"
4543
#include "runtime.h"
4644
#include "pin.h"
47-
#include "genhdr/pins.h"
4845
#include "led.h"
4946
#include "extint.h"
5047
#include "spi.h"
@@ -58,14 +55,14 @@
5855
#define DEBUG_printf(args...) (void)0
5956
#endif
6057

61-
#define PIN_CS MICROPY_HW_WLAN_PIN_CS
62-
#define PIN_EN MICROPY_HW_WLAN_PIN_EN
63-
#define PIN_IRQ MICROPY_HW_WLAN_PIN_IRQ
64-
#define SPI_HANDLE MICROPY_HW_WLAN_SPI_HANDLE
65-
#define IRQ_LINE MICROPY_HW_WLAN_IRQ_LINE
58+
// these need to be set to valid values before anything in this file will work
59+
STATIC SPI_HandleTypeDef *SPI_HANDLE = NULL;
60+
STATIC const pin_obj_t *PIN_CS = NULL;
61+
STATIC const pin_obj_t *PIN_EN = NULL;
62+
STATIC const pin_obj_t *PIN_IRQ = NULL;
6663

67-
#define CS_LOW() HAL_GPIO_WritePin(PIN_CS.gpio, PIN_CS.pin_mask, GPIO_PIN_RESET)
68-
#define CS_HIGH() HAL_GPIO_WritePin(PIN_CS.gpio, PIN_CS.pin_mask, GPIO_PIN_SET)
64+
#define CS_LOW() HAL_GPIO_WritePin(PIN_CS->gpio, PIN_CS->pin_mask, GPIO_PIN_RESET)
65+
#define CS_HIGH() HAL_GPIO_WritePin(PIN_CS->gpio, PIN_CS->pin_mask, GPIO_PIN_SET)
6966

7067
#define READ 3
7168
#define WRITE 1
@@ -106,10 +103,19 @@ tSpiInformation sSpiInformation;
106103
char spi_buffer[CC3000_RX_BUFFER_SIZE];
107104
unsigned char wlan_tx_buffer[CC3000_TX_BUFFER_SIZE];
108105

109-
static const mp_obj_fun_native_t irq_callback_obj;
106+
STATIC const mp_obj_fun_builtin_t irq_callback_obj;
110107
void SpiWriteDataSynchronous(unsigned char *data, unsigned short size);
111108
void SpiReadDataSynchronous(unsigned char *data, unsigned short size);
112109

110+
// set the pins to use to communicate with the CC3000
111+
// the arguments must be of type pin_obj_t* and SPI_HandleTypeDef*
112+
void SpiInit(void *spi, const void *pin_cs, const void *pin_en, const void *pin_irq) {
113+
SPI_HANDLE = spi;
114+
PIN_CS = pin_cs;
115+
PIN_EN = pin_en;
116+
PIN_IRQ = pin_irq;
117+
}
118+
113119
void SpiClose(void)
114120
{
115121
if (sSpiInformation.pRxPacket) {
@@ -118,7 +124,7 @@ void SpiClose(void)
118124

119125
tSLInformation.WlanInterruptDisable();
120126

121-
//HAL_SPI_DeInit(&SPI_HANDLE);
127+
//HAL_SPI_DeInit(SPI_HANDLE);
122128
}
123129

124130
void SpiOpen(gcSpiHandleRx pfRxHandler)
@@ -136,18 +142,18 @@ void SpiOpen(gcSpiHandleRx pfRxHandler)
136142
wlan_tx_buffer[CC3000_TX_BUFFER_SIZE - 1] = CC3000_BUFFER_MAGIC_NUMBER;
137143

138144
/* SPI configuration */
139-
SPI_HANDLE.Init.Mode = SPI_MODE_MASTER;
140-
SPI_HANDLE.Init.Direction = SPI_DIRECTION_2LINES;
141-
SPI_HANDLE.Init.DataSize = SPI_DATASIZE_8BIT;
142-
SPI_HANDLE.Init.CLKPolarity = SPI_POLARITY_LOW;
143-
SPI_HANDLE.Init.CLKPhase = SPI_PHASE_2EDGE;
144-
SPI_HANDLE.Init.NSS = SPI_NSS_SOFT;
145-
SPI_HANDLE.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8;
146-
SPI_HANDLE.Init.FirstBit = SPI_FIRSTBIT_MSB;
147-
SPI_HANDLE.Init.TIMode = SPI_TIMODE_DISABLED;
148-
SPI_HANDLE.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;
149-
SPI_HANDLE.Init.CRCPolynomial = 7;
150-
spi_init(&SPI_HANDLE);
145+
SPI_HANDLE->Init.Mode = SPI_MODE_MASTER;
146+
SPI_HANDLE->Init.Direction = SPI_DIRECTION_2LINES;
147+
SPI_HANDLE->Init.DataSize = SPI_DATASIZE_8BIT;
148+
SPI_HANDLE->Init.CLKPolarity = SPI_POLARITY_LOW;
149+
SPI_HANDLE->Init.CLKPhase = SPI_PHASE_2EDGE;
150+
SPI_HANDLE->Init.NSS = SPI_NSS_SOFT;
151+
SPI_HANDLE->Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8;
152+
SPI_HANDLE->Init.FirstBit = SPI_FIRSTBIT_MSB;
153+
SPI_HANDLE->Init.TIMode = SPI_TIMODE_DISABLED;
154+
SPI_HANDLE->Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;
155+
SPI_HANDLE->Init.CRCPolynomial = 7;
156+
spi_init(SPI_HANDLE);
151157

152158
// configure wlan CS and EN pins
153159
GPIO_InitTypeDef GPIO_InitStructure;
@@ -156,48 +162,48 @@ void SpiOpen(gcSpiHandleRx pfRxHandler)
156162
GPIO_InitStructure.Pull = GPIO_NOPULL;
157163
GPIO_InitStructure.Alternate = 0;
158164

159-
GPIO_InitStructure.Pin = PIN_CS.pin_mask;
160-
HAL_GPIO_Init(PIN_CS.gpio, &GPIO_InitStructure);
165+
GPIO_InitStructure.Pin = PIN_CS->pin_mask;
166+
HAL_GPIO_Init(PIN_CS->gpio, &GPIO_InitStructure);
161167

162-
GPIO_InitStructure.Pin = PIN_EN.pin_mask;
163-
HAL_GPIO_Init(PIN_EN.gpio, &GPIO_InitStructure);
168+
GPIO_InitStructure.Pin = PIN_EN->pin_mask;
169+
HAL_GPIO_Init(PIN_EN->gpio, &GPIO_InitStructure);
164170

165-
HAL_GPIO_WritePin(PIN_CS.gpio, PIN_CS.pin_mask, GPIO_PIN_SET);
166-
HAL_GPIO_WritePin(PIN_EN.gpio, PIN_EN.pin_mask, GPIO_PIN_RESET);
171+
HAL_GPIO_WritePin(PIN_CS->gpio, PIN_CS->pin_mask, GPIO_PIN_SET);
172+
HAL_GPIO_WritePin(PIN_EN->gpio, PIN_EN->pin_mask, GPIO_PIN_RESET);
167173

168174
/* do a dummy read, this ensures SCLK is low before
169175
actual communications start, it might be required */
170176
CS_LOW();
171177
uint8_t buf[1];
172-
HAL_SPI_Receive(&SPI_HANDLE, buf, sizeof(buf), SPI_TIMEOUT);
178+
HAL_SPI_Receive(SPI_HANDLE, buf, sizeof(buf), SPI_TIMEOUT);
173179
CS_HIGH();
174180

175181
// register EXTI
176-
extint_register((mp_obj_t)&PIN_IRQ, GPIO_MODE_IT_FALLING, GPIO_PULLUP, (mp_obj_t)&irq_callback_obj, true, NULL);
177-
extint_enable(IRQ_LINE);
182+
extint_register((mp_obj_t)PIN_IRQ, GPIO_MODE_IT_FALLING, GPIO_PULLUP, (mp_obj_t)&irq_callback_obj, true, NULL);
183+
extint_enable(PIN_IRQ->pin);
178184

179-
DEBUG_printf("SpiOpen finished; IRQ.pin=%d IRQ_LINE=%d\n", PIN_IRQ.pin, IRQ_LINE);
185+
DEBUG_printf("SpiOpen finished; IRQ.pin=%d IRQ_LINE=%d\n", PIN_IRQ->pin, PIN_IRQ->pin);
180186
}
181187

182188

183189
void SpiPauseSpi(void)
184190
{
185-
extint_disable(IRQ_LINE);
191+
extint_disable(PIN_IRQ->pin);
186192
}
187193

188194
void SpiResumeSpi(void)
189195
{
190-
extint_enable(IRQ_LINE);
196+
extint_enable(PIN_IRQ->pin);
191197
}
192198

193199
long ReadWlanInterruptPin(void)
194200
{
195-
return HAL_GPIO_ReadPin(PIN_IRQ.gpio, PIN_IRQ.pin_mask);
201+
return HAL_GPIO_ReadPin(PIN_IRQ->gpio, PIN_IRQ->pin_mask);
196202
}
197203

198204
void WriteWlanPin(unsigned char val)
199205
{
200-
HAL_GPIO_WritePin(PIN_EN.gpio, PIN_EN.pin_mask,
206+
HAL_GPIO_WritePin(PIN_EN->gpio, PIN_EN->pin_mask,
201207
(WLAN_ENABLE)? GPIO_PIN_SET:GPIO_PIN_RESET);
202208
}
203209

@@ -306,7 +312,7 @@ void SpiWriteDataSynchronous(unsigned char *data, unsigned short size)
306312
{
307313
DEBUG_printf("SpiWriteDataSynchronous(data=%p [%x %x %x %x], size=%u)\n", data, data[0], data[1], data[2], data[3], size);
308314
__disable_irq();
309-
if (HAL_SPI_TransmitReceive(&SPI_HANDLE, data, data, size, SPI_TIMEOUT) != HAL_OK) {
315+
if (HAL_SPI_TransmitReceive(SPI_HANDLE, data, data, size, SPI_TIMEOUT) != HAL_OK) {
310316
//BREAK();
311317
}
312318
__enable_irq();
@@ -317,7 +323,7 @@ void SpiReadDataSynchronous(unsigned char *data, unsigned short size)
317323
{
318324
memset(data, READ, size);
319325
__disable_irq();
320-
if (HAL_SPI_TransmitReceive(&SPI_HANDLE, data, data, size, SPI_TIMEOUT) != HAL_OK) {
326+
if (HAL_SPI_TransmitReceive(SPI_HANDLE, data, data, size, SPI_TIMEOUT) != HAL_OK) {
321327
//BREAK();
322328
}
323329
__enable_irq();
@@ -453,5 +459,3 @@ STATIC mp_obj_t irq_callback(mp_obj_t line)
453459
}
454460

455461
STATIC MP_DEFINE_CONST_FUN_OBJ_1(irq_callback_obj, irq_callback);
456-
457-
#endif // MICROPY_HW_ENABLE_CC3K

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy