Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ BINDIR = $(PREFIX)/bin
SRCDIR = src
BUILDDIR = build
MKDIR = mkdir -p
LDFLAGS =

DEVICES = $(BUILDDIR)/devices/dspic33e.o \
$(BUILDDIR)/devices/dspic33f.o \
Expand All @@ -28,21 +29,24 @@ raspberrypi: CFLAGS += -DBOARD_RPI
raspberrypi2: CFLAGS += -DBOARD_RPI2
raspberrypi4: CFLAGS += -DBOARD_RPI4
am335x: CFLAGS += -DBOARD_AM335X
rk3399: CFLAGS += -DBOARD_RK3399
rk3399: LDFLAGS += -L/usr/lib -l:libwiringx.a

default:
@echo "Please specify a target with 'make raspberrypi', 'make a10' or 'make am335x'."
@echo "Please specify a target with 'make raspberrypi', 'make a10', 'make am335x', or 'make rk3399'."

raspberrypi: prepare picberry
raspberrypi2: prepare picberry
raspberrypi4: prepare picberry
a10: prepare picberry
rk3399: prepare picberry
am335x: prepare picberry gpio_test

prepare:
$(MKDIR) $(BUILDDIR)/devices

picberry: $(BUILDDIR)/inhx.o $(DEVICES) $(BUILDDIR)/picberry.o
$(CC) $(CFLAGS) -o $(TARGET) $(BUILDDIR)/inhx.o $(DEVICES) $(BUILDDIR)/picberry.o
$(CC) $(CFLAGS) -o $(TARGET) $(BUILDDIR)/inhx.o $(DEVICES) $(BUILDDIR)/picberry.o $(LDFLAGS)

gpio_test: $(BUILDDIR)/gpio_test.o
$(CC) $(CFLAGS) -o gpio_test $(BUILDDIR)/gpio_test.o
Expand Down
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ It theorically supports dsPIC33E/PIC24E, dsPIC33F/PIC24H, PIC24FJ, PIC18FxxJxx,
- the [Raspberry Pi](https://www.raspberrypi.org/)
- Allwinner A10-based boards (like the [Cubieboard](http://cubieboard.org/))
- TI AM335x-based boards (like the [Beaglebone Black](https://beagleboard.org/black) or the [AM3359 ICEv2](http://www.ti.com/tool/tmdsice3359)).
- RK3399 based boards (like Radxa's [RockPi4(A/B/B+/C)](https://rockpi.org/rockpi4))

Support for additional boards and processors can be easily added, providing the following macro in a header file inside the _hosts_ folder:

Expand Down Expand Up @@ -54,16 +55,38 @@ To build picberry launch `make TARGET`, where _TARGET_ can be one of the followi
| ------------- | ------------------------------------------ |
| raspberrypi | Raspberry Pi v1 or Zero |
| raspberrypi2 | Raspberry Pi v2 or v3 |
| raspberrypi4 | Raspberry Pi 4A or 4B or CM4
| raspberrypi4 | Raspberry Pi 4A or 4B or CM4 |
| am335x | Boards based on TI AM335x (BeagleBone) |
| a10 | Boards based on Allwinner A10 (Cubieboard) |
| rk3399 | Boards based on Rockchip RK3399 (RockPi) |

Then launch `sudo make install` to install it to /usr/bin.

To change destination prefix use PREFIX=, e.g. `sudo make install PREFIX=/usr/local`.

For cross-compilation, given that you have the required cross toolchain in you PATH, simply export the `CROSS_COMPILE` variable before launching `make`, e.g. `CROSS_COMPILE=arm-linux-gnueabihf- make raspberrypi2`.

### Note about rk3399 target

To build for rk3399-based boards, you must install the static library for [wiringX](https://github.com/wiringX/wiringX).

```bash
sudo apt-get update && sudo apt-get install -y build-essential cmake
BRANCH=rk3399 # use this branch until it has been merged into master, at which point use 'master'
cd ~/tmp
wget https://github.com/wiringX/wiringX/archive/refs/heads/${BRANCH}.zip
unzip ${BRANCH}.zip
cd wiringX-${BRANCH}
mkdir build
cd build
cmake ..
make
cpack -G DEB
sudo dpkg -i libwiringx*.deb
```

After running these commands, you should have the static library `libwiringx.a` available at `/usr/lib/`.

## Using picberry

picberry [options]
Expand Down
2 changes: 2 additions & 0 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include "hosts/rpi4.h"
#elif defined(BOARD_AM335X)
#include "hosts/am335x.h"
#elif defined(BOARD_RK3399)
#include "hosts/rk3399.h"
#endif

#include "devices/device.h"
Expand Down
44 changes: 44 additions & 0 deletions src/hosts/rk3399.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Raspberry Pi PIC Programmer using GPIO connector
* https://github.com/WallaceIT/picberry
* Copyright 2016 Francesco Valla
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "wiringx.h"
#include <stdio.h>
/* GPIO registers address */
#define GPIO_BASE 0x00000000
#define PORTOFFSET 0

/* GPIO setup macros. Always use GPIO_IN(x) before using GPIO_OUT(x) */
#define GPIO_IN(g) (pinMode(g, PINMODE_INPUT))
#define GPIO_OUT(g) (pinMode(g, PINMODE_OUTPUT))

#define GPIO_SET(g) (digitalWrite(g, HIGH))
#define GPIO_CLR(g) (digitalWrite(g, LOW))
#define GPIO_LEV(g) (digitalRead(g)) & 0x1

/* default GPIO <-> PIC connections */
// To override, give the CLI option: -g PGC,PGD,MCLR

// For RockPi4, these gpio #'s correspond to pin #'s 33, 35, 37.
// see: https://wiki.radxa.com/Rockpi4/hardware/gpio
#define DEFAULT_PIC_CLK 76 /* PGC - Output */
#define DEFAULT_PIC_DATA 133 /* PGD - I/O */
#define DEFAULT_PIC_MCLR 158 /* MCLR - Output */

#define WIRINGX_PLATFORM "rock4"
27 changes: 24 additions & 3 deletions src/picberry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@
#include "devices/pic24fjxxxga2_gb2.h"
#include "devices/pic24fxxka1xx.h"


#if defined(BOARD_RK3399)
#include "wiringx.h"
#endif

int mem_fd;
void *gpio_map;
volatile uint32_t *gpio;
Expand Down Expand Up @@ -209,9 +214,15 @@ int main(int argc, char *argv[])
<< endl;
exit(0);
}
#if defined(BOARD_RK3399)
pic_clk = (pic_clk_port-'A');
pic_data = (pic_data_port-'A');
pic_mclr = (pic_mclr_port-'A');
#else
pic_clk |= ((pic_clk_port-'A')*PORTOFFSET)<<8;
pic_data |= ((pic_data_port-'A')*PORTOFFSET)<<8;
pic_mclr |= ((pic_mclr_port-'A')*PORTOFFSET)<<8;
#endif
}
}

Expand Down Expand Up @@ -374,6 +385,10 @@ int main(int argc, char *argv[])
/* Set up a memory regions to access GPIO */
void setup_io(void)
{

#if defined(BOARD_RK3399)
wiringXSetup(WIRINGX_PLATFORM, NULL);
#else
/* open /dev/mem */
mem_fd = open("/dev/mem", O_RDWR|O_SYNC);
if (mem_fd == -1) {
Expand All @@ -391,6 +406,8 @@ void setup_io(void)

/* Always use volatile pointer! */
gpio = (volatile uint32_t *) gpio_map;

#endif

GPIO_IN(pic_clk); // NOTE: MUST use GPIO_IN before GPIO_OUT
GPIO_OUT(pic_clk);
Expand All @@ -408,12 +425,15 @@ void setup_io(void)

/* Release GPIO memory region */
void close_io(void)
{
{
#if defined(BOARD_RK3399)
GPIO_IN(pic_mclr);
return;
#else
int ret;

/* MCLR as input, puts the output driver in Hi-Z */
GPIO_IN(pic_mclr);

/* munmap GPIO */
ret = munmap(gpio_map, BLOCK_SIZE);
if (ret == -1) {
Expand All @@ -427,6 +447,7 @@ void close_io(void)
perror("Cannot close /dev/mem");
exit(1);
}
#endif
}

/* reset the device */
Expand Down