Skip to content

Commit

Permalink
Correct problem with SPI constructors, now executed at compile time
Browse files Browse the repository at this point in the history
This version compiles with XCode5.0.2 under Mac OS X Maverics

  cd stm32/libraries
  make
  cd ../tests
  make

To test CoAP, then flash test_CoAP_no_threads
  • Loading branch information
Pekka Nikander committed May 29, 2014
1 parent b5ac9f7 commit 1389b8a
Show file tree
Hide file tree
Showing 15 changed files with 75 additions and 30 deletions.
3 changes: 2 additions & 1 deletion stm32/emulator/src/emulator_post.c
Expand Up @@ -20,7 +20,8 @@
extern void *const __peripheral_end __attribute__((section(".text,.peripheral")));
void *const __peripheral_end = 0;

#include <udp.h>
#include <assert.h>
#include <netinet/udp.h>

const struct udp_socket __udp_sockets_end[0] = {};

Expand Down
3 changes: 2 additions & 1 deletion stm32/emulator/src/emulator_pre.c
Expand Up @@ -20,7 +20,8 @@
extern void *const __peripheral_start __attribute__((section(".text,.peripheral")));
void *const __peripheral_start = 0;

#include <udp.h>
#include <assert.h>
#include <netinet/udp.h>

const struct udp_socket __udp_sockets[0] = {};

Expand Down
2 changes: 1 addition & 1 deletion stm32/libraries/CoAP/src/enc28j60/enc28j60_packet.h
Expand Up @@ -24,7 +24,7 @@
* @brief ENC28J60 ethernet interface
*/

#ifdef _ENC28J60_PACKET_H_
#ifndef _ENC28J60_PACKET_H_
# define _ENC28J60_PACKET_H_

# include <enc28j60/ENC28J60.h>
Expand Down
6 changes: 3 additions & 3 deletions stm32/libraries/CoAP/src/enc28j60/enc28j60_reg.h
Expand Up @@ -24,8 +24,8 @@
* @brief ENC28J60 ethernet interface
*/

#ifdef _ECN28J60_REG_H_
# define _ECN28J60_REG_H_
#ifndef _ENC28J60_REG_H_
# define _ENC28J60_REG_H_


# define SPI_XFER_RX(op, reg, xtra) spi_command((op) | ((reg) & ENC_REG_MASK), 0, (xtra))
Expand Down Expand Up @@ -184,4 +184,4 @@ ENC28J60Class::phy_set(enc_reg_t reg, int value, bool nowait) const {
;
}

#endif //_ECN28J60_REG_H_
#endif //_ENC28J60_REG_H_
16 changes: 8 additions & 8 deletions stm32/libraries/CoAP/src/netinet/net_debug.h
Expand Up @@ -26,13 +26,13 @@
#ifndef _NET_DEBUG_H
# define _NET_DEBUG_H

#ifdef EMULATOR
#include <stdio.h>
#define net_error(...) fprintf(stderr, __VA_ARGS__)
#define net_debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define net_error(...)
#define net_debug(...)
#endif
# ifdef EMULATOR
# include <stdio.h>
# define net_error(...) fprintf(stderr, __VA_ARGS__)
# define net_debug(...) fprintf(stderr, __VA_ARGS__)
# else
# define net_error(...)
# define net_debug(...)
# endif

#endif //_NET_DEBUG_H
2 changes: 2 additions & 0 deletions stm32/libraries/SPI/src/SPI/spiAPI.h
Expand Up @@ -56,6 +56,8 @@
extern "C" {
# endif

static inline void spi_master_begin(const struct SPI *const spi, const pin_t ss_pin) __attribute__ ((always_inline));

/**
* Connect an SPI peripheral to the given pins as a master.
*
Expand Down
2 changes: 2 additions & 0 deletions stm32/libraries/SPI/src/SPI/spiStruct.h
Expand Up @@ -148,12 +148,14 @@ struct SPI {
IF(spi_dynamic_) dynamicFields, \
}

#if 0
/**
* Constant boot-time initialisation structures, defined in SPIInitSTM32F0cpp
*/

extern const SystemInitRecordData16Only SPI_INIT_STM32F0_DefaultRecordsData[];
extern const SystemInitRecordRegisterOffset SPI_INIT_STM32F0_DefaultRecordsOffsets[];
extern const uint8_t SPI_INIT_STM32F0_DefaultRecordsCount;
#endif

#endif //_SPISTRUCT_H_
File renamed without changes.
4 changes: 2 additions & 2 deletions stm32/libraries/SPI/src/ellduino_spi.cpp
Expand Up @@ -23,6 +23,8 @@

#include "SPI/ellduino_spi.h"

#include "SPIInitSTM32F0.cppinc"

/*
* Boot-time definitions for the STM32F0 series MCU SPIs.
*
Expand All @@ -32,8 +34,6 @@
* peripheral ports accordingly.
*/

Pin2Int7 spimap1, spimap2;

DEFINE_SPI_DEVICE(/*SPI*/1, /*APB*/2,
SPI_INIT_STM32F0_DefaultRecordsData,
SPI_INIT_STM32F0_DefaultRecordsOffsets,
Expand Down
27 changes: 27 additions & 0 deletions stm32/libraries/SPI/src/ellduino_spi_maps.cpp
@@ -0,0 +1,27 @@
/*
* Copyright (c) 2014 ELL-i co-operative.
*
* This file is part of ELL-i software.
*
* ELL-i software is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ELL-i software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ELL-i software. If not, see <http://www.gnu.org/licenses/>.
*/

/**
* @author Pekka Nikander <pekka.nikander@ell-i.org> 2014
*/

#include "SPI/ellduino_spi.h"

Pin2Int7 spimap1, spimap2;

10 changes: 9 additions & 1 deletion stm32/make/app.mk
Expand Up @@ -32,6 +32,14 @@ APP ?= sketch

APP_OBJS ?= main.o $(APP).o $(VARIANT).o

#
# Libraries to be included
#
ifeq ($(PLATFORM) $(shell uname -s),emulator Darwin)
APP_LIBS := $(LIBS) $(POST_OBJS) $(EMULATOR_LIBS)
else
APP_LIBS := --start-group $(LIBS) --end-group $(POST_OBJS) $(EMULATOR_LIBS)
endif

#
# Rules
Expand All @@ -51,7 +59,7 @@ clean::
rm -f make.map

$(APP): $(APP_OBJS) $(SYSTEM_LIBS) $(PRE_OBJS) $(POST_OBJS)
$(LD) $(LDFLAGS) -o $@ $(PRE_OBJS) $(APP_OBJS) --start-group $(LIBS) --end-group $(POST_OBJS) $(EMULATOR_LIBS)
$(LD) $(LDFLAGS) -o $@ $(PRE_OBJS) $(APP_OBJS) $(APP_LIBS)

#
# Define rules for producing .hex files
Expand Down
2 changes: 1 addition & 1 deletion stm32/make/emulator.mk
Expand Up @@ -49,7 +49,7 @@ CFLAGS := \
CXXFLAGS := \
$(subst -std=gnu++0x,-std=c++11,$(subst -mcpu=cortex-m0,,$(call expand,compiler.cmd.cxx.flags)))

LDFLAGS := -m32 -demangle -march=i386 $(LD_SCRIPT)
LDFLAGS := -m32 -march=i386 $(LD_SCRIPT)
ARFLAGS := $(call expand,compiler.cmd.ar.flags)

$(eval LIBS = $(call expand,compiler.cmd.ld.libs))
Expand Down
6 changes: 1 addition & 5 deletions stm32/make/libs_inc.mk
Expand Up @@ -7,11 +7,7 @@
CFLAGS += $(patsubst %,-I%,$(wildcard $(TOP)libraries/*/src/.))
CXXFLAGS += $(patsubst %,-I%,$(wildcard $(TOP)libraries/*/src/.))

CFLAGS += $(patsubst %,-I%,$(wildcard $(TOP)libraries/CoAP/arch/*/.))
CXXFLAGS += $(patsubst %,-I%,$(wildcard $(TOP)libraries/CoAP/arch/*/.))

LIBS += $(wildcard $(TOP)libraries/*/*.a)
LIBS += $(wildcard $(TOP)libraries/CoAP/arch/*/*.a)
# LIBS += $(TOP)libraries/SPI/ellduino_spi.o



8 changes: 7 additions & 1 deletion stm32/tests/test_CoAP_no_threads/Makefile
Expand Up @@ -15,6 +15,12 @@ VARIANT ?= ellduino

APP := test_CoAP_no_threads

APP_OBJS ?= main.o ../../libraries/CoAP/coap_input.o $(APP).o $(VARIANT).o
APP_OBJS ?= main.o coap_input.o $(APP).o $(VARIANT).o

include $(TOP)make/app.mk

VPATH += ../../libraries/CoAP/src/coap
CXXFLAGS += \
-I../../libraries/CoAP/src/netinet \
-I../../libraries/CoAP/src/coap \
-I../../libraries/CoAP/src/enc28j60 \
14 changes: 8 additions & 6 deletions stm32/tests/test_CoAP_no_threads/test_CoAP_no_threads.cpp
Expand Up @@ -17,12 +17,14 @@
* along with ELL-i software. If not, see <http://www.gnu.org/licenses/>.
*/

#include <assert.h>
#include <stddef.h>
#include <coap_internal.h>
#include <udp.h>
#include <ip.h>
#include <ethernet.h>
#include <string.h>
#include <ENC28J60.h>
#include <ethernet.h>
#include <ip.h>
#include <udp.h>
#include <coap_internal.h>

#define DEBUG_LED 5

Expand All @@ -32,7 +34,7 @@ struct ether_header *const ether_header = (struct ether_header *)(buffer+8);

void setup() {

ENC28J60.begin(ether_local_address);
ENC28J60.begin();

pinMode(DEBUG_LED, OUTPUT);
digitalWrite(DEBUG_LED, 1);
Expand All @@ -52,7 +54,7 @@ void loop() {
if (toggle) {
digitalWrite(DEBUG_LED, 0);
toggle = false;
}else{
} else {
digitalWrite(DEBUG_LED, 1);
toggle = true;
}
Expand Down

0 comments on commit 1389b8a

Please sign in to comment.