Skip to content

Integrating MindConnect Library (MCL) to Sony Spresense Environment

Copying MCL to Spresense SDK

  • After cloning Spresense repository as told here, a new folder named "mcl" should be created in "spresense/externals".

  • Copy "mcl_core" and "mcl_connectivity" folders into the new folder "spresense/externals/mcl".

Add Kconfig, LibIncludes.mk and LibTarget.mk files

In "spresense/externals/mcl" folder, we need these three files (Kconfig, LibIncludes.mk and LibTarget.mk).

Kconfig

For mcl_core and mcl_connectivity modules, this sample Kconfig can be used.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
menu "MindConnect Library"

config EXTERNALS_MINDCONNECT_LIBRARY_CORE
    bool "MCL Core Component"
    default n
    ---help---
        Enable MindConnect Library Core component.

config EXTERNALS_MINDCONNECT_LIBRARY_CONNECTIVITY
    bool "MCL Connectivity Component"
    default n
    depends on EXTERNALS_MINDCONNECT_LIBRARY_CORE
    ---help---
        Enable MindConnect Library Connectivity component.

endmenu # MindConnect Library

LibIncludes.mk

For mcl_core and mcl_connectivity modules, this sample LibIncludes.mk can be used.

1
2
3
4
5
6
7
8
9
ifeq ($(CONFIG_EXTERNALS_MINDCONNECT_LIBRARY_CORE),y)
CFLAGS   += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" "$(SDKDIR)/../externals/mcl/mcl_core/include"}
CXXFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" "$(SDKDIR)/../externals/mcl/mcl_core/include"}
endif

ifeq ($(CONFIG_EXTERNALS_MINDCONNECT_LIBRARY_CONNECTIVITY),y)
CFLAGS   += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" "$(SDKDIR)/../externals/mcl/mcl_connectivity/include"}
CXXFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" "$(SDKDIR)/../externals/mcl/mcl_connectivity/include"}
endif

LibTarget.mk

For mcl_core and mcl_connectivity modules, this sample LibTarget.mk can be used.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
ifeq ($(CONFIG_EXTERNALS_MINDCONNECT_LIBRARY_CORE),y)
EXTLIBS += lib$(DELIM)libmcl_core$(LIBEXT)
MCL_CORE_DIRS += $(EXTERNAL_DIR)$(DELIM)mcl$(DELIM)mcl_core$(DELIM)src
endif
SDKCLEANDIRS += $(MCL_CORE_DIRS)

$(MCL_CORE_DIRS)$(DELIM)libmcl_core$(LIBEXT): context
    $(Q) $(MAKE) -C $(dir $@) TOPDIR="$(TOPDIR)" SDKDIR="$(SDKDIR)" $(notdir $@)

lib$(DELIM)libmcl_core$(LIBEXT): $(MCL_CORE_DIRS)$(DELIM)libmcl_core$(LIBEXT)
    $(Q) install $< $@

ifeq ($(CONFIG_EXTERNALS_MINDCONNECT_LIBRARY_CONNECTIVITY),y)
EXTLIBS += lib$(DELIM)libmcl_connectivity$(LIBEXT)
MCL_CONNECTIVITY_DIRS += $(EXTERNAL_DIR)$(DELIM)mcl$(DELIM)mcl_connectivity$(DELIM)src
endif
SDKCLEANDIRS += $(MCL_CONNECTIVITY_DIRS)

$(MCL_CONNECTIVITY_DIRS)$(DELIM)libmcl_connectivity$(LIBEXT): context
    $(Q) $(MAKE) -C $(dir $@) TOPDIR="$(TOPDIR)" SDKDIR="$(SDKDIR)" $(notdir $@)

lib$(DELIM)libmcl_connectivity$(LIBEXT): $(MCL_CONNECTIVITY_DIRS)$(DELIM)libmcl_connectivity$(LIBEXT)
    $(Q) install $< $@

Add Makefiles

Makefile for mcl_core

Makefile for mcl_core should be placed in "spresense/externals/mcl/mcl_core/src". Here is the sample Makefile for mcl_core module:

 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
MCL_CORE_DIR = $(EXTERNAL_DIR)$(DELIM)mcl$(DELIM)mcl_core

-include $(TOPDIR)/Make.defs
-include $(SDKDIR)/Make.defs
DELIM ?= $(strip /)

# C_SRCS
ASRCS =
CSRCS =  $(wildcard *.c)
CSRCS += ..$(DELIM)lib$(DELIM)cJSON$(DELIM)cJSON.c
CSRCS += http_client$(DELIM)basic$(DELIM)http_client_basic.c
CSRCS += http_client$(DELIM)basic$(DELIM)mbedtls$(DELIM)tls_socket_mbedtls.c
CSRCS += memory$(DELIM)standard$(DELIM)memory.c
CSRCS += crypto$(DELIM)mbedtls$(DELIM)security_mbedtls.c
CSRCS += file_util$(DELIM)standard$(DELIM)file_util.c

AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))

SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS)

BIN = libmcl_core.a

DEPPATH = --dep-path .
VPATH =  :..$(DELIM)lib
VPATH += :memory$(DELIM)standard
VPATH += :http_client$(DELIM)basic
VPATH += :http_client$(DELIM)basic$(DELIM)mbedtls

CFLAGS += -DMCL_STATICLIB=1

ifeq ($(WINTOOL),y)
CFLAGS += -I"${shell cygpath -w $(MCL_CORE_DIR)$(DELIM)lib}"
else
CFLAGS += -I$(MCL_CORE_DIR)$(DELIM)lib
endif

# Common build

all: $(BIN)
.PHONY: context depend clean distclean

$(AOBJS): %$(OBJEXT): %.S
    $(call ASSEMBLE, $<, $@)

$(COBJS): %$(OBJEXT): %.c
    $(call COMPILE, $<, $@)

$(BIN): $(OBJS)
    $(call ARCHIVE, $@, $(OBJS))

# Create dependencies

.depend: Makefile $(SRCS)
    $(Q) $(MKDEP) $(DEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
    $(Q) touch $@

depend: .depend

# context target proceeds before depend. User can be used this rule
# to prerequisite process (e.g. generate header file).

.context:
    $(Q) touch $@

context:

clean:
    $(call DELFILE, $(BIN))
    $(call CLEAN)

distclean: clean
    $(call DELFILE, .context)
    $(call DELFILE, Make.dep)
    $(call DELFILE, .depend)

-include Make.dep
.PHONY: preconfig
preconfig:

Makefile for mcl_connectivity

Makefile for mcl_connectivity should be placed in "spresense/externals/mcl/mcl_connectivity/src". Here is the sample Makefile for mcl_connectivity module:

 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
MCL_CORE_DIR = $(EXTERNAL_DIR)$(DELIM)mcl$(DELIM)mcl_core
MCL_CONNECTIVITY_DIR = $(EXTERNAL_DIR)$(DELIM)mcl$(DELIM)mcl_connectivity

-include $(TOPDIR)/Make.defs
-include $(SDKDIR)/Make.defs
DELIM ?= $(strip /)

# C_SRCS
CSRCS =  $(wildcard *.c)

COBJS = $(CSRCS:.c=$(OBJEXT))

SRCS = $(CSRCS)
OBJS = $(COBJS)

BIN = libmcl_connectivity.a

DEPPATH = --dep-path .

# Common build

ifeq ($(WINTOOL),y)
CFLAGS += -I"${shell cygpath -w $(MCL_CORE_DIR)$(DELIM)include}"
CFLAGS += -I"${shell cygpath -w $(MCL_CONNECTIVITY_DIR)$(DELIM)include}"
else
CFLAGS += -I$(MCL_CORE_DIR)$(DELIM)include
CFLAGS += -I$(MCL_CONNECTIVITY_DIR)$(DELIM)include
endif

VPATH =

CFLAGS += -DMCL_STATICLIB=1

all: $(BIN)
.PHONY: context depend clean distclean

$(AOBJS): %$(OBJEXT): %.S
    $(call ASSEMBLE, $<, $@)

$(COBJS): %$(OBJEXT): %.c
    $(call COMPILE, $<, $@)

$(BIN): $(OBJS)
    $(call ARCHIVE, $@, $(OBJS))

# Create dependencies

.depend: Makefile $(SRCS)
    $(Q) $(MKDEP) $(DEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
    $(Q) touch $@

depend: .depend

# context target proceeds before depend. User can be used this rule
# to prerequisite process (e.g. generate header file).

.context:
    $(Q) touch $@

context:

clean:
    $(call DELFILE, $(BIN))
    $(call CLEAN)

distclean: clean
    $(call DELFILE, .context)
    $(call DELFILE, Make.dep)
    $(call DELFILE, .depend)

-include Make.dep
.PHONY: preconfig
preconfig:

mbedTLS Network Module

By default MBEDTLS_NET_C is defined and mbedTLS will use its own network module (implemented in net_sockets.c). You may choose to disable it in the configuration header file of mbedTLS and implement your own mbedtls_net_init, mbedtls_net_connect, mbedtls_net_recv, mbedtls_net_send, mbedtls_net_free functions.

Known Issue

  • cJSON relies on "%g" specifier to use minimum number of digits to print number. However, standard library provided by NuttX violates this, e.g. prints "1591179742" with "%1.15g" specifier as "1591179742.000000000000000". This situation leads to problems, even a hard fault due to stack corruption.

Any questions left?

Ask the community


Except where otherwise noted, content on this site is licensed under the MindSphere Development License Agreement.