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);
}
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