-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* initial SPI DMA support * spi dma: add dma channel update points * micropython spi test --------- Co-authored-by: Guy Sviry <[email protected]>
- Loading branch information
Showing
8 changed files
with
127 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { GPIOPinState, RP2040 } from '../src'; | ||
import { ConsoleLogger, LogLevel } from '../src/utils/logging'; | ||
import { bootromB1 } from '../demo/bootrom'; | ||
import { loadUF2, loadMicropythonFlashImage } from '../demo/load-flash'; | ||
import fs from 'fs'; | ||
import minimist from 'minimist'; | ||
|
||
const args = minimist(process.argv.slice(2)); | ||
|
||
const mcu = new RP2040(); | ||
mcu.loadBootrom(bootromB1); | ||
mcu.logger = new ConsoleLogger(LogLevel.Error); | ||
|
||
const imageName = 'micropython.uf2'; | ||
console.log(`Loading uf2 image ${imageName}`); | ||
loadUF2(imageName, mcu); | ||
|
||
const littlefs = 'littlefs-spi.img'; | ||
|
||
if (fs.existsSync(littlefs)) { | ||
console.log(`Loading littlefs image ${littlefs}`); | ||
loadMicropythonFlashImage(littlefs, mcu); | ||
} | ||
|
||
let spiBuf = ''; | ||
mcu.gpio[5].addListener((state: GPIOPinState, oldState: GPIOPinState) => { | ||
if (!spiBuf) { | ||
return; | ||
} | ||
|
||
if (state === GPIOPinState.High && oldState === GPIOPinState.Low) { | ||
if (spiBuf !== args._?.shift()) { | ||
console.log('SPI TEST FAILED.'); | ||
process.exit(1); | ||
} else { | ||
console.log('SPI MESSAGE RECEIVED.'); | ||
spiBuf = ''; | ||
} | ||
|
||
if (args._.length === 0) { | ||
console.log('SPI TEST PASSED.'); | ||
process.exit(0); | ||
} | ||
} | ||
}); | ||
|
||
mcu.spi[0].onTransmit = (char) => { | ||
spiBuf += String.fromCharCode(char); | ||
mcu.spi[0].completeTransmit(0); | ||
}; | ||
|
||
mcu.core.PC = 0x10000000; | ||
mcu.execute(); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from machine import Pin, SPI | ||
|
||
spi = SPI(0) | ||
cs = Pin(5, Pin.OUT) | ||
cs(1) | ||
|
||
spi.init(baudrate=10 * 1024 * 1024, polarity=0, phase=0) | ||
cs(0) | ||
spi.write(b'hello world') | ||
cs(1) | ||
|
||
cs(0) | ||
spi.write(b'h') | ||
cs(1) | ||
|
||
cs(0) | ||
spi.write(b'0123456789abcdef0123456789abcdef0123456789abcdef') | ||
cs(1) |
This file contains 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