From b2d3417559862a7808b1e20edf429f4e789b6633 Mon Sep 17 00:00:00 2001 From: Robert May Date: Tue, 27 Oct 2015 19:25:21 +0000 Subject: [PATCH 1/7] Fix build when $git_branch fails to be set correctly. --- source/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 2d9806c..271ed29 100755 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -42,7 +42,7 @@ set(YOTTA_AUTO_MICROBIT-DAL_CPP_FILES execute_process(WORKING_DIRECTORY "../../yotta_modules/${PROJECT_NAME}" COMMAND "git" "log" "--pretty=format:%h" "-n" "1" OUTPUT_VARIABLE git_hash) execute_process(WORKING_DIRECTORY "../../yotta_modules/${PROJECT_NAME}" COMMAND "git" "rev-parse" "--abbrev-ref" "HEAD" OUTPUT_VARIABLE git_branch OUTPUT_STRIP_TRAILING_WHITESPACE) -if (${git_branch} STREQUAL "master") +if ("${git_branch}" STREQUAL "master") set(MICROBIT_DAL_VERSION_STRING "${YOTTA_MICROBIT_DAL_VERSION_STRING}") else() set(MICROBIT_DAL_VERSION_STRING "${YOTTA_MICROBIT_DAL_VERSION_STRING}-${git_branch}-g${git_hash}") From a39ba7d4f712d5d9e83a56e39775e44fe467cf21 Mon Sep 17 00:00:00 2001 From: Robert May Date: Tue, 27 Oct 2015 19:53:37 +0000 Subject: [PATCH 2/7] Turn off GCC warnings when building the dependancies --- source/CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 271ed29..3ce290e 100755 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -80,3 +80,9 @@ target_link_libraries(microbit-dal ble ble-nrf51822 ) + +if(CMAKE_COMPILER_IS_GNUCC) + target_compile_options(mbed-classic PRIVATE "-w") + target_compile_options(ble PRIVATE "-w") + target_compile_options(ble-nrf51822 PRIVATE "-w") +endif() From 3a8c72144fcdaa163e3a3518d71dd94b9ab6947e Mon Sep 17 00:00:00 2001 From: Robert May Date: Tue, 27 Oct 2015 20:00:10 +0000 Subject: [PATCH 3/7] up the cmake version required to 2.8.12, which is required for target_compile_options. --- source/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 3ce290e..8d16619 100755 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -1,7 +1,7 @@ # This file is no longer auto-generated to make the repository builds with GCC # and ARMCC no matter what. -cmake_minimum_required(VERSION 2.8.11) +cmake_minimum_required(VERSION 2.8.12) enable_language(ASM) From 1a1a5976a8c4bc4b8c89d27bd24c6bbe76659179 Mon Sep 17 00:00:00 2001 From: Robert May Date: Tue, 27 Oct 2015 22:17:04 +0000 Subject: [PATCH 4/7] Silence GCC -Wall --- inc/MicroBit.h | 6 +++++- source/ManagedString.cpp | 2 +- source/MicroBit.cpp | 5 ++++- source/MicroBitDisplay.cpp | 6 +++--- source/MicroBitFiber.cpp | 10 ++++++---- source/MicroBitHeapAllocator.cpp | 2 +- source/ble-services/MicroBitAccelerometerService.cpp | 1 + source/ble-services/MicroBitDFUService.cpp | 2 ++ source/ble-services/MicroBitIOPinService.cpp | 2 +- source/ble-services/MicroBitLEDService.cpp | 4 ++-- source/ble-services/MicroBitMagnetometerService.cpp | 4 ++++ source/ble-services/MicroBitTemperatureService.cpp | 2 ++ 12 files changed, 32 insertions(+), 14 deletions(-) diff --git a/inc/MicroBit.h b/inc/MicroBit.h index 5f01c75..573be37 100644 --- a/inc/MicroBit.h +++ b/inc/MicroBit.h @@ -32,7 +32,11 @@ #include "MicroBitFiber.h" #include "MicroBitMessageBus.h" +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-parameter" #include "ble/BLE.h" +#pragma GCC diagnostic pop + #include "ble/services/DeviceInformationService.h" #include "MicroBitDFUService.h" #include "MicroBitEventService.h" @@ -270,7 +274,7 @@ class MicroBit * @return A textual description of the currentlt executing micro:bit runtime. * TODO: handle overflow case. */ - char *systemVersion(); + const char *systemVersion(); /** * Triggers a microbit panic where an infinite loop will occur swapping between the panicFace and statusCode if provided. diff --git a/source/ManagedString.cpp b/source/ManagedString.cpp index 362045a..829b65a 100644 --- a/source/ManagedString.cpp +++ b/source/ManagedString.cpp @@ -127,7 +127,7 @@ ManagedString::ManagedString(const ManagedString &s1, const ManagedString &s2) ManagedString::ManagedString(const char *str, const int16_t length) { // Sanity check. Return EmptyString for anything distasteful - if (str == NULL || *str == 0 || length > strlen(str)) + if (str == NULL || *str == 0 || (uint16_t)length > strlen(str)) // XXX length should be unsigned on the interface { initEmpty(); return; diff --git a/source/MicroBit.cpp b/source/MicroBit.cpp index 54c2c17..66913ff 100644 --- a/source/MicroBit.cpp +++ b/source/MicroBit.cpp @@ -33,6 +33,9 @@ microbit_reset() */ void bleDisconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason) { + (void) handle; /* -Wunused-param */ + (void) reason; /* -Wunused-param */ + uBit.ble->startAdvertising(); } @@ -478,7 +481,7 @@ unsigned long MicroBit::systemTime() * @return A textual description of the currentlt executing micro:bit runtime. * TODO: handle overflow case. */ -char *MicroBit::systemVersion() +const char *MicroBit::systemVersion() { return MICROBIT_DAL_VERSION; } diff --git a/source/MicroBitDisplay.cpp b/source/MicroBitDisplay.cpp index cbedd7d..dacdde4 100644 --- a/source/MicroBitDisplay.cpp +++ b/source/MicroBitDisplay.cpp @@ -87,7 +87,7 @@ void MicroBitDisplay::renderFinish() //kept inline to reduce overhead //clear the old bit pattern for this row. //clear port 0 4-7 and retain lower 4 bits - nrf_gpio_port_write(NRF_GPIO_PORT_SELECT_PORT0, 0xF0 | nrf_gpio_port_read(NRF_GPIO_PORT_SELECT_PORT0) & 0x0F); + nrf_gpio_port_write(NRF_GPIO_PORT_SELECT_PORT0, 0xF0 | (nrf_gpio_port_read(NRF_GPIO_PORT_SELECT_PORT0) & 0x0F)); // clear port 1 8-12 for the current row nrf_gpio_port_write(NRF_GPIO_PORT_SELECT_PORT1, strobeBitMsk | 0x1F); @@ -132,7 +132,7 @@ void MicroBitDisplay::render() //write the new bit pattern //set port 0 4-7 and retain lower 4 bits - nrf_gpio_port_write(NRF_GPIO_PORT_SELECT_PORT0, ~coldata<<4 & 0xF0 | nrf_gpio_port_read(NRF_GPIO_PORT_SELECT_PORT0) & 0x0F); + nrf_gpio_port_write(NRF_GPIO_PORT_SELECT_PORT0, (~coldata<<4 & 0xF0) | (nrf_gpio_port_read(NRF_GPIO_PORT_SELECT_PORT0) & 0x0F)); //set port 1 8-12 for the current row nrf_gpio_port_write(NRF_GPIO_PORT_SELECT_PORT1, strobeBitMsk | (~coldata>>4 & 0x1F)); @@ -180,7 +180,7 @@ void MicroBitDisplay::renderGreyscale() } //write the new bit pattern //set port 0 4-7 and retain lower 4 bits - nrf_gpio_port_write(NRF_GPIO_PORT_SELECT_PORT0, ~coldata<<4 & 0xF0 | nrf_gpio_port_read(NRF_GPIO_PORT_SELECT_PORT0) & 0x0F); + nrf_gpio_port_write(NRF_GPIO_PORT_SELECT_PORT0, (~coldata<<4 & 0xF0) | (nrf_gpio_port_read(NRF_GPIO_PORT_SELECT_PORT0) & 0x0F)); //set port 1 8-12 for the current row nrf_gpio_port_write(NRF_GPIO_PORT_SELECT_PORT1, strobeBitMsk | (~coldata>>4 & 0x1F)); diff --git a/source/MicroBitFiber.cpp b/source/MicroBitFiber.cpp index 1ae5111..461da33 100644 --- a/source/MicroBitFiber.cpp +++ b/source/MicroBitFiber.cpp @@ -130,8 +130,8 @@ Fiber *getFiberContext() if (f == NULL) return NULL; - f->stack_bottom = NULL; - f->stack_top = NULL; + f->stack_bottom = 0; + f->stack_top = 0; } // Ensure this fiber is in suitable state for reuse. @@ -512,7 +512,7 @@ Fiber *__create_fiber(uint32_t ep, uint32_t cp, uint32_t pm, int parameterised) */ Fiber *create_fiber(void (*entry_fn)(void), void (*completion_fn)(void)) { - return __create_fiber((uint32_t) entry_fn, (uint32_t)completion_fn, NULL, 0); + return __create_fiber((uint32_t) entry_fn, (uint32_t)completion_fn, 0, 0); } @@ -535,6 +535,8 @@ Fiber *create_fiber(void (*entry_fn)(void *), void *param, void (*completion_fn) */ void release_fiber(void * param) { + (void)param; /* -Wunused-parameter */ + release_fiber(); } @@ -688,7 +690,7 @@ void schedule() if (oldFiber == idleFiber) { // Just swap in the new fiber, and discard changes to stack and register context. - swap_context(NULL, ¤tFiber->tcb, NULL, currentFiber->stack_top); + swap_context(NULL, ¤tFiber->tcb, 0, currentFiber->stack_top); } else { diff --git a/source/MicroBitHeapAllocator.cpp b/source/MicroBitHeapAllocator.cpp index dd07121..1535a95 100644 --- a/source/MicroBitHeapAllocator.cpp +++ b/source/MicroBitHeapAllocator.cpp @@ -32,7 +32,7 @@ struct HeapDefinition // Create the necessary heap definitions. // We use two heaps by default: one for SoftDevice reuse, and one to run inside the mbed heap. -HeapDefinition heap[MICROBIT_HEAP_COUNT] = { NULL }; +HeapDefinition heap[MICROBIT_HEAP_COUNT] = { }; // Scans the status of the heap definition table, and returns the number of INITIALISED heaps. int microbit_active_heaps() diff --git a/source/ble-services/MicroBitAccelerometerService.cpp b/source/ble-services/MicroBitAccelerometerService.cpp index 3ab777f..46d299a 100644 --- a/source/ble-services/MicroBitAccelerometerService.cpp +++ b/source/ble-services/MicroBitAccelerometerService.cpp @@ -67,6 +67,7 @@ void MicroBitAccelerometerService::onDataWritten(const GattWriteCallbackParams * */ void MicroBitAccelerometerService::accelerometerUpdate(MicroBitEvent e) { + (void) e; /* -Wunused-parameter */ if (ble.getGapState().connected) { accelerometerDataCharacteristicBuffer[0] = uBit.accelerometer.getX(); diff --git a/source/ble-services/MicroBitDFUService.cpp b/source/ble-services/MicroBitDFUService.cpp index 27753e9..9c3db90 100644 --- a/source/ble-services/MicroBitDFUService.cpp +++ b/source/ble-services/MicroBitDFUService.cpp @@ -51,6 +51,7 @@ MicroBitDFUService::MicroBitDFUService(BLEDevice &_ble) : void MicroBitDFUService::onButtonA(MicroBitEvent e) { + (void) e; /* -Wunused-parameter */ if (flashCodeRequested) { releaseFlashCode(); @@ -63,6 +64,7 @@ void MicroBitDFUService::onButtonA(MicroBitEvent e) void MicroBitDFUService::onButtonB(MicroBitEvent e) { + (void) e; /* -Wunused-parameter */ uBit.display.scroll("VERSION: TODO"); showNameHistogram(); } diff --git a/source/ble-services/MicroBitIOPinService.cpp b/source/ble-services/MicroBitIOPinService.cpp index 38319c7..a48e5cd 100644 --- a/source/ble-services/MicroBitIOPinService.cpp +++ b/source/ble-services/MicroBitIOPinService.cpp @@ -138,7 +138,7 @@ void MicroBitIOPinService::onDataWritten(const GattWriteCallbackParams *params) if (params->handle == ioPinServiceDataCharacteristic->getValueHandle()) { // We have some pin data to change... - int len = params->len; + uint16_t len = params->len; IOData *data = (IOData *)params->data; // There may be multiple write operaitons... take each in turn and update the pin values diff --git a/source/ble-services/MicroBitLEDService.cpp b/source/ble-services/MicroBitLEDService.cpp index 059ab0b..5295615 100644 --- a/source/ble-services/MicroBitLEDService.cpp +++ b/source/ble-services/MicroBitLEDService.cpp @@ -59,7 +59,7 @@ void MicroBitLEDService::onDataWritten(const GattWriteCallbackParams *params) { for (int y=0; ylen; y++) for (int x=0; x<5; x++) - uBit.display.image.setPixelValue(x, y, (data[y] & (0x01 << 4-x)) ? 255 : 0); + uBit.display.image.setPixelValue(x, y, (data[y] & (0x01 << (4-x))) ? 255 : 0); } else if (params->handle == textCharacteristicHandle) @@ -94,7 +94,7 @@ void MicroBitLEDService::onDataRead(GattReadAuthCallbackParams *params) for (int x=0; x<5; x++) { if (uBit.display.image.getPixelValue(x, y)) - matrixCharacteristicBuffer[y] |= 0x01 << 4-x; + matrixCharacteristicBuffer[y] |= 0x01 << (4-x); } } diff --git a/source/ble-services/MicroBitMagnetometerService.cpp b/source/ble-services/MicroBitMagnetometerService.cpp index 08217ed..3ee4647 100644 --- a/source/ble-services/MicroBitMagnetometerService.cpp +++ b/source/ble-services/MicroBitMagnetometerService.cpp @@ -69,6 +69,8 @@ void MicroBitMagnetometerService::onDataWritten(const GattWriteCallbackParams *p */ void MicroBitMagnetometerService::magnetometerUpdate(MicroBitEvent e) { + (void) e; /* -Wunused-parameter */ + if (ble.getGapState().connected) { magnetometerDataCharacteristicBuffer[0] = uBit.compass.getX(); @@ -90,6 +92,8 @@ void MicroBitMagnetometerService::magnetometerUpdate(MicroBitEvent e) */ void MicroBitMagnetometerService::samplePeriodUpdateNeeded(MicroBitEvent e) { + (void) e; /* -Wunused-parameter */ + // Reconfigure the compass. This might take a while... uBit.compass.setPeriod(magnetometerPeriodCharacteristicBuffer); diff --git a/source/ble-services/MicroBitTemperatureService.cpp b/source/ble-services/MicroBitTemperatureService.cpp index bd2fd9e..0b97cb7 100644 --- a/source/ble-services/MicroBitTemperatureService.cpp +++ b/source/ble-services/MicroBitTemperatureService.cpp @@ -47,6 +47,8 @@ MicroBitTemperatureService::MicroBitTemperatureService(BLEDevice &_ble) : */ void MicroBitTemperatureService::temperatureUpdate(MicroBitEvent e) { + (void) e; /* -Wunused-parameter */ + if (ble.getGapState().connected) { temperatureDataCharacteristicBuffer = uBit.thermometer.getTemperature(); From 9591ef40dc01e76c2add4eb98b0cf4c86fa26d0c Mon Sep 17 00:00:00 2001 From: Robert May Date: Fri, 30 Oct 2015 20:20:51 +0000 Subject: [PATCH 5/7] Turn off -Wunused-parameter for include "nrf_soc.h" Unfortunately we can't turn it off just while nrf_soc.h is being included as the way the defines are used the compiler can't tell the parameters are unused until the end of the compilation unit. So we can't use the more normal as that pops the supression too early. WARNING: including nrf_soc.h will turn off unused-function warnings for the rest of the compilation unit - see included nrf_svc.h --- source/MicroBitThermometer.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/source/MicroBitThermometer.cpp b/source/MicroBitThermometer.cpp index 8e1df04..094572b 100644 --- a/source/MicroBitThermometer.cpp +++ b/source/MicroBitThermometer.cpp @@ -1,4 +1,18 @@ #include "MicroBit.h" + +/** + * Turn off unused-parameter warnings under gcc -Wall + * This turns them off for the entire compilation unit + * (i.e. the whole of this file) as the compiler can't + * tell that a parameter is unused until the end, and + * so we can't just turn it off as a guard around the + * next include. + * It might be better to add + * #pragram GCC system header + * as the first line of nrf_soc.h, but that's a different + * module ... + */ +#pragma GCC diagnostic ignored "-Wunused-parameter" #include "nrf_soc.h" /** From b8083908a736c96b89990380a57a92e4a98600f8 Mon Sep 17 00:00:00 2001 From: Robert May Date: Sun, 1 Nov 2015 19:23:47 +0000 Subject: [PATCH 6/7] Correct warnings supression in more obvious way Whilst a little more invasive change than the previous warnings supression this is more correct and more obvious as to what's being done, and what warnigns will remain in place for the rest of the comilation unit. --- source/MicroBitThermometer.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/source/MicroBitThermometer.cpp b/source/MicroBitThermometer.cpp index 094572b..23163bd 100644 --- a/source/MicroBitThermometer.cpp +++ b/source/MicroBitThermometer.cpp @@ -1,19 +1,22 @@ #include "MicroBit.h" /** - * Turn off unused-parameter warnings under gcc -Wall - * This turns them off for the entire compilation unit - * (i.e. the whole of this file) as the compiler can't - * tell that a parameter is unused until the end, and - * so we can't just turn it off as a guard around the - * next include. - * It might be better to add + * Turn off warnings under gcc -Wall + * We turn off unused-function for the entire compilation + * unit as the compiler can't tell if a function is + * unused until the end of the unit. The macro + * expansion for SVCALL() in nrf_soc.h and nrf_srv.h + * tries to leave unused-function turned off, but + * It might be leaner to add * #pragram GCC system header * as the first line of nrf_soc.h, but that's a different * module ... */ +#pragma GCC diagnostic ignored "-Wunused-function" +#pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-parameter" #include "nrf_soc.h" +#pragma GCC diagnostic pop /** * Constructor. From ea51f396ca6415dbaf47f70e968c0811b50cf6dc Mon Sep 17 00:00:00 2001 From: Joe Finney Date: Sun, 8 Nov 2015 18:04:17 +0000 Subject: [PATCH 7/7] Added compatibility for builds under ARMCC --- inc/MicroBit.h | 14 ++++++++++++++ source/MicroBitThermometer.cpp | 17 +++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/inc/MicroBit.h b/inc/MicroBit.h index fd74fed..417b300 100644 --- a/inc/MicroBit.h +++ b/inc/MicroBit.h @@ -32,10 +32,24 @@ #include "MicroBitFiber.h" #include "MicroBitMessageBus.h" +/* + * The underlying Nordic libraries that support BLE do not compile cleanly with the stringent GCC settings we employ + * If we're compiling under GCC, then we suppress any warnings generated from this code (but not the rest of the DAL) + * The ARM cc compiler is more tolerant. We don't test __GNUC__ here to detect GCC as ARMCC also typically sets this + * as a compatability option, but does not support the options used... + */ +#if !defined (__arm) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-parameter" +#endif #include "ble/BLE.h" + +/* + * Return to our predefined compiler settings. + */ +#if !defined (__arm) #pragma GCC diagnostic pop +#endif #include "ble/services/DeviceInformationService.h" #include "MicroBitDFUService.h" diff --git a/source/MicroBitThermometer.cpp b/source/MicroBitThermometer.cpp index 23163bd..2619f69 100644 --- a/source/MicroBitThermometer.cpp +++ b/source/MicroBitThermometer.cpp @@ -12,11 +12,28 @@ * as the first line of nrf_soc.h, but that's a different * module ... */ + + +/* + * The underlying Nordic libraries that support BLE do not compile cleanly with the stringent GCC settings we employ + * If we're compiling under GCC, then we suppress any warnings generated from this code (but not the rest of the DAL) + * The ARM cc compiler is more tolerant. We don't test __GNUC__ here to detect GCC as ARMCC also typically sets this + * as a compatability option, but does not support the options used... + */ +#if !defined(__arm) #pragma GCC diagnostic ignored "-Wunused-function" #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-parameter" +#endif + #include "nrf_soc.h" + +/* + * Return to our predefined compiler settings. + */ +#if !defined(__arm) #pragma GCC diagnostic pop +#endif /** * Constructor.