Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GCC 9 support #2103

Merged
merged 14 commits into from
May 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .buildpackrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# build targets in Particle Cloud when pushing a tag.

# GCC buildpack variation to use ( see: https://hub.docker.com/r/particle/buildpack-hal/tags/ )
export BUILDPACK_VARIATION=gcc-arm-none-eabi-5_3-2016q1
export BUILDPACK_VARIATION=gcc-arm-none-eabi-9_2-2019q4

# Platforms for which this firmware is considered stable
export RELEASE_PLATFORMS=( )
Expand Down
22 changes: 11 additions & 11 deletions .workbench/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"toolchains": [
{
"firmware": "deviceOS@source",
"compilers": "gcc-arm@5.3.1",
"compilers": "gcc-arm@9.2.1",
"debuggers": "openocd@0.11.2-adhoc6ea4372.0",
"platforms": [6, 8, 10, 12, 13, 14, 22, 23, 25],
"platforms": [6, 8, 10, 12, 13, 22, 23, 25],
"scripts": "buildscripts@1.9.2",
"tools": "buildtools@1.1.1"
}
Expand All @@ -15,10 +15,10 @@
"x64": [
{
"name": "gcc-arm",
"version": "5.3.1",
"version": "9.2.1",
"main": "./bin",
"url": "https://binaries.particle.io/gcc-arm/windows/x64/gcc-arm-v5.3.1.tar.gz",
"sha256": "9d5106811e6ad8f3fd63ac266fb3e6e31798e14333b50f849130f604e331ba3d"
"url": "https://binaries.particle.io/gcc-arm/windows/x64/gcc-arm-v9.2.1.tar.gz",
"sha256": "4cd5e43a2ab144b2beb589b0b0d9f9632ad918154f3749fcff0c36da93468a96"
}
],
"x86": []
Expand All @@ -27,10 +27,10 @@
"x64": [
{
"name": "gcc-arm",
"version": "5.3.1",
"version": "9.2.1",
"main": "./bin",
"url": "https://binaries.particle.io/gcc-arm/darwin/x64/gcc-arm-v5.3.1.tar.gz",
"sha256": "f41f32436188c3017422635b187378c8bf0938a3ad396506b2d3b8ce1fb402c9"
"url": "https://binaries.particle.io/gcc-arm/darwin/x64/gcc-arm-v9.2.1.tar.gz",
"sha256": "c98939900d147182f3e603a7ec4fd13e4e67292f3c7f1f3bc09308c7f97e9974"
}
],
"x86": []
Expand All @@ -39,10 +39,10 @@
"x64": [
{
"name": "gcc-arm",
"version": "5.3.1",
"version": "9.2.1",
"main": "./bin",
"url": "https://binaries.particle.io/gcc-arm/linux/x64/gcc-arm-v5.3.1.tar.gz",
"sha256": "99c8dc248a6f39c92268d680fc661b51b38b773db1148204cdf59792d170bfdc"
"url": "https://binaries.particle.io/gcc-arm/linux/x64/gcc-arm-v9.2.1.tar.gz",
"sha256": "d7c24c8a3464b1806c8d2e93e2d616acb1ac934199756316cf746fdfddaaefe4"
}
],
"x86": []
Expand Down
17 changes: 8 additions & 9 deletions bootloader/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@

void platform_startup();

__attribute__((naked)) static void jump_to_system(uint32_t addr, uint32_t sp) {
asm("msr msp, %1\n"
"bx %0\n" : : "r" (addr), "r" (sp));
}

/* Private typedef -----------------------------------------------------------*/
typedef void (*pFunction)(void);
Expand All @@ -62,8 +66,6 @@ volatile uint8_t FACTORY_RESET_MODE = 0; //0, 1
volatile uint8_t SAFE_MODE = 0;
volatile uint8_t RESET_SETTINGS = 0;

pFunction Jump_To_Application;
uint32_t JumpAddress;
uint32_t ApplicationAddress;

volatile uint32_t TimingBUTTON;
Expand Down Expand Up @@ -446,10 +448,6 @@ int main(void)
// Test if user code is programmed starting from ApplicationAddress
if (is_application_valid(ApplicationAddress))
{
// Jump to user application
JumpAddress = *(__IO uint32_t*) (ApplicationAddress + 4);
Jump_To_Application = (pFunction) JumpAddress;

uint8_t disable_iwdg = 0;
#ifdef CHECK_FIRMWARE
// Pre-0.7.0 firmwares were expecting IWDG flag to be set in the DCT, now it's stored in
Expand All @@ -466,9 +464,10 @@ int main(void)

Reset_System();

// Initialize user application's Stack Pointer
__set_MSP(*(__IO uint32_t*) ApplicationAddress);
Jump_To_Application();
// Jump to system firmware
uint32_t addr = *(volatile uint32_t*)(ApplicationAddress + 4);
uint32_t stack = *(volatile uint32_t*)ApplicationAddress;
jump_to_system(addr, stack);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference: this is required because GCC9 now throws a deprecated error when calling CMSIS __set_MSP(), which clobbers sp, which is in fact not what is supposed to happen.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A quote from recent gcc docs:

Another restriction is that the clobber list should not contain the stack pointer register. This is because the compiler requires the value of the stack pointer to be the same after an asm statement as it was on entry to the statement. However, previous versions of GCC did not enforce this rule and allowed the stack pointer to appear in the list, with unclear semantics. This behavior is deprecated and listing the stack pointer may become an error in future versions of GCC.

}
#if !HAL_PLATFORM_NRF52840
else
Expand Down
2 changes: 1 addition & 1 deletion hal/inc/spi_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
typedef enum HAL_SPI_Interface {
HAL_SPI_INTERFACE1 = 0, //maps to SPI1 (pins: A3, A4, A5)
HAL_SPI_INTERFACE2 = 1 //maps to SPI3 (pins: D4, D3, D2)
#if PLATFORM_ID == 10 // Electron
#if PLATFORM_ID == PLATFORM_ELECTRON_PRODUCTION
,HAL_SPI_INTERFACE3 = 2 //maps to SPI3 (pins: C3, C2, C1)
#endif
,TOTAL_SPI
Expand Down
8 changes: 4 additions & 4 deletions hal/src/electron/core_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
/**
* Start of interrupt vector table.
*/
extern char link_interrupt_vectors_location;
extern char link_ram_interrupt_vectors_location;
extern char link_ram_interrupt_vectors_location_end;
extern uintptr_t link_interrupt_vectors_location[];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference: this is now required because of array bounds checks warnings in GCC9.

extern uintptr_t link_ram_interrupt_vectors_location[];
extern uintptr_t link_ram_interrupt_vectors_location_end;

void SysTickChain();

Expand Down Expand Up @@ -170,7 +170,7 @@ void HAL_Core_Config_systick_configuration(void) {
*/
void HAL_Core_Setup_override_interrupts(void)
{
memcpy(&link_ram_interrupt_vectors_location, &link_interrupt_vectors_location, &link_ram_interrupt_vectors_location_end-&link_ram_interrupt_vectors_location);
memcpy(&link_ram_interrupt_vectors_location, &link_interrupt_vectors_location, (uintptr_t)&link_ram_interrupt_vectors_location_end-(uintptr_t)&link_ram_interrupt_vectors_location);
uint32_t* isrs = (uint32_t*)&link_ram_interrupt_vectors_location;
SCB->VTOR = (unsigned long)isrs;
}
Expand Down
8 changes: 4 additions & 4 deletions hal/src/nRF52840/core_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ void app_error_fault_handler(uint32_t id, uint32_t pc, uint32_t info);
void app_error_handler_bare(uint32_t err);

extern char link_heap_location, link_heap_location_end;
extern char link_interrupt_vectors_location;
extern char link_ram_interrupt_vectors_location;
extern char link_ram_interrupt_vectors_location_end;
extern uintptr_t link_interrupt_vectors_location[];
extern uintptr_t link_ram_interrupt_vectors_location[];
extern uintptr_t link_ram_interrupt_vectors_location_end;
extern char _Stack_Init;

static void* new_heap_end = &link_heap_location_end;
Expand Down Expand Up @@ -288,7 +288,7 @@ void HAL_Core_Config(void) {
#endif

/* Forward interrupts */
memcpy(&link_ram_interrupt_vectors_location, &link_interrupt_vectors_location, &link_ram_interrupt_vectors_location_end-&link_ram_interrupt_vectors_location);
memcpy(&link_ram_interrupt_vectors_location, &link_interrupt_vectors_location, (uintptr_t)&link_ram_interrupt_vectors_location_end-(uintptr_t)&link_ram_interrupt_vectors_location);
uint32_t* isrs = (uint32_t*)&link_ram_interrupt_vectors_location;
SCB->VTOR = (uint32_t)isrs;

Expand Down
6 changes: 3 additions & 3 deletions hal/src/nRF52840/interrupts_hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ struct hal_interrupts_suspend_data_t {

static hal_interrupts_suspend_data_t s_suspend_data = {};

extern char link_interrupt_vectors_location;
extern char link_ram_interrupt_vectors_location;
extern char link_ram_interrupt_vectors_location_end;
extern uintptr_t link_interrupt_vectors_location[];
extern uintptr_t link_ram_interrupt_vectors_location[];
extern uintptr_t link_ram_interrupt_vectors_location_end;

static void gpiote_interrupt_handler(nrfx_gpiote_pin_t nrf_pin, nrf_gpiote_polarity_t action) {
uint8_t pin = NRF_PIN_LOOKUP_TABLE[nrf_pin];
Expand Down
8 changes: 4 additions & 4 deletions hal/src/nRF52840/sleep_hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,10 @@ static int enterStopMode(const hal_sleep_config_t* config, hal_wakeup_source_bas
// Reducing power consumption
// Suspend all PWM instance remembering their state
bool pwmState[4] = {
NRF_PWM0->ENABLE & PWM_ENABLE_ENABLE_Msk,
NRF_PWM1->ENABLE & PWM_ENABLE_ENABLE_Msk,
NRF_PWM2->ENABLE & PWM_ENABLE_ENABLE_Msk,
NRF_PWM3->ENABLE & PWM_ENABLE_ENABLE_Msk,
(bool)(NRF_PWM0->ENABLE & PWM_ENABLE_ENABLE_Msk),
(bool)(NRF_PWM1->ENABLE & PWM_ENABLE_ENABLE_Msk),
(bool)(NRF_PWM2->ENABLE & PWM_ENABLE_ENABLE_Msk),
(bool)(NRF_PWM3->ENABLE & PWM_ENABLE_ENABLE_Msk),
};
nrf_pwm_disable(NRF_PWM0);
nrf_pwm_disable(NRF_PWM1);
Expand Down
6 changes: 4 additions & 2 deletions hal/src/nRF52840/spi_hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
#include "concurrent_hal.h"
#include "delay_hal.h"



#define DEFAULT_SPI_MODE SPI_MODE_MASTER
#define DEFAULT_DATA_MODE SPI_MODE3
#define DEFAULT_BIT_ORDER MSBFIRST
Expand Down Expand Up @@ -288,6 +286,10 @@ void HAL_SPI_Begin(HAL_SPI_Interface spi, uint16_t pin) {
}

void HAL_SPI_Begin_Ext(HAL_SPI_Interface spi, SPI_Mode mode, uint16_t pin, void* reserved) {
if (spi >= TOTAL_SPI) {
return;
}

if (spi == HAL_SPI_INTERFACE1 && mode == SPI_MODE_SLAVE) {
// HAL_SPI_INTERFACE1 does not support slave mode
return;
Expand Down
2 changes: 1 addition & 1 deletion hal/src/nRF52840/timer_hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ volatile uint32_t sTickCountAtLastOverflow = 0; ///< DWT->CYCCNT value at the ti
volatile uint64_t sTimerMicrosAtLastOverflow = 0; ///< microseconds at the time latest overflow occured
volatile uint64_t sTimerMicrosBaseOffset = 0; ///< Base offset for Particle-specific microsecond counter

constexpr auto RTC_INSTANCE = NRF_RTC2;
auto RTC_INSTANCE = NRF_RTC2;
constexpr auto RTC_IRQN = RTC2_IRQn;
constexpr auto RTC_IRQ_PRIORITY = 6;
constexpr auto RTC_USECS_PER_SEC = 1000000ULL;
Expand Down
13 changes: 13 additions & 0 deletions hal/src/newhal/concurrent_hal_impl.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <bits/gthr-default.h>
#include <time.h>

// redefine these for the underlying concurrency primitives available in the RTOS
Expand All @@ -17,3 +18,15 @@ typedef struct timespec __gthread_time_t;

#define OS_THREAD_PRIORITY_DEFAULT (0)
#define OS_THREAD_STACK_SIZE_DEFAULT (0)

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

int __gthread_mutex_timedlock (__gthread_mutex_t* mutex, const __gthread_time_t* timeout);

int __gthread_recursive_mutex_timedlock (__gthread_recursive_mutex_t* mutex, const __gthread_time_t* timeout);

#ifdef __cplusplus
}
#endif // __cplusplus
8 changes: 4 additions & 4 deletions hal/src/photon/core_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ void SysTickChain();
/**
* Start of interrupt vector table.
*/
extern char link_interrupt_vectors_location;
extern uintptr_t link_interrupt_vectors_location[];

extern char link_ram_interrupt_vectors_location;
extern char link_ram_interrupt_vectors_location_end;
extern uintptr_t link_ram_interrupt_vectors_location[];
extern uintptr_t link_ram_interrupt_vectors_location_end;

const HAL_InterruptOverrideEntry hal_interrupt_overrides[] = {
{HardFault_IRQn, HardFault_Handler},
Expand Down Expand Up @@ -70,7 +70,7 @@ void HAL_Core_Config_systick_configuration(void) {

void HAL_Core_Setup_override_interrupts(void) {

memcpy(&link_ram_interrupt_vectors_location, &link_interrupt_vectors_location, &link_ram_interrupt_vectors_location_end-&link_ram_interrupt_vectors_location);
memcpy(&link_ram_interrupt_vectors_location, &link_interrupt_vectors_location, (uintptr_t)&link_ram_interrupt_vectors_location_end-(uintptr_t)&link_ram_interrupt_vectors_location);
uint32_t* isrs = (uint32_t*)&link_ram_interrupt_vectors_location;
for(int i = 0; i < sizeof(hal_interrupt_overrides)/sizeof(HAL_InterruptOverrideEntry); i++) {
isrs[IRQN_TO_IDX(hal_interrupt_overrides[i].irq)] = (uint32_t)hal_interrupt_overrides[i].handler;
Expand Down
2 changes: 1 addition & 1 deletion scripts/fetch-buildpack
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
BUILDPACK_FILES=$(mkdir buildpack && wget https://github.com/particle-iot/firmware-buildpack-builder/tarball/0.0.8 -O - | tar -xvz -C buildpack --strip-components 1)
BUILDPACK_FILES=$(mkdir buildpack && wget https://github.com/particle-iot/firmware-buildpack-builder/tarball/0.0.10 -O - | tar -xvz -C buildpack --strip-components 1)
SHORT_REF=$(echo "$BUILDPACK_FILES" | head -n1 | cut -d '/' -f 1 | rev | cut -d '-' -f 1 | rev)
mkdir buildpack/.git
echo "${SHORT_REF}" > buildpack/.git/short_ref
6 changes: 3 additions & 3 deletions user/tests/wiring/api/arduino.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ test(map) {
}

test(trigs) {
sin(0.5);
cos(0.5);
tan(0.5);
API_COMPILE((void)sin(0.5));
API_COMPILE((void)cos(0.5));
API_COMPILE((void)tan(0.5));
}

test(LED_BUILTIN) {
Expand Down
2 changes: 1 addition & 1 deletion user/tests/wiring/api/cloud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ test(api_spark_sleep) {
test(api_spark_connection) {
bool connected = false;
API_COMPILE(connected=Particle.connected());
connected++;
(void)connected;
API_COMPILE(Particle.connect());
API_COMPILE(Particle.disconnect());
API_COMPILE(Particle.disconnect(CloudDisconnectOptions().graceful(true).timeout(60000)));
Expand Down
4 changes: 2 additions & 2 deletions user/tests/wiring/api/led.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ class CustomStatus: public LEDStatus {
test(api_led_status) {
// LEDStatus()
API_COMPILE(LEDStatus());
API_COMPILE(LEDStatus(LED_PATTERN_BLINK));
API_COMPILE(LEDStatus dummy(LED_PATTERN_BLINK));
API_COMPILE(LEDStatus(LED_PATTERN_BLINK, LED_SPEED_NORMAL));
API_COMPILE(LEDStatus(LED_PATTERN_BLINK, 1000 /* period */));
API_COMPILE(LEDStatus(RGB_COLOR_WHITE));
API_COMPILE(LEDStatus(RGB_COLOR_WHITE, LED_PATTERN_BLINK));
API_COMPILE(LEDStatus(RGB_COLOR_WHITE, LED_PATTERN_BLINK, LED_SPEED_NORMAL));
API_COMPILE(LEDStatus(RGB_COLOR_WHITE, LED_PATTERN_BLINK, 1000 /* period */));
// Same as above plus priority argument
API_COMPILE(LEDStatus(LED_PRIORITY_NORMAL));
API_COMPILE(LEDStatus dummy(LED_PRIORITY_NORMAL));
API_COMPILE(LEDStatus(LED_PATTERN_BLINK, LED_PRIORITY_NORMAL));
API_COMPILE(LEDStatus(LED_PATTERN_BLINK, LED_SPEED_NORMAL, LED_PRIORITY_NORMAL));
API_COMPILE(LEDStatus(LED_PATTERN_BLINK, 1000 /* period */, LED_PRIORITY_NORMAL));
Expand Down
2 changes: 1 addition & 1 deletion user/tests/wiring/api/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

test(api_ip_address) {

API_COMPILE(IPAddress(HAL_IPAddress()));
API_COMPILE(IPAddress dummy(HAL_IPAddress()));



Expand Down
4 changes: 2 additions & 2 deletions user/tests/wiring/api/string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ test(api_string) {
API_COMPILE(String());
API_COMPILE(String("abc"));
API_COMPILE(String("abc", 3));
API_COMPILE(String(s)); // Copy constructor
API_COMPILE(String dummy(s)); // Copy constructor
API_COMPILE(String(std::move(s))); // Move constructor
API_COMPILE(String('a'));
API_COMPILE(String(123, (unsigned)10 /* base */)); // FIXME: Ambiguous call
Expand Down Expand Up @@ -127,6 +127,6 @@ test(api_string) {

test(api_string_constructor_printable) {
IPAddress address;
API_COMPILE(String(address));
API_COMPILE(String dummy(address));
(void)address;
}
6 changes: 3 additions & 3 deletions user/tests/wiring/api/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,9 @@ test(system_sleep)

test(system_mode) {
API_COMPILE(System.mode());
API_COMPILE(SystemClass(AUTOMATIC));
API_COMPILE(SystemClass(SEMI_AUTOMATIC));
API_COMPILE(SystemClass(MANUAL));
API_COMPILE(SystemClass dummy(AUTOMATIC));
API_COMPILE(SystemClass dummy(SEMI_AUTOMATIC));
API_COMPILE(SystemClass dummy(MANUAL));

// braces are required since the macro evaluates to a declaration
API_COMPILE({ SYSTEM_MODE(AUTOMATIC) });
Expand Down
8 changes: 5 additions & 3 deletions user/tests/wiring/api/wifi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,17 @@
test(api_wifi_config)
{
IPAddress address;
uint8_t* ether = nullptr;
uint8_t mac[6];
uint8_t* ether;
String ssid;
API_COMPILE(ssid=WiFi.SSID());
API_COMPILE(address=WiFi.localIP());
API_COMPILE(address=WiFi.dnsServerIP());
API_COMPILE(address=WiFi.dhcpServerIP());
API_COMPILE(address=WiFi.gatewayIP());
API_COMPILE(ether=WiFi.macAddress(ether));
API_COMPILE(ether=WiFi.BSSID(ether));
API_COMPILE(ether=WiFi.macAddress(mac));
API_COMPILE(ether=WiFi.BSSID(mac));
(void)ether;
}

test(api_wifi_resolve)
Expand Down
2 changes: 1 addition & 1 deletion user/tests/wiring/no_fixture/spi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ static __SPISettings spiSettingsFromSpiInfo(hal_spi_info_t* info)
return __SPISettings(info->clock, info->bit_order, info->data_mode);
}

static bool spiSettingsApplyCheck(auto& spi, const __SPISettings& settings, HAL_SPI_Interface interface = HAL_SPI_INTERFACE1)
static bool spiSettingsApplyCheck(SPIClass& spi, const __SPISettings& settings, HAL_SPI_Interface interface = HAL_SPI_INTERFACE1)
{
hal_spi_info_t info;
spi.beginTransaction(settings);
Expand Down
6 changes: 4 additions & 2 deletions user/tests/wiring/no_fixture/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ test(SYSTEM_06_out_of_memory)

const size_t size = 1024*1024*1024;
register_oom();
malloc(size);
auto ptr = malloc(size);
(void)ptr;
Particle.process();
unregister_oom();

Expand Down Expand Up @@ -257,7 +258,8 @@ test(SYSTEM_08_out_of_memory_not_raised_for_0_size_malloc)
{
const size_t size = 0;
register_oom();
malloc(size);
auto ptr = malloc(size);
(void)ptr;
Particle.process();
unregister_oom();

Expand Down
Loading