rp2040js 1.3.3 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +128 -128
- package/dist/cjs/gdb/gdb-server.js +31 -31
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/peripherals/clocks.d.ts +11 -0
- package/dist/cjs/peripherals/clocks.js +108 -0
- package/dist/cjs/peripherals/pll.d.ts +25 -0
- package/dist/cjs/peripherals/pll.js +94 -0
- package/dist/cjs/peripherals/pwm.js +8 -5
- package/dist/cjs/peripherals/uart.d.ts +2 -0
- package/dist/cjs/peripherals/uart.js +7 -0
- package/dist/cjs/rp2040.d.ts +24 -0
- package/dist/cjs/rp2040.js +52 -3
- package/dist/cjs/utils/timer32.js +6 -0
- package/dist/esm/gdb/gdb-server.js +31 -31
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/peripherals/clocks.d.ts +11 -0
- package/dist/esm/peripherals/clocks.js +108 -0
- package/dist/esm/peripherals/pll.d.ts +25 -0
- package/dist/esm/peripherals/pll.js +90 -0
- package/dist/esm/peripherals/pwm.js +8 -5
- package/dist/esm/peripherals/uart.d.ts +2 -0
- package/dist/esm/peripherals/uart.js +7 -0
- package/dist/esm/rp2040.d.ts +24 -0
- package/dist/esm/rp2040.js +52 -3
- package/dist/esm/utils/timer32.js +6 -0
- package/package.json +88 -88
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2021 Uri Shaked
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
|
13
|
-
all copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
-
THE SOFTWARE.
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Uri Shaked
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,128 +1,128 @@
|
|
|
1
|
-
  
|
|
2
|
-
|
|
3
|
-
# rp2040js
|
|
4
|
-
|
|
5
|
-
Raspberry Pi Pico Emulator for the [Wokwi Simulation Platform](https://wokwi.com). It blinks, runs Arduino code, and even the MicroPython REPL!
|
|
6
|
-
|
|
7
|
-
## Online examples
|
|
8
|
-
|
|
9
|
-
If you are just looking to play around with the Raspberry Pi Pico Simulator, check out the Wokwi Simulator:
|
|
10
|
-
|
|
11
|
-
- [Raspberry Pi Pico Traffic Light](https://wokwi.com/arduino/projects/297322571959894536)
|
|
12
|
-
- [LCD1602 Hello World](https://wokwi.com/arduino/projects/297323005822894602)
|
|
13
|
-
- [MicroPython Blink](https://wokwi.com/arduino/projects/300504213470839309)
|
|
14
|
-
- [MicroPython 7-Segment Counter](https://wokwi.com/arduino/projects/300210834979684872)
|
|
15
|
-
|
|
16
|
-
For more information, take a look at the [wokwi-pi-pico docs](https://docs.wokwi.com/parts/wokwi-pi-pico) and the [Pi Pico MicroPython Guide](https://docs.wokwi.com/guides/micropython).
|
|
17
|
-
|
|
18
|
-
If you want to develop your own application using the Raspberry Pi Pico simulator, the following examples may be helpful:
|
|
19
|
-
|
|
20
|
-
- [Blink LEDs with RP2040js, from scratch](https://stackblitz.com/edit/rp2040js-blink?file=index.ts) - Press "Run" and patiently wait for the code to compile ;-)
|
|
21
|
-
|
|
22
|
-
## Run the demo project
|
|
23
|
-
|
|
24
|
-
### Native code
|
|
25
|
-
|
|
26
|
-
You'd need to get `hello_uart.hex` by building it from the [pico-examples repo](https://github.com/raspberrypi/pico-examples/tree/master/uart/hello_uart), then copy it to the rp2040js root directory and run:
|
|
27
|
-
|
|
28
|
-
```
|
|
29
|
-
npm install
|
|
30
|
-
npm start
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
You can also specify the path to the image on the command line and/or load an UF2 image:
|
|
34
|
-
|
|
35
|
-
```sh
|
|
36
|
-
npm run start -- --image ./my-pico-project.uf2
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
A GDB server will be available on port 3333, and the data written to UART0 will be printed
|
|
40
|
-
to the console.
|
|
41
|
-
|
|
42
|
-
### MicroPython code
|
|
43
|
-
|
|
44
|
-
To run the MicroPython demo, first download [RPI_PICO-20230426-v1.20.0.uf2](https://micropython.org/resources/firmware/RPI_PICO-20230426-v1.20.0.uf2), place it in the rp2040js root directory, then run:
|
|
45
|
-
|
|
46
|
-
```
|
|
47
|
-
npm install
|
|
48
|
-
npm run start:micropython
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
and enjoy the MicroPython REPL! Quit the REPL with Ctrl+X. A different MicroPython UF2 image can be loaded by supplying the `--image` option:
|
|
52
|
-
|
|
53
|
-
```
|
|
54
|
-
npm run start:micropython -- --image=my_image.uf2
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
A GDB server on port 3333 can be enabled by specifying the `--gdb` flag:
|
|
58
|
-
|
|
59
|
-
```
|
|
60
|
-
npm run start:micropython -- --gdb
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
For using the MicroPython demo code in tests, the `--expect-text` can come handy: it will look for the given text in the serial output and exit with code 0 if found, or 1 if not found. You can find an example in [the MicroPython CI test](./.github/workflows/ci-micropython.yml).
|
|
64
|
-
|
|
65
|
-
#### Filesystem support
|
|
66
|
-
|
|
67
|
-
With MicroPython, you can use the filesystem on the Pico. This becomes useful as more than one script file is used in your code. Just put a [LittleFS](https://github.com/littlefs-project/littlefs) formatted filesystem image called `littlefs.img` into the rp2040js root directory, and your `main.py` will be automatically started from there.
|
|
68
|
-
|
|
69
|
-
A simple way to create a suitable LittleFS image containing your script files is outlined in [create_littlefs_image.py](https://github.com/tomods/GrinderController/blob/358ad3e0f795d8cc0bdf4f21bb35f806871d433f/tools/create_littlefs_image.py).
|
|
70
|
-
So, using [littlefs-python](https://pypi.org/project/littlefs-python/), you can do the following:
|
|
71
|
-
|
|
72
|
-
```python
|
|
73
|
-
from littlefs import LittleFS
|
|
74
|
-
files = ['your.py', 'files.py', 'here.py', 'main.py']
|
|
75
|
-
output_image = 'output/littlefs.img' # symlinked/copied to rp2040js root directory
|
|
76
|
-
lfs = LittleFS(block_size=4096, block_count=352, prog_size=256)
|
|
77
|
-
for filename in files:
|
|
78
|
-
with open(filename, 'rb') as src_file, lfs.open(filename, 'w') as lfs_file:
|
|
79
|
-
lfs_file.write(src_file.read())
|
|
80
|
-
with open(output_image, 'wb') as fh:
|
|
81
|
-
fh.write(lfs.context.buffer)
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
Other ways of creating LittleFS images can be found [here](https://github.com/wokwi/littlefs-wasm) or [here](https://github.com/littlefs-project/littlefs#related-projects).
|
|
85
|
-
|
|
86
|
-
Currently, the filesystem is not writeable, as the SSI peripheral required for flash writing is not implemented yet. If you're interested in hacking, see the discussion in https://github.com/wokwi/rp2040js/issues/88 for a workaround.
|
|
87
|
-
|
|
88
|
-
### CircuitPython code
|
|
89
|
-
|
|
90
|
-
To run the CircuitPython demo, you can follow the directions above for MicroPython, except download [adafruit-circuitpython-raspberry_pi_pico-en_US-8.0.2.uf2](https://adafruit-circuit-python.s3.amazonaws.com/bin/raspberry_pi_pico/en_US/adafruit-circuitpython-raspberry_pi_pico-en_US-8.0.2.uf2) instead of the MicroPython UF2 file. Place it in the rp2040js root directory, then run:
|
|
91
|
-
|
|
92
|
-
```
|
|
93
|
-
npm install
|
|
94
|
-
npm run start:circuitpython
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
and start the CircuitPython REPL! The rest of the experience is the same as the MicroPython demo (Ctrl+X to exit, using the `--image` and
|
|
98
|
-
`--gdb` options, etc).
|
|
99
|
-
|
|
100
|
-
#### Filesystem support
|
|
101
|
-
|
|
102
|
-
For CircuitPython, you can create a FAT12 filesystem in Linux using the `truncate` and `mkfs.vfat` utilities:
|
|
103
|
-
|
|
104
|
-
```shell
|
|
105
|
-
truncate fat12.img -s 1M # make the image file
|
|
106
|
-
mkfs.vfat -F12 -S512 fat12.img # create the FAT12 filesystem
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
You can then mount the filesystem image and add files to it:
|
|
110
|
-
|
|
111
|
-
```shell
|
|
112
|
-
mkdir fat12 # create the mounting folder if needed
|
|
113
|
-
sudo mount -o loop fat12.img fat12/ # mount the filesystem to the folder
|
|
114
|
-
sudo cp code.py fat12/ # copy code.py to the filesystem
|
|
115
|
-
sudo umount fat12/ # unmount the filesystem
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
While CircuitPython does not typically use a writeable filesystem, note that this functionality is unavailable (see MicroPython filesystem
|
|
119
|
-
support section for more details).
|
|
120
|
-
|
|
121
|
-
## Learn more
|
|
122
|
-
|
|
123
|
-
- [Live-coding stream playlist](https://www.youtube.com/playlist?list=PLLomdjsHtJTxT-vdJHwa3z62dFXZnzYBm)
|
|
124
|
-
- [Hackaday project page](https://hackaday.io/project/177082-raspberry-pi-pico-emulator)
|
|
125
|
-
|
|
126
|
-
## License
|
|
127
|
-
|
|
128
|
-
Released under the MIT licence. Copyright (c) 2021-2023, Uri Shaked.
|
|
1
|
+
  
|
|
2
|
+
|
|
3
|
+
# rp2040js
|
|
4
|
+
|
|
5
|
+
Raspberry Pi Pico Emulator for the [Wokwi Simulation Platform](https://wokwi.com). It blinks, runs Arduino code, and even the MicroPython REPL!
|
|
6
|
+
|
|
7
|
+
## Online examples
|
|
8
|
+
|
|
9
|
+
If you are just looking to play around with the Raspberry Pi Pico Simulator, check out the Wokwi Simulator:
|
|
10
|
+
|
|
11
|
+
- [Raspberry Pi Pico Traffic Light](https://wokwi.com/arduino/projects/297322571959894536)
|
|
12
|
+
- [LCD1602 Hello World](https://wokwi.com/arduino/projects/297323005822894602)
|
|
13
|
+
- [MicroPython Blink](https://wokwi.com/arduino/projects/300504213470839309)
|
|
14
|
+
- [MicroPython 7-Segment Counter](https://wokwi.com/arduino/projects/300210834979684872)
|
|
15
|
+
|
|
16
|
+
For more information, take a look at the [wokwi-pi-pico docs](https://docs.wokwi.com/parts/wokwi-pi-pico) and the [Pi Pico MicroPython Guide](https://docs.wokwi.com/guides/micropython).
|
|
17
|
+
|
|
18
|
+
If you want to develop your own application using the Raspberry Pi Pico simulator, the following examples may be helpful:
|
|
19
|
+
|
|
20
|
+
- [Blink LEDs with RP2040js, from scratch](https://stackblitz.com/edit/rp2040js-blink?file=index.ts) - Press "Run" and patiently wait for the code to compile ;-)
|
|
21
|
+
|
|
22
|
+
## Run the demo project
|
|
23
|
+
|
|
24
|
+
### Native code
|
|
25
|
+
|
|
26
|
+
You'd need to get `hello_uart.hex` by building it from the [pico-examples repo](https://github.com/raspberrypi/pico-examples/tree/master/uart/hello_uart), then copy it to the rp2040js root directory and run:
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
npm install
|
|
30
|
+
npm start
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
You can also specify the path to the image on the command line and/or load an UF2 image:
|
|
34
|
+
|
|
35
|
+
```sh
|
|
36
|
+
npm run start -- --image ./my-pico-project.uf2
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
A GDB server will be available on port 3333, and the data written to UART0 will be printed
|
|
40
|
+
to the console.
|
|
41
|
+
|
|
42
|
+
### MicroPython code
|
|
43
|
+
|
|
44
|
+
To run the MicroPython demo, first download [RPI_PICO-20230426-v1.20.0.uf2](https://micropython.org/resources/firmware/RPI_PICO-20230426-v1.20.0.uf2), place it in the rp2040js root directory, then run:
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
npm install
|
|
48
|
+
npm run start:micropython
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
and enjoy the MicroPython REPL! Quit the REPL with Ctrl+X. A different MicroPython UF2 image can be loaded by supplying the `--image` option:
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
npm run start:micropython -- --image=my_image.uf2
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
A GDB server on port 3333 can be enabled by specifying the `--gdb` flag:
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
npm run start:micropython -- --gdb
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
For using the MicroPython demo code in tests, the `--expect-text` can come handy: it will look for the given text in the serial output and exit with code 0 if found, or 1 if not found. You can find an example in [the MicroPython CI test](./.github/workflows/ci-micropython.yml).
|
|
64
|
+
|
|
65
|
+
#### Filesystem support
|
|
66
|
+
|
|
67
|
+
With MicroPython, you can use the filesystem on the Pico. This becomes useful as more than one script file is used in your code. Just put a [LittleFS](https://github.com/littlefs-project/littlefs) formatted filesystem image called `littlefs.img` into the rp2040js root directory, and your `main.py` will be automatically started from there.
|
|
68
|
+
|
|
69
|
+
A simple way to create a suitable LittleFS image containing your script files is outlined in [create_littlefs_image.py](https://github.com/tomods/GrinderController/blob/358ad3e0f795d8cc0bdf4f21bb35f806871d433f/tools/create_littlefs_image.py).
|
|
70
|
+
So, using [littlefs-python](https://pypi.org/project/littlefs-python/), you can do the following:
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
from littlefs import LittleFS
|
|
74
|
+
files = ['your.py', 'files.py', 'here.py', 'main.py']
|
|
75
|
+
output_image = 'output/littlefs.img' # symlinked/copied to rp2040js root directory
|
|
76
|
+
lfs = LittleFS(block_size=4096, block_count=352, prog_size=256)
|
|
77
|
+
for filename in files:
|
|
78
|
+
with open(filename, 'rb') as src_file, lfs.open(filename, 'w') as lfs_file:
|
|
79
|
+
lfs_file.write(src_file.read())
|
|
80
|
+
with open(output_image, 'wb') as fh:
|
|
81
|
+
fh.write(lfs.context.buffer)
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Other ways of creating LittleFS images can be found [here](https://github.com/wokwi/littlefs-wasm) or [here](https://github.com/littlefs-project/littlefs#related-projects).
|
|
85
|
+
|
|
86
|
+
Currently, the filesystem is not writeable, as the SSI peripheral required for flash writing is not implemented yet. If you're interested in hacking, see the discussion in https://github.com/wokwi/rp2040js/issues/88 for a workaround.
|
|
87
|
+
|
|
88
|
+
### CircuitPython code
|
|
89
|
+
|
|
90
|
+
To run the CircuitPython demo, you can follow the directions above for MicroPython, except download [adafruit-circuitpython-raspberry_pi_pico-en_US-8.0.2.uf2](https://adafruit-circuit-python.s3.amazonaws.com/bin/raspberry_pi_pico/en_US/adafruit-circuitpython-raspberry_pi_pico-en_US-8.0.2.uf2) instead of the MicroPython UF2 file. Place it in the rp2040js root directory, then run:
|
|
91
|
+
|
|
92
|
+
```
|
|
93
|
+
npm install
|
|
94
|
+
npm run start:circuitpython
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
and start the CircuitPython REPL! The rest of the experience is the same as the MicroPython demo (Ctrl+X to exit, using the `--image` and
|
|
98
|
+
`--gdb` options, etc).
|
|
99
|
+
|
|
100
|
+
#### Filesystem support
|
|
101
|
+
|
|
102
|
+
For CircuitPython, you can create a FAT12 filesystem in Linux using the `truncate` and `mkfs.vfat` utilities:
|
|
103
|
+
|
|
104
|
+
```shell
|
|
105
|
+
truncate fat12.img -s 1M # make the image file
|
|
106
|
+
mkfs.vfat -F12 -S512 fat12.img # create the FAT12 filesystem
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
You can then mount the filesystem image and add files to it:
|
|
110
|
+
|
|
111
|
+
```shell
|
|
112
|
+
mkdir fat12 # create the mounting folder if needed
|
|
113
|
+
sudo mount -o loop fat12.img fat12/ # mount the filesystem to the folder
|
|
114
|
+
sudo cp code.py fat12/ # copy code.py to the filesystem
|
|
115
|
+
sudo umount fat12/ # unmount the filesystem
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
While CircuitPython does not typically use a writeable filesystem, note that this functionality is unavailable (see MicroPython filesystem
|
|
119
|
+
support section for more details).
|
|
120
|
+
|
|
121
|
+
## Learn more
|
|
122
|
+
|
|
123
|
+
- [Live-coding stream playlist](https://www.youtube.com/playlist?list=PLLomdjsHtJTxT-vdJHwa3z62dFXZnzYBm)
|
|
124
|
+
- [Hackaday project page](https://hackaday.io/project/177082-raspberry-pi-pico-emulator)
|
|
125
|
+
|
|
126
|
+
## License
|
|
127
|
+
|
|
128
|
+
Released under the MIT licence. Copyright (c) 2021-2023, Uri Shaked.
|
|
@@ -32,37 +32,37 @@ const registers = [
|
|
|
32
32
|
`name:pc;bitsize:32;offset:60;encoding:int;format:hex;set:General Purpose Registers;generic:pc;alt-name:r15;gcc:15;dwarf:15;`,
|
|
33
33
|
`name:cpsr;bitsize:32;offset:64;encoding:int;format:hex;set:General Purpose Registers;generic:flags;alt-name:psr;gcc:16;dwarf:16;`,
|
|
34
34
|
];
|
|
35
|
-
const targetXML = `<?xml version="1.0"?>
|
|
36
|
-
<!DOCTYPE target SYSTEM "gdb-target.dtd">
|
|
37
|
-
<target version="1.0">
|
|
38
|
-
<architecture>arm</architecture>
|
|
39
|
-
<feature name="org.gnu.gdb.arm.m-profile">
|
|
40
|
-
<reg name="r0" bitsize="32" regnum="0" save-restore="yes" type="int" group="general"/>
|
|
41
|
-
<reg name="r1" bitsize="32" regnum="1" save-restore="yes" type="int" group="general"/>
|
|
42
|
-
<reg name="r2" bitsize="32" regnum="2" save-restore="yes" type="int" group="general"/>
|
|
43
|
-
<reg name="r3" bitsize="32" regnum="3" save-restore="yes" type="int" group="general"/>
|
|
44
|
-
<reg name="r4" bitsize="32" regnum="4" save-restore="yes" type="int" group="general"/>
|
|
45
|
-
<reg name="r5" bitsize="32" regnum="5" save-restore="yes" type="int" group="general"/>
|
|
46
|
-
<reg name="r6" bitsize="32" regnum="6" save-restore="yes" type="int" group="general"/>
|
|
47
|
-
<reg name="r7" bitsize="32" regnum="7" save-restore="yes" type="int" group="general"/>
|
|
48
|
-
<reg name="r8" bitsize="32" regnum="8" save-restore="yes" type="int" group="general"/>
|
|
49
|
-
<reg name="r9" bitsize="32" regnum="9" save-restore="yes" type="int" group="general"/>
|
|
50
|
-
<reg name="r10" bitsize="32" regnum="10" save-restore="yes" type="int" group="general"/>
|
|
51
|
-
<reg name="r11" bitsize="32" regnum="11" save-restore="yes" type="int" group="general"/>
|
|
52
|
-
<reg name="r12" bitsize="32" regnum="12" save-restore="yes" type="int" group="general"/>
|
|
53
|
-
<reg name="sp" bitsize="32" regnum="13" save-restore="yes" type="data_ptr" group="general"/>
|
|
54
|
-
<reg name="lr" bitsize="32" regnum="14" save-restore="yes" type="int" group="general"/>
|
|
55
|
-
<reg name="pc" bitsize="32" regnum="15" save-restore="yes" type="code_ptr" group="general"/>
|
|
56
|
-
<reg name="xPSR" bitsize="32" regnum="16" save-restore="yes" type="int" group="general"/>
|
|
57
|
-
</feature>
|
|
58
|
-
<feature name="org.gnu.gdb.arm.m-system">
|
|
59
|
-
<reg name="msp" bitsize="32" regnum="17" save-restore="yes" type="data_ptr" group="system"/>
|
|
60
|
-
<reg name="psp" bitsize="32" regnum="18" save-restore="yes" type="data_ptr" group="system"/>
|
|
61
|
-
<reg name="primask" bitsize="1" regnum="19" save-restore="yes" type="int8" group="system"/>
|
|
62
|
-
<reg name="basepri" bitsize="8" regnum="20" save-restore="yes" type="int8" group="system"/>
|
|
63
|
-
<reg name="faultmask" bitsize="1" regnum="21" save-restore="yes" type="int8" group="system"/>
|
|
64
|
-
<reg name="control" bitsize="2" regnum="22" save-restore="yes" type="int8" group="system"/>
|
|
65
|
-
</feature>
|
|
35
|
+
const targetXML = `<?xml version="1.0"?>
|
|
36
|
+
<!DOCTYPE target SYSTEM "gdb-target.dtd">
|
|
37
|
+
<target version="1.0">
|
|
38
|
+
<architecture>arm</architecture>
|
|
39
|
+
<feature name="org.gnu.gdb.arm.m-profile">
|
|
40
|
+
<reg name="r0" bitsize="32" regnum="0" save-restore="yes" type="int" group="general"/>
|
|
41
|
+
<reg name="r1" bitsize="32" regnum="1" save-restore="yes" type="int" group="general"/>
|
|
42
|
+
<reg name="r2" bitsize="32" regnum="2" save-restore="yes" type="int" group="general"/>
|
|
43
|
+
<reg name="r3" bitsize="32" regnum="3" save-restore="yes" type="int" group="general"/>
|
|
44
|
+
<reg name="r4" bitsize="32" regnum="4" save-restore="yes" type="int" group="general"/>
|
|
45
|
+
<reg name="r5" bitsize="32" regnum="5" save-restore="yes" type="int" group="general"/>
|
|
46
|
+
<reg name="r6" bitsize="32" regnum="6" save-restore="yes" type="int" group="general"/>
|
|
47
|
+
<reg name="r7" bitsize="32" regnum="7" save-restore="yes" type="int" group="general"/>
|
|
48
|
+
<reg name="r8" bitsize="32" regnum="8" save-restore="yes" type="int" group="general"/>
|
|
49
|
+
<reg name="r9" bitsize="32" regnum="9" save-restore="yes" type="int" group="general"/>
|
|
50
|
+
<reg name="r10" bitsize="32" regnum="10" save-restore="yes" type="int" group="general"/>
|
|
51
|
+
<reg name="r11" bitsize="32" regnum="11" save-restore="yes" type="int" group="general"/>
|
|
52
|
+
<reg name="r12" bitsize="32" regnum="12" save-restore="yes" type="int" group="general"/>
|
|
53
|
+
<reg name="sp" bitsize="32" regnum="13" save-restore="yes" type="data_ptr" group="general"/>
|
|
54
|
+
<reg name="lr" bitsize="32" regnum="14" save-restore="yes" type="int" group="general"/>
|
|
55
|
+
<reg name="pc" bitsize="32" regnum="15" save-restore="yes" type="code_ptr" group="general"/>
|
|
56
|
+
<reg name="xPSR" bitsize="32" regnum="16" save-restore="yes" type="int" group="general"/>
|
|
57
|
+
</feature>
|
|
58
|
+
<feature name="org.gnu.gdb.arm.m-system">
|
|
59
|
+
<reg name="msp" bitsize="32" regnum="17" save-restore="yes" type="data_ptr" group="system"/>
|
|
60
|
+
<reg name="psp" bitsize="32" regnum="18" save-restore="yes" type="data_ptr" group="system"/>
|
|
61
|
+
<reg name="primask" bitsize="1" regnum="19" save-restore="yes" type="int8" group="system"/>
|
|
62
|
+
<reg name="basepri" bitsize="8" regnum="20" save-restore="yes" type="int8" group="system"/>
|
|
63
|
+
<reg name="faultmask" bitsize="1" regnum="21" save-restore="yes" type="int8" group="system"/>
|
|
64
|
+
<reg name="control" bitsize="2" regnum="22" save-restore="yes" type="int8" group="system"/>
|
|
65
|
+
</feature>
|
|
66
66
|
</target>`;
|
|
67
67
|
const LOG_NAME = 'GDBServer';
|
|
68
68
|
class GDBServer {
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export { I2CMode, I2CSpeed, RPI2C } from './peripherals/i2c.js';
|
|
|
5
5
|
export { BasePeripheral, type Peripheral } from './peripherals/peripheral.js';
|
|
6
6
|
export { RPPIO, StateMachine } from './peripherals/pio.js';
|
|
7
7
|
export { RPUSBController } from './peripherals/usb.js';
|
|
8
|
-
export { RP2040 } from './rp2040.js';
|
|
8
|
+
export { RP2040, type ClockListener } from './rp2040.js';
|
|
9
9
|
export { Simulator } from './simulator.js';
|
|
10
10
|
export { USBCDC } from './usb/cdc.js';
|
|
11
11
|
export { DataDirection, DescriptorType, SetupRecipient, SetupRequest, SetupType, type ISetupPacketParams, } from './usb/interfaces.js';
|
|
@@ -22,6 +22,17 @@ export declare class RPClocks extends BasePeripheral implements Peripheral {
|
|
|
22
22
|
rtcCtrl: number;
|
|
23
23
|
rtcDiv: number;
|
|
24
24
|
constructor(rp2040: RP2040, name: string);
|
|
25
|
+
/** clk_ref frequency, in Hz. GPIN0/GPIN1 are not modelled and yield 0. */
|
|
26
|
+
get refFreq(): number;
|
|
27
|
+
/** clk_sys frequency, in Hz. GPIN0/GPIN1 are not modelled and yield 0. */
|
|
28
|
+
get sysFreq(): number;
|
|
29
|
+
/**
|
|
30
|
+
* clk_peri frequency, in Hz. Feeds the UART and SPI baud rate generators. Returns 0 while
|
|
31
|
+
* the clock generator is stopped, and for the GPIN0/GPIN1 sources we do not model.
|
|
32
|
+
*/
|
|
33
|
+
get periFreq(): number;
|
|
34
|
+
private get refSourceFreq();
|
|
35
|
+
private get sysSourceFreq();
|
|
25
36
|
readUint32(offset: number): number;
|
|
26
37
|
writeUint32(offset: number, value: number): void;
|
|
27
38
|
}
|
|
@@ -34,6 +34,44 @@ const CLK_RTC_DIV = 0x70;
|
|
|
34
34
|
const CLK_RTC_SELECTED = 0x74;
|
|
35
35
|
const CLK_SYS_RESUS_CTRL = 0x78;
|
|
36
36
|
const CLK_SYS_RESUS_STATUS = 0x7c;
|
|
37
|
+
// CLK_REF_CTRL
|
|
38
|
+
const CLK_REF_CTRL_SRC_MASK = 0x3;
|
|
39
|
+
const CLK_REF_CTRL_SRC_ROSC = 0x0;
|
|
40
|
+
const CLK_REF_CTRL_SRC_AUX = 0x1;
|
|
41
|
+
const CLK_REF_CTRL_SRC_XOSC = 0x2;
|
|
42
|
+
const CLK_REF_CTRL_AUXSRC_SHIFT = 5;
|
|
43
|
+
const CLK_REF_CTRL_AUXSRC_MASK = 0x3;
|
|
44
|
+
const CLK_REF_CTRL_AUXSRC_PLL_USB = 0x0;
|
|
45
|
+
// CLK_REF_DIV has no fractional part, only INT (bits 9:8)
|
|
46
|
+
const CLK_REF_DIV_INT_BITS = 0x300;
|
|
47
|
+
// CLK_SYS_CTRL
|
|
48
|
+
const CLK_SYS_CTRL_SRC_MASK = 0x1;
|
|
49
|
+
const CLK_SYS_CTRL_SRC_REF = 0x0;
|
|
50
|
+
const CLK_SYS_CTRL_AUXSRC_SHIFT = 5;
|
|
51
|
+
const CLK_SYS_CTRL_AUXSRC_MASK = 0x7;
|
|
52
|
+
const CLK_SYS_CTRL_AUXSRC_PLL_SYS = 0x0;
|
|
53
|
+
const CLK_SYS_CTRL_AUXSRC_PLL_USB = 0x1;
|
|
54
|
+
const CLK_SYS_CTRL_AUXSRC_ROSC = 0x2;
|
|
55
|
+
const CLK_SYS_CTRL_AUXSRC_XOSC = 0x3;
|
|
56
|
+
// CLK_PERI_CTRL. clk_peri has no SRC mux and no divider: it is driven straight from AUXSRC,
|
|
57
|
+
// which uses its own encoding (not the CLK_SYS one).
|
|
58
|
+
const CLK_PERI_CTRL_ENABLE = 1 << 11;
|
|
59
|
+
const CLK_PERI_CTRL_KILL = 1 << 10;
|
|
60
|
+
const CLK_PERI_CTRL_AUXSRC_SHIFT = 5;
|
|
61
|
+
const CLK_PERI_CTRL_AUXSRC_MASK = 0x7;
|
|
62
|
+
const CLK_PERI_CTRL_AUXSRC_CLK_SYS = 0x0;
|
|
63
|
+
const CLK_PERI_CTRL_AUXSRC_PLL_SYS = 0x1;
|
|
64
|
+
const CLK_PERI_CTRL_AUXSRC_PLL_USB = 0x2;
|
|
65
|
+
const CLK_PERI_CTRL_AUXSRC_ROSC = 0x3;
|
|
66
|
+
const CLK_PERI_CTRL_AUXSRC_XOSC = 0x4;
|
|
67
|
+
// CLK_x_DIV: 24.8 fixed point (INT bits 31:8, FRAC bits 7:0)
|
|
68
|
+
const CLK_DIV_INT_SHIFT = 8;
|
|
69
|
+
const CLK_DIV_FRAC_MASK = 0xff;
|
|
70
|
+
/** Decodes a CLK_x_DIV register value. INT = 0 means divide by 2^16. */
|
|
71
|
+
function clockDivisor(div) {
|
|
72
|
+
const int = div >>> CLK_DIV_INT_SHIFT;
|
|
73
|
+
return int ? int + (div & CLK_DIV_FRAC_MASK) / 256 : 0x10000;
|
|
74
|
+
}
|
|
37
75
|
class RPClocks extends peripheral_js_1.BasePeripheral {
|
|
38
76
|
constructor(rp2040, name) {
|
|
39
77
|
super(rp2040, name);
|
|
@@ -58,6 +96,71 @@ class RPClocks extends peripheral_js_1.BasePeripheral {
|
|
|
58
96
|
this.rtcCtrl = 0;
|
|
59
97
|
this.rtcDiv = 0x100;
|
|
60
98
|
}
|
|
99
|
+
/** clk_ref frequency, in Hz. GPIN0/GPIN1 are not modelled and yield 0. */
|
|
100
|
+
get refFreq() {
|
|
101
|
+
return this.refSourceFreq / clockDivisor(this.refDiv & CLK_REF_DIV_INT_BITS);
|
|
102
|
+
}
|
|
103
|
+
/** clk_sys frequency, in Hz. GPIN0/GPIN1 are not modelled and yield 0. */
|
|
104
|
+
get sysFreq() {
|
|
105
|
+
return this.sysSourceFreq / clockDivisor(this.sysDiv);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* clk_peri frequency, in Hz. Feeds the UART and SPI baud rate generators. Returns 0 while
|
|
109
|
+
* the clock generator is stopped, and for the GPIN0/GPIN1 sources we do not model.
|
|
110
|
+
*/
|
|
111
|
+
get periFreq() {
|
|
112
|
+
const { rp2040 } = this;
|
|
113
|
+
if (!(this.periCtrl & CLK_PERI_CTRL_ENABLE) || this.periCtrl & CLK_PERI_CTRL_KILL) {
|
|
114
|
+
return 0;
|
|
115
|
+
}
|
|
116
|
+
switch ((this.periCtrl >>> CLK_PERI_CTRL_AUXSRC_SHIFT) & CLK_PERI_CTRL_AUXSRC_MASK) {
|
|
117
|
+
case CLK_PERI_CTRL_AUXSRC_CLK_SYS:
|
|
118
|
+
return this.sysFreq;
|
|
119
|
+
case CLK_PERI_CTRL_AUXSRC_PLL_SYS:
|
|
120
|
+
return rp2040.pllSys.frequency;
|
|
121
|
+
case CLK_PERI_CTRL_AUXSRC_PLL_USB:
|
|
122
|
+
return rp2040.pllUsb.frequency;
|
|
123
|
+
case CLK_PERI_CTRL_AUXSRC_ROSC:
|
|
124
|
+
return rp2040.roscFreq;
|
|
125
|
+
case CLK_PERI_CTRL_AUXSRC_XOSC:
|
|
126
|
+
return rp2040.xoscFreq;
|
|
127
|
+
default:
|
|
128
|
+
return 0;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
get refSourceFreq() {
|
|
132
|
+
const { rp2040 } = this;
|
|
133
|
+
switch (this.refCtrl & CLK_REF_CTRL_SRC_MASK) {
|
|
134
|
+
case CLK_REF_CTRL_SRC_ROSC:
|
|
135
|
+
return rp2040.roscFreq;
|
|
136
|
+
case CLK_REF_CTRL_SRC_XOSC:
|
|
137
|
+
return rp2040.xoscFreq;
|
|
138
|
+
case CLK_REF_CTRL_SRC_AUX: {
|
|
139
|
+
const auxsrc = (this.refCtrl >>> CLK_REF_CTRL_AUXSRC_SHIFT) & CLK_REF_CTRL_AUXSRC_MASK;
|
|
140
|
+
return auxsrc === CLK_REF_CTRL_AUXSRC_PLL_USB ? rp2040.pllUsb.frequency : 0;
|
|
141
|
+
}
|
|
142
|
+
default:
|
|
143
|
+
return 0;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
get sysSourceFreq() {
|
|
147
|
+
const { rp2040 } = this;
|
|
148
|
+
if ((this.sysCtrl & CLK_SYS_CTRL_SRC_MASK) === CLK_SYS_CTRL_SRC_REF) {
|
|
149
|
+
return this.refFreq;
|
|
150
|
+
}
|
|
151
|
+
switch ((this.sysCtrl >>> CLK_SYS_CTRL_AUXSRC_SHIFT) & CLK_SYS_CTRL_AUXSRC_MASK) {
|
|
152
|
+
case CLK_SYS_CTRL_AUXSRC_PLL_SYS:
|
|
153
|
+
return rp2040.pllSys.frequency;
|
|
154
|
+
case CLK_SYS_CTRL_AUXSRC_PLL_USB:
|
|
155
|
+
return rp2040.pllUsb.frequency;
|
|
156
|
+
case CLK_SYS_CTRL_AUXSRC_ROSC:
|
|
157
|
+
return rp2040.roscFreq;
|
|
158
|
+
case CLK_SYS_CTRL_AUXSRC_XOSC:
|
|
159
|
+
return rp2040.xoscFreq;
|
|
160
|
+
default:
|
|
161
|
+
return 0;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
61
164
|
readUint32(offset) {
|
|
62
165
|
switch (offset) {
|
|
63
166
|
case CLK_GPOUT0_CTRL:
|
|
@@ -155,18 +258,23 @@ class RPClocks extends peripheral_js_1.BasePeripheral {
|
|
|
155
258
|
break;
|
|
156
259
|
case CLK_REF_CTRL:
|
|
157
260
|
this.refCtrl = value;
|
|
261
|
+
this.rp2040.updateClocks();
|
|
158
262
|
break;
|
|
159
263
|
case CLK_REF_DIV:
|
|
160
264
|
this.refDiv = value;
|
|
265
|
+
this.rp2040.updateClocks();
|
|
161
266
|
break;
|
|
162
267
|
case CLK_SYS_CTRL:
|
|
163
268
|
this.sysCtrl = value;
|
|
269
|
+
this.rp2040.updateClocks();
|
|
164
270
|
break;
|
|
165
271
|
case CLK_SYS_DIV:
|
|
166
272
|
this.sysDiv = value;
|
|
273
|
+
this.rp2040.updateClocks();
|
|
167
274
|
break;
|
|
168
275
|
case CLK_PERI_CTRL:
|
|
169
276
|
this.periCtrl = value;
|
|
277
|
+
this.rp2040.updateClocks();
|
|
170
278
|
break;
|
|
171
279
|
case CLK_PERI_DIV:
|
|
172
280
|
this.periDiv = value;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { BasePeripheral, Peripheral } from './peripheral.js';
|
|
2
|
+
/**
|
|
3
|
+
* RP2040 PLL peripheral.
|
|
4
|
+
*
|
|
5
|
+
* Always reports locked (we have no startup delay to model), and computes its output
|
|
6
|
+
* frequency from the divider registers:
|
|
7
|
+
*
|
|
8
|
+
* f_out = (f_ref / REFDIV * FBDIV) / (POSTDIV1 * POSTDIV2)
|
|
9
|
+
*
|
|
10
|
+
* The frequency is what makes `RP2040.clkSys` follow `set_sys_clock_khz()` and friends.
|
|
11
|
+
*/
|
|
12
|
+
export declare class RPPLL extends BasePeripheral implements Peripheral {
|
|
13
|
+
private cs;
|
|
14
|
+
private pwr;
|
|
15
|
+
private fbdivInt;
|
|
16
|
+
private prim;
|
|
17
|
+
get refdiv(): number;
|
|
18
|
+
get fbdiv(): number;
|
|
19
|
+
get postdiv1(): number;
|
|
20
|
+
get postdiv2(): number;
|
|
21
|
+
/** PLL output frequency, in Hz, derived from the current register values. */
|
|
22
|
+
get frequency(): number;
|
|
23
|
+
readUint32(offset: number): number;
|
|
24
|
+
writeUint32(offset: number, value: number): void;
|
|
25
|
+
}
|