Skip to main content
Explorer
May 22, 2024
Solved

Program won't run after upload

  • May 22, 2024
  • 10 replies
  • 6485 views

I have designed my own PCB and I have the problem that while the code uploads successfully, it doesn't run.Qwyntex_0-1716384046463.png

I have checked NRST and BOOT0 and both should not be the problem. I have found a similar issue where the chip didn't get a clock signal and therefor was stuck. I have used the debugger to step through the code and it went past HAL_Init but I never come past SystemClock_Config, when trying to step into it the debugger throws 'Cannot find bounds of current function'. I am new to designing PCBs and I don't really know where to go from here or what the issue could be.

It is not the debugger itself as I can run the blinking sketch with no problems on a dev board that I have bought, which is why I have attached the schematic. I can also provide the PCB layout but I think it is much more likely that I made a basic mistake than that the layout is the culprit.

Thank you

    This topic has been closed for replies.
    Best answer by Peter BENSCH

    You have not connected anything to VCAP1, although 4.7µF must be connected to your UFQFPN48 (see data sheet, table 16)?

    Regards
    /Peter

    10 replies

    Technical Moderator
    May 22, 2024

    You have not connected anything to VCAP1, although 4.7µF must be connected to your UFQFPN48 (see data sheet, table 16)?

    Regards
    /Peter

    QwyntexAuthor
    Explorer
    May 22, 2024

    I don't know how I missed that, thank you. I will try and solder it on and when it works I'll mark your answer as the solution

    Graduate II
    May 24, 2024

    Is your added VCAP electrolytic? If yes is you connection polarity right or better change to ...?

    MM1_0-1716524112575.png

     

    QwyntexAuthor
    Explorer
    May 22, 2024

    I have soldered the capacitor and now the program gets past the SystemClock_Config function. The blink script still doesn't work though. After inspecting it with the debugger I narrowed it down to the HAL_Delay function, specifically inside it in the HAL_GetTick function that returns uwTick, which I am assuming should change but for me it stays at zero. I wanted to try the internal clock but the IDE keeps crashing.

    Graduate II
    May 22, 2024

    Make sure HSE and PLL are set with the anticipation that it's using 25 MHz, check HSE_VALUE define. Make sure the clock starts, or use the initial HSI clock to run the part, at least until you've established things are working.

    Have Error_Handler() and HardFault_Handler() indicate if you've died there.

    PC13, PC14, PC15 are assumed to be Low Current, and in the backup/low power domain.

    SysTick not working, double check the base address of the firmware, check vector table, and that you haven't disabled interrupts.  Often SysTick set up in HAL_Init(),  Vectors in SystemInit()

    Graduate
    May 22, 2024

    Hi

    according to your schematic , NRST has no pullup resistor.

    connect like 4.7k pullup resistor.

     

    I.N

    Technical Moderator
    May 22, 2024

    It is NOT recommended to use a pull-up at NRST, because it is already built-in.

    You will find details in the reference manual.

    [edit] Even though such pull-ups are familiar from MCUs of the last millennium and can be found in some horribly constructed Blue, Black or other Pills, this does not mean that they are actually recommended or useful. [/edit]

    Graduate
    May 22, 2024

    Hi Peter ,,

    Thanks for information.

    regards

    I.N

    QwyntexAuthor
    Explorer
    May 22, 2024

    HSE and PLL should both be expecting a 25MHz clock. I have probed the oscillator with an oscilloscope and it works fine. I don't know if that means the clock actually started nor how to check for that.
    When I change the clock source to internal my IDE crashes whenever I try to have it automatically resolve the clock and manually changing it doesn't work either because it insists that something is wrong even if there isn't. Manually changing it in the code would probably work but I have not done that yet and don't know what parameters I would need to change where, I would probably introduce more issues (but I want to ditch HAL sometime anyways, so any good resources will help me later).

    The error handlers don't trigger as it is just stuck in a while loop waiting for uwTick to increment.

    I am not sure of the relevance of the pins being assumed to be low current. Do you mean that drawing too much current on them could introduce odd behavior? I have only one red LED and a 120ohm resistor connected to PC13.

    For the last part I assume they are correct because if they weren't it shouldn't work on the same chip model on a different board, right?

    This is what puzzles me the most, I can upload the same sketch to a different f411ceu6 chip and it works just fine. But it doesn't work on my custom PCB.

    Graduate
    May 22, 2024

    As Tesla mentioned PC13 is not a good choice to drive an LED.

    Datasheet footnote:

    PC13, PC14 and PC15 are supplied through the power switch. Since the switch only sinks a limited amount of current (3mA), the use of GPIOs PC13 to PC15 in output mode is limited:
    - The speed should not exceed 2 MHz with a maximum load of 30 pF.
    - These I/Os must not be used as a current source (e.g. to drive an LED).

    Graduate II
    May 22, 2024

    >>IDE keeps crashing

    What IDE, you keep mentioning "Sketches" which makes me think Arduino. Do you have some loader between you and the code you're running?

    Is it compiling / linking for 0x08000000 operation?

     

    QwyntexAuthor
    Explorer
    May 22, 2024

    The IDE is the STM32CubeIDE. I guess I just internalized using the word sketches from Arudino and didn't want to write 'code' all the time. I'll just write 'script' or 'code' from now on.

    As for the current drawing problem, I didn't know that. I've put the LED there because the dev board I have did, too. I'll change that in the next version but for now, is it actually the problem? Even when the LED should be off and isn't drawing any current the HAL_Delay gets stuck in its loop.

    > Is it compiling / linking for 0x08000000 operation?

    yes

    QwyntexAuthor
    Explorer
    May 23, 2024

    That I couldn't use the internal clock was because I had still enabled the controller as a USB device which wouldn't allow me to use the internal clock. After I changed that I could manually resolve the clock issues and because it was the dialog box that crashes the IDE I was able to generate the code.
    It still doesn't work though, the HAL_Delay gets stuck because the uwTick doesn't increase. Uploading the same code without changes works without a problem on the dev board.

    QwyntexAuthor
    Explorer
    May 23, 2024

    Should I open a new post for this? It might make it easier to find for other people with the same issue and the original question was answered in the first reply by Peter.

    Graduate II
    May 23, 2024

    You could, I suppose, but already a bunch of detail here, I'd press on..

    The SysTick not working is a bit odd. Suggests some issue with NVIC or VTOR configuration, or simply not started. Was a different TIM selected for timing purposes? SysTick is a "System Handler" rather than and interrupt in the broader sense.

    Is this example something you could share on GitHub?

    Look at HAL_Init() code

    F411, no issues are jumping to top-of-mind about odd failings..

    QwyntexAuthor
    Explorer
    May 23, 2024

    Interrupts for the System Tick timer are enabled in the NVIC and I don't think the issue lies in the vector tables either because it runs just fine on the F411 on my dev board (the MCU is exactly the same model, I chose it to not have to modify my code after receiving the PCB). Correct me if I am wrong but the vector tables shouldn't change from one physical chip to another only for different types, right?

    There was, at the beginning, a different timer used but after I figured out the clock configuration issue had something to do with just enabling the USB I created a new project from scratch only enabling the HSE and PC13.
    Same result. The code runs successfully on the dev board but not on my custom PCB.

    That kind of also answers whether I can put it on github. I guess, I could but it really is just a bare bones blinking script.

    The only other thing I can currently think of besides another design mistake in my schematic is that there is maybe some firmware or boot configuration flashed to the dev board that isn't on the MCU of my PCB, but I really don't know anything about that.

    Graduate II
    May 23, 2024

    Well by default SCB->VTOR resets to ZERO, and then what BOOT0 pin maps/shadows there gets to determine what runs, ie FLASH, ROM, RAM,etc

    The actual address then usually gets established in SystemInit() with a bunch of defines getting in the way of SCB->VTOR = 0x08000000;

    You could perhaps re-gen the project, or use one of the NUCLEO or DISCO examples, watching to address the PLL and HSE_VALUE differences.

     

    When I make a template project for a new board I tend to get a UART working with STDIO so printf() works, and get Error_Handler() and HardFault_Handler() to output actionable output via that channel. Also print out the MCU, AHB, and APB clocks so I know what the machine thinks it's doing.

    Check that the Hard Fault works, good way to confirm the Vector Table is in order.

    QwyntexAuthor
    Explorer
    May 23, 2024

    I can't find any errors with the debugger and the Hard Fault seems to work. I didn't have time right now to get UART working, I will do that and print out the clocks if you think it's worth it

    I just have a few other things to do right now

    QwyntexAuthor
    Explorer
    May 24, 2024

    I have literally no idea what I changed but it's working now. I was trying to get printf to output to the debugger console and have changed a few things, including in the debugger I enabled SWV but that's pretty much it. (On my computer if I scroll over a dropdown I can change its value so maybe that happened by accident? But why did it then work on the dev board?), maybe that was it, I really don't know. There was also an update for the debugger but it didn't work immediately after that and it has worked on the dev board before that so I can't really imagine that being the fix.
    Weirdly, now it works with my other debug configuration, too, and I haven't changed anything there.
    I am very confused.

    At least it works now.

    For anybody wondering, the LED works fine. It surely isn't good to have it on PC13 but it isn't killing the chip (as of now). So if anybody made the same mistake and put it there with a comparatively low resistor l it'll probably be ok.


    To answer the few remaining questions that I tested before it suddenly worked:

    enabling css didn't change anything as far as I can tell. I haven't tested for higher voltages but I haven't found any shorts on the PCB (and now that it works that means there probably aren't any).

    The capacitor I added is electrolytic but I have triple checked before soldering it on that I have connected it correctly. I didn't have any ceramic capacitors of that size.

     

    Thank you all so much for trying to help me get this to work, it's just a little sad I can't tell you what was actually wrong.
    I will accept the the first reply by Peter as the solution because they fixed the original problem and there isn't really a solution here for the other one. (though it seems a little wrong as the other three pages were about the second problem)

    Thank you, again, and I am sorry I didn't really figure out what the problem was