diff --git a/.github/workflows/real-time-cpp.yml b/.github/workflows/real-time-cpp.yml index 68af60956..c5b19a61c 100644 --- a/.github/workflows/real-time-cpp.yml +++ b/.github/workflows/real-time-cpp.yml @@ -133,7 +133,7 @@ jobs: strategy: fail-fast: false matrix: - suite: [ am335x, bcm2835_raspi_b, lpc11c24, nxp_imxrt1062, rpi_pico_rp2040, stm32f100, stm32f407, stm32f429, stm32f446, stm32h7a3, stm32l100c, stm32l152, stm32l432 ] + suite: [ am335x, bcm2835_raspi_b, lpc11c24, nxp_imxrt1062, rpi_pico_rp2040, rpi_pico2_rp2350, stm32f100, stm32f407, stm32f429, stm32f446, stm32h7a3, stm32l100c, stm32l152, stm32l432 ] steps: - uses: actions/checkout@v4 with: @@ -173,7 +173,7 @@ jobs: strategy: fail-fast: false matrix: - suite: [ am335x, bcm2835_raspi_b, lpc11c24, nxp_imxrt1062, rpi_pico_rp2040, stm32f100, stm32f407, stm32f429, stm32f446, stm32h7a3, stm32l100c, stm32l152, stm32l432 ] + suite: [ am335x, bcm2835_raspi_b, lpc11c24, nxp_imxrt1062, rpi_pico_rp2040, rpi_pico2_rp2350, stm32f100, stm32f407, stm32f429, stm32f446, stm32h7a3, stm32l100c, stm32l152, stm32l432 ] steps: - uses: actions/checkout@v4 with: diff --git a/readme.md b/readme.md index 702090602..52b1f196a 100644 --- a/readme.md +++ b/readme.md @@ -22,20 +22,6 @@ Boost Software License 1.0

---- - -# :loudspeaker: **Announcement** - -**Make-File Unified:** - -The file -[`app_make.gmk`](https://github.com/ckormanyos/real-time-cpp/blob/master/ref_app/target/app/make/app_make.gmk) -is now used uniformly on all operating systems. The file `app_make_linux.gmk` has been removed. -If you have been building target(s) via direct manual call to `make` with `app_make_linux.gmk`, -simply use `app_make.gmk` now. Calls of `build.sh` (and `build.bat`) remain unchanged. - ---- - This is the companion code for the book C.M. Kormanyos, [Real-Time C++](https://www.springer.com/de/book/9783662629956): @@ -96,6 +82,7 @@ The reference application supports the following targets: | `riscvfe310` | SiFive RISC-V FE310 SoC | | | `rl78` | Renesas(R) RL78/G13 | | | `rpi_pico_rp2040` | RaspberryPi(R) Pico RP2040 with dual ARM(R) Cortex(R)-M0+ | X | +| `rpi_pico2_rp2350` | RaspberryPi(R) Pico2 RP2350 with dual ARM(R) Cortex(R)-M33 | X | | `rx63n` | Renesas(R) RX630/RX631 | | | `stm32f100` | STMicroelectronics(R) STM32F100 ARM(R) Cortex(R)-M3 | X | | `stm32f407` | STMicroelectronics(R) STM32F407 ARM(R) Cortex(R)-M4F | | diff --git a/ref_app/ref_app.vcxproj b/ref_app/ref_app.vcxproj index 0794ea605..73bebda05 100644 --- a/ref_app/ref_app.vcxproj +++ b/ref_app/ref_app.vcxproj @@ -572,15 +572,47 @@ true true - + true true - + true true - + + true + true + + + true + true + + + true + true + + + true + true + + + true + true + + + true + true + + + true + true + + + true + true + + true true @@ -1855,10 +1887,6 @@ true true - - true - true - true true @@ -1955,15 +1983,64 @@ true true - + + true true - + + true + true + + + true + true + + + true + true + + + true + true + + + true + true + + + true + true + + + true + true + + + true + true + + + true + true + + + true + true + + + true + true + + + true + true + + true true - + true true diff --git a/ref_app/ref_app.vcxproj.filters b/ref_app/ref_app.vcxproj.filters index bb2d6dee1..2194f2d73 100644 --- a/ref_app/ref_app.vcxproj.filters +++ b/ref_app/ref_app.vcxproj.filters @@ -230,9 +230,6 @@ {2f061ca1-4483-4a8b-aaee-0ccff4b22769} - - {2cf60274-f899-454e-8fcc-690618c7ad0e} - {f73dba03-036f-4f98-9729-fc2d7336ff26} @@ -243,10 +240,7 @@ {5f7361ff-0d9a-4223-bcef-30455fe7d1ea} - {efd86679-8e03-4f9d-a44a-2bebc5ab607b} - - - {5e0acfbd-219f-4b10-a237-ea58c3677e31} + {663bb776-7f47-4142-acd6-8da02d48d8fa} @@ -1141,14 +1135,38 @@ src\mcal\stm32l432 - - src\mcal\rpi_pico2_rp2350\Mcal\Clock - - + src\mcal\rpi_pico2_rp2350\Mcal\Cpu - - src\mcal\rpi_pico2_rp2350\Mcal\SysTickTimer + + src\mcal\rpi_pico2_rp2350 + + + src\mcal\rpi_pico2_rp2350 + + + src\mcal\rpi_pico2_rp2350 + + + src\mcal\rpi_pico2_rp2350 + + + src\mcal\rpi_pico2_rp2350 + + + src\mcal\rpi_pico2_rp2350 + + + src\mcal\rpi_pico2_rp2350 + + + src\mcal\rpi_pico2_rp2350 + + + src\mcal\rpi_pico2_rp2350 + + + src\mcal\rpi_pico2_rp2350 @@ -2622,9 +2640,6 @@ src\mcal\rpi_pico2_rp2350\Mcal - - src\mcal\rpi_pico2_rp2350\Mcal\Clock - src\mcal\rpi_pico2_rp2350\Mcal\Cmsis @@ -2700,8 +2715,47 @@ src\mcal\rpi_pico2_rp2350\Mcal\Gpio - - src\mcal\rpi_pico2_rp2350\Mcal\SysTickTimer + + src\mcal\rpi_pico2_rp2350 + + + src\mcal\rpi_pico2_rp2350 + + + src\mcal\rpi_pico2_rp2350 + + + src\mcal\rpi_pico2_rp2350 + + + src\mcal\rpi_pico2_rp2350 + + + src\mcal\rpi_pico2_rp2350 + + + src\mcal\rpi_pico2_rp2350 + + + src\mcal\rpi_pico2_rp2350 + + + src\mcal\rpi_pico2_rp2350 + + + src\mcal\rpi_pico2_rp2350 + + + src\mcal\rpi_pico2_rp2350 + + + src\mcal\rpi_pico2_rp2350 + + + src\mcal\rpi_pico2_rp2350 + + + src\mcal\rpi_pico2_rp2350 diff --git a/ref_app/src/mcal/lpc11c24/mcal_gpt.cpp b/ref_app/src/mcal/lpc11c24/mcal_gpt.cpp index 9c0d6d91b..977e4df99 100644 --- a/ref_app/src/mcal/lpc11c24/mcal_gpt.cpp +++ b/ref_app/src/mcal/lpc11c24/mcal_gpt.cpp @@ -30,9 +30,9 @@ namespace } } -extern "C" void __sys_tick_handler() __attribute__((interrupt)); +extern "C" void __sys_tick_handler(void) __attribute__((interrupt)); -extern "C" void __sys_tick_handler() +extern "C" void __sys_tick_handler(void) { // Update 64-bit counter with microsecond count. mcal_gpt_system_tick += mcal::config::systick_inc; diff --git a/ref_app/src/mcal/mcal_gcc_cxx_completion.cpp b/ref_app/src/mcal/mcal_gcc_cxx_completion.cpp index 8ae542a8c..cb2fa8dad 100644 --- a/ref_app/src/mcal/mcal_gcc_cxx_completion.cpp +++ b/ref_app/src/mcal/mcal_gcc_cxx_completion.cpp @@ -5,11 +5,12 @@ // or copy at http://www.boost.org/LICENSE_1_0.txt) // -#include -#include #include #include +#include +#include + #if defined(__GNUC__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wmissing-declarations" diff --git a/ref_app/src/mcal/mcal_gpt_arm_sys_tick.h b/ref_app/src/mcal/mcal_gpt_arm_sys_tick.h index 2490aab8c..1e469cfe9 100644 --- a/ref_app/src/mcal/mcal_gpt_arm_sys_tick.h +++ b/ref_app/src/mcal/mcal_gpt_arm_sys_tick.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2022 - 2023. +// Copyright Christopher Kormanyos 2022 - 2024. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -12,7 +12,7 @@ #include #if defined(__GNUC__) - extern "C" auto __sys_tick_handler(void) noexcept -> void __attribute__((used, noinline)); + extern "C" auto __sys_tick_handler(void) -> void __attribute__((used, noinline)); #endif namespace mcal { namespace gpt { @@ -165,7 +165,7 @@ } #if defined(__GNUC__) - friend auto ::__sys_tick_handler(void) noexcept -> void; + friend auto ::__sys_tick_handler(void) -> void; #endif }; diff --git a/ref_app/src/mcal/nxp_imxrt1062/mcal_gpt.cpp b/ref_app/src/mcal/nxp_imxrt1062/mcal_gpt.cpp index 541d68828..437b6bb4b 100644 --- a/ref_app/src/mcal/nxp_imxrt1062/mcal_gpt.cpp +++ b/ref_app/src/mcal/nxp_imxrt1062/mcal_gpt.cpp @@ -8,7 +8,7 @@ #include extern "C" -auto __sys_tick_handler(void) noexcept -> void +auto __sys_tick_handler(void) -> void { using local_arm_sys_tick_type = ::mcal::gpt::arm_sys_tick_type; using local_value_type = typename local_arm_sys_tick_type::value_type; diff --git a/ref_app/src/mcal/rpi_pico2_rp2350/Mcal/Clock/Clock.c b/ref_app/src/mcal/rpi_pico2_rp2350/Mcal/Clock/Clock.c deleted file mode 100644 index 871074d67..000000000 --- a/ref_app/src/mcal/rpi_pico2_rp2350/Mcal/Clock/Clock.c +++ /dev/null @@ -1,81 +0,0 @@ -/****************************************************************************************** - Filename : Clock.c - - Core : ARM Cortex-M33 / RISC-V Hazard3 - - MCU : RP2350 - - Author : Chalandi Amine - - Owner : Chalandi Amine - - Date : 04.09.2024 - - Description : Clock initialization for RP2350 - -******************************************************************************************/ - -//============================================================================= -// Includes -//============================================================================= -#include "Clock.h" - - -//----------------------------------------------------------------------------------------- -/// \brief RP2350_ClockInit function -/// -/// \param void -/// -/// \return void -//----------------------------------------------------------------------------------------- -void RP2350_ClockInit(void) -{ - /* Init the clock XOSC */ - HW_PER_XOSC->STARTUP.bit.X4 = 0U; - HW_PER_XOSC->STARTUP.bit.DELAY = 47U; - HW_PER_XOSC->CTRL.bit.FREQ_RANGE = HW_PER_XOSC->STATUS.bit.FREQ_RANGE; - HW_PER_XOSC->CTRL.bit.ENABLE = XOSC_CTRL_ENABLE_ENABLE; - while(HW_PER_XOSC->STATUS.bit.STABLE != 1U); - - /* Switch the ref clock to use the xosc clock as source */ - HW_PER_CLOCKS->CLK_REF_CTRL.bit.SRC = CLOCKS_CLK_REF_CTRL_SRC_xosc_clksrc; - while(HW_PER_CLOCKS->CLK_REF_SELECTED.reg != (1ul << CLOCKS_CLK_REF_CTRL_SRC_xosc_clksrc)); - - while(HW_PER_CLOCKS->CLK_REF_DIV.bit.INT != 1); - - /* Release the reset of PLL_SYS */ - HW_PER_RESETS->RESET.bit.PLL_SYS = 0U; - while(HW_PER_RESETS->RESET_DONE.bit.PLL_SYS != 1); - - /* Configure the PLL_SYS */ - HW_PER_PLL_SYS->CS.bit.REFDIV = 1U; - HW_PER_PLL_SYS->FBDIV_INT.bit.FBDIV_INT = 125U; - HW_PER_PLL_SYS->PRIM.bit.POSTDIV1 = 5U; - HW_PER_PLL_SYS->PRIM.bit.POSTDIV2 = 2U; - - HW_PER_PLL_SYS->PWR.bit.PD = 0U; - HW_PER_PLL_SYS->PWR.bit.VCOPD = 0U; - HW_PER_PLL_SYS->PWR.bit.POSTDIVPD = 0U; - - while(HW_PER_PLL_SYS->CS.bit.LOCK != 1U); - - /* Switch the system clock to use the PLL */ - - if(HW_PER_CLOCKS->CLK_SYS_DIV.reg != 0x10000ul) - HW_PER_CLOCKS->CLK_SYS_DIV.reg = 0x10000ul; - - HW_PER_CLOCKS->CLK_SYS_CTRL.bit.AUXSRC = CLOCKS_CLK_SYS_CTRL_AUXSRC_clksrc_pll_sys; - HW_PER_CLOCKS->CLK_SYS_CTRL.bit.SRC = CLOCKS_CLK_SYS_CTRL_SRC_clksrc_clk_sys_aux; - - while(HW_PER_CLOCKS->CLK_SYS_SELECTED.bit.CLK_SYS_SELECTED != (1ul << CLOCKS_CLK_SYS_CTRL_SRC_clksrc_clk_sys_aux)); - - /* Enable clock for peripheral */ - HW_PER_CLOCKS->CLK_PERI_CTRL.bit.ENABLE = 1U; - - /* Release reset on IO_BANK0 */ - HW_PER_RESETS->RESET.bit.IO_BANK0 = 0U; - - /* Wait for reset to be done */ - /* Release reset is done on IO_BANK0 */ - while(HW_PER_RESETS->RESET_DONE.bit.IO_BANK0 != 1); -} diff --git a/ref_app/src/mcal/rpi_pico2_rp2350/Mcal/Clock/Clock.h b/ref_app/src/mcal/rpi_pico2_rp2350/Mcal/Clock/Clock.h deleted file mode 100644 index e1a1f1c87..000000000 --- a/ref_app/src/mcal/rpi_pico2_rp2350/Mcal/Clock/Clock.h +++ /dev/null @@ -1,35 +0,0 @@ -/****************************************************************************************** - Filename : Clock.h - - Core : ARM Cortex-M33 / RISC-V Hazard3 - - MCU : RP2350 - - Author : Chalandi Amine - - Owner : Chalandi Amine - - Date : 04.09.2024 - - Description : Clock initialization header file for RP2350 - -******************************************************************************************/ -#ifndef __RP2350_CLOCK_H__ -#define __RP2350_CLOCK_H__ - -//============================================================================= -// Includes -//============================================================================= -#include "RP2350.h" -#include "Platform_Types.h" - - - -//============================================================================= -// Functions prototype -//============================================================================= -void RP2350_ClockInit(void); - - - -#endif /*__RP2350_CLOCK_H__*/ diff --git a/ref_app/src/mcal/rpi_pico2_rp2350/Mcal/Cpu/Cpu.c b/ref_app/src/mcal/rpi_pico2_rp2350/Mcal/Cpu/Cpu.cpp similarity index 63% rename from ref_app/src/mcal/rpi_pico2_rp2350/Mcal/Cpu/Cpu.c rename to ref_app/src/mcal/rpi_pico2_rp2350/Mcal/Cpu/Cpu.cpp index a27799db8..fde64b122 100644 --- a/ref_app/src/mcal/rpi_pico2_rp2350/Mcal/Cpu/Cpu.c +++ b/ref_app/src/mcal/rpi_pico2_rp2350/Mcal/Cpu/Cpu.cpp @@ -18,17 +18,23 @@ //============================================================================= // Includes //============================================================================= -#include "Cpu.h" -#include "core_arch.h" +#include -#include +extern "C" +{ + void arch_spin_lock (uint32* lock); + void arch_spin_unlock(uint32* lock); +} -//============================================================================= -// Globals -//============================================================================= -static uint32 u32MulticoreLock = 0; -static volatile uint32 u32MulticoreSync = 0; +namespace +{ + uint32 u32MulticoreLock; + volatile uint32 u32MulticoreSync; +} +#define CORE_ARCH_SEND_EVENT_INST() __asm("SEV") +#define CORE_ARCH_DISABLE_INTERRUPTS() __asm("CPSID i") +#define CORE_ARCH_ENABLE_INTERRUPTS() __asm("CPSIE i") //----------------------------------------------------------------------------------------- /// \brief RP2350_MulticoreSync function @@ -37,6 +43,7 @@ static volatile uint32 u32MulticoreSync = 0; /// /// \return void //----------------------------------------------------------------------------------------- +extern "C" void RP2350_MulticoreSync(uint32 CpuId) { /* aquire the multicore lock */ @@ -57,46 +64,7 @@ void RP2350_MulticoreSync(uint32 CpuId) /// /// \return void //----------------------------------------------------------------------------------------- -void RP2350_InitCore(void) -{ - /* we came here from the RP2350 BootRom and SBL */ - /* Reset core1 to start from a known state */ - - HW_PER_PSM->FRCE_OFF.bit.PROC1 = 1U; - - while((HW_PER_PSM->DONE.bit.PROC1 == 1U)); - - HW_PER_PSM->FRCE_OFF.bit.PROC1 = 0U; - - while((HW_PER_PSM->DONE.bit.PROC1 != 1U)); - - /* Reset peripheral to start from a known state */ - HW_PER_RESETS->RESET.bit.IO_BANK0 = 1U; - HW_PER_RESETS->RESET.bit.PADS_BANK0 = 1U; - - while((HW_PER_RESETS->RESET_DONE.bit.IO_BANK0 == 1U) || (HW_PER_RESETS->RESET_DONE.bit.PADS_BANK0 == 1U)); - - HW_PER_RESETS->RESET.bit.IO_BANK0 = 0U; - HW_PER_RESETS->RESET.bit.PADS_BANK0 = 0U; - - while((HW_PER_RESETS->RESET_DONE.bit.IO_BANK0 == 0U) || (HW_PER_RESETS->RESET_DONE.bit.PADS_BANK0 == 0U)); - -#ifdef CORE_FAMILY_ARM - /*Setting EXTEXCLALL allows external exclusive operations to be used in a configuration with no MPU. - This is because the default memory map does not include any shareable Normal memory.*/ - SCnSCB->ACTLR |= (1ul<<29); -#endif -} - -extern bool core_1_run_flag_get(void); - -//----------------------------------------------------------------------------------------- -/// \brief RP2350_StartCore1 function -/// -/// \param void -/// -/// \return void -//----------------------------------------------------------------------------------------- +extern "C" boolean RP2350_StartCore1(void) { extern uint32 __INTVECT_Core1[2]; @@ -166,7 +134,5 @@ boolean RP2350_StartCore1(void) /* Clear the stiky bits of the FIFO_ST on core 0 */ HW_PER_SIO->FIFO_ST.reg = 0xFFu; - while(!core_1_run_flag_get()) { ; } - return(TRUE); } diff --git a/ref_app/src/mcal/rpi_pico2_rp2350/Mcal/Cpu/Cpu.h b/ref_app/src/mcal/rpi_pico2_rp2350/Mcal/Cpu/Cpu.h index a11e59adf..cab7e4a99 100644 --- a/ref_app/src/mcal/rpi_pico2_rp2350/Mcal/Cpu/Cpu.h +++ b/ref_app/src/mcal/rpi_pico2_rp2350/Mcal/Cpu/Cpu.h @@ -20,8 +20,13 @@ //============================================================================= // Includes //============================================================================= -#include "RP2350.h" -#include "Platform_Types.h" +#include +#include + +#if defined(__cplusplus) +extern "C" +{ +#endif //============================================================================= // Defines @@ -34,8 +39,11 @@ //============================================================================= // Functions prototype //============================================================================= -void RP2350_MulticoreSync(uint32 CpuId); -boolean RP2350_StartCore1(void); -void RP2350_InitCore(void); +void RP2350_MulticoreSync(uint32 CpuId); +boolean RP2350_StartCore1 (void); + +#if defined(__cplusplus) +} +#endif #endif /*__RP2350_CPU_H__*/ diff --git a/ref_app/src/mcal/rpi_pico2_rp2350/Mcal/Gpio/Gpio.h b/ref_app/src/mcal/rpi_pico2_rp2350/Mcal/Gpio/Gpio.h index 9967e0642..b11f24b44 100644 --- a/ref_app/src/mcal/rpi_pico2_rp2350/Mcal/Gpio/Gpio.h +++ b/ref_app/src/mcal/rpi_pico2_rp2350/Mcal/Gpio/Gpio.h @@ -20,8 +20,8 @@ //============================================================================= // Includes //============================================================================= -#include "RP2350.h" -#include "Platform_Types.h" +#include +#include //============================================================================= // Macros diff --git a/ref_app/src/mcal/rpi_pico2_rp2350/Mcal/RP2350.h b/ref_app/src/mcal/rpi_pico2_rp2350/Mcal/RP2350.h index 4823d0016..d7a134630 100644 --- a/ref_app/src/mcal/rpi_pico2_rp2350/Mcal/RP2350.h +++ b/ref_app/src/mcal/rpi_pico2_rp2350/Mcal/RP2350.h @@ -33,8 +33,6 @@ extern "C" { * @{ */ -#if defined(CORE_FAMILY_ARM) - /* =========================================================================================================================== */ /* ================ Interrupt Number Definition ================ */ /* =========================================================================================================================== */ @@ -121,28 +119,8 @@ typedef enum { /** @} */ /* End of group Configuration_of_CMSIS */ -#include "core_cm33.h" /*!< ARM Cortex-M33 processor and core peripherals */ - -#elif defined(CORE_FAMILY_RISC_V) - -#include "stdint.h" - -#ifdef __cplusplus - #define __I volatile /*!< Defines 'read only' permissions */ -#else - #define __I volatile const /*!< Defines 'read only' permissions */ -#endif -#define __O volatile /*!< Defines 'write only' permissions */ -#define __IO volatile /*!< Defines 'read / write' permissions */ +#include /*!< ARM Cortex-M33 processor and core peripherals */ -/* following defines should be used for structure members */ -#define __IM volatile const /*! Defines 'read only' structure member permissions */ -#define __OM volatile /*! Defines 'write only' structure member permissions */ -#define __IOM volatile /*! Defines 'read / write' structure member permissions */ - -#else -#error "Unknown core family !" -#endif #ifndef __IM /*!< Fallback for older CMSIS versions */ #define __IM __I diff --git a/ref_app/src/mcal/rpi_pico2_rp2350/Mcal/SysTickTimer/SysTickTimer.c b/ref_app/src/mcal/rpi_pico2_rp2350/Mcal/SysTickTimer/SysTickTimer.c deleted file mode 100644 index 72848f0f0..000000000 --- a/ref_app/src/mcal/rpi_pico2_rp2350/Mcal/SysTickTimer/SysTickTimer.c +++ /dev/null @@ -1,82 +0,0 @@ -/****************************************************************************************** - Filename : SysTickTimer.c - - Core : ARM Cortex-M33 / RISC-V Hazard3 - - MCU : RP2350 - - Author : Chalandi Amine - - Owner : Chalandi Amine - - Date : 04.09.2024 - - Description : System timer driver implementation - -******************************************************************************************/ - -#include "SysTickTimer.h" - -//========================================================================================= -// Functions -//========================================================================================= - -//----------------------------------------------------------------------------- -/// \brief -/// -/// \descr -/// -/// \param -/// -/// \return -//----------------------------------------------------------------------------- -void SysTickTimer_Init(void) -{ - pSTK_CTRL->u32Register = 0; - pSTK_VAL->u32Register = 0; - pSTK_CTRL->bits.u1CLOCKSRC = SYS_TICK_CLKSRC_PROCESSOR_CLOCK; - pSTK_CTRL->bits.u1TICKINT = SYS_TICK_ENABLE_INT; -} - -//----------------------------------------------------------------------------- -/// \brief -/// -/// \descr -/// -/// \param -/// -/// \return -//----------------------------------------------------------------------------- -void SysTickTimer_Start(uint32 timeout) -{ - pSTK_LOAD->u32Register = timeout; - pSTK_CTRL->bits.u1ENABLE = SYS_TICK_ENABLE_TIMER; -} - -//----------------------------------------------------------------------------- -/// \brief -/// -/// \descr -/// -/// \param -/// -/// \return -//----------------------------------------------------------------------------- -void SysTickTimer_Reload(uint32 timeout) -{ - pSTK_LOAD->u32Register = timeout; -} - -//----------------------------------------------------------------------------- -/// \brief -/// -/// \descr -/// -/// \param -/// -/// \return -//----------------------------------------------------------------------------- -void SysTickTimer_Stop(void) -{ - pSTK_CTRL->bits.u1ENABLE = 0U; -} \ No newline at end of file diff --git a/ref_app/src/mcal/rpi_pico2_rp2350/Mcal/SysTickTimer/SysTickTimer.h b/ref_app/src/mcal/rpi_pico2_rp2350/Mcal/SysTickTimer/SysTickTimer.h deleted file mode 100644 index fca437feb..000000000 --- a/ref_app/src/mcal/rpi_pico2_rp2350/Mcal/SysTickTimer/SysTickTimer.h +++ /dev/null @@ -1,107 +0,0 @@ -/****************************************************************************************** - Filename : SysTickTimer.h - - Core : ARM Cortex-M33 / RISC-V Hazard3 - - MCU : RP2350 - - Author : Chalandi Amine - - Owner : Chalandi Amine - - Date : 04.09.2024 - - Description : System timer driver header file - -******************************************************************************************/ - -#ifndef __SYSTICK_TIMER_H__ -#define __SYSTICK_TIMER_H__ - -#include "Platform_Types.h" - -//========================================================================================= -// Types definition -//========================================================================================= -typedef union -{ - struct - { - uint32 u1ENABLE:1; - uint32 u1TICKINT:1; - uint32 u1CLOCKSRC:1; - uint32 :13; - uint32 u1COUNTFLAG:1; - uint32 :15; - }bits; - - uint32 u32Register; - -}stStkCtrl; - -typedef union -{ - struct - { - uint32 u24RELOAD:24; - uint32 :8; - }bits; - - uint32 u32Register; - -}stStkLoad; - -typedef union -{ - struct - { - uint32 u24CURRENT:24; - uint32 :8; - }bits; - - uint32 u32Register; - -}stStkVal; - -typedef union -{ - struct - { - uint32 u24TENMS:24; - uint32 :6; - uint32 u1SKEW:1; - uint32 u1NOREF:1; - }bits; - - uint32 u32Register; - -}stStkCalib; - -//========================================================================================= -// Definitions -//========================================================================================= -#define SYS_TICK_BASE_REG (0xE000E010UL) - -#define pSTK_CTRL ((volatile stStkCtrl* const) (SYS_TICK_BASE_REG + 0x00)) -#define pSTK_LOAD ((volatile stStkLoad* const) (SYS_TICK_BASE_REG + 0x04)) -#define pSTK_VAL ((volatile stStkVal* const) (SYS_TICK_BASE_REG + 0x08)) -#define pSTK_CALIB ((volatile stStkCalib* const)(SYS_TICK_BASE_REG + 0x0C)) - -#define CPU_FREQ_MHZ 150U -#define SYS_TICK_MS(x) ((uint32)(CPU_FREQ_MHZ * x * 1000UL) - 1UL) -#define SYS_TICK_US(x) ((uint32)(CPU_FREQ_MHZ * x) - 1UL) - -#define SYS_TICK_CLKSRC_PROCESSOR_CLOCK 1U -#define SYS_TICK_CLKSRC_EXTERNAL_REFERENCE_CLOCK 0U -#define SYS_TICK_ENABLE_INT 1U -#define SYS_TICK_ENABLE_TIMER 1U - -//========================================================================================= -// Prototypes -//========================================================================================= -void SysTickTimer_Init(void); -void SysTickTimer_Start(uint32 timeout); -void SysTickTimer_Stop(void); -void SysTickTimer_Reload(uint32 timeout); - -#endif /*__SYSTICK_TIMER_H__*/ diff --git a/ref_app/src/mcal/rpi_pico2_rp2350/Mcal/USB/USB.c b/ref_app/src/mcal/rpi_pico2_rp2350/Mcal/USB/USB.c deleted file mode 100644 index cf80376ec..000000000 --- a/ref_app/src/mcal/rpi_pico2_rp2350/Mcal/USB/USB.c +++ /dev/null @@ -1,1019 +0,0 @@ -/****************************************************************************************** - Filename : USB.c - - Core : ARM Cortex-M33 / RISC-V Hazard3 - - MCU : RP2350 - - Author : Chalandi Amine - - Owner : Chalandi Amine - - Date : 04.09.2024 - - Description : USB low level device driver implementation - -******************************************************************************************/ - -//============================================================================= -// Includes -//============================================================================= -#include "RP2350.h" -#include "USB.h" -#include "usb_hwreg.h" -#include "usb_types.h" -#include - -//============================================================================= -// Globals (Debug purpose only) -//============================================================================= -#define ENABLE_DEBUG_USB 0 -#define ENABLE_DEBUG_HLT 0 - -#if ENABLE_DEBUG_USB - #define __DEBUG_USB__ -#endif - -#if ENABLE_DEBUG_USB && ENABLE_DEBUG_HLT - #define __DEBUG_HALT__ -#endif - -#ifdef __DEBUG_USB__ -volatile uint64 _EP0_[100] = {0}; -volatile uint32 _EP0_index = 0; - -volatile uint64 _EP0_SpecificReq[100] = {0}; -volatile uint32 _EP0_SpecificReq_index = 0; - -volatile uint32 BusResetCounter = 0; - -volatile uint32 UsbReceived_EP0_OUT_count = 0; -volatile uint32 UsbReceived_EP0_IN_count = 0; - -volatile uint32 UsbReceived_EP1_IN_count = 0; -volatile uint32 UsbReceived_EP1_OUT_count = 0; - -volatile uint32 UsbReceived_EP2_IN_count = 0; -volatile uint32 UsbReceived_EP2_OUT_count = 0; - -volatile uint32 UsbReceived_EP3_IN_count = 0; -volatile uint32 UsbReceived_EP3_OUT_count = 0; - -volatile uint32 UsbNotSupportedRequestCount = 0; - -volatile uint32 boHaltBeforeEnableUsb = 1; -#endif -//============================================================================= -// Local types -//============================================================================= -typedef void (*pStandardRequestHandler)(const tUsbSetupPacket* const pUsbSetupPacket); - -//============================================================================= -// Static functions -//============================================================================= -static void UsbDriver_HandleSetupPacket (const tUsbSetupPacket* const pUsbSetupPacket); -static boolean UsbDriver_SendDataToHost (uint8 endpoint, uint8 pid, uint8* buffer, uint8 size); -static boolean UsbDriver_ConfigureEpOutBuf (uint8 endpoint, uint8 pid, uint8 size); -static boolean UsbDriver_SendStallToHost (uint8 endpoint, uint8 pid); -static boolean UsbDriver_ConfigureEndpoint (uint8 endpoint, uint8 direction, uint8 type); -static void UsbDriver_Req_get_status (const tUsbSetupPacket* const pUsbSetupPacket); -static void UsbDriver_Req_clear_feature (const tUsbSetupPacket* const pUsbSetupPacket); -static void UsbDriver_Req_set_feature (const tUsbSetupPacket* const pUsbSetupPacket); -static void UsbDriver_Req_set_address (const tUsbSetupPacket* const pUsbSetupPacket); -static void UsbDriver_Req_get_descriptor (const tUsbSetupPacket* const pUsbSetupPacket); -static void UsbDriver_Req_set_descriptor (const tUsbSetupPacket* const pUsbSetupPacket); -static void UsbDriver_Req_get_configuration (const tUsbSetupPacket* const pUsbSetupPacket); -static void UsbDriver_Req_set_configuration (const tUsbSetupPacket* const pUsbSetupPacket); -static void UsbDriver_Req_get_interface (const tUsbSetupPacket* const pUsbSetupPacket); -static void UsbDriver_Req_set_interface (const tUsbSetupPacket* const pUsbSetupPacket); -static void UsbDriver_Req_synch_frame (const tUsbSetupPacket* const pUsbSetupPacket); - -//============================================================================= -// Globals -//============================================================================= -static volatile uint32 UsbDeviceAddress = 0; -static volatile uint8 EPx_dataPid[16] = {DATA0_PID}; - -static const pStandardRequestHandler - StandardRequestHandlerLockupTable[13] = { - UsbDriver_Req_get_status, - UsbDriver_Req_clear_feature, - NULL, - UsbDriver_Req_set_feature, - NULL, - UsbDriver_Req_set_address, - UsbDriver_Req_get_descriptor, - UsbDriver_Req_set_descriptor, - UsbDriver_Req_get_configuration, - UsbDriver_Req_set_configuration, - UsbDriver_Req_get_interface, - UsbDriver_Req_set_interface, - UsbDriver_Req_synch_frame - }; - -//----------------------------------------------------------------------------------------- -/// \brief -/// -/// \param -/// -/// \return -//----------------------------------------------------------------------------------------- -void USBCTRL_IRQ(void) -{ - /* handle SETUP packets */ - if(USBCTRL_REGS->INTS.bit.SETUP_REQ) - { - /* clear the interrupt */ - USBCTRL_REGS->SIE_STATUS.bit.SETUP_REC = 1u; - - /* get the SETUP packet data */ - const tUsbSetupPacket* const UsbSetupPacket = (const tUsbSetupPacket* const)USBCTRL_DPRAM_BASE; - - /* call the appropriate SETUP packet handler */ - UsbDriver_HandleSetupPacket(UsbSetupPacket); - -#ifdef __DEBUG_USB__ - //save the data - _EP0_[_EP0_index++] = *(volatile uint64*)(USBCTRL_DPRAM_BASE); -#endif - } - - /* handle bus reset */ - if(USBCTRL_REGS->INTS.bit.BUS_RESET) - { - /* clear the bus reset interrupt flag */ - USBCTRL_REGS->SIE_STATUS.bit.BUS_RESET = 1; - USBCTRL_REGS->ADDR_ENDP.bit.ADDRESS = 0; - UsbDeviceAddress = 0; -#ifdef __DEBUG_USB__ - BusResetCounter++; -#endif - } - - /* handle OUT and IN packets */ - if(USBCTRL_REGS->INTS.bit.BUFF_STATUS) - { - /***************************************************************************/ - /* endpoint 0 */ - /***************************************************************************/ - if(USBCTRL_REGS->BUFF_STATUS.bit.EP0_OUT) - { -#ifdef __DEBUG_USB__ - UsbReceived_EP0_OUT_count++; -#endif - /* clear the EP0_OUT buffer status */ - USBCTRL_REGS->BUFF_STATUS.bit.EP0_OUT = 1; - - /* configure the expected OUT packet */ - UsbDriver_ConfigureEpOutBuf(EP0, DATA1_PID, 64); - } - - if(USBCTRL_REGS->BUFF_STATUS.bit.EP0_IN) - { - /* this bit indicate that the DATA is received by the HOST and we received ACK from HOST, the EP0_IN buffer is empty - (USBCTRL_DPRAM->EP0_IN_BUFFER_CONTROL.bit.FULL_0 is cleared to indicate that data has been sent). - */ -#ifdef __DEBUG_USB__ - UsbReceived_EP0_IN_count++; -#endif - /* clear the EP0_IN buffer status */ - USBCTRL_REGS->BUFF_STATUS.bit.EP0_IN = 1; - - if(UsbDeviceAddress != 0) - { - /* setup device address */ - USBCTRL_REGS->ADDR_ENDP.reg |= (uint32)(UsbDeviceAddress & 0x7Ful); - } - - /* configure the expected OUT packet */ - UsbDriver_ConfigureEpOutBuf(EP0, DATA1_PID, 64); - } - - /***************************************************************************/ - /* endpoint 1 */ - /***************************************************************************/ - if(USBCTRL_REGS->BUFF_STATUS.bit.EP1_OUT) - { -#ifdef __DEBUG_USB__ - UsbReceived_EP1_OUT_count++; -#endif - /* clear the EP1_OUT buffer status */ - USBCTRL_REGS->BUFF_STATUS.bit.EP1_OUT = 1; - - /* TODO: copy the received data and call the handler */ - - EPx_dataPid[EP1] ^= 1u; - UsbDriver_ConfigureEpOutBuf(EP1, EPx_dataPid[EP1], 64u); - } - if(USBCTRL_REGS->BUFF_STATUS.bit.EP1_IN) - { -#ifdef __DEBUG_USB__ - UsbReceived_EP1_IN_count++; -#endif - /* clear the EP1_IN buffer status */ - USBCTRL_REGS->BUFF_STATUS.bit.EP1_IN = 1; - - /* TODO: notify the handler */ - - /* update the EP1_OUT buffer config with the new expect data pid */ - EPx_dataPid[EP1] ^= 1u; - UsbDriver_ConfigureEpOutBuf(EP1, EPx_dataPid[EP1], 64u); - } - /***************************************************************************/ - /* endpoint 2 */ - /***************************************************************************/ - if(USBCTRL_REGS->BUFF_STATUS.bit.EP2_OUT) - { -#ifdef __DEBUG_USB__ - UsbReceived_EP2_OUT_count++; -#endif - /* clear the EP2_OUT buffer status */ - USBCTRL_REGS->BUFF_STATUS.bit.EP2_OUT = 1; - - /* TODO: copy the received data and call the handler */ - - EPx_dataPid[EP2] ^= 1u; - UsbDriver_ConfigureEpOutBuf(EP2, EPx_dataPid[EP2], 64u); - } - if(USBCTRL_REGS->BUFF_STATUS.bit.EP2_IN) - { -#ifdef __DEBUG_USB__ - UsbReceived_EP2_IN_count++; -#endif - /* clear the EP2_IN buffer status */ - USBCTRL_REGS->BUFF_STATUS.bit.EP2_IN = 1; - - /* TODO: notify the handler */ - - /* update the EP2_OUT buffer config with the new expect data pid */ - EPx_dataPid[EP2] ^= 1u; - UsbDriver_ConfigureEpOutBuf(EP2, EPx_dataPid[EP2], 64u); - } - /***************************************************************************/ - /* endpoint 3 */ - /***************************************************************************/ - if(USBCTRL_REGS->BUFF_STATUS.bit.EP3_OUT) - { -#ifdef __DEBUG_USB__ - UsbReceived_EP3_OUT_count++; -#endif - /* clear the EP3_OUT buffer status */ - USBCTRL_REGS->BUFF_STATUS.bit.EP3_OUT = 1; - - /* TODO: copy the received data and call the handler */ - - EPx_dataPid[EP3] ^= 1u; - UsbDriver_ConfigureEpOutBuf(EP3, EPx_dataPid[EP3], 64u); - } - if(USBCTRL_REGS->BUFF_STATUS.bit.EP3_IN) - { -#ifdef __DEBUG_USB__ - UsbReceived_EP3_IN_count++; -#endif - /* clear the EP3_IN buffer status */ - USBCTRL_REGS->BUFF_STATUS.bit.EP3_IN = 1; - - /* TODO: notify the handler */ - - /* update the EP3_OUT buffer config with the new expect data pid */ - EPx_dataPid[EP3] ^= 1u; - UsbDriver_ConfigureEpOutBuf(EP3, EPx_dataPid[EP3], 64u); - } - } - - /* handle EP's NAK and STALL notification */ - if(USBCTRL_REGS->INTS.bit.EP_STALL_NAK) - { - if(USBCTRL_REGS->EP_STATUS_STALL_NAK.bit.EP1_IN) - { - /* NAK token was sent by the device controller as response for IN token from host. - this means that the host is requesting a DATA packet on EP1_IN - */ - /* clear the EP1_IN NAK interrupt flag */ - USBCTRL_REGS->EP_STATUS_STALL_NAK.bit.EP1_IN = 1u; - - /* send back the last received data from the host (echo test) */ - uint8* const pBuffer_EP1 = (uint8*)((uint32)(USBCTRL_DPRAM_BASE + 0x100u + (EP1 * 0x80u))); - UsbDriver_SendDataToHost(EP1, EPx_dataPid[EP1], pBuffer_EP1, 4u); - } - - if(USBCTRL_REGS->EP_STATUS_STALL_NAK.bit.EP2_IN) - { - /* NAK token was sent by the device controller as response for IN token from host. - this means that the host is requesting a DATA packet on EP2_IN - */ - /* clear the EP2_IN NAK interrupt flag */ - USBCTRL_REGS->EP_STATUS_STALL_NAK.bit.EP2_IN = 1u; - } - - if(USBCTRL_REGS->EP_STATUS_STALL_NAK.bit.EP3_IN) - { - /* NAK token was sent by the device controller as response for IN token from host. - this means that the host is requesting a DATA packet on EP3_IN - */ - /* clear the EP3_IN NAK interrupt flag */ - USBCTRL_REGS->EP_STATUS_STALL_NAK.bit.EP3_IN = 1u; - } - } -} - -//----------------------------------------------------------------------------------------- -/// \brief -/// -/// \param -/// -/// \return -//----------------------------------------------------------------------------------------- -void UsbInit(void) -{ - //release the reset of PLL_USB - RESETS->RESET.bit.pll_usb = 0u; - while(RESETS->RESET_DONE.bit.pll_usb != 1); - - //configure the PLL_USB - PLL_USB->CS.bit.REFDIV = 1u; - PLL_USB->FBDIV_INT.bit.FBDIV_INT = 40U; - PLL_USB->PRIM.bit.POSTDIV1 = 5U; - PLL_USB->PRIM.bit.POSTDIV2 = 2U; - - PLL_USB->PWR.bit.PD = 0u; - PLL_USB->PWR.bit.VCOPD = 0u; - - while(PLL_USB->CS.bit.LOCK != 1u); - - PLL_USB->PWR.bit.POSTDIVPD = 0u; - - // switch the system clock to use the PLL - CLOCKS->CLK_SYS_CTRL.bit.AUXSRC = CLOCKS_CLK_SYS_CTRL_AUXSRC_clksrc_pll_sys; - CLOCKS->CLK_SYS_CTRL.bit.SRC = CLOCKS_CLK_SYS_CTRL_SRC_clksrc_clk_sys_aux; - - //switch on the USB clock - CLOCKS->CLK_USB_CTRL.bit.AUXSRC = CLOCKS_CLK_USB_CTRL_AUXSRC_clksrc_pll_usb; - CLOCKS->CLK_USB_CTRL.bit.ENABLE = 1u; - - // switch off the ROSC clock - - //release reset of usb - RESETS->RESET.bit.usbctrl = 0u; - while(RESETS->RESET_DONE.bit.usbctrl != 1); - - //clear the DPRAM - for(uint32 i=0; i < 4096U; i = i+8) - { - *(volatile uint64*)(USBCTRL_DPRAM_BASE + i) = 0; - } - - //enable USB - USBCTRL_REGS->USB_MUXING.bit.TO_PHY = 1u; - USBCTRL_REGS->USB_MUXING.bit.SOFTCON = 0u; - USBCTRL_REGS->MAIN_CTRL.bit.HOST_NDEVICE = 0u; - - USBCTRL_REGS->USB_PWR.bit.VBUS_DETECT = 1u; - USBCTRL_REGS->USB_PWR.bit.VBUS_DETECT_OVERRIDE_EN = 1u; - - USBCTRL_REGS->MAIN_CTRL.bit.CONTROLLER_EN = 1u; - - USBCTRL_REGS->SIE_CTRL.bit.EP0_INT_1BUF = 1u; - - //enable usb interrupt - USBCTRL_REGS->INTE.bit.BUFF_STATUS = 1u; // note: this interrupt is needed to detect OUT and IN requests send by the host. - USBCTRL_REGS->INTE.bit.BUS_RESET = 1u; // note: this interrupt is needed to detect a reset state on the USB bus. - USBCTRL_REGS->INTE.bit.SETUP_REQ = 1u; // note: this interrupt is needed to notify the CPU about a received SETUP packet. - USBCTRL_REGS->INTE.bit.EP_STALL_NAK = 1u; // note: this interrupt is needed to notify the CPU about a sent/received NAK/STALL packet. - - //enable NVIC - NVIC_EnableIRQ(USBCTRL_IRQ_IRQn); - __enable_irq(); - - /* enable endpoint 1 */ - UsbDriver_ConfigureEndpoint(EP1, EP_DIR_IN, 2u); - UsbDriver_ConfigureEndpoint(EP1, EP_DIR_OUT, 2u); - UsbDriver_ConfigureEpOutBuf(EP1, EPx_dataPid[EP1], 64u); - - /* enable endpoint 2 */ - UsbDriver_ConfigureEndpoint(EP2, EP_DIR_IN, 2u); - UsbDriver_ConfigureEndpoint(EP2, EP_DIR_OUT, 2u); - UsbDriver_ConfigureEpOutBuf(EP2, EPx_dataPid[EP2], 64u); - - /* enable endpoint 3 */ - UsbDriver_ConfigureEndpoint(EP3, EP_DIR_IN, 3u); - -#ifdef __DEBUG_HALT__ - while(boHaltBeforeEnableUsb); -#endif - - /* enable the USB controller */ - USBCTRL_REGS->SIE_CTRL.bit.PULLUP_EN = 1u; - -} - -//----------------------------------------------------------------------------------------- -/// \brief -/// -/// \param -/// -/// \return -//----------------------------------------------------------------------------------------- -static boolean UsbDriver_ConfigureEndpoint(uint8 endpoint, uint8 direction, uint8 type) -{ - boolean status = FALSE; - - if(endpoint > 0u && endpoint < 16u) - { - if(EP_DIR_IN == direction) - { - volatile EPx_CONTROL* epx_in_control = (volatile EPx_CONTROL*)(USBCTRL_DPRAM_BASE + (EPx_IN_CONTROL_OFFSET * endpoint)); - epx_in_control->reg = 0; - epx_in_control->bit.INTERRUPT_PER_BUFF = 1u; - epx_in_control->bit.INTERRUPT_ON_NAK = 1u; - epx_in_control->bit.INTERRUPT_ON_STALL = 1u; - epx_in_control->bit.ENDPOINT_TYPE = type & 0x03u; - epx_in_control->bit.BUFFER_ADDRESS = (uint16)(0x100u + (endpoint * 0x80u)); - epx_in_control->bit.ENABLE = 1u; - } - else if(EP_DIR_OUT == direction) - { - volatile EPx_CONTROL* epx_out_control = (volatile EPx_CONTROL*)(USBCTRL_DPRAM_BASE + EPx_OUT_CONTROL_OFFSET + ((endpoint)* 8ul)); - epx_out_control->reg = 0u; - epx_out_control->bit.INTERRUPT_PER_BUFF = 1u; - epx_out_control->bit.ENDPOINT_TYPE = type & 0x03u; - epx_out_control->bit.BUFFER_ADDRESS = (uint16)(0x100u + (endpoint * 0x80u)); - epx_out_control->bit.ENABLE = 1u; - } - else - { - /* wrong endpoint direction */ - return(status); - } - status = TRUE; - } - - return(status); -} - -//----------------------------------------------------------------------------------------- -/// \brief -/// -/// \param -/// -/// \return -//----------------------------------------------------------------------------------------- -static boolean UsbDriver_SendDataToHost(uint8 endpoint, uint8 pid, uint8* buffer, uint8 size) -{ - boolean status = FALSE; - - EPx_BUFFER_CONTROL* epx_in_buffer_control = (EPx_BUFFER_CONTROL*)(USBCTRL_DPRAM_BASE + EPx_IN_BUFFER_CONTROL_OFFSET + (endpoint * 8ul)); - - if((size < 65u) && (endpoint < 16u) && (pid < 2u)) - { - if(buffer != NULL) - { - for(uint8 i = 0; i < size; i++) - { - ((volatile uint8*)(USBCTRL_DPRAM_BASE + 0x100ul + (endpoint * 0x80ul)))[i] = buffer[i]; - } - } - - epx_in_buffer_control->reg = 0; - epx_in_buffer_control->bit.LENGTH_0 = size; - epx_in_buffer_control->bit.AVAILABLE_0 = 1u; - epx_in_buffer_control->bit.PID_0 = (pid == 0 ? 0 : 1); - epx_in_buffer_control->bit.FULL_0 = 1u; - - status = TRUE; - } - - return(status); -} - -//----------------------------------------------------------------------------------------- -/// \brief -/// -/// \param -/// -/// \return -//----------------------------------------------------------------------------------------- -static boolean UsbDriver_SendStallToHost(uint8 endpoint, uint8 pid) -{ - boolean status = FALSE; - - EPx_BUFFER_CONTROL* epx_in_buffer_control = (EPx_BUFFER_CONTROL*)(USBCTRL_DPRAM_BASE + EPx_IN_BUFFER_CONTROL_OFFSET + (endpoint * 8ul)); - - if((endpoint < 16u) && (pid < 2u)) - { - epx_in_buffer_control->reg = 0; - epx_in_buffer_control->bit.LENGTH_0 = 0; - epx_in_buffer_control->bit.AVAILABLE_0 = 1u; - epx_in_buffer_control->bit.PID_0 = (pid == 0 ? 0 : 1); - epx_in_buffer_control->bit.STALL = 1u; - - if(endpoint == EP0) - { - USBCTRL_REGS->EP_STALL_ARM.bit.EP0_IN = 1u; - } - epx_in_buffer_control->bit.FULL_0 = 1u; - - status = TRUE; - } - - return(status); -} -//----------------------------------------------------------------------------------------- -/// \brief -/// -/// \param -/// -/// \return -//----------------------------------------------------------------------------------------- -static boolean UsbDriver_ConfigureEpOutBuf(uint8 endpoint, uint8 pid, uint8 size) -{ - boolean status = FALSE; - - EPx_BUFFER_CONTROL* epx_out_buffer_control = (EPx_BUFFER_CONTROL*)(USBCTRL_DPRAM_BASE + EPx_OUT_BUFFER_CONTROL_OFFSET + (endpoint * 8ul)); - - if((size < 65u) && (endpoint < 16u) && (pid < 2u)) - { - /* configure the expected OUT packet */ - epx_out_buffer_control->reg = 0; - epx_out_buffer_control->bit.LENGTH_0 = size; - epx_out_buffer_control->bit.AVAILABLE_0 = 1u; - epx_out_buffer_control->bit.PID_0 = (pid == 0 ? 0 : 1); - epx_out_buffer_control->bit.FULL_0 = 0u; - status = TRUE; - } - - return(status); -} - -//----------------------------------------------------------------------------------------- -/// \brief -/// -/// \param -/// -/// \return -//----------------------------------------------------------------------------------------- -static void UsbDriver_HandleSetupPacket(const tUsbSetupPacket* const pUsbSetupPacket) -{ - const uint8 Request = pUsbSetupPacket->bRequest; - const tbmRequestType* const bmRequestType = (tbmRequestType*)(pUsbSetupPacket); - - if((bmRequestType->Type == USB_REQ_TYPE_STANDARD) && (Request < 13u) && (StandardRequestHandlerLockupTable[Request] != NULL)) - { - /* call the appropriate handler */ - StandardRequestHandlerLockupTable[Request](pUsbSetupPacket); - } - else if(bmRequestType->Type == USB_REQ_TYPE_CLASS) - { - /* class specific requests */ - if(bmRequestType->TransferDirection == USB_REQ_DIR_DEVICE_TO_HOST) - { - /* IN token is expected from the host, handle the specific request immediatly to the upper layer */ - if(Request == 0x21u) - { - /* GET_LINE_CODING */ - uint8 LineCodingFormat[7] = { 0x80, - 0x25, - 0, - 0, - 0, - 0, - 8 - }; - UsbDriver_SendDataToHost(EP0, DATA1_PID, (uint8*)LineCodingFormat, 7u); - } - } - else - { - /* OUT token is expected from the host, handle the specific request to upper layer after receiving the data on EP0 */ - if(Request == 0x20u) - { - /* SET_LINE_CODING */ - UsbDriver_SendDataToHost(EP0, DATA1_PID, NULL, 0); - } - else if(Request == 0x22u) - { - /* SET_CONTROL_LINE_STATE */ - UsbDriver_SendDataToHost(EP0, DATA1_PID, NULL, 0); - } - else - { - } - } -#ifdef __DEBUG_USB__ - _EP0_SpecificReq[_EP0_SpecificReq_index++] = *(volatile uint64*)pUsbSetupPacket; -#endif - } - else - { - for(;;); - } -} - -//----------------------------------------------------------------------------------------- -/// \brief -/// -/// \param -/// -/// \return -//----------------------------------------------------------------------------------------- -static void UsbDriver_Req_get_status(const tUsbSetupPacket* const pUsbSetupPacket) -{ - (void)pUsbSetupPacket; -} - -//----------------------------------------------------------------------------------------- -/// \brief -/// -/// \param -/// -/// \return -//----------------------------------------------------------------------------------------- -static void UsbDriver_Req_clear_feature(const tUsbSetupPacket* const pUsbSetupPacket) -{ - (void)pUsbSetupPacket; -} - -//----------------------------------------------------------------------------------------- -/// \brief -/// -/// \param -/// -/// \return -//----------------------------------------------------------------------------------------- -static void UsbDriver_Req_set_feature(const tUsbSetupPacket* const pUsbSetupPacket) -{ - (void)pUsbSetupPacket; -} - -//----------------------------------------------------------------------------------------- -/// \brief -/// -/// \param -/// -/// \return -//----------------------------------------------------------------------------------------- -static void UsbDriver_Req_set_address(const tUsbSetupPacket* const pUsbSetupPacket) -{ - UsbDeviceAddress = pUsbSetupPacket->wValue; - UsbDriver_SendDataToHost(EP0, DATA1_PID, NULL, 0); -} - -//----------------------------------------------------------------------------------------- -/// \brief -/// -/// \param -/// -/// \return -//----------------------------------------------------------------------------------------- -static void UsbDriver_Req_get_descriptor(const tUsbSetupPacket* const pUsbSetupPacket) -{ - const uint8 DescriptorType = (uint8)(pUsbSetupPacket->wValue >> 8); - - if(USB_DESCRIPTOR_TYPE_DEVICE == DescriptorType) - { - /* send the device descriptor */ - const unsigned char device_dsc[0x12] = { - 0x12, // bLength - 0x01, // bDescriptorType (Device) - 0x10, 0x01, // bcdUSB (1.1) - 0xEF, // bDeviceClass (Miscellaneous Device Class) - 0x02, // bDeviceSubClass (Common Class) - 0x01, // bDeviceProtocol (Interface Association Descriptor) - 0x40, // bMaxPacketSize0 (64 bytes) - 0x8a, 0x2e, // idVendor - 0x0a, 0x00, // idProduct - 0x01, 0x00, // bcdDevice (Device Version 0.01) - 0x01, // iManufacturer (String Index 1) - 0x02, // iProduct (String Index 2) - 0x03, // iSerialNumber (String Index 3) - 0x01 // bNumConfigurations (1 configuration) - }; - UsbDriver_SendDataToHost(EP0, DATA1_PID, (uint8*)device_dsc, sizeof(device_dsc)); - } - else if(USB_DESCRIPTOR_TYPE_CONFIGURATION == DescriptorType) - { - /* send configuration descriptor */ - static const uint8 configuration_dsc[] = { - /* Configuration Descriptor */ - 0x09, // bLength: Configuration Descriptor size - 0x02, // bDescriptorType: Configuration - 98, 0x00, // wTotalLength: The number of bytes in the configuration descriptor and all of its subordinate descriptors - 0x03, // bNumInterfaces: 3 interfaces (1 for vendor custom class, 1 for CDC Control and 1 for CDC Data) - 0x01, // bConfigurationValue: this Configuration index - 0x00, // iConfiguration: Index of string descriptor describing the configuration - 0x80, // bmAttributes: Self-powered - 250, // bMaxPower: 500 mA - - // Interface Descriptor (vendor custom class) - 0x09, // bLength - Descriptor size in bytes (09h) - 0x04, // bDescriptorType - The constant Interface (04h) - 0, // bInterfaceNumber - Interface number 0 - 0, // bAlternateSetting - A number that identifies a descriptor with alternate settings for this bInterfaceNumber. - 2, // bNumEndpoint - Number of endpoints supported not counting endpoint zero - 0xff, // bInterfaceClass - Class code - 0xff, // bInterfaceSubclass - Subclass code - 0xff, // bInterfaceProtocol - Protocol code - 0, // iInterface - Interface string index - - // Endpoint Descriptor (IN) - 0x07, // bLength - Descriptor size in bytes (07h) - 0x05, // bDescriptorType - The constant Endpoint (05h) - EP_DIR_IN | EP1, // bEndpointAddress - Endpoint number and direction - 0x02, // bmAttributes - Transfer type and supplementary information - 0x40,0x00, // wMaxPacketSize - Maximum packet size supported - 255, // bInterval - Service interval or NAK rate - - // Endpoint Descriptor (OUT) - 0x07, // bLength - Descriptor size in bytes (07h) - 0x05, // bDescriptorType - The constant Endpoint (05h) - EP_DIR_OUT | EP1, // bEndpointAddress - Endpoint number and direction - 0x02, // bmAttributes - Transfer type and supplementary information - 0x40,0x00, // wMaxPacketSize - Maximum packet size supported - 255, // bInterval - Service interval or NAK rate - - /* Interface Association Descriptor (IAD) for CDC/ACM */ - 0x08, // bLength: Interface Descriptor size - 0x0B, // bDescriptorType: IAD - 0x01, // bFirstInterface: First interface number (1) - 0x02, // bInterfaceCount: Number of interfaces for this function (2) - 0x02, // bFunctionClass: Communication Interface Class (CDC) - 0x02, // bFunctionSubClass: Abstract Control Model (ACM) - 0x00, // bFunctionProtocol: ???? - 0x00, // iFunction: Index of string descriptor describing this function - - /* Interface Descriptor (CDC Control) */ - 0x09, // bLength: Interface Descriptor size - 0x04, // bDescriptorType: Interface - 1, // bInterfaceNumber: Interface number 1 - 0x00, // bAlternateSetting: Alternate setting - 0x01, // bNumEndpoints: One endpoint (CDC Control) - 0x02, // bInterfaceClass: CDC - 0x02, // bInterfaceSubClass: Abstract Control Model - 0x00, // bInterfaceProtocol: V.25ter (AT commands) - 0x00, // iInterface: Index of string descriptor describing this interface - - /* CDC Header Functional Descriptor */ - 0x05, // bLength: CDC header Descriptor size - 0x24, // bDescriptorType: CS_INTERFACE - 0x00, // bDescriptorSubType: Header - 0x20, 0x01, // bcdCDC: CDC specification release number - - /* CDC Call Management Functional Descriptor */ - 0x05, // bLength: CDC Call Management Descriptor size - 0x24, // bDescriptorType: CS_INTERFACE - 0x01, // bDescriptorSubType: Call Management - 0x00, // bmCapabilities: Device does not handle call management itself - 0x02, // bDataInterface: Interface number of Data Class interface - - /* CDC Abstract Control Management Functional Descriptor */ - 0x04, // bLength: CDC Abstract Control Management Descriptor size - 0x24, // bDescriptorType: CS_INTERFACE - 0x02, // bDescriptorSubType: Abstract Control Management - 0x02, // bmCapabilities: Device supports the request combination of Set_Line_Coding, Set_Control_Line_State, Get_Line_Coding, and the notification Serial_State - - /* CDC Union Functional Descriptor */ - 0x05, // bLength: CDC Union Descriptor size - 0x24, // bDescriptorType: CS_INTERFACE - 0x06, // bDescriptorSubType: Union - 0x01, // bControlInterface: Interface number of the Control interface - 0x02, // bSubordinateInterface0: Interface number of the subordinate interface - - /* Endpoint Descriptor (CDC Control IN) */ - 0x07, // bLength: Endpoint Descriptor size - 0x05, // bDescriptorType: Endpoint - EP_DIR_IN | EP3, // bEndpointAddress: CDC Control endpoint address (IN) - 0x03, // bmAttributes: Interrupt - 0x08, 0x00, // wMaxPacketSize: CDC Control packet size (8 bytes) - 0x10, // bInterval: Polling interval (16ms) - - /* Interface Descriptor (CDC Data) */ - 0x09, // bLength: Interface Descriptor size - 0x04, // bDescriptorType: Interface - 2, // bInterfaceNumber: Interface number 2 - 0x00, // bAlternateSetting: Alternate setting - 0x02, // bNumEndpoints: Two endpoints (CDC Data) - 0x0A, // bInterfaceClass: CDC Data - 0x00, // bInterfaceSubClass - 0x00, // bInterfaceProtocol - 0x00, // iInterface: Index of string descriptor describing this interface - - /* Endpoint Descriptor (CDC Data IN) */ - 0x07, // bLength: Endpoint Descriptor size - 0x05, // bDescriptorType: Endpoint - EP_DIR_IN | EP2, // bEndpointAddress: CDC Data IN endpoint address - 0x02, // bmAttributes: Bulk - 0x40, 0x00, // wMaxPacketSize: CDC Data packet size (64 bytes) - 0x00, // bInterval: Never NAK - - /* Endpoint Descriptor (CDC Data OUT) */ - 0x07, // bLength: Endpoint Descriptor size - 0x05, // bDescriptorType: Endpoint - EP_DIR_OUT | EP2, // bEndpointAddress: CDC Data OUT endpoint address - 0x02, // bmAttributes: Bulk - 0x40, 0x00, // wMaxPacketSize: CDC Data packet size (64 bytes) - 0x00 // bInterval: Never NAK - }; - - - /* check the configuration size requested by the host - note: we must send exactly the requested size otherwise the host will abort the enumeration process */ - const uint8 size = (((uint8)(pUsbSetupPacket->wLength) > sizeof(configuration_dsc)) && (sizeof(configuration_dsc) < 65u)) ? sizeof(configuration_dsc) : (uint8)(pUsbSetupPacket->wLength); - - const uint8 number_of_64_packet_size = sizeof(configuration_dsc) / 64u; - const uint8 remaining_config_data_size = sizeof(configuration_dsc) % 64u; - - EPx_BUFFER_CONTROL* epx_in_buffer_control = (EPx_BUFFER_CONTROL*)(USBCTRL_DPRAM_BASE + EPx_IN_BUFFER_CONTROL_OFFSET + (EP0 * 8ul)); - - if(size > 64u) - { - uint8 data_pid = DATA1_PID; - - for(uint32 i=0; i < number_of_64_packet_size; i++) - { - UsbDriver_SendDataToHost(EP0, data_pid, (uint8*)((uint32)configuration_dsc + i*64u), (uint8)64); - - data_pid ^= 1u; - - /* wait till the buffer got transmitterd */ - while(epx_in_buffer_control->bit.FULL_0); - } - - /* send the remaining data */ - UsbDriver_SendDataToHost(EP0, data_pid, (uint8*)((uint32)configuration_dsc + number_of_64_packet_size*64u), (uint8)remaining_config_data_size); - - } - else - { - /* only one packet of 64-byte max */ - /* send the configuration to the host */ - UsbDriver_SendDataToHost(EP0, DATA1_PID, (uint8*)configuration_dsc, (uint8)size); - } - } - else if(USB_DESCRIPTOR_TYPE_HID_REPORT == DescriptorType) - { - const uint8 hid_rpt_desc[] = - { - 0x06, 0x00, 0xFF, // Usage Page = 0xFF00 (Vendor Defined Page 1) - 0x09, 0x01, // Usage (Vendor Usage 1) - 0xA1, 0x01, // Collection (Application) - // Input report - 0x19, 0x01, // Usage Minimum - 0x29, 0x40, // Usage Maximum - 0x15, 0x00, // Logical Minimum (data bytes in the report may have minimum value = 0x00) - 0x26, 0xFF, 0x00, // Logical Maximum (data bytes in the report may have maximum value = 0x00FF = unsigned 255) - 0x75, 0x08, // Report Size: 8-bit field size - 0x95, 64, // Report Count - 0x81, 0x02, // Input (Data, Array, Abs) - // Output report - 0x19, 0x01, // Usage Minimum - 0x29, 0x40, // Usage Maximum - 0x75, 0x08, // Report Size: 8-bit field size - 0x95, 64, // Report Count - 0x91, 0x02, // Output (Data, Array, Abs) - 0xC0 // End Collection - }; - - UsbDriver_SendDataToHost(EP0, DATA1_PID, (uint8*)hid_rpt_desc, sizeof(hid_rpt_desc)); - - } - else if(USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER == DescriptorType) - { - /* As DEVICE_QUALIFIER is used only for high speed we will not support it on RP2350 (has only a full speed device controller) */ - UsbDriver_SendStallToHost(EP0, DATA1_PID); - } - else if(USB_DESCRIPTOR_TYPE_STRING == DescriptorType) - { - const tUsbStringDescriptor UsbStringDescriptor = {4, 0x03, {0x0409}}; - const tUsbSubsequentStringDescriptor UsbSubsequentStringDescriptor_0 = {30, 0x03, {'C','H','A','L','A','N','D','I',' ','A','M','I','N','E'}}; /* Manufacturer string descriptor */ - const tUsbSubsequentStringDescriptor UsbSubsequentStringDescriptor_1 = {36, 0x03, {'C','H','A','L','A','N','D','I',' ','D','E','B','U','G','G','E','R'}}; /* Product string descriptor */ - const tUsbSubsequentStringDescriptor UsbSubsequentStringDescriptor_2 = {10, 0x03, {'2','0','2','3'}}; /* SerialNumber */ - - const uint8 StrIdx = (uint8)pUsbSetupPacket->wValue; - - if(StrIdx == 0u) - { - UsbDriver_SendDataToHost(EP0, DATA1_PID, (uint8*)&UsbStringDescriptor,UsbStringDescriptor.bLength); - } - else if(StrIdx == 1u) - { - UsbDriver_SendDataToHost(EP0, DATA1_PID, (uint8*)&UsbSubsequentStringDescriptor_0, UsbSubsequentStringDescriptor_0.bLength); - } - else if(StrIdx == 2u) - { - UsbDriver_SendDataToHost(EP0, DATA1_PID, (uint8*)&UsbSubsequentStringDescriptor_1, UsbSubsequentStringDescriptor_1.bLength); - } - else if(StrIdx == 3u) - { - UsbDriver_SendDataToHost(EP0, DATA1_PID, (uint8*)&UsbSubsequentStringDescriptor_2, UsbSubsequentStringDescriptor_2.bLength); - } - else - { - UsbDriver_SendStallToHost(EP0, DATA1_PID); - } - } - else - { - - } -} - -//----------------------------------------------------------------------------------------- -/// \brief -/// -/// \param -/// -/// \return -//----------------------------------------------------------------------------------------- -static void UsbDriver_Req_set_descriptor(const tUsbSetupPacket* const pUsbSetupPacket) -{ - (void)pUsbSetupPacket; -} - -//----------------------------------------------------------------------------------------- -/// \brief -/// -/// \param -/// -/// \return -//----------------------------------------------------------------------------------------- -static void UsbDriver_Req_get_configuration(const tUsbSetupPacket* const pUsbSetupPacket) -{ - /* as we have only one configuration just send one to the host */ - (void)pUsbSetupPacket; - const uint8 config = 1; - UsbDriver_SendDataToHost(EP0, DATA1_PID, (uint8*)&config, 1); -} - -//----------------------------------------------------------------------------------------- -/// \brief -/// -/// \param -/// -/// \return -//----------------------------------------------------------------------------------------- -static void UsbDriver_Req_set_configuration(const tUsbSetupPacket* const pUsbSetupPacket) -{ - /* as we have only one configuration just send ACK to the host */ - (void)pUsbSetupPacket; - UsbDriver_SendDataToHost(EP0, DATA1_PID, NULL, 0); -} - -//----------------------------------------------------------------------------------------- -/// \brief -/// -/// \param -/// -/// \return -//----------------------------------------------------------------------------------------- -static void UsbDriver_Req_get_interface(const tUsbSetupPacket* const pUsbSetupPacket) -{ - (void)pUsbSetupPacket; -} - -//----------------------------------------------------------------------------------------- -/// \brief -/// -/// \param -/// -/// \return -//----------------------------------------------------------------------------------------- -static void UsbDriver_Req_set_interface(const tUsbSetupPacket* const pUsbSetupPacket) -{ - (void)pUsbSetupPacket; -} - -//----------------------------------------------------------------------------------------- -/// \brief -/// -/// \param -/// -/// \return -//----------------------------------------------------------------------------------------- -static void UsbDriver_Req_synch_frame(const tUsbSetupPacket* const pUsbSetupPacket) -{ - (void)pUsbSetupPacket; -} - -//----------------------------------------------------------------------------------------- -/// \brief -/// -/// \param -/// -/// \return -//----------------------------------------------------------------------------------------- -void UsbDriver_SendSerialMsg(uint8* msg) -{ - UsbDriver_SendDataToHost(EP2, EPx_dataPid[EP2], (uint8*)msg, (uint8)strlen((const char*)msg)); -} - -//----------------------------------------------------------------------------------------- -/// \brief -/// -/// \param -/// -/// \return -//----------------------------------------------------------------------------------------- -boolean UsbDriver_IsDeviceConnected(void) -{ - return(USBCTRL_REGS->SIE_STATUS.bit.CONNECTED == 1u ? TRUE : FALSE); -} diff --git a/ref_app/src/mcal/rpi_pico2_rp2350/Mcal/USB/USB.h b/ref_app/src/mcal/rpi_pico2_rp2350/Mcal/USB/USB.h deleted file mode 100644 index 1781337c9..000000000 --- a/ref_app/src/mcal/rpi_pico2_rp2350/Mcal/USB/USB.h +++ /dev/null @@ -1,257 +0,0 @@ -/****************************************************************************************** - Filename : USB.h - - Core : ARM Cortex-M33 / RISC-V Hazard3 - - MCU : RP2350 - - Author : Chalandi Amine - - Owner : Chalandi Amine - - Date : 04.09.2024 - - Description : USB low level device driver header file - -******************************************************************************************/ - -#ifndef __USB_H__ -#define __USB_H__ - -#include "Platform_Types.h" -#include "usb_types.h" - -void USBCTRL_IRQ(void); -void UsbInit(void); -void UsbDriver_SendSerialMsg(uint8* msg); -boolean UsbDriver_IsDeviceConnected(void); - -/* endpoints IDs */ -#define EP0 0u -#define EP1 1u -#define EP2 2u -#define EP3 3u -#define EP4 4u -#define EP5 5u -#define EP6 6u -#define EP7 7u -#define EP8 8u -#define EP9 9u -#define EP10 10u -#define EP11 11u -#define EP12 12u -#define EP13 13u -#define EP14 14u -#define EP15 15u - -/* endpoints direction */ -#define EP_DIR_IN 0x80 -#define EP_DIR_OUT 0x00 - -/* Data PIDs */ -#define DATA0_PID 0u -#define DATA1_PID 1u - -/* SETUP Packet - Standard requests */ -#define USB_REQ_GET_STATUS 0u -#define USB_REQ_CLEAR_FEATURE 1u -#define USB_REQ_SET_FEATURE 3u -#define USB_REQ_SET_ADDRESS 5u -#define USB_REQ_GET_DESCRIPTOR 6u -#define USB_REQ_SET_DESCRIPTOR 7u -#define USB_REQ_GET_CONFIGURATION 8u -#define USB_REQ_SET_CONFIGURATION 9u -#define USB_REQ_GET_INTERFACE 10u -#define USB_REQ_SET_INTERFACE 11u -#define USB_REQ_SYNCH_FRAME 12u - -#define USB_REQ_DIR_DEVICE_TO_HOST 1u -#define USB_REQ_DIR_HOST_TO_DEVICE 0u - -#define USB_REQ_TYPE_STANDARD 0u -#define USB_REQ_TYPE_CLASS 1u -#define USB_REQ_TYPE_VENDOR 2u -#define USB_REQ_TYPE_RESERVED 3u - -#define USB_REQ_RECIPIENT_DEVICE 0u -#define USB_REQ_RECIPIENT_INTERFACE 1u -#define USB_REQ_RECIPIENT_ENDPOINT 2u - -/* Descriptor Types */ -#define USB_DESCRIPTOR_TYPE_DEVICE 1u -#define USB_DESCRIPTOR_TYPE_CONFIGURATION 2u -#define USB_DESCRIPTOR_TYPE_STRING 3u -#define USB_DESCRIPTOR_TYPE_INTERFACE 4u -#define USB_DESCRIPTOR_TYPE_ENDPOINT 5u -#define USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER 6u -#define USB_DESCRIPTOR_TYPE_OTHER_SPEED_CONFIGURATION 7u -#define USB_DESCRIPTOR_TYPE_INTERFACE_POWER 8u -#define USB_DESCRIPTOR_TYPE_HID_REPORT 0x22u - - -/* USB device type */ -typedef struct -{ - uint32_t DeviceAddress; - tUsbDeviceDescriptor UsbDeviceDescriptor; - tUsbEndpointDescriptor UsbEndpointDescriptor; /* this must be a pointer to a pool of endpoints (maybe a linked list) */ - tUsbConfigurationDescriptor UsbConfigurationDescriptor; - uint8_t desc[]; -}__attribute__((packed)) UsbDeviceDriverContainer_t; - -#if 0 -static UsbDeviceDriverContainer_t UsbDeviceDriverContainer = { - /* DeviceAddress */ - 0, - /* UsbDeviceDescriptor */ - { - 0x12, // bLength - 0x01, // bDescriptorType (Device) - 0x10, 0x01, // bcdUSB (1.1) - 0xEF, // bDeviceClass (Miscellaneous Device Class) - 0x02, // bDeviceSubClass (Common Class) - 0x01, // bDeviceProtocol (Interface Association Descriptor) - 0x40, // bMaxPacketSize0 (64 bytes) - 0x8a, 0x2e, // idVendor - 0x0a, 0x00, // idProduct - 0x01, 0x00, // bcdDevice (Device Version 0.01) - 0x01, // iManufacturer (String Index 1) - 0x02, // iProduct (String Index 2) - 0x03, // iSerialNumber (String Index 3) - 0x01 // bNumConfigurations (1 configuration) - }, - /* UsbEndpointDescriptor */ - { - 0 - }, - /* UsbConfigurationDescriptor */ - { - /* Configuration Descriptor */ - 0x09, // bLength: Configuration Descriptor size - 0x02, // bDescriptorType: Configuration - 98, 0x00, // wTotalLength: The number of bytes in the configuration descriptor and all of its subordinate descriptors - 0x03, // bNumInterfaces: 3 interfaces (1 for vendor custom class, 1 for CDC Control and 1 for CDC Data) - 0x01, // bConfigurationValue: this Configuration index - 0x00, // iConfiguration: Index of string descriptor describing the configuration - 0x80, // bmAttributes: Self-powered - 250 // bMaxPower: 500 mA - }, - { - // Interface Descriptor (vendor custom class) - 0x09, // bLength - Descriptor size in bytes (09h) - 0x04, // bDescriptorType - The constant Interface (04h) - 0, // bInterfaceNumber - Interface number 0 - 0, // bAlternateSetting - A number that identifies a descriptor with alternate settings for this bInterfaceNumber. - 2, // bNumEndpoint - Number of endpoints supported not counting endpoint zero - 0xff, // bInterfaceClass - Class code - 0xff, // bInterfaceSubclass - Subclass code - 0xff, // bInterfaceProtocol - Protocol code - 0, // iInterface - Interface string index - - // Endpoint Descriptor (IN) - 0x07, // bLength - Descriptor size in bytes (07h) - 0x05, // bDescriptorType - The constant Endpoint (05h) - EP_DIR_IN | EP1, // bEndpointAddress - Endpoint number and direction - 0x02, // bmAttributes - Transfer type and supplementary information - 0x40,0x00, // wMaxPacketSize - Maximum packet size supported - 255, // bInterval - Service interval or NAK rate - - // Endpoint Descriptor (OUT) - 0x07, // bLength - Descriptor size in bytes (07h) - 0x05, // bDescriptorType - The constant Endpoint (05h) - EP_DIR_OUT | EP1, // bEndpointAddress - Endpoint number and direction - 0x02, // bmAttributes - Transfer type and supplementary information - 0x40,0x00, // wMaxPacketSize - Maximum packet size supported - 255, // bInterval - Service interval or NAK rate - - /* Interface Association Descriptor (IAD) for CDC/ACM */ - 0x08, // bLength: Interface Descriptor size - 0x0B, // bDescriptorType: IAD - 0x01, // bFirstInterface: First interface number (1) - 0x02, // bInterfaceCount: Number of interfaces for this function (2) - 0x02, // bFunctionClass: Communication Interface Class (CDC) - 0x02, // bFunctionSubClass: Abstract Control Model (ACM) - 0x00, // bFunctionProtocol: ???? - 0x00, // iFunction: Index of string descriptor describing this function - - /* Interface Descriptor (CDC Control) */ - 0x09, // bLength: Interface Descriptor size - 0x04, // bDescriptorType: Interface - 1, // bInterfaceNumber: Interface number 1 - 0x00, // bAlternateSetting: Alternate setting - 0x01, // bNumEndpoints: One endpoint (CDC Control) - 0x02, // bInterfaceClass: CDC - 0x02, // bInterfaceSubClass: Abstract Control Model - 0x00, // bInterfaceProtocol: V.25ter (AT commands) - 0x00, // iInterface: Index of string descriptor describing this interface - - /* CDC Header Functional Descriptor */ - 0x05, // bLength: CDC header Descriptor size - 0x24, // bDescriptorType: CS_INTERFACE - 0x00, // bDescriptorSubType: Header - 0x20, 0x01, // bcdCDC: CDC specification release number - - /* CDC Call Management Functional Descriptor */ - 0x05, // bLength: CDC Call Management Descriptor size - 0x24, // bDescriptorType: CS_INTERFACE - 0x01, // bDescriptorSubType: Call Management - 0x00, // bmCapabilities: Device does not handle call management itself - 0x01, // bDataInterface: Interface number of Data Class interface - - /* CDC Abstract Control Management Functional Descriptor */ - 0x04, // bLength: CDC Abstract Control Management Descriptor size - 0x24, // bDescriptorType: CS_INTERFACE - 0x02, // bDescriptorSubType: Abstract Control Management - 0x02, // bmCapabilities: Device supports the request combination of Set_Line_Coding, Set_Control_Line_State, Get_Line_Coding, and the notification Serial_State - - /* CDC Union Functional Descriptor */ - 0x05, // bLength: CDC Union Descriptor size - 0x24, // bDescriptorType: CS_INTERFACE - 0x06, // bDescriptorSubType: Union - 0x01, // bControlInterface: Interface number of the Control interface - 0x02, // bSubordinateInterface0: Interface number of the subordinate interface - - /* Endpoint Descriptor (CDC Control IN) */ - 0x07, // bLength: Endpoint Descriptor size - 0x05, // bDescriptorType: Endpoint - EP_DIR_IN | EP3, // bEndpointAddress: CDC Control endpoint address (IN) - 0x03, // bmAttributes: Interrupt - 0x08, 0x00, // wMaxPacketSize: CDC Control packet size (8 bytes) - 0x10, // bInterval: Polling interval (16ms) - - /* Interface Descriptor (CDC Data) */ - 0x09, // bLength: Interface Descriptor size - 0x04, // bDescriptorType: Interface - 2, // bInterfaceNumber: Interface number 2 - 0x00, // bAlternateSetting: Alternate setting - 0x02, // bNumEndpoints: Two endpoints (CDC Data) - 0x0A, // bInterfaceClass: CDC Data - 0x00, // bInterfaceSubClass - 0x00, // bInterfaceProtocol - 0x00, // iInterface: Index of string descriptor describing this interface - - /* Endpoint Descriptor (CDC Data IN) */ - 0x07, // bLength: Endpoint Descriptor size - 0x05, // bDescriptorType: Endpoint - EP_DIR_IN | EP2, // bEndpointAddress: CDC Data IN endpoint address - 0x02, // bmAttributes: Bulk - 0x40, 0x00, // wMaxPacketSize: CDC Data packet size (64 bytes) - 0x00, // bInterval: Never NAK - - /* Endpoint Descriptor (CDC Data OUT) */ - 0x07, // bLength: Endpoint Descriptor size - 0x05, // bDescriptorType: Endpoint - EP_DIR_OUT | EP2, // bEndpointAddress: CDC Data OUT endpoint address - 0x02, // bmAttributes: Bulk - 0x40, 0x00, // wMaxPacketSize: CDC Data packet size (64 bytes) - 0x00 // bInterval: Never NAK - } - }; - - - -#endif - - - -#endif diff --git a/ref_app/src/mcal/rpi_pico2_rp2350/Mcal/USB/usb_hwreg.h b/ref_app/src/mcal/rpi_pico2_rp2350/Mcal/USB/usb_hwreg.h deleted file mode 100644 index 72565fa41..000000000 --- a/ref_app/src/mcal/rpi_pico2_rp2350/Mcal/USB/usb_hwreg.h +++ /dev/null @@ -1,87 +0,0 @@ - -#ifndef __USB_HWREG_H__ -#define __USB_HWREG_H__ - -#include - -#define __IM volatile const /*! Defines 'read only' structure member permissions */ -#define __OM volatile /*! Defines 'write only' structure member permissions */ -#define __IOM volatile /*! Defines 'read / write' structure member permissions */ - - -typedef union { - __IOM uint32_t reg; /*!< (@ 0x00000080) Buffer control for both buffers of an endpoint. - Fields ending in a _1 are for buffer 1. - Fields ending in a _0 are for buffer 0. - Buffer 1 controls are only valid if the - endpoint is in double buffered mode. */ - - struct { - __IOM uint32_t LENGTH_0 : 10; /*!< [9..0] The length of the data in buffer 1. */ - __IOM uint32_t AVAILABLE_0 : 1; /*!< [10..10] Buffer 0 is available. This bit is set to indicate - the buffer can be used by the controller. The controller - clears the available bit when writing the status back. */ - __IOM uint32_t STALL : 1; /*!< [11..11] Reply with a stall (valid for both buffers). */ - __IOM uint32_t RESET : 1; /*!< [12..12] Reset the buffer selector to buffer 0. */ - __IOM uint32_t PID_0 : 1; /*!< [13..13] The data pid of buffer 0. */ - __IOM uint32_t LAST_0 : 1; /*!< [14..14] Buffer 0 is the last buffer of the transfer. */ - __IOM uint32_t FULL_0 : 1; /*!< [15..15] Buffer 0 is full. For an IN transfer (TX to the host) - the bit is set to indicate the data is valid. For an OUT - transfer (RX from the host) this bit should be left as - a 0. The host will set it when it has filled the buffer - with data. */ - __IOM uint32_t LENGTH_1 : 10; /*!< [25..16] The length of the data in buffer 1. */ - __IOM uint32_t AVAILABLE_1 : 1; /*!< [26..26] Buffer 1 is available. This bit is set to indicate - the buffer can be used by the controller. The controller - clears the available bit when writing the status back. */ - __IOM uint32_t DOUBLE_BUFFER_ISO_OFFSET : 2;/*!< [28..27] The number of bytes buffer 1 is offset from buffer - 0 in Isochronous mode. Only valid in double buffered mode - for an Isochronous endpoint. - For a non Isochronous endpoint the offset is always 64 - bytes. */ - __IOM uint32_t PID_1 : 1; /*!< [29..29] The data pid of buffer 1. */ - __IOM uint32_t LAST_1 : 1; /*!< [30..30] Buffer 1 is the last buffer of the transfer. */ - __IOM uint32_t FULL_1 : 1; /*!< [31..31] Buffer 1 is full. For an IN transfer (TX to the host) - the bit is set to indicate the data is valid. For an OUT - transfer (RX from the host) this bit should be left as - a 0. The host will set it when it has filled the buffer - with data. */ - } bit; -} EPx_BUFFER_CONTROL; - -typedef union { - __IOM uint32_t reg; /*!< (@ 0x00000008) EP1_IN_CONTROL */ - - struct { - __IOM uint32_t BUFFER_ADDRESS : 16; /*!< [15..0] 64 byte aligned buffer address for this EP (bits 0-5 - are ignored). Relative to the start of the DPRAM. */ - __IOM uint32_t INTERRUPT_ON_NAK : 1; /*!< [16..16] Trigger an interrupt if a NAK is sent. Intended for - debug only. */ - __IOM uint32_t INTERRUPT_ON_STALL : 1; /*!< [17..17] Trigger an interrupt if a STALL is sent. Intended for - debug only. */ - uint32_t : 8; - __IOM uint32_t ENDPOINT_TYPE : 2; /*!< [27..26] ENDPOINT_TYPE */ - __IOM uint32_t INTERRUPT_PER_DOUBLE_BUFF : 1;/*!< [28..28] Trigger an interrupt each time both buffers are done. - Only valid in double buffered mode. */ - __IOM uint32_t INTERRUPT_PER_BUFF : 1; /*!< [29..29] Trigger an interrupt each time a buffer is done. */ - __IOM uint32_t DOUBLE_BUFFERED : 1; /*!< [30..30] This endpoint is double buffered. */ - __IOM uint32_t ENABLE : 1; /*!< [31..31] Enable this endpoint. The device will not reply to - any packets for this endpoint if this bit is not set. */ - } bit; -} EPx_CONTROL; - -#ifndef USBCTRL_DPRAM_BASE -#define USBCTRL_DPRAM_BASE 0x50100000UL -#endif - -#ifndef USBCTRL_REGS_BASE -#define USBCTRL_REGS_BASE 0x50110000UL -#endif - -#define EPx_IN_CONTROL_OFFSET 0x08 -#define EPx_OUT_CONTROL_OFFSET 0x04 - -#define EPx_IN_BUFFER_CONTROL_OFFSET 0x80 -#define EPx_OUT_BUFFER_CONTROL_OFFSET 0x84 - -#endif /*__USB_HWREG_H__*/ diff --git a/ref_app/src/mcal/rpi_pico2_rp2350/Mcal/USB/usb_types.h b/ref_app/src/mcal/rpi_pico2_rp2350/Mcal/USB/usb_types.h deleted file mode 100644 index b5d93e9ff..000000000 --- a/ref_app/src/mcal/rpi_pico2_rp2350/Mcal/USB/usb_types.h +++ /dev/null @@ -1,133 +0,0 @@ - -#ifndef __USB_TYPES_H__ -#define __USB_TYPES_H__ - -#include "Platform_Types.h" - -//------------------------------------------------------------------------------------------------------------------ -// Setup Packet -//------------------------------------------------------------------------------------------------------------------ -typedef struct -{ - uint8 bmRequestType; - uint8 bRequest; - uint16 wValue; - uint16 wIndex; - uint16 wLength; -}tUsbSetupPacket; - -typedef struct -{ - uint8 Recipient:5u; - uint8 Type:2u; - uint8 TransferDirection:1u; -}tbmRequestType; - -//------------------------------------------------------------------------------------------------------------------ -// Device Descriptor -//------------------------------------------------------------------------------------------------------------------ -typedef struct -{ - uint8 bLength; //Size of the Descriptor in Bytes (18 bytes) - uint8 bDescriptorType; //Constant Device Descriptor (0x01) - uint8 bcdUSB_L; //USB Specification Number (LSB byte) which device complies too. - uint8 bcdUSB_H; //USB Specification Number (MSB byte) which device complies too. - uint8 bDeviceClass; //Class Code (Assigned by USB Org) If equal to Zero, each interface specifies it’s own class code If equal to 0xFF, the class code is vendor specified. Otherwise field is valid Class Code. - uint8 bDeviceSubClass; //SubClass Subclass Code (Assigned by USB Org) - uint8 bDeviceProtocol; //Protocol Protocol Code (Assigned by USB Org) - uint8 bMaxPacketSize; //Number Maximum Packet Size for Zero Endpoint. Valid Sizes are 8, 16, 32, 64 - uint8 idVendor_L; //Vendor ID (LSB byte) (Assigned by USB Org) - uint8 idVendor_H; //Vendor ID (MSB byte) (Assigned by USB Org) - uint8 idProduct_L; //Product ID (LSB byte) (Assigned by Manufacturer) - uint8 idProduct_H; //Product ID (MSB byte) (Assigned by Manufacturer) - uint8 bcdDevice_L; //Device Release Number (LSB byte) - uint8 bcdDevice_H; //Device Release Number (MSB byte) - uint8 iManufacturer; //Index of Manufacturer String Descriptor - uint8 iProduct; //Index of Product String Descriptor - uint8 iSerialNumber; //Index of Serial Number String Descriptor - uint8 bNumConfigurations; //Number of Possible Configurations -}tUsbDeviceDescriptor; - -//------------------------------------------------------------------------------------------------------------------ -// Configuration Descriptor -//------------------------------------------------------------------------------------------------------------------ -typedef struct -{ - uint8 bLength; //Size of Descriptor in Bytes - uint8 bDescriptorType; //Configuration Descriptor (0x02) - uint8 wTotalLength_L; //Total length in bytes of data returned (LSB byte) - uint8 wTotalLength_H; //Total length in bytes of data returned (MSB byte) - uint8 bNumInterfaces; //Number of Interfaces - uint8 bConfigurationValue; //Value to use as an argument to select this configuration - uint8 iConfiguration; //Index of String Descriptor describing this configuration - uint8 bmAttributes; //D7 Reserved, set to 1. (USB 1.0 Bus Powered) D6 Self Powered, D5 Remote Wakeup, D4..0 Reserved, set to 0. - uint8 bMaxPower; //Maximum Power Consumption in 2mA units -}tUsbConfigurationDescriptor; - -//------------------------------------------------------------------------------------------------------------------ -// Interface Descriptor -//------------------------------------------------------------------------------------------------------------------ -typedef struct -{ - uint8 bLength; //Size of Descriptor in Bytes (9 Bytes) - uint8 bDescriptorType; //Interface Descriptor (0x04) - uint8 bInterfaceNumber; //Number of Interface - uint8 bAlternateSetting; //Value used to select alternative setting - uint8 bNumEndpoints; //Number of Endpoints used for this interface - uint8 bInterfaceClass; //Class Code (Assigned by USB Org) - uint8 bInterfaceSubClass; //Subclass Code (Assigned by USB Org) - uint8 bInterfaceProtocol; //Protocol Code (Assigned by USB Org) - uint8 iInterface; //Index of String Descriptor Describing this interface -}tUsbInterfaceDescriptor; - -//------------------------------------------------------------------------------------------------------------------ -// Endpoint Descriptor -//------------------------------------------------------------------------------------------------------------------ -typedef struct -{ - uint8 bLength; //Size of Descriptor in Bytes (7 bytes) - uint8 bDescriptorType; //Endpoint Descriptor (0x05) - uint8 bEndpointAddress; //Endpoint AddressBits 0..3b Endpoint Number.Bits 4..6b Reserved. Set to Zero Bits 7 Direction 0 = Out, 1 = In (Ignored for Control Endpoints) - uint8 bmAttributes; //Bits 0..1 Transfer Type - //00 = Control - //01 = Isochronous - //10 = Bulk - //11 = Interrupt - //Bits 2..7 are reserved. If Isochronous endpoint, - //Bits 3..2 = Synchronisation Type (Iso Mode) - //00 = No Synchonisation - //01 = Asynchronous - //10 = Adaptive - //11 = Synchronous - //Bits 5..4 = Usage Type (Iso Mode) - //00 = Data Endpoint - //01 = Feedback Endpoint - //10 = Explicit Feedback Data Endpoint - //11 = Reserved - uint8 wMaxPacketSize_L; //Maximum Packet Size this endpoint is capable of sending or receiving (LSB byte) - uint8 wMaxPacketSize_H; //Maximum Packet Size this endpoint is capable of sending or receiving (MSB byte) - uint8 bInterval; //Interval for polling endpoint data transfers. Value in frame counts. Ignored for Bulk & Control Endpoints. Isochronous must equal 1 and field may range from 1 to 255 for interrupt endpoints. -}tUsbEndpointDescriptor; - -//------------------------------------------------------------------------------------------------------------------ -// String Descriptors -//------------------------------------------------------------------------------------------------------------------ -#define USB_NUMBER_OF_SUPPORTED_LANGUAGE 1U -#define USB_MAX_STRING_LENGTH 50U - -typedef struct -{ - uint8 bLength; //Size of Descriptor in Bytes - uint8 bDescriptorType; //String Descriptor (0x03) - uint16 wLANGID[USB_NUMBER_OF_SUPPORTED_LANGUAGE]; //Supported Language Code (e.g. 0x0409 English - United States) -}tUsbStringDescriptor; - - -typedef struct -{ - uint8 bLength; //Size of Descriptor in Bytes - uint8 bDescriptorType; //String Descriptor (0x03) - uint16 bString[USB_MAX_STRING_LENGTH]; //Unicode Encoded String -}tUsbSubsequentStringDescriptor; - -#endif diff --git a/ref_app/src/mcal/rpi_pico2_rp2350/mcal_benchmark.h b/ref_app/src/mcal/rpi_pico2_rp2350/mcal_benchmark.h new file mode 100644 index 000000000..30540ecb9 --- /dev/null +++ b/ref_app/src/mcal/rpi_pico2_rp2350/mcal_benchmark.h @@ -0,0 +1,24 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2014 - 2024. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#ifndef MCAL_BENCHMARK_2014_04_16_H_ + #define MCAL_BENCHMARK_2014_04_16_H_ + + #include + + #include + #include + + namespace mcal + { + namespace benchmark + { + using benchmark_port_type = mcal::port::port_pin<15U>; + } + } + +#endif // MCAL_BENCHMARK_2014_04_16_H_ diff --git a/ref_app/src/mcal/rpi_pico2_rp2350/mcal_cpu.cpp b/ref_app/src/mcal/rpi_pico2_rp2350/mcal_cpu.cpp new file mode 100644 index 000000000..2731d4e75 --- /dev/null +++ b/ref_app/src/mcal/rpi_pico2_rp2350/mcal_cpu.cpp @@ -0,0 +1,57 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2007 - 2024. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#include +#include +#include + +#include + +namespace local { + +auto init_core() -> void; + +auto init_core() -> void +{ + /* we came here from the RP2350 BootRom and SBL */ + /* Reset core1 to start from a known state */ + + HW_PER_PSM->FRCE_OFF.bit.PROC1 = 1U; + + while((HW_PER_PSM->DONE.bit.PROC1 == 1U)); + + HW_PER_PSM->FRCE_OFF.bit.PROC1 = 0U; + + while((HW_PER_PSM->DONE.bit.PROC1 != 1U)); + + /* Reset peripheral to start from a known state */ + HW_PER_RESETS->RESET.bit.IO_BANK0 = 1U; + HW_PER_RESETS->RESET.bit.PADS_BANK0 = 1U; + + while((HW_PER_RESETS->RESET_DONE.bit.IO_BANK0 == 1U) || (HW_PER_RESETS->RESET_DONE.bit.PADS_BANK0 == 1U)); + + HW_PER_RESETS->RESET.bit.IO_BANK0 = 0U; + HW_PER_RESETS->RESET.bit.PADS_BANK0 = 0U; + + while((HW_PER_RESETS->RESET_DONE.bit.IO_BANK0 == 0U) || (HW_PER_RESETS->RESET_DONE.bit.PADS_BANK0 == 0U)); + + /*Setting EXTEXCLALL allows external exclusive operations to be used in a configuration with no MPU. + This is because the default memory map does not include any shareable Normal memory.*/ + SCnSCB->ACTLR |= (1ul<<29); +} + +} // namespace local + + +void mcal::cpu::init() +{ + local::init_core(); + + mcal::wdg::init(nullptr); + //mcal::port::init(nullptr); + mcal::osc::init(nullptr); +} diff --git a/ref_app/src/mcal/rpi_pico2_rp2350/mcal_cpu.h b/ref_app/src/mcal/rpi_pico2_rp2350/mcal_cpu.h new file mode 100644 index 000000000..a8436728e --- /dev/null +++ b/ref_app/src/mcal/rpi_pico2_rp2350/mcal_cpu.h @@ -0,0 +1,26 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2007 - 2019. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#ifndef MCAL_CPU_2009_02_14_H_ + #define MCAL_CPU_2009_02_14_H_ + + #define MY_PROGMEM + + #include + #include + + namespace mcal { namespace cpu { + + void init(); + + inline void post_init() { } + + inline void nop() { asm volatile("nop"); } + + } } // namespace mcal::cpu + +#endif // MCAL_CPU_2009_02_14_H_ diff --git a/ref_app/src/mcal/rpi_pico2_rp2350/mcal_eep.cpp b/ref_app/src/mcal/rpi_pico2_rp2350/mcal_eep.cpp new file mode 100644 index 000000000..bdaf4cf89 --- /dev/null +++ b/ref_app/src/mcal/rpi_pico2_rp2350/mcal_eep.cpp @@ -0,0 +1,21 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2007 - 2022. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#include + +void mcal::eep::write(const address_type addr, const std::uint8_t data) +{ + static_cast(addr); + static_cast(data); +} + +std::uint8_t mcal::eep::read(const address_type addr) +{ + static_cast(addr); + + return std::uint8_t(0U); +} diff --git a/ref_app/src/mcal/rpi_pico2_rp2350/mcal_eep.h b/ref_app/src/mcal/rpi_pico2_rp2350/mcal_eep.h new file mode 100644 index 000000000..0cd43d875 --- /dev/null +++ b/ref_app/src/mcal/rpi_pico2_rp2350/mcal_eep.h @@ -0,0 +1,27 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2007 - 2022. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#ifndef MCAL_EEP_2018_12_15_H_ + #define MCAL_EEP_2018_12_15_H_ + + #include + + namespace mcal + { + namespace eep + { + using config_type = void; + using address_type = std::uint32_t; + + inline void init(const config_type*) { } + + void write(const address_type addr, const std::uint8_t data); + std::uint8_t read (const address_type addr); + } + } + +#endif // MCAL_EEP_2018_12_15_H_ diff --git a/ref_app/src/mcal/rpi_pico2_rp2350/mcal_gpt.cpp b/ref_app/src/mcal/rpi_pico2_rp2350/mcal_gpt.cpp new file mode 100644 index 000000000..437b6bb4b --- /dev/null +++ b/ref_app/src/mcal/rpi_pico2_rp2350/mcal_gpt.cpp @@ -0,0 +1,24 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2007 - 2023. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#include + +extern "C" +auto __sys_tick_handler(void) -> void +{ + using local_arm_sys_tick_type = ::mcal::gpt::arm_sys_tick_type; + using local_value_type = typename local_arm_sys_tick_type::value_type; + + // Increment the system tick (having 64-bits) with 0x01000000. + + local_arm_sys_tick_type::my_sys_tick_value = + static_cast + ( + local_arm_sys_tick_type::my_sys_tick_value + + static_cast(UINT32_C(0x01000000)) + ); +} diff --git a/ref_app/src/mcal/rpi_pico2_rp2350/mcal_gpt.h b/ref_app/src/mcal/rpi_pico2_rp2350/mcal_gpt.h new file mode 100644 index 000000000..4b366c60d --- /dev/null +++ b/ref_app/src/mcal/rpi_pico2_rp2350/mcal_gpt.h @@ -0,0 +1,58 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2007 - 2024. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#ifndef MCAL_GPT_2011_10_20_H + #define MCAL_GPT_2011_10_20_H + + #include + #include + + #include + + // Forward declaration of the util::timer template class. + namespace util + { + template + class timer; + } + + namespace mcal + { + namespace gpt + { + using arm_sys_tick_type = arm_sys_tick(UINT16_C(150))>; + + using config_type = void; + using value_type = typename arm_sys_tick_type::value_type; + + inline auto init(const config_type*) -> void; + + inline auto init(const config_type*) -> void + { + using local_arm_sys_tick_type = arm_sys_tick_type; + + local_arm_sys_tick_type::init(); + } + + class secure final + { + static auto get_time_elapsed() -> value_type + { + using local_arm_sys_tick_type = arm_sys_tick_type; + + return static_cast(local_arm_sys_tick_type::get_time_elapsed()); + } + + friend std::chrono::high_resolution_clock::time_point std::chrono::high_resolution_clock::now() noexcept; + + template + friend class util::timer; + }; + } + } + +#endif // MCAL_GPT_2011_10_20_H diff --git a/ref_app/src/mcal/rpi_pico2_rp2350/mcal_irq.cpp b/ref_app/src/mcal/rpi_pico2_rp2350/mcal_irq.cpp new file mode 100644 index 000000000..a0320023f --- /dev/null +++ b/ref_app/src/mcal/rpi_pico2_rp2350/mcal_irq.cpp @@ -0,0 +1,14 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2007 - 2020. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#include + +void mcal::irq::init(const config_type*) +{ + // Enable all global interrupts. + mcal::irq::enable_all(); +} diff --git a/ref_app/src/mcal/rpi_pico2_rp2350/mcal_irq.h b/ref_app/src/mcal/rpi_pico2_rp2350/mcal_irq.h new file mode 100644 index 000000000..08e861840 --- /dev/null +++ b/ref_app/src/mcal/rpi_pico2_rp2350/mcal_irq.h @@ -0,0 +1,23 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2007 - 2020. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#ifndef MCAL_IRQ_2010_04_10_H_ + #define MCAL_IRQ_2010_04_10_H_ + + namespace mcal + { + namespace irq + { + typedef void config_type; + void init(const config_type*); + + inline void enable_all () { asm volatile("cpsie i"); } + inline void disable_all() { asm volatile("cpsid i"); } + } + } + +#endif // MCAL_IRQ_2010_04_10_H_ diff --git a/ref_app/src/mcal/rpi_pico2_rp2350/mcal_led.cpp b/ref_app/src/mcal/rpi_pico2_rp2350/mcal_led.cpp new file mode 100644 index 000000000..3fd541241 --- /dev/null +++ b/ref_app/src/mcal/rpi_pico2_rp2350/mcal_led.cpp @@ -0,0 +1,44 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2007 - 2024. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#include + +#include +#include + +namespace mcal { namespace led { + +class led_port_green_25 : public mcal::led::led_boolean_state_base +{ +private: + using base_class_type = mcal::led::led_boolean_state_base; + +public: + led_port_green_25() + { + LED_GREEN_CFG(); + } + + auto toggle() -> void override + { + LED_GREEN_TOGGLE(); + + base_class_type::toggle(); + } +}; + +} // namespace led +} // namespace mcal + +mcal::led::led_base& mcal::led::led0() +{ + using led0_led_type = mcal::led::led_port_green_25; + + static led0_led_type l0; + + return l0; +} diff --git a/ref_app/src/mcal/rpi_pico2_rp2350/mcal_led.h b/ref_app/src/mcal/rpi_pico2_rp2350/mcal_led.h new file mode 100644 index 000000000..a52a8883b --- /dev/null +++ b/ref_app/src/mcal/rpi_pico2_rp2350/mcal_led.h @@ -0,0 +1,21 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2007 - 2020. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#ifndef MCAL_LED_2010_09_14_H_ + #define MCAL_LED_2010_09_14_H_ + + #include + + namespace mcal + { + namespace led + { + led_base& led0(); + } + } + +#endif // MCAL_LED_2010_09_14_H_ diff --git a/ref_app/src/mcal/rpi_pico2_rp2350/mcal_memory_progmem.h b/ref_app/src/mcal/rpi_pico2_rp2350/mcal_memory_progmem.h new file mode 100644 index 000000000..9668b68c4 --- /dev/null +++ b/ref_app/src/mcal/rpi_pico2_rp2350/mcal_memory_progmem.h @@ -0,0 +1,72 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2019 - 2020. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#ifndef MCAL_MEMORY_PROGMEM_2019_08_17_H_ + #define MCAL_MEMORY_PROGMEM_2019_08_17_H_ + + #include + + #define MY_PROGMEM + + #if defined(__cplusplus) + extern "C" + { + #endif + + typedef uintptr_t mcal_progmem_uintptr_t; + typedef ptrdiff_t mcal_progmem_ptrdiff_t; + + #define MCAL_PROGMEM_ADDRESSOF(x) ((mcal_progmem_uintptr_t) (&(x))) + + static inline uint8_t mcal_memory_progmem_read_byte(const mcal_progmem_uintptr_t src_addr) + { + return *(const uint8_t*) src_addr; + } + + static inline uint16_t mcal_memory_progmem_read_word(const mcal_progmem_uintptr_t src_addr) + { + uint16_t dest; + + *(((uint8_t*) &dest) + 0U) = *((const uint8_t*) (src_addr + 0U)); + *(((uint8_t*) &dest) + 1U) = *((const uint8_t*) (src_addr + 1U)); + + return dest; + } + + static inline uint32_t mcal_memory_progmem_read_dword(const mcal_progmem_uintptr_t src_addr) + { + uint32_t dest; + + *(((uint8_t*) &dest) + 0U) = *((const uint8_t*) (src_addr + 0U)); + *(((uint8_t*) &dest) + 1U) = *((const uint8_t*) (src_addr + 1U)); + *(((uint8_t*) &dest) + 2U) = *((const uint8_t*) (src_addr + 2U)); + *(((uint8_t*) &dest) + 3U) = *((const uint8_t*) (src_addr + 3U)); + + return dest; + } + + static inline uint64_t mcal_memory_progmem_read_qword(const mcal_progmem_uintptr_t src_addr) + { + uint64_t dest; + + *(((uint8_t*) &dest) + 0U) = *((const uint8_t*) (src_addr + 0U)); + *(((uint8_t*) &dest) + 1U) = *((const uint8_t*) (src_addr + 1U)); + *(((uint8_t*) &dest) + 2U) = *((const uint8_t*) (src_addr + 2U)); + *(((uint8_t*) &dest) + 3U) = *((const uint8_t*) (src_addr + 3U)); + *(((uint8_t*) &dest) + 4U) = *((const uint8_t*) (src_addr + 4U)); + *(((uint8_t*) &dest) + 5U) = *((const uint8_t*) (src_addr + 5U)); + *(((uint8_t*) &dest) + 6U) = *((const uint8_t*) (src_addr + 6U)); + *(((uint8_t*) &dest) + 7U) = *((const uint8_t*) (src_addr + 7U)); + + return dest; + } + + #if defined(__cplusplus) + } + #endif + +#endif // MCAL_MEMORY_PROGMEM_2019_08_17_H_ diff --git a/ref_app/src/mcal/rpi_pico2_rp2350/mcal_osc.cpp b/ref_app/src/mcal/rpi_pico2_rp2350/mcal_osc.cpp new file mode 100644 index 000000000..a78272ed3 --- /dev/null +++ b/ref_app/src/mcal/rpi_pico2_rp2350/mcal_osc.cpp @@ -0,0 +1,64 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2011 - 2024. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#include + +#include + +void mcal::osc::init(const config_type*) +{ + /* Init the clock XOSC */ + HW_PER_XOSC->STARTUP.bit.X4 = 0U; + HW_PER_XOSC->STARTUP.bit.DELAY = 47U; + HW_PER_XOSC->CTRL.bit.FREQ_RANGE = HW_PER_XOSC->STATUS.bit.FREQ_RANGE; + HW_PER_XOSC->CTRL.bit.ENABLE = XOSC_CTRL_ENABLE_ENABLE; + while(HW_PER_XOSC->STATUS.bit.STABLE != 1U); + + /* Switch the ref clock to use the xosc clock as source */ + HW_PER_CLOCKS->CLK_REF_CTRL.bit.SRC = CLOCKS_CLK_REF_CTRL_SRC_xosc_clksrc; + while(HW_PER_CLOCKS->CLK_REF_SELECTED.reg != (1ul << CLOCKS_CLK_REF_CTRL_SRC_xosc_clksrc)); + + while(HW_PER_CLOCKS->CLK_REF_DIV.bit.INT != 1); + + /* Release the reset of PLL_SYS */ + HW_PER_RESETS->RESET.bit.PLL_SYS = 0U; + while(HW_PER_RESETS->RESET_DONE.bit.PLL_SYS != 1); + + /* Configure the PLL_SYS */ + HW_PER_PLL_SYS->CS.bit.REFDIV = 1U; + HW_PER_PLL_SYS->FBDIV_INT.bit.FBDIV_INT = 125U; + HW_PER_PLL_SYS->PRIM.bit.POSTDIV1 = 5U; + HW_PER_PLL_SYS->PRIM.bit.POSTDIV2 = 2U; + + HW_PER_PLL_SYS->PWR.bit.PD = 0U; + HW_PER_PLL_SYS->PWR.bit.VCOPD = 0U; + HW_PER_PLL_SYS->PWR.bit.POSTDIVPD = 0U; + + while(HW_PER_PLL_SYS->CS.bit.LOCK != 1U); + + /* Switch the system clock to use the PLL */ + + if(HW_PER_CLOCKS->CLK_SYS_DIV.reg != 0x10000ul) + { + HW_PER_CLOCKS->CLK_SYS_DIV.reg = 0x10000ul; + } + + HW_PER_CLOCKS->CLK_SYS_CTRL.bit.AUXSRC = CLOCKS_CLK_SYS_CTRL_AUXSRC_clksrc_pll_sys; + HW_PER_CLOCKS->CLK_SYS_CTRL.bit.SRC = CLOCKS_CLK_SYS_CTRL_SRC_clksrc_clk_sys_aux; + + while(HW_PER_CLOCKS->CLK_SYS_SELECTED.bit.CLK_SYS_SELECTED != (1ul << CLOCKS_CLK_SYS_CTRL_SRC_clksrc_clk_sys_aux)); + + /* Enable clock for peripheral */ + HW_PER_CLOCKS->CLK_PERI_CTRL.bit.ENABLE = 1U; + + /* Release reset on IO_BANK0 */ + HW_PER_RESETS->RESET.bit.IO_BANK0 = 0U; + + /* Wait for reset to be done */ + /* Release reset is done on IO_BANK0 */ + while(HW_PER_RESETS->RESET_DONE.bit.IO_BANK0 != 1); +} diff --git a/ref_app/src/mcal/rpi_pico2_rp2350/mcal_osc.h b/ref_app/src/mcal/rpi_pico2_rp2350/mcal_osc.h new file mode 100644 index 000000000..95744b4ef --- /dev/null +++ b/ref_app/src/mcal/rpi_pico2_rp2350/mcal_osc.h @@ -0,0 +1,20 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2007 - 2020. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#ifndef MCAL_OSC_2011_10_20_H_ + #define MCAL_OSC_2011_10_20_H_ + + namespace mcal + { + namespace osc + { + typedef void config_type; + void init(const config_type*); + } + } + +#endif // MCAL_OSC_2011_10_20_H_ diff --git a/ref_app/src/mcal/rpi_pico2_rp2350/mcal_port.cpp b/ref_app/src/mcal/rpi_pico2_rp2350/mcal_port.cpp new file mode 100644 index 000000000..b6fdd3047 --- /dev/null +++ b/ref_app/src/mcal/rpi_pico2_rp2350/mcal_port.cpp @@ -0,0 +1,12 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2007 - 2024. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#include + +void mcal::port::init(const config_type*) +{ +} diff --git a/ref_app/src/mcal/rpi_pico2_rp2350/mcal_port.h b/ref_app/src/mcal/rpi_pico2_rp2350/mcal_port.h new file mode 100644 index 000000000..1d6cadda6 --- /dev/null +++ b/ref_app/src/mcal/rpi_pico2_rp2350/mcal_port.h @@ -0,0 +1,55 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2007 - 2024. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#ifndef MCAL_PORT_2012_06_27_H_ + #define MCAL_PORT_2012_06_27_H_ + + #include + + #include + + namespace mcal + { + namespace port + { + typedef void config_type; + void init(const config_type*); + + template + class port_pin + { + public: + static void set_direction_output() + { + // SIO Structure: Line 27173 + } + + static void set_direction_input() + { + } + + static void set_pin_high() + { + } + + static void set_pin_low() + { + } + + static bool read_input_value() + { + return false; + } + + static void toggle_pin() + { + } + }; + } + } + +#endif // MCAL_PORT_2012_06_27_H_ diff --git a/ref_app/src/mcal/rpi_pico2_rp2350/mcal_pwm.cpp b/ref_app/src/mcal/rpi_pico2_rp2350/mcal_pwm.cpp new file mode 100644 index 000000000..7f24024db --- /dev/null +++ b/ref_app/src/mcal/rpi_pico2_rp2350/mcal_pwm.cpp @@ -0,0 +1,20 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2007 - 2020. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#include +#include + +mcal::pwm::pwm_base& mcal::pwm::pwm0() noexcept +{ + static mcal::pwm::pwm_dummy pwm; + + static const volatile bool init_is_ok = pwm.init(); + + static_cast(init_is_ok); + + return pwm; +} diff --git a/ref_app/src/mcal/rpi_pico2_rp2350/mcal_pwm.h b/ref_app/src/mcal/rpi_pico2_rp2350/mcal_pwm.h new file mode 100644 index 000000000..cd7a4ddc3 --- /dev/null +++ b/ref_app/src/mcal/rpi_pico2_rp2350/mcal_pwm.h @@ -0,0 +1,25 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2007 - 2020. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#ifndef MCAL_PWM_2010_09_14_H_ + #define MCAL_PWM_2010_09_14_H_ + + #include + + namespace mcal + { + namespace pwm + { + typedef void config_type; + + inline void init(const config_type*) { } + + mcal::pwm::pwm_base& pwm0() noexcept; + } + } + +#endif // MCAL_PWM_2010_09_14_H_ diff --git a/ref_app/src/mcal/rpi_pico2_rp2350/mcal_reg.h b/ref_app/src/mcal/rpi_pico2_rp2350/mcal_reg.h new file mode 100644 index 000000000..0acdec4e4 --- /dev/null +++ b/ref_app/src/mcal/rpi_pico2_rp2350/mcal_reg.h @@ -0,0 +1,35 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2007 - 2024. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#ifndef MCAL_REG_2010_04_10_H + #define MCAL_REG_2010_04_10_H + + #include + + namespace mcal + { + namespace reg + { + // Single-instruction registers. + constexpr std::uint32_t sio_base { UINT32_C(0xD0000000) }; + constexpr std::uint32_t sio_cpuid { sio_base + UINT32_C(0x00000000) }; + constexpr std::uint32_t sio_gpio_out_set { sio_base + UINT32_C(0x00000018) }; + constexpr std::uint32_t sio_gpio_out_clr { sio_base + UINT32_C(0x00000020) }; + constexpr std::uint32_t sio_gpio_out_xor { sio_base + UINT32_C(0x00000028) }; + constexpr std::uint32_t sio_gpio_oe_set { sio_base + UINT32_C(0x00000038) }; + constexpr std::uint32_t sio_gpio_oe_clr { sio_base + UINT32_C(0x00000040) }; + + // I/O-Bank registers. + constexpr std::uint32_t io_bank0_base { UINT32_C(0x40028000) }; + constexpr std::uint32_t io_bank0_status_base { io_bank0_base + UINT32_C(0x00000000) }; + } + } + + #include + #include + +#endif // MCAL_REG_2010_04_10_H diff --git a/ref_app/src/mcal/rpi_pico2_rp2350/mcal_ser.h b/ref_app/src/mcal/rpi_pico2_rp2350/mcal_ser.h new file mode 100644 index 000000000..80f1cf011 --- /dev/null +++ b/ref_app/src/mcal/rpi_pico2_rp2350/mcal_ser.h @@ -0,0 +1,21 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2007 - 2020. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#ifndef MCAL_SER_2011_10_20_H_ + #define MCAL_SER_2011_10_20_H_ + + namespace mcal + { + namespace ser + { + typedef void config_type; + + inline void init(const config_type*) { } + } + } + +#endif // MCAL_SER_2011_10_20_H_ diff --git a/ref_app/src/mcal/rpi_pico2_rp2350/mcal_spi.cpp b/ref_app/src/mcal/rpi_pico2_rp2350/mcal_spi.cpp new file mode 100644 index 000000000..a2fa4b7f9 --- /dev/null +++ b/ref_app/src/mcal/rpi_pico2_rp2350/mcal_spi.cpp @@ -0,0 +1,21 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2012 - 2020. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#include + +#include + +void mcal::spi::init(const mcal::spi::config_type*) +{ +} + +util::communication_base& mcal::spi::spi0() +{ + static mcal::spi::spi_software_dummy com; + + return com; +} diff --git a/ref_app/src/mcal/rpi_pico2_rp2350/mcal_spi.h b/ref_app/src/mcal/rpi_pico2_rp2350/mcal_spi.h new file mode 100644 index 000000000..300ec4577 --- /dev/null +++ b/ref_app/src/mcal/rpi_pico2_rp2350/mcal_spi.h @@ -0,0 +1,23 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2012 - 2020. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#ifndef MCAL_SPI_2012_05_24_H_ + #define MCAL_SPI_2012_05_24_H_ + + #include + + namespace mcal { namespace spi { + + typedef void config_type; + + void init(const config_type*); + + extern util::communication_base& spi0(); + + } } + +#endif // MCAL_SPI_2012_05_24_H_ diff --git a/ref_app/src/mcal/rpi_pico2_rp2350/mcal_wdg.cpp b/ref_app/src/mcal/rpi_pico2_rp2350/mcal_wdg.cpp new file mode 100644 index 000000000..d30e8b405 --- /dev/null +++ b/ref_app/src/mcal/rpi_pico2_rp2350/mcal_wdg.cpp @@ -0,0 +1,16 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2007 - 2024. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#include + +void mcal::wdg::init(const config_type*) +{ +} + +void mcal::wdg::secure::trigger() +{ +} diff --git a/ref_app/src/mcal/rpi_pico2_rp2350/mcal_wdg.h b/ref_app/src/mcal/rpi_pico2_rp2350/mcal_wdg.h new file mode 100644 index 000000000..817769d13 --- /dev/null +++ b/ref_app/src/mcal/rpi_pico2_rp2350/mcal_wdg.h @@ -0,0 +1,26 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2007 - 2024. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#ifndef MCAL_WDG_2010_04_10_H + #define MCAL_WDG_2010_04_10_H + + namespace mcal + { + namespace wdg + { + typedef void config_type; + + void init(const config_type*); + + struct secure final + { + static void trigger(); + }; + } + } + +#endif // MCAL_WDG_2010_04_10_H diff --git a/ref_app/src/mcal/rpi_pico_rp2040/mcal_gpt.cpp b/ref_app/src/mcal/rpi_pico_rp2040/mcal_gpt.cpp index 541d68828..cbcafa079 100644 --- a/ref_app/src/mcal/rpi_pico_rp2040/mcal_gpt.cpp +++ b/ref_app/src/mcal/rpi_pico_rp2040/mcal_gpt.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2007 - 2023. +// Copyright Christopher Kormanyos 2007 - 2024. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -8,7 +8,7 @@ #include extern "C" -auto __sys_tick_handler(void) noexcept -> void +auto __sys_tick_handler(void) -> void { using local_arm_sys_tick_type = ::mcal::gpt::arm_sys_tick_type; using local_value_type = typename local_arm_sys_tick_type::value_type; diff --git a/ref_app/src/mcal/rpi_pico_rp2040/mcal_osc.cpp b/ref_app/src/mcal/rpi_pico_rp2040/mcal_osc.cpp index 7ef9bf96b..10e34df33 100644 --- a/ref_app/src/mcal/rpi_pico_rp2040/mcal_osc.cpp +++ b/ref_app/src/mcal/rpi_pico_rp2040/mcal_osc.cpp @@ -17,119 +17,119 @@ void mcal::osc::init(const config_type*) mcal::reg::reg_access_static::bit_set(); + std::uint32_t { UINT32_C(20) }>::bit_set(); // XOSC->STARTUP.bit.DELAY = 47U; mcal::reg::reg_access_static::template reg_msk(); + std::uint32_t { UINT32_C(47) }>::template reg_msk(); // XOSC->CTRL.bit.FREQ_RANGE = XOSC_CTRL_FREQ_RANGE_1_15MHZ; mcal::reg::reg_access_static::template reg_msk(); + std::uint32_t { UINT32_C(2720) }>::template reg_msk(); // XOSC->CTRL.bit.ENABLE = XOSC_CTRL_ENABLE_ENABLE; mcal::reg::reg_access_static::template reg_msk(); + std::uint32_t { UINT32_C(4011) << 12U }>::template reg_msk(); // while(XOSC->STATUS.bit.STABLE != 1U); while(!mcal::reg::reg_access_static::bit_get()) { mcal::cpu::nop(); } + std::uint32_t { UINT32_C(31) }>::bit_get()) { mcal::cpu::nop(); } // Release the reset of PLL_SYS // RESETS->RESET.bit.pll_sys = 0U; mcal::reg::reg_access_static::bit_clr(); + std::uint32_t { UINT32_C(12) }>::bit_clr(); // while(RESETS->RESET_DONE.bit.pll_sys != 1); while(!mcal::reg::reg_access_static::bit_get()) { mcal::cpu::nop(); } + std::uint32_t { UINT32_C(12) }>::bit_get()) { mcal::cpu::nop(); } // Configure the PLL_SYS. // PLL_SYS->CS.bit.REFDIV = 1U; mcal::reg::reg_access_static::template reg_msk(); + std::uint32_t { UINT32_C(1) }>::template reg_msk(); // PLL_SYS->FBDIV_INT.bit.FBDIV_INT = 133U; mcal::reg::reg_access_static::template reg_msk(); + std::uint32_t { UINT32_C(133) }>::template reg_msk(); // PLL_SYS->PRIM.bit.POSTDIV1 = 6U; mcal::reg::reg_access_static::template reg_msk(); + std::uint32_t { UINT32_C(6) << 16U }>::template reg_msk(); // PLL_SYS->PRIM.bit.POSTDIV2 = 2U; mcal::reg::reg_access_static::template reg_msk(); + std::uint32_t { UINT32_C(2) << 12U }>::template reg_msk(); // PLL_SYS->PWR.bit.PD = 0U; mcal::reg::reg_access_static::bit_clr(); + std::uint32_t { UINT32_C(0) }>::bit_clr(); // PLL_SYS->PWR.bit.VCOPD = 0U; mcal::reg::reg_access_static::bit_clr(); + std::uint32_t { UINT32_C(5) }>::bit_clr(); // while(PLL_SYS->CS.bit.LOCK != 1U); while(!mcal::reg::reg_access_static::bit_get()) { mcal::cpu::nop(); } + std::uint32_t { UINT32_C(31) }>::bit_get()) { mcal::cpu::nop(); } // PLL_SYS->PWR.bit.POSTDIVPD = 0U; mcal::reg::reg_access_static::bit_clr(); + std::uint32_t { UINT32_C(3) }>::bit_clr(); // Switch the system clock to use the PLL. // CLOCKS->CLK_SYS_CTRL.bit.AUXSRC = CLOCKS_CLK_SYS_CTRL_AUXSRC_clksrc_pll_sys; mcal::reg::reg_access_static::template reg_msk(); + std::uint32_t { UINT32_C(0) << 5U }>::template reg_msk(); // CLOCKS->CLK_SYS_CTRL.bit.SRC = CLOCKS_CLK_SYS_CTRL_SRC_clksrc_clk_sys_aux; mcal::reg::reg_access_static::bit_set(); + std::uint32_t { UINT32_C(0) }>::bit_set(); // CLOCKS->CLK_SYS_DIV.bit.INT = 1U; mcal::reg::reg_access_static::template reg_msk(); + std::uint32_t { UINT32_C(1) << 8U }>::template reg_msk(); // CLOCKS->CLK_SYS_DIV.bit.FRAC = 0U; mcal::reg::reg_access_static::template reg_msk(); + std::uint32_t { UINT32_C(0) << 0U }>::template reg_msk(); // while(CLOCKS->CLK_SYS_SELECTED == 0UL); while(mcal::reg::reg_access_static::bit_set(); + std::uint32_t { UINT32_C(11) }>::bit_set(); // Release reset on IO_BANK0. // RESETS->RESET.bit.io_bank0 = 0U; mcal::reg::reg_access_static::bit_clr(); + std::uint32_t { UINT32_C(5) }>::bit_clr(); // Wait for reset to be done. // Release reset is done on IO_BANK0. @@ -160,5 +160,5 @@ void mcal::osc::init(const config_type*) while(!mcal::reg::reg_access_static::bit_get()) { mcal::cpu::nop(); } + std::uint32_t { UINT32_C(5) }>::bit_get()) { mcal::cpu::nop(); } } diff --git a/ref_app/src/mcal/rpi_pico_rp2040/mcal_port.h b/ref_app/src/mcal/rpi_pico_rp2040/mcal_port.h index fe26fc300..a7af21b2d 100644 --- a/ref_app/src/mcal/rpi_pico_rp2040/mcal_port.h +++ b/ref_app/src/mcal/rpi_pico_rp2040/mcal_port.h @@ -23,17 +23,9 @@ class port_pin { private: - static constexpr std::uint32_t spi1_ss_n { UINT32_C( 1) }; // spi1_ss_n : spi1_ss_n - static constexpr std::uint32_t uart1_rx { UINT32_C( 2) }; // uart1_rx : uart1_rx - static constexpr std::uint32_t i2c0_scl { UINT32_C( 3) }; // i2c0_scl : i2c0_scl - static constexpr std::uint32_t pwm_b_4 { UINT32_C( 4) }; // pwm_b_4 : pwm_b_4 static constexpr std::uint32_t sio_xx { UINT32_C( 5) }; // sio_xx : sio_xx static constexpr std::uint32_t pio0_xx { UINT32_C( 6) }; // pio0_xx : pio0_xx static constexpr std::uint32_t pio1_xx { UINT32_C( 7) }; // pio1_xx : pio1_xx - static constexpr std::uint32_t clocks_gpout_3 { UINT32_C( 8) }; // clocks_gpout_3 : clocks_gpout_3 - static constexpr std::uint32_t usb_muxing_vbus_detect { UINT32_C( 9) }; // usb_muxing_vbus_detect : usb_muxing_vbus_detect - static constexpr std::uint32_t null { UINT32_C(31) }; // null : null - static constexpr std::uint32_t port_index { PortIndex }; static constexpr std::uint32_t addr_io_bank0_gpio_pin_ctrl { mcal::reg::io_bank0_status_base + std::uint32_t { port_index * 8U + 4U } }; diff --git a/ref_app/src/mcal/rpi_pico_rp2040/mcal_wdg.cpp b/ref_app/src/mcal/rpi_pico_rp2040/mcal_wdg.cpp index 5d1272fae..d30e8b405 100644 --- a/ref_app/src/mcal/rpi_pico_rp2040/mcal_wdg.cpp +++ b/ref_app/src/mcal/rpi_pico_rp2040/mcal_wdg.cpp @@ -6,7 +6,6 @@ // #include -#include void mcal::wdg::init(const config_type*) { diff --git a/ref_app/src/mcal/stm32f100/mcal_gpt.cpp b/ref_app/src/mcal/stm32f100/mcal_gpt.cpp index bc1998603..e20d569db 100644 --- a/ref_app/src/mcal/stm32f100/mcal_gpt.cpp +++ b/ref_app/src/mcal/stm32f100/mcal_gpt.cpp @@ -8,7 +8,7 @@ #include extern "C" -auto __sys_tick_handler(void) noexcept -> void +auto __sys_tick_handler(void) -> void { using local_arm_sys_tick_type = ::mcal::gpt::arm_sys_tick_type; using local_value_type = typename local_arm_sys_tick_type::value_type; diff --git a/ref_app/src/mcal/stm32f407/mcal_gpt.cpp b/ref_app/src/mcal/stm32f407/mcal_gpt.cpp index bc1998603..e20d569db 100644 --- a/ref_app/src/mcal/stm32f407/mcal_gpt.cpp +++ b/ref_app/src/mcal/stm32f407/mcal_gpt.cpp @@ -8,7 +8,7 @@ #include extern "C" -auto __sys_tick_handler(void) noexcept -> void +auto __sys_tick_handler(void) -> void { using local_arm_sys_tick_type = ::mcal::gpt::arm_sys_tick_type; using local_value_type = typename local_arm_sys_tick_type::value_type; diff --git a/ref_app/src/mcal/stm32f429/mcal_gpt.cpp b/ref_app/src/mcal/stm32f429/mcal_gpt.cpp index bc1998603..e20d569db 100644 --- a/ref_app/src/mcal/stm32f429/mcal_gpt.cpp +++ b/ref_app/src/mcal/stm32f429/mcal_gpt.cpp @@ -8,7 +8,7 @@ #include extern "C" -auto __sys_tick_handler(void) noexcept -> void +auto __sys_tick_handler(void) -> void { using local_arm_sys_tick_type = ::mcal::gpt::arm_sys_tick_type; using local_value_type = typename local_arm_sys_tick_type::value_type; diff --git a/ref_app/src/mcal/stm32f446/mcal_gpt.cpp b/ref_app/src/mcal/stm32f446/mcal_gpt.cpp index 541d68828..437b6bb4b 100644 --- a/ref_app/src/mcal/stm32f446/mcal_gpt.cpp +++ b/ref_app/src/mcal/stm32f446/mcal_gpt.cpp @@ -8,7 +8,7 @@ #include extern "C" -auto __sys_tick_handler(void) noexcept -> void +auto __sys_tick_handler(void) -> void { using local_arm_sys_tick_type = ::mcal::gpt::arm_sys_tick_type; using local_value_type = typename local_arm_sys_tick_type::value_type; diff --git a/ref_app/src/mcal/stm32h7a3/mcal_gpt.cpp b/ref_app/src/mcal/stm32h7a3/mcal_gpt.cpp index 541d68828..437b6bb4b 100644 --- a/ref_app/src/mcal/stm32h7a3/mcal_gpt.cpp +++ b/ref_app/src/mcal/stm32h7a3/mcal_gpt.cpp @@ -8,7 +8,7 @@ #include extern "C" -auto __sys_tick_handler(void) noexcept -> void +auto __sys_tick_handler(void) -> void { using local_arm_sys_tick_type = ::mcal::gpt::arm_sys_tick_type; using local_value_type = typename local_arm_sys_tick_type::value_type; diff --git a/ref_app/src/mcal/stm32l100c/mcal_gpt.cpp b/ref_app/src/mcal/stm32l100c/mcal_gpt.cpp index 541d68828..437b6bb4b 100644 --- a/ref_app/src/mcal/stm32l100c/mcal_gpt.cpp +++ b/ref_app/src/mcal/stm32l100c/mcal_gpt.cpp @@ -8,7 +8,7 @@ #include extern "C" -auto __sys_tick_handler(void) noexcept -> void +auto __sys_tick_handler(void) -> void { using local_arm_sys_tick_type = ::mcal::gpt::arm_sys_tick_type; using local_value_type = typename local_arm_sys_tick_type::value_type; diff --git a/ref_app/src/mcal/stm32l432/mcal_gpt.cpp b/ref_app/src/mcal/stm32l432/mcal_gpt.cpp index 8b0fab095..cbcafa079 100644 --- a/ref_app/src/mcal/stm32l432/mcal_gpt.cpp +++ b/ref_app/src/mcal/stm32l432/mcal_gpt.cpp @@ -8,7 +8,7 @@ #include extern "C" -auto __sys_tick_handler(void) noexcept -> void +auto __sys_tick_handler(void) -> void { using local_arm_sys_tick_type = ::mcal::gpt::arm_sys_tick_type; using local_value_type = typename local_arm_sys_tick_type::value_type; diff --git a/ref_app/src/util/STL/cstdbool b/ref_app/src/util/STL/cstdbool index d752d529d..79bb86ad6 100644 --- a/ref_app/src/util/STL/cstdbool +++ b/ref_app/src/util/STL/cstdbool @@ -8,15 +8,18 @@ #ifndef CSTDBOOL_2012_12_14_ #define CSTDBOOL_2012_12_14_ - #include + #if (!defined(__cplusplus) && !defined(__bool_true_false_are_defined)) + + #define bool _Bool + #define false 0 + #define true 1 + + #define __bool_true_false_are_defined 1 + + #endif #if !defined(__bool_true_false_are_defined) #define __bool_true_false_are_defined 1 #endif - namespace std - { - using ::bool; - } - #endif // CSTDBOOL_2012_12_14_ diff --git a/ref_app/target.vcxproj b/ref_app/target.vcxproj index 52f1efbe6..f8b004e51 100644 --- a/ref_app/target.vcxproj +++ b/ref_app/target.vcxproj @@ -904,7 +904,7 @@ - + @@ -1010,11 +1010,12 @@ - - - - - + + + + + + @@ -1076,7 +1077,6 @@ - diff --git a/ref_app/target.vcxproj.filters b/ref_app/target.vcxproj.filters index ad1c601d0..affde59f6 100644 --- a/ref_app/target.vcxproj.filters +++ b/ref_app/target.vcxproj.filters @@ -259,24 +259,15 @@ {6e60b74b-286f-4cd0-a99e-75ae6bb76af8} - - {66796a1a-dbfb-41d7-b5fa-0226f8a52cde} - - - {8c5a07af-8670-4a05-ad94-771c344e97e8} - - - {7fd0772a-f2d2-4eb4-832f-f32f0bc0cae9} - {451ca947-56ce-46cf-a4e8-036c75f8b86a} - - {8f7c20e8-9cec-4cf8-b3b5-48ce200d6733} - {6be8f2e8-8491-442a-9308-13667c843931} + + {66796a1a-dbfb-41d7-b5fa-0226f8a52cde} + @@ -612,9 +603,6 @@ micros\stm32l432\make - - micros\rpi_pico2_rp2350\Startup\Core\ARM - micros\rpi_pico2_rp2350\make @@ -624,6 +612,9 @@ micros\rpi_pico2_rp2350\make + + micros\rpi_pico2_rp2350\startup + @@ -896,20 +887,23 @@ micros\stm32l432\startup - - micros\rpi_pico2_rp2350\Startup + + micros\rpi_pico2_rp2350\startup - - micros\rpi_pico2_rp2350\Startup\Core\ARM + + micros\rpi_pico2_rp2350\startup - - micros\rpi_pico2_rp2350\Startup\Core\ARM + + micros\rpi_pico2_rp2350\startup - - micros\rpi_pico2_rp2350\Appli + + micros\rpi_pico2_rp2350\startup - - micros\rpi_pico2_rp2350\Startup\Core\ARM + + micros\rpi_pico2_rp2350\startup + + + micros\rpi_pico2_rp2350\startup @@ -918,9 +912,6 @@ - - micros\rpi_pico2_rp2350\Startup\Core\ARM - micros\rpi_pico2_rp2350\Std diff --git a/ref_app/target/app/make/app_rules.gmk b/ref_app/target/app/make/app_rules.gmk index d76505a1f..7674bacac 100644 --- a/ref_app/target/app/make/app_rules.gmk +++ b/ref_app/target/app/make/app_rules.gmk @@ -22,7 +22,7 @@ # GCC dependency flags. # ------------------------------------------------------------------------------ -DEP_FLAGS = -MMD -MF $(PATH_OBJ)/$(basename $(@F)).d +DEP_FLAGS := -MMD -MF $(PATH_OBJ)/$(basename $(@F)).d # ------------------------------------------------------------------------------ diff --git a/ref_app/target/micros/rpi_pico2_rp2350/Appli/main.c b/ref_app/target/micros/rpi_pico2_rp2350/Appli/main.c deleted file mode 100644 index 5eacd801f..000000000 --- a/ref_app/target/micros/rpi_pico2_rp2350/Appli/main.c +++ /dev/null @@ -1,217 +0,0 @@ -/****************************************************************************************** - Filename : main.c - - Core : ARM Cortex-M33 / RISC-V Hazard3 - - MCU : RP2350 - - Author : Chalandi Amine - - Owner : Chalandi Amine - - Date : 04.09.2024 - - Description : Application main function - -******************************************************************************************/ - -//============================================================================= -// Includes -//============================================================================= -#include "Platform_Types.h" -#include "Cpu.h" -#include "Gpio.h" -#include "SysTickTimer.h" - -#include - -//============================================================================= -// Macros -//============================================================================= - -//============================================================================= -// Prototypes -//============================================================================= -void main_Core0(void); -void main_Core1(void); -void BlockingDelay(uint32 delay); - -//============================================================================= -// Globals -//============================================================================= -#ifdef DEBUG - volatile boolean boHaltCore0 = TRUE; - volatile boolean boHaltCore1 = TRUE; -#endif - -//----------------------------------------------------------------------------------------- -/// \brief main function -/// -/// \param void -/// -/// \return void -//----------------------------------------------------------------------------------------- -int main(void) -{ - /* Run the main function of the core 0, it will start the core 1 */ - main_Core0(); - - /* Synchronize with core 1 */ - RP2350_MulticoreSync((uint32_t)HW_PER_SIO->CPUID.reg); - - /* endless loop on the core 0 */ - for(;;); - - /* never reached */ - return(0); -} - -//----------------------------------------------------------------------------------------- -/// \brief main_Core0 function -/// -/// \param void -/// -/// \return void -//----------------------------------------------------------------------------------------- -void main_Core0(void) -{ -#ifdef DEBUG - while(boHaltCore0); -#endif - -#ifdef CORE_FAMILY_ARM - /* Disable interrupts on core 0 */ - __asm volatile("CPSID i"); -#endif - - /* Output disable on pin 25 */ - LED_GREEN_CFG(); - - - /* Start the Core 1 and turn on the led to be sure that we passed successfully the core 1 initiaization */ - if(TRUE == RP2350_StartCore1()) - { - LED_GREEN_ON(); - } - else - { - /* Loop forever in case of error */ - while(1) - { - __asm volatile("NOP"); - } - } - -} - -//----------------------------------------------------------------------------------------- -/// \brief main_Core1 function -/// -/// \param void -/// -/// \return void -//----------------------------------------------------------------------------------------- -#if defined(__GNUC__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wcast-align" -#endif - -volatile uint64_t* pMTIMECMP = (volatile uint64_t*)&(HW_PER_SIO->MTIMECMP.reg); -volatile uint64_t* pMTIME = (volatile uint64_t*)&(HW_PER_SIO->MTIME.reg); - -#if defined(__GNUC__) -#pragma GCC diagnostic pop -#endif - -extern void core_1_run_flag_set(bool); - -void main_Core1(void) -{ -#ifdef DEBUG - while(boHaltCore1); -#endif - - core_1_run_flag_set(true); - - /* Note: Core 1 is started with interrupt enabled by the BootRom */ - - /* Clear the stiky bits of the FIFO_ST on core 1 */ - HW_PER_SIO->FIFO_ST.reg = 0xFFu; - -#ifdef CORE_FAMILY_ARM - - /*Setting EXTEXCLALL allows external exclusive operations to be used in a configuration with no MPU. - This is because the default memory map does not include any shareable Normal memory.*/ - SCnSCB->ACTLR |= (1ul<<29); - - __asm volatile("DSB"); - - /* Clear all pending interrupts on core 1 */ - NVIC->ICPR[0] = (uint32)-1; - -#endif - - /* Synchronize with core 0 */ - RP2350_MulticoreSync((uint32_t)HW_PER_SIO->CPUID.reg); - - -#ifdef CORE_FAMILY_RISC_V - - /* configure the machine timer for 1Hz interrupt window */ - #include "riscv.h" - - /* enable machine timer interrupt */ - riscv_set_csr(RVCSR_MIE_OFFSET, 0x80ul); - - /* enable global interrupt */ - riscv_set_csr(RVCSR_MSTATUS_OFFSET, 0x08ul); - - /* configure machine timer to use 150 MHz */ - HW_PER_SIO->MTIME_CTRL.bit.FULLSPEED = 1; - - /* set next timeout (machine timer is enabled by default) */ - *pMTIMECMP = *pMTIME + 150000000ul; //1s - -#else - - /* configure ARM systick timer */ - SysTickTimer_Init(); - SysTickTimer_Start(SYS_TICK_MS(100)); - -#endif - - while(1) - { - __asm("nop"); - } -} - - -#ifdef CORE_FAMILY_RISC_V - __attribute__((interrupt)) void Isr_MachineTimerInterrupt(void); - - void Isr_MachineTimerInterrupt(void) - { - *pMTIMECMP = *pMTIME + 150000000ul; - - LED_GREEN_TOGGLE(); - } - -#else - - void SysTickTimer(void); - - void SysTickTimer(void) - { - static uint32_t cpt = 0; - - SysTickTimer_Reload(SYS_TICK_MS(100)); - - if(++cpt >= 10ul) - { - LED_GREEN_TOGGLE(); - cpt = 0; - } - } -#endif - diff --git a/ref_app/target/micros/rpi_pico2_rp2350/Startup/Core/ARM/core_arch.h b/ref_app/target/micros/rpi_pico2_rp2350/Startup/Core/ARM/core_arch.h deleted file mode 100644 index fbdfda840..000000000 --- a/ref_app/target/micros/rpi_pico2_rp2350/Startup/Core/ARM/core_arch.h +++ /dev/null @@ -1,28 +0,0 @@ -/****************************************************************************************** - Filename : core_arch.h - - Core : ARM Cortex-M33 - - MCU : RP2350 - - Author : Chalandi Amine - - Owner : Chalandi Amine - - Date : 29.08.2024 - - Description : ARM macros for Raspberry Pi Pico 2 - -******************************************************************************************/ - -#ifndef __CORE_ARCH_H__ -#define __CORE_ARCH_H__ - -#define CORE_ARCH_SEND_EVENT_INST() __asm("SEV") -#define CORE_ARCH_DISABLE_INTERRUPTS() __asm("CPSID i") -#define CORE_ARCH_ENABLE_INTERRUPTS() __asm("CPSIE i") - -void arch_spin_lock (uint32* lock); -void arch_spin_unlock(uint32* lock); - -#endif //__CORE_ARCH_H__ diff --git a/ref_app/target/micros/rpi_pico2_rp2350/Startup/Startup.c b/ref_app/target/micros/rpi_pico2_rp2350/Startup/Startup.c deleted file mode 100644 index 78212065f..000000000 --- a/ref_app/target/micros/rpi_pico2_rp2350/Startup/Startup.c +++ /dev/null @@ -1,205 +0,0 @@ -// *************************************************************************************** -// Filename : Startup.c -// -// Author : Chalandi Amine -// -// Owner : Chalandi Amine -// -// Date : 04.09.2024 -// -// Description : C/C++ Runtime Setup (Crt0) -// -// *************************************************************************************** - -//========================================================================================= -// types definitions -//========================================================================================= -typedef struct -{ - unsigned long sourceAddr; /* Source Address (section in ROM memory) */ - unsigned long targetAddr; /* Target Address (section in RAM memory) */ - unsigned long size; /* length of section (bytes) */ -} runtimeCopyTable_t; - -typedef struct -{ - unsigned long Addr; /* source Address (section in RAM memory) */ - unsigned long size; /* length of section (bytes) */ -} runtimeClearTable_t; - -//========================================================================================= -// linker variables -//========================================================================================= -extern const runtimeCopyTable_t __RUNTIME_COPY_TABLE[]; -extern const runtimeClearTable_t __RUNTIME_CLEAR_TABLE[]; -extern unsigned long __CPPCTOR_LIST__[]; - -//========================================================================================= -// defines -//========================================================================================= -#define __STARTUP_RUNTIME_COPYTABLE (runtimeCopyTable_t*)(&__RUNTIME_COPY_TABLE[0]) -#define __STARTUP_RUNTIME_CLEARTABLE (runtimeClearTable_t*)(&__RUNTIME_CLEAR_TABLE[0]) -#define __STARTUP_RUNTIME_CTORS (unsigned long*)(&__CPPCTOR_LIST__[0]) - -//========================================================================================= -// function prototype -//========================================================================================= -void Startup_Init(void) __attribute__((used)); -static void Startup_InitRam(void); -static void Startup_InitCtors(void); -static void Startup_RunApplication(void); -static void Startup_Unexpected_Exit(void); -static void Startup_InitSystemClock(void); -static void Startup_InitCore(void); -//========================================================================================= -// extern function prototype -//========================================================================================= -int main(void); -void RP2350_ClockInit(void) __attribute__((weak)); -void RP2350_InitCore(void) __attribute__((weak)); - -//========================================================================================= -// macros -//========================================================================================= -#define ENABLE_IRQ() __asm("CPSIE i") -#define DISABLE_IRQ() __asm("CPSID i") - -//----------------------------------------------------------------------------------------- -/// \brief Startup_Init function -/// -/// \param void -/// -/// \return void -//----------------------------------------------------------------------------------------- -void Startup_Init(void) -{ - /* Initialize the CPU Core */ - Startup_InitCore(); - - /* Configure the system clock */ - Startup_InitSystemClock(); - - /* Initialize the RAM memory */ - Startup_InitRam(); - - /* Initialize the non-local C++ objects */ - Startup_InitCtors(); - - /* Start the application */ - Startup_RunApplication(); -} - - -//----------------------------------------------------------------------------------------- -/// \brief Startup_InitRam function -/// -/// \param void -/// -/// \return void -//----------------------------------------------------------------------------------------- -static void Startup_InitRam(void) -{ - unsigned long ClearTableIdx = 0; - unsigned long CopyTableIdx = 0; - - /* Clear Table */ - - while((__STARTUP_RUNTIME_CLEARTABLE)[ClearTableIdx].Addr != (unsigned long)-1 && (__STARTUP_RUNTIME_CLEARTABLE)[ClearTableIdx].size != (unsigned long)-1) - { - for(unsigned int cpt = 0; cpt < (__STARTUP_RUNTIME_CLEARTABLE)[ClearTableIdx].size; cpt++) - { - *(volatile unsigned char*)((unsigned long)((__STARTUP_RUNTIME_CLEARTABLE)[ClearTableIdx].Addr) + cpt) = 0; - } - - ClearTableIdx++; - } - - /* Copy Table */ - - while((__STARTUP_RUNTIME_COPYTABLE)[CopyTableIdx].sourceAddr != (unsigned long)-1 && - (__STARTUP_RUNTIME_COPYTABLE)[CopyTableIdx].targetAddr != (unsigned long)-1 && - (__STARTUP_RUNTIME_COPYTABLE)[CopyTableIdx].size != (unsigned long)-1 - ) - { - for(unsigned int cpt = 0; cpt < (__STARTUP_RUNTIME_COPYTABLE)[CopyTableIdx].size; cpt++) - { - *(volatile unsigned char*)((unsigned long)((__STARTUP_RUNTIME_COPYTABLE)[CopyTableIdx].targetAddr) + cpt) = - *(volatile unsigned char*)((unsigned long)((__STARTUP_RUNTIME_COPYTABLE)[CopyTableIdx].sourceAddr) + cpt); - } - - CopyTableIdx++; - } -} - -//----------------------------------------------------------------------------------------- -/// \brief Startup_InitCtors function -/// -/// \param void -/// -/// \return void -//----------------------------------------------------------------------------------------- -static void Startup_InitCtors(void) -{ - unsigned long CtorIdx = 0U; - - while((__STARTUP_RUNTIME_CTORS)[CtorIdx] != ((unsigned long)-1)) - { - ((void (*)(void))((__STARTUP_RUNTIME_CTORS)[CtorIdx++]))(); - } -} - -//----------------------------------------------------------------------------------------- -/// \brief Startup_RunApplication function -/// -/// \param void -/// -/// \return void -//----------------------------------------------------------------------------------------- -static void Startup_RunApplication(void) -{ - /* Check the weak function */ - if((unsigned int) main != 0) - { - /* Call the main function */ - (void)main(); - } - - /* Catch unexpected exit from main or if main does not exist */ - Startup_Unexpected_Exit(); -} - -//----------------------------------------------------------------------------------------- -/// \brief Startup_Unexpected_Exit function -/// -/// \param void -/// -/// \return void -//----------------------------------------------------------------------------------------- -static void Startup_Unexpected_Exit(void) -{ - for(;;); -} - -//----------------------------------------------------------------------------------------- -/// \brief Startup_InitSystemClock function -/// -/// \param void -/// -/// \return void -//----------------------------------------------------------------------------------------- -static void Startup_InitSystemClock(void) -{ - RP2350_ClockInit(); -} - -//----------------------------------------------------------------------------------------- -/// \brief Startup_InitCore function -/// -/// \param void -/// -/// \return void -//----------------------------------------------------------------------------------------- -void Startup_InitCore(void) -{ - RP2350_InitCore(); -} diff --git a/ref_app/target/micros/rpi_pico2_rp2350/Std/Platform_Types.h b/ref_app/target/micros/rpi_pico2_rp2350/Std/Platform_Types.h index c5524b9cc..96d44fbb4 100644 --- a/ref_app/target/micros/rpi_pico2_rp2350/Std/Platform_Types.h +++ b/ref_app/target/micros/rpi_pico2_rp2350/Std/Platform_Types.h @@ -18,6 +18,11 @@ #ifndef __PLATFORM_TYPES_H__ #define __PLATFORM_TYPES_H__ +#if defined(__cplusplus) +extern "C" +{ +#endif + typedef unsigned char uint8; typedef signed char sint8; typedef unsigned short uint16; @@ -31,12 +36,27 @@ typedef void (*pFunc)(void); typedef enum { - FALSE = 0, + FALSE, TRUE -}boolean; +} +boolean; +#if !defined(NULL) +#if defined(__cplusplus) +#define NULL 0 +#else #define NULL (void*)0 +#endif +#endif +#if defined(__cplusplus) +#define NULL_PTR nullptr +#else #define NULL_PTR (void*)0 +#endif + +#if defined(__cplusplus) +} +#endif #endif diff --git a/ref_app/target/micros/rpi_pico2_rp2350/make/rpi_pico2_rp2350.ld b/ref_app/target/micros/rpi_pico2_rp2350/make/rpi_pico2_rp2350.ld index d1598b86b..5ae960728 100644 --- a/ref_app/target/micros/rpi_pico2_rp2350/make/rpi_pico2_rp2350.ld +++ b/ref_app/target/micros/rpi_pico2_rp2350/make/rpi_pico2_rp2350.ld @@ -1,142 +1,128 @@ -/****************************************************************************************** - Filename : Memory_Map.ld - - Core : ARM Cortex-M33 / RISC-V Hazard3 - - MCU : RP2350 - - Author : Chalandi Amine - - Owner : Chalandi Amine - - Date : 04.09.2024 - - Description : Linker description file for Raspberry Pi Pico 2 - -******************************************************************************************/ - -/****************************************************************************************** - ELF Entrypoint -******************************************************************************************/ -ENTRY(Startup_Init) - -/****************************************************************************************** - Globals -******************************************************************************************/ -__STACK_SIZE_CORE0 = 2K; -__STACK_SIZE_CORE1 = 2K; - -/****************************************************************************************** - Memory configuration -******************************************************************************************/ +/* + Copyright Christopher Kormanyos 2024. + Distributed under the Boost Software License, + Version 1.0. (See accompanying file LICENSE_1_0.txt + or copy at http://www.boost.org/LICENSE_1_0.txt) +*/ + +/* Linker script for STM32F1xx ARM(R) Cortex(TM)-M3 MCU */ + +INPUT(libc.a libm.a libgcc.a) + +OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm") +OUTPUT_ARCH(arm) MEMORY { - FLASH(rx) : ORIGIN = 0x10000000, LENGTH = 32M - RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 512K + VEC(rx) : ORIGIN = 0x10000000, LENGTH = 0x400 + ROM(rx) : ORIGIN = 0x10000400, LENGTH = 32M - 0x400 + RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 512K - 4K - 4K } -/****************************************************************************************** - Sections definition -******************************************************************************************/ SECTIONS { - /* Program code */ - .program : ALIGN(4) + /* Interrupt vector table */ + .intvect : { - PROVIDE(__CODE_BASE_ADDRESS = .); + . = ALIGN(4); PROVIDE(__INTVECT_BASE_ADDRESS = .); - *(.riscv_intvect) - KEEP(*(.riscv_intvect)) *(.intvect_c0) *(.intvect_c1) KEEP(*(.intvect_c0)) KEEP(*(.intvect_c1)) PROVIDE(__IMAGE_DEF_BLOCK_START_ADDRESS = .); KEEP(*(.image_start_block)) - *(.text) - *(.text*) - } > FLASH + } > VEC - /* Read-only data (.rodata) */ - .rodata : ALIGN(4) + /* Program code (text), read-only data and static ctors */ + .text : { - PROVIDE(__RODATA_BASE_ADDRESS = .); + _ctors_begin = .; + KEEP(*(SORT(.init_array.*))) + KEEP(*(.init_array*)) + _ctors_end = .; + *(.progmem*) + . = ALIGN(4); + *(.text) + . = ALIGN(4); + *(.text*) + . = ALIGN(4); *(.rodata) - } > FLASH + . = ALIGN(4); + *(.rodata*) + . = ALIGN(4); + *(.glue_7) + . = ALIGN(4); + *(.glue_7t) + . = ALIGN(4); + } > ROM - /* Section for constructors */ - .ctors : ALIGN(4) + .ARM.extab : { - PROVIDE(__CPPCTOR_LIST__ = .); - KEEP (*(SORT(.ctors.*))) - KEEP (*(.ctors)) - KEEP (*(SORT(.init_array.*))) - KEEP (*(.init_array)) - LONG(-1) ; - PROVIDE(__CPPCTOR_END__ = .); . = ALIGN(4); - } > FLASH - + *(.ARM.extab) + *(.ARM.extab*) + *(.gnu.linkonce.armextab.*) + . = ALIGN(4); + } > ROM - /* Section for destructors */ - .dtors : ALIGN(4) + .exidx : { - PROVIDE(__CPPDTOR_LIST__ = .); - KEEP (*(SORT(.dtors.*))) - KEEP (*(.dtors)) - KEEP (*(SORT(.fini_array.*))) - KEEP (*(.fini_array)) - LONG(-1) ; - PROVIDE(__CPPDTOR_END__ = .); - . = ALIGN(4); - } > FLASH - - /* Runtime clear table */ - .clear_sec : ALIGN(4) - { - PROVIDE(__RUNTIME_CLEAR_TABLE = .) ; - LONG(0 + ADDR(.bss)); LONG(SIZEOF(.bss)); - LONG(-1); LONG(-1); . = ALIGN(4); - } > FLASH + PROVIDE(__exidx_start = .); + *(.ARM.exidx*) + . = ALIGN(4); + PROVIDE(__exidx_end = .); + } > ROM - /* Runtime copy table */ - .copy_sec : ALIGN(4) + .ARM.attributes : { - PROVIDE(__RUNTIME_COPY_TABLE = .) ; - LONG(LOADADDR(.data)); LONG(0 + ADDR(.data)); LONG(SIZEOF(.data)); - LONG(-1); LONG(-1); LONG(-1); - . = ALIGN(4); - } > FLASH + *(.ARM.attributes) + } > ROM + + . = 0x20000000; + . = ALIGN(4); /* The ROM-to-RAM initialized data section */ - .data : ALIGN(4) + .data : { - PROVIDE(__DATA_BASE_ADDRESS = .); + _data_begin = .; *(.data) + . = ALIGN(4); + KEEP (*(.data)) *(.data*) - } > RAM AT>FLASH + . = ALIGN(4); + KEEP (*(.data*)) + _data_end = .; + } > RAM AT > ROM - /* The uninitialized (zero-cleared) bss section */ - .bss : ALIGN(4) + /* The uninitialized (zero-cleared) data section */ + .bss : { - PROVIDE(__BSS_BASE_ADDRESS = .); + _bss_begin = .; *(.bss) + . = ALIGN(4); + KEEP (*(.bss)) *(.bss*) + . = ALIGN(4); + KEEP (*(.bss*)) + _bss_end = .; } > RAM - /* stack definition */ - .stack_core0 : - { - . = ALIGN(MAX(__STACK_SIZE_CORE0 , .), 8); - PROVIDE(__CORE0_STACK_TOP = .) ; - } > RAM + PROVIDE(end = .); + PROVIDE(_fini = .); - .stack_core1 : - { - . = ALIGN(MAX(__STACK_SIZE_CORE1 , .), 8); - PROVIDE(__CORE1_STACK_TOP = .) ; - } > RAM + _rom_data_begin = LOADADDR(.data); + + /* stack definitions */ + + . = 0x2007EFF8; + . = ALIGN(8); + + PROVIDE(__CORE1_STACK_TOP = .) ; + + . = 0x2007FFF8; + . = ALIGN(8); + PROVIDE(__CORE0_STACK_TOP = .) ; } diff --git a/ref_app/target/micros/rpi_pico2_rp2350/make/rpi_pico2_rp2350_files.gmk b/ref_app/target/micros/rpi_pico2_rp2350/make/rpi_pico2_rp2350_files.gmk index 47a33fdf2..58a482144 100644 --- a/ref_app/target/micros/rpi_pico2_rp2350/make/rpi_pico2_rp2350_files.gmk +++ b/ref_app/target/micros/rpi_pico2_rp2350/make/rpi_pico2_rp2350_files.gmk @@ -9,14 +9,12 @@ # File list of the stm32f1xx files in the project # ------------------------------------------------------------------------------ -FILES_CPP := - -FILES_TGT = $(PATH_APP)/mcal/$(TGT)/Mcal/Clock/Clock \ +FILES_TGT = $(PATH_APP)/mcal/mcal_gcc_cxx_completion \ $(PATH_APP)/mcal/$(TGT)/Mcal/Cpu/Cpu \ - $(PATH_APP)/mcal/$(TGT)/Mcal/SysTickTimer/SysTickTimer \ - $(PATH_TGT)/Appli/main \ - $(PATH_TGT)/Startup/Core/ARM/core_1_run \ - $(PATH_TGT)/Startup/Core/ARM/image_definition_block \ - $(PATH_TGT)/Startup/Core/ARM/IntVect \ - $(PATH_TGT)/Startup/Core/ARM/util \ - $(PATH_TGT)/Startup/Startup + $(PATH_TGT)/startup/core_1_run \ + $(PATH_TGT)/startup/crt0 \ + $(PATH_TGT)/startup/crt0_init_ram \ + $(PATH_TGT)/startup/crt1 \ + $(PATH_TGT)/startup/image_definition_block \ + $(PATH_TGT)/startup/IntVect \ + $(PATH_TGT)/startup/util diff --git a/ref_app/target/micros/rpi_pico2_rp2350/make/rpi_pico2_rp2350_flags.gmk b/ref_app/target/micros/rpi_pico2_rp2350/make/rpi_pico2_rp2350_flags.gmk index 67ed8f694..5f834bb88 100644 --- a/ref_app/target/micros/rpi_pico2_rp2350/make/rpi_pico2_rp2350_flags.gmk +++ b/ref_app/target/micros/rpi_pico2_rp2350/make/rpi_pico2_rp2350_flags.gmk @@ -8,7 +8,7 @@ # compiler flags for the target architecture # ------------------------------------------------------------------------------ -GCC_VERSION = 13.3.1 +GCC_VERSION = 13.2.1 GCC_TARGET = arm-none-eabi GCC_PREFIX = arm-none-eabi @@ -19,45 +19,36 @@ TGT_ALLFLAGS = -O2 \ -mthumb \ -march=armv8-m.main+fp+dsp \ -mabi=aapcs \ - -mfloat-abi=softfp \ - -DCORE_FAMILY_ARM \ - -MD \ - -fomit-frame-pointer \ - -Wa,-adhln=$(PATH_LST)/$(basename $(@F)).lst + -mfloat-abi=hard \ + -MD TGT_CFLAGS = -std=c11 \ -Wunsuffixed-float-constants \ - $(TGT_ALLFLAGS) \ - -DCORE_FAMILY_ARM \ - -Wa,-adhln=$(PATH_LST)/$(basename $(@F)).lst + $(TGT_ALLFLAGS) TGT_CXXFLAGS = -std=c++14 \ -Wno-psabi \ - $(TGT_ALLFLAGS) \ - -Wa,-adhln=$(PATH_LST)/$(basename $(@F)).lst + $(TGT_ALLFLAGS) -TGT_INCLUDES = -I$(PATH_TGT)/Startup/Core/ARM \ - -I$(PATH_APP)/mcal/$(TGT)/Mcal/Clock \ - -I$(PATH_APP)/mcal/$(TGT)/Mcal/Cmsis/m-profile \ +TGT_INCLUDES = -I$(PATH_APP)/mcal/$(TGT)/Mcal/Cmsis/m-profile \ -I$(PATH_APP)/mcal/$(TGT)/Mcal/Cmsis \ -I$(PATH_APP)/mcal/$(TGT)/Mcal/Cpu \ -I$(PATH_APP)/mcal/$(TGT)/Mcal/Gpio \ - -I$(PATH_APP)/mcal/$(TGT)/Mcal/SysTickTimer \ -I$(PATH_APP)/mcal/$(TGT)/Mcal \ - -I$(PATH_TGT)/Std + -I$(PATH_TGT)/Std \ + -isystem $(PATH_APP)/util/STL TGT_AFLAGS = $(TGT_ALLFLAGS) TGT_LDFLAGS = -nostdlib \ -nostartfiles \ $(TGT_ALLFLAGS) \ - -e Startup_Init \ - -Wl,--no-warn-rwx-segments \ + -e __my_startup \ -Wl,-z,max-page-size=4096 \ -Wl,-Map,$(APP).map \ -T $(LINKER_DEFINITION_FILE) \ --specs=nano.specs \ - --specs=nosys.specs + --specs=nosys.specs ifeq ($(TYP_OS),WIN) diff --git a/ref_app/target/micros/rpi_pico2_rp2350/Startup/Core/ARM/IntVect.c b/ref_app/target/micros/rpi_pico2_rp2350/startup/IntVect.c similarity index 97% rename from ref_app/target/micros/rpi_pico2_rp2350/Startup/Core/ARM/IntVect.c rename to ref_app/target/micros/rpi_pico2_rp2350/startup/IntVect.c index 1f1ecea68..a0e6a0adb 100644 --- a/ref_app/target/micros/rpi_pico2_rp2350/Startup/Core/ARM/IntVect.c +++ b/ref_app/target/micros/rpi_pico2_rp2350/startup/IntVect.c @@ -23,11 +23,13 @@ typedef void (*InterruptHandler)(void); void UndefinedHandler(void); void UndefinedHandler(void) { for(;;); } +void __sys_tick_handler(void) __attribute__((used, noinline)); + //============================================================================= // Functions prototype //============================================================================= -void Startup_Init(void) __attribute__((used)); -void main_Core1 (void) __attribute__((weak, alias("UndefinedHandler"))); +void __my_startup(void) __attribute__((used)); +void __main_core1(void) __attribute__((used)); void __CORE0_STACK_TOP(void); void __CORE1_STACK_TOP(void); @@ -88,7 +90,7 @@ void POWMAN_IRQ_TIMER_IRQn(void) __attribute__((weak, alias("UndefinedHandler")) const InterruptHandler __attribute__((section(".intvect_c0"), used, aligned(128))) __INTVECT_Core0[] = { (InterruptHandler)&__CORE0_STACK_TOP, - (InterruptHandler)&Startup_Init, + (InterruptHandler)&__my_startup, (InterruptHandler)&NMI, (InterruptHandler)&HardFault, (InterruptHandler)0, @@ -161,7 +163,7 @@ const InterruptHandler __attribute__((section(".intvect_c0"), used, aligned(128) const InterruptHandler __attribute__((section(".intvect_c1"), used, aligned(128))) __INTVECT_Core1[] = { (InterruptHandler)&__CORE1_STACK_TOP, - (InterruptHandler)&main_Core1, + (InterruptHandler)&__main_core1, (InterruptHandler)&NMI, (InterruptHandler)&HardFault, (InterruptHandler)0, @@ -175,7 +177,7 @@ const InterruptHandler __attribute__((section(".intvect_c1"), used, aligned(128) (InterruptHandler)0, (InterruptHandler)0, (InterruptHandler)&PendSV, - (InterruptHandler)&SysTickTimer, + (InterruptHandler)&__sys_tick_handler, (InterruptHandler)&TIMER0_IRQ_0_IRQn, (InterruptHandler)&TIMER0_IRQ_1_IRQn, (InterruptHandler)&TIMER0_IRQ_2_IRQn, diff --git a/ref_app/target/micros/rpi_pico2_rp2350/Startup/Core/ARM/core_1_run.cpp b/ref_app/target/micros/rpi_pico2_rp2350/startup/core_1_run.cpp similarity index 100% rename from ref_app/target/micros/rpi_pico2_rp2350/Startup/Core/ARM/core_1_run.cpp rename to ref_app/target/micros/rpi_pico2_rp2350/startup/core_1_run.cpp diff --git a/ref_app/target/micros/rpi_pico2_rp2350/startup/crt0.cpp b/ref_app/target/micros/rpi_pico2_rp2350/startup/crt0.cpp new file mode 100644 index 000000000..08f4cfd1c --- /dev/null +++ b/ref_app/target/micros/rpi_pico2_rp2350/startup/crt0.cpp @@ -0,0 +1,158 @@ +// *************************************************************************************** +// Filename : Startup.c +// +// Author : Chalandi Amine +// +// Owner : Chalandi Amine +// +// Date : 04.09.2024 +// +// Description : C/C++ Runtime Setup (Crt0) +// +// *************************************************************************************** + +#include +#include + +#include +#include + +#include + +extern "C" +{ + extern void core_1_run_flag_set(bool); + extern bool core_1_run_flag_get(void); + + void __my_startup(void) __attribute__((used)); + void __main(void); + + extern int main (void); + extern void __main_core0(void); + extern void __main_core1(void) __attribute__((used)); + + extern boolean RP2350_StartCore1 (void); + extern void RP2350_MulticoreSync(uint32_t CpuId); +} + +namespace crt +{ + auto init_ram () -> void; + auto init_ctors() -> void; +} + +namespace local +{ + inline auto get_cpuid() -> std::uint32_t + { + const std::uint32_t cpuid { HW_PER_SIO->CPUID.reg }; + + return cpuid; + } +} + +extern "C" +void __my_startup(void) +{ + /* Configure the system clock */ + mcal::cpu::init(); + + /* Initialize the RAM memory */ + crt::init_ram(); + + /* Initialize the non-local C++ objects */ + crt::init_ctors(); + + // Jump to __main, which calls __main_core0, the main + // function of core 0. The main function of core 0 + // itself then subsequently starts up core 1 which + // is launched in __main_core1. Both of these core 0/1 + // subroutines will never return. + + ::__main(); + + // Catch an unexpected return from __main(). + for(;;) + { + // Replace with a loud error if desired. + mcal::wdg::secure::trigger(); + } +} + +extern "C" +void __main(void) +{ + // Run the main function of core 0. + // This will subsequently start core 1. + ::__main_core0(); + + // Synchronize with core 1. + RP2350_MulticoreSync(local::get_cpuid()); + + // It is here that an actual application could + // be started and then executed on core 0. + + // Execute an endless loop on core 0 (while the application runs on core 1). + for(;;) { mcal::cpu::nop(); } + + // This point is never reached. +} + +extern "C" +void __main_core0(void) +{ + // Disable interrupts on core 0. + mcal::irq::disable_all(); + + /* Start the Core 1 and turn on the led to be sure that we passed successfully the core 1 initiaization */ + if(TRUE == RP2350_StartCore1()) + { + while(!core_1_run_flag_get()) + { + mcal::cpu::nop(); + } + } + else + { + /* Loop forever in case of error */ + while(1) + { + mcal::cpu::nop(); + } + } +} + +extern "C" +void __main_core1(void) +{ + // Disable interrupts on core 1. + mcal::irq::disable_all(); + + core_1_run_flag_set(true); + + /* Note: Core 1 is started with interrupt enabled by the BootRom */ + + /* Clear the stiky bits of the FIFO_ST on core 1 */ + HW_PER_SIO->FIFO_ST.reg = 0xFFu; + + /*Setting EXTEXCLALL allows external exclusive operations to be used in a configuration with no MPU. + This is because the default memory map does not include any shareable Normal memory.*/ + SCnSCB->ACTLR |= (1ul<<29); + + __asm volatile("DSB"); + + /* Clear all pending interrupts on core 1 */ + NVIC->ICPR[0] = (uint32_t)-1; + + // Synchronize with core 0. + RP2350_MulticoreSync(local::get_cpuid()); + + // Initialize the FPU: Enable CP10 and CP11. + //CPACR |= 0x00F00000UL; + HW_PER_PPB->CPACR.reg |= (std::uint32_t) 0x00F00000UL; + //mcal::reg::reg_access_static(UINT32_C(0x00F00000))>::reg_or(); + + // Jump to main on core 1 (and never return). + asm volatile("ldr r3, =main"); + asm volatile("blx r3"); +} diff --git a/ref_app/target/micros/rpi_pico2_rp2350/startup/crt0_init_ram.cpp b/ref_app/target/micros/rpi_pico2_rp2350/startup/crt0_init_ram.cpp new file mode 100644 index 000000000..328b4be4c --- /dev/null +++ b/ref_app/target/micros/rpi_pico2_rp2350/startup/crt0_init_ram.cpp @@ -0,0 +1,62 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2007 - 2024. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#if defined(__GNUC__) && (__GNUC__ >= 12) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Warray-bounds" +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wstringop-overflow" +#endif + +#include +#include +#include + +extern "C" +{ + extern std::uintptr_t _rom_data_begin; // Start address for the initialization values of the rom-to-ram section. + extern std::uintptr_t _data_begin; // Start address for the .data section. + extern std::uintptr_t _data_end; // End address for the .data section. + extern std::uintptr_t _bss_begin; // Start address for the .bss section. + extern std::uintptr_t _bss_end; // End address for the .bss section. +} + +namespace crt +{ + auto init_ram() -> void; +} + +auto crt::init_ram() -> void +{ + using memory_aligned_type = std::uint32_t; + + // Copy the data segment initializers from ROM to RAM. + // Note that all data segments are aligned by 4. + const std::size_t size_data + { + static_cast + ( + static_cast(static_cast(&_data_end)) + - static_cast(static_cast(&_data_begin)) + ) + }; + + std::copy(static_cast(static_cast(&_rom_data_begin)), + static_cast(static_cast(&_rom_data_begin)) + size_data, + static_cast< memory_aligned_type*>(static_cast< void*>(&_data_begin))); + + // Clear the bss segment. + // Note that the bss segment is aligned by 4. + std::fill(static_cast(static_cast(&_bss_begin)), + static_cast(static_cast(&_bss_end)), + static_cast(0U)); +} + +#if defined(__GNUC__) && (__GNUC__ >= 12) +#pragma GCC diagnostic pop +#pragma GCC diagnostic pop +#endif diff --git a/ref_app/target/micros/rpi_pico2_rp2350/startup/crt1.cpp b/ref_app/target/micros/rpi_pico2_rp2350/startup/crt1.cpp new file mode 100644 index 000000000..fba863842 --- /dev/null +++ b/ref_app/target/micros/rpi_pico2_rp2350/startup/crt1.cpp @@ -0,0 +1,37 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2007 - 2024. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#include +#include + +extern "C" +{ + struct ctor_type + { + using function_type = void(*)(void); + }; + + extern ctor_type::function_type _ctors_end; + extern ctor_type::function_type _ctors_begin; +} + +namespace crt +{ + auto init_ctors() -> void; +} + +auto crt::init_ctors() -> void +{ + using local_const_reverse_iterator = std::reverse_iterator; + + std::for_each(local_const_reverse_iterator { &_ctors_end }, + local_const_reverse_iterator { &_ctors_begin }, + [](const ctor_type::function_type pf) + { + pf(); + }); +} diff --git a/ref_app/target/micros/rpi_pico2_rp2350/Startup/Core/ARM/image_definition_block.c b/ref_app/target/micros/rpi_pico2_rp2350/startup/image_definition_block.c similarity index 100% rename from ref_app/target/micros/rpi_pico2_rp2350/Startup/Core/ARM/image_definition_block.c rename to ref_app/target/micros/rpi_pico2_rp2350/startup/image_definition_block.c diff --git a/ref_app/target/micros/rpi_pico2_rp2350/Startup/Core/ARM/util.s b/ref_app/target/micros/rpi_pico2_rp2350/startup/util.s similarity index 80% rename from ref_app/target/micros/rpi_pico2_rp2350/Startup/Core/ARM/util.s rename to ref_app/target/micros/rpi_pico2_rp2350/startup/util.s index f840de27e..d0d3b8fa0 100644 --- a/ref_app/target/micros/rpi_pico2_rp2350/Startup/Core/ARM/util.s +++ b/ref_app/target/micros/rpi_pico2_rp2350/startup/util.s @@ -17,27 +17,6 @@ .cpu cortex-m33 -/******************************************************************************************* - \brief - - \param - - \return -********************************************************************************************/ -.thumb_func -.section ".text", "ax" -.align 8 -.globl BlockingDelay -.type BlockingDelay, % function - - -BlockingDelay: - subs r0, r0, #1 - bne BlockingDelay - bx lr - -.size BlockingDelay, .-BlockingDelay - /******************************************************************************************* \brief diff --git a/ref_app/target/micros/rpi_pico_rp2040/make/rpi_pico_rp2040.ld b/ref_app/target/micros/rpi_pico_rp2040/make/rpi_pico_rp2040.ld index 7240ae485..5505b4a44 100644 --- a/ref_app/target/micros/rpi_pico_rp2040/make/rpi_pico_rp2040.ld +++ b/ref_app/target/micros/rpi_pico_rp2040/make/rpi_pico_rp2040.ld @@ -132,13 +132,13 @@ SECTIONS /* stack definitions */ - . = 0x20041FF8; + . = 0x2003EFF8; . = ALIGN(8); - PROVIDE(__CORE0_STACK_TOP = .) ; + PROVIDE(__CORE1_STACK_TOP = .) ; - . = 0x20040FF8; + . = 0x2003FFF8; . = ALIGN(8); - PROVIDE(__CORE1_STACK_TOP = .) ; + PROVIDE(__CORE0_STACK_TOP = .) ; } diff --git a/ref_app/target/micros/rpi_pico_rp2040/startup/crt0.cpp b/ref_app/target/micros/rpi_pico_rp2040/startup/crt0.cpp index 46ab10aa6..32df0f24a 100644 --- a/ref_app/target/micros/rpi_pico_rp2040/startup/crt0.cpp +++ b/ref_app/target/micros/rpi_pico_rp2040/startup/crt0.cpp @@ -26,6 +26,20 @@ extern "C" auto __main () -> void __attribute__((section(".startup"), used, extern "C" auto __main_core0() -> void __attribute__((section(".startup"), used, noinline)); extern "C" auto __main_core1() -> void __attribute__((section(".startup"), used, noinline)); +namespace local +{ + inline auto get_cpuid() -> std::uint32_t + { + const std::uint32_t + cpuid + { + mcal::reg::reg_access_static::reg_get() + }; + + return cpuid; + } +} + extern "C" auto __my_startup() -> void { @@ -70,7 +84,7 @@ auto __main() -> void ::__main_core0(); // Synchronize with core 1. - mcal::cpu::rp2040::multicore_sync(mcal::reg::reg_access_static::reg_get()); + mcal::cpu::rp2040::multicore_sync(local::get_cpuid()); // It is here that an actual application could // be started and then executed on core 0. @@ -124,10 +138,13 @@ auto __main_core1() -> void // Clear all pending interrupts on core 1. // NVIC->ICPR[0U] = static_cast(UINT32_C(0xFFFFFFFF)); - mcal::reg::reg_access_static::reg_set(); + mcal::reg::reg_access_static::reg_set(); // Synchronize with core 0. - mcal::cpu::rp2040::multicore_sync(mcal::reg::reg_access_static::reg_get()); + mcal::cpu::rp2040::multicore_sync(local::get_cpuid()); // Jump to main on core 1 (and never return). asm volatile("ldr r3, =main"); diff --git a/ref_app/target/micros/rpi_pico_rp2040/startup/int_vect.cpp b/ref_app/target/micros/rpi_pico_rp2040/startup/int_vect.cpp index bca578016..4c7e5f133 100644 --- a/ref_app/target/micros/rpi_pico_rp2040/startup/int_vect.cpp +++ b/ref_app/target/micros/rpi_pico_rp2040/startup/int_vect.cpp @@ -15,7 +15,7 @@ extern "C" auto UndefinedHandler() -> void { for(;;) { mcal::cpu::nop(); } } extern "C" auto __my_startup() -> void __attribute__((used, noinline)); extern "C" auto __main_core1() -> void __attribute__((weak, alias("UndefinedHandler"))); -extern "C" auto __sys_tick_handler() noexcept -> void __attribute__((used, noinline)); +extern "C" auto __sys_tick_handler(void) -> void __attribute__((used, noinline)); extern "C" auto __CORE0_STACK_TOP() -> void; extern "C" auto __CORE1_STACK_TOP() -> void;