You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The repository contains a set of utilities, structured for use with the Raspberry Pico SDK. This are target a new or unique functionality not fully supported by the standard ```pico-sdk``` yet, or that are unique to SparkFun Boards.
4
4
5
-
## The sparkfun_pico CMake library
5
+
## Using The sparkfun_pico CMake library
6
6
7
7
A majority of the functionality outlined in this repository is contained in the folder ```sparkfun_pico```. This folder is structured as a ```cmake``` library, ready for use by the ```pico-sdk``` build environment.
8
8
9
-
### General Use
9
+
### Add sparkfun_pico Library to a pico-sdk Project
10
10
11
-
For a majority of the examples provided in this repository - especially those related to the use of PSRAM on the RP2350 - the following steps are used to build the examples:
11
+
To use the library as part of the cmake build process of the ```pico-sdk```, perform the following:
12
12
13
-
* Clone this repository
13
+
* Clone this repository to some directory ($SRC_DIR)
14
14
* CD into the cloned repository
15
-
* Checkout the submodules in the repository (```git submodule update --init --recursive```)
16
-
* For an example that uses the ```sparkfun_pico``` library, copy ```sparkfun_pico``` folder in this repository to the example folder. (```cd examples/myexample; cp -R ../../sparkfun_pico .```)
* Copy the ```sparkfun_pico``` folder in this repository to the project folder.
25
+
26
+
```sh
27
+
cd myproject
28
+
cp -R $SRC_DIR/sparkfun-pico/sparkfun_pico .
29
+
```
30
+
31
+
* Add the sparkfun_pico library to your projects ```CMakeLists.txt``` file using the following line:
32
+
33
+
```cmake
34
+
add_subdirectory(sparkfun_pico)
35
+
```
36
+
37
+
### Replacing the Integrated Memory Allocator Routines
38
+
39
+
One option the sparkfun_pico library provides is replacing the default allocator in the pico-sdk and it's associated members (```malloc, free, ...```) with a version that access both the build heap SRAM and PSRAM. This leverages the ***wrap*** functionality provided by the ```pico-sdk```.
40
+
41
+
To enable this functionality, the following lines are added to your projects CMakeLists.txt file.
42
+
43
+
```cmake
44
+
# use our own allocator
45
+
46
+
# the following enables the system malloc/free to be wrapped
47
+
set(SKIP_PICO_MALLOC 1)
48
+
49
+
# the following enables wrapping in sparkfun_pico builds
50
+
set(SFE_PICO_ALLOC_WRAP 1)
51
+
52
+
# the following enables the system malloc/free to be wrapped during compilation
53
+
add_definitions(-DSFE_PICO_ALLOC_WRAP)
54
+
```
55
+
56
+
> [!NOTE]
57
+
> These lines must be added before the include of the pico-sdk file ```pico_sdk_import.cmake```
58
+
59
+
Once setup in the CMakeFiles.txt file, the resulting firmware will use all available PSRAM and SRAM via the standard allocator API (malloc, free, calloc, realloc ).
60
+
61
+
The example [all_allocator](examples/all_allocator) shows how to use this functionality.
62
+
63
+
### Board File
64
+
65
+
The sparkfun_pico library also includes a board file that includes board specific defines that are not part of the standard pico-sdk board files.
66
+
67
+
Currently this is just the PIN used as CS for the PSRAM on sparkfun RP2350 boards.
68
+
69
+
Example:
70
+
71
+
```c
72
+
// For the pro micro rp2350
73
+
#defineSFE_RP2350_XIP_CSI_PIN 19
74
+
```
75
+
76
+
The file settings key off the board #defined set during the build process.
77
+
78
+
Mostly the use of this board file is automatic, not requiring direct access, but when using the raw PSRAM detection functionality, the required value of the PSRAM CS pin is obtained by including the file ```sparkfun_pico/sfe_pico_boards.h```, and defining a supported board in your cmake command.
79
+
80
+
```sh
81
+
cmake .. -DPICO_BOARD=sparkfun_promicro_rp2350
82
+
```
83
+
84
+
### Examples - General Use
85
+
86
+
For a majority of the examples provided in this repository - especially those related to the use of PSRAM on the RP2350 - the following steps are used to build the examples:
87
+
88
+
* Clone and setup this repo as noted above
89
+
* Copy in the ```sparkfun_pico``` library as noted above
17
90
18
91
At this point, the examples are built following the standard ```pico-sdk``` build process.
19
92
20
-
>>[!NOTE]
21
-
>>Specify the target SparkFun Board when calling cmake.
93
+
>[!NOTE]
94
+
> Specify the target SparkFun Board when calling cmake.
The sparkfun_pico library supports the following functions:
107
+
108
+
### PSRAM detection
109
+
110
+
> [!NOTE]
111
+
> SparkFun RP2350 boards the PSRAM IC detailed [here](https://cdn.sparkfun.com/assets/0/a/3/d/e/APS6404L_3SQR_Datasheet.pdf)
112
+
113
+
These functions are exported from the file [sfe_psram.h](sparkfun_pico/sfe_psram.h)
114
+
115
+
```C
116
+
size_tsfe_setup_psram(uint32_t psram_cs_pin);
117
+
```
118
+
119
+
This function is used to detect the presence of PSRAM on the board and return the size of the PSRAM available. If no PSRAM is detected, a value of ```0``` is returned.
120
+
121
+
|Parameter|Description|
122
+
|---|---|
123
+
|psram_cs_pin| The CS pin used by the PSRAM IC on the board|
124
+
125
+
Additionally, if PSRAM is detected, it is setup correctly for use by the RP2350.
126
+
127
+
## The Examples
32
128
33
129
This repository contains the following examples:
34
130
35
-
####[has_psram](examples/has_psram)
131
+
### [has_psram](examples/has_psram)
36
132
37
133
One of the more simple examples, this example shows how to detect if PSRAM is on the rp2350 board, and the size of the PSRAM available. It also walks through the available PSRAM, manually setting and verifying values.
38
134
39
-
####[psram_allocator](examples/psram_allocator)
135
+
### [psram_allocator](examples/psram_allocator)
40
136
41
137
This example detects the PSRAM available on the board, and adds it to an allocator, which manages the *allocation* of the PSRAM. PSRAM is accessed (allocated) using a provided API, which mimics the standard malloc/free functionality.
42
138
43
139
A "Two-Level Segregated Fit" (flsf) allocator is used from [here](https://github.com/espressif/tlsf).
44
140
45
-
####[all_allocator](examples/all_allocator)
141
+
### [all_allocator](examples/all_allocator)
46
142
47
143
This example detects the PSRAM available on the board, and adds it as well as the built in SRAM based heap to an allocator to provide an unified access to available memory. The allocator manages the *allocation* of the PSRAM and heap SRAM via a single API. The example also ```wraps``` the built in ```malloc``` and ```free``` suite of commands to integrate with existing examples and uses.
48
144
49
145
A "Two-Level Segregated Fit" (flsf) allocator is used from [here](https://github.com/espressif/tlsf).
50
146
51
-
####[set_qflash](examples/set_qflash)
147
+
### [set_qflash](examples/set_qflash)
52
148
53
149
This is a simple example that is used to verify the Quad SPI bit is set in the flash IC used on the attached board. It doesn't require the use of the ```sparkfun_pico``` library, but is helpful during board development and fits with the goals of this repository.
0 commit comments