summaryrefslogtreecommitdiff
path: root/src/read_flash.c
diff options
context:
space:
mode:
authorDawsyn Schraiber <[email protected]>2024-05-09 02:05:35 -0400
committerGitHub <[email protected]>2024-05-09 02:05:35 -0400
commit93acde052369568beaefb0d99629d8797f5c191f (patch)
treea3fb96ddad2d289aa7f8bf410c60cf6289bca7a1 /src/read_flash.c
parent5f68c7a1b5c8dec82d4a2e1e12443a41b5196b1d (diff)
downloadactive-drag-system-93acde052369568beaefb0d99629d8797f5c191f.tar.gz
active-drag-system-93acde052369568beaefb0d99629d8797f5c191f.tar.bz2
active-drag-system-93acde052369568beaefb0d99629d8797f5c191f.zip
Raspberry Pi Pico (#12)
* Adding a 90% completed, compilable but untested ADS * Made basic changes to actuator & sensor. Also added motor class * Removed unnecessary .cpp files * Updated sensor & actuator classes, finished ads, added variable time step to kalman filter, set up all tests for future assertions * Relocated 'main' to 'active-drag-system.cpp'. Added more info to README * Removed main.cpp * Added more details to README * Changed some function parameters from pass-by-pointer to pass-by-reference. Also removed the std namespace * Started writing the test cases * Updated the .gitignore file * Removed some files that should be gitignored * Up to date with Jazz's pull request * Test Launch Branch Created; PRU Servo Control with Test Program * Added I2C device class and register IDs for MPL [INCOMPLETE SENSOR IMPLEMENTATION] Needs actual data getting function implementation for both sensors and register IDs for BNO, will implement shortly. * Partial implementation of MPL sensor Added startup method, still needs fleshed out data getters and setters and finished I2C implementation. MOST LIKELY WILL HAVE COMPILATION ISSUES. * *Hypothetically* complete MPL implementation NEEDS HARDWARE TESTING * IMU Header and init() method implementation Needs like, all data handling still lol * Hypothetically functional (Definitely won't compile) * We ball? * Conversion to Raspberry Pi Pico Build System; Removed Beaglebone specific code; Simple blinking example in ADS source file; builds for Pico W * Rearranged build so dependent upon cmake file already existing in pico-sdk; current executable prints current altitude, velocity, and time taken to read and calculate said values; ~320 us to do so * Altimeter interrupt callback for Pad to Boost State; dummy templates for other callbacks with comments describing potential implementation details * Altimeter interrupts relatively finished; need to test with vacuum chamber to verify behavior * Established interrupt pins as pullup and active-low; adjusted callback functions to properly use function pointers; still need to verify interrupt system with vacuum chamber * Removed weird artifact in .gitignore, adjust CMakeLists to auto pull pico sdk, added Dockerfile * added Docker dev container file * modified CMakeLists to auto pull sdk if not already downloaded, add build.sh script, fixed Dockerfile * added bno055 support * changed bno055 lin accel struct to use float instead of double * added bno055 support not tested, but compiles, fixed CMakLists to before I messed with it * added absolute quaternion output from bno055 * Added Euler and aboslute linear accelration * Flash implementation for data logging; each log entry is 32 bytes long * added base pwm functions and started on apogee detection * State machine verified functional with logging capabilities; currently on same core * Ooops missed double define, renamed LOOP_HZ to LOOP_PERIOD; State machine functional after merge still * Simple test program to see servo PWM range; logging with semaphores for safe multithreading * Kalman filters generously provided from various sources for temporary replacement; minimum deployment 30 percent; state machine functionality restored; multithreading logging verified; altimeter broke and replaced * Stop logging on END state; provide deployment function with AGL instead of ASL altitude * Various minimal changes; Flash size from 1MB to 8MB; M1939 to M2500T burn time; pin assignments for new PCB; External Status LED to Internal Status LED --------- Co-authored-by: Jazz Jackson <[email protected]> Co-authored-by: Cian Capacci <[email protected]> Co-authored-by: Gregory Wainer <[email protected]>
Diffstat (limited to 'src/read_flash.c')
-rw-r--r--src/read_flash.c71
1 files changed, 71 insertions, 0 deletions
diff --git a/src/read_flash.c b/src/read_flash.c
new file mode 100644
index 0000000..71d2870
--- /dev/null
+++ b/src/read_flash.c
@@ -0,0 +1,71 @@
+#include <stdio.h>
+#include <inttypes.h>
+#include "boards/pico_w.h"
+#include "hardware/spi.h"
+#include "spi_flash.h"
+
+int main() {
+ stdio_init_all();
+ getchar();
+ // Enable SPI 0 at 1 MHz and connect to GPIOs
+ spi_init(spi_default, 1000 * 1000 * 60);
+ gpio_set_function(PICO_DEFAULT_SPI_RX_PIN, GPIO_FUNC_SPI);
+ gpio_set_function(PICO_DEFAULT_SPI_TX_PIN, GPIO_FUNC_SPI);
+ gpio_set_function(PICO_DEFAULT_SPI_SCK_PIN, GPIO_FUNC_SPI);
+
+ // Chip select is active-low, so we'll initialise it to a driven-high state
+ gpio_init(PICO_DEFAULT_SPI_CSN_PIN);
+ gpio_set_dir(PICO_DEFAULT_SPI_CSN_PIN, GPIO_OUT);
+ gpio_put(PICO_DEFAULT_SPI_CSN_PIN, 1);
+
+ uint8_t entry[PACKET_SIZE];
+
+ // flash_erase(spi_default, PICO_DEFAULT_SPI_CSN_PIN);
+ flash_read(spi_default, PICO_DEFAULT_SPI_CSN_PIN, base_addr, page_buffer, FLASH_PAGE_SIZE);
+ for (uint16_t i = 0; i < FLASH_PAGE_SIZE; i += PACKET_SIZE) {
+ if (page_buffer[i] == 0xFF) {
+ base_addr += i;
+ break;
+ }
+ if ((i + PACKET_SIZE) == FLASH_PAGE_SIZE) {
+ base_addr += FLASH_PAGE_SIZE;
+ flash_read(spi_default, PICO_DEFAULT_SPI_CSN_PIN, base_addr, page_buffer, FLASH_PAGE_SIZE);
+ i = 0;
+ }
+ }
+
+ printf("\nRead Data:\n");
+ printf("time (us) | state | dep pcnt | alt (m) | vel (m/s) | quat_w | quat_x | quat_y | quat_z | lin_ax | lin_ay | lin_az\n");
+ for (uint32_t i = 0; i < base_addr; i += PACKET_SIZE) {
+ flash_read(spi_default, PICO_DEFAULT_SPI_CSN_PIN, i, entry, PACKET_SIZE);
+ uint64_t now_us = (((uint64_t)entry[0] << 56) | ((uint64_t)entry[1] << 48) | \
+ ((uint64_t)entry[2] << 40) | ((uint64_t)entry[3] << 32) | \
+ ((uint64_t)entry[4] << 24) | ((uint64_t)entry[5] << 16) | \
+ ((uint64_t)entry[6] << 8) | ((uint64_t)entry[7]));
+
+ uint8_t state = entry[8];
+ uint8_t deploy_percent = entry[9];
+
+ uint32_t alt_bits = (entry[10] << 24) | (entry[11] << 16) | (entry[12] << 8) | (entry[13]);
+ uint32_t vel_bits = (entry[14] << 24) | (entry[15] << 16) | (entry[16] << 8) | (entry[17]);
+ float altitude = *(float *)(&alt_bits);
+ float velocity = *(float *)(&vel_bits);
+
+ int16_t w = ((int16_t)entry[18]) | (((int16_t)entry[19]) << 8);
+ int16_t x = ((int16_t)entry[20]) | (((int16_t)entry[21]) << 8);
+ int16_t y = ((int16_t)entry[22]) | (((int16_t)entry[23]) << 8);
+ int16_t z = ((int16_t)entry[24]) | (((int16_t)entry[25]) << 8);
+ float qw = ((float)w) / 16384.0; // 2^14 LSB
+ float qx = ((float)x) / 16384.0;
+ float qy = ((float)y) / 16384.0;
+ float qz = ((float)z) / 16384.0;
+ int16_t ax = ((int16_t)entry[26]) | (((int16_t)entry[27]) << 8);
+ int16_t ay = ((int16_t)entry[28]) | (((int16_t)entry[29]) << 8);
+ int16_t az = ((int16_t)entry[30]) | (((int16_t)entry[31]) << 8);
+ float lax = ((float)x) / 100.0;
+ float lay = ((float)y) / 100.0;
+ float laz = ((float)z) / 100.0;
+ printf("%"PRIu64" | %c | %"PRIu8" | %4.2f | %4.2f | %4.2f | %4.2f| %4.2f | %4.2f | %4.2f | %4.2f |%4.2f\n", \
+ now_us, state, deploy_percent, altitude, velocity, qw, qx, qy, qz, lax, lay, laz);
+ }
+}