diff --git a/.idea/runConfigurations/OCD_Boot.xml b/.idea/runConfigurations/OCD_Boot.xml index 795ddc5..59f6ee9 100644 --- a/.idea/runConfigurations/OCD_Boot.xml +++ b/.idea/runConfigurations/OCD_Boot.xml @@ -1,9 +1,10 @@ - + + diff --git a/App/app.cpp b/App/app.cpp index 4bc1859..fed05b1 100644 --- a/App/app.cpp +++ b/App/app.cpp @@ -117,7 +117,7 @@ void proximityMessureCompleted(void) { VL6180_RangeData_t VL6180_Range; uint32_t waitAnswerFromReaderMs = 0; #define MAX_WAIT_ANSWER_FROM_GM60 30000 -#define MAX_WAIT_FOR_BOOT_COMMAND 10000 +#define MAX_WAIT_FOR_BOOT_COMMAND 30000 #define DATA_TIMEOUT 500 uint32_t bootStartMs = 0; @@ -146,6 +146,8 @@ uint8_t uartTask(void) // return 0 if data received , otherwise return 1 { uint8_t com = stringView[0]; if (com == ENTER_FIRMWARE_UPDATE) { + HAL_UART_Transmit_IT(bridge.getHuart1(), (uint8_t*) &uart1Buf[0], sizeof(sendCommand)); + HAL_Delay(200); HAL_UART_DeInit(bridge.getHuart1()); BootComInit(); zummerOff(); diff --git a/Boot/App/blt_conf.h b/Boot/App/blt_conf.h index b763798..b9c9e93 100644 --- a/Boot/App/blt_conf.h +++ b/Boot/App/blt_conf.h @@ -73,7 +73,7 @@ /** \brief Configure number of bytes in the host->target data packet. */ #define BOOT_COM_RS232_RX_MAX_DATA (129) /** \brief Select the desired UART peripheral as a zero based index. */ -#define BOOT_COM_RS232_CHANNEL_INDEX (1) +#define BOOT_COM_RS232_CHANNEL_INDEX (0) /**************************************************************************************** diff --git a/Boot/Boot.ioc b/Boot/Boot.ioc index 937590e..45af959 100644 --- a/Boot/Boot.ioc +++ b/Boot/Boot.ioc @@ -11,8 +11,9 @@ Mcu.IP0=CRC Mcu.IP1=NVIC Mcu.IP2=RCC Mcu.IP3=SYS -Mcu.IP4=USART2 -Mcu.IPNb=5 +Mcu.IP4=USART1 +Mcu.IP5=USART2 +Mcu.IPNb=6 Mcu.Name=STM32G070CBTx Mcu.Package=LQFP48 Mcu.Pin0=PF0-OSC_IN (PF0) @@ -56,8 +57,10 @@ PA5.GPIO_Label=READER_EN PA5.Locked=true PA5.Signal=GPIO_Output PB6.Locked=true +PB6.Mode=Asynchronous PB6.Signal=USART1_TX PB7.Locked=true +PB7.Mode=Asynchronous PB7.Signal=USART1_RX PF0-OSC_IN\ (PF0).Mode=HSE-External-Oscillator PF0-OSC_IN\ (PF0).Signal=RCC_OSC_IN @@ -92,7 +95,7 @@ ProjectManager.StackSize=0x400 ProjectManager.TargetToolchain=STM32CubeIDE ProjectManager.ToolChainLocation= ProjectManager.UnderRoot=true -ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-LL-false,2-MX_GPIO_Init-GPIO-false-LL-true,3-MX_USART2_UART_Init-USART2-false-LL-true,4-MX_CRC_Init-CRC-false-HAL-true +ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-LL-false,2-MX_GPIO_Init-GPIO-false-LL-true,3-MX_USART2_UART_Init-USART2-false-LL-true,4-MX_CRC_Init-CRC-false-HAL-true,5-MX_USART1_UART_Init-USART1-false-LL-true RCC.ADCFreq_Value=64000000 RCC.AHBFreq_Value=64000000 RCC.APBFreq_Value=64000000 @@ -120,6 +123,9 @@ RCC.USART1Freq_Value=64000000 RCC.USART2Freq_Value=64000000 RCC.VCOInputFreq_Value=16000000 RCC.VCOOutputFreq_Value=128000000 +USART1.BaudRate=9600 +USART1.IPParameters=VirtualMode-Asynchronous,BaudRate +USART1.VirtualMode-Asynchronous=VM_ASYNC USART2.BaudRate=9600 USART2.IPParameters=VirtualMode-Asynchronous,BaudRate USART2.VirtualMode-Asynchronous=VM_ASYNC diff --git a/Boot/Core/Inc/usart.h b/Boot/Core/Inc/usart.h index 62d5830..d298a63 100644 --- a/Boot/Core/Inc/usart.h +++ b/Boot/Core/Inc/usart.h @@ -36,6 +36,7 @@ extern "C" { /* USER CODE END Private defines */ +void MX_USART1_UART_Init(void); void MX_USART2_UART_Init(void); /* USER CODE BEGIN Prototypes */ diff --git a/Boot/Core/Src/crc.c b/Boot/Core/Src/crc.c index 3b534b9..f8ad7a0 100644 --- a/Boot/Core/Src/crc.c +++ b/Boot/Core/Src/crc.c @@ -26,6 +26,7 @@ /* CRC init function */ + void HAL_CRC_MspInit(CRC_HandleTypeDef* crcHandle) { diff --git a/Boot/Core/Src/gpio.c b/Boot/Core/Src/gpio.c index c5d597e..88fdba5 100644 --- a/Boot/Core/Src/gpio.c +++ b/Boot/Core/Src/gpio.c @@ -39,8 +39,6 @@ * EVENT_OUT * EXTI PA11 [PA9] ------> I2C2_SCL - PB6 ------> USART1_TX - PB7 ------> USART1_RX */ void MX_GPIO_Init(void) { @@ -72,24 +70,6 @@ void MX_GPIO_Init(void) GPIO_InitStruct.Alternate = LL_GPIO_AF_6; LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_0; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_0; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - } /* USER CODE BEGIN 2 */ diff --git a/Boot/Core/Src/main.c b/Boot/Core/Src/main.c index ca3634d..fcc70ec 100644 --- a/Boot/Core/Src/main.c +++ b/Boot/Core/Src/main.c @@ -89,6 +89,7 @@ int main(void) MX_GPIO_Init(); MX_USART2_UART_Init(); MX_CRC_Init(); + MX_USART1_UART_Init(); /* USER CODE BEGIN 2 */ /* Initialize the bootloader application. */ AppInit(); diff --git a/Boot/Core/Src/usart.c b/Boot/Core/Src/usart.c index ca34eb4..79e69e6 100644 --- a/Boot/Core/Src/usart.c +++ b/Boot/Core/Src/usart.c @@ -24,6 +24,77 @@ /* USER CODE END 0 */ +/* USART1 init function */ + +void MX_USART1_UART_Init(void) +{ + + /* USER CODE BEGIN USART1_Init 0 */ + + /* USER CODE END USART1_Init 0 */ + + LL_USART_InitTypeDef USART_InitStruct = {0}; + + LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; + + LL_RCC_SetUSARTClockSource(LL_RCC_USART1_CLKSOURCE_PCLK1); + + /* Peripheral clock enable */ + LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_USART1); + + LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOB); + /**USART1 GPIO Configuration + PB6 ------> USART1_TX + PB7 ------> USART1_RX + */ + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; + GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + GPIO_InitStruct.Alternate = LL_GPIO_AF_0; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; + GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + GPIO_InitStruct.Alternate = LL_GPIO_AF_0; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /* USER CODE BEGIN USART1_Init 1 */ + + /* USER CODE END USART1_Init 1 */ + USART_InitStruct.PrescalerValue = LL_USART_PRESCALER_DIV1; + USART_InitStruct.BaudRate = 9600; + USART_InitStruct.DataWidth = LL_USART_DATAWIDTH_8B; + USART_InitStruct.StopBits = LL_USART_STOPBITS_1; + USART_InitStruct.Parity = LL_USART_PARITY_NONE; + USART_InitStruct.TransferDirection = LL_USART_DIRECTION_TX_RX; + USART_InitStruct.HardwareFlowControl = LL_USART_HWCONTROL_NONE; + USART_InitStruct.OverSampling = LL_USART_OVERSAMPLING_16; + LL_USART_Init(USART1, &USART_InitStruct); + LL_USART_SetTXFIFOThreshold(USART1, LL_USART_FIFOTHRESHOLD_1_8); + LL_USART_SetRXFIFOThreshold(USART1, LL_USART_FIFOTHRESHOLD_1_8); + LL_USART_DisableFIFO(USART1); + LL_USART_ConfigAsyncMode(USART1); + + /* USER CODE BEGIN WKUPType USART1 */ + + /* USER CODE END WKUPType USART1 */ + + LL_USART_Enable(USART1); + + /* Polling USART1 initialisation */ + while((!(LL_USART_IsActiveFlag_TEACK(USART1))) || (!(LL_USART_IsActiveFlag_REACK(USART1)))) + { + } + /* USER CODE BEGIN USART1_Init 2 */ + + /* USER CODE END USART1_Init 2 */ + +} /* USART2 init function */ void MX_USART2_UART_Init(void) diff --git a/Boot/loader/backdoor.c b/Boot/loader/backdoor.c index 4073ac8..60f012f 100644 --- a/Boot/loader/backdoor.c +++ b/Boot/loader/backdoor.c @@ -42,7 +42,7 @@ * BOOT_BACKDOOR_ENTRY_TIMEOUT_MS to blt_conf.h with your desired backdoor * open time in milliseconds. */ -#define BOOT_BACKDOOR_ENTRY_TIMEOUT_MS (500) +#define BOOT_BACKDOOR_ENTRY_TIMEOUT_MS (5000) #endif #endif /* BOOT_BACKDOOR_HOOKS_ENABLE == 0 */ @@ -168,6 +168,7 @@ void BackDoorCheck(void) } } #endif + } /*** end of BackDoorCheck ***/ diff --git a/Boot/loader/xcp.c b/Boot/loader/xcp.c index 8dbbeb4..70f0813 100644 --- a/Boot/loader/xcp.c +++ b/Boot/loader/xcp.c @@ -171,6 +171,7 @@ void XcpInit(void) ****************************************************************************************/ blt_bool XcpIsConnected(void) { + if (xcpInfo.connected == 0) { return BLT_FALSE; diff --git a/utils/board.cfg b/utils/board.cfg index 82698af..183e683 100644 --- a/utils/board.cfg +++ b/utils/board.cfg @@ -1,4 +1,4 @@ -adapter serial "\x34\x00\x48\x00\x0D\x00\x00\x59\x33\x4A\x53\x4E" +adapter serial "48FF71066567495729231187" # This is for all ST NUCLEO with any STM32F4. Known boards at the moment: # STM32F401RET6 diff --git a/utils/debugger_script.ps1 b/utils/debugger_script.ps1 index 6b0f6b3..2118490 100644 --- a/utils/debugger_script.ps1 +++ b/utils/debugger_script.ps1 @@ -3,10 +3,20 @@ $dir=$PSScriptRoot $MyCommand="$dir"+"\stlink\st-info.exe --probe --hot-plug" Invoke-Expression -Command $MyCommand | Out-String -OutVariable output $DevicesNum=$output.Substring($output.IndexOf("Found") + 7, 1) +Write-Host -ForegroundColor Yellow -BackgroundColor Blue 'Do you wanna run the script N/Y' +$key=Read-Host +if ($key.ToUpper() -notmatch 'Y') +{ + exit +} if ($DevicesNum -eq 1) { $serial=$output.Substring($output.Trim().IndexOf("serial") + 12, 24) } +elseif ($DevicesNum -eq 0) +{ + exit +} else { Write-Host -ForegroundColor Yellow -BackgroundColor Blue 'Press key which number of debugger you wanna use' @@ -24,7 +34,7 @@ $serial=$serial.ToCharArray() $StringForCompare='adapter serial "' for ($i = 0; $i -lt $serial.Count; $i=$i+2) { - $StringForCompare=$StringForCompare.Insert($StringForCompare.Length,"\x$($serial.Get($i))$($serial.Get($i+1))") + $StringForCompare=$StringForCompare.Insert($StringForCompare.Length,"$($serial.Get($i))$($serial.Get($i+1))") } $StringForCompare=$StringForCompare.Insert($StringForCompare.Length,'"') $Path = "$dir"+"/board.cfg"