mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-08-23 04:27:39 +00:00
Generalize method for executing SPI flash image in M4 RAM.
This commit is contained in:
@@ -23,15 +23,8 @@
|
||||
|
||||
#include "hal.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
#include <cstring>
|
||||
|
||||
static constexpr uint32_t m4_text_flash_image_offset = 0x20000;
|
||||
static constexpr size_t m4_text_size = 0x8000;
|
||||
static constexpr uint32_t m4_text_flash_base = LPC_SPIFI_DATA_CACHED_BASE + m4_text_flash_image_offset;
|
||||
static constexpr uint32_t m4_text_ram_base = 0x10080000;
|
||||
|
||||
/* TODO: OK, this is cool, but how do I put the M4 to sleep so I can switch to
|
||||
* a different image? Other than asking the old image to sleep while the M0
|
||||
* makes changes?
|
||||
@@ -39,14 +32,14 @@ static constexpr uint32_t m4_text_ram_base = 0x10080000;
|
||||
* I suppose I could force M4MEMMAP to an invalid memory reason which would
|
||||
* cause an exception and effectively halt the M4. But that feels gross.
|
||||
*/
|
||||
void m4_init() {
|
||||
void m4_init(const portapack::spi_flash::region_t from, void* const to) {
|
||||
/* Initialize M4 code RAM */
|
||||
std::memcpy((void*)m4_text_ram_base, (void*)m4_text_flash_base, m4_text_size);
|
||||
std::memcpy(to, from.base_address(), from.size);
|
||||
|
||||
/* M4 core is assumed to be sleeping with interrupts off, so we can mess
|
||||
* with its address space and RAM without concern.
|
||||
*/
|
||||
LPC_CREG->M4MEMMAP = m4_text_ram_base;
|
||||
LPC_CREG->M4MEMMAP = reinterpret_cast<uint32_t>(to);
|
||||
|
||||
/* Reset M4 core */
|
||||
LPC_RGU->RESET_CTRL[0] = (1 << 13);
|
||||
|
@@ -22,6 +22,10 @@
|
||||
#ifndef __M4_STARTUP_H__
|
||||
#define __M4_STARTUP_H__
|
||||
|
||||
void m4_init();
|
||||
#include <cstddef>
|
||||
|
||||
#include "spi_image.hpp"
|
||||
|
||||
void m4_init(const portapack::spi_flash::region_t from, void* const to);
|
||||
|
||||
#endif/*__M4_STARTUP_H__*/
|
||||
|
@@ -59,6 +59,7 @@ using namespace hackrf::one;
|
||||
#include "spi_pp.hpp"
|
||||
|
||||
#include "m4_startup.hpp"
|
||||
#include "spi_image.hpp"
|
||||
|
||||
#include "debug.hpp"
|
||||
#include "led.hpp"
|
||||
@@ -649,7 +650,8 @@ context.message_map[Message::ID::FSKPacket] = [](const Message* const p) {
|
||||
};
|
||||
|
||||
m4txevent_interrupt_enable();
|
||||
m4_init();
|
||||
|
||||
m4_init(portapack::spi_flash::baseband, portapack::spi_flash::m4_text_ram_base);
|
||||
|
||||
while(true) {
|
||||
const auto events = event_dispatcher.wait();
|
||||
|
Reference in New Issue
Block a user