sdcard stuff, remove unused board

This commit is contained in:
saji 2024-04-02 00:06:19 -05:00
parent 4ea1463044
commit 79fcfc4283
16 changed files with 246 additions and 181 deletions

View file

@ -5,8 +5,10 @@
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
cmake_minimum_required(VERSION 3.13.1) cmake_minimum_required(VERSION 3.13.1)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(app LANGUAGES C) project(app LANGUAGES C)
target_include_directories(app PRIVATE inc)
target_sources(app PRIVATE src/main.c src/canlog.c)
target_sources(app PRIVATE src/main.c)

View file

@ -13,7 +13,6 @@ CONFIG_CONSOLE=y
# UART console # UART console
CONFIG_SERIAL=y CONFIG_SERIAL=y
CONFIG_UART_CONSOLE=y CONFIG_UART_CONSOLE=y
# logging # logging
CONFIG_LOG=y CONFIG_LOG=y
CONFIG_APP_LOG_LEVEL_DBG=y CONFIG_APP_LOG_LEVEL_DBG=y

View file

@ -4,3 +4,36 @@
# This file contains selected Kconfig options for the application. # This file contains selected Kconfig options for the application.
CONFIG_SENSOR=y CONFIG_SENSOR=y
CONFIG_POLL=y
CONFIG_CAN=y
CONFIG_CAN_INIT_PRIORITY=80
CONFIG_CAN_MAX_FILTER=5
CONFIG_LOG=y
CONFIG_SHELL=y
CONFIG_SENSOR_SHELL=y
CONFIG_CAN_SHELL=y
CONFIG_DEVICE_SHELL=y
CONFIG_GPIO_SHELL=y
CONFIG_STATS=y
CONFIG_STATS_NAMES=y
CONFIG_STATS_SHELL=y
CONFIG_CAN_STATS=y
CONFIG_DISK_ACCESS=y
CONFIG_FILE_SYSTEM=y
CONFIG_FAT_FILESYSTEM_ELM=y
CONFIG_FILE_SYSTEM_MKFS=y
CONFIG_FILE_SYSTEM_SHELL=y
CONFIG_FS_LOG_LEVEL_DBG=y
CONFIG_SDMMC_LOG_LEVEL_DBG=y
CONFIG_HEAP_MEM_POOL_SIZE=16384
CONFIG_GNSS=y
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_USB_DEVICE_STACK=y
CONFIG_USB_DEVICE_PRODUCT="Telem3.0"
CONFIG_USB_DEVICE_PID=0x0004
CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=y

137
app/src/canlog.c Normal file
View file

@ -0,0 +1,137 @@
/*
* Copyright (c) 2024 Saji Champlin
*/
/*
* Listens to all can packets and logs them to a file.
* each power cycle generates a new file increment.
*/
#include <zephyr/storage/disk_access.h>
#include <zephyr/logging/log.h>
#include <zephyr/fs/fs.h>
#include <zephyr/net/canbus.h>
#include <zephyr/init.h>
#include <ff.h>
#define CANLOG_STACKSIZE 1024
#define DISK_DRIVE_NAME "SD"
#define DISK_MOUNT_PT "/"DISK_DRIVE_NAME":"
static const char *disk_mount_pt = DISK_MOUNT_PT;
LOG_MODULE_REGISTER(canlog, CONFIG_APP_LOG_LEVEL);
static FATFS fat_fs;
/* mounting info */
static struct fs_mount_t mp = {
.type = FS_FATFS,
.fs_data = &fat_fs,
};
int mount_sd() {
mp.mnt_point = disk_mount_pt;
int res = fs_mount(&mp);
if (res != FR_OK) {
LOG_ERR("SD mount failed: %d", res);
return -1;
}
LOG_INF("init sd ok");
return 0;
}
SYS_INIT(mount_sd, APPLICATION, 31);
const struct device *const can_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_canbus));
int init_can() {
int res;
if (!device_is_ready(can_dev)) {
LOG_ERR("CAN %s not ready.\n", can_dev->name);
return -1;
}
res = can_set_mode(can_dev, CAN_MODE_LOOPBACK);
if (res != 0) {
printf("Error setting CAN mode [%d]", res);
return 0;
}
res = can_start(can_dev);
if (res) {
LOG_ERR("CAN %s failed to start: %d", can_dev->name, res);
return -1;
}
LOG_INF("can start ok");
return 0;
}
SYS_INIT(init_can, APPLICATION, 32);
/*
* This init is specifically to setup the filters before we start
* the routine.
*
*/
int setup_can_filters() {
#ifndef CONFIG_LOOPBACK_MODE
int ret = can_set_mode(can_dev, CAN_MODE_LOOPBACK);
if (ret != 0) {
printf("Error setting CAN mode [%d]", ret);
return 0;
}
#endif
}
const struct can_filter all_packets_filter = {
.flags = 0U,
.id = 0,
.mask = 0,
};
const struct can_filter high_prio_filter = {
.flags = 0U,
.id = 0U,
.mask = 0xE00U,
};
K_MSGQ_DEFINE(sd_canframes, sizeof(struct can_frame), 20, 1);
void can_task() {
struct fs_file_t logfile;
int res;
struct can_frame incoming_frame;
fs_file_t_init(&logfile);
res = fs_open(&logfile, "/SD:/log3.txt", FS_O_CREATE |FS_O_APPEND | FS_O_WRITE);
if (res != FR_OK) {
LOG_ERR("Open file failed: %d", res);
return;
}
res = can_add_rx_filter_msgq(can_dev, &sd_canframes, &all_packets_filter);
if (res) {
LOG_ERR("Could not add filter: %d", res);
return;
}
while (1) {
// read the frame.
k_msgq_get(&sd_canframes, &incoming_frame, K_FOREVER);
fs_write(&logfile, &incoming_frame, sizeof(incoming_frame));
fs_sync(&logfile);
LOG_INF("write!");
}
}
/*
* work queue handler for SD card log.
*/
K_THREAD_DEFINE(canlog_th, CANLOG_STACKSIZE, can_task, NULL, NULL, NULL, 5, 0, 0);
// create the task, mount the FS, listen to the can bus.

View file

@ -11,54 +11,60 @@
#include <zephyr/logging/log.h> #include <zephyr/logging/log.h>
static void gnss_data_cb(const struct device *dev, const struct gnss_data *data) #include <zephyr/usb/usb_device.h>
{ #include <zephyr/usb/usbd.h>
if (data->info.fix_status != GNSS_FIX_STATUS_NO_FIX) { #include <zephyr/drivers/uart.h>
printf("%s has fix!\r\n", dev->name);
} BUILD_ASSERT(DT_NODE_HAS_COMPAT(DT_CHOSEN(zephyr_console), zephyr_cdc_acm_uart),
} "Console device is not ACM CDC UART device");
GNSS_SATELLITES_CALLBACK_DEFINE(DEVICE_DT_GET(DT_ALIAS(gnss)), gnss_satellites_cb);
LOG_MODULE_REGISTER(main, CONFIG_APP_LOG_LEVEL); LOG_MODULE_REGISTER(main, CONFIG_APP_LOG_LEVEL);
static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(gps_en, gpios); static const struct gpio_dt_spec good_led = GPIO_DT_SPEC_GET(DT_NODELABEL(good_led), gpios);
static const struct gpio_dt_spec fault_led = GPIO_DT_SPEC_GET(DT_NODELABEL(fault_led), gpios);
static const struct gpio_dt_spec status_0_led = GPIO_DT_SPEC_GET(DT_NODELABEL(status_led0), gpios);
static const struct gpio_dt_spec status_1_led = GPIO_DT_SPEC_GET(DT_NODELABEL(status_led1), gpios);
static const struct gpio_dt_spec status_2_led = GPIO_DT_SPEC_GET(DT_NODELABEL(status_led2), gpios);
static const struct gpio_dt_spec status_3_led = GPIO_DT_SPEC_GET(DT_NODELABEL(status_led3), gpios);
static const struct gpio_dt_spec gps_en = GPIO_DT_SPEC_GET(DT_NODELABEL(gps_en), gpios);
int main(void) int main(void)
{ {
int ret; int ret;
const struct device *sensor;
printk("Zephyr Example Application! hello\n"); LOG_INF("Telem3 Bootup sequence...");
if (!gpio_is_ready_dt(&led)) { if (!gpio_is_ready_dt(&good_led)) {
return 0; return 0;
} }
ret = gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE); ret = gpio_pin_configure_dt(&good_led, GPIO_OUTPUT_ACTIVE);
ret |= gpio_pin_configure_dt(&fault_led, GPIO_OUTPUT_ACTIVE);
ret |= gpio_pin_configure_dt(&status_0_led, GPIO_OUTPUT_ACTIVE);
ret |= gpio_pin_configure_dt(&status_1_led, GPIO_OUTPUT_ACTIVE);
ret |= gpio_pin_configure_dt(&status_2_led, GPIO_OUTPUT_ACTIVE);
ret |= gpio_pin_configure_dt(&status_3_led, GPIO_OUTPUT_ACTIVE);
ret |= gpio_pin_configure_dt(&gps_en, GPIO_OUTPUT_ACTIVE);
if (ret < 0) { if (ret < 0) {
return 0; return 0;
} }
gpio_pin_set_dt(&led, 1); gpio_pin_set_dt(&good_led, 0);
gpio_pin_set_dt(&fault_led, 0);
gpio_pin_set_dt(&status_0_led, 0);
gpio_pin_set_dt(&status_1_led, 0);
gpio_pin_set_dt(&status_2_led, 0);
gpio_pin_set_dt(&status_3_led, 0);
gpio_pin_set_dt(&gps_en, 0); // enable gps
LOG_DBG("Init complete");
while (1) { while (1) {
struct sensor_value val; gpio_pin_toggle_dt(&fault_led);
k_sleep(K_MSEC(500));
ret = sensor_sample_fetch(sensor);
if (ret < 0) {
LOG_ERR("Could not fetch sample (%d)", ret);
return 0;
}
ret = sensor_channel_get(sensor, SENSOR_CHAN_PROX, &val);
if (ret < 0) {
LOG_ERR("Could not get sample (%d)", ret);
return 0;
}
printk("Sensor value: %d\n", val.val1);
k_sleep(K_MSEC(1000));
} }
return 0; return 0;

View file

@ -1,8 +0,0 @@
# Copyright (c) 2021 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0
config BOARD_ENABLE_DCDC
bool "Enable DCDC mode"
select SOC_DCDC_NRF52X
default y
depends on BOARD_CUSTOM_PLANK

View file

@ -1,5 +0,0 @@
# Copyright (c) 2021 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0
config BOARD_CUSTOM_PLANK
select SOC_NRF52840_QIAA

View file

@ -1,6 +0,0 @@
# Custom Plank Board
`custom_plank` board is used to demonstrate how to create custom boards. It is
in fact a simplified version of the nRF52840-DK board, so the
`example-application` can be run on that development kit when using
`custom_plank`.

View file

@ -1,12 +0,0 @@
# Copyright (c) 2021 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0
board_runner_args(jlink "--device=nrf52" "--speed=4000")
board_runner_args(pyocd "--target=nrf52840" "--frequency=4000000")
set(OPENOCD_NRF5_SUBFAMILY "nrf52")
include(${ZEPHYR_BASE}/boards/common/nrfjprog.board.cmake)
include(${ZEPHYR_BASE}/boards/common/jlink.board.cmake)
include(${ZEPHYR_BASE}/boards/common/pyocd.board.cmake)
include(${ZEPHYR_BASE}/boards/common/openocd-nrf5.board.cmake)

View file

@ -1,8 +0,0 @@
# Copyright (c) 2024 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0
board:
name: custom_plank
vendor: vendor
socs:
- name: nrf52840

View file

@ -1,26 +0,0 @@
/*
* Copyright (c) 2022 Nordic Semiconductor ASA
* SPDX-License-Identifier: Apache-2.0
*/
&pinctrl {
uart0_default: uart0_default {
group1 {
psels = <NRF_PSEL(UART_TX, 0, 6)>,
<NRF_PSEL(UART_RX, 0, 8)>,
<NRF_PSEL(UART_RTS, 0, 5)>,
<NRF_PSEL(UART_CTS, 0, 7)>;
};
};
uart0_sleep: uart0_sleep {
group1 {
psels = <NRF_PSEL(UART_TX, 0, 6)>,
<NRF_PSEL(UART_RX, 0, 8)>,
<NRF_PSEL(UART_RTS, 0, 5)>,
<NRF_PSEL(UART_CTS, 0, 7)>;
low-power-enable;
};
};
};

View file

@ -1,46 +0,0 @@
/*
* Copyright (c) 2021 Nordic Semiconductor ASA
* SPDX-License-Identifier: Apache-2.0
*/
/dts-v1/;
#include <nordic/nrf52840_qiaa.dtsi>
#include "custom_plank-pinctrl.dtsi"
/ {
model = "Custom Plank Board";
compatible = "vendor,custom-plank";
chosen {
zephyr,console = &uart0;
zephyr,sram = &sram0;
zephyr,flash = &flash0;
};
examplesensor0: examplesensor_0 {
compatible = "zephyr,examplesensor";
input-gpios = <&gpio0 11 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
};
};
&uicr {
gpio-as-nreset;
};
&gpiote {
status = "okay";
};
&gpio0 {
status = "okay";
};
&uart0 {
compatible = "nordic,nrf-uarte";
status = "okay";
current-speed = <115200>;
pinctrl-0 = <&uart0_default>;
pinctrl-1 = <&uart0_sleep>;
pinctrl-names = "default", "sleep";
};

View file

@ -1,16 +0,0 @@
# Copyright (c) 2021 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0
identifier: custom_plank
name: Custom-Plank
vendor: vendor
type: mcu
arch: arm
ram: 256
flash: 1024
toolchain:
- zephyr
- gnuarmemb
- xtools
supported:
- gpio

View file

@ -1,9 +0,0 @@
# Copyright (c) 2021 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0
CONFIG_ARM_MPU=y
CONFIG_HW_STACK_PROTECTION=y
CONFIG_GPIO=y
CONFIG_PINCTRL=y

View file

@ -38,10 +38,10 @@
}; };
// TODO: should this really be here // TODO: should this really be here
// gps_en: gps_en { gps_en: gps_en {
// gpios = <&gpiod 9 GPIO_ACTIVE_HIGH>; gpios = <&gpiod 9 GPIO_ACTIVE_HIGH>;
// label = "GPS power enable"; label = "GPS power enable";
// }; };
}; };
option_switches { option_switches {
@ -60,11 +60,12 @@
}; };
}; };
chosen { chosen {
zephyr,console = &usart1; zephyr,console = &cdc_acm_uart;
zephyr,shell-uart = &usart1; zephyr,shell-uart = &cdc_acm_uart;
zephyr,sram = &sram0; zephyr,sram = &sram0;
zephyr,flash = &flash0; zephyr,flash = &flash0;
zephyr,canbus = &fdcan1; zephyr,canbus = &fdcan1;
zephyr,sdmmc-disk = &sdmmc1;
}; };
aliases { aliases {
led0 = &good_led; led0 = &good_led;
@ -72,6 +73,7 @@
die-temp0 = &die_temp; die-temp0 = &die_temp;
volt-sensor0 = &vref; volt-sensor0 = &vref;
volt-sensor1 = &vbat; volt-sensor1 = &vbat;
spi-flash0 = &spiflash0;
}; };
soc { soc {
@ -92,6 +94,9 @@
// status = "okay"; // status = "okay";
// }; // };
&clk_hsi48 {
status = "okay";
};
&clk_hse { &clk_hse {
status = "okay"; status = "okay";
clock-frequency = <DT_FREQ_M(8)>; clock-frequency = <DT_FREQ_M(8)>;
@ -132,7 +137,7 @@
pinctrl-0 = <&usart2_tx_pd5 &usart2_rx_pd6>; pinctrl-0 = <&usart2_tx_pd5 &usart2_rx_pd6>;
pinctrl-names = "default"; pinctrl-names = "default";
status = "okay"; status = "okay";
gnss: gnss-nmea-generic { gnss: l80_gps {
compatible = "gnss-nmea-generic"; compatible = "gnss-nmea-generic";
}; };
}; };
@ -149,6 +154,9 @@ zephyr_udc0: &usb {
pinctrl-0 = <&usb_dp_pa12 &usb_dm_pa11>; pinctrl-0 = <&usb_dp_pa12 &usb_dm_pa11>;
pinctrl-names = "default"; pinctrl-names = "default";
status = "okay"; status = "okay";
cdc_acm_uart: cdc_acm_uart {
compatible = "zephyr,cdc-acm-uart";
};
}; };
&sdmmc1 { &sdmmc1 {
@ -160,6 +168,7 @@ zephyr_udc0: &usb {
&sdmmc1_d3_pc11 &sdmmc1_d3_pc11
&sdmmc1_ck_pc12 &sdmmc1_ck_pc12
&sdmmc1_cmd_pd2>; &sdmmc1_cmd_pd2>;
// bus-width = <4>;
pinctrl-names = "default"; pinctrl-names = "default";
}; };
@ -203,3 +212,20 @@ zephyr_udc0: &usb {
pinctrl-0 = <&fdcan1_tx_pd1 &fdcan1_rx_pd0>; pinctrl-0 = <&fdcan1_tx_pd1 &fdcan1_rx_pd0>;
pinctrl-names = "default"; pinctrl-names = "default";
}; };
&octospi1 {
pinctrl-0 = <&octospi1_clk_pf10 &octospi1_ncs_pa2 \
&octospi1_io0_pf8 &octospi1_io1_pf9 &octospi1_io2_pf7
&octospi1_io3_pf6 &octospi1_io4_pc1 &octospi1_io5_pc2
&octospi1_io6_pc3 &octospi1_io7_pc0>;
pinctrl-names = "default";
status = "okay";
spiflash0: ospi-nor-flash@90000000 {
compatible = "st,stm32-ospi-nor";
reg = <0x90000000 DT_SIZE_M(16)>; /* 128 Mbits */
ospi-max-frequency = <80000000>;
spi-bus-width = <OSPI_QUAD_MODE>;
data-rate = <OSPI_DTR_TRANSFER>;
status = "okay";
};
};

View file

@ -11,12 +11,6 @@ CONFIG_CLOCK_CONTROL=y
CONFIG_CONSOLE=y CONFIG_CONSOLE=y
CONFIG_UART_CONSOLE=y CONFIG_UART_CONSOLE=y
CONFIG_GNSS=y
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_LOG=y
CONFIG_GNSS_DUMP_TO_LOG=y
# Enable MPU # Enable MPU
CONFIG_ARM_MPU=y CONFIG_ARM_MPU=y
@ -25,3 +19,7 @@ CONFIG_HW_STACK_PROTECTION=y
# enable pin controller # enable pin controller
CONFIG_PINCTRL=y CONFIG_PINCTRL=y
CONFIG_DISK_DRIVER_SDMMC=y
CONFIG_SDMMC_STM32=y
CONFIG_SDMMC_STM32_HWFC=y