├── README.md ├── RobotDog ├── Bsp │ ├── mpu6050.c │ ├── mpu6050.h │ ├── nrf24l01.c │ ├── nrf24l01.h │ ├── remote.c │ ├── remote.h │ ├── scs009.c │ ├── scs009.h │ ├── soft_i2c.c │ └── soft_i2c.h ├── Inc │ ├── FreeRTOSConfig.h │ ├── gpio.h │ ├── main.h │ ├── spi.h │ ├── stm32f4xx_hal_conf.h │ ├── stm32f4xx_it.h │ └── usart.h ├── RobotDog.ioc ├── Src │ ├── freertos.c │ ├── gpio.c │ ├── main.c │ ├── spi.c │ ├── stm32f4xx_hal_msp.c │ ├── stm32f4xx_hal_timebase_tim.c │ ├── stm32f4xx_it.c │ ├── system_stm32f4xx.c │ └── usart.c └── Task │ ├── body_task.c │ ├── body_task.h │ ├── head_task.c │ ├── head_task.h │ ├── robotcmd.c │ └── robotcmd.h ├── RobotDog_Remote ├── Inc │ ├── adc.h │ ├── dma.h │ ├── gpio.h │ ├── main.h │ ├── nrf24l01.h │ ├── spi.h │ ├── stm32f1xx_hal_conf.h │ └── stm32f1xx_it.h ├── RoboDog_Remote.ioc └── Src │ ├── adc.c │ ├── dma.c │ ├── gpio.c │ ├── main.c │ ├── nrf24l01.c │ ├── spi.c │ ├── stm32f1xx_hal_msp.c │ ├── stm32f1xx_it.c │ └── system_stm32f1xx.c └── img ├── RobotDog.jpg ├── 上下云台稳.gif ├── 全向移动.gif ├── 左右云台稳.gif └── 狗头乱动.gif /README.md: -------------------------------------------------------------------------------- 1 | ![RobotDog](img/RobotDog.jpg) 2 | 3 | # RobotDog机器狗 4 | 小型四足机器人源码 5 | 6 | ## 资源总览 7 | * 机械设计:SolidWorks 2016 8 | * 结构材料:PLA 3D打印 9 | * 电机:飞特SCS0009舵机 10 | * 电池:12V锂电池 11 | * 控制芯片:遥控器:STM32F103C8T6;机器狗:STM32F405RGT6 12 | * 无线通信模块:NRF24L01 13 | * 陀螺仪:MPU6050 14 | * 开发环境:STM32CubeMX+Keil 5 15 | * 代码库:遥控器:HAL库;机器狗:HAL库+FreeRTOS 16 | 17 | ## 文件说明 18 | `RobotDog`是四足机器人的代码,`RobotDog_Remote`是四足机器人的遥控器的代码。每个文件夹里面都有一个STM32CubeMX工程`.ioc`文件,可以使用STM32CubeMX打开重新生成工程文件。 19 | 20 | ## 机器人功能展示 21 | * 全向移动 22 | 23 | ![全向移动](img/全向移动.gif) 24 | 25 | * 狗头稳定 26 | 27 | ![狗头稳定](img/上下云台稳.gif) 28 | ![狗头稳定](img/左右云台稳.gif) 29 | 30 | * 更多细节待你发现 31 | 32 | ## 代码详解 33 | 参见以下文章: 34 | 35 | * [四足机器人制作(一) 腿部运动算法](https://imuncle.github.io/content.html?id=61) 36 | * [四足机器人制作(二) 姿态解析](https://imuncle.github.io/content.html?id=62) 37 | * [四足机器人制作(三) 全向移动](https://imuncle.github.io/content.html?id=63) 38 | * [四足机器人制作(四) 云台稳定](https://imuncle.github.io/content.html?id=64) 39 | * [四足机器人制作 (五) 代码实现](https://imuncle.github.io/content.html?id=73) 40 | * [四足机器人制作(六) 更便捷的姿态解析](https://imuncle.github.io/content.html?id=74) -------------------------------------------------------------------------------- /RobotDog/Bsp/mpu6050.c: -------------------------------------------------------------------------------- 1 | #include "mpu6050.h" 2 | #include "soft_i2c.h" 3 | #include "math.h" 4 | 5 | #define DEG2RAD 0.017453293f /*度转弧度*/ 6 | #define RAD2DEG 57.29578f /*弧度转度*/ 7 | 8 | struct MPU6500_t mpu6500; 9 | 10 | BiasObj gyroBiasRunning; 11 | int gyroBiasFound = 0; 12 | 13 | float Kp = 1.0f; /*比例增益*/ 14 | float Ki = 0.5f; /*积分增益*/ 15 | 16 | float q0 = 1.0f; /*四元数*/ 17 | float q1 = 0.0f; 18 | float q2 = 0.0f; 19 | float q3 = 0.0f; 20 | 21 | uint8_t imu_data[14]={0}; 22 | 23 | struct Axisf gyroBias; 24 | 25 | volatile uint32_t last_update, now_update; 26 | 27 | int MPU6050_Init(void) 28 | { 29 | uint8_t temp_data = 0; 30 | if(IIC_ReadData(MPU6050_ADDRESS, MPU_WHO_I_AM, &temp_data, 1) == 0) 31 | { 32 | if(temp_data != 0x68) 33 | { 34 | return 0xff; 35 | } 36 | } 37 | else 38 | { 39 | return 0xff; 40 | } 41 | 42 | if(IIC_WriteData(MPU6050_ADDRESS,MPU_PWR_MGMT1_REG,0x01) == 0xff) //½â³ýÐÝÃß״̬ 43 | { 44 | return 0xff; 45 | } 46 | if(IIC_WriteData(MPU6050_ADDRESS,MPU_SAMPLE_RATE_REG,0x07) == 0xff)//cyq£º07 ¸üÐÂÆµÂÊ1khz 47 | { 48 | return 0xff; 49 | } 50 | if(IIC_WriteData(MPU6050_ADDRESS,MPU_CFG_REG,6) == 0xff) 51 | { 52 | return 0xff; 53 | } 54 | if(IIC_WriteData(MPU6050_ADDRESS,MPU_GYRO_CFG_REG,0x18) == 0xff) //Á¿³Ì500¡ã/s 55 | { 56 | return 0xff; 57 | } 58 | return 0; 59 | } 60 | 61 | int MPU6050_ReadData(void) 62 | { 63 | if(IIC_ReadData(MPU6050_ADDRESS, MPU_ACCEL_XOUTH_REG, imu_data, 14) == 0xff) 64 | { 65 | return 0xff; 66 | } 67 | else 68 | { 69 | return 0; 70 | } 71 | } 72 | 73 | /*计算方差和平均值*/ 74 | static void sensorsCalculateVarianceAndMean(BiasObj* bias, struct Axisf* varOut, struct Axisf* meanOut) 75 | { 76 | uint32_t i; 77 | int64_t sum[3] = {0}; 78 | int64_t sumsq[3] = {0}; 79 | 80 | for (i = 0; i < SENSORS_NBR_OF_BIAS_SAMPLES; i++) 81 | { 82 | sum[0] += bias->buffer[i].x; 83 | sum[1] += bias->buffer[i].y; 84 | sum[2] += bias->buffer[i].z; 85 | sumsq[0] += bias->buffer[i].x * bias->buffer[i].x; 86 | sumsq[1] += bias->buffer[i].y * bias->buffer[i].y; 87 | sumsq[2] += bias->buffer[i].z * bias->buffer[i].z; 88 | } 89 | 90 | varOut->x = (sumsq[0] - ((int64_t)sum[0] * sum[0]) / SENSORS_NBR_OF_BIAS_SAMPLES); 91 | varOut->y = (sumsq[1] - ((int64_t)sum[1] * sum[1]) / SENSORS_NBR_OF_BIAS_SAMPLES); 92 | varOut->z = (sumsq[2] - ((int64_t)sum[2] * sum[2]) / SENSORS_NBR_OF_BIAS_SAMPLES); 93 | 94 | meanOut->x = (float)sum[0] / SENSORS_NBR_OF_BIAS_SAMPLES; 95 | meanOut->y = (float)sum[1] / SENSORS_NBR_OF_BIAS_SAMPLES; 96 | meanOut->z = (float)sum[2] / SENSORS_NBR_OF_BIAS_SAMPLES; 97 | } 98 | 99 | /*传感器查找偏置值*/ 100 | static int sensorsFindBiasValue(BiasObj* bias) 101 | { 102 | int foundbias = 0; 103 | 104 | if (bias->isBufferFilled) 105 | { 106 | 107 | struct Axisf mean; 108 | struct Axisf variance; 109 | sensorsCalculateVarianceAndMean(bias, &variance, &mean); 110 | 111 | if (variance.x < GYRO_VARIANCE_BASE && variance.y < GYRO_VARIANCE_BASE && variance.z < GYRO_VARIANCE_BASE) 112 | { 113 | bias->bias.x = mean.x; 114 | bias->bias.y = mean.y; 115 | bias->bias.z = mean.z; 116 | foundbias = 1; 117 | bias->isBiasValueFound= 1; 118 | }else 119 | bias->isBufferFilled=0; 120 | } 121 | return foundbias; 122 | } 123 | 124 | /** 125 | * 计算陀螺方差 126 | */ 127 | int processGyroBias(int16_t gx, int16_t gy, int16_t gz, struct Axisf *gyroBiasOut) 128 | { 129 | static int count = 0; 130 | gyroBiasRunning.buffer[count].x = gx; 131 | gyroBiasRunning.buffer[count].y = gy; 132 | gyroBiasRunning.buffer[count].z = gz; 133 | count++; 134 | if(count == 1024) 135 | { 136 | count = 0; 137 | gyroBiasRunning.isBufferFilled = 1; 138 | } 139 | 140 | if (!gyroBiasRunning.isBiasValueFound) 141 | { 142 | sensorsFindBiasValue(&gyroBiasRunning); 143 | } 144 | 145 | gyroBiasOut->x = gyroBiasRunning.bias.x; 146 | gyroBiasOut->y = gyroBiasRunning.bias.y; 147 | gyroBiasOut->z = gyroBiasRunning.bias.z; 148 | 149 | return gyroBiasRunning.isBiasValueFound; 150 | } 151 | 152 | void imuDataHandle(void) 153 | { 154 | short gyrox,gyroy,gyroz; 155 | float fgyrox, fgyroy, fgyroz; 156 | float gyro_sensitivity = 16.384f; 157 | 158 | gyrox = (imu_data[8]<<8)|imu_data[9]; 159 | gyroy = (imu_data[10]<<8)|imu_data[11]; 160 | gyroz = (imu_data[12]<<8)|imu_data[13]; 161 | 162 | gyroBiasFound = processGyroBias(gyrox, gyroy, gyroz, &gyroBias); 163 | 164 | fgyrox = -(float)(gyrox-gyroBias.x)/gyro_sensitivity; 165 | fgyroy = (float)(gyroy-gyroBias.y)/gyro_sensitivity; 166 | fgyroz = (float)(gyroz-gyroBias.z)/gyro_sensitivity; 167 | 168 | mpu6500.gyro.x = 0.8f*fgyrox + 0.2f*mpu6500.gyro.x; 169 | mpu6500.gyro.y = 0.8f*fgyroy + 0.2f*mpu6500.gyro.y; 170 | mpu6500.gyro.z = 0.8f*fgyroz + 0.2f*mpu6500.gyro.z; 171 | 172 | if(mpu6500.gyro.x < 0.1f && mpu6500.gyro.x > -0.1f) mpu6500.gyro.x = 0; 173 | if(mpu6500.gyro.y < 0.1f && mpu6500.gyro.y > -0.1f) mpu6500.gyro.y = 0; 174 | if(mpu6500.gyro.z < 0.1f && mpu6500.gyro.z > -0.1f) mpu6500.gyro.z = 0; 175 | } 176 | 177 | void imuUpdate(struct Axisf gyro) 178 | { 179 | float normalise; 180 | float halfT; 181 | 182 | now_update = HAL_GetTick(); //单位ms 183 | halfT = ((float)(now_update - last_update) / 2000.0f); 184 | last_update = now_update; 185 | 186 | gyro.x *= DEG2RAD; /*度转弧度*/ 187 | gyro.y *= DEG2RAD; 188 | gyro.z *= DEG2RAD; 189 | 190 | /* 使用一阶龙格库塔更新四元数 */ 191 | q0 += (-q1 * gyro.x - q2 * gyro.y - q3 * gyro.z) * halfT; 192 | q1 += ( q0 * gyro.x + q2 * gyro.z - q3 * gyro.y) * halfT; 193 | q2 += ( q0 * gyro.y - q1 * gyro.z + q3 * gyro.x) * halfT; 194 | q3 += ( q0 * gyro.z + q1 * gyro.y - q2 * gyro.x) * halfT; 195 | 196 | /* 对四元数进行归一化处理 */ 197 | normalise = sqrt(q0 * q0 + q1 * q1 + q2 * q2 + q3 * q3); 198 | q0 /= normalise; 199 | q1 /= normalise; 200 | q2 /= normalise; 201 | q3 /= normalise; 202 | 203 | /* 由四元数求解欧拉角 */ 204 | mpu6500.attitude.z = atan2f(2*q1*q2 + 2*q0*q3, -2*q2*q2 - 2*q3*q3 + 1) * RAD2DEG; //yaw 205 | mpu6500.attitude.y = atan2f(2*q2*q3 + 2*q0*q1, -2*q1*q1 - 2*q2*q2 + 1) * RAD2DEG; //roll 206 | mpu6500.attitude.x = -asinf(-2*q1*q3 + 2*q0*q2) * RAD2DEG; //pitch 207 | 208 | mpu6500.angle.yaw = mpu6500.attitude.z; 209 | mpu6500.angle.pitch = mpu6500.attitude.x; 210 | mpu6500.angle.roll = mpu6500.attitude.y; 211 | } 212 | -------------------------------------------------------------------------------- /RobotDog/Bsp/mpu6050.h: -------------------------------------------------------------------------------- 1 | #ifndef MPU6050_H 2 | #define MPU6050_H 3 | 4 | #define MPU6050_ADDRESS 0xD0 5 | #define MPU_PWR_MGMT1_REG 0X6B //电源管理寄存器1 6 | #define MPU_SAMPLE_RATE_REG 0X19 //陀螺仪采样频率分频器 7 | #define MPU_CFG_REG 0x1A 8 | #define MPU_GYRO_CFG_REG 0X1B //陀螺仪配置寄存器 9 | #define MPU_INT_PIN_CFG 0X37 10 | 11 | #define MPU_WHO_I_AM 0x75 //陀螺仪ID 12 | 13 | #define MPU_ACCEL_XOUTH_REG 0X3B //加速度值,X轴高8位寄存器 14 | #define MPU_ACCEL_XOUTL_REG 0X3C //加速度值,X轴低8位寄存器 15 | #define MPU_ACCEL_YOUTH_REG 0X3D //加速度值,Y轴高8位寄存器 16 | #define MPU_ACCEL_YOUTL_REG 0X3E //加速度值,Y轴低8位寄存器 17 | #define MPU_ACCEL_ZOUTH_REG 0X3F //加速度值,Z轴高8位寄存器 18 | #define MPU_ACCEL_ZOUTL_REG 0X40 //加速度值,Z轴低8位寄存器 19 | 20 | #define MPU_GYRO_XOUTH_REG 0X43 //陀螺仪值,X轴高8位寄存器 21 | #define MPU_GYRO_XOUTL_REG 0X44 //陀螺仪值,X轴低8位寄存器 22 | #define MPU_GYRO_YOUTH_REG 0X45 //陀螺仪值,Y轴高8位寄存器 23 | #define MPU_GYRO_YOUTL_REG 0X46 //陀螺仪值,Y轴低8位寄存器 24 | #define MPU_GYRO_ZOUTH_REG 0X47 //陀螺仪值,Z轴高8位寄存器 25 | #define MPU_GYRO_ZOUTL_REG 0X48 //陀螺仪值,Z轴低8位寄存器 26 | 27 | #define SENSORS_NBR_OF_BIAS_SAMPLES 1024 /*计算方差的采样样本个数 */ 28 | #define GYRO_VARIANCE_BASE 4000 /* 陀螺仪零偏方差阈值 */ 29 | 30 | struct Axisf 31 | { 32 | float x; 33 | float y; 34 | float z; 35 | }; 36 | 37 | struct Axisi 38 | { 39 | int x; 40 | int y; 41 | int z; 42 | }; 43 | 44 | struct MPU6500_t 45 | { 46 | struct Axisf gyro; 47 | struct Axisf attitude; 48 | struct 49 | { 50 | int yaw; 51 | int last_yaw; 52 | int encoder_yaw; 53 | int yaw_count; 54 | int pitch; 55 | int roll; 56 | } angle; 57 | }; 58 | 59 | typedef struct 60 | { 61 | struct Axisf bias; 62 | int isBiasValueFound; 63 | int isBufferFilled; 64 | struct Axisi buffer[SENSORS_NBR_OF_BIAS_SAMPLES]; 65 | }BiasObj; 66 | 67 | extern BiasObj gyroBiasRunning; 68 | extern struct MPU6500_t mpu6500; 69 | 70 | int MPU6050_Init(void); 71 | int MPU6050_ReadData(void); 72 | void imuDataHandle(void); 73 | void imuUpdate(struct Axisf gyro); 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /RobotDog/Bsp/nrf24l01.c: -------------------------------------------------------------------------------- 1 | #include "nrf24l01.h" 2 | 3 | const uint8_t TX_ADDRESS[TX_ADR_WIDTH]={0xb0,0x43,0x10,0x10,0x01}; 4 | const uint8_t RX_ADDRESS[RX_ADR_WIDTH]={0xb0,0x43,0x10,0x10,0x01}; 5 | 6 | uint8_t SPIx_ReadWriteByte(SPI_HandleTypeDef* hspi,uint8_t byte) 7 | { 8 | uint8_t d_read,d_send=byte; 9 | if(HAL_SPI_TransmitReceive(hspi,&d_send,&d_read,1,0xFF)!=HAL_OK) 10 | { 11 | d_read=0xFF; 12 | } 13 | return d_read; 14 | } 15 | 16 | uint8_t NRF24L01_Write_Buf(uint8_t reg, uint8_t *pBuf, uint8_t len) 17 | { 18 | uint8_t status,uint8_t_ctr; 19 | HAL_GPIO_WritePin(GPIO_CSN, GPIO_CSN_PIN, GPIO_PIN_RESET); 20 | status=SPIx_ReadWriteByte(&hspi_NRF24L01,reg); 21 | for(uint8_t_ctr=0; uint8_t_ctr> 8; 25 | tmp_position[1] = nDat[i]; 26 | HAL_UART_Transmit(&huart2, tmp_position, nLen, 10); 27 | checkSum += ID[i]; 28 | // for(j=0; j>!AND MODIFIED BY!<< the FreeRTOS exception. 13 | 14 | *************************************************************************** 15 | >>! NOTE: The modification to the GPL is included to allow you to !<< 16 | >>! distribute a combined work that includes FreeRTOS without being !<< 17 | >>! obliged to provide the source code for proprietary components !<< 18 | >>! outside of the FreeRTOS kernel. !<< 19 | *************************************************************************** 20 | 21 | FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY 22 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 23 | FOR A PARTICULAR PURPOSE. Full license text is available on the following 24 | link: http://www.freertos.org/a00114.html 25 | 26 | *************************************************************************** 27 | * * 28 | * FreeRTOS provides completely free yet professionally developed, * 29 | * robust, strictly quality controlled, supported, and cross * 30 | * platform software that is more than just the market leader, it * 31 | * is the industry's de facto standard. * 32 | * * 33 | * Help yourself get started quickly while simultaneously helping * 34 | * to support the FreeRTOS project by purchasing a FreeRTOS * 35 | * tutorial book, reference manual, or both: * 36 | * http://www.FreeRTOS.org/Documentation * 37 | * * 38 | *************************************************************************** 39 | 40 | http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading 41 | the FAQ page "My application does not run, what could be wrong?". Have you 42 | defined configASSERT()? 43 | 44 | http://www.FreeRTOS.org/support - In return for receiving this top quality 45 | embedded software for free we request you assist our global community by 46 | participating in the support forum. 47 | 48 | http://www.FreeRTOS.org/training - Investing in training allows your team to 49 | be as productive as possible as early as possible. Now you can receive 50 | FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers 51 | Ltd, and the world's leading authority on the world's leading RTOS. 52 | 53 | http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, 54 | including FreeRTOS+Trace - an indispensable productivity tool, a DOS 55 | compatible FAT file system, and our tiny thread aware UDP/IP stack. 56 | 57 | http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate. 58 | Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS. 59 | 60 | http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High 61 | Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS 62 | licenses offer ticketed support, indemnification and commercial middleware. 63 | 64 | http://www.SafeRTOS.com - High Integrity Systems also provide a safety 65 | engineered and independently SIL3 certified version for use in safety and 66 | mission critical applications that require provable dependability. 67 | 68 | 1 tab == 4 spaces! 69 | */ 70 | /* USER CODE END Header */ 71 | 72 | #ifndef FREERTOS_CONFIG_H 73 | #define FREERTOS_CONFIG_H 74 | 75 | /*----------------------------------------------------------- 76 | * Application specific definitions. 77 | * 78 | * These definitions should be adjusted for your particular hardware and 79 | * application requirements. 80 | * 81 | * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE 82 | * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. 83 | * 84 | * See http://www.freertos.org/a00110.html. 85 | *----------------------------------------------------------*/ 86 | 87 | /* USER CODE BEGIN Includes */ 88 | /* Section where include file can be added */ 89 | /* USER CODE END Includes */ 90 | 91 | /* Ensure stdint is only used by the compiler, and not the assembler. */ 92 | #if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__) 93 | #include 94 | extern uint32_t SystemCoreClock; 95 | #endif 96 | 97 | #define configUSE_PREEMPTION 1 98 | #define configSUPPORT_STATIC_ALLOCATION 0 99 | #define configSUPPORT_DYNAMIC_ALLOCATION 1 100 | #define configUSE_IDLE_HOOK 0 101 | #define configUSE_TICK_HOOK 0 102 | #define configCPU_CLOCK_HZ ( SystemCoreClock ) 103 | #define configTICK_RATE_HZ ((TickType_t)1000) 104 | #define configMAX_PRIORITIES ( 7 ) 105 | #define configMINIMAL_STACK_SIZE ((uint16_t)128) 106 | #define configTOTAL_HEAP_SIZE ((size_t)15360) 107 | #define configMAX_TASK_NAME_LEN ( 16 ) 108 | #define configUSE_16_BIT_TICKS 0 109 | #define configUSE_MUTEXES 1 110 | #define configQUEUE_REGISTRY_SIZE 8 111 | #define configUSE_PORT_OPTIMISED_TASK_SELECTION 1 112 | 113 | /* Co-routine definitions. */ 114 | #define configUSE_CO_ROUTINES 0 115 | #define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) 116 | 117 | /* Software timer definitions. */ 118 | #define configUSE_TIMERS 1 119 | #define configTIMER_TASK_PRIORITY ( 3 ) 120 | #define configTIMER_QUEUE_LENGTH 10 121 | #define configTIMER_TASK_STACK_DEPTH 256 122 | 123 | /* Set the following definitions to 1 to include the API function, or zero 124 | to exclude the API function. */ 125 | #define INCLUDE_vTaskPrioritySet 1 126 | #define INCLUDE_uxTaskPriorityGet 1 127 | #define INCLUDE_vTaskDelete 1 128 | #define INCLUDE_vTaskCleanUpResources 0 129 | #define INCLUDE_vTaskSuspend 1 130 | #define INCLUDE_vTaskDelayUntil 0 131 | #define INCLUDE_vTaskDelay 1 132 | #define INCLUDE_xTaskGetSchedulerState 1 133 | 134 | /* Cortex-M specific definitions. */ 135 | #ifdef __NVIC_PRIO_BITS 136 | /* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */ 137 | #define configPRIO_BITS __NVIC_PRIO_BITS 138 | #else 139 | #define configPRIO_BITS 4 140 | #endif 141 | 142 | /* The lowest interrupt priority that can be used in a call to a "set priority" 143 | function. */ 144 | #define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 15 145 | 146 | /* The highest interrupt priority that can be used by any interrupt service 147 | routine that makes calls to interrupt safe FreeRTOS API functions. DO NOT CALL 148 | INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER 149 | PRIORITY THAN THIS! (higher priorities are lower numeric values. */ 150 | #define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 5 151 | 152 | /* Interrupt priorities used by the kernel port layer itself. These are generic 153 | to all Cortex-M ports, and do not rely on any particular library functions. */ 154 | #define configKERNEL_INTERRUPT_PRIORITY ( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) ) 155 | /* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!! 156 | See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */ 157 | #define configMAX_SYSCALL_INTERRUPT_PRIORITY ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) ) 158 | 159 | /* Normal assert() semantics without relying on the provision of an assert.h 160 | header file. */ 161 | /* USER CODE BEGIN 1 */ 162 | #define configASSERT( x ) if ((x) == 0) {taskDISABLE_INTERRUPTS(); for( ;; );} 163 | /* USER CODE END 1 */ 164 | 165 | /* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS 166 | standard names. */ 167 | #define vPortSVCHandler SVC_Handler 168 | #define xPortPendSVHandler PendSV_Handler 169 | 170 | /* IMPORTANT: This define is commented when used with STM32Cube firmware, when timebase is systick, 171 | to prevent overwriting SysTick_Handler defined within STM32Cube HAL */ 172 | #define xPortSysTickHandler SysTick_Handler 173 | 174 | /* USER CODE BEGIN Defines */ 175 | /* Section where parameter definitions can be added (for instance, to override default ones in FreeRTOS.h) */ 176 | /* USER CODE END Defines */ 177 | 178 | #endif /* FREERTOS_CONFIG_H */ 179 | -------------------------------------------------------------------------------- /RobotDog/Inc/gpio.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * File Name : gpio.h 4 | * Description : This file contains all the functions prototypes for 5 | * the gpio 6 | ****************************************************************************** 7 | * This notice applies to any and all portions of this file 8 | * that are not between comment pairs USER CODE BEGIN and 9 | * USER CODE END. Other portions of this file, whether 10 | * inserted by the user or by software development tools 11 | * are owned by their respective copyright owners. 12 | * 13 | * Copyright (c) 2019 STMicroelectronics International N.V. 14 | * All rights reserved. 15 | * 16 | * Redistribution and use in source and binary forms, with or without 17 | * modification, are permitted, provided that the following conditions are met: 18 | * 19 | * 1. Redistribution of source code must retain the above copyright notice, 20 | * this list of conditions and the following disclaimer. 21 | * 2. Redistributions in binary form must reproduce the above copyright notice, 22 | * this list of conditions and the following disclaimer in the documentation 23 | * and/or other materials provided with the distribution. 24 | * 3. Neither the name of STMicroelectronics nor the names of other 25 | * contributors to this software may be used to endorse or promote products 26 | * derived from this software without specific written permission. 27 | * 4. This software, including modifications and/or derivative works of this 28 | * software, must execute solely and exclusively on microcontroller or 29 | * microprocessor devices manufactured by or for STMicroelectronics. 30 | * 5. Redistribution and use of this software other than as permitted under 31 | * this license is void and will automatically terminate your rights under 32 | * this license. 33 | * 34 | * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" 35 | * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT 36 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 37 | * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY 38 | * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT 39 | * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 40 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 42 | * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 43 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 44 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 45 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 46 | * 47 | ****************************************************************************** 48 | */ 49 | 50 | /* Define to prevent recursive inclusion -------------------------------------*/ 51 | #ifndef __gpio_H 52 | #define __gpio_H 53 | #ifdef __cplusplus 54 | extern "C" { 55 | #endif 56 | 57 | /* Includes ------------------------------------------------------------------*/ 58 | #include "main.h" 59 | 60 | /* USER CODE BEGIN Includes */ 61 | 62 | /* USER CODE END Includes */ 63 | 64 | /* USER CODE BEGIN Private defines */ 65 | 66 | /* USER CODE END Private defines */ 67 | 68 | void MX_GPIO_Init(void); 69 | 70 | /* USER CODE BEGIN Prototypes */ 71 | 72 | /* USER CODE END Prototypes */ 73 | 74 | #ifdef __cplusplus 75 | } 76 | #endif 77 | #endif /*__ pinoutConfig_H */ 78 | 79 | /** 80 | * @} 81 | */ 82 | 83 | /** 84 | * @} 85 | */ 86 | 87 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 88 | -------------------------------------------------------------------------------- /RobotDog/Inc/main.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : main.h 5 | * @brief : Header for main.c file. 6 | * This file contains the common defines of the application. 7 | ****************************************************************************** 8 | * This notice applies to any and all portions of this file 9 | * that are not between comment pairs USER CODE BEGIN and 10 | * USER CODE END. Other portions of this file, whether 11 | * inserted by the user or by software development tools 12 | * are owned by their respective copyright owners. 13 | * 14 | * Copyright (c) 2019 STMicroelectronics International N.V. 15 | * All rights reserved. 16 | * 17 | * Redistribution and use in source and binary forms, with or without 18 | * modification, are permitted, provided that the following conditions are met: 19 | * 20 | * 1. Redistribution of source code must retain the above copyright notice, 21 | * this list of conditions and the following disclaimer. 22 | * 2. Redistributions in binary form must reproduce the above copyright notice, 23 | * this list of conditions and the following disclaimer in the documentation 24 | * and/or other materials provided with the distribution. 25 | * 3. Neither the name of STMicroelectronics nor the names of other 26 | * contributors to this software may be used to endorse or promote products 27 | * derived from this software without specific written permission. 28 | * 4. This software, including modifications and/or derivative works of this 29 | * software, must execute solely and exclusively on microcontroller or 30 | * microprocessor devices manufactured by or for STMicroelectronics. 31 | * 5. Redistribution and use of this software other than as permitted under 32 | * this license is void and will automatically terminate your rights under 33 | * this license. 34 | * 35 | * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" 36 | * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT 37 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 38 | * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY 39 | * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT 40 | * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 41 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 42 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 43 | * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 44 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 45 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 46 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 47 | * 48 | ****************************************************************************** 49 | */ 50 | /* USER CODE END Header */ 51 | 52 | /* Define to prevent recursive inclusion -------------------------------------*/ 53 | #ifndef __MAIN_H 54 | #define __MAIN_H 55 | 56 | #ifdef __cplusplus 57 | extern "C" { 58 | #endif 59 | 60 | /* Includes ------------------------------------------------------------------*/ 61 | #include "stm32f4xx_hal.h" 62 | 63 | /* Private includes ----------------------------------------------------------*/ 64 | /* USER CODE BEGIN Includes */ 65 | 66 | /* USER CODE END Includes */ 67 | 68 | /* Exported types ------------------------------------------------------------*/ 69 | /* USER CODE BEGIN ET */ 70 | 71 | /* USER CODE END ET */ 72 | 73 | /* Exported constants --------------------------------------------------------*/ 74 | /* USER CODE BEGIN EC */ 75 | 76 | /* USER CODE END EC */ 77 | 78 | /* Exported macro ------------------------------------------------------------*/ 79 | /* USER CODE BEGIN EM */ 80 | 81 | /* USER CODE END EM */ 82 | 83 | /* Exported functions prototypes ---------------------------------------------*/ 84 | void Error_Handler(void); 85 | 86 | /* USER CODE BEGIN EFP */ 87 | 88 | /* USER CODE END EFP */ 89 | 90 | /* Private defines -----------------------------------------------------------*/ 91 | /* USER CODE BEGIN Private defines */ 92 | 93 | /* USER CODE END Private defines */ 94 | 95 | #ifdef __cplusplus 96 | } 97 | #endif 98 | 99 | #endif /* __MAIN_H */ 100 | 101 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 102 | -------------------------------------------------------------------------------- /RobotDog/Inc/spi.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * File Name : SPI.h 4 | * Description : This file provides code for the configuration 5 | * of the SPI instances. 6 | ****************************************************************************** 7 | * This notice applies to any and all portions of this file 8 | * that are not between comment pairs USER CODE BEGIN and 9 | * USER CODE END. Other portions of this file, whether 10 | * inserted by the user or by software development tools 11 | * are owned by their respective copyright owners. 12 | * 13 | * Copyright (c) 2019 STMicroelectronics International N.V. 14 | * All rights reserved. 15 | * 16 | * Redistribution and use in source and binary forms, with or without 17 | * modification, are permitted, provided that the following conditions are met: 18 | * 19 | * 1. Redistribution of source code must retain the above copyright notice, 20 | * this list of conditions and the following disclaimer. 21 | * 2. Redistributions in binary form must reproduce the above copyright notice, 22 | * this list of conditions and the following disclaimer in the documentation 23 | * and/or other materials provided with the distribution. 24 | * 3. Neither the name of STMicroelectronics nor the names of other 25 | * contributors to this software may be used to endorse or promote products 26 | * derived from this software without specific written permission. 27 | * 4. This software, including modifications and/or derivative works of this 28 | * software, must execute solely and exclusively on microcontroller or 29 | * microprocessor devices manufactured by or for STMicroelectronics. 30 | * 5. Redistribution and use of this software other than as permitted under 31 | * this license is void and will automatically terminate your rights under 32 | * this license. 33 | * 34 | * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" 35 | * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT 36 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 37 | * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY 38 | * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT 39 | * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 40 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 42 | * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 43 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 44 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 45 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 46 | * 47 | ****************************************************************************** 48 | */ 49 | /* Define to prevent recursive inclusion -------------------------------------*/ 50 | #ifndef __spi_H 51 | #define __spi_H 52 | #ifdef __cplusplus 53 | extern "C" { 54 | #endif 55 | 56 | /* Includes ------------------------------------------------------------------*/ 57 | #include "main.h" 58 | 59 | /* USER CODE BEGIN Includes */ 60 | 61 | /* USER CODE END Includes */ 62 | 63 | extern SPI_HandleTypeDef hspi1; 64 | 65 | /* USER CODE BEGIN Private defines */ 66 | 67 | /* USER CODE END Private defines */ 68 | 69 | void MX_SPI1_Init(void); 70 | 71 | /* USER CODE BEGIN Prototypes */ 72 | 73 | /* USER CODE END Prototypes */ 74 | 75 | #ifdef __cplusplus 76 | } 77 | #endif 78 | #endif /*__ spi_H */ 79 | 80 | /** 81 | * @} 82 | */ 83 | 84 | /** 85 | * @} 86 | */ 87 | 88 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 89 | -------------------------------------------------------------------------------- /RobotDog/Inc/stm32f4xx_it.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32f4xx_it.h 5 | * @brief This file contains the headers of the interrupt handlers. 6 | ****************************************************************************** 7 | * 8 | * COPYRIGHT(c) 2019 STMicroelectronics 9 | * 10 | * Redistribution and use in source and binary forms, with or without modification, 11 | * are permitted provided that the following conditions are met: 12 | * 1. Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright notice, 15 | * this list of conditions and the following disclaimer in the documentation 16 | * and/or other materials provided with the distribution. 17 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | ****************************************************************************** 33 | */ 34 | /* USER CODE END Header */ 35 | 36 | /* Define to prevent recursive inclusion -------------------------------------*/ 37 | #ifndef __STM32F4xx_IT_H 38 | #define __STM32F4xx_IT_H 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | /* Private includes ----------------------------------------------------------*/ 45 | /* USER CODE BEGIN Includes */ 46 | 47 | /* USER CODE END Includes */ 48 | 49 | /* Exported types ------------------------------------------------------------*/ 50 | /* USER CODE BEGIN ET */ 51 | 52 | /* USER CODE END ET */ 53 | 54 | /* Exported constants --------------------------------------------------------*/ 55 | /* USER CODE BEGIN EC */ 56 | 57 | /* USER CODE END EC */ 58 | 59 | /* Exported macro ------------------------------------------------------------*/ 60 | /* USER CODE BEGIN EM */ 61 | 62 | /* USER CODE END EM */ 63 | 64 | /* Exported functions prototypes ---------------------------------------------*/ 65 | void NMI_Handler(void); 66 | void HardFault_Handler(void); 67 | void MemManage_Handler(void); 68 | void BusFault_Handler(void); 69 | void UsageFault_Handler(void); 70 | void DebugMon_Handler(void); 71 | void EXTI2_IRQHandler(void); 72 | void TIM7_IRQHandler(void); 73 | /* USER CODE BEGIN EFP */ 74 | 75 | /* USER CODE END EFP */ 76 | 77 | #ifdef __cplusplus 78 | } 79 | #endif 80 | 81 | #endif /* __STM32F4xx_IT_H */ 82 | 83 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 84 | -------------------------------------------------------------------------------- /RobotDog/Inc/usart.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * File Name : USART.h 4 | * Description : This file provides code for the configuration 5 | * of the USART instances. 6 | ****************************************************************************** 7 | * This notice applies to any and all portions of this file 8 | * that are not between comment pairs USER CODE BEGIN and 9 | * USER CODE END. Other portions of this file, whether 10 | * inserted by the user or by software development tools 11 | * are owned by their respective copyright owners. 12 | * 13 | * Copyright (c) 2019 STMicroelectronics International N.V. 14 | * All rights reserved. 15 | * 16 | * Redistribution and use in source and binary forms, with or without 17 | * modification, are permitted, provided that the following conditions are met: 18 | * 19 | * 1. Redistribution of source code must retain the above copyright notice, 20 | * this list of conditions and the following disclaimer. 21 | * 2. Redistributions in binary form must reproduce the above copyright notice, 22 | * this list of conditions and the following disclaimer in the documentation 23 | * and/or other materials provided with the distribution. 24 | * 3. Neither the name of STMicroelectronics nor the names of other 25 | * contributors to this software may be used to endorse or promote products 26 | * derived from this software without specific written permission. 27 | * 4. This software, including modifications and/or derivative works of this 28 | * software, must execute solely and exclusively on microcontroller or 29 | * microprocessor devices manufactured by or for STMicroelectronics. 30 | * 5. Redistribution and use of this software other than as permitted under 31 | * this license is void and will automatically terminate your rights under 32 | * this license. 33 | * 34 | * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" 35 | * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT 36 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 37 | * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY 38 | * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT 39 | * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 40 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 42 | * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 43 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 44 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 45 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 46 | * 47 | ****************************************************************************** 48 | */ 49 | /* Define to prevent recursive inclusion -------------------------------------*/ 50 | #ifndef __usart_H 51 | #define __usart_H 52 | #ifdef __cplusplus 53 | extern "C" { 54 | #endif 55 | 56 | /* Includes ------------------------------------------------------------------*/ 57 | #include "main.h" 58 | 59 | /* USER CODE BEGIN Includes */ 60 | 61 | /* USER CODE END Includes */ 62 | 63 | extern UART_HandleTypeDef huart2; 64 | 65 | /* USER CODE BEGIN Private defines */ 66 | 67 | /* USER CODE END Private defines */ 68 | 69 | void MX_USART2_UART_Init(void); 70 | 71 | /* USER CODE BEGIN Prototypes */ 72 | 73 | /* USER CODE END Prototypes */ 74 | 75 | #ifdef __cplusplus 76 | } 77 | #endif 78 | #endif /*__ usart_H */ 79 | 80 | /** 81 | * @} 82 | */ 83 | 84 | /** 85 | * @} 86 | */ 87 | 88 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 89 | -------------------------------------------------------------------------------- /RobotDog/RobotDog.ioc: -------------------------------------------------------------------------------- 1 | #MicroXplorer Configuration settings - do not modify 2 | FREERTOS.FootprintOK=true 3 | FREERTOS.IPParameters=Tasks01,configUSE_TIMERS,configTIMER_TASK_PRIORITY,FootprintOK,Timers01 4 | FREERTOS.Tasks01=RobotCmd,0,128,robotcmd_task,Default,NULL,Dynamic,NULL,NULL;Imu,0,256,imu_task,Default,NULL,Dynamic,NULL,NULL;Body,0,512,body_task,Default,NULL,Dynamic,NULL,NULL;Head,0,512,head_task,Default,NULL,Dynamic,NULL,NULL;Remote,0,128,remote_task,Default,NULL,Dynamic,NULL,NULL 5 | FREERTOS.Timers01=Led,led_timer,osTimerPeriodic,Default,NULL,Dynamic,NULL 6 | FREERTOS.configTIMER_TASK_PRIORITY=3 7 | FREERTOS.configUSE_TIMERS=1 8 | File.Version=6 9 | KeepUserPlacement=false 10 | Mcu.Family=STM32F4 11 | Mcu.IP0=FREERTOS 12 | Mcu.IP1=NVIC 13 | Mcu.IP2=RCC 14 | Mcu.IP3=SPI1 15 | Mcu.IP4=SYS 16 | Mcu.IP5=USART2 17 | Mcu.IPNb=6 18 | Mcu.Name=STM32F405RGTx 19 | Mcu.Package=LQFP64 20 | Mcu.Pin0=PC13-ANTI_TAMP 21 | Mcu.Pin1=PC14-OSC32_IN 22 | Mcu.Pin10=PA14 23 | Mcu.Pin11=PC12 24 | Mcu.Pin12=PD2 25 | Mcu.Pin13=PB3 26 | Mcu.Pin14=PB4 27 | Mcu.Pin15=PB5 28 | Mcu.Pin16=PB6 29 | Mcu.Pin17=VP_FREERTOS_VS_ENABLE 30 | Mcu.Pin18=VP_SYS_VS_tim7 31 | Mcu.Pin2=PC15-OSC32_OUT 32 | Mcu.Pin3=PH0-OSC_IN 33 | Mcu.Pin4=PH1-OSC_OUT 34 | Mcu.Pin5=PA2 35 | Mcu.Pin6=PA3 36 | Mcu.Pin7=PB10 37 | Mcu.Pin8=PB11 38 | Mcu.Pin9=PA13 39 | Mcu.PinsNb=19 40 | Mcu.ThirdPartyNb=0 41 | Mcu.UserConstants= 42 | Mcu.UserName=STM32F405RGTx 43 | MxCube.Version=5.0.1 44 | MxDb.Version=DB.5.0.1 45 | NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false 46 | NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false 47 | NVIC.EXTI2_IRQn=true\:0\:0\:false\:false\:true\:false\:true 48 | NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false 49 | NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false\:false 50 | NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false 51 | NVIC.PendSV_IRQn=true\:15\:0\:false\:false\:false\:true\:false 52 | NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4 53 | NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:false\:false\:false 54 | NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:false\:true\:false 55 | NVIC.TIM7_IRQn=true\:0\:0\:false\:false\:true\:false\:false 56 | NVIC.TimeBase=TIM7_IRQn 57 | NVIC.TimeBaseIP=TIM7 58 | NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false 59 | PA13.Mode=Serial_Wire 60 | PA13.Signal=SYS_JTMS-SWDIO 61 | PA14.Mode=Serial_Wire 62 | PA14.Signal=SYS_JTCK-SWCLK 63 | PA2.Mode=Asynchronous 64 | PA2.Signal=USART2_TX 65 | PA3.Mode=Asynchronous 66 | PA3.Signal=USART2_RX 67 | PB10.GPIOParameters=GPIO_Speed 68 | PB10.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH 69 | PB10.Locked=true 70 | PB10.Signal=GPIO_Output 71 | PB11.GPIOParameters=GPIO_Speed 72 | PB11.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH 73 | PB11.Locked=true 74 | PB11.Signal=GPIO_Output 75 | PB3.Locked=true 76 | PB3.Mode=Full_Duplex_Master 77 | PB3.Signal=SPI1_SCK 78 | PB4.Locked=true 79 | PB4.Mode=Full_Duplex_Master 80 | PB4.Signal=SPI1_MISO 81 | PB5.Locked=true 82 | PB5.Mode=Full_Duplex_Master 83 | PB5.Signal=SPI1_MOSI 84 | PB6.Locked=true 85 | PB6.Signal=GPIO_Output 86 | PC12.Locked=true 87 | PC12.Signal=GPIO_Output 88 | PC13-ANTI_TAMP.Locked=true 89 | PC13-ANTI_TAMP.Signal=GPIO_Output 90 | PC14-OSC32_IN.Locked=true 91 | PC14-OSC32_IN.Signal=GPIO_Output 92 | PC15-OSC32_OUT.Locked=true 93 | PC15-OSC32_OUT.Signal=GPIO_Output 94 | PCC.Checker=false 95 | PCC.Line=STM32F405/415 96 | PCC.MCU=STM32F405RGTx 97 | PCC.PartNumber=STM32F405RGTx 98 | PCC.Seq0=0 99 | PCC.Series=STM32F4 100 | PCC.Temperature=25 101 | PCC.Vdd=3.3 102 | PD2.Locked=true 103 | PD2.Signal=GPXTI2 104 | PH0-OSC_IN.Mode=HSE-External-Oscillator 105 | PH0-OSC_IN.Signal=RCC_OSC_IN 106 | PH1-OSC_OUT.Mode=HSE-External-Oscillator 107 | PH1-OSC_OUT.Signal=RCC_OSC_OUT 108 | PinOutPanel.RotationAngle=0 109 | ProjectManager.AskForMigrate=true 110 | ProjectManager.BackupPrevious=false 111 | ProjectManager.CompilerOptimize=6 112 | ProjectManager.ComputerToolchain=false 113 | ProjectManager.CoupleFile=true 114 | ProjectManager.CustomerFirmwarePackage= 115 | ProjectManager.DefaultFWLocation=true 116 | ProjectManager.DeletePrevious=true 117 | ProjectManager.DeviceId=STM32F405RGTx 118 | ProjectManager.FirmwarePackage=STM32Cube FW_F4 V1.23.0 119 | ProjectManager.FreePins=false 120 | ProjectManager.HalAssertFull=false 121 | ProjectManager.HeapSize=0x200 122 | ProjectManager.KeepUserCode=true 123 | ProjectManager.LastFirmware=true 124 | ProjectManager.LibraryCopy=1 125 | ProjectManager.MainLocation=Core/Src 126 | ProjectManager.NoMain=false 127 | ProjectManager.PreviousToolchain= 128 | ProjectManager.ProjectBuild=false 129 | ProjectManager.ProjectFileName=RobotDog.ioc 130 | ProjectManager.ProjectName=RobotDog 131 | ProjectManager.StackSize=0x400 132 | ProjectManager.TargetToolchain=MDK-ARM V5 133 | ProjectManager.ToolChainLocation= 134 | ProjectManager.UnderRoot=false 135 | ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-SystemClock_Config-RCC-false-HAL-false,3-MX_USART2_UART_Init-USART2-false-HAL-true,4-MX_SPI1_Init-SPI1-false-HAL-true 136 | RCC.48MHZClocksFreq_Value=72000000 137 | RCC.AHBFreq_Value=144000000 138 | RCC.APB1CLKDivider=RCC_HCLK_DIV4 139 | RCC.APB1Freq_Value=36000000 140 | RCC.APB1TimFreq_Value=72000000 141 | RCC.APB2CLKDivider=RCC_HCLK_DIV2 142 | RCC.APB2Freq_Value=72000000 143 | RCC.APB2TimFreq_Value=144000000 144 | RCC.CortexFreq_Value=144000000 145 | RCC.EthernetFreq_Value=144000000 146 | RCC.FCLKCortexFreq_Value=144000000 147 | RCC.FamilyName=M 148 | RCC.HCLKFreq_Value=144000000 149 | RCC.HSE_VALUE=8000000 150 | RCC.HSI_VALUE=16000000 151 | RCC.I2SClocksFreq_Value=192000000 152 | RCC.IPParameters=48MHZClocksFreq_Value,AHBFreq_Value,APB1CLKDivider,APB1Freq_Value,APB1TimFreq_Value,APB2CLKDivider,APB2Freq_Value,APB2TimFreq_Value,CortexFreq_Value,EthernetFreq_Value,FCLKCortexFreq_Value,FamilyName,HCLKFreq_Value,HSE_VALUE,HSI_VALUE,I2SClocksFreq_Value,LSE_VALUE,LSI_VALUE,MCO2PinFreq_Value,PLLCLKFreq_Value,PLLM,PLLN,PLLQCLKFreq_Value,PLLSourceVirtual,RTCFreq_Value,RTCHSEDivFreq_Value,SYSCLKFreq_VALUE,SYSCLKSource,VCOI2SOutputFreq_Value,VCOInputFreq_Value,VCOOutputFreq_Value,VcooutputI2S 153 | RCC.LSE_VALUE=32768 154 | RCC.LSI_VALUE=32000 155 | RCC.MCO2PinFreq_Value=144000000 156 | RCC.PLLCLKFreq_Value=144000000 157 | RCC.PLLM=4 158 | RCC.PLLN=144 159 | RCC.PLLQCLKFreq_Value=72000000 160 | RCC.PLLSourceVirtual=RCC_PLLSOURCE_HSE 161 | RCC.RTCFreq_Value=32000 162 | RCC.RTCHSEDivFreq_Value=4000000 163 | RCC.SYSCLKFreq_VALUE=144000000 164 | RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK 165 | RCC.VCOI2SOutputFreq_Value=384000000 166 | RCC.VCOInputFreq_Value=2000000 167 | RCC.VCOOutputFreq_Value=288000000 168 | RCC.VcooutputI2S=192000000 169 | SH.GPXTI2.0=GPIO_EXTI2 170 | SH.GPXTI2.ConfNb=1 171 | SPI1.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_8 172 | SPI1.CalculateBaudRate=9.0 MBits/s 173 | SPI1.Direction=SPI_DIRECTION_2LINES 174 | SPI1.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate,BaudRatePrescaler 175 | SPI1.Mode=SPI_MODE_MASTER 176 | SPI1.VirtualType=VM_MASTER 177 | USART2.BaudRate=1000000 178 | USART2.IPParameters=VirtualMode,BaudRate 179 | USART2.VirtualMode=VM_ASYNC 180 | VP_FREERTOS_VS_ENABLE.Mode=Enabled 181 | VP_FREERTOS_VS_ENABLE.Signal=FREERTOS_VS_ENABLE 182 | VP_SYS_VS_tim7.Mode=TIM7 183 | VP_SYS_VS_tim7.Signal=SYS_VS_tim7 184 | board=custom 185 | -------------------------------------------------------------------------------- /RobotDog/Src/freertos.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * File Name : freertos.c 5 | * Description : Code for freertos applications 6 | ****************************************************************************** 7 | * This notice applies to any and all portions of this file 8 | * that are not between comment pairs USER CODE BEGIN and 9 | * USER CODE END. Other portions of this file, whether 10 | * inserted by the user or by software development tools 11 | * are owned by their respective copyright owners. 12 | * 13 | * Copyright (c) 2019 STMicroelectronics International N.V. 14 | * All rights reserved. 15 | * 16 | * Redistribution and use in source and binary forms, with or without 17 | * modification, are permitted, provided that the following conditions are met: 18 | * 19 | * 1. Redistribution of source code must retain the above copyright notice, 20 | * this list of conditions and the following disclaimer. 21 | * 2. Redistributions in binary form must reproduce the above copyright notice, 22 | * this list of conditions and the following disclaimer in the documentation 23 | * and/or other materials provided with the distribution. 24 | * 3. Neither the name of STMicroelectronics nor the names of other 25 | * contributors to this software may be used to endorse or promote products 26 | * derived from this software without specific written permission. 27 | * 4. This software, including modifications and/or derivative works of this 28 | * software, must execute solely and exclusively on microcontroller or 29 | * microprocessor devices manufactured by or for STMicroelectronics. 30 | * 5. Redistribution and use of this software other than as permitted under 31 | * this license is void and will automatically terminate your rights under 32 | * this license. 33 | * 34 | * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" 35 | * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT 36 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 37 | * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY 38 | * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT 39 | * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 40 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 42 | * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 43 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 44 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 45 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 46 | * 47 | ****************************************************************************** 48 | */ 49 | /* USER CODE END Header */ 50 | 51 | /* Includes ------------------------------------------------------------------*/ 52 | #include "FreeRTOS.h" 53 | #include "task.h" 54 | #include "main.h" 55 | #include "cmsis_os.h" 56 | 57 | /* Private includes ----------------------------------------------------------*/ 58 | /* USER CODE BEGIN Includes */ 59 | #include "mpu6050.h" 60 | #include "scs009.h" 61 | #include "remote.h" 62 | #include "robotcmd.h" 63 | #include "body_task.h" 64 | #include "head_task.h" 65 | /* USER CODE END Includes */ 66 | 67 | /* Private typedef -----------------------------------------------------------*/ 68 | /* USER CODE BEGIN PTD */ 69 | 70 | /* USER CODE END PTD */ 71 | 72 | /* Private define ------------------------------------------------------------*/ 73 | /* USER CODE BEGIN PD */ 74 | 75 | /* USER CODE END PD */ 76 | 77 | /* Private macro -------------------------------------------------------------*/ 78 | /* USER CODE BEGIN PM */ 79 | 80 | /* USER CODE END PM */ 81 | 82 | /* Private variables ---------------------------------------------------------*/ 83 | /* USER CODE BEGIN Variables */ 84 | int test_position = 500; 85 | extern int gyroBiasFound; 86 | /* USER CODE END Variables */ 87 | osThreadId RobotCmdHandle; 88 | osThreadId ImuHandle; 89 | osThreadId BodyHandle; 90 | osThreadId HeadHandle; 91 | osThreadId RemoteHandle; 92 | osTimerId LedHandle; 93 | 94 | /* Private function prototypes -----------------------------------------------*/ 95 | /* USER CODE BEGIN FunctionPrototypes */ 96 | 97 | /* USER CODE END FunctionPrototypes */ 98 | 99 | void robotcmd_task(void const * argument); 100 | void imu_task(void const * argument); 101 | void body_task(void const * argument); 102 | void head_task(void const * argument); 103 | void remote_task(void const * argument); 104 | void led_timer(void const * argument); 105 | 106 | void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */ 107 | 108 | /** 109 | * @brief FreeRTOS initialization 110 | * @param None 111 | * @retval None 112 | */ 113 | void MX_FREERTOS_Init(void) { 114 | /* USER CODE BEGIN Init */ 115 | 116 | /* USER CODE END Init */ 117 | 118 | /* USER CODE BEGIN RTOS_MUTEX */ 119 | /* add mutexes, ... */ 120 | /* USER CODE END RTOS_MUTEX */ 121 | 122 | /* USER CODE BEGIN RTOS_SEMAPHORES */ 123 | /* add semaphores, ... */ 124 | /* USER CODE END RTOS_SEMAPHORES */ 125 | 126 | /* Create the timer(s) */ 127 | /* definition and creation of Led */ 128 | osTimerDef(Led, led_timer); 129 | LedHandle = osTimerCreate(osTimer(Led), osTimerPeriodic, NULL); 130 | 131 | /* USER CODE BEGIN RTOS_TIMERS */ 132 | /* start timers, add new ones, ... */ 133 | osTimerStart(LedHandle, 200); 134 | /* USER CODE END RTOS_TIMERS */ 135 | 136 | /* Create the thread(s) */ 137 | /* definition and creation of RobotCmd */ 138 | osThreadDef(RobotCmd, robotcmd_task, osPriorityNormal, 0, 128); 139 | RobotCmdHandle = osThreadCreate(osThread(RobotCmd), NULL); 140 | 141 | /* definition and creation of Imu */ 142 | osThreadDef(Imu, imu_task, osPriorityNormal, 0, 256); 143 | ImuHandle = osThreadCreate(osThread(Imu), NULL); 144 | 145 | /* definition and creation of Body */ 146 | osThreadDef(Body, body_task, osPriorityNormal, 0, 512); 147 | BodyHandle = osThreadCreate(osThread(Body), NULL); 148 | 149 | /* definition and creation of Head */ 150 | osThreadDef(Head, head_task, osPriorityNormal, 0, 512); 151 | HeadHandle = osThreadCreate(osThread(Head), NULL); 152 | 153 | /* definition and creation of Remote */ 154 | osThreadDef(Remote, remote_task, osPriorityNormal, 0, 128); 155 | RemoteHandle = osThreadCreate(osThread(Remote), NULL); 156 | 157 | /* USER CODE BEGIN RTOS_THREADS */ 158 | /* add threads, ... */ 159 | /* USER CODE END RTOS_THREADS */ 160 | 161 | /* USER CODE BEGIN RTOS_QUEUES */ 162 | /* add queues, ... */ 163 | /* USER CODE END RTOS_QUEUES */ 164 | } 165 | 166 | /* USER CODE BEGIN Header_robotcmd_task */ 167 | /** 168 | * @brief Function implementing the RobotCmd thread. 169 | * @param argument: Not used 170 | * @retval None 171 | */ 172 | /* USER CODE END Header_robotcmd_task */ 173 | void robotcmd_task(void const * argument) 174 | { 175 | 176 | /* USER CODE BEGIN robotcmd_task */ 177 | /* Infinite loop */ 178 | for(;;) 179 | { 180 | LedStateChange(); 181 | BodyParamChange(); 182 | HeadStateChange(); 183 | osDelay(1); 184 | } 185 | /* USER CODE END robotcmd_task */ 186 | } 187 | 188 | /* USER CODE BEGIN Header_imu_task */ 189 | /** 190 | * @brief Function implementing the Imu thread. 191 | * @param argument: Not used 192 | * @retval None 193 | */ 194 | /* USER CODE END Header_imu_task */ 195 | void imu_task(void const * argument) 196 | { 197 | /* USER CODE BEGIN imu_task */ 198 | while(MPU6050_Init()){} 199 | /* Infinite loop */ 200 | for(;;) 201 | { 202 | MPU6050_ReadData(); 203 | imuDataHandle(); 204 | if(gyroBiasFound) 205 | { 206 | imuUpdate(mpu6500.gyro); 207 | HAL_GPIO_WritePin(GPIOC, GPIO_PIN_15, GPIO_PIN_RESET); 208 | } 209 | osDelay(2); 210 | } 211 | /* USER CODE END imu_task */ 212 | } 213 | 214 | /* USER CODE BEGIN Header_body_task */ 215 | /** 216 | * @brief Function implementing the Body thread. 217 | * @param argument: Not used 218 | * @retval None 219 | */ 220 | /* USER CODE END Header_body_task */ 221 | void body_task(void const * argument) 222 | { 223 | /* USER CODE BEGIN body_task */ 224 | BodyInit(); 225 | /* Infinite loop */ 226 | for(;;) 227 | { 228 | BodyChange(); 229 | LegChange(); 230 | ServoSendData(); 231 | osDelay(5); 232 | } 233 | /* USER CODE END body_task */ 234 | } 235 | 236 | /* USER CODE BEGIN Header_head_task */ 237 | /** 238 | * @brief Function implementing the Head thread. 239 | * @param argument: Not used 240 | * @retval None 241 | */ 242 | /* USER CODE END Header_head_task */ 243 | void head_task(void const * argument) 244 | { 245 | /* USER CODE BEGIN head_task */ 246 | HeadInit(); 247 | /* Infinite loop */ 248 | for(;;) 249 | { 250 | HeadChange(); 251 | HeadCalc(); 252 | HeadServoSendData(); 253 | osDelay(5); 254 | } 255 | /* USER CODE END head_task */ 256 | } 257 | 258 | /* USER CODE BEGIN Header_remote_task */ 259 | /** 260 | * @brief Function implementing the Remote thread. 261 | * @param argument: Not used 262 | * @retval None 263 | */ 264 | /* USER CODE END Header_remote_task */ 265 | void remote_task(void const * argument) 266 | { 267 | /* USER CODE BEGIN remote_task */ 268 | while(NRF24L01_Check()){}; 269 | NRF24L01_RX_Mode(); 270 | /* Infinite loop */ 271 | for(;;) 272 | { 273 | RemoteReceive(); 274 | osDelay(1); 275 | } 276 | /* USER CODE END remote_task */ 277 | } 278 | 279 | /* led_timer function */ 280 | void led_timer(void const * argument) 281 | { 282 | /* USER CODE BEGIN led_timer */ 283 | HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13); 284 | /* USER CODE END led_timer */ 285 | } 286 | 287 | /* Private application code --------------------------------------------------*/ 288 | /* USER CODE BEGIN Application */ 289 | 290 | /* USER CODE END Application */ 291 | 292 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 293 | -------------------------------------------------------------------------------- /RobotDog/Src/gpio.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * File Name : gpio.c 4 | * Description : This file provides code for the configuration 5 | * of all used GPIO pins. 6 | ****************************************************************************** 7 | * This notice applies to any and all portions of this file 8 | * that are not between comment pairs USER CODE BEGIN and 9 | * USER CODE END. Other portions of this file, whether 10 | * inserted by the user or by software development tools 11 | * are owned by their respective copyright owners. 12 | * 13 | * Copyright (c) 2019 STMicroelectronics International N.V. 14 | * All rights reserved. 15 | * 16 | * Redistribution and use in source and binary forms, with or without 17 | * modification, are permitted, provided that the following conditions are met: 18 | * 19 | * 1. Redistribution of source code must retain the above copyright notice, 20 | * this list of conditions and the following disclaimer. 21 | * 2. Redistributions in binary form must reproduce the above copyright notice, 22 | * this list of conditions and the following disclaimer in the documentation 23 | * and/or other materials provided with the distribution. 24 | * 3. Neither the name of STMicroelectronics nor the names of other 25 | * contributors to this software may be used to endorse or promote products 26 | * derived from this software without specific written permission. 27 | * 4. This software, including modifications and/or derivative works of this 28 | * software, must execute solely and exclusively on microcontroller or 29 | * microprocessor devices manufactured by or for STMicroelectronics. 30 | * 5. Redistribution and use of this software other than as permitted under 31 | * this license is void and will automatically terminate your rights under 32 | * this license. 33 | * 34 | * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" 35 | * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT 36 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 37 | * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY 38 | * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT 39 | * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 40 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 42 | * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 43 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 44 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 45 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 46 | * 47 | ****************************************************************************** 48 | */ 49 | 50 | /* Includes ------------------------------------------------------------------*/ 51 | #include "gpio.h" 52 | /* USER CODE BEGIN 0 */ 53 | 54 | /* USER CODE END 0 */ 55 | 56 | /*----------------------------------------------------------------------------*/ 57 | /* Configure GPIO */ 58 | /*----------------------------------------------------------------------------*/ 59 | /* USER CODE BEGIN 1 */ 60 | 61 | /* USER CODE END 1 */ 62 | 63 | /** Configure pins as 64 | * Analog 65 | * Input 66 | * Output 67 | * EVENT_OUT 68 | * EXTI 69 | */ 70 | void MX_GPIO_Init(void) 71 | { 72 | 73 | GPIO_InitTypeDef GPIO_InitStruct = {0}; 74 | 75 | /* GPIO Ports Clock Enable */ 76 | __HAL_RCC_GPIOC_CLK_ENABLE(); 77 | __HAL_RCC_GPIOH_CLK_ENABLE(); 78 | __HAL_RCC_GPIOA_CLK_ENABLE(); 79 | __HAL_RCC_GPIOB_CLK_ENABLE(); 80 | __HAL_RCC_GPIOD_CLK_ENABLE(); 81 | 82 | /*Configure GPIO pin Output Level */ 83 | HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_12, GPIO_PIN_SET); 84 | 85 | /*Configure GPIO pin Output Level */ 86 | HAL_GPIO_WritePin(GPIOB, GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_6, GPIO_PIN_RESET); 87 | 88 | /*Configure GPIO pins : PC13 PC14 PC15 PC12 */ 89 | GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_12; 90 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 91 | GPIO_InitStruct.Pull = GPIO_NOPULL; 92 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 93 | HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); 94 | 95 | /*Configure GPIO pins : PB10 PB11 */ 96 | GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_11; 97 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 98 | GPIO_InitStruct.Pull = GPIO_NOPULL; 99 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; 100 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); 101 | 102 | /*Configure GPIO pin : PD2 */ 103 | GPIO_InitStruct.Pin = GPIO_PIN_2; 104 | GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; 105 | GPIO_InitStruct.Pull = GPIO_NOPULL; 106 | HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); 107 | 108 | /*Configure GPIO pin : PB6 */ 109 | GPIO_InitStruct.Pin = GPIO_PIN_6; 110 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 111 | GPIO_InitStruct.Pull = GPIO_NOPULL; 112 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 113 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); 114 | 115 | /* EXTI interrupt init*/ 116 | HAL_NVIC_SetPriority(EXTI2_IRQn, 0, 0); 117 | HAL_NVIC_EnableIRQ(EXTI2_IRQn); 118 | 119 | } 120 | 121 | /* USER CODE BEGIN 2 */ 122 | 123 | /* USER CODE END 2 */ 124 | 125 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 126 | -------------------------------------------------------------------------------- /RobotDog/Src/main.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : main.c 5 | * @brief : Main program body 6 | ****************************************************************************** 7 | * This notice applies to any and all portions of this file 8 | * that are not between comment pairs USER CODE BEGIN and 9 | * USER CODE END. Other portions of this file, whether 10 | * inserted by the user or by software development tools 11 | * are owned by their respective copyright owners. 12 | * 13 | * Copyright (c) 2019 STMicroelectronics International N.V. 14 | * All rights reserved. 15 | * 16 | * Redistribution and use in source and binary forms, with or without 17 | * modification, are permitted, provided that the following conditions are met: 18 | * 19 | * 1. Redistribution of source code must retain the above copyright notice, 20 | * this list of conditions and the following disclaimer. 21 | * 2. Redistributions in binary form must reproduce the above copyright notice, 22 | * this list of conditions and the following disclaimer in the documentation 23 | * and/or other materials provided with the distribution. 24 | * 3. Neither the name of STMicroelectronics nor the names of other 25 | * contributors to this software may be used to endorse or promote products 26 | * derived from this software without specific written permission. 27 | * 4. This software, including modifications and/or derivative works of this 28 | * software, must execute solely and exclusively on microcontroller or 29 | * microprocessor devices manufactured by or for STMicroelectronics. 30 | * 5. Redistribution and use of this software other than as permitted under 31 | * this license is void and will automatically terminate your rights under 32 | * this license. 33 | * 34 | * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" 35 | * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT 36 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 37 | * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY 38 | * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT 39 | * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 40 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 42 | * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 43 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 44 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 45 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 46 | * 47 | ****************************************************************************** 48 | */ 49 | /* USER CODE END Header */ 50 | 51 | /* Includes ------------------------------------------------------------------*/ 52 | #include "main.h" 53 | #include "cmsis_os.h" 54 | #include "spi.h" 55 | #include "usart.h" 56 | #include "gpio.h" 57 | 58 | /* Private includes ----------------------------------------------------------*/ 59 | /* USER CODE BEGIN Includes */ 60 | 61 | /* USER CODE END Includes */ 62 | 63 | /* Private typedef -----------------------------------------------------------*/ 64 | /* USER CODE BEGIN PTD */ 65 | 66 | /* USER CODE END PTD */ 67 | 68 | /* Private define ------------------------------------------------------------*/ 69 | /* USER CODE BEGIN PD */ 70 | 71 | /* USER CODE END PD */ 72 | 73 | /* Private macro -------------------------------------------------------------*/ 74 | /* USER CODE BEGIN PM */ 75 | 76 | /* USER CODE END PM */ 77 | 78 | /* Private variables ---------------------------------------------------------*/ 79 | 80 | /* USER CODE BEGIN PV */ 81 | 82 | /* USER CODE END PV */ 83 | 84 | /* Private function prototypes -----------------------------------------------*/ 85 | void SystemClock_Config(void); 86 | void MX_FREERTOS_Init(void); 87 | /* USER CODE BEGIN PFP */ 88 | 89 | /* USER CODE END PFP */ 90 | 91 | /* Private user code ---------------------------------------------------------*/ 92 | /* USER CODE BEGIN 0 */ 93 | 94 | /* USER CODE END 0 */ 95 | 96 | /** 97 | * @brief The application entry point. 98 | * @retval int 99 | */ 100 | int main(void) 101 | { 102 | /* USER CODE BEGIN 1 */ 103 | 104 | /* USER CODE END 1 */ 105 | 106 | /* MCU Configuration--------------------------------------------------------*/ 107 | 108 | /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ 109 | HAL_Init(); 110 | 111 | /* USER CODE BEGIN Init */ 112 | 113 | /* USER CODE END Init */ 114 | 115 | /* Configure the system clock */ 116 | SystemClock_Config(); 117 | 118 | /* USER CODE BEGIN SysInit */ 119 | 120 | /* USER CODE END SysInit */ 121 | 122 | /* Initialize all configured peripherals */ 123 | MX_GPIO_Init(); 124 | MX_USART2_UART_Init(); 125 | MX_SPI1_Init(); 126 | /* USER CODE BEGIN 2 */ 127 | 128 | /* USER CODE END 2 */ 129 | 130 | /* Call init function for freertos objects (in freertos.c) */ 131 | MX_FREERTOS_Init(); 132 | 133 | /* Start scheduler */ 134 | osKernelStart(); 135 | 136 | /* We should never get here as control is now taken by the scheduler */ 137 | 138 | /* Infinite loop */ 139 | /* USER CODE BEGIN WHILE */ 140 | while (1) 141 | { 142 | /* USER CODE END WHILE */ 143 | 144 | /* USER CODE BEGIN 3 */ 145 | } 146 | /* USER CODE END 3 */ 147 | } 148 | 149 | /** 150 | * @brief System Clock Configuration 151 | * @retval None 152 | */ 153 | void SystemClock_Config(void) 154 | { 155 | RCC_OscInitTypeDef RCC_OscInitStruct = {0}; 156 | RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; 157 | 158 | /**Configure the main internal regulator output voltage 159 | */ 160 | __HAL_RCC_PWR_CLK_ENABLE(); 161 | __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); 162 | /**Initializes the CPU, AHB and APB busses clocks 163 | */ 164 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; 165 | RCC_OscInitStruct.HSEState = RCC_HSE_ON; 166 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; 167 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; 168 | RCC_OscInitStruct.PLL.PLLM = 4; 169 | RCC_OscInitStruct.PLL.PLLN = 144; 170 | RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; 171 | RCC_OscInitStruct.PLL.PLLQ = 4; 172 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) 173 | { 174 | Error_Handler(); 175 | } 176 | /**Initializes the CPU, AHB and APB busses clocks 177 | */ 178 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK 179 | |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; 180 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; 181 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; 182 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; 183 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; 184 | 185 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK) 186 | { 187 | Error_Handler(); 188 | } 189 | } 190 | 191 | /* USER CODE BEGIN 4 */ 192 | 193 | /* USER CODE END 4 */ 194 | 195 | /** 196 | * @brief Period elapsed callback in non blocking mode 197 | * @note This function is called when TIM7 interrupt took place, inside 198 | * HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment 199 | * a global variable "uwTick" used as application time base. 200 | * @param htim : TIM handle 201 | * @retval None 202 | */ 203 | void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) 204 | { 205 | /* USER CODE BEGIN Callback 0 */ 206 | 207 | /* USER CODE END Callback 0 */ 208 | if (htim->Instance == TIM7) { 209 | HAL_IncTick(); 210 | } 211 | /* USER CODE BEGIN Callback 1 */ 212 | 213 | /* USER CODE END Callback 1 */ 214 | } 215 | 216 | /** 217 | * @brief This function is executed in case of error occurrence. 218 | * @retval None 219 | */ 220 | void Error_Handler(void) 221 | { 222 | /* USER CODE BEGIN Error_Handler_Debug */ 223 | /* User can add his own implementation to report the HAL error return state */ 224 | 225 | /* USER CODE END Error_Handler_Debug */ 226 | } 227 | 228 | #ifdef USE_FULL_ASSERT 229 | /** 230 | * @brief Reports the name of the source file and the source line number 231 | * where the assert_param error has occurred. 232 | * @param file: pointer to the source file name 233 | * @param line: assert_param error line source number 234 | * @retval None 235 | */ 236 | void assert_failed(uint8_t *file, uint32_t line) 237 | { 238 | /* USER CODE BEGIN 6 */ 239 | /* User can add his own implementation to report the file name and line number, 240 | tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ 241 | /* USER CODE END 6 */ 242 | } 243 | #endif /* USE_FULL_ASSERT */ 244 | 245 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 246 | -------------------------------------------------------------------------------- /RobotDog/Src/spi.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * File Name : SPI.c 4 | * Description : This file provides code for the configuration 5 | * of the SPI instances. 6 | ****************************************************************************** 7 | * This notice applies to any and all portions of this file 8 | * that are not between comment pairs USER CODE BEGIN and 9 | * USER CODE END. Other portions of this file, whether 10 | * inserted by the user or by software development tools 11 | * are owned by their respective copyright owners. 12 | * 13 | * Copyright (c) 2019 STMicroelectronics International N.V. 14 | * All rights reserved. 15 | * 16 | * Redistribution and use in source and binary forms, with or without 17 | * modification, are permitted, provided that the following conditions are met: 18 | * 19 | * 1. Redistribution of source code must retain the above copyright notice, 20 | * this list of conditions and the following disclaimer. 21 | * 2. Redistributions in binary form must reproduce the above copyright notice, 22 | * this list of conditions and the following disclaimer in the documentation 23 | * and/or other materials provided with the distribution. 24 | * 3. Neither the name of STMicroelectronics nor the names of other 25 | * contributors to this software may be used to endorse or promote products 26 | * derived from this software without specific written permission. 27 | * 4. This software, including modifications and/or derivative works of this 28 | * software, must execute solely and exclusively on microcontroller or 29 | * microprocessor devices manufactured by or for STMicroelectronics. 30 | * 5. Redistribution and use of this software other than as permitted under 31 | * this license is void and will automatically terminate your rights under 32 | * this license. 33 | * 34 | * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" 35 | * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT 36 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 37 | * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY 38 | * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT 39 | * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 40 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 42 | * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 43 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 44 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 45 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 46 | * 47 | ****************************************************************************** 48 | */ 49 | 50 | /* Includes ------------------------------------------------------------------*/ 51 | #include "spi.h" 52 | 53 | /* USER CODE BEGIN 0 */ 54 | 55 | /* USER CODE END 0 */ 56 | 57 | SPI_HandleTypeDef hspi1; 58 | 59 | /* SPI1 init function */ 60 | void MX_SPI1_Init(void) 61 | { 62 | 63 | hspi1.Instance = SPI1; 64 | hspi1.Init.Mode = SPI_MODE_MASTER; 65 | hspi1.Init.Direction = SPI_DIRECTION_2LINES; 66 | hspi1.Init.DataSize = SPI_DATASIZE_8BIT; 67 | hspi1.Init.CLKPolarity = SPI_POLARITY_LOW; 68 | hspi1.Init.CLKPhase = SPI_PHASE_1EDGE; 69 | hspi1.Init.NSS = SPI_NSS_SOFT; 70 | hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8; 71 | hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB; 72 | hspi1.Init.TIMode = SPI_TIMODE_DISABLE; 73 | hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; 74 | hspi1.Init.CRCPolynomial = 10; 75 | if (HAL_SPI_Init(&hspi1) != HAL_OK) 76 | { 77 | Error_Handler(); 78 | } 79 | 80 | } 81 | 82 | void HAL_SPI_MspInit(SPI_HandleTypeDef* spiHandle) 83 | { 84 | 85 | GPIO_InitTypeDef GPIO_InitStruct = {0}; 86 | if(spiHandle->Instance==SPI1) 87 | { 88 | /* USER CODE BEGIN SPI1_MspInit 0 */ 89 | 90 | /* USER CODE END SPI1_MspInit 0 */ 91 | /* SPI1 clock enable */ 92 | __HAL_RCC_SPI1_CLK_ENABLE(); 93 | 94 | __HAL_RCC_GPIOB_CLK_ENABLE(); 95 | /**SPI1 GPIO Configuration 96 | PB3 ------> SPI1_SCK 97 | PB4 ------> SPI1_MISO 98 | PB5 ------> SPI1_MOSI 99 | */ 100 | GPIO_InitStruct.Pin = GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5; 101 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 102 | GPIO_InitStruct.Pull = GPIO_NOPULL; 103 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; 104 | GPIO_InitStruct.Alternate = GPIO_AF5_SPI1; 105 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); 106 | 107 | /* USER CODE BEGIN SPI1_MspInit 1 */ 108 | 109 | /* USER CODE END SPI1_MspInit 1 */ 110 | } 111 | } 112 | 113 | void HAL_SPI_MspDeInit(SPI_HandleTypeDef* spiHandle) 114 | { 115 | 116 | if(spiHandle->Instance==SPI1) 117 | { 118 | /* USER CODE BEGIN SPI1_MspDeInit 0 */ 119 | 120 | /* USER CODE END SPI1_MspDeInit 0 */ 121 | /* Peripheral clock disable */ 122 | __HAL_RCC_SPI1_CLK_DISABLE(); 123 | 124 | /**SPI1 GPIO Configuration 125 | PB3 ------> SPI1_SCK 126 | PB4 ------> SPI1_MISO 127 | PB5 ------> SPI1_MOSI 128 | */ 129 | HAL_GPIO_DeInit(GPIOB, GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5); 130 | 131 | /* USER CODE BEGIN SPI1_MspDeInit 1 */ 132 | 133 | /* USER CODE END SPI1_MspDeInit 1 */ 134 | } 135 | } 136 | 137 | /* USER CODE BEGIN 1 */ 138 | 139 | /* USER CODE END 1 */ 140 | 141 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 142 | -------------------------------------------------------------------------------- /RobotDog/Src/stm32f4xx_hal_msp.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * File Name : stm32f4xx_hal_msp.c 5 | * Description : This file provides code for the MSP Initialization 6 | * and de-Initialization codes. 7 | ****************************************************************************** 8 | * This notice applies to any and all portions of this file 9 | * that are not between comment pairs USER CODE BEGIN and 10 | * USER CODE END. Other portions of this file, whether 11 | * inserted by the user or by software development tools 12 | * are owned by their respective copyright owners. 13 | * 14 | * Copyright (c) 2019 STMicroelectronics International N.V. 15 | * All rights reserved. 16 | * 17 | * Redistribution and use in source and binary forms, with or without 18 | * modification, are permitted, provided that the following conditions are met: 19 | * 20 | * 1. Redistribution of source code must retain the above copyright notice, 21 | * this list of conditions and the following disclaimer. 22 | * 2. Redistributions in binary form must reproduce the above copyright notice, 23 | * this list of conditions and the following disclaimer in the documentation 24 | * and/or other materials provided with the distribution. 25 | * 3. Neither the name of STMicroelectronics nor the names of other 26 | * contributors to this software may be used to endorse or promote products 27 | * derived from this software without specific written permission. 28 | * 4. This software, including modifications and/or derivative works of this 29 | * software, must execute solely and exclusively on microcontroller or 30 | * microprocessor devices manufactured by or for STMicroelectronics. 31 | * 5. Redistribution and use of this software other than as permitted under 32 | * this license is void and will automatically terminate your rights under 33 | * this license. 34 | * 35 | * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" 36 | * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT 37 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 38 | * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY 39 | * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT 40 | * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 41 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 42 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 43 | * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 44 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 45 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 46 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 47 | * 48 | ****************************************************************************** 49 | */ 50 | /* USER CODE END Header */ 51 | 52 | /* Includes ------------------------------------------------------------------*/ 53 | #include "main.h" 54 | /* USER CODE BEGIN Includes */ 55 | 56 | /* USER CODE END Includes */ 57 | 58 | /* Private typedef -----------------------------------------------------------*/ 59 | /* USER CODE BEGIN TD */ 60 | 61 | /* USER CODE END TD */ 62 | 63 | /* Private define ------------------------------------------------------------*/ 64 | /* USER CODE BEGIN Define */ 65 | 66 | /* USER CODE END Define */ 67 | 68 | /* Private macro -------------------------------------------------------------*/ 69 | /* USER CODE BEGIN Macro */ 70 | 71 | /* USER CODE END Macro */ 72 | 73 | /* Private variables ---------------------------------------------------------*/ 74 | /* USER CODE BEGIN PV */ 75 | 76 | /* USER CODE END PV */ 77 | 78 | /* Private function prototypes -----------------------------------------------*/ 79 | /* USER CODE BEGIN PFP */ 80 | 81 | /* USER CODE END PFP */ 82 | 83 | /* External functions --------------------------------------------------------*/ 84 | /* USER CODE BEGIN ExternalFunctions */ 85 | 86 | /* USER CODE END ExternalFunctions */ 87 | 88 | /* USER CODE BEGIN 0 */ 89 | 90 | /* USER CODE END 0 */ 91 | /** 92 | * Initializes the Global MSP. 93 | */ 94 | void HAL_MspInit(void) 95 | { 96 | /* USER CODE BEGIN MspInit 0 */ 97 | 98 | /* USER CODE END MspInit 0 */ 99 | 100 | __HAL_RCC_SYSCFG_CLK_ENABLE(); 101 | __HAL_RCC_PWR_CLK_ENABLE(); 102 | 103 | /* System interrupt init*/ 104 | /* PendSV_IRQn interrupt configuration */ 105 | HAL_NVIC_SetPriority(PendSV_IRQn, 15, 0); 106 | 107 | /* USER CODE BEGIN MspInit 1 */ 108 | 109 | /* USER CODE END MspInit 1 */ 110 | } 111 | 112 | /* USER CODE BEGIN 1 */ 113 | 114 | /* USER CODE END 1 */ 115 | 116 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 117 | -------------------------------------------------------------------------------- /RobotDog/Src/stm32f4xx_hal_timebase_tim.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32f4xx_hal_timebase_TIM.c 5 | * @brief HAL time base based on the hardware TIM. 6 | ****************************************************************************** 7 | * This notice applies to any and all portions of this file 8 | * that are not between comment pairs USER CODE BEGIN and 9 | * USER CODE END. Other portions of this file, whether 10 | * inserted by the user or by software development tools 11 | * are owned by their respective copyright owners. 12 | * 13 | * Copyright (c) 2019 STMicroelectronics International N.V. 14 | * All rights reserved. 15 | * 16 | * Redistribution and use in source and binary forms, with or without 17 | * modification, are permitted, provided that the following conditions are met: 18 | * 19 | * 1. Redistribution of source code must retain the above copyright notice, 20 | * this list of conditions and the following disclaimer. 21 | * 2. Redistributions in binary form must reproduce the above copyright notice, 22 | * this list of conditions and the following disclaimer in the documentation 23 | * and/or other materials provided with the distribution. 24 | * 3. Neither the name of STMicroelectronics nor the names of other 25 | * contributors to this software may be used to endorse or promote products 26 | * derived from this software without specific written permission. 27 | * 4. This software, including modifications and/or derivative works of this 28 | * software, must execute solely and exclusively on microcontroller or 29 | * microprocessor devices manufactured by or for STMicroelectronics. 30 | * 5. Redistribution and use of this software other than as permitted under 31 | * this license is void and will automatically terminate your rights under 32 | * this license. 33 | * 34 | * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" 35 | * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT 36 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 37 | * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY 38 | * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT 39 | * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 40 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 42 | * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 43 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 44 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 45 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 46 | * 47 | ****************************************************************************** 48 | */ 49 | /* USER CODE END Header */ 50 | 51 | /* Includes ------------------------------------------------------------------*/ 52 | #include "stm32f4xx_hal.h" 53 | #include "stm32f4xx_hal_tim.h" 54 | 55 | /* Private typedef -----------------------------------------------------------*/ 56 | /* Private define ------------------------------------------------------------*/ 57 | /* Private macro -------------------------------------------------------------*/ 58 | /* Private variables ---------------------------------------------------------*/ 59 | TIM_HandleTypeDef htim7; 60 | /* Private function prototypes -----------------------------------------------*/ 61 | /* Private functions ---------------------------------------------------------*/ 62 | 63 | /** 64 | * @brief This function configures the TIM7 as a time base source. 65 | * The time source is configured to have 1ms time base with a dedicated 66 | * Tick interrupt priority. 67 | * @note This function is called automatically at the beginning of program after 68 | * reset by HAL_Init() or at any time when clock is configured, by HAL_RCC_ClockConfig(). 69 | * @param TickPriority: Tick interrupt priority. 70 | * @retval HAL status 71 | */ 72 | HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) 73 | { 74 | RCC_ClkInitTypeDef clkconfig; 75 | uint32_t uwTimclock = 0; 76 | uint32_t uwPrescalerValue = 0; 77 | uint32_t pFLatency; 78 | 79 | /*Configure the TIM7 IRQ priority */ 80 | HAL_NVIC_SetPriority(TIM7_IRQn, TickPriority ,0); 81 | 82 | /* Enable the TIM7 global Interrupt */ 83 | HAL_NVIC_EnableIRQ(TIM7_IRQn); 84 | 85 | /* Enable TIM7 clock */ 86 | __HAL_RCC_TIM7_CLK_ENABLE(); 87 | 88 | /* Get clock configuration */ 89 | HAL_RCC_GetClockConfig(&clkconfig, &pFLatency); 90 | 91 | /* Compute TIM7 clock */ 92 | uwTimclock = 2*HAL_RCC_GetPCLK1Freq(); 93 | 94 | /* Compute the prescaler value to have TIM7 counter clock equal to 1MHz */ 95 | uwPrescalerValue = (uint32_t) ((uwTimclock / 1000000) - 1); 96 | 97 | /* Initialize TIM7 */ 98 | htim7.Instance = TIM7; 99 | 100 | /* Initialize TIMx peripheral as follow: 101 | + Period = [(TIM7CLK/1000) - 1]. to have a (1/1000) s time base. 102 | + Prescaler = (uwTimclock/1000000 - 1) to have a 1MHz counter clock. 103 | + ClockDivision = 0 104 | + Counter direction = Up 105 | */ 106 | htim7.Init.Period = (1000000 / 1000) - 1; 107 | htim7.Init.Prescaler = uwPrescalerValue; 108 | htim7.Init.ClockDivision = 0; 109 | htim7.Init.CounterMode = TIM_COUNTERMODE_UP; 110 | if(HAL_TIM_Base_Init(&htim7) == HAL_OK) 111 | { 112 | /* Start the TIM time Base generation in interrupt mode */ 113 | return HAL_TIM_Base_Start_IT(&htim7); 114 | } 115 | 116 | /* Return function status */ 117 | return HAL_ERROR; 118 | } 119 | 120 | /** 121 | * @brief Suspend Tick increment. 122 | * @note Disable the tick increment by disabling TIM7 update interrupt. 123 | * @param None 124 | * @retval None 125 | */ 126 | void HAL_SuspendTick(void) 127 | { 128 | /* Disable TIM7 update Interrupt */ 129 | __HAL_TIM_DISABLE_IT(&htim7, TIM_IT_UPDATE); 130 | } 131 | 132 | /** 133 | * @brief Resume Tick increment. 134 | * @note Enable the tick increment by Enabling TIM7 update interrupt. 135 | * @param None 136 | * @retval None 137 | */ 138 | void HAL_ResumeTick(void) 139 | { 140 | /* Enable TIM7 Update interrupt */ 141 | __HAL_TIM_ENABLE_IT(&htim7, TIM_IT_UPDATE); 142 | } 143 | 144 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 145 | -------------------------------------------------------------------------------- /RobotDog/Src/stm32f4xx_it.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32f4xx_it.c 5 | * @brief Interrupt Service Routines. 6 | ****************************************************************************** 7 | * 8 | * COPYRIGHT(c) 2019 STMicroelectronics 9 | * 10 | * Redistribution and use in source and binary forms, with or without modification, 11 | * are permitted provided that the following conditions are met: 12 | * 1. Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright notice, 15 | * this list of conditions and the following disclaimer in the documentation 16 | * and/or other materials provided with the distribution. 17 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | ****************************************************************************** 33 | */ 34 | /* USER CODE END Header */ 35 | 36 | /* Includes ------------------------------------------------------------------*/ 37 | #include "main.h" 38 | #include "stm32f4xx_it.h" 39 | #include "cmsis_os.h" 40 | /* Private includes ----------------------------------------------------------*/ 41 | /* USER CODE BEGIN Includes */ 42 | /* USER CODE END Includes */ 43 | 44 | /* Private typedef -----------------------------------------------------------*/ 45 | /* USER CODE BEGIN TD */ 46 | 47 | /* USER CODE END TD */ 48 | 49 | /* Private define ------------------------------------------------------------*/ 50 | /* USER CODE BEGIN PD */ 51 | 52 | /* USER CODE END PD */ 53 | 54 | /* Private macro -------------------------------------------------------------*/ 55 | /* USER CODE BEGIN PM */ 56 | 57 | /* USER CODE END PM */ 58 | 59 | /* Private variables ---------------------------------------------------------*/ 60 | /* USER CODE BEGIN PV */ 61 | 62 | /* USER CODE END PV */ 63 | 64 | /* Private function prototypes -----------------------------------------------*/ 65 | /* USER CODE BEGIN PFP */ 66 | 67 | /* USER CODE END PFP */ 68 | 69 | /* Private user code ---------------------------------------------------------*/ 70 | /* USER CODE BEGIN 0 */ 71 | 72 | /* USER CODE END 0 */ 73 | 74 | /* External variables --------------------------------------------------------*/ 75 | extern TIM_HandleTypeDef htim7; 76 | 77 | /* USER CODE BEGIN EV */ 78 | 79 | /* USER CODE END EV */ 80 | 81 | /******************************************************************************/ 82 | /* Cortex-M4 Processor Interruption and Exception Handlers */ 83 | /******************************************************************************/ 84 | /** 85 | * @brief This function handles Non maskable interrupt. 86 | */ 87 | void NMI_Handler(void) 88 | { 89 | /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ 90 | 91 | /* USER CODE END NonMaskableInt_IRQn 0 */ 92 | /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ 93 | 94 | /* USER CODE END NonMaskableInt_IRQn 1 */ 95 | } 96 | 97 | /** 98 | * @brief This function handles Hard fault interrupt. 99 | */ 100 | void HardFault_Handler(void) 101 | { 102 | /* USER CODE BEGIN HardFault_IRQn 0 */ 103 | 104 | /* USER CODE END HardFault_IRQn 0 */ 105 | while (1) 106 | { 107 | /* USER CODE BEGIN W1_HardFault_IRQn 0 */ 108 | /* USER CODE END W1_HardFault_IRQn 0 */ 109 | } 110 | } 111 | 112 | /** 113 | * @brief This function handles Memory management fault. 114 | */ 115 | void MemManage_Handler(void) 116 | { 117 | /* USER CODE BEGIN MemoryManagement_IRQn 0 */ 118 | 119 | /* USER CODE END MemoryManagement_IRQn 0 */ 120 | while (1) 121 | { 122 | /* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */ 123 | /* USER CODE END W1_MemoryManagement_IRQn 0 */ 124 | } 125 | } 126 | 127 | /** 128 | * @brief This function handles Pre-fetch fault, memory access fault. 129 | */ 130 | void BusFault_Handler(void) 131 | { 132 | /* USER CODE BEGIN BusFault_IRQn 0 */ 133 | 134 | /* USER CODE END BusFault_IRQn 0 */ 135 | while (1) 136 | { 137 | /* USER CODE BEGIN W1_BusFault_IRQn 0 */ 138 | /* USER CODE END W1_BusFault_IRQn 0 */ 139 | } 140 | } 141 | 142 | /** 143 | * @brief This function handles Undefined instruction or illegal state. 144 | */ 145 | void UsageFault_Handler(void) 146 | { 147 | /* USER CODE BEGIN UsageFault_IRQn 0 */ 148 | 149 | /* USER CODE END UsageFault_IRQn 0 */ 150 | while (1) 151 | { 152 | /* USER CODE BEGIN W1_UsageFault_IRQn 0 */ 153 | /* USER CODE END W1_UsageFault_IRQn 0 */ 154 | } 155 | } 156 | 157 | /** 158 | * @brief This function handles Debug monitor. 159 | */ 160 | void DebugMon_Handler(void) 161 | { 162 | /* USER CODE BEGIN DebugMonitor_IRQn 0 */ 163 | 164 | /* USER CODE END DebugMonitor_IRQn 0 */ 165 | /* USER CODE BEGIN DebugMonitor_IRQn 1 */ 166 | 167 | /* USER CODE END DebugMonitor_IRQn 1 */ 168 | } 169 | 170 | /******************************************************************************/ 171 | /* STM32F4xx Peripheral Interrupt Handlers */ 172 | /* Add here the Interrupt Handlers for the used peripherals. */ 173 | /* For the available peripheral interrupt handler names, */ 174 | /* please refer to the startup file (startup_stm32f4xx.s). */ 175 | /******************************************************************************/ 176 | 177 | /** 178 | * @brief This function handles EXTI line2 interrupt. 179 | */ 180 | void EXTI2_IRQHandler(void) 181 | { 182 | /* USER CODE BEGIN EXTI2_IRQn 0 */ 183 | 184 | /* USER CODE END EXTI2_IRQn 0 */ 185 | HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_2); 186 | /* USER CODE BEGIN EXTI2_IRQn 1 */ 187 | 188 | /* USER CODE END EXTI2_IRQn 1 */ 189 | } 190 | 191 | /** 192 | * @brief This function handles TIM7 global interrupt. 193 | */ 194 | void TIM7_IRQHandler(void) 195 | { 196 | /* USER CODE BEGIN TIM7_IRQn 0 */ 197 | 198 | /* USER CODE END TIM7_IRQn 0 */ 199 | HAL_TIM_IRQHandler(&htim7); 200 | /* USER CODE BEGIN TIM7_IRQn 1 */ 201 | 202 | /* USER CODE END TIM7_IRQn 1 */ 203 | } 204 | 205 | /* USER CODE BEGIN 1 */ 206 | 207 | /* USER CODE END 1 */ 208 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 209 | -------------------------------------------------------------------------------- /RobotDog/Src/usart.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * File Name : USART.c 4 | * Description : This file provides code for the configuration 5 | * of the USART instances. 6 | ****************************************************************************** 7 | * This notice applies to any and all portions of this file 8 | * that are not between comment pairs USER CODE BEGIN and 9 | * USER CODE END. Other portions of this file, whether 10 | * inserted by the user or by software development tools 11 | * are owned by their respective copyright owners. 12 | * 13 | * Copyright (c) 2019 STMicroelectronics International N.V. 14 | * All rights reserved. 15 | * 16 | * Redistribution and use in source and binary forms, with or without 17 | * modification, are permitted, provided that the following conditions are met: 18 | * 19 | * 1. Redistribution of source code must retain the above copyright notice, 20 | * this list of conditions and the following disclaimer. 21 | * 2. Redistributions in binary form must reproduce the above copyright notice, 22 | * this list of conditions and the following disclaimer in the documentation 23 | * and/or other materials provided with the distribution. 24 | * 3. Neither the name of STMicroelectronics nor the names of other 25 | * contributors to this software may be used to endorse or promote products 26 | * derived from this software without specific written permission. 27 | * 4. This software, including modifications and/or derivative works of this 28 | * software, must execute solely and exclusively on microcontroller or 29 | * microprocessor devices manufactured by or for STMicroelectronics. 30 | * 5. Redistribution and use of this software other than as permitted under 31 | * this license is void and will automatically terminate your rights under 32 | * this license. 33 | * 34 | * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" 35 | * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT 36 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 37 | * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY 38 | * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT 39 | * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 40 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 42 | * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 43 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 44 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 45 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 46 | * 47 | ****************************************************************************** 48 | */ 49 | 50 | /* Includes ------------------------------------------------------------------*/ 51 | #include "usart.h" 52 | 53 | /* USER CODE BEGIN 0 */ 54 | 55 | /* USER CODE END 0 */ 56 | 57 | UART_HandleTypeDef huart2; 58 | 59 | /* USART2 init function */ 60 | 61 | void MX_USART2_UART_Init(void) 62 | { 63 | 64 | huart2.Instance = USART2; 65 | huart2.Init.BaudRate = 1000000; 66 | huart2.Init.WordLength = UART_WORDLENGTH_8B; 67 | huart2.Init.StopBits = UART_STOPBITS_1; 68 | huart2.Init.Parity = UART_PARITY_NONE; 69 | huart2.Init.Mode = UART_MODE_TX_RX; 70 | huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE; 71 | huart2.Init.OverSampling = UART_OVERSAMPLING_16; 72 | if (HAL_UART_Init(&huart2) != HAL_OK) 73 | { 74 | Error_Handler(); 75 | } 76 | 77 | } 78 | 79 | void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) 80 | { 81 | 82 | GPIO_InitTypeDef GPIO_InitStruct = {0}; 83 | if(uartHandle->Instance==USART2) 84 | { 85 | /* USER CODE BEGIN USART2_MspInit 0 */ 86 | 87 | /* USER CODE END USART2_MspInit 0 */ 88 | /* USART2 clock enable */ 89 | __HAL_RCC_USART2_CLK_ENABLE(); 90 | 91 | __HAL_RCC_GPIOA_CLK_ENABLE(); 92 | /**USART2 GPIO Configuration 93 | PA2 ------> USART2_TX 94 | PA3 ------> USART2_RX 95 | */ 96 | GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3; 97 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 98 | GPIO_InitStruct.Pull = GPIO_PULLUP; 99 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; 100 | GPIO_InitStruct.Alternate = GPIO_AF7_USART2; 101 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 102 | 103 | /* USER CODE BEGIN USART2_MspInit 1 */ 104 | 105 | /* USER CODE END USART2_MspInit 1 */ 106 | } 107 | } 108 | 109 | void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle) 110 | { 111 | 112 | if(uartHandle->Instance==USART2) 113 | { 114 | /* USER CODE BEGIN USART2_MspDeInit 0 */ 115 | 116 | /* USER CODE END USART2_MspDeInit 0 */ 117 | /* Peripheral clock disable */ 118 | __HAL_RCC_USART2_CLK_DISABLE(); 119 | 120 | /**USART2 GPIO Configuration 121 | PA2 ------> USART2_TX 122 | PA3 ------> USART2_RX 123 | */ 124 | HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_3); 125 | 126 | /* USER CODE BEGIN USART2_MspDeInit 1 */ 127 | 128 | /* USER CODE END USART2_MspDeInit 1 */ 129 | } 130 | } 131 | 132 | /* USER CODE BEGIN 1 */ 133 | 134 | /* USER CODE END 1 */ 135 | 136 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 137 | -------------------------------------------------------------------------------- /RobotDog/Task/body_task.c: -------------------------------------------------------------------------------- 1 | #include "body_task.h" 2 | #include "scs009.h" 3 | #include "remote.h" 4 | #include "math.h" 5 | #include "mpu6050.h" 6 | 7 | struct Leg_t FR_Leg; 8 | struct Leg_t FL_Leg; 9 | struct Leg_t BL_Leg; 10 | struct Leg_t BR_Leg; 11 | 12 | struct Body_t body; 13 | 14 | // 静止站立状态时12个舵机的位置 15 | int init_position[12] = {550, 641, 796, 16 | 525, 491, 79, 17 | 600, 864, 766, 18 | 274, 342, 207}; 19 | 20 | int Abs(float a) 21 | { 22 | return (a>=0)?a:-a; 23 | } 24 | 25 | void BodyInit(void) 26 | { 27 | // 初始化右前腿 28 | FR_Leg.IDs[0] = 1; 29 | FR_Leg.IDs[1] = 2; 30 | FR_Leg.IDs[2] = 3; 31 | FR_Leg.bias_position[0] = init_position[0]; 32 | FR_Leg.bias_position[1] = init_position[1]; 33 | FR_Leg.bias_position[2] = init_position[2]; 34 | FR_Leg.coefficient_1 = 1; 35 | FR_Leg.coefficient_2 = -1; 36 | FR_Leg.x = 0.0f; 37 | FR_Leg.y = 0.0f; 38 | FR_Leg.z = 86.6f; 39 | 40 | // 初始化左前腿 41 | FL_Leg.IDs[0] = 4; 42 | FL_Leg.IDs[1] = 5; 43 | FL_Leg.IDs[2] = 6; 44 | FL_Leg.bias_position[0] = init_position[3]; 45 | FL_Leg.bias_position[1] = init_position[4]; 46 | FL_Leg.bias_position[2] = init_position[5]; 47 | FL_Leg.coefficient_1 = 1; 48 | FL_Leg.coefficient_2 = 1; 49 | FL_Leg.x = 0.0f; 50 | FL_Leg.y = 0.0f; 51 | FL_Leg.z = 86.6f; 52 | 53 | // 初始化左后腿 54 | BL_Leg.IDs[0] = 10; 55 | BL_Leg.IDs[1] = 11; 56 | BL_Leg.IDs[2] = 12; 57 | BL_Leg.bias_position[0] = init_position[9]; 58 | BL_Leg.bias_position[1] = init_position[10]; 59 | BL_Leg.bias_position[2] = init_position[11]; 60 | BL_Leg.coefficient_1 = -1; 61 | BL_Leg.coefficient_2 = 1; 62 | BL_Leg.x = 0.0f; 63 | BL_Leg.y = 0.0f; 64 | BL_Leg.z = 86.6f; 65 | 66 | // 初始化右后腿 67 | BR_Leg.IDs[0] = 7; 68 | BR_Leg.IDs[1] = 8; 69 | BR_Leg.IDs[2] = 9; 70 | BR_Leg.bias_position[0] = init_position[6]; 71 | BR_Leg.bias_position[1] = init_position[7]; 72 | BR_Leg.bias_position[2] = init_position[8]; 73 | BR_Leg.coefficient_1 = -1; 74 | BR_Leg.coefficient_2 = -1; 75 | BR_Leg.x = 0.0f; 76 | BR_Leg.y = 0.0f; 77 | BR_Leg.z = 86.6f; 78 | 79 | body.workstate = Stop; 80 | } 81 | 82 | // 根据腿末端坐标计算腿部三个舵机的位置 83 | void LegCalc(struct Leg_t* leg) 84 | { 85 | leg->x = leg->delta_x; 86 | leg->y = leg->delta_y; 87 | leg->z = 86.6f + leg->delta_z; 88 | float L; 89 | L = sqrt(leg->x * leg->x + leg->y * leg->y + leg->z * leg->z); 90 | leg->angle_1 = asin(leg->y/L); 91 | leg->angle_2 = acos(L/100) - asin(leg->x/L); 92 | leg->angle_3 = acos(1 - L*L/5000); 93 | leg->angle_1 *= RAD_TO_DEGREE; 94 | leg->angle_2 *= RAD_TO_DEGREE; 95 | leg->angle_3 *= RAD_TO_DEGREE; 96 | leg->angle_3 = 180 - leg->angle_3; 97 | leg->position[0] = leg->bias_position[0] + leg->coefficient_1 * leg->angle_1 * ANGLE_TO_ENCODER; 98 | leg->position[1] = leg->bias_position[1] + leg->coefficient_2 * leg->angle_2 * ANGLE_TO_ENCODER; 99 | leg->position[2] = leg->bias_position[2] + leg->coefficient_2 * leg->angle_3 * ANGLE_TO_ENCODER; 100 | } 101 | 102 | void LegChange(void) 103 | { 104 | LegCalc(&FR_Leg); 105 | LegCalc(&FL_Leg); 106 | LegCalc(&BL_Leg); 107 | LegCalc(&BR_Leg); 108 | } 109 | 110 | // 机器人姿态解析,根据机器人的yaw、pitch、roll计算四条腿末端坐标 111 | void AttitudeParse(void) 112 | { 113 | float yaw_angle = 42.249f - body.yaw; 114 | yaw_angle /= RAD_TO_DEGREE; 115 | float yaw_delta_x = 56.95f - 84.7f*sin(yaw_angle); 116 | float yaw_delta_y = 84.7f * cos(yaw_angle) - 62.7f; 117 | 118 | float pitch_angle = 90.0f - Abs(body.pitch)/2; 119 | pitch_angle -= 53.489f; 120 | pitch_angle /= RAD_TO_DEGREE; 121 | float tmp_length = sqrt(22210.76f*(1-cos(body.pitch/57.596f))); 122 | float pitch_delta_x = tmp_length * cos(pitch_angle); 123 | float pitch_delta_z = tmp_length * sin(pitch_angle); 124 | if(body.pitch < 0) 125 | { 126 | pitch_delta_x = -pitch_delta_x; 127 | pitch_delta_z = -pitch_delta_z; 128 | } 129 | 130 | tmp_length = sqrt(20834.785f*(1-cos(body.roll/57.596f))); 131 | pitch_angle = 90.0f - Abs(body.roll)/2; 132 | pitch_angle -= 56.084f; 133 | pitch_angle /= RAD_TO_DEGREE; 134 | float roll_delta_y = tmp_length * cos(pitch_angle); 135 | float roll_delta_z = tmp_length * sin(pitch_angle); 136 | if(body.roll < 0) 137 | { 138 | roll_delta_y = -roll_delta_y; 139 | roll_delta_z = -roll_delta_z; 140 | } 141 | 142 | FR_Leg.delta_x = yaw_delta_x - pitch_delta_x; 143 | FR_Leg.delta_y = -yaw_delta_y + roll_delta_y; 144 | FR_Leg.delta_z = pitch_delta_z - roll_delta_z; 145 | 146 | FL_Leg.delta_x = -yaw_delta_x - pitch_delta_x; 147 | FL_Leg.delta_y = -yaw_delta_y + roll_delta_y; 148 | FL_Leg.delta_z = pitch_delta_z + roll_delta_z; 149 | 150 | BL_Leg.delta_x = -yaw_delta_x - pitch_delta_x; 151 | BL_Leg.delta_y = yaw_delta_y + roll_delta_y; 152 | BL_Leg.delta_z = -pitch_delta_z + roll_delta_z; 153 | 154 | BR_Leg.delta_x = yaw_delta_x - pitch_delta_x; 155 | BR_Leg.delta_y = yaw_delta_y + roll_delta_y; 156 | BR_Leg.delta_z = -pitch_delta_z - roll_delta_z; 157 | } 158 | 159 | void ClearLegData(struct Leg_t * leg) 160 | { 161 | leg->delta_x = 0; 162 | leg->delta_y = 0; 163 | leg->delta_z = 0; 164 | } 165 | 166 | // 机器人单条腿的行走运动 167 | void Move(struct Leg_t * leg) 168 | { 169 | uint8_t cycle = 36; 170 | int StepLength = 2*body.vx; 171 | int LR_StepLength = 2*body.vy; 172 | int R_StepLength = 2*body.rotate; 173 | // 设置遥控器死区 174 | if(Abs(body.vx) < 2 && Abs(body.vy) < 2 && Abs(body.rotate) < 2) 175 | { 176 | leg->delta_x = 0; 177 | leg->count = 0; 178 | return; 179 | } 180 | if(leg->state != leg->last_state) leg->count = 0; 181 | leg->count++; 182 | if(leg->state == Up) 183 | { 184 | leg->delta_x = -StepLength+leg->count*2*StepLength/cycle; 185 | leg->delta_y = -LR_StepLength+leg->count*2*LR_StepLength/cycle; 186 | if(leg == &FR_Leg || leg == &FL_Leg) 187 | { 188 | leg->delta_y += -R_StepLength+leg->count*2*R_StepLength/cycle; 189 | } 190 | else 191 | { 192 | leg->delta_y -= -R_StepLength+leg->count*2*R_StepLength/cycle; 193 | } 194 | } 195 | else if(leg->state == Down) 196 | { 197 | leg->delta_x = StepLength-leg->count*2*StepLength/(3*cycle); 198 | leg->delta_y = LR_StepLength-leg->count*2*LR_StepLength/(3*cycle); 199 | if(leg == &FR_Leg || leg == &FL_Leg) 200 | { 201 | leg->delta_y += R_StepLength-leg->count*2*R_StepLength/(3*cycle); 202 | } 203 | else 204 | { 205 | leg->delta_y -= R_StepLength-leg->count*2*R_StepLength/(3*cycle); 206 | } 207 | } 208 | } 209 | 210 | // 依次控制四条腿的行走状态 211 | void ListLeg(void) 212 | { 213 | static int count = 0; 214 | if(Abs(body.vx) < 2 && Abs(body.vy) < 2 && Abs(body.rotate) < 2) 215 | { 216 | count = 0; 217 | FR_Leg.state = Down; 218 | BL_Leg.state = Down; 219 | FL_Leg.state = Down; 220 | BR_Leg.state = Down; 221 | FR_Leg.delta_z = 0; 222 | BL_Leg.delta_z = 0; 223 | FL_Leg.delta_z = 0; 224 | BR_Leg.delta_z = 0; 225 | return; 226 | } 227 | count ++; 228 | uint8_t cycle = 36; 229 | FR_Leg.last_state = FR_Leg.state; 230 | BL_Leg.last_state = BL_Leg.state; 231 | FL_Leg.last_state = FL_Leg.state; 232 | BR_Leg.last_state = BR_Leg.state; 233 | if(count 10) body.pitch = 10; 322 | if(body.pitch < -10) body.pitch = -10; 323 | if(body.roll > 10) body.roll = 10; 324 | if(body.roll < -10) body.roll = -10; 325 | AttitudeParse(); 326 | } 327 | else if(body.workstate == Walk) 328 | { 329 | body.vx = remote.value.right_y - 16; 330 | body.vy = remote.value.right_x - 16; 331 | body.rotate = remote.value.left_x - 16; 332 | ListLeg(); 333 | Move(&FR_Leg); 334 | Move(&FL_Leg); 335 | Move(&BL_Leg); 336 | Move(&BR_Leg); 337 | } 338 | else if(body.workstate == Body_Stable) 339 | { 340 | body.pitch = -mpu6500.angle.pitch; 341 | body.roll = mpu6500.angle.roll; 342 | if(body.pitch > 5) body.pitch = 5; 343 | if(body.pitch < -5) body.pitch = -5; 344 | if(body.roll > 5) body.roll = 5; 345 | if(body.roll < -5) body.roll = -5; 346 | AttitudeParse(); 347 | } 348 | } 349 | 350 | // 控制舵机 351 | void ServoSendData(void) 352 | { 353 | snycWrite(FR_Leg.IDs, 3, 0x2A, FR_Leg.position); 354 | snycWrite(FL_Leg.IDs, 3, 0x2A, FL_Leg.position); 355 | snycWrite(BL_Leg.IDs, 3, 0x2A, BL_Leg.position); 356 | snycWrite(BR_Leg.IDs, 3, 0x2A, BR_Leg.position); 357 | } 358 | -------------------------------------------------------------------------------- /RobotDog/Task/body_task.h: -------------------------------------------------------------------------------- 1 | #ifndef BODY_TASK_H 2 | #define BODY_TASK_H 3 | 4 | #include "stm32f4xx.h" 5 | 6 | #define BIG_LEG_LENGTH 50 7 | #define SMALL_LEG_LENGTH 50 8 | #define LONG_LENGTH 125.4f 9 | #define SHORT_LENGTH 113.9f 10 | #define SHORT_LONG_ANGLE 42.249f 11 | #define DIAGNONAL_LENGTH 84.7f 12 | 13 | #define ANGLE_TO_ENCODER 3.413f 14 | #define RAD_TO_DEGREE 57.596f; 15 | 16 | struct Leg_t 17 | { 18 | uint8_t IDs[3]; 19 | int position[3]; 20 | int bias_position[3]; 21 | int coefficient_1; 22 | int coefficient_2; 23 | float x; 24 | float y; 25 | float z; 26 | float delta_x; 27 | float delta_y; 28 | float delta_z; 29 | float angle_1; //踝关节电机 30 | float angle_2; //小腿关节 31 | float angle_3; //大腿关节 32 | uint8_t count; 33 | enum 34 | { 35 | Down, 36 | Up, 37 | } state,last_state; 38 | }; 39 | 40 | struct Body_t 41 | { 42 | int vx; 43 | int vy; 44 | int rotate; 45 | float yaw; 46 | float pitch; 47 | float roll; 48 | enum 49 | { 50 | Attitude, 51 | Walk, 52 | Stop, 53 | Body_Stable 54 | } workstate; 55 | }; 56 | 57 | extern struct Body_t body; 58 | 59 | void BodyInit(void); 60 | void LegChange(void); 61 | void ServoSendData(void); 62 | void BodyChange(void); 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /RobotDog/Task/head_task.c: -------------------------------------------------------------------------------- 1 | #include "head_task.h" 2 | #include "body_task.h" 3 | #include "remote.h" 4 | #include "math.h" 5 | #include "scs009.h" 6 | 7 | struct Head_t head; 8 | 9 | // 头部初始状态时三个舵机的位置 10 | int head_init_position[3] = {505, 500, 518}; 11 | 12 | void HeadInit(void) 13 | { 14 | head.IDs[0] = 13; 15 | head.IDs[1] = 14; 16 | head.IDs[2] = 15; 17 | head.bias_position[0] = head_init_position[0]; 18 | head.bias_position[1] = head_init_position[1]; 19 | head.bias_position[2] = head_init_position[2]; 20 | head.x = 70.71f; 21 | head.y = 0.0f; 22 | head.z = 0.0f; 23 | 24 | head.workstate = Head_Stop; 25 | } 26 | 27 | // 头部控制函数入口 28 | void HeadChange(void) 29 | { 30 | if(head.workstate == Work) 31 | { 32 | head.delta_x = remote.value.right_y - 16; 33 | head.delta_y = remote.value.right_x - 16; 34 | head.delta_z = remote.value.left_x - 16; 35 | } 36 | else if(head.workstate == Head_Stop) 37 | { 38 | head.delta_x = 0; 39 | head.delta_y = 0; 40 | head.delta_z = 0; 41 | } 42 | else if(head.workstate == Stable) 43 | { 44 | float Length = sqrt(27852.72f*(1-cos(body.yaw/57.596f))); 45 | float theta = 90 - body.yaw/2; 46 | theta /= RAD_TO_DEGREE; 47 | head.delta_y = -Length * sin(theta); 48 | head.delta_x = -Length * cos(theta); 49 | if(body.yaw < 0) 50 | { 51 | head.delta_y = -head.delta_y; 52 | } 53 | Length = sqrt(29529.36f*(1-cos(body.pitch/57.596f))); 54 | theta = 90 - body.pitch/2; 55 | theta /= RAD_TO_DEGREE; 56 | head.delta_x -= Length * cos(theta); 57 | head.delta_z = -Length * sin(theta); 58 | if(body.pitch < 0) 59 | { 60 | head.delta_z = -head.delta_z; 61 | } 62 | } 63 | } 64 | 65 | // 根据头部末端坐标计算三个舵机的角度 66 | void HeadCalc(void) 67 | { 68 | float L; 69 | head.x = 70.71f + head.delta_x; 70 | head.y = head.delta_y; 71 | head.z = head.delta_z; 72 | L = sqrt(head.x * head.x + head.y * head.y + head.z * head.z); 73 | head.angle_1 = asin(head.y/L); 74 | head.angle_2 = asin(head.z/L)+acos(L/100); 75 | head.angle_3 = acos(1 - L*L/5000); 76 | head.angle_1 *= RAD_TO_DEGREE; 77 | head.angle_2 *= RAD_TO_DEGREE; 78 | head.angle_3 *= RAD_TO_DEGREE; 79 | head.angle_2 = 90 - head.angle_2; 80 | head.angle_3 = 90 - head.angle_3; 81 | head.position[0] = head.bias_position[0] + head.angle_1 * ANGLE_TO_ENCODER; 82 | head.position[1] = head.bias_position[1] + head.angle_2 * ANGLE_TO_ENCODER; 83 | head.position[2] = head.bias_position[2] - head.angle_3 * ANGLE_TO_ENCODER; 84 | } 85 | 86 | void HeadServoSendData(void) 87 | { 88 | snycWrite(head.IDs, 3, 0x2A, head.position); 89 | } 90 | -------------------------------------------------------------------------------- /RobotDog/Task/head_task.h: -------------------------------------------------------------------------------- 1 | #ifndef HEAD_TASK_H 2 | #define HEAD_TASK_H 3 | 4 | #include "stm32f4xx.h" 5 | 6 | struct Head_t 7 | { 8 | uint8_t IDs[3]; 9 | int position[3]; 10 | int bias_position[3]; 11 | float x; 12 | float y; 13 | float z; 14 | float delta_x; 15 | float delta_y; 16 | float delta_z; 17 | float angle_1; //踝关节电机 18 | float angle_2; //小腿关节 19 | float angle_3; //大腿关节 20 | enum 21 | { 22 | Work, // 遥控器直接控制头部末端位置 23 | Head_Stop, // 遥控器无法控制头部 24 | Stable // 遥控器控制身体姿态,同时头部稳定在原位 25 | } workstate; 26 | }; 27 | 28 | extern struct Head_t head; 29 | 30 | void HeadInit(void); 31 | void HeadCalc(void); 32 | void HeadChange(void); 33 | void HeadServoSendData(void); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /RobotDog/Task/robotcmd.c: -------------------------------------------------------------------------------- 1 | #include "robotcmd.h" 2 | #include "body_task.h" 3 | #include "head_task.h" 4 | 5 | void LedStateChange(void) 6 | { 7 | if(remote.value.key_1 == 1) 8 | { 9 | HAL_GPIO_WritePin(GPIOC, GPIO_PIN_14, GPIO_PIN_RESET); 10 | } 11 | else 12 | { 13 | HAL_GPIO_WritePin(GPIOC, GPIO_PIN_14, GPIO_PIN_SET); 14 | } 15 | } 16 | 17 | void BodyParamChange(void) 18 | { 19 | if(remote.state == 1) 20 | { 21 | if(remote.value.key_1 == 1 || remote.value.key_4 == 1) 22 | { 23 | body.workstate = Stop; 24 | } 25 | if(remote.value.key_2 == 1 || remote.value.key_5 == 1) 26 | { 27 | body.workstate = Attitude; 28 | } 29 | if(remote.value.key_3 == 1) 30 | { 31 | body.workstate = Walk; 32 | } 33 | if(remote.value.key_6 == 1) 34 | { 35 | body.workstate = Body_Stable; 36 | } 37 | } 38 | else 39 | { 40 | body.workstate = Stop; 41 | } 42 | } 43 | 44 | void HeadStateChange(void) 45 | { 46 | if(remote.state == 1) 47 | { 48 | if(remote.value.key_4 == 1) 49 | { 50 | head.workstate = Work; 51 | } 52 | else if(remote.value.key_1 == 1 || remote.value.key_2 == 1 || remote.value.key_3 == 1 || remote.value.key_6 == 1) 53 | { 54 | head.workstate = Head_Stop; 55 | } 56 | else if(remote.value.key_5 == 1) 57 | { 58 | head.workstate = Stable; 59 | } 60 | } 61 | else 62 | { 63 | head.workstate = Head_Stop; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /RobotDog/Task/robotcmd.h: -------------------------------------------------------------------------------- 1 | #ifndef ROBOTCMD_H 2 | #define ROBOTCMD_H 3 | 4 | #include "remote.h" 5 | 6 | void LedStateChange(void); 7 | void BodyParamChange(void); 8 | void HeadStateChange(void); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /RobotDog_Remote/Inc/adc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * File Name : ADC.h 4 | * Description : This file provides code for the configuration 5 | * of the ADC instances. 6 | ****************************************************************************** 7 | ** This notice applies to any and all portions of this file 8 | * that are not between comment pairs USER CODE BEGIN and 9 | * USER CODE END. Other portions of this file, whether 10 | * inserted by the user or by software development tools 11 | * are owned by their respective copyright owners. 12 | * 13 | * COPYRIGHT(c) 2019 STMicroelectronics 14 | * 15 | * Redistribution and use in source and binary forms, with or without modification, 16 | * are permitted provided that the following conditions are met: 17 | * 1. Redistributions of source code must retain the above copyright notice, 18 | * this list of conditions and the following disclaimer. 19 | * 2. Redistributions in binary form must reproduce the above copyright notice, 20 | * this list of conditions and the following disclaimer in the documentation 21 | * and/or other materials provided with the distribution. 22 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 23 | * may be used to endorse or promote products derived from this software 24 | * without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 29 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 32 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 33 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 34 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | * 37 | ****************************************************************************** 38 | */ 39 | /* Define to prevent recursive inclusion -------------------------------------*/ 40 | #ifndef __adc_H 41 | #define __adc_H 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | /* Includes ------------------------------------------------------------------*/ 47 | #include "main.h" 48 | 49 | /* USER CODE BEGIN Includes */ 50 | 51 | /* USER CODE END Includes */ 52 | 53 | extern ADC_HandleTypeDef hadc1; 54 | 55 | /* USER CODE BEGIN Private defines */ 56 | 57 | /* USER CODE END Private defines */ 58 | 59 | void MX_ADC1_Init(void); 60 | 61 | /* USER CODE BEGIN Prototypes */ 62 | 63 | /* USER CODE END Prototypes */ 64 | 65 | #ifdef __cplusplus 66 | } 67 | #endif 68 | #endif /*__ adc_H */ 69 | 70 | /** 71 | * @} 72 | */ 73 | 74 | /** 75 | * @} 76 | */ 77 | 78 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 79 | -------------------------------------------------------------------------------- /RobotDog_Remote/Inc/dma.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * File Name : dma.h 4 | * Description : This file contains all the function prototypes for 5 | * the dma.c file 6 | ****************************************************************************** 7 | ** This notice applies to any and all portions of this file 8 | * that are not between comment pairs USER CODE BEGIN and 9 | * USER CODE END. Other portions of this file, whether 10 | * inserted by the user or by software development tools 11 | * are owned by their respective copyright owners. 12 | * 13 | * COPYRIGHT(c) 2019 STMicroelectronics 14 | * 15 | * Redistribution and use in source and binary forms, with or without modification, 16 | * are permitted provided that the following conditions are met: 17 | * 1. Redistributions of source code must retain the above copyright notice, 18 | * this list of conditions and the following disclaimer. 19 | * 2. Redistributions in binary form must reproduce the above copyright notice, 20 | * this list of conditions and the following disclaimer in the documentation 21 | * and/or other materials provided with the distribution. 22 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 23 | * may be used to endorse or promote products derived from this software 24 | * without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 29 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 32 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 33 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 34 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | * 37 | ****************************************************************************** 38 | */ 39 | /* Define to prevent recursive inclusion -------------------------------------*/ 40 | #ifndef __dma_H 41 | #define __dma_H 42 | 43 | #ifdef __cplusplus 44 | extern "C" { 45 | #endif 46 | 47 | /* Includes ------------------------------------------------------------------*/ 48 | #include "main.h" 49 | 50 | /* DMA memory to memory transfer handles -------------------------------------*/ 51 | 52 | /* USER CODE BEGIN Includes */ 53 | 54 | /* USER CODE END Includes */ 55 | 56 | /* USER CODE BEGIN Private defines */ 57 | 58 | /* USER CODE END Private defines */ 59 | 60 | void MX_DMA_Init(void); 61 | 62 | /* USER CODE BEGIN Prototypes */ 63 | 64 | /* USER CODE END Prototypes */ 65 | 66 | #ifdef __cplusplus 67 | } 68 | #endif 69 | 70 | #endif /* __dma_H */ 71 | 72 | /** 73 | * @} 74 | */ 75 | 76 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 77 | -------------------------------------------------------------------------------- /RobotDog_Remote/Inc/gpio.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * File Name : gpio.h 4 | * Description : This file contains all the functions prototypes for 5 | * the gpio 6 | ****************************************************************************** 7 | ** This notice applies to any and all portions of this file 8 | * that are not between comment pairs USER CODE BEGIN and 9 | * USER CODE END. Other portions of this file, whether 10 | * inserted by the user or by software development tools 11 | * are owned by their respective copyright owners. 12 | * 13 | * COPYRIGHT(c) 2019 STMicroelectronics 14 | * 15 | * Redistribution and use in source and binary forms, with or without modification, 16 | * are permitted provided that the following conditions are met: 17 | * 1. Redistributions of source code must retain the above copyright notice, 18 | * this list of conditions and the following disclaimer. 19 | * 2. Redistributions in binary form must reproduce the above copyright notice, 20 | * this list of conditions and the following disclaimer in the documentation 21 | * and/or other materials provided with the distribution. 22 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 23 | * may be used to endorse or promote products derived from this software 24 | * without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 29 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 32 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 33 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 34 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | * 37 | ****************************************************************************** 38 | */ 39 | 40 | /* Define to prevent recursive inclusion -------------------------------------*/ 41 | #ifndef __gpio_H 42 | #define __gpio_H 43 | #ifdef __cplusplus 44 | extern "C" { 45 | #endif 46 | 47 | /* Includes ------------------------------------------------------------------*/ 48 | #include "main.h" 49 | 50 | /* USER CODE BEGIN Includes */ 51 | 52 | /* USER CODE END Includes */ 53 | 54 | /* USER CODE BEGIN Private defines */ 55 | 56 | /* USER CODE END Private defines */ 57 | 58 | void MX_GPIO_Init(void); 59 | 60 | /* USER CODE BEGIN Prototypes */ 61 | 62 | /* USER CODE END Prototypes */ 63 | 64 | #ifdef __cplusplus 65 | } 66 | #endif 67 | #endif /*__ pinoutConfig_H */ 68 | 69 | /** 70 | * @} 71 | */ 72 | 73 | /** 74 | * @} 75 | */ 76 | 77 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 78 | -------------------------------------------------------------------------------- /RobotDog_Remote/Inc/main.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : main.h 5 | * @brief : Header for main.c file. 6 | * This file contains the common defines of the application. 7 | ****************************************************************************** 8 | ** This notice applies to any and all portions of this file 9 | * that are not between comment pairs USER CODE BEGIN and 10 | * USER CODE END. Other portions of this file, whether 11 | * inserted by the user or by software development tools 12 | * are owned by their respective copyright owners. 13 | * 14 | * COPYRIGHT(c) 2019 STMicroelectronics 15 | * 16 | * Redistribution and use in source and binary forms, with or without modification, 17 | * are permitted provided that the following conditions are met: 18 | * 1. Redistributions of source code must retain the above copyright notice, 19 | * this list of conditions and the following disclaimer. 20 | * 2. Redistributions in binary form must reproduce the above copyright notice, 21 | * this list of conditions and the following disclaimer in the documentation 22 | * and/or other materials provided with the distribution. 23 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 24 | * may be used to endorse or promote products derived from this software 25 | * without specific prior written permission. 26 | * 27 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 28 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 29 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 30 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 31 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 33 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 34 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 35 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 36 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 37 | * 38 | ****************************************************************************** 39 | */ 40 | /* USER CODE END Header */ 41 | 42 | /* Define to prevent recursive inclusion -------------------------------------*/ 43 | #ifndef __MAIN_H 44 | #define __MAIN_H 45 | 46 | #ifdef __cplusplus 47 | extern "C" { 48 | #endif 49 | 50 | /* Includes ------------------------------------------------------------------*/ 51 | #include "stm32f1xx_hal.h" 52 | 53 | /* Private includes ----------------------------------------------------------*/ 54 | /* USER CODE BEGIN Includes */ 55 | 56 | /* USER CODE END Includes */ 57 | 58 | /* Exported types ------------------------------------------------------------*/ 59 | /* USER CODE BEGIN ET */ 60 | 61 | /* USER CODE END ET */ 62 | 63 | /* Exported constants --------------------------------------------------------*/ 64 | /* USER CODE BEGIN EC */ 65 | 66 | /* USER CODE END EC */ 67 | 68 | /* Exported macro ------------------------------------------------------------*/ 69 | /* USER CODE BEGIN EM */ 70 | 71 | /* USER CODE END EM */ 72 | 73 | /* Exported functions prototypes ---------------------------------------------*/ 74 | void Error_Handler(void); 75 | 76 | /* USER CODE BEGIN EFP */ 77 | 78 | /* USER CODE END EFP */ 79 | 80 | /* Private defines -----------------------------------------------------------*/ 81 | /* USER CODE BEGIN Private defines */ 82 | 83 | /* USER CODE END Private defines */ 84 | 85 | #ifdef __cplusplus 86 | } 87 | #endif 88 | 89 | #endif /* __MAIN_H */ 90 | 91 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 92 | -------------------------------------------------------------------------------- /RobotDog_Remote/Inc/nrf24l01.h: -------------------------------------------------------------------------------- 1 | #ifndef NRF24L01_H 2 | #define NRF24L01_H 3 | 4 | #include "spi.h" 5 | 6 | #define hspi_NRF24L01 hspi1 7 | 8 | #define GPIO_CE GPIOB 9 | #define GPIO_CE_PIN GPIO_PIN_1 10 | #define GPIO_CSN GPIOB 11 | #define GPIO_CSN_PIN GPIO_PIN_0 12 | #define GPIO_IRQ GPIOB 13 | #define GPIO_IRQ_PIN GPIO_PIN_10 14 | 15 | #define NRF24L01_READ_REG 0x00 16 | #define NRF24L01_WRITE_REG 0x20 17 | #define NRF24L01_RD_RX_PLOAD 0x61 18 | #define NRF24L01_WR_TX_PLOAD 0xA0 19 | #define NRF24L01_FLUSH_TX 0xE1 20 | #define NRF24L01_FLUSH_RX 0xE2 21 | 22 | #define NRF24L01_TX_ADDR 0x10 23 | #define NRF24L01_RX_ADDR_P0 0x0A 24 | 25 | #define NRF24L01_CONFIG 0x00 26 | #define NRF24L01_EN_AA 0x01 27 | #define NRF24L01_EN_RXADDR 0x02 28 | #define NRF24L01_SETUP_RETR 0x04 29 | #define NRF24L01_RF_CH 0x05 30 | #define NRF24L01_RF_SETUP 0x06 31 | #define NRF24L01_STATUS 0x07 32 | 33 | #define NRF24L01_MAX_TX 0x10 34 | #define NRF24L01_TX_OK 0x20 35 | #define NRF24L01_RX_OK 0x40 36 | 37 | #define NRF24L01_RX_PW_P0 0x11 38 | 39 | #define TX_ADR_WIDTH 5 40 | #define RX_ADR_WIDTH 5 41 | #define TX_PLOAD_WIDTH 32 42 | #define RX_PLOAD_WIDTH 32 43 | 44 | int NRF24L01_Check(void); 45 | void NRF24L01_TX_Mode(void); 46 | void NRF24L01_RX_Mode(void); 47 | uint8_t NRF24L01_TxPacket(uint8_t *txbuf); 48 | uint8_t NRF24L01_RxPacket(uint8_t *rxbuf); 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /RobotDog_Remote/Inc/spi.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * File Name : SPI.h 4 | * Description : This file provides code for the configuration 5 | * of the SPI instances. 6 | ****************************************************************************** 7 | ** This notice applies to any and all portions of this file 8 | * that are not between comment pairs USER CODE BEGIN and 9 | * USER CODE END. Other portions of this file, whether 10 | * inserted by the user or by software development tools 11 | * are owned by their respective copyright owners. 12 | * 13 | * COPYRIGHT(c) 2019 STMicroelectronics 14 | * 15 | * Redistribution and use in source and binary forms, with or without modification, 16 | * are permitted provided that the following conditions are met: 17 | * 1. Redistributions of source code must retain the above copyright notice, 18 | * this list of conditions and the following disclaimer. 19 | * 2. Redistributions in binary form must reproduce the above copyright notice, 20 | * this list of conditions and the following disclaimer in the documentation 21 | * and/or other materials provided with the distribution. 22 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 23 | * may be used to endorse or promote products derived from this software 24 | * without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 29 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 32 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 33 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 34 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | * 37 | ****************************************************************************** 38 | */ 39 | /* Define to prevent recursive inclusion -------------------------------------*/ 40 | #ifndef __spi_H 41 | #define __spi_H 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | /* Includes ------------------------------------------------------------------*/ 47 | #include "main.h" 48 | 49 | /* USER CODE BEGIN Includes */ 50 | 51 | /* USER CODE END Includes */ 52 | 53 | extern SPI_HandleTypeDef hspi1; 54 | 55 | /* USER CODE BEGIN Private defines */ 56 | 57 | /* USER CODE END Private defines */ 58 | 59 | void MX_SPI1_Init(void); 60 | 61 | /* USER CODE BEGIN Prototypes */ 62 | 63 | /* USER CODE END Prototypes */ 64 | 65 | #ifdef __cplusplus 66 | } 67 | #endif 68 | #endif /*__ spi_H */ 69 | 70 | /** 71 | * @} 72 | */ 73 | 74 | /** 75 | * @} 76 | */ 77 | 78 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 79 | -------------------------------------------------------------------------------- /RobotDog_Remote/Inc/stm32f1xx_hal_conf.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f1xx_hal_conf.h 4 | * @brief HAL configuration file. 5 | ****************************************************************************** 6 | * @attention 7 | * 8 | *

© COPYRIGHT(c) 2019 STMicroelectronics

9 | * 10 | * Redistribution and use in source and binary forms, with or without modification, 11 | * are permitted provided that the following conditions are met: 12 | * 1. Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright notice, 15 | * this list of conditions and the following disclaimer in the documentation 16 | * and/or other materials provided with the distribution. 17 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | ****************************************************************************** 33 | */ 34 | 35 | /* Define to prevent recursive inclusion -------------------------------------*/ 36 | #ifndef __STM32F1xx_HAL_CONF_H 37 | #define __STM32F1xx_HAL_CONF_H 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | /* Exported types ------------------------------------------------------------*/ 44 | /* Exported constants --------------------------------------------------------*/ 45 | 46 | /* ########################## Module Selection ############################## */ 47 | /** 48 | * @brief This is the list of modules to be used in the HAL driver 49 | */ 50 | 51 | #define HAL_MODULE_ENABLED 52 | #define HAL_ADC_MODULE_ENABLED 53 | /*#define HAL_CRYP_MODULE_ENABLED */ 54 | /*#define HAL_CAN_MODULE_ENABLED */ 55 | /*#define HAL_CEC_MODULE_ENABLED */ 56 | /*#define HAL_CORTEX_MODULE_ENABLED */ 57 | /*#define HAL_CRC_MODULE_ENABLED */ 58 | /*#define HAL_DAC_MODULE_ENABLED */ 59 | #define HAL_DMA_MODULE_ENABLED 60 | /*#define HAL_ETH_MODULE_ENABLED */ 61 | /*#define HAL_FLASH_MODULE_ENABLED */ 62 | #define HAL_GPIO_MODULE_ENABLED 63 | /*#define HAL_I2C_MODULE_ENABLED */ 64 | /*#define HAL_I2S_MODULE_ENABLED */ 65 | /*#define HAL_IRDA_MODULE_ENABLED */ 66 | /*#define HAL_IWDG_MODULE_ENABLED */ 67 | /*#define HAL_NOR_MODULE_ENABLED */ 68 | /*#define HAL_NAND_MODULE_ENABLED */ 69 | /*#define HAL_PCCARD_MODULE_ENABLED */ 70 | /*#define HAL_PCD_MODULE_ENABLED */ 71 | /*#define HAL_HCD_MODULE_ENABLED */ 72 | /*#define HAL_PWR_MODULE_ENABLED */ 73 | /*#define HAL_RCC_MODULE_ENABLED */ 74 | /*#define HAL_RTC_MODULE_ENABLED */ 75 | /*#define HAL_SD_MODULE_ENABLED */ 76 | /*#define HAL_MMC_MODULE_ENABLED */ 77 | /*#define HAL_SDRAM_MODULE_ENABLED */ 78 | /*#define HAL_SMARTCARD_MODULE_ENABLED */ 79 | #define HAL_SPI_MODULE_ENABLED 80 | /*#define HAL_SRAM_MODULE_ENABLED */ 81 | /*#define HAL_TIM_MODULE_ENABLED */ 82 | /*#define HAL_UART_MODULE_ENABLED */ 83 | /*#define HAL_USART_MODULE_ENABLED */ 84 | /*#define HAL_WWDG_MODULE_ENABLED */ 85 | /*#define HAL_EXTI_MODULE_ENABLED */ 86 | 87 | #define HAL_CORTEX_MODULE_ENABLED 88 | #define HAL_DMA_MODULE_ENABLED 89 | #define HAL_FLASH_MODULE_ENABLED 90 | #define HAL_GPIO_MODULE_ENABLED 91 | #define HAL_PWR_MODULE_ENABLED 92 | #define HAL_RCC_MODULE_ENABLED 93 | 94 | /* ########################## Oscillator Values adaptation ####################*/ 95 | /** 96 | * @brief Adjust the value of External High Speed oscillator (HSE) used in your application. 97 | * This value is used by the RCC HAL module to compute the system frequency 98 | * (when HSE is used as system clock source, directly or through the PLL). 99 | */ 100 | #if !defined (HSE_VALUE) 101 | #define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */ 102 | #endif /* HSE_VALUE */ 103 | 104 | #if !defined (HSE_STARTUP_TIMEOUT) 105 | #define HSE_STARTUP_TIMEOUT ((uint32_t)100) /*!< Time out for HSE start up, in ms */ 106 | #endif /* HSE_STARTUP_TIMEOUT */ 107 | 108 | /** 109 | * @brief Internal High Speed oscillator (HSI) value. 110 | * This value is used by the RCC HAL module to compute the system frequency 111 | * (when HSI is used as system clock source, directly or through the PLL). 112 | */ 113 | #if !defined (HSI_VALUE) 114 | #define HSI_VALUE ((uint32_t)8000000) /*!< Value of the Internal oscillator in Hz*/ 115 | #endif /* HSI_VALUE */ 116 | 117 | /** 118 | * @brief Internal Low Speed oscillator (LSI) value. 119 | */ 120 | #if !defined (LSI_VALUE) 121 | #define LSI_VALUE 40000U /*!< LSI Typical Value in Hz */ 122 | #endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz 123 | The real value may vary depending on the variations 124 | in voltage and temperature. */ 125 | 126 | /** 127 | * @brief External Low Speed oscillator (LSE) value. 128 | * This value is used by the UART, RTC HAL module to compute the system frequency 129 | */ 130 | #if !defined (LSE_VALUE) 131 | #define LSE_VALUE ((uint32_t)32768) /*!< Value of the External oscillator in Hz*/ 132 | #endif /* LSE_VALUE */ 133 | 134 | #if !defined (LSE_STARTUP_TIMEOUT) 135 | #define LSE_STARTUP_TIMEOUT ((uint32_t)5000) /*!< Time out for LSE start up, in ms */ 136 | #endif /* LSE_STARTUP_TIMEOUT */ 137 | 138 | /* Tip: To avoid modifying this file each time you need to use different HSE, 139 | === you can define the HSE value in your toolchain compiler preprocessor. */ 140 | 141 | /* ########################### System Configuration ######################### */ 142 | /** 143 | * @brief This is the HAL system configuration section 144 | */ 145 | #define VDD_VALUE ((uint32_t)3300) /*!< Value of VDD in mv */ 146 | #define TICK_INT_PRIORITY ((uint32_t)0) /*!< tick interrupt priority (lowest by default) */ 147 | #define USE_RTOS 0 148 | #define PREFETCH_ENABLE 1 149 | 150 | /* ########################## Assert Selection ############################## */ 151 | /** 152 | * @brief Uncomment the line below to expanse the "assert_param" macro in the 153 | * HAL drivers code 154 | */ 155 | /* #define USE_FULL_ASSERT 1U */ 156 | 157 | /* ################## Ethernet peripheral configuration ##################### */ 158 | 159 | /* Section 1 : Ethernet peripheral configuration */ 160 | 161 | /* MAC ADDRESS: MAC_ADDR0:MAC_ADDR1:MAC_ADDR2:MAC_ADDR3:MAC_ADDR4:MAC_ADDR5 */ 162 | #define MAC_ADDR0 2 163 | #define MAC_ADDR1 0 164 | #define MAC_ADDR2 0 165 | #define MAC_ADDR3 0 166 | #define MAC_ADDR4 0 167 | #define MAC_ADDR5 0 168 | 169 | /* Definition of the Ethernet driver buffers size and count */ 170 | #define ETH_RX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for receive */ 171 | #define ETH_TX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for transmit */ 172 | #define ETH_RXBUFNB ((uint32_t)8) /* 4 Rx buffers of size ETH_RX_BUF_SIZE */ 173 | #define ETH_TXBUFNB ((uint32_t)4) /* 4 Tx buffers of size ETH_TX_BUF_SIZE */ 174 | 175 | /* Section 2: PHY configuration section */ 176 | 177 | /* DP83848_PHY_ADDRESS Address*/ 178 | #define DP83848_PHY_ADDRESS 0x01U 179 | /* PHY Reset delay these values are based on a 1 ms Systick interrupt*/ 180 | #define PHY_RESET_DELAY ((uint32_t)0x000000FF) 181 | /* PHY Configuration delay */ 182 | #define PHY_CONFIG_DELAY ((uint32_t)0x00000FFF) 183 | 184 | #define PHY_READ_TO ((uint32_t)0x0000FFFF) 185 | #define PHY_WRITE_TO ((uint32_t)0x0000FFFF) 186 | 187 | /* Section 3: Common PHY Registers */ 188 | 189 | #define PHY_BCR ((uint16_t)0x00) /*!< Transceiver Basic Control Register */ 190 | #define PHY_BSR ((uint16_t)0x01) /*!< Transceiver Basic Status Register */ 191 | 192 | #define PHY_RESET ((uint16_t)0x8000) /*!< PHY Reset */ 193 | #define PHY_LOOPBACK ((uint16_t)0x4000) /*!< Select loop-back mode */ 194 | #define PHY_FULLDUPLEX_100M ((uint16_t)0x2100) /*!< Set the full-duplex mode at 100 Mb/s */ 195 | #define PHY_HALFDUPLEX_100M ((uint16_t)0x2000) /*!< Set the half-duplex mode at 100 Mb/s */ 196 | #define PHY_FULLDUPLEX_10M ((uint16_t)0x0100) /*!< Set the full-duplex mode at 10 Mb/s */ 197 | #define PHY_HALFDUPLEX_10M ((uint16_t)0x0000) /*!< Set the half-duplex mode at 10 Mb/s */ 198 | #define PHY_AUTONEGOTIATION ((uint16_t)0x1000) /*!< Enable auto-negotiation function */ 199 | #define PHY_RESTART_AUTONEGOTIATION ((uint16_t)0x0200) /*!< Restart auto-negotiation function */ 200 | #define PHY_POWERDOWN ((uint16_t)0x0800) /*!< Select the power down mode */ 201 | #define PHY_ISOLATE ((uint16_t)0x0400) /*!< Isolate PHY from MII */ 202 | 203 | #define PHY_AUTONEGO_COMPLETE ((uint16_t)0x0020) /*!< Auto-Negotiation process completed */ 204 | #define PHY_LINKED_STATUS ((uint16_t)0x0004) /*!< Valid link established */ 205 | #define PHY_JABBER_DETECTION ((uint16_t)0x0002) /*!< Jabber condition detected */ 206 | 207 | /* Section 4: Extended PHY Registers */ 208 | #define PHY_SR ((uint16_t)0x10U) /*!< PHY status register Offset */ 209 | 210 | #define PHY_SPEED_STATUS ((uint16_t)0x0002U) /*!< PHY Speed mask */ 211 | #define PHY_DUPLEX_STATUS ((uint16_t)0x0004U) /*!< PHY Duplex mask */ 212 | 213 | /* Includes ------------------------------------------------------------------*/ 214 | /** 215 | * @brief Include module's header file 216 | */ 217 | 218 | #ifdef HAL_RCC_MODULE_ENABLED 219 | #include "stm32f1xx_hal_rcc.h" 220 | #endif /* HAL_RCC_MODULE_ENABLED */ 221 | 222 | #ifdef HAL_EXTI_MODULE_ENABLED 223 | #include "stm32f1xx_hal_exti.h" 224 | #endif /* HAL_EXTI_MODULE_ENABLED */ 225 | 226 | #ifdef HAL_GPIO_MODULE_ENABLED 227 | #include "stm32f1xx_hal_gpio.h" 228 | #endif /* HAL_GPIO_MODULE_ENABLED */ 229 | 230 | #ifdef HAL_DMA_MODULE_ENABLED 231 | #include "stm32f1xx_hal_dma.h" 232 | #endif /* HAL_DMA_MODULE_ENABLED */ 233 | 234 | #ifdef HAL_ETH_MODULE_ENABLED 235 | #include "stm32f1xx_hal_eth.h" 236 | #endif /* HAL_ETH_MODULE_ENABLED */ 237 | 238 | #ifdef HAL_CAN_MODULE_ENABLED 239 | #include "stm32f1xx_hal_can.h" 240 | #endif /* HAL_CAN_MODULE_ENABLED */ 241 | 242 | #ifdef HAL_CEC_MODULE_ENABLED 243 | #include "stm32f1xx_hal_cec.h" 244 | #endif /* HAL_CEC_MODULE_ENABLED */ 245 | 246 | #ifdef HAL_CORTEX_MODULE_ENABLED 247 | #include "stm32f1xx_hal_cortex.h" 248 | #endif /* HAL_CORTEX_MODULE_ENABLED */ 249 | 250 | #ifdef HAL_ADC_MODULE_ENABLED 251 | #include "stm32f1xx_hal_adc.h" 252 | #endif /* HAL_ADC_MODULE_ENABLED */ 253 | 254 | #ifdef HAL_CRC_MODULE_ENABLED 255 | #include "stm32f1xx_hal_crc.h" 256 | #endif /* HAL_CRC_MODULE_ENABLED */ 257 | 258 | #ifdef HAL_DAC_MODULE_ENABLED 259 | #include "stm32f1xx_hal_dac.h" 260 | #endif /* HAL_DAC_MODULE_ENABLED */ 261 | 262 | #ifdef HAL_FLASH_MODULE_ENABLED 263 | #include "stm32f1xx_hal_flash.h" 264 | #endif /* HAL_FLASH_MODULE_ENABLED */ 265 | 266 | #ifdef HAL_SRAM_MODULE_ENABLED 267 | #include "stm32f1xx_hal_sram.h" 268 | #endif /* HAL_SRAM_MODULE_ENABLED */ 269 | 270 | #ifdef HAL_NOR_MODULE_ENABLED 271 | #include "stm32f1xx_hal_nor.h" 272 | #endif /* HAL_NOR_MODULE_ENABLED */ 273 | 274 | #ifdef HAL_I2C_MODULE_ENABLED 275 | #include "stm32f1xx_hal_i2c.h" 276 | #endif /* HAL_I2C_MODULE_ENABLED */ 277 | 278 | #ifdef HAL_I2S_MODULE_ENABLED 279 | #include "stm32f1xx_hal_i2s.h" 280 | #endif /* HAL_I2S_MODULE_ENABLED */ 281 | 282 | #ifdef HAL_IWDG_MODULE_ENABLED 283 | #include "stm32f1xx_hal_iwdg.h" 284 | #endif /* HAL_IWDG_MODULE_ENABLED */ 285 | 286 | #ifdef HAL_PWR_MODULE_ENABLED 287 | #include "stm32f1xx_hal_pwr.h" 288 | #endif /* HAL_PWR_MODULE_ENABLED */ 289 | 290 | #ifdef HAL_RTC_MODULE_ENABLED 291 | #include "stm32f1xx_hal_rtc.h" 292 | #endif /* HAL_RTC_MODULE_ENABLED */ 293 | 294 | #ifdef HAL_PCCARD_MODULE_ENABLED 295 | #include "stm32f1xx_hal_pccard.h" 296 | #endif /* HAL_PCCARD_MODULE_ENABLED */ 297 | 298 | #ifdef HAL_SD_MODULE_ENABLED 299 | #include "stm32f1xx_hal_sd.h" 300 | #endif /* HAL_SD_MODULE_ENABLED */ 301 | 302 | #ifdef HAL_MMC_MODULE_ENABLED 303 | #include "stm32f1xx_hal_mmc.h" 304 | #endif /* HAL_MMC_MODULE_ENABLED */ 305 | 306 | #ifdef HAL_NAND_MODULE_ENABLED 307 | #include "stm32f1xx_hal_nand.h" 308 | #endif /* HAL_NAND_MODULE_ENABLED */ 309 | 310 | #ifdef HAL_SPI_MODULE_ENABLED 311 | #include "stm32f1xx_hal_spi.h" 312 | #endif /* HAL_SPI_MODULE_ENABLED */ 313 | 314 | #ifdef HAL_TIM_MODULE_ENABLED 315 | #include "stm32f1xx_hal_tim.h" 316 | #endif /* HAL_TIM_MODULE_ENABLED */ 317 | 318 | #ifdef HAL_UART_MODULE_ENABLED 319 | #include "stm32f1xx_hal_uart.h" 320 | #endif /* HAL_UART_MODULE_ENABLED */ 321 | 322 | #ifdef HAL_USART_MODULE_ENABLED 323 | #include "stm32f1xx_hal_usart.h" 324 | #endif /* HAL_USART_MODULE_ENABLED */ 325 | 326 | #ifdef HAL_IRDA_MODULE_ENABLED 327 | #include "stm32f1xx_hal_irda.h" 328 | #endif /* HAL_IRDA_MODULE_ENABLED */ 329 | 330 | #ifdef HAL_SMARTCARD_MODULE_ENABLED 331 | #include "stm32f1xx_hal_smartcard.h" 332 | #endif /* HAL_SMARTCARD_MODULE_ENABLED */ 333 | 334 | #ifdef HAL_WWDG_MODULE_ENABLED 335 | #include "stm32f1xx_hal_wwdg.h" 336 | #endif /* HAL_WWDG_MODULE_ENABLED */ 337 | 338 | #ifdef HAL_PCD_MODULE_ENABLED 339 | #include "stm32f1xx_hal_pcd.h" 340 | #endif /* HAL_PCD_MODULE_ENABLED */ 341 | 342 | #ifdef HAL_HCD_MODULE_ENABLED 343 | #include "stm32f1xx_hal_hcd.h" 344 | #endif /* HAL_HCD_MODULE_ENABLED */ 345 | 346 | 347 | /* Exported macro ------------------------------------------------------------*/ 348 | #ifdef USE_FULL_ASSERT 349 | /** 350 | * @brief The assert_param macro is used for function's parameters check. 351 | * @param expr: If expr is false, it calls assert_failed function 352 | * which reports the name of the source file and the source 353 | * line number of the call that failed. 354 | * If expr is true, it returns no value. 355 | * @retval None 356 | */ 357 | #define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__)) 358 | /* Exported functions ------------------------------------------------------- */ 359 | void assert_failed(uint8_t* file, uint32_t line); 360 | #else 361 | #define assert_param(expr) ((void)0U) 362 | #endif /* USE_FULL_ASSERT */ 363 | 364 | #ifdef __cplusplus 365 | } 366 | #endif 367 | 368 | #endif /* __STM32F1xx_HAL_CONF_H */ 369 | 370 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 371 | -------------------------------------------------------------------------------- /RobotDog_Remote/Inc/stm32f1xx_it.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32f1xx_it.h 5 | * @brief This file contains the headers of the interrupt handlers. 6 | ****************************************************************************** 7 | * 8 | * COPYRIGHT(c) 2019 STMicroelectronics 9 | * 10 | * Redistribution and use in source and binary forms, with or without modification, 11 | * are permitted provided that the following conditions are met: 12 | * 1. Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright notice, 15 | * this list of conditions and the following disclaimer in the documentation 16 | * and/or other materials provided with the distribution. 17 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | ****************************************************************************** 33 | */ 34 | /* USER CODE END Header */ 35 | 36 | /* Define to prevent recursive inclusion -------------------------------------*/ 37 | #ifndef __STM32F1xx_IT_H 38 | #define __STM32F1xx_IT_H 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | /* Private includes ----------------------------------------------------------*/ 45 | /* USER CODE BEGIN Includes */ 46 | 47 | /* USER CODE END Includes */ 48 | 49 | /* Exported types ------------------------------------------------------------*/ 50 | /* USER CODE BEGIN ET */ 51 | 52 | /* USER CODE END ET */ 53 | 54 | /* Exported constants --------------------------------------------------------*/ 55 | /* USER CODE BEGIN EC */ 56 | 57 | /* USER CODE END EC */ 58 | 59 | /* Exported macro ------------------------------------------------------------*/ 60 | /* USER CODE BEGIN EM */ 61 | 62 | /* USER CODE END EM */ 63 | 64 | /* Exported functions prototypes ---------------------------------------------*/ 65 | void NMI_Handler(void); 66 | void HardFault_Handler(void); 67 | void MemManage_Handler(void); 68 | void BusFault_Handler(void); 69 | void UsageFault_Handler(void); 70 | void SVC_Handler(void); 71 | void DebugMon_Handler(void); 72 | void PendSV_Handler(void); 73 | void SysTick_Handler(void); 74 | void DMA1_Channel1_IRQHandler(void); 75 | void EXTI15_10_IRQHandler(void); 76 | /* USER CODE BEGIN EFP */ 77 | 78 | /* USER CODE END EFP */ 79 | 80 | #ifdef __cplusplus 81 | } 82 | #endif 83 | 84 | #endif /* __STM32F1xx_IT_H */ 85 | 86 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 87 | -------------------------------------------------------------------------------- /RobotDog_Remote/RoboDog_Remote.ioc: -------------------------------------------------------------------------------- 1 | #MicroXplorer Configuration settings - do not modify 2 | ADC1.Channel-17\#ChannelRegularConversion=ADC_CHANNEL_1 3 | ADC1.Channel-18\#ChannelRegularConversion=ADC_CHANNEL_2 4 | ADC1.Channel-19\#ChannelRegularConversion=ADC_CHANNEL_3 5 | ADC1.Channel-20\#ChannelRegularConversion=ADC_CHANNEL_VREFINT 6 | ADC1.ContinuousConvMode=ENABLE 7 | ADC1.IPParameters=Rank-17\#ChannelRegularConversion,Channel-17\#ChannelRegularConversion,SamplingTime-17\#ChannelRegularConversion,NbrOfConversionFlag,ContinuousConvMode,Rank-18\#ChannelRegularConversion,Channel-18\#ChannelRegularConversion,SamplingTime-18\#ChannelRegularConversion,Rank-19\#ChannelRegularConversion,Channel-19\#ChannelRegularConversion,SamplingTime-19\#ChannelRegularConversion,Rank-20\#ChannelRegularConversion,Channel-20\#ChannelRegularConversion,SamplingTime-20\#ChannelRegularConversion,NbrOfConversion,master 8 | ADC1.NbrOfConversion=4 9 | ADC1.NbrOfConversionFlag=1 10 | ADC1.Rank-17\#ChannelRegularConversion=1 11 | ADC1.Rank-18\#ChannelRegularConversion=2 12 | ADC1.Rank-19\#ChannelRegularConversion=3 13 | ADC1.Rank-20\#ChannelRegularConversion=4 14 | ADC1.SamplingTime-17\#ChannelRegularConversion=ADC_SAMPLETIME_239CYCLES_5 15 | ADC1.SamplingTime-18\#ChannelRegularConversion=ADC_SAMPLETIME_239CYCLES_5 16 | ADC1.SamplingTime-19\#ChannelRegularConversion=ADC_SAMPLETIME_239CYCLES_5 17 | ADC1.SamplingTime-20\#ChannelRegularConversion=ADC_SAMPLETIME_239CYCLES_5 18 | ADC1.master=1 19 | Dma.ADC1.0.Direction=DMA_PERIPH_TO_MEMORY 20 | Dma.ADC1.0.Instance=DMA1_Channel1 21 | Dma.ADC1.0.MemDataAlignment=DMA_MDATAALIGN_HALFWORD 22 | Dma.ADC1.0.MemInc=DMA_MINC_ENABLE 23 | Dma.ADC1.0.Mode=DMA_CIRCULAR 24 | Dma.ADC1.0.PeriphDataAlignment=DMA_PDATAALIGN_HALFWORD 25 | Dma.ADC1.0.PeriphInc=DMA_PINC_DISABLE 26 | Dma.ADC1.0.Priority=DMA_PRIORITY_LOW 27 | Dma.ADC1.0.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority 28 | Dma.Request0=ADC1 29 | Dma.RequestsNb=1 30 | File.Version=6 31 | KeepUserPlacement=false 32 | Mcu.Family=STM32F1 33 | Mcu.IP0=ADC1 34 | Mcu.IP1=DMA 35 | Mcu.IP2=NVIC 36 | Mcu.IP3=RCC 37 | Mcu.IP4=SPI1 38 | Mcu.IP5=SYS 39 | Mcu.IPNb=6 40 | Mcu.Name=STM32F103C(8-B)Tx 41 | Mcu.Package=LQFP48 42 | Mcu.Pin0=PC13-TAMPER-RTC 43 | Mcu.Pin1=PD0-OSC_IN 44 | Mcu.Pin10=PB1 45 | Mcu.Pin11=PB10 46 | Mcu.Pin12=PB12 47 | Mcu.Pin13=PB13 48 | Mcu.Pin14=PB14 49 | Mcu.Pin15=PB15 50 | Mcu.Pin16=PA8 51 | Mcu.Pin17=PA9 52 | Mcu.Pin18=PA13 53 | Mcu.Pin19=PA14 54 | Mcu.Pin2=PD1-OSC_OUT 55 | Mcu.Pin20=VP_ADC1_Vref_Input 56 | Mcu.Pin21=VP_SYS_VS_Systick 57 | Mcu.Pin3=PA1 58 | Mcu.Pin4=PA2 59 | Mcu.Pin5=PA3 60 | Mcu.Pin6=PA5 61 | Mcu.Pin7=PA6 62 | Mcu.Pin8=PA7 63 | Mcu.Pin9=PB0 64 | Mcu.PinsNb=22 65 | Mcu.ThirdPartyNb=0 66 | Mcu.UserConstants= 67 | Mcu.UserName=STM32F103C8Tx 68 | MxCube.Version=5.0.1 69 | MxDb.Version=DB.5.0.1 70 | NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false 71 | NVIC.DMA1_Channel1_IRQn=true\:0\:0\:false\:false\:true\:false 72 | NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false 73 | NVIC.EXTI15_10_IRQn=true\:0\:0\:false\:false\:true\:true 74 | NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false 75 | NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false 76 | NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false 77 | NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false 78 | NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4 79 | NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false 80 | NVIC.SysTick_IRQn=true\:0\:0\:false\:false\:true\:false 81 | NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false 82 | PA1.Signal=ADCx_IN1 83 | PA13.Mode=Serial_Wire 84 | PA13.Signal=SYS_JTMS-SWDIO 85 | PA14.Mode=Serial_Wire 86 | PA14.Signal=SYS_JTCK-SWCLK 87 | PA2.Signal=ADCx_IN2 88 | PA3.Signal=ADCx_IN3 89 | PA5.Mode=Full_Duplex_Master 90 | PA5.Signal=SPI1_SCK 91 | PA6.Mode=Full_Duplex_Master 92 | PA6.Signal=SPI1_MISO 93 | PA7.Mode=Full_Duplex_Master 94 | PA7.Signal=SPI1_MOSI 95 | PA8.GPIOParameters=GPIO_PuPd 96 | PA8.GPIO_PuPd=GPIO_PULLDOWN 97 | PA8.Locked=true 98 | PA8.Signal=GPIO_Input 99 | PA9.GPIOParameters=GPIO_PuPd 100 | PA9.GPIO_PuPd=GPIO_PULLDOWN 101 | PA9.Locked=true 102 | PA9.Signal=GPIO_Input 103 | PB0.Locked=true 104 | PB0.Signal=GPIO_Output 105 | PB1.Locked=true 106 | PB1.Signal=GPIO_Output 107 | PB10.Locked=true 108 | PB10.Signal=GPXTI10 109 | PB12.GPIOParameters=GPIO_PuPd 110 | PB12.GPIO_PuPd=GPIO_PULLDOWN 111 | PB12.Locked=true 112 | PB12.Signal=GPIO_Input 113 | PB13.GPIOParameters=GPIO_PuPd 114 | PB13.GPIO_PuPd=GPIO_PULLDOWN 115 | PB13.Locked=true 116 | PB13.Signal=GPIO_Input 117 | PB14.GPIOParameters=GPIO_PuPd 118 | PB14.GPIO_PuPd=GPIO_PULLDOWN 119 | PB14.Locked=true 120 | PB14.Signal=GPIO_Input 121 | PB15.GPIOParameters=GPIO_PuPd 122 | PB15.GPIO_PuPd=GPIO_PULLDOWN 123 | PB15.Locked=true 124 | PB15.Signal=GPIO_Input 125 | PC13-TAMPER-RTC.Locked=true 126 | PC13-TAMPER-RTC.Signal=GPIO_Output 127 | PCC.Checker=false 128 | PCC.Line=STM32F103 129 | PCC.MCU=STM32F103C(8-B)Tx 130 | PCC.PartNumber=STM32F103C8Tx 131 | PCC.Seq0=0 132 | PCC.Series=STM32F1 133 | PCC.Temperature=25 134 | PCC.Vdd=3.3 135 | PD0-OSC_IN.Mode=HSE-External-Oscillator 136 | PD0-OSC_IN.Signal=RCC_OSC_IN 137 | PD1-OSC_OUT.Mode=HSE-External-Oscillator 138 | PD1-OSC_OUT.Signal=RCC_OSC_OUT 139 | PinOutPanel.RotationAngle=0 140 | ProjectManager.AskForMigrate=true 141 | ProjectManager.BackupPrevious=false 142 | ProjectManager.CompilerOptimize=6 143 | ProjectManager.ComputerToolchain=false 144 | ProjectManager.CoupleFile=true 145 | ProjectManager.CustomerFirmwarePackage= 146 | ProjectManager.DefaultFWLocation=true 147 | ProjectManager.DeletePrevious=true 148 | ProjectManager.DeviceId=STM32F103C8Tx 149 | ProjectManager.FirmwarePackage=STM32Cube FW_F1 V1.7.0 150 | ProjectManager.FreePins=false 151 | ProjectManager.HalAssertFull=false 152 | ProjectManager.HeapSize=0x200 153 | ProjectManager.KeepUserCode=true 154 | ProjectManager.LastFirmware=true 155 | ProjectManager.LibraryCopy=1 156 | ProjectManager.MainLocation=Core/Src 157 | ProjectManager.NoMain=false 158 | ProjectManager.PreviousToolchain= 159 | ProjectManager.ProjectBuild=false 160 | ProjectManager.ProjectFileName=RoboDog_Remote.ioc 161 | ProjectManager.ProjectName=RoboDog_Remote 162 | ProjectManager.StackSize=0x400 163 | ProjectManager.TargetToolchain=MDK-ARM V5 164 | ProjectManager.ToolChainLocation= 165 | ProjectManager.UnderRoot=false 166 | ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-MX_DMA_Init-DMA-false-HAL-true,3-SystemClock_Config-RCC-false-HAL-false,4-MX_SPI1_Init-SPI1-false-HAL-true,5-MX_ADC1_Init-ADC1-false-HAL-true 167 | RCC.ADCFreqValue=12000000 168 | RCC.ADCPresc=RCC_ADCPCLK2_DIV6 169 | RCC.AHBFreq_Value=72000000 170 | RCC.APB1CLKDivider=RCC_HCLK_DIV2 171 | RCC.APB1Freq_Value=36000000 172 | RCC.APB1TimFreq_Value=72000000 173 | RCC.APB2Freq_Value=72000000 174 | RCC.APB2TimFreq_Value=72000000 175 | RCC.FCLKCortexFreq_Value=72000000 176 | RCC.FamilyName=M 177 | RCC.HCLKFreq_Value=72000000 178 | RCC.IPParameters=ADCFreqValue,ADCPresc,AHBFreq_Value,APB1CLKDivider,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,FCLKCortexFreq_Value,FamilyName,HCLKFreq_Value,MCOFreq_Value,PLLCLKFreq_Value,PLLMCOFreq_Value,PLLMUL,PLLSourceVirtual,SYSCLKFreq_VALUE,SYSCLKSource,TimSysFreq_Value,USBFreq_Value,VCOOutput2Freq_Value 179 | RCC.MCOFreq_Value=72000000 180 | RCC.PLLCLKFreq_Value=72000000 181 | RCC.PLLMCOFreq_Value=36000000 182 | RCC.PLLMUL=RCC_PLL_MUL9 183 | RCC.PLLSourceVirtual=RCC_PLLSOURCE_HSE 184 | RCC.SYSCLKFreq_VALUE=72000000 185 | RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK 186 | RCC.TimSysFreq_Value=72000000 187 | RCC.USBFreq_Value=72000000 188 | RCC.VCOOutput2Freq_Value=8000000 189 | SH.ADCx_IN1.0=ADC1_IN1,IN1 190 | SH.ADCx_IN1.ConfNb=1 191 | SH.ADCx_IN2.0=ADC1_IN2,IN2 192 | SH.ADCx_IN2.ConfNb=1 193 | SH.ADCx_IN3.0=ADC1_IN3,IN3 194 | SH.ADCx_IN3.ConfNb=1 195 | SH.GPXTI10.0=GPIO_EXTI10 196 | SH.GPXTI10.ConfNb=1 197 | SPI1.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_8 198 | SPI1.CalculateBaudRate=9.0 MBits/s 199 | SPI1.Direction=SPI_DIRECTION_2LINES 200 | SPI1.IPParameters=VirtualType,Mode,Direction,BaudRatePrescaler,CalculateBaudRate 201 | SPI1.Mode=SPI_MODE_MASTER 202 | SPI1.VirtualType=VM_MASTER 203 | VP_ADC1_Vref_Input.Mode=IN-Vrefint 204 | VP_ADC1_Vref_Input.Signal=ADC1_Vref_Input 205 | VP_SYS_VS_Systick.Mode=SysTick 206 | VP_SYS_VS_Systick.Signal=SYS_VS_Systick 207 | board=custom 208 | -------------------------------------------------------------------------------- /RobotDog_Remote/Src/adc.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * File Name : ADC.c 4 | * Description : This file provides code for the configuration 5 | * of the ADC instances. 6 | ****************************************************************************** 7 | ** This notice applies to any and all portions of this file 8 | * that are not between comment pairs USER CODE BEGIN and 9 | * USER CODE END. Other portions of this file, whether 10 | * inserted by the user or by software development tools 11 | * are owned by their respective copyright owners. 12 | * 13 | * COPYRIGHT(c) 2019 STMicroelectronics 14 | * 15 | * Redistribution and use in source and binary forms, with or without modification, 16 | * are permitted provided that the following conditions are met: 17 | * 1. Redistributions of source code must retain the above copyright notice, 18 | * this list of conditions and the following disclaimer. 19 | * 2. Redistributions in binary form must reproduce the above copyright notice, 20 | * this list of conditions and the following disclaimer in the documentation 21 | * and/or other materials provided with the distribution. 22 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 23 | * may be used to endorse or promote products derived from this software 24 | * without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 29 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 32 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 33 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 34 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | * 37 | ****************************************************************************** 38 | */ 39 | 40 | /* Includes ------------------------------------------------------------------*/ 41 | #include "adc.h" 42 | 43 | /* USER CODE BEGIN 0 */ 44 | 45 | /* USER CODE END 0 */ 46 | 47 | ADC_HandleTypeDef hadc1; 48 | DMA_HandleTypeDef hdma_adc1; 49 | 50 | /* ADC1 init function */ 51 | void MX_ADC1_Init(void) 52 | { 53 | ADC_ChannelConfTypeDef sConfig = {0}; 54 | 55 | /**Common config 56 | */ 57 | hadc1.Instance = ADC1; 58 | hadc1.Init.ScanConvMode = ADC_SCAN_ENABLE; 59 | hadc1.Init.ContinuousConvMode = ENABLE; 60 | hadc1.Init.DiscontinuousConvMode = DISABLE; 61 | hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START; 62 | hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT; 63 | hadc1.Init.NbrOfConversion = 4; 64 | if (HAL_ADC_Init(&hadc1) != HAL_OK) 65 | { 66 | Error_Handler(); 67 | } 68 | /**Configure Regular Channel 69 | */ 70 | sConfig.Channel = ADC_CHANNEL_1; 71 | sConfig.Rank = ADC_REGULAR_RANK_1; 72 | sConfig.SamplingTime = ADC_SAMPLETIME_239CYCLES_5; 73 | if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) 74 | { 75 | Error_Handler(); 76 | } 77 | /**Configure Regular Channel 78 | */ 79 | sConfig.Channel = ADC_CHANNEL_2; 80 | sConfig.Rank = ADC_REGULAR_RANK_2; 81 | if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) 82 | { 83 | Error_Handler(); 84 | } 85 | /**Configure Regular Channel 86 | */ 87 | sConfig.Channel = ADC_CHANNEL_3; 88 | sConfig.Rank = ADC_REGULAR_RANK_3; 89 | if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) 90 | { 91 | Error_Handler(); 92 | } 93 | /**Configure Regular Channel 94 | */ 95 | sConfig.Channel = ADC_CHANNEL_VREFINT; 96 | sConfig.Rank = ADC_REGULAR_RANK_4; 97 | if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) 98 | { 99 | Error_Handler(); 100 | } 101 | 102 | } 103 | 104 | void HAL_ADC_MspInit(ADC_HandleTypeDef* adcHandle) 105 | { 106 | 107 | GPIO_InitTypeDef GPIO_InitStruct = {0}; 108 | if(adcHandle->Instance==ADC1) 109 | { 110 | /* USER CODE BEGIN ADC1_MspInit 0 */ 111 | 112 | /* USER CODE END ADC1_MspInit 0 */ 113 | /* ADC1 clock enable */ 114 | __HAL_RCC_ADC1_CLK_ENABLE(); 115 | 116 | __HAL_RCC_GPIOA_CLK_ENABLE(); 117 | /**ADC1 GPIO Configuration 118 | PA1 ------> ADC1_IN1 119 | PA2 ------> ADC1_IN2 120 | PA3 ------> ADC1_IN3 121 | */ 122 | GPIO_InitStruct.Pin = GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3; 123 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; 124 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 125 | 126 | /* ADC1 DMA Init */ 127 | /* ADC1 Init */ 128 | hdma_adc1.Instance = DMA1_Channel1; 129 | hdma_adc1.Init.Direction = DMA_PERIPH_TO_MEMORY; 130 | hdma_adc1.Init.PeriphInc = DMA_PINC_DISABLE; 131 | hdma_adc1.Init.MemInc = DMA_MINC_ENABLE; 132 | hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD; 133 | hdma_adc1.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD; 134 | hdma_adc1.Init.Mode = DMA_CIRCULAR; 135 | hdma_adc1.Init.Priority = DMA_PRIORITY_LOW; 136 | if (HAL_DMA_Init(&hdma_adc1) != HAL_OK) 137 | { 138 | Error_Handler(); 139 | } 140 | 141 | __HAL_LINKDMA(adcHandle,DMA_Handle,hdma_adc1); 142 | 143 | /* USER CODE BEGIN ADC1_MspInit 1 */ 144 | 145 | /* USER CODE END ADC1_MspInit 1 */ 146 | } 147 | } 148 | 149 | void HAL_ADC_MspDeInit(ADC_HandleTypeDef* adcHandle) 150 | { 151 | 152 | if(adcHandle->Instance==ADC1) 153 | { 154 | /* USER CODE BEGIN ADC1_MspDeInit 0 */ 155 | 156 | /* USER CODE END ADC1_MspDeInit 0 */ 157 | /* Peripheral clock disable */ 158 | __HAL_RCC_ADC1_CLK_DISABLE(); 159 | 160 | /**ADC1 GPIO Configuration 161 | PA1 ------> ADC1_IN1 162 | PA2 ------> ADC1_IN2 163 | PA3 ------> ADC1_IN3 164 | */ 165 | HAL_GPIO_DeInit(GPIOA, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3); 166 | 167 | /* ADC1 DMA DeInit */ 168 | HAL_DMA_DeInit(adcHandle->DMA_Handle); 169 | /* USER CODE BEGIN ADC1_MspDeInit 1 */ 170 | 171 | /* USER CODE END ADC1_MspDeInit 1 */ 172 | } 173 | } 174 | 175 | /* USER CODE BEGIN 1 */ 176 | 177 | /* USER CODE END 1 */ 178 | 179 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 180 | -------------------------------------------------------------------------------- /RobotDog_Remote/Src/dma.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * File Name : dma.c 4 | * Description : This file provides code for the configuration 5 | * of all the requested memory to memory DMA transfers. 6 | ****************************************************************************** 7 | ** This notice applies to any and all portions of this file 8 | * that are not between comment pairs USER CODE BEGIN and 9 | * USER CODE END. Other portions of this file, whether 10 | * inserted by the user or by software development tools 11 | * are owned by their respective copyright owners. 12 | * 13 | * COPYRIGHT(c) 2019 STMicroelectronics 14 | * 15 | * Redistribution and use in source and binary forms, with or without modification, 16 | * are permitted provided that the following conditions are met: 17 | * 1. Redistributions of source code must retain the above copyright notice, 18 | * this list of conditions and the following disclaimer. 19 | * 2. Redistributions in binary form must reproduce the above copyright notice, 20 | * this list of conditions and the following disclaimer in the documentation 21 | * and/or other materials provided with the distribution. 22 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 23 | * may be used to endorse or promote products derived from this software 24 | * without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 29 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 32 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 33 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 34 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | * 37 | ****************************************************************************** 38 | */ 39 | /* Includes ------------------------------------------------------------------*/ 40 | #include "dma.h" 41 | 42 | /* USER CODE BEGIN 0 */ 43 | 44 | /* USER CODE END 0 */ 45 | 46 | /*----------------------------------------------------------------------------*/ 47 | /* Configure DMA */ 48 | /*----------------------------------------------------------------------------*/ 49 | 50 | /* USER CODE BEGIN 1 */ 51 | 52 | /* USER CODE END 1 */ 53 | 54 | /** 55 | * Enable DMA controller clock 56 | */ 57 | void MX_DMA_Init(void) 58 | { 59 | /* DMA controller clock enable */ 60 | __HAL_RCC_DMA1_CLK_ENABLE(); 61 | 62 | /* DMA interrupt init */ 63 | /* DMA1_Channel1_IRQn interrupt configuration */ 64 | HAL_NVIC_SetPriority(DMA1_Channel1_IRQn, 0, 0); 65 | HAL_NVIC_EnableIRQ(DMA1_Channel1_IRQn); 66 | 67 | } 68 | 69 | /* USER CODE BEGIN 2 */ 70 | 71 | /* USER CODE END 2 */ 72 | 73 | /** 74 | * @} 75 | */ 76 | 77 | /** 78 | * @} 79 | */ 80 | 81 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 82 | -------------------------------------------------------------------------------- /RobotDog_Remote/Src/gpio.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * File Name : gpio.c 4 | * Description : This file provides code for the configuration 5 | * of all used GPIO pins. 6 | ****************************************************************************** 7 | ** This notice applies to any and all portions of this file 8 | * that are not between comment pairs USER CODE BEGIN and 9 | * USER CODE END. Other portions of this file, whether 10 | * inserted by the user or by software development tools 11 | * are owned by their respective copyright owners. 12 | * 13 | * COPYRIGHT(c) 2019 STMicroelectronics 14 | * 15 | * Redistribution and use in source and binary forms, with or without modification, 16 | * are permitted provided that the following conditions are met: 17 | * 1. Redistributions of source code must retain the above copyright notice, 18 | * this list of conditions and the following disclaimer. 19 | * 2. Redistributions in binary form must reproduce the above copyright notice, 20 | * this list of conditions and the following disclaimer in the documentation 21 | * and/or other materials provided with the distribution. 22 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 23 | * may be used to endorse or promote products derived from this software 24 | * without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 29 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 32 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 33 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 34 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | * 37 | ****************************************************************************** 38 | */ 39 | 40 | /* Includes ------------------------------------------------------------------*/ 41 | #include "gpio.h" 42 | /* USER CODE BEGIN 0 */ 43 | 44 | /* USER CODE END 0 */ 45 | 46 | /*----------------------------------------------------------------------------*/ 47 | /* Configure GPIO */ 48 | /*----------------------------------------------------------------------------*/ 49 | /* USER CODE BEGIN 1 */ 50 | 51 | /* USER CODE END 1 */ 52 | 53 | /** Configure pins as 54 | * Analog 55 | * Input 56 | * Output 57 | * EVENT_OUT 58 | * EXTI 59 | */ 60 | void MX_GPIO_Init(void) 61 | { 62 | 63 | GPIO_InitTypeDef GPIO_InitStruct = {0}; 64 | 65 | /* GPIO Ports Clock Enable */ 66 | __HAL_RCC_GPIOC_CLK_ENABLE(); 67 | __HAL_RCC_GPIOD_CLK_ENABLE(); 68 | __HAL_RCC_GPIOA_CLK_ENABLE(); 69 | __HAL_RCC_GPIOB_CLK_ENABLE(); 70 | 71 | /*Configure GPIO pin Output Level */ 72 | HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET); 73 | 74 | /*Configure GPIO pin Output Level */ 75 | HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0|GPIO_PIN_1, GPIO_PIN_RESET); 76 | 77 | /*Configure GPIO pin : PC13 */ 78 | GPIO_InitStruct.Pin = GPIO_PIN_13; 79 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 80 | GPIO_InitStruct.Pull = GPIO_NOPULL; 81 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 82 | HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); 83 | 84 | /*Configure GPIO pins : PB0 PB1 */ 85 | GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1; 86 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 87 | GPIO_InitStruct.Pull = GPIO_NOPULL; 88 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 89 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); 90 | 91 | /*Configure GPIO pin : PB10 */ 92 | GPIO_InitStruct.Pin = GPIO_PIN_10; 93 | GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; 94 | GPIO_InitStruct.Pull = GPIO_NOPULL; 95 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); 96 | 97 | /*Configure GPIO pins : PB12 PB13 PB14 PB15 */ 98 | GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15; 99 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT; 100 | GPIO_InitStruct.Pull = GPIO_PULLDOWN; 101 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); 102 | 103 | /*Configure GPIO pins : PA8 PA9 */ 104 | GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9; 105 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT; 106 | GPIO_InitStruct.Pull = GPIO_PULLDOWN; 107 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 108 | 109 | /* EXTI interrupt init*/ 110 | HAL_NVIC_SetPriority(EXTI15_10_IRQn, 0, 0); 111 | HAL_NVIC_EnableIRQ(EXTI15_10_IRQn); 112 | 113 | } 114 | 115 | /* USER CODE BEGIN 2 */ 116 | 117 | /* USER CODE END 2 */ 118 | 119 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 120 | -------------------------------------------------------------------------------- /RobotDog_Remote/Src/main.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : main.c 5 | * @brief : Main program body 6 | ****************************************************************************** 7 | ** This notice applies to any and all portions of this file 8 | * that are not between comment pairs USER CODE BEGIN and 9 | * USER CODE END. Other portions of this file, whether 10 | * inserted by the user or by software development tools 11 | * are owned by their respective copyright owners. 12 | * 13 | * COPYRIGHT(c) 2019 STMicroelectronics 14 | * 15 | * Redistribution and use in source and binary forms, with or without modification, 16 | * are permitted provided that the following conditions are met: 17 | * 1. Redistributions of source code must retain the above copyright notice, 18 | * this list of conditions and the following disclaimer. 19 | * 2. Redistributions in binary form must reproduce the above copyright notice, 20 | * this list of conditions and the following disclaimer in the documentation 21 | * and/or other materials provided with the distribution. 22 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 23 | * may be used to endorse or promote products derived from this software 24 | * without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 29 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 32 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 33 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 34 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | * 37 | ****************************************************************************** 38 | */ 39 | /* USER CODE END Header */ 40 | 41 | /* Includes ------------------------------------------------------------------*/ 42 | #include "main.h" 43 | #include "adc.h" 44 | #include "dma.h" 45 | #include "spi.h" 46 | #include "gpio.h" 47 | 48 | /* Private includes ----------------------------------------------------------*/ 49 | /* USER CODE BEGIN Includes */ 50 | #include "nrf24l01.h" 51 | /* USER CODE END Includes */ 52 | 53 | /* Private typedef -----------------------------------------------------------*/ 54 | /* USER CODE BEGIN PTD */ 55 | 56 | /* USER CODE END PTD */ 57 | 58 | /* Private define ------------------------------------------------------------*/ 59 | /* USER CODE BEGIN PD */ 60 | 61 | /* USER CODE END PD */ 62 | 63 | /* Private macro -------------------------------------------------------------*/ 64 | /* USER CODE BEGIN PM */ 65 | 66 | /* USER CODE END PM */ 67 | 68 | /* Private variables ---------------------------------------------------------*/ 69 | 70 | /* USER CODE BEGIN PV */ 71 | uint16_t adc_data[4]; 72 | float voltage_ref; 73 | struct 74 | { 75 | int left_x; 76 | int right_x; 77 | int right_y; 78 | int key_1; 79 | int key_2; 80 | int key_3; 81 | int key_4; 82 | int key_5; 83 | int key_6; 84 | } remote; 85 | int transmit_status = 0; 86 | uint8_t tmp_buf[9] = {0}; 87 | /* USER CODE END PV */ 88 | 89 | /* Private function prototypes -----------------------------------------------*/ 90 | void SystemClock_Config(void); 91 | /* USER CODE BEGIN PFP */ 92 | 93 | /* USER CODE END PFP */ 94 | 95 | /* Private user code ---------------------------------------------------------*/ 96 | /* USER CODE BEGIN 0 */ 97 | 98 | /* USER CODE END 0 */ 99 | 100 | /** 101 | * @brief The application entry point. 102 | * @retval int 103 | */ 104 | int main(void) 105 | { 106 | /* USER CODE BEGIN 1 */ 107 | 108 | /* USER CODE END 1 */ 109 | 110 | /* MCU Configuration--------------------------------------------------------*/ 111 | 112 | /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ 113 | HAL_Init(); 114 | 115 | /* USER CODE BEGIN Init */ 116 | 117 | /* USER CODE END Init */ 118 | 119 | /* Configure the system clock */ 120 | SystemClock_Config(); 121 | 122 | /* USER CODE BEGIN SysInit */ 123 | 124 | /* USER CODE END SysInit */ 125 | 126 | /* Initialize all configured peripherals */ 127 | MX_GPIO_Init(); 128 | MX_DMA_Init(); 129 | MX_SPI1_Init(); 130 | MX_ADC1_Init(); 131 | /* USER CODE BEGIN 2 */ 132 | HAL_ADC_Start_DMA(&hadc1, (uint32_t *)adc_data, 4); 133 | while(NRF24L01_Check()){}; 134 | NRF24L01_TX_Mode(); 135 | /* USER CODE END 2 */ 136 | 137 | /* Infinite loop */ 138 | /* USER CODE BEGIN WHILE */ 139 | while (1) 140 | { 141 | /* USER CODE END WHILE */ 142 | 143 | /* USER CODE BEGIN 3 */ 144 | static int count = 0; 145 | count++; 146 | if(count == 10) 147 | { 148 | HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13); 149 | count = 0; 150 | } 151 | 152 | // 更新遥控器按键数据 153 | remote.key_1 = HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_13); 154 | remote.key_2 = HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_14); 155 | remote.key_3 = HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_12); 156 | remote.key_4 = HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_15); 157 | remote.key_5 = HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_8); 158 | remote.key_6 = HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_9); 159 | 160 | tmp_buf[0] = remote.left_x; 161 | tmp_buf[1] = remote.right_x; 162 | tmp_buf[2] = remote.right_y; 163 | tmp_buf[3] = remote.key_1; 164 | tmp_buf[4] = remote.key_2; 165 | tmp_buf[5] = remote.key_3; 166 | tmp_buf[6] = remote.key_4; 167 | tmp_buf[7] = remote.key_5; 168 | tmp_buf[8] = remote.key_6; 169 | 170 | // 发送遥控器指令 171 | transmit_status = NRF24L01_TxPacket(tmp_buf); 172 | 173 | HAL_Delay(1); 174 | } 175 | /* USER CODE END 3 */ 176 | } 177 | 178 | /** 179 | * @brief System Clock Configuration 180 | * @retval None 181 | */ 182 | void SystemClock_Config(void) 183 | { 184 | RCC_OscInitTypeDef RCC_OscInitStruct = {0}; 185 | RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; 186 | RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; 187 | 188 | /**Initializes the CPU, AHB and APB busses clocks 189 | */ 190 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; 191 | RCC_OscInitStruct.HSEState = RCC_HSE_ON; 192 | RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1; 193 | RCC_OscInitStruct.HSIState = RCC_HSI_ON; 194 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; 195 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; 196 | RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9; 197 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) 198 | { 199 | Error_Handler(); 200 | } 201 | /**Initializes the CPU, AHB and APB busses clocks 202 | */ 203 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK 204 | |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; 205 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; 206 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; 207 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; 208 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; 209 | 210 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) 211 | { 212 | Error_Handler(); 213 | } 214 | PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC; 215 | PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV6; 216 | if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) 217 | { 218 | Error_Handler(); 219 | } 220 | } 221 | 222 | /* USER CODE BEGIN 4 */ 223 | // 更新遥控器摇杆数据 224 | void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef * hadc) 225 | { 226 | float left_x,right_x,right_y,voltage_ref; 227 | left_x = (float)adc_data[0]/4096*3.3; 228 | right_x = (float)adc_data[1]/4096*3.3; 229 | right_y = (float)adc_data[2]/4096*3.3; 230 | voltage_ref = (float)adc_data[3]/4096*3.3; 231 | 232 | left_x *= 1.2/voltage_ref; 233 | right_x *= 1.2/voltage_ref; 234 | right_y *= 1.2/voltage_ref; 235 | 236 | remote.left_x = left_x*10; 237 | remote.right_x = right_x*10; 238 | remote.right_y = right_y*10; 239 | } 240 | /* USER CODE END 4 */ 241 | 242 | /** 243 | * @brief This function is executed in case of error occurrence. 244 | * @retval None 245 | */ 246 | void Error_Handler(void) 247 | { 248 | /* USER CODE BEGIN Error_Handler_Debug */ 249 | /* User can add his own implementation to report the HAL error return state */ 250 | 251 | /* USER CODE END Error_Handler_Debug */ 252 | } 253 | 254 | #ifdef USE_FULL_ASSERT 255 | /** 256 | * @brief Reports the name of the source file and the source line number 257 | * where the assert_param error has occurred. 258 | * @param file: pointer to the source file name 259 | * @param line: assert_param error line source number 260 | * @retval None 261 | */ 262 | void assert_failed(uint8_t *file, uint32_t line) 263 | { 264 | /* USER CODE BEGIN 6 */ 265 | /* User can add his own implementation to report the file name and line number, 266 | tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ 267 | /* USER CODE END 6 */ 268 | } 269 | #endif /* USE_FULL_ASSERT */ 270 | 271 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 272 | -------------------------------------------------------------------------------- /RobotDog_Remote/Src/nrf24l01.c: -------------------------------------------------------------------------------- 1 | #include "nrf24l01.h" 2 | 3 | const uint8_t TX_ADDRESS[TX_ADR_WIDTH]={0xb0,0x43,0x10,0x10,0x01}; 4 | const uint8_t RX_ADDRESS[RX_ADR_WIDTH]={0xb0,0x43,0x10,0x10,0x01}; 5 | 6 | uint8_t SPIx_ReadWriteByte(SPI_HandleTypeDef* hspi,uint8_t byte) 7 | { 8 | uint8_t d_read,d_send=byte; 9 | if(HAL_SPI_TransmitReceive(hspi,&d_send,&d_read,1,0xFF)!=HAL_OK) 10 | { 11 | d_read=0xFF; 12 | } 13 | return d_read; 14 | } 15 | 16 | uint8_t NRF24L01_Write_Buf(uint8_t reg, uint8_t *pBuf, uint8_t len) 17 | { 18 | uint8_t status,uint8_t_ctr; 19 | HAL_GPIO_WritePin(GPIO_CSN, GPIO_CSN_PIN, GPIO_PIN_RESET); 20 | status=SPIx_ReadWriteByte(&hspi_NRF24L01,reg); 21 | for(uint8_t_ctr=0; uint8_t_ctrInstance==SPI1) 77 | { 78 | /* USER CODE BEGIN SPI1_MspInit 0 */ 79 | 80 | /* USER CODE END SPI1_MspInit 0 */ 81 | /* SPI1 clock enable */ 82 | __HAL_RCC_SPI1_CLK_ENABLE(); 83 | 84 | __HAL_RCC_GPIOA_CLK_ENABLE(); 85 | /**SPI1 GPIO Configuration 86 | PA5 ------> SPI1_SCK 87 | PA6 ------> SPI1_MISO 88 | PA7 ------> SPI1_MOSI 89 | */ 90 | GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_7; 91 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 92 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; 93 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 94 | 95 | GPIO_InitStruct.Pin = GPIO_PIN_6; 96 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT; 97 | GPIO_InitStruct.Pull = GPIO_NOPULL; 98 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 99 | 100 | /* USER CODE BEGIN SPI1_MspInit 1 */ 101 | 102 | /* USER CODE END SPI1_MspInit 1 */ 103 | } 104 | } 105 | 106 | void HAL_SPI_MspDeInit(SPI_HandleTypeDef* spiHandle) 107 | { 108 | 109 | if(spiHandle->Instance==SPI1) 110 | { 111 | /* USER CODE BEGIN SPI1_MspDeInit 0 */ 112 | 113 | /* USER CODE END SPI1_MspDeInit 0 */ 114 | /* Peripheral clock disable */ 115 | __HAL_RCC_SPI1_CLK_DISABLE(); 116 | 117 | /**SPI1 GPIO Configuration 118 | PA5 ------> SPI1_SCK 119 | PA6 ------> SPI1_MISO 120 | PA7 ------> SPI1_MOSI 121 | */ 122 | HAL_GPIO_DeInit(GPIOA, GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7); 123 | 124 | /* USER CODE BEGIN SPI1_MspDeInit 1 */ 125 | 126 | /* USER CODE END SPI1_MspDeInit 1 */ 127 | } 128 | } 129 | 130 | /* USER CODE BEGIN 1 */ 131 | 132 | /* USER CODE END 1 */ 133 | 134 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 135 | -------------------------------------------------------------------------------- /RobotDog_Remote/Src/stm32f1xx_hal_msp.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * File Name : stm32f1xx_hal_msp.c 5 | * Description : This file provides code for the MSP Initialization 6 | * and de-Initialization codes. 7 | ****************************************************************************** 8 | ** This notice applies to any and all portions of this file 9 | * that are not between comment pairs USER CODE BEGIN and 10 | * USER CODE END. Other portions of this file, whether 11 | * inserted by the user or by software development tools 12 | * are owned by their respective copyright owners. 13 | * 14 | * COPYRIGHT(c) 2019 STMicroelectronics 15 | * 16 | * Redistribution and use in source and binary forms, with or without modification, 17 | * are permitted provided that the following conditions are met: 18 | * 1. Redistributions of source code must retain the above copyright notice, 19 | * this list of conditions and the following disclaimer. 20 | * 2. Redistributions in binary form must reproduce the above copyright notice, 21 | * this list of conditions and the following disclaimer in the documentation 22 | * and/or other materials provided with the distribution. 23 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 24 | * may be used to endorse or promote products derived from this software 25 | * without specific prior written permission. 26 | * 27 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 28 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 29 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 30 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 31 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 33 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 34 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 35 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 36 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 37 | * 38 | ****************************************************************************** 39 | */ 40 | /* USER CODE END Header */ 41 | 42 | /* Includes ------------------------------------------------------------------*/ 43 | #include "main.h" 44 | /* USER CODE BEGIN Includes */ 45 | 46 | /* USER CODE END Includes */ 47 | 48 | /* Private typedef -----------------------------------------------------------*/ 49 | /* USER CODE BEGIN TD */ 50 | 51 | /* USER CODE END TD */ 52 | 53 | /* Private define ------------------------------------------------------------*/ 54 | /* USER CODE BEGIN Define */ 55 | 56 | /* USER CODE END Define */ 57 | 58 | /* Private macro -------------------------------------------------------------*/ 59 | /* USER CODE BEGIN Macro */ 60 | 61 | /* USER CODE END Macro */ 62 | 63 | /* Private variables ---------------------------------------------------------*/ 64 | /* USER CODE BEGIN PV */ 65 | 66 | /* USER CODE END PV */ 67 | 68 | /* Private function prototypes -----------------------------------------------*/ 69 | /* USER CODE BEGIN PFP */ 70 | 71 | /* USER CODE END PFP */ 72 | 73 | /* External functions --------------------------------------------------------*/ 74 | /* USER CODE BEGIN ExternalFunctions */ 75 | 76 | /* USER CODE END ExternalFunctions */ 77 | 78 | /* USER CODE BEGIN 0 */ 79 | 80 | /* USER CODE END 0 */ 81 | /** 82 | * Initializes the Global MSP. 83 | */ 84 | void HAL_MspInit(void) 85 | { 86 | /* USER CODE BEGIN MspInit 0 */ 87 | 88 | /* USER CODE END MspInit 0 */ 89 | 90 | __HAL_RCC_AFIO_CLK_ENABLE(); 91 | __HAL_RCC_PWR_CLK_ENABLE(); 92 | 93 | /* System interrupt init*/ 94 | 95 | /**NOJTAG: JTAG-DP Disabled and SW-DP Enabled 96 | */ 97 | __HAL_AFIO_REMAP_SWJ_NOJTAG(); 98 | 99 | /* USER CODE BEGIN MspInit 1 */ 100 | 101 | /* USER CODE END MspInit 1 */ 102 | } 103 | 104 | /* USER CODE BEGIN 1 */ 105 | 106 | /* USER CODE END 1 */ 107 | 108 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 109 | -------------------------------------------------------------------------------- /RobotDog_Remote/Src/stm32f1xx_it.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32f1xx_it.c 5 | * @brief Interrupt Service Routines. 6 | ****************************************************************************** 7 | * 8 | * COPYRIGHT(c) 2019 STMicroelectronics 9 | * 10 | * Redistribution and use in source and binary forms, with or without modification, 11 | * are permitted provided that the following conditions are met: 12 | * 1. Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright notice, 15 | * this list of conditions and the following disclaimer in the documentation 16 | * and/or other materials provided with the distribution. 17 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | ****************************************************************************** 33 | */ 34 | /* USER CODE END Header */ 35 | 36 | /* Includes ------------------------------------------------------------------*/ 37 | #include "main.h" 38 | #include "stm32f1xx_it.h" 39 | /* Private includes ----------------------------------------------------------*/ 40 | /* USER CODE BEGIN Includes */ 41 | /* USER CODE END Includes */ 42 | 43 | /* Private typedef -----------------------------------------------------------*/ 44 | /* USER CODE BEGIN TD */ 45 | 46 | /* USER CODE END TD */ 47 | 48 | /* Private define ------------------------------------------------------------*/ 49 | /* USER CODE BEGIN PD */ 50 | 51 | /* USER CODE END PD */ 52 | 53 | /* Private macro -------------------------------------------------------------*/ 54 | /* USER CODE BEGIN PM */ 55 | 56 | /* USER CODE END PM */ 57 | 58 | /* Private variables ---------------------------------------------------------*/ 59 | /* USER CODE BEGIN PV */ 60 | 61 | /* USER CODE END PV */ 62 | 63 | /* Private function prototypes -----------------------------------------------*/ 64 | /* USER CODE BEGIN PFP */ 65 | 66 | /* USER CODE END PFP */ 67 | 68 | /* Private user code ---------------------------------------------------------*/ 69 | /* USER CODE BEGIN 0 */ 70 | 71 | /* USER CODE END 0 */ 72 | 73 | /* External variables --------------------------------------------------------*/ 74 | extern DMA_HandleTypeDef hdma_adc1; 75 | /* USER CODE BEGIN EV */ 76 | 77 | /* USER CODE END EV */ 78 | 79 | /******************************************************************************/ 80 | /* Cortex-M3 Processor Interruption and Exception Handlers */ 81 | /******************************************************************************/ 82 | /** 83 | * @brief This function handles Non maskable interrupt. 84 | */ 85 | void NMI_Handler(void) 86 | { 87 | /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ 88 | 89 | /* USER CODE END NonMaskableInt_IRQn 0 */ 90 | /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ 91 | 92 | /* USER CODE END NonMaskableInt_IRQn 1 */ 93 | } 94 | 95 | /** 96 | * @brief This function handles Hard fault interrupt. 97 | */ 98 | void HardFault_Handler(void) 99 | { 100 | /* USER CODE BEGIN HardFault_IRQn 0 */ 101 | 102 | /* USER CODE END HardFault_IRQn 0 */ 103 | while (1) 104 | { 105 | /* USER CODE BEGIN W1_HardFault_IRQn 0 */ 106 | /* USER CODE END W1_HardFault_IRQn 0 */ 107 | } 108 | } 109 | 110 | /** 111 | * @brief This function handles Memory management fault. 112 | */ 113 | void MemManage_Handler(void) 114 | { 115 | /* USER CODE BEGIN MemoryManagement_IRQn 0 */ 116 | 117 | /* USER CODE END MemoryManagement_IRQn 0 */ 118 | while (1) 119 | { 120 | /* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */ 121 | /* USER CODE END W1_MemoryManagement_IRQn 0 */ 122 | } 123 | } 124 | 125 | /** 126 | * @brief This function handles Prefetch fault, memory access fault. 127 | */ 128 | void BusFault_Handler(void) 129 | { 130 | /* USER CODE BEGIN BusFault_IRQn 0 */ 131 | 132 | /* USER CODE END BusFault_IRQn 0 */ 133 | while (1) 134 | { 135 | /* USER CODE BEGIN W1_BusFault_IRQn 0 */ 136 | /* USER CODE END W1_BusFault_IRQn 0 */ 137 | } 138 | } 139 | 140 | /** 141 | * @brief This function handles Undefined instruction or illegal state. 142 | */ 143 | void UsageFault_Handler(void) 144 | { 145 | /* USER CODE BEGIN UsageFault_IRQn 0 */ 146 | 147 | /* USER CODE END UsageFault_IRQn 0 */ 148 | while (1) 149 | { 150 | /* USER CODE BEGIN W1_UsageFault_IRQn 0 */ 151 | /* USER CODE END W1_UsageFault_IRQn 0 */ 152 | } 153 | } 154 | 155 | /** 156 | * @brief This function handles System service call via SWI instruction. 157 | */ 158 | void SVC_Handler(void) 159 | { 160 | /* USER CODE BEGIN SVCall_IRQn 0 */ 161 | 162 | /* USER CODE END SVCall_IRQn 0 */ 163 | /* USER CODE BEGIN SVCall_IRQn 1 */ 164 | 165 | /* USER CODE END SVCall_IRQn 1 */ 166 | } 167 | 168 | /** 169 | * @brief This function handles Debug monitor. 170 | */ 171 | void DebugMon_Handler(void) 172 | { 173 | /* USER CODE BEGIN DebugMonitor_IRQn 0 */ 174 | 175 | /* USER CODE END DebugMonitor_IRQn 0 */ 176 | /* USER CODE BEGIN DebugMonitor_IRQn 1 */ 177 | 178 | /* USER CODE END DebugMonitor_IRQn 1 */ 179 | } 180 | 181 | /** 182 | * @brief This function handles Pendable request for system service. 183 | */ 184 | void PendSV_Handler(void) 185 | { 186 | /* USER CODE BEGIN PendSV_IRQn 0 */ 187 | 188 | /* USER CODE END PendSV_IRQn 0 */ 189 | /* USER CODE BEGIN PendSV_IRQn 1 */ 190 | 191 | /* USER CODE END PendSV_IRQn 1 */ 192 | } 193 | 194 | /** 195 | * @brief This function handles System tick timer. 196 | */ 197 | void SysTick_Handler(void) 198 | { 199 | /* USER CODE BEGIN SysTick_IRQn 0 */ 200 | 201 | /* USER CODE END SysTick_IRQn 0 */ 202 | HAL_IncTick(); 203 | /* USER CODE BEGIN SysTick_IRQn 1 */ 204 | 205 | /* USER CODE END SysTick_IRQn 1 */ 206 | } 207 | 208 | /******************************************************************************/ 209 | /* STM32F1xx Peripheral Interrupt Handlers */ 210 | /* Add here the Interrupt Handlers for the used peripherals. */ 211 | /* For the available peripheral interrupt handler names, */ 212 | /* please refer to the startup file (startup_stm32f1xx.s). */ 213 | /******************************************************************************/ 214 | 215 | /** 216 | * @brief This function handles DMA1 channel1 global interrupt. 217 | */ 218 | void DMA1_Channel1_IRQHandler(void) 219 | { 220 | /* USER CODE BEGIN DMA1_Channel1_IRQn 0 */ 221 | 222 | /* USER CODE END DMA1_Channel1_IRQn 0 */ 223 | HAL_DMA_IRQHandler(&hdma_adc1); 224 | /* USER CODE BEGIN DMA1_Channel1_IRQn 1 */ 225 | 226 | /* USER CODE END DMA1_Channel1_IRQn 1 */ 227 | } 228 | 229 | /** 230 | * @brief This function handles EXTI line[15:10] interrupts. 231 | */ 232 | void EXTI15_10_IRQHandler(void) 233 | { 234 | /* USER CODE BEGIN EXTI15_10_IRQn 0 */ 235 | 236 | /* USER CODE END EXTI15_10_IRQn 0 */ 237 | HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_10); 238 | /* USER CODE BEGIN EXTI15_10_IRQn 1 */ 239 | 240 | /* USER CODE END EXTI15_10_IRQn 1 */ 241 | } 242 | 243 | /* USER CODE BEGIN 1 */ 244 | 245 | /* USER CODE END 1 */ 246 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 247 | -------------------------------------------------------------------------------- /img/RobotDog.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/imuncle/RobotDog/c31cd5e1445d7ef4a6af2f20f1f1c17a17b86b14/img/RobotDog.jpg -------------------------------------------------------------------------------- /img/上下云台稳.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/imuncle/RobotDog/c31cd5e1445d7ef4a6af2f20f1f1c17a17b86b14/img/上下云台稳.gif -------------------------------------------------------------------------------- /img/全向移动.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/imuncle/RobotDog/c31cd5e1445d7ef4a6af2f20f1f1c17a17b86b14/img/全向移动.gif -------------------------------------------------------------------------------- /img/左右云台稳.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/imuncle/RobotDog/c31cd5e1445d7ef4a6af2f20f1f1c17a17b86b14/img/左右云台稳.gif -------------------------------------------------------------------------------- /img/狗头乱动.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/imuncle/RobotDog/c31cd5e1445d7ef4a6af2f20f1f1c17a17b86b14/img/狗头乱动.gif --------------------------------------------------------------------------------