Having a problem with bootloader after uploading code

Bootloader for STM32F103 and STM32F4xx micro-controllers
No special driver is required. Support for Windows, Linux and Mac Operating System
mauriziostm32
Posts: 23
Joined: Sat Mar 21, 2020 3:18 pm
Answers: 1

Re: Having a problem with bootloader after uploading code

Post by mauriziostm32 »

Hi Guys

Thanks for the help and the hints.
stas2z nvic_sys_reset() is working... for the second point I was hoping in a function()… like for the soft reset nvic_sys_reset()… the recompiling and coding solution is a little bit too time consuming in relation to my actual knowledge... as always I like to study, and one day I will dig dipper, but in this moment I need to go on with the project...
To the end I think that I will go on with Roger's core... I tested some hardware solution very easy to implement.. and i'm almost there... I just need another small help.

So what I've done is: to put the MCU on bootloader mode
- I connected to Pin 20 (boot1) a capacitor in series to a resistor (connected to ground) in order to create a timer (that for the discharge time of the capacitor )
- Then I used another pin to pump 3.3v on the capacitor... after a small delay (to let the the capacitor charge (R*C*5)) I nvic_sys_reset() ; when the board reboot the capacitor has kept enough voltage to let PB20 "feel HIGH" so it goes in Bootloader mode...

Then there is the last problem I need to fix... it doesn't reenumerate… the logical solution (without adding any extra circuitry) is: before to put the MCU in bootloader mode I need to pull down PA12 (USB+). Not being an expert I tried the easiest solution to set PA12 as OUTPUT_OPEN_DRAIN and then LOW... but it doesn't work...
I guess before to set PA12 as output I need to disable the USB (I guess there is no function like reenumerate(); or a SDIS bit to set for software disconnect like for other microcontroller)
I gave a look to the HID bootloader and in the usb.c file there is a nice function that in principle let me understand the way needs to be done... but I don't have the background knowledge to translate this code to ARDUINO code... or to insert the proper register settings to the Arduino code...

Code: Select all

void USB_Shutdown(void)
{

	/* Disable USB IRQ */
	NVIC_DisableIRQ(USB_LP_CAN1_RX0_IRQn);
	WRITE_REG(*ISTR, 0);
	DeviceConfigured = 0;

	/* Turn USB Macrocell off */
	WRITE_REG(*CNTR, CNTR_FRES | CNTR_PDWN);

	/* PA12: General purpose output 50 MHz open drain */
	SET_BIT(RCC->APB2ENR, RCC_APB2ENR_IOPAEN);
	MODIFY_REG(GPIOA->CRH,
		GPIO_CRH_CNF12 | GPIO_CRH_MODE12,
		GPIO_CRH_CNF12_0 | GPIO_CRH_MODE12);

	/* Sinks PA12 to GND */
	WRITE_REG(GPIOA->BRR, GPIO_BRR_BR12);

	/* Disable USB Clock on APB1 */
	CLEAR_BIT(RCC->APB1ENR, RCC_APB1ENR_USBEN);
}
So the road seems to be: Shut down procedure of the USB and then PA12 down...
After I put PA12 down I don't need anything else.. because i will charge the capacitor and SOFT-RESET.. and when the microcontroller will reboot it will be in bootloader mode and with PA12 high again... ready to be reprogrammed -> HID

Is there some instruction I can insert in my Arduino code to do this? I don't want to use another Pin to put Pa12 physically down....

Thanks
stevestrong
Posts: 502
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 8
Location: Munich, Germany
Contact:

Re: Having a problem with bootloader after uploading code

Post by stevestrong »

The way in this thread was posted:
to shutdown the USB you need to call

Code: Select all

Serial.end();
After that you can set pin mode and it should work.
mauriziostm32
Posts: 23
Joined: Sat Mar 21, 2020 3:18 pm
Answers: 1

Re: Having a problem with bootloader after uploading code

Post by mauriziostm32 »

stevestrong wrote: Mon Apr 20, 2020 7:20 am The way in this thread was posted:
to shutdown the USB you need to call

Code: Select all

Serial.end();
After that you can set pin mode and it should work.
:o :) stevestrong you are a wizard.... i spent all the morning (I live in UTC+ 8 timezone) to look for it

You saved my day... It works... it goes in HID mode and reenumerate... so I don't need driver and I don't need to specify com port.

Great!!!

Many many thanks...
mauriziostm32
Posts: 23
Joined: Sat Mar 21, 2020 3:18 pm
Answers: 1

Re: Having a problem with bootloader after uploading code

Post by mauriziostm32 »

Hi Guys

One small problem... then I promise I will be quiet ;)

Roger Clark Core with Hid Bootloader patch... All works great... but

If I try to upload a sketch using ST-Link V2 it seems the SWD port is disabled... the only way is to pull up to 3.3 V boot1 then I can upload using ST-Link V2. I tried to put enableDebugPorts(); in the setup()… but it is still not working... Not a big problem but I'd like to know the cause...

Other problem... I want to make a copy of the content of the Flash (sketch and bootloader) after I connect St-Link v2 (Pulling up boot 1) I click on save... as .bin
But If I try to upload back it is not possible...
The elf loader program function fails
Memory-Loader error
program memory checksum 0x0002ABFD

:shock:
stevestrong
Posts: 502
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 8
Location: Munich, Germany
Contact:

Re: Having a problem with bootloader after uploading code

Post by stevestrong »

The HID patch is not needed for Roger's core, you can select the HID upload in the Arduino IDE.
mauriziostm32
Posts: 23
Joined: Sat Mar 21, 2020 3:18 pm
Answers: 1

Re: Having a problem with bootloader after uploading code

Post by mauriziostm32 »

stevestrong wrote: Thu Apr 23, 2020 3:26 pm The HID patch is not needed for Roger's core, you can select the HID upload in the Arduino IDE.
Hi Steve

Thanks

I've tried many combinations of Roger's core releases and Hid Bootloaders..
If I install the last Roger Core one of the HID bootloader is working, but doesn't reboot the board on the first upload... and then it is not possible to upload using Hid bootloader, USB -to serial maple... needs to move boot1.... I have to underline that definitely on the last Roger's core you don't have to install the patch otherwise nothing is working (referring hid things)... but you can use St-link without moving boot 1

I installed the core I used more... it is probably almost 1 year old...
… and with that if you want HID things to work you do need to install the patch...
Then everything is working (almost).. first upload is 100% Hid... then Arduino manage to reboot the blue pill and the board is recognized as Maple serial and further upload are possible by hid bootloader ( USB-serial)… in my final solution as I pointed out i will put in bootloader mode every time by a resistor in parallel with a capacitor. and a pin to 1.. the only small problem is that to use ST-link v2 you have to pull Boot 1 high...

So for now i keep the old core and the patch... till something some other problem come out ;)

Keep reading the next post because there is something weird and funny...
mauriziostm32
Posts: 23
Joined: Sat Mar 21, 2020 3:18 pm
Answers: 1

FAKE OR NOT FAKE? Probably fake but good enough

Post by mauriziostm32 »

Hi Guys

I keep writing here because it is in some way HID- bootloader related...

In the past I bought many Blue and Black pills from different Taobao shops... and they always worked... I was using Roger's USB bootloader, and they never failed me....

But now I'm starting questioning the genuineness of the chip on top of these boards...

These are the symptoms: You upload the HID bootloader by ST-link utility... then...
The board is not recognized.... the message from windows 7 is USB not recognized... … some other boards accept the first HID upload and then after the reenumeration … the message is the same USB not recognized... Genuine chip after the first upload are recognized as Maple serial and accept further uploads by USB-Serial... Yes... I thought could have been a resistor problem, so i soldered a 2k in parallel to put the value at 1.6.. but the problem is still there

I started to google a little and in facts there are clones around....

Looking at the chips many are different from each others … some have 2 small circular depressions some even 3... chips that works ok with the bootloader they always have 1 depression... Some chip have white fonts and other have some sort of marked depressed font without white ink...
All writing STM32F103C8T6...

To test the code and play around with the comfortable Roger's USB bootloader they all work...
with ST-link utility they are all recognized as original...
Is there an interface and a software that can tell for sure if they are original???



Thanks
mauriziostm32
Posts: 23
Joined: Sat Mar 21, 2020 3:18 pm
Answers: 1

Re: Having a problem with bootloader after uploading code

Post by mauriziostm32 »

Hi Guys

Thanks also to you I completed the project early April... Then I started to produce , but I encountered the usual problem of the self made PCB and soldering...

Few months ago I built myself a PICK & PLACE machine...


Image

the results: Nice pictures of the STM32F103C8T6 I used

Image

I live in China, and here everything related to electronics is economically and logistically accessible. The problem was to do something professional i needed the support of factories, they can take care of all the PCB soldering... But also here in China this is not a solution for prototyping and small production... so few years ago i built myself a reflow oven... However placing the SMD components on the PCB by tweezers or by vacuum pen was a nightmare... Holding the breath and squeezing the eyes... To go really pro i needed a Pick and Place machine... but... the prices for a manual one are high... and also here in China there is nothing good and affordable... I decided to build one myself ... ordering many small mechanical pieces to test... finally i was able to have a very good and affordable pick and place machine with microscope.


Image


I think let other people benefit from my effort could be useful to many.

I built a website, there you can see many pictures of my development, and many pictures of my STM32 solutions. The stencil in China is about 8us dollar, so every time I prototype I go for the stencil....

I also made a video of the production of the PCB (picture above) using my Pick and Place machine and my reflow oven but the strategy I used may be used with yourself built Pick and Place machine tooo. this is the YOUTUBE link.

https://www.youtube.com/watch?v=RCHVMQy ... e=emb_logo

I don't know if it is allowed post link to personal websites so I won't do.

Now i'm adding to my project a gps. So I need to squeeze on that small PCB also a GPS, antenna and micro sd..... the software is almost done... I will start to redesign the PCB by Eagle soon.
If you need suggestion or info about how to do just contact me.
parisianos
Posts: 11
Joined: Tue Jan 18, 2022 11:17 pm

Re: Having a problem with bootloader after uploading code

Post by parisianos »

For me I have the same problem but not valide solution. Blackpill not accept any program. I have the same config that you write. I try anything and nothing works. Thanks
mrburnette
Posts: 633
Joined: Thu Dec 19, 2019 1:23 am
Answers: 7

Re: Having a problem with bootloader after uploading code

Post by mrburnette »

fpiSTM wrote: Sun Apr 19, 2020 5:21 am ...
When dealing with Windows 32/64 one can dig deeper than OS tools with specific utilities:
https://docs.microsoft.com/en-us/sysint ... downloads/

For example:
Portmon is a utility that monitors and displays all serial and parallel port activity on a system. It has advanced filtering and search capabilities that make it a powerful tool for exploring the way Windows works, seeing how applications use ports, or tracking down problems in system or application configurations.
There is a gold mine in these utilities...


Ray
Post Reply

Return to “STM32 HID bootloader”