Skip to content

Commit

Permalink
atmel-samd: Use link time optimization to reduce code size of builds …
Browse files Browse the repository at this point in the history
…which

share space with the file system.

"Express" builds with SPI flash crash the compiler for some reason so its
currently disabled for them.
  • Loading branch information
tannewt committed Feb 26, 2017
1 parent 3fd19c6 commit 062fac1
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 10 deletions.
6 changes: 3 additions & 3 deletions atmel-samd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ CFLAGS_CORTEX_M0 = \
-DTC_ASYNC=true \
-DUSB_DEVICE_LPM_SUPPORT \
--param max-inline-insns-single=500
CFLAGS = $(INC) -Wall -Werror -std=gnu11 -nostdlib $(CFLAGS_CORTEX_M0) $(COPT)
CFLAGS = $(INC) -Wall -Werror -std=gnu11 -nostdlib $(CFLAGS_CORTEX_M0) $(COPT) $(BOARD_CFLAGS)

#Debugging/Optimization
# TODO(tannewt): Figure out what NDEBUG does. Adding it to the debug build
Expand All @@ -139,8 +139,8 @@ CFLAGS += -DMICROPY_QSTR_EXTRA_POOL=mp_qstr_frozen_const_pool
CFLAGS += -DMICROPY_MODULE_FROZEN_MPY
endif

LIBM_FILE_NAME = $(shell $(CC) $(CFLAGS) -print-file-name=libm.a)
LDFLAGS = -mthumb -mcpu=cortex-m0plus -Lasf/thirdparty/CMSIS/Lib/GCC/ -LQTouch/ -L$(dir $(LIBM_FILE_NAME)) -Wl,-nostdlib -Wl,-T,$(LD_FILE) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections -specs=nano.specs
#LIBM_FILE_NAME = $(shell $(CC) $(CFLAGS) -print-file-name=libm.a)
LDFLAGS = $(CFLAGS) -nostartfiles -fshort-enums -mthumb -mcpu=cortex-m0plus -Lasf/thirdparty/CMSIS/Lib/GCC/ -LQTouch/ -Wl,-nostdlib -Wl,-T,$(LD_FILE) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections -specs=nano.specs
LIBS = -larm_cortexM0l_math -lsamd21_qtouch_gcc -lm -lgcc -lc

SRC_ASF = $(addprefix asf/sam0/,\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ void AC1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler
#endif

/* Exception Table */
__attribute__ ((section(".vectors")))
__attribute__ ((used, section(".vectors")))
const DeviceVectors exception_table = {

/* Configure Initial Stack Pointer, using linker-generated symbols */
Expand Down Expand Up @@ -229,7 +229,7 @@ const DeviceVectors exception_table = {
* \brief This is the code that gets called on processor reset.
* To initialize the device, and call the main() routine.
*/
void Reset_Handler(void)
__attribute__ ((used))void Reset_Handler(void)
{
uint32_t *pSrc, *pDest;

Expand Down
2 changes: 2 additions & 0 deletions atmel-samd/boards/arduino_zero/mpconfigboard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ USB_PID = 0x824D
FLASH_IMPL = internal_flash.c

CHIP_VARIANT = SAMD21G18A

BOARD_CFLAGS = -flto
2 changes: 2 additions & 0 deletions atmel-samd/boards/feather_m0_adalogger/mpconfigboard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ USB_PID = 0x8015
FLASH_IMPL = internal_flash.c

CHIP_VARIANT = SAMD21G18A

BOARD_CFLAGS = -flto
2 changes: 2 additions & 0 deletions atmel-samd/boards/feather_m0_basic/mpconfigboard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ USB_PID = 0x8015
FLASH_IMPL = internal_flash.c

CHIP_VARIANT = SAMD21G18A

BOARD_CFLAGS = -flto
2 changes: 2 additions & 0 deletions atmel-samd/boards/gemma_m0/mpconfigboard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ USB_PID = 0x8015
FLASH_IMPL = internal_flash.c

CHIP_VARIANT = SAMD21E18A

BOARD_CFLAGS = -flto
2 changes: 2 additions & 0 deletions atmel-samd/boards/trinket_m0/mpconfigboard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ USB_PID = 0x8015
FLASH_IMPL = internal_flash.c

CHIP_VARIANT = SAMD21E18A

BOARD_CFLAGS = -flto
2 changes: 1 addition & 1 deletion atmel-samd/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ void samd21_init(void) {
nvm_set_config(&config_nvm);
}

int main(int argc, char **argv) {
int main(void) {
// initialise the cpu and peripherals
samd21_init();

Expand Down
6 changes: 5 additions & 1 deletion py/objnamedtuple.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,11 @@ mp_obj_t namedtuple_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t
return MP_OBJ_FROM_PTR(tuple);
}

const mp_rom_obj_tuple_t namedtuple_base_tuple = {{&mp_type_tuple}, 1, {MP_ROM_PTR(&mp_type_tuple)}};
const mp_rom_obj_tuple1_t namedtuple_base_tuple = {
.base = {&mp_type_tuple},
.len = 1u,
.items = {MP_OBJ_FROM_PTR(&mp_type_tuple)}
};

STATIC mp_obj_t mp_obj_new_namedtuple_type(qstr name, mp_uint_t n_fields, mp_obj_t *fields) {
mp_obj_namedtuple_type_t *o = m_new_obj_var(mp_obj_namedtuple_type_t, qstr, n_fields);
Expand Down
7 changes: 6 additions & 1 deletion py/objnamedtuple.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
* THE SOFTWARE.
*/

#ifndef __MICROPY_INCLUDED_PY_OBJNAMEDTUPLE_H__
#define __MICROPY_INCLUDED_PY_OBJNAMEDTUPLE_H__

#include <string.h>

#include "py/nlr.h"
Expand All @@ -50,6 +53,8 @@ void namedtuple_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest);

mp_obj_t namedtuple_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args);

const mp_rom_obj_tuple_t namedtuple_base_tuple;
const mp_rom_obj_tuple1_t namedtuple_base_tuple;

#endif // MICROPY_PY_COLLECTIONS

#endif // __MICROPY_INCLUDED_PY_OBJNAMEDTUPLE_H__
10 changes: 9 additions & 1 deletion py/objtuple.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,18 @@ typedef struct _mp_obj_tuple_t {

typedef struct _mp_rom_obj_tuple_t {
mp_obj_base_t base;
mp_uint_t len;
uint32_t len;
mp_rom_obj_t items[];
} mp_rom_obj_tuple_t;

// This is identical to the type above except it makes it clear that there is
// only one item. This makes lto happy with the namedtuple_base_tuple.
typedef struct _mp_rom_obj_tuple1_t {
mp_obj_base_t base;
uint32_t len;
mp_rom_obj_t items[1];
} mp_rom_obj_tuple1_t;

void mp_obj_tuple_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind);
mp_obj_t mp_obj_tuple_unary_op(mp_uint_t op, mp_obj_t self_in);
mp_obj_t mp_obj_tuple_binary_op(mp_uint_t op, mp_obj_t lhs, mp_obj_t rhs);
Expand Down
2 changes: 1 addition & 1 deletion shared-bindings/time/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ STATIC const mp_map_elem_t time_module_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_monotonic), (mp_obj_t)&time_monotonic_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_sleep), (mp_obj_t)&time_sleep_obj },
#if MICROPY_PY_COLLECTIONS
{ MP_OBJ_NEW_QSTR(MP_QSTR_struct_time), (mp_obj_t)&struct_time_type_obj },
//{ MP_OBJ_NEW_QSTR(MP_QSTR_struct_time), (mp_obj_t)&struct_time_type_obj },
#endif
};

Expand Down

0 comments on commit 062fac1

Please sign in to comment.