Compare commits

...

10 Commits

Author SHA1 Message Date
Ben Kyd
e42048b369 some weird behaviour with the NRF not toggling the reset pin correctly 2023-06-23 23:38:36 +01:00
Ben Kyd
28728f90e5 SPI Functional 2023-06-19 01:00:33 +01:00
Ben Kyd
4a130a9e74 IT FUCKING WORKSSSSSSS 2023-06-18 20:29:00 +01:00
Ben Kyd
d4e84fe4cf About to reset my local repo 2023-06-18 20:13:28 +01:00
Ben Kyd
8985df0a6e Im not sure where i'm going wrong but SPI just won't work 2023-06-15 00:38:42 +01:00
Ben Kyd
984d2de97d epic 2023-06-05 23:05:59 +01:00
Ben Kyd
cd7c124e24 non functional spi 2023-06-04 20:03:53 +01:00
Ben Kyd
f51302bc0f remove log 2023-06-02 21:28:53 +01:00
Ben Kyd
2e07a22f41 super epic SPI 2023-06-02 21:27:52 +01:00
Ben Kyd
5f5dc5be2b zephyr UF2 -- This is the last pi pico prototype 2023-05-31 20:39:30 +01:00
13 changed files with 69561 additions and 62 deletions

View File

@@ -1,7 +1,16 @@
cmake_minimum_required(VERSION 3.20.0)
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${BOARD}.overlay")
set(mcuboot_DTC_OVERLAY_FILE "${CMAKE_CURRENT_SOURCE_DIR}/${BOARD}.overlay")
endif()
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
#
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2")
project(passr)
target_sources(app PRIVATE src/main.c)

View File

@@ -1,12 +1,13 @@
.ONESHELL:
TARGET=rpi_pico
TARGET=nrf52840dk_nrf52840
CMAKE_ZEPHYR_PATH=../zephyrproject/zephyr
CMAKE_ZEPHYR_COMMAND=west build
CMAKE_ZEPHYR_FLAGS=-b $(TARGET)
all: compile flash_pico
all: compile flash listen
cf: compile flash
setup:
west init
@@ -14,18 +15,17 @@ setup:
compile:
$(CMAKE_ZEPHYR_COMMAND) $(CMAKE_ZEPHYR_FLAGS)
cp build/zephyr/zephyr.uf2 ./zephyr.uf2
echo "Copied zephyr.uf2 to project root"
flash_pico:
# mount then copy the uf2
sudo mount -L RPI-RP2 /mnt
sudo cp zephyr.uf2 /mnt
echo "Copied zephyr.uf2 to pico"
flash: compile
cp build/zephyr/zephyr.hex ./zephyr.hex
echo "Copied zephyr.hex to project root"
nrfjprog -f nrf52 --program zephyr.hex --sectorerase --verify --reset
# FIXME: This is entirely board specific, for example the pi pico will vibe differently
flash:
west flash
listen: flash
minicom -D /dev/ttyACM0 -b 115200
com:
minicom -D /dev/ttyACM0 -b 115200
clean:
rm -rf build/

View File

@@ -0,0 +1,31 @@
&pinctrl {
spi_master_default: spi_master_default {
group1 {
psels = <NRF_PSEL(SPIM_SCK, 0, 31)>,
<NRF_PSEL(SPIM_MOSI, 0, 30)>,
<NRF_PSEL(SPIM_MISO, 0, 29)>;
};
};
spi_master_sleep: spi_master_sleep {
group1 {
psels = <NRF_PSEL(SPIM_SCK, 0, 31)>,
<NRF_PSEL(SPIM_MOSI, 0, 30)>,
<NRF_PSEL(SPIM_MISO, 0, 29)>;
low-power-enable;
};
};
};
spi_master: &spi3 {
compatible = "nordic,nrf-spim";
status = "okay";
pinctrl-0 = <&spi_master_default>;
pinctrl-1 = <&spi_master_sleep>;
pinctrl-names = "default", "sleep";
cs-gpios = <&gpio0 28 GPIO_ACTIVE_LOW>;
reg_spi_master: spi-dev-a@0 {
reg = <0>;
};
};

View File

@@ -1,5 +0,0 @@
west build -b adafruit_feather_nrf52840 .
# nrfutil dfu genpkg --application build/zephyr/zephyr.hex --application-version 0xFF --dev-revision 0xFF --dev-type 0xFFFF --sd-req 0x81 feather_nrf52840_express_bootloader-0.7.0_s140_6.1.1.zip
# nrfutil dfu usb-serial -pkg app.zip -p ttyACM0 // DO NOT FUCKING DO THIS
# ./uf2conv.py build/zephyr/zephyr.hex -c -f 0xADA52840
cp build/zephyr/zephyr.uf2 .

View File

@@ -1,20 +0,0 @@
{
"manifest": {
"dfu_version": 0.5,
"softdevice_bootloader": {
"bin_file": "sd_bl.bin",
"bl_size": 39000,
"dat_file": "sd_bl.dat",
"init_packet_data": {
"application_version": 4294967295,
"device_revision": 52840,
"device_type": 82,
"firmware_crc16": 40783,
"softdevice_req": [
65534
]
},
"sd_size": 151016
}
}
}

Binary file not shown.

Binary file not shown.

View File

@@ -1,4 +1,6 @@
CONFIG_BUILD_OUTPUT_UF2=y
CONFIG_GPIO=y
CONFIG_SPI=y
CONFIG_SPI_ASYNC=y
CONFIG_SPI_PL022_INTERRUPT=y
CONFIG_SPI_SLAVE=y

67497
spi.txt Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,45 +1,111 @@
#include <stdint.h>
#include <zephyr/kernel.h>
#include <zephyr/drivers/gpio.h>
#include <zephyr/device.h>
#include <zephyr/devicetree.h>
#include <zephyr/drivers/gpio.h>
#include <zephyr/drivers/spi.h>
// SPI Master Interface on SPI1 of the rp2040
const struct device* spi1_dev = DEVICE_DT_GET(DT_NODELABEL(spi1));
#include "nrf_gpio.h"
// SPI but broken out
#define EPD_RST_PIN = 12;
#define EEPD_DC_PIN = 8;
#define EEPD_BUSY_PIN = 13;
#define EEPD_CS_PIN = 9;
#define EEPD_CLK_PIN = 10;
#define EEPD_MOSI_PIN = 11;
/* 1000 msec = 1 sec */
#define SLEEP_TIME_MS 100
// GPIO - so we can have a status LED
/* The devicetree node identifier for the "led0" alias. */
#define LED0_NODE DT_ALIAS(led0)
#define SPI_MASTER DT_NODELABEL(spi_master)
#define RST_PAPER NRF_GPIO_PIN_MAP(0, 4)
// SPI
const struct device *spi_dev;
static struct k_poll_signal spi_done_sig = K_POLL_SIGNAL_INITIALIZER(spi_done_sig);
struct spi_cs_control spim_cs = {
.gpio = SPI_CS_GPIOS_DT_SPEC_GET(DT_NODELABEL(reg_spi_master)),
.delay = 0,
};
static void spi_init(void)
{
spi_dev = DEVICE_DT_GET(SPI_MASTER);
if(!device_is_ready(spi_dev)) {
printk("SPI master device not ready!\n");
}
if(!device_is_ready(spim_cs.gpio.port)){
printk("SPI master chip select device not ready!\n");
}
}
static const struct spi_config spi_cfg = {
.operation = SPI_WORD_SET(8) | SPI_TRANSFER_MSB,
.frequency = 4000000,
.slave = 0,
.cs = &spim_cs,
};
static int spi_write_8(uint8_t command) {
const struct spi_buf tx_buf = {
.buf = &command,
.len = sizeof(command)
};
const struct spi_buf_set tx = {
.buffers = &tx_buf,
.count = 1
};
k_poll_signal_reset(&spi_done_sig);
int error = spi_write(spi_dev, &spi_cfg, &tx);
if(error != 0){
printk("SPI write error: %i\n", error);
return error;
}
}
static int spi_write_buf(uint8_t* buf, int len) {
const struct spi_buf tx_buf = {
.buf = buf,
.len = len
};
const struct spi_buf_set tx = {
.buffers = &tx_buf,
.count = 1
};
k_poll_signal_reset(&spi_done_sig);
int error = spi_write(spi_dev, &spi_cfg, &tx);
if(error != 0){
printk("SPI write error: %i\n", error);
return error;
}
}
static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios);
void main(void)
{
while (!device_is_ready(spi1_dev)) {
}
if (!device_is_ready(led.port)) {
return;
}
int ret = gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE);
ret += nrf_gpio_cfg_output(RST_PAPER);
if (ret < 0) {
return;
}
while (1) {
ret = gpio_pin_toggle_dt(&led);
if (ret < 0) {
return;
}
k_msleep(500);
}
}
spi_init();
gpio_pin_set_dt(&rst, 0);
k_msleep(SLEEP_TIME_MS);
gpio_pin_set_dt(&rst, 1);
k_msleep(SLEEP_TIME_MS);
spi_write_8(0x12);
k_msleep(SLEEP_TIME_MS);
while (1) {
gpio_pin_toggle_dt(&led);
k_msleep(SLEEP_TIME_MS);
}
}

1919
zephyr.hex Normal file

File diff suppressed because it is too large Load Diff

Binary file not shown.