Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open Bot Brain primitives for motors + color sensor #285

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
Draft
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
5 changes: 5 additions & 0 deletions platforms/Zephyr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(warduino)

# Note on _POSIX_C_SOURCE: If you define this macro to a value greater than or equal to 200809L, then the functionality from the 2008 edition of the POSIX standard (IEEE Standard 1003.1-2008) is made available.
target_compile_definitions(app PRIVATE _POSIX_C_SOURCE=200809L)

add_custom_command(
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/upload.h
COMMAND xxd -i upload.wasm > upload.h
Expand All @@ -16,6 +19,8 @@ target_sources(app PRIVATE
../../src/Interpreter/instructions.cpp
../../src/Interpreter/interpreter.cpp
../../src/Primitives/zephyr.cpp
../../src/Primitives/Mindstorms/Motor.cpp
../../src/Primitives/Mindstorms/uart_sensor.cpp
../../src/Memory/mem.cpp
../../src/Utils/util.cpp
../../src/Utils/util_arduino.cpp
Expand Down
258 changes: 137 additions & 121 deletions platforms/Zephyr/boards/stm32l496g_disco.overlay
Original file line number Diff line number Diff line change
@@ -1,132 +1,148 @@
#include "../app.overlay"

/ {
zephyr,user {
warduino-gpios =
<&gpioa 0 0>,
<&gpioa 1 0>,
<&gpioa 2 0>,
<&gpioa 3 0>,
<&gpioa 4 0>,
<&gpioa 5 0>,
<&gpioa 6 0>,
<&gpioa 7 0>,
<&gpioa 8 0>,
<&gpioa 9 0>,
<&gpioa 10 0>,
<&gpioa 11 0>,
<&gpioa 12 0>,
<&gpioa 15 0>,
<&gpiob 0 0>,
<&gpiob 1 0>,
<&gpiob 2 0>,
<&gpiob 3 0>,
<&gpiob 4 0>,
<&gpiob 5 0>,
<&gpiob 6 0>,
<&gpiob 7 0>,
<&gpiob 8 0>,
<&gpiob 9 0>,
<&gpiob 12 0>,
<&gpiob 13 0>,
<&gpiob 14 0>,
<&gpiob 15 0>,
<&gpioc 0 0>,
<&gpioc 1 0>,
<&gpioc 2 0>,
<&gpioc 3 0>,
<&gpioc 4 0>,
<&gpioc 5 0>,
<&gpioc 6 0>,
<&gpioc 7 0>,
<&gpioc 8 0>,
<&gpioc 9 0>,
<&gpioc 12 0>,
<&gpioc 15 0>,
<&gpiod 0 0>,
<&gpiod 1 0>,
<&gpiod 2 0>,
<&gpiod 3 0>,
<&gpiod 4 0>,
<&gpiod 7 0>,
<&gpiod 8 0>,
<&gpiod 9 0>,
<&gpiod 10 0>,
<&gpiod 11 0>,
<&gpiod 12 0>,
<&gpiod 13 0>,
<&gpiod 14 0>,
<&gpiod 15 0>,
<&gpioe 0 0>,
<&gpioe 1 0>,
<&gpioe 2 0>,
<&gpioe 3 0>,
<&gpioe 4 0>,
<&gpioe 7 0>,
<&gpioe 8 0>,
<&gpioe 10 0>,
<&gpioe 11 0>,
<&gpioe 12 0>,
<&gpioe 13 0>,
<&gpioe 14 0>,
<&gpioe 15 0>,
<&gpiof 3 0>,
<&gpiof 4 0>,
<&gpiof 5 0>,
<&gpiof 6 0>,
<&gpiof 7 0>,
<&gpiof 8 0>,
<&gpiof 9 0>,
<&gpiof 10 0>,
<&gpiof 11 0>,
<&gpiof 12 0>,
<&gpiof 13 0>,
<&gpiof 14 0>,
<&gpiog 2 0>,
<&gpiog 3 0>,
<&gpiog 4 0>,
<&gpiog 5 0>,
<&gpiog 6 0>,
<&gpiog 7 0>,
<&gpiog 8 0>,
<&gpiog 11 0>,
<&gpiog 12 0>,
<&gpiog 15 0>,
<&gpiob 10 0>,
<&gpiob 11 0>,
<&gpioc 10 0>,
<&gpioc 11 0>,
<&gpiog 13 0>,
<&gpiog 14 0>,
<&gpiod 5 0>,
<&gpiod 6 0>,
<&gpiof 0 0>,
<&gpiof 1 0>,
<&gpiog 9 0>,
<&gpiog 10 0>;
zephyr,user {
warduino-gpios =
<&gpioa 0 0>,
<&gpioa 1 0>,
<&gpioa 2 0>,
<&gpioa 3 0>,
<&gpioa 4 0>,
<&gpioa 5 0>,
<&gpioa 6 0>,
<&gpioa 7 0>,
<&gpioa 8 0>,
<&gpioa 9 0>,
<&gpioa 10 0>,
<&gpioa 11 0>,
<&gpioa 12 0>,
<&gpioa 15 0>,
<&gpiob 0 0>,
<&gpiob 1 0>,
<&gpiob 2 0>,
<&gpiob 3 0>,
<&gpiob 4 0>,
<&gpiob 5 0>,
<&gpiob 6 0>,
<&gpiob 7 0>,
<&gpiob 8 0>,
<&gpiob 9 0>,
<&gpiob 12 0>,
<&gpiob 13 0>,
<&gpiob 14 0>,
<&gpiob 15 0>,
<&gpioc 0 0>,
<&gpioc 1 0>,
<&gpioc 2 0>,
<&gpioc 3 0>,
<&gpioc 4 0>,
<&gpioc 5 0>,
<&gpioc 6 0>,
<&gpioc 7 0>,
<&gpioc 8 0>,
<&gpioc 9 0>,
<&gpioc 12 0>,
<&gpioc 15 0>,
<&gpiod 0 0>,
<&gpiod 1 0>,
<&gpiod 2 0>,
<&gpiod 3 0>,
<&gpiod 4 0>,
<&gpiod 7 0>,
<&gpiod 8 0>,
<&gpiod 9 0>,
<&gpiod 10 0>,
<&gpiod 11 0>,
<&gpiod 12 0>,
<&gpiod 13 0>,
<&gpiod 14 0>,
<&gpiod 15 0>,
<&gpioe 0 0>,
<&gpioe 1 0>,
<&gpioe 2 0>,
<&gpioe 3 0>,
<&gpioe 4 0>,
<&gpioe 7 0>,
<&gpioe 8 0>,
<&gpioe 10 0>,
<&gpioe 11 0>,
<&gpioe 12 0>,
<&gpioe 13 0>,
<&gpioe 14 0>,
<&gpioe 15 0>,
<&gpiof 3 0>,
<&gpiof 4 0>,
<&gpiof 5 0>,
<&gpiof 6 0>,
<&gpiof 7 0>,
<&gpiof 8 0>,
<&gpiof 9 0>,
<&gpiof 10 0>,
<&gpiof 11 0>,
<&gpiof 12 0>,
<&gpiof 13 0>,
<&gpiof 14 0>,
<&gpiog 2 0>,
<&gpiog 3 0>,
<&gpiog 4 0>,
<&gpiog 5 0>,
<&gpiog 6 0>,
<&gpiog 7 0>,
<&gpiog 8 0>,
<&gpiog 11 0>,
<&gpiog 12 0>,
<&gpiog 15 0>,
<&gpiob 10 0>,
<&gpiob 11 0>,
<&gpioc 10 0>,
<&gpioc 11 0>,
<&gpiog 13 0>,
<&gpiog 14 0>,
<&gpiod 5 0>,
<&gpiod 6 0>,
<&gpiof 0 0>,
<&gpiof 1 0>,
<&gpiog 9 0>,
<&gpiog 10 0>;

pwms =
<&pwm8 3 10000 PWM_POLARITY_NORMAL>,
<&pwm8 4 10000 PWM_POLARITY_NORMAL>,
<&pwm8 1 10000 PWM_POLARITY_NORMAL>,
<&pwm8 2 10000 PWM_POLARITY_NORMAL>;

warduino-uarts =
<&usart1>;
};
pwms =
<&pwm8 3 10000 PWM_POLARITY_NORMAL>,
<&pwm8 4 10000 PWM_POLARITY_NORMAL>,
<&pwm8 1 10000 PWM_POLARITY_NORMAL>,
<&pwm8 2 10000 PWM_POLARITY_NORMAL>,
<&pwm1 3 10000 PWM_POLARITY_NORMAL>,
<&pwm1 4 10000 PWM_POLARITY_NORMAL>,
<&pwm1 1 10000 PWM_POLARITY_NORMAL>,
<&pwm1 2 10000 PWM_POLARITY_NORMAL>;

warduino-uarts =
<&usart1>;
};
};

&timers8 {
status = "okay";
pwm8: pwm {
status = "okay";
pinctrl-0 = <&tim8_ch3_pc8 &tim8_ch4_pc9 &tim8_ch1_pc6 &tim8_ch2_pc7>;
pinctrl-names =
"default";
};
status = "okay";

pwm8: pwm {
status = "okay";
pinctrl-0 = <&tim8_ch3_pc8 &tim8_ch4_pc9 &tim8_ch1_pc6 &tim8_ch2_pc7>;
pinctrl-names =
"default";
};
};

&timers1 {
status = "okay";

pwm1: pwm {
status = "okay";
pinctrl-0 = <&tim1_ch3_pe13 &tim1_ch4_pe14 &tim1_ch1_pa8 &tim1_ch2_pa9>;
pinctrl-names =
"default";
};
};

&usart1 {
pinctrl-0 = <&usart1_tx_pg9 &usart1_rx_pg10>;
current-speed = <2400>;
pinctrl-0 = <&usart1_tx_pg9 &usart1_rx_pg10>;
current-speed = <2400>;
};
23 changes: 14 additions & 9 deletions platforms/Zephyr/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,26 @@ int war_console_init(void) {

WARDuino *wac = WARDuino::instance();

int valread;
uint8_t buffer[1024] = {0};

void read_debug_messages() {
while ((valread = war_console_read(NULL, buffer, 1024)) > 0) {
wac->handleInterrupt(valread, buffer);
}
}

void startDebuggerStd() {
Channel *duplex = new Duplex(stdin, stdout);
wac->debugger->setChannel(duplex);
duplex->open();

war_console_init();
int valread;
uint8_t buffer[1024] = {0};
while (true) {
k_msleep(1000);

while ((valread = war_console_read(NULL, buffer, 1024)) > 0) {
wac->handleInterrupt(valread, buffer);
}
}
/*while (true) {
k_msleep(500);
//printf("From debugger thread!\n");
read_debug_messages();
}*/
}

K_THREAD_DEFINE(debugger_tid, DEBUGGER_STACK_SIZE, startDebuggerStd, NULL, NULL,
Expand Down
3 changes: 3 additions & 0 deletions platforms/Zephyr/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ CONFIG_CONSOLE_PUTCHAR_BUFSIZE=4096

CONFIG_POSIX_API=y
CONFIG_MAIN_STACK_SIZE=4096

# Allow flashing the board without reset (increases power consumption so should only be used for development)
CONFIG_STM32_ENABLE_DEBUG_SLEEP_STOP=y
Loading
Loading