diff --git a/Readme.md b/Readme.md index 1ab89d1..d35cfd3 100644 --- a/Readme.md +++ b/Readme.md @@ -71,13 +71,13 @@ Also be careful to prevent the motor from overheating. Then write 1 to `state` to enter the drag mode, where a constant current is continuously passed through some of the motor's coils (please complete the subsequent operations as soon as possible to prevent the motor from overheating). -Write 1 to `cali_run` to start the calibration, the motor coil will be energized sequentially, the motor will turn clockwise first, then counterclockwise, -and finally print the calculated encoder offset value, write it to `bias_encoder`, and finally save it. +Write 1 to `cali_run` to start the calibration. The motor coils will be energized sequentially, causing the motor to turn clockwise first, then counterclockwise. +Afterward, the calculated encoder offset value will be printed and written to `bias_encoder`. Be sure to save it to flash. -Write 1 to `cali_run` as soon as possible after writing 1 to `state`, so that the coils can be energized in turn, sharing the strain on individual coils. +Write 1 to `cali_run` as soon as possible after writing 1 to `state`, so that the coils can be energized in turn, sharing the strain on individual coils. If the motor does not rotate clockwise first during calibration (the encoder value not increases), -you will need to swap any two wires of the motor to change the direction of motor rotation. +you will need to swap any two wires of the motor to change the direction of motor rotation. ### Torque Mode (state = 2) diff --git a/mdrv_bl/Makefile b/mdrv_bl/Makefile index a62fc3e..30a1503 100644 --- a/mdrv_bl/Makefile +++ b/mdrv_bl/Makefile @@ -62,8 +62,7 @@ Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_uart_ex.c \ Core/Src/system_stm32g4xx.c \ Core/Src/sysmem.c \ Core/Src/syscalls.c \ -cdnet/dispatch/cdnet_dispatch.c \ -cdnet/dispatch/helper.c \ +cdnet/core/cdnet_core.c \ cdnet/parser/cdnet_l0.c \ cdnet/parser/cdnet_l1.c \ cdnet/dev/cdctl.c \ @@ -138,7 +137,7 @@ C_INCLUDES = \ -IDrivers/CMSIS/Device/ST/STM32G4xx/Include \ -IDrivers/CMSIS/Include \ -Icdnet/parser \ --Icdnet/dispatch \ +-Icdnet/core \ -Icdnet/utils \ -Icdnet/dev \ -Icdnet/arch/stm32 \ diff --git a/mdrv_bl/cdnet b/mdrv_bl/cdnet index 170eb1f..eaad950 160000 --- a/mdrv_bl/cdnet +++ b/mdrv_bl/cdnet @@ -1 +1 @@ -Subproject commit 170eb1f081ac546a249090e2521f66bbdddbfc94 +Subproject commit eaad9501596f9305c7b51c5201a5cc1b832f6240 diff --git a/mdrv_bl/usr/app_main.h b/mdrv_bl/usr/app_main.h index fa9c13f..56fc6e4 100644 --- a/mdrv_bl/usr/app_main.h +++ b/mdrv_bl/usr/app_main.h @@ -10,7 +10,7 @@ #ifndef __APP_MAIN_H__ #define __APP_MAIN_H__ -#include "cdnet_dispatch.h" +#include "cdnet_core.h" #include "cd_debug.h" #include "cdbus_uart.h" #include "cdctl.h" diff --git a/mdrv_fw/Makefile b/mdrv_fw/Makefile index 3f8ed08..412056c 100644 --- a/mdrv_fw/Makefile +++ b/mdrv_fw/Makefile @@ -67,8 +67,7 @@ Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_uart_ex.c \ Core/Src/system_stm32g4xx.c \ Core/Src/sysmem.c \ Core/Src/syscalls.c \ -cdnet/dispatch/cdnet_dispatch.c \ -cdnet/dispatch/helper.c \ +cdnet/core/cdnet_core.c \ cdnet/parser/cdnet_l0.c \ cdnet/parser/cdnet_l1.c \ cdnet/dev/cdctl_it.c \ @@ -147,7 +146,7 @@ C_INCLUDES = \ -IDrivers/CMSIS/Device/ST/STM32G4xx/Include \ -IDrivers/CMSIS/Include \ -Icdnet/parser \ --Icdnet/dispatch \ +-Icdnet/core \ -Icdnet/utils \ -Icdnet/dev \ -Icdnet/arch/stm32 \ diff --git a/mdrv_fw/cdnet b/mdrv_fw/cdnet index 170eb1f..eaad950 160000 --- a/mdrv_fw/cdnet +++ b/mdrv_fw/cdnet @@ -1 +1 @@ -Subproject commit 170eb1f081ac546a249090e2521f66bbdddbfc94 +Subproject commit eaad9501596f9305c7b51c5201a5cc1b832f6240 diff --git a/mdrv_fw/usr/app_main.c b/mdrv_fw/usr/app_main.c index 74c693d..8a64e6f 100644 --- a/mdrv_fw/usr/app_main.c +++ b/mdrv_fw/usr/app_main.c @@ -77,33 +77,6 @@ static void device_init(void) } -extern uint32_t end; // end of bss -#define STACK_CHECK_SKIP 0x200 -#define STACK_CHECK_SIZE (64 + STACK_CHECK_SKIP) - -static void stack_check_init(void) -{ - int i; - printf("stack_check_init: skip: %p ~ %p, to %p\n", - &end, &end + STACK_CHECK_SKIP, &end + STACK_CHECK_SIZE); - for (i = STACK_CHECK_SKIP; i < STACK_CHECK_SIZE; i+=4) - *(uint32_t *)(&end + i) = 0xababcdcd; -} - -static void stack_check(void) -{ - int i; - for (i = STACK_CHECK_SKIP; i < STACK_CHECK_SIZE; i+=4) { - if (*(uint32_t *)(&end + i) != 0xababcdcd) { - printf("stack overflow %p (skip: %p ~ %p): %08lx\n", - &end + i, &end, &end + STACK_CHECK_SKIP, *(uint32_t *)(&end + i)); - d_error("stack overflow %p (skip: %p ~ %p): %08lx\n", - &end + i, &end, &end + STACK_CHECK_SKIP, *(uint32_t *)(&end + i)); - while (true); - } - } -} - #if 0 static void dump_hw_status(void) { @@ -317,7 +290,8 @@ void cali_elec_angle(void) d_info("cali: finished, result:\n"); d_info("cali: cw: %02x\n", (amount_f / csa.motor_poles) & 0xffff); d_info("cali: ccw: %02x\n", (amount_r / csa.motor_poles) & 0xffff); - d_info("cali: avg: %02x\n", ((amount_f + amount_r) / csa.motor_poles / 2) & 0xffff); + csa.bias_encoder = ((amount_f + amount_r) / csa.motor_poles / 2) & 0xffff; + d_info("cali: avg: %02x, updated to bias_encoder\n", csa.bias_encoder); uint8_t dat = ST_STOP; state_w_hook_before(0, 1, &dat); csa.state = ST_STOP; @@ -354,11 +328,13 @@ void cali_elec_angle(void) void app_main(void) { + uint64_t *stack_check = (uint64_t *)((uint32_t)&end + 256); + gpio_set_value(&led_r, 1); gpio_set_value(&led_g, 1); printf("\nstart app_main (mdrv)...\n"); + *stack_check = 0xababcdcd12123434; - stack_check_init(); load_conf(); debug_init(&dft_ns, &csa.dbg_dst, &csa.dbg_en); device_init(); @@ -452,13 +428,17 @@ void app_main(void) } } - stack_check(); app_motor_routine(); cdn_routine(&dft_ns); // handle cdnet common_service_routine(); cali_elec_angle(); //dump_hw_status(); debug_flush(false); + + if (*stack_check != 0xababcdcd12123434) { + printf("stack overflow\n"); + while (true); + } } } diff --git a/mdrv_fw/usr/app_main.h b/mdrv_fw/usr/app_main.h index 11b3fbf..09f7c44 100644 --- a/mdrv_fw/usr/app_main.h +++ b/mdrv_fw/usr/app_main.h @@ -10,7 +10,7 @@ #ifndef __APP_MAIN_H__ #define __APP_MAIN_H__ -#include "cdnet_dispatch.h" +#include "cdnet_core.h" #include "cd_debug.h" #include "cdbus_uart.h" #include "cdctl_it.h" @@ -222,6 +222,8 @@ extern gpio_t sen_int; extern cdn_ns_t dft_ns; extern list_head_t frame_free_head; +extern uint32_t end; // end of bss + inline void encoder_isr(void) {