diff --git a/firmware/common/LPC43xx_M4_memory.ld b/firmware/common/LPC43xx_M4_memory.ld index 71e78216..1926c0bf 100644 --- a/firmware/common/LPC43xx_M4_memory.ld +++ b/firmware/common/LPC43xx_M4_memory.ld @@ -34,3 +34,4 @@ MEMORY } usb_bulk_buffer = ORIGIN(ram_usb); +PROVIDE(__ram_m0_start__ = ORIGIN(ram_m0)); diff --git a/firmware/hackrf_usb/CMakeLists.txt b/firmware/hackrf_usb/CMakeLists.txt index 7e124b1f..03a073f8 100644 --- a/firmware/hackrf_usb/CMakeLists.txt +++ b/firmware/hackrf_usb/CMakeLists.txt @@ -63,6 +63,8 @@ set(SRC_M4 "${PATH_HACKRF_FIRMWARE_COMMON}/operacake.c" ) +set(SRC_M0 sgpio_m0.c) + if(BOARD STREQUAL "HACKRF_ONE") SET(SRC_M4 ${SRC_M4} diff --git a/firmware/hackrf_usb/hackrf_usb.c b/firmware/hackrf_usb/hackrf_usb.c index 2498c9fb..8798913d 100644 --- a/firmware/hackrf_usb/hackrf_usb.c +++ b/firmware/hackrf_usb/hackrf_usb.c @@ -22,7 +22,9 @@ #include +#include #include +#include #include @@ -50,6 +52,10 @@ #include "hackrf-ui.h" +extern uint32_t __m0_start__; +extern uint32_t __m0_end__; +extern uint32_t __ram_m0_start__; + static usb_request_handler_fn vendor_request_handler[] = { NULL, usb_vendor_request_set_transceiver_mode, @@ -176,6 +182,16 @@ static bool cpld_jtag_sram_load(jtag_t* const jtag) { return success; } +static void m0_rom_to_ram() { + uint32_t *dest = &__ram_m0_start__; + uint32_t *src = &__m0_start__; + while (src < &__m0_end__) { + *dest = *src; + dest++; + src++; + } +} + int main(void) { bool operacake_allow_gpio; pin_setup(); @@ -188,6 +204,10 @@ int main(void) { #endif cpu_clock_init(); + /* Wake the M0 */ + m0_rom_to_ram(); + ipc_start_m0((uint32_t)&__ram_m0_start__); + if( !cpld_jtag_sram_load(&jtag_cpld) ) { halt_and_flash(6000000); } diff --git a/firmware/hackrf_usb/sgpio_m0.c b/firmware/hackrf_usb/sgpio_m0.c new file mode 100644 index 00000000..36fd7d7c --- /dev/null +++ b/firmware/hackrf_usb/sgpio_m0.c @@ -0,0 +1,29 @@ +/* + * Copyright 2020 Mike Walters + * + * This file is part of HackRF. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#include "gpio_lpc.h" + +int main() { + while(1) { + *(uint8_t*)0x400f4048 ^= 1; + for (volatile int i = 0; i < 10000000; i++) {} + } +}