Fixed Race-Condtion problem with arming of done_flag
This commit is contained in:
20
motor-control/firmware/scripts/remote/run_openocd.exp
Normal file
20
motor-control/firmware/scripts/remote/run_openocd.exp
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
#!/usr/bin/expect
|
||||||
|
|
||||||
|
set timeout 30
|
||||||
|
|
||||||
|
spawn ssh [lindex $argv 0]
|
||||||
|
|
||||||
|
expect "# "
|
||||||
|
send "cd ~/gobot/"
|
||||||
|
expect "# "
|
||||||
|
|
||||||
|
send "git fetch"
|
||||||
|
expect "# "
|
||||||
|
|
||||||
|
send "git checkout motor-ctrl-firmware"
|
||||||
|
expect "# "
|
||||||
|
|
||||||
|
send "cd motor-control/firmware/scripts/remote"
|
||||||
|
expect "# "
|
||||||
|
|
||||||
|
send "./run_openocd.sh"
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
#!/usr/bin/bash
|
#!/usr/bin/bash
|
||||||
|
|
||||||
sudo src/openocd -f interface/cmsis-dap.cfg -c "bindto 0.0.0.0" -c "adapter speed 5000" -f target/rp2040.cfg -s tcl
|
src/openocd -f interface/cmsis-dap.cfg -c "bindto 0.0.0.0" -c "adapter speed 5000" -f target/rp2040.cfg -s tcl
|
||||||
@@ -21,6 +21,9 @@
|
|||||||
#define ENABLE0_PIN 2
|
#define ENABLE0_PIN 2
|
||||||
#define ENABLE1_PIN 3
|
#define ENABLE1_PIN 3
|
||||||
|
|
||||||
|
#define LIMIT0_PIN 10
|
||||||
|
#define LIMIT1_PIN 11
|
||||||
|
|
||||||
#define STEP0_PIN 6
|
#define STEP0_PIN 6
|
||||||
#define STEP1_PIN 7
|
#define STEP1_PIN 7
|
||||||
#define DIR0_PIN 8
|
#define DIR0_PIN 8
|
||||||
@@ -58,40 +61,50 @@ int main() {
|
|||||||
|
|
||||||
sleep_ms(5);
|
sleep_ms(5);
|
||||||
|
|
||||||
step_driver.set_conf0(10000, 0);
|
|
||||||
step_driver.set_conf1(10000, 0);
|
step_driver.set_conf1(10000, 0);
|
||||||
step_driver.pulse0(1000);
|
|
||||||
step_driver.pulse1(1000);
|
|
||||||
step_driver.wait0(0);
|
|
||||||
step_driver.wait1(0);
|
|
||||||
|
|
||||||
sleep_ms(200);
|
|
||||||
|
gpio_init(LIMIT0_PIN);
|
||||||
|
gpio_set_dir(LIMIT0_PIN, GPIO_IN);
|
||||||
|
gpio_pull_up(LIMIT0_PIN);
|
||||||
|
|
||||||
|
gpio_init(LIMIT1_PIN);
|
||||||
|
gpio_set_dir(LIMIT1_PIN, GPIO_IN);
|
||||||
|
gpio_pull_up(LIMIT1_PIN);
|
||||||
|
|
||||||
|
step_driver.set_conf0(10000, 1);
|
||||||
|
step_driver.pulse0(10000);
|
||||||
|
step_driver.wait0(0);
|
||||||
|
|
||||||
|
step_driver.set_conf0(10000, 0);
|
||||||
|
step_driver.pulse0(100000);
|
||||||
|
while(!gpio_get(LIMIT1_PIN)) {
|
||||||
|
sleep_ms(1);
|
||||||
|
}
|
||||||
|
step_driver.pulse0(0);
|
||||||
|
sleep_ms(500);
|
||||||
|
|
||||||
step_driver.set_conf0(10000, 1);
|
step_driver.set_conf0(10000, 1);
|
||||||
step_driver.set_conf1(10000, 1);
|
step_driver.pulse0(200);
|
||||||
step_driver.pulse0(1000);
|
|
||||||
step_driver.pulse1(1000);
|
|
||||||
step_driver.wait0(0);
|
step_driver.wait0(0);
|
||||||
step_driver.wait1(0);
|
|
||||||
|
|
||||||
volatile uint t = 500 - step_driver.get_remaining_steps0();
|
|
||||||
volatile uint s = step_driver.get_remaining_steps1();
|
|
||||||
|
|
||||||
step_driver.set_conf0(1000, 1);
|
step_driver.set_conf0(500, 0);
|
||||||
step_driver.set_conf1(1000, 1);
|
step_driver.pulse0(5000);
|
||||||
|
while(!gpio_get(LIMIT1_PIN)) {
|
||||||
|
sleep_ms(1);
|
||||||
sleep_ms(100);
|
}
|
||||||
|
step_driver.pulse0(0);
|
||||||
|
sleep_ms(1);
|
||||||
|
|
||||||
gpio_init(LED_PIN);
|
gpio_init(LED_PIN);
|
||||||
gpio_set_dir(LED_PIN, GPIO_OUT);
|
gpio_set_dir(LED_PIN, GPIO_OUT);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
sleep_ms(50);
|
|
||||||
gpio_put(LED_PIN, 1);
|
|
||||||
|
|
||||||
sleep_ms(50);
|
sleep_ms(50);
|
||||||
gpio_put(LED_PIN, 0);
|
gpio_put(LED_PIN, 0);
|
||||||
|
sleep_ms(50);
|
||||||
|
gpio_put(LED_PIN, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -23,14 +23,14 @@ counter:
|
|||||||
l1:
|
l1:
|
||||||
PULL NOBLOCK
|
PULL NOBLOCK
|
||||||
MOV Y, OSR
|
MOV Y, OSR
|
||||||
|
MOV X, OSR
|
||||||
JMP !Y l1_end
|
JMP !Y l1_end
|
||||||
IRQ WAIT 2 REL
|
|
||||||
|
|
||||||
|
IRQ WAIT 2 REL
|
||||||
SET PINS, 1
|
SET PINS, 1
|
||||||
IRQ WAIT 2 REL
|
IRQ WAIT 2 REL
|
||||||
|
|
||||||
SET PINS, 0
|
SET PINS, 0
|
||||||
MOV X, OSR
|
|
||||||
JMP X-- l1
|
JMP X-- l1
|
||||||
|
|
||||||
l1_end:
|
l1_end:
|
||||||
|
|||||||
@@ -167,6 +167,8 @@ void TMC2209_step_dual::set_conf1(uint frequency, bool dir) {
|
|||||||
void TMC2209_step_dual::pulse0(uint n) {
|
void TMC2209_step_dual::pulse0(uint n) {
|
||||||
this->remaining_step_count0 = n;
|
this->remaining_step_count0 = n;
|
||||||
this->done_flag0_arm = true;
|
this->done_flag0_arm = true;
|
||||||
|
this->done_flag0 = false;
|
||||||
|
|
||||||
pio_sm_put_blocking(
|
pio_sm_put_blocking(
|
||||||
this->pio_core, this->sm_num_counter0, n
|
this->pio_core, this->sm_num_counter0, n
|
||||||
);
|
);
|
||||||
@@ -175,12 +177,15 @@ void TMC2209_step_dual::pulse0(uint n) {
|
|||||||
void TMC2209_step_dual::pulse1(uint n) {
|
void TMC2209_step_dual::pulse1(uint n) {
|
||||||
this->remaining_step_count1 = n;
|
this->remaining_step_count1 = n;
|
||||||
this->done_flag1_arm = true;
|
this->done_flag1_arm = true;
|
||||||
|
this->done_flag1 = false;
|
||||||
|
|
||||||
pio_sm_put_blocking(
|
pio_sm_put_blocking(
|
||||||
this->pio_core, this->sm_num_counter1, n
|
this->pio_core, this->sm_num_counter1, n
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
void TMC2209_step_dual::pulse0_int(int n) {
|
void TMC2209_step_dual::pulse0_int(int n) {
|
||||||
|
this->remaining_step_count0 = n;
|
||||||
this->done_flag0_arm = true;
|
this->done_flag0_arm = true;
|
||||||
if(n < 0) {
|
if(n < 0) {
|
||||||
n = abs(n);
|
n = abs(n);
|
||||||
@@ -193,6 +198,7 @@ void TMC2209_step_dual::pulse0_int(int n) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
void TMC2209_step_dual::pulse1_int(int n) {
|
void TMC2209_step_dual::pulse1_int(int n) {
|
||||||
|
this->remaining_step_count1 = n;
|
||||||
this->done_flag1_arm = true;
|
this->done_flag1_arm = true;
|
||||||
if(n < 0) {
|
if(n < 0) {
|
||||||
n = abs(n);
|
n = abs(n);
|
||||||
@@ -212,6 +218,7 @@ void TMC2209_step_dual::irq_handler0() {
|
|||||||
} else {
|
} else {
|
||||||
done_flag0 = false;
|
done_flag0 = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
pio_interrupt_clear(this->pio_core, 2);
|
pio_interrupt_clear(this->pio_core, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user