Created
July 5, 2022 12:30
-
-
Save Novakov/2d921fc26b6743a96a092147b5fad408 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MEMORY | |
{ | |
rom (rx) : ORIGIN = 0x00000000, LENGTH = 0x00040000 | |
ram (rwx) : ORIGIN = 0x20002000, LENGTH = 0x00004000 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void mtb_disable(void) { | |
MTB_REGS->MTB_MASTER &= ~MTB_MASTER_EN_Msk; | |
} | |
void mtb_enable(size_t mtb_size) { | |
if ((mtb_size < 16) || (__builtin_popcount(mtb_size) != 1)) { | |
// MTB must be at least 16 bytes and be a power of 2 | |
while (1); | |
} | |
// scrub MTB SRAM so it's easy to see what has gotten written to | |
memset((void *) MTB_REGS->MTB_BASE, 0x00, mtb_size); | |
const int mask = __builtin_ctz(mtb_size) - 4; | |
mtb_disable(); | |
MTB_REGS->MTB_POSITION = 0; | |
MTB_REGS->MTB_MASTER = MTB_MASTER_EN(1) | MTB_MASTER_MASK(mask); | |
} | |
int main(int argc, char** argv) { | |
mtb_enable(4096); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment