close-circle
Close

Help getting STM32 to work

FloppidyDingo wrote 11/03/2017 at 21:46 • 2 min read • Like

Hello everyone! I have a question regarding my game console (https://hackaday.io/project/9907-kyle-an-8-bit-portable-game-console). I'm trying to program the STM32 chip in it (specifically the STM32F401), but I'm getting trouble having the bootloader to do anything. I tried USB mode but my computer gives a Device Descriptor Request Failed error, but I think that's because I accidentally left out termination resistors. So I tried SPI mode using my Arduino, but all I can get it to do is send a bunch of 0xFF and then 0x00. It never sends the ACK byte it should be sending. I made sure the wiring was correct and there is no other method I can use to program this chip. The closest I got was getting the chip to send 0xFF on SPI when I reset it. I know it's going into the bootloader because when I have the program jumper removed, my PC doesnt see it all on the USB port. But when I put the jumper in and reset it, the PC gives the error. So the STM32 is trying to communicate with my PC but something is going wrong. I'll put up my schematics and arduino code below.

(Schematic) https://cdn.hackaday.io/files/9907423861088/board.pdf

#include <SPI.h>

const byte CS_Pin = 53;
const byte Get_Version = 0x01;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(CS_Pin, OUTPUT);
  digitalWrite(CS_Pin, LOW);
  SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE0));
}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.println(SPIWrite(0x5A));
  Serial.println(SPIWrite(0x01));
  Serial.println(SPIWrite(0xFE));
  while(true){
    Serial.println(SPIWrite(0x5A));
    Serial.println(SPIWrite(0x01));
    Serial.println(SPIWrite(0xFE));
  }
}

byte SPIRead(){
  byte res = SPI.transfer(0x00);
  return res;
}

byte SPIWrite(byte dat){
  byte res = SPI.transfer(dat);
  return res;
}
Like

Discussions

rbruno96 wrote 11/08/2017 at 18:35 point

Oh, I hope you find the problem.

How does the MCU know whether you send the program via USB or SPI? I know that in the STM32f103t8 experimental board (the cheap one, "blue pill") you have two jumpers to let the bootloader where it sholud expect data. Some people had problems when programming because they didn't move the correct or neither of them.

With the question I wanted to know that the boot0 pin does, I think it has to do with the bootloader in some way. Sorry about asking but I am not used to them, I bought two of these experimental boards I mentioned before to learn but I couldn't get to start yet.

  Are you sure? yes | no

FloppidyDingo wrote an hour ago point

When i read the datasheets it said the chip looks for a clock signal on the SPI line to go into SPI mode, and for USB it checks if anything is connected. I haven't read anything about setting pin to the right value. But I'm not too sure so I'm just going to use my SWD debugger to make my life easier

  Are you sure? yes | no

rbruno96 wrote 11/07/2017 at 21:44 point

Are you sure what kind of bootloader your micro has loaded? Maybe it is willing to get the code via UART or even I2C and you're sending it via USB and SPI. Does your programmer automatically reset the target or you have to push the button? 

By the wat, what's that boot0 jumper to?

  Are you sure? yes | no

FloppidyDingo wrote 11/07/2017 at 22:00 point

I'm using the bootloader that's flashed at the factory. I checked the datasheet and for my particular chip SPI and USB are supported. I'm getting the feeling my arduino isn't responding quickly enough so i bought an SWD debugger that i can use.

The programmer does not reset the micro automatically so i have to press the reset button every time, maybe that's why i can't get any communication going. Either way, I'll see how well the SWD debugger works and go from there

Also, the boot0 jumper connects boot0 to VCC, otherwise the pin is pulled low.

  Are you sure? yes | no