diff --git a/CMakeLists.txt b/CMakeLists.txt index b5b027c9b6..c932b261c4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -264,23 +264,20 @@ add_subdirectory(cmsis/device/rtos EXCLUDE_FROM_ALL) # Create top-level targets ---------------------------------------------------------------------------------- if(NOT MBED_IS_NATIVE_BUILD) - - # Create a distro for the microcontroller cmake target, ensuring its sources are only compiled once - mbed_create_distro(${MBED_TARGET_CMAKE_NAME}-lib ${MBED_TARGET_CMAKE_NAME} mbed-core-flags) - - # Set up the linker script and hook it up to the MCU cmake target - mbed_setup_linker_script(${MBED_TARGET_CMAKE_NAME}-lib) - - # Now make the Mbed OS code depend on the target, ensuring everything has access to the uC's flags and objects. - target_link_libraries(mbed-core-flags INTERFACE ${MBED_TARGET_CMAKE_NAME}-lib) - # Core Mbed OS libraries # mbed-baremetal contains baremetal sources + target sources + target compile flags. # mbed-os will be a superset of mbed-baremetal, also containing the RTOS sources and RTOS flags. # Note that many different source files will compile differently depending on if the RTOS is in use. # So, it's needed to compile the core sources twice, once for RTOS and once for non-RTOS. - mbed_create_distro(mbed-baremetal mbed-core-flags mbed-core-sources) - mbed_create_distro(mbed-os mbed-core-flags mbed-core-sources mbed-rtos-flags mbed-rtos-sources) + mbed_create_distro(mbed-baremetal ${MBED_TARGET_CMAKE_NAME} mbed-core-flags mbed-core-sources) + mbed_create_distro(mbed-os ${MBED_TARGET_CMAKE_NAME} mbed-core-flags mbed-core-sources mbed-rtos-flags mbed-rtos-sources) + + # Set up the linker script and hook it up to the top-level OS targets + mbed_setup_linker_script(mbed-baremetal mbed-os) + + # Make sure that things linking mbed-core-flags can also get the target-specific include dirs and flags. + mbed_extract_flags(${MBED_TARGET_CMAKE_NAME}-flags ${MBED_TARGET_CMAKE_NAME}) + target_link_libraries(mbed-core-flags INTERFACE ${MBED_TARGET_CMAKE_NAME}-flags) endif() # Ninja requires to be forced for response files diff --git a/connectivity/drivers/emac/TARGET_STM/CMakeLists.txt b/connectivity/drivers/emac/TARGET_STM/CMakeLists.txt index 6391816499..bc7b057676 100644 --- a/connectivity/drivers/emac/TARGET_STM/CMakeLists.txt +++ b/connectivity/drivers/emac/TARGET_STM/CMakeLists.txt @@ -19,5 +19,4 @@ target_include_directories(mbed-emac target_sources(mbed-emac PRIVATE stm32xx_emac.cpp - stm32xx_eth_irq_callback.cpp ) diff --git a/connectivity/drivers/emac/TARGET_STM/TARGET_STM32F2/TARGET_NUCLEO_F207ZG/stm32f2_eth_init.c b/connectivity/drivers/emac/TARGET_STM/TARGET_STM32F2/TARGET_NUCLEO_F207ZG/stm32f2_eth_init.c index 7b054c7eed..c2fa21015d 100644 --- a/connectivity/drivers/emac/TARGET_STM/TARGET_STM32F2/TARGET_NUCLEO_F207ZG/stm32f2_eth_init.c +++ b/connectivity/drivers/emac/TARGET_STM/TARGET_STM32F2/TARGET_NUCLEO_F207ZG/stm32f2_eth_init.c @@ -1,7 +1,9 @@ /* mbed Microcontroller Library - * Copyright (c) 2018, STMicroelectronics + * Copyright (c) 2022, STMicroelectronics * All rights reserved. * + * SPDX-License-Identifier: Apache-2.0 + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * @@ -117,3 +119,7 @@ void HAL_ETH_MspDeInit(ETH_HandleTypeDef *heth) } #endif /* USE_USER_DEFINED_HAL_ETH_MSPINIT */ + +// Blank, non-weak-override function to make sure the linker pulls in this file +void stm32_eth_init_weak_symbol_helper() +{} \ No newline at end of file diff --git a/connectivity/drivers/emac/TARGET_STM/TARGET_STM32F4/TARGET_ARCH_MAX/stm32f4_eth_init.c b/connectivity/drivers/emac/TARGET_STM/TARGET_STM32F4/TARGET_ARCH_MAX/stm32f4_eth_init.c index a95ea0f8ea..f824247481 100644 --- a/connectivity/drivers/emac/TARGET_STM/TARGET_STM32F4/TARGET_ARCH_MAX/stm32f4_eth_init.c +++ b/connectivity/drivers/emac/TARGET_STM/TARGET_STM32F4/TARGET_ARCH_MAX/stm32f4_eth_init.c @@ -1,3 +1,33 @@ +/* mbed Microcontroller Library + * Copyright (c) 2022, STMicroelectronics + * All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + #include "stm32f4xx_hal.h" /** @@ -79,3 +109,7 @@ void HAL_ETH_MspDeInit(ETH_HandleTypeDef *heth) NVIC_DisableIRQ(ETH_IRQn); } } + +// Blank, non-weak-override function to make sure the linker pulls in this file +void stm32_eth_init_weak_symbol_helper() +{} \ No newline at end of file diff --git a/connectivity/drivers/emac/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F429ZI/stm32f4_eth_init.c b/connectivity/drivers/emac/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F429ZI/stm32f4_eth_init.c index 09dfb94000..223af59124 100644 --- a/connectivity/drivers/emac/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F429ZI/stm32f4_eth_init.c +++ b/connectivity/drivers/emac/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F429ZI/stm32f4_eth_init.c @@ -1,7 +1,9 @@ /* mbed Microcontroller Library - * Copyright (c) 2018, STMicroelectronics + * Copyright (c) 2022, STMicroelectronics * All rights reserved. * + * SPDX-License-Identifier: Apache-2.0 + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * @@ -117,3 +119,7 @@ void HAL_ETH_MspDeInit(ETH_HandleTypeDef *heth) } #endif /* USE_USER_DEFINED_HAL_ETH_MSPINIT */ + +// Blank, non-weak-override function to make sure the linker pulls in this file +void stm32_eth_init_weak_symbol_helper() +{} \ No newline at end of file diff --git a/connectivity/drivers/emac/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F439ZI/stm32f4_eth_init.c b/connectivity/drivers/emac/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F439ZI/stm32f4_eth_init.c index 09dfb94000..223af59124 100644 --- a/connectivity/drivers/emac/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F439ZI/stm32f4_eth_init.c +++ b/connectivity/drivers/emac/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F439ZI/stm32f4_eth_init.c @@ -1,7 +1,9 @@ /* mbed Microcontroller Library - * Copyright (c) 2018, STMicroelectronics + * Copyright (c) 2022, STMicroelectronics * All rights reserved. * + * SPDX-License-Identifier: Apache-2.0 + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * @@ -117,3 +119,7 @@ void HAL_ETH_MspDeInit(ETH_HandleTypeDef *heth) } #endif /* USE_USER_DEFINED_HAL_ETH_MSPINIT */ + +// Blank, non-weak-override function to make sure the linker pulls in this file +void stm32_eth_init_weak_symbol_helper() +{} \ No newline at end of file diff --git a/connectivity/drivers/emac/TARGET_STM/TARGET_STM32F7/TARGET_DISCO_F746NG/stm32f7_eth_init.c b/connectivity/drivers/emac/TARGET_STM/TARGET_STM32F7/TARGET_DISCO_F746NG/stm32f7_eth_init.c index 28836e03b8..dd5e38e027 100644 --- a/connectivity/drivers/emac/TARGET_STM/TARGET_STM32F7/TARGET_DISCO_F746NG/stm32f7_eth_init.c +++ b/connectivity/drivers/emac/TARGET_STM/TARGET_STM32F7/TARGET_DISCO_F746NG/stm32f7_eth_init.c @@ -1,7 +1,9 @@ /* mbed Microcontroller Library - * Copyright (c) 2018, STMicroelectronics + * Copyright (c) 2022, STMicroelectronics * All rights reserved. * + * SPDX-License-Identifier: Apache-2.0 + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * @@ -116,3 +118,7 @@ void HAL_ETH_MspDeInit(ETH_HandleTypeDef *heth) } #endif /* USE_USER_DEFINED_HAL_ETH_MSPINIT */ + +// Blank, non-weak-override function to make sure the linker pulls in this file +void stm32_eth_init_weak_symbol_helper() +{} \ No newline at end of file diff --git a/connectivity/drivers/emac/TARGET_STM/TARGET_STM32F7/TARGET_DISCO_F769NI/stm32f7_eth_init.c b/connectivity/drivers/emac/TARGET_STM/TARGET_STM32F7/TARGET_DISCO_F769NI/stm32f7_eth_init.c index d798504c34..90d00bc661 100644 --- a/connectivity/drivers/emac/TARGET_STM/TARGET_STM32F7/TARGET_DISCO_F769NI/stm32f7_eth_init.c +++ b/connectivity/drivers/emac/TARGET_STM/TARGET_STM32F7/TARGET_DISCO_F769NI/stm32f7_eth_init.c @@ -1,7 +1,9 @@ /* mbed Microcontroller Library - * Copyright (c) 2018, STMicroelectronics + * Copyright (c) 2022, STMicroelectronics * All rights reserved. * + * SPDX-License-Identifier: Apache-2.0 + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * @@ -122,3 +124,7 @@ void HAL_ETH_MspDeInit(ETH_HandleTypeDef *heth) } #endif /* USE_USER_DEFINED_HAL_ETH_MSPINIT */ + +// Blank, non-weak-override function to make sure the linker pulls in this file +void stm32_eth_init_weak_symbol_helper() +{} \ No newline at end of file diff --git a/connectivity/drivers/emac/TARGET_STM/TARGET_STM32F7/TARGET_NUCLEO_F746ZG/stm32f7_eth_init.c b/connectivity/drivers/emac/TARGET_STM/TARGET_STM32F7/TARGET_NUCLEO_F746ZG/stm32f7_eth_init.c index 404d908016..064c5a6ee2 100644 --- a/connectivity/drivers/emac/TARGET_STM/TARGET_STM32F7/TARGET_NUCLEO_F746ZG/stm32f7_eth_init.c +++ b/connectivity/drivers/emac/TARGET_STM/TARGET_STM32F7/TARGET_NUCLEO_F746ZG/stm32f7_eth_init.c @@ -1,7 +1,9 @@ /* mbed Microcontroller Library - * Copyright (c) 2018, STMicroelectronics + * Copyright (c) 2022, STMicroelectronics * All rights reserved. * + * SPDX-License-Identifier: Apache-2.0 + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * @@ -122,3 +124,7 @@ void HAL_ETH_MspDeInit(ETH_HandleTypeDef *heth) } #endif /* USE_USER_DEFINED_HAL_ETH_MSPINIT */ + +// Blank, non-weak-override function to make sure the linker pulls in this file +void stm32_eth_init_weak_symbol_helper() +{} diff --git a/connectivity/drivers/emac/TARGET_STM/TARGET_STM32F7/TARGET_NUCLEO_F756ZG/stm32f7_eth_init.c b/connectivity/drivers/emac/TARGET_STM/TARGET_STM32F7/TARGET_NUCLEO_F756ZG/stm32f7_eth_init.c index 404d908016..14bec833c4 100644 --- a/connectivity/drivers/emac/TARGET_STM/TARGET_STM32F7/TARGET_NUCLEO_F756ZG/stm32f7_eth_init.c +++ b/connectivity/drivers/emac/TARGET_STM/TARGET_STM32F7/TARGET_NUCLEO_F756ZG/stm32f7_eth_init.c @@ -1,7 +1,9 @@ /* mbed Microcontroller Library - * Copyright (c) 2018, STMicroelectronics + * Copyright (c) 2022, STMicroelectronics * All rights reserved. * + * SPDX-License-Identifier: Apache-2.0 + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * @@ -122,3 +124,7 @@ void HAL_ETH_MspDeInit(ETH_HandleTypeDef *heth) } #endif /* USE_USER_DEFINED_HAL_ETH_MSPINIT */ + +// Blank, non-weak-override function to make sure the linker pulls in this file +void stm32_eth_init_weak_symbol_helper() +{} \ No newline at end of file diff --git a/connectivity/drivers/emac/TARGET_STM/TARGET_STM32F7/TARGET_NUCLEO_F767ZI/stm32f7_eth_init.c b/connectivity/drivers/emac/TARGET_STM/TARGET_STM32F7/TARGET_NUCLEO_F767ZI/stm32f7_eth_init.c index 404d908016..05559878a9 100644 --- a/connectivity/drivers/emac/TARGET_STM/TARGET_STM32F7/TARGET_NUCLEO_F767ZI/stm32f7_eth_init.c +++ b/connectivity/drivers/emac/TARGET_STM/TARGET_STM32F7/TARGET_NUCLEO_F767ZI/stm32f7_eth_init.c @@ -1,7 +1,9 @@ /* mbed Microcontroller Library - * Copyright (c) 2018, STMicroelectronics + * Copyright (c) 2022, STMicroelectronics * All rights reserved. * + * SPDX-License-Identifier: Apache-2.0 + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * @@ -25,7 +27,6 @@ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - #ifndef USE_USER_DEFINED_HAL_ETH_MSPINIT #include "stm32f7xx_hal.h" @@ -122,3 +123,7 @@ void HAL_ETH_MspDeInit(ETH_HandleTypeDef *heth) } #endif /* USE_USER_DEFINED_HAL_ETH_MSPINIT */ + +// Blank, non-weak-override function to make sure the linker pulls in this file +void stm32_eth_init_weak_symbol_helper() +{} diff --git a/connectivity/drivers/emac/TARGET_STM/TARGET_STM32H7/TARGET_DISCO_H747I/stm32h7_eth_init.c b/connectivity/drivers/emac/TARGET_STM/TARGET_STM32H7/TARGET_DISCO_H747I/stm32h7_eth_init.c index 79af6dd486..a7d1444d7c 100644 --- a/connectivity/drivers/emac/TARGET_STM/TARGET_STM32H7/TARGET_DISCO_H747I/stm32h7_eth_init.c +++ b/connectivity/drivers/emac/TARGET_STM/TARGET_STM32H7/TARGET_DISCO_H747I/stm32h7_eth_init.c @@ -1,7 +1,9 @@ /* mbed Microcontroller Library - * Copyright (c) 2018, STMicroelectronics + * Copyright (c) 2022, STMicroelectronics * All rights reserved. * + * SPDX-License-Identifier: Apache-2.0 + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * @@ -150,3 +152,7 @@ void HAL_ETH_MspDeInit(ETH_HandleTypeDef *heth) } #endif /* USE_USER_DEFINED_HAL_ETH_MSPINIT */ + +// Blank, non-weak-override function to make sure the linker pulls in this file +void stm32_eth_init_weak_symbol_helper() +{} \ No newline at end of file diff --git a/connectivity/drivers/emac/TARGET_STM/TARGET_STM32H7/TARGET_NUCLEO_H743ZI/stm32h7_eth_init.c b/connectivity/drivers/emac/TARGET_STM/TARGET_STM32H7/TARGET_NUCLEO_H743ZI/stm32h7_eth_init.c index 0690d7bf67..81be13b3c5 100644 --- a/connectivity/drivers/emac/TARGET_STM/TARGET_STM32H7/TARGET_NUCLEO_H743ZI/stm32h7_eth_init.c +++ b/connectivity/drivers/emac/TARGET_STM/TARGET_STM32H7/TARGET_NUCLEO_H743ZI/stm32h7_eth_init.c @@ -1,7 +1,9 @@ /* mbed Microcontroller Library - * Copyright (c) 2018, STMicroelectronics + * Copyright (c) 2022, STMicroelectronics * All rights reserved. * + * SPDX-License-Identifier: Apache-2.0 + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * @@ -161,3 +163,7 @@ void HAL_ETH_MspDeInit(ETH_HandleTypeDef *heth) } #endif /* USE_USER_DEFINED_HAL_ETH_MSPINIT */ + +// Blank, non-weak-override function to make sure the linker pulls in this file +void stm32_eth_init_weak_symbol_helper() +{} diff --git a/connectivity/drivers/emac/TARGET_STM/TARGET_STM32H7/TARGET_NUCLEO_H743ZI2/stm32h7_eth_init.c b/connectivity/drivers/emac/TARGET_STM/TARGET_STM32H7/TARGET_NUCLEO_H743ZI2/stm32h7_eth_init.c index 0690d7bf67..a06114909c 100644 --- a/connectivity/drivers/emac/TARGET_STM/TARGET_STM32H7/TARGET_NUCLEO_H743ZI2/stm32h7_eth_init.c +++ b/connectivity/drivers/emac/TARGET_STM/TARGET_STM32H7/TARGET_NUCLEO_H743ZI2/stm32h7_eth_init.c @@ -1,7 +1,9 @@ /* mbed Microcontroller Library - * Copyright (c) 2018, STMicroelectronics + * Copyright (c) 2022, STMicroelectronics * All rights reserved. * + * SPDX-License-Identifier: Apache-2.0 + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * @@ -161,3 +163,7 @@ void HAL_ETH_MspDeInit(ETH_HandleTypeDef *heth) } #endif /* USE_USER_DEFINED_HAL_ETH_MSPINIT */ + +// Blank, non-weak-override function to make sure the linker pulls in this file +void stm32_eth_init_weak_symbol_helper() +{} \ No newline at end of file diff --git a/connectivity/drivers/emac/TARGET_STM/TARGET_STM32H7/TARGET_PORTENTA_H7/stm32h7_eth_init.c b/connectivity/drivers/emac/TARGET_STM/TARGET_STM32H7/TARGET_PORTENTA_H7/stm32h7_eth_init.c index 3fbac0555f..f9891ff757 100644 --- a/connectivity/drivers/emac/TARGET_STM/TARGET_STM32H7/TARGET_PORTENTA_H7/stm32h7_eth_init.c +++ b/connectivity/drivers/emac/TARGET_STM/TARGET_STM32H7/TARGET_PORTENTA_H7/stm32h7_eth_init.c @@ -1,10 +1,9 @@ /* mbed Microcontroller Library - * Copyright (c) 2018, STMicroelectronics - * Copyright (c) 2020, Arduino SA - * - * SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2022, STMicroelectronics * All rights reserved. * + * SPDX-License-Identifier: Apache-2.0 + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * @@ -176,3 +175,7 @@ void HAL_ETH_MspDeInit(ETH_HandleTypeDef *heth) } #endif /* USE_USER_DEFINED_HAL_ETH_MSPINIT */ + +// Blank, non-weak-override function to make sure the linker pulls in this file +void stm32_eth_init_weak_symbol_helper() +{} \ No newline at end of file diff --git a/connectivity/drivers/emac/TARGET_STM/stm32xx_emac.cpp b/connectivity/drivers/emac/TARGET_STM/stm32xx_emac.cpp index 0230a90665..daddbf1167 100644 --- a/connectivity/drivers/emac/TARGET_STM/stm32xx_emac.cpp +++ b/connectivity/drivers/emac/TARGET_STM/stm32xx_emac.cpp @@ -145,7 +145,16 @@ extern "C" { void _eth_config_mac(ETH_HandleTypeDef *heth); void ETH_IRQHandler(void); -MBED_WEAK void STM_HAL_ETH_Handler(ETH_HandleTypeDef *heth); + +// We need to give the linker a reason to pull in the stmxx_eth_init.c files, since they only contain +// weak symbol overrides and would otherwise be ignored. +void stm32_eth_init_weak_symbol_helper(); + +#ifdef USE_USER_DEFINED_HAL_ETH_IRQ_CALLBACK +MBED_WEAK void STM_HAL_ETH_Handler(); +#else +void STM_HAL_ETH_Handler(); +#endif #ifdef __cplusplus } @@ -242,16 +251,6 @@ static void MPU_Config(void) #endif -/** - * IRQ Handler - * - * @param heth: ETH handle - * @retval None - */ -MBED_WEAK void STM_HAL_ETH_Handler() -{ -} - /** * Ethernet IRQ Handler * @@ -289,6 +288,9 @@ static osThreadId_t create_new_thread(const char *threadName, void (*thread)(voi bool STM32_EMAC::low_level_init_successful() #ifndef ETH_IP_VERSION_V2 { + // Generate a reference to this empty function so the linker pulls it in. + stm32_eth_init_weak_symbol_helper(); + uint32_t PHY_ID; /* Init ETH */ @@ -360,6 +362,9 @@ bool STM32_EMAC::low_level_init_successful() { uint32_t idx; + // Generate a reference to this empty function so the linker pulls it in. + stm32_eth_init_weak_symbol_helper(); + MPU_Config(); /* Init ETH */ @@ -1085,4 +1090,46 @@ void HAL_ETH_MACErrorCallback(ETH_HandleTypeDef *heth) } #endif // ETH_IP_VERSION_V2 +#ifndef USE_USER_DEFINED_HAL_ETH_IRQ_CALLBACK + +#define FLAG_RX 1 + +/** + * Override Ethernet Rx Transfer completed callback + * @param heth: ETH handle + * @retval None + */ +void HAL_ETH_RxCpltCallback(ETH_HandleTypeDef *heth) +{ + STM32_EMAC &emac = STM32_EMAC::get_instance(); + if (emac.thread) { + osThreadFlagsSet(emac.thread, FLAG_RX); + } +} + +/** + * Override the IRQ Handler + * @param None + * @retval None + */ +void STM_HAL_ETH_Handler() +{ + STM32_EMAC &emac = STM32_EMAC::get_instance(); + HAL_ETH_IRQHandler(&emac.EthHandle); +} + +#else /* USE_USER_DEFINED_HAL_ETH_IRQ_CALLBACK */ + +/** + * IRQ Handler + * + * @param heth: ETH handle + * @retval None + */ +MBED_WEAK void STM_HAL_ETH_Handler() +{ +} + +#endif /* USE_USER_DEFINED_HAL_ETH_IRQ_CALLBACK */ + #endif /* DEVICE_EMAC */ diff --git a/connectivity/drivers/emac/TARGET_STM/stm32xx_eth_irq_callback.cpp b/connectivity/drivers/emac/TARGET_STM/stm32xx_eth_irq_callback.cpp deleted file mode 100644 index cfe7782a68..0000000000 --- a/connectivity/drivers/emac/TARGET_STM/stm32xx_eth_irq_callback.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/* Copyright (c) 2017-2019 ARM Limited - * Copyright (c) 2017-2019 STMicroelectronics - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef USE_USER_DEFINED_HAL_ETH_IRQ_CALLBACK - -#if DEVICE_EMAC - -#include "stm32xx_emac.h" -#define FLAG_RX 1 - -/** - * Override Ethernet Rx Transfer completed callback - * @param heth: ETH handle - * @retval None - */ -void HAL_ETH_RxCpltCallback(ETH_HandleTypeDef *heth) -{ - STM32_EMAC &emac = STM32_EMAC::get_instance(); - if (emac.thread) { - osThreadFlagsSet(emac.thread, FLAG_RX); - } -} - -/** - * Override the IRQ Handler - * @param None - * @retval None - */ -void STM_HAL_ETH_Handler() -{ - STM32_EMAC &emac = STM32_EMAC::get_instance(); - HAL_ETH_IRQHandler(&emac.EthHandle); -} - -#endif /* DEVICE_EMAC */ - -#endif /* USE_USER_DEFINED_HAL_ETH_IRQ_CALLBACK */ diff --git a/connectivity/lwipstack/CMakeLists.txt b/connectivity/lwipstack/CMakeLists.txt index 9baff8bb2e..ddd4e9cb27 100644 --- a/connectivity/lwipstack/CMakeLists.txt +++ b/connectivity/lwipstack/CMakeLists.txt @@ -102,3 +102,4 @@ target_link_libraries(mbed-lwipstack PRIVATE mbed-rtos-flags ) + diff --git a/connectivity/netsocket/CMakeLists.txt b/connectivity/netsocket/CMakeLists.txt index 9e810ca55c..0d9c0d0432 100644 --- a/connectivity/netsocket/CMakeLists.txt +++ b/connectivity/netsocket/CMakeLists.txt @@ -55,21 +55,28 @@ target_link_libraries(mbed-netsocket-api mbed-mbedtls ) +# Currently, netsocket-api needs to link to whichever library is providing an implementation +# of OnboardNetworkStack::get_default_instance(). Otherwise, the link order is not correct. +if("MBED_CONF_NSAPI_DEFAULT_STACK=LWIP" IN_LIST MBED_CONFIG_DEFINITIONS) + target_link_libraries(mbed-netsocket-api PUBLIC mbed-lwipstack) +elseif("MBED_CONF_NSAPI_DEFAULT_STACK=NANOSTACK" IN_LIST MBED_CONFIG_DEFINITIONS) + target_link_libraries(mbed-netsocket-api PUBLIC mbed-nanostack) +endif() + +if("DEVICE_EMAC=1" IN_LIST MBED_TARGET_DEFINITIONS) + target_link_libraries(mbed-netsocket-api + INTERFACE + mbed-emac + ) +endif() + add_library(mbed-netsocket INTERFACE) target_link_libraries(mbed-netsocket INTERFACE mbed-mbedtls - mbed-lwipstack ) -if("DEVICE_EMAC=1" IN_LIST MBED_TARGET_DEFINITIONS) - target_link_libraries(mbed-netsocket - INTERFACE - mbed-emac - ) -endif() - target_link_libraries(mbed-netsocket INTERFACE mbed-wifi diff --git a/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/scripts/mbed_set_post_build_tfm.cmake b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/scripts/mbed_set_post_build_tfm.cmake index 577ad91677..68ae36b656 100644 --- a/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/scripts/mbed_set_post_build_tfm.cmake +++ b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/scripts/mbed_set_post_build_tfm.cmake @@ -1,7 +1,7 @@ # Copyright (c) 2021 ARM Limited. All rights reserved. # SPDX-License-Identifier: Apache-2.0 -include(mbed_set_post_build) +include(mbed_target_functions) # # Sign TF-M secure and non-secure images and combine them with the bootloader diff --git a/targets/TARGET_Cypress/scripts/mbed_set_post_build_cypress.cmake b/targets/TARGET_Cypress/scripts/mbed_set_post_build_cypress.cmake index 5dbe9e24b4..0a3ebe3e41 100644 --- a/targets/TARGET_Cypress/scripts/mbed_set_post_build_cypress.cmake +++ b/targets/TARGET_Cypress/scripts/mbed_set_post_build_cypress.cmake @@ -1,7 +1,7 @@ # Copyright (c) 2021 ARM Limited. All rights reserved. # SPDX-License-Identifier: Apache-2.0 -include(mbed_set_post_build) +include(mbed_target_functions) # # Merge Cortex-M4 HEX and a Cortex-M0 HEX. diff --git a/targets/TARGET_NUVOTON/scripts/mbed_set_post_build_nuvoton.cmake b/targets/TARGET_NUVOTON/scripts/mbed_set_post_build_nuvoton.cmake index 68be229a9f..a2f1d76449 100644 --- a/targets/TARGET_NUVOTON/scripts/mbed_set_post_build_nuvoton.cmake +++ b/targets/TARGET_NUVOTON/scripts/mbed_set_post_build_nuvoton.cmake @@ -1,7 +1,7 @@ # Copyright (c) 2021 ARM Limited. All rights reserved. # SPDX-License-Identifier: Apache-2.0 -include(mbed_set_post_build) +include(mbed_target_functions) # # Sign TF-M secure and non-secure images and combine them with the bootloader diff --git a/targets/TARGET_NXP/scripts/mbed_set_post_build_nxp.cmake b/targets/TARGET_NXP/scripts/mbed_set_post_build_nxp.cmake index 12f0b47d61..974e1200dd 100644 --- a/targets/TARGET_NXP/scripts/mbed_set_post_build_nxp.cmake +++ b/targets/TARGET_NXP/scripts/mbed_set_post_build_nxp.cmake @@ -1,7 +1,7 @@ # Copyright (c) 2021 ARM Limited. All rights reserved. # SPDX-License-Identifier: Apache-2.0 -include(mbed_set_post_build) +include(mbed_target_functions) # # Patch an LPC target vector table in the binary file. diff --git a/tools/cmake/app.cmake b/tools/cmake/app.cmake index eccda5bebc..47915aad88 100644 --- a/tools/cmake/app.cmake +++ b/tools/cmake/app.cmake @@ -35,7 +35,7 @@ else() endif() include(mbed_generate_config_header) -include(mbed_set_post_build) +include(mbed_target_functions) include(mbed_create_distro) # Load toolchain and mbed configuration, generating it if needed diff --git a/tools/cmake/mbed_create_distro.cmake b/tools/cmake/mbed_create_distro.cmake index 40afa3c6d3..6dc83e4d17 100644 --- a/tools/cmake/mbed_create_distro.cmake +++ b/tools/cmake/mbed_create_distro.cmake @@ -1,24 +1,8 @@ # Copyright (c) 2021 ARM Limited. All rights reserved. # SPDX-License-Identifier: Apache-2.0 -# This script provides mbed_create_distro(), a function that lets you compile multiple -# apps that use Mbed OS without waiting for Mbed OS to build multiple times. - -# You can use it like this: -# mbed_create_distro(mbed_for_my_app mbed-os mbed-storage-kvstore mbed-storage-filesystem) -# -# add_executable(myapp1 MyApp1.cpp) -# target_link_libraries(myapp1 PRIVATE mbed_for_my_app) -# mbed_set_post_build(myapp1) -# -# add_executable(myapp2 MyApp2.cpp) -# target_link_libraries(myapp2 PRIVATE mbed_for_my_app) -# mbed_set_post_build(myapp2) -# -# Both myapp1 and myapp2 will act like they were linked to mbed-os, mbed-storage-kvstore, -# and mbed-storage-filesystem. Note that if you actually did target_link_libraries(myapp1 PRIVATE mbed-os -# mbed-storage-kvstore mbed-storage-filesystem), it would compile a new version of the Mbed OS source -# files for each target. However, using mbed_create_distro(), Mbed OS will only be compiled once. +# This script provides mbed_create_distro(), a function that combines a tree of INTERFACE targets +# into a single library target, copying properties appropriately. # Append the value of PROPERTY from SOURCE to the value of PROPERTY on DESTINATION function(copy_append_property PROPERTY SOURCE DESTINATION) @@ -32,7 +16,13 @@ endfunction(copy_append_property) # Create a "distribution" of Mbed OS containing the base Mbed and certain modules. # This distribution only needs to be compiled once and can be referenced in an arbitrary amount of targets. function(mbed_create_distro NAME) # ARGN: modules... - add_library(${NAME} STATIC EXCLUDE_FROM_ALL) + + # Use an OBJECT library so that weak symbol resolution works properly + add_library(${NAME} OBJECT EXCLUDE_FROM_ALL) + + # Workaround to ensure that everything that links to this library receives its objects, including other object libraries + # from here: https://gitlab.kitware.com/cmake/cmake/-/issues/18090#note_1041608 + target_sources(${NAME} INTERFACE $) # Now copy include dirs, compile defs, and compile options (but NOT interface source files) over # to the distribution target so they will be passed into things that link to it. @@ -46,41 +36,105 @@ function(mbed_create_distro NAME) # ARGN: modules... list(GET REMAINING_MODULES 0 CURR_MODULE) list(REMOVE_AT REMAINING_MODULES 0) - get_property(CURR_MODULE_TYPE TARGET ${CURR_MODULE} PROPERTY TYPE) + if(TARGET "${CURR_MODULE}") - # Pass up mbed linker script property, which is used by the top level code to select the linker script - copy_append_property(INTERFACE_MBED_LINKER_SCRIPT ${CURR_MODULE} ${NAME}) + get_property(CURR_MODULE_TYPE TARGET ${CURR_MODULE} PROPERTY TYPE) - if("${CURR_MODULE_TYPE}" STREQUAL "STATIC_LIBRARY") - # Don't need to do anything other than linking it - target_link_libraries(${NAME} PUBLIC ${CURR_MODULE}) + # Pass up mbed linker script property, which is used by the top level code to select the linker script + copy_append_property(INTERFACE_MBED_LINKER_SCRIPT ${CURR_MODULE} ${NAME}) + + if("${CURR_MODULE_TYPE}" STREQUAL "STATIC_LIBRARY") + # Don't need to do anything other than linking it + target_link_libraries(${NAME} PUBLIC ${CURR_MODULE}) + else() + # Make sure that linking to the distro pulls in the compiled code from CURR_MODULE + target_link_libraries(${NAME} PRIVATE ${CURR_MODULE}) + + copy_append_property(INTERFACE_COMPILE_DEFINITIONS ${CURR_MODULE} ${NAME}) + copy_append_property(INTERFACE_COMPILE_OPTIONS ${CURR_MODULE} ${NAME}) + copy_append_property(INTERFACE_INCLUDE_DIRECTORIES ${CURR_MODULE} ${NAME}) + copy_append_property(INTERFACE_LINK_OPTIONS ${CURR_MODULE} ${NAME}) + + # Additionally, interface libraries can export precompiled .o files as sources. + # We need to copy these to the interface sources of the distro, because adding a .o + # to the sources of an object library does nothing. + get_property(CURR_MODULE_INTERFACE_SOURCES TARGET ${CURR_MODULE} PROPERTY INTERFACE_SOURCES) + foreach(INTERFACE_SOURCE ${CURR_MODULE_INTERFACE_SOURCES}) + if("${INTERFACE_SOURCE}" MATCHES ".o$" OR "${INTERFACE_SOURCE}" MATCHES ".obj$") + # Object file found + target_sources(${NAME} INTERFACE ${INTERFACE_SOURCE}) + endif() + endforeach() + + # CMake currently has a limitation that OBJECT libraries cannot link to other OBJECT libraries + # via the LINK_LIBRARIES property -- CMake will not link the objects in properly :/. + # see: https://cmake.org/pipermail/cmake/2019-May/069453.html + # also: https://gitlab.kitware.com/cmake/cmake/-/issues/18090 + + if("${CURR_MODULE_TYPE}" STREQUAL "OBJECT_LIBRARY") + target_sources(${NAME} INTERFACE $) + + # Check if this object library has any other libraries exported through its INTERFACE_SOURCES. + # If it does, we need to propagate those too. + foreach(INTERFACE_SOURCE ${CURR_MODULE_INTERFACE_SOURCES}) + if(INTERFACE_SOURCE MATCHES "\\$") + target_sources(${NAME} INTERFACE ${INTERFACE_SOURCE}) + endif() + endforeach() + endif() + + + list(APPEND COMPLETED_MODULES ${CURR_MODULE}) + + # find sub-modules of this module + get_property(SUBMODULES TARGET ${CURR_MODULE} PROPERTY INTERFACE_LINK_LIBRARIES) + foreach(SUBMODULE ${SUBMODULES}) + if(NOT "${SUBMODULE}" MATCHES "::@") # remove CMake internal CMAKE_DIRECTORY_ID_SEP markers + # Remove LINK_ONLY genexes from target_link_libraries(... PRIVATE). We can ignore things wrapped in these + # because they will already have been handled by the target_link_libraries earlier on. + if(NOT "${SUBMODULE}" MATCHES "\\$") + if(NOT ${SUBMODULE} IN_LIST COMPLETED_MODULES) + list(APPEND REMAINING_MODULES ${SUBMODULE}) + endif() + endif() + endif() + endforeach() + endif() else() - # Make sure that linking to the distro pulls in the compiled code from CURR_MODULE - target_link_libraries(${NAME} PRIVATE ${CURR_MODULE}) + # Module is not a target, it's something else like a linker flag or a generator expression + # So, just link it to the output. + target_link_libraries(${NAME} INTERFACE ${CURR_MODULE}) + endif() + endwhile() + +endfunction(mbed_create_distro) + +# Traverse a tree of targets and create an interface target containing all of the flags (includes/compile options/ +# etc) but none of the source files extracted from those targets. +# This is mainly used as a shim so that we don't need to edit 100s of target CMake files and separate out the targets +# containing flags from the targets containing source files. +function(mbed_extract_flags NAME) # ARGN: modules... + add_library(${NAME} INTERFACE) + + # Now copy include dirs, compile defs, and compile options (but NOT interface source files) over + # to the distribution target so they will be passed into things that link to it. + # To do this, we need to recursively traverse the tree of dependencies. + set(REMAINING_MODULES ${ARGN}) + set(COMPLETED_MODULES ${ARGN}) + while(NOT "${REMAINING_MODULES}" STREQUAL "") + + #message("Flags: ${NAME}. REMAINING_MODULES: ${REMAINING_MODULES}") + + list(GET REMAINING_MODULES 0 CURR_MODULE) + list(REMOVE_AT REMAINING_MODULES 0) + + if(TARGET "${CURR_MODULE}") copy_append_property(INTERFACE_COMPILE_DEFINITIONS ${CURR_MODULE} ${NAME}) copy_append_property(INTERFACE_COMPILE_OPTIONS ${CURR_MODULE} ${NAME}) copy_append_property(INTERFACE_INCLUDE_DIRECTORIES ${CURR_MODULE} ${NAME}) copy_append_property(INTERFACE_LINK_OPTIONS ${CURR_MODULE} ${NAME}) - # CMake currently has a limitation that OBJECT libraries cannot link to other OBJECT libraries - # via the LINK_LIBRARIES property -- CMake will not link the objects in properly :/. - # see: https://cmake.org/pipermail/cmake/2019-May/069453.html - # also: https://gitlab.kitware.com/cmake/cmake/-/issues/18090 - - if("${CURR_MODULE_TYPE}" STREQUAL "OBJECT_LIBRARY") - target_sources(${NAME} INTERFACE $) - - # Check if this object library has any other libraries exported through its INTERFACE_SOURCES. - # If it does, we need to propagate those too. - get_property(OBJ_INTERFACE_SOURCES TARGET ${NAME} PROPERTY INTERFACE_SOURCES) - foreach(INTERFACE_SOURCE ${OBJ_INTERFACE_SOURCES}) - if(INTERFACE_SOURCE MATCHES "\\$") - target_sources(${NAME} INTERFACE ${INTERFACE_SOURCE}) - endif() - endforeach() - endif() - list(APPEND COMPLETED_MODULES ${CURR_MODULE}) # find sub-modules of this module @@ -96,8 +150,12 @@ function(mbed_create_distro NAME) # ARGN: modules... endif() endif() endforeach() + else() + # Module is not a target, it's something else like a linker flag or a generator expression + # So, just link it to the output. + target_link_libraries(${NAME} INTERFACE ${CURR_MODULE}) endif() endwhile() -endfunction(mbed_create_distro) \ No newline at end of file +endfunction(mbed_extract_flags) \ No newline at end of file diff --git a/tools/cmake/mbed_set_linker_script.cmake b/tools/cmake/mbed_set_linker_script.cmake index 9d1a4038f7..6438890b23 100644 --- a/tools/cmake/mbed_set_linker_script.cmake +++ b/tools/cmake/mbed_set_linker_script.cmake @@ -18,13 +18,14 @@ endfunction(mbed_set_linker_script) # -# Set up the linker script for the top-level Mbed MCU target. +# Set up the linker script for the top-level Mbed OS targets. # If needed, this also creates another target to preprocess the linker script. # -function(mbed_setup_linker_script mbed_mcu_target) +function(mbed_setup_linker_script mbed_os_target mbed_baremetal_target) # Find the path to the desired linker script - get_property(RAW_LINKER_SCRIPT_PATHS TARGET ${mbed_mcu_target} PROPERTY INTERFACE_MBED_LINKER_SCRIPT) + # (the property should be set on both the OS and baremetal targets in a sane world) + get_property(RAW_LINKER_SCRIPT_PATHS TARGET ${mbed_baremetal_target} PROPERTY INTERFACE_MBED_LINKER_SCRIPT) # Check if two (or more) different linker scripts got used list(REMOVE_DUPLICATES RAW_LINKER_SCRIPT_PATHS) @@ -71,19 +72,26 @@ function(mbed_setup_linker_script mbed_mcu_target) # which is then added as a dependency of the MCU target. This ensures the linker script will exist # by the time we need it. add_custom_target(mbed-linker-script DEPENDS ${LINKER_SCRIPT_PATH} VERBATIM) - add_dependencies(${mbed_mcu_target} mbed-linker-script) - # Add linker flags to the MCU target to pick up the preprocessed linker script - target_link_options(${mbed_mcu_target} - INTERFACE - "-T" "${LINKER_SCRIPT_PATH}" - ) + foreach(TARGET ${mbed_baremetal_target} ${mbed_os_target}) + + + add_dependencies(${TARGET} mbed-linker-script) + + # Add linker flags to the MCU target to pick up the preprocessed linker script + target_link_options(${TARGET} + INTERFACE + "-T" "${LINKER_SCRIPT_PATH}" + ) + endforeach() elseif(MBED_TOOLCHAIN STREQUAL "ARM") - target_link_options(${mbed_mcu_target} - INTERFACE - "--scatter=${raw_linker_script_path}" - "--predefine=${_linker_preprocess_definitions}" - "--map" - ) + foreach(TARGET ${mbed_baremetal_target} ${mbed_os_target}) + target_link_options(${TARGET} + INTERFACE + "--scatter=${raw_linker_script_path}" + "--predefine=${_linker_preprocess_definitions}" + "--map" + ) + endforeach() endif() endfunction(mbed_setup_linker_script) diff --git a/tools/cmake/mbed_set_post_build.cmake b/tools/cmake/mbed_target_functions.cmake similarity index 97% rename from tools/cmake/mbed_set_post_build.cmake rename to tools/cmake/mbed_target_functions.cmake index eb163b8910..8d3aaae68e 100644 --- a/tools/cmake/mbed_set_post_build.cmake +++ b/tools/cmake/mbed_target_functions.cmake @@ -1,6 +1,8 @@ # Copyright (c) 2021 ARM Limited. All rights reserved. # SPDX-License-Identifier: Apache-2.0 +# File containing various functions for operating on library and executable targets. + # # Converts output file of `target` to binary file and to Intel HEX file. # diff --git a/tools/cmake/toolchains/GCC_ARM.cmake b/tools/cmake/toolchains/GCC_ARM.cmake index d7eeda9361..e7b7cb6b91 100644 --- a/tools/cmake/toolchains/GCC_ARM.cmake +++ b/tools/cmake/toolchains/GCC_ARM.cmake @@ -20,14 +20,8 @@ list(APPEND link_options "-Wl,--end-group" "-specs=nosys.specs" "-Wl,--cref" - "-Wl,--allow-multiple-definition" ) -# Add the -Wl,--whole-archive flag as a hack to fix resolution of weak symbols between .a libraries. -# This basically causes the linker to process each object in each .a library as if it was its own file. -set(CMAKE_C_LINK_EXECUTABLE " -Wl,--whole-archive -o -Wl,--no-whole-archive") -set(CMAKE_CXX_LINK_EXECUTABLE " -Wl,--whole-archive -o -Wl,--no-whole-archive") - # Add linking time preprocessor macro for TFM targets if("TFM" IN_LIST MBED_TARGET_LABELS) list(APPEND link_options diff --git a/tools/requirements.txt b/tools/requirements.txt index 9251570e24..b20b043ecb 100644 --- a/tools/requirements.txt +++ b/tools/requirements.txt @@ -4,4 +4,8 @@ future>=0.18.0,<1.0 jinja2>=2.11.3 intelhex>=2.3.0,<3.0.0 mbed-tools -mbed-os-tools \ No newline at end of file +mbed-os-tools + +# needed for signing secure images +cryptography +cbor \ No newline at end of file