cancel
Showing results for 
Search instead for 
Did you mean: 

debugging a hoverboard motor controller

iamrobot
Associate II

i have a hoverboard motor controller in which there is STM32F103RCT6.
i have hacked the firmware but it was not working due to some reason; some MOSFET got burned.
i tried to check communication with Arduino.

 

 
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.c
* @brief : Main program body
******************************************************************************
*/
/* USER CODE END Header */

#include "main.h"

/* USER CODE BEGIN Includes */
#include <string.h>
/* USER CODE END Includes */

/* Private variables ---------------------------------------------------------*/
UART_HandleTypeDef huart3;

/* USER CODE BEGIN PV */
char msg[] = "STM32 UART TEST\r\n";
/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_USART3_UART_Init(void);

int main(void)
{
HAL_Init();

SystemClock_Config();

MX_GPIO_Init();
MX_USART3_UART_Init();

/* USER CODE BEGIN 2 */
HAL_UART_Transmit(&huart3, (uint8_t*)msg, strlen(msg), 100);
/* USER CODE END 2 */

while (1)
{
/* USER CODE BEGIN 3 */
HAL_UART_Transmit(&huart3, (uint8_t*)msg, strlen(msg), 100);
HAL_Delay(500);
/* USER CODE END 3 */
}
}

/* Clock config (unchanged CubeMX generated) */
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;

HAL_RCC_OscConfig(&RCC_OscInitStruct);

RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;

RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0);
}

/* USART3 Init (PB10 TX, PB11 RX) */
static void MX_USART3_UART_Init(void)
{
huart3.Instance = USART3;
huart3.Init.BaudRate = 115200;
huart3.Init.WordLength = UART_WORDLENGTH_8B;
huart3.Init.StopBits = UART_STOPBITS_1;
huart3.Init.Parity = UART_PARITY_NONE;
huart3.Init.Mode = UART_MODE_TX_RX;
huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart3.Init.OverSampling = UART_OVERSAMPLING_16;

HAL_UART_Init(&huart3);
}

/* GPIO Init */
static void MX_GPIO_Init(void)
{
__HAL_RCC_GPIOB_CLK_ENABLE();
}

/* Error handler */
void Error_Handler(void)
{
__disable_irq();
while (1)
{
}
}

when I flash it, my STM is not being detected by ST-Link. I am trying to check whether the issue is with the STM or the firmware. I also flashed it into another board, but the same issue happened, so I guess the problem is in the firmware.

the power is good; I checked between all VDD and VSS and it is good (3.27V).
there is BOOT0, BOOT1, and NRST.
BOOT0 and BOOT1 are low and NRST is high.
when I short BOOT0 with VDD, the ST-Link turns off.

I am completely lost.

the screen shot is after and before firmware 

15 REPLIES 15

> I am actually a programming and AI student, ...

So, more of a beginner when it comes to microcontroller and actual hardware. Nothing wrong with that.

> As far as I know, if I need to connect to the bootloader through UART or debugging pins, I need to make BOOT0 high. But after spending a lot of time on it, I found that BOOT0 is shorted to ground through a resistor. 

I recommend to download the datasheet and reference manual for the F103, and check those.
Here the respective RefMan section for another MCU I use :

Ozone_0-1779863476255.png

A commercial product will most probably tie the BOOTx pins to the state that ensures running from Flash, as they either come with a fixed firmware, or a second-stage bootloader.
Evaluation and prototype boards (like ST's Disco and Nucleo boards) often have jumpers or 0-Ohm resistors.

You can surely try to modify the board, to get into System Boot mode.
But as said, it is not guaranteed - a blown power component often comes with side effects, so the MCU might be damaged.


@iamrobot wrote:

There is no official documentation. 


You really should discuss this with your teacher:  whether it is worth spending your time on this unsupported, undocumented, possibly damaged unit ...

 


@iamrobot wrote:

I find STM quite complex.


Suggests your time may well be better spent in bettering your STM32 understanding than chasing this thing?

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

On a related note - I think the partial schematics is probably not correct, it doesn't make much sense from a design point of view.

Probably the BOOT0 pin is connected to the point between R103 and R224, and R103 is a very low value (perhaps 0 Ohm).
If that is correct, you could replace R103 with a jumper.


@Ozone wrote:

I think the partial schematics is probably not correct, it doesn't make much sense from a design point of view.


Indeed.

 


@Ozone wrote:

Probably the BOOT0 pin is connected to the point between R103 and R224...


Or R103 and R224 are entirely unrelated to BOOT0 - it's pure coincidence that they happen to be grounded at a point somewhere physically near to BOOT0 ?

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

To be honest, the whole board looks like from a low-cost, mass product, without provisions for update and repair. Which doesn't necessarily mean it's not worth investing some time, especially if you are out to learn.

But knowing the F103 is not so new, I suspect the manufacturer had moved on to newer product versions with other (cheaper) MCU years ago.


@Ozone wrote:

Which doesn't necessarily mean it's not worth investing some time, especially if you are out to learn.


Maybe.

But I'd say the time would be better spent with something well-documented and properly supported.

Reverse engineering requires a pretty good understanding of what you're looking at ...

 

@iamrobot again, you really need to discuss this with your tutor(s) - they should be able to advise whether this is something worth pursuing, or just a waste of your time.

They will know the context of your course, etc - we have no idea about that!

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.