From 369ac5edd0f0cd3810100a093600e2e3fc67d215 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 25 Jun 2018 13:38:58 +1000 Subject: [PATCH] HAL_ChibiOS: save more space in the bootloader --- .../AP_HAL_ChibiOS/HAL_ChibiOS_Class.cpp | 9 ++++ libraries/AP_HAL_ChibiOS/UARTDriver.cpp | 2 +- .../AP_HAL_ChibiOS/hwdef/common/chconf.h | 8 ++++ .../AP_HAL_ChibiOS/hwdef/common/malloc.c | 4 ++ libraries/AP_HAL_ChibiOS/hwdef/common/stdio.c | 20 ++++++++- .../hwdef/scripts/chibios_hwdef.py | 44 ++++++++++++++++--- 6 files changed, 80 insertions(+), 7 deletions(-) diff --git a/libraries/AP_HAL_ChibiOS/HAL_ChibiOS_Class.cpp b/libraries/AP_HAL_ChibiOS/HAL_ChibiOS_Class.cpp index ee02df701e9..4825d4717ab 100644 --- a/libraries/AP_HAL_ChibiOS/HAL_ChibiOS_Class.cpp +++ b/libraries/AP_HAL_ChibiOS/HAL_ChibiOS_Class.cpp @@ -28,12 +28,21 @@ #include +#ifndef HAL_NO_UARTDRIVER static HAL_UARTA_DRIVER; static HAL_UARTB_DRIVER; static HAL_UARTC_DRIVER; static HAL_UARTD_DRIVER; static HAL_UARTE_DRIVER; static HAL_UARTF_DRIVER; +#else +static Empty::UARTDriver uartADriver; +static Empty::UARTDriver uartBDriver; +static Empty::UARTDriver uartCDriver; +static Empty::UARTDriver uartDDriver; +static Empty::UARTDriver uartEDriver; +static Empty::UARTDriver uartFDriver; +#endif #if HAL_USE_I2C == TRUE static ChibiOS::I2CDeviceManager i2cDeviceManager; diff --git a/libraries/AP_HAL_ChibiOS/UARTDriver.cpp b/libraries/AP_HAL_ChibiOS/UARTDriver.cpp index 4b278363ab0..0ffef499a8b 100644 --- a/libraries/AP_HAL_ChibiOS/UARTDriver.cpp +++ b/libraries/AP_HAL_ChibiOS/UARTDriver.cpp @@ -16,7 +16,7 @@ */ #include -#if CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS +#if CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS && !defined(HAL_NO_UARTDRIVER) #include "UARTDriver.h" #include "GPIO.h" #include diff --git a/libraries/AP_HAL_ChibiOS/hwdef/common/chconf.h b/libraries/AP_HAL_ChibiOS/hwdef/common/chconf.h index af47ae33e21..952d0778a3e 100644 --- a/libraries/AP_HAL_ChibiOS/hwdef/common/chconf.h +++ b/libraries/AP_HAL_ChibiOS/hwdef/common/chconf.h @@ -119,7 +119,9 @@ * function becomes the idle thread and must implement an * infinite loop. */ +#ifndef CH_CFG_NO_IDLE_THREAD #define CH_CFG_NO_IDLE_THREAD FALSE +#endif /** @} */ @@ -166,7 +168,9 @@ * * @note The default is @p TRUE. */ +#ifndef CH_CFG_USE_REGISTRY #define CH_CFG_USE_REGISTRY TRUE +#endif /** * @brief Threads synchronization APIs. @@ -250,7 +254,9 @@ * * @note The default is @p TRUE. */ +#ifndef CH_CFG_USE_EVENTS #define CH_CFG_USE_EVENTS TRUE +#endif /** * @brief Events Flags APIs with timeout. @@ -260,7 +266,9 @@ * @note The default is @p TRUE. * @note Requires @p CH_CFG_USE_EVENTS. */ +#ifndef CH_CFG_USE_EVENTS_TIMEOUT #define CH_CFG_USE_EVENTS_TIMEOUT TRUE +#endif /** * @brief Synchronous Messages APIs. diff --git a/libraries/AP_HAL_ChibiOS/hwdef/common/malloc.c b/libraries/AP_HAL_ChibiOS/hwdef/common/malloc.c index 626c510ef1b..06e5303dd89 100644 --- a/libraries/AP_HAL_ChibiOS/hwdef/common/malloc.c +++ b/libraries/AP_HAL_ChibiOS/hwdef/common/malloc.c @@ -35,6 +35,10 @@ #define MIN_ALIGNMENT 8 +#ifdef HAL_NO_CCM +#undef CCM_RAM_SIZE_KB +#endif + #if defined(CCM_RAM_SIZE_KB) static memory_heap_t ccm_heap; static bool ccm_heap_initialised = false; diff --git a/libraries/AP_HAL_ChibiOS/hwdef/common/stdio.c b/libraries/AP_HAL_ChibiOS/hwdef/common/stdio.c index 88e5ae7a16a..545486056e6 100644 --- a/libraries/AP_HAL_ChibiOS/hwdef/common/stdio.c +++ b/libraries/AP_HAL_ChibiOS/hwdef/common/stdio.c @@ -33,10 +33,11 @@ int vsnprintf(char *str, size_t size, const char *fmt, va_list ap) { + int retval = 0; +#ifndef HAL_NO_PRINTF MemoryStream ms; BaseSequentialStream *chp; size_t size_wo_nul; - int retval; if (size > 0) size_wo_nul = size - 1; @@ -58,11 +59,13 @@ int vsnprintf(char *str, size_t size, const char *fmt, va_list ap) str[ms.eos] = 0; /* Return number of bytes that would have been written.*/ +#endif return retval; } int snprintf(char *str, size_t size, const char *fmt, ...) { +#ifndef HAL_NO_PRINTF va_list arg; int done; @@ -71,10 +74,14 @@ int snprintf(char *str, size_t size, const char *fmt, ...) va_end (arg); return done; +#else + return 0; +#endif } int vasprintf(char **strp, const char *fmt, va_list ap) { +#ifndef HAL_NO_PRINTF int len = vsnprintf(NULL, 0, fmt, ap); if (len <= 0) { return -1; @@ -86,15 +93,22 @@ int vasprintf(char **strp, const char *fmt, va_list ap) vsnprintf(buf, len+1, fmt, ap); (*strp) = buf; return len; +#else + return 0; +#endif } int asprintf(char **strp, const char *fmt, ...) { +#ifndef HAL_NO_PRINTF va_list ap; va_start(ap, fmt); int ret = vasprintf(strp, fmt, ap); va_end(ap); return ret; +#else + return 0; +#endif } int vprintf(const char *fmt, va_list arg) @@ -112,6 +126,7 @@ int (*vprintf_console_hook)(const char *fmt, va_list arg) = vprintf; int printf(const char *fmt, ...) { +#ifndef HAL_NO_PRINTF va_list arg; int done; @@ -120,6 +135,9 @@ int printf(const char *fmt, ...) va_end (arg); return done; +#else + return 0; +#endif } //just a stub diff --git a/libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py b/libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py index 4f611132cb2..bfbb649a15e 100644 --- a/libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py +++ b/libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py @@ -442,7 +442,26 @@ def write_mcu_config(f): #define HAL_BOOTLOADER_BUILD TRUE #define HAL_USE_ADC FALSE #define HAL_USE_EXT FALSE +#define HAL_NO_UARTDRIVER +#define HAL_NO_PRINTF +#define HAL_NO_CCM #define CH_DBG_STATISTICS FALSE +#define SERIAL_ADVANCED_BUFFERING_SUPPORT FALSE +#define CH_CFG_USE_TM FALSE +#define CH_CFG_USE_REGISTRY FALSE +#define CH_CFG_USE_WAITEXIT FALSE +#define CH_CFG_USE_DYNAMIC FALSE +#define CH_CFG_USE_MEMPOOLS FALSE +#define CH_DBG_FILL_THREADS FALSE +#define CH_CFG_USE_SEMAPHORES TRUE +#define CH_CFG_USE_MUTEXES FALSE +#define CH_CFG_USE_CONDVARS FALSE +#define CH_CFG_USE_CONDVARS_TIMEOUT FALSE +#define CH_CFG_USE_EVENTS_TIMEOUT FALSE +#define CH_CFG_USE_MESSAGES FALSE +#define CH_CFG_USE_MAILBOXES FALSE +#define HAL_USE_I2C FALSE +#define HAL_USE_PWM FALSE ''') def write_ldscript(fname): @@ -626,9 +645,22 @@ def write_UART_config(f): f.write("STM32_%s_RX_DMA_CONFIG, STM32_%s_TX_DMA_CONFIG, %s}\n" % (dev, dev, rts_line)) f.write('#define HAL_UART_DEVICE_LIST %s\n\n' % ','.join(devlist)) - if not need_uart_driver: + if not need_uart_driver and not args.bootloader: f.write('#define HAL_USE_SERIAL FALSE\n') +def write_UART_config_bootloader(f): + '''write UART config defines''' + get_config('UART_ORDER') + uart_list = config['UART_ORDER'] + f.write('\n// UART configuration\n') + devlist = [] + for u in uart_list: + if u.startswith('OTG'): + devlist.append('(BaseChannel *)&SDU1') + else: + unum = int(u[-1]) + devlist.append('(BaseChannel *)&SD%u' % unum) + f.write('#define BOOTLOADER_DEV_LIST %s\n' % ','.join(devlist)) def write_I2C_config(f): '''write I2C config defines''' @@ -978,10 +1010,12 @@ def write_hwdef_header(outfilename): dma_priority=get_config('DMA_PRIORITY',default='TIM* SPI*', spaces=True), dma_noshare=get_config('DMA_NOSHARE',default='', spaces=True)) - write_PWM_config(f) - - write_I2C_config(f) - write_UART_config(f) + if not args.bootloader: + write_PWM_config(f) + write_I2C_config(f) + write_UART_config(f) + else: + write_UART_config_bootloader(f) if len(romfs) > 0: f.write('#define HAL_HAVE_AP_ROMFS_EMBEDDED_H 1\n')