Skip to content

Commit

Permalink
added check_stack() to determine stack usage with Contiki
Browse files Browse the repository at this point in the history
tinydtls uses some stack space for HMAC calculations etc. This may
cause trouble on platforms where the stack is very small. For example,
the platform mbxxx (using an STM32 CPU) has reserved 1280 bytes for
this. During tests, I found that this is too limited for a complete
handshake. check_stack() shows that around 2 KiB should work.
  • Loading branch information
obgm committed Jul 16, 2014
1 parent 28e9d62 commit 014c0a4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
21 changes: 20 additions & 1 deletion debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,27 @@
# define DEBUG DEBUG_PRINT
# endif /* DEBUG */
#include "net/ip/uip-debug.h"
#else

#ifdef CONTIKI_TARGET_MBXXX
extern char __Stack_Init, _estack;

static inline void check_stack() {
const char *p = &__Stack_Init;
while (p < &_estack && *p == 0x38) {
p++;
}

PRINTF("Stack: %d bytes used (%d free)\n", &_estack - p, p - &__Stack_Init);
}
#else /* CONTIKI_TARGET_MBXXX */
static inline void check_stack() {
}
#endif /* CONTIKI_TARGET_MBXXX */
#else /* WITH_CONTKI */
#define PRINTF(...)

static inline void check_stack() {
}
#endif

struct __session_t;
Expand Down
1 change: 1 addition & 0 deletions dtls.c
Original file line number Diff line number Diff line change
Expand Up @@ -3135,6 +3135,7 @@ handle_handshake_msg(dtls_context_t *ctx, dtls_peer_t *peer, session_t *session,
dtls_handshake_free(peer->handshake_params);
peer->handshake_params = NULL;
dtls_debug("Handshake complete\n");
check_stack();
peer->state = DTLS_STATE_CONNECTED;

/* return here to not increase the message receive counter */
Expand Down

0 comments on commit 014c0a4

Please sign in to comment.