Initial Release
This commit is contained in:
14
flash/xip_stream/CMakeLists.txt
Normal file
14
flash/xip_stream/CMakeLists.txt
Normal file
@@ -0,0 +1,14 @@
|
||||
add_executable(flash_xip_stream
|
||||
flash_xip_stream.c
|
||||
)
|
||||
|
||||
target_link_libraries(flash_xip_stream
|
||||
pico_stdlib
|
||||
hardware_dma
|
||||
)
|
||||
|
||||
# create map/bin/hex file etc.
|
||||
pico_add_extra_outputs(flash_xip_stream)
|
||||
|
||||
# add url via pico_set_program_url
|
||||
example_auto_set_url(flash_xip_stream)
|
||||
88
flash/xip_stream/flash_xip_stream.c
Normal file
88
flash/xip_stream/flash_xip_stream.c
Normal file
@@ -0,0 +1,88 @@
|
||||
/**
|
||||
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "pico/stdlib.h"
|
||||
#include "hardware/dma.h"
|
||||
#include "hardware/regs/addressmap.h"
|
||||
#include "hardware/structs/xip_ctrl.h"
|
||||
|
||||
#include "random_test_data.h"
|
||||
|
||||
// The XIP has some internal hardware that can stream a linear access sequence
|
||||
// to a DMAable FIFO, while the system is still doing random accesses on flash
|
||||
// code + data.
|
||||
|
||||
uint32_t buf[count_of(random_test_data)];
|
||||
|
||||
int main() {
|
||||
stdio_init_all();
|
||||
for (int i = 0; i < count_of(random_test_data); ++i)
|
||||
buf[i] = 0;
|
||||
|
||||
// This example won't work with PICO_NO_FLASH builds. Note that XIP stream
|
||||
// can be made to work in these cases, if you enable some XIP mode first
|
||||
// (e.g. via calling flash_enter_cmd_xip() in ROM). However, you will get
|
||||
// much better performance by DMAing directly from the SSI's FIFOs, as in
|
||||
// this way you can clock data continuously on the QSPI bus, rather than a
|
||||
// series of short transfers.
|
||||
if ((uint32_t) &random_test_data[0] >= SRAM_BASE) {
|
||||
printf("You need to run this example from flash!\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
// Transfer started by writing nonzero value to stream_ctr. stream_ctr
|
||||
// will count down as the transfer progresses. Can terminate early by
|
||||
// writing 0 to stream_ctr.
|
||||
// It's a good idea to drain the FIFO first!
|
||||
printf("Starting stream from %p\n", random_test_data);
|
||||
//tag::start_stream[]
|
||||
while (!(xip_ctrl_hw->stat & XIP_STAT_FIFO_EMPTY))
|
||||
(void) xip_ctrl_hw->stream_fifo;
|
||||
xip_ctrl_hw->stream_addr = (uint32_t) &random_test_data[0];
|
||||
xip_ctrl_hw->stream_ctr = count_of(random_test_data);
|
||||
//end::start_stream[]
|
||||
|
||||
// Start DMA transfer from XIP stream FIFO to our buffer in memory. Use
|
||||
// the auxiliary bus slave for the DMA<-FIFO accesses, to avoid stalling
|
||||
// the DMA against general XIP traffic. Doesn't really matter for this
|
||||
// example, but it can have a huge effect on DMA throughput.
|
||||
|
||||
printf("Starting DMA\n");
|
||||
//tag::start_dma[]
|
||||
const uint dma_chan = 0;
|
||||
dma_channel_config cfg = dma_channel_get_default_config(dma_chan);
|
||||
channel_config_set_read_increment(&cfg, false);
|
||||
channel_config_set_write_increment(&cfg, true);
|
||||
channel_config_set_dreq(&cfg, DREQ_XIP_STREAM);
|
||||
dma_channel_configure(
|
||||
dma_chan,
|
||||
&cfg,
|
||||
(void *) buf, // Write addr
|
||||
(const void *) XIP_AUX_BASE, // Read addr
|
||||
count_of(random_test_data), // Transfer count
|
||||
true // Start immediately!
|
||||
);
|
||||
//end::start_dma[]
|
||||
|
||||
dma_channel_wait_for_finish_blocking(dma_chan);
|
||||
|
||||
printf("DMA complete\n");
|
||||
|
||||
bool mismatch = false;
|
||||
for (int i = 0; i < count_of(random_test_data); ++i) {
|
||||
if (random_test_data[i] != buf[i]) {
|
||||
printf("Data mismatch: %08x (actual) != %08x (expected)\n", buf[i], random_test_data[i]);
|
||||
mismatch = true;
|
||||
break;
|
||||
}
|
||||
printf("%08x%c", buf[i], i % 8 == 7 ? '\n' : ' ');
|
||||
}
|
||||
if (!mismatch)
|
||||
printf("Data check OK\n");
|
||||
}
|
||||
160
flash/xip_stream/random_test_data.h
Normal file
160
flash/xip_stream/random_test_data.h
Normal file
@@ -0,0 +1,160 @@
|
||||
const uint32_t random_test_data[] = {
|
||||
0x76654e22, 0x47207265, 0x616e6e6f,
|
||||
0x76694720, 0x6f592065, 0x70552075,
|
||||
0x570a0a22, 0x65722765, 0x206f6e20,
|
||||
0x61727473, 0x7265676e, 0x6f742073,
|
||||
0x766f6c20, 0x6f590a65, 0x6e6b2075,
|
||||
0x7420776f, 0x72206568, 0x73656c75,
|
||||
0x646e6120, 0x206f7320, 0x49206f64,
|
||||
0x6620410a, 0x206c6c75, 0x6d6d6f63,
|
||||
0x656d7469, 0x7327746e, 0x61687720,
|
||||
0x27492074, 0x6874206d, 0x696b6e69,
|
||||
0x6f20676e, 0x6f590a66, 0x6f772075,
|
||||
0x6e646c75, 0x67207427, 0x74207465,
|
||||
0x20736968, 0x6d6f7266, 0x796e6120,
|
||||
0x68746f20, 0x67207265, 0x0a0a7975,
|
||||
0x756a2049, 0x77207473, 0x616e6e61,
|
||||
0x6c657420, 0x6f79206c, 0x6f682075,
|
||||
0x27492077, 0x6566206d, 0x6e696c65,
|
||||
0x6f470a67, 0x20617474, 0x656b616d,
|
||||
0x756f7920, 0x646e7520, 0x74737265,
|
||||
0x0a646e61, 0x76654e0a, 0x67207265,
|
||||
0x616e6e6f, 0x76696720, 0x6f792065,
|
||||
0x70752075, 0x76654e0a, 0x67207265,
|
||||
0x616e6e6f, 0x74656c20, 0x756f7920,
|
||||
0x776f6420, 0x654e0a6e, 0x20726576,
|
||||
0x6e6e6f67, 0x75722061, 0x7261206e,
|
||||
0x646e756f, 0x646e6120, 0x73656420,
|
||||
0x20747265, 0x0a756f79, 0x6576654e,
|
||||
0x6f672072, 0x20616e6e, 0x656b616d,
|
||||
0x756f7920, 0x79726320, 0x76654e0a,
|
||||
0x67207265, 0x616e6e6f, 0x79617320,
|
||||
0x6f6f6720, 0x65796264, 0x76654e0a,
|
||||
0x67207265, 0x616e6e6f, 0x6c657420,
|
||||
0x2061206c, 0x2065696c, 0x20646e61,
|
||||
0x74727568, 0x756f7920, 0x65570a0a,
|
||||
0x20657627, 0x776f6e6b, 0x6165206e,
|
||||
0x6f206863, 0x72656874, 0x726f6620,
|
||||
0x206f7320, 0x676e6f6c, 0x756f590a,
|
||||
0x65682072, 0x27747261, 0x65622073,
|
||||
0x61206e65, 0x6e696863, 0x62202c67,
|
||||
0x590a7475, 0x7227756f, 0x6f742065,
|
||||
0x6873206f, 0x6f742079, 0x79617320,
|
||||
0x0a746920, 0x69736e49, 0x202c6564,
|
||||
0x62206577, 0x2068746f, 0x776f6e6b,
|
||||
0x61687720, 0x20732774, 0x6e656562,
|
||||
0x696f6720, 0x6f20676e, 0x65570a6e,
|
||||
0x6f6e6b20, 0x68742077, 0x61672065,
|
||||
0x6120656d, 0x7720646e, 0x65722765,
|
||||
0x6e6f6720, 0x7020616e, 0x2079616c,
|
||||
0x0a0a7469, 0x20646e41, 0x79206669,
|
||||
0x6120756f, 0x6d206b73, 0x6f682065,
|
||||
0x27492077, 0x6566206d, 0x6e696c65,
|
||||
0x6f440a67, 0x2074276e, 0x6c6c6574,
|
||||
0x20656d20, 0x27756f79, 0x74206572,
|
||||
0x62206f6f, 0x646e696c, 0x206f7420,
|
||||
0x0a656573, 0x76654e0a, 0x67207265,
|
||||
0x616e6e6f, 0x76696720, 0x6f792065,
|
||||
0x70752075, 0x76654e0a, 0x67207265,
|
||||
0x616e6e6f, 0x74656c20, 0x756f7920,
|
||||
0x776f6420, 0x654e0a6e, 0x20726576,
|
||||
0x6e6e6f67, 0x75722061, 0x7261206e,
|
||||
0x646e756f, 0x646e6120, 0x73656420,
|
||||
0x20747265, 0x0a756f79, 0x6576654e,
|
||||
0x6f672072, 0x20616e6e, 0x656b616d,
|
||||
0x756f7920, 0x79726320, 0x76654e0a,
|
||||
0x67207265, 0x616e6e6f, 0x79617320,
|
||||
0x6f6f6720, 0x65796264, 0x76654e0a,
|
||||
0x67207265, 0x616e6e6f, 0x6c657420,
|
||||
0x2061206c, 0x2065696c, 0x20646e61,
|
||||
0x74727568, 0x756f7920, 0x654e0a0a,
|
||||
0x20726576, 0x6e6e6f67, 0x69672061,
|
||||
0x79206576, 0x7520756f, 0x654e0a70,
|
||||
0x20726576, 0x6e6e6f67, 0x656c2061,
|
||||
0x6f792074, 0x6f642075, 0x4e0a6e77,
|
||||
0x72657665, 0x6e6f6720, 0x7220616e,
|
||||
0x61206e75, 0x6e756f72, 0x6e612064,
|
||||
0x65642064, 0x74726573, 0x756f7920,
|
||||
0x76654e0a, 0x67207265, 0x616e6e6f,
|
||||
0x6b616d20, 0x6f792065, 0x72632075,
|
||||
0x654e0a79, 0x20726576, 0x6e6e6f67,
|
||||
0x61732061, 0x6f672079, 0x7962646f,
|
||||
0x654e0a65, 0x20726576, 0x6e6e6f67,
|
||||
0x65742061, 0x61206c6c, 0x65696c20,
|
||||
0x646e6120, 0x72756820, 0x6f792074,
|
||||
0x280a0a75, 0x2c686f4f, 0x76696720,
|
||||
0x6f792065, 0x70752075, 0x4f280a29,
|
||||
0x202c686f, 0x65766967, 0x756f7920,
|
||||
0x29707520, 0x76654e0a, 0x67207265,
|
||||
0x616e6e6f, 0x76696720, 0x6e202c65,
|
||||
0x72657665, 0x6e6f6720, 0x6720616e,
|
||||
0x0a657669, 0x76694728, 0x6f792065,
|
||||
0x70752075, 0x654e0a29, 0x20726576,
|
||||
0x6e6e6f67, 0x69672061, 0x202c6576,
|
||||
0x6576656e, 0x6f672072, 0x20616e6e,
|
||||
0x65766967, 0x6947280a, 0x79206576,
|
||||
0x7520756f, 0x0a0a2970, 0x76276557,
|
||||
0x6e6b2065, 0x206e776f, 0x68636165,
|
||||
0x68746f20, 0x66207265, 0x7320726f,
|
||||
0x6f6c206f, 0x590a676e, 0x2072756f,
|
||||
0x72616568, 0x20732774, 0x6e656562,
|
||||
0x68636120, 0x2c676e69, 0x74756220,
|
||||
0x756f590a, 0x20657227, 0x206f6f74,
|
||||
0x20796873, 0x73206f74, 0x69207961,
|
||||
0x6e490a74, 0x65646973, 0x6577202c,
|
||||
0x746f6220, 0x6e6b2068, 0x7720776f,
|
||||
0x27746168, 0x65622073, 0x67206e65,
|
||||
0x676e696f, 0x0a6e6f20, 0x6b206557,
|
||||
0x20776f6e, 0x20656874, 0x656d6167,
|
||||
0x646e6120, 0x27657720, 0x67206572,
|
||||
0x616e6e6f, 0x616c7020, 0x74692079,
|
||||
0x20490a0a, 0x7473756a, 0x6e617720,
|
||||
0x7420616e, 0x206c6c65, 0x20756f79,
|
||||
0x20776f68, 0x206d2749, 0x6c656566,
|
||||
0x0a676e69, 0x74746f47, 0x616d2061,
|
||||
0x7920656b, 0x7520756f, 0x7265646e,
|
||||
0x6e617473, 0x4e0a0a64, 0x72657665,
|
||||
0x6e6f6720, 0x6720616e, 0x20657669,
|
||||
0x20756f79, 0x4e0a7075, 0x72657665,
|
||||
0x6e6f6720, 0x6c20616e, 0x79207465,
|
||||
0x6420756f, 0x0a6e776f, 0x6576654e,
|
||||
0x6f672072, 0x20616e6e, 0x206e7572,
|
||||
0x756f7261, 0x6120646e, 0x6420646e,
|
||||
0x72657365, 0x6f792074, 0x654e0a75,
|
||||
0x20726576, 0x6e6e6f67, 0x616d2061,
|
||||
0x7920656b, 0x6320756f, 0x4e0a7972,
|
||||
0x72657665, 0x6e6f6720, 0x7320616e,
|
||||
0x67207961, 0x62646f6f, 0x4e0a6579,
|
||||
0x72657665, 0x6e6f6720, 0x7420616e,
|
||||
0x206c6c65, 0x696c2061, 0x6e612065,
|
||||
0x75682064, 0x79207472, 0x0a0a756f,
|
||||
0x6576654e, 0x6f672072, 0x20616e6e,
|
||||
0x65766967, 0x756f7920, 0x0a707520,
|
||||
0x6576654e, 0x6f672072, 0x20616e6e,
|
||||
0x2074656c, 0x20756f79, 0x6e776f64,
|
||||
0x76654e0a, 0x67207265, 0x616e6e6f,
|
||||
0x6e757220, 0x6f726120, 0x20646e75,
|
||||
0x20646e61, 0x65736564, 0x79207472,
|
||||
0x4e0a756f, 0x72657665, 0x6e6f6720,
|
||||
0x6d20616e, 0x20656b61, 0x20756f79,
|
||||
0x0a797263, 0x6576654e, 0x6f672072,
|
||||
0x20616e6e, 0x20796173, 0x646f6f67,
|
||||
0x0a657962, 0x6576654e, 0x6f672072,
|
||||
0x20616e6e, 0x6c6c6574, 0x6c206120,
|
||||
0x61206569, 0x6820646e, 0x20747275,
|
||||
0x0a756f79, 0x76654e0a, 0x67207265,
|
||||
0x616e6e6f, 0x76696720, 0x6f792065,
|
||||
0x70752075, 0x76654e0a, 0x67207265,
|
||||
0x616e6e6f, 0x74656c20, 0x756f7920,
|
||||
0x776f6420, 0x654e0a6e, 0x20726576,
|
||||
0x6e6e6f67, 0x75722061, 0x7261206e,
|
||||
0x646e756f, 0x646e6120, 0x73656420,
|
||||
0x20747265, 0x0a756f79, 0x6576654e,
|
||||
0x6f672072, 0x20616e6e, 0x656b616d,
|
||||
0x756f7920, 0x79726320, 0x76654e0a,
|
||||
0x67207265, 0x616e6e6f, 0x79617320,
|
||||
0x6f6f6720, 0x65796264, 0x76654e0a,
|
||||
0x67207265, 0x616e6e6f, 0x6c657420,
|
||||
0x2061206c, 0x2065696c, 0x20646e61
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user